-#include "PUI.h"
+/*
+ * Copyright © 2019 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * 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, sublicense, 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
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * 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 "PUI_internal.h"
#include "PUI_backend.h"
+#include "PUI.h"
+
+#include <wayland-tbm-client.h>
+#include <tbm_surface_internal.h>
+#include <stdio.h>
+#include <dlfcn.h>
#ifndef PUI_MODULE_DIR
#define PUI_MODULE_DIR "/usr/lib"
#endif
-#define pui_err(msg, ...) \
- do { \
- fprintf(stderr, "[ERROR][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
- } while(0)
+static int _pui_init_count = 0;
+static pui_module_data *pui_module = NULL;
-#define pui_warn(msg, ...) \
- do { \
- fprintf(stderr, "[WARNING][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
- } while(0)
+int PUI_EVENT_ANI_STARTED = 0;
+int PUI_EVENT_ANI_STOPPED = 0;
+int PUI_EVENT_ANI_PAUSED = 0;
+int PUI_EVENT_ANI_READY_TO_START = 0;
+int PUI_EVENT_ANI_READY_TO_RESUME = 0;
-#define pui_info(msg, ...) \
- do { \
- fprintf(stdout, "[INFO][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
- } while(0)
+static int KEY_WL_BUFFER = 0xabcdbeaf;
+static int KEY_CLIENT = 0xdcbabeaf;
-static int _pui_init_count = 0;
-static pui_module_data *pui_module = NUJLL;
+static const char *
+_pui_magic_string_get(PUI_Magic m)
+{
+ switch (m)
+ {
+ case PUI_MAGIC_NONE:
+ return "None (Freed Object)";
+ break;
-EAPI int PUI_EVENT_ANI_STARTED = 0;
-EAPI int PUI_EVENT_ANI_STOPPED = 0;
-EAPI int PUI_EVENT_ANI_PAUSED = 0;
-EAPI int PUI_EVENT_ANI_READY_TO_START = 0;
-EAPI int PUI_EVENT_ANI_READY_TO_RESUME = 0;
-EAPI int PUI_EVENT_ANI_FRAME_DONE = 0;
-EAPI int PUI_EVENT_ANI_BUFFER_RELEASED = 0;
+ case PUI_MAGIC_PUI_M:
+ return "PUI MODULE (PUI_M)";
+ break;
+
+ case PUI_MAGIC_PUI_H:
+ return "PUI HANDLE (PUI_H)";
+ break;
+
+ case PUI_MAGIC_ANI_H:
+ return "PUI ANI HANDLE (ANI_H)";
+ break;
+
+ case PUI_MAGIC_ANI_T:
+ return "PUI ANI RUNTIME HANDLE (ANI_T)";
+ break;
+
+ default:
+ return "<Unknown>";
+ }
+}
+
+PUI_API void
+_pui_magic_fail(const void *p, PUI_Magic m, PUI_Magic req_m, const char *fname)
+{
+ pui_err(" ### PUI ERROR : PUI Magic Check Failed !!! in %s().\n", fname);
+
+ if (!p)
+ pui_err(" Given handle/pointer is NULL !\n");
+ else if (m == PUI_MAGIC_NONE)
+ pui_err(" Given handle/pointer has been freed !\n");
+ else if (m != req_m)
+ pui_err(" Given handle/pointer is wrong type\n"
+ " Expected: %08x - %s\n"
+ " Supplied: %08x - %s",
+ (unsigned int)req_m, _pui_magic_string_get(req_m),
+ (unsigned int)m, _pui_magic_string_get(m));
+
+ /* abort here as a failure of magic can be caused by a memory corruption */
+ pui_err("### PUI MAGIC FAILED ! Abort ! ###\n");
+ abort();
+}
-const pui_error_string
+pui_error_string
pui_error_to_string(pui_error e)
{
- const pui_error_string str = NULL;
+ pui_error_string str = NULL;
switch (e)
{
str = "PUI_Invalid_Animation_Command";
break;
- case PUI_ERROR_INVALID_ANI_OPT:
- str = "PUI_Invalid_Animation_Option";
- break;
-
case PUI_ERROR_INTERNAL:
str = "PUI_Internal_Error";
break;
+ case PUI_ERROR_MANUAL_RENDER_ENABLED:
+ str = "PUI_Manual_Render_Enabled";
+ break;
+
+ case PUI_ERROR_UNABLE_SET_MANUAL_RENDER:
+ str = "PUI_Unable_To_Set_Manual_Render";
+ break;
+
default:
str = "PUI_Unknown_Error";
}
}
static void
-_pui_cb_frame(Ecore_Wl2_Window *win, uint32_t timestamp EINA_UNUSED, void *data)
+_buffer_release(void *data, struct wl_buffer *buffer)
{
- pui_h handle = (pui_h) data;
+ tbm_surface_h surface = (tbm_surface_h)data;
+ pui_h handle;
- TRACE("Frame done ! (window=%p)\n", win);
+ tbm_surface_internal_get_user_data(surface, (unsigned long)&KEY_CLIENT, (void **)&handle);
+ tbm_surface_queue_release(handle->tbm_queue, surface);
- // TODO
+ pui_info("[UPDATE] release wl_buffer:%p, surface:%p\n", buffer, surface);
+}
- return;
+static const struct wl_buffer_listener buffer_listener = {
+ _buffer_release
+};
+
+pui_ani_control_buffer *
+pui_display_get_last_buffer(pui_h handle)
+{
+ tbm_surface_error_e ret;
+ tbm_surface_h surface;
+ pui_ani_control_buffer *buffer = NULL;
+
+ if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+ {
+ PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+ return NULL;
+ }
+
+ if (handle->current_sinfo.size <= 0)
+ {
+ pui_err("Failed to get last buffer which is not set\n");
+ return buffer;
+ }
+
+ buffer = (pui_ani_control_buffer *)&(handle->current_sinfo.planes[0].ptr);
+
+ return buffer;
+}
+
+
+pui_ani_control_buffer *
+pui_display_get_buffer(pui_h handle)
+{
+ tbm_surface_error_e ret;
+ tbm_surface_h surface;
+ pui_ani_control_buffer *buffer = NULL;
+
+ if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+ {
+ PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+ return NULL;
+ }
+
+ if (handle->current_surface)
+ {
+ pui_debug("[GET BUFFER] Current_surface is not used !\n");
+ }
+
+ if (!tbm_surface_queue_can_dequeue(handle->tbm_queue, 0))
+ {
+ pui_err("[GET BUFFER] Failed to dequeue a tbm_surface !\n");
+ return NULL;
+ }
+
+ ret = tbm_surface_queue_dequeue(handle->tbm_queue, &surface);
+
+ if (ret != TBM_SURFACE_ERROR_NONE)
+ {
+ pui_err("[GET BUFFER] Dequeue err:%d\n", ret);
+ return NULL;
+ }
+
+ tbm_surface_map(surface, TBM_SURF_OPTION_READ | TBM_SURF_OPTION_WRITE, &handle->current_sinfo);
+
+ handle->current_surface = surface;
+ buffer = (pui_ani_control_buffer *)&(handle->current_sinfo.planes[0]);
+
+ return buffer;
+}
+
+pui_error
+pui_display_set_buffer(pui_h handle, pui_ani_control_buffer *buffer)
+{
+ if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+ {
+ PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+ return PUI_ERROR_INVALID_HANDLE;
+ }
+
+ if (!handle->current_surface)
+ {
+ pui_err("Current_surface is not valid !\n");
+ return PUI_ERROR_INVALID_SURFACE;
+ }
+
+ if (!buffer || !buffer->ptr || !buffer->size)
+ return PUI_ERROR_INVALID_BUFFER;
+
+ handle->is_buffer_set = 1;
+
+ return PUI_ERROR_NONE;
+}
+
+pui_error
+pui_display_update(pui_h handle)
+{
+ tbm_surface_h surface;
+ tbm_surface_error_e ret;
+ struct wl_buffer *wl_buffer = NULL;
+
+ if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+ {
+ PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+ return PUI_ERROR_INVALID_HANDLE;
+ }
+
+ if (!handle->current_surface)
+ return PUI_ERROR_INVALID_SURFACE;
+
+ if (!handle->is_buffer_set)
+ {
+ pui_err("[UPDATE] Buffer is not set !\n");
+ return PUI_ERROR_INVALID_BUFFER;
+ }
+
+ surface = handle->current_surface;
+ handle->current_surface = NULL;
+
+ tbm_surface_unmap(surface);
+
+ ret = tbm_surface_queue_enqueue(handle->tbm_queue, surface);
+
+ if (ret != TBM_SURFACE_ERROR_NONE)
+ {
+ pui_err("[UPDATE] enqueue err:%d\n", ret);
+ return PUI_ERROR_INVALID_SURFACE;
+ }
+
+ ret = tbm_surface_queue_acquire(handle->tbm_queue, &surface);
+
+ if (ret != TBM_SURFACE_ERROR_NONE)
+ {
+ pui_err("[UPDATE] acquire err:%d\n", ret);
+ return PUI_ERROR_INVALID_SURFACE;
+ }
+
+ if (!tbm_surface_internal_get_user_data(surface, (unsigned long)&KEY_WL_BUFFER, (void **)&wl_buffer)) {
+ wl_buffer = wayland_tbm_client_create_buffer(handle->wl_tbm_client, surface);
+
+ if (!wl_buffer)
+ {
+ pui_err("[UPDATE] failed to create wl_buffer tbm_surface:%p\n", surface);
+ return PUI_ERROR_INVALID_BUFFER;
+ }
+
+ wl_buffer_add_listener(wl_buffer, &buffer_listener, surface);
+
+ tbm_surface_internal_add_user_data(surface, (unsigned long)&KEY_WL_BUFFER, NULL);
+ tbm_surface_internal_set_user_data(surface, (unsigned long)&KEY_WL_BUFFER, wl_buffer);
+ tbm_surface_internal_add_user_data(surface, (unsigned long)&KEY_CLIENT, NULL);
+ tbm_surface_internal_set_user_data(surface, (unsigned long)&KEY_CLIENT, handle);
+ }
+
+ if (!wl_buffer)
+ {
+ pui_err("[UPDATE] dequeue err:%d\n", ret);
+ return PUI_ERROR_INVALID_BUFFER;
+ }
+
+ ecore_wl2_window_buffer_attach(handle->win, wl_buffer, 0, 0, 0);
+ ecore_wl2_window_damage(handle->win, NULL, 0);
+ ecore_wl2_window_commit(handle->win, EINA_TRUE);
+
+ pui_info("[UPDATE] commit wl_buffer:%p, surface:%p\n", wl_buffer, surface);
+
+ handle->is_buffer_set = 0;
+
+ return PUI_ERROR_NONE;
+}
+
+pui_error
+pui_display_manual_render_set(pui_h handle, pui_bool set)
+{
+ pui_ani_h ani_h = NULL;
+
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+ {
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+ return PUI_ERROR_INVALID_HANDLE;
+ }
+
+ ani_h = handle->current_ani_h;
+
+ if (ani_h)
+ {
+ if (pui_ani_status_get(ani_h->ani) == PUI_ANI_STATUS_RUNNING ||
+ pui_ani_status_get(ani_h->ani) == PUI_ANI_STATUS_PAUSED)
+ {
+ pui_err("Please stop the current animation.\n");
+ return PUI_ERROR_UNABLE_SET_MANUAL_RENDER;
+ }
+ }
+
+ handle->manual_render = !!set;
+
+ return PUI_ERROR_NONE;
+}
+
+pui_bool
+pui_display_manual_render_get(pui_h handle)
+{
+ if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+ {
+ PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
+ return 0;
+ }
+
+ return handle->manual_render;
+}
+
+pui_bool
+pui_display_geometry_get(pui_h handle, int *width, int *height)
+{
+ if (!width || !height)
+ return 0;
+
+ *width = 0;
+ *height = 0;
+ (void) handle;
+
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+ {
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+ return 0;
+ }
+
+ if (!pui_module->backend_module_data) {
+ pui_err("pui module data is not loaded\n");
+ return 0;
+ }
+
+ if (!pui_module->backend_module_data->geometry_get)
+ {
+ pui_err("Backend doesn't have geometry_get() !\n");
+ return 0;
+ }
+
+ return pui_module->backend_module_data->geometry_get(width, height);
}
pui_h
pui_create(Ecore_Wl2_Window *win)
{
pui_h handle = NULL;
- Ecore_Wl2_display *ewd = ecore_wl2_window_display_get(win);
+ Ecore_Wl2_Display *ewd = ecore_wl2_window_display_get(win);
struct wayland_tbm_client *wl_tbm_client = NULL;
- Ecore_Wl2_Frame_Cb_Handle *frame_cb = NULL;
if (!win || !ewd)
{
- pui_err("Invalid window or display !");
+ pui_err("Invalid window or display !\n");
+ return NULL;
+ }
+
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+ {
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
return NULL;
}
if (!wl_tbm_client)
{
- pui_err("Failed to init wayland_tbm_client !");
+ pui_err("Failed to init wayland_tbm_client !\n");
return NULL;
}
- handle = (pui_h)calloc(1, sizeof(pui_h));
+ handle = (pui_h)calloc(1, sizeof(pui));
if (!handle)
return NULL;
handle->visibility = 0;
handle->wl_tbm_client = wl_tbm_client;
handle->ani_handles = NULL;
+ handle->current_ani_h = NULL;
+ handle->manual_render = 0;
handle->backend_module_data = pui_module->backend_module_data;
handle->tbm_queue = wayland_tbm_client_create_surface_queue(handle->wl_tbm_client,
ecore_wl2_window_surface_get(handle->win),
- 2, 100, 100, TBM_FORMAT_ABGR8888);
+ 3, 100, 100, TBM_FORMAT_ABGR8888);
if (!handle->tbm_queue)
{
goto err;
}
+ PUI_MAGIC_SET(handle, PUI_MAGIC_PUI_H);
return handle;
err:
void
pui_destroy(pui_h handle)
{
- pui_ani_h *ani_h = NULL;
+ pui_ani_h ani_h = NULL;
- if (!handle)
+ if (!PUI_MAGIC_CHECK(handle, PUI_MAGIC_PUI_H))
+ {
+ PUI_MAGIC_FAIL(handle, PUI_MAGIC_PUI_H, __FUNCTION__);
return;
+ }
EINA_LIST_FREE(handle->ani_handles, ani_h)
{
pui_ani_destroy(ani_h);
- free(ani_h);
}
if (handle->tbm_queue)
{
tbm_surface_queue_destroy(handle->tbm_queue);
- handle->tbm_queue = NULL;
}
if (handle->wl_tbm_client)
handle->wl_tbm_client = NULL;
}
+ PUI_MAGIC_SET(handle, PUI_MAGIC_NONE);
free(handle);
}
-#define PREFIX_LIB "libpui_"
+#define PREFIX_LIB "libpui-"
#define SUFFIX_LIB ".so"
-#define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB
+#define DEFAULT_LIB PREFIX_LIB"default-backend"SUFFIX_LIB
static void
_pui_load_backend_module(void)
pui_backend_module_data *backend_module_data = NULL;
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+ {
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+ return;
+ }
module_info = dlopen(DEFAULT_LIB, RTLD_LAZY);
backend_module_minor = PUI_BACKEND_GET_ABI_MINOR(backend_module_info->abi_version);
if (backend_module_major > pui_backend_major) {
- TBM_ERR("PUI backend module ABI major ver(%d) is newer than the PUI's ver(%d)\n",
+ pui_err("PUI backend module ABI major ver(%d) is newer than the PUI's ver(%d)\n",
backend_module_major, pui_backend_major);
goto err;
} else if (backend_module_minor > pui_backend_minor) {
- TBM_ERR("PUI backend module ABI minor ver(%d) is newer than the PUI's ver(%d)\n",
+ pui_err("PUI backend module ABI minor ver(%d) is newer than the PUI's ver(%d)\n",
backend_module_minor, pui_backend_minor);
goto err;
}
return;
err:
- if (backend_module_info)
- backend_module_info->backend_deinit
+ if (backend_module_info && backend_module_info->backend_deinit)
+ backend_module_info->backend_deinit(backend_module_data);
if (module_info)
dlclose(module_info);
static void
_pui_unload_backend_module(void)
{
- if (!pui_module)
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
{
- pui_err("Invalid pui module !\n");
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
return;
}
}
static void
+_pui_load_backend_collect_animations(void)
+{
+ pui_int_error ret;
+
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
+ {
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
+ return;
+ }
+
+ if (!pui_module->backend_module_data) {
+ pui_err("pui module data is not loaded\n");
+ return;
+ }
+
+ if (!pui_module->backend_module_data->create_ani_collection)
+ {
+ pui_err("Backend doesn't have create_ani_collection() !\n");
+ return;
+ }
+
+ ret = pui_module->backend_module_data->create_ani_collection();
+ if (ret != PUI_INT_ERROR_NONE) {
+ pui_err("Failed to collect animations data (%s)\n",
+ pui_error_to_string(ret));
+ }
+}
+
+static void
_pui_load(void)
{
_pui_load_backend_module();
+ _pui_load_backend_collect_animations();
}
static void
PUI_EVENT_ANI_PAUSED = ecore_event_type_new();
PUI_EVENT_ANI_READY_TO_START = ecore_event_type_new();
PUI_EVENT_ANI_READY_TO_RESUME = ecore_event_type_new();
- PUI_EVENT_ANI_FRAME_DONE = ecore_event_type_new();
- PUI_EVENT_ANI_BUFFER_RELEASED = ecore_event_type_new();
}
static void
PUI_EVENT_ANI_STOPPED,
PUI_EVENT_ANI_PAUSED,
PUI_EVENT_ANI_READY_TO_START,
- PUI_EVENT_ANI_READY_TO_RESUME,
- PUI_EVENT_ANI_FRAME_DONE,
- PUI_EVENT_ANI_BUFFER_RELEASED);
+ PUI_EVENT_ANI_READY_TO_RESUME);
PUI_EVENT_ANI_STARTED = -1;
PUI_EVENT_ANI_STOPPED = -1;
PUI_EVENT_ANI_PAUSED = -1;
PUI_EVENT_ANI_READY_TO_START = -1;
PUI_EVENT_ANI_READY_TO_RESUME = -1;
- PUI_EVENT_ANI_FRAME_DONE = -1;
- PUI_EVENT_ANI_BUFFER_RELEASED = -1;
}
int
pui_init(void)
{
+ const char *cp = NULL;
+
if (++_pui_init_count != 1)
return _pui_init_count;
+ _pui_log_level = PUI_LOG_LEVEL_DEBUG;
+
+ cp = getenv("LIBPUI_LOG_LEVEL");
+
+ if (cp)
+ {
+ _pui_log_level = atoi(cp);
+ }
+
if (pui_module)
{
pui_err("Invalid calling of pui_init() !\n");
goto error;
}
- //TODO
+ PUI_MAGIC_SET(pui_module, PUI_MAGIC_PUI_M);
+
ecore_wl2_init();
_pui_event_init();
return 0;
}
- if (!pui_module)
+ if (!PUI_MAGIC_CHECK(pui_module, PUI_MAGIC_PUI_M))
{
- pui_err("Invalid pui module data !\n");
+ PUI_MAGIC_FAIL(pui_module, PUI_MAGIC_PUI_M, __FUNCTION__);
return _pui_init_count;
}
ecore_wl2_shutdown();
+ PUI_MAGIC_SET(pui_module, PUI_MAGIC_NONE);
free(pui_module);
return _pui_init_count;