diff options
author | emersion <contact@emersion.fr> | 2017-10-08 02:11:56 +0200 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-10-08 02:11:56 +0200 |
commit | 0ce313530446b801302850f03c4a8d8c20cfd782 (patch) | |
tree | cc0779ca8ef0000fb3e357fb1ac9c96bf2bed51e /render | |
parent | 55c063f440fd12b1ee8bba5cef56a75c33e66719 (diff) |
Move read_pixels from output to renderer
Diffstat (limited to 'render')
-rw-r--r-- | render/gles2/renderer.c | 19 | ||||
-rw-r--r-- | render/wlr_renderer.c | 5 |
2 files changed, 23 insertions, 1 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index d6c22ebe..9a013338 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -226,7 +226,23 @@ static bool wlr_gles2_buffer_is_drm(struct wlr_renderer *_renderer, (struct wlr_gles2_renderer *)_renderer; EGLint format; return wlr_egl_query_buffer(renderer->egl, buffer, - EGL_TEXTURE_FORMAT, &format); + EGL_TEXTURE_FORMAT, &format); +} + +static void rgba_to_argb(uint32_t *data, size_t height, size_t stride) { + size_t n = height*stride/4; + for (size_t i = 0; i < n; ++i) { + uint32_t v = data[i]; + uint32_t rgb = (v & 0xffffff00) >> 8; + uint32_t a = v & 0x000000ff; + data[i] = rgb | (a << 24); + } +} + +static void wlr_gles2_read_pixels(struct wlr_renderer *renderer, int x, int y, + int width, int height, void *out_data) { + glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, out_data); + rgba_to_argb(out_data, height, width*4); } static struct wlr_renderer_impl wlr_renderer_impl = { @@ -238,6 +254,7 @@ static struct wlr_renderer_impl wlr_renderer_impl = { .render_ellipse = wlr_gles2_render_ellipse, .formats = wlr_gles2_formats, .buffer_is_drm = wlr_gles2_buffer_is_drm, + .read_pixels = wlr_gles2_read_pixels, }; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index fec5e38a..ef0c31be 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -51,3 +51,8 @@ bool wlr_renderer_buffer_is_drm(struct wlr_renderer *r, struct wl_resource *buffer) { return r->impl->buffer_is_drm(r, buffer); } + +void wlr_renderer_read_pixels(struct wlr_renderer *r, int x, int y, + int width, int height, void *out_data) { + r->impl->read_pixels(r, x, y, width, height, out_data); +} |