summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorScott Moreau <oreaus@gmail.com>2012-04-20 13:37:34 -0600
committerKristian Høgsberg <krh@bitplanet.net>2012-04-20 16:16:05 -0400
commit72c2372148918c8ed5a2d5cd47b726f48218989c (patch)
treecacb5610a63fe377e1547e235b07ea2f1b894a49 /clients
parent062be7ec93bc658f0e5ae02fc1b4e5b43f3f100a (diff)
screenshooter: Move buffer assembly to client side
Diffstat (limited to 'clients')
-rw-r--r--clients/screenshot.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/clients/screenshot.c b/clients/screenshot.c
index 328d106..a23ef13 100644
--- a/clients/screenshot.c
+++ b/clients/screenshot.c
@@ -47,6 +47,7 @@ struct screenshooter_output {
struct wl_output *output;
struct wl_buffer *buffer;
int width, height, offset_x, offset_y;
+ void *data;
struct wl_list link;
};
@@ -165,23 +166,45 @@ create_shm_buffer(int width, int height, void **data_out)
}
static void
-write_png(int width, int height, void *data)
+write_png(int width, int height)
{
+ int output_stride, buffer_stride, i;
cairo_surface_t *surface;
+ void *data, *d, *s;
+ struct screenshooter_output *output, *next;
+
+ buffer_stride = width * 4;
+
+ data = malloc(buffer_stride * height);
+ if (!data)
+ return;
+
+ wl_list_for_each_safe(output, next, &output_list, link) {
+ output_stride = output->width * 4;
+ s = output->data;
+ d = data + output->offset_y * buffer_stride + output->offset_x * 4;
+
+ for (i = 0; i < output->height; i++) {
+ memcpy(d, s, output_stride);
+ d += buffer_stride;
+ s += output_stride;
+ }
+
+ free(output);
+ }
surface = cairo_image_surface_create_for_data(data,
CAIRO_FORMAT_ARGB32,
- width, height, width * 4);
+ width, height, buffer_stride);
cairo_surface_write_to_png(surface, "wayland-screenshot.png");
cairo_surface_destroy(surface);
+ free(data);
}
int main(int argc, char *argv[])
{
struct wl_display *display;
- struct wl_buffer *buffer;
- void *data = NULL;
- struct screenshooter_output *output, *next;
+ struct screenshooter_output *output;
int width = 0, height = 0;
display = wl_display_connect(NULL);
@@ -203,21 +226,16 @@ int main(int argc, char *argv[])
wl_list_for_each(output, &output_list, link) {
+ output->buffer = create_shm_buffer(output->width, output->height, &output->data);
+ screenshooter_shoot(screenshooter, output->output, output->buffer);
width = MAX(width, output->offset_x + output->width);
height = MAX(height, output->offset_y + output->height);
- }
-
- buffer = create_shm_buffer(width, height, &data);
-
- wl_list_for_each_safe(output, next, &output_list, link) {
- screenshooter_shoot(screenshooter, output->output, buffer);
buffer_copy_done = 0;
while (!buffer_copy_done)
wl_display_roundtrip(display);
- free(output);
}
- write_png(width, height, data);
+ write_png(width, height);
return 0;
}