add tbm_dummy_display 33/181633/6
authorSooChan Lim <sc1.lim@samsung.com>
Fri, 15 Jun 2018 07:35:51 +0000 (16:35 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Mon, 18 Jun 2018 04:37:09 +0000 (13:37 +0900)
This tbm_dummy_display is just void pointer managed by tbm.
This pointer is used when the user get the EGLDisplay for the offscreen rendering.
Therefore when the user wants to use the offscreen rendering, it use this
tbm_dummy_display handle as the native_display argument of the EGLGetDisplay().

Change-Id: Icece26c0a35c98da7b9e826a3d541b7eb45e0034

include/Makefile.am
include/tbm_dummy_display.h [new file with mode: 0644]
src/Makefile.am
src/tbm_dummy_display.c [new file with mode: 0644]

index 255ec9c..5455209 100644 (file)
@@ -12,4 +12,5 @@ libtbminclude_HEADERS = \
                                                tbm_sync.h \
                                                tbm_drm_helper.h \
                                                tbm_bufmgr_backend.h \
-                                               tbm_backend.h
+                                               tbm_backend.h \
+                                               tbm_dummy_display.h
diff --git a/include/tbm_dummy_display.h b/include/tbm_dummy_display.h
new file mode 100644 (file)
index 0000000..d404e18
--- /dev/null
@@ -0,0 +1,77 @@
+/**************************************************************************
+
+libtbm
+
+Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>,
+                Changyeon Lee <cyeon.lee@samsung.com>,
+                Sangjin Lee <lsj119@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.
+
+**************************************************************************/
+
+#ifndef _TBM_DUMMY_DISPLAY_H_
+#define _TBM_DUMMY_DISPLAY_H_
+
+/**
+ * \file tbm_dummy_display.h
+ * \brief TBM dummy display
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Definition for dummy display
+ */
+typedef void tbm_dummy_display;
+
+/**
+ * @brief Create the dummy display.
+ * @details The dummy display usually is used by the native_display for the parameger of the eglGetDisplay()\n
+ * The user uses the dummy display as the native_display for calling eglGetDisplay() when the user want to \n
+ * get EGLDisplay for the offscreen rendering in Tizen.
+ * \n
+ * @return a tbm dummy display
+ * @retval #tbm_dummy_display
+ */
+tbm_dummy_display *tbm_dummy_display_create(void);
+
+/**
+ * @brief Destroy the dummy display.
+ * @param[in] dpy : the tbm dummy display
+ */
+void               tbm_dummy_display_destroy(tbm_dummy_display *dpy);
+
+/**
+ * @brief Validate the dummy display.
+ * @param[in] dpy : the tbm dummy display
+ * @return 1 if this dpy is valid, otherwise 0.
+ */
+int                tbm_dummy_display_is_valid(tbm_dummy_display *dpy);
+
+#ifdef __cplusplus
+}
+#endif
+#endif                                                 /* _TBM_DUMMY_DISPLAY_H_ */
index 0ab96ac..bdc188f 100644 (file)
@@ -26,7 +26,8 @@ libtbm_la_SOURCES = \
        tbm_sync.c \
        tbm_log.c \
        tbm_error.c \
-       tbm_backend.c
+       tbm_backend.c \
+       tbm_dummy_display.c
 
 nodist_libtbm_la_SOURCES =             \
        wayland-tbm-drm-auth-server-protocol.h  \
