/**************************************************************************
-
-libtdm
-
-Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: Eunchul Kim <chulspro.kim@samsung.com>,
- JinYoung Jeon <jy0.jeon@samsung.com>,
- Taeheon Kim <th908.kim@samsung.com>,
- YoungJun Cho <yj44.cho@samsung.com>,
- SooChan Lim <sc1.lim@samsung.com>,
- Boram Park <sc1.lim@samsung.com>
-
-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 <chulspro.kim@samsung.com>,
+ * JinYoung Jeon <jy0.jeon@samsung.com>,
+ * Taeheon Kim <th908.kim@samsung.com>,
+ * YoungJun Cho <yj44.cho@samsung.com>,
+ * SooChan Lim <sc1.lim@samsung.com>,
+ * Boram Park <sc1.lim@samsung.com>
+ *
+ * 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
#include "tdm_private.h"
#include "tdm_helper.h"
+pthread_mutex_t tdm_mutex_check_lock = PTHREAD_MUTEX_INITIALIZER;
+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;
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;
return NULL;
}
+INTERN tdm_private_output *
+tdm_display_find_output_stamp(tdm_private_display *private_display,
+ unsigned long stamp)
+{
+ tdm_private_output *private_output = NULL;
+
+ LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
+ if (private_output->stamp == stamp)
+ return private_output;
+ }
+
+ return NULL;
+}
+
static void
_tdm_display_destroy_caps_pp(tdm_caps_pp *caps_pp)
{
- free(caps_pp->formats);
+ if (caps_pp->formats)
+ free(caps_pp->formats);
+
memset(caps_pp, 0, sizeof(tdm_caps_pp));
}
static void
_tdm_display_destroy_caps_capture(tdm_caps_capture *caps_capture)
{
- free(caps_capture->formats);
+ if (caps_capture->formats)
+ free(caps_capture->formats);
+
memset(caps_capture, 0, sizeof(tdm_caps_capture));
}
static void
_tdm_display_destroy_caps_layer(tdm_caps_layer *caps_layer)
{
- free(caps_layer->formats);
- free(caps_layer->props);
+ if (caps_layer->formats)
+ free(caps_layer->formats);
+
+ if (caps_layer->props)
+ free(caps_layer->props);
+
memset(caps_layer, 0, sizeof(tdm_caps_layer));
}
static void
_tdm_display_destroy_caps_output(tdm_caps_output *caps_output)
{
- free(caps_output->modes);
- free(caps_output->props);
+ if (caps_output->modes)
+ free(caps_output->modes);
+
+ if (caps_output->props)
+ free(caps_output->props);
+
memset(caps_output, 0, sizeof(tdm_caps_output));
}
free(m);
}
- LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list, link) {
+ LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_main, link) {
+ LIST_DEL(&h->link);
+ free(h);
+ }
+
+ LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_sub, link) {
LIST_DEL(&h->link);
free(h);
}
_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);
}
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);
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))
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))
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) {
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,
- tdm_output *output_backend, tdm_caps_output *caps)
+_tdm_display_update_caps_output(tdm_private_display *private_display, int pipe,
+ tdm_output *output_backend, tdm_caps_output *caps)
{
tdm_func_output *func_output = &private_display->func_output;
- int i;
+ char temp[TDM_NAME_LEN];
tdm_error ret;
if (!func_output->output_get_capability) {
return TDM_ERROR_BAD_MODULE;
}
- 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);
+ /* FIXME: Use model for tdm client to distinguish amoung outputs */
+ snprintf(temp, TDM_NAME_LEN, "%s-%d", caps->model, pipe);
+ snprintf(caps->model, TDM_NAME_LEN, "%s", temp);
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;
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;
_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;
return ret;
}
-static void
-_tdm_output_cb_status(tdm_output *output, tdm_output_conn_status status,
- void *user_data)
-{
- tdm_private_output *private_output = user_data;
- tdm_value value;
-
- TDM_RETURN_IF_FAIL(private_output);
-
- value.u32 = status;
- tdm_output_call_change_handler_internal(private_output,
- TDM_OUTPUT_CHANGE_CONNECTION,
- value);
-}
-
-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;
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);
- LIST_ADD(&private_output->link, &private_display->output_list);
+ private_output->stamp = tdm_helper_get_time_in_millis();
+ while (tdm_display_find_output_stamp(private_display, private_output->stamp))
+ private_output->stamp++;
+
+ LIST_ADDTAIL(&private_output->link, &private_display->output_list);
+
private_output->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);
LIST_INITHEAD(&private_output->vblank_handler_list);
LIST_INITHEAD(&private_output->commit_handler_list);
- LIST_INITHEAD(&private_output->change_handler_list);
+ LIST_INITHEAD(&private_output->change_handler_list_main);
+ LIST_INITHEAD(&private_output->change_handler_list_sub);
if (func_output->output_set_status_handler) {
+ func_output->output_set_status_handler(private_output->output_backend,
+ tdm_output_cb_status,
+ private_output);
private_output->regist_change_cb = 1;
- ret = func_output->output_set_status_handler(output_backend,
- _tdm_output_cb_status,
- private_output);
- if (ret != TDM_ERROR_NONE)
- goto failed_update;
}
+
} else
_tdm_display_destroy_caps_output(&private_output->caps);
- ret = _tdm_display_update_caps_output(private_display, output_backend,
- &private_output->caps);
+ ret = _tdm_display_update_caps_output(private_display, pipe, output_backend,
+ &private_output->caps);
if (ret != TDM_ERROR_NONE)
return ret;
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;
}
return ret;
}
+static tdm_output **
+_tdm_display_set_main_first(tdm_output **outputs, int index)
+{
+ tdm_output *output_tmp = NULL;
+
+ if (index == 0)
+ return outputs;
+
+ output_tmp = outputs[0];
+ outputs[0] = outputs[index];
+ outputs[index] = output_tmp;
+
+ return outputs;
+}
+
+static tdm_output **
+_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;
+ tdm_output **new_outputs = NULL;
+ tdm_output *output_dsi = NULL;
+ tdm_output *output_lvds = NULL;
+ tdm_output *output_hdmia = NULL;
+ tdm_output *output_hdmib = NULL;
+ int i, output_count = 0, output_connected_count = 0;
+ int index_dsi = 0, index_lvds = 0, index_hdmia = 0, index_hdmib = 0;
+ tdm_error 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;
+
+ *count = output_count;
+
+ if (output_count == 0)
+ goto failed_get_outputs;
+ else if (output_count == 1) {
+ private_display->outputs = outputs;
+ return outputs;
+ }
+
+ /* count connected outputs */
+ for (i = 0; i < output_count; i++) {
+ tdm_func_output *func_output = &private_display->func_output;
+ tdm_caps_output caps;
+ memset(&caps, 0, sizeof(tdm_caps_output));
+
+ if (!func_output->output_get_capability) {
+ TDM_ERR("no output_get_capability()");
+ goto failed_get_outputs;
+ }
+
+ ret = func_output->output_get_capability(outputs[i], &caps);
+ if (ret != TDM_ERROR_NONE) {
+ TDM_ERR("output_get_capability() failed");
+ goto failed_get_outputs;
+ }
+
+ if (caps.status == TDM_OUTPUT_CONN_STATUS_CONNECTED) {
+ output_connected_count++;
+
+ switch (caps.type) {
+ case TDM_OUTPUT_TYPE_DSI:
+ output_dsi = outputs[i];
+ index_dsi = i;
+ break;
+ case TDM_OUTPUT_TYPE_LVDS:
+ output_lvds = outputs[i];
+ index_lvds = i;
+ break;
+ case TDM_OUTPUT_TYPE_HDMIA:
+ output_hdmia = outputs[i];
+ index_hdmia = i;
+ break;
+ case TDM_OUTPUT_TYPE_HDMIB:
+ output_hdmib = outputs[i];
+ index_hdmib = i;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ /* ordering : main output is first */
+ /* If there is no connected output, lvds or dsi cannot be main display. (cannot connect after booting)
+ * But hdmi is possible, so set hdmi to main display.
+ * If connected only one output, it is main output.
+ * If connected outputs over 2, has priority like below.
+ * (dsi > lvds > hdmi > else)
+ */
+ if (output_connected_count == 0) {
+ /* hdmi > dsi > lvds > else */
+ if (output_hdmia != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_hdmia);
+ else if (output_hdmib != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_hdmib);
+ else if (output_dsi != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_dsi);
+ else if (output_lvds != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_lvds);
+ else
+ new_outputs = outputs;
+ } else { /* (output_connected_count > 1) */
+ /* dsi > lvds > hdmi > else */
+ if (output_dsi != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_dsi);
+ else if (output_lvds != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_lvds);
+ else if (output_hdmia != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_hdmia);
+ else if (output_hdmib != NULL)
+ new_outputs = _tdm_display_set_main_first(outputs, index_hdmib);
+ else
+ 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_func_display *func_display = &private_display->func_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);
+ LIST_INITHEAD(&private_display->capture_list);
if (!only_display) {
ret = _tdm_display_update_caps_pp(private_display, &private_display->caps_pp);
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 = func_display->display_get_outputs(private_display->bdata,
- &output_count, &ret);
- if (ret != TDM_ERROR_NONE)
+ 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;
}
#define SUFFIX_MODULE ".so"
#define DEFAULT_MODULE "libtdm-default"SUFFIX_MODULE
-int tdm_debug;
-int tdm_debug_buffer;
-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;
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;
}
/* 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);
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;
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;
/* 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;
}
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:
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_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;
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");
goto failed_mutex_init;
}
- ret = tdm_event_init(private_display);
+ _pthread_mutex_lock(&private_display->lock);
+
+ ret = tdm_event_loop_init(private_display);
if (ret != TDM_ERROR_NONE)
- goto failed_load;
+ goto failed_event;
ret = _tdm_display_load_module(private_display);
if (ret != TDM_ERROR_NONE)
goto failed_load;
+#ifdef INIT_BUFMGR
+ int tdm_drm_fd = tdm_helper_get_fd("TDM_DRM_MASTER_FD");
+ if (tdm_drm_fd >= 0) {
+ private_display->bufmgr = tbm_bufmgr_init(tdm_drm_fd);
+ close(tdm_drm_fd);
+ if (!private_display->bufmgr) {
+ TDM_ERR("tbm_bufmgr_init failed");
+ goto failed_update;
+ } else {
+ TDM_INFO("tbm_bufmgr_init successed");
+ }
+ }
+#endif
+
TDM_TRACE_BEGIN(Update_Display);
ret = _tdm_display_update_internal(private_display, 0);
TDM_TRACE_END();
if (ret != TDM_ERROR_NONE)
goto failed_update;
- tdm_event_create_main_source(private_display);
+ tdm_event_loop_create_backend_source(private_display);
private_display->init_count = 1;
if (error)
*error = TDM_ERROR_NONE;
+ _pthread_mutex_unlock(&private_display->lock);
_pthread_mutex_unlock(&gLock);
return (tdm_display *)private_display;
failed_update:
_tdm_display_unload_module(private_display);
failed_load:
+ tdm_event_loop_deinit(private_display);
+failed_event:
+ _pthread_mutex_unlock(&private_display->lock);
pthread_mutex_destroy(&private_display->lock);
failed_mutex_init:
free(private_display);
failed_alloc:
- tdm_debug = 0;
- tdm_debug_buffer = 0;
if (error)
*error = ret;
_pthread_mutex_unlock(&gLock);
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);
- tdm_event_deinit(private_display);
- tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1);
+#ifdef INIT_BUFMGR
+ if (private_display->bufmgr)
+ tbm_bufmgr_deinit(private_display->bufmgr);
+#endif
- _pthread_mutex_unlock(&private_display->lock);
+ tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1);
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;
+}