/**************************************************************************
-
-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 "config.h"
#endif
-#include "tdm.h"
-#include "tdm_backend.h"
#include "tdm_private.h"
-#include "tdm_helper.h"
pthread_mutex_t tdm_mutex_check_lock = PTHREAD_MUTEX_INITIALIZER;
int tdm_mutex_locked;
+const char *tdm_mutex_lock_func;
+int tdm_mutex_lock_line;
+const char *tdm_mutex_unlock_func;
+int tdm_mutex_unlock_line;
+/* LCOV_EXCL_START */
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;
return NULL;
}
-static tdm_private_output *
-_tdm_display_find_private_output(tdm_private_display *private_display,
- tdm_output *output_backend)
+INTERN tdm_private_output *
+tdm_display_find_private_output(tdm_private_display *private_display, 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)
+INTERN void *
+tdm_display_find_output_stamp(tdm_private_display *private_display, double stamp)
{
tdm_private_output *private_output = 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));
}
{
tdm_private_capture *c = NULL, *cc = NULL;
- LIST_DEL(&private_layer->link);
+ tdm_layer_unset_buffer_internal(private_layer);
LIST_FOR_EACH_ENTRY_SAFE(c, cc, &private_layer->capture_list, link)
tdm_capture_destroy_internal(c);
_tdm_display_destroy_caps_layer(&private_layer->caps);
+ /* when destroying layer, someone could check if layer is valid. So delete
+ * the layer's link at last.
+ */
+ LIST_DEL(&private_layer->link);
+
free(private_layer);
}
static void
_tdm_display_destroy_private_output(tdm_private_output *private_output)
{
+ tdm_private_display *private_display = private_output->private_display;
tdm_private_layer *l = NULL, *ll = NULL;
+ tdm_private_hwc_window *hw = NULL, *hww = NULL;
tdm_private_capture *c = NULL, *cc = NULL;
- tdm_private_vblank_handler *v = NULL, *vv = NULL;
- tdm_private_commit_handler *m = NULL, *mm = NULL;
- tdm_private_change_handler *h = NULL, *hh = NULL;
-
- LIST_DEL(&private_output->link);
+ tdm_private_output_vblank_handler *v = NULL, *vv = NULL;
+ tdm_private_output_commit_handler *om = NULL, *omm = NULL;
+ tdm_private_layer_commit_handler *lm = NULL, *lmm = NULL;
+ tdm_private_output_change_handler *h = NULL, *hh = NULL;
free(private_output->layers_ptr);
+ if (private_output->vblank_timeout_timer)
+ tdm_event_loop_source_remove(private_output->vblank_timeout_timer);
+
LIST_FOR_EACH_ENTRY_SAFE(v, vv, &private_output->vblank_handler_list, link) {
LIST_DEL(&v->link);
free(v);
}
- LIST_FOR_EACH_ENTRY_SAFE(m, mm, &private_output->commit_handler_list, link) {
- LIST_DEL(&m->link);
- free(m);
+ LIST_FOR_EACH_ENTRY_SAFE(om, omm, &private_output->output_commit_handler_list, link) {
+ LIST_DEL(&om->link);
+ free(om);
}
- 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(lm, lmm, &private_output->layer_commit_handler_list, link) {
+ LIST_DEL(&lm->link);
+ free(lm);
+ }
+
+ LIST_FOR_EACH_ENTRY_SAFE(lm, lmm, &private_output->pending_commit_handler_list, link) {
+ LIST_DEL(&lm->link);
+ free(lm);
}
- LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list_sub, link) {
+ LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_output->change_handler_list, link) {
LIST_DEL(&h->link);
+ tdm_thread_cb_remove(h->private_output, TDM_THREAD_CB_OUTPUT_CHANGE, NULL, tdm_output_thread_cb_change, h);
free(h);
}
+ if (private_output->vblank) {
+ /* tdm_vblank APIs is for server. it should be called in unlock status*/
+ _pthread_mutex_unlock(&private_display->lock);
+ tdm_vblank_destroy(private_output->vblank);
+ _pthread_mutex_lock(&private_display->lock);
+ }
+
+ if (private_output->ttrace_vblank) {
+ /* tdm_vblank APIs is for server. it should be called in unlock status*/
+ _pthread_mutex_unlock(&private_display->lock);
+ tdm_vblank_destroy(private_output->ttrace_vblank);
+ _pthread_mutex_lock(&private_display->lock);
+ }
+
LIST_FOR_EACH_ENTRY_SAFE(c, cc, &private_output->capture_list, link)
tdm_capture_destroy_internal(c);
+ LIST_FOR_EACH_ENTRY_SAFE(hw, hww, &private_output->hwc_window_list, link)
+ tdm_hwc_window_destroy_internal(hw);
+
LIST_FOR_EACH_ENTRY_SAFE(l, ll, &private_output->layer_list, link)
_tdm_display_destroy_private_layer(l);
_tdm_display_destroy_caps_output(&private_output->caps);
+ tdm_thread_cb_remove(private_output, TDM_THREAD_CB_NEED_VALIDATE, NULL,
+ tdm_output_need_validate_handler_thread, NULL);
+ tdm_event_loop_source_remove(private_output->need_validate.event_source);
+ close(private_output->need_validate.event_fd);
+
+ /* when destroying output, vblank objects are also destroyed. vblank checks
+ * if output object is valid. So delete the output's link at last.
+ */
+ LIST_DEL(&private_output->link);
+
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);
_tdm_display_destroy_caps_capture(&private_display->caps_capture);
private_display->capabilities = 0;
- private_display->caps_display.max_layer_count = -1;
+ private_display->caps_display.max_layer_count = 0;
}
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, 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;
+ double stamp;
if (!func_output->output_get_capability) {
TDM_ERR("no output_get_capability()");
return TDM_ERROR_BAD_MODULE;
}
+ stamp = tdm_helper_get_time();
ret = func_output->output_get_capability(output_backend, caps);
+ TDM_DBG("backend output_get_capability() time: %.3f ms", (tdm_helper_get_time() - stamp) * 1000.0);
+
if (ret != TDM_ERROR_NONE) {
TDM_ERR("output_get_capability() failed");
return TDM_ERROR_BAD_MODULE;
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;
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 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);
- private_output->stamp = tdm_helper_get_time_in_millis();
+ private_output->stamp = tdm_helper_get_time();
while (tdm_display_find_output_stamp(private_display, private_output->stamp))
private_output->stamp++;
- LIST_ADD(&private_output->link, &private_display->output_list);
+ 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->hwc_window_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_main);
- LIST_INITHEAD(&private_output->change_handler_list_sub);
+ LIST_INITHEAD(&private_output->output_commit_handler_list);
+ LIST_INITHEAD(&private_output->layer_commit_handler_list);
+ LIST_INITHEAD(&private_output->pending_commit_handler_list);
+ LIST_INITHEAD(&private_output->change_handler_list);
- 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);
+ if (ret != TDM_ERROR_NONE)
+ return ret;
+ } else {
+ tdm_caps_output new_caps;
- ret = _tdm_display_update_caps_output(private_display, pipe, output_backend,
- &private_output->caps);
- if (ret != TDM_ERROR_NONE)
- return ret;
+ ret = _tdm_display_update_caps_output(private_display, pipe, output_backend,
+ &new_caps);
+ if (ret != TDM_ERROR_NONE)
+ return ret;
+
+ /* FIXME: This is very ugly. need to fix after the TDM ABI is changed. */
+ if (private_output->caps.status != new_caps.status) {
+ _tdm_display_destroy_caps_output(&private_output->caps);
+ private_output->caps = new_caps;
+ private_output->current_mode = NULL;
+ } else {
+ tdm_output_mode *old_modes = private_output->caps.modes;
+ unsigned int old_mode_count = private_output->caps.mode_count;
+ if (new_caps.modes)
+ free(new_caps.modes);
+ new_caps.modes = old_modes;
+ new_caps.mode_count = old_mode_count;
+ if (private_output->caps.props)
+ free(private_output->caps.props);
+ private_output->caps = new_caps;
+ }
+ }
layers = func_output->output_get_layers(output_backend, &layer_count, &ret);
if (ret != TDM_ERROR_NONE)
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;
+ }
+ }
+
+ _tdm_display_destroy_caps_output(&caps);
+ }
+
+ /* 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);
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;
}
+/* LCOV_EXCL_STOP */
EXTERN tdm_error
tdm_display_update(tdm_display *dpy)
tdm_error ret;
TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(tdm_display_is_valid(dpy), TDM_ERROR_INVALID_PARAMETER);
private_display = dpy;
_pthread_mutex_lock(&private_display->lock);
}
#define SUFFIX_MODULE ".so"
-#define DEFAULT_MODULE "libtdm-default"SUFFIX_MODULE
+#define TDM_DEFAULT_MODULE "libtdm-default"SUFFIX_MODULE
+#define TDM_DUMMY_MODULE "libtdm-dummy"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;
+int tdm_ttrace_module;
+int tdm_ttrace_output;
static tdm_private_display *g_private_display;
static pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
+/* LCOV_EXCL_START */
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_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);
+ ret = func_display->display_get_capability(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_layer->layer_create_capture, TDM_ERROR_BAD_MODULE);
+ TDM_RETURN_VAL_IF_FAIL(func_display->display_get_capture_capability, TDM_ERROR_BAD_MODULE);
+ if (private_display->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT)
+ TDM_RETURN_VAL_IF_FAIL(func_output->output_create_capture, TDM_ERROR_BAD_MODULE);
+ if (private_display->caps_capture.capabilities & TDM_CAPTURE_CAPABILITY_LAYER)
+ 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,};
+ char path[TDM_PATH_LEN] = {0,};
tdm_backend_module *module_data;
void *module;
tdm_error ret;
+ double stamp;
+ int size;
- snprintf(path, sizeof(path), TDM_MODULE_PATH "/%s", file);
+ size = snprintf(path, sizeof(path), TDM_MODULE_PATH "/%s", file);
+ if (size >= (int)sizeof(path)) {
+ TDM_WRN("too long: %s/%s", TDM_MODULE_PATH, file);
+ return TDM_ERROR_BAD_MODULE;
+ };
- TDM_TRACE_BEGIN(Load_Backend);
+ stamp = tdm_helper_get_time();
+ TDM_TRACE_BEGIN("TDM_Load_Backend");
module = dlopen(path, RTLD_LAZY);
if (!module) {
TDM_ERR("failed to load module: %s(%s)", dlerror(), file);
TDM_TRACE_END();
goto failed_load;
}
+ TDM_TRACE_END();
+
+ TDM_DBG("dlopen, dlsym time: %.3f ms", (tdm_helper_get_time() - stamp) * 1000.0);
private_display->module_data = module_data;
private_display->module = module;
if (ret != TDM_ERROR_NONE)
goto failed_load;
- TDM_TRACE_END();
-
/* 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);
+ TDM_TRACE_BEGIN("TDM_Init_Backend");
+ stamp = tdm_helper_get_time();
+ private_display->bdata = module_data->init((tdm_display *)private_display, &ret);
+ TDM_DBG("backend init() time: %.3f ms", (tdm_helper_get_time() - stamp) * 1000.0);
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:
static tdm_error
_tdm_display_load_module(tdm_private_display *private_display)
{
- const char *module_name;
- struct dirent **namelist;
- int n;
+ const char *module_names;
tdm_error ret = 0;
+ char temp[TDM_PATH_LEN];
+ char *arg;
+ char *end;
- module_name = getenv("TDM_MODULE");
- if (!module_name)
- module_name = DEFAULT_MODULE;
+ module_names = tdm_config_get_string(TDM_CONFIG_KEY_GENERAL_BACKENDS, TDM_DEFAULT_MODULE);
- /* load bufmgr priv from default lib */
- ret = _tdm_display_load_module_with_file(private_display, module_name);
- if (ret == TDM_ERROR_NONE)
- return TDM_ERROR_NONE;
+ snprintf(temp, TDM_PATH_LEN, "%s", module_names);
- /* load bufmgr priv from configured path */
- n = scandir(TDM_MODULE_PATH, &namelist, 0, alphasort);
- if (n < 0) {
- TDM_ERR("no module in '%s'\n", TDM_MODULE_PATH);
- return TDM_ERROR_BAD_MODULE;
- }
-
- ret = TDM_ERROR_BAD_MODULE;
- while (n--) {
- if (ret < 0 && strstr(namelist[n]->d_name, SUFFIX_MODULE))
- ret = _tdm_display_load_module_with_file(private_display, namelist[n]->d_name);
+ arg = strtok_r(temp, TDM_CONFIG_DELIM, &end);
+ while (arg) {
+ ret = _tdm_display_load_module_with_file(private_display, arg);
+ if (ret == TDM_ERROR_NONE)
+ return TDM_ERROR_NONE;
- free(namelist[n]);
+ arg = strtok_r(NULL, TDM_CONFIG_DELIM, &end);
}
- free(namelist);
+
+ /* load bufmgr priv from dummy lib */
+ ret = _tdm_display_load_module_with_file(private_display, TDM_DUMMY_MODULE);
+ if (ret == TDM_ERROR_NONE)
+ return TDM_ERROR_NONE;
return ret;
}
private_display->module_data = NULL;
private_display->module = NULL;
}
+/* LCOV_EXCL_STOP */
EXTERN tdm_display *
tdm_display_init(tdm_error *error)
{
tdm_private_display *private_display = NULL;
- const char *debug;
+ const char *str;
tdm_error ret;
+ double stamp1, stamp2, start;
+ int mode;
- _pthread_mutex_lock(&gLock);
+ pthread_mutex_lock(&gLock);
if (g_private_display) {
g_private_display->init_count++;
- _pthread_mutex_unlock(&gLock);
+ pthread_mutex_unlock(&gLock);
if (error)
*error = TDM_ERROR_NONE;
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;
+ start = stamp1 = tdm_helper_get_time();
- debug = getenv("TDM_DEBUG_MUTEX");
- if (debug && (strstr(debug, "1")))
- tdm_debug_mutex = 1;
+ stamp2 = tdm_helper_get_time();
+ TDM_INFO("config init time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ stamp1 = stamp2;
private_display = calloc(1, sizeof(tdm_private_display));
if (!private_display) {
+ /* LCOV_EXCL_START */
ret = TDM_ERROR_OUT_OF_MEMORY;
TDM_ERR("'private_display != NULL' failed");
goto failed_alloc;
+ /* LCOV_EXCL_STOP */
}
+ private_display->stamp = tdm_helper_get_time();
+
+ str = tdm_config_get_string(TDM_CONFIG_KEY_DEBUG_MODULE, NULL);
+ if (str)
+ tdm_display_enable_debug_module(str);
+
+ str = tdm_config_get_string(TDM_CONFIG_KEY_DEBUG_DUMP, NULL);
+ if (str)
+ tdm_display_enable_dump(private_display, str, NULL, NULL);
+
if (pthread_mutex_init(&private_display->lock, NULL)) {
+ /* LCOV_EXCL_START */
ret = TDM_ERROR_OPERATION_FAILED;
TDM_ERR("mutex init failed: %m");
goto failed_mutex_init;
+ /* LCOV_EXCL_STOP */
}
_pthread_mutex_lock(&private_display->lock);
+ stamp2 = tdm_helper_get_time();
+ TDM_DBG("prepare init time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ stamp1 = stamp2;
+
+ ret = tdm_vblank_init(private_display);
+ if (ret != TDM_ERROR_NONE)
+ goto failed_vblank;
+
ret = tdm_event_loop_init(private_display);
if (ret != TDM_ERROR_NONE)
goto failed_event;
+ stamp2 = tdm_helper_get_time();
+ TDM_INFO("event loop init time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ stamp1 = stamp2;
+
+ ret = tdm_output_init(private_display);
+ if (ret != TDM_ERROR_NONE)
+ goto failed_load;
+
+ ret = tdm_pp_init(private_display);
+ if (ret != TDM_ERROR_NONE)
+ goto failed_load;
+
+ ret = tdm_capture_init(private_display);
+ if (ret != TDM_ERROR_NONE)
+ goto failed_load;
+
ret = _tdm_display_load_module(private_display);
if (ret != TDM_ERROR_NONE)
goto failed_load;
+ stamp2 = tdm_helper_get_time();
+ TDM_INFO("loading backend time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ stamp1 = stamp2;
+
#ifdef INIT_BUFMGR
int tdm_drm_fd = tdm_helper_get_fd("TDM_DRM_MASTER_FD");
if (tdm_drm_fd >= 0) {
} else {
TDM_INFO("tbm_bufmgr_init successed");
}
+
+ stamp2 = tdm_helper_get_time();
+ TDM_DBG("initializing bufmgr time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ stamp1 = stamp2;
}
#endif
- TDM_TRACE_BEGIN(Update_Display);
+ TDM_TRACE_BEGIN("TDM_Update_Display");
ret = _tdm_display_update_internal(private_display, 0);
TDM_TRACE_END();
if (ret != TDM_ERROR_NONE)
goto failed_update;
+ stamp2 = tdm_helper_get_time();
+ TDM_DBG("updating display time: %.3f ms", (stamp2 - stamp1) * 1000.0);
+ stamp1 = stamp2;
+
tdm_event_loop_create_backend_source(private_display);
private_display->init_count = 1;
-
g_private_display = private_display;
+ tdm_private_output *o = NULL;
+ LIST_FOR_EACH_ENTRY(o, &private_display->output_list, link) {
+ if (o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
+ tdm_output_need_validate_event_init(o);
+ }
+
+ /* the COMMIT_PER_VBLANK functionality is ability of an output to support
+ * several operational modes (commit_per_vblank modes) related to tdm_commit;
+ * this functionality can be turned off which means a default mode */
+ mode = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, 0);
+ if (mode > 0) {
+ tdm_private_output *o = NULL;
+
+ /* outputs which support hwc capability can work only
+ * if commit_per_vblank mode is '0' (default mode) */
+ LIST_FOR_EACH_ENTRY(o, &private_display->output_list, link)
+ if (!(o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC))
+ tdm_output_choose_commit_per_vblank_mode(o, mode);
+ }
+
if (error)
*error = TDM_ERROR_NONE;
_pthread_mutex_unlock(&private_display->lock);
- _pthread_mutex_unlock(&gLock);
+ pthread_mutex_unlock(&gLock);
+
+ TDM_INFO("init time: %.3f ms", (tdm_helper_get_time() - start) * 1000.0);
return (tdm_display *)private_display;
+/* LCOV_EXCL_START */
failed_update:
_tdm_display_unload_module(private_display);
failed_load:
+ tdm_event_loop_stop(private_display);
tdm_event_loop_deinit(private_display);
failed_event:
+ tdm_vblank_deinit(private_display);
+failed_vblank:
_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);
+ pthread_mutex_unlock(&gLock);
return NULL;
+/* LCOV_EXCL_STOP */
}
EXTERN void
if (!private_display)
return;
- _pthread_mutex_lock(&gLock);
+ TDM_RETURN_IF_FAIL(tdm_display_is_valid(dpy));
+
+ pthread_mutex_lock(&gLock);
private_display->init_count--;
if (private_display->init_count > 0) {
- _pthread_mutex_unlock(&gLock);
+ 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_stop(private_display);
tdm_event_loop_deinit(private_display);
+ _pthread_mutex_unlock(&private_display->lock);
+ /* when private_output is destroyed, all vblank resources of client and server
+ * are destroyed. Then we can call tdm_vblank_deinit. After destroying display,
+ * we can unload backend modulues.
+ */
_tdm_display_destroy_private_display(private_display);
_tdm_display_unload_module(private_display);
+ tdm_vblank_deinit(private_display);
+
#ifdef INIT_BUFMGR
if (private_display->bufmgr)
tbm_bufmgr_deinit(private_display->bufmgr);
#endif
- tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1);
-
- _pthread_mutex_unlock(&private_display->lock);
+ tbm_drm_helper_unset_tbm_master_fd();
pthread_mutex_destroy(&private_display->lock);
free(private_display);
g_private_display = NULL;
- tdm_debug = 0;
- tdm_debug_buffer = 0;
- _pthread_mutex_unlock(&gLock);
+ if (tdm_debug_dump_dir) {
+ free(tdm_debug_dump_dir);
+ tdm_debug_dump_dir = NULL;
+ }
+
+ tdm_config_deinit();
+
+ pthread_mutex_unlock(&gLock);
TDM_INFO("done");
}
+INTERN tdm_private_display *
+tdm_display_get(void)
+{
+ return g_private_display;
+}
+
+INTERN int
+tdm_display_is_valid(tdm_display *dpy)
+{
+ if (dpy != NULL && dpy == g_private_display)
+ return 1;
+ return 0;
+}
+
+INTERN int
+tdm_output_is_valid(tdm_output *output)
+{
+ tdm_private_output *o = NULL, *private_output = output;
+ if (output && g_private_display)
+ LIST_FOR_EACH_ENTRY(o, &g_private_display->output_list, link)
+ if (o == private_output)
+ return 1;
+ return 0;
+}
+
+/* LCOV_EXCL_START */
+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_CONFIG_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, "event", 5))
+ tdm_debug_module |= TDM_DEBUG_EVENT;
+ 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 if (!strncmp(arg, "commit", 6))
+ tdm_debug_module |= TDM_DEBUG_COMMIT;
+
+ arg = strtok_r(NULL, TDM_CONFIG_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 = NULL, *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++;
+
+ 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;
+ TDM_SNPRINTF(reply, len, "path: %s\n", (tdm_debug_dump_dir) ? : "unknown");
+ if (tdm_debug_dump_dir) {
+ free(tdm_debug_dump_dir);
+ tdm_debug_dump_dir = NULL;
+ }
+ goto done;
+ }
+
+ path = tdm_helper_dump_make_directory(path2, reply, len);
+ TDM_GOTO_IF_FAIL(path != NULL, 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 || l->caps.capabilities & TDM_LAYER_CAPABILITY_VIDEO)
+ continue;
+ if (!l->showing_buffer)
+ continue;
+ snprintf(str, TDM_PATH_LEN, "layer_%d_%d", o->index, l->index);
+ tdm_helper_dump_buffer_str(l->showing_buffer->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 if (!strncmp(arg, "window", 6)) {
+ tdm_debug_dump |= TDM_DUMP_FLAG_WINDOW;
+ } 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:
+ if (path)
+ free(path);
+
+ return TDM_ERROR_NONE;
+}
+
+static void
+_tdm_display_ttrace_vblank_cb(tdm_vblank *vblank, tdm_error error, unsigned int sequence,
+ unsigned int tv_sec, unsigned int tv_usec, void *user_data)
+{
+ tdm_error ret = TDM_ERROR_NONE;
+
+ TDM_TRACE_MARK("VSYNC");
+
+ ret = tdm_vblank_wait(vblank, 0, 0, 1, _tdm_display_ttrace_vblank_cb, NULL);
+ TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+}
+
+INTERN tdm_error
+tdm_display_enable_ttrace_vblank(tdm_display *dpy, tdm_output *output, int enable)
+{
+ tdm_private_display *private_display = dpy;
+ tdm_private_output *private_output = NULL;
+ const tdm_output_mode *mode = NULL;
+ tdm_vblank *vblank = NULL;
+ tdm_error ret = TDM_ERROR_NONE;
+
+ if (!enable) {
+ LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
+ if (private_output->ttrace_vblank)
+ tdm_vblank_destroy(private_output->ttrace_vblank);
+ private_output->ttrace_vblank = NULL;
+ }
+ return TDM_ERROR_NONE;
+ }
+
+ private_output = output;
+ TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ if (private_output->ttrace_vblank)
+ return TDM_ERROR_NONE;
+
+ vblank = tdm_vblank_create(private_display, output, &ret);
+ TDM_RETURN_VAL_IF_FAIL(vblank != NULL, ret);
+
+ ret = tdm_output_get_mode(output, &mode);
+ TDM_GOTO_IF_FAIL(mode != NULL, enable_fail);
+
+ ret = tdm_vblank_set_fps(vblank, mode->vrefresh);
+ TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, enable_fail);
+
+ ret = tdm_vblank_set_enable_fake(vblank, 1);
+ TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, enable_fail);
+
+ ret = tdm_vblank_wait(vblank, 0, 0, 1, _tdm_display_ttrace_vblank_cb, NULL);
+ TDM_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, enable_fail);
+
+ private_output->ttrace_vblank = vblank;
+
+ return TDM_ERROR_NONE;
+
+enable_fail:
+ if (vblank)
+ tdm_vblank_destroy(vblank);
+
+ return ret;
+}
+
+INTERN tdm_error
+tdm_display_enable_ttrace(tdm_private_display *private_display, const char *ttrace, int output_id, char *reply, int *len)
+{
+ char temp[TDM_PATH_LEN];
+ char *arg;
+ char *end;
+ tdm_output *output;
+ tdm_error ret;
+ tdm_output_type type;
+
+ snprintf(temp, TDM_PATH_LEN, "%s", ttrace);
+
+ tdm_ttrace_output = output_id;
+ tdm_ttrace_module = 0;
+
+ output = tdm_display_get_output(private_display, output_id, &ret);
+ if (!output) {
+ TDM_SNPRINTF(reply, len, "can't find the output_id(%d)\n", output_id);
+ return ret;
+ }
+
+ ret = tdm_output_get_output_type(output, &type);
+ if (ret != TDM_ERROR_NONE) {
+ TDM_SNPRINTF(reply, len, "can't find the type of output_id(%d)\n", output_id);
+ return ret;
+ }
+
+ arg = strtok_r(temp, TDM_CONFIG_DELIM, &end);
+ while (arg) {
+ if (!strncmp(arg, "none", 4))
+ tdm_ttrace_module = 0;
+ else if (!strncmp(arg, "all", 3))
+ tdm_ttrace_module = 0xFFFFFFFF;
+ else if (!strncmp(arg, "vsync", 5))
+ tdm_ttrace_module |= TDM_TTRACE_VSYNC;
+ else if (!strncmp(arg, "client_vblank", 13))
+ tdm_ttrace_module |= TDM_TTRACE_CLIENT_VBLANK;
+ else if (!strncmp(arg, "server_vblank", 13))
+ tdm_ttrace_module |= TDM_TTRACE_SERVER_VBLANK;
+ else if (!strncmp(arg, "vblank", 6))
+ tdm_ttrace_module |= TDM_TTRACE_VBLANK;
+ else if (!strncmp(arg, "layer", 5))
+ tdm_ttrace_module |= TDM_TTRACE_LAYER;
+ else if (!strncmp(arg, "pp", 2))
+ tdm_ttrace_module |= TDM_TTRACE_PP;
+ else if (!strncmp(arg, "capture", 7))
+ tdm_ttrace_module |= TDM_TTRACE_CAPTURE;
+ else {
+ tdm_ttrace_module = 0;
+ tdm_display_enable_ttrace_vblank(private_display, NULL, 0);
+ tdm_server_enable_ttrace_client_vblank(private_display, NULL, 0);
+ TDM_SNPRINTF(reply, len, "unknown option: '%s'\n", arg);
+ return TDM_ERROR_NONE;
+ }
+
+ arg = strtok_r(NULL, TDM_CONFIG_DELIM, &end);
+ }
+
+ TDM_SNPRINTF(reply, len, "ttrace debugging... '%s' %x\n", ttrace, tdm_ttrace_module);
+
+ if (tdm_ttrace_module & TDM_TTRACE_VSYNC)
+ tdm_display_enable_ttrace_vblank(private_display, output, 1);
+ else
+ tdm_display_enable_ttrace_vblank(private_display, NULL, 0);
+
+ if (tdm_ttrace_module & TDM_TTRACE_CLIENT_VBLANK)
+ tdm_server_enable_ttrace_client_vblank(private_display, output, 1);
+ else
+ tdm_server_enable_ttrace_client_vblank(private_display, NULL, 0);
+
+ return TDM_ERROR_NONE;
+}
+
+INTERN tdm_error
+tdm_display_enable_fps(tdm_private_display *private_display, int enable)
+{
+ private_display->print_fps = enable;
+
+ TDM_INFO("print fps: %s", (enable) ? "enable" : "disable");
+
+ return TDM_ERROR_NONE;
+}
+/* LCOV_EXCL_STOP */