Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 3 | * Copyright © 2013 Collabora, Ltd. |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 4 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 12 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 25 | */ |
| 26 | |
Bryce Harrington | 12cc405 | 2014-11-19 17:18:33 -0800 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 29 | #include "weston-test-client-helper.h" |
Pekka Paalanen | 701676d | 2019-11-13 15:45:10 +0200 | [diff] [blame] | 30 | #include "weston-test-fixture-compositor.h" |
| 31 | |
| 32 | static enum test_result_code |
| 33 | fixture_setup(struct weston_test_harness *harness) |
| 34 | { |
| 35 | struct compositor_setup setup; |
| 36 | |
| 37 | compositor_setup_defaults(&setup); |
| 38 | |
| 39 | return weston_test_harness_execute_as_client(harness, &setup); |
| 40 | } |
| 41 | DECLARE_FIXTURE_SETUP(fixture_setup); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 42 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 43 | static int |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 44 | output_contains_client(struct client *client) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 45 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 46 | struct output *output = client->output; |
| 47 | struct surface *surface = client->surface; |
| 48 | |
| 49 | return !(output->x >= surface->x + surface->width |
| 50 | || output->x + output->width <= surface->x |
| 51 | || output->y >= surface->y + surface->height |
| 52 | || output->y + output->height <= surface->y); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 56 | check_client_move(struct client *client, int x, int y) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 57 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 58 | move_client(client, x, y); |
| 59 | |
| 60 | if (output_contains_client(client)) { |
| 61 | assert(client->surface->output == client->output); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 62 | } else { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 63 | assert(client->surface->output == NULL); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 67 | TEST(test_surface_output) |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 68 | { |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 69 | struct client *client; |
| 70 | int x, y; |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 71 | |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 72 | client = create_client_and_test_surface(100, 100, 100, 100); |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 73 | assert(client); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 74 | |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 75 | assert(output_contains_client(client)); |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 76 | |
| 77 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 78 | x = 0; |
| 79 | y = -client->surface->height; |
| 80 | check_client_move(client, x, y); |
| 81 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 82 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 83 | check_client_move(client, x, ++y); |
| 84 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 85 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 86 | x = -client->surface->width; |
| 87 | y = 0; |
| 88 | check_client_move(client, x, y); |
| 89 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 90 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 91 | check_client_move(client, ++x, y); |
| 92 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 93 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 94 | x = client->output->width; |
| 95 | y = 0; |
| 96 | check_client_move(client, x, y); |
| 97 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 98 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 99 | check_client_move(client, --x, y); |
| 100 | assert(output_contains_client(client)); |
| 101 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 102 | /* not visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 103 | x = 0; |
| 104 | y = client->output->height; |
| 105 | check_client_move(client, x, y); |
| 106 | assert(!output_contains_client(client)); |
| 107 | |
U. Artie Eoff | 1ae298f | 2012-09-28 06:39:30 -0700 | [diff] [blame] | 108 | /* visible */ |
U. Artie Eoff | 84f9db5 | 2012-12-07 13:50:33 -0800 | [diff] [blame] | 109 | check_client_move(client, x, --y); |
| 110 | assert(output_contains_client(client)); |
Pekka Paalanen | d3acfd3 | 2021-06-14 14:25:08 +0300 | [diff] [blame] | 111 | |
| 112 | client_destroy(client); |
Kristian Høgsberg | 3018b44 | 2012-04-27 15:02:56 -0400 | [diff] [blame] | 113 | } |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 114 | |
| 115 | static void |
| 116 | buffer_release_handler(void *data, struct wl_buffer *buffer) |
| 117 | { |
| 118 | int *released = data; |
| 119 | |
| 120 | *released = 1; |
| 121 | } |
| 122 | |
| 123 | static struct wl_buffer_listener buffer_listener = { |
| 124 | buffer_release_handler |
| 125 | }; |
| 126 | |
| 127 | TEST(buffer_release) |
| 128 | { |
| 129 | struct client *client; |
| 130 | struct wl_surface *surface; |
Pekka Paalanen | 7789acd | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 131 | struct buffer *buf1; |
| 132 | struct buffer *buf2; |
| 133 | struct buffer *buf3; |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 134 | int buf1_released = 0; |
| 135 | int buf2_released = 0; |
| 136 | int buf3_released = 0; |
| 137 | int frame; |
| 138 | |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 139 | client = create_client_and_test_surface(100, 100, 100, 100); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 140 | assert(client); |
| 141 | surface = client->surface->wl_surface; |
| 142 | |
Pekka Paalanen | 7789acd | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 143 | buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 144 | wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 145 | |
Pekka Paalanen | 7789acd | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 146 | buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 147 | wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 148 | |
Pekka Paalanen | 7789acd | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 149 | buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 150 | wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * buf1 must never be released, since it is replaced before |
| 154 | * it is committed, therefore it never becomes busy. |
| 155 | */ |
| 156 | |
Pekka Paalanen | 7789acd | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 157 | wl_surface_attach(surface, buf1->proxy, 0, 0); |
| 158 | wl_surface_attach(surface, buf2->proxy, 0, 0); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 159 | frame_callback_set(surface, &frame); |
| 160 | wl_surface_commit(surface); |
| 161 | frame_callback_wait(client, &frame); |
| 162 | assert(buf1_released == 0); |
| 163 | /* buf2 may or may not be released */ |
| 164 | assert(buf3_released == 0); |
| 165 | |
Pekka Paalanen | 7789acd | 2016-05-20 18:01:05 +0300 | [diff] [blame] | 166 | wl_surface_attach(surface, buf3->proxy, 0, 0); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 167 | frame_callback_set(surface, &frame); |
| 168 | wl_surface_commit(surface); |
| 169 | frame_callback_wait(client, &frame); |
| 170 | assert(buf1_released == 0); |
| 171 | assert(buf2_released == 1); |
| 172 | /* buf3 may or may not be released */ |
| 173 | |
Pekka Paalanen | 924cd94 | 2016-05-20 17:25:38 +0300 | [diff] [blame] | 174 | wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 175 | frame_callback_set(surface, &frame); |
| 176 | wl_surface_commit(surface); |
| 177 | frame_callback_wait(client, &frame); |
| 178 | assert(buf1_released == 0); |
| 179 | assert(buf2_released == 1); |
| 180 | assert(buf3_released == 1); |
Pekka Paalanen | d3acfd3 | 2021-06-14 14:25:08 +0300 | [diff] [blame] | 181 | |
| 182 | buffer_destroy(buf1); |
| 183 | buffer_destroy(buf2); |
| 184 | buffer_destroy(buf3); |
| 185 | client_destroy(client); |
Pekka Paalanen | d1c426e | 2013-02-08 17:01:27 +0200 | [diff] [blame] | 186 | } |