+/**************************************************************************
+ *
+ * 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"
+
+#define COUNT_MAX 10
+
+#define HWC_WINDOW_FUNC_ENTRY() \
+ tdm_private_display *private_display; \
+ tdm_private_output *private_output; \
+ tdm_private_hwc_window *private_hwc_window; \
+ tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
+ TDM_RETURN_VAL_IF_FAIL(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER); \
+ private_hwc_window = (tdm_private_hwc_window*)hwc_window; \
+ private_output = private_hwc_window->private_output; \
+ private_display = private_output->private_display
+
+#define HWC_WINDOW_FUNC_ENTRY_ERROR() \
+ tdm_private_display *private_display; \
+ tdm_private_output *private_output; \
+ tdm_private_hwc_window *private_hwc_window; \
+ tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
+ TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER, NULL); \
+ private_hwc_window = (tdm_private_hwc_window*)hwc_window; \
+ private_output = private_hwc_window->private_output; \
+ private_display = private_output->private_display
+
+#define HWC_WINDOW_FUNC_ENTRY_VOID_RETURN() \
+ tdm_private_display *private_display; \
+ tdm_private_output *private_output; \
+ tdm_private_hwc_window *private_hwc_window; \
+ tdm_error ret = TDM_ERROR_NONE; /* default TDM_ERROR_NONE */\
+ TDM_RETURN_IF_FAIL(hwc_window != NULL); \
+ private_hwc_window = (tdm_private_hwc_window*)hwc_window; \
+ private_output = private_hwc_window->private_output; \
+ private_display = private_output->private_display
+
+tbm_surface_queue_h
+tdm_hwc_window_get_tbm_surface_queue(tdm_hwc_window *hwc_window, tdm_error *error)
+{
+ tdm_func_hwc_window *func_hwc_window = NULL;
+ tbm_surface_queue_h queue = NULL;
+
+ HWC_WINDOW_FUNC_ENTRY_ERROR();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ func_hwc_window = &private_display->func_hwc_window;
+
+ if (!func_hwc_window->hwc_window_get_tbm_surface_queue) {
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ *error = TDM_ERROR_NOT_IMPLEMENTED;
+ return NULL;
+ }
+
+ queue = func_hwc_window->hwc_window_get_tbm_surface_queue(private_hwc_window->hwc_window_backend, error);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return queue;
+}
+
+EXTERN tdm_error
+tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, uint32_t zpos)
+{
+ tdm_func_hwc_window *func_hwc_window = NULL;
+
+ HWC_WINDOW_FUNC_ENTRY();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ func_hwc_window = &private_display->func_hwc_window;
+
+ if (!func_hwc_window->hwc_window_set_zpos) {
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ }
+
+ ret = func_hwc_window->hwc_window_set_zpos(private_hwc_window->hwc_window_backend, zpos);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+EXTERN tdm_error
+tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
+ tdm_hwc_window_composition_t composition_type)
+{
+ tdm_func_hwc_window *func_hwc_window = NULL;
+
+ HWC_WINDOW_FUNC_ENTRY();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ func_hwc_window = &private_display->func_hwc_window;
+
+ if (!func_hwc_window->hwc_window_set_composition_type) {
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ }
+
+ ret = func_hwc_window->hwc_window_set_composition_type(private_hwc_window->hwc_window_backend, composition_type);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+EXTERN tdm_error
+tdm_hwc_window_set_surface_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage)
+{
+ tdm_func_hwc_window *func_hwc_window = NULL;
+
+ HWC_WINDOW_FUNC_ENTRY();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ func_hwc_window = &private_display->func_hwc_window;
+
+ if (!func_hwc_window->hwc_window_set_surface_damage) {
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ }
+
+ ret = func_hwc_window->hwc_window_set_surface_damage(private_hwc_window->hwc_window_backend, damage);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+
+EXTERN tdm_error
+tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info)
+{
+ tdm_func_hwc_window *func_hwc_window = NULL;
+ char fmtstr[128];
+
+ HWC_WINDOW_FUNC_ENTRY();
+
+ TDM_RETURN_VAL_IF_FAIL(info != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ func_hwc_window = &private_display->func_hwc_window;
+
+ if (!func_hwc_window->hwc_window_set_info) {
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ }
+
+ if (info->src_config.format)
+ snprintf(fmtstr, 128, "%c%c%c%c", FOURCC_STR(info->src_config.format));
+ else
+ snprintf(fmtstr, 128, "NONE");
+
+ TDM_INFO("hwc_window(%p) info: src(%dx%d %d,%d %dx%d %s) dst(%d,%d %dx%d) trans(%d)",
+ private_hwc_window, info->src_config.size.h, info->src_config.size.v,
+ info->src_config.pos.x, info->src_config.pos.y,
+ info->src_config.pos.w, info->src_config.pos.h,
+ fmtstr,
+ info->dst_pos.x, info->dst_pos.y,
+ info->dst_pos.w, info->dst_pos.h,
+ info->transform);
+
+ ret = func_hwc_window->hwc_window_set_info(private_hwc_window->hwc_window_backend, info);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+EXTERN tdm_error
+tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer)
+{
+ tdm_func_hwc_window *func_hwc_window;
+
+ HWC_WINDOW_FUNC_ENTRY();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+
+ func_hwc_window = &private_display->func_hwc_window;
+
+ if (!func_hwc_window->hwc_window_set_buffer) {
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ }
+
+ ret = func_hwc_window->hwc_window_set_buffer(private_hwc_window->hwc_window_backend, buffer);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+INTERN tdm_hwc_window *
+tdm_hwc_window_create_internal(tdm_private_output *private_output,
+ tdm_error *error)
+{
+ tdm_private_display *private_display = private_output->private_display;
+ tdm_func_output *func_output = &private_display->func_output;
+ tdm_private_hwc_window *private_hwc_window = NULL;
+ tdm_hwc_window *hwc_window_backend = NULL;
+ tdm_error ret = TDM_ERROR_NONE;
+
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), NULL);
+
+ hwc_window_backend = func_output->output_create_hwc_window(
+ private_output->output_backend, &ret);
+ if (ret != TDM_ERROR_NONE) {
+ if (error)
+ *error = ret;
+ return NULL;
+ }
+
+ private_hwc_window = calloc(1, sizeof(tdm_private_capture));
+ if (!private_hwc_window) {
+ TDM_ERR("failed: alloc memory");
+ func_output->output_destroy_hwc_window(private_output->output_backend, hwc_window_backend);
+ if (error)
+ *error = TDM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ LIST_ADD(&private_hwc_window->link, &private_output->hwc_window_list);
+
+ private_hwc_window->private_display = private_display;
+ private_hwc_window->private_output = private_output;
+ private_hwc_window->hwc_window_backend = hwc_window_backend;
+
+ TDM_DBG("hwc_window(%p) create", private_hwc_window);
+
+ if (error)
+ *error = TDM_ERROR_NONE;
+
+ return private_hwc_window;
+}
+
+INTERN tdm_error
+tdm_hwc_window_destroy_internal(tdm_private_hwc_window * private_hwc_window)
+{
+ tdm_private_display *private_display;
+ tdm_private_output *private_output;
+ tdm_func_output *func_output;
+
+ TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
+ if (!private_hwc_window)
+ return TDM_ERROR_OPERATION_FAILED;
+
+ private_display = private_hwc_window->private_display;
+ private_output = private_hwc_window->private_output;
+
+ LIST_DEL(&private_hwc_window->link);
+
+ func_output = &private_display->func_output;
+ func_output->output_destroy_hwc_window(private_output->output_backend, private_hwc_window->hwc_window_backend);
+
+ free(private_hwc_window);
+ return TDM_ERROR_NONE;
+}