3 #include "libds-private.h"
4 #include "presentation-time-protocol.h"
6 #define PRESENTATION_VERSION 1
10 struct wl_global *global;
13 struct wl_signal destroy;
17 struct ds_presentation_feedback
19 struct wl_list resources;
23 struct ds_presentation_surface_state
27 struct ds_presentation_feedback
29 struct wl_resource *resource;
34 static void presentation_bind(struct wl_client *client, void *data,
35 uint32_t version, uint32_t id);
36 static void handle_display_destroy(struct wl_listener *listener, void *data);
38 struct ds_presentation *
39 ds_presentation_create(struct wl_display *display, clockid_t clk_id)
41 struct ds_presentation *presentation;
43 presentation = calloc(1, sizeof *presentation);
47 presentation->global = wl_global_create(display, &wp_presentation_interface,
48 PRESENTATION_VERSION, presentation, presentation_bind);
49 if (!presentation->global) {
54 presentation->clock = clk_id;
56 wl_signal_init(&presentation->events.destroy);
58 presentation->display_destroy.notify = handle_display_destroy;
59 wl_display_add_destroy_listener(display, &presentation->display_destroy);
63 presentation_handle_destroy(struct wl_client *client, struct wl_resource *resource)
65 wl_resource_destroy(resource);
69 presentation_handle_feedback(struct wl_client *client,
70 struct wl_resource *presentation_resource,
71 struct wl_resource *surface_resource, uint32_t id)
73 struct ds_presentation *presentation;
74 struct ds_surface *surface;
76 presentation = wl_resource_get_user_data(presentation_resource);
77 surface = ds_surface_from_resource(surface_resource);
80 static const struct wp_presentation_interface presentation_impl =
82 .destroy = presentation_handle_destroy,
83 .feedback = presentation_handle_feedback,
87 presentation_bind(struct wl_client *client, void *data,
88 uint32_t version, uint32_t id)
90 struct ds_presentation *presentation = data;
91 struct wl_resource *resource;
93 resource = wl_resource_create(client, &wp_presentation_interface,
96 wl_client_post_no_memory(client);
99 wl_resource_set_implementation(resource, &presentation_impl,
102 wp_presentation_send_clock_id(resource, (uint32_t)presentation->clock);
106 handle_display_destroy(struct wl_listener *listener, void *data)
108 struct ds_presentation *presentation;
110 presentation = wl_container_of(listener, presentation, display_destroy);
111 wl_signal_emit(&presentation->events.destroy, presentation);
112 wl_list_remove(&presentation->display_destroy.link);
113 wl_global_destroy(presentation->global);