[gnome-photos/wip/baedert/gtkimageview: 9/10] Revert "geglimage; Pre-render to surface"



commit f57b5427f35826a75d539b3d78d12e91e37bf6de
Author: Timm Bäder <mail baedert org>
Date:   Fri Apr 15 19:39:57 2016 +0200

    Revert "geglimage; Pre-render to surface"
    
    This reverts commit 1b6d9369e88249061509c759a482c9700cff57e2.

 src/photos-gegl-image.c          |  162 ++++++++++++--------------------------
 src/photos-gegl-image.h          |    5 +-
 src/photos-preview-nav-buttons.c |    2 +-
 src/photos-tool-crop.c           |    4 +-
 4 files changed, 53 insertions(+), 120 deletions(-)
---
diff --git a/src/photos-gegl-image.c b/src/photos-gegl-image.c
index 8c9e875..cb3cab1 100644
--- a/src/photos-gegl-image.c
+++ b/src/photos-gegl-image.c
@@ -23,108 +23,70 @@ photos_gegl_image_get_scale_factor (GtkAbstractImage *_image)
 }
 
 static void
-photos_gegl_image_update_bbox (PhotosGeglImage *image)
+photos_gegl_image_render_surface (PhotosGeglImage *image)
 {
   GeglRectangle roi = image->roi;
-  GeglRectangle box = gegl_node_get_bounding_box (image->node);
-  gboolean bbox_changed = !gegl_rectangle_equal (&roi, &box);
 
-  image->width = box.width;
-  image->height = box.height;
+  roi.x *= image->view_scale;
+  roi.y *= image->view_scale;
 
-  image->roi = box;
-  g_message ("%s: New roi: %d, %d, %d, %d", __FUNCTION__, box.x, box.y, box.width, box.height);
+  gegl_node_blit (image->node,
+                  image->view_scale,
+                  &roi,
+                  image->format,
+                  image->buf,
+                  GEGL_AUTO_ROWSTRIDE,
+                  GEGL_BLIT_CACHE | GEGL_BLIT_DIRTY);
 
-  if (bbox_changed)
-    g_signal_emit_by_name (G_OBJECT (image), "changed", 0);
-}
+  /*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_render_surface (PhotosGeglImage *image)
+photos_gegl_image_update_bbox (PhotosGeglImage *image)
 {
-  int w, h;
-  GeglRectangle roi = image->roi;
   GeglRectangle box;
-  gboolean bbox_changed;
-  gboolean bbox_size_changed;
-  gboolean height_changed;
-  gboolean stride_changed = FALSE;
-  gboolean scale_changed = (image->view_scale != image->rendered_scale);
 
-  g_assert (image->node);
+  if (!image->node)
+    return;
 
   box = gegl_node_get_bounding_box (image->node);
 
-  bbox_changed = !gegl_rectangle_equal (&box, &image->roi);
-  bbox_size_changed = (box.width != image->width || box.height != image->height);
-  height_changed = (box.height != image->height);
+#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 (bbox_size_changed || scale_changed)
-    {
-      int new_stride;
+  /*if (image->width != box.width || image->height != box.height ||*/
+      /*image->roi.x != box.x     || image->roi.y != box.y)*/
+    /*{*/
       image->width  = box.width;
       image->height = box.height;
 
-      image->roi = box;
-      g_message ("%s: New roi: %d, %d, %d, %d", __FUNCTION__, box.x, box.y, box.width, box.height);
-      new_stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
-                                                  box.width * image->view_scale);
-      stride_changed = (image->stride != new_stride);
-      image->stride = new_stride;
-    }
-
-  roi = image->roi;
-
-  roi.x      *= image->view_scale;
-  roi.y      *= image->view_scale;
-  roi.width  *= image->view_scale;
-  roi.height *= image->view_scale;
+      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;
 
-  if (stride_changed || height_changed)
-    {
-      g_clear_pointer (&image->buf, g_free);
-      image->buf = g_malloc (image->stride * image->height); /* stride is already scaled */
-    }
 
-  if (scale_changed || bbox_changed)
-    {
-      g_message ("Blit");
-      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)
-    {
-      w = cairo_image_surface_get_width (image->surface);
-      h = cairo_image_surface_get_height (image->surface);
-    }
-  else
-    {
-      w = 0;
-      h = 0;
-    }
+      image->stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
+                                                     box.width * image->view_scale);
 
-  if (!image->surface ||
-      w != (image->width  * image->view_scale) ||
-      h != (image->height * image->view_scale))
-    {
-      g_message ("New surface");
-      g_clear_pointer (&image->surface, cairo_surface_destroy);
-      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_clear_pointer (&image->buf, g_free);
+      g_clear_pointer (&image->buf, cairo_surface_destroy);
 
-  image->rendered_scale = image->view_scale;
-  g_signal_emit_by_name (G_OBJECT (image), "changed", 0);
+      image->buf = g_malloc (image->stride * box.height); /* stride is already scaled */
+    /*}*/
 }
 
 static void
