keyrouter: Fix wrong validity check
[platform/core/uifw/libds-tizen.git] / src / libds / presentation.c
1 // TODO
2
3 #include "libds-private.h"
4 #include "presentation-time-protocol.h"
5
6 #define PRESENTATION_VERSION 1
7
8 struct ds_presentation
9 {
10     struct wl_global *global;
11
12     struct {
13         struct wl_signal destroy;
14     } events;
15 };
16
17 struct ds_presentation_feedback
18 {
19     struct wl_list resources;
20
21 }
22
23 struct ds_presentation_surface_state
24 {
25 };
26
27 struct ds_presentation_feedback
28 {
29     struct wl_resource *resource;
30     struct wl_list link;
31     uint32_t psf_flags;
32 };
33
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);
37
38 struct ds_presentation *
39 ds_presentation_create(struct wl_display *display, clockid_t clk_id)
40 {
41     struct ds_presentation *presentation;
42
43     presentation = calloc(1, sizeof *presentation);
44     if (!presentation)
45         return NULL;
46
47     presentation->global = wl_global_create(display, &wp_presentation_interface,
48             PRESENTATION_VERSION, presentation, presentation_bind);
49     if (!presentation->global) {
50         free(presentation);
51         return NULL;
52     }
53
54     presentation->clock = clk_id;
55
56     wl_signal_init(&presentation->events.destroy);
57
58     presentation->display_destroy.notify = handle_display_destroy;
59     wl_display_add_destroy_listener(display, &presentation->display_destroy);
60 }
61
62 static void
63 presentation_handle_destroy(struct wl_client *client, struct wl_resource *resource)
64 {
65     wl_resource_destroy(resource);
66 }
67
68 static void
69 presentation_handle_feedback(struct wl_client *client,
70         struct wl_resource *presentation_resource,
71         struct wl_resource *surface_resource, uint32_t id)
72 {
73     struct ds_presentation *presentation;
74     struct ds_surface *surface;
75
76     presentation = wl_resource_get_user_data(presentation_resource);
77     surface = ds_surface_from_resource(surface_resource);
78 }
79
80 static const struct wp_presentation_interface presentation_impl =
81 {
82     .destroy = presentation_handle_destroy,
83     .feedback = presentation_handle_feedback,
84 };
85
86 static void
87 presentation_bind(struct wl_client *client, void *data,
88         uint32_t version, uint32_t id)
89 {
90     struct ds_presentation *presentation = data;
91     struct wl_resource *resource;
92
93     resource = wl_resource_create(client, &wp_presentation_interface,
94             version, id);
95     if (!resource) {
96         wl_client_post_no_memory(client);
97         return;
98     }
99     wl_resource_set_implementation(resource, &presentation_impl,
100             presentation, NULL);
101
102     wp_presentation_send_clock_id(resource, (uint32_t)presentation->clock);
103 }
104
105 static void
106 handle_display_destroy(struct wl_listener *listener, void *data)
107 {
108     struct ds_presentation *presentation;
109
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);
114     free(presentation);
115 }