Cache the GC for drawing the grid as suggested in bug #138081:

2004-04-04  Sven Neumann  <sven@gimp.org>

	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.
This commit is contained in:
Sven Neumann 2004-04-04 15:53:21 +00:00 committed by Sven Neumann
parent b982c495fd
commit b179d2a76b
5 changed files with 45 additions and 15 deletions

View file

@ -1,3 +1,18 @@
2004-04-04 Sven Neumann <sven@gimp.org>
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 <sven@gimp.org>
* app/core/gimpundo.c (gimp_undo_type_to_name): added a missing

View file

@ -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;
}

View file

@ -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 */

View file

@ -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;

View file

@ -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;