Blame SOURCES/0003-texture-support-copy_sub_image.patch

b5e56d
From d8b34ab0604d80d0be22b8b78e9aa6bf4fac7db0 Mon Sep 17 00:00:00 2001
b5e56d
From: Sian Cao <yinshuiboy@gmail.com>
b5e56d
Date: Thu, 27 Oct 2016 15:19:32 +0800
b5e56d
Subject: texture: Support copy_sub_image
b5e56d
b5e56d
The patch is used to implement feature similar with kwin blur effect
b5e56d
by being abel to copy partial of framebuffer contents as texture and
b5e56d
do post blurring.
b5e56d
b5e56d
Signed-off-by:
b5e56d
 Sian Cao <yinshuiboy@gmail.com>: initial
b5e56d
 Bowen Li <sensor.wen@gmail.com>: fix coding style
b5e56d
b5e56d
---
b5e56d
 cogl/cogl-atlas-texture.c                   |  1 +
b5e56d
 cogl/cogl-driver.h                          | 10 ++++++++
b5e56d
 cogl/cogl-sub-texture.c                     |  1 +
b5e56d
 cogl/cogl-texture-2d-sliced.c               |  1 +
b5e56d
 cogl/cogl-texture-2d.c                      | 30 ++++++++++++++++++++++
b5e56d
 cogl/cogl-texture-3d.c                      |  1 +
b5e56d
 cogl/cogl-texture-private.h                 |  9 +++++++
b5e56d
 cogl/cogl-texture-rectangle.c               |  1 +
b5e56d
 cogl/cogl-texture.c                         | 33 ++++++++++++++++++++++++
b5e56d
 cogl/cogl-texture.h                         |  9 +++++++
b5e56d
 cogl/driver/gl/cogl-texture-2d-gl-private.h |  9 +++++++
b5e56d
 cogl/driver/gl/cogl-texture-2d-gl.c         | 39 +++++++++++++++++++++++++++++
b5e56d
 cogl/driver/gl/gl/cogl-driver-gl.c          |  1 +
b5e56d
 cogl/driver/gl/gles/cogl-driver-gles.c      |  1 +
b5e56d
 cogl/driver/nop/cogl-driver-nop.c           |  1 +
b5e56d
 cogl/winsys/cogl-texture-pixmap-x11.c       |  1 +
b5e56d
 16 files changed, 148 insertions(+)
b5e56d
b5e56d
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
b5e56d
index 1c8b569..e411302 100644
b5e56d
--- a/cogl/cogl-atlas-texture.c
b5e56d
+++ b/cogl/cogl-atlas-texture.c
b5e56d
@@ -1027,6 +1027,7 @@ cogl_atlas_texture_vtable =
b5e56d
     FALSE, /* not primitive */
b5e56d
     _cogl_atlas_texture_allocate,
b5e56d
     _cogl_atlas_texture_set_region,
b5e56d
+    NULL, /* copy_sub_image */
b5e56d
     NULL, /* get_data */
b5e56d
     _cogl_atlas_texture_foreach_sub_texture_in_region,
b5e56d
     _cogl_atlas_texture_get_max_waste,
b5e56d
diff --git a/cogl/cogl-driver.h b/cogl/cogl-driver.h
b5e56d
index 648228c..4a0aeaf 100644
b5e56d
--- a/cogl/cogl-driver.h
b5e56d
+++ b/cogl/cogl-driver.h
b5e56d
@@ -192,6 +192,16 @@ struct _CoglDriverVtable
b5e56d
                                    int level,
b5e56d
                                    CoglError **error);
b5e56d
 
b5e56d
+  CoglBool
b5e56d
+  (* texture_2d_copy_sub_image) (CoglTexture2D *tex_2d,
b5e56d
+                                 GLint xoffset,
b5e56d
+                                 GLint yoffset,
b5e56d
+                                 GLint x,
b5e56d
+                                 GLint y,
b5e56d
+                                 GLsizei width,
b5e56d
+                                 GLsizei height,
b5e56d
+                                 CoglError **error);
b5e56d
+
b5e56d
   /* Reads back the full contents of the given texture and write it to
b5e56d
    * @data in the given @format and with the given @rowstride.
b5e56d
    *
b5e56d
diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c
b5e56d
index 7baf95e..0a16193 100644
b5e56d
--- a/cogl/cogl-sub-texture.c
b5e56d
+++ b/cogl/cogl-sub-texture.c
b5e56d
@@ -460,6 +460,7 @@ cogl_sub_texture_vtable =
b5e56d
     FALSE, /* not primitive */
