diff --git a/cogl-bitmap.h b/cogl-bitmap.h new file mode 100644 index 000000000..1bb3eb3db --- /dev/null +++ b/cogl-bitmap.h @@ -0,0 +1,78 @@ +/* + * Cogl + * + * An object oriented GL/GLES Abstraction/Utility Layer + * + * Copyright (C) 2007,2008,2009 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, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __COGL_BITMAP_H__ +#define __COGL_BITMAP_H__ + +G_BEGIN_DECLS + +#include + +/** + * SECTION:cogl-bitmap + * @short_description: Fuctions for loading images but not directly + * into textures + * + * Cogl allows loading image data into memory as CoglBitmaps without + * loading them immediately into GPU textures. + */ + + +/** + * cogl_bitmap_new_from_file: + * @filename: the file to load. + * @error: a #GError or %NULL. + * + * Load an image file from disk. This function can be safely called from + * within a thread. + * + * Returns: A CoglBitmap to the new loaded image data, or %NULL if loading + * the image failed. + * + * Since: 1.0 + */ +CoglHandle cogl_bitmap_new_from_file (const gchar *filename, + GError **error); + +/** + * cogl_bitmap_get_size_from_file: + * @filename: the file to check + * @width: return location for the bitmap width + * @height: return location for the bitmap height + * + * Parses an image file enough to extract the width and height + * of the bitmap. + * + * Since: 1.0 + */ +gboolean cogl_bitmap_get_size_from_file (const gchar *filename, + gint *width, + gint *height); + +G_END_DECLS + +#endif /* __COGL_BITMAP_H__ */ diff --git a/cogl-texture.h b/cogl-texture.h index f75abb3e5..ccf55eb0c 100644 --- a/cogl-texture.h +++ b/cogl-texture.h @@ -146,21 +146,21 @@ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle, /** * cogl_texture_new_from_bitmap: - * @bitmap: a #CoglBitmap + * @bmp_handle: A CoglBitmap handle * @max_waste: maximum extra horizontal and|or vertical margin pixels * to make the texture fit GPU limitations * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE * @internal_format: the #CoglPixelFormat to use for the GPU storage of the * texture * - * Creates a COGL texture from a #CoglBitmap. + * Creates a COGL texture from a CoglBitmap. * * Return value: a #CoglHandle to the newly created texture or * %COGL_INVALID_HANDLE on failure * * Since: 1.0 */ -CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap, +CoglHandle cogl_texture_new_from_bitmap (CoglHandle bmp_handle, gint max_waste, CoglTextureFlags flags, CoglPixelFormat internal_format); @@ -363,45 +363,6 @@ CoglHandle cogl_texture_ref (CoglHandle handle); */ void cogl_texture_unref (CoglHandle handle); -/** - * cogl_bitmap_new_from_file: - * @filename: the file to load. - * @error: a #GError or %NULL. - * - * Load an image file from disk. This function can be safely called from - * within a thread. - * - * Returns: A #CoglBitmap to the new loaded image data, or %NULL if loading - * the image failed. - * - * Since: 1.0 - */ -CoglBitmap * cogl_bitmap_new_from_file (const gchar *filename, - GError **error); - -/** - * cogl_bitmap_get_size_from_file: - * @filename: the file to check - * @width: return location for the bitmap width - * @height: return location for the bitmap height - * - * Parses an image file enough to extract the width and height - * of the bitmap. - * - * Since: 1.0 - */ -gboolean cogl_bitmap_get_size_from_file (const gchar *filename, - gint *width, - gint *height); - -/** - * cogl_bitmap_free: - * @bmp: a #CoglBitmap. - * - * Frees a #CoglBitmap. - */ -void cogl_bitmap_free (CoglBitmap *bmp); - /** * cogl_rectangle_with_texture_coords: * @x1: x coordinate upper left on screen. diff --git a/cogl-types.h b/cogl-types.h index d00da14c6..b2c082bc8 100644 --- a/cogl-types.h +++ b/cogl-types.h @@ -32,13 +32,6 @@ G_BEGIN_DECLS -/** - * CoglBitmap: - * - * Type used for storing image data. - */ -typedef struct _CoglBitmap CoglBitmap; - /** * CoglHandle: * diff --git a/cogl.h.in b/cogl.h.in index 3e7860a61..2422cd1da 100644 --- a/cogl.h.in +++ b/cogl.h.in @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include diff --git a/common/Makefile.am b/common/Makefile.am index c2c8310dc..a4f0bfbb7 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -22,7 +22,7 @@ libclutter_cogl_common_la_SOURCES = \ cogl.c \ cogl-util.h \ cogl-util.c \ - cogl-bitmap.h \ + cogl-bitmap-private.h \ cogl-bitmap.c \ cogl-bitmap-fallback.c \ cogl-current-matrix.c \ diff --git a/common/cogl-bitmap-fallback.c b/common/cogl-bitmap-fallback.c index b9ba9b737..e118459e1 100644 --- a/common/cogl-bitmap-fallback.c +++ b/common/cogl-bitmap-fallback.c @@ -27,7 +27,7 @@ #include "cogl.h" #include "cogl-internal.h" -#include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include diff --git a/common/cogl-bitmap-pixbuf.c b/common/cogl-bitmap-pixbuf.c index 4108e321a..f1e500534 100644 --- a/common/cogl-bitmap-pixbuf.c +++ b/common/cogl-bitmap-pixbuf.c @@ -27,7 +27,7 @@ #include "cogl.h" #include "cogl-internal.h" -#include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include diff --git a/common/cogl-bitmap.h b/common/cogl-bitmap-private.h similarity index 96% rename from common/cogl-bitmap.h rename to common/cogl-bitmap-private.h index 953ac5a32..f54961bd0 100644 --- a/common/cogl-bitmap.h +++ b/common/cogl-bitmap-private.h @@ -28,14 +28,17 @@ #include -struct _CoglBitmap +#include "cogl-handle.h" + +typedef struct _CoglBitmap { + CoglHandleObject _parent; guchar *data; CoglPixelFormat format; gint width; gint height; gint rowstride; -}; +} CoglBitmap; gboolean _cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst); diff --git a/common/cogl-bitmap.c b/common/cogl-bitmap.c index af3bc53b6..f4c322abb 100644 --- a/common/cogl-bitmap.c +++ b/common/cogl-bitmap.c @@ -27,10 +27,21 @@ #include "cogl.h" #include "cogl-internal.h" -#include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include +static void _cogl_bitmap_free (CoglBitmap *bmp); + +COGL_HANDLE_DEFINE (Bitmap, bitmap); + +static void +_cogl_bitmap_free (CoglBitmap *bmp) +{ + g_free (bmp->data); + g_free (bmp); +} + gint _cogl_get_format_bpp (CoglPixelFormat format) { @@ -155,11 +166,12 @@ cogl_bitmap_get_size_from_file (const gchar *filename, return _cogl_bitmap_get_size_from_file (filename, width, height); } -CoglBitmap * +CoglHandle cogl_bitmap_new_from_file (const gchar *filename, GError **error) { CoglBitmap bmp; + CoglBitmap *ret; g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); @@ -176,12 +188,7 @@ cogl_bitmap_new_from_file (const gchar *filename, } } - return (CoglBitmap *) g_memdup (&bmp, sizeof (CoglBitmap)); + ret = g_memdup (&bmp, sizeof (CoglBitmap)); + return _cogl_bitmap_handle_new (ret); } -void -cogl_bitmap_free (CoglBitmap *bmp) -{ - g_free (bmp->data); - g_free (bmp); -} diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index f99461c43..bc9d6afc1 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -103,6 +103,13 @@ cogl_path_stroke_preserve cogl_color +
+cogl-bitmap +Bitmaps +cogl_bitmap_new_from_file +cogl_bitmap_get_size_from_file +
+
cogl-texture Textures @@ -130,12 +137,6 @@ cogl_texture_get_gl_texture cogl_texture_get_data cogl_texture_set_filters cogl_texture_set_region - - -CoglBitmap -cogl_bitmap_new_from_file -cogl_bitmap_free -cogl_bitmap_get_size_from_file
diff --git a/gl/Makefile.am b/gl/Makefile.am index 12e2ee92a..b143e8e9b 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -8,6 +8,7 @@ libclutterinclude_HEADERS = \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \ + $(top_builddir)/clutter/cogl/cogl-bitmap.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h \ @@ -43,6 +44,7 @@ libclutter_cogl_la_SOURCES = \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \ + $(top_builddir)/clutter/cogl/cogl-bitmap.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-debug.h \ diff --git a/gl/cogl-texture-private.h b/gl/cogl-texture-private.h index 2905175bb..cd60528e4 100644 --- a/gl/cogl-texture-private.h +++ b/gl/cogl-texture-private.h @@ -24,7 +24,7 @@ #ifndef __COGL_TEXTURE_H #define __COGL_TEXTURE_H -#include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include "cogl-handle.h" typedef struct _CoglTexture CoglTexture; diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index 59132c2d4..8fb4980f5 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -34,6 +34,7 @@ #include "cogl-internal.h" #include "cogl-util.h" #include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include "cogl-texture-private.h" #include "cogl-material.h" #include "cogl-context.h" @@ -1339,12 +1340,15 @@ cogl_texture_new_from_data (guint width, } CoglHandle -cogl_texture_new_from_bitmap (CoglBitmap *bmp, +cogl_texture_new_from_bitmap (CoglHandle bmp_handle, gint max_waste, CoglTextureFlags flags, CoglPixelFormat internal_format) { CoglTexture *tex; + CoglBitmap *bmp = (CoglBitmap *)bmp_handle; + + g_return_val_if_fail (bmp_handle != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE); /* Create new texture and fill with loaded data */ tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); @@ -1402,19 +1406,20 @@ cogl_texture_new_from_file (const gchar *filename, CoglPixelFormat internal_format, GError **error) { - CoglBitmap *bmp; + CoglHandle bmp; CoglHandle handle; g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); - if (!(bmp = cogl_bitmap_new_from_file (filename, error))) + bmp = cogl_bitmap_new_from_file (filename, error); + if (bmp == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; handle = cogl_texture_new_from_bitmap (bmp, max_waste, flags, internal_format); - cogl_bitmap_free (bmp); + cogl_handle_unref (bmp); return handle; } diff --git a/gles/Makefile.am b/gles/Makefile.am index 1ec4ae789..409f655b8 100644 --- a/gles/Makefile.am +++ b/gles/Makefile.am @@ -8,6 +8,7 @@ libclutterinclude_HEADERS = \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \ + $(top_builddir)/clutter/cogl/cogl-bitmap.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-vertex-buffer.h \ @@ -43,6 +44,7 @@ libclutter_cogl_la_SOURCES = \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-shader.h \ + $(top_builddir)/clutter/cogl/cogl-bitmap.h \ $(top_builddir)/clutter/cogl/cogl-texture.h \ $(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-debug.h \ diff --git a/gles/cogl-texture-private.h b/gles/cogl-texture-private.h index 2905175bb..cd60528e4 100644 --- a/gles/cogl-texture-private.h +++ b/gles/cogl-texture-private.h @@ -24,7 +24,7 @@ #ifndef __COGL_TEXTURE_H #define __COGL_TEXTURE_H -#include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include "cogl-handle.h" typedef struct _CoglTexture CoglTexture; diff --git a/gles/cogl-texture.c b/gles/cogl-texture.c index 66af941c2..959332919 100644 --- a/gles/cogl-texture.c +++ b/gles/cogl-texture.c @@ -28,7 +28,7 @@ #include "cogl.h" #include "cogl-internal.h" #include "cogl-util.h" -#include "cogl-bitmap.h" +#include "cogl-bitmap-private.h" #include "cogl-texture-private.h" #include "cogl-material.h" #include "cogl-context.h" @@ -1433,12 +1433,13 @@ cogl_texture_new_from_data (guint width, } CoglHandle -cogl_texture_new_from_bitmap (CoglBitmap *bmp, +cogl_texture_new_from_bitmap (CoglHandle bmp_handle, gint max_waste, CoglTextureFlags flags, CoglPixelFormat internal_format) { CoglTexture *tex; + CoglBitmap *bmp = (CoglBitmap *)bmp_handle; /* Create new texture and fill with loaded data */ tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); @@ -1496,19 +1497,20 @@ cogl_texture_new_from_file (const gchar *filename, CoglPixelFormat internal_format, GError **error) { - CoglBitmap *bmp; + CoglHandle bmp; CoglHandle handle; g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); - if (!(bmp = cogl_bitmap_new_from_file (filename, error))) + bmp = cogl_bitmap_new_from_file (filename, error); + if (bmp == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; handle = cogl_texture_new_from_bitmap (bmp, max_waste, flags, internal_format); - cogl_bitmap_free (bmp); + cogl_handle_unref (bmp); return handle; }