X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftdm.c;h=3f6388c90e87b768d7c13a060d1199063ce010cb;hb=969d9f15369b577ba5b8cd29c1e818e6e7e0c2ca;hp=fef325e5ff31280bda11b1e6e760cd154484c8de;hpb=33aca53f00924cf8055f5ef92ffff3d96eefb633;p=platform%2Fcore%2Fuifw%2Flibtdm.git diff --git a/src/tdm.c b/src/tdm.c index fef325e..3f6388c 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -1,36 +1,36 @@ /************************************************************************** - -libtdm - -Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved. - -Contact: Eunchul Kim , - JinYoung Jeon , - Taeheon Kim , - YoungJun Cho , - SooChan Lim , - Boram Park - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + * + * libtdm + * + * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Eunchul Kim , + * JinYoung Jeon , + * Taeheon Kim , + * YoungJun Cho , + * SooChan Lim , + * Boram Park + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * **************************************************************************/ #ifdef HAVE_CONFIG_H @@ -47,7 +47,7 @@ int tdm_mutex_locked; static tdm_private_layer * _tdm_display_find_private_layer(tdm_private_output *private_output, - tdm_layer *layer_backend) + tdm_layer *layer_backend) { tdm_private_layer *private_layer = NULL; @@ -61,7 +61,7 @@ _tdm_display_find_private_layer(tdm_private_output *private_output, static tdm_private_output * _tdm_display_find_private_output(tdm_private_display *private_display, - tdm_output *output_backend) + tdm_output *output_backend) { tdm_private_output *private_output = NULL; @@ -75,7 +75,7 @@ _tdm_display_find_private_output(tdm_private_display *private_display, INTERN tdm_private_output * tdm_display_find_output_stamp(tdm_private_display *private_display, - unsigned long stamp) + unsigned long stamp) { tdm_private_output *private_output = NULL; @@ -185,6 +185,9 @@ _tdm_display_destroy_private_output(tdm_private_output *private_output) _tdm_display_destroy_caps_output(&private_output->caps); + if (private_output->dpms_changed_timer) + tdm_event_loop_source_remove(private_output->dpms_changed_timer); + private_output->stamp = 0; free(private_output); } @@ -196,6 +199,10 @@ _tdm_display_destroy_private_display(tdm_private_display *private_display) tdm_private_pp *p = NULL, *pp = NULL; free(private_display->outputs_ptr); + if (private_display->outputs) { + free(private_display->outputs); + private_display->outputs = NULL; + } LIST_FOR_EACH_ENTRY_SAFE(p, pp, &private_display->pp_list, link) tdm_pp_destroy_internal(p); @@ -212,14 +219,9 @@ _tdm_display_destroy_private_display(tdm_private_display *private_display) static tdm_error _tdm_display_update_caps_pp(tdm_private_display *private_display, - tdm_caps_pp *caps) + tdm_caps_pp *caps) { tdm_func_display *func_display = &private_display->func_display; - char buf[1024]; - int bufsize = sizeof(buf); - char *str_buf = buf; - int *len_buf = &bufsize; - int i; tdm_error ret; if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP)) @@ -236,28 +238,14 @@ _tdm_display_update_caps_pp(tdm_private_display *private_display, return TDM_ERROR_BAD_MODULE; } - TDM_DBG("pp capabilities: %x", caps->capabilities); - buf[0] = '\0'; - for (i = 0; i < caps->format_count; i++) - TDM_SNPRINTF(str_buf, len_buf, "%c%c%c%c ", FOURCC_STR(caps->formats[i])); - TDM_DBG("pp formats: %s", buf); - TDM_DBG("pp min : %dx%d", caps->min_w, caps->min_h); - TDM_DBG("pp max : %dx%d", caps->max_w, caps->max_h); - TDM_DBG("pp align: %d", caps->preferred_align); - return TDM_ERROR_NONE; } static tdm_error _tdm_display_update_caps_capture(tdm_private_display *private_display, - tdm_caps_capture *caps) + tdm_caps_capture *caps) { tdm_func_display *func_display = &private_display->func_display; - char buf[1024]; - int bufsize = sizeof(buf); - char *str_buf = buf; - int *len_buf = &bufsize; - int i; tdm_error ret; if (!(private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE)) @@ -268,31 +256,20 @@ _tdm_display_update_caps_capture(tdm_private_display *private_display, return TDM_ERROR_BAD_MODULE; } - ret = func_display->display_get_capture_capability(private_display->bdata, - caps); + ret = func_display->display_get_capture_capability(private_display->bdata, caps); if (ret != TDM_ERROR_NONE) { TDM_ERR("display_get_capture_capability() failed"); return TDM_ERROR_BAD_MODULE; } - buf[0] = '\0'; - for (i = 0; i < caps->format_count; i++) - TDM_SNPRINTF(str_buf, len_buf, "%c%c%c%c ", FOURCC_STR(caps->formats[i])); - TDM_DBG("capture formats: %s", buf); - return TDM_ERROR_NONE; } static tdm_error _tdm_display_update_caps_layer(tdm_private_display *private_display, - tdm_layer *layer_backend, tdm_caps_layer *caps) + tdm_layer *layer_backend, tdm_caps_layer *caps) { tdm_func_layer *func_layer = &private_display->func_layer; - char buf[1024]; - int bufsize = sizeof(buf); - char *str_buf = buf; - int *len_buf = &bufsize; - int i; tdm_error ret; if (!func_layer->layer_get_capability) { @@ -306,25 +283,15 @@ _tdm_display_update_caps_layer(tdm_private_display *private_display, return TDM_ERROR_BAD_MODULE; } - TDM_DBG("layer capabilities: %x", caps->capabilities); - TDM_DBG("layer zpos : %d", caps->zpos); - buf[0] = '\0'; - for (i = 0; i < caps->format_count; i++) - TDM_SNPRINTF(str_buf, len_buf, "%c%c%c%c ", FOURCC_STR(caps->formats[i])); - TDM_DBG("layer formats: %s", buf); - for (i = 0; i < caps->prop_count; i++) - TDM_DBG("layer props: %d, %s", caps->props[i].id, caps->props[i].name); - return TDM_ERROR_NONE; } static tdm_error _tdm_display_update_caps_output(tdm_private_display *private_display, int pipe, - tdm_output *output_backend, tdm_caps_output *caps) + tdm_output *output_backend, tdm_caps_output *caps) { tdm_func_output *func_output = &private_display->func_output; char temp[TDM_NAME_LEN]; - int i; tdm_error ret; if (!func_output->output_get_capability) { @@ -342,35 +309,13 @@ _tdm_display_update_caps_output(tdm_private_display *private_display, int pipe, snprintf(temp, TDM_NAME_LEN, "%s-%d", caps->model, pipe); snprintf(caps->model, TDM_NAME_LEN, "%s", temp); - TDM_DBG("output maker: %s", caps->maker); - TDM_DBG("output model: %s", caps->model); - TDM_DBG("output name: %s", caps->name); - TDM_DBG("output status: %d", caps->status); - TDM_DBG("output type : %d", caps->type); - for (i = 0; i < caps->prop_count; i++) - TDM_DBG("output props: %d, %s", caps->props[i].id, caps->props[i].name); - for (i = 0; i < caps->mode_count; i++) { - TDM_DBG("output modes: name(%s), clock(%d) vrefresh(%d), flags(%x), type(%d)", - caps->modes[i].name, caps->modes[i].clock, caps->modes[i].vrefresh, - caps->modes[i].flags, caps->modes[i].type); - TDM_DBG("\t\t %d, %d, %d, %d, %d", - caps->modes[i].hdisplay, caps->modes[i].hsync_start, caps->modes[i].hsync_end, - caps->modes[i].htotal, caps->modes[i].hskew); - TDM_DBG("\t\t %d, %d, %d, %d, %d", - caps->modes[i].vdisplay, caps->modes[i].vsync_start, caps->modes[i].vsync_end, - caps->modes[i].vtotal, caps->modes[i].vscan); - } - TDM_DBG("output min : %dx%d", caps->min_w, caps->min_h); - TDM_DBG("output max : %dx%d", caps->max_w, caps->max_h); - TDM_DBG("output align: %d", caps->preferred_align); - return TDM_ERROR_NONE; } static tdm_error _tdm_display_update_layer(tdm_private_display *private_display, - tdm_private_output *private_output, - tdm_layer *layer_backend) + tdm_private_output *private_output, + tdm_layer *layer_backend, int index) { tdm_private_layer *private_layer; tdm_error ret; @@ -380,7 +325,8 @@ _tdm_display_update_layer(tdm_private_display *private_display, private_layer = calloc(1, sizeof(tdm_private_layer)); TDM_RETURN_VAL_IF_FAIL(private_layer != NULL, TDM_ERROR_OUT_OF_MEMORY); - LIST_ADD(&private_layer->link, &private_output->layer_list); + LIST_ADDTAIL(&private_layer->link, &private_output->layer_list); + private_layer->index = index; private_layer->private_display = private_display; private_layer->private_output = private_output; private_layer->layer_backend = layer_backend; @@ -392,7 +338,7 @@ _tdm_display_update_layer(tdm_private_display *private_display, _tdm_display_destroy_caps_layer(&private_layer->caps); ret = _tdm_display_update_caps_layer(private_display, layer_backend, - &private_layer->caps); + &private_layer->caps); if (ret != TDM_ERROR_NONE) goto failed_update; @@ -402,9 +348,9 @@ failed_update: return ret; } -static tdm_error -_tdm_display_update_output(tdm_private_display *private_display, - tdm_output *output_backend, int pipe) +INTERN tdm_error +tdm_display_update_output(tdm_private_display *private_display, + tdm_output *output_backend, int pipe) { tdm_func_output *func_output = &private_display->func_output; tdm_private_output *private_output = NULL; @@ -412,8 +358,7 @@ _tdm_display_update_output(tdm_private_display *private_display, int layer_count = 0, i; tdm_error ret; - private_output = _tdm_display_find_private_output(private_display, - output_backend); + private_output = _tdm_display_find_private_output(private_display, output_backend); if (!private_output) { private_output = calloc(1, sizeof(tdm_private_output)); TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_OUT_OF_MEMORY); @@ -428,6 +373,7 @@ _tdm_display_update_output(tdm_private_display *private_display, private_output->current_dpms_value = TDM_OUTPUT_DPMS_OFF; private_output->output_backend = output_backend; private_output->pipe = pipe; + private_output->index = pipe; LIST_INITHEAD(&private_output->layer_list); LIST_INITHEAD(&private_output->capture_list); @@ -436,16 +382,18 @@ _tdm_display_update_output(tdm_private_display *private_display, LIST_INITHEAD(&private_output->change_handler_list_main); LIST_INITHEAD(&private_output->change_handler_list_sub); - if (func_output->output_set_status_handler) + if (func_output->output_set_status_handler) { func_output->output_set_status_handler(private_output->output_backend, - tdm_output_cb_status, - private_output); + tdm_output_cb_status, + private_output); + private_output->regist_change_cb = 1; + } } else _tdm_display_destroy_caps_output(&private_output->caps); ret = _tdm_display_update_caps_output(private_display, pipe, output_backend, - &private_output->caps); + &private_output->caps); if (ret != TDM_ERROR_NONE) return ret; @@ -454,7 +402,7 @@ _tdm_display_update_output(tdm_private_display *private_display, goto failed_update; for (i = 0; i < layer_count; i++) { - ret = _tdm_display_update_layer(private_display, private_output, layers[i]); + ret = _tdm_display_update_layer(private_display, private_output, layers[i], i); if (ret != TDM_ERROR_NONE) goto failed_update; } @@ -484,8 +432,7 @@ _tdm_display_set_main_first(tdm_output **outputs, int index) } static tdm_output ** -_tdm_display_get_ordered_outputs(tdm_private_display *private_display, - int *count, int init) +_tdm_display_get_ordered_outputs(tdm_private_display *private_display, int *count) { tdm_func_display *func_display = &private_display->func_display; tdm_output **outputs = NULL; @@ -498,8 +445,11 @@ _tdm_display_get_ordered_outputs(tdm_private_display *private_display, int index_dsi = 0, index_lvds = 0, index_hdmia = 0, index_hdmib = 0; tdm_error ret; - outputs = func_display->display_get_outputs(private_display->bdata, - &output_count, &ret); + /* don't change list order if not init time */ + if (private_display->outputs) + return private_display->outputs; + + outputs = func_display->display_get_outputs(private_display->bdata, &output_count, &ret); if (ret != TDM_ERROR_NONE) goto failed_get_outputs; @@ -507,12 +457,10 @@ _tdm_display_get_ordered_outputs(tdm_private_display *private_display, if (output_count == 0) goto failed_get_outputs; - else if (output_count == 1) - return outputs; - - /* don't change list order if not init time */ - if (init != 0) + else if (output_count == 1) { + private_display->outputs = outputs; return outputs; + } /* count connected outputs */ for (i = 0; i < output_count; i++) { @@ -522,13 +470,13 @@ _tdm_display_get_ordered_outputs(tdm_private_display *private_display, if (!func_output->output_get_capability) { TDM_ERR("no output_get_capability()"); - return outputs; + goto failed_get_outputs; } ret = func_output->output_get_capability(outputs[i], &caps); if (ret != TDM_ERROR_NONE) { TDM_ERR("output_get_capability() failed"); - return outputs; + goto failed_get_outputs; } if (caps.status == TDM_OUTPUT_CONN_STATUS_CONNECTED) { @@ -551,7 +499,7 @@ _tdm_display_get_ordered_outputs(tdm_private_display *private_display, output_hdmib = outputs[i]; index_hdmib = i; break; - default : + default: break; } } @@ -590,20 +538,23 @@ _tdm_display_get_ordered_outputs(tdm_private_display *private_display, new_outputs = outputs; } + private_display->outputs = new_outputs; + return new_outputs; failed_get_outputs: + free(outputs); *count = 0; return NULL; } static tdm_error _tdm_display_update_internal(tdm_private_display *private_display, - int only_display) + int only_display) { tdm_output **outputs = NULL; int output_count = 0, i; - tdm_error ret; + tdm_error ret = TDM_ERROR_NONE; LIST_INITHEAD(&private_display->output_list); LIST_INITHEAD(&private_display->pp_list); @@ -615,28 +566,25 @@ _tdm_display_update_internal(tdm_private_display *private_display, goto failed_update; ret = _tdm_display_update_caps_capture(private_display, - &private_display->caps_capture); + &private_display->caps_capture); if (ret != TDM_ERROR_NONE) goto failed_update; } - outputs = _tdm_display_get_ordered_outputs(private_display, &output_count, only_display); + outputs = _tdm_display_get_ordered_outputs(private_display, &output_count); if (!outputs) goto failed_update; for (i = 0; i < output_count; i++) { - ret = _tdm_display_update_output(private_display, outputs[i], i); + ret = tdm_display_update_output(private_display, outputs[i], i); if (ret != TDM_ERROR_NONE) goto failed_update; } - free(outputs); - return TDM_ERROR_NONE; failed_update: _tdm_display_destroy_private_display(private_display); - free(outputs); return ret; } @@ -661,10 +609,8 @@ tdm_display_update(tdm_display *dpy) #define SUFFIX_MODULE ".so" #define DEFAULT_MODULE "libtdm-default"SUFFIX_MODULE -int tdm_debug; -int tdm_debug_buffer; -int tdm_debug_thread; -int tdm_debug_mutex; +int tdm_debug_module; +int tdm_debug_dump; static tdm_private_display *g_private_display; static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; @@ -672,42 +618,47 @@ static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; static tdm_error _tdm_display_check_module(tdm_backend_module *module) { - const char *name; - const char *vendor; int major, minor; - int abimaj, abimin; - abimaj = TDM_BACKEND_GET_ABI_MAJOR(TDM_BACKEND_ABI_VERSION); - abimin = TDM_BACKEND_GET_ABI_MINOR(TDM_BACKEND_ABI_VERSION); + TDM_INFO("TDM ABI version : %d.%d", + TDM_MAJOR_VERSION, TDM_MINOR_VERSION); - TDM_INFO("TDM module ABI version : %d.%d", abimaj, abimin); + if (!module->name) { + TDM_ERR("TDM backend doesn't have name"); + return TDM_ERROR_BAD_MODULE; + } + + if (!module->vendor) { + TDM_ERR("TDM backend doesn't have vendor"); + return TDM_ERROR_BAD_MODULE; + } - name = module->name ? module->name : "unknown"; - vendor = module->vendor ? module->vendor : "unknown"; major = TDM_BACKEND_GET_ABI_MAJOR(module->abi_version); minor = TDM_BACKEND_GET_ABI_MINOR(module->abi_version); - TDM_INFO("TDM module name: %s", name); - TDM_INFO("'%s' vendor: %s", name, vendor); - TDM_INFO("'%s' version: %d.%d", name, major, minor); + TDM_INFO("TDM module name: %s", module->name); + TDM_INFO("'%s' vendor: %s", module->name, module->vendor); + TDM_INFO("'%s' version: %d.%d", module->name, major, minor); - if (major != abimaj) { - TDM_ERR("'%s' major version mismatch, %d != %d", name, major, abimaj); + if (major != TDM_MAJOR_VERSION) { + TDM_ERR("'%s' major version mismatch, %d != %d", + module->name, major, TDM_MAJOR_VERSION); return TDM_ERROR_BAD_MODULE; } - if (minor > abimin) { - TDM_ERR("'%s' minor version(%d) is newer than %d", name, minor, abimin); + if (minor > TDM_MINOR_VERSION) { + TDM_ERR("'%s' minor version(%d) is newer than %d", + module->name, minor, TDM_MINOR_VERSION); return TDM_ERROR_BAD_MODULE; } if (!module->init) { - TDM_ERR("'%s' doesn't have init function", name); + TDM_ERR("'%s' doesn't have init function", module->name); return TDM_ERROR_BAD_MODULE; } if (!module->deinit) { - TDM_ERR("'%s' doesn't have deinit function", name); + TDM_ERR("'%s' doesn't have deinit function", module->name); return TDM_ERROR_BAD_MODULE; } @@ -725,25 +676,24 @@ _tdm_display_check_backend_functions(tdm_private_display *private_display) /* below functions should be implemented in backend side */ TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_BAD_MODULE); - TDM_RETURN_VAL_IF_FAIL(func_display->display_get_capabilitiy, - TDM_ERROR_BAD_MODULE); +// TDM_RETURN_VAL_IF_FAIL(func_display->display_get_capabilitiy, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_display->display_get_outputs, TDM_ERROR_BAD_MODULE); - TDM_RETURN_VAL_IF_FAIL(func_output->output_get_capability, - TDM_ERROR_BAD_MODULE); + TDM_RETURN_VAL_IF_FAIL(func_output->output_get_capability, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_output->output_get_layers, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_layer->layer_get_capability, TDM_ERROR_BAD_MODULE); - ret = func_display->display_get_capabilitiy(private_display->bdata, - &private_display->caps_display); + if (func_display->display_get_capability) + ret = func_display->display_get_capability(private_display->bdata, &private_display->caps_display); + else + ret = func_display->display_get_capabilitiy(private_display->bdata, &private_display->caps_display); if (ret != TDM_ERROR_NONE) { - TDM_ERR("display_get_capabilitiy() failed"); + TDM_ERR("display_get_capability() failed"); return TDM_ERROR_BAD_MODULE; } if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) { tdm_func_pp *func_pp = &private_display->func_pp; - TDM_RETURN_VAL_IF_FAIL(func_display->display_get_pp_capability, - TDM_ERROR_BAD_MODULE); + TDM_RETURN_VAL_IF_FAIL(func_display->display_get_pp_capability, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_display->display_create_pp, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_pp->pp_destroy, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_pp->pp_commit, TDM_ERROR_BAD_MODULE); @@ -752,15 +702,12 @@ _tdm_display_check_backend_functions(tdm_private_display *private_display) if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) { tdm_func_capture *func_capture = &private_display->func_capture; - TDM_RETURN_VAL_IF_FAIL(func_display->display_get_capture_capability, - TDM_ERROR_BAD_MODULE); - TDM_RETURN_VAL_IF_FAIL(func_output->output_create_capture, - TDM_ERROR_BAD_MODULE); + TDM_RETURN_VAL_IF_FAIL(func_display->display_get_capture_capability, TDM_ERROR_BAD_MODULE); + TDM_RETURN_VAL_IF_FAIL(func_output->output_create_capture, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_layer->layer_create_capture, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_capture->capture_destroy, TDM_ERROR_BAD_MODULE); TDM_RETURN_VAL_IF_FAIL(func_capture->capture_commit, TDM_ERROR_BAD_MODULE); - TDM_RETURN_VAL_IF_FAIL(func_capture->capture_set_done_handler, - TDM_ERROR_BAD_MODULE); + TDM_RETURN_VAL_IF_FAIL(func_capture->capture_set_done_handler, TDM_ERROR_BAD_MODULE); } return TDM_ERROR_NONE; @@ -768,7 +715,7 @@ _tdm_display_check_backend_functions(tdm_private_display *private_display) static tdm_error _tdm_display_load_module_with_file(tdm_private_display *private_display, - const char *file) + const char *file) { char path[PATH_MAX] = {0,}; tdm_backend_module *module_data; @@ -806,11 +753,10 @@ _tdm_display_load_module_with_file(tdm_private_display *private_display, /* We don't care if backend_data is NULL or not. It's up to backend. */ TDM_TRACE_BEGIN(Init_Backend); - private_display->bdata = module_data->init((tdm_display *)private_display, - &ret); + private_display->bdata = module_data->init((tdm_display *)private_display, &ret); TDM_TRACE_END(); if (ret != TDM_ERROR_NONE) { - TDM_ERR("'%s' init failed", file); + TDM_ERR("failed to init '%s' module", module_data->name); goto failed_load; } @@ -821,7 +767,7 @@ _tdm_display_load_module_with_file(tdm_private_display *private_display, goto failed_load; } - TDM_INFO("Success to load module(%s)", file); + TDM_INFO("Success to load '%s' module", module_data->name); return TDM_ERROR_NONE; failed_load: @@ -897,22 +843,6 @@ tdm_display_init(tdm_error *error) return g_private_display; } - debug = getenv("TDM_DEBUG"); - if (debug && (strstr(debug, "1"))) - tdm_debug = 1; - - debug = getenv("TDM_DEBUG_BUFFER"); - if (debug && (strstr(debug, "1"))) - tdm_debug_buffer = 1; - - debug = getenv("TDM_DEBUG_THREAD"); - if (debug && (strstr(debug, "1"))) - tdm_debug_thread = 1; - - debug = getenv("TDM_DEBUG_MUTEX"); - if (debug && (strstr(debug, "1"))) - tdm_debug_mutex = 1; - private_display = calloc(1, sizeof(tdm_private_display)); if (!private_display) { ret = TDM_ERROR_OUT_OF_MEMORY; @@ -920,6 +850,18 @@ tdm_display_init(tdm_error *error) goto failed_alloc; } + debug = getenv("TDM_DEBUG_MODULE"); + if (debug) + tdm_display_enable_debug_module(debug); + + debug = getenv("TDM_DEBUG_DUMP"); + if (debug) + tdm_display_enable_dump(private_display, debug, NULL, NULL); + + debug = getenv("TDM_DEBUG_PATH"); + if (debug) + tdm_display_enable_path(debug); + if (pthread_mutex_init(&private_display->lock, NULL)) { ret = TDM_ERROR_OPERATION_FAILED; TDM_ERR("mutex init failed: %m"); @@ -980,8 +922,6 @@ failed_event: failed_mutex_init: free(private_display); failed_alloc: - tdm_debug = 0; - tdm_debug_buffer = 0; if (error) *error = ret; _pthread_mutex_unlock(&gLock); @@ -1004,9 +944,13 @@ tdm_display_deinit(tdm_display *dpy) return; } + /* dont move the position of lock/unlock. all resource should be protected + * during destroying. after tdm_event_loop_deinit, we don't worry about thread + * things because it's finalized. + */ _pthread_mutex_lock(&private_display->lock); - tdm_event_loop_deinit(private_display); + _pthread_mutex_unlock(&private_display->lock); _tdm_display_destroy_private_display(private_display); _tdm_display_unload_module(private_display); @@ -1018,16 +962,189 @@ tdm_display_deinit(tdm_display *dpy) tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1); - _pthread_mutex_unlock(&private_display->lock); - pthread_mutex_destroy(&private_display->lock); free(private_display); g_private_display = NULL; - tdm_debug = 0; - tdm_debug_buffer = 0; + + if (tdm_debug_dump_dir) { + free(tdm_debug_dump_dir); + tdm_debug_dump_dir = NULL; + } _pthread_mutex_unlock(&gLock); TDM_INFO("done"); } +INTERN int +tdm_display_check_module_abi(tdm_private_display *private_display, int abimaj, int abimin) +{ + tdm_backend_module *module = private_display->module_data; + + if (TDM_BACKEND_GET_ABI_MAJOR(module->abi_version) < abimaj) + return 0; + + if (TDM_BACKEND_GET_ABI_MINOR(module->abi_version) < abimin) + return 0; + + return 1; +} + +INTERN tdm_error +tdm_display_enable_debug_module(const char*modules) +{ + char temp[TDM_PATH_LEN]; + char *arg; + char *end; + + snprintf(temp, TDM_PATH_LEN, "%s", modules); + + tdm_debug_module = 0; + + arg = strtok_r(temp, TDM_DELIM, &end); + while (arg) { + if (!strncmp(arg, "none", 4)) { + tdm_debug_module = 0; + return TDM_ERROR_NONE; + } + if (!strncmp(arg, "all", 3)) { + tdm_debug_module = 0xFFFFFFFF; + return TDM_ERROR_NONE; + } + if (!strncmp(arg, "buffer", 6)) + tdm_debug_module |= TDM_DEBUG_BUFFER; + else if (!strncmp(arg, "thread", 6)) + tdm_debug_module |= TDM_DEBUG_THREAD; + else if (!strncmp(arg, "mutex", 5)) + tdm_debug_module |= TDM_DEBUG_MUTEX; + else if (!strncmp(arg, "vblank", 6)) + tdm_debug_module |= TDM_DEBUG_VBLANK; + else + return TDM_ERROR_BAD_REQUEST; + + arg = strtok_r(NULL, TDM_DELIM, &end); + } + + TDM_INFO("module debugging... '%s'", modules); + + return TDM_ERROR_NONE; +} + +INTERN tdm_error +tdm_display_enable_dump(tdm_private_display *private_display, const char *dump_str, char *reply, int *len) +{ + char temp[TDM_PATH_LEN] = {0,}, temp2[TDM_PATH_LEN] = {0,}; + char *path, *path2; + char *arg; + char *end; + + snprintf(temp2, TDM_PATH_LEN, "%s", dump_str); + path2 = strtostr(temp, TDM_PATH_LEN, temp2, "@"); + if (!path2 || path2[0] == '\0') + path2 = TDM_DUMP_DIR; + else + path2++; + + path = tdm_helper_dump_make_directory(path2, reply, len); + TDM_GOTO_IF_FAIL(path != NULL, done); + + tdm_debug_dump = 0; + + snprintf(temp, sizeof(temp), "%s", dump_str); + arg = strtok_r(temp, ",", &end); + TDM_GOTO_IF_FAIL(arg != NULL, done); + + if (!strncmp(arg, "none", 4)) { + tdm_debug_dump = 0; + if (tdm_debug_dump_dir) { + free(tdm_debug_dump_dir); + tdm_debug_dump_dir = NULL; + } + TDM_SNPRINTF(reply, len, "path: %s\n", path); + goto done; + } + + if (!strncmp(arg, "current", 7)) { + tdm_private_output *o = NULL; + if (!private_display) { + TDM_WRN("no private_display"); + goto done; + } + + LIST_FOR_EACH_ENTRY(o, &private_display->output_list, link) { + tdm_private_layer *l = NULL; + LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) { + char str[TDM_PATH_LEN]; + if (l->usable) + continue; + snprintf(str, TDM_PATH_LEN, "layer_%d_%d", o->index, l->index); + tdm_helper_dump_buffer_str(l->showing_buffer, path, str); + } + } + + TDM_SNPRINTF(reply, len, "path: %s\n", path); + goto done; + } + + TDM_SNPRINTF(reply, len, "dump: %s\n", arg); + + while (arg) { + if (!strncmp(arg, "all", 3)) { + tdm_debug_dump = 0xFFFFFFFF; + goto done; + } else if (!strncmp(arg, "layer", 5)) { + tdm_debug_dump |= TDM_DUMP_FLAG_LAYER; + } else if (!strncmp(arg, "pp", 2)) { + tdm_debug_dump |= TDM_DUMP_FLAG_PP; + } else if (!strncmp(arg, "capture", 7)) { + tdm_debug_dump |= TDM_DUMP_FLAG_CAPTURE; + } else + goto done; + + arg = strtok_r(NULL, ",", &end); + } + + if (tdm_debug_dump_dir) + free(tdm_debug_dump_dir); + + tdm_debug_dump_dir = strndup(path, TDM_PATH_LEN); + + TDM_INFO("dump... '%s'", dump_str); + +done: + free(path); + return TDM_ERROR_NONE; +} + +INTERN tdm_error +tdm_display_enable_path(const char *path) +{ + static int old_stdout = -1; + char fd_name[TDM_PATH_LEN]; + int log_fd = -1; + FILE *log_fl; + + if (old_stdout == -1) + old_stdout = dup(STDOUT_FILENO); + + tdm_log_enable_dlog(0); + + snprintf(fd_name, TDM_PATH_LEN, "%s", path); + + log_fl = fopen(fd_name, "a"); + if (!log_fl) { + TDM_ERR("failed: open file(%s)\n", fd_name); + return TDM_ERROR_OPERATION_FAILED; + } + + fflush(stderr); + close(STDOUT_FILENO); + + setvbuf(log_fl, NULL, _IOLBF, 512); + log_fd = fileno(log_fl); + + dup2(log_fd, STDOUT_FILENO); + fclose(log_fl); + + return TDM_ERROR_NONE; +}