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

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