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 = PTHREAD_MUTEX_INITIALIZER;
42 void _tbm_dummy_display_mutex_unlock(void);
44 struct _tbm_dummy_display {
45 struct list_head link;
49 _tbm_dummy_display_mutex_lock(void)
51 pthread_mutex_lock(&tbm_dummy_display_lock);
55 _tbm_dummy_display_mutex_unlock(void)
57 pthread_mutex_unlock(&tbm_dummy_display_lock);
61 _tbm_dummy_display_is_valid(struct _tbm_dummy_display *dummy_dpy)
63 struct _tbm_dummy_display *tmp_dpy = NULL;
66 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
70 if (!LIST_IS_EMPTY(&g_dummy_display_list)) {
71 LIST_FOR_EACH_ENTRY(tmp_dpy, &g_dummy_display_list, link) {
72 if (tmp_dpy == dummy_dpy) {
73 TBM_INFO("tbm_dummy_display(%p)\n", dummy_dpy);
79 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
85 tbm_dummy_display_create(void)
87 struct _tbm_dummy_display *dpy = NULL;
89 _tbm_dummy_display_mutex_lock();
90 _tbm_set_last_result(TBM_ERROR_NONE);
94 LIST_INITHEAD(&g_dummy_display_list);
98 dpy = calloc(1, sizeof(struct _tbm_dummy_display));
100 /* LCOV_EXCL_START */
101 TBM_ERR("fail to allocate struct _tbm_dummy_display.\n");
102 _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
103 _tbm_dummy_display_mutex_unlock();
108 LIST_ADD(&dpy->link, &g_dummy_display_list);
110 _tbm_dummy_display_mutex_unlock();
112 return (tbm_dummy_display *)dpy;
116 tbm_dummy_display_destroy(tbm_dummy_display *dpy)
118 struct _tbm_dummy_display *dummy_dpy = NULL;
120 _tbm_dummy_display_mutex_lock();
121 _tbm_set_last_result(TBM_ERROR_NONE);
123 dummy_dpy = (struct _tbm_dummy_display *)dpy;
125 if (!_tbm_dummy_display_is_valid(dummy_dpy)) {
126 _tbm_dummy_display_mutex_unlock();
130 LIST_DEL(&dummy_dpy->link);
134 _tbm_dummy_display_mutex_unlock();
138 tbm_dummy_display_is_valid(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 /* Return silently if dummy_display is null. */
150 _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER);
151 _tbm_dummy_display_mutex_unlock();
155 ret = _tbm_dummy_display_is_valid(dummy_dpy);
157 _tbm_dummy_display_mutex_unlock();