From e27c63e41b75e2d516c5cd375f4eef14baaeff56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 19 Dec 2018 11:46:45 +0100 Subject: [PATCH] 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 --- cogl/cogl/cogl-atlas-texture.c | 3 ++- cogl/cogl/cogl-driver.h | 3 +++ cogl/cogl/cogl-sub-texture.c | 11 ++++++++++- cogl/cogl/cogl-texture-2d-sliced.c | 3 ++- cogl/cogl/cogl-texture-2d.c | 12 +++++++++++- cogl/cogl/cogl-texture-3d.c | 3 ++- cogl/cogl/cogl-texture-private.h | 2 ++ cogl/cogl/cogl-texture-rectangle.c | 3 ++- cogl/cogl/cogl-texture.c | 9 +++++++++ cogl/cogl/cogl-texture.h | 6 ++++++ cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h | 3 +++ cogl/cogl/driver/gl/cogl-texture-2d-gl.c | 9 +++++++++ cogl/cogl/driver/gl/gl/cogl-driver-gl.c | 1 + cogl/cogl/driver/gl/gles/cogl-driver-gles.c | 1 + cogl/cogl/driver/nop/cogl-driver-nop.c | 1 + cogl/cogl/winsys/cogl-texture-pixmap-x11.c | 3 ++- 16 files changed, 66 insertions(+), 7 deletions(-) diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index 97bb84a6a..1a1f99b11 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -1043,5 +1043,6 @@ cogl_atlas_texture_vtable = _cogl_atlas_texture_get_gl_format, _cogl_atlas_texture_get_type, NULL, /* is_foreign */ - NULL /* set_auto_mipmap */ + NULL, /* set_auto_mipmap */ + NULL /* is_get_data_supported */ }; diff --git a/cogl/cogl/cogl-driver.h b/cogl/cogl/cogl-driver.h index 85aa0d870..33a7598a9 100644 --- a/cogl/cogl/cogl-driver.h +++ b/cogl/cogl/cogl-driver.h @@ -210,6 +210,9 @@ struct _CoglDriverVtable int rowstride, uint8_t *data); + CoglBool + (* texture_2d_is_get_data_supported) (CoglTexture2D *tex_2d); + /* Prepares for drawing by flushing the journal, framebuffer state, * pipeline state and attribute state. */ diff --git a/cogl/cogl/cogl-sub-texture.c b/cogl/cogl/cogl-sub-texture.c index 9d7abea90..c3b436140 100644 --- a/cogl/cogl/cogl-sub-texture.c +++ b/cogl/cogl/cogl-sub-texture.c @@ -454,6 +454,14 @@ _cogl_sub_texture_get_type (CoglTexture *tex) return _cogl_texture_get_type (sub_tex->full_texture); } +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 const CoglTextureVtable cogl_sub_texture_vtable = { @@ -476,5 +484,6 @@ cogl_sub_texture_vtable = _cogl_sub_texture_get_gl_format, _cogl_sub_texture_get_type, NULL, /* is_foreign */ - NULL /* set_auto_mipmap */ + NULL, /* set_auto_mipmap */ + _cogl_sub_texture_is_get_data_supported }; diff --git a/cogl/cogl/cogl-texture-2d-sliced.c b/cogl/cogl/cogl-texture-2d-sliced.c index 4f586cde7..458b29ce5 100644 --- a/cogl/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl/cogl-texture-2d-sliced.c @@ -1542,5 +1542,6 @@ cogl_texture_2d_sliced_vtable = _cogl_texture_2d_sliced_get_gl_format, _cogl_texture_2d_sliced_get_type, _cogl_texture_2d_sliced_is_foreign, - NULL /* set_auto_mipmap */ + NULL, /* set_auto_mipmap */ + NULL /* is_get_data_supported */ }; diff --git a/cogl/cogl/cogl-texture-2d.c b/cogl/cogl/cogl-texture-2d.c index 663125890..0e4a73de0 100644 --- a/cogl/cogl/cogl-texture-2d.c +++ b/cogl/cogl/cogl-texture-2d.c @@ -94,6 +94,15 @@ _cogl_texture_2d_set_auto_mipmap (CoglTexture *tex, tex_2d->auto_mipmap = value; } +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); +} + CoglTexture2D * _cogl_texture_2d_create_base (CoglContext *ctx, int width, @@ -693,5 +702,6 @@ cogl_texture_2d_vtable = _cogl_texture_2d_get_gl_format, _cogl_texture_2d_get_type, _cogl_texture_2d_is_foreign, - _cogl_texture_2d_set_auto_mipmap + _cogl_texture_2d_set_auto_mipmap, + _cogl_texture_2d_is_get_data_supported }; diff --git a/cogl/cogl/cogl-texture-3d.c b/cogl/cogl/cogl-texture-3d.c index 5644119d7..00b3447ec 100644 --- a/cogl/cogl/cogl-texture-3d.c +++ b/cogl/cogl/cogl-texture-3d.c @@ -755,5 +755,6 @@ cogl_texture_3d_vtable = _cogl_texture_3d_get_gl_format, _cogl_texture_3d_get_type, NULL, /* is_foreign */ - _cogl_texture_3d_set_auto_mipmap + _cogl_texture_3d_set_auto_mipmap, + NULL /* is_get_data_supported */ }; diff --git a/cogl/cogl/cogl-texture-private.h b/cogl/cogl/cogl-texture-private.h index 742983e2d..44100f0b7 100644 --- a/cogl/cogl/cogl-texture-private.h +++ b/cogl/cogl/cogl-texture-private.h @@ -149,6 +149,8 @@ struct _CoglTextureVtable /* Only needs to be implemented if is_primitive == TRUE */ void (* set_auto_mipmap) (CoglTexture *texture, CoglBool value); + + CoglBool (* is_get_data_supported) (CoglTexture *texture); }; typedef enum _CoglTextureSoureType { diff --git a/cogl/cogl/cogl-texture-rectangle.c b/cogl/cogl/cogl-texture-rectangle.c index cc2e642d3..0179324a4 100644 --- a/cogl/cogl/cogl-texture-rectangle.c +++ b/cogl/cogl/cogl-texture-rectangle.c @@ -773,5 +773,6 @@ cogl_texture_rectangle_vtable = _cogl_texture_rectangle_get_gl_format, _cogl_texture_rectangle_get_type, _cogl_texture_rectangle_is_foreign, - _cogl_texture_rectangle_set_auto_mipmap + _cogl_texture_rectangle_set_auto_mipmap, + NULL /* is_get_data_supported */ }; diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index e2d37e225..eef2abdbe 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -205,6 +205,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) { diff --git a/cogl/cogl/cogl-texture.h b/cogl/cogl/cogl-texture.h index ef7d14281..67647aa9c 100644 --- a/cogl/cogl/cogl-texture.h +++ b/cogl/cogl/cogl-texture.h @@ -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); + COGL_END_DECLS #endif /* __COGL_TEXTURE_H__ */ diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h b/cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h index e5c658534..1379e9a93 100644 --- a/cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h +++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h @@ -116,4 +116,7 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d, int rowstride, uint8_t *data); +CoglBool +_cogl_texture_2d_gl_is_get_data_supported (CoglTexture2D *tex_2d); + #endif /* _COGL_TEXTURE_2D_GL_PRIVATE_H_ */ diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c index 2cf6fed51..f04e3ebca 100644 --- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c @@ -869,3 +869,12 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d, gl_type, data); } + +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; +} diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c index 178262ac0..9247e4e78 100644 --- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c @@ -714,6 +714,7 @@ _cogl_driver_gl = _cogl_texture_2d_gl_generate_mipmap, _cogl_texture_2d_gl_copy_from_bitmap, _cogl_texture_2d_gl_get_data, + _cogl_texture_2d_gl_is_get_data_supported, _cogl_gl_flush_attributes_state, _cogl_clip_stack_gl_flush, _cogl_buffer_gl_create, diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index 521f6ef3d..14f9b282c 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -493,6 +493,7 @@ _cogl_driver_gles = _cogl_texture_2d_gl_generate_mipmap, _cogl_texture_2d_gl_copy_from_bitmap, NULL, /* texture_2d_get_data */ + NULL, /* texture_2d_is_get_data_supported */ _cogl_gl_flush_attributes_state, _cogl_clip_stack_gl_flush, _cogl_buffer_gl_create, diff --git a/cogl/cogl/driver/nop/cogl-driver-nop.c b/cogl/cogl/driver/nop/cogl-driver-nop.c index 6e04e7164..8424c64ef 100644 --- a/cogl/cogl/driver/nop/cogl-driver-nop.c +++ b/cogl/cogl/driver/nop/cogl-driver-nop.c @@ -82,6 +82,7 @@ _cogl_driver_nop = _cogl_texture_2d_nop_generate_mipmap, _cogl_texture_2d_nop_copy_from_bitmap, NULL, /* texture_2d_get_data */ + NULL, /* texture_2d_is_get_data_supported */ _cogl_nop_flush_attributes_state, _cogl_clip_stack_nop_flush, }; diff --git a/cogl/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/cogl/winsys/cogl-texture-pixmap-x11.c index d03040c24..3bb057f4a 100644 --- a/cogl/cogl/winsys/cogl-texture-pixmap-x11.c +++ b/cogl/cogl/winsys/cogl-texture-pixmap-x11.c @@ -1180,5 +1180,6 @@ cogl_texture_pixmap_x11_vtable = _cogl_texture_pixmap_x11_get_gl_format, _cogl_texture_pixmap_x11_get_type, NULL, /* is_foreign */ - NULL /* set_auto_mipmap */ + NULL, /* set_auto_mipmap */ + NULL /* is_get_data_supported */ };