From b179d2a76be6683f71a7e135dbc3406fcb2db4e0 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sun, 4 Apr 2004 15:53:21 +0000 Subject: [PATCH] Cache the GC for drawing the grid as suggested in bug #138081: 2004-04-04 Sven Neumann Cache the GC for drawing the grid as suggested in bug #138081: * app/display/gimpdisplayshell.[ch]: added a grid_gc member to GimpDisplayShell. * app/display/gimpdisplayshell-handlers.c (gimp_display_shell_grid_notify_handler) (gimp_display_shell_disconnect): invalidate the grid GC. * app/display/gimpdisplayshell-draw.c (gimp_display_shell_draw_grid): use the cached grid_gc. Also applied the fix that Pedro Gimeno did for bug #138606. --- ChangeLog | 15 ++++++++++++ app/display/gimpdisplayshell-draw.c | 31 +++++++++++++------------ app/display/gimpdisplayshell-handlers.c | 12 ++++++++++ app/display/gimpdisplayshell.c | 1 + app/display/gimpdisplayshell.h | 1 + 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index a33a84a1b0..a2833892c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-04-04 Sven Neumann + + Cache the GC for drawing the grid as suggested in bug #138081: + + * app/display/gimpdisplayshell.[ch]: added a grid_gc member to + GimpDisplayShell. + + * app/display/gimpdisplayshell-handlers.c + (gimp_display_shell_grid_notify_handler) + (gimp_display_shell_disconnect): invalidate the grid GC. + + * app/display/gimpdisplayshell-draw.c (gimp_display_shell_draw_grid): + use the cached grid_gc. Also applied the fix that Pedro Gimeno did + for bug #138606. + 2004-04-04 Sven Neumann * app/core/gimpundo.c (gimp_undo_type_to_name): added a missing diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 8776648a79..c1d50b1104 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -44,8 +44,8 @@ /* local function prototypes */ -static GdkGC * gimp_display_shell_grid_gc_new (GtkWidget *widget, - GimpGrid *grid); +static GdkGC * gimp_display_shell_get_grid_gc (GimpDisplayShell *shell, + GimpGrid *grid); /* public functions */ @@ -132,10 +132,9 @@ gimp_display_shell_draw_grid (GimpDisplayShell *shell) { GimpGrid *grid; GimpCanvas *canvas; - GdkGC *gc; + gdouble x, y; gint x1, x2; gint y1, y2; - gint x, y; gint x_real, y_real; gint width, height; const gint length = 2; @@ -156,9 +155,8 @@ gimp_display_shell_draw_grid (GimpDisplayShell *shell) canvas = GIMP_CANVAS (shell->canvas); - gc = gimp_display_shell_grid_gc_new (shell->canvas, grid); - gimp_canvas_set_custom_gc (canvas, gc); - g_object_unref (gc); + gimp_canvas_set_custom_gc (canvas, + gimp_display_shell_get_grid_gc (shell, grid)); switch (grid->style) { @@ -386,13 +384,15 @@ gimp_display_shell_draw_area (GimpDisplayShell *shell, /* private functions */ static GdkGC * -gimp_display_shell_grid_gc_new (GtkWidget *widget, - GimpGrid *grid) +gimp_display_shell_get_grid_gc (GimpDisplayShell *shell, + GimpGrid *grid) { - GdkGC *gc; GdkGCValues values; GdkColor fg, bg; + if (shell->grid_gc) + return shell->grid_gc; + switch (grid->style) { case GIMP_GRID_ON_OFF_DASH: @@ -412,14 +412,15 @@ gimp_display_shell_grid_gc_new (GtkWidget *widget, values.join_style = GDK_JOIN_MITER; - gc = gdk_gc_new_with_values (widget->window, - &values, GDK_GC_LINE_STYLE | GDK_GC_JOIN_STYLE); + shell->grid_gc = gdk_gc_new_with_values (shell->canvas->window, + &values, (GDK_GC_LINE_STYLE | + GDK_GC_JOIN_STYLE)); gimp_rgb_get_gdk_color (&grid->fgcolor, &fg); gimp_rgb_get_gdk_color (&grid->bgcolor, &bg); - gdk_gc_set_rgb_fg_color (gc, &fg); - gdk_gc_set_rgb_bg_color (gc, &bg); + gdk_gc_set_rgb_fg_color (shell->grid_gc, &fg); + gdk_gc_set_rgb_bg_color (shell->grid_gc, &bg); - return gc; + return shell->grid_gc; } diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c index 947c8abf86..87a671e670 100644 --- a/app/display/gimpdisplayshell-handlers.c +++ b/app/display/gimpdisplayshell-handlers.c @@ -266,6 +266,12 @@ gimp_display_shell_disconnect (GimpDisplayShell *shell) shell->icon_idle_id = 0; } + if (shell->grid_gc) + { + g_object_unref (shell->grid_gc); + shell->grid_gc = NULL; + } + g_signal_handlers_disconnect_by_func (gimage->gimp->config, gimp_display_shell_ants_speed_notify_handler, shell); @@ -361,6 +367,12 @@ gimp_display_shell_grid_notify_handler (GimpGrid *grid, GParamSpec *pspec, GimpDisplayShell *shell) { + if (shell->grid_gc) + { + g_object_unref (shell->grid_gc); + shell->grid_gc = NULL; + } + gimp_display_shell_expose_full (shell); /* update item factory */ diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index fc77754059..b5e4b84685 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -232,6 +232,7 @@ gimp_display_shell_init (GimpDisplayShell *shell) shell->vsbdata = NULL; shell->canvas = NULL; + shell->grid_gc = NULL; shell->hsb = NULL; shell->vsb = NULL; diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index 6e90fd7cc1..e8efe52ecf 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -99,6 +99,7 @@ struct _GimpDisplayShell GtkAdjustment *vsbdata; GtkWidget *canvas; /* GimpCanvas widget */ + GdkGC *grid_gc; /* GC for grid drawing */ GtkWidget *hsb; /* scroll bars */ GtkWidget *vsb;