[gimp] app: move creating of the cairo_t to gimp_display_shell_canvas_expose()



commit d1393686abae45ea403798511c36faf2f7f5d1ad
Author: Michael Natterer <mitch gimp org>
Date:   Sat Aug 28 00:09:31 2010 +0200

    app: move creating of the cairo_t to gimp_display_shell_canvas_expose()
    
    and pass it down to the drawing functions.

 app/display/gimpdisplayshell-callbacks.c |   44 +++++++++++++++---------------
 1 files changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index d8df28b..b2181c3 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -103,9 +103,11 @@ static GdkModifierType
 static GdkEvent * gimp_display_shell_compress_motion          (GimpDisplayShell *shell);
 
 static void       gimp_display_shell_canvas_expose_image      (GimpDisplayShell *shell,
-                                                               GdkEventExpose   *eevent);
+                                                               GdkEventExpose   *eevent,
+                                                               cairo_t          *cr);
 static void       gimp_display_shell_canvas_expose_drop_zone  (GimpDisplayShell *shell,
-                                                               GdkEventExpose   *eevent);
+                                                               GdkEventExpose   *eevent,
+                                                               cairo_t          *cr);
 static void       gimp_display_shell_process_tool_event_queue (GimpDisplayShell *shell,
                                                                GdkModifierType   state,
                                                                guint32           time);
@@ -392,19 +394,30 @@ gimp_display_shell_canvas_expose (GtkWidget        *widget,
   /*  ignore events on overlays  */
   if (eevent->window == gtk_widget_get_window (widget))
     {
+      cairo_t *cr;
+
       if (gimp_display_get_image (shell->display))
         {
           gimp_display_shell_pause (shell);
 
           if (gimp_display_shell_is_double_buffered (shell))
             gdk_window_begin_paint_region (eevent->window, eevent->region);
+        }
 
-          gimp_display_shell_canvas_expose_image (shell, eevent);
+      cr = gdk_cairo_create (gtk_widget_get_window (shell->canvas));
+      gdk_cairo_region (cr, eevent->region);
+      cairo_clip (cr);
+
+      if (gimp_display_get_image (shell->display))
+        {
+          gimp_display_shell_canvas_expose_image (shell, eevent, cr);
         }
       else
         {
-          gimp_display_shell_canvas_expose_drop_zone (shell, eevent);
+          gimp_display_shell_canvas_expose_drop_zone (shell, eevent, cr);
         }
+
+      cairo_destroy (cr);
     }
 
   return FALSE;
@@ -2078,7 +2091,7 @@ gimp_display_shell_hscrollbar_update (GtkAdjustment    *adjustment,
                                       GimpDisplayShell *shell)
 {
   /* If we are panning with mouse, scrollbars are to be ignored
-   * or they will cause jitter in motion 
+   * or they will cause jitter in motion
    */
   if (! shell->scrolling)
     gimp_display_shell_scroll (shell,
@@ -2214,9 +2227,9 @@ gimp_display_shell_compress_motion (GimpDisplayShell *shell)
 
 static void
 gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
-                                        GdkEventExpose   *eevent)
+                                        GdkEventExpose   *eevent,
+                                        cairo_t          *cr)
 {
-  cairo_t      *cr;
   GdkRegion    *clear_region;
   GdkRegion    *image_region;
   GdkRectangle  image_rect;
@@ -2224,11 +2237,6 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
   gint          n_rects;
   gint          i;
 
-  cr = gdk_cairo_create (eevent->window);
-
-  gdk_cairo_region (cr, eevent->region);
-  cairo_clip (cr);
-
   /*  first, clear the exposed part of the region that is outside the
    *  image, which is the exposed region minus the image rectangle
    */
@@ -2317,15 +2325,13 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
 
   /* restart (and recalculate) the selection boundaries */
   gimp_display_shell_selection_control (shell, GIMP_SELECTION_ON);
-
-  cairo_destroy (cr);
 }
 
 static void
 gimp_display_shell_canvas_expose_drop_zone (GimpDisplayShell *shell,
-                                            GdkEventExpose   *eevent)
+                                            GdkEventExpose   *eevent,
+                                            cairo_t          *cr)
 {
-  cairo_t      *cr;
   GdkRectangle *rects;
   gint          n_rects;
   gint          i;
@@ -2343,11 +2349,5 @@ gimp_display_shell_canvas_expose_drop_zone (GimpDisplayShell *shell,
 
   g_free (rects);
 
-  cr = gdk_cairo_create (gtk_widget_get_window (shell->canvas));
-  gdk_cairo_region (cr, eevent->region);
-  cairo_clip (cr);
-
   gimp_canvas_draw_drop_zone (GIMP_CANVAS (shell->canvas), cr);
-
-  cairo_destroy (cr);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]