@@ -134,8 +96,7 @@ photos_gegl_image_draw (GtkAbstractImage *_image, cairo_t *ct)
 
   if (image->surface)
     {
-      cairo_scale (ct, 1.0 / image->rendered_scale, 1.0 / image->rendered_scale);
-      /*cairo_scale (ct, 1.0 / image->view_scale, 1.0 / image->view_scale);*/
+      cairo_scale (ct, 1.0 / image->view_scale, 1.0 / image->view_scale);
       cairo_set_source_surface (ct, image->surface, 0, 0);
     }
 }
@@ -143,9 +104,7 @@ photos_gegl_image_draw (GtkAbstractImage *_image, cairo_t *ct)
 static void
 photos_gegl_image_computed (PhotosGeglImage *image)
 {
-  static int i = -1;
-
-  g_message ("%s: %d", __FUNCTION__, ++i);
+  photos_gegl_image_update_bbox (image);
   photos_gegl_image_render_surface (image);
 }
 
@@ -160,6 +119,7 @@ photos_gegl_image_new (GeglNode *node, int scale_factor)
   image->scale_factor = scale_factor;
   image->format = babl_format ("cairo-ARGB32");
 
+  photos_gegl_image_update_bbox (image);
   photos_gegl_image_render_surface (image);
 
   return image;
@@ -170,7 +130,6 @@ photos_gegl_image_init (PhotosGeglImage *image)
 {
   image->surface = NULL;
   image->view_scale = 1.0;
-  image->rendered_scale = 1.0;
 }
 
 static void
@@ -178,8 +137,11 @@ photos_gegl_image_finalize (GObject *_image)
 {
   PhotosGeglImage *image = PHOTOS_GEGL_IMAGE (_image);
 
-  g_clear_pointer (&image->surface, cairo_surface_destroy);
-  g_clear_pointer (&image->buf, g_free);
+  if (image->surface)
+    cairo_surface_destroy (image->surface);
+
+  if (image->buf)
+    g_free (image->buf);
 
   G_OBJECT_CLASS (photos_gegl_image_parent_class)->finalize (_image);
 }
@@ -198,19 +160,6 @@ photos_gegl_image_class_init (PhotosGeglImageClass *klass)
   image_class->get_scale_factor = photos_gegl_image_get_scale_factor;
 }
 
-static gboolean
-redraw_cb (gpointer data)
-{
-  PhotosGeglImage *image = data;
-
-
-  if (G_LIKELY (image->node))
-    photos_gegl_image_render_surface (image);
-
-  image->redraw_id = 0;
-  return G_SOURCE_REMOVE;
-}
-
 void
 photos_gegl_image_set_view_scale (PhotosGeglImage *image, double view_scale)
 {
@@ -219,16 +168,5 @@ photos_gegl_image_set_view_scale (PhotosGeglImage *image, double view_scale)
 
   image->view_scale = view_scale;
 
-  if (!image->node)
-    return;
-
-  photos_gegl_image_update_bbox (image);
-
-  if (image->redraw_id != 0)
-    {
-      g_source_remove (image->redraw_id);
-      image->redraw_id = 0;
-    }
-
-  image->redraw_id = g_timeout_add (200, redraw_cb, image);
+  photos_gegl_image_render_surface (image);
 }
diff --git a/src/photos-gegl-image.h b/src/photos-gegl-image.h
index aafde0e..57c8e05 100644
--- a/src/photos-gegl-image.h
+++ b/src/photos-gegl-image.h
@@ -19,16 +19,13 @@ struct _PhotosGeglImage
   GeglNode *node;
   int width;
   int height;
+  double view_scale;
   cairo_surface_t *surface;
   guchar *buf;
   const Babl *format;
   GeglRectangle roi;
   int stride;
   int scale_factor;
-
-  double view_scale;
-  double rendered_scale;
-  guint redraw_id;
 };
 
 struct _PhotosGeglImageClass
diff --git a/src/photos-preview-nav-buttons.c b/src/photos-preview-nav-buttons.c
index 410175d..166e8d8 100644
--- a/src/photos-preview-nav-buttons.c
+++ b/src/photos-preview-nav-buttons.c
@@ -114,7 +114,7 @@ photos_preview_nav_buttons_fade_in_button (PhotosPreviewNavButtons *self, GtkWid
     return;
 
   gtk_widget_show_all (widget);
-  gtk_revealer_set_reveal_child (GTK_REVEALER (widget), FALSE);
+  gtk_revealer_set_reveal_child (GTK_REVEALER (widget), TRUE);
 }
 
 
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index 8fc7c18..7120e77 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -233,10 +233,8 @@ photos_tool_crop_surface_create (PhotosToolCrop *self)
 
   window = gtk_widget_get_window (self->view);
   zoom = photos_image_view_get_zoom (PHOTOS_IMAGE_VIEW (self->view));
-  g_message ("bbox_source: %d, %d (zoom: %f)", self->bbox_source.width, self->bbox_source.height, zoom);
-  /*zoom = 1.0;*/
-  self->bbox_zoomed.width = (gint) (zoom * self->bbox_source.width + 0.5);
   self->bbox_zoomed.height = (gint) (zoom * self->bbox_source.height + 0.5);
+  self->bbox_zoomed.width = (gint) (zoom * self->bbox_source.width + 0.5);
   self->surface = gdk_window_create_similar_surface (window,
                                                      CAIRO_CONTENT_COLOR_ALPHA,
                                                      self->bbox_zoomed.width,


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