texture: Clean up error reporting

ClutterTexture relies too much on GError, even for things that are
clearly programmer errors. Also, no error message passed to GError
is marked for translation as it should.

We should move the programmer errors, like passing the wrong bpp
value with regards to the presence of the alpha channel, to real
warnings; we should also try and harmonize all the error messages,
and not mention Cogl — especially in the ones marked for translation.
This commit is contained in:
Emmanuele Bassi 2011-07-18 16:10:17 +01:00
parent 672bc337ba
commit 123bd41e6c

View File

@ -1554,7 +1554,7 @@ clutter_texture_set_from_data (ClutterTexture *texture,
g_set_error (&inner_error, CLUTTER_TEXTURE_ERROR, g_set_error (&inner_error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT, CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Failed to create Cogl texture"); _("Failed to load the image data"));
g_signal_emit (texture, texture_signals[LOAD_FINISHED], 0, inner_error); g_signal_emit (texture, texture_signals[LOAD_FINISHED], 0, inner_error);
@ -1578,6 +1578,49 @@ clutter_texture_set_from_data (ClutterTexture *texture,
return TRUE; return TRUE;
} }
static inline gboolean
get_pixel_format_from_texture_flags (gint bpp,
gboolean has_alpha,
ClutterTextureFlags flags,
CoglPixelFormat *source_format)
{
/* Convert the flags to a CoglPixelFormat */
if (has_alpha)
{
if (G_UNLIKELY (bpp != 4))
{
g_warning ("Unsupported bits per pixel value '%d': "
"Clutter supports only a value of 4 "
"for RGBA data",
bpp);
return FALSE;
}
*source_format = COGL_PIXEL_FORMAT_RGBA_8888;
}
else
{
if (G_UNLIKELY (bpp != 3))
{
g_warning ("Unsupported bits per pixel value '%d': "
"Clutter supports only a BPP value of 3 "
"for RGB data",
bpp);
return FALSE;
}
*source_format = COGL_PIXEL_FORMAT_RGB_888;
}
if ((flags & CLUTTER_TEXTURE_RGB_FLAG_BGR))
*source_format |= COGL_BGR_BIT;
if ((flags & CLUTTER_TEXTURE_RGB_FLAG_PREMULT))
*source_format |= COGL_PREMULT_BIT;
return TRUE;
}
/** /**
* clutter_texture_set_from_rgb_data: * clutter_texture_set_from_rgb_data:
* @texture: A #ClutterTexture * @texture: A #ClutterTexture
@ -1612,43 +1655,14 @@ clutter_texture_set_from_rgb_data (ClutterTexture *texture,
g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE); g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE);
/* Convert the flags to a CoglPixelFormat */ if (!get_pixel_format_from_texture_flags (bpp,
if (has_alpha) has_alpha,
flags,
&source_format))
{ {
if (bpp != 4)
{
g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Unsupported bits per pixel value '%d': "
"Clutter supports only a BPP value of 4 "
"for RGBA data",
bpp);
return FALSE; return FALSE;
} }
source_format = COGL_PIXEL_FORMAT_RGBA_8888;
}
else
{
if (bpp != 3)
{
g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Unsupported bits per pixel value '%d': "
"Clutter supports only a BPP value of 3 "
"for RGB data",
bpp);
return FALSE;
}
source_format = COGL_PIXEL_FORMAT_RGB_888;
}
if ((flags & CLUTTER_TEXTURE_RGB_FLAG_BGR))
source_format |= COGL_BGR_BIT;
if ((flags & CLUTTER_TEXTURE_RGB_FLAG_PREMULT))
source_format |= COGL_PREMULT_BIT;
return clutter_texture_set_from_data (texture, data, return clutter_texture_set_from_data (texture, data,
source_format, source_format,
width, height, width, height,
@ -1686,7 +1700,7 @@ clutter_texture_set_from_yuv_data (ClutterTexture *texture,
{ {
g_set_error (error, CLUTTER_TEXTURE_ERROR, g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_NO_YUV, CLUTTER_TEXTURE_ERROR_NO_YUV,
"YUV textures are not supported"); _("YUV textures are not supported"));
return FALSE; return FALSE;
} }
@ -1695,7 +1709,7 @@ clutter_texture_set_from_yuv_data (ClutterTexture *texture,
{ {
g_set_error (error, CLUTTER_TEXTURE_ERROR, g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT, CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"YUV2 textues are not supported"); _("YUV2 textues are not supported"));
return FALSE; return FALSE;
} }
@ -1950,7 +1964,7 @@ clutter_texture_async_load (ClutterTexture *self,
{ {
g_set_error (error, CLUTTER_TEXTURE_ERROR, g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT, CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Failed to create Cogl texture"); _("Failed to load the image data"));
return FALSE; return FALSE;
} }
else else
@ -2045,7 +2059,7 @@ clutter_texture_set_from_file (ClutterTexture *texture,
{ {
g_set_error (&internal_error, CLUTTER_TEXTURE_ERROR, g_set_error (&internal_error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT, CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Failed to create Cogl texture"); _("Failed to load the image data"));
} }
if (internal_error != NULL) if (internal_error != NULL)
@ -2291,37 +2305,12 @@ clutter_texture_set_area_from_rgb_data (ClutterTexture *texture,
CoglPixelFormat source_format; CoglPixelFormat source_format;
CoglHandle cogl_texture; CoglHandle cogl_texture;
if (has_alpha) if (!get_pixel_format_from_texture_flags (bpp, has_alpha, flags,
&source_format))
{ {
if (bpp != 4)
{
g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Unsupported BPP");
return FALSE; return FALSE;
} }
source_format = COGL_PIXEL_FORMAT_RGBA_8888;
}
else
{
if (bpp != 3)
{
g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Unsupported BPP");
return FALSE;
}
source_format = COGL_PIXEL_FORMAT_RGB_888;
}
if ((flags & CLUTTER_TEXTURE_RGB_FLAG_BGR))
source_format |= COGL_BGR_BIT;
if ((flags & CLUTTER_TEXTURE_RGB_FLAG_PREMULT))
source_format |= COGL_PREMULT_BIT;
/* attempt to realize ... */ /* attempt to realize ... */
if (!CLUTTER_ACTOR_IS_REALIZED (texture) && if (!CLUTTER_ACTOR_IS_REALIZED (texture) &&
clutter_actor_get_stage (CLUTTER_ACTOR (texture)) != NULL) clutter_actor_get_stage (CLUTTER_ACTOR (texture)) != NULL)
@ -2336,9 +2325,8 @@ clutter_texture_set_area_from_rgb_data (ClutterTexture *texture,
cogl_texture = clutter_texture_get_cogl_texture (texture); cogl_texture = clutter_texture_get_cogl_texture (texture);
if (cogl_texture == COGL_INVALID_HANDLE) if (cogl_texture == COGL_INVALID_HANDLE)
{ {
g_set_error (error, CLUTTER_TEXTURE_ERROR, g_warning ("Failed to realize actor '%s'",
CLUTTER_TEXTURE_ERROR_BAD_FORMAT, _clutter_actor_get_debug_name (CLUTTER_ACTOR (texture)));
"Failed to realize actor");
return FALSE; return FALSE;
} }
@ -2352,7 +2340,7 @@ clutter_texture_set_area_from_rgb_data (ClutterTexture *texture,
{ {
g_set_error (error, CLUTTER_TEXTURE_ERROR, g_set_error (error, CLUTTER_TEXTURE_ERROR,
CLUTTER_TEXTURE_ERROR_BAD_FORMAT, CLUTTER_TEXTURE_ERROR_BAD_FORMAT,
"Failed to upload Cogl texture data"); _("Failed to load the image data"));
return FALSE; return FALSE;
} }