[clutter/wip/actor-content: 4/24] image-loader: Add stub for GdkPixbuf-based loader
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/wip/actor-content: 4/24] image-loader: Add stub for GdkPixbuf-based loader
- Date: Fri, 15 Apr 2011 16:44:05 +0000 (UTC)
commit d127d947cf6e18abc40d14d56c4c6de3ea30cea2
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Mon Dec 6 18:10:24 2010 +0000
image-loader: Add stub for GdkPixbuf-based loader
Synchronous API only, for the moment.
clutter/Makefile.am | 5 +
clutter/clutter-main.c | 10 ++
.../image-loaders/clutter-image-loader-pixbuf.c | 150 ++++++++++++++++++++
.../image-loaders/clutter-image-loader-pixbuf.h | 19 +++
4 files changed, 184 insertions(+), 0 deletions(-)
---
diff --git a/clutter/Makefile.am b/clutter/Makefile.am
index 8d4ced7..40328f3 100644
--- a/clutter/Makefile.am
+++ b/clutter/Makefile.am
@@ -611,6 +611,11 @@ imageloader_sources_h = \
$(srcdir)/image-loaders/clutter-image-loader-null.h \
$(NULL)
+if SUPPORT_GDK_PIXBUF
+imageloader_sources_c += $(srcdir)/image-loaders/clutter-image-loader-pixbuf.c
+imageloader_sources_h += $(srcdir)/image-loaders/clutter-image-loader-pixbuf.h
+endif
+
# general build rules:
# you should not need to modify anything below this point
diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index 1a74ba4..e39d013 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -121,6 +121,10 @@
#include "cally.h" /* For accessibility support */
+#ifdef USE_GDKPIXBUF
+#include "image-loaders/clutter-image-loader-pixbuf.h"
+#endif
+
/* main context */
static ClutterMainContext *ClutterCntx = NULL;
@@ -3133,6 +3137,8 @@ _clutter_io_modules_ensure_loaded (void)
if (!loaded_dirs)
{
+ volatile GType dummy_type;
+
loaded_dirs = TRUE;
g_io_modules_scan_all_in_directory (CLUTTER_MODULEDIR);
@@ -3153,6 +3159,10 @@ _clutter_io_modules_ensure_loaded (void)
}
/* XXX Initialize types from built-in "modules" here XXX */
+
+#ifdef USE_GDKPIXBUF
+ dummy_type = _clutter_image_loader_pixbuf_get_type ();
+#endif
}
G_UNLOCK (loaded_dirs);
diff --git a/clutter/image-loaders/clutter-image-loader-pixbuf.c b/clutter/image-loaders/clutter-image-loader-pixbuf.c
new file mode 100644
index 0000000..204e31c
--- /dev/null
+++ b/clutter/image-loaders/clutter-image-loader-pixbuf.c
@@ -0,0 +1,150 @@
+#include "config.h"
+
+#include "clutter-image-loader-pixbuf.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gio/gio.h>
+#include <cogl/cogl.h>
+
+#include "clutter-debug.h"
+#include "clutter-image.h"
+#include "clutter-private.h"
+
+struct _ClutterImageLoaderPixbuf
+{
+ ClutterImageLoader parent_instance;
+
+ GdkPixbufLoader *loader;
+
+ gint image_width;
+ gint image_height;
+ gint rowstride;
+
+ CoglPixelFormat pixel_format;
+
+ CoglHandle texture;
+};
+
+#define clutter_image_loader_pixbuf_get_type _clutter_image_loader_pixbuf_get_type
+G_DEFINE_TYPE_WITH_CODE (ClutterImageLoaderPixbuf,
+ clutter_image_loader_pixbuf,
+ CLUTTER_TYPE_IMAGE_LOADER,
+ g_io_extension_point_implement (CLUTTER_IMAGE_LOADER_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "gdk-pixbuf",
+ 20));
+
+static void
+clutter_image_loader_pixbuf_dispose (GObject *gobject)
+{
+ ClutterImageLoaderPixbuf *loader;
+
+ loader = CLUTTER_IMAGE_LOADER_PIXBUF (gobject);
+
+ if (loader->loader != NULL)
+ {
+ gdk_pixbuf_loader_close (loader->loader, NULL);
+ g_object_unref (loader->loader);
+ loader->loader = NULL;
+ }
+
+ if (loader->texture != COGL_INVALID_HANDLE)
+ {
+ cogl_handle_unref (loader->texture);
+ loader->texture = COGL_INVALID_HANDLE;
+ }
+
+ G_OBJECT_CLASS (clutter_image_loader_pixbuf_parent_class)->dispose (gobject);
+}
+
+static gboolean
+clutter_image_loader_pixbuf_is_supported (void)
+{
+ return TRUE;
+}
+
+static gboolean
+clutter_image_loader_pixbuf_load_stream (ClutterImageLoader *loader,
+ GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
+{
+ ClutterImageLoaderPixbuf *self = CLUTTER_IMAGE_LOADER_PIXBUF (loader);
+ GdkPixbuf *pixbuf;
+
+ pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, error);
+ if (pixbuf == NULL)
+ return FALSE;
+
+ self->image_width = gdk_pixbuf_get_width (pixbuf);
+ self->image_height = gdk_pixbuf_get_height (pixbuf);
+ self->pixel_format = gdk_pixbuf_get_has_alpha (pixbuf)
+ ? COGL_PIXEL_FORMAT_RGBA_8888
+ : COGL_PIXEL_FORMAT_RGB_888;
+ self->rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+
+ CLUTTER_NOTE (MISC, "Image: %d x %d (rowstride: %d, has-alpha: %s)",
+ self->image_width,
+ self->image_height,
+ self->rowstride,
+ gdk_pixbuf_get_has_alpha (pixbuf) ? "yes" : "no");
+
+ self->texture = cogl_texture_new_from_data (self->image_width,
+ self->image_height,
+ COGL_TEXTURE_NONE,
+ self->pixel_format,
+ COGL_PIXEL_FORMAT_ANY,
+ self->rowstride,
+ gdk_pixbuf_get_pixels (pixbuf));
+
+ g_object_unref (pixbuf);
+
+ if (self->texture == COGL_INVALID_HANDLE &&
+ (error != NULL && *error == NULL))
+ g_set_error_literal (error, CLUTTER_IMAGE_ERROR,
+ CLUTTER_IMAGE_ERROR_INVALID_DATA,
+ _("Unable to load the image data"));
+
+ return (self->texture != COGL_INVALID_HANDLE);
+}
+
+static void
+clutter_image_loader_pixbuf_get_image_size (ClutterImageLoader *loader,
+ gint *width,
+ gint *height)
+{
+ ClutterImageLoaderPixbuf *self = CLUTTER_IMAGE_LOADER_PIXBUF (loader);
+
+ if (width)
+ *width = self->image_width;
+
+ if (height)
+ *height = self->image_height;
+}
+
+static CoglHandle
+clutter_image_loader_pixbuf_get_texture_handle (ClutterImageLoader *loader)
+{
+ ClutterImageLoaderPixbuf *self = CLUTTER_IMAGE_LOADER_PIXBUF (loader);
+
+ return self->texture;
+}
+
+static void
+clutter_image_loader_pixbuf_class_init (ClutterImageLoaderPixbufClass *klass)
+{
+ ClutterImageLoaderClass *loader_class = CLUTTER_IMAGE_LOADER_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = clutter_image_loader_pixbuf_dispose;
+
+ loader_class->is_supported = clutter_image_loader_pixbuf_is_supported;
+ loader_class->load_stream = clutter_image_loader_pixbuf_load_stream;
+ loader_class->get_image_size = clutter_image_loader_pixbuf_get_image_size;
+ loader_class->get_texture_handle = clutter_image_loader_pixbuf_get_texture_handle;
+}
+
+static void
+clutter_image_loader_pixbuf_init (ClutterImageLoaderPixbuf *loader)
+{
+}
diff --git a/clutter/image-loaders/clutter-image-loader-pixbuf.h b/clutter/image-loaders/clutter-image-loader-pixbuf.h
new file mode 100644
index 0000000..4e06c4d
--- /dev/null
+++ b/clutter/image-loaders/clutter-image-loader-pixbuf.h
@@ -0,0 +1,19 @@
+#ifndef __CLUTTER_IMAGE_LOADER_PIXBUF_H__
+#define __CLUTTER_IMAGE_LOADER_PIXBUF_H__
+
+#include <clutter/clutter-image-loader.h>
+
+G_BEGIN_DECLS
+
+#define CLUTTER_TYPE_IMAGE_LOADER_PIXBUF (_clutter_image_loader_pixbuf_get_type ())
+#define CLUTTER_IMAGE_LOADER_PIXBUF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_IMAGE_LOADER_PIXBUF, ClutterImageLoaderPixbuf))
+#define CLUTTER_IS_IMAGE_LOADER_PIXBUF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_IMAGE_LOADER_PIXBUF))
+
+typedef struct _ClutterImageLoaderPixbuf ClutterImageLoaderPixbuf;
+typedef struct _ClutterImageLoaderClass ClutterImageLoaderPixbufClass;
+
+GType _clutter_image_loader_pixbuf_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __CLUTTER_IMAGE_LOADER_PIXBUF_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]