<br><br><div class="gmail_quote">On Wed, Apr 4, 2012 at 6:37 AM, Kristian Hoegsberg <span dir="ltr"><<a href="mailto:hoegsberg@gmail.com">hoegsberg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, Apr 04, 2012 at 01:51:08AM -0600, Scott Moreau wrote:<br>
> ---<br>
<br>
Looks pretty good. There are a few small comments below, but the<br>
overall approach is good.<br>
<div class="im"><br>
> Tested: Side-by-side and stacked output configurations, in x11 and drm.<br>
> Shooting under drm glitches sometimes and either or both output data<br>
> contains garbage.<br>
<br>
</div>I see the drm glitches without this, it's a different problem.<br>
<div><div class="h5"><br>
><br>
> clients/screenshot.c | 69 ++++++++++++++++++++++++++++++++++++++++------<br>
> src/compositor-drm.c | 14 +++++++++<br>
> src/compositor-wayland.c | 14 +++++++++<br>
> src/compositor-x11.c | 14 +++++++++<br>
> src/compositor.h | 1 +<br>
> src/screenshooter.c | 28 +++++++++---------<br>
> 6 files changed, 117 insertions(+), 23 deletions(-)<br>
><br>
> diff --git a/clients/screenshot.c b/clients/screenshot.c<br>
> index 6cc2ebb..40f0af4 100644<br>
> --- a/clients/screenshot.c<br>
> +++ b/clients/screenshot.c<br>
> @@ -32,14 +32,24 @@<br>
> #include <wayland-client.h><br>
> #include "screenshooter-client-protocol.h"<br>
><br>
> +#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))<br>
> +<br>
> /* The screenshooter is a good example of a custom object exposed by<br>
> * the compositor and serves as a test bed for implementing client<br>
> * side marshalling outside libwayland.so */<br>
><br>
> -static struct wl_output *output;<br>
> static struct wl_shm *shm;<br>
> static struct screenshooter *screenshooter;<br>
> -static int output_width, output_height;<br>
> +static struct wl_list output_list;<br>
> +<br>
> +struct ss_output {<br>
> + struct wl_output *output;<br>
> + struct wl_buffer *buffer;<br>
> + int width, height, offset_x, offset_y;<br>
> + struct wl_list link;<br>
> +};<br>
> +<br>
> +static struct ss_output *output;<br>
<br>
</div></div>Can we call this screenshooter_output instead?<br></blockquote><div><br>I named it screenshooter_output to begin with but felt it made the code too messy.<br>It can be renamed back.<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
> static void<br>
> display_handle_geometry(void *data,<br>
> @@ -52,6 +62,14 @@ display_handle_geometry(void *data,<br>
> const char *make,<br>
> const char *model)<br>
> {<br>
> + struct ss_output *ss_output;<br>
> +<br>
> + wl_list_for_each(ss_output, &output_list, link) {<br>
> + if (wl_output == ss_output->output) {<br>
> + ss_output->offset_x = x;<br>
> + ss_output->offset_y = y;<br>
> + }<br>
> + }<br>
<br>
</div>Instead of this loop, you can just set the user data on the wl_output<br>
object (the data arg to add_listener) and then get it here using<br>
<br>
ss_output = wl_output_get_user_data(wl_output);<br></blockquote><div><br>Yes, I didn't realize you can do this. <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
<br>
> }<br>
><br>
> static void<br>
> @@ -62,8 +80,15 @@ display_handle_mode(void *data,<br>
> int height,<br>
> int refresh)<br>
> {<br>
> - output_width = width;<br>
> - output_height = height;<br>
> + struct ss_output *ss_output;<br>
> +<br>
> + wl_list_for_each(ss_output, &output_list, link) {<br>
> + if (wl_output == ss_output->output &&<br>
> + (flags & WL_OUTPUT_MODE_CURRENT)) {<br>
> + ss_output->width = width;<br>
> + ss_output->height = height;<br>
> + }<br>
> + }<br>
<br>
</div>Same here.<br></blockquote><div><br>Right. <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
> }<br>
><br>
> static const struct wl_output_listener output_listener = {<br>
> @@ -76,8 +101,10 @@ handle_global(struct wl_display *display, uint32_t id,<br>
> const char *interface, uint32_t version, void *data)<br>
> {<br>
> if (strcmp(interface, "wl_output") == 0) {<br>
> - output = wl_display_bind(display, id, &wl_output_interface);<br>
> - wl_output_add_listener(output, &output_listener, NULL);<br>
> + output = malloc(sizeof *output);<br>
> + output->output = wl_display_bind(display, id, &wl_output_interface);<br>
> + wl_list_insert(&output_list, &output->link);<br>
> + wl_output_add_listener(output->output, &output_listener, NULL);<br>
<br>
</div>Pass output instead of NULL as the last arg here.<br></blockquote><div><br>I see.. <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="h5"><br>
> } else if (strcmp(interface, "wl_shm") == 0) {<br>
> shm = wl_display_bind(display, id, &wl_shm_interface);<br>
> } else if (strcmp(interface, "screenshooter") == 0) {<br>
> @@ -144,6 +171,8 @@ int main(int argc, char *argv[])<br>
> struct wl_display *display;<br>
> struct wl_buffer *buffer;<br>
> void *data = NULL;<br>
> + struct ss_output *ss_output;<br>
> + int ss_area_width = 0, ss_area_height = 0, num_outputs = 0;<br>
><br>
> display = wl_display_connect(NULL);<br>
> if (display == NULL) {<br>
> @@ -151,6 +180,7 @@ int main(int argc, char *argv[])<br>
> return -1;<br>
> }<br>
><br>
> + wl_list_init(&output_list);<br>
> wl_display_add_global_listener(display, handle_global, &screenshooter);<br>
> wl_display_iterate(display, WL_DISPLAY_READABLE);<br>
> wl_display_roundtrip(display);<br>
> @@ -159,11 +189,32 @@ int main(int argc, char *argv[])<br>
> return -1;<br>
> }<br>
><br>
> - buffer = create_shm_buffer(output_width, output_height, &data);<br>
> - screenshooter_shoot(screenshooter, output, buffer);<br>
> + wl_list_for_each(ss_output, &output_list, link) {<br>
> +<br>
> + if (!num_outputs) {<br>
> + ss_area_width = ss_output->width + ss_output->offset_x;<br>
> + ss_area_height = ss_output->height + ss_output->offset_y;<br>
> + }<br>
<br>
</div></div>I'd just set ss_area_width/height to 0 initially.<br></blockquote><div><br>num_outputs must be initialised since it checks !num_outputs on the first pass.<br>Unless there is another way to do this, we need to set num_outputs to begin with.<br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
<br>
> + else {<br>
> + ss_area_width = MAX(ss_area_width, ss_output->offset_x + ss_output->width);<br>
> + ss_area_height = MAX(ss_area_height, ss_output->offset_y + ss_output->height);<br>
> + }<br>
> + num_outputs++;<br>
> + }<br>
> +<br>
> + buffer = create_shm_buffer(ss_area_width, ss_area_height, &data);<br>
> +<br>
> + wl_list_for_each(ss_output, &output_list, link) {<br>
> + screenshooter_shoot(screenshooter, ss_output->output, buffer);<br>
> + }<br>
> +<br>
> wl_display_roundtrip(display);<br>
><br>
> - write_png(output_width, output_height, data);<br>
> + write_png(ss_area_width, ss_area_height, data);<br>
> +<br>
> + wl_list_for_each(ss_output, &output_list, link) {<br>
> + free(ss_output);<br>
<br>
</div>You need wl_list_for_each_safe here since you're freeing the structs<br>
that holds the prev/next pointers.<br></blockquote><div><br>Ah, I was wondering about that. <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="h5"><br>
> + }<br>
><br>
> return 0;<br>
> }<br>
> diff --git a/src/compositor-drm.c b/src/compositor-drm.c<br>
> index d428c82..7f2886e 100644<br>
> --- a/src/compositor-drm.c<br>
> +++ b/src/compositor-drm.c<br>
> @@ -1047,6 +1047,19 @@ drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)<br>
> drmModeFreeConnector(connector);<br>
> }<br>
><br>
> +static void<br>
> +drm_output_read_pixels(struct weston_output *output_base, void *data) {<br>
> + struct drm_output *output = (struct drm_output *) output_base;<br>
> + struct drm_compositor *compositor =<br>
> + (struct drm_compositor *) output->base.compositor;<br>
> +<br>
> + eglMakeCurrent(compositor->base.display, output->egl_surface,<br>
> + output->egl_surface, compositor->base.context);<br>
> +<br>
> + glReadPixels(0, 0, output_base->current->width, output_base->current->height,<br>
> + GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);<br>
> +}<br>
> +<br>
> static int<br>
> create_output_for_connector(struct drm_compositor *ec,<br>
> drmModeRes *resources,<br>
> @@ -1085,6 +1098,7 @@ create_output_for_connector(struct drm_compositor *ec,<br>
> output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);<br>
> output->base.make = "unknown";<br>
> output->base.model = "unknown";<br>
> + output->base.read_pixels = drm_output_read_pixels;<br>
<br>
</div></div>Group this assignment with the other function pointer assignments<br>
(repaint, destroy etc, at the end of the function).<br></blockquote><div><br>Got it. <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><div class="h5"><br>
> wl_list_init(&output->base.mode_list);<br>
><br>
> output->crtc_id = resources->crtcs[i];<br>
> diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c<br>
> index 593e272..8c87721 100644<br>
> --- a/src/compositor-wayland.c<br>
> +++ b/src/compositor-wayland.c<br>
> @@ -377,6 +377,19 @@ wayland_output_destroy(struct weston_output *output_base)<br>
> return;<br>
> }<br>
><br>
> +static void<br>
> +wayland_output_read_pixels(struct weston_output *output_base, void *data) {<br>
> + struct wayland_output *output = (struct wayland_output *) output_base;<br>
> + struct wayland_compositor *compositor =<br>
> + (struct wayland_compositor *) output->base.compositor;<br>
> +<br>
> + eglMakeCurrent(compositor->base.display, output->egl_surface,<br>
> + output->egl_surface, compositor->base.context);<br>
> +<br>
> + glReadPixels(0, 0, output_base->current->width, output_base->current->height,<br>
> + GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);<br>
> +}<br>
> +<br>
> static int<br>
> wayland_compositor_create_output(struct wayland_compositor *c,<br>
> int width, int height)<br>
> @@ -393,6 +406,7 @@ wayland_compositor_create_output(struct wayland_compositor *c,<br>
> output->mode.width = width;<br>
> output->mode.height = height;<br>
> output->mode.refresh = 60;<br>
> + output->base.read_pixels = wayland_output_read_pixels;<br>
> wl_list_init(&output->base.mode_list);<br>
> wl_list_insert(&output->base.mode_list, &output->mode.link);<br>
><br>
> diff --git a/src/compositor-x11.c b/src/compositor-x11.c<br>
> index d0203ca..09aa117 100644<br>
> --- a/src/compositor-x11.c<br>
> +++ b/src/compositor-x11.c<br>
> @@ -344,6 +344,19 @@ x11_output_set_icon(struct x11_compositor *c,<br>
> pixman_image_unref(image);<br>
> }<br>
><br>
> +static void<br>
> +x11_output_read_pixels(struct weston_output *output_base, void *data) {<br>
> + struct x11_output *output = (struct x11_output *) output_base;<br>
> + struct x11_compositor *compositor =<br>
> + (struct x11_compositor *) output->base.compositor;<br>
> +<br>
> + eglMakeCurrent(compositor->base.display, output->egl_surface,<br>
> + output->egl_surface, compositor->base.context);<br>
> +<br>
> + glReadPixels(0, 0, output_base->current->width, output_base->current->height,<br>
> + GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);<br>
> +}<br>
> +<br>
> static int<br>
> x11_compositor_create_output(struct x11_compositor *c, int x, int y,<br>
> int width, int height, int fullscreen)<br>
> @@ -381,6 +394,7 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,<br>
> output->mode.width = width;<br>
> output->mode.height = height;<br>
> output->mode.refresh = 60;<br>
> + output->base.read_pixels = x11_output_read_pixels;<br>
> wl_list_init(&output->base.mode_list);<br>
> wl_list_insert(&output->base.mode_list, &output->mode.link);<br>
><br>
> diff --git a/src/compositor.h b/src/compositor.h<br>
> index d1cd7c8..ea18b7b 100644<br>
> --- a/src/compositor.h<br>
> +++ b/src/compositor.h<br>
> @@ -96,6 +96,7 @@ struct weston_output {<br>
> pixman_region32_t *damage);<br>
> void (*destroy)(struct weston_output *output);<br>
> void (*assign_planes)(struct weston_output *output);<br>
> + void (*read_pixels)(struct weston_output *output, void *data);<br>
><br>
> /* backlight values are on 0-255 range, where higher is brighter */<br>
> uint32_t backlight_current;<br>
> diff --git a/src/screenshooter.c b/src/screenshooter.c<br>
> index f9497f7..3fe7bc3 100644<br>
> --- a/src/screenshooter.c<br>
> +++ b/src/screenshooter.c<br>
> @@ -32,7 +32,7 @@ struct screenshooter {<br>
> struct weston_compositor *ec;<br>
> struct wl_global *global;<br>
> struct wl_client *client;<br>
> - struct weston_process screenshooter_process;<br>
> + struct weston_process process;<br>
> };<br>
><br>
> static void<br>
> @@ -44,7 +44,7 @@ screenshooter_shoot(struct wl_client *client,<br>
> struct weston_output *output = output_resource->data;<br>
> struct wl_buffer *buffer = buffer_resource->data;<br>
> uint8_t *tmp, *d, *s;<br>
> - int32_t stride, i;<br>
> + int32_t buffer_stride, output_stride, i;<br>
><br>
> if (!wl_buffer_is_shm(buffer))<br>
> return;<br>
> @@ -53,24 +53,24 @@ screenshooter_shoot(struct wl_client *client,<br>
> buffer->height < output->current->height)<br>
> return;<br>
><br>
> - stride = wl_shm_buffer_get_stride(buffer);<br>
> - tmp = malloc(stride * buffer->height);<br>
> + buffer_stride = wl_shm_buffer_get_stride(buffer);<br>
> + output_stride = output->current->width * 4;<br>
> + tmp = malloc(output_stride * output->current->height);<br>
> if (tmp == NULL) {<br>
> wl_resource_post_no_memory(resource);<br>
> return;<br>
> }<br>
><br>
> glPixelStorei(GL_PACK_ALIGNMENT, 1);<br>
> - glReadPixels(0, 0, output->current->width, output->current->height,<br>
> - GL_BGRA_EXT, GL_UNSIGNED_BYTE, tmp);<br>
> + output->read_pixels(output, tmp);<br>
><br>
> - d = wl_shm_buffer_get_data(buffer);<br>
> - s = tmp + stride * (buffer->height - 1);<br>
> + d = wl_shm_buffer_get_data(buffer) + output->y * buffer_stride;<br>
<br>
</div></div>Just add output->x * 4 term to d here instead of inside the loop.<br></blockquote><div><br>Good idea. <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
> + s = tmp + output_stride * (output->current->height - 1);<br>
><br>
> - for (i = 0; i < buffer->height; i++) {<br>
> - memcpy(d, s, stride);<br>
> - d += stride;<br>
> - s -= stride;<br>
> + for (i = 0; i < output->current->height; i++) {<br>
> + memcpy(d + output->x * 4, s, output_stride);<br>
> + d += buffer_stride;<br>
> + s -= output_stride;<br>
> }<br>
><br>
> free(tmp);<br>
> @@ -101,7 +101,7 @@ static void<br>
> screenshooter_sigchld(struct weston_process *process, int status)<br>
> {<br>
> struct screenshooter *shooter =<br>
> - container_of(process, struct screenshooter, screenshooter_process);<br>
> + container_of(process, struct screenshooter, process);<br>
><br>
> shooter->client = NULL;<br>
> }<br>
> @@ -116,7 +116,7 @@ screenshooter_binding(struct wl_input_device *device, uint32_t time,<br>
><br>
> if (!shooter->client)<br>
> shooter->client = weston_client_launch(shooter->ec,<br>
> - &shooter->screenshooter_process,<br>
> + &shooter->process,<br>
> screenshooter_exe, screenshooter_sigchld);<br>
> }<br>
><br>
> --<br>
> 1.7.4.1<br>
><br>
</div>> _______________________________________________<br>
> wayland-devel mailing list<br>
> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br></blockquote><div><br><br><br>Thanks for your review, I will write a new patch considering what you've mentioned here.<br>
<br><br>Scott<br></div></div><br>