2 * Copyright © 2014 Collabora, Ltd.
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:
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.
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
35 #include "shared/helpers.h"
36 #include "shared/xalloc.h"
37 #include "shared/timespec-util.h"
38 #include "weston-test-client-helper.h"
39 #include "presentation-time-client-protocol.h"
41 static struct wp_presentation *
42 get_presentation(struct client *client)
45 struct global *global_pres = NULL;
46 static struct wp_presentation *pres;
51 wl_list_for_each(g, &client->global_list, link) {
52 if (strcmp(g->interface, wp_presentation_interface.name))
56 assert(0 && "multiple presentation objects");
61 assert(global_pres && "no presentation found");
63 assert(global_pres->version == 1);
65 pres = wl_registry_bind(client->wl_registry, global_pres->name,
66 &wp_presentation_interface, 1);
73 struct client *client;
74 struct wp_presentation_feedback *obj;
82 struct wl_output *sync_output;
85 uint32_t refresh_nsec;
90 feedback_sync_output(void *data,
91 struct wp_presentation_feedback *presentation_feedback,
92 struct wl_output *output)
94 struct feedback *fb = data;
96 assert(fb->result == FB_PENDING);
99 fb->sync_output = output;
103 feedback_presented(void *data,
104 struct wp_presentation_feedback *presentation_feedback,
108 uint32_t refresh_nsec,
113 struct feedback *fb = data;
115 assert(fb->result == FB_PENDING);
116 fb->result = FB_PRESENTED;
117 fb->seq = ((uint64_t)seq_hi << 32) + seq_lo;
118 timespec_from_proto(&fb->time, tv_sec_hi, tv_sec_lo, tv_nsec);
119 fb->refresh_nsec = refresh_nsec;
124 feedback_discarded(void *data,
125 struct wp_presentation_feedback *presentation_feedback)
127 struct feedback *fb = data;
129 assert(fb->result == FB_PENDING);
130 fb->result = FB_DISCARDED;
133 static const struct wp_presentation_feedback_listener feedback_listener = {
134 feedback_sync_output,
139 static struct feedback *
140 feedback_create(struct client *client, struct wl_surface *surface)
144 fb = xzalloc(sizeof *fb);
146 fb->obj = wp_presentation_feedback(get_presentation(client), surface);
147 wp_presentation_feedback_add_listener(fb->obj, &feedback_listener, fb);
153 feedback_wait(struct feedback *fb)
155 while (fb->result == FB_PENDING) {
156 assert(wl_display_dispatch(fb->client->wl_display) >= 0);
161 pflags_to_str(uint32_t flags, char *str, unsigned len)
163 static const struct {
167 { WP_PRESENTATION_FEEDBACK_KIND_VSYNC, 's' },
168 { WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK, 'c' },
169 { WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION, 'e' },
170 { WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY, 'z' },
175 if (len < ARRAY_LENGTH(desc) + 1)
178 for (i = 0; i < ARRAY_LENGTH(desc); i++)
179 str[i] = flags & desc[i].flag ? desc[i].sym : '_';
180 str[ARRAY_LENGTH(desc)] = '\0';
186 feedback_print(struct feedback *fb)
190 switch (fb->result) {
201 pflags_to_str(fb->flags, str, sizeof str);
202 printf("presented %lld.%09lld, refresh %u us, [%s] seq %" PRIu64,
203 (long long)fb->time.tv_sec, (long long)fb->time.tv_nsec,
204 fb->refresh_nsec / 1000, str, fb->seq);
208 feedback_destroy(struct feedback *fb)
210 wp_presentation_feedback_destroy(fb->obj);
214 TEST(test_presentation_feedback_simple)
216 struct client *client;
219 client = create_client_and_test_surface(100, 50, 123, 77);
222 wl_surface_attach(client->surface->wl_surface,
223 client->surface->buffer->proxy, 0, 0);
224 fb = feedback_create(client, client->surface->wl_surface);
225 wl_surface_damage(client->surface->wl_surface, 0, 0, 100, 100);
226 wl_surface_commit(client->surface->wl_surface);
228 client_roundtrip(client);
232 printf("%s feedback:", __func__);
236 feedback_destroy(fb);