[dia/dia-next: 27/59] Working rendering of the canvas



commit e9b31b82a6c8886eebadbfb0f3bee38f7a1144d3
Author: Zander Brown <zbrown gnome org>
Date:   Tue Dec 25 12:25:09 2018 +0000

    Working rendering of the canvas

 app/display.c                       | 164 +-----------------------------------
 app/display.h                       |   5 --
 app/interface.c                     |  41 ++-------
 lib/diainteractiverenderer.c        |  16 +++-
 lib/diarenderer.h                   |  13 ++-
 lib/renderer/diacairo-interactive.c |  20 +++--
 6 files changed, 45 insertions(+), 214 deletions(-)
---
diff --git a/app/display.c b/app/display.c
index 1b26ca8a..0b5ef0c9 100644
--- a/app/display.c
+++ b/app/display.c
@@ -198,8 +198,6 @@ copy_display(DDisplay *orig_ddisp)
   ddisp->aa_renderer = orig_ddisp->aa_renderer;
   
   ddisp->update_areas = orig_ddisp->update_areas;
-  ddisp->display_areas = orig_ddisp->display_areas;
-  ddisp->update_id = 0;
 
   ddisp->clicked_position.x = ddisp->clicked_position.y = 0.0;
   
@@ -257,8 +255,6 @@ new_display(Diagram *dia)
     ddisp->aa_renderer = (preset > 0 ? TRUE : FALSE);
   
   ddisp->update_areas = NULL;
-  ddisp->display_areas = NULL;
-  ddisp->update_id = 0;
 
   ddisp->clicked_position.x = ddisp->clicked_position.y = 0.0;
 
@@ -361,20 +357,6 @@ ddisplay_add_update_pixels(DDisplay *ddisp, Point *point,
   ddisplay_add_update(ddisp, &rect);
 }
 
-/** Free display_areas list */
-static void
-ddisplay_free_display_areas(DDisplay *ddisp)
-{
-  GSList *l;
-  l = ddisp->display_areas;
-  while(l!=NULL) {
-    g_free(l->data);
-    l = g_slist_next(l);
-  }
-  g_slist_free(ddisp->display_areas);
-  ddisp->display_areas = NULL;
-}
-
 /** Free update_areas list */
 static void
 ddisplay_free_update_areas(DDisplay *ddisp)
@@ -398,9 +380,6 @@ ddisplay_add_update_all(DDisplay *ddisp)
   if (ddisp->update_areas != NULL) {
     ddisplay_free_update_areas(ddisp);
   }
-  if (ddisp->display_areas != NULL) {
-    ddisplay_free_display_areas(ddisp);
-  }
   ddisplay_add_update(ddisp, &ddisp->visible);
 }
 
@@ -425,8 +404,6 @@ void
 ddisplay_add_update(DDisplay *ddisp, const Rectangle *rect)
 {
   Rectangle *r;
-  int top,bottom,left,right;
-  Rectangle *visible;
   int width, height;
 
   if (!ddisp->renderer)
@@ -449,122 +426,7 @@ ddisplay_add_update(DDisplay *ddisp, const Rectangle *rect)
     rectangle_intersection(r, &ddisp->visible);
   }
   