diff --git a/src/tbm_dummy_display.c b/src/tbm_dummy_display.c
new file mode 100644 (file)
index 0000000..6bce30c
--- /dev/null
@@ -0,0 +1,185 @@
+/**************************************************************************
+
+libtbm
+
+Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>,
+                Changyeon Lee <cyeon.lee@samsung.com>,
+                Sangjin Lee <lsj119@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.
+
+**************************************************************************/
+#include "config.h"
+#include "tbm_dummy_display.h"
+#include "tbm_bufmgr_int.h"
+#include "list.h"
+
+/* LCOV_EXCL_START */
+
+static int init_list = 0;
+static struct list_head g_dummy_display_list;
+static pthread_mutex_t tbm_dummy_display_lock;
+void _tbm_dummy_display_mutex_unlock(void);
+
+struct _tbm_dummy_display {
+       struct list_head link;
+};
+
+static bool
+_tbm_dummy_display_mutex_init(void)
+{
+       static bool tbm_dummy_display_mutex_init = false;
+
+       if (tbm_dummy_display_mutex_init)
+               return true;
+
+       if (pthread_mutex_init(&tbm_dummy_display_lock, NULL)) {
+               TBM_ERR("fail: pthread_mutex_init for tbm_dummy_display_lock.\n");
+               return false;
+       }
+
+       tbm_dummy_display_mutex_init = true;
+
+       return true;
+}
+
+void
+_tbm_dummy_display_mutex_lock(void)
+{
+       if (!_tbm_dummy_display_mutex_init()) {
+               TBM_ERR("fail: _tbm_dummy_display_mutex_init.\n");
+               return;
+       }
+
+       pthread_mutex_lock(&tbm_dummy_display_lock);
+}
+
+void
+_tbm_dummy_display_mutex_unlock(void)
+{
+       pthread_mutex_unlock(&tbm_dummy_display_lock);
+}
+
+static int
+_tbm_dummy_display_is_valid(struct _tbm_dummy_display *dummy_dpy)
+{
+       struct _tbm_dummy_display *tmp_dpy = NULL;
+
+       if (!init_list) {
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+               return 0;
+       }
+
+       if (!LIST_IS_EMPTY(&g_dummy_display_list)) {
+               LIST_FOR_EACH_ENTRY(tmp_dpy, &g_dummy_display_list, link) {
+                       if (tmp_dpy == dummy_dpy) {
+                               TBM_INFO("tbm_dummy_display(%p)\n", dummy_dpy);
+                               return 1;
+                       }
+               }
+       }
+
+       _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+
+       return 0;
+}
+
+tbm_dummy_display *
+tbm_dummy_display_create(void)
+{
+       struct _tbm_dummy_display *dpy = NULL;
+
+       _tbm_dummy_display_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       /* init list */
+       if (!init_list) {
+               LIST_INITHEAD(&g_dummy_display_list);
+               init_list = 1;
+       }
+
+       dpy = calloc(1, sizeof(struct _tbm_dummy_display));
+       if (!dpy) {
+               /* LCOV_EXCL_START */
+               TBM_ERR("fail to allocate struct _tbm_dummy_display.\n");
+               _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+               _tbm_dummy_display_mutex_unlock();
+               return NULL;
+               /* LCOV_EXCL_STOP */
+       }
+
+       LIST_ADD(&dpy->link, &g_dummy_display_list);
+
+       _tbm_dummy_display_mutex_unlock();
+
+       return (tbm_dummy_display *)dpy;
+}
+
+void
+tbm_dummy_display_destroy(tbm_dummy_display *dpy)
+{
+       struct _tbm_dummy_display *dummy_dpy = NULL;
+
+       _tbm_dummy_display_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       dummy_dpy = (struct _tbm_dummy_display *)dpy;
+
+       if (!_tbm_dummy_display_is_valid(dummy_dpy)) {
+               _tbm_dummy_display_mutex_unlock();
+               return;
+       }
+
+       LIST_DEL(&dummy_dpy->link);
+
+       free(dummy_dpy);
+
+       _tbm_dummy_display_mutex_unlock();
+}
+
+int
+tbm_dummy_display_is_valid(tbm_dummy_display *dpy)
+{
+       int ret = 0;
+       struct _tbm_dummy_display *dummy_dpy = NULL;
+
+       _tbm_dummy_display_mutex_lock();
+       _tbm_set_last_result(TBM_ERROR_NONE);
+
+       dummy_dpy = (struct _tbm_dummy_display *)dpy;
+
+       /* Return silently if dummy_display is null. */
+       if (!dummy_dpy) {
+               _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
+               _tbm_dummy_display_mutex_unlock();
+               return 0;
+       }
+
+       ret = _tbm_dummy_display_is_valid(dummy_dpy);
+
+       _tbm_dummy_display_mutex_unlock();
+
+       return ret;
+}
+
+/* LCOV_EXCL_STOP */