[hwc] use TDM_OUTPUT_CAPABILITY_HWC instead of TDM_DISPLAY_CAPABILITY_HWC
[platform/core/uifw/libtdm.git] / src / tdm_backend.c
index 8f34672..9c1992d 100644 (file)
@@ -1,36 +1,36 @@
 /**************************************************************************
-
-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
@@ -42,9 +42,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tdm_private.h"
 
 #define BACKEND_FUNC_ENTRY() \
-    tdm_private_display *private_display; \
-    TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_INVALID_PARAMETER); \
-    private_display = (tdm_private_display*)dpy;
+       tdm_private_display *private_display; \
+       TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_INVALID_PARAMETER); \
+       private_display = (tdm_private_display*)dpy;
 
 static int
 _check_abi_version(tdm_backend_module *module, int abimaj, int abimin)
@@ -53,22 +53,24 @@ _check_abi_version(tdm_backend_module *module, int abimaj, int abimin)
        int minor = TDM_BACKEND_GET_ABI_MINOR(module->abi_version);
 
        if (major < abimaj) goto failed;
-       if (major > abimaj) return 1;
+       if (major > abimaj) return 0;
        if (minor < abimin) goto failed;
-       return 1;
+       return 0;
 failed:
        TDM_ERR("The ABI version(%d.%d) of '%s' is less than %d.%d",
-               major, minor, module->name ? module->name : "unknown",
-               abimaj, abimin);
-       return 0;
+                       major, minor, module->name ? module->name : "unknown",
+                       abimaj, abimin);
+       return -1;
 }
 
 EXTERN tdm_error
 tdm_backend_register_func_display(tdm_display *dpy,
-                                  tdm_func_display *func_display)
+                                                                 tdm_func_display *func_display)
 {
        tdm_backend_module *module;
 
+       TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
        BACKEND_FUNC_ENTRY();
 
        TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_INVALID_PARAMETER);
@@ -78,9 +80,7 @@ tdm_backend_register_func_display(tdm_display *dpy,
        if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       pthread_mutex_lock(&private_display->lock);
        private_display->func_display = *func_display;
-       pthread_mutex_unlock(&private_display->lock);
 
        return TDM_ERROR_NONE;
 }
@@ -90,6 +90,8 @@ tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
 {
        tdm_backend_module *module;
 
+       TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
        BACKEND_FUNC_ENTRY();
 
        TDM_RETURN_VAL_IF_FAIL(func_output != NULL, TDM_ERROR_INVALID_PARAMETER);
@@ -99,9 +101,7 @@ tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
        if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       pthread_mutex_lock(&private_display->lock);
        private_display->func_output = *func_output;
-       pthread_mutex_unlock(&private_display->lock);
 
        return TDM_ERROR_NONE;
 }
@@ -111,6 +111,8 @@ tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
 {
        tdm_backend_module *module;
 
+       TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
        BACKEND_FUNC_ENTRY();
 
        TDM_RETURN_VAL_IF_FAIL(func_layer != NULL, TDM_ERROR_INVALID_PARAMETER);
@@ -120,9 +122,27 @@ tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
        if (_check_abi_version(module, 1, 1) < 0)
                return TDM_ERROR_BAD_MODULE;
 
-       pthread_mutex_lock(&private_display->lock);
        private_display->func_layer = *func_layer;
-       pthread_mutex_unlock(&private_display->lock);
+
+       return TDM_ERROR_NONE;
+}
+
+EXTERN tdm_error
+tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func_hwc_window)
+{
+       tdm_backend_module *module;
+
+       TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
+       BACKEND_FUNC_ENTRY();
+
+       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)
+               return TDM_ERROR_BAD_MODULE;
+
+       private_display->func_hwc_window = *func_hwc_window;
 
        return TDM_ERROR_NONE;
 }
@@ -130,33 +150,53 @@ tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
 EXTERN tdm_error
 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
 {
+       TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
        BACKEND_FUNC_ENTRY();
 
        if (!func_pp)
                return TDM_ERROR_NONE;
 
-       pthread_mutex_lock(&private_display->lock);
        private_display->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
        private_display->func_pp = *func_pp;
-       pthread_mutex_unlock(&private_display->lock);
 
        return TDM_ERROR_NONE;
 }
 
 EXTERN tdm_error
 tdm_backend_register_func_capture(tdm_display *dpy,
-                                  tdm_func_capture *func_capture)
+                                                                 tdm_func_capture *func_capture)
 {
+       TDM_RETURN_VAL_IF_FAIL(TDM_MUTEX_IS_LOCKED(), TDM_ERROR_OPERATION_FAILED);
+
        BACKEND_FUNC_ENTRY();
 
        if (!func_capture)
                return TDM_ERROR_NONE;
 
-       pthread_mutex_lock(&private_display->lock);
        private_display->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
        private_display->func_capture = *func_capture;
-       pthread_mutex_unlock(&private_display->lock);
 
        return TDM_ERROR_NONE;
 }
 
+EXTERN tdm_error
+tdm_backend_trigger_need_validate_event(tdm_output *output)
+{
+       tdm_private_output *private_output;
+       uint64_t value;
+       int res;
+
+       TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+       private_output = (tdm_private_output*)output;
+       value = 1;
+
+       /* do not lock the global display lock here */
+
+       res = write(private_output->need_validate.event_fd, &value, sizeof(value));
+       if (res < 0)
+               return TDM_ERROR_OPERATION_FAILED;
+
+       return TDM_ERROR_NONE;
+}