summaryrefslogtreecommitdiff
path: root/cogl
diff options
context:
space:
mode:
authorJonas Ã…dahl <jadahl@gmail.com>2022-09-06 12:27:24 +0200
committerMarge Bot <marge-bot@gnome.org>2022-09-20 13:38:41 +0000
commit911741994066fa52aef0f51aa25412649c49c98b (patch)
tree248de1eb17bcbfa2a3025d6636d11fd1298f8869 /cogl
parent89b8edcc6faefb5d2788bb5fa6d91b92181a4cde (diff)
downloadmutter-911741994066fa52aef0f51aa25412649c49c98b.tar.gz
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>
Diffstat (limited to 'cogl')
-rw-r--r--cogl/cogl/cogl-texture.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c
index 0206caac3..880454f68 100644
--- a/cogl/cogl/cogl-texture.c
+++ b/cogl/cogl/cogl-texture.c
@@ -197,12 +197,16 @@ cogl_texture_is_get_data_supported (CoglTexture *texture)
unsigned int
cogl_texture_get_width (CoglTexture *texture)
{
+ g_return_val_if_fail (cogl_is_texture (texture), 0);
+
return texture->width;
}
unsigned int
cogl_texture_get_height (CoglTexture *texture)
{
+ g_return_val_if_fail (cogl_is_texture (texture), 0);
+
return texture->height;
}
@@ -217,6 +221,8 @@ _cogl_texture_get_format (CoglTexture *texture)
int
cogl_texture_get_max_waste (CoglTexture *texture)
{
+ g_return_val_if_fail (cogl_is_texture (texture), 0);
+
return texture->vtable->get_max_waste (texture);
}
@@ -272,6 +278,8 @@ _cogl_texture_get_level_size (CoglTexture *texture,
gboolean
cogl_texture_is_sliced (CoglTexture *texture)
{
+ g_return_val_if_fail (cogl_is_texture (texture), FALSE);
+
if (!texture->allocated)
cogl_texture_allocate (texture, NULL);
return texture->vtable->is_sliced (texture);
@@ -312,6 +320,8 @@ cogl_texture_get_gl_texture (CoglTexture *texture,
GLuint *out_gl_handle,
GLenum *out_gl_target)
{
+ g_return_val_if_fail (cogl_is_texture (texture), FALSE);
+
if (!texture->allocated)
cogl_texture_allocate (texture, NULL);
@@ -393,14 +403,17 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
CoglBitmap *bitmap)
{
GError *ignore_error = NULL;
- gboolean status =
- _cogl_texture_set_region_from_bitmap (texture,
- src_x, src_y,
- dst_width, dst_height,
- bitmap,
- dst_x, dst_y,
- 0, /* level */
- &ignore_error);
+ gboolean status;
+
+ g_return_val_if_fail (cogl_is_texture (texture), FALSE);
+
+ status = _cogl_texture_set_region_from_bitmap (texture,
+ src_x, src_y,
+ dst_width, dst_height,
+ bitmap,
+ dst_x, dst_y,
+ 0, /* level */
+ &ignore_error);
g_clear_error (&ignore_error);
return status;
@@ -468,6 +481,7 @@ cogl_texture_set_region (CoglTexture *texture,
int bytes_per_pixel;
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 (cogl_pixel_format_get_n_planes (format) == 1, FALSE);
@@ -503,6 +517,8 @@ cogl_texture_set_data (CoglTexture *texture,
int level_width;
int level_height;
+ g_return_val_if_fail (cogl_is_texture (texture), FALSE);
+
_cogl_texture_get_level_size (texture,
level,
&level_width,
@@ -723,7 +739,7 @@ cogl_texture_get_data (CoglTexture *texture,
unsigned int rowstride,
uint8_t *data)
{
- CoglContext *ctx = texture->context;
+ CoglContext *ctx;
int bpp;
int byte_size;
CoglPixelFormat closest_format;
@@ -734,9 +750,10 @@ cogl_texture_get_data (CoglTexture *texture,
int tex_height;
CoglPixelFormat texture_format;
GError *ignore_error = NULL;
-
CoglTextureGetData tg_data;
+ g_return_val_if_fail (cogl_is_texture (texture), 0);
+
texture_format = _cogl_texture_get_format (texture);
/* Default to internal format if none specified */
@@ -759,6 +776,7 @@ cogl_texture_get_data (CoglTexture *texture,
if (data == NULL)
return byte_size;
+ ctx = texture->context;
closest_format =
ctx->texture_driver->find_best_gl_get_data_format (ctx,
format,
@@ -1063,6 +1081,8 @@ gboolean
cogl_texture_allocate (CoglTexture *texture,
GError **error)
{
+ g_return_val_if_fail (cogl_is_texture (texture), FALSE);
+
if (texture->allocated)
return TRUE;
@@ -1176,6 +1196,7 @@ void
cogl_texture_set_components (CoglTexture *texture,
CoglTextureComponents components)
{
+ g_return_if_fail (cogl_is_texture (texture));
g_return_if_fail (!texture->allocated);
if (texture->components == components)
@@ -1187,6 +1208,8 @@ cogl_texture_set_components (CoglTexture *texture,
CoglTextureComponents
cogl_texture_get_components (CoglTexture *texture)
{
+ g_return_val_if_fail (cogl_is_texture (texture), 0);
+
return texture->components;
}
@@ -1194,6 +1217,7 @@ void
cogl_texture_set_premultiplied (CoglTexture *texture,
gboolean premultiplied)
{
+ g_return_if_fail (cogl_is_texture (texture));
g_return_if_fail (!texture->allocated);
premultiplied = !!premultiplied;
@@ -1207,6 +1231,8 @@ cogl_texture_set_premultiplied (CoglTexture *texture,
gboolean
cogl_texture_get_premultiplied (CoglTexture *texture)
{
+ g_return_val_if_fail (cogl_is_texture (texture), FALSE);
+
return texture->premultiplied;
}