[clutter/wip/actor-content: 11/24] image: Add accessor for the Cogl texture handle



commit 7307642abe734666eedf10b3da64c755f2a15f1c
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Dec 20 14:51:02 2010 +0000

    image: Add accessor for the Cogl texture handle
    
    Allow retrieving the Cogl texture handle from the ClutterImage instance.

 clutter/clutter-image.c    |   37 +++++++++++++++++++++++++++++++++++++
 clutter/clutter-image.h    |    2 ++
 tests/conform/test-image.c |    5 ++++-
 3 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/clutter/clutter-image.c b/clutter/clutter-image.c
index 6e6bfbc..9a7fb0a 100644
--- a/clutter/clutter-image.c
+++ b/clutter/clutter-image.c
@@ -55,6 +55,7 @@ struct _ClutterImagePrivate
   gint image_height;
 
   CoglMaterial *material;
+  CoglHandle texture;
 };
 
 enum
@@ -110,6 +111,7 @@ clutter_image_dispose (GObject *gobject)
     {
       cogl_object_unref (priv->material);
       priv->material = NULL;
+      priv->texture = NULL;
     }
 
   G_OBJECT_CLASS (clutter_image_parent_class)->dispose (gobject);
@@ -346,6 +348,11 @@ clutter_image_load_from_data (ClutterImage     *image,
   cogl_material_set_layer (priv->material, 0, texture);
   cogl_handle_unref (texture);
 
+  if (priv->texture != COGL_INVALID_HANDLE)
+    cogl_handle_unref (priv->texture);
+
+  priv->texture = texture;
+
   g_object_freeze_notify (G_OBJECT (image));
 
   if (width != priv->image_width)
@@ -458,6 +465,11 @@ clutter_image_load (ClutterImage  *image,
 
   cogl_material_set_layer (priv->material, 0, texture);
 
+  if (priv->texture != COGL_INVALID_HANDLE)
+    cogl_handle_unref (priv->texture);
+
+  priv->texture = texture;
+
   g_object_freeze_notify (G_OBJECT (image));
 
   if (priv->image_width != old_image_width)
@@ -725,6 +737,11 @@ clutter_image_load_finish (ClutterImage  *image,
   texture = _clutter_image_loader_get_texture_handle (closure->loader);
   cogl_material_set_layer (priv->material, 0, texture);
 
+  if (priv->texture != COGL_INVALID_HANDLE)
+    cogl_handle_unref (priv->texture);
+
+  priv->texture = texture;
+
   g_object_freeze_notify (G_OBJECT (image));
 
   if (priv->image_width != old_image_width)
@@ -766,3 +783,23 @@ clutter_image_error_quark (void)
 {
   return g_quark_from_static_string ("clutter-image-error-quark");
 }
+
+/**
+ * clutter_image_get_cogl_texture:
+ * @image: a #ClutterImage
+ *
+ * Retrieves the pointer to the Cogl texture containing the data
+ * loaded by @image.
+ *
+ * Return value: (transfer none): a pointer to a Cogl texture handle,
+ *   or %NULL
+ *
+ * Since: 1.6
+ */
+CoglHandle
+clutter_image_get_cogl_texture (ClutterImage *image)
+{
+  g_return_val_if_fail (CLUTTER_IS_IMAGE (image), NULL);
+
+  return image->priv->texture;
+}
diff --git a/clutter/clutter-image.h b/clutter/clutter-image.h
index 53ecf79..bbe3f24 100644
--- a/clutter/clutter-image.h
+++ b/clutter/clutter-image.h
@@ -151,6 +151,8 @@ void            clutter_image_get_size          (ClutterImage         *image,
                                                  gint                 *width,
                                                  gint                 *height);
 
+CoglHandle      clutter_image_get_cogl_texture  (ClutterImage         *image);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_IMAGE_H__ */
diff --git a/tests/conform/test-image.c b/tests/conform/test-image.c
index 5a89b6c..a607a7c 100644
--- a/tests/conform/test-image.c
+++ b/tests/conform/test-image.c
@@ -29,6 +29,7 @@ image_sync_loading (void)
   g_assert (res);
   g_assert_cmpint (width, >, 0);
   g_assert_cmpint (height, >, 0);
+  g_assert (clutter_image_get_cogl_texture (image) != COGL_INVALID_HANDLE);
 
   g_object_unref (gfile);
   g_object_unref (image);
@@ -39,13 +40,14 @@ async_load_done_cb (GObject      *gobject,
                     GAsyncResult *result,
                     gpointer      user_data)
 {
+  ClutterImage *image = CLUTTER_IMAGE (gobject);
   GMainLoop *main_loop = user_data;
   GError *error = NULL;
   gint width, height;
   gboolean res;
 
   width = height = 0;
-  res = clutter_image_load_finish (CLUTTER_IMAGE (gobject), result,
+  res = clutter_image_load_finish (image, result,
                                    &width,
                                    &height,
                                    &error);
@@ -57,6 +59,7 @@ async_load_done_cb (GObject      *gobject,
   g_assert (error == NULL);
   g_assert_cmpint (width, >, 0);
   g_assert_cmpint (height, >, 0);
+  g_assert (clutter_image_get_cogl_texture (image) != COGL_INVALID_HANDLE);
 
   g_main_loop_quit (main_loop);
 }



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