Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2018 Collabora, Ltd. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
| 28 | #include <string.h> |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 29 | #include <unistd.h> |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 30 | |
| 31 | #include "linux-explicit-synchronization-unstable-v1-client-protocol.h" |
| 32 | #include "weston-test-client-helper.h" |
| 33 | #include "wayland-server-protocol.h" |
Pekka Paalanen | dd13498 | 2019-11-13 16:28:20 +0200 | [diff] [blame] | 34 | #include "weston-test-fixture-compositor.h" |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 35 | |
Pekka Paalanen | dd13498 | 2019-11-13 16:28:20 +0200 | [diff] [blame] | 36 | static enum test_result_code |
| 37 | fixture_setup(struct weston_test_harness *harness) |
| 38 | { |
| 39 | struct compositor_setup setup; |
| 40 | |
| 41 | compositor_setup_defaults(&setup); |
| 42 | |
| 43 | /* We need to use the pixman renderer, since a few of the tests depend |
| 44 | * on the renderer holding onto a surface buffer until the next one |
| 45 | * is committed, which the noop renderer doesn't do. */ |
| 46 | setup.renderer = RENDERER_PIXMAN; |
| 47 | |
| 48 | return weston_test_harness_execute_as_client(harness, &setup); |
| 49 | } |
| 50 | DECLARE_FIXTURE_SETUP(fixture_setup); |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 51 | |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 52 | static struct zwp_linux_explicit_synchronization_v1 * |
| 53 | get_linux_explicit_synchronization(struct client *client) |
| 54 | { |
| 55 | struct global *g; |
| 56 | struct global *global_sync = NULL; |
| 57 | struct zwp_linux_explicit_synchronization_v1 *sync = NULL; |
| 58 | |
| 59 | wl_list_for_each(g, &client->global_list, link) { |
| 60 | if (strcmp(g->interface, |
| 61 | zwp_linux_explicit_synchronization_v1_interface.name)) |
| 62 | continue; |
| 63 | |
| 64 | if (global_sync) |
| 65 | assert(!"Multiple linux explicit sync objects"); |
| 66 | |
| 67 | global_sync = g; |
| 68 | } |
| 69 | |
| 70 | assert(global_sync); |
Alexandros Frantzis | 3802241 | 2019-08-02 16:29:57 +0300 | [diff] [blame] | 71 | assert(global_sync->version == 2); |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 72 | |
| 73 | sync = wl_registry_bind( |
| 74 | client->wl_registry, global_sync->name, |
Alexandros Frantzis | 3802241 | 2019-08-02 16:29:57 +0300 | [diff] [blame] | 75 | &zwp_linux_explicit_synchronization_v1_interface, 2); |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 76 | assert(sync); |
| 77 | |
| 78 | return sync; |
| 79 | } |
| 80 | |
| 81 | static struct client * |
| 82 | create_test_client(void) |
| 83 | { |
| 84 | struct client *cl = create_client_and_test_surface(0, 0, 100, 100); |
| 85 | assert(cl); |
| 86 | return cl; |
| 87 | } |
| 88 | |
| 89 | TEST(second_surface_synchronization_on_surface_raises_error) |
| 90 | { |
| 91 | struct client *client = create_test_client(); |
| 92 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 93 | get_linux_explicit_synchronization(client); |
| 94 | struct zwp_linux_surface_synchronization_v1 *surface_sync1; |
| 95 | struct zwp_linux_surface_synchronization_v1 *surface_sync2; |
| 96 | |
| 97 | surface_sync1 = |
| 98 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 99 | sync, client->surface->wl_surface); |
| 100 | client_roundtrip(client); |
| 101 | |
| 102 | /* Second surface_synchronization creation should fail */ |
| 103 | surface_sync2 = |
| 104 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 105 | sync, client->surface->wl_surface); |
| 106 | expect_protocol_error( |
| 107 | client, |
| 108 | &zwp_linux_explicit_synchronization_v1_interface, |
| 109 | ZWP_LINUX_EXPLICIT_SYNCHRONIZATION_V1_ERROR_SYNCHRONIZATION_EXISTS); |
| 110 | |
| 111 | zwp_linux_surface_synchronization_v1_destroy(surface_sync2); |
| 112 | zwp_linux_surface_synchronization_v1_destroy(surface_sync1); |
| 113 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 114 | client_destroy(client); |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 115 | } |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 116 | |
| 117 | TEST(set_acquire_fence_with_invalid_fence_raises_error) |
| 118 | { |
| 119 | struct client *client = create_test_client(); |
| 120 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 121 | get_linux_explicit_synchronization(client); |
| 122 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 123 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 124 | sync, client->surface->wl_surface); |
| 125 | int pipefd[2] = { -1, -1 }; |
| 126 | |
| 127 | assert(pipe(pipefd) == 0); |
| 128 | |
| 129 | zwp_linux_surface_synchronization_v1_set_acquire_fence(surface_sync, |
| 130 | pipefd[0]); |
| 131 | expect_protocol_error( |
| 132 | client, |
| 133 | &zwp_linux_surface_synchronization_v1_interface, |
| 134 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_INVALID_FENCE); |
| 135 | |
| 136 | close(pipefd[0]); |
| 137 | close(pipefd[1]); |
| 138 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 139 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 140 | client_destroy(client); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | TEST(set_acquire_fence_on_destroyed_surface_raises_error) |
| 144 | { |
| 145 | struct client *client = create_test_client(); |
| 146 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 147 | get_linux_explicit_synchronization(client); |
| 148 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 149 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 150 | sync, client->surface->wl_surface); |
| 151 | int pipefd[2] = { -1, -1 }; |
| 152 | |
| 153 | assert(pipe(pipefd) == 0); |
| 154 | |
| 155 | wl_surface_destroy(client->surface->wl_surface); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 156 | client->surface->wl_surface = NULL; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 157 | zwp_linux_surface_synchronization_v1_set_acquire_fence(surface_sync, |
| 158 | pipefd[0]); |
| 159 | expect_protocol_error( |
| 160 | client, |
| 161 | &zwp_linux_surface_synchronization_v1_interface, |
| 162 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_SURFACE); |
| 163 | |
| 164 | close(pipefd[0]); |
| 165 | close(pipefd[1]); |
| 166 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 167 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 168 | client_destroy(client); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 169 | } |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 170 | |
| 171 | TEST(second_buffer_release_in_commit_raises_error) |
| 172 | { |
| 173 | struct client *client = create_test_client(); |
| 174 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 175 | get_linux_explicit_synchronization(client); |
| 176 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 177 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 178 | sync, client->surface->wl_surface); |
| 179 | struct zwp_linux_buffer_release_v1 *buffer_release1; |
| 180 | struct zwp_linux_buffer_release_v1 *buffer_release2; |
| 181 | |
| 182 | buffer_release1 = |
| 183 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 184 | client_roundtrip(client); |
| 185 | |
| 186 | /* Second buffer_release creation should fail */ |
| 187 | buffer_release2 = |
| 188 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 189 | expect_protocol_error( |
| 190 | client, |
| 191 | &zwp_linux_surface_synchronization_v1_interface, |
| 192 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_DUPLICATE_RELEASE); |
| 193 | |
| 194 | zwp_linux_buffer_release_v1_destroy(buffer_release2); |
| 195 | zwp_linux_buffer_release_v1_destroy(buffer_release1); |
| 196 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 197 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 198 | client_destroy(client); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | TEST(get_release_without_buffer_raises_commit_error) |
| 202 | { |
| 203 | struct client *client = create_test_client(); |
| 204 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 205 | get_linux_explicit_synchronization(client); |
| 206 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 207 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 208 | sync, client->surface->wl_surface); |
| 209 | struct wl_surface *surface = client->surface->wl_surface; |
| 210 | struct zwp_linux_buffer_release_v1 *buffer_release; |
| 211 | |
| 212 | buffer_release = |
| 213 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 214 | wl_surface_commit(surface); |
| 215 | expect_protocol_error( |
| 216 | client, |
| 217 | &zwp_linux_surface_synchronization_v1_interface, |
| 218 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER); |
| 219 | |
| 220 | zwp_linux_buffer_release_v1_destroy(buffer_release); |
| 221 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 222 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 223 | client_destroy(client); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | TEST(get_release_on_destroyed_surface_raises_error) |
| 227 | { |
| 228 | struct client *client = create_test_client(); |
| 229 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 230 | get_linux_explicit_synchronization(client); |
| 231 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 232 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 233 | sync, client->surface->wl_surface); |
| 234 | struct zwp_linux_buffer_release_v1 *buffer_release; |
| 235 | |
| 236 | wl_surface_destroy(client->surface->wl_surface); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 237 | client->surface->wl_surface = NULL; |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 238 | buffer_release = |
| 239 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 240 | expect_protocol_error( |
| 241 | client, |
| 242 | &zwp_linux_surface_synchronization_v1_interface, |
| 243 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_SURFACE); |
| 244 | |
| 245 | zwp_linux_buffer_release_v1_destroy(buffer_release); |
| 246 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 247 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 248 | client_destroy(client); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | TEST(get_release_after_commit_succeeds) |
| 252 | { |
| 253 | struct client *client = create_test_client(); |
| 254 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 255 | get_linux_explicit_synchronization(client); |
| 256 | struct wl_surface *surface = client->surface->wl_surface; |
| 257 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 258 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 259 | sync, surface); |
| 260 | struct buffer *buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 261 | struct zwp_linux_buffer_release_v1 *buffer_release1; |
| 262 | struct zwp_linux_buffer_release_v1 *buffer_release2; |
| 263 | |
| 264 | buffer_release1 = |
| 265 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 266 | client_roundtrip(client); |
| 267 | |
| 268 | wl_surface_attach(surface, buf1->proxy, 0, 0); |
| 269 | wl_surface_commit(surface); |
| 270 | |
| 271 | buffer_release2 = |
| 272 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 273 | client_roundtrip(client); |
| 274 | |
| 275 | buffer_destroy(buf1); |
| 276 | zwp_linux_buffer_release_v1_destroy(buffer_release2); |
| 277 | zwp_linux_buffer_release_v1_destroy(buffer_release1); |
| 278 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 279 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 280 | client_destroy(client); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static void |
| 284 | buffer_release_fenced_handler(void *data, |
| 285 | struct zwp_linux_buffer_release_v1 *buffer_release, |
| 286 | int32_t fence) |
| 287 | { |
| 288 | assert(!"Fenced release not supported yet"); |
| 289 | } |
| 290 | |
| 291 | static void |
| 292 | buffer_release_immediate_handler(void *data, |
| 293 | struct zwp_linux_buffer_release_v1 *buffer_release) |
| 294 | { |
| 295 | int *released = data; |
| 296 | |
| 297 | *released += 1; |
| 298 | } |
| 299 | |
| 300 | struct zwp_linux_buffer_release_v1_listener buffer_release_listener = { |
| 301 | buffer_release_fenced_handler, |
| 302 | buffer_release_immediate_handler |
| 303 | }; |
| 304 | |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 305 | /* The following release event tests depend on the behavior of the used |
| 306 | * backend, in this case the pixman backend. This doesn't limit their |
| 307 | * usefulness, though, since it allows them to check if, given a typical |
| 308 | * backend implementation, weston core supports the per commit nature of the |
| 309 | * release events. |
| 310 | */ |
| 311 | |
| 312 | TEST(get_release_events_are_emitted_for_different_buffers) |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 313 | { |
| 314 | struct client *client = create_test_client(); |
| 315 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 316 | get_linux_explicit_synchronization(client); |
| 317 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 318 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 319 | sync, client->surface->wl_surface); |
| 320 | struct buffer *buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 321 | struct buffer *buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 322 | struct wl_surface *surface = client->surface->wl_surface; |
| 323 | struct zwp_linux_buffer_release_v1 *buffer_release1; |
| 324 | struct zwp_linux_buffer_release_v1 *buffer_release2; |
| 325 | int buf_released1 = 0; |
| 326 | int buf_released2 = 0; |
| 327 | int frame; |
| 328 | |
| 329 | buffer_release1 = |
| 330 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 331 | zwp_linux_buffer_release_v1_add_listener(buffer_release1, |
| 332 | &buffer_release_listener, |
| 333 | &buf_released1); |
| 334 | wl_surface_attach(surface, buf1->proxy, 0, 0); |
| 335 | frame_callback_set(surface, &frame); |
| 336 | wl_surface_commit(surface); |
| 337 | frame_callback_wait(client, &frame); |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 338 | /* No release event should have been emitted yet (we are using the |
| 339 | * pixman renderer, which holds buffers until they are replaced). */ |
| 340 | assert(buf_released1 == 0); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 341 | |
| 342 | buffer_release2 = |
| 343 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 344 | zwp_linux_buffer_release_v1_add_listener(buffer_release2, |
| 345 | &buffer_release_listener, |
| 346 | &buf_released2); |
| 347 | wl_surface_attach(surface, buf2->proxy, 0, 0); |
| 348 | frame_callback_set(surface, &frame); |
| 349 | wl_surface_commit(surface); |
| 350 | frame_callback_wait(client, &frame); |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 351 | /* Check that exactly one buffer_release event was emitted for the |
| 352 | * previous commit (buf1). */ |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 353 | assert(buf_released1 == 1); |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 354 | assert(buf_released2 == 0); |
| 355 | |
| 356 | wl_surface_attach(surface, buf1->proxy, 0, 0); |
| 357 | frame_callback_set(surface, &frame); |
| 358 | wl_surface_commit(surface); |
| 359 | frame_callback_wait(client, &frame); |
| 360 | /* Check that exactly one buffer_release event was emitted for the |
| 361 | * previous commit (buf2). */ |
| 362 | assert(buf_released1 == 1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 363 | assert(buf_released2 == 1); |
| 364 | |
| 365 | buffer_destroy(buf2); |
| 366 | buffer_destroy(buf1); |
| 367 | zwp_linux_buffer_release_v1_destroy(buffer_release2); |
| 368 | zwp_linux_buffer_release_v1_destroy(buffer_release1); |
| 369 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 370 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 371 | client_destroy(client); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 372 | } |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 373 | |
| 374 | TEST(get_release_events_are_emitted_for_same_buffer_on_surface) |
| 375 | { |
| 376 | struct client *client = create_test_client(); |
| 377 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 378 | get_linux_explicit_synchronization(client); |
| 379 | struct zwp_linux_surface_synchronization_v1 *surface_sync = |
| 380 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 381 | sync, client->surface->wl_surface); |
| 382 | struct buffer *buf = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 383 | struct wl_surface *surface = client->surface->wl_surface; |
| 384 | struct zwp_linux_buffer_release_v1 *buffer_release1; |
| 385 | struct zwp_linux_buffer_release_v1 *buffer_release2; |
| 386 | int buf_released1 = 0; |
| 387 | int buf_released2 = 0; |
| 388 | int frame; |
| 389 | |
| 390 | buffer_release1 = |
| 391 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 392 | zwp_linux_buffer_release_v1_add_listener(buffer_release1, |
| 393 | &buffer_release_listener, |
| 394 | &buf_released1); |
| 395 | wl_surface_attach(surface, buf->proxy, 0, 0); |
| 396 | frame_callback_set(surface, &frame); |
| 397 | wl_surface_commit(surface); |
| 398 | frame_callback_wait(client, &frame); |
| 399 | /* No release event should have been emitted yet (we are using the |
| 400 | * pixman renderer, which holds buffers until they are replaced). */ |
| 401 | assert(buf_released1 == 0); |
| 402 | |
| 403 | buffer_release2 = |
| 404 | zwp_linux_surface_synchronization_v1_get_release(surface_sync); |
| 405 | zwp_linux_buffer_release_v1_add_listener(buffer_release2, |
| 406 | &buffer_release_listener, |
| 407 | &buf_released2); |
| 408 | wl_surface_attach(surface, buf->proxy, 0, 0); |
| 409 | frame_callback_set(surface, &frame); |
| 410 | wl_surface_commit(surface); |
| 411 | frame_callback_wait(client, &frame); |
| 412 | /* Check that exactly one buffer_release event was emitted for the |
| 413 | * previous commit (buf). */ |
| 414 | assert(buf_released1 == 1); |
| 415 | assert(buf_released2 == 0); |
| 416 | |
| 417 | wl_surface_attach(surface, buf->proxy, 0, 0); |
| 418 | frame_callback_set(surface, &frame); |
| 419 | wl_surface_commit(surface); |
| 420 | frame_callback_wait(client, &frame); |
| 421 | /* Check that exactly one buffer_release event was emitted for the |
| 422 | * previous commit (buf again). */ |
| 423 | assert(buf_released1 == 1); |
| 424 | assert(buf_released2 == 1); |
| 425 | |
| 426 | buffer_destroy(buf); |
| 427 | zwp_linux_buffer_release_v1_destroy(buffer_release2); |
| 428 | zwp_linux_buffer_release_v1_destroy(buffer_release1); |
| 429 | zwp_linux_surface_synchronization_v1_destroy(surface_sync); |
| 430 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 431 | client_destroy(client); |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | TEST(get_release_events_are_emitted_for_same_buffer_on_different_surfaces) |
| 435 | { |
| 436 | struct client *client = create_test_client(); |
| 437 | struct surface *other_surface = create_test_surface(client); |
| 438 | struct wl_surface *surface1 = client->surface->wl_surface; |
| 439 | struct wl_surface *surface2 = other_surface->wl_surface; |
| 440 | struct zwp_linux_explicit_synchronization_v1 *sync = |
| 441 | get_linux_explicit_synchronization(client); |
| 442 | struct zwp_linux_surface_synchronization_v1 *surface_sync1 = |
| 443 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 444 | sync, surface1); |
| 445 | struct zwp_linux_surface_synchronization_v1 *surface_sync2 = |
| 446 | zwp_linux_explicit_synchronization_v1_get_synchronization( |
| 447 | sync, surface2); |
| 448 | struct buffer *buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 449 | struct buffer *buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100); |
| 450 | struct zwp_linux_buffer_release_v1 *buffer_release1; |
| 451 | struct zwp_linux_buffer_release_v1 *buffer_release2; |
| 452 | int buf_released1 = 0; |
| 453 | int buf_released2 = 0; |
| 454 | int frame; |
| 455 | |
| 456 | weston_test_move_surface(client->test->weston_test, surface2, 0, 0); |
| 457 | |
| 458 | /* Attach buf1 to both surface1 and surface2. */ |
| 459 | buffer_release1 = |
| 460 | zwp_linux_surface_synchronization_v1_get_release(surface_sync1); |
| 461 | zwp_linux_buffer_release_v1_add_listener(buffer_release1, |
| 462 | &buffer_release_listener, |
| 463 | &buf_released1); |
| 464 | wl_surface_attach(surface1, buf1->proxy, 0, 0); |
| 465 | frame_callback_set(surface1, &frame); |
| 466 | wl_surface_commit(surface1); |
| 467 | frame_callback_wait(client, &frame); |
| 468 | |
| 469 | buffer_release2 = |
| 470 | zwp_linux_surface_synchronization_v1_get_release(surface_sync2); |
| 471 | zwp_linux_buffer_release_v1_add_listener(buffer_release2, |
| 472 | &buffer_release_listener, |
| 473 | &buf_released2); |
| 474 | wl_surface_attach(surface2, buf1->proxy, 0, 0); |
| 475 | frame_callback_set(surface2, &frame); |
| 476 | wl_surface_commit(surface2); |
| 477 | frame_callback_wait(client, &frame); |
| 478 | |
| 479 | assert(buf_released1 == 0); |
| 480 | assert(buf_released2 == 0); |
| 481 | |
| 482 | /* Attach buf2 to surface1, and check that a buffer_release event for |
| 483 | * the previous commit (buf1) for that surface is emitted. */ |
| 484 | wl_surface_attach(surface1, buf2->proxy, 0, 0); |
| 485 | frame_callback_set(surface1, &frame); |
| 486 | wl_surface_commit(surface1); |
| 487 | frame_callback_wait(client, &frame); |
| 488 | |
| 489 | assert(buf_released1 == 1); |
| 490 | assert(buf_released2 == 0); |
| 491 | |
| 492 | /* Attach buf2 to surface2, and check that a buffer_release event for |
| 493 | * the previous commit (buf1) for that surface is emitted. */ |
| 494 | wl_surface_attach(surface2, buf2->proxy, 0, 0); |
| 495 | frame_callback_set(surface2, &frame); |
| 496 | wl_surface_commit(surface2); |
| 497 | frame_callback_wait(client, &frame); |
| 498 | |
| 499 | assert(buf_released1 == 1); |
| 500 | assert(buf_released2 == 1); |
| 501 | |
| 502 | buffer_destroy(buf2); |
| 503 | buffer_destroy(buf1); |
| 504 | zwp_linux_buffer_release_v1_destroy(buffer_release2); |
| 505 | zwp_linux_buffer_release_v1_destroy(buffer_release1); |
| 506 | zwp_linux_surface_synchronization_v1_destroy(surface_sync2); |
| 507 | zwp_linux_surface_synchronization_v1_destroy(surface_sync1); |
| 508 | zwp_linux_explicit_synchronization_v1_destroy(sync); |
Pekka Paalanen | 4f515a1 | 2021-06-18 12:57:26 +0300 | [diff] [blame] | 509 | surface_destroy(other_surface); |
| 510 | client_destroy(client); |
Alexandros Frantzis | c715c75 | 2018-11-12 18:33:54 +0200 | [diff] [blame] | 511 | } |