[gnome-photos/wip/baedert/gtkimageview: 34/39] blit in draw()



commit 7b8df557640223c2f6589e3766b07854018c4807
Author: Timm Bäder <mail baedert org>
Date:   Fri Apr 15 21:02:08 2016 +0200

    blit in draw()

 src/photos-gegl-image.c |  111 +++++++++++++++++++++--------------------------
 src/photos-gegl-image.h |    2 +-
 src/photos-image-view.c |    2 +-
 3 files changed, 51 insertions(+), 64 deletions(-)
---
diff --git a/src/photos-gegl-image.c b/src/photos-gegl-image.c
index cb3cab1..9c6e07f 100644
--- a/src/photos-gegl-image.c
+++ b/src/photos-gegl-image.c
@@ -23,70 +23,36 @@ photos_gegl_image_get_scale_factor (GtkAbstractImage *_image)
 }
 
 static void
-photos_gegl_image_render_surface (PhotosGeglImage *image)
+photos_gegl_image_update_bbox (PhotosGeglImage *image, gboolean scale_changed)
 {
-  GeglRectangle roi = image->roi;
+  GeglRectangle box    = gegl_node_get_bounding_box (image->node);
+  gboolean roi_changed = !gegl_rectangle_equal (&image->roi, &box);
 
-  roi.x *= image->view_scale;
-  roi.y *= image->view_scale;
-
-  gegl_node_blit (image->node,
-                  image->view_scale,
-                  &roi,
-                  image->format,
-                  image->buf,
-                  GEGL_AUTO_ROWSTRIDE,
-                  GEGL_BLIT_CACHE | GEGL_BLIT_DIRTY);
-
-  /*if (!image->surface)*/
-    /*{*/
-      image->surface = cairo_image_surface_create_for_data (image->buf,
-                                                            CAIRO_FORMAT_ARGB32,
-                                                            image->width * image->view_scale,
-                                                            image->height * image->view_scale,
-                                                            image->stride);
-    /*}*/
-
-  g_signal_emit_by_name (G_OBJECT (image), "changed", 0);
-}
-
-static void
-photos_gegl_image_update_bbox (PhotosGeglImage *image)
-{
-  GeglRectangle box;
-
-  if (!image->node)
-    return;
-
-  box = gegl_node_get_bounding_box (image->node);
-
-#if 0
-  g_message ("old size: %d, %d; new size: %d, %d", image->width, image->height,
-             box.width, box.height);
-  g_message ("bbox: %d, %d, %d, %d", box.x, box.y, box.width, box.height);
-#endif
-
-  /*if (image->width != box.width || image->height != box.height ||*/
-      /*image->roi.x != box.x     || image->roi.y != box.y)*/
-    /*{*/
+  if (roi_changed || scale_changed)
+    {
+      int stride;
       image->width  = box.width;
       image->height = box.height;
 
-      image->roi.x      = box.x;
-      image->roi.y      = box.y;
-      image->roi.width  = box.width  /* image->scale_factor */* image->view_scale;
-      image->roi.height = box.height /* image->scale_factor */* image->view_scale;
+      image->roi = box;
 
+      stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
+                                              box.width * image->view_scale);
 
+      g_clear_pointer (&image->buf, g_free);
+      g_clear_pointer (&image->surface, cairo_surface_destroy);
 
-      image->stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
-                                                     box.width * image->view_scale);
+      image->buf = g_malloc (stride * box.height); /* stride is already scaled */
+      image->surface = cairo_image_surface_create_for_data (image->buf,
+                                                            CAIRO_FORMAT_ARGB32,
+                                                            image->width * image->view_scale,
+                                                            image->height * image->view_scale,
+                                                            stride);
 
-      g_clear_pointer (&image->buf, g_free);
-      g_clear_pointer (&image->buf, cairo_surface_destroy);
+      image->need_blit = TRUE;
 
