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=706930
This commit is contained in:
parent
f1df49ad17
commit
57258dc1d4
@ -68,8 +68,6 @@ struct _MetaShapedTexturePrivate
|
||||
Pixmap pixmap;
|
||||
CoglTexturePixmapX11 *texture;
|
||||
CoglTexture *mask_texture;
|
||||
CoglPipeline *pipeline;
|
||||
CoglPipeline *pipeline_unshaped;
|
||||
|
||||
cairo_region_t *clip_region;
|
||||
|
||||
@ -118,8 +116,6 @@ meta_shaped_texture_dispose (GObject *object)
|
||||
meta_texture_tower_free (priv->paint_tower);
|
||||
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);
|
||||
|
||||
meta_shaped_texture_set_mask_texture (self, NULL);
|
||||
@ -128,6 +124,27 @@ meta_shaped_texture_dispose (GObject *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
|
||||
meta_shaped_texture_paint (ClutterActor *actor)
|
||||
{
|
||||
@ -136,10 +153,7 @@ meta_shaped_texture_paint (ClutterActor *actor)
|
||||
CoglTexture *paint_tex;
|
||||
guint tex_width, tex_height;
|
||||
ClutterActorBox alloc;
|
||||
|
||||
static CoglPipeline *pipeline_template = NULL;
|
||||
static CoglPipeline *pipeline_unshaped_template = NULL;
|
||||
|
||||
CoglContext *ctx;
|
||||
CoglPipeline *pipeline;
|
||||
|
||||
if (priv->clip_region && cairo_region_is_empty (priv->clip_region))
|
||||
@ -177,38 +191,15 @@ meta_shaped_texture_paint (ClutterActor *actor)
|
||||
if (tex_width == 0 || tex_height == 0) /* no contents yet */
|
||||
return;
|
||||
|
||||
ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
|
||||
|
||||
if (priv->mask_texture == NULL)
|
||||
{
|
||||
/* Use a single-layer texture if we don't have a mask. */
|
||||
|
||||
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;
|
||||
pipeline = get_unmasked_pipeline (ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (priv->pipeline == NULL)
|
||||
{
|
||||
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;
|
||||
|
||||
pipeline = get_masked_pipeline (ctx);
|
||||
cogl_pipeline_set_layer_texture (pipeline, 1, priv->mask_texture);
|
||||
}
|
||||
|
||||
@ -269,13 +260,16 @@ meta_shaped_texture_paint (ClutterActor *actor)
|
||||
&coords[0], 8);
|
||||
}
|
||||
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
cogl_rectangle (0, 0,
|
||||
alloc.x2 - alloc.x1,
|
||||
alloc.y2 - alloc.y1);
|
||||
|
||||
out:
|
||||
cogl_object_unref (pipeline);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -502,12 +496,6 @@ set_cogl_texture (MetaShapedTexture *stex,
|
||||
|
||||
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)
|
||||
{
|
||||
width = cogl_texture_get_width (COGL_TEXTURE (cogl_tex));
|
||||
|
Loading…
Reference in New Issue
Block a user