[clutter/wip/actor-content: 2/33] Add ClutterImage



commit bfbd2b6634015e3a0982aa74477884a6787f189f
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Dec 10 14:46:30 2010 +0000

    Add ClutterImage
    
    ClutterImage is an object that handles the image data loading from a
    buffer or from a resource, possibly asynchronously.

 clutter/Makefile.am     |    2 +
 clutter/clutter-image.c |  263 +++++++++++++++++++++++++++++++++++++++++++++++
 clutter/clutter-image.h |  120 +++++++++++++++++++++
 clutter/clutter.h       |    1 +
 4 files changed, 386 insertions(+), 0 deletions(-)
---
diff --git a/clutter/Makefile.am b/clutter/Makefile.am
index b207907..53e4ab6 100644
--- a/clutter/Makefile.am
+++ b/clutter/Makefile.am
@@ -97,6 +97,7 @@ source_h =					\
 	$(srcdir)/clutter-flow-layout.h		\
 	$(srcdir)/clutter-frame-source.h        \
 	$(srcdir)/clutter-group.h 		\
+	$(srcdir)/clutter-image.h		\
 	$(srcdir)/clutter-input-device.h	\
         $(srcdir)/clutter-interval.h            \
 	$(srcdir)/clutter-keysyms.h 		\
@@ -180,6 +181,7 @@ source_c = \
 	$(srcdir)/clutter-flow-layout.c		\
 	$(srcdir)/clutter-frame-source.c	\
 	$(srcdir)/clutter-group.c 		\
+	$(srcdir)/clutter-image.c		\
 	$(srcdir)/clutter-input-device.c	\
 	$(srcdir)/clutter-interval.c            \
 	$(srcdir)/clutter-keysyms-table.c	\
