2012-04-27 23:02:56 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
2013-02-08 19:01:27 +04:00
|
|
|
* Copyright © 2013 Collabora, Ltd.
|
2012-04-27 23:02:56 +04:00
|
|
|
*
|
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:
|
2012-04-27 23:02:56 +04: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.
|
2012-04-27 23:02:56 +04:00
|
|
|
*/
|
|
|
|
|
2014-11-20 04:18:33 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
#include "weston-test-client-helper.h"
|
2019-11-13 16:45:10 +03:00
|
|
|
#include "weston-test-fixture-compositor.h"
|
|
|
|
|
|
|
|
static enum test_result_code
|
|
|
|
fixture_setup(struct weston_test_harness *harness)
|
|
|
|
{
|
|
|
|
struct compositor_setup setup;
|
|
|
|
|
|
|
|
compositor_setup_defaults(&setup);
|
|
|
|
|
|
|
|
return weston_test_harness_execute_as_client(harness, &setup);
|
|
|
|
}
|
|
|
|
DECLARE_FIXTURE_SETUP(fixture_setup);
|
2012-09-28 17:39:30 +04:00
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
static int
|
|
|
|
output_contains_client(struct client *client)
|
|
|
|
{
|
|
|
|
struct output *output = client->output;
|
|
|
|
struct surface *surface = client->surface;
|
2012-09-28 17:39:30 +04:00
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
return !(output->x >= surface->x + surface->width
|
|
|
|
|| output->x + output->width <= surface->x
|
|
|
|
|| output->y >= surface->y + surface->height
|
|
|
|
|| output->y + output->height <= surface->y);
|
2012-09-28 17:39:30 +04:00
|
|
|
}
|
|
|
|
|
2012-04-27 23:02:56 +04:00
|
|
|
static void
|
2012-12-08 01:50:33 +04:00
|
|
|
check_client_move(struct client *client, int x, int y)
|
2012-04-27 23:02:56 +04:00
|
|
|
{
|
2012-12-08 01:50:33 +04:00
|
|
|
move_client(client, x, y);
|
|
|
|
|
|
|
|
if (output_contains_client(client)) {
|
|
|
|
assert(client->surface->output == client->output);
|
|
|
|
} else {
|
|
|
|
assert(client->surface->output == NULL);
|
|
|
|
}
|
2012-04-27 23:02:56 +04:00
|
|
|
}
|
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
TEST(test_surface_output)
|
2012-04-27 23:02:56 +04:00
|
|
|
{
|
2012-12-08 01:50:33 +04:00
|
|
|
struct client *client;
|
|
|
|
int x, y;
|
|
|
|
|
2015-03-26 13:56:10 +03:00
|
|
|
client = create_client_and_test_surface(100, 100, 100, 100);
|
2012-12-08 01:50:33 +04:00
|
|
|
assert(client);
|
2012-04-27 23:02:56 +04:00
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
assert(output_contains_client(client));
|
2012-04-27 23:02:56 +04:00
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
/* not visible */
|
|
|
|
x = 0;
|
|
|
|
y = -client->surface->height;
|
|
|
|
check_client_move(client, x, y);
|
2012-04-27 23:02:56 +04:00
|
|
|
|
2012-12-08 01:50:33 +04:00
|
|
|
/* visible */
|
|
|
|
check_client_move(client, x, ++y);
|
|
|
|
|
|
|
|
/* not visible */
|
|
|
|
x = -client->surface->width;
|
|
|
|
y = 0;
|
|
|
|
check_client_move(client, x, y);
|
|
|
|
|
|
|
|
/* visible */
|
|
|
|
check_client_move(client, ++x, y);
|
|
|
|
|
|
|
|
/* not visible */
|
|
|
|
x = client->output->width;
|
|
|
|
y = 0;
|
|
|
|
check_client_move(client, x, y);
|
|
|
|
|
|
|
|
/* visible */
|
|
|
|
check_client_move(client, --x, y);
|
|
|
|
assert(output_contains_client(client));
|
|
|
|
|
|
|
|
/* not visible */
|
|
|
|
x = 0;
|
|
|
|
y = client->output->height;
|
|
|
|
check_client_move(client, x, y);
|
|
|
|
assert(!output_contains_client(client));
|
|
|
|
|
|
|
|
/* visible */
|
|
|
|
check_client_move(client, x, --y);
|
|
|
|
assert(output_contains_client(client));
|
2021-06-14 14:25:08 +03:00
|
|
|
|
|
|
|
client_destroy(client);
|
2012-04-27 23:02:56 +04:00
|
|
|
}
|
2013-02-08 19:01:27 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
buffer_release_handler(void *data, struct wl_buffer *buffer)
|
|
|
|
{
|
|
|
|
int *released = data;
|
|
|
|
|
|
|
|
*released = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wl_buffer_listener buffer_listener = {
|
|
|
|
buffer_release_handler
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(buffer_release)
|
|
|
|
{
|
|
|
|
struct client *client;
|
|
|
|
struct wl_surface *surface;
|
2016-05-20 18:01:05 +03:00
|
|
|
struct buffer *buf1;
|
|
|
|
struct buffer *buf2;
|
|
|
|
struct buffer *buf3;
|
2013-02-08 19:01:27 +04:00
|
|
|
int buf1_released = 0;
|
|
|
|
int buf2_released = 0;
|
|
|
|
int buf3_released = 0;
|
|
|
|
int frame;
|
|
|
|
|
2015-03-26 13:56:10 +03:00
|
|
|
client = create_client_and_test_surface(100, 100, 100, 100);
|
2013-02-08 19:01:27 +04:00
|
|
|
assert(client);
|
|
|
|
surface = client->surface->wl_surface;
|
|
|
|
|
2016-05-20 18:01:05 +03:00
|
|
|
buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100);
|
|
|
|
wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released);
|
2013-02-08 19:01:27 +04:00
|
|
|
|
2016-05-20 18:01:05 +03:00
|
|
|
buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100);
|
|
|
|
wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released);
|
2013-02-08 19:01:27 +04:00
|
|
|
|
2016-05-20 18:01:05 +03:00
|
|
|
buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100);
|
|
|
|
wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released);
|
2013-02-08 19:01:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* buf1 must never be released, since it is replaced before
|
|
|
|
* it is committed, therefore it never becomes busy.
|
|
|
|
*/
|
|
|
|
|
2016-05-20 18:01:05 +03:00
|
|
|
wl_surface_attach(surface, buf1->proxy, 0, 0);
|
|
|
|
wl_surface_attach(surface, buf2->proxy, 0, 0);
|
2013-02-08 19:01:27 +04:00
|
|
|
frame_callback_set(surface, &frame);
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
frame_callback_wait(client, &frame);
|
|
|
|
assert(buf1_released == 0);
|
|
|
|
/* buf2 may or may not be released */
|
|
|
|
assert(buf3_released == 0);
|
|
|
|
|
2016-05-20 18:01:05 +03:00
|
|
|
wl_surface_attach(surface, buf3->proxy, 0, 0);
|
2013-02-08 19:01:27 +04:00
|
|
|
frame_callback_set(surface, &frame);
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
frame_callback_wait(client, &frame);
|
|
|
|
assert(buf1_released == 0);
|
|
|
|
assert(buf2_released == 1);
|
|
|
|
/* buf3 may or may not be released */
|
|
|
|
|
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
|
|
|
wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0);
|
2013-02-08 19:01:27 +04:00
|
|
|
frame_callback_set(surface, &frame);
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
frame_callback_wait(client, &frame);
|
|
|
|
assert(buf1_released == 0);
|
|
|
|
assert(buf2_released == 1);
|
|
|
|
assert(buf3_released == 1);
|
2021-06-14 14:25:08 +03:00
|
|
|
|
|
|
|
buffer_destroy(buf1);
|
|
|
|
buffer_destroy(buf2);
|
|
|
|
buffer_destroy(buf3);
|
|
|
|
client_destroy(client);
|
2013-02-08 19:01:27 +04:00
|
|
|
}
|