app: add GimpTileHandlerValidate::{begin,end}_validate() vfuncs

Add begin_validate() and end_validate() virtual functions, and
corresponding free functions, to GimpTileHandlerValidate.  These
functions are called before/after validation happens, and should
perform any necessary steps to prepare for validation.  The default
implementation suspends validation on tile access, so that the
assigned buffer may be accessed without causing validation.

Implement the new functions in GimpTileHandlerProjectable, by
calling gimp_projectable_begin_render() and
gimp_projectable_end_render(), respectively, instead of calling
these functions in the ::validate() implementation (which, in turn,
allows us to use the default ::validate() implementation.)

In GimpProjection, use the new functions in place of
gimp_projectable_{begin,end}_render().

(cherry picked from commit 5a623fc54b)
This commit is contained in:
Ell
2018-11-27 13:32:55 -05:00
parent 18815512f2
commit cc81f66f12
4 changed files with 94 additions and 45 deletions

View File

@ -678,11 +678,11 @@ gimp_projection_finish_draw (GimpProjection *proj)
{ {
gimp_projection_chunk_render_stop (proj); gimp_projection_chunk_render_stop (proj);
gimp_projectable_begin_render (proj->priv->projectable); gimp_tile_handler_validate_begin_validate (proj->priv->validate_handler);
while (gimp_projection_chunk_render_iteration (proj, FALSE)); while (gimp_projection_chunk_render_iteration (proj, FALSE));
gimp_projectable_end_render (proj->priv->projectable); gimp_tile_handler_validate_end_validate (proj->priv->validate_handler);
} }
} }
@ -854,7 +854,7 @@ gimp_projection_chunk_render_callback (gpointer data)
*/ */
chunk_render->n_pixels = 0; chunk_render->n_pixels = 0;
gimp_projectable_begin_render (proj->priv->projectable); gimp_tile_handler_validate_begin_validate (proj->priv->validate_handler);
do do
{ {
@ -871,7 +871,7 @@ gimp_projection_chunk_render_callback (gpointer data)
} }
while (g_timer_elapsed (timer, NULL) < GIMP_PROJECTION_CHUNK_TIME); while (g_timer_elapsed (timer, NULL) < GIMP_PROJECTION_CHUNK_TIME);
gimp_projectable_end_render (proj->priv->projectable); gimp_tile_handler_validate_end_validate (proj->priv->validate_handler);
/* adjust the target number of pixels to be processed on the next frame, /* adjust the target number of pixels to be processed on the next frame,
* according to the number of pixels processed during this frame and the * according to the number of pixels processed during this frame and the

View File

@ -27,11 +27,8 @@
#include "gimptilehandlerprojectable.h" #include "gimptilehandlerprojectable.h"
static void gimp_tile_handler_projectable_validate (GimpTileHandlerValidate *validate, static void gimp_tile_handler_projectable_begin_validate (GimpTileHandlerValidate *validate);
const GeglRectangle *rect, static void gimp_tile_handler_projectable_end_validate (GimpTileHandlerValidate *validate);
const Babl *format,
gpointer dest_buf,
gint dest_stride);
G_DEFINE_TYPE (GimpTileHandlerProjectable, gimp_tile_handler_projectable, G_DEFINE_TYPE (GimpTileHandlerProjectable, gimp_tile_handler_projectable,
@ -47,7 +44,8 @@ gimp_tile_handler_projectable_class_init (GimpTileHandlerProjectableClass *klass
validate_class = GIMP_TILE_HANDLER_VALIDATE_CLASS (klass); validate_class = GIMP_TILE_HANDLER_VALIDATE_CLASS (klass);
validate_class->validate = gimp_tile_handler_projectable_validate; validate_class->begin_validate = gimp_tile_handler_projectable_begin_validate;
validate_class->end_validate = gimp_tile_handler_projectable_end_validate;
} }
static void static void
@ -56,24 +54,23 @@ gimp_tile_handler_projectable_init (GimpTileHandlerProjectable *projectable)
} }
static void static void
gimp_tile_handler_projectable_validate (GimpTileHandlerValidate *validate, gimp_tile_handler_projectable_begin_validate (GimpTileHandlerValidate *validate)
const GeglRectangle *rect,
const Babl *format,
gpointer dest_buf,
gint dest_stride)
{ {
GimpTileHandlerProjectable *handler = GIMP_TILE_HANDLER_PROJECTABLE (validate); GimpTileHandlerProjectable *handler = GIMP_TILE_HANDLER_PROJECTABLE (validate);
GeglNode *graph;
graph = gimp_projectable_get_graph (handler->projectable); GIMP_TILE_HANDLER_VALIDATE_CLASS (parent_class)->begin_validate (validate);
gimp_projectable_begin_render (handler->projectable); gimp_projectable_begin_render (handler->projectable);
}
gegl_node_blit (graph, 1.0, rect, format, static void
dest_buf, dest_stride, gimp_tile_handler_projectable_end_validate (GimpTileHandlerValidate *validate)
GEGL_BLIT_DEFAULT); {
GimpTileHandlerProjectable *handler = GIMP_TILE_HANDLER_PROJECTABLE (validate);
gimp_projectable_end_render (handler->projectable); gimp_projectable_end_render (handler->projectable);
GIMP_TILE_HANDLER_VALIDATE_CLASS (parent_class)->end_validate (validate);
} }
GeglTileHandler * GeglTileHandler *
@ -85,6 +82,9 @@ gimp_tile_handler_projectable_new (GimpProjectable *projectable)
handler = g_object_new (GIMP_TYPE_TILE_HANDLER_PROJECTABLE, NULL); handler = g_object_new (GIMP_TYPE_TILE_HANDLER_PROJECTABLE, NULL);
GIMP_TILE_HANDLER_VALIDATE (handler)->graph =
g_object_ref (gimp_projectable_get_graph (projectable));
handler->projectable = projectable; handler->projectable = projectable;
return GEGL_TILE_HANDLER (handler); return GEGL_TILE_HANDLER (handler);

View File

@ -35,28 +35,30 @@ enum
}; };
static void gimp_tile_handler_validate_finalize (GObject *object); static void gimp_tile_handler_validate_finalize (GObject *object);
static void gimp_tile_handler_validate_set_property (GObject *object, static void gimp_tile_handler_validate_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_tile_handler_validate_get_property (GObject *object, static void gimp_tile_handler_validate_get_property (GObject *object,
guint property_id, guint property_id,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_tile_handler_validate_real_validate (GimpTileHandlerValidate *validate, static void gimp_tile_handler_validate_real_begin_validate (GimpTileHandlerValidate *validate);
const GeglRectangle *rect, static void gimp_tile_handler_validate_real_end_validate (GimpTileHandlerValidate *validate);
const Babl *format, static void gimp_tile_handler_validate_real_validate (GimpTileHandlerValidate *validate,
gpointer dest_buf, const GeglRectangle *rect,
gint dest_stride); const Babl *format,
gpointer dest_buf,
gint dest_stride);
static gpointer gimp_tile_handler_validate_command (GeglTileSource *source, static gpointer gimp_tile_handler_validate_command (GeglTileSource *source,
GeglTileCommand command, GeglTileCommand command,
gint x, gint x,
gint y, gint y,
gint z, gint z,
gpointer data); gpointer data);
G_DEFINE_TYPE (GimpTileHandlerValidate, gimp_tile_handler_validate, G_DEFINE_TYPE (GimpTileHandlerValidate, gimp_tile_handler_validate,
@ -74,6 +76,8 @@ gimp_tile_handler_validate_class_init (GimpTileHandlerValidateClass *klass)
object_class->set_property = gimp_tile_handler_validate_set_property; object_class->set_property = gimp_tile_handler_validate_set_property;
object_class->get_property = gimp_tile_handler_validate_get_property; object_class->get_property = gimp_tile_handler_validate_get_property;
klass->begin_validate = gimp_tile_handler_validate_real_begin_validate;
klass->end_validate = gimp_tile_handler_validate_real_end_validate;
klass->validate = gimp_tile_handler_validate_real_validate; klass->validate = gimp_tile_handler_validate_real_validate;
g_object_class_install_property (object_class, PROP_FORMAT, g_object_class_install_property (object_class, PROP_FORMAT,
@ -178,6 +182,18 @@ gimp_tile_handler_validate_get_property (GObject *object,
} }
} }
static void
gimp_tile_handler_validate_real_begin_validate (GimpTileHandlerValidate *validate)
{
validate->suspend_validate++;
}
static void
gimp_tile_handler_validate_real_end_validate (GimpTileHandlerValidate *validate)
{
validate->suspend_validate--;
}
static void static void
gimp_tile_handler_validate_real_validate (GimpTileHandlerValidate *validate, gimp_tile_handler_validate_real_validate (GimpTileHandlerValidate *validate,
const GeglRectangle *rect, const GeglRectangle *rect,
@ -235,6 +251,8 @@ gimp_tile_handler_validate_validate (GeglTileSource *source,
tile_bpp = babl_format_get_bytes_per_pixel (validate->format); tile_bpp = babl_format_get_bytes_per_pixel (validate->format);
tile_stride = tile_bpp * validate->tile_width; tile_stride = tile_bpp * validate->tile_width;
gimp_tile_handler_validate_begin_validate (validate);
gegl_tile_lock (tile); gegl_tile_lock (tile);
GIMP_TILE_HANDLER_VALIDATE_GET_CLASS (validate)->validate GIMP_TILE_HANDLER_VALIDATE_GET_CLASS (validate)->validate
@ -248,6 +266,8 @@ gimp_tile_handler_validate_validate (GeglTileSource *source,
tile_stride); tile_stride);
gegl_tile_unlock (tile); gegl_tile_unlock (tile);
gimp_tile_handler_validate_end_validate (validate);
} }
} }
else else
@ -277,6 +297,8 @@ gimp_tile_handler_validate_validate (GeglTileSource *source,
0, tile_stride * validate->tile_height); 0, tile_stride * validate->tile_height);
} }
gimp_tile_handler_validate_begin_validate (validate);
gegl_tile_lock (tile); gegl_tile_lock (tile);
n_rects = cairo_region_num_rectangles (tile_region); n_rects = cairo_region_num_rectangles (tile_region);
@ -305,6 +327,8 @@ gimp_tile_handler_validate_validate (GeglTileSource *source,
} }
gegl_tile_unlock (tile); gegl_tile_unlock (tile);
gimp_tile_handler_validate_end_validate (validate);
} }
cairo_region_destroy (tile_region); cairo_region_destroy (tile_region);
@ -415,6 +439,25 @@ gimp_tile_handler_validate_undo_invalidate (GimpTileHandlerValidate *validate,
(cairo_rectangle_int_t *) rect); (cairo_rectangle_int_t *) rect);
} }
void
gimp_tile_handler_validate_begin_validate (GimpTileHandlerValidate *validate)
{
g_return_if_fail (GIMP_IS_TILE_HANDLER_VALIDATE (validate));
if (validate->validating++ == 0)
GIMP_TILE_HANDLER_VALIDATE_GET_CLASS (validate)->begin_validate (validate);
}
void
gimp_tile_handler_validate_end_validate (GimpTileHandlerValidate *validate)
{
g_return_if_fail (GIMP_IS_TILE_HANDLER_VALIDATE (validate));
g_return_if_fail (validate->validating > 0);
if (--validate->validating == 0)
GIMP_TILE_HANDLER_VALIDATE_GET_CLASS (validate)->end_validate (validate);
}
void void
gimp_tile_handler_validate_buffer_copy (GeglBuffer *src_buffer, gimp_tile_handler_validate_buffer_copy (GeglBuffer *src_buffer,
const GeglRectangle *src_rect, const GeglRectangle *src_rect,

View File

@ -48,6 +48,7 @@ struct _GimpTileHandlerValidate
gint tile_width; gint tile_width;
gint tile_height; gint tile_height;
gboolean whole_tile; gboolean whole_tile;
gint validating;
gint suspend_validate; gint suspend_validate;
}; };
@ -55,11 +56,13 @@ struct _GimpTileHandlerValidateClass
{ {
GeglTileHandlerClass parent_class; GeglTileHandlerClass parent_class;
void (* validate) (GimpTileHandlerValidate *validate, void (* begin_validate) (GimpTileHandlerValidate *validate);
const GeglRectangle *rect, void (* end_validate) (GimpTileHandlerValidate *validate);
const Babl *format, void (* validate) (GimpTileHandlerValidate *validate,
gpointer dest_buf, const GeglRectangle *rect,
gint dest_stride); const Babl *format,
gpointer dest_buf,
gint dest_stride);
}; };
@ -78,6 +81,9 @@ void gimp_tile_handler_validate_invalidate (GimpTileHa
void gimp_tile_handler_validate_undo_invalidate (GimpTileHandlerValidate *validate, void gimp_tile_handler_validate_undo_invalidate (GimpTileHandlerValidate *validate,
const GeglRectangle *rect); const GeglRectangle *rect);
void gimp_tile_handler_validate_begin_validate (GimpTileHandlerValidate *validate);
void gimp_tile_handler_validate_end_validate (GimpTileHandlerValidate *validate);
void gimp_tile_handler_validate_buffer_copy (GeglBuffer *src_buffer, void gimp_tile_handler_validate_buffer_copy (GeglBuffer *src_buffer,
const GeglRectangle *src_rect, const GeglRectangle *src_rect,
GeglBuffer *dst_buffer, GeglBuffer *dst_buffer,