+EXTERN tdm_hwc_window *
+tdm_output_hwc_create_window(tdm_output *output, tdm_error *error)
+{
+ tdm_hwc_window *hwc_window = NULL;
+
+ OUTPUT_FUNC_ENTRY_ERROR();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
+ hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, 0, error);
+ else {
+ /* LCOV_EXCL_START */
+ TDM_ERR("output(%p) not support HWC", private_output);
+ if (error)
+ *error = TDM_ERROR_BAD_REQUEST;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return hwc_window;
+}
+
+EXTERN tdm_hwc_window *
+tdm_output_hwc_create_video_window(tdm_output *output, tdm_error *error)
+{
+ tdm_hwc_window *hwc_window = NULL;
+
+ OUTPUT_FUNC_ENTRY_ERROR();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)
+ hwc_window = (tdm_hwc_window *)tdm_hwc_window_create_internal(private_output, 1, error);
+ else {
+ /* LCOV_EXCL_START */
+ TDM_ERR("output(%p) not support HWC", private_output);
+ if (error)
+ *error = TDM_ERROR_BAD_REQUEST;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return hwc_window;
+}
+
+EXTERN tdm_error
+tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window)
+{
+ OUTPUT_FUNC_ENTRY();
+
+ TDM_RETURN_VAL_IF_FAIL(hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ ret = tdm_hwc_window_destroy_internal(hwc_window);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+EXTERN tdm_error
+tdm_output_hwc_validate(tdm_output *output, tdm_hwc_window **composited_wnds,
+ uint32_t num_wnds, uint32_t *num_types)
+{
+ tdm_func_output *func_output = NULL;
+ tdm_private_hwc_window **composited_wnds_frontend = NULL;
+ tdm_hwc_window **composited_wnds_backend = NULL;
+ int i;
+
+ OUTPUT_FUNC_ENTRY();
+
+ TDM_RETURN_VAL_IF_FAIL(num_types != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
+ TDM_ERR("output(%p) not support HWC", private_output);
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_BAD_REQUEST;
+ }
+
+ func_output = &private_display->func_output;
+
+ if (!func_output->output_hwc_validate) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (num_wnds == 0) {
+ ret = func_output->output_hwc_validate(private_output->output_backend, NULL, 0, num_types);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+ }
+
+ composited_wnds_backend = calloc(num_wnds, sizeof(tdm_hwc_window *));
+ if (!composited_wnds_backend) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+ composited_wnds_frontend = (tdm_private_hwc_window **)composited_wnds;
+
+ for (i = 0; i < num_wnds; i++)
+ composited_wnds_backend[i] = composited_wnds_frontend[i]->hwc_window_backend;
+
+ ret = func_output->output_hwc_validate(private_output->output_backend, composited_wnds_backend, num_wnds, num_types);
+
+ free(composited_wnds_backend);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+EXTERN tdm_error
+tdm_output_hwc_set_need_validate_handler(tdm_output *output,
+ tdm_output_need_validate_handler hndl)
+{
+ OUTPUT_FUNC_ENTRY();
+
+ TDM_RETURN_VAL_IF_FAIL(hndl != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
+ TDM_ERR("output(%p) not support HWC", private_output);
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_BAD_REQUEST;
+ }
+
+ /* there's no reason to allow this */
+ if (private_output->need_validate.hndl) {
+
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_OPERATION_FAILED;
+ }
+
+ private_output->need_validate.hndl = hndl;
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+EXTERN tdm_error
+tdm_output_hwc_get_changed_composition_types(tdm_output *output,
+ uint32_t *num_elements,
+ tdm_hwc_window **hwc_window,
+ tdm_hwc_window_composition *composition_types)
+{
+ tdm_func_output *func_output = NULL;
+ tdm_private_hwc_window * private_hwc_window = NULL;
+ int i = 0;
+
+ OUTPUT_FUNC_ENTRY();
+
+ TDM_RETURN_VAL_IF_FAIL(num_elements != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
+ TDM_ERR("output(%p) not support HWC", private_output);
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_BAD_REQUEST;
+ }
+
+ func_output = &private_display->func_output;
+
+ if (!func_output->output_hwc_get_changed_composition_types) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = func_output->output_hwc_get_changed_composition_types(private_output->output_backend,
+ num_elements, hwc_window, composition_types);
+ if (ret != TDM_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (hwc_window == NULL || composition_types == NULL) {
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_NONE;
+ }
+
+ for (i = 0; i < *num_elements; i++) {
+
+ private_hwc_window = _tdm_output_find_private_hwc_window(private_output, hwc_window[i]);
+
+ if (private_hwc_window == NULL) {
+ /* LCOV_EXCL_START */
+ TDM_ERR("failed! This should never happen!");
+ func_output->output_hwc_destroy_window(private_output->output_backend, hwc_window[i]);
+ *num_elements = 0;
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_OPERATION_FAILED;
+ /* LCOV_EXCL_STOP */
+ }
+
+ hwc_window[i] = (tdm_hwc_window*)private_hwc_window;
+ }
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+tdm_error
+tdm_output_hwc_accept_changes(tdm_output *output)
+{
+ tdm_func_output *func_output = NULL;
+
+ OUTPUT_FUNC_ENTRY();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
+ TDM_ERR("output(%p) not support HWC", private_output);
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_BAD_REQUEST;
+ }
+
+ func_output = &private_display->func_output;
+
+ if (!func_output->output_hwc_validate) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = func_output->output_hwc_accept_changes(private_output->output_backend);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+tbm_surface_queue_h
+tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error)
+{
+ tdm_func_output *func_output = NULL;
+ tbm_surface_queue_h queue = NULL;
+
+ OUTPUT_FUNC_ENTRY_ERROR();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
+ TDM_ERR("output(%p) not support HWC", private_output);
+ if (error)
+ *error = TDM_ERROR_BAD_REQUEST;
+ _pthread_mutex_unlock(&private_display->lock);
+ return NULL;
+ }
+
+ func_output = &private_display->func_output;
+
+ if (!func_output->output_hwc_get_target_buffer_queue) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ queue = func_output->output_hwc_get_target_buffer_queue(private_output->output_backend, error);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return queue;
+}
+
+EXTERN tdm_error
+tdm_output_hwc_set_client_target_buffer(tdm_output *output, tbm_surface_h target_buffer, tdm_hwc_region damage)
+{
+ tdm_func_output *func_output = NULL;
+
+ OUTPUT_FUNC_ENTRY();
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ if (!(private_output->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) {
+ TDM_ERR("output(%p) not support HWC", private_output);
+ _pthread_mutex_unlock(&private_display->lock);
+ return TDM_ERROR_BAD_REQUEST;
+ }
+
+ if (tdm_debug_dump & TDM_DUMP_FLAG_WINDOW) {
+ /* LCOV_EXCL_START */
+ char str[TDM_PATH_LEN];
+ static int i;
+ snprintf(str, TDM_PATH_LEN, "target_window_%d_%03d",
+ private_output->index, i++);
+ tdm_helper_dump_buffer_str(target_buffer, tdm_debug_dump_dir, str);
+ /* LCOV_EXCL_STOP */
+ }
+
+ func_output = &private_display->func_output;
+
+ if (!func_output->output_hwc_set_client_target_buffer) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = func_output->output_hwc_set_client_target_buffer(private_output->output_backend, target_buffer, damage);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+
+tdm_error
+tdm_output_hwc_get_video_supported_formats(tdm_output *output, const tbm_format **formats,
+ int *count)
+{
+ tdm_func_output *func_output;
+ OUTPUT_FUNC_ENTRY();
+
+ TDM_RETURN_VAL_IF_FAIL(formats != NULL, TDM_ERROR_INVALID_PARAMETER);
+ TDM_RETURN_VAL_IF_FAIL(count != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+ _pthread_mutex_lock(&private_display->lock);
+
+ func_output = &private_display->func_output;
+
+ if (!func_output->output_hwc_get_video_supported_formats) {
+ /* LCOV_EXCL_START */
+ _pthread_mutex_unlock(&private_display->lock);
+ TDM_ERR("not implemented!!");
+ return TDM_ERROR_NOT_IMPLEMENTED;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = func_output->output_hwc_get_video_supported_formats(
+ private_output->output_backend, formats, count);
+
+ _pthread_mutex_unlock(&private_display->lock);
+
+ return ret;
+}
+