-  visible = &ddisp->visible;
-  left = floor( (r->left - visible->left)  * (real)width /
-               (visible->right - visible->left) ) - 1;
-  top = floor( (r->top - visible->top)  * (real)height /
-              (visible->bottom - visible->top) ) - 1; 
-  right = ceil( (r->right - visible->left)  * (real)width /
-               (visible->right - visible->left) ) + 1;
-  bottom = ceil( (r->bottom - visible->top)  * (real)height /
-                (visible->bottom - visible->top) ) + 1;
-
-  ddisplay_add_display_area(ddisp,
-                           left, top, 
-                           right, bottom);
-}
-
-void
-ddisplay_add_display_area(DDisplay *ddisp,
-                         int left, int top,
-                         int right, int bottom)
-{
-  IRectangle *r;
-
-  if (!ddisp->renderer)
-    return; /* if we don't have a renderer yet prefer ignoring over crashing */
-  if (left < 0)
-    left = 0;
-  if (top < 0)
-    top = 0;
-  if (right > dia_renderer_get_width_pixels (ddisp->renderer))
-    right = dia_renderer_get_width_pixels (ddisp->renderer); 
-  if (bottom > dia_renderer_get_height_pixels (ddisp->renderer))
-    bottom = dia_renderer_get_height_pixels (ddisp->renderer); 
-  
-  /* draw some rectangles to show where updates are...*/
-  /*
-  gdk_draw_rectangle(gtk_widget_get_window(ddisp->canvas), 
-                    gtk_widget_get_style(ddisp->canvas)->black_gc, TRUE, 
-                    left, top, right-left,bottom-top);
-   */
-  /* Temporarily just do a union of all Irectangles: */
-  if (ddisp->display_areas==NULL) {
-    r = g_new(IRectangle,1);
-    r->top = top; r->bottom = bottom;
-    r->left = left; r->right = right;
-    ddisp->display_areas = g_slist_prepend(ddisp->display_areas, r);
-  } else {
-    r = (IRectangle *) ddisp->display_areas->data;
-  
-    r->top = MIN( r->top, top );
-    r->bottom = MAX( r->bottom, bottom );
-    r->left = MIN( r->left, left );
-    r->right = MAX( r->right, right );
-  }
-}
-
-static gboolean
-ddisplay_update_handler(DDisplay *ddisp)
-{
-  GSList *l;
-  IRectangle *ir;
-  Rectangle *r, totrect;
-  DiaInteractiveRendererInterface *renderer;
-
-  g_return_val_if_fail (ddisp->renderer != NULL, FALSE);
-
-  /* Renders updates to pixmap + copies display_areas to canvas(screen) */
-  renderer = DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp->renderer);
-
-  /* Only update if update_areas exist */
-  l = ddisp->update_areas;
-  if (l != NULL)
-  {
-    totrect = *(Rectangle *) l->data;
-  
-    g_return_val_if_fail (   renderer->clip_region_clear != NULL
-                          && renderer->clip_region_add_rect != NULL, FALSE);
-
-    renderer->clip_region_clear (ddisp->renderer);
-
-    while(l!=NULL) {
-      r = (Rectangle *) l->data;
-
-      rectangle_union(&totrect, r);
-      renderer->clip_region_add_rect (ddisp->renderer, r);
-      
-      l = g_slist_next(l);
-    }
-    /* Free update_areas list: */
-    ddisplay_free_update_areas(ddisp);
-
-    totrect.left -= 0.1;
-    totrect.right += 0.1;
-    totrect.top -= 0.1;
-    totrect.bottom += 0.1;
-    
-    ddisplay_render_pixmap(ddisp, &totrect);
-  }
-
-  l = ddisp->display_areas;
-  while(l!=NULL) {
-    ir = (IRectangle *) l->data;
-
-    g_return_val_if_fail (renderer->copy_to_window, FALSE);
-    renderer->copy_to_window(ddisp->renderer, 
-                             gtk_widget_get_window(ddisp->canvas),
-                             ir->left, ir->top,
-                             ir->right - ir->left, ir->bottom - ir->top);
-    
-    l = g_slist_next(l);
-  }
-
-  ddisplay_free_display_areas(ddisp);
-
-  ddisp->update_id = 0;
-
-  return FALSE;
+  gtk_widget_queue_draw (ddisp->canvas);
 }
 
 void
@@ -578,13 +440,7 @@ ddisplay_flush(DDisplay *ddisp)
    * GTK_PRIORITY_RESIZE = (G_PRIORITY_HIGH_IDLE + 10)
    * Dia's canvas rendering is in between
    */
-  /*if (!ddisp->update_id)
-    ddisp->update_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE+15, (GSourceFunc)ddisplay_update_handler, 
ddisp, NULL);*/
   gtk_widget_queue_draw (ddisp->canvas);
-  if (ddisp->display_areas) {
-    IRectangle *r = (IRectangle *)ddisp->display_areas->data;
-    dia_log_message ("DispUpdt: %4d,%3d - %4d,%3d\n", r->left, r->top, r->right, r->bottom);
-  }
 }
 
 static void
@@ -1100,12 +956,6 @@ ddisplay_set_renderer(DDisplay *ddisp, int aa_renderer)
   GdkWindow *window = gtk_widget_get_window(ddisp->canvas);
   GtkAllocation alloc;
 
-  /* dont mix new renderer with old updates */
-  if (ddisp->update_id) {
-    g_source_remove (ddisp->update_id);
-    ddisp->update_id = 0;
-  }
-
   if (ddisp->renderer)
     g_object_unref (ddisp->renderer);
 
