[mutter/wip/wayland] meta-shaped-texture: Fix the pick material



commit 5ea7aa65cd2ba53cd12d7b5b5b8cafde99202755
Author: Neil Roberts <neil linux intel com>
Date:   Wed Jan 11 18:30:35 2012 +0000

    meta-shaped-texture: Fix the pick material
    
    The picking code for MetaShapedTexture was trying to combine the mask
    texture with a color by first calling cogl_set_source_color4ub and
    then calling cogl_set_source_texture. This doesn't do the right thing
    because the second call to set the source just replaces the previous
    color source instead of combining it. This patch changes it to create
    a new pick material with a special combine mode to multiply the alpha
    component of the mask texture with the primary color of the
    material. It uses a pick template material in the same way as the
    paint template material.
    
    The patch also renames priv->material and priv->material_unshaped to
    priv->paint_material and priv->paint_material_unshaped to avoid
    confusion about what the materials are used for.

 src/compositor/meta-shaped-texture.c |   93 +++++++++++++++++++++++-----------
 1 files changed, 63 insertions(+), 30 deletions(-)
---
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index e79c2c5..8f448b4 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -76,8 +76,9 @@ struct _MetaShapedTexturePrivate
 {
   MetaTextureTower *paint_tower;
   CoglHandle mask_texture;
-  CoglHandle material;
-  CoglHandle material_unshaped;
+  CoglHandle paint_material;
+  CoglHandle paint_material_unshaped;
+  CoglHandle pick_material;
 
   cairo_region_t *clip_region;
   cairo_region_t *shape_region;
@@ -146,15 +147,20 @@ meta_shaped_texture_dispose (GObject *object)
 
   meta_shaped_texture_dirty_mask (self);
 
-  if (priv->material != COGL_INVALID_HANDLE)
+  if (priv->paint_material != COGL_INVALID_HANDLE)
+    {
+      cogl_handle_unref (priv->paint_material);
+      priv->paint_material = COGL_INVALID_HANDLE;
+    }
+  if (priv->paint_material_unshaped != COGL_INVALID_HANDLE)
     {
-      cogl_handle_unref (priv->material);
-      priv->material = COGL_INVALID_HANDLE;
+      cogl_handle_unref (priv->paint_material_unshaped);
+      priv->paint_material_unshaped = COGL_INVALID_HANDLE;
     }
-  if (priv->material_unshaped != COGL_INVALID_HANDLE)
+  if (priv->pick_material != COGL_INVALID_HANDLE)
     {
-      cogl_handle_unref (priv->material_unshaped);
-      priv->material_unshaped = COGL_INVALID_HANDLE;
+      cogl_handle_unref (priv->pick_material);
+      priv->pick_material = COGL_INVALID_HANDLE;
     }
 
   meta_shaped_texture_set_shape_region (self, NULL);
@@ -213,8 +219,11 @@ meta_shaped_texture_dirty_mask (MetaShapedTexture *stex)
           priv->mask_texture = COGL_INVALID_HANDLE;
         }
 
-      if (priv->material != COGL_INVALID_HANDLE)
-        cogl_material_set_layer (priv->material, 1, COGL_INVALID_HANDLE);
+      if (priv->paint_material != COGL_INVALID_HANDLE)
+        cogl_material_set_layer (priv->paint_material, 1, COGL_INVALID_HANDLE);
+
+      if (priv->pick_material != COGL_INVALID_HANDLE)
+        cogl_material_set_layer (priv->pick_material, 0, COGL_INVALID_HANDLE);
     }
 }
 
@@ -458,8 +467,8 @@ meta_shaped_texture_paint (ClutterActor *actor)
   guint tex_width, tex_height;
   ClutterActorBox alloc;
 
-  static CoglHandle material_template = COGL_INVALID_HANDLE;
-  static CoglHandle material_unshaped_template = COGL_INVALID_HANDLE;
+  static CoglHandle paint_material_template = COGL_INVALID_HANDLE;
+  static CoglHandle paint_material_unshaped_template = COGL_INVALID_HANDLE;
 
   CoglHandle material;
 
