From cf9dea7cf6e079a8897c7b0d92da030c88cb964f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 11 Dec 2008 15:48:43 +0000 Subject: [PATCH] Print a warning when creating a cairo_t while painting If you create a Cairo context in the middle of a paint run and then you destroy it, the CairoTexture will have to upload the contents of the image surface to the GL pipeline. This usually leads to slow downs and general performance degradation. ClutterCairoTexture will warn to the console if Clutter has been compiled with the debug messages and if create() or create_region() are called while an actor is in the middle of a paint. --- clutter/clutter-cairo-texture.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/clutter/clutter-cairo-texture.c b/clutter/clutter-cairo-texture.c index 42597ae0a..1aa15b75e 100644 --- a/clutter/clutter-cairo-texture.c +++ b/clutter/clutter-cairo-texture.c @@ -53,9 +53,10 @@ * cairo_destroy (cr); * ]| * - * Note that you should never use the code above inside the + * Note that you should never use the code above inside the * #ClutterActor::paint or #ClutterActor::pick virtual functions or - * signal handlers because of performance degradation. + * signal handlers because it will lead to performance + * degradation. * * Since #ClutterCairoTexture uses a Cairo image surface * internally all the drawing operations will be performed in @@ -88,6 +89,18 @@ enum PROP_SURFACE_HEIGHT }; +#ifdef CLUTTER_ENABLE_DEBUG +#define clutter_return_val_if_paint_fail(obj,retval) G_STMT_START { \ + if (CLUTTER_PRIVATE_FLAGS ((obj)) & CLUTTER_ACTOR_IN_PAINT) { \ + g_warning ("%s should not be called during the paint sequence " \ + "of a ClutterCairoTexture as it will likely cause " \ + "performance issues.", G_STRFUNC); \ + return (retval); \ + } } G_STMT_END +#else +#define clutter_return_val_if_paint_fail(obj,retval) /* void */ +#endif /* CLUTTER_ENABLE_DEBUG */ + #define CLUTTER_CAIRO_TEXTURE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_CAIRO_TEXTURE, ClutterCairoTexturePrivate)) struct _ClutterCairoTexturePrivate @@ -564,6 +577,7 @@ clutter_cairo_texture_create_region (ClutterCairoTexture *self, cairo_t *cr; g_return_val_if_fail (CLUTTER_IS_CAIRO_TEXTURE (self), NULL); + clutter_return_val_if_paint_fail (self, NULL); priv = self->priv; @@ -619,6 +633,7 @@ cairo_t * clutter_cairo_texture_create (ClutterCairoTexture *self) { g_return_val_if_fail (CLUTTER_IS_CAIRO_TEXTURE (self), NULL); + clutter_return_val_if_paint_fail (self, NULL); return clutter_cairo_texture_create_region (self, 0, 0, -1, -1); }