2 * Copyright © 2019 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "PUI_internal.h"
27 #include "PUI_backend.h"
30 #include <wayland-tbm-client.h>
31 #include <tbm_surface_internal.h>
35 #ifndef PUI_MODULE_DIR
36 #define PUI_MODULE_DIR "/usr/lib"
39 static int _pui_init_count = 0;
40 static pui_module_data *pui_module = NULL;
42 int PUI_EVENT_ANI_STARTED = 0;
43 int PUI_EVENT_ANI_STOPPED = 0;
44 int PUI_EVENT_ANI_PAUSED = 0;
45 int PUI_EVENT_ANI_READY_TO_START = 0;
46 int PUI_EVENT_ANI_READY_TO_RESUME = 0;
49 pui_error_to_string(pui_error e)
51 pui_error_string str = NULL;
59 case PUI_ERROR_INVALID_ANI_HANDLE:
60 str = "PUI_Invalid_Animation_Handle";
63 case PUI_ERROR_INVALID_ANI_CMD:
64 str = "PUI_Invalid_Animation_Command";
67 case PUI_ERROR_INTERNAL:
68 str = "PUI_Internal_Error";
72 str = "PUI_Unknown_Error";
79 pui_create(Ecore_Wl2_Window *win)
82 Ecore_Wl2_Display *ewd = ecore_wl2_window_display_get(win);
83 struct wayland_tbm_client *wl_tbm_client = NULL;
87 pui_err("Invalid window or display !\n");
91 wl_tbm_client = wayland_tbm_client_init(ecore_wl2_display_get(ewd));
95 pui_err("Failed to init wayland_tbm_client !\n");
99 handle = (pui_h)calloc(1, sizeof(pui));
106 handle->visibility = 0;
107 handle->wl_tbm_client = wl_tbm_client;
108 handle->ani_handles = NULL;
109 handle->current_ani_h = NULL;
110 handle->backend_module_data = pui_module->backend_module_data;
112 handle->tbm_queue = wayland_tbm_client_create_surface_queue(handle->wl_tbm_client,
113 ecore_wl2_window_surface_get(handle->win),
114 3, 100, 100, TBM_FORMAT_ABGR8888);
116 if (!handle->tbm_queue)
118 pui_err("Failed to create a surface queue !");
131 pui_destroy(pui_h handle)
133 pui_ani_h ani_h = NULL;
138 EINA_LIST_FREE(handle->ani_handles, ani_h)
140 pui_ani_destroy(ani_h);
144 if (handle->tbm_queue)
146 tbm_surface_queue_destroy(handle->tbm_queue);
149 if (handle->wl_tbm_client)
151 wayland_tbm_client_deinit(handle->wl_tbm_client);
152 handle->wl_tbm_client = NULL;
158 #define PREFIX_LIB "libpui-"
159 #define SUFFIX_LIB ".so"
160 #define DEFAULT_LIB PREFIX_LIB"default-backend"SUFFIX_LIB
163 _pui_load_backend_module(void)
165 //char path[PATH_MAX] = {0, };
166 void *module_info = NULL;
167 pui_backend_module *backend_module_info = NULL;
168 int backend_module_major, backend_module_minor;
169 int pui_backend_major, pui_backend_minor;
171 pui_backend_module_data *backend_module_data = NULL;
174 module_info = dlopen(DEFAULT_LIB, RTLD_LAZY);
178 pui_err("Failed to dlopen(error:%s, path:%s) !\n", dlerror(), DEFAULT_LIB);
182 backend_module_info = dlsym(module_info, "pui_backend_module_info");
184 if (!backend_module_info) {
185 pui_err("Backend module(%s) doesn't have pui_backend_module_info !\n", DEFAULT_LIB);
189 pui_backend_major = PUI_BACKEND_GET_ABI_MAJOR(PUI_BACKEND_AB_VERSION_LAST);
190 pui_backend_minor = PUI_BACKEND_GET_ABI_MINOR(PUI_BACKEND_AB_VERSION_LAST);
192 backend_module_major = PUI_BACKEND_GET_ABI_MAJOR(backend_module_info->abi_version);
193 backend_module_minor = PUI_BACKEND_GET_ABI_MINOR(backend_module_info->abi_version);
195 if (backend_module_major > pui_backend_major) {
196 pui_err("PUI backend module ABI major ver(%d) is newer than the PUI's ver(%d)\n",
197 backend_module_major, pui_backend_major);
199 } else if (backend_module_minor > pui_backend_minor) {
200 pui_err("PUI backend module ABI minor ver(%d) is newer than the PUI's ver(%d)\n",
201 backend_module_minor, pui_backend_minor);
205 if (!backend_module_info->backend_init || !backend_module_info->backend_deinit)
207 pui_err("Backend module doesn't have backend_init/backend_deinit function !\n");
211 backend_module_data = backend_module_info->backend_init();
213 if (!backend_module_data)
215 pui_err("Failed to init module (%s) !\n", DEFAULT_LIB);
219 pui_module->module_info = module_info;
220 pui_module->backend_module_info = backend_module_info;
221 pui_module->backend_module_data = backend_module_data;
226 if (backend_module_info && backend_module_info->backend_init)
227 backend_module_info->backend_deinit(backend_module_data);
230 dlclose(module_info);
236 _pui_unload_backend_module(void)
240 pui_err("Invalid pui module !\n");
244 if (pui_module->backend_module_info)
246 pui_module->backend_module_info->backend_deinit(pui_module->backend_module_data);
247 pui_module->backend_module_data = NULL;
248 pui_module->backend_module_info = NULL;
251 if (pui_module->module_info)
252 dlclose(pui_module->module_info);
256 _pui_load_backend_collect_animations(void)
260 if (!pui_module || !pui_module->backend_module_data) {
261 pui_err("pui module data is not loaded\n");
265 ret = pui_module->backend_module_data->create_ani_collection();
266 if (ret != PUI_INT_ERROR_NONE) {
267 pui_err("Failed to collect animations data (%s)\n",
268 pui_error_to_string(ret));
275 _pui_load_backend_module();
276 _pui_load_backend_collect_animations();
282 _pui_unload_backend_module();
286 _pui_event_init(void)
288 PUI_EVENT_ANI_STARTED = ecore_event_type_new();
289 PUI_EVENT_ANI_STOPPED = ecore_event_type_new();
290 PUI_EVENT_ANI_PAUSED = ecore_event_type_new();
291 PUI_EVENT_ANI_READY_TO_START = ecore_event_type_new();
292 PUI_EVENT_ANI_READY_TO_RESUME = ecore_event_type_new();
296 _pui_event_shutdown(void)
298 ecore_event_type_flush(PUI_EVENT_ANI_STARTED,
299 PUI_EVENT_ANI_STOPPED,
300 PUI_EVENT_ANI_PAUSED,
301 PUI_EVENT_ANI_READY_TO_START,
302 PUI_EVENT_ANI_READY_TO_RESUME);
304 PUI_EVENT_ANI_STARTED = -1;
305 PUI_EVENT_ANI_STOPPED = -1;
306 PUI_EVENT_ANI_PAUSED = -1;
307 PUI_EVENT_ANI_READY_TO_START = -1;
308 PUI_EVENT_ANI_READY_TO_RESUME = -1;
314 if (++_pui_init_count != 1)
315 return _pui_init_count;
319 pui_err("Invalid calling of pui_init() !\n");
323 pui_module = (pui_module_data *)calloc(1, sizeof(pui_module_data));
327 pui_err("Failed to allocate memory for pui module data !\n");
338 return _pui_init_count;
341 return --_pui_init_count;
347 if (_pui_init_count <= 0)
349 pui_err("Invalid pui init count : %d\n", _pui_init_count);
356 pui_err("Invalid pui module data !\n");
357 return _pui_init_count;
365 _pui_event_shutdown();
367 ecore_wl2_shutdown();
371 return _pui_init_count;