cogl/texture: Add API to check whether _get_data() will work

Currently, GL_TEXTURE_EXTERNAL_OES textures doesn't support getting pixel data.
Make it possible for texture users to know this.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/362
This commit is contained in:
Jonas Ådahl 2018-12-19 11:46:45 +01:00 committed by Georges Basile Stavracas Neto
parent c681ccef3c
commit eac18647c3
16 changed files with 59 additions and 0 deletions

View File

@ -1025,6 +1025,7 @@ cogl_atlas_texture_vtable =
FALSE, /* not primitive */
_cogl_atlas_texture_allocate,
_cogl_atlas_texture_set_region,
NULL, /* is_get_data_supported */
NULL, /* get_data */
_cogl_atlas_texture_foreach_sub_texture_in_region,
_cogl_atlas_texture_get_max_waste,

View File

@ -199,6 +199,9 @@ struct _CoglDriverVtable
int level,
CoglError **error);
CoglBool
(* texture_2d_is_get_data_supported) (CoglTexture2D *tex_2d);
/* Reads back the full contents of the given texture and write it to
* @data in the given @format and with the given @rowstride.
*

View File

@ -428,6 +428,14 @@ _cogl_sub_texture_set_region (CoglTexture *tex,
error);
}
static CoglBool
_cogl_sub_texture_is_get_data_supported (CoglTexture *tex)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
return cogl_texture_is_get_data_supported (sub_tex->full_texture);
}
static CoglPixelFormat
_cogl_sub_texture_get_format (CoglTexture *tex)
{
@ -458,6 +466,7 @@ cogl_sub_texture_vtable =
FALSE, /* not primitive */
_cogl_sub_texture_allocate,
_cogl_sub_texture_set_region,
_cogl_sub_texture_is_get_data_supported,
NULL, /* get_data */
_cogl_sub_texture_foreach_sub_texture_in_region,
_cogl_sub_texture_get_max_waste,

View File

@ -1524,6 +1524,7 @@ cogl_texture_2d_sliced_vtable =
FALSE, /* not primitive */
_cogl_texture_2d_sliced_allocate,
_cogl_texture_2d_sliced_set_region,
NULL, /* is_get_data_supported */
NULL, /* get_data */
_cogl_texture_2d_sliced_foreach_sub_texture_in_region,
_cogl_texture_2d_sliced_get_max_waste,

View File

@ -629,6 +629,15 @@ _cogl_texture_2d_set_region (CoglTexture *tex,
return TRUE;
}
static CoglBool
_cogl_texture_2d_is_get_data_supported (CoglTexture *tex)
{
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
CoglContext *ctx = tex->context;
return ctx->driver_vtable->texture_2d_is_get_data_supported (tex_2d);
}
static CoglBool
_cogl_texture_2d_get_data (CoglTexture *tex,
CoglPixelFormat format,
@ -677,6 +686,7 @@ cogl_texture_2d_vtable =
TRUE, /* primitive */
_cogl_texture_2d_allocate,
_cogl_texture_2d_set_region,
_cogl_texture_2d_is_get_data_supported,
_cogl_texture_2d_get_data,
NULL, /* foreach_sub_texture_in_region */
_cogl_texture_2d_get_max_waste,

View File

@ -737,6 +737,7 @@ cogl_texture_3d_vtable =
TRUE, /* primitive */
_cogl_texture_3d_allocate,
_cogl_texture_3d_set_region,
NULL, /* is_get_data_supported */
_cogl_texture_3d_get_data,
NULL, /* foreach_sub_texture_in_region */
_cogl_texture_3d_get_max_waste,

View File

@ -91,6 +91,8 @@ struct _CoglTextureVtable
CoglBitmap *bitmap,
CoglError **error);
CoglBool (* is_get_data_supported) (CoglTexture *texture);
/* This should copy the image data of the texture into @data. The
requested format will have been first passed through
ctx->texture_driver->find_best_gl_get_data_format so it should

View File

@ -755,6 +755,7 @@ cogl_texture_rectangle_vtable =
TRUE, /* primitive */
_cogl_texture_rectangle_allocate,
_cogl_texture_rectangle_set_region,
NULL, /* is_get_data_supported */
_cogl_texture_rectangle_get_data,
NULL, /* foreach_sub_texture_in_region */
_cogl_texture_rectangle_get_max_waste,

View File

@ -203,6 +203,15 @@ _cogl_texture_is_foreign (CoglTexture *texture)
return FALSE;
}
CoglBool
cogl_texture_is_get_data_supported (CoglTexture *texture)
{
if (texture->vtable->is_get_data_supported)
return texture->vtable->is_get_data_supported (texture);
else
return TRUE;
}
unsigned int
cogl_texture_get_width (CoglTexture *texture)
{

View File

@ -511,6 +511,12 @@ CoglBool
cogl_texture_allocate (CoglTexture *texture,
CoglError **error);
/**
* cogl_texture_is_get_data_supported: (skip)
*/
CoglBool
cogl_texture_is_get_data_supported (CoglTexture *texture);
G_END_DECLS
#endif /* __COGL_TEXTURE_H__ */

View File

@ -110,6 +110,9 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
int level,
CoglError **error);
CoglBool
_cogl_texture_2d_gl_is_get_data_supported (CoglTexture2D *tex_2d);
void
_cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
CoglPixelFormat format,

View File

@ -838,6 +838,15 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
return status;
}
CoglBool
_cogl_texture_2d_gl_is_get_data_supported (CoglTexture2D *tex_2d)
{
if (tex_2d->gl_target == GL_TEXTURE_EXTERNAL_OES)
return FALSE;
else
return TRUE;
}
void
_cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
CoglPixelFormat format,

View File

@ -705,6 +705,7 @@ _cogl_driver_gl =
_cogl_texture_2d_gl_get_gl_handle,
_cogl_texture_2d_gl_generate_mipmap,
_cogl_texture_2d_gl_copy_from_bitmap,
_cogl_texture_2d_gl_is_get_data_supported,
_cogl_texture_2d_gl_get_data,
_cogl_gl_flush_attributes_state,
_cogl_clip_stack_gl_flush,

View File

@ -469,6 +469,7 @@ _cogl_driver_gles =
_cogl_texture_2d_gl_get_gl_handle,
_cogl_texture_2d_gl_generate_mipmap,
_cogl_texture_2d_gl_copy_from_bitmap,
NULL, /* texture_2d_is_get_data_supported */
NULL, /* texture_2d_get_data */
_cogl_gl_flush_attributes_state,
_cogl_clip_stack_gl_flush,

View File

@ -79,6 +79,7 @@ _cogl_driver_nop =
_cogl_texture_2d_nop_get_gl_handle,
_cogl_texture_2d_nop_generate_mipmap,
_cogl_texture_2d_nop_copy_from_bitmap,
NULL, /* texture_2d_is_get_data_supported */
NULL, /* texture_2d_get_data */
_cogl_nop_flush_attributes_state,
_cogl_clip_stack_nop_flush,

View File

@ -1162,6 +1162,7 @@ cogl_texture_pixmap_x11_vtable =
FALSE, /* not primitive */
_cogl_texture_pixmap_x11_allocate,
_cogl_texture_pixmap_x11_set_region,
NULL, /* is_get_data_supported */
_cogl_texture_pixmap_x11_get_data,
_cogl_texture_pixmap_x11_foreach_sub_texture_in_region,
_cogl_texture_pixmap_x11_get_max_waste,