shaped-texture: Simplify pipeline creation

Split out pipeline creation to a separate function so that we don't
have so much dense code in the paint function itself, and remove some
indentation levels.

Also, don't use our own template for the unmasked pipeline, since it
has nothing different from the default pipeline template.

We also don't store the pipelines anymore since their creation isn't
really helping us; we set the mask texture and paint texture on every
paint anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=707019
This commit is contained in:
Jasper St. Pierre 2013-08-27 16:03:42 -04:00
parent 2d35e07fae
commit 69f038f7c7

View File

@ -91,8 +91,6 @@ struct _MetaShapedTexturePrivate
CoglTexture *texture; CoglTexture *texture;
CoglTexture *mask_texture; CoglTexture *mask_texture;
CoglPipeline *pipeline;
CoglPipeline *pipeline_unshaped;
cairo_region_t *clip_region; cairo_region_t *clip_region;
cairo_region_t *input_shape_region; cairo_region_t *input_shape_region;
@ -145,8 +143,6 @@ meta_shaped_texture_dispose (GObject *object)
meta_texture_tower_free (priv->paint_tower); meta_texture_tower_free (priv->paint_tower);
priv->paint_tower = NULL; priv->paint_tower = NULL;
g_clear_pointer (&priv->pipeline, cogl_object_unref);
g_clear_pointer (&priv->pipeline_unshaped, cogl_object_unref);
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_pointer (&priv->texture, cogl_object_unref);
meta_shaped_texture_set_mask_texture (self, NULL); meta_shaped_texture_set_mask_texture (self, NULL);
@ -155,6 +151,27 @@ meta_shaped_texture_dispose (GObject *object)
G_OBJECT_CLASS (meta_shaped_texture_parent_class)->dispose (object); G_OBJECT_CLASS (meta_shaped_texture_parent_class)->dispose (object);
} }
static CoglPipeline *
get_unmasked_pipeline (CoglContext *ctx)
{
return cogl_pipeline_new (ctx);
}
static CoglPipeline *
get_masked_pipeline (CoglContext *ctx)
{
static CoglPipeline *template = NULL;
if (G_UNLIKELY (template == NULL))
{
template = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_combine (template, 1,
"RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
NULL);
}
return cogl_pipeline_copy (template);
}
static void static void
set_cogl_texture (MetaShapedTexture *stex, set_cogl_texture (MetaShapedTexture *stex,
CoglTexture *cogl_tex) CoglTexture *cogl_tex)
@ -171,12 +188,6 @@ set_cogl_texture (MetaShapedTexture *stex,
priv->texture = cogl_tex; priv->texture = cogl_tex;
if (priv->pipeline != NULL)
cogl_pipeline_set_layer_texture (priv->pipeline, 0, COGL_TEXTURE (cogl_tex));
if (priv->pipeline_unshaped != NULL)
cogl_pipeline_set_layer_texture (priv->pipeline_unshaped, 0, COGL_TEXTURE (cogl_tex));
if (cogl_tex != NULL) if (cogl_tex != NULL)
{ {
width = cogl_texture_get_width (COGL_TEXTURE (cogl_tex)); width = cogl_texture_get_width (COGL_TEXTURE (cogl_tex));
@ -213,10 +224,7 @@ meta_shaped_texture_paint (ClutterActor *actor)
CoglTexture *paint_tex; CoglTexture *paint_tex;
guint tex_width, tex_height; guint tex_width, tex_height;
ClutterActorBox alloc; ClutterActorBox alloc;
CoglContext *ctx;
static CoglPipeline *pipeline_template = NULL;
static CoglPipeline *pipeline_unshaped_template = NULL;
CoglPipeline *pipeline; CoglPipeline *pipeline;
if (priv->clip_region && cairo_region_is_empty (priv->clip_region)) if (priv->clip_region && cairo_region_is_empty (priv->clip_region))
@ -254,38 +262,15 @@ meta_shaped_texture_paint (ClutterActor *actor)
if (tex_width == 0 || tex_height == 0) /* no contents yet */ if (tex_width == 0 || tex_height == 0) /* no contents yet */
return; return;
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
if (priv->mask_texture == NULL) if (priv->mask_texture == NULL)
{ {
/* Use a single-layer texture if we don't have a mask. */ pipeline = get_unmasked_pipeline (ctx);
if (priv->pipeline_unshaped == NULL)
{
if (G_UNLIKELY (pipeline_unshaped_template == NULL))
{
CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
pipeline_unshaped_template = cogl_pipeline_new (ctx);
}
priv->pipeline_unshaped = cogl_pipeline_copy (pipeline_unshaped_template);
}
pipeline = priv->pipeline_unshaped;
} }
else else
{ {
if (priv->pipeline == NULL) pipeline = get_masked_pipeline (ctx);
{
if (G_UNLIKELY (pipeline_template == NULL))
{
CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
pipeline_template = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_combine (pipeline_template, 1,
"RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
NULL);
}
priv->pipeline = cogl_pipeline_copy (pipeline_template);
}
pipeline = priv->pipeline;
cogl_pipeline_set_layer_texture (pipeline, 1, priv->mask_texture); cogl_pipeline_set_layer_texture (pipeline, 1, priv->mask_texture);
} }
@ -346,13 +331,16 @@ meta_shaped_texture_paint (ClutterActor *actor)
&coords[0], 8); &coords[0], 8);
} }
return; goto out;
} }
} }
cogl_rectangle (0, 0, cogl_rectangle (0, 0,
alloc.x2 - alloc.x1, alloc.x2 - alloc.x1,
alloc.y2 - alloc.y1); alloc.y2 - alloc.y1);
out:
cogl_object_unref (pipeline);
} }
static void static void