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;
47 int PUI_EVENT_ANI_FRAME_DONE = 0;
48 int PUI_EVENT_ANI_BUFFER_RELEASED = 0;
51 pui_error_to_string(pui_error e)
53 pui_error_string str = NULL;
61 case PUI_ERROR_INVALID_ANI_HANDLE:
62 str = "PUI_Invalid_Animation_Handle";
65 case PUI_ERROR_INVALID_ANI_CMD:
66 str = "PUI_Invalid_Animation_Command";
69 case PUI_ERROR_INTERNAL:
70 str = "PUI_Internal_Error";
74 str = "PUI_Unknown_Error";
81 pui_create(Ecore_Wl2_Window *win)
84 Ecore_Wl2_Display *ewd = ecore_wl2_window_display_get(win);
85 struct wayland_tbm_client *wl_tbm_client = NULL;
89 pui_err("Invalid window or display !\n");
93 wl_tbm_client = wayland_tbm_client_init(ecore_wl2_display_get(ewd));
97 pui_err("Failed to init wayland_tbm_client !\n");
101 handle = (pui_h)calloc(1, sizeof(pui));
108 handle->visibility = 0;
109 handle->wl_tbm_client = wl_tbm_client;
110 handle->ani_handles = NULL;
111 handle->backend_module_data = pui_module->backend_module_data;
113 handle->tbm_queue = wayland_tbm_client_create_surface_queue(handle->wl_tbm_client,
114 ecore_wl2_window_surface_get(handle->win),
115 2, 100, 100, TBM_FORMAT_ABGR8888);
117 if (!handle->tbm_queue)
119 pui_err("Failed to create a surface queue !");
132 pui_destroy(pui_h handle)
134 pui_ani_h ani_h = NULL;
139 EINA_LIST_FREE(handle->ani_handles, ani_h)
141 pui_ani_destroy(ani_h);
145 if (handle->tbm_queue)
147 tbm_surface_queue_destroy(handle->tbm_queue);
150 if (handle->wl_tbm_client)
152 wayland_tbm_client_deinit(handle->wl_tbm_client);
153 handle->wl_tbm_client = NULL;
159 #define PREFIX_LIB "libpui-"
160 #define SUFFIX_LIB ".so"
161 #define DEFAULT_LIB PREFIX_LIB"default-backend"SUFFIX_LIB
164 _pui_load_backend_module(void)
166 //char path[PATH_MAX] = {0, };
167 void *module_info = NULL;
168 pui_backend_module *backend_module_info = NULL;
169 int backend_module_major, backend_module_minor;
170 int pui_backend_major, pui_backend_minor;
172 pui_backend_module_data *backend_module_data = NULL;
175 module_info = dlopen(DEFAULT_LIB, RTLD_LAZY);
179 pui_err("Failed to dlopen(error:%s, path:%s) !\n", dlerror(), DEFAULT_LIB);
183 backend_module_info = dlsym(module_info, "pui_backend_module_info");
185 if (!backend_module_info) {
186 pui_err("Backend module(%s) doesn't have pui_backend_module_info !\n", DEFAULT_LIB);
190 pui_backend_major = PUI_BACKEND_GET_ABI_MAJOR(PUI_BACKEND_AB_VERSION_LAST);
191 pui_backend_minor = PUI_BACKEND_GET_ABI_MINOR(PUI_BACKEND_AB_VERSION_LAST);
193 backend_module_major = PUI_BACKEND_GET_ABI_MAJOR(backend_module_info->abi_version);
194 backend_module_minor = PUI_BACKEND_GET_ABI_MINOR(backend_module_info->abi_version);
196 if (backend_module_major > pui_backend_major) {
197 pui_err("PUI backend module ABI major ver(%d) is newer than the PUI's ver(%d)\n",
198 backend_module_major, pui_backend_major);
200 } else if (backend_module_minor > pui_backend_minor) {
201 pui_err("PUI backend module ABI minor ver(%d) is newer than the PUI's ver(%d)\n",
202 backend_module_minor, pui_backend_minor);
206 if (!backend_module_info->backend_init || !backend_module_info->backend_deinit)
208 pui_err("Backend module doesn't have backend_init/backend_deinit function !\n");
212 backend_module_data = backend_module_info->backend_init();
214 if (!backend_module_data)
216 pui_err("Failed to init module (%s) !\n", DEFAULT_LIB);
220 pui_module->module_info = module_info;
221 pui_module->backend_module_info = backend_module_info;
222 pui_module->backend_module_data = backend_module_data;
227 if (backend_module_info && backend_module_info->backend_init)
228 backend_module_info->backend_deinit(backend_module_data);
231 dlclose(module_info);
237 _pui_unload_backend_module(void)
241 pui_err("Invalid pui module !\n");
245 if (pui_module->backend_module_info)
247 pui_module->backend_module_info->backend_deinit(pui_module->backend_module_data);
248 pui_module->backend_module_data = NULL;
249 pui_module->backend_module_info = NULL;
252 if (pui_module->module_info)
253 dlclose(pui_module->module_info);
257 _pui_load_backend_collect_animations(void)
261 if (!pui_module || !pui_module->backend_module_data) {
262 pui_err("pui module data is not loaded\n");
266 ret = pui_module->backend_module_data->create_ani_collection();
267 if (ret != PUI_INT_ERROR_NONE) {
268 pui_err("Failed to collect animations data (%s)\n",
269 pui_error_to_string(ret));
276 _pui_load_backend_module();
277 _pui_load_backend_collect_animations();
283 _pui_unload_backend_module();
287 _pui_event_init(void)
289 PUI_EVENT_ANI_STARTED = ecore_event_type_new();
290 PUI_EVENT_ANI_STOPPED = ecore_event_type_new();
291 PUI_EVENT_ANI_PAUSED = ecore_event_type_new();
292 PUI_EVENT_ANI_READY_TO_START = ecore_event_type_new();
293 PUI_EVENT_ANI_READY_TO_RESUME = ecore_event_type_new();
294 PUI_EVENT_ANI_FRAME_DONE = ecore_event_type_new();
295 PUI_EVENT_ANI_BUFFER_RELEASED = ecore_event_type_new();
299 _pui_event_shutdown(void)
301 ecore_event_type_flush(PUI_EVENT_ANI_STARTED,
302 PUI_EVENT_ANI_STOPPED,
303 PUI_EVENT_ANI_PAUSED,
304 PUI_EVENT_ANI_READY_TO_START,
305 PUI_EVENT_ANI_READY_TO_RESUME,
306 PUI_EVENT_ANI_FRAME_DONE,
307 PUI_EVENT_ANI_BUFFER_RELEASED);
309 PUI_EVENT_ANI_STARTED = -1;
310 PUI_EVENT_ANI_STOPPED = -1;
311 PUI_EVENT_ANI_PAUSED = -1;
312 PUI_EVENT_ANI_READY_TO_START = -1;
313 PUI_EVENT_ANI_READY_TO_RESUME = -1;
314 PUI_EVENT_ANI_FRAME_DONE = -1;
315 PUI_EVENT_ANI_BUFFER_RELEASED = -1;
321 if (++_pui_init_count != 1)
322 return _pui_init_count;
326 pui_err("Invalid calling of pui_init() !\n");
330 pui_module = (pui_module_data *)calloc(1, sizeof(pui_module_data));
334 pui_err("Failed to allocate memory for pui module data !\n");
345 return _pui_init_count;
348 return --_pui_init_count;
354 if (_pui_init_count <= 0)
356 pui_err("Invalid pui init count : %d\n", _pui_init_count);
363 pui_err("Invalid pui module data !\n");
364 return _pui_init_count;
372 _pui_event_shutdown();
374 ecore_wl2_shutdown();
378 return _pui_init_count;