[clutter/wip/apocalypses/apocalypse-3: 20/35] Add ClutterImage, and image data content



commit ab3659faee8d497a3939f95efbf2fa817d99ef5c
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Thu Mar 8 16:38:45 2012 +0000

    Add ClutterImage, and image data content

 clutter/Makefile.am     |    2 +
 clutter/clutter-image.c |  190 +++++++++++++++++++++++++++++++++++++++++++++++
 clutter/clutter-image.h |  101 +++++++++++++++++++++++++
 clutter/clutter.h       |    1 +
 4 files changed, 294 insertions(+), 0 deletions(-)
---
diff --git a/clutter/Makefile.am b/clutter/Makefile.am
index 7f65b97..0b46680 100644
--- a/clutter/Makefile.am
+++ b/clutter/Makefile.am
@@ -90,6 +90,7 @@ source_h =					\
 	$(srcdir)/clutter-flow-layout.h		\
 	$(srcdir)/clutter-gesture-action.h 	\
 	$(srcdir)/clutter-group.h 		\
+	$(srcdir)/clutter-image.h		\
 	$(srcdir)/clutter-input-device.h	\
         $(srcdir)/clutter-interval.h            \
 	$(srcdir)/clutter-keysyms.h 		\
@@ -167,6 +168,7 @@ source_c = \
 	$(srcdir)/clutter-flatten-effect.c	\
 	$(srcdir)/clutter-flow-layout.c		\
 	$(srcdir)/clutter-gesture-action.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..2f49f7a
