1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <boram1288.park@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
40 #define WL_HIDE_DEPRECATED
42 #include <tdm-server-protocol.h>
44 #include "tdm_private.h"
47 * - tdm server doesn't care about thread things.
48 * - DO NOT use the TDM internal functions here.
49 * However, the internal function which does lock/unlock the mutex of
50 * private_display in itself can be called.
51 * - DO NOT use the tdm_private_display structure here.
52 * - The callback function things can be called in main thread.
55 struct _tdm_private_server {
56 tdm_private_loop *private_loop;
57 struct list_head output_list;
58 struct list_head voutput_list;
59 struct list_head wait_list;
62 typedef struct _tdm_server_output_info {
63 struct list_head link;
64 tdm_private_server *private_server;
65 struct wl_resource *resource;
67 struct list_head vblank_list;
68 unsigned int watch_output_changes;
69 } tdm_server_output_info;
71 typedef struct _tdm_server_voutput_buffer {
72 struct list_head link;
73 struct wl_resource *wl_buffer;
75 } tdm_server_voutput_buffer;
77 typedef struct _tdm_server_voutput_info {
78 struct list_head link;
79 tdm_private_server *private_server;
80 struct wl_resource *resource;
84 tdm_output_conn_status status;
87 tdm_output_mode *modes;
91 unsigned int mmheight;
93 struct list_head buffer_list;
94 tdm_server_voutput_buffer *attach_buffer;
96 unsigned int request_commit;
97 } tdm_server_voutput_info;
99 typedef struct _tdm_server_vblank_info {
100 struct list_head link;
101 tdm_server_output_info *output_info;
102 struct wl_resource *resource;
108 tdm_event_loop_source *vblank_timeout_timer;
109 } tdm_server_vblank_info;
111 typedef struct _tdm_server_wait_info {
112 struct list_head link;
113 tdm_server_vblank_info *vblank_info;
118 unsigned int timeout;
119 } tdm_server_wait_info;
121 typedef struct _tdm_server_client_info {
122 struct list_head link;
124 char name[TDM_NAME_LEN];
125 struct wl_resource *resource;
126 } tdm_server_client_info;
128 static tdm_private_server *keep_private_server;
129 static struct list_head client_list;
131 static void destroy_wait(tdm_server_wait_info *wait_info);
132 static void _tdm_server_vblank_timeout_update(tdm_server_vblank_info *vblank_info, int ms_delay);
135 _tdm_server_get_process_name(pid_t pid, char *name, unsigned int size)
137 char proc[TDM_NAME_LEN], pname[TDM_NAME_LEN];
141 snprintf(name, size, "Unknown");
143 snprintf(proc, TDM_NAME_LEN, "/proc/%d/cmdline", pid);
144 h = fopen(proc, "r");
148 len = fread(pname, sizeof(char), TDM_NAME_LEN, h);
150 char *p = strncpy(pname, "NO NAME", sizeof(pname) - 1);
153 pname[len - 1] = '\0';
155 strncpy(name, pname, size - 1);
156 name[size - 1] = '\0';
161 /* LCOV_EXCL_START */
163 _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error,
164 unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec)
166 tdm_server_wait_info *found;
167 tdm_server_vblank_info *vblank_info;
168 tdm_server_output_info *output_info;
169 tdm_private_server *private_server;
170 tdm_private_loop *private_loop;
172 TDM_RETURN_IF_FAIL(keep_private_server != NULL);
174 LIST_FIND_ITEM(wait_info, &keep_private_server->wait_list,
175 tdm_server_wait_info, link, found);
177 TDM_ERR("wait_info(%p) is destroyed", wait_info);
181 if (tdm_debug_module & TDM_DEBUG_VBLANK)
182 TDM_DBG("req_id(%d) done", wait_info->req_id);
184 vblank_info = wait_info->vblank_info;
185 output_info = vblank_info->output_info;
186 private_server = output_info->private_server;
187 private_loop = private_server->private_loop;
189 tdm_display_lock(private_loop->dpy);
190 _tdm_server_vblank_timeout_update(vblank_info, 0);
191 tdm_display_unlock(private_loop->dpy);
193 if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK)
194 TDM_TRACE_ASYNC_END((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp);
196 if (!wait_info->timeout)
197 wl_tdm_vblank_send_done(vblank_info->resource, wait_info->req_id,
198 sequence, tv_sec, tv_usec, error);
200 destroy_wait(wait_info);
204 /* LCOV_EXCL_START */
206 _tdm_server_timeout_timer_cb(void *user_data)
208 tdm_server_vblank_info *vblank_info = user_data;
209 tdm_server_wait_info *wait_info = NULL;
212 unsigned int tv_usec;
214 TDM_RETURN_VAL_IF_FAIL(vblank_info != NULL, TDM_ERROR_OPERATION_FAILED);
215 TDM_RETURN_VAL_IF_FAIL(keep_private_server != NULL, TDM_ERROR_OPERATION_FAILED);
217 curr = tdm_helper_get_time();
218 tv_sec = TDM_TIME_SEC(curr);
219 tv_usec = TDM_TIME_USEC(curr);
221 LIST_FOR_EACH_ENTRY(wait_info, &keep_private_server->wait_list, link) {
222 if (wait_info->timeout) continue;
223 if (vblank_info != wait_info->vblank_info) continue;
225 wl_tdm_vblank_send_done(vblank_info->resource, wait_info->req_id,
226 0, tv_sec, tv_usec, TDM_ERROR_TIMEOUT);
227 TDM_ERR("tdm_server_vblank(%p) req_id(%d) timeout force send vblank", vblank_info, wait_info->req_id);
228 wait_info->timeout = 1;
231 return TDM_ERROR_NONE;
235 _tdm_server_vblank_timeout_update(tdm_server_vblank_info *vblank_info, int ms_delay)
237 tdm_server_output_info *output_info = vblank_info->output_info;
238 tdm_private_server *private_server = output_info->private_server;
239 tdm_private_loop *private_loop = private_server->private_loop;
242 if (!vblank_info->vblank_timeout_timer) {
243 vblank_info->vblank_timeout_timer =
244 tdm_event_loop_add_timer_handler(private_loop->dpy,
245 _tdm_server_timeout_timer_cb,
248 if (!vblank_info->vblank_timeout_timer) {
249 TDM_ERR("tdm_server_vblank(%p) couldn't add timer", vblank_info);
253 if (tdm_debug_module & TDM_DEBUG_VBLANK)
254 TDM_INFO("tdm_server_vblank(%p) create vblank timeout timer", vblank_info);
257 ret = tdm_event_loop_source_timer_update(vblank_info->vblank_timeout_timer, ms_delay);
258 if (ret != TDM_ERROR_NONE) {
259 TDM_ERR("tdm_server_vblank(%p) couldn't update timer", vblank_info);
265 _tdm_server_cb_vblank(tdm_vblank *vblank, tdm_error error, unsigned int sequence,
266 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
268 _tdm_server_send_done((tdm_server_wait_info*)user_data, error, sequence, tv_sec, tv_usec);
272 /* LCOV_EXCL_START */
274 _tdm_server_cb_output_change(tdm_output *output, tdm_output_change_type type,
275 tdm_value value, void *user_data)
277 tdm_server_output_info *output_info = user_data;
278 struct wl_client *client;
280 tdm_output_conn_status status;
281 tdm_error ret = TDM_ERROR_NONE;
283 TDM_RETURN_IF_FAIL(output_info != NULL);
285 client = wl_resource_get_client(output_info->resource);
286 TDM_RETURN_IF_FAIL(client != NULL);
288 wl_client_get_credentials(client, &pid, NULL, NULL);
290 if (!output_info->watch_output_changes) {
291 TDM_DBG("skip sending the output changes: pid(%d)", (unsigned int)pid);
295 TDM_DBG("send the output changes: %d, type:%d, value:%d", (unsigned int)pid, type, value.u32);
298 case TDM_OUTPUT_CHANGE_DPMS:
299 wl_tdm_output_send_dpms(output_info->resource, value.u32, TDM_ERROR_NONE);
301 case TDM_OUTPUT_CHANGE_CONNECTION:
303 if (status == TDM_OUTPUT_CONN_STATUS_MODE_SETTED) {
304 const tdm_output_mode *mode = NULL;
305 unsigned int hdisplay, vdisplay, vrefresh;
307 ret = tdm_output_get_mode(output_info->output, &mode);
308 if (ret == TDM_ERROR_NONE) {
309 hdisplay = (mode) ? mode->hdisplay : 0;
310 vdisplay = (mode) ? mode->vdisplay : 0;
311 vrefresh = (mode) ? mode->vrefresh : 0;
313 wl_tdm_output_send_mode(output_info->resource, hdisplay, vdisplay, vrefresh, ret);
315 wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, ret);
318 wl_tdm_output_send_connection(output_info->resource, value.u32, TDM_ERROR_NONE);
327 destroy_wait(tdm_server_wait_info *wait_info)
329 LIST_DEL(&wait_info->link);
334 destroy_vblank_callback(struct wl_resource *resource)
336 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
337 tdm_server_output_info *output_info = vblank_info->output_info;
338 tdm_private_server *private_server = output_info->private_server;
339 tdm_private_loop *private_loop = private_server->private_loop;
340 tdm_server_wait_info *w = NULL, *ww = NULL;
342 TDM_RETURN_IF_FAIL(vblank_info != NULL);
344 if (vblank_info->vblank_timeout_timer) {
345 tdm_display_lock(private_loop->dpy);
346 tdm_event_loop_source_remove(vblank_info->vblank_timeout_timer);
347 tdm_display_unlock(private_loop->dpy);
350 LIST_DEL(&vblank_info->link);
352 if (vblank_info->vblank)
353 tdm_vblank_destroy(vblank_info->vblank);
355 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &keep_private_server->wait_list, link) {
356 if (w->vblank_info == vblank_info)
363 /* LCOV_EXCL_START */
365 _tdm_server_vblank_cb_destroy(struct wl_client *client, struct wl_resource *resource)
367 wl_resource_destroy(resource);
371 /* LCOV_EXCL_START */
373 _tdm_server_vblank_cb_set_name(struct wl_client *client, struct wl_resource *resource, const char *name)
375 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
378 ret = tdm_vblank_set_name(vblank_info->vblank, name);
379 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
383 /* LCOV_EXCL_START */
385 _tdm_server_vblank_cb_set_fps(struct wl_client *client, struct wl_resource *resource, uint32_t fps)
387 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
390 ret = tdm_vblank_set_fps(vblank_info->vblank, fps);
391 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
395 /* LCOV_EXCL_START */
397 _tdm_server_vblank_cb_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t offset)
399 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
402 ret = tdm_vblank_set_offset(vblank_info->vblank, offset);
403 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
408 _tdm_server_vblank_cb_set_enable_fake(struct wl_client *client, struct wl_resource *resource, uint32_t enable_fake)
410 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
413 ret = tdm_vblank_set_enable_fake(vblank_info->vblank, enable_fake);
414 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
418 _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource *resource,
419 uint32_t interval, uint32_t req_id, uint32_t req_sec, uint32_t req_usec)
421 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
422 tdm_server_output_info *output_info = vblank_info->output_info;
423 tdm_private_server *private_server = output_info->private_server;
424 tdm_private_loop *private_loop = private_server->private_loop;
425 tdm_server_wait_info *wait_info;
426 unsigned int enable_fake = 0;
429 wait_info = calloc(1, sizeof * wait_info);
431 /* LCOV_EXCL_START */
433 TDM_ERR("alloc failed");
434 ret = TDM_ERROR_OUT_OF_MEMORY;
440 LIST_ADDTAIL(&wait_info->link, &private_server->wait_list);
441 wait_info->vblank_info = vblank_info;
442 wait_info->req_id = req_id;
443 wait_info->req_time = TDM_TIME(req_sec, req_usec);
445 if (tdm_debug_module & TDM_DEBUG_VBLANK)
446 TDM_DBG("req_id(%d) wait", req_id);
448 if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK)
449 TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp);
451 ret = tdm_vblank_wait(vblank_info->vblank, req_sec, req_usec, interval, _tdm_server_cb_vblank, wait_info);
453 tdm_vblank_get_enable_fake(vblank_info->vblank, &enable_fake);
454 if (!enable_fake && ret == TDM_ERROR_DPMS_OFF)
457 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
459 tdm_display_lock(private_loop->dpy);
460 _tdm_server_vblank_timeout_update(vblank_info, 1000);
461 tdm_display_unlock(private_loop->dpy);
465 /* LCOV_EXCL_START */
467 wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret);
469 destroy_wait(wait_info);
475 _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resource *resource,
476 uint32_t sequence, uint32_t req_id, uint32_t req_sec, uint32_t req_usec)
478 tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource);
479 tdm_server_output_info *output_info = vblank_info->output_info;
480 tdm_private_server *private_server = output_info->private_server;
481 tdm_server_wait_info *wait_info;
482 unsigned int enable_fake = 0;
485 wait_info = calloc(1, sizeof * wait_info);
487 /* LCOV_EXCL_START */
489 TDM_ERR("alloc failed");
490 ret = TDM_ERROR_OUT_OF_MEMORY;
496 LIST_ADDTAIL(&wait_info->link, &private_server->wait_list);
497 wait_info->vblank_info = vblank_info;
498 wait_info->req_id = req_id;
499 wait_info->req_time = TDM_TIME(req_sec, req_usec);
501 if (tdm_debug_module & TDM_DEBUG_VBLANK)
502 TDM_DBG("req_id(%d) wait", req_id);
504 if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK)
505 TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp);
507 ret = tdm_vblank_wait_seq(vblank_info->vblank, req_sec, req_usec, sequence, _tdm_server_cb_vblank, wait_info);
509 tdm_vblank_get_enable_fake(vblank_info->vblank, &enable_fake);
510 if (!enable_fake && ret == TDM_ERROR_DPMS_OFF)
513 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, wait_failed);
517 /* LCOV_EXCL_START */
519 wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret);
521 destroy_wait(wait_info);
526 static const struct wl_tdm_vblank_interface tdm_vblank_implementation = {
527 _tdm_server_vblank_cb_destroy,
528 _tdm_server_vblank_cb_set_name,
529 _tdm_server_vblank_cb_set_fps,
530 _tdm_server_vblank_cb_set_offset,
531 _tdm_server_vblank_cb_set_enable_fake,
532 _tdm_server_vblank_cb_wait_vblank,
533 _tdm_server_vblank_cb_wait_vblank_seq,
536 /* LCOV_EXCL_START */
538 _tdm_server_output_cb_destroy(struct wl_client *client, struct wl_resource *resource)
540 wl_resource_destroy(resource);
545 _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource *resource, uint32_t id)
547 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
548 tdm_private_server *private_server = output_info->private_server;
549 tdm_private_loop *private_loop = private_server->private_loop;
550 struct wl_resource *vblank_resource;
552 tdm_server_vblank_info *vblank_info;
555 wl_resource_create(client, &wl_tdm_vblank_interface,
556 wl_resource_get_version(resource), id);
557 if (!vblank_resource) {
558 /* LCOV_EXCL_START */
560 wl_resource_post_no_memory(resource);
561 TDM_ERR("wl_resource_create failed");
567 vblank = tdm_vblank_create(private_loop->dpy, output_info->output, NULL);
569 /* LCOV_EXCL_START */
571 wl_resource_post_no_memory(resource);
572 wl_resource_destroy(vblank_resource);
573 TDM_ERR("tdm_vblank_create failed");
579 vblank_info = calloc(1, sizeof * vblank_info);
581 /* LCOV_EXCL_START */
583 wl_resource_post_no_memory(resource);
584 wl_resource_destroy(vblank_resource);
585 tdm_vblank_destroy(vblank);
586 TDM_ERR("alloc failed");
592 LIST_ADDTAIL(&vblank_info->link, &output_info->vblank_list);
593 vblank_info->output_info = output_info;
594 vblank_info->resource = vblank_resource;
595 vblank_info->vblank = vblank;
596 vblank_info->stamp = (unsigned int)tdm_vblank_get_stamp(vblank);
598 tdm_vblank_set_resource(vblank, vblank_resource);
600 wl_resource_set_implementation(vblank_resource, &tdm_vblank_implementation,
601 vblank_info, destroy_vblank_callback);
603 wl_tdm_vblank_send_stamp(vblank_info->resource, vblank_info->stamp);
605 if (tdm_ttrace_module & TDM_TTRACE_CLIENT_VBLANK) {
606 tdm_output *output = tdm_display_get_output(private_loop->dpy, tdm_ttrace_output, NULL);
607 if (output == output_info->output)
608 wl_tdm_vblank_send_ttrace(vblank_info->resource, 1);
614 /* LCOV_EXCL_START */
616 _tdm_server_output_cb_watch_output_changes(struct wl_client *client, struct wl_resource *resource, unsigned int enable)
618 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
620 TDM_RETURN_IF_FAIL(output_info != NULL);
622 output_info->watch_output_changes = enable;
627 _tdm_server_output_cb_get_connection(struct wl_client *client, struct wl_resource *resource)
629 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
630 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
633 TDM_RETURN_IF_FAIL(output_info != NULL);
635 ret = tdm_output_get_conn_status(output_info->output, &status);
636 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
638 wl_tdm_output_send_connection(output_info->resource, status, ret);
643 wl_tdm_output_send_connection(output_info->resource, TDM_OUTPUT_CONN_STATUS_DISCONNECTED, ret);
647 _tdm_server_output_cb_get_mode(struct wl_client *client, struct wl_resource *resource)
649 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
650 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
653 TDM_RETURN_IF_FAIL(output_info != NULL);
655 ret = tdm_output_get_conn_status(output_info->output, &status);
656 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
658 if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
659 const tdm_output_mode *mode = NULL;
660 unsigned int hdisplay, vdisplay, vrefresh;
662 ret = tdm_output_get_mode(output_info->output, &mode);
663 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
665 hdisplay = (mode) ? mode->hdisplay : 0;
666 vdisplay = (mode) ? mode->vdisplay : 0;
667 vrefresh = (mode) ? mode->vrefresh : 0;
669 wl_tdm_output_send_mode(output_info->resource, hdisplay, vdisplay, vrefresh, ret);
671 wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED);
676 wl_tdm_output_send_mode(output_info->resource, 0, 0, 0, ret);
680 _tdm_server_output_cb_get_dpms(struct wl_client *client, struct wl_resource *resource)
682 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
683 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
686 TDM_RETURN_IF_FAIL(output_info != NULL);
688 ret = tdm_output_get_conn_status(output_info->output, &status);
689 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
691 if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
692 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
694 ret = tdm_output_get_dpms(output_info->output, &dpms_value);
695 TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
697 wl_tdm_output_send_dpms(output_info->resource, dpms_value, ret);
699 wl_tdm_output_send_dpms(output_info->resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED);
704 wl_tdm_output_send_dpms(output_info->resource, TDM_OUTPUT_DPMS_OFF, ret);
707 static const struct wl_tdm_output_interface tdm_output_implementation = {
708 _tdm_server_output_cb_destroy,
709 _tdm_server_output_cb_create_vblank,
710 _tdm_server_output_cb_watch_output_changes,
711 _tdm_server_output_cb_get_connection,
712 _tdm_server_output_cb_get_mode,
713 _tdm_server_output_cb_get_dpms,
717 destroy_output_callback(struct wl_resource *resource)
719 tdm_server_output_info *output_info = wl_resource_get_user_data(resource);
720 tdm_server_vblank_info *v = NULL, *vv = NULL;
722 TDM_RETURN_IF_FAIL(output_info != NULL);
724 LIST_DEL(&output_info->link);
726 tdm_output_remove_change_handler(output_info->output,
727 _tdm_server_cb_output_change, output_info);
729 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &output_info->vblank_list, link) {
730 wl_resource_destroy(v->resource);
737 _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resource,
738 const char *name, uint32_t id)
740 tdm_private_server *private_server = wl_resource_get_user_data(resource);
741 tdm_server_output_info *output_info;
742 struct wl_resource *output_resource = NULL;
744 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
747 output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
749 /* LCOV_EXCL_START */
751 TDM_ERR("There is no '%s' output", name);
752 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
753 "There is no '%s' output", name);
760 wl_resource_create(client, &wl_tdm_output_interface,
761 wl_resource_get_version(resource), id);
762 if (!output_resource) {
763 /* LCOV_EXCL_START */
765 wl_resource_post_no_memory(resource);
766 TDM_ERR("wl_resource_create failed");
772 output_info = calloc(1, sizeof * output_info);
774 /* LCOV_EXCL_START */
776 wl_resource_post_no_memory(resource);
777 wl_resource_destroy(output_resource);
778 TDM_ERR("alloc failed");
784 ret = tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info);
785 if (ret != TDM_ERROR_NONE) {
786 wl_resource_post_no_memory(resource);
787 wl_resource_destroy(output_resource);
789 TDM_ERR("tdm_output_add_change_handler failed");
793 LIST_ADDTAIL(&output_info->link, &private_server->output_list);
794 output_info->private_server = private_server;
795 output_info->resource = output_resource;
796 output_info->output = output;
797 LIST_INITHEAD(&output_info->vblank_list);
799 wl_resource_set_implementation(output_resource, &tdm_output_implementation,
800 output_info, destroy_output_callback);
802 ret = tdm_output_get_conn_status(output, &status);
803 wl_tdm_output_send_connection(output_resource, status, ret);
805 if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
806 tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
807 const tdm_output_mode *mode = NULL;
808 unsigned int hdisplay, vdisplay, vrefresh;
810 ret = tdm_output_get_mode(output, &mode);
811 hdisplay = (mode) ? mode->hdisplay : 0;
812 vdisplay = (mode) ? mode->vdisplay : 0;
813 vrefresh = (mode) ? mode->vrefresh : 0;
814 wl_tdm_output_send_mode(output_resource, hdisplay, vdisplay, vrefresh, ret);
816 ret = tdm_output_get_dpms(output, &dpms_value);
817 wl_tdm_output_send_dpms(output_resource, dpms_value, ret);
819 wl_tdm_output_send_mode(output_resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED);
820 wl_tdm_output_send_dpms(output_resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED);
824 static void _tdm_voutput_cb_destroy(struct wl_client *client, struct wl_resource *resource)
826 wl_resource_destroy(resource);
830 _tdm_voutput_cb_set_available_modes(struct wl_client *client,
831 struct wl_resource *resource,
832 struct wl_array *modes)
834 tdm_server_voutput_info *voutput_info;
835 tdm_output_mode *mode;
836 int size, count = 0, i = 0;
838 voutput_info = wl_resource_get_user_data(resource);
840 voutput_info->available_modes.count = 0;
841 if (voutput_info->available_modes.modes)
842 free(voutput_info->available_modes.modes);
844 wl_array_for_each(mode, modes)
846 size = sizeof(tdm_output_mode);
848 voutput_info->available_modes.modes = malloc(count * size);
849 voutput_info->available_modes.count = count;
851 wl_array_for_each(mode, modes)
852 memcpy(&voutput_info->available_modes.modes[i++], mode, size);
856 _tdm_voutput_cb_set_physical_size(struct wl_client *client, struct wl_resource *resource,
857 unsigned int mmwidth, unsigned int mmheight)
859 tdm_server_voutput_info *voutput_info;
861 voutput_info = wl_resource_get_user_data(resource);
863 voutput_info->mmwidth = mmwidth;
864 voutput_info->mmheight = mmheight;
868 _tdm_voutput_cb_set_mode(struct wl_client *client, struct wl_resource *resource, unsigned int index)
870 tdm_server_voutput_info *voutput_info = NULL;
871 tdm_output *output = NULL;
872 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
873 const tdm_output_mode *modes, *mode;
878 voutput_info = wl_resource_get_user_data(resource);
879 TDM_RETURN_IF_FAIL(voutput_info != NULL);
880 output = voutput_info->output;
882 ret = tdm_output_get_conn_status(output, &status);
883 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
884 TDM_RETURN_IF_FAIL(status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED);
886 ret = tdm_output_get_available_modes(output, &modes, &count);
887 TDM_RETURN_IF_FAIL(index < count);
889 mode = &modes[index];
890 TDM_DBG("mode set request to index:%d (%dx%d, %d)", index, mode->hdisplay, mode->vdisplay, mode->vrefresh);
892 ret = tdm_output_set_mode(output, mode);
893 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
895 tdm_output_request_mode_set(voutput_info->output, index);
899 _tdm_voutput_cb_connect(struct wl_client *client, struct wl_resource *resource)
901 tdm_server_voutput_info *voutput_info;
903 voutput_info = wl_resource_get_user_data(resource);
904 voutput_info->status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
906 voutput_info->request_commit = 1;
908 tdm_voutput_set_physical_size(voutput_info->voutput, voutput_info->mmwidth, voutput_info->mmheight);
909 tdm_voutput_set_available_mode(voutput_info->voutput, voutput_info->available_modes.modes, voutput_info->available_modes.count);
910 tdm_voutput_connect(voutput_info->voutput);
911 tdm_output_set_voutput_commit(voutput_info->voutput);
915 _tdm_voutput_cb_disconnect(struct wl_client *client, struct wl_resource *resource)
917 tdm_server_voutput_info *voutput_info;
919 voutput_info = wl_resource_get_user_data(resource);
920 voutput_info->status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
922 /* Do free resources when it's being disconnected */
923 free(voutput_info->available_modes.modes);
924 voutput_info->available_modes.modes = NULL;
925 voutput_info->available_modes.count = 0;
926 voutput_info->mmwidth = 0;
927 voutput_info->mmheight = 0;
929 if (voutput_info->attach_buffer) {
930 tbm_surface_h buffer = voutput_info->attach_buffer->buffer;
931 tbm_surface_internal_unref(buffer);
932 voutput_info->committing = 0;
933 voutput_info->attach_buffer = NULL;
936 if (voutput_info->request_commit == 1) {
937 tdm_output_unset_voutput_commit(voutput_info->voutput);
938 voutput_info->request_commit = 0;
941 tdm_voutput_disconnect(voutput_info->voutput);
945 _tdm_voutput_cb_commit_done(struct wl_client *client, struct wl_resource *resource)
947 tdm_server_voutput_info *voutput_info;
948 tbm_surface_h buffer;
950 voutput_info = wl_resource_get_user_data(resource);
951 if (voutput_info->status != TDM_OUTPUT_CONN_STATUS_CONNECTED) {
952 TDM_DBG("not connected.");
956 buffer = voutput_info->attach_buffer->buffer;
957 tbm_surface_internal_unref(buffer);
958 voutput_info->committing = 0;
959 voutput_info->attach_buffer = NULL;
961 if (voutput_info->request_commit == 1)
962 tdm_output_set_voutput_commit(voutput_info->voutput);
964 tdm_voutput_commit_done(voutput_info->voutput);
967 static const struct wl_tdm_voutput_interface tdm_voutput_implementation = {
968 _tdm_voutput_cb_destroy,
969 _tdm_voutput_cb_set_available_modes,
970 _tdm_voutput_cb_set_physical_size,
971 _tdm_voutput_cb_set_mode,
972 _tdm_voutput_cb_connect,
973 _tdm_voutput_cb_disconnect,
974 _tdm_voutput_cb_commit_done
978 _tdm_voutput_wl_buffer_destroy(struct wl_client *client, struct wl_resource *wl_buffer)
980 wl_resource_destroy(wl_buffer);
983 static const struct wl_buffer_interface _tdm_voutput_buffer_impementation = {
984 _tdm_voutput_wl_buffer_destroy
988 _tdm_voutput_buffer_destory(struct wl_resource *wl_buffer)
990 tdm_server_voutput_info *voutput_info = NULL;
991 tdm_server_voutput_buffer *vb = NULL, *vbb = NULL;
993 voutput_info = (tdm_server_voutput_info *)wl_resource_get_user_data(wl_buffer);
994 TDM_RETURN_IF_FAIL(voutput_info != NULL);
996 LIST_FOR_EACH_ENTRY_SAFE(vb, vbb, &voutput_info->buffer_list, link) {
997 if (vb->wl_buffer == wl_buffer) {
998 tbm_surface_internal_unref(vb->buffer);
999 wl_resource_set_user_data(wl_buffer, NULL);
1000 LIST_DEL(&vb->link);
1006 struct wl_resource *
1007 _tdm_voutput_create_wl_buffer(tdm_server_voutput_info *voutput_info)
1009 struct wl_client *wl_client;
1010 struct wl_resource *wl_buffer = NULL;
1012 wl_client = wl_resource_get_client(voutput_info->resource);
1014 /* create a wl_buffer resource */
1015 wl_buffer = wl_resource_create(wl_client, &wl_buffer_interface, 1, 0);
1016 TDM_RETURN_VAL_IF_FAIL(wl_buffer != NULL, NULL);
1018 wl_resource_set_implementation(wl_buffer,
1019 (void (**)(void)) &_tdm_voutput_buffer_impementation,
1020 voutput_info, _tdm_voutput_buffer_destory);
1025 struct wl_resource *
1026 _tdm_voutput_export_buffer(tdm_server_voutput_info *voutput_info,
1027 tbm_surface_h buffer)
1029 int bufs[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
1030 struct wl_resource *wl_buffer = NULL;
1031 int num_buf, is_fd = -1, i;
1032 tbm_surface_info_s info;
1034 struct wl_array plane_buf_idx, plane_offset, plane_stride, plane_size;
1037 TDM_RETURN_VAL_IF_FAIL(voutput_info != NULL, NULL);
1038 TDM_RETURN_VAL_IF_FAIL(buffer != NULL, NULL);
1040 if (tbm_surface_get_info(buffer, &info) != TBM_SURFACE_ERROR_NONE) {
1041 TDM_ERR("Failed to create buffer from surface");
1045 if (info.num_planes > 3) {
1046 TDM_ERR("invalid num_planes(%d)", info.num_planes);
1050 num_buf = tbm_surface_internal_get_num_bos(buffer);
1052 TDM_ERR("surface doesn't have any bo.");
1056 for (i = 0; i < num_buf; i++) {
1057 tbm_bo bo = tbm_surface_internal_get_bo(buffer, i);
1059 TDM_ERR("Failed to get bo from surface");
1063 /* try to get fd first */
1064 if (is_fd == -1 || is_fd == 1) {
1065 bufs[i] = tbm_bo_export_fd(bo);
1066 if (is_fd == -1 && bufs[i] >= 0)
1070 /* if fail to get fd, try to get name second */
1071 if (is_fd == -1 || is_fd == 0) {
1072 bufs[i] = tbm_bo_export(bo);
1073 if (is_fd == -1 && bufs[i] > 0)
1078 (is_fd == 1 && bufs[i] < 0) ||
1079 (is_fd == 0 && bufs[i] <= 0)) {
1080 TDM_ERR("Failed to export(is_fd:%d, bufs:%d)", is_fd, bufs[i]);
1085 wl_buffer = _tdm_voutput_create_wl_buffer(voutput_info);
1087 TDM_ERR("Failed to create wl_buffer");
1091 wl_array_init(&plane_buf_idx);
1092 wl_array_init(&plane_offset);
1093 wl_array_init(&plane_stride);
1094 wl_array_init(&plane_size);
1096 for (i = 0; i < 3; i++) {
1097 p = wl_array_add(&plane_buf_idx, sizeof(int));
1098 *p = tbm_surface_internal_get_plane_bo_idx(buffer, i);
1099 p = wl_array_add(&plane_offset, sizeof(int));
1100 *p = info.planes[i].offset;
1101 p = wl_array_add(&plane_stride, sizeof(int));
1102 *p = info.planes[i].stride;
1103 p = wl_array_add(&plane_size, sizeof(int));
1104 *p = info.planes[i].size;
1108 wl_tdm_voutput_send_buffer_set_with_fd(voutput_info->resource,
1110 info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
1111 &plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
1112 flags, num_buf, bufs[0],
1113 (bufs[1] == -1) ? bufs[0] : bufs[1],
1114 (bufs[2] == -1) ? bufs[0] : bufs[2]);
1116 wl_tdm_voutput_send_buffer_set_with_id(voutput_info->resource,
1118 info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
1119 &plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
1121 num_buf, bufs[0], bufs[1], bufs[2]);
1123 wl_array_release(&plane_buf_idx);
1124 wl_array_release(&plane_offset);
1125 wl_array_release(&plane_stride);
1126 wl_array_release(&plane_size);
1128 for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
1129 if (is_fd == 1 && (bufs[i] >= 0))
1136 for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
1137 if (is_fd == 1 && (bufs[i] >= 0))
1144 tdm_server_voutput_buffer *
1145 _tdm_output_get_voutput_buffer(tdm_server_voutput_info *voutput_info, tbm_surface_h buffer)
1147 tdm_server_voutput_buffer *voutput_buffer = NULL, *vb = NULL;
1149 LIST_FOR_EACH_ENTRY(vb, &voutput_info->buffer_list, link) {
1150 if (vb && vb->buffer == buffer) {
1151 tbm_surface_internal_ref(vb->buffer);
1156 tbm_surface_internal_ref(buffer);
1157 voutput_buffer = calloc(1, sizeof *voutput_buffer);
1158 if (!voutput_buffer) {
1159 /* LCOV_EXCL_START */
1161 TDM_ERR("fail calloc");
1162 tbm_surface_internal_unref(buffer);
1165 /* LCOV_EXCL_STOP */
1168 voutput_buffer->wl_buffer = _tdm_voutput_export_buffer(voutput_info, buffer);
1169 if (!voutput_buffer->wl_buffer) {
1170 /* LCOV_EXCL_START */
1172 TDM_ERR("fail export buffer");
1173 free(voutput_buffer);
1174 tbm_surface_internal_unref(buffer);
1177 /* LCOV_EXCL_STOP */
1180 voutput_buffer->buffer = buffer;
1181 LIST_ADDTAIL(&voutput_buffer->link, &voutput_info->buffer_list);
1183 return voutput_buffer;
1187 tdm_voutput_attach_buffer(tdm_voutput *voutput, tbm_surface_h buffer)
1189 tdm_private_server *private_server = keep_private_server;
1190 tdm_server_voutput_info *voutput_info = NULL, *vo = NULL;
1191 tdm_server_voutput_buffer *voutput_buffer = NULL;
1193 TDM_RETURN_VAL_IF_FAIL(keep_private_server != NULL, TDM_ERROR_OPERATION_FAILED);
1195 LIST_FOR_EACH_ENTRY(vo, &private_server->voutput_list, link) {
1196 if (vo && vo->voutput == voutput) {
1201 TDM_RETURN_VAL_IF_FAIL(voutput_info != NULL, TDM_ERROR_INVALID_PARAMETER);
1202 TDM_RETURN_VAL_IF_FAIL(voutput_info->attach_buffer == NULL, TDM_ERROR_OPERATION_FAILED);
1204 voutput_buffer = _tdm_output_get_voutput_buffer(voutput_info, buffer);
1205 TDM_RETURN_VAL_IF_FAIL(voutput_buffer != NULL, TDM_ERROR_OUT_OF_MEMORY);
1207 voutput_info->attach_buffer = voutput_buffer;
1209 wl_tdm_voutput_send_attach_buffer(voutput_info->resource, voutput_buffer->wl_buffer);
1211 return TDM_ERROR_NONE;
1215 tdm_voutput_commit_buffer(tdm_voutput *voutput)
1217 tdm_private_server *private_server = keep_private_server;
1218 tdm_server_voutput_info *voutput_info = NULL, *vo = NULL;
1220 TDM_RETURN_VAL_IF_FAIL(keep_private_server != NULL, TDM_ERROR_OPERATION_FAILED);
1222 LIST_FOR_EACH_ENTRY(vo, &private_server->voutput_list, link) {
1223 if (vo && vo->voutput == voutput) {
1228 TDM_RETURN_VAL_IF_FAIL(voutput_info != NULL, TDM_ERROR_INVALID_PARAMETER);
1229 TDM_RETURN_VAL_IF_FAIL(voutput_info->attach_buffer != NULL, TDM_ERROR_OPERATION_FAILED);
1230 TDM_RETURN_VAL_IF_FAIL(voutput_info->committing == 0, TDM_ERROR_OPERATION_FAILED);
1232 voutput_info->committing = 1;
1234 wl_tdm_voutput_send_commit(voutput_info->resource);
1236 return TDM_ERROR_NONE;
1240 tdm_voutput_cb_resource_destroy(struct wl_resource *resource)
1242 tdm_server_voutput_info *voutput_info = wl_resource_get_user_data(resource);
1243 tdm_server_voutput_buffer *vb = NULL;
1244 tdm_voutput *voutput;
1245 tdm_error ret = TDM_ERROR_NONE;
1247 TDM_RETURN_IF_FAIL(voutput_info != NULL);
1249 voutput = voutput_info->voutput;
1251 if (voutput_info->request_commit)
1252 tdm_output_unset_voutput_commit(voutput_info->voutput);
1255 if (voutput_info->request_commit == 1) {
1256 tdm_output_unset_voutput_commit(voutput_info->voutput);
1257 voutput_info->request_commit = 0;
1258 tdm_voutput_disconnect(voutput_info->voutput);
1261 ret = tdm_voutput_destroy(voutput);
1262 if (ret != TDM_ERROR_NONE)
1263 TDM_ERR("_tdm_voutput_cb_destroy fail");
1266 if (voutput_info->attach_buffer) {
1267 tbm_surface_h buffer = voutput_info->attach_buffer->buffer;
1268 tbm_surface_internal_unref(buffer);
1269 voutput_info->committing = 0;
1270 voutput_info->attach_buffer = NULL;
1273 LIST_FOR_EACH_ENTRY(vb, &voutput_info->buffer_list, link) {
1275 wl_resource_destroy(vb->wl_buffer);
1278 LIST_DEL(&voutput_info->link);
1280 /* Do free your own resource */
1285 _tdm_server_cb_create_virtual_output(struct wl_client *client, struct wl_resource *resource, const char *name, uint32_t id)
1287 struct wl_resource *voutput_resource = NULL;
1288 tdm_private_server *private_server = wl_resource_get_user_data(resource);
1289 tdm_server_voutput_info *voutput_info;
1290 tdm_voutput *voutput;
1294 output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
1296 TDM_ERR("There is '%s' output, cannot create.", name);
1297 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1298 "There is '%s' output", name);
1302 voutput = tdm_voutput_create(private_server->private_loop->dpy, name, &ret);
1304 TDM_ERR("voutput creation fail(%s)(%d).", name, ret);
1305 wl_resource_post_error(resource, WL_DISPLAY_ERROR_NO_MEMORY,
1306 "%s output creation fail", name);
1310 output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
1312 TDM_ERR("There is no '%s' output.", name);
1313 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1314 "There is '%s' output", name);
1319 wl_resource_create(client, &wl_tdm_voutput_interface,
1320 wl_resource_get_version(resource), id);
1321 if (!voutput_resource) {
1322 /* LCOV_EXCL_START */
1324 wl_resource_post_no_memory(resource);
1325 TDM_ERR("wl_resource_create failed");
1328 /* LCOV_EXCL_STOP */
1331 voutput_info = calloc(1, sizeof * voutput_info);
1332 if (!voutput_info) {
1333 /* LCOV_EXCL_START */
1335 wl_resource_post_no_memory(resource);
1336 wl_resource_destroy(voutput_resource);
1337 TDM_ERR("alloc failed");
1340 /* LCOV_EXCL_STOP */
1343 LIST_ADDTAIL(&voutput_info->link, &private_server->voutput_list);
1344 voutput_info->private_server = private_server;
1345 voutput_info->resource = voutput_resource;
1346 voutput_info->voutput = voutput;
1347 voutput_info->output = output;
1348 LIST_INITHEAD(&voutput_info->buffer_list);
1350 wl_resource_set_implementation(voutput_resource,
1351 &tdm_voutput_implementation,
1353 tdm_voutput_cb_resource_destroy);
1355 wl_tdm_voutput_send_ack_message(voutput_resource, WL_TDM_VOUTPUT_MESSAGE_ADDED);
1358 /* LCOV_EXCL_START */
1360 _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, const char *options)
1362 tdm_private_server *private_server = wl_resource_get_user_data(resource);
1363 tdm_private_loop *private_loop = private_server->private_loop;
1364 char message[TDM_SERVER_REPLY_MSG_LEN];
1366 int len = sizeof(message), size;
1369 wl_client_get_credentials(client, NULL, &uid, NULL);
1372 snprintf(message, len, "tdm-monitor: SHOULD be a superuser.\n");
1373 TDM_ERR("%s", message);
1375 tdm_monitor_server_command(private_loop->dpy, options, message, &len);
1378 size = sizeof(message) - len;
1381 wl_client_flush(client);
1384 char buffer[TDM_DEBUG_REPLY_MSG_LEN];
1385 int copylen = TDM_MIN(size, sizeof(buffer) - 1);
1387 strncpy(buffer, m, copylen);
1391 buffer[copylen] = '\0';
1393 wl_tdm_send_debug_message(resource, buffer);
1396 wl_tdm_send_debug_done(resource);
1398 /* LCOV_EXCL_STOP */
1400 static const struct wl_tdm_interface tdm_implementation = {
1401 _tdm_server_cb_debug,
1402 _tdm_server_cb_create_output,
1403 _tdm_server_cb_create_virtual_output
1407 destroy_client(struct wl_resource *resource)
1409 tdm_server_client_info *c = NULL, *cc = NULL;
1410 struct wl_client *client;
1412 client = wl_resource_get_client(resource);
1413 TDM_RETURN_IF_FAIL(client != NULL);
1415 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) {
1416 if (c->resource == resource) {
1425 _tdm_server_bind(struct wl_client *client, void *data,
1426 uint32_t version, uint32_t id)
1428 struct wl_resource *resource;
1429 tdm_server_client_info *cinfo;
1431 resource = wl_resource_create(client, &wl_tdm_interface, version, id);
1433 /* LCOV_EXCL_START */
1435 wl_client_post_no_memory(client);
1438 /* LCOV_EXCL_STOP */
1441 cinfo = calloc(1, sizeof(tdm_server_client_info));
1443 /* LCOV_EXCL_START */
1445 wl_client_post_no_memory(client);
1446 wl_resource_destroy(resource);
1449 /* LCOV_EXCL_STOP */
1452 cinfo->resource = resource;
1454 LIST_ADDTAIL(&cinfo->link, &client_list);
1455 wl_client_get_credentials(client, &cinfo->pid, NULL, NULL);
1456 _tdm_server_get_process_name(cinfo->pid, cinfo->name, TDM_NAME_LEN);
1458 wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client);
1462 tdm_server_init(tdm_private_loop *private_loop)
1464 tdm_private_server *private_server;
1466 TDM_RETURN_VAL_IF_FAIL(private_loop, TDM_ERROR_OPERATION_FAILED);
1467 TDM_RETURN_VAL_IF_FAIL(private_loop->wl_display, TDM_ERROR_OPERATION_FAILED);
1469 if (private_loop->private_server)
1470 return TDM_ERROR_NONE;
1472 if (wl_display_add_socket(private_loop->wl_display, "tdm-socket")) {
1473 /* LCOV_EXCL_START */
1475 TDM_ERR("createing a tdm-socket failed");
1476 return TDM_ERROR_OPERATION_FAILED;
1478 /* LCOV_EXCL_STOP */
1481 private_server = calloc(1, sizeof * private_server);
1482 if (!private_server) {
1483 TDM_ERR("alloc failed");
1484 return TDM_ERROR_OUT_OF_MEMORY;
1487 LIST_INITHEAD(&private_server->output_list);
1488 LIST_INITHEAD(&private_server->voutput_list);
1489 LIST_INITHEAD(&private_server->wait_list);
1491 if (!wl_global_create(private_loop->wl_display, &wl_tdm_interface, 1,
1492 private_server, _tdm_server_bind)) {
1493 /* LCOV_EXCL_START */
1495 TDM_ERR("creating a global resource failed");
1496 free(private_server);
1497 return TDM_ERROR_OUT_OF_MEMORY;
1499 /* LCOV_EXCL_STOP */
1502 private_server->private_loop = private_loop;
1503 private_loop->private_server = private_server;
1504 keep_private_server = private_server;
1506 LIST_INITHEAD(&client_list);
1508 return TDM_ERROR_NONE;
1512 tdm_server_deinit(tdm_private_loop *private_loop)
1514 tdm_server_output_info *o = NULL, *oo = NULL;
1515 tdm_server_voutput_info *vo = NULL, *voo = NULL;
1516 tdm_server_wait_info *w = NULL, *ww = NULL;
1517 tdm_server_client_info *c = NULL, *cc = NULL;
1518 tdm_private_server *private_server;
1520 if (!private_loop->private_server)
1523 private_server = private_loop->private_server;
1525 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &private_server->wait_list, link) {
1529 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &private_server->output_list, link) {
1530 wl_resource_destroy(o->resource);
1533 LIST_FOR_EACH_ENTRY_SAFE(vo, voo, &private_server->voutput_list, link) {
1534 wl_resource_destroy(vo->resource);
1537 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) {
1538 wl_resource_destroy(c->resource);
1541 free(private_server);
1542 private_loop->private_server = NULL;
1543 keep_private_server = NULL;
1546 /* LCOV_EXCL_START */
1548 tdm_server_get_client_name(pid_t pid)
1550 tdm_server_client_info *c = NULL;
1552 LIST_FOR_EACH_ENTRY(c, &client_list, link) {
1554 return (const char*)c->name;
1559 /* LCOV_EXCL_STOP */
1561 /* LCOV_EXCL_START */
1563 tdm_server_enable_ttrace_client_vblank(tdm_display *dpy, tdm_output *output, int enable)
1565 tdm_private_server *private_server = keep_private_server;
1566 tdm_server_output_info *output_info = NULL;
1568 if (!keep_private_server)
1569 return TDM_ERROR_NONE;
1571 LIST_FOR_EACH_ENTRY(output_info, &private_server->output_list, link) {
1572 tdm_server_vblank_info *vblank_info = NULL;
1574 if (output && output_info->output != output)
1577 LIST_FOR_EACH_ENTRY(vblank_info, &output_info->vblank_list, link) {
1578 wl_tdm_vblank_send_ttrace(vblank_info->resource, enable);
1582 return TDM_ERROR_NONE;
1584 /* LCOV_EXCL_STOP */