aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-10-08 10:06:41 -0400
committerGitHub <noreply@github.com>2017-10-08 10:06:41 -0400
commit9e1ff2dce9eded87673c8cd7eeb7e31a421f7a22 (patch)
tree4d97bb0ddb8475b992c846f74d39ff8ee3109801 /render
parent1908d88fab23660e863928d8fc874bad4593b087 (diff)
parent0ce313530446b801302850f03c4a8d8c20cfd782 (diff)
Merge pull request #140 from emersion/screenshooter
Add screenshooter
Diffstat (limited to 'render')
-rw-r--r--render/gles2/renderer.c19
-rw-r--r--render/wlr_renderer.c5
2 files changed, 23 insertions, 1 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 325e1571..94c50b9a 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -208,7 +208,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 = {
@@ -220,6 +236,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);
+}