package version up to 1.16.13
[platform/core/uifw/libtdm.git] / src / tdm_backend.c
index 9c1992d..8be51f0 100644 (file)
@@ -9,7 +9,7 @@
  *          Taeheon Kim <th908.kim@samsung.com>,
  *          YoungJun Cho <yj44.cho@samsung.com>,
  *          SooChan Lim <sc1.lim@samsung.com>,
- *          Boram Park <sc1.lim@samsung.com>
+ *          Boram Park <boram1288.park@samsung.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
@@ -37,8 +37,6 @@
 #include "config.h"
 #endif
 
-#include "tdm.h"
-#include "tdm_backend.h"
 #include "tdm_private.h"
 
 #define BACKEND_FUNC_ENTRY() \
@@ -75,12 +73,14 @@ tdm_backend_register_func_display(tdm_display *dpy,
 
        TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_INVALID_PARAMETER);
 
+       assert(private_display->current_module);
+
        /* the ABI version of backend module should be more than 1.1 */
-       module = private_display->module_data;
+       module = private_display->current_module->module_data;
        if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       private_display->func_display = *func_display;
+       private_display->current_module->func_display = *func_display;
 
        return TDM_ERROR_NONE;
 }
@@ -96,12 +96,14 @@ tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
 
        TDM_RETURN_VAL_IF_FAIL(func_output != NULL, TDM_ERROR_INVALID_PARAMETER);
 
+       assert(private_display->current_module);
+
        /* the ABI version of backend module should be more than 1.1 */
-       module = private_display->module_data;
+       module = private_display->current_module->module_data;
        if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       private_display->func_output = *func_output;
+       private_display->current_module->func_output = *func_output;
 
        return TDM_ERROR_NONE;
 }
@@ -117,16 +119,19 @@ tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
 
        TDM_RETURN_VAL_IF_FAIL(func_layer != NULL, TDM_ERROR_INVALID_PARAMETER);
 
+       assert(private_display->current_module);
+
        /* the ABI version of backend module should be more than 1.1 */
-       module = private_display->module_data;
+       module = private_display->current_module->module_data;
        if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       private_display->func_layer = *func_layer;
+       private_display->current_module->func_layer = *func_layer;
 
        return TDM_ERROR_NONE;
 }
 
+/* LCOV_EXCL_START */
 EXTERN tdm_error
 tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func_hwc_window)
 {
@@ -138,14 +143,20 @@ tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func
 
        TDM_RETURN_VAL_IF_FAIL(func_hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER);
 
-       module = private_display->module_data;
-       if (_check_abi_version(module, 2, 0) < 0)
+       assert(private_display->current_module);
+
+       module = private_display->current_module->module_data;
+       /* FIX ME:
+                  Temporarily, we set the version of hwc window to 1.1 for the development.
+                  Originally the hwc window version is 2.0. */
+       if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       private_display->func_hwc_window = *func_hwc_window;
+       private_display->current_module->func_hwc_window = *func_hwc_window;
 
        return TDM_ERROR_NONE;
 }
+/* LCOV_EXCL_STOP */
 
 EXTERN tdm_error
 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
@@ -157,8 +168,15 @@ tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
        if (!func_pp)
                return TDM_ERROR_NONE;
 
-       private_display->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
-       private_display->func_pp = *func_pp;
+       assert(private_display->current_module);
+
+       private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
+       private_display->current_module->func_pp = *func_pp;
+
+       if (!private_display->pp_module)
+               private_display->pp_module = private_display->current_module;
+       else
+               TDM_ERR("already has pp backend(%s)", private_display->pp_module->module_data->name);
 
        return TDM_ERROR_NONE;
 }
@@ -174,12 +192,44 @@ tdm_backend_register_func_capture(tdm_display *dpy,
        if (!func_capture)
                return TDM_ERROR_NONE;
 
-       private_display->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
-       private_display->func_capture = *func_capture;
+       assert(private_display->current_module);
+
+       private_display->current_module->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
+       private_display->current_module->func_capture = *func_capture;
+
+       //TODO: remove later
+       if (!private_display->capture_module)
+               private_display->capture_module = private_display->current_module;
+       else
+               TDM_ERR("already has capture backend(%s)", private_display->capture_module->module_data->name);
 
        return TDM_ERROR_NONE;
 }
 
+/* LCOV_EXCL_START */
+/* backend operates itself types */
+static tdm_private_output*
+_look_for_frontend_hwc_output(tdm_output *backend_output)
+{
+       tdm_private_output *frontend_output = NULL, *o = NULL;
+       tdm_private_display *private_display = tdm_display_get();
+       tdm_private_module *private_module = NULL;
+
+       LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
+               LIST_FOR_EACH_ENTRY(o, &private_module->output_list, link) {
+                       if (!(o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC))
+                               continue;
+
+                       if (o->output_backend == backend_output) {
+                               frontend_output = o;
+                               return frontend_output;
+                       }
+               }
+       }
+
+       return NULL;
+}
+
 EXTERN tdm_error
 tdm_backend_trigger_need_validate_event(tdm_output *output)
 {
@@ -187,9 +237,9 @@ tdm_backend_trigger_need_validate_event(tdm_output *output)
        uint64_t value;
        int res;
 
-       TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
+       private_output = _look_for_frontend_hwc_output(output);
+       TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER);
 
-       private_output = (tdm_private_output*)output;
        value = 1;
 
        /* do not lock the global display lock here */
@@ -200,3 +250,4 @@ tdm_backend_trigger_need_validate_event(tdm_output *output)
 
        return TDM_ERROR_NONE;
 }
+/* LCOV_EXCL_STOP */