From 19a19579ba72ea9ca4f6d406c035c3ad074fd442 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 27 Nov 2009 16:59:51 +0000 Subject: [PATCH] cogl: Move some of the texture_2d_sliced_new_* functions into cogl-texture new_from_data and new_from_file can be implemented in terms of new_from_bitmap so it makes sense to move these to cogl-texture rather than having to implement them in every texture backend. --- .../cogl/cogl-texture-2d-sliced-private.h | 16 ---- clutter/cogl/cogl/cogl-texture-2d-sliced.c | 84 ------------------- clutter/cogl/cogl/cogl-texture.c | 44 +++++++--- 3 files changed, 33 insertions(+), 111 deletions(-) diff --git a/clutter/cogl/cogl/cogl-texture-2d-sliced-private.h b/clutter/cogl/cogl/cogl-texture-2d-sliced-private.h index 70eba4a97..dfde144ac 100644 --- a/clutter/cogl/cogl/cogl-texture-2d-sliced-private.h +++ b/clutter/cogl/cogl/cogl-texture-2d-sliced-private.h @@ -84,12 +84,6 @@ _cogl_texture_2d_sliced_new_with_size (unsigned int width, CoglTextureFlags flags, CoglPixelFormat internal_format); -CoglHandle -_cogl_texture_2d_sliced_new_from_file (const gchar *filename, - CoglTextureFlags flags, - CoglPixelFormat internal_format, - GError **error); - CoglHandle _cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle, GLenum gl_target, @@ -99,16 +93,6 @@ _cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle, GLuint y_pot_waste, CoglPixelFormat format); -CoglHandle -_cogl_texture_2d_sliced_new_from_data (unsigned int width, - unsigned int height, - CoglTextureFlags flags, - CoglPixelFormat format, - CoglPixelFormat internal_format, - unsigned int rowstride, - const guint8 *data); - - CoglHandle _cogl_texture_2d_sliced_new_from_bitmap (CoglHandle bmp_handle, CoglTextureFlags flags, diff --git a/clutter/cogl/cogl/cogl-texture-2d-sliced.c b/clutter/cogl/cogl/cogl-texture-2d-sliced.c index 5f0900d4b..0f53bc1dc 100644 --- a/clutter/cogl/cogl/cogl-texture-2d-sliced.c +++ b/clutter/cogl/cogl/cogl-texture-2d-sliced.c @@ -992,67 +992,6 @@ _cogl_texture_2d_sliced_new_with_size (unsigned int width, return _cogl_texture_2d_sliced_handle_new (tex_2ds); } -CoglHandle -_cogl_texture_2d_sliced_new_from_data (unsigned int width, - unsigned int height, - CoglTextureFlags flags, - CoglPixelFormat format, - CoglPixelFormat internal_format, - unsigned int rowstride, - const guint8 *data) -{ - CoglTexture2DSliced *tex_2ds; - CoglTexture *tex; - CoglTextureUploadData upload_data; - - if (format == COGL_PIXEL_FORMAT_ANY) - return COGL_INVALID_HANDLE; - - if (data == NULL) - return COGL_INVALID_HANDLE; - - /* Rowstride from width if not given */ - if (rowstride == 0) - rowstride = width * _cogl_get_format_bpp (format); - - /* Create new texture and fill with given data */ - tex_2ds = g_new0 (CoglTexture2DSliced, 1); - - tex = COGL_TEXTURE (tex_2ds); - tex->vtable = &cogl_texture_2d_sliced_vtable; - - upload_data.bitmap.width = width; - upload_data.bitmap.height = height; - upload_data.bitmap.data = (guchar*)data; - upload_data.bitmap.format = format; - upload_data.bitmap.rowstride = rowstride; - upload_data.bitmap_owner = FALSE; - - if (flags & COGL_TEXTURE_NO_SLICING) - tex_2ds->max_waste = -1; - else - tex_2ds->max_waste = COGL_TEXTURE_MAX_WASTE; - - /* FIXME: If upload fails we should set some kind of - * error flag but still return texture handle (this - * is to keep the behavior equal to _new_from_file; - * see below) */ - - if (!_cogl_texture_2d_sliced_upload_from_data (tex_2ds, &upload_data, - internal_format)) - { - _cogl_texture_2d_sliced_free (tex_2ds); - _cogl_texture_upload_data_free (&upload_data); - return COGL_INVALID_HANDLE; - } - - _cogl_texture_upload_data_free (&upload_data); - - tex_2ds->auto_mipmap = (flags & COGL_TEXTURE_NO_AUTO_MIPMAP) == 0; - - return _cogl_texture_2d_sliced_handle_new (tex_2ds); -} - CoglHandle _cogl_texture_2d_sliced_new_from_bitmap (CoglHandle bmp_handle, CoglTextureFlags flags, @@ -1101,29 +1040,6 @@ _cogl_texture_2d_sliced_new_from_bitmap (CoglHandle bmp_handle, return _cogl_texture_2d_sliced_handle_new (tex_2ds); } -CoglHandle -_cogl_texture_2d_sliced_new_from_file ( - const char *filename, - CoglTextureFlags flags, - CoglPixelFormat internal_format, - GError **error) -{ - CoglHandle bmp; - CoglHandle handle; - - g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); - - bmp = cogl_bitmap_new_from_file (filename, error); - if (bmp == COGL_INVALID_HANDLE) - return COGL_INVALID_HANDLE; - - handle = - _cogl_texture_2d_sliced_new_from_bitmap (bmp, flags, internal_format); - cogl_handle_unref (bmp); - - return handle; -} - CoglHandle _cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle, GLenum gl_target, diff --git a/clutter/cogl/cogl/cogl-texture.c b/clutter/cogl/cogl/cogl-texture.c index 5fc0892cb..516b23002 100644 --- a/clutter/cogl/cogl/cogl-texture.c +++ b/clutter/cogl/cogl/cogl-texture.c @@ -319,13 +319,26 @@ cogl_texture_new_from_data (guint width, guint rowstride, const guchar *data) { - return _cogl_texture_2d_sliced_new_from_data (width, - height, - flags, - format, - internal_format, - rowstride, - data); + CoglBitmap bitmap; + + if (format == COGL_PIXEL_FORMAT_ANY) + return COGL_INVALID_HANDLE; + + if (data == NULL) + return COGL_INVALID_HANDLE; + + /* Rowstride from width if not given */ + if (rowstride == 0) + rowstride = width * _cogl_get_format_bpp (format); + + /* Wrap the data into a bitmap */ + bitmap.width = width; + bitmap.height = height; + bitmap.data = (guchar *) data; + bitmap.format = format; + bitmap.rowstride = rowstride; + + return cogl_texture_new_from_bitmap (&bitmap, flags, internal_format); } CoglHandle @@ -344,10 +357,19 @@ cogl_texture_new_from_file (const gchar *filename, CoglPixelFormat internal_format, GError **error) { - return _cogl_texture_2d_sliced_new_from_file (filename, - flags, - internal_format, - error); + CoglHandle bmp; + CoglHandle handle; + + g_return_val_if_fail (error == NULL || *error == NULL, COGL_INVALID_HANDLE); + + bmp = cogl_bitmap_new_from_file (filename, error); + if (bmp == COGL_INVALID_HANDLE) + return COGL_INVALID_HANDLE; + + handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format); + cogl_handle_unref (bmp); + + return handle; } CoglHandle