2014-09-24 06:08:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Collabora, 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-09-24 06:08:48 +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.
|
2014-09-24 06:08:48 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2014-09-24 06:08:48 +04:00
|
|
|
#include <stdio.h>
|
2014-11-20 04:18:34 +03:00
|
|
|
#include <stdlib.h>
|
2014-09-24 06:08:48 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2015-06-16 01:37:08 +03:00
|
|
|
#include "shared/helpers.h"
|
2016-03-17 00:15:18 +03:00
|
|
|
#include "shared/xalloc.h"
|
2017-12-13 14:27:53 +03:00
|
|
|
#include "shared/timespec-util.h"
|
2014-09-24 06:08:48 +04:00
|
|
|
#include "weston-test-client-helper.h"
|
2016-02-18 17:53:27 +03:00
|
|
|
#include "presentation-time-client-protocol.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);
|
2014-09-24 06:08:48 +04:00
|
|
|
|
2016-02-18 17:53:27 +03:00
|
|
|
static struct wp_presentation *
|
2014-09-24 06:08:48 +04:00
|
|
|
get_presentation(struct client *client)
|
|
|
|
{
|
|
|
|
struct global *g;
|
|
|
|
struct global *global_pres = NULL;
|
2019-11-13 16:50:51 +03:00
|
|
|
struct wp_presentation *pres;
|
2014-09-24 06:08:48 +04:00
|
|
|
|
|
|
|
wl_list_for_each(g, &client->global_list, link) {
|
2016-02-18 17:53:27 +03:00
|
|
|
if (strcmp(g->interface, wp_presentation_interface.name))
|
2014-09-24 06:08:48 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (global_pres)
|
|
|
|
assert(0 && "multiple presentation objects");
|
|
|
|
|
|
|
|
global_pres = g;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(global_pres && "no presentation found");
|
|
|
|
|
|
|
|
assert(global_pres->version == 1);
|
|
|
|
|
|
|
|
pres = wl_registry_bind(client->wl_registry, global_pres->name,
|
2016-02-18 17:53:27 +03:00
|
|
|
&wp_presentation_interface, 1);
|
2014-09-24 06:08:48 +04:00
|
|
|
assert(pres);
|
|
|
|
|
|
|
|
return pres;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct feedback {
|
|
|
|
struct client *client;
|
2016-02-18 17:53:27 +03:00
|
|
|
struct wp_presentation_feedback *obj;
|
2014-09-24 06:08:48 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
FB_PENDING = 0,
|
|
|
|
FB_PRESENTED,
|
|
|
|
FB_DISCARDED
|
|
|
|
} result;
|
|
|
|
|
|
|
|
struct wl_output *sync_output;
|
|
|
|
uint64_t seq;
|
|
|
|
struct timespec time;
|
|
|
|
uint32_t refresh_nsec;
|
|
|
|
uint32_t flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
feedback_sync_output(void *data,
|
2016-02-18 17:53:27 +03:00
|
|
|
struct wp_presentation_feedback *presentation_feedback,
|
2014-09-24 06:08:48 +04:00
|
|
|
struct wl_output *output)
|
|
|
|
{
|
|
|
|
struct feedback *fb = data;
|
|
|
|
|
|
|
|
assert(fb->result == FB_PENDING);
|
|
|
|
|
|
|
|
if (output)
|
|
|
|
fb->sync_output = output;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
feedback_presented(void *data,
|
2016-02-18 17:53:27 +03:00
|
|
|
struct wp_presentation_feedback *presentation_feedback,
|
2014-09-24 06:08:48 +04:00
|
|
|
uint32_t tv_sec_hi,
|
|
|
|
uint32_t tv_sec_lo,
|
|
|
|
uint32_t tv_nsec,
|
|
|
|
uint32_t refresh_nsec,
|
|
|
|
uint32_t seq_hi,
|
|
|
|
uint32_t seq_lo,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
struct feedback *fb = data;
|
|
|
|
|
|
|
|
assert(fb->result == FB_PENDING);
|
|
|
|
fb->result = FB_PRESENTED;
|
2022-10-25 22:54:58 +03:00
|
|
|
fb->seq = u64_from_u32s(seq_hi, seq_lo);
|
2014-09-24 06:08:48 +04:00
|
|
|
timespec_from_proto(&fb->time, tv_sec_hi, tv_sec_lo, tv_nsec);
|
|
|
|
fb->refresh_nsec = refresh_nsec;
|
|
|
|
fb->flags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
feedback_discarded(void *data,
|
2016-02-18 17:53:27 +03:00
|
|
|
struct wp_presentation_feedback *presentation_feedback)
|
2014-09-24 06:08:48 +04:00
|
|
|
{
|
|
|
|
struct feedback *fb = data;
|
|
|
|
|
|
|
|
assert(fb->result == FB_PENDING);
|
|
|
|
fb->result = FB_DISCARDED;
|
|
|
|
}
|
|
|
|
|
2016-02-18 17:53:27 +03:00
|
|
|
static const struct wp_presentation_feedback_listener feedback_listener = {
|
2014-09-24 06:08:48 +04:00
|
|
|
feedback_sync_output,
|
|
|
|
feedback_presented,
|
|
|
|
feedback_discarded
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct feedback *
|
2019-11-13 16:50:51 +03:00
|
|
|
feedback_create(struct client *client,
|
|
|
|
struct wl_surface *surface,
|
|
|
|
struct wp_presentation *pres)
|
2014-09-24 06:08:48 +04:00
|
|
|
{
|
|
|
|
struct feedback *fb;
|
|
|
|
|
|
|
|
fb = xzalloc(sizeof *fb);
|
|
|
|
fb->client = client;
|
2019-11-13 16:50:51 +03:00
|
|
|
fb->obj = wp_presentation_feedback(pres, surface);
|
2016-02-18 17:53:27 +03:00
|
|
|
wp_presentation_feedback_add_listener(fb->obj, &feedback_listener, fb);
|
2014-09-24 06:08:48 +04:00
|
|
|
|
|
|
|
return fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
feedback_wait(struct feedback *fb)
|
|
|
|
{
|
|
|
|
while (fb->result == FB_PENDING) {
|
|
|
|
assert(wl_display_dispatch(fb->client->wl_display) >= 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
pflags_to_str(uint32_t flags, char *str, unsigned len)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
uint32_t flag;
|
|
|
|
char sym;
|
|
|
|
} desc[] = {
|
2016-02-18 17:53:27 +03:00
|
|
|
{ WP_PRESENTATION_FEEDBACK_KIND_VSYNC, 's' },
|
|
|
|
{ WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK, 'c' },
|
|
|
|
{ WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION, 'e' },
|
|
|
|
{ WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY, 'z' },
|
2014-09-24 06:08:48 +04:00
|
|
|
};
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
*str = '\0';
|
|
|
|
if (len < ARRAY_LENGTH(desc) + 1)
|
|
|
|
return str;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(desc); i++)
|
|
|
|
str[i] = flags & desc[i].flag ? desc[i].sym : '_';
|
|
|
|
str[ARRAY_LENGTH(desc)] = '\0';
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
feedback_print(struct feedback *fb)
|
|
|
|
{
|
|
|
|
char str[10];
|
|
|
|
|
|
|
|
switch (fb->result) {
|
|
|
|
case FB_PENDING:
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("pending");
|
2014-09-24 06:08:48 +04:00
|
|
|
return;
|
|
|
|
case FB_DISCARDED:
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("discarded");
|
2014-09-24 06:08:48 +04:00
|
|
|
return;
|
|
|
|
case FB_PRESENTED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pflags_to_str(fb->flags, str, sizeof str);
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("presented %lld.%09lld, refresh %u us, [%s] seq %" PRIu64,
|
2014-09-24 06:08:48 +04:00
|
|
|
(long long)fb->time.tv_sec, (long long)fb->time.tv_nsec,
|
|
|
|
fb->refresh_nsec / 1000, str, fb->seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
feedback_destroy(struct feedback *fb)
|
|
|
|
{
|
2016-02-18 17:53:27 +03:00
|
|
|
wp_presentation_feedback_destroy(fb->obj);
|
2014-09-24 06:08:48 +04:00
|
|
|
free(fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(test_presentation_feedback_simple)
|
|
|
|
{
|
|
|
|
struct client *client;
|
|
|
|
struct feedback *fb;
|
2019-11-13 16:50:51 +03:00
|
|
|
struct wp_presentation *pres;
|
2014-09-24 06:08:48 +04:00
|
|
|
|
2015-03-26 13:56:10 +03:00
|
|
|
client = create_client_and_test_surface(100, 50, 123, 77);
|
2014-09-24 06:08:48 +04:00
|
|
|
assert(client);
|
2019-11-13 16:50:51 +03:00
|
|
|
pres = get_presentation(client);
|
2014-09-24 06:08:48 +04:00
|
|
|
|
|
|
|
wl_surface_attach(client->surface->wl_surface,
|
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
|
|
|
client->surface->buffer->proxy, 0, 0);
|
2019-11-13 16:50:51 +03:00
|
|
|
fb = feedback_create(client, client->surface->wl_surface, pres);
|
2014-09-24 06:08:48 +04:00
|
|
|
wl_surface_damage(client->surface->wl_surface, 0, 0, 100, 100);
|
|
|
|
wl_surface_commit(client->surface->wl_surface);
|
|
|
|
|
|
|
|
client_roundtrip(client);
|
|
|
|
|
|
|
|
feedback_wait(fb);
|
|
|
|
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("%s feedback:", __func__);
|
2014-09-24 06:08:48 +04:00
|
|
|
feedback_print(fb);
|
2019-11-06 16:59:33 +03:00
|
|
|
testlog("\n");
|
2014-09-24 06:08:48 +04:00
|
|
|
|
|
|
|
feedback_destroy(fb);
|
2021-06-15 16:53:52 +03:00
|
|
|
wp_presentation_destroy(pres);
|
|
|
|
client_destroy(client);
|
2014-09-24 06:08:48 +04:00
|
|
|
}
|