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



commit eac18647c37d59134a56508eca34ccdd04103786
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed Dec 19 11:46:45 2018 +0100

    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                   |  1 +
 cogl/cogl/cogl-driver.h                          |  3 +++
 cogl/cogl/cogl-sub-texture.c                     |  9 +++++++++
 cogl/cogl/cogl-texture-2d-sliced.c               |  1 +
 cogl/cogl/cogl-texture-2d.c                      | 10 ++++++++++
 cogl/cogl/cogl-texture-3d.c                      |  1 +
 cogl/cogl/cogl-texture-private.h                 |  2 ++
 cogl/cogl/cogl-texture-rectangle.c               |  1 +
 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       |  1 +
 16 files changed, 59 insertions(+)
---
diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c
index cae8650e7..a77fcd91f 100644
--- a/cogl/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl/cogl-atlas-texture.c
@@ -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,
diff --git a/cogl/cogl/cogl-driver.h b/cogl/cogl/cogl-driver.h
index 85aa0d870..2abc0df45 100644
--- a/cogl/cogl/cogl-driver.h
+++ b/cogl/cogl/cogl-driver.h
@@ -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.
    *
diff --git a/cogl/cogl/cogl-sub-texture.c b/cogl/cogl/cogl-sub-texture.c
index 2f803babc..b33ea52ae 100644
--- a/cogl/cogl/cogl-sub-texture.c
+++ b/cogl/cogl/cogl-sub-texture.c
@@ -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,
diff --git a/cogl/cogl/cogl-texture-2d-sliced.c b/cogl/cogl/cogl-texture-2d-sliced.c
index 4d5209dc2..3e276f9f0 100644
--- a/cogl/cogl/cogl-texture-2d-sliced.c
+++ b/cogl/cogl/cogl-texture-2d-sliced.c
@@ -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,
diff --git a/cogl/cogl/cogl-texture-2d.c b/cogl/cogl/cogl-texture-2d.c
index 65ba5114b..52fab8213 100644
--- a/cogl/cogl/cogl-texture-2d.c
+++ b/cogl/cogl/cogl-texture-2d.c
@@ -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,
diff --git a/cogl/cogl/cogl-texture-3d.c b/cogl/cogl/cogl-texture-3d.c
index d6bc683a6..0d59f771c 100644
--- a/cogl/cogl/cogl-texture-3d.c
+++ b/cogl/cogl/cogl-texture-3d.c
@@ -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,
diff --git a/cogl/cogl/cogl-texture-private.h b/cogl/cogl/cogl-texture-private.h
index 742983e2d..27406827b 100644
--- a/cogl/cogl/cogl-texture-private.h
+++ b/cogl/cogl/cogl-texture-private.h
@@ -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
diff --git a/cogl/cogl/cogl-texture-rectangle.c b/cogl/cogl/cogl-texture-rectangle.c
index 8db7d75dc..e6d58eff1 100644
--- a/cogl/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl/cogl-texture-rectangle.c
@@ -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,
diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c
index c142221fa..918f1ccf7 100644
--- a/cogl/cogl/cogl-texture.c
+++ b/cogl/cogl/cogl-texture.c
@@ -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)
 {
diff --git a/cogl/cogl/cogl-texture.h b/cogl/cogl/cogl-texture.h
index 350d02dac..3a07e8545 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);
+
 G_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..9f77bf99f 100644
--- a/cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h
+++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl-private.h
@@ -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,
diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
index d806ee123..a501be3d1 100644
--- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
+++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
@@ -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,
diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
index f7454aa07..2a0392be8 100644
--- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
+++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
@@ -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,
diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
index cc20a0bd6..38d2f7b8b 100644
--- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
+++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
@@ -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,
diff --git a/cogl/cogl/driver/nop/cogl-driver-nop.c b/cogl/cogl/driver/nop/cogl-driver-nop.c
index cdde59b56..0421df85b 100644
--- a/cogl/cogl/driver/nop/cogl-driver-nop.c
+++ b/cogl/cogl/driver/nop/cogl-driver-nop.c
@@ -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,
diff --git a/cogl/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/cogl/winsys/cogl-texture-pixmap-x11.c
index 18e328632..74ed671a8 100644
--- a/cogl/cogl/winsys/cogl-texture-pixmap-x11.c
+++ b/cogl/cogl/winsys/cogl-texture-pixmap-x11.c
@@ -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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]