From 6090d199a5ccf44c2777b66e13254754c8486e0c Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Mon, 28 Jan 2002 05:34:17 +0000 Subject: [PATCH] Optimize the case where a component is entirely transparent by skipping Sun Jan 27 23:58:13 2002 Owen Taylor * pixbuf-render.c (compute_hint): Optimize the case where a component is entirely transparent by skipping drawing it. * pixbuf-rc-style.c (theme_parse_image): Catch case where background or overlay border/stretch are specified without a background image. * pixbuf-render.c (theme_pixbuf_destroy): Actually free the structure and filename. --- modules/engines/pixbuf/ChangeLog | 13 ++++++++++++ modules/engines/pixbuf/Makefile.am | 4 ++++ modules/engines/pixbuf/pixbuf-draw.c | 3 ++- modules/engines/pixbuf/pixbuf-rc-style.c | 14 +++++++++++++ modules/engines/pixbuf/pixbuf-render.c | 26 ++++++++++++++++++------ modules/engines/pixbuf/pixbuf.h | 3 ++- 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/modules/engines/pixbuf/ChangeLog b/modules/engines/pixbuf/ChangeLog index cc8e0f4e13..b1cc574825 100644 --- a/modules/engines/pixbuf/ChangeLog +++ b/modules/engines/pixbuf/ChangeLog @@ -1,3 +1,16 @@ +Sun Jan 27 23:58:13 2002 Owen Taylor + + * pixbuf-render.c (compute_hint): Optimize the case + where a component is entirely transparent by skipping + drawing it. + + * pixbuf-rc-style.c (theme_parse_image): Catch case + where background or overlay border/stretch are specified + without a background image. + + * pixbuf-render.c (theme_pixbuf_destroy): Actually free + the structure and filename. + =================== Move back into gtk-engines ==================== Sat Jan 19 02:45:17 2002 Owen Taylor diff --git a/modules/engines/pixbuf/Makefile.am b/modules/engines/pixbuf/Makefile.am index 22bb327e82..d3e6bdef40 100644 --- a/modules/engines/pixbuf/Makefile.am +++ b/modules/engines/pixbuf/Makefile.am @@ -14,3 +14,7 @@ libpixmap_la_SOURCES = \ pixbuf.h libpixmap_la_LDFLAGS = -avoid-version -module + +dist-hook: + cp -pr examples $(distdir); \ + find $(distdir)/examples -name 'CVS' -print | xargs rm -rf diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c index ab192a446e..2fe5bc6412 100644 --- a/modules/engines/pixbuf/pixbuf-draw.c +++ b/modules/engines/pixbuf/pixbuf-draw.c @@ -659,9 +659,10 @@ draw_box (GtkStyle *style, match_data.state = state; if (!draw_simple_image (style, window, area, widget, &match_data, TRUE, TRUE, - x, y, width, height)) + x, y, width, height)) { parent_class->draw_box (style, window, state, shadow, area, widget, detail, x, y, width, height); + } } static void diff --git a/modules/engines/pixbuf/pixbuf-rc-style.c b/modules/engines/pixbuf/pixbuf-rc-style.c index 6fbb92fb15..210b0f5256 100644 --- a/modules/engines/pixbuf/pixbuf-rc-style.c +++ b/modules/engines/pixbuf/pixbuf-rc-style.c @@ -664,6 +664,20 @@ theme_parse_image(GtkSettings *settings, token = g_scanner_get_next_token(scanner); + if (data->background && !data->background->filename) + { + g_scanner_warn (scanner, "Background image options specified without filename"); + theme_pixbuf_destroy (data->background); + data->background = NULL; + } + + if (data->overlay && !data->overlay->filename) + { + g_scanner_warn (scanner, "Overlay image options specified without filename"); + theme_pixbuf_destroy (data->overlay); + data->overlay = NULL; + } + if (token != G_TOKEN_RIGHT_CURLY) { /* error - cleanup for exit */ diff --git a/modules/engines/pixbuf/pixbuf-render.c b/modules/engines/pixbuf/pixbuf-render.c index 08201f330f..d34632b236 100644 --- a/modules/engines/pixbuf/pixbuf-render.c +++ b/modules/engines/pixbuf/pixbuf-render.c @@ -180,6 +180,9 @@ pixbuf_render (GdkPixbuf *src, rect.width = dest_width; rect.height = dest_height; + if (hints & THEME_MISSING) + return; + /* FIXME: Because we use the mask to shape windows, we don't use * clip_rect to clip what we draw to the mask, only to clip * what we actually draw. But this leads to the horrible ineffiency @@ -290,8 +293,8 @@ theme_pixbuf_new (void) void theme_pixbuf_destroy (ThemePixbuf *theme_pb) { - if (theme_pb->pixbuf) - g_cache_remove (pixbuf_cache, theme_pb->pixbuf); + theme_pixbuf_set_filename (theme_pb, NULL); + g_free (theme_pb); } void @@ -307,7 +310,10 @@ theme_pixbuf_set_filename (ThemePixbuf *theme_pb, if (theme_pb->filename) g_free (theme_pb->filename); - theme_pb->filename = g_strdup (filename); + if (filename) + theme_pb->filename = g_strdup (filename); + else + theme_pb->filename = NULL; } static guint @@ -318,7 +324,7 @@ compute_hint (GdkPixbuf *pixbuf, gint y1) { int i, j; - int hints = THEME_CONSTANT_ROWS | THEME_CONSTANT_COLS; + int hints = THEME_CONSTANT_ROWS | THEME_CONSTANT_COLS | THEME_MISSING; int n_channels = gdk_pixbuf_get_n_channels (pixbuf); guchar *data = gdk_pixbuf_get_pixels (pixbuf); @@ -340,13 +346,21 @@ compute_hint (GdkPixbuf *pixbuf, for (j = x0 + 1; j < x1 ; j++) { + if (n_channels != 4 || p[4] != 0) + { + hints &= ~THEME_MISSING; + if (!(hints & THEME_CONSTANT_ROWS)) + goto cols; + } + if (r != *(p++) || g != *(p++) || b != *(p++) || - (n_channels == 4 && a != *(p++))) + (n_channels != 4 && a != *(p++))) { hints &= ~THEME_CONSTANT_ROWS; - goto cols; + if (!(hints & THEME_MISSING)) + goto cols; } } } diff --git a/modules/engines/pixbuf/pixbuf.h b/modules/engines/pixbuf/pixbuf.h index 34dfeb61c0..2638fc87bd 100644 --- a/modules/engines/pixbuf/pixbuf.h +++ b/modules/engines/pixbuf/pixbuf.h @@ -121,7 +121,8 @@ typedef enum { typedef enum { THEME_CONSTANT_ROWS = 1 << 0, - THEME_CONSTANT_COLS = 1 << 1 + THEME_CONSTANT_COLS = 1 << 1, + THEME_MISSING = 1 << 2 } ThemeRenderHints; struct _ThemePixbuf