[gimp] app: in GimpOperationGradient, move cache generation back to process()



commit 38ba45cf31dde26b31809084b15f2e975dc142f7
Author: Ell <ell_se yahoo com>
Date:   Wed Apr 25 13:05:29 2018 -0400

    app: in GimpOperationGradient, move cache generation back to process()
    
    Undo the part of commit fa9a4108c3d4dc52ab73a2af49762832a4ccabc5
    that moved cache generation from process() to prepare().  prepare()
    is called after each property change, in order to calculate the
    op's bounding box for invalidation.  Since we only need the cache
    for actual processing, generating it in process() avoids that
    overhead.

 app/operations/gimpoperationgradient.c |   40 +++++++++++++++++++++++++++----
 app/operations/gimpoperationgradient.h |    1 +
 2 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/app/operations/gimpoperationgradient.c b/app/operations/gimpoperationgradient.c
index 0496fa7..7d6ca08 100644
--- a/app/operations/gimpoperationgradient.c
+++ b/app/operations/gimpoperationgradient.c
@@ -91,6 +91,7 @@ typedef struct
 /*  local function prototypes  */
 
 static void            gimp_operation_gradient_dispose           (GObject               *gobject);
+static void            gimp_operation_gradient_finalize          (GObject               *gobject);
 static void            gimp_operation_gradient_get_property      (GObject               *object,
                                                                   guint                  property_id,
                                                                   GValue                *value,
@@ -183,6 +184,7 @@ gimp_operation_gradient_class_init (GimpOperationGradientClass *klass)
   GeglOperationFilterClass *filter_class    = GEGL_OPERATION_FILTER_CLASS (klass);
 
   object_class->dispose             = gimp_operation_gradient_dispose;
+  object_class->finalize            = gimp_operation_gradient_finalize;
   object_class->set_property        = gimp_operation_gradient_set_property;
   object_class->get_property        = gimp_operation_gradient_get_property;
 
@@ -325,6 +327,7 @@ gimp_operation_gradient_class_init (GimpOperationGradientClass *klass)
 static void
 gimp_operation_gradient_init (GimpOperationGradient *self)
 {
+  g_mutex_init (&self->gradient_cache_mutex);
 }
 
 static void
@@ -341,6 +344,16 @@ gimp_operation_gradient_dispose (GObject *object)
 }
 
 static void
+gimp_operation_gradient_finalize (GObject *object)
+{
+  GimpOperationGradient *self = GIMP_OPERATION_GRADIENT (object);
+
+  g_mutex_clear (&self->gradient_cache_mutex);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
 gimp_operation_gradient_get_property (GObject    *object,
                                       guint       property_id,
                                       GValue     *value,
@@ -526,11 +539,7 @@ gimp_operation_gradient_set_property (GObject      *object,
 static void
 gimp_operation_gradient_prepare (GeglOperation *operation)
 {
-  GimpOperationGradient *self = GIMP_OPERATION_GRADIENT (operation);
-
   gegl_operation_set_format (operation, "output", babl_format ("R'G'B'A float"));
-
-  gimp_operation_gradient_validate_cache (self);
 }
 
 static GeglRectangle
@@ -1034,6 +1043,8 @@ gimp_operation_gradient_process (GeglOperation       *operation,
   if (! self->gradient)
     return TRUE;
 
+  gimp_operation_gradient_validate_cache (self);
+
   rbd.gradient            = self->gradient;
   rbd.reverse             = self->gradient_reverse;
   rbd.blend_color_space   = self->gradient_blend_color_space;
@@ -1203,9 +1214,18 @@ gimp_operation_gradient_validate_cache (GimpOperationGradient *self)
   gint                 cache_size;
   gint                 i;
 
-  if (! self->gradient || self->gradient_cache)
+  if (! self->gradient)
     return;
 
+  g_mutex_lock (&self->gradient_cache_mutex);
+
+  if (self->gradient_cache)
+    {
+      g_mutex_unlock (&self->gradient_cache_mutex);
+
+      return;
+    }
+
   switch (self->gradient_type)
     {
     case GIMP_GRADIENT_CONICAL_SYMMETRIC:
@@ -1213,6 +1233,8 @@ gimp_operation_gradient_validate_cache (GimpOperationGradient *self)
       /*  don't use a gradient cache for conical gradients, since the necessary
        *  cache size is not related to the line length
        */
+      g_mutex_unlock (&self->gradient_cache_mutex);
+
       return;
 
     default:
@@ -1228,7 +1250,11 @@ gimp_operation_gradient_validate_cache (GimpOperationGradient *self)
 
   /*  don't use a cache if its necessary size is too big  */
   if (cache_size > GRADIENT_CACHE_MAX_SIZE)
-    return;
+    {
+      g_mutex_unlock (&self->gradient_cache_mutex);
+
+      return;
+    }
 
   self->gradient_cache      = g_new0 (GimpRGB, cache_size);
   self->gradient_cache_size = cache_size;
@@ -1243,4 +1269,6 @@ gimp_operation_gradient_validate_cache (GimpOperationGradient *self)
                                              self->gradient_blend_color_space,
                                              self->gradient_cache + i);
     }
+
+  g_mutex_unlock (&self->gradient_cache_mutex);
 }
diff --git a/app/operations/gimpoperationgradient.h b/app/operations/gimpoperationgradient.h
index 008ed13..9cbbc99 100644
--- a/app/operations/gimpoperationgradient.h
+++ b/app/operations/gimpoperationgradient.h
@@ -58,6 +58,7 @@ struct _GimpOperationGradient
 
   GimpRGB                     *gradient_cache;
   gint                         gradient_cache_size;
+  GMutex                       gradient_cache_mutex;
 };
 
 struct _GimpOperationGradientClass


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