X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftdm_server.c;h=b3946185452eda22c4d34d95a9be0ac3c5d1934a;hb=7e7fcd357fbec8140bb607ba4f9417baef49f747;hp=b193ac60939dea95b19010cb6a3db5e26563e5d5;hpb=ceee662cf0bdb1f8452ece299dbfe8bba5fe035b;p=platform%2Fcore%2Fuifw%2Flibtdm.git diff --git a/src/tdm_server.c b/src/tdm_server.c index b193ac6..b394618 100644 --- a/src/tdm_server.c +++ b/src/tdm_server.c @@ -9,7 +9,7 @@ * Taeheon Kim , * YoungJun Cho , * SooChan Lim , - * Boram Park + * Boram Park * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -37,10 +37,9 @@ #include "config.h" #endif -#include "tdm.h" +#include + #include "tdm_private.h" -#include "tdm_list.h" -#include "tdm-server-protocol.h" /* CAUTION: * - tdm server doesn't care about thread things. @@ -54,6 +53,7 @@ struct _tdm_private_server { tdm_private_loop *private_loop; struct list_head output_list; + struct list_head voutput_list; struct list_head wait_list; }; @@ -66,6 +66,29 @@ typedef struct _tdm_server_output_info { unsigned int watch_output_changes; } tdm_server_output_info; +typedef struct _tdm_server_voutput_info { + struct list_head link; + tdm_private_server *private_server; + struct wl_resource *resource; + tdm_output *output; + struct list_head output_list; + + tdm_output_conn_status status; + struct + { + int count; + tdm_output_mode *modes; + } available_modes; + struct + { + int count; + tbm_format *formats; + } available_formats; + + unsigned int mmwidth; + unsigned int mmheight; +} tdm_server_voutput_info; + typedef struct _tdm_server_vblank_info { struct list_head link; tdm_server_output_info *output_info; @@ -87,6 +110,7 @@ typedef struct _tdm_server_client_info { struct list_head link; pid_t pid; char name[TDM_NAME_LEN]; + struct wl_resource *resource; } tdm_server_client_info; static tdm_private_server *keep_private_server; @@ -121,45 +145,7 @@ _tdm_server_get_process_name(pid_t pid, char *name, unsigned int size) fclose(h); } -static tdm_output* -_tdm_server_find_output(tdm_private_server *private_server, const char *name) -{ - tdm_private_loop *private_loop = private_server->private_loop; - tdm_output *found = NULL; - - if (!strncasecmp(name, "primary", 7) || !strncasecmp(name, "default", 7)) - found = tdm_display_get_output(private_loop->dpy, 0, NULL); - - if (!found) { - int count = 0, i; - - tdm_display_get_output_count(private_loop->dpy, &count); - - for (i = 0; i < count; i++) { - tdm_output *output = tdm_display_get_output(private_loop->dpy, i, NULL); - tdm_output_conn_status status; - const char *model = NULL; - tdm_error ret; - - ret = tdm_output_get_conn_status(output, &status); - if (ret || status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) - continue; - - ret = tdm_output_get_model_info(output, NULL, &model, NULL); - if (ret || !model) - continue; - - if (strncmp(model, name, TDM_NAME_LEN)) - continue; - - found = output; - break; - } - } - - return found; -} - +/* LCOV_EXCL_START */ static void _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec) @@ -167,13 +153,12 @@ _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error, tdm_server_wait_info *found; tdm_server_vblank_info *vblank_info; - if (!keep_private_server) - return; + TDM_RETURN_IF_FAIL(keep_private_server != NULL); LIST_FIND_ITEM(wait_info, &keep_private_server->wait_list, tdm_server_wait_info, link, found); if (!found) { - TDM_DBG("wait_info(%p) is destroyed", wait_info); + TDM_ERR("wait_info(%p) is destroyed", wait_info); return; } @@ -181,21 +166,27 @@ _tdm_server_send_done(tdm_server_wait_info *wait_info, tdm_error error, TDM_DBG("req_id(%d) done", wait_info->req_id); vblank_info = wait_info->vblank_info; + + if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK) + TDM_TRACE_ASYNC_END((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); + wl_tdm_vblank_send_done(vblank_info->resource, wait_info->req_id, sequence, tv_sec, tv_usec, error); - TDM_TRACE_ASYNC_END((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); - destroy_wait(wait_info); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_cb_vblank(tdm_vblank *vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data) { _tdm_server_send_done((tdm_server_wait_info*)user_data, error, sequence, tv_sec, tv_usec); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_cb_output_change(tdm_output *output, tdm_output_change_type type, tdm_value value, void *user_data) @@ -229,6 +220,7 @@ _tdm_server_cb_output_change(tdm_output *output, tdm_output_change_type type, break; } } +/* LCOV_EXCL_STOP */ static void destroy_wait(tdm_server_wait_info *wait_info) @@ -258,42 +250,58 @@ destroy_vblank_callback(struct wl_resource *resource) free(vblank_info); } +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_set_name(struct wl_client *client, struct wl_resource *resource, const char *name) { tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource); + tdm_error ret; - tdm_vblank_set_name(vblank_info->vblank, name); + ret = tdm_vblank_set_name(vblank_info->vblank, name); + TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_set_fps(struct wl_client *client, struct wl_resource *resource, uint32_t fps) { tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource); + tdm_error ret; - tdm_vblank_set_fps(vblank_info->vblank, fps); + ret = tdm_vblank_set_fps(vblank_info->vblank, fps); + TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE); } +/* LCOV_EXCL_STOP */ +/* LCOV_EXCL_START */ static void _tdm_server_vblank_cb_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t offset) { tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource); + tdm_error ret; - tdm_vblank_set_offset(vblank_info->vblank, offset); + ret = tdm_vblank_set_offset(vblank_info->vblank, offset); + TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE); } +/* LCOV_EXCL_STOP */ static void _tdm_server_vblank_cb_set_enable_fake(struct wl_client *client, struct wl_resource *resource, uint32_t enable_fake) { tdm_server_vblank_info *vblank_info = wl_resource_get_user_data(resource); + tdm_error ret; - tdm_vblank_set_enable_fake(vblank_info->vblank, enable_fake); + ret = tdm_vblank_set_enable_fake(vblank_info->vblank, enable_fake); + TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE); } static void @@ -309,9 +317,13 @@ _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource * wait_info = calloc(1, sizeof * wait_info); if (!wait_info) { + /* LCOV_EXCL_START */ + TDM_ERR("alloc failed"); ret = TDM_ERROR_OUT_OF_MEMORY; goto wait_failed; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&wait_info->link, &private_server->wait_list); @@ -322,7 +334,8 @@ _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource * if (tdm_debug_module & TDM_DEBUG_VBLANK) TDM_DBG("req_id(%d) wait", req_id); - TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); + if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK) + TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); ret = tdm_vblank_wait(vblank_info->vblank, req_sec, req_usec, interval, _tdm_server_cb_vblank, wait_info); @@ -334,9 +347,13 @@ _tdm_server_vblank_cb_wait_vblank(struct wl_client *client, struct wl_resource * return; wait_failed: + /* LCOV_EXCL_START */ + wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret); if (wait_info) destroy_wait(wait_info); + + /* LCOV_EXCL_STOP */ } static void @@ -352,9 +369,13 @@ _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resour wait_info = calloc(1, sizeof * wait_info); if (!wait_info) { + /* LCOV_EXCL_START */ + TDM_ERR("alloc failed"); ret = TDM_ERROR_OUT_OF_MEMORY; goto wait_failed; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&wait_info->link, &private_server->wait_list); @@ -365,7 +386,8 @@ _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resour if (tdm_debug_module & TDM_DEBUG_VBLANK) TDM_DBG("req_id(%d) wait", req_id); - TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); + if (tdm_ttrace_module & TDM_TTRACE_SERVER_VBLANK) + TDM_TRACE_ASYNC_BEGIN((int)wait_info->req_time, "TDM_Server_Vblank:%u", vblank_info->stamp); ret = tdm_vblank_wait_seq(vblank_info->vblank, req_sec, req_usec, sequence, _tdm_server_cb_vblank, wait_info); @@ -377,9 +399,13 @@ _tdm_server_vblank_cb_wait_vblank_seq(struct wl_client *client, struct wl_resour return; wait_failed: + /* LCOV_EXCL_START */ + wl_tdm_vblank_send_done(vblank_info->resource, req_id, 0, 0, 0, ret); if (wait_info) destroy_wait(wait_info); + + /* LCOV_EXCL_STOP */ } static const struct wl_tdm_vblank_interface tdm_vblank_implementation = { @@ -392,11 +418,13 @@ static const struct wl_tdm_vblank_interface tdm_vblank_implementation = { _tdm_server_vblank_cb_wait_vblank_seq, }; +/* LCOV_EXCL_START */ static void _tdm_server_output_cb_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); } +/* LCOV_EXCL_STOP */ static void _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource *resource, uint32_t id) @@ -412,26 +440,38 @@ _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource wl_resource_create(client, &wl_tdm_vblank_interface, wl_resource_get_version(resource), id); if (!vblank_resource) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); TDM_ERR("wl_resource_create failed"); return; + + /* LCOV_EXCL_STOP */ } vblank = tdm_vblank_create(private_loop->dpy, output_info->output, NULL); if (!vblank) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); wl_resource_destroy(vblank_resource); TDM_ERR("tdm_vblank_create failed"); return; + + /* LCOV_EXCL_STOP */ } vblank_info = calloc(1, sizeof * vblank_info); if (!vblank_info) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); wl_resource_destroy(vblank_resource); tdm_vblank_destroy(vblank); TDM_ERR("alloc failed"); return; + + /* LCOV_EXCL_STOP */ } LIST_ADDTAIL(&vblank_info->link, &output_info->vblank_list); @@ -447,9 +487,16 @@ _tdm_server_output_cb_create_vblank(struct wl_client *client, struct wl_resource wl_tdm_vblank_send_stamp(vblank_info->resource, vblank_info->stamp); + if (tdm_ttrace_module & TDM_TTRACE_CLIENT_VBLANK) { + tdm_output *output = tdm_display_get_output(private_loop->dpy, tdm_ttrace_output, NULL); + if (output == output_info->output) + wl_tdm_vblank_send_ttrace(vblank_info->resource, 1); + } + return; } +/* LCOV_EXCL_START */ static void _tdm_server_output_cb_watch_output_changes(struct wl_client *client, struct wl_resource *resource, unsigned int enable) { @@ -459,6 +506,7 @@ _tdm_server_output_cb_watch_output_changes(struct wl_client *client, struct wl_r output_info->watch_output_changes = enable; } +/* LCOV_EXCL_STOP */ static void _tdm_server_output_cb_get_connection(struct wl_client *client, struct wl_resource *resource) @@ -470,7 +518,7 @@ _tdm_server_output_cb_get_connection(struct wl_client *client, struct wl_resourc TDM_RETURN_IF_FAIL(output_info != NULL); ret = tdm_output_get_conn_status(output_info->output, &status); - TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed); wl_tdm_output_send_connection(output_info->resource, status, ret); @@ -490,14 +538,14 @@ _tdm_server_output_cb_get_mode(struct wl_client *client, struct wl_resource *res TDM_RETURN_IF_FAIL(output_info != NULL); ret = tdm_output_get_conn_status(output_info->output, &status); - TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed); if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) { const tdm_output_mode *mode = NULL; unsigned int hdisplay, vdisplay, vrefresh; ret = tdm_output_get_mode(output_info->output, &mode); - TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed); hdisplay = (mode) ? mode->hdisplay : 0; vdisplay = (mode) ? mode->vdisplay : 0; @@ -523,13 +571,13 @@ _tdm_server_output_cb_get_dpms(struct wl_client *client, struct wl_resource *res TDM_RETURN_IF_FAIL(output_info != NULL); ret = tdm_output_get_conn_status(output_info->output, &status); - TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed); if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) { tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; ret = tdm_output_get_dpms(output_info->output, &dpms_value); - TDM_GOTO_IF_FAIL(ret != TDM_ERROR_NONE, failed); + TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed); wl_tdm_output_send_dpms(output_info->resource, dpms_value, ret); } else { @@ -581,29 +629,50 @@ _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resou tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; tdm_error ret; - output = _tdm_server_find_output(private_server, name); + output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL); if (!output) { + /* LCOV_EXCL_START */ + TDM_ERR("There is no '%s' output", name); wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "There is no '%s' output", name); return; + + /* LCOV_EXCL_STOP */ } output_resource = wl_resource_create(client, &wl_tdm_output_interface, wl_resource_get_version(resource), id); if (!output_resource) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); TDM_ERR("wl_resource_create failed"); return; + + /* LCOV_EXCL_STOP */ } output_info = calloc(1, sizeof * output_info); if (!output_info) { + /* LCOV_EXCL_START */ + wl_resource_post_no_memory(resource); wl_resource_destroy(output_resource); TDM_ERR("alloc failed"); return; + + /* LCOV_EXCL_STOP */ + } + + ret = tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info); + if (ret != TDM_ERROR_NONE) { + wl_resource_post_no_memory(resource); + wl_resource_destroy(output_resource); + free(output_info); + TDM_ERR("tdm_output_add_change_handler failed"); + return; } LIST_ADDTAIL(&output_info->link, &private_server->output_list); @@ -612,8 +681,6 @@ _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resou output_info->output = output; LIST_INITHEAD(&output_info->vblank_list); - tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info); - wl_resource_set_implementation(output_resource, &tdm_output_implementation, output_info, destroy_output_callback); @@ -639,6 +706,249 @@ _tdm_server_cb_create_output(struct wl_client *client, struct wl_resource *resou } } +static void _tdm_voutput_cb_destroy(struct wl_client *client, struct wl_resource *resource) +{ + tdm_server_voutput_info *voutput_info; + tdm_private_server *private_server; + tdm_output *output; + tdm_error ret = TDM_ERROR_NONE; + + voutput_info = wl_resource_get_user_data(resource); + + private_server = voutput_info->private_server; + output = voutput_info->output; + + if (output) + ret = tdm_display_destroy_output(private_server->private_loop->dpy, output); + + if (ret != TDM_ERROR_NONE) + TDM_ERR("_tdm_voutput_cb_destroy fail"); + + wl_resource_destroy(resource); +} + +static void +_tdm_voutput_cb_set_available_modes(struct wl_client *client, + struct wl_resource *resource, + uint32_t index, + uint32_t clock, + uint32_t hdisplay, + uint32_t hsync_start, + uint32_t hsync_end, + uint32_t htotal, + uint32_t hskew, + uint32_t vdisplay, + uint32_t vsync_start, + uint32_t vsync_end, + uint32_t vtotal, + uint32_t vscan, + uint32_t vrefresh, + uint32_t flags, + uint32_t type, + const char *name) +{ + tdm_server_voutput_info *voutput_info; + tdm_output_mode *tmp_modes, *old_modes; + tdm_output_mode *new_mode; + int count, len; + + voutput_info = wl_resource_get_user_data(resource); + + count = voutput_info->available_modes.count; + old_modes = voutput_info->available_modes.modes; + if (index >= count) { + if (count > 0) { + tmp_modes = malloc(count * sizeof(*tmp_modes)); + memcpy(tmp_modes, old_modes, count * sizeof(tdm_output_mode)); + } + + voutput_info->available_modes.count = index + 1; + voutput_info->available_modes.modes = + realloc(voutput_info->available_modes.modes, + sizeof(tdm_output_mode) * (index + 1)); + + if (count > 0) { + memcpy(voutput_info->available_modes.modes, tmp_modes, count * sizeof(tdm_output_mode)); + free(tmp_modes); + } + } + + new_mode = &voutput_info->available_modes.modes[index]; + new_mode->clock = clock; + new_mode->hdisplay = hdisplay; + new_mode->hsync_start = hsync_start; + new_mode->hsync_end = hsync_end; + new_mode->htotal = htotal; + new_mode->hskew= hskew; + new_mode->vdisplay= vdisplay; + new_mode->vsync_start= vsync_start; + new_mode->vsync_end = vsync_end; + new_mode->vtotal = vtotal; + new_mode->vscan = vscan; + new_mode->vrefresh = vrefresh; + new_mode->flags = flags; + new_mode->type = type; + + len = strlen(name); + strncpy(new_mode->name, name, len); + new_mode->name[len] = '\0'; +} + +static void +_tdm_voutput_cb_set_available_formats(struct wl_client *client, + struct wl_resource *resource, + struct wl_array *formats) +{ + tdm_server_voutput_info *voutput_info; + tbm_format *f; + int count = 0, i = 0; + + voutput_info = wl_resource_get_user_data(resource); + + voutput_info->available_formats.count = 0; + if (voutput_info->available_formats.formats) + free(voutput_info->available_formats.formats); + + wl_array_for_each(f, formats) + count++; + + voutput_info->available_formats.formats = malloc(count * sizeof(tbm_format)); + voutput_info->available_formats.count = count; + + wl_array_for_each(f, formats) + voutput_info->available_formats.formats[i++] = *f; +} + +static void +_tdm_voutput_cb_set_physical_size(struct wl_client *client, struct wl_resource *resource, + unsigned int mmwidth, unsigned int mmheight) +{ + tdm_server_voutput_info *voutput_info; + + voutput_info = wl_resource_get_user_data(resource); + + voutput_info->mmwidth = mmwidth; + voutput_info->mmheight = mmheight; +} + +static void +_tdm_voutput_cb_connect(struct wl_client *client, struct wl_resource *resource) +{ + tdm_server_voutput_info *voutput_info; + + voutput_info = wl_resource_get_user_data(resource); + voutput_info->status = TDM_OUTPUT_CONN_STATUS_CONNECTED; + + tdm_output_set_physical_size(voutput_info->output, voutput_info->mmwidth, voutput_info->mmheight); + tdm_output_set_available_mode(voutput_info->output, voutput_info->available_modes.modes, voutput_info->available_modes.count); + tdm_output_set_connect(voutput_info->output); +} + +static void +_tdm_voutput_cb_disconnect(struct wl_client *client, struct wl_resource *resource) +{ + tdm_server_voutput_info *voutput_info; + + voutput_info = wl_resource_get_user_data(resource); + voutput_info->status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + + /* Do free resources when it's being disconnected */ + free(voutput_info->available_modes.modes); + voutput_info->available_modes.modes = NULL; + voutput_info->available_modes.count = 0; + voutput_info->mmwidth = 0; + voutput_info->mmheight = 0; + + tdm_output_set_disconnect(voutput_info->output); +} + +static const struct wl_tdm_voutput_interface tdm_voutput_implementation = { + _tdm_voutput_cb_destroy, + _tdm_voutput_cb_set_available_modes, + _tdm_voutput_cb_set_available_formats, + _tdm_voutput_cb_set_physical_size, + _tdm_voutput_cb_connect, + _tdm_voutput_cb_disconnect +}; + +void +tdm_voutput_cb_resource_destroy(struct wl_resource *resource) +{ + tdm_server_voutput_info *voutput_info = wl_resource_get_user_data(resource); + + TDM_RETURN_IF_FAIL(voutput_info != NULL); + + LIST_DEL(&voutput_info->link); + + /* Do free your own resource */ + free(voutput_info); +} + +static void +_tdm_server_cb_create_virtual_output(struct wl_client *client, struct wl_resource *resource, const char *name, uint32_t id) +{ + struct wl_resource *voutput_resource = NULL; + tdm_private_server *private_server = wl_resource_get_user_data(resource); + tdm_server_voutput_info *voutput_info; + tdm_output *output; + tdm_error ret; + + output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL); + if (output) { + TDM_ERR("There is '%s' output, cannot create.", name); + wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, + "There is '%s' output", name); + return; + } + + output = tdm_display_create_output(private_server->private_loop->dpy, name, &ret); + if (!output) { + TDM_ERR("output creation fail(%s)(%d).", name, ret); + wl_resource_post_error(resource, WL_DISPLAY_ERROR_NO_MEMORY, + "%s output creation fail", name); + return; + } + + voutput_resource = + wl_resource_create(client, &wl_tdm_voutput_interface, + wl_resource_get_version(resource), id); + if (!voutput_resource) { + /* LCOV_EXCL_START */ + + wl_resource_post_no_memory(resource); + TDM_ERR("wl_resource_create failed"); + return; + + /* LCOV_EXCL_STOP */ + } + + voutput_info = calloc(1, sizeof * voutput_info); + if (!voutput_info) { + /* LCOV_EXCL_START */ + + wl_resource_post_no_memory(resource); + wl_resource_destroy(voutput_resource); + TDM_ERR("alloc failed"); + return; + + /* LCOV_EXCL_STOP */ + } + + LIST_ADDTAIL(&voutput_info->link, &private_server->voutput_list); + voutput_info->private_server = private_server; + voutput_info->resource = voutput_resource; + voutput_info->output = output; + LIST_INITHEAD(&voutput_info->output_list); + + wl_resource_set_implementation(voutput_resource, + &tdm_voutput_implementation, + voutput_info, + tdm_voutput_cb_resource_destroy); + + wl_tdm_voutput_send_ack_message(voutput_resource, WL_TDM_VOUTPUT_MESSAGE_ADDED); +} + +/* LCOV_EXCL_START */ static void _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, const char *options) { @@ -678,21 +988,12 @@ _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, con wl_tdm_send_debug_done(resource); } - -static void -_tdm_server_cb_set_client_vblank_fps(struct wl_client *client, struct wl_resource *resource, - unsigned int pid, const char *name, unsigned int fps) -{ - tdm_error ret = tdm_vblank_set_client_vblank_fps(pid, name, fps); - TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE); - - TDM_INFO("'%s' vblank fps(PID: '%u'): %u", name, pid, fps); -} +/* LCOV_EXCL_STOP */ static const struct wl_tdm_interface tdm_implementation = { _tdm_server_cb_debug, _tdm_server_cb_create_output, - _tdm_server_cb_set_client_vblank_fps, + _tdm_server_cb_create_virtual_output }; static void @@ -700,15 +1001,12 @@ destroy_client(struct wl_resource *resource) { tdm_server_client_info *c = NULL, *cc = NULL; struct wl_client *client; - pid_t pid = -1; client = wl_resource_get_client(resource); TDM_RETURN_IF_FAIL(client != NULL); - wl_client_get_credentials(client, &pid, NULL, NULL); - LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) { - if (c->pid == pid) { + if (c->resource == resource) { LIST_DEL(&c->link); free(c); return; @@ -725,17 +1023,27 @@ _tdm_server_bind(struct wl_client *client, void *data, resource = wl_resource_create(client, &wl_tdm_interface, version, id); if (!resource) { + /* LCOV_EXCL_START */ + wl_client_post_no_memory(client); return; + + /* LCOV_EXCL_STOP */ } cinfo = calloc(1, sizeof(tdm_server_client_info)); if (!cinfo) { + /* LCOV_EXCL_START */ + wl_client_post_no_memory(client); wl_resource_destroy(resource); return; + + /* LCOV_EXCL_STOP */ } + cinfo->resource = resource; + LIST_ADDTAIL(&cinfo->link, &client_list); wl_client_get_credentials(client, &cinfo->pid, NULL, NULL); _tdm_server_get_process_name(cinfo->pid, cinfo->name, TDM_NAME_LEN); @@ -743,106 +1051,6 @@ _tdm_server_bind(struct wl_client *client, void *data, wl_resource_set_implementation(resource, &tdm_implementation, data, destroy_client); } -static int -_tdm_getgrnam_r(const char *name) -{ - struct group *grp = NULL; - struct group *grp_res = NULL; - char* buf = NULL; - size_t buf_len; - int ret; - int id; - - buf_len = sysconf(_SC_GETGR_R_SIZE_MAX); - if (buf_len == -1) - buf_len = 2048; - - buf = calloc(1, buf_len * sizeof(char)); - if (!buf) { - TDM_ERR("creating buffer failed"); - goto failed; - } - - grp = calloc(1, sizeof(struct group)); - if (!grp) { - TDM_ERR("creating group failed"); - goto failed; - } - - ret = getgrnam_r(name, grp, buf, buf_len, &grp_res); - if (ret < 0) { - TDM_ERR("getgrnam_r failed errno:%d(%m)", ret); - goto failed; - } - - if (grp_res == NULL) { - TDM_ERR("finding name:%s group failed", name); - goto failed; - } - - id = grp->gr_gid; - free(buf); - free(grp); - - return id; - -failed: - if (buf) - free(buf); - if (grp) - free(grp); - - return -1; -} - -static void -_tdm_socket_init(tdm_private_loop *private_loop) -{ - const char *dir = NULL; - char socket_path[TDM_NAME_LEN * 2]; - int ret = -1; - uid_t uid; - gid_t gid; - - dir = getenv("XDG_RUNTIME_DIR"); - if (!dir) { - TDM_WRN("getting XDG_RUNTIME_DIR failed"); - return; - } - - strncpy(socket_path, dir, TDM_NAME_LEN - 1); - socket_path[TDM_NAME_LEN - 1] = '\0'; - - strncat(socket_path, "/tdm-socket", 11); - socket_path[TDM_NAME_LEN + 10] = '\0'; - - ret = chmod(socket_path, 509); - if (ret < 0) { - TDM_WRN("changing modes of socket file failed:%s (%m)", socket_path); - return; - } - - ret = _tdm_getgrnam_r("root"); - if (ret < 0) { - TDM_WRN("getting uid failed"); - return; - } - uid = ret; - - ret = _tdm_getgrnam_r("display"); - if (ret < 0) { - TDM_WRN("getting gid failed"); - return; - } - gid = ret; - - ret = chown(socket_path, uid, gid); - if (ret < 0) { - TDM_WRN("changing owner of socket file failed:%s (%m)", socket_path); - return; - } -} - INTERN tdm_error tdm_server_init(tdm_private_loop *private_loop) { @@ -855,11 +1063,13 @@ tdm_server_init(tdm_private_loop *private_loop) return TDM_ERROR_NONE; if (wl_display_add_socket(private_loop->wl_display, "tdm-socket")) { + /* LCOV_EXCL_START */ + TDM_ERR("createing a tdm-socket failed"); return TDM_ERROR_OPERATION_FAILED; - } - _tdm_socket_init(private_loop); + /* LCOV_EXCL_STOP */ + } private_server = calloc(1, sizeof * private_server); if (!private_server) { @@ -868,13 +1078,18 @@ tdm_server_init(tdm_private_loop *private_loop) } LIST_INITHEAD(&private_server->output_list); + LIST_INITHEAD(&private_server->voutput_list); LIST_INITHEAD(&private_server->wait_list); if (!wl_global_create(private_loop->wl_display, &wl_tdm_interface, 1, private_server, _tdm_server_bind)) { + /* LCOV_EXCL_START */ + TDM_ERR("creating a global resource failed"); free(private_server); return TDM_ERROR_OUT_OF_MEMORY; + + /* LCOV_EXCL_STOP */ } private_server->private_loop = private_loop; @@ -890,6 +1105,7 @@ INTERN void tdm_server_deinit(tdm_private_loop *private_loop) { tdm_server_output_info *o = NULL, *oo = NULL; +// tdm_server_voutput_info *vo = NULL, *voo = NULL; tdm_server_wait_info *w = NULL, *ww = NULL; tdm_server_client_info *c = NULL, *cc = NULL; tdm_private_server *private_server; @@ -906,17 +1122,21 @@ tdm_server_deinit(tdm_private_loop *private_loop) LIST_FOR_EACH_ENTRY_SAFE(o, oo, &private_server->output_list, link) { wl_resource_destroy(o->resource); } +#if 0 + LIST_FOR_EACH_ENTRY_SAFE(vo, voo, &private_server->voutput_list, link) { + wl_resource_destroy(vo->resource); + } +#endif + LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) { + wl_resource_destroy(c->resource); + } free(private_server); private_loop->private_server = NULL; keep_private_server = NULL; - - LIST_FOR_EACH_ENTRY_SAFE(c, cc, &client_list, link) { - LIST_DEL(&c->link); - free(c); - } } +/* LCOV_EXCL_START */ INTERN const char* tdm_server_get_client_name(pid_t pid) { @@ -929,3 +1149,29 @@ tdm_server_get_client_name(pid_t pid) return NULL; } +/* LCOV_EXCL_STOP */ + +/* LCOV_EXCL_START */ +INTERN tdm_error +tdm_server_enable_ttrace_client_vblank(tdm_display *dpy, tdm_output *output, int enable) +{ + tdm_private_server *private_server = keep_private_server; + tdm_server_output_info *output_info = NULL; + + if (!keep_private_server) + return TDM_ERROR_NONE; + + LIST_FOR_EACH_ENTRY(output_info, &private_server->output_list, link) { + tdm_server_vblank_info *vblank_info = NULL; + + if (output && output_info->output != output) + continue; + + LIST_FOR_EACH_ENTRY(vblank_info, &output_info->vblank_list, link) { + wl_tdm_vblank_send_ttrace(vblank_info->resource, enable); + } + } + + return TDM_ERROR_NONE; +} +/* LCOV_EXCL_STOP */