[clutter/wip/actor-content: 20/33] image: Allow deferring the material creation



commit dd4bb2b3a392fbf8d104f81607c6b35950daad5a
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Wed Dec 8 12:54:25 2010 +0000

    image: Allow deferring the material creation
    
    Sub-classes might have different requirements for the material creation,
    which means that the ClutterImage class should provide a way to ask the
    current implementation for the material that will be used as the source
    in the paint operation.

 clutter/clutter-image.c |   21 +++++++++++++++++++--
 clutter/clutter-image.h |    4 ++++
 2 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/clutter/clutter-image.c b/clutter/clutter-image.c
index dba61af..67cef2d 100644
--- a/clutter/clutter-image.c
+++ b/clutter/clutter-image.c
@@ -165,6 +165,12 @@ clutter_image_real_image_changed (ClutterImage *image)
   clutter_content_invalidate (CLUTTER_CONTENT (image));
 }
 
+static CoglMaterial *
+clutter_image_real_create_material (ClutterImage *image)
+{
+  return copy_template_material ();
+}
+
 static void
 clutter_image_get_property (GObject    *gobject,
                             guint       prop_id,
@@ -279,6 +285,7 @@ clutter_image_class_init (ClutterImageClass *klass)
 
   klass->size_changed = clutter_image_real_size_changed;
   klass->image_changed = clutter_image_real_image_changed;
+  klass->create_material = clutter_image_real_create_material;
 }
 
 static void
@@ -286,8 +293,6 @@ clutter_image_init (ClutterImage *image)
 {
   image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image, CLUTTER_TYPE_IMAGE,
                                              ClutterImagePrivate);
-
-  image->priv->material = copy_template_material ();
 }
 
 /**
@@ -381,6 +386,9 @@ clutter_image_load_from_data (ClutterImage     *image,
       return FALSE;
     }
 
+  if (priv->material == NULL)
+    priv->material = _clutter_image_create_material (image);
+
   cogl_material_set_layer (priv->material, 0, texture);
   cogl_handle_unref (texture);
 
@@ -499,6 +507,9 @@ clutter_image_load (ClutterImage  *image,
       return FALSE;
     }
 
+  if (priv->material == NULL)
+    priv->material = _clutter_image_create_material (image);
+
   cogl_material_set_layer (priv->material, 0, texture);
 
   if (priv->texture != COGL_INVALID_HANDLE)
@@ -771,6 +782,12 @@ clutter_image_load_finish (ClutterImage  *image,
                                         &priv->image_height);
 
   texture = _clutter_image_loader_get_texture_handle (closure->loader);
+  if (texture == NULL)
+    return FALSE;
+
+  if (priv->material == NULL)
+    priv->material = _clutter_image_create_material (image);
+
   cogl_material_set_layer (priv->material, 0, texture);
 
   if (priv->texture != COGL_INVALID_HANDLE)
diff --git a/clutter/clutter-image.h b/clutter/clutter-image.h
index bbe3f24..b8518eb 100644
--- a/clutter/clutter-image.h
+++ b/clutter/clutter-image.h
@@ -88,6 +88,8 @@ struct _ClutterImage
  * @size_changed: class handler for the #ClutterImage::size-changed signal
  * @image_changed: class handler for the #ClutterImage::image-changed
  *   signal
+ * @create_material: virtual functions for creating the material to be
+ *   painted
  *
  * The <structname>ClutterImageClass</structname> structure contains only
  * private data.
@@ -106,6 +108,8 @@ struct _ClutterImageClass
 
   void (* image_changed) (ClutterImage *image);
 
+  CoglMaterial *(* create_material) (ClutterImage *image);
+
   /*< private >*/
   void (* _clutter_image_padding1) (void);
   void (* _clutter_image_padding2) (void);



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