cogl/texture: Add a is_allocated helper

Reduce the usage of direct access of Texture struct fields, so we can
migrate to using macros in the future.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4100>
This commit is contained in:
Bilal Elmoussaoui 2024-10-20 10:54:11 +02:00 committed by Marge Bot
parent 7d5f1b5898
commit cc3bf059e6
3 changed files with 16 additions and 8 deletions

View File

@ -746,7 +746,7 @@ _cogl_texture_2d_sliced_is_sliced (CoglTexture *tex)
/* It's only after allocating a sliced texture that we will know
* whether it really needed to be sliced... */
if (!tex->allocated)
if (!cogl_texture_is_allocated (tex))
cogl_texture_allocate (tex, NULL);
if (tex_2ds->slice_x_spans->len != 1 ||

View File

@ -337,3 +337,5 @@ cogl_texture_get_max_level_set (CoglTexture *texture);
void
cogl_texture_set_max_level_set (CoglTexture *texture,
int max_level_set);
gboolean cogl_texture_is_allocated (CoglTexture *texture);

View File

@ -258,7 +258,7 @@ cogl_texture_get_height (CoglTexture *texture)
CoglPixelFormat
cogl_texture_get_format (CoglTexture *texture)
{
if (!texture->allocated)
if (!cogl_texture_is_allocated (texture))
cogl_texture_allocate (texture, NULL);
return COGL_TEXTURE_GET_CLASS (texture)->get_format (texture);
@ -324,7 +324,7 @@ cogl_texture_is_sliced (CoglTexture *texture)
{
g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
if (!texture->allocated)
if (!cogl_texture_is_allocated (texture))
cogl_texture_allocate (texture, NULL);
return COGL_TEXTURE_GET_CLASS (texture)->is_sliced (texture);
@ -337,7 +337,7 @@ cogl_texture_is_sliced (CoglTexture *texture)
gboolean
_cogl_texture_can_hardware_repeat (CoglTexture *texture)
{
if (!texture->allocated)
if (!cogl_texture_is_allocated (texture))
cogl_texture_allocate (texture, NULL);
return COGL_TEXTURE_GET_CLASS (texture)->can_hardware_repeat (texture);
}
@ -349,7 +349,7 @@ cogl_texture_get_gl_texture (CoglTexture *texture,
{
g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
if (!texture->allocated)
if (!cogl_texture_is_allocated (texture))
cogl_texture_allocate (texture, NULL);
return COGL_TEXTURE_GET_CLASS (texture)->get_gl_texture (texture,
@ -1100,13 +1100,19 @@ _cogl_texture_set_allocated (CoglTexture *texture,
_cogl_texture_free_loader (texture);
}
gboolean
cogl_texture_is_allocated (CoglTexture *texture)
{
return texture->allocated;
}
gboolean
cogl_texture_allocate (CoglTexture *texture,
GError **error)
{
g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
if (texture->allocated)
if (cogl_texture_is_allocated (texture))
return TRUE;
if (texture->components == COGL_TEXTURE_COMPONENTS_RG &&
@ -1220,7 +1226,7 @@ cogl_texture_set_components (CoglTexture *texture,
CoglTextureComponents components)
{
g_return_if_fail (COGL_IS_TEXTURE (texture));
g_return_if_fail (!texture->allocated);
g_return_if_fail (!cogl_texture_is_allocated (texture));
if (texture->components == components)
return;
@ -1241,7 +1247,7 @@ cogl_texture_set_premultiplied (CoglTexture *texture,
gboolean premultiplied)
{
g_return_if_fail (COGL_IS_TEXTURE (texture));
g_return_if_fail (!texture->allocated);
g_return_if_fail (!cogl_texture_is_allocated (texture));
premultiplied = !!premultiplied;