b5e56d
     _cogl_sub_texture_allocate,
b5e56d
     _cogl_sub_texture_set_region,
b5e56d
+    NULL, /* copy_sub_image */
b5e56d
     NULL, /* get_data */
b5e56d
     _cogl_sub_texture_foreach_sub_texture_in_region,
b5e56d
     _cogl_sub_texture_get_max_waste,
b5e56d
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c
b5e56d
index e76bef6..b0b099f 100644
b5e56d
--- a/cogl/cogl-texture-2d-sliced.c
b5e56d
+++ b/cogl/cogl-texture-2d-sliced.c
b5e56d
@@ -1526,6 +1526,7 @@ cogl_texture_2d_sliced_vtable =
b5e56d
     FALSE, /* not primitive */
b5e56d
     _cogl_texture_2d_sliced_allocate,
b5e56d
     _cogl_texture_2d_sliced_set_region,
b5e56d
+    NULL, /* copy_sub_image */
b5e56d
     NULL, /* get_data */
b5e56d
     _cogl_texture_2d_sliced_foreach_sub_texture_in_region,
b5e56d
     _cogl_texture_2d_sliced_get_max_waste,
b5e56d
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
b5e56d
index cc28cd9..d9ab188 100644
b5e56d
--- a/cogl/cogl-texture-2d.c
b5e56d
+++ b/cogl/cogl-texture-2d.c
b5e56d
@@ -628,6 +628,35 @@ _cogl_texture_2d_set_region (CoglTexture *tex,
b5e56d
 }
b5e56d
 
b5e56d
 static CoglBool
b5e56d
+_cogl_texture_2d_copy_sub_image (CoglTexture *tex,
b5e56d
+                                 GLint xoffset,
b5e56d
+                                 GLint yoffset,
b5e56d
+                                 GLint x,
b5e56d
+                                 GLint y,
b5e56d
+                                 GLsizei width,
b5e56d
+                                 GLsizei height,
b5e56d
+                                 CoglError **error)
b5e56d
+{
b5e56d
+  CoglContext *ctx = tex->context;
b5e56d
+  CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
b5e56d
+
b5e56d
+  cogl_texture_allocate (tex, NULL); /* (abort on error) */
b5e56d
+
b5e56d
+  ctx->driver_vtable->texture_2d_copy_sub_image (tex_2d,
b5e56d
+                                                 xoffset,
b5e56d
+                                                 yoffset,
b5e56d
+                                                 x,
b5e56d
+                                                 y,
b5e56d
+                                                 width,
b5e56d
+                                                 height,
b5e56d
+                                                 error);
b5e56d
+
b5e56d
+  tex_2d->mipmaps_dirty = TRUE;
b5e56d
+
b5e56d
+  return TRUE;
b5e56d
+}
b5e56d
+
b5e56d
+static CoglBool
b5e56d
 _cogl_texture_2d_get_data (CoglTexture *tex,
b5e56d
                            CoglPixelFormat format,
b5e56d
                            int rowstride,
b5e56d
@@ -675,6 +704,7 @@ cogl_texture_2d_vtable =
b5e56d
     TRUE, /* primitive */
b5e56d
     _cogl_texture_2d_allocate,
b5e56d
     _cogl_texture_2d_set_region,
b5e56d
+    _cogl_texture_2d_copy_sub_image,
b5e56d
     _cogl_texture_2d_get_data,
b5e56d
     NULL, /* foreach_sub_texture_in_region */
b5e56d
     _cogl_texture_2d_get_max_waste,
b5e56d
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
b5e56d
index 8e2ff08..a59d386 100644
b5e56d
--- a/cogl/cogl-texture-3d.c
b5e56d
+++ b/cogl/cogl-texture-3d.c
b5e56d
@@ -741,6 +741,7 @@ cogl_texture_3d_vtable =
b5e56d
     TRUE, /* primitive */
b5e56d
     _cogl_texture_3d_allocate,
b5e56d
     _cogl_texture_3d_set_region,
b5e56d
+    NULL, /* copy_sub_image */
b5e56d
     _cogl_texture_3d_get_data,
b5e56d
     NULL, /* foreach_sub_texture_in_region */
b5e56d
     _cogl_texture_3d_get_max_waste,
b5e56d
diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h
b5e56d
index 472c41d..34ff81c 100644
b5e56d
--- a/cogl/cogl-texture-private.h
b5e56d
+++ b/cogl/cogl-texture-private.h
b5e56d
@@ -90,6 +90,15 @@ struct _CoglTextureVtable
b5e56d
                            CoglBitmap *bitmap,
b5e56d
                            CoglError **error);