--- /dev/null
+++ b/clutter/clutter-image.c
@@ -0,0 +1,190 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive image' library.
+ *
+ * Copyright (C) 2012  Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *   Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "clutter-image.h"
+
+#include "clutter-color.h"
+#include "clutter-content-private.h"
+#include "clutter-debug.h"
+#include "clutter-paint-node.h"
+#include "clutter-paint-nodes.h"
+#include "clutter-private.h"
+
+struct _ClutterImagePrivate
+{
+  CoglTexture *texture;
+};
+
+static void clutter_content_iface_init (ClutterContentIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ClutterImage, clutter_image, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTENT,
+                                                clutter_content_iface_init))
+
+GQuark
+clutter_image_error_quark (void)
+{
+  return g_quark_from_static_string ("clutter-image-error-quark");
+}
+
+static void
+clutter_image_finalize (GObject *gobject)
+{
+  ClutterImagePrivate *priv = CLUTTER_IMAGE (gobject)->priv;
+
+  if (priv->texture != NULL)
+    {
+      cogl_object_unref (priv->texture);
+      priv->texture = NULL;
+    }
+
+  G_OBJECT_CLASS (clutter_image_parent_class)->finalize (gobject);
+}
+
+static void
+clutter_image_class_init (ClutterImageClass *klass)
+{
+  g_type_class_add_private (klass, sizeof (ClutterImagePrivate));
+
+  G_OBJECT_CLASS (klass)->finalize = clutter_image_finalize;
+}
+
+static void
+clutter_image_init (ClutterImage *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, CLUTTER_TYPE_IMAGE,
+                                            ClutterImagePrivate);
+}
+
+static void
+clutter_image_paint_content (ClutterContent   *content,
+                             ClutterActor     *actor,
+                             ClutterPaintNode *root)
+{
+  ClutterImagePrivate *priv = CLUTTER_IMAGE (content)->priv;
+  ClutterPaintNode *node;
+  ClutterActorBox box;
+  ClutterColor color;
+  guint8 paint_opacity;
+
+  if (priv->texture == NULL)
+    return;
+
+  clutter_actor_get_content_box (actor, &box);
+  paint_opacity = clutter_actor_get_paint_opacity (actor);
+
+  color.red = paint_opacity;
+  color.green = paint_opacity;
+  color.blue = paint_opacity;
+  color.alpha = paint_opacity;
+
+  node = clutter_texture_node_new (priv->texture, &color);
+  clutter_paint_node_set_name (node, "Image");
+  clutter_paint_node_add_rectangle (node, &box);
+  clutter_paint_node_add_child (root, node);
+  clutter_paint_node_unref (node);
+}
+
+static gboolean
+clutter_image_get_preferred_size (ClutterContent *content,
+                                  gfloat         *width,
+                                  gfloat         *height)
+{
+  ClutterImagePrivate *priv = CLUTTER_IMAGE (content)->priv;
+
+  if (priv->texture == NULL)
+    return FALSE;
+
+  if (width != NULL)
+    *width = cogl_texture_get_width (priv->texture);
+
+  if (height != NULL)
+    *height = cogl_texture_get_height (priv->texture);
+
+  return TRUE;
+}
+
+static void
+clutter_content_iface_init (ClutterContentIface *iface)
+{
+  iface->get_preferred_size = clutter_image_get_preferred_size;
+  iface->paint_content = clutter_image_paint_content;
+}
+
+/**
+ * clutter_image_new:
+ *
+ * FIXME
+ *
+ * Return value: (transfer full): FIXME
+ *
+ * Since: 1.10
+ */
+ClutterContent *
+clutter_image_new (void)
+{
+  return g_object_new (CLUTTER_TYPE_IMAGE, NULL);
+}
+
+gboolean
+clutter_image_set_data (ClutterImage     *image,
+                        const guint8     *data,
+                        CoglPixelFormat   pixel_format,
+                        guint             width,
+                        guint             height,
+                        guint             row_stride,
+                        GError          **error)
+{
+  ClutterImagePrivate *priv;
+
+  g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (data != NULL, FALSE);
+
+  priv = image->priv;
+
+  if (priv->texture != NULL)
+    cogl_object_unref (priv->texture);
+
+  priv->texture = cogl_texture_new_from_data (width, height,
+                                              COGL_TEXTURE_NONE,
+                                              pixel_format,
+                                              COGL_PIXEL_FORMAT_ANY,
+                                              row_stride,
+                                              data);
+  if (priv->texture == NULL)
+    {
+      g_set_error_literal (error, CLUTTER_IMAGE_ERROR,
+                           CLUTTER_IMAGE_ERROR_INVALID_DATA,
+                           _("Unable to load image data"));
+      return FALSE;
+    }
+
+  clutter_content_invalidate (CLUTTER_CONTENT (image));
+
+  return TRUE;
+}
diff --git a/clutter/clutter-image.h b/clutter/clutter-image.h
new file mode 100644
index 0000000..690bd65
--- /dev/null
+++ b/clutter/clutter-image.h
@@ -0,0 +1,101 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive image' library.
+ *
+ * Copyright (C) 2012  Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *   Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#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 <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;
+
+typedef enum {
+  CLUTTER_IMAGE_ERROR_INVALID_DATA
+} ClutterImageError;
+
+/**
+ * ClutterImage:
+ *
+ * The <structname>ClutterImage</structname> structure contains
+ * private data and should only be accessed using the provided
+ * API.
+ *
+ * Since: 1.10
+ */
+struct _ClutterImage
+{
+  /*< private >*/
+  GObject parent_instance;
+
+  ClutterImagePrivate *priv;
+};
+
+/**
+ * ClutterImageClass:
+ *
+ * The <structname>ClutterImageClass</structname> structure contains
+ * private data.
+ *
+ * Since: 1.10
+ */
+struct _ClutterImageClass
+{
+  /*< private >*/
+  GObjectClass parent_class;
+
+  gpointer _padding[16];
+};
+
+GQuark clutter_image_error_quark (void);
+GType clutter_image_get_type (void) G_GNUC_CONST;
+
+ClutterContent *        clutter_image_new               (void);
+gboolean                clutter_image_set_data          (ClutterImage     *image,
+                                                         const guint8     *data,
+                                                         CoglPixelFormat   pixel_format,
+                                                         guint             width,
+                                                         guint             height,
+                                                         guint             row_stride,
+                                                         GError          **error);
+
+G_END_DECLS
+
+#endif /* __CLUTTER_IMAGE_H__ */
diff --git a/clutter/clutter.h b/clutter/clutter.h
index 2a412df..34788e3 100644
--- a/clutter/clutter.h
+++ b/clutter/clutter.h
@@ -70,6 +70,7 @@
 #include "clutter-flow-layout.h"
 #include "clutter-gesture-action.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]