tests: make screenshooting return a buffer

Screenshooting does not involve creating a wl_surface, so using struct
surface is superfluous.

Return a struct buffer instead. It could have been just a
pixman_image_t, but setting up proper destruction would be a bit more
work. Should not hurt to keep the wl_buffer around until the user is
ready to free the image.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
dev
Pekka Paalanen 9 years ago
parent fd10ef0f63
commit 365c1296fa
  1. 12
      tests/internal-screenshot-test.c
  2. 51
      tests/weston-test-client-helper.c
  3. 5
      tests/weston-test-client-helper.h

@ -65,7 +65,7 @@ TEST(internal_screenshot)
struct buffer *buf; struct buffer *buf;
struct client *client; struct client *client;
struct wl_surface *surface; struct wl_surface *surface;
struct surface *screenshot = NULL; struct buffer *screenshot = NULL;
pixman_image_t *reference_good = NULL; pixman_image_t *reference_good = NULL;
pixman_image_t *reference_bad = NULL; pixman_image_t *reference_bad = NULL;
struct rectangle clip; struct rectangle clip;
@ -123,8 +123,7 @@ TEST(internal_screenshot)
/* Test check_images_match() without a clip. /* Test check_images_match() without a clip.
* We expect this to fail since we use a bad reference image * We expect this to fail since we use a bad reference image
*/ */
match = check_images_match(screenshot->buffer->image, match = check_images_match(screenshot->image, reference_bad, NULL);
reference_bad, NULL);
printf("Screenshot %s reference image\n", match? "equal to" : "different from"); printf("Screenshot %s reference image\n", match? "equal to" : "different from");
assert(!match); assert(!match);
pixman_image_unref(reference_bad); pixman_image_unref(reference_bad);
@ -138,18 +137,17 @@ TEST(internal_screenshot)
clip.width = 100; clip.width = 100;
clip.height = 100; clip.height = 100;
printf("Clip: %d,%d %d x %d\n", clip.x, clip.y, clip.width, clip.height); printf("Clip: %d,%d %d x %d\n", clip.x, clip.y, clip.width, clip.height);
match = check_images_match(screenshot->buffer->image, match = check_images_match(screenshot->image, reference_good, &clip);
reference_good, &clip);
printf("Screenshot %s reference image in clipped area\n", match? "matches" : "doesn't match"); printf("Screenshot %s reference image in clipped area\n", match? "matches" : "doesn't match");
pixman_image_unref(reference_good); pixman_image_unref(reference_good);
/* Test dumping of non-matching images */ /* Test dumping of non-matching images */
if (!match || dump_all_images) { if (!match || dump_all_images) {
fname = screenshot_output_filename("internal-screenshot", 0); fname = screenshot_output_filename("internal-screenshot", 0);
write_image_as_png(screenshot->buffer->image, fname); write_image_as_png(screenshot->image, fname);
} }
free(screenshot); buffer_destroy(screenshot);
printf("Test complete\n"); printf("Test complete\n");
assert(match); assert(match);

@ -1255,54 +1255,29 @@ load_image_from_png(const char *fname)
return converted; return converted;
} }
/** create_screenshot_surface() /**
* * Take screenshot of a single output
* Allocates and initializes a weston test surface for use in
* storing a screenshot of the client's output. Establishes a
* shm backed wl_buffer for retrieving screenshot image data
* from the server, sized to match the client's output display.
*
* @returns stack allocated surface image, which should be
* free'd when done using it.
*/
struct surface *
create_screenshot_surface(struct client *client)
{
struct surface *screenshot;
screenshot = zalloc(sizeof *screenshot);
if (screenshot == NULL)
return NULL;
screenshot->buffer = create_shm_buffer_a8r8g8b8(client,
client->output->width,
client->output->height);
screenshot->height = client->output->height;
screenshot->width = client->output->width;
return screenshot;
}
/** capture_screenshot_of_output()
* *
* Requests a screenshot from the server of the output that the * Requests a screenshot from the server of the output that the
* client appears on. The image data returned from the server * client appears on. This implies that the compositor goes through an output
* can be accessed from the screenshot surface's data member. * repaint to provide the screenshot before this function returns. This
* function is therefore both a server roundtrip and a wait for a repaint.
* *
* @returns a new surface object, which should be free'd when no * @returns A new buffer object, that should be freed with buffer_destroy().
* longer needed.
*/ */
struct surface * struct buffer *
capture_screenshot_of_output(struct client *client) capture_screenshot_of_output(struct client *client)
{ {
struct surface *screenshot; struct buffer *buffer;
/* Create a surface to hold the screenshot */ buffer = create_shm_buffer_a8r8g8b8(client,
screenshot = create_screenshot_surface(client); client->output->width,
client->output->height);
client->test->buffer_copy_done = 0; client->test->buffer_copy_done = 0;
weston_test_capture_screenshot(client->test->weston_test, weston_test_capture_screenshot(client->test->weston_test,
client->output->wl_output, client->output->wl_output,
screenshot->buffer->proxy); buffer->proxy);
while (client->test->buffer_copy_done == 0) while (client->test->buffer_copy_done == 0)
if (wl_display_dispatch(client->wl_display) < 0) if (wl_display_dispatch(client->wl_display) < 0)
break; break;
@ -1313,5 +1288,5 @@ capture_screenshot_of_output(struct client *client)
* Protocol docs in the XML, comparison function docs in Doxygen style. * Protocol docs in the XML, comparison function docs in Doxygen style.
*/ */
return screenshot; return buffer;
} }

@ -207,10 +207,7 @@ write_image_as_png(pixman_image_t *image, const char *fname);
pixman_image_t * pixman_image_t *
load_image_from_png(const char *fname); load_image_from_png(const char *fname);
struct surface * struct buffer *
create_screenshot_surface(struct client *client);
struct surface *
capture_screenshot_of_output(struct client *client); capture_screenshot_of_output(struct client *client);
#endif #endif

Loading…
Cancel
Save