1 #include <tizen-extension-server-protocol.h>
2 #include "screenshooter.h"
5 #define TIZEN_SCREENSHOOTER_VERSION 3
7 static void screenshooter_handle_display_destroy(struct wl_listener *listener,
10 static void screenshooter_bind(struct wl_client *wl_client, void *data,
11 uint32_t version, uint32_t id);
13 WL_EXPORT struct ds_tizen_screenshooter *
14 ds_tizen_screenshooter_create(struct wl_display *display)
16 struct ds_tizen_screenshooter *shot;
18 shot = calloc(1, sizeof *shot);
20 ds_err("screenshooter create fail : memory alloc failed");
24 shot->global = wl_global_create(display, &tizen_screenshooter_interface,
25 TIZEN_SCREENSHOOTER_VERSION, NULL, screenshooter_bind);
27 wl_list_init(&shot->clients);
28 wl_signal_init(&shot->events.destroy);
29 wl_signal_init(&shot->events.shoot);
31 shot->destroy.notify = screenshooter_handle_display_destroy;
32 wl_display_add_destroy_listener(display, &shot->destroy);
34 ds_inf("create : tizen_screenshooter(%p)", shot);
40 ds_tizen_screenshooter_add_destroy_listener(struct ds_tizen_screenshooter *shot,
41 struct wl_listener *listener)
43 wl_signal_add(&shot->events.destroy, listener);
47 ds_tizen_screenshooter_add_get_screenmirror_listener(struct ds_tizen_screenshooter *shot,
48 struct wl_listener *listener)
50 wl_signal_add(&shot->events.get_screenmirror, listener);
54 ds_tizen_screenshooter_add_shoot_listener(struct ds_tizen_screenshooter *shot,
55 struct wl_listener *listener)
57 wl_signal_add(&shot->events.shoot, listener);
61 ds_tizen_screenshooter_send_shoot_done(struct ds_tizen_screenshooter *shot,
62 struct ds_tizen_screenshooter_client *client)
64 struct ds_tizen_screenshooter_client *temp;
66 wl_list_for_each(temp, &shot->clients, link) {
68 ds_dbg("screenshooter send shoot done");
69 tizen_screenshooter_send_done(client->res);
75 screenshooter_handle_display_destroy(struct wl_listener *listener, void *data)
77 struct ds_tizen_screenshooter *shot;
79 shot = wl_container_of(listener, shot, destroy);
81 ds_inf("global destroy : tizen_screenshooter(%p)", shot);
83 wl_signal_emit(&shot->events.destroy, shot);
84 wl_list_remove(&shot->destroy.link);
85 wl_global_destroy(shot->global);
90 _tizen_screenshooter_handle_get_screenmirror(struct wl_client *client,
91 struct wl_resource *resource, uint32_t id, struct wl_resource *output)
93 struct ds_tizen_screenshooter *shot;
94 struct ds_tizen_screenshooter_client *shot_client;
95 int version = wl_resource_get_version(resource);
97 shot_client = wl_resource_get_user_data(resource);
98 shot = shot_client->shot;
100 if (shot_client->mirror) {
101 ds_err("screenshooter get_screenmirror error : already created");
105 shot_client->mirror = ds_tizen_screenmirror_create(shot_client, version, id);
106 if (shot_client->mirror == NULL)
107 wl_client_post_no_memory(client);
109 wl_signal_emit(&shot->events.get_screenmirror, shot_client->mirror);
113 _tizen_screenshooter_handle_set_oneshot_auto_rotation(struct wl_client *client,
114 struct wl_resource *resource, uint32_t set)
116 struct ds_tizen_screenshooter *shot;
117 struct ds_tizen_screenshooter_client *shot_client;
119 shot_client = wl_resource_get_user_data(resource);
120 shot = shot_client->shot;
122 shot->auto_rotation = true;
124 shot->auto_rotation = false;
128 _tizen_screenshooter_handle_destroy(struct wl_client *client,
129 struct wl_resource *resource)
131 ds_inf("_tizen_screenshooter_handle_destroy (res:%p)", resource);
132 wl_resource_destroy(resource);
136 _tizen_screenshooter_handle_shoot(struct wl_client *client,
137 struct wl_resource *resource, struct wl_resource *wl_output,
138 struct wl_resource *wl_buffer)
140 struct ds_tizen_screenshooter *shot;
141 struct ds_tizen_screenshooter_client *shot_client;
142 struct ds_output *output = NULL;
143 struct ds_buffer *buffer = NULL;
145 shot_client = wl_resource_get_user_data(resource);
146 shot = shot_client->shot;
147 output = wl_resource_get_user_data(wl_output);
148 buffer = ds_buffer_from_resource(wl_buffer);
150 ds_err("ds_buffer_from_resource fail");
154 struct ds_tizen_screenshooter_event_shoot event = {
157 .client = shot_client,
158 .auto_rotation = shot->auto_rotation,
161 wl_signal_emit(&shot->events.shoot, &event);
164 static const struct tizen_screenshooter_interface _tizen_screenshooter_interface =
166 _tizen_screenshooter_handle_get_screenmirror,
167 _tizen_screenshooter_handle_set_oneshot_auto_rotation,
168 _tizen_screenshooter_handle_destroy,
169 _tizen_screenshooter_handle_shoot,
173 _screenshooter_client_cb_destroy(struct wl_resource *resource)
175 struct ds_tizen_screenshooter_client *shot_client;
177 ds_inf("_screenshooter_client_cb_destroy (res:%p)", resource);
179 shot_client = wl_resource_get_user_data(resource);
181 wl_list_remove(&shot_client->link);
187 screenshooter_bind(struct wl_client *client, void *data, uint32_t version,
190 struct ds_tizen_screenshooter *shot = data;
191 struct ds_tizen_screenshooter_client *shot_client;
193 shot_client = calloc(1, sizeof *shot_client);
194 if (shot_client == NULL) {
195 wl_client_post_no_memory(client);
199 shot_client->shot = shot;
200 shot_client->client = client;
202 shot_client->res = wl_resource_create(client, &tizen_screenshooter_interface,
203 MIN(version, TIZEN_SCREENSHOOTER_VERSION), id);
204 if (shot_client->res == NULL) {
205 ds_err("screenshooter bind error : wl_resource_create failed.");
206 wl_client_post_no_memory(client);
211 wl_resource_set_implementation(shot_client->res, &_tizen_screenshooter_interface,
212 shot_client, _screenshooter_client_cb_destroy);
214 wl_list_insert(&shot->clients, &shot_client->link);