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.
This commit is contained in:
Neil Roberts 2010-02-03 23:08:30 +00:00
parent e83e0c3e5b
commit 264f0f0f05

View File

@ -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;