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

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