-      image->buf = g_malloc (image->stride * box.height); /* stride is already scaled */
-    /*}*/
+      g_signal_emit_by_name (G_OBJECT (image), "changed", 0);
+    }
 }
 
 static void
@@ -94,8 +60,28 @@ photos_gegl_image_draw (GtkAbstractImage *_image, cairo_t *ct)
 {
   PhotosGeglImage *image = PHOTOS_GEGL_IMAGE (_image);
 
-  if (image->surface)
+  if (G_LIKELY (image->surface))
     {
+      if (image->need_blit)
+        {
+          GeglRectangle roi = image->roi;
+          roi.x      *= image->view_scale;
+          roi.y      *= image->view_scale;
+          roi.width  *= image->view_scale;
+          roi.height *= image->view_scale;
+
+
+          gegl_node_blit (image->node,
+                          image->view_scale,
+                          &roi,
+                          image->format,
+                          image->buf,
+                          GEGL_AUTO_ROWSTRIDE,
+                          GEGL_BLIT_CACHE | GEGL_BLIT_DIRTY);
+
+          image->need_blit = FALSE;
+        }
+
       cairo_scale (ct, 1.0 / image->view_scale, 1.0 / image->view_scale);
       cairo_set_source_surface (ct, image->surface, 0, 0);
     }
@@ -104,8 +90,8 @@ photos_gegl_image_draw (GtkAbstractImage *_image, cairo_t *ct)
 static void
 photos_gegl_image_computed (PhotosGeglImage *image)
 {
-  photos_gegl_image_update_bbox (image);
-  photos_gegl_image_render_surface (image);
+  image->need_blit = TRUE;
+  photos_gegl_image_update_bbox (image, FALSE);
 }
 
 
@@ -118,9 +104,9 @@ photos_gegl_image_new (GeglNode *node, int scale_factor)
   image->node = node;
   image->scale_factor = scale_factor;
   image->format = babl_format ("cairo-ARGB32");
-
-  photos_gegl_image_update_bbox (image);
-  photos_gegl_image_render_surface (image);
+  image->roi = gegl_node_get_bounding_box (image->node);
+  image->width = image->roi.width;
+  image->height = image->roi.height;
 
   return image;
 }
@@ -129,7 +115,7 @@ static void
 photos_gegl_image_init (PhotosGeglImage *image)
 {
   image->surface = NULL;
-  image->view_scale = 1.0;
+  image->view_scale = 0.0;
 }
 
 static void
@@ -163,10 +149,11 @@ photos_gegl_image_class_init (PhotosGeglImageClass *klass)
 void
 photos_gegl_image_set_view_scale (PhotosGeglImage *image, double view_scale)
 {
+  g_message ("New scale: %f, old scale: %f", view_scale, image->view_scale);
   if (view_scale == image->view_scale)
     return;
 
   image->view_scale = view_scale;
 
-  photos_gegl_image_render_surface (image);
+  photos_gegl_image_update_bbox (image, TRUE);
 }
diff --git a/src/photos-gegl-image.h b/src/photos-gegl-image.h
index 57c8e05..68830b1 100644
--- a/src/photos-gegl-image.h
+++ b/src/photos-gegl-image.h
@@ -24,8 +24,8 @@ struct _PhotosGeglImage
   guchar *buf;
   const Babl *format;
   GeglRectangle roi;
-  int stride;
   int scale_factor;
+  gboolean need_blit;
 };
 
 struct _PhotosGeglImageClass
diff --git a/src/photos-image-view.c b/src/photos-image-view.c
index 7951987..ec1e808 100644
--- a/src/photos-image-view.c
+++ b/src/photos-image-view.c
@@ -247,7 +247,7 @@ photos_image_view_new (void)
 {
   return g_object_new (PHOTOS_TYPE_IMAGE_VIEW,
                        "fit-allocation", TRUE,
-                       /*"zoomable", FALSE,*/
+                       "zoomable", FALSE,
                        "rotatable", FALSE,
                        NULL);
 }


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