@@ -506,31 +515,33 @@ meta_shaped_texture_paint (ClutterActor *actor)
     {
       /* No region means an unclipped shape. Use a single-layer texture. */
 
-      if (priv->material_unshaped == COGL_INVALID_HANDLE) 
+      if (priv->paint_material_unshaped == COGL_INVALID_HANDLE)
         {
-          if (G_UNLIKELY (material_unshaped_template == COGL_INVALID_HANDLE))
-            material_unshaped_template = cogl_material_new ();
+          if (G_UNLIKELY (paint_material_unshaped_template ==
+                          COGL_INVALID_HANDLE))
+            paint_material_unshaped_template = cogl_material_new ();
 
-          priv->material_unshaped = cogl_material_copy (material_unshaped_template);
+          priv->paint_material_unshaped =
+            cogl_material_copy (paint_material_unshaped_template);
         }
-        material = priv->material_unshaped;
+        material = priv->paint_material_unshaped;
     }
   else
     {
       meta_shaped_texture_ensure_mask (stex);
 
-      if (priv->material == COGL_INVALID_HANDLE)
+      if (priv->paint_material == COGL_INVALID_HANDLE)
 	{
-	   if (G_UNLIKELY (material_template == COGL_INVALID_HANDLE))
+	   if (G_UNLIKELY (paint_material_template == COGL_INVALID_HANDLE))
 	    {
-	      material_template =  cogl_material_new ();
-	      cogl_material_set_layer_combine (material_template, 1,
+	      paint_material_template = cogl_material_new ();
+	      cogl_material_set_layer_combine (paint_material_template, 1,
 					   "RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
 					   NULL);
 	    }
-	  priv->material = cogl_material_copy (material_template);
+	  priv->paint_material = cogl_material_copy (paint_material_template);
 	}
-      material = priv->material;
+      material = priv->paint_material;
 
       cogl_material_set_layer (material, 1, priv->mask_texture);
     }
@@ -632,13 +643,34 @@ meta_shaped_texture_pick (ClutterActor       *actor,
 
       meta_shaped_texture_ensure_mask (stex);
 
-      cogl_set_source_color4ub (color->red, color->green, color->blue,
-                                 color->alpha);
+      if (priv->pick_material == COGL_INVALID_HANDLE)
+        {
+          static CoglHandle pick_material_template = COGL_INVALID_HANDLE;
+
+          if (G_UNLIKELY (pick_material_template == COGL_INVALID_HANDLE))
+            {
+              pick_material_template = cogl_material_new ();
+              cogl_material_set_layer_combine
+                (pick_material_template, 0,
+                 "RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
+                 NULL);
+            }
+
+          priv->pick_material = cogl_material_copy (pick_material_template);
+        }
+
+      cogl_material_set_layer (priv->pick_material, 0, priv->mask_texture);
+
+      cogl_material_set_color4ub (priv->pick_material,
+                                  color->red,
+                                  color->green,
+                                  color->blue,
+                                  color->alpha);
 
       clutter_actor_get_allocation_box (actor, &alloc);
 
       /* Paint the mask rectangle in the given color */
-      cogl_set_source_texture (priv->mask_texture);
+      cogl_set_source (priv->pick_material);
       cogl_rectangle_with_texture_coords (0, 0,
                                           alloc.x2 - alloc.x1,
                                           alloc.y2 - alloc.y1,
@@ -773,11 +805,12 @@ meta_shaped_texture_clear (MetaShapedTexture *stex)
 
   meta_texture_tower_set_base_texture (priv->paint_tower, COGL_INVALID_HANDLE);
 
-  if (priv->material != COGL_INVALID_HANDLE)
-    cogl_material_set_layer (priv->material, 0, COGL_INVALID_HANDLE);
+  if (priv->paint_material != COGL_INVALID_HANDLE)
+    cogl_material_set_layer (priv->paint_material, 0, COGL_INVALID_HANDLE);
 
-  if (priv->material_unshaped != COGL_INVALID_HANDLE)
-    cogl_material_set_layer (priv->material_unshaped, 0, COGL_INVALID_HANDLE);
+  if (priv->paint_material_unshaped != COGL_INVALID_HANDLE)
+    cogl_material_set_layer (priv->paint_material_unshaped,
+                             0, COGL_INVALID_HANDLE);
 }
 
 void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]