aboutsummaryrefslogtreecommitdiff
path: root/render/gles2/renderer.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-06-30 15:27:45 -0700
committerGitHub <noreply@github.com>2018-06-30 15:27:45 -0700
commit015ebc5750c4224d4796bba0e6deeb20c8d8a777 (patch)
tree2897ecafe78c4ca7686f63a68392aed70db40e70 /render/gles2/renderer.c
parent02dfa9101ec7fd8328ed329d2f2faa815b1ad61c (diff)
parentcc9b198f9e4e00e59773e78ab8afe1c4c0fd1ee1 (diff)
Merge pull request #1069 from emersion/screencopy
Add wlr-screencopy-unstable-v1 support
Diffstat (limited to 'render/gles2/renderer.c')
-rw-r--r--render/gles2/renderer.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 05426fa9..5233ed1b 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -250,10 +250,11 @@ static int gles2_get_dmabuf_modifiers(struct wlr_renderer *wlr_renderer,
}
static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
- enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
- uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x,
- uint32_t dst_y, void *data) {
- gles2_get_renderer_in_context(wlr_renderer);
+ enum wl_shm_format wl_fmt, uint32_t *flags, uint32_t stride,
+ uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y,
+ uint32_t dst_x, uint32_t dst_y, void *data) {
+ struct wlr_gles2_renderer *renderer =
+ gles2_get_renderer_in_context(wlr_renderer);
const struct wlr_gles2_pixel_format *fmt = get_gles2_format_from_wl(wl_fmt);
if (fmt == NULL) {
@@ -266,17 +267,31 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
// Make sure any pending drawing is finished before we try to read it
glFinish();
- // Unfortunately GLES2 doesn't support GL_PACK_*, so we have to read
- // the lines out row by row
+ glGetError(); // Clear the error flag
+
unsigned char *p = data + dst_y * stride;
- for (size_t i = src_y; i < src_y + height; ++i) {
- glReadPixels(src_x, src_y + height - i - 1, width, 1, fmt->gl_format,
- fmt->gl_type, p + i * stride + dst_x * fmt->bpp / 8);
+ uint32_t pack_stride = width * fmt->bpp / 8;
+ if (pack_stride == stride && dst_x == 0 && flags != NULL) {
+ // Under these particular conditions, we can read the pixels with only
+ // one glReadPixels call
+ glReadPixels(src_x, renderer->viewport_height - height - src_y,
+ width, height, fmt->gl_format, fmt->gl_type, p);
+ *flags = WLR_RENDERER_READ_PIXELS_Y_INVERT;
+ } else {
+ // Unfortunately GLES2 doesn't support GL_PACK_*, so we have to read
+ // the lines out row by row
+ for (size_t i = src_y; i < src_y + height; ++i) {
+ glReadPixels(src_x, src_y + height - i - 1, width, 1, fmt->gl_format,
+ fmt->gl_type, p + i * stride + dst_x * fmt->bpp / 8);
+ }
+ if (flags != NULL) {
+ *flags = 0;
+ }
}
POP_GLES2_DEBUG;
- return true;
+ return glGetError() == GL_NO_ERROR;
}
static bool gles2_format_supported(struct wlr_renderer *wlr_renderer,