From 2d6954186ed621deeb4c7cb575501861272b99d6 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 7 Aug 2014 12:38:42 -0400 Subject: [PATCH] background: Don't render with blending when we don't need to If we have an opaque background image, then we shouldn't need to blend against anything for it to work. Turn off blending in this case. --- src/compositor/meta-background.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c index 634a2deaf..22b3b8928 100644 --- a/src/compositor/meta-background.c +++ b/src/compositor/meta-background.c @@ -288,6 +288,26 @@ get_wrap_mode (MetaBackground *self) } } +static gboolean +texture_has_alpha (CoglTexture *texture) +{ + if (!texture) + return FALSE; + + switch (cogl_texture_get_components (texture)) + { + case COGL_TEXTURE_COMPONENTS_A: + case COGL_TEXTURE_COMPONENTS_RGBA: + return TRUE; + case COGL_TEXTURE_COMPONENTS_RG: + case COGL_TEXTURE_COMPONENTS_RGB: + case COGL_TEXTURE_COMPONENTS_DEPTH: + return FALSE; + default: + g_assert_not_reached (); + } +} + static ClutterPaintNode * meta_background_paint_node_new (MetaBackground *self, ClutterActor *actor) @@ -296,6 +316,7 @@ meta_background_paint_node_new (MetaBackground *self, ClutterPaintNode *node; guint8 opacity; guint8 color_component; + gboolean needs_blending; opacity = clutter_actor_get_paint_opacity (actor); color_component = (guint8) (0.5 + opacity * priv->brightness); @@ -308,6 +329,13 @@ meta_background_paint_node_new (MetaBackground *self, node = clutter_pipeline_node_new (priv->pipeline); + needs_blending = (opacity < 255) || (texture_has_alpha (priv->texture)); + + if (needs_blending) + cogl_pipeline_set_blend (priv->pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))", NULL); + else + cogl_pipeline_set_blend (priv->pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL); + return node; }