From e6a3b6ebe75a2c0c3709fbe12cf04c4357b54fdd Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 3 Feb 2010 23:08:30 +0000 Subject: [PATCH] cogl-texture: Avoid copying the bitmap when premultiplying from a file In cogl_texture_new_from_file we create and own a temporary bitmap. There's no need to copy this data if we need to do a premult conversion so instead it just does conversion before passing it on to cogl_texture_new_from_bitmap. --- clutter/cogl/cogl/cogl-texture.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/clutter/cogl/cogl/cogl-texture.c b/clutter/cogl/cogl/cogl-texture.c index da55fd004..db9a0650d 100644 --- a/clutter/cogl/cogl/cogl-texture.c +++ b/clutter/cogl/cogl/cogl-texture.c @@ -396,16 +396,29 @@ cogl_texture_new_from_file (const gchar *filename, CoglPixelFormat internal_format, GError **error) { - CoglHandle bmp; - CoglHandle handle; + CoglHandle bmp_handle; + CoglBitmap *bmp; + CoglHandle handle = COGL_INVALID_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) + bmp_handle = cogl_bitmap_new_from_file (filename, error); + if (bmp_handle == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; - handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format); + bmp = (CoglBitmap *) bmp_handle; + + /* We know that the bitmap data is solely owned by this function so + we can do the premult conversion in place. This avoids having to + copy the bitmap which will otherwise happen in + _cogl_texture_prepare_for_upload */ + internal_format = _cogl_texture_determine_internal_format (bmp->format, + internal_format); + if (!_cogl_texture_needs_premult_conversion (bmp->format, internal_format) || + _cogl_bitmap_convert_premult_status (bmp, + bmp->format ^= COGL_PREMULT_BIT)) + handle = cogl_texture_new_from_bitmap (bmp, flags, internal_format); + cogl_handle_unref (bmp); return handle;