[cogl] Only expose CoglBitmap as a CoglHandle

It was inconsistent that we exposed the CoglBitmap struct instead of an
opaque CoglHandle.
This commit is contained in:
Robert Bragg 2009-04-30 18:00:22 +01:00
parent 66cb117056
commit c8862e35cc
16 changed files with 135 additions and 80 deletions

78
cogl-bitmap.h Normal file
View File

@ -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 <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_BITMAP_H__
#define __COGL_BITMAP_H__
G_BEGIN_DECLS
#include <cogl/cogl-types.h>
/**
* 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__ */

View File

@ -146,21 +146,21 @@ CoglHandle cogl_texture_new_from_foreign (GLuint gl_handle,
/** /**
* cogl_texture_new_from_bitmap: * cogl_texture_new_from_bitmap:
* @bitmap: a #CoglBitmap * @bmp_handle: A CoglBitmap handle
* @max_waste: maximum extra horizontal and|or vertical margin pixels * @max_waste: maximum extra horizontal and|or vertical margin pixels
* to make the texture fit GPU limitations * to make the texture fit GPU limitations
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE * @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture * 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 * Return value: a #CoglHandle to the newly created texture or
* %COGL_INVALID_HANDLE on failure * %COGL_INVALID_HANDLE on failure
* *
* Since: 1.0 * Since: 1.0
*/ */
CoglHandle cogl_texture_new_from_bitmap (CoglBitmap *bitmap, CoglHandle cogl_texture_new_from_bitmap (CoglHandle bmp_handle,
gint max_waste, gint max_waste,
CoglTextureFlags flags, CoglTextureFlags flags,
CoglPixelFormat internal_format); CoglPixelFormat internal_format);
@ -363,45 +363,6 @@ CoglHandle cogl_texture_ref (CoglHandle handle);
*/ */
void cogl_texture_unref (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: * cogl_rectangle_with_texture_coords:
* @x1: x coordinate upper left on screen. * @x1: x coordinate upper left on screen.

View File

@ -32,13 +32,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* CoglBitmap:
*
* Type used for storing image data.
*/
typedef struct _CoglBitmap CoglBitmap;
/** /**
* CoglHandle: * CoglHandle:
* *

View File

@ -40,6 +40,7 @@
#include <cogl/cogl-material.h> #include <cogl/cogl-material.h>
#include <cogl/cogl-path.h> #include <cogl/cogl-path.h>
#include <cogl/cogl-shader.h> #include <cogl/cogl-shader.h>
#include <cogl/cogl-bitmap.h>
#include <cogl/cogl-texture.h> #include <cogl/cogl-texture.h>
#include <cogl/cogl-types.h> #include <cogl/cogl-types.h>
#include <cogl/cogl-debug.h> #include <cogl/cogl-debug.h>

View File

@ -22,7 +22,7 @@ libclutter_cogl_common_la_SOURCES = \
cogl.c \ cogl.c \
cogl-util.h \ cogl-util.h \
cogl-util.c \ cogl-util.c \
cogl-bitmap.h \ cogl-bitmap-private.h \
cogl-bitmap.c \ cogl-bitmap.c \
cogl-bitmap-fallback.c \ cogl-bitmap-fallback.c \
cogl-current-matrix.c \ cogl-current-matrix.c \

View File

@ -27,7 +27,7 @@
#include "cogl.h" #include "cogl.h"
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-bitmap.h" #include "cogl-bitmap-private.h"
#include <string.h> #include <string.h>

View File

@ -27,7 +27,7 @@
#include "cogl.h" #include "cogl.h"
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-bitmap.h" #include "cogl-bitmap-private.h"
#include <string.h> #include <string.h>

View File

@ -28,14 +28,17 @@
#include <glib.h> #include <glib.h>
struct _CoglBitmap #include "cogl-handle.h"
typedef struct _CoglBitmap
{ {
CoglHandleObject _parent;
guchar *data; guchar *data;
CoglPixelFormat format; CoglPixelFormat format;
gint width; gint width;
gint height; gint height;
gint rowstride; gint rowstride;
}; } CoglBitmap;
gboolean gboolean
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst); _cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);

View File

@ -27,10 +27,21 @@
#include "cogl.h" #include "cogl.h"
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-bitmap.h" #include "cogl-bitmap-private.h"
#include <string.h> #include <string.h>
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 gint
_cogl_get_format_bpp (CoglPixelFormat format) _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); return _cogl_bitmap_get_size_from_file (filename, width, height);
} }
CoglBitmap * CoglHandle
cogl_bitmap_new_from_file (const gchar *filename, cogl_bitmap_new_from_file (const gchar *filename,
GError **error) GError **error)
{ {
CoglBitmap bmp; CoglBitmap bmp;
CoglBitmap *ret;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); 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);
}

View File

@ -103,6 +103,13 @@ cogl_path_stroke_preserve
cogl_color cogl_color
</SECTION> </SECTION>
<SECTION>
<FILE>cogl-bitmap</FILE>
<TITLE>Bitmaps</TITLE>
cogl_bitmap_new_from_file
cogl_bitmap_get_size_from_file
</SECTION>
<SECTION> <SECTION>
<FILE>cogl-texture</FILE> <FILE>cogl-texture</FILE>
<TITLE>Textures</TITLE> <TITLE>Textures</TITLE>
@ -130,12 +137,6 @@ cogl_texture_get_gl_texture
cogl_texture_get_data cogl_texture_get_data
cogl_texture_set_filters cogl_texture_set_filters
cogl_texture_set_region cogl_texture_set_region
<SUBSECTION>
CoglBitmap
cogl_bitmap_new_from_file
cogl_bitmap_free
cogl_bitmap_get_size_from_file
</SECTION> </SECTION>
<SECTION> <SECTION>

View File

@ -8,6 +8,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-path.h \
$(top_builddir)/clutter/cogl/cogl-shader.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-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-vertex-buffer.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-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-path.h \
$(top_builddir)/clutter/cogl/cogl-shader.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-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-debug.h \ $(top_builddir)/clutter/cogl/cogl-debug.h \

View File

@ -24,7 +24,7 @@
#ifndef __COGL_TEXTURE_H #ifndef __COGL_TEXTURE_H
#define __COGL_TEXTURE_H #define __COGL_TEXTURE_H
#include "cogl-bitmap.h" #include "cogl-bitmap-private.h"
#include "cogl-handle.h" #include "cogl-handle.h"
typedef struct _CoglTexture CoglTexture; typedef struct _CoglTexture CoglTexture;

View File

@ -34,6 +34,7 @@
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-util.h" #include "cogl-util.h"
#include "cogl-bitmap.h" #include "cogl-bitmap.h"
#include "cogl-bitmap-private.h"
#include "cogl-texture-private.h" #include "cogl-texture-private.h"
#include "cogl-material.h" #include "cogl-material.h"
#include "cogl-context.h" #include "cogl-context.h"
@ -1339,12 +1340,15 @@ cogl_texture_new_from_data (guint width,
} }
CoglHandle CoglHandle
cogl_texture_new_from_bitmap (CoglBitmap *bmp, cogl_texture_new_from_bitmap (CoglHandle bmp_handle,
gint max_waste, gint max_waste,
CoglTextureFlags flags, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; 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 */ /* Create new texture and fill with loaded data */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
@ -1402,19 +1406,20 @@ cogl_texture_new_from_file (const gchar *filename,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
CoglBitmap *bmp; CoglHandle bmp;
CoglHandle handle; CoglHandle handle;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_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; return COGL_INVALID_HANDLE;
handle = cogl_texture_new_from_bitmap (bmp, handle = cogl_texture_new_from_bitmap (bmp,
max_waste, max_waste,
flags, flags,
internal_format); internal_format);
cogl_bitmap_free (bmp); cogl_handle_unref (bmp);
return handle; return handle;
} }

View File

@ -8,6 +8,7 @@ libclutterinclude_HEADERS = \
$(top_builddir)/clutter/cogl/cogl-offscreen.h \ $(top_builddir)/clutter/cogl/cogl-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-path.h \
$(top_builddir)/clutter/cogl/cogl-shader.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-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-vertex-buffer.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-offscreen.h \
$(top_builddir)/clutter/cogl/cogl-path.h \ $(top_builddir)/clutter/cogl/cogl-path.h \
$(top_builddir)/clutter/cogl/cogl-shader.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-texture.h \
$(top_builddir)/clutter/cogl/cogl-types.h \ $(top_builddir)/clutter/cogl/cogl-types.h \
$(top_builddir)/clutter/cogl/cogl-debug.h \ $(top_builddir)/clutter/cogl/cogl-debug.h \

View File

@ -24,7 +24,7 @@
#ifndef __COGL_TEXTURE_H #ifndef __COGL_TEXTURE_H
#define __COGL_TEXTURE_H #define __COGL_TEXTURE_H
#include "cogl-bitmap.h" #include "cogl-bitmap-private.h"
#include "cogl-handle.h" #include "cogl-handle.h"
typedef struct _CoglTexture CoglTexture; typedef struct _CoglTexture CoglTexture;

View File

@ -28,7 +28,7 @@
#include "cogl.h" #include "cogl.h"
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-util.h" #include "cogl-util.h"
#include "cogl-bitmap.h" #include "cogl-bitmap-private.h"
#include "cogl-texture-private.h" #include "cogl-texture-private.h"
#include "cogl-material.h" #include "cogl-material.h"
#include "cogl-context.h" #include "cogl-context.h"
@ -1433,12 +1433,13 @@ cogl_texture_new_from_data (guint width,
} }
CoglHandle CoglHandle
cogl_texture_new_from_bitmap (CoglBitmap *bmp, cogl_texture_new_from_bitmap (CoglHandle bmp_handle,
gint max_waste, gint max_waste,
CoglTextureFlags flags, CoglTextureFlags flags,
CoglPixelFormat internal_format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
CoglBitmap *bmp = (CoglBitmap *)bmp_handle;
/* Create new texture and fill with loaded data */ /* Create new texture and fill with loaded data */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
@ -1496,19 +1497,20 @@ cogl_texture_new_from_file (const gchar *filename,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
GError **error) GError **error)
{ {
CoglBitmap *bmp; CoglHandle bmp;
CoglHandle handle; CoglHandle handle;
g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_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; return COGL_INVALID_HANDLE;
handle = cogl_texture_new_from_bitmap (bmp, handle = cogl_texture_new_from_bitmap (bmp,
max_waste, max_waste,
flags, flags,
internal_format); internal_format);
cogl_bitmap_free (bmp); cogl_handle_unref (bmp);
return handle; return handle;
} }