b5e56d
 
b5e56d
+    CoglBool (* copy_sub_image) (CoglTexture *texture,
b5e56d
+                                 GLint xoffset,
b5e56d
+                                 GLint yoffset,
b5e56d
+                                 GLint x,
b5e56d
+                                 GLint y,
b5e56d
+                                 GLsizei width,
b5e56d
+                                 GLsizei height,
b5e56d
+                                 CoglError **error);
b5e56d
+
b5e56d
   /* This should copy the image data of the texture into @data. The
b5e56d
      requested format will have been first passed through
b5e56d
      ctx->texture_driver->find_best_gl_get_data_format so it should
b5e56d
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
b5e56d
index 65d2f06..9f533c9 100644
b5e56d
--- a/cogl/cogl-texture-rectangle.c
b5e56d
+++ b/cogl/cogl-texture-rectangle.c
b5e56d
@@ -761,6 +761,7 @@ cogl_texture_rectangle_vtable =
b5e56d
     TRUE, /* primitive */
b5e56d
     _cogl_texture_rectangle_allocate,
b5e56d
     _cogl_texture_rectangle_set_region,
b5e56d
+    NULL, /* copy_sub_image */
b5e56d
     _cogl_texture_rectangle_get_data,
b5e56d
     NULL, /* foreach_sub_texture_in_region */
b5e56d
     _cogl_texture_rectangle_get_max_waste,
b5e56d
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
b5e56d
index d93db22..1f4b43c 100644
b5e56d
--- a/cogl/cogl-texture.c
b5e56d
+++ b/cogl/cogl-texture.c
b5e56d
@@ -514,6 +514,39 @@ cogl_texture_set_region (CoglTexture *texture,
b5e56d
 }
b5e56d
 
b5e56d
 CoglBool
