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"
|
|
|
|
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2014-11-05 03:39:38 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "weston-test-client-helper.h"
|
2019-11-11 18:29:41 +03:00
|
|
|
#include "weston-test-fixture-compositor.h"
|
2022-06-13 12:58:35 +03:00
|
|
|
#include "image-iter.h"
|
2019-11-11 18:29:41 +03:00
|
|
|
#include "test-config.h"
|
2014-11-05 03:39:38 +03:00
|
|
|
|
2019-11-11 18:29:41 +03:00
|
|
|
static enum test_result_code
|
|
|
|
fixture_setup(struct weston_test_harness *harness)
|
|
|
|
{
|
|
|
|
struct compositor_setup setup;
|
|
|
|
|
|
|
|
compositor_setup_defaults(&setup);
|
2022-12-05 19:05:21 +03:00
|
|
|
setup.renderer = WESTON_RENDERER_PIXMAN;
|
2019-11-11 18:29:41 +03:00
|
|
|
setup.width = 320;
|
|
|
|
setup.height = 240;
|
|
|
|
setup.shell = SHELL_DESKTOP;
|
2024-02-20 23:09:41 +03:00
|
|
|
setup.refresh = HIGHEST_OUTPUT_REFRESH;
|
2020-08-16 03:19:13 +03:00
|
|
|
|
|
|
|
weston_ini_setup (&setup,
|
|
|
|
cfgln("[shell]"),
|
|
|
|
cfgln("startup-animation=%s", "none"),
|
|
|
|
cfgln("background-color=%s", "0xCC336699"));
|
2019-11-11 18:29:41 +03:00
|
|
|
|
|
|
|
return weston_test_harness_execute_as_client(harness, &setup);
|
|
|
|
}
|
|
|
|
DECLARE_FIXTURE_SETUP(fixture_setup);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
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
|
|
|
{
|
2022-06-13 12:58:35 +03:00
|
|
|
struct image_header ih = image_header_from(image);
|
2015-05-25 23:19:38 +03:00
|
|
|
int x, y;
|
2019-10-16 23:07:47 +03:00
|
|
|
uint32_t r, g, b;
|
2016-05-20 18:01:05 +03:00
|
|
|
|
2022-06-13 12:58:35 +03:00
|
|
|
for (y = 0; y < ih.height; y++) {
|
|
|
|
uint32_t *pixel = image_header_get_row_u32(&ih, y);
|
2016-05-20 18:01:05 +03:00
|
|
|
|
2022-06-13 12:58:35 +03:00
|
|
|
for (x = 0; x < ih.width; x++, pixel++) {
|
2015-05-26 20:00:49 +03:00
|
|
|
b = x;
|
|
|
|
g = x + y;
|
|
|
|
r = y;
|
2019-10-16 23:07:47 +03:00
|
|
|
*pixel = (255U << 24) | (r << 16) | (g << 8) | b;
|
2015-05-25 23:19:38 +03:00
|
|
|
}
|
2022-06-13 12:58:35 +03:00
|
|
|
}
|
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;
|
2016-05-27 14:11:01 +03:00
|
|
|
struct buffer *screenshot = NULL;
|
2016-05-25 11:47:41 +03:00
|
|
|
pixman_image_t *reference_good = NULL;
|
|
|
|
pixman_image_t *reference_bad = NULL;
|
2016-06-02 18:02:46 +03:00
|
|
|
pixman_image_t *diffimg;
|
2015-05-15 01:07:55 +03:00
|
|
|
struct rectangle clip;
|
2021-06-14 14:30:22 +03:00
|
|
|
char *fname;
|
2015-05-15 01:07:55 +03:00
|
|
|
bool match = false;
|
|
|
|
bool dump_all_images = true;
|
|
|
|
|
|
|
|
/* Create the client */
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Creating client for test\n");
|
2015-05-15 01:07:55 +03:00
|
|
|
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. */
|
2017-12-13 14:27:55 +03:00
|
|
|
weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 0, 0);
|
2016-06-10 10:50:04 +03:00
|
|
|
|
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. */
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Taking a screenshot\n");
|
2022-11-30 18:54:16 +03:00
|
|
|
screenshot = capture_screenshot_of_output(client, NULL);
|
2015-05-15 01:07:55 +03:00
|
|
|
assert(screenshot);
|
|
|
|
|
2015-05-25 23:19:38 +03:00
|
|
|
/* Load good reference image */
|
|
|
|
fname = screenshot_reference_filename("internal-screenshot-good", 0);
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Loading good reference image %s\n", fname);
|
2016-05-25 11:47:41 +03:00
|
|
|
reference_good = load_image_from_png(fname);
|
2015-05-25 23:19:38 +03:00
|
|
|
assert(reference_good);
|
2021-06-14 14:30:22 +03:00
|
|
|
free(fname);
|
2015-05-25 23:19:38 +03:00
|
|
|
|
|
|
|
/* Load bad reference image */
|
|
|
|
fname = screenshot_reference_filename("internal-screenshot-bad", 0);
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Loading bad reference image %s\n", fname);
|
2016-05-25 11:47:41 +03:00
|
|
|
reference_bad = load_image_from_png(fname);
|
2015-05-25 23:19:38 +03:00
|
|
|
assert(reference_bad);
|
2021-06-14 14:30:22 +03:00
|
|
|
free(fname);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
2016-05-23 17:42:27 +03:00
|
|
|
/* Test check_images_match() without a clip.
|
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
|
|
|
*/
|
2019-11-25 15:54:06 +03:00
|
|
|
match = check_images_match(screenshot->image, reference_bad, NULL, NULL);
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Screenshot %s reference image\n", match? "equal to" : "different from");
|
2014-11-05 03:39:38 +03:00
|
|
|
assert(!match);
|
2016-05-25 11:47:41 +03:00
|
|
|
pixman_image_unref(reference_bad);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
2016-05-23 17:42:27 +03:00
|
|
|
/* Test check_images_match() with clip.
|
2014-11-05 03:39:38 +03:00
|
|
|
* 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;
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Clip: %d,%d %d x %d\n", clip.x, clip.y, clip.width, clip.height);
|
2019-11-25 15:54:06 +03:00
|
|
|
match = check_images_match(screenshot->image, reference_good, &clip, NULL);
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Screenshot %s reference image in clipped area\n", match? "matches" : "doesn't match");
|
2016-06-02 18:02:46 +03:00
|
|
|
if (!match) {
|
2019-11-25 15:54:06 +03:00
|
|
|
diffimg = visualize_image_difference(screenshot->image, reference_good, &clip, NULL);
|
2024-02-08 00:29:31 +03:00
|
|
|
fname = output_filename_for_test_case("error", 0, "png");
|
2016-06-02 18:02:46 +03:00
|
|
|
write_image_as_png(diffimg, fname);
|
|
|
|
pixman_image_unref(diffimg);
|
2021-06-14 14:30:22 +03:00
|
|
|
free(fname);
|
2016-06-02 18:02:46 +03:00
|
|
|
}
|
2016-05-25 11:47:41 +03:00
|
|
|
pixman_image_unref(reference_good);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
|
|
|
/* Test dumping of non-matching images */
|
|
|
|
if (!match || dump_all_images) {
|
2024-02-08 00:29:31 +03:00
|
|
|
fname = output_filename_for_test_case(NULL, 0, "png");
|
2016-05-27 14:11:01 +03:00
|
|
|
write_image_as_png(screenshot->image, fname);
|
2021-06-14 14:30:22 +03:00
|
|
|
free(fname);
|
2014-11-05 03:39:38 +03:00
|
|
|
}
|
|
|
|
|
2016-05-27 14:11:01 +03:00
|
|
|
buffer_destroy(screenshot);
|
2014-11-05 03:39:38 +03:00
|
|
|
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("Test complete\n");
|
2014-11-05 03:39:38 +03:00
|
|
|
assert(match);
|
2021-06-14 14:30:22 +03:00
|
|
|
|
|
|
|
buffer_destroy(buf);
|
|
|
|
client_destroy(client);
|
2014-11-05 03:39:38 +03:00
|
|
|
}
|