@@ -1217,10 +1067,6 @@ are_you_sure_close_dialog_respond(GtkWidget *widget, /* the dialog */
     if (close_ddisp) /* saving succeeded */
       recent_file_history_add(ddisp->diagram->filename);
 
-    if (ddisp->update_id && close_ddisp) {
-      g_source_remove (ddisp->update_id);
-      ddisp->update_id = 0;
-    }
     /* fall through */
   case GTK_RESPONSE_NO :
     if (close_ddisp)
@@ -1346,12 +1192,6 @@ ddisplay_really_destroy(DDisplay *ddisp)
 {
   if (active_display == ddisp)
     display_set_active(NULL);
-
-  /* last chance to avoid crashing in the idle update */
-  if (ddisp->update_id) {
-    g_source_remove (ddisp->update_id);
-    ddisp->update_id = 0;
-  }
   
   if (ddisp->diagram) {
     diagram_remove_ddisplay(ddisp->diagram, ddisp);
@@ -1365,8 +1205,6 @@ ddisplay_really_destroy(DDisplay *ddisp)
 
   /* Free update_areas list: */
   ddisplay_free_update_areas(ddisp);
-  /* Free display_areas list */
-  ddisplay_free_display_areas(ddisp);
 
   g_free(ddisp);
 }
diff --git a/app/display.h b/app/display.h
index 2fef0f05..929e8905 100644
--- a/app/display.h
+++ b/app/display.h
@@ -83,8 +83,6 @@ struct _DDisplay {
   DiaRenderer *renderer;
   
   GSList *update_areas;           /* Update areas list                 */
-  GSList *display_areas;          /* Display areas list                */
-  guint update_id;                /* idle handler ID for redraws       */
 
   GtkIMContext *im_context;
 
@@ -135,9 +133,6 @@ void ddisplay_add_update_all(DDisplay *ddisp);
 void ddisplay_add_update_with_border(DDisplay *ddisp, const Rectangle *rect,
                                     int pixel_border);
 void ddisplay_add_update(DDisplay *ddisp, const Rectangle *rect);
-void ddisplay_add_display_area(DDisplay *ddisp,
-                              int left, int top,
-                              int right, int bottom);
 void ddisplay_flush(DDisplay *ddisp);
 void ddisplay_update_scrollbars(DDisplay *ddisp);
 void ddisplay_set_origo(DDisplay *ddisp,
diff --git a/app/interface.c b/app/interface.c
index 89c43929..2ffeb819 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -378,10 +378,6 @@ canvas_configure_event (GtkWidget         *widget,
   return new_size;
 }
 
-/* Got when an area previously obscured need to be redrawn.
- * Needs GDK_EXPOSURE_MASK.
- * Gone with gtk+-3.0 or better replaced by "draw".
- */
 static gboolean
 canvas_draw (GtkWidget      *widget,
              cairo_t        *ctx,
@@ -391,12 +387,6 @@ canvas_draw (GtkWidget      *widget,
   Rectangle *r, totrect;
   DiaInteractiveRendererInterface *renderer;
 
-  /* Add all the area (hangover from expose) */
-  ddisplay_add_display_area (ddisp,
-                             0, 0,
-                             gtk_widget_get_allocated_width (widget),
-                             gtk_widget_get_allocated_height (widget));
-  
   g_return_val_if_fail (ddisp->renderer != NULL, FALSE);
 
   /* Renders updates to pixmap + copies display_areas to canvas(screen) */
@@ -422,13 +412,13 @@ canvas_draw (GtkWidget      *widget,
       l = g_slist_next(l);
     }
     /* Free update_areas list: */
-    l = ddisp->display_areas;
+    l = ddisp->update_areas;
     while(l!=NULL) {
       g_free(l->data);
       l = g_slist_next(l);
     }
-    g_slist_free(ddisp->display_areas);
-    ddisp->display_areas = NULL;
+    g_slist_free(ddisp->update_areas);
+    ddisp->update_areas = NULL;
 
     totrect.left -= 0.1;
     totrect.right += 0.1;
@@ -438,27 +428,10 @@ canvas_draw (GtkWidget      *widget,
     ddisplay_render_pixmap(ddisp, &totrect);
   }
 
-  l = ddisp->display_areas;
-  while(l!=NULL) {
-    g_return_val_if_fail (renderer->copy_to_window, FALSE);
-    renderer->copy_to_window(ddisp->renderer, 
-                             ctx,
-                             0, 0,
-                             gtk_widget_get_allocated_width (widget),
-                             gtk_widget_get_allocated_height (widget));
-    
-    l = g_slist_next(l);
-  }
-
-  l = ddisp->display_areas;
-  while(l!=NULL) {
-    g_free(l->data);
-    l = g_slist_next(l);
-  }
-  g_slist_free(ddisp->display_areas);
-  ddisp->display_areas = NULL;
-
-  ddisp->update_id = 0;
+  dia_interactive_renderer_paint (ddisp->renderer,
+                                  ctx,
+                                  gtk_widget_get_allocated_width (widget),
+                                  gtk_widget_get_allocated_height (widget));
 
   return FALSE;
 }
diff --git a/lib/diainteractiverenderer.c b/lib/diainteractiverenderer.c
index 04197970..6d0976de 100644
--- a/lib/diainteractiverenderer.c
+++ b/lib/diainteractiverenderer.c
@@ -31,7 +31,7 @@ dia_interactive_renderer_iface_init (DiaInteractiveRendererInterface *iface)
   iface->draw_pixel_line = NULL;
   iface->draw_pixel_rect = NULL;
   iface->fill_pixel_rect = NULL;
-  iface->copy_to_window = NULL;
+  iface->paint = NULL;
   iface->set_size = NULL;
   iface->draw_object_highlighted = NULL;
 }
@@ -78,3 +78,17 @@ dia_renderer_set_size (DiaRenderer* renderer, gpointer window,
   irenderer->set_size (renderer, window, width, height);
 }
 
+void
+dia_interactive_renderer_paint (DiaRenderer *renderer,
+                                cairo_t     *ctx, 
+                                int          width,
+                                int          height)
+{
+  DiaInteractiveRendererInterface *irenderer =
+    DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);
+  
+  g_return_if_fail (irenderer != NULL);
+  g_return_if_fail (irenderer->paint != NULL);
+
+  irenderer->paint (renderer, ctx, width, height);
+}
\ No newline at end of file
diff --git a/lib/diarenderer.h b/lib/diarenderer.h
index 2a4fc6c2..1f94a434 100644
--- a/lib/diarenderer.h
+++ b/lib/diarenderer.h
@@ -304,10 +304,11 @@ struct _DiaInteractiveRendererInterface
   void (*fill_pixel_rect)      (DiaRenderer *renderer,
                                 int x, int y, int width, int height,
                                 GdkRGBA *color);
-  /*! Copy already rendered content to the given window */
-  void (*copy_to_window)      (DiaRenderer *renderer,
+  /*! Copy already rendered content to the given context */
+  void (*paint)               (DiaRenderer *renderer,
                                cairo_t     *ctx, 
-                               int x, int y, int width, int height);
+                               int          width,
+                               int          height);
   /*! Support for drawing selected objects highlighted */
   void (*draw_object_highlighted) (DiaRenderer *renderer,
                                   DiaObject *object,
@@ -315,6 +316,12 @@ struct _DiaInteractiveRendererInterface
 };
 
 GType dia_interactive_renderer_interface_get_type (void) G_GNUC_CONST;
+
+void dia_interactive_renderer_paint (DiaRenderer *renderer,
+                                     cairo_t     *ctx, 
+                                     int          width,
+                                     int          height);
+
 /*!
  * \brief Size adjustment to the given window
  * \memberof DiaInteractiveRendererInterface
diff --git a/lib/renderer/diacairo-interactive.c b/lib/renderer/diacairo-interactive.c
index f49a6404..242171f2 100644
--- a/lib/renderer/diacairo-interactive.c
+++ b/lib/renderer/diacairo-interactive.c
@@ -81,9 +81,10 @@ static void fill_pixel_rect(DiaRenderer *renderer,
 static void set_size (DiaRenderer *renderer, 
                       gpointer window,
                       int width, int height);
-static void copy_to_window (DiaRenderer *renderer, 
-                cairo_t *ctx,
-                int x, int y, int width, int height);
+static void paint        (DiaRenderer *renderer, 
+                          cairo_t     *ctx,
+                          int          width,
+                          int          height);
 
 static void cairo_interactive_renderer_get_property (GObject         *object,
                         guint            prop_id,
@@ -269,7 +270,7 @@ dia_cairo_interactive_renderer_iface_init (DiaInteractiveRendererInterface* ifac
   iface->draw_pixel_line = draw_pixel_line;
   iface->draw_pixel_rect = draw_pixel_rect;
   iface->fill_pixel_rect = fill_pixel_rect;
-  iface->copy_to_window = copy_to_window;
+  iface->paint = paint;
   iface->set_size = set_size;
   iface->draw_object_highlighted = draw_object_highlighted;
 }
@@ -460,16 +461,19 @@ set_size(DiaRenderer *object, gpointer window,
 }
 
 static void
-copy_to_window (DiaRenderer *object, cairo_t *ctx,
-                int x, int y, int width, int height)
+paint (DiaRenderer *object,
+       cairo_t     *ctx,
+       int          width,
+       int          height)
 {
   DiaCairoInteractiveRenderer *renderer = DIA_CAIRO_INTERACTIVE_RENDERER (object);
 
+  cairo_save (ctx);
   cairo_set_source_surface (ctx, renderer->pixmap, 0.0, 0.0);
-  cairo_rectangle (ctx, x, y, width > 0 ? width : -width, height > 0 ? height : -height);
+  cairo_rectangle (ctx, 0, 0, width > 0 ? width : -width, height > 0 ? height : -height);
   cairo_clip (ctx);
   cairo_paint (ctx);
-  cairo_destroy (ctx);
+  cairo_restore (ctx);
 }
 
 static void


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