1 /**************************************************************************
5 Copyright 2018 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>,
8 Changyeon Lee <cyeon.lee@samsung.com>,
9 Sangjin Lee <lsj119@samsung.com>
11 Permission is hereby granted, free of charge, to any person obtaining a
12 copy of this software and associated documentation files (the
13 "Software"), to deal in the Software without restriction, including
14 without limitation the rights to use, copy, modify, merge, publish,
15 distribute, sub license, and/or sell copies of the Software, and to
16 permit persons to whom the Software is furnished to do so, subject to
17 the following conditions:
19 The above copyright notice and this permission notice (including the
20 next paragraph) shall be included in all copies or substantial portions
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
26 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 **************************************************************************/
33 #include "tbm_dummy_display.h"
34 #include "tbm_bufmgr_int.h"
39 static int init_list = 0;
40 static struct list_head g_dummy_display_list;
41 static pthread_mutex_t tbm_dummy_display_lock;
42 void _tbm_dummy_display_mutex_unlock(void);
44 struct _tbm_dummy_display {
45 struct list_head link;
49 _tbm_dummy_display_mutex_init(void)
51 static bool tbm_dummy_display_mutex_init = false;
53 if (tbm_dummy_display_mutex_init)
56 if (pthread_mutex_init(&tbm_dummy_display_lock, NULL)) {
57 TBM_ERR("fail: pthread_mutex_init for tbm_dummy_display_lock.\n");
61 tbm_dummy_display_mutex_init = true;
67 _tbm_dummy_display_mutex_lock(void)
69 if (!_tbm_dummy_display_mutex_init()) {
70 TBM_ERR("fail: _tbm_dummy_display_mutex_init.\n");
74 pthread_mutex_lock(&tbm_dummy_display_lock);
78 _tbm_dummy_display_mutex_unlock(void)
80 pthread_mutex_unlock(&tbm_dummy_display_lock);
84 _tbm_dummy_display_is_valid(struct _tbm_dummy_display *dummy_dpy)
86 struct _tbm_dummy_display *tmp_dpy = NULL;
89 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
93 if (!LIST_IS_EMPTY(&g_dummy_display_list)) {
94 LIST_FOR_EACH_ENTRY(tmp_dpy, &g_dummy_display_list, link) {
95 if (tmp_dpy == dummy_dpy) {
96 TBM_INFO("tbm_dummy_display(%p)\n", dummy_dpy);
102 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
108 tbm_dummy_display_create(void)
110 struct _tbm_dummy_display *dpy = NULL;
112 _tbm_dummy_display_mutex_lock();
113 _tbm_set_last_result(TBM_ERROR_NONE);
117 LIST_INITHEAD(&g_dummy_display_list);
121 dpy = calloc(1, sizeof(struct _tbm_dummy_display));
123 /* LCOV_EXCL_START */
124 TBM_ERR("fail to allocate struct _tbm_dummy_display.\n");
125 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
126 _tbm_dummy_display_mutex_unlock();
131 LIST_ADD(&dpy->link, &g_dummy_display_list);
133 _tbm_dummy_display_mutex_unlock();
135 return (tbm_dummy_display *)dpy;
139 tbm_dummy_display_destroy(tbm_dummy_display *dpy)
141 struct _tbm_dummy_display *dummy_dpy = NULL;
143 _tbm_dummy_display_mutex_lock();
144 _tbm_set_last_result(TBM_ERROR_NONE);
146 dummy_dpy = (struct _tbm_dummy_display *)dpy;
148 if (!_tbm_dummy_display_is_valid(dummy_dpy)) {
149 _tbm_dummy_display_mutex_unlock();
153 LIST_DEL(&dummy_dpy->link);
157 _tbm_dummy_display_mutex_unlock();
161 tbm_dummy_display_is_valid(tbm_dummy_display *dpy)
164 struct _tbm_dummy_display *dummy_dpy = NULL;
166 _tbm_dummy_display_mutex_lock();
167 _tbm_set_last_result(TBM_ERROR_NONE);
169 dummy_dpy = (struct _tbm_dummy_display *)dpy;
171 /* Return silently if dummy_display is null. */
173 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
174 _tbm_dummy_display_mutex_unlock();
178 ret = _tbm_dummy_display_is_valid(dummy_dpy);
180 _tbm_dummy_display_mutex_unlock();