diff --git a/clutter/clutter-image.c b/clutter/clutter-image.c
new file mode 100644
index 0000000..b8ccd1d
--- /dev/null
+++ b/clutter/clutter-image.c
@@ -0,0 +1,263 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <cogl/cogl.h>
+
+#include "clutter-image.h"
+
+#include "clutter-debug.h"
+#include "clutter-marshal.h"
+#include "clutter-private.h"
+
+struct _ClutterImagePrivate
+{
+  gint image_width;
+  gint image_height;
+
+  CoglMaterial *material;
+};
+
+enum
+{
+  PROP_0,
+
+  PROP_WIDTH,
+  PROP_HEIGHT,
+
+  LAST_PROP
+};
+
+static GParamSpec *image_props[LAST_PROP] = { NULL, };
+
+enum
+{
+  SIZE_CHANGED,
+
+  LAST_SIGNAL
+};
+
+static guint image_signals[LAST_SIGNAL] = { 0, };
+
+static CoglMaterial *image_template_material = NULL;
+
+G_DEFINE_TYPE (ClutterImage, clutter_image, G_TYPE_OBJECT);
+
+static CoglMaterial *
+copy_template_material (void)
+{
+  if (G_UNLIKELY (image_template_material == NULL))
+    {
+      CoglHandle dummy_tex;
+
+      dummy_tex = cogl_texture_new_with_size (1, 1, COGL_TEXTURE_NO_SLICING,
+                                              COGL_PIXEL_FORMAT_RGBA_8888_PRE);
+
+      image_template_material = cogl_material_new ();
+      cogl_material_set_layer (image_template_material, 0, dummy_tex);
+      cogl_handle_unref (dummy_tex);
+    }
+
+  return cogl_material_copy (image_template_material);
+}
+
+static void
+clutter_image_dispose (GObject *gobject)
+{
+  ClutterImagePrivate *priv = CLUTTER_IMAGE (gobject)->priv;
+
+  if (priv->material != NULL)
+    {
+      cogl_object_unref (priv->material);
+      priv->material = NULL;
+    }
+
+  G_OBJECT_CLASS (clutter_image_parent_class)->dispose (gobject);
+}
+
+static void
+clutter_image_real_size_changed (ClutterImage *image,
+                                 gint          width,
+                                 gint          height)
+{
+}
+
+static void
+clutter_image_get_property (GObject    *gobject,
+                            guint       prop_id,
+                            GValue     *value,
+                            GParamSpec *pspec)
+{
+  ClutterImagePrivate *priv = CLUTTER_IMAGE (gobject)->priv;
+
+  switch (prop_id)
+    {
+    case PROP_WIDTH:
+      g_value_set_int (value, priv->image_width);
+      break;
+
+    case PROP_HEIGHT:
+      g_value_set_int (value, priv->image_height);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+    }
+}
+
+static void
+clutter_image_class_init (ClutterImageClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (ClutterImagePrivate));
+
+  image_props[PROP_WIDTH] =
+    g_param_spec_int ("width",
+                      P_("Width"),
+                      P_("The width of the image, in pixels"),
+                      0, G_MAXINT,
+                      0,
+                      CLUTTER_PARAM_READABLE);
+
+  image_props[PROP_HEIGHT] =
+    g_param_spec_int ("height",
+                      P_("Height"),
+                      P_("The height of the image, in pixels"),
+                      0, G_MAXINT,
+                      0,
+                      CLUTTER_PARAM_READABLE);
+
+  gobject_class->dispose = clutter_image_dispose;
+  gobject_class->get_property = clutter_image_get_property;
+  g_object_class_install_properties (gobject_class, LAST_PROP, image_props);
+
+  image_signals[SIZE_CHANGED] =
+    g_signal_new (I_("size-changed"),
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (ClutterImageClass, size_changed),
+                  NULL, NULL,
+                  _clutter_marshal_VOID__INT_INT,
+                  G_TYPE_NONE, 2,
+                  G_TYPE_INT,
+                  G_TYPE_INT);
+
+  klass->size_changed = clutter_image_real_size_changed;
+}
+
+static void
+clutter_image_init (ClutterImage *image)
+{
+  image->priv = G_TYPE_INSTANCE_GET_PRIVATE (image, CLUTTER_TYPE_IMAGE,
+                                             ClutterImagePrivate);
+
+  image->priv->material = copy_template_material ();
+}
+
+ClutterImage *
+clutter_image_new (void)
+{
+  return g_object_new (CLUTTER_TYPE_IMAGE, NULL);
+}
+
+void
+clutter_image_get_size (ClutterImage *image,
+                        gint         *width,
+                        gint         *height)
+{
+  g_return_if_fail (CLUTTER_IS_IMAGE (image));
+
+  if (width)
+    *width = image->priv->image_width;
+
+  if (height)
+    *height = image->priv->image_height;
+}
+
+gboolean
+clutter_image_load_from_data (ClutterImage     *image,
+                              const guchar     *data,
+                              CoglPixelFormat   format,
+                              gint              width,
+                              gint              height,
+                              gint              rowstride,
+                              gint              bpp,
+                              GError          **error)
+{
+  ClutterImagePrivate *priv;
+  CoglHandle texture;
+
+  g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (data != NULL, FALSE);
+
+  priv = image->priv;
+
+  texture = cogl_texture_new_from_data (width, height,
+                                        COGL_TEXTURE_NONE,
+                                        format,
+                                        COGL_PIXEL_FORMAT_ANY,
+                                        rowstride,
+                                        data);
+  if (texture == COGL_INVALID_HANDLE)
+    {
+      g_set_error (error, CLUTTER_IMAGE_ERROR,
+                   CLUTTER_IMAGE_ERROR_INVALID_DATA,
+                   _("Unable to load image data"));
+      return FALSE;
+    }
+
+  cogl_material_set_layer (priv->material, 0, texture);
+  cogl_handle_unref (texture);
+
+  return TRUE;
+}
+
+gboolean
+clutter_image_load (ClutterImage  *image,
+                    GFile         *gfile,
+                    GCancellable  *cancellable,
+                    gint          *width,
+                    gint          *height,
+                    GError       **error)
+{
+  g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (G_IS_FILE (gfile), FALSE);
+  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable),
+                        FALSE);
+
+
+  return TRUE;
+}
+
+void
+clutter_image_load_async (ClutterImage        *image,
+                          GFile               *gfile,
+                          GCancellable        *cancellable,
+                          GAsyncReadyCallback  callback,
+                          gpointer             user_data)
+{
+  g_return_if_fail (CLUTTER_IS_IMAGE (image));
+  g_return_if_fail (G_IS_FILE (gfile));
+  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+  g_return_if_fail (callback != NULL);
+}
+
+gboolean
+clutter_image_load_finish (ClutterImage  *image,
+                           GAsyncResult  *res,
+                           gint          *width,
+                           gint          *height,
+                           GError       **error)
+{
+  g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+
+  return TRUE;
+}
+
+GQuark
+clutter_image_error_quark (void)
+{
+  return g_quark_from_static_string ("clutter-image-error-quark");
+}
diff --git a/clutter/clutter-image.h b/clutter/clutter-image.h
new file mode 100644
index 0000000..4f5e061
--- /dev/null
+++ b/clutter/clutter-image.h
@@ -0,0 +1,120 @@
+#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
+#error "Only <clutter/clutter.h> can be included directly."
+#endif
+
+#ifndef __CLUTTER_IMAGE_H__
+#define __CLUTTER_IMAGE_H__
+
+#include <gio/gio.h>
+#include <cogl/cogl.h>
+#include <clutter/clutter-types.h>
+
+G_BEGIN_DECLS
+
+#define CLUTTER_TYPE_IMAGE              (clutter_image_get_type ())
+#define CLUTTER_IMAGE(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_IMAGE, ClutterImage))
+#define CLUTTER_IS_IMAGE(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_IMAGE))
+#define CLUTTER_IMAGE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_IMAGE, ClutterImageClass))
+#define CLUTTER_IS_IMAGE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_IMAGE))
+#define CLUTTER_IMAGE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_IMAGE, ClutterImageClass))
+
+#define CLUTTER_IMAGE_ERROR             (clutter_image_error_quark ())
+
+typedef struct _ClutterImage            ClutterImage;
+typedef struct _ClutterImagePrivate     ClutterImagePrivate;
+typedef struct _ClutterImageClass       ClutterImageClass;
+
+/**
+ * ClutterImageError:
+ * @CLUTTER_IMAGE_ERROR_INVALID_DATA: Unable to load the image data
+ *
+ * Error enumeration for #ClutterImage
+ *
+ * Since: 1.6
+ */
+typedef enum {
+  CLUTTER_IMAGE_ERROR_INVALID_DATA
+} ClutterImageError;
+
+/**
+ * ClutterImage:
+ *
+ * The <structname>ClutterImage</structname> structure contains only private
+ * data and should be accessed using the provided API.
+ *
+ * Since: 1.6
+ */
+struct _ClutterImage
+{
+  /*< private >*/
+  GObject parent_instance;
+
+  ClutterImagePrivate *priv;
+};
+
+/**
+ * ClutterImageClass:
+ * @size_changes: class handler for the #ClutterImage::size-changed signal
+ *
+ * The <structname>ClutterImageClass</structname> structure contains only
+ * private data.
+ *
+ * Since: 1.6
+ */
+struct _ClutterImageClass
+{
+  /*< private >*/
+  GObjectClass parent_class;
+
+  /*< public >*/
+  void (* size_changed) (ClutterImage *image,
+                         gint          new_width,
+                         gint          new_height);
+
+  void (* _clutter_image_padding1) (void);
+  void (* _clutter_image_padding2) (void);
+  void (* _clutter_image_padding3) (void);
+  void (* _clutter_image_padding4) (void);
+  void (* _clutter_image_padding5) (void);
+  void (* _clutter_image_padding6) (void);
+  void (* _clutter_image_padding7) (void);
+};
+
+GQuark clutter_image_error_quark (void);
+GType clutter_image_get_type (void) G_GNUC_CONST;
+
+ClutterImage *  clutter_image_new               (void);
+
+gboolean        clutter_image_load_from_data    (ClutterImage         *image,
+                                                 const guchar         *data,
+                                                 CoglPixelFormat       format,
+                                                 gint                  width,
+                                                 gint                  height,
+                                                 gint                  rowstride,
+                                                 gint                  bpp,
+                                                 GError              **error);
+
+gboolean        clutter_image_load              (ClutterImage         *image,
+                                                 GFile                *gfile,
+                                                 GCancellable         *cancellable,
+                                                 gint                 *width,
+                                                 gint                 *height,
+                                                 GError              **error);
+void            clutter_image_load_async        (ClutterImage         *image,
+                                                 GFile                *gfile,
+                                                 GCancellable         *cancellable,
+                                                 GAsyncReadyCallback   callback,
+                                                 gpointer              user_data);
+gboolean        clutter_image_load_finish       (ClutterImage         *image,
+                                                 GAsyncResult         *res,
+                                                 gint                 *width,
+                                                 gint                 *height,
+                                                 GError              **error);
+
+void            clutter_image_get_size          (ClutterImage         *image,
+                                                 gint                 *width,
+                                                 gint                 *height);
+
+G_END_DECLS
+
+#endif /* __CLUTTER_IMAGE_H__ */
diff --git a/clutter/clutter.h b/clutter/clutter.h
index 3729cf8..fae0766 100644
--- a/clutter/clutter.h
+++ b/clutter/clutter.h
@@ -74,6 +74,7 @@
 #include "clutter-flow-layout.h"
 #include "clutter-frame-source.h"
 #include "clutter-group.h"
+#include "clutter-image.h"
 #include "clutter-input-device.h"
 #include "clutter-interval.h"
 #include "clutter-keysyms.h" 



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