cogl/texture: Type check introspected calls
CoglTexture can be used by e.g. Javascript, and the convention is to be more forgiving regarding passed input so that invalid Javascript calls doesn't cause actual SIGSEGV/SIGABRT. As elsewhere, do this by sprinkeling g_return(_val)_if_fail() on introspected functions. Related: https://bugzilla.redhat.com/show_bug.cgi?id=2124322 Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2616>
This commit is contained in:
parent
89b8edcc6f
commit
9117419940
@ -197,12 +197,16 @@ cogl_texture_is_get_data_supported (CoglTexture *texture)
|
|||||||
unsigned int
|
unsigned int
|
||||||
cogl_texture_get_width (CoglTexture *texture)
|
cogl_texture_get_width (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), 0);
|
||||||
|
|
||||||
return texture->width;
|
return texture->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
cogl_texture_get_height (CoglTexture *texture)
|
cogl_texture_get_height (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), 0);
|
||||||
|
|
||||||
return texture->height;
|
return texture->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,6 +221,8 @@ _cogl_texture_get_format (CoglTexture *texture)
|
|||||||
int
|
int
|
||||||
cogl_texture_get_max_waste (CoglTexture *texture)
|
cogl_texture_get_max_waste (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), 0);
|
||||||
|
|
||||||
return texture->vtable->get_max_waste (texture);
|
return texture->vtable->get_max_waste (texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +278,8 @@ _cogl_texture_get_level_size (CoglTexture *texture,
|
|||||||
gboolean
|
gboolean
|
||||||
cogl_texture_is_sliced (CoglTexture *texture)
|
cogl_texture_is_sliced (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
|
|
||||||
if (!texture->allocated)
|
if (!texture->allocated)
|
||||||
cogl_texture_allocate (texture, NULL);
|
cogl_texture_allocate (texture, NULL);
|
||||||
return texture->vtable->is_sliced (texture);
|
return texture->vtable->is_sliced (texture);
|
||||||
@ -312,6 +320,8 @@ cogl_texture_get_gl_texture (CoglTexture *texture,
|
|||||||
GLuint *out_gl_handle,
|
GLuint *out_gl_handle,
|
||||||
GLenum *out_gl_target)
|
GLenum *out_gl_target)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
|
|
||||||
if (!texture->allocated)
|
if (!texture->allocated)
|
||||||
cogl_texture_allocate (texture, NULL);
|
cogl_texture_allocate (texture, NULL);
|
||||||
|
|
||||||
@ -393,14 +403,17 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
|
|||||||
CoglBitmap *bitmap)
|
CoglBitmap *bitmap)
|
||||||
{
|
{
|
||||||
GError *ignore_error = NULL;
|
GError *ignore_error = NULL;
|
||||||
gboolean status =
|
gboolean status;
|
||||||
_cogl_texture_set_region_from_bitmap (texture,
|
|
||||||
src_x, src_y,
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
dst_width, dst_height,
|
|
||||||
bitmap,
|
status = _cogl_texture_set_region_from_bitmap (texture,
|
||||||
dst_x, dst_y,
|
src_x, src_y,
|
||||||
0, /* level */
|
dst_width, dst_height,
|
||||||
&ignore_error);
|
bitmap,
|
||||||
|
dst_x, dst_y,
|
||||||
|
0, /* level */
|
||||||
|
&ignore_error);
|
||||||
|
|
||||||
g_clear_error (&ignore_error);
|
g_clear_error (&ignore_error);
|
||||||
return status;
|
return status;
|
||||||
@ -468,6 +481,7 @@ cogl_texture_set_region (CoglTexture *texture,
|
|||||||
int bytes_per_pixel;
|
int bytes_per_pixel;
|
||||||
gboolean status;
|
gboolean status;
|
||||||
|
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, FALSE);
|
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, FALSE);
|
||||||
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, FALSE);
|
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, FALSE);
|
||||||
|
|
||||||
@ -503,6 +517,8 @@ cogl_texture_set_data (CoglTexture *texture,
|
|||||||
int level_width;
|
int level_width;
|
||||||
int level_height;
|
int level_height;
|
||||||
|
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
|
|
||||||
_cogl_texture_get_level_size (texture,
|
_cogl_texture_get_level_size (texture,
|
||||||
level,
|
level,
|
||||||
&level_width,
|
&level_width,
|
||||||
@ -723,7 +739,7 @@ cogl_texture_get_data (CoglTexture *texture,
|
|||||||
unsigned int rowstride,
|
unsigned int rowstride,
|
||||||
uint8_t *data)
|
uint8_t *data)
|
||||||
{
|
{
|
||||||
CoglContext *ctx = texture->context;
|
CoglContext *ctx;
|
||||||
int bpp;
|
int bpp;
|
||||||
int byte_size;
|
int byte_size;
|
||||||
CoglPixelFormat closest_format;
|
CoglPixelFormat closest_format;
|
||||||
@ -734,9 +750,10 @@ cogl_texture_get_data (CoglTexture *texture,
|
|||||||
int tex_height;
|
int tex_height;
|
||||||
CoglPixelFormat texture_format;
|
CoglPixelFormat texture_format;
|
||||||
GError *ignore_error = NULL;
|
GError *ignore_error = NULL;
|
||||||
|
|
||||||
CoglTextureGetData tg_data;
|
CoglTextureGetData tg_data;
|
||||||
|
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), 0);
|
||||||
|
|
||||||
texture_format = _cogl_texture_get_format (texture);
|
texture_format = _cogl_texture_get_format (texture);
|
||||||
|
|
||||||
/* Default to internal format if none specified */
|
/* Default to internal format if none specified */
|
||||||
@ -759,6 +776,7 @@ cogl_texture_get_data (CoglTexture *texture,
|
|||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return byte_size;
|
return byte_size;
|
||||||
|
|
||||||
|
ctx = texture->context;
|
||||||
closest_format =
|
closest_format =
|
||||||
ctx->texture_driver->find_best_gl_get_data_format (ctx,
|
ctx->texture_driver->find_best_gl_get_data_format (ctx,
|
||||||
format,
|
format,
|
||||||
@ -1063,6 +1081,8 @@ gboolean
|
|||||||
cogl_texture_allocate (CoglTexture *texture,
|
cogl_texture_allocate (CoglTexture *texture,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
|
|
||||||
if (texture->allocated)
|
if (texture->allocated)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
@ -1176,6 +1196,7 @@ void
|
|||||||
cogl_texture_set_components (CoglTexture *texture,
|
cogl_texture_set_components (CoglTexture *texture,
|
||||||
CoglTextureComponents components)
|
CoglTextureComponents components)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail (cogl_is_texture (texture));
|
||||||
g_return_if_fail (!texture->allocated);
|
g_return_if_fail (!texture->allocated);
|
||||||
|
|
||||||
if (texture->components == components)
|
if (texture->components == components)
|
||||||
@ -1187,6 +1208,8 @@ cogl_texture_set_components (CoglTexture *texture,
|
|||||||
CoglTextureComponents
|
CoglTextureComponents
|
||||||
cogl_texture_get_components (CoglTexture *texture)
|
cogl_texture_get_components (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), 0);
|
||||||
|
|
||||||
return texture->components;
|
return texture->components;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1194,6 +1217,7 @@ void
|
|||||||
cogl_texture_set_premultiplied (CoglTexture *texture,
|
cogl_texture_set_premultiplied (CoglTexture *texture,
|
||||||
gboolean premultiplied)
|
gboolean premultiplied)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail (cogl_is_texture (texture));
|
||||||
g_return_if_fail (!texture->allocated);
|
g_return_if_fail (!texture->allocated);
|
||||||
|
|
||||||
premultiplied = !!premultiplied;
|
premultiplied = !!premultiplied;
|
||||||
@ -1207,6 +1231,8 @@ cogl_texture_set_premultiplied (CoglTexture *texture,
|
|||||||
gboolean
|
gboolean
|
||||||
cogl_texture_get_premultiplied (CoglTexture *texture)
|
cogl_texture_get_premultiplied (CoglTexture *texture)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (cogl_is_texture (texture), FALSE);
|
||||||
|
|
||||||
return texture->premultiplied;
|
return texture->premultiplied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user