summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Moreau <oreaus@gmail.com>2012-04-04 11:49:21 -0600
committerKristian Høgsberg <krh@bitplanet.net>2012-04-04 14:28:53 -0400
commit80d27b7e06f673988d4a5dc73ca4dbcd5a02ce07 (patch)
treecaff5a566e5576015fea74ca5667b054d9fbd8e8 /src
parentd0810204353f887693063bbc3b2bf75d561c3080 (diff)
screenshooter: Properly handle multiple outputs.
Diffstat (limited to 'src')
-rw-r--r--src/compositor-drm.c15
-rw-r--r--src/compositor-wayland.c15
-rw-r--r--src/compositor-x11.c15
-rw-r--r--src/compositor.h1
-rw-r--r--src/screenshooter.c29
5 files changed, 61 insertions, 14 deletions
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index d428c82..5747662 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1047,6 +1047,20 @@ drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)
drmModeFreeConnector(connector);
}
+static void
+drm_output_read_pixels(struct weston_output *output_base, void *data)
+{
+ struct drm_output *output = (struct drm_output *) output_base;
+ struct drm_compositor *compositor =
+ (struct drm_compositor *) output->base.compositor;
+
+ eglMakeCurrent(compositor->base.display, output->egl_surface,
+ output->egl_surface, compositor->base.context);
+
+ glReadPixels(0, 0, output_base->current->width, output_base->current->height,
+ GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);
+}
+
static int
create_output_for_connector(struct drm_compositor *ec,
drmModeRes *resources,
@@ -1154,6 +1168,7 @@ create_output_for_connector(struct drm_compositor *ec,
output->base.repaint = drm_output_repaint;
output->base.destroy = drm_output_destroy;
output->base.assign_planes = drm_assign_planes;
+ output->base.read_pixels = drm_output_read_pixels;
output->base.set_dpms = drm_set_dpms;
return 0;
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 593e272..c79d6b5 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -377,6 +377,20 @@ wayland_output_destroy(struct weston_output *output_base)
return;
}
+static void
+wayland_output_read_pixels(struct weston_output *output_base, void *data)
+{
+ struct wayland_output *output = (struct wayland_output *) output_base;
+ struct wayland_compositor *compositor =
+ (struct wayland_compositor *) output->base.compositor;
+
+ eglMakeCurrent(compositor->base.display, output->egl_surface,
+ output->egl_surface, compositor->base.context);
+
+ glReadPixels(0, 0, output_base->current->width, output_base->current->height,
+ GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);
+}
+
static int
wayland_compositor_create_output(struct wayland_compositor *c,
int width, int height)
@@ -444,6 +458,7 @@ wayland_compositor_create_output(struct wayland_compositor *c,
output->base.repaint = wayland_output_repaint;
output->base.destroy = wayland_output_destroy;
output->base.assign_planes = NULL;
+ output->base.read_pixels = wayland_output_read_pixels;
output->base.set_backlight = NULL;
output->base.set_dpms = NULL;
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index d0203ca..62b514e 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -344,6 +344,20 @@ x11_output_set_icon(struct x11_compositor *c,
pixman_image_unref(image);
}
+static void
+x11_output_read_pixels(struct weston_output *output_base, void *data)
+{
+ struct x11_output *output = (struct x11_output *) output_base;
+ struct x11_compositor *compositor =
+ (struct x11_compositor *) output->base.compositor;
+
+ eglMakeCurrent(compositor->base.display, output->egl_surface,
+ output->egl_surface, compositor->base.context);
+
+ glReadPixels(0, 0, output_base->current->width, output_base->current->height,
+ GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);
+}
+
static int
x11_compositor_create_output(struct x11_compositor *c, int x, int y,
int width, int height, int fullscreen)
@@ -454,6 +468,7 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
output->base.repaint = x11_output_repaint;
output->base.destroy = x11_output_destroy;
output->base.assign_planes = NULL;
+ output->base.read_pixels = x11_output_read_pixels;
output->base.set_backlight = NULL;
output->base.set_dpms = NULL;
diff --git a/src/compositor.h b/src/compositor.h
index d1cd7c8..ea18b7b 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -96,6 +96,7 @@ struct weston_output {
pixman_region32_t *damage);
void (*destroy)(struct weston_output *output);
void (*assign_planes)(struct weston_output *output);
+ void (*read_pixels)(struct weston_output *output, void *data);
/* backlight values are on 0-255 range, where higher is brighter */
uint32_t backlight_current;
diff --git a/src/screenshooter.c b/src/screenshooter.c
index f9497f7..1df413f 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -32,7 +32,7 @@ struct screenshooter {
struct weston_compositor *ec;
struct wl_global *global;
struct wl_client *client;
- struct weston_process screenshooter_process;
+ struct weston_process process;
};
static void
@@ -44,7 +44,7 @@ screenshooter_shoot(struct wl_client *client,
struct weston_output *output = output_resource->data;
struct wl_buffer *buffer = buffer_resource->data;
uint8_t *tmp, *d, *s;
- int32_t stride, i;
+ int32_t buffer_stride, output_stride, i;
if (!wl_buffer_is_shm(buffer))
return;
@@ -53,24 +53,25 @@ screenshooter_shoot(struct wl_client *client,
buffer->height < output->current->height)
return;
- stride = wl_shm_buffer_get_stride(buffer);
- tmp = malloc(stride * buffer->height);
+ buffer_stride = wl_shm_buffer_get_stride(buffer);
+ output_stride = output->current->width * 4;
+ tmp = malloc(output_stride * output->current->height);
if (tmp == NULL) {
wl_resource_post_no_memory(resource);
return;
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, output->current->width, output->current->height,
- GL_BGRA_EXT, GL_UNSIGNED_BYTE, tmp);
+ output->read_pixels(output, tmp);
- d = wl_shm_buffer_get_data(buffer);
- s = tmp + stride * (buffer->height - 1);
+ d = wl_shm_buffer_get_data(buffer) + output->y * buffer_stride +
+ output->x * 4;
+ s = tmp + output_stride * (output->current->height - 1);
- for (i = 0; i < buffer->height; i++) {
- memcpy(d, s, stride);
- d += stride;
- s -= stride;
+ for (i = 0; i < output->current->height; i++) {
+ memcpy(d, s, output_stride);
+ d += buffer_stride;
+ s -= output_stride;
}
free(tmp);
@@ -101,7 +102,7 @@ static void
screenshooter_sigchld(struct weston_process *process, int status)
{
struct screenshooter *shooter =
- container_of(process, struct screenshooter, screenshooter_process);
+ container_of(process, struct screenshooter, process);
shooter->client = NULL;
}
@@ -116,7 +117,7 @@ screenshooter_binding(struct wl_input_device *device, uint32_t time,
if (!shooter->client)
shooter->client = weston_client_launch(shooter->ec,
- &shooter->screenshooter_process,
+ &shooter->process,
screenshooter_exe, screenshooter_sigchld);
}