2014-11-05 03:39:38 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Samsung Electronics Co., Ltd
|
|
|
|
*
|
2015-06-12 01:39:40 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2014-11-05 03:39:38 +03:00
|
|
|
*
|
2015-06-12 01:39:40 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2014-11-05 03:39:38 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "weston-test-client-helper.h"
|
|
|
|
|
|
|
|
char *server_parameters="--use-pixman --width=320 --height=240";
|
|
|
|
|
2015-05-25 23:19:38 +03:00
|
|
|
static void
|
2016-05-20 18:01:05 +03:00
|
|
|
draw_stuff(pixman_image_t *image)
|
2015-05-25 23:19:38 +03:00
|
|
|
{
|
2016-05-20 18:01:05 +03:00
|
|
|
int w, h;
|
|
|
|
int stride; /* bytes */
|
2015-05-25 23:19:38 +03:00
|
|
|
int x, y;
|
2015-05-26 20:00:49 +03:00
|
|
|
uint8_t r, g, b;
|
2016-05-20 18:01:05 +03:00
|
|
|
uint32_t *pixels;
|
2015-05-26 20:00:49 +03:00
|
|
|
uint32_t *pixel;
|
2016-05-20 18:01:05 +03:00
|
|
|
pixman_format_code_t fmt;
|
|
|
|
|
|
|
|
fmt = pixman_image_get_format(image);
|
|
|
|
w = pixman_image_get_width(image);
|
|
|
|
h = pixman_image_get_height(image);
|
|
|
|
stride = pixman_image_get_stride(image);
|
|
|
|
pixels = pixman_image_get_data(image);
|
|
|
|
|
|
|
|
assert(PIXMAN_FORMAT_BPP(fmt) == 32);
|
2015-05-25 23:19:38 +03:00
|
|
|
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
for (y = 0; y < h; y++) {
|
2015-05-26 20:00:49 +03:00
|
|
|
b = x;
|
|
|
|
g = x + y;
|
|
|
|
r = y;
|
2016-05-20 18:01:05 +03:00
|
|
|
pixel = pixels + (y * stride / 4) + x;
|
2015-05-26 20:00:49 +03:00
|
|
|
*pixel = (255 << 24) | (r << 16) | (g << 8) | b;
|
2015-05-25 23:19:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 01:07:55 +03:00
|
|
|
TEST(internal_screenshot)
|
|
|
|
{
|
2016-05-20 18:01:05 +03:00
|
|
|
struct buffer *buf;
|
2015-05-15 01:07:55 +03:00
|
|
|
struct client *client;
|
2015-05-25 23:19:38 +03:00
|
|
|
struct wl_surface *surface;
|
2015-05-15 01:07:55 +03:00
|
|
|
struct surface *screenshot = NULL;
|
2015-05-25 23:19:38 +03:00
|
|
|
struct surface *reference_good = NULL;
|
|
|
|
struct surface *reference_bad = NULL;
|
2015-05-15 01:07:55 +03:00
|
|
|
struct rectangle clip;
|
|
|
|
const char *fname;
|
|
|
|
bool match = false;
|
|
|
|
bool dump_all_images = true;
|
|
|
|
|
|
|
|
/* Create the client */
|
|
|
|
printf("Creating client for test\n");
|
|
|
|
client = create_client_and_test_surface(100, 100, 100, 100);
|
|
|
|
assert(client);
|
2015-05-25 23:19:38 +03:00
|
|
|
surface = client->surface->wl_surface;
|
|
|
|
|
2016-06-10 10:50:04 +03:00
|
|
|
/*
|
|
|
|
* We are racing our screenshooting against weston-desktop-shell
|
|
|
|
* setting the cursor. If w-d-s wins, our screenshot will have a cursor
|
|
|
|
* shown, which makes the image comparison fail. Our window and the
|
|
|
|
* default pointer position are accidentally causing an overlap that
|
|
|
|
* intersects our test clip rectangle.
|
|
|
|
*
|
|
|
|
* w-d-s wins very rarely though, so the race is easy to miss. You can
|
|
|
|
* make it happen by putting a delay before the call to
|
|
|
|
* create_client_and_test_surface().
|
|
|
|
*
|
|
|
|
* The weston_test_move_pointer() below makes the race irrelevant, as
|
|
|
|
* the cursor won't overlap with anything we care about.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Move the pointer away from the screenshot area. */
|
|
|
|
weston_test_move_pointer(client->test->weston_test, 0, 0);
|
|
|
|
|
2016-05-20 18:01:05 +03:00
|
|
|
buf = create_shm_buffer_a8r8g8b8(client, 100, 100);
|
|
|
|
draw_stuff(buf->image);
|
|
|
|
wl_surface_attach(surface, buf->proxy, 0, 0);
|
2015-05-25 23:19:38 +03:00
|
|
|
wl_surface_damage(surface, 0, 0, 100, 100);
|
|
|
|
wl_surface_commit(surface);
|
2015-05-15 01:07:55 +03:00
|
|
|
|
|
|
|
/* Take a snapshot. Result will be in screenshot->wl_buffer. */
|
|
|
|
printf("Taking a screenshot\n");
|
|
|
|
screenshot = capture_screenshot_of_output(client);
|
|
|
|
assert(screenshot);
|
|
|
|
|
2015-05-25 23:19:38 +03:00
|
|
|
/* Load good reference image */
|
|
|
|
fname = screenshot_reference_filename("internal-screenshot-good", 0);
|
|
|
|
printf("Loading good reference image %s\n", fname);
|
|
|
|
reference_good = load_surface_from_png(fname);
|
|
|
|
assert(reference_good);
|
|
|
|
|
|
|
|
/* Load bad reference image */
|
|
|
|
fname = screenshot_reference_filename("internal-screenshot-bad", 0);
|
|
|
|
printf("Loading bad reference image %s\n", fname);
|
|
|
|
reference_bad = load_surface_from_png(fname);
|
|
|
|
assert(reference_bad);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
|
|
|
/* Test check_surfaces_equal()
|
2015-05-25 23:19:38 +03:00
|
|
|
* We expect this to fail since we use a bad reference image
|
2014-11-05 03:39:38 +03:00
|
|
|
*/
|
2015-05-25 23:19:38 +03:00
|
|
|
match = check_surfaces_equal(screenshot, reference_bad);
|
2014-11-05 03:39:38 +03:00
|
|
|
printf("Screenshot %s reference image\n", match? "equal to" : "different from");
|
|
|
|
assert(!match);
|
tests: introduce struct buffer for client-helper
We are growing more tests that need to handle buffers, both just images
and wl_buffers. Particularly the screenshooting facility needs these.
Currently everything is in struct surface, which contains more than we
need. It is a bit messy.
Create a new struct buffer to encapsulate the image representation, the
wl_buffer, and enough information to tear it all down (munmap) so we
don't have to leak everything. Some tests might start doing things in
loops, and leaking would accumulate.
Instead of inventing our own image representation, use pixman_image_t.
It is a well-tested library worth using, and we already rely on it in
other places.
This makes the tests depend on Pixman, which requires the fix for
building buffer-count, which would otherwise not find pixman.h.
The new create_shm_buffer_a8r8g8b8() creates an image with an explicit
format, and pixman_image_t keeps track of it. And stride and size and
data. This implementation is still a little hacky due to calling
create_shm_buffer().
A very new thing is buffer_destroy(). Previously we didn't really free
any buffers. It is not a problem when the process will exit soon anyway,
but it may become a problem if tests start iterating things.
Manual memset() on a image is converted to a pixman action, just to show
how to do it properly with pixman.
Stride and pixel format assumptions still linger all around, but those
are for another patch.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-05-20 17:25:38 +03:00
|
|
|
buffer_destroy(reference_bad->buffer);
|
2015-05-25 23:19:38 +03:00
|
|
|
free(reference_bad);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
|
|
|
/* Test check_surfaces_match_in_clip()
|
|
|
|
* Alpha-blending and other effects can cause irrelevant discrepancies, so look only
|
|
|
|
* at a small portion of the solid-colored background
|
|
|
|
*/
|
2015-05-25 23:19:38 +03:00
|
|
|
clip.x = 100;
|
|
|
|
clip.y = 100;
|
|
|
|
clip.width = 100;
|
|
|
|
clip.height = 100;
|
2014-11-05 03:39:38 +03:00
|
|
|
printf("Clip: %d,%d %d x %d\n", clip.x, clip.y, clip.width, clip.height);
|
2015-05-25 23:19:38 +03:00
|
|
|
match = check_surfaces_match_in_clip(screenshot, reference_good,
|
|
|
|
&clip);
|
2014-11-05 03:39:38 +03:00
|
|
|
printf("Screenshot %s reference image in clipped area\n", match? "matches" : "doesn't match");
|
tests: introduce struct buffer for client-helper
We are growing more tests that need to handle buffers, both just images
and wl_buffers. Particularly the screenshooting facility needs these.
Currently everything is in struct surface, which contains more than we
need. It is a bit messy.
Create a new struct buffer to encapsulate the image representation, the
wl_buffer, and enough information to tear it all down (munmap) so we
don't have to leak everything. Some tests might start doing things in
loops, and leaking would accumulate.
Instead of inventing our own image representation, use pixman_image_t.
It is a well-tested library worth using, and we already rely on it in
other places.
This makes the tests depend on Pixman, which requires the fix for
building buffer-count, which would otherwise not find pixman.h.
The new create_shm_buffer_a8r8g8b8() creates an image with an explicit
format, and pixman_image_t keeps track of it. And stride and size and
data. This implementation is still a little hacky due to calling
create_shm_buffer().
A very new thing is buffer_destroy(). Previously we didn't really free
any buffers. It is not a problem when the process will exit soon anyway,
but it may become a problem if tests start iterating things.
Manual memset() on a image is converted to a pixman action, just to show
how to do it properly with pixman.
Stride and pixel format assumptions still linger all around, but those
are for another patch.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-05-20 17:25:38 +03:00
|
|
|
buffer_destroy(reference_good->buffer);
|
2015-05-25 23:19:38 +03:00
|
|
|
free(reference_good);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
|
|
|
/* Test dumping of non-matching images */
|
|
|
|
if (!match || dump_all_images) {
|
2015-05-14 22:21:13 +03:00
|
|
|
fname = screenshot_output_filename("internal-screenshot", 0);
|
|
|
|
write_surface_as_png(screenshot, fname);
|
2014-11-05 03:39:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(screenshot);
|
|
|
|
|
|
|
|
printf("Test complete\n");
|
|
|
|
assert(match);
|
|
|
|
}
|