b5e56d
+cogl_texture_copy_sub_image (CoglTexture *texture,
b5e56d
+                             int xoffset,
b5e56d
+                             int yoffset,
b5e56d
+                             int x,
b5e56d
+                             int y,
b5e56d
+                             size_t width,
b5e56d
+                             size_t height)
b5e56d
+{
b5e56d
+  CoglError *ignore_error = NULL;
b5e56d
+  CoglBool status;
b5e56d
+
b5e56d
+  if (!texture->allocated)
b5e56d
+    cogl_texture_allocate (texture, NULL);
b5e56d
+
b5e56d
+  if (!texture->vtable->copy_sub_image)
b5e56d
+    return FALSE;
b5e56d
+
b5e56d
+  status = texture->vtable->copy_sub_image (texture,
b5e56d
+                                            xoffset,
b5e56d
+                                            yoffset,
b5e56d
+                                            x,
b5e56d
+                                            y,
b5e56d
+                                            width,
b5e56d
+                                            height,
b5e56d
+                                            &ignore_error);
b5e56d
+
b5e56d
+  if (!status)
b5e56d
+    cogl_error_free (ignore_error);
b5e56d
+  return status;
b5e56d
+}
b5e56d
+
b5e56d
+
b5e56d
+CoglBool
b5e56d
 cogl_texture_set_data (CoglTexture *texture,
b5e56d
                        CoglPixelFormat format,
b5e56d
                        int rowstride,
b5e56d
diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
b5e56d
index 2718830..81657d1 100644
b5e56d
--- a/cogl/cogl-texture.h
b5e56d
+++ b/cogl/cogl-texture.h
b5e56d
@@ -399,6 +399,15 @@ cogl_texture_set_region (CoglTexture *texture,
b5e56d
                          unsigned int rowstride,
b5e56d
                          const uint8_t *data);
b5e56d
 
b5e56d
+CoglBool
b5e56d
+cogl_texture_copy_sub_image (CoglTexture *texture,
b5e56d
+                             int xoffset,
b5e56d
+                             int yoffset,
b5e56d
+                             int x,
b5e56d
+                             int y,
b5e56d
+                             size_t width,
b5e56d
+                             size_t height);
b5e56d
+
b5e56d
 #if defined (COGL_ENABLE_EXPERIMENTAL_API)
b5e56d
 
b5e56d
 /**
b5e56d
diff --git a/cogl/driver/gl/cogl-texture-2d-gl-private.h b/cogl/driver/gl/cogl-texture-2d-gl-private.h
b5e56d
index e5c6585..d2f9985 100644
b5e56d
--- a/cogl/driver/gl/cogl-texture-2d-gl-private.h
b5e56d
+++ b/cogl/driver/gl/cogl-texture-2d-gl-private.h
b5e56d
@@ -109,6 +109,15 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
b5e56d
                                       int dst_y,
b5e56d
                                       int level,
b5e56d
                                       CoglError **error);
b5e56d
+CoglBool
b5e56d
+_cogl_texture_2d_gl_copy_sub_image (CoglTexture2D *tex_2d,
b5e56d
+                                    GLint xoffset,
b5e56d
+                                    GLint yoffset,
b5e56d
+                                    GLint x,
b5e56d
+                                    GLint y,
b5e56d
+                                    GLsizei width,
b5e56d
+                                    GLsizei height,
b5e56d
+                                    CoglError **error);
b5e56d
 
b5e56d
 void
b5e56d
 _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
b5e56d
diff --git a/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/driver/gl/cogl-texture-2d-gl.c
b5e56d
index 8675f52..bc15ac5 100644
b5e56d
--- a/cogl/driver/gl/cogl-texture-2d-gl.c
b5e56d
+++ b/cogl/driver/gl/cogl-texture-2d-gl.c
b5e56d
@@ -35,6 +35,7 @@
b5e56d
 #include <config.h>
b5e56d
 
b5e56d
 #include <string.h>
b5e56d
+#include <stdio.h>
b5e56d
 
b5e56d
 #include "cogl-private.h"
b5e56d
 #include "cogl-texture-private.h"
b5e56d
@@ -719,6 +720,44 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
b5e56d
   return status;
b5e56d
 }
b5e56d
 
b5e56d
+CoglBool
b5e56d
+_cogl_texture_2d_gl_copy_sub_image (CoglTexture2D *tex_2d,
b5e56d
+                                    GLint xoffset,
b5e56d
+                                    GLint yoffset,
b5e56d
+                                    GLint x,
b5e56d
+                                    GLint y,
b5e56d
+                                    GLsizei width,
b5e56d
+                                    GLsizei height,
b5e56d
+                                    CoglError **error)
b5e56d
+{
b5e56d
+  CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
b5e56d
+
b5e56d
+  if (ctx->current_read_buffer == NULL)
b5e56d
+    return FALSE;
b5e56d
+
b5e56d
+  if (ctx->current_draw_buffer)
b5e56d
+    _cogl_framebuffer_flush_journal (ctx->current_draw_buffer);
b5e56d
+
b5e56d
+  if (ctx->current_read_buffer != NULL &&
b5e56d
+      ctx->current_read_buffer != ctx->current_draw_buffer)
b5e56d
+    _cogl_framebuffer_flush_journal (ctx->current_read_buffer);
b5e56d
+
b5e56d
+  _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
b5e56d
+                                   tex_2d->gl_texture,
b5e56d
+                                   tex_2d->is_foreign);
b5e56d
+
b5e56d
+  ctx->glCopyTexSubImage2D (GL_TEXTURE_2D,
b5e56d
+                            0,
b5e56d
+                            xoffset,
b5e56d
+                            yoffset,
b5e56d
+                            x,
b5e56d
+                            y,
b5e56d
+                            width,
b5e56d
+                            height);
b5e56d
+
b5e56d
+  return TRUE;
b5e56d
+}
b5e56d
+
b5e56d
 void
b5e56d
 _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
b5e56d
                               CoglPixelFormat format,
b5e56d
diff --git a/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/driver/gl/gl/cogl-driver-gl.c
b5e56d
index f305b6a..f7f5020 100644
b5e56d
--- a/cogl/driver/gl/gl/cogl-driver-gl.c
b5e56d
+++ b/cogl/driver/gl/gl/cogl-driver-gl.c
b5e56d
@@ -695,6 +695,7 @@ _cogl_driver_gl =
b5e56d
     _cogl_texture_2d_gl_get_gl_handle,
b5e56d
     _cogl_texture_2d_gl_generate_mipmap,
b5e56d
     _cogl_texture_2d_gl_copy_from_bitmap,
b5e56d
+    _cogl_texture_2d_gl_copy_sub_image,
b5e56d
     _cogl_texture_2d_gl_get_data,
b5e56d
     _cogl_gl_flush_attributes_state,
b5e56d
     _cogl_clip_stack_gl_flush,
b5e56d
diff --git a/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/driver/gl/gles/cogl-driver-gles.c
b5e56d
index e94449f..f5ac771 100644
b5e56d
--- a/cogl/driver/gl/gles/cogl-driver-gles.c
b5e56d
+++ b/cogl/driver/gl/gles/cogl-driver-gles.c
b5e56d
@@ -476,6 +476,7 @@ _cogl_driver_gles =
b5e56d
     _cogl_texture_2d_gl_get_gl_handle,
b5e56d
     _cogl_texture_2d_gl_generate_mipmap,
b5e56d
     _cogl_texture_2d_gl_copy_from_bitmap,
b5e56d
+    _cogl_texture_2d_gl_copy_sub_image,
b5e56d
     NULL, /* texture_2d_get_data */
b5e56d
     _cogl_gl_flush_attributes_state,
b5e56d
     _cogl_clip_stack_gl_flush,
b5e56d
diff --git a/cogl/driver/nop/cogl-driver-nop.c b/cogl/driver/nop/cogl-driver-nop.c
b5e56d
index 53f5975..9d88955 100644
b5e56d
--- a/cogl/driver/nop/cogl-driver-nop.c
b5e56d
+++ b/cogl/driver/nop/cogl-driver-nop.c
b5e56d
@@ -80,6 +80,7 @@ _cogl_driver_nop =
b5e56d
     _cogl_texture_2d_nop_get_gl_handle,
b5e56d
     _cogl_texture_2d_nop_generate_mipmap,
b5e56d
     _cogl_texture_2d_nop_copy_from_bitmap,
b5e56d
+    NULL, /* texture_2d_copy_from_image */
b5e56d
     NULL, /* texture_2d_get_data */
b5e56d
     _cogl_nop_flush_attributes_state,
b5e56d
     _cogl_clip_stack_nop_flush,
b5e56d
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c
b5e56d
index 398c357..a44cdaf 100644
b5e56d
--- a/cogl/winsys/cogl-texture-pixmap-x11.c
b5e56d
+++ b/cogl/winsys/cogl-texture-pixmap-x11.c
b5e56d
@@ -1164,6 +1164,7 @@ cogl_texture_pixmap_x11_vtable =
b5e56d
     FALSE, /* not primitive */
b5e56d
     _cogl_texture_pixmap_x11_allocate,
b5e56d
     _cogl_texture_pixmap_x11_set_region,
b5e56d
+    NULL, /* copy_sub_image */
b5e56d
     _cogl_texture_pixmap_x11_get_data,
b5e56d
     _cogl_texture_pixmap_x11_foreach_sub_texture_in_region,
b5e56d
     _cogl_texture_pixmap_x11_get_max_waste,
b5e56d
-- 
b5e56d
2.9.5
b5e56d