+/*
+ * 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"
int PUI_EVENT_ANI_PAUSED = 0;
int PUI_EVENT_ANI_READY_TO_START = 0;
int PUI_EVENT_ANI_READY_TO_RESUME = 0;
-int PUI_EVENT_ANI_FRAME_DONE = 0;
-int PUI_EVENT_ANI_BUFFER_RELEASED = 0;
+
+static int KEY_WL_BUFFER = 0xabcdbeaf;
+static int KEY_CLIENT = 0xdcbabeaf;
pui_error_string
pui_error_to_string(pui_error e)
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";
}
return str;
}
+static void
+_buffer_release(void *data, struct wl_buffer *buffer)
+{
+ tbm_surface_h surface = (tbm_surface_h)data;
+ pui_h handle;
+
+ tbm_surface_internal_get_user_data(surface, (unsigned long)&KEY_CLIENT, (void **)&handle);
+ tbm_surface_queue_release(handle->tbm_queue, surface);
+
+ pui_info("[UPDATE] release wl_buffer:%p, surface:%p\n", buffer, surface);
+}
+
+static const struct wl_buffer_listener buffer_listener = {
+ _buffer_release
+};
+
+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 (!handle)
+ {
+ pui_err("Error : PUI_INT_ERROR_INVALID_HANDLE\n");
+ 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 (!handle)
+ {
+ pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+ 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 (!handle)
+ {
+ pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+ 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 (!handle)
+ {
+ pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+ 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 (!handle)
+ {
+ pui_err("Error : PUI_ERROR_INVALID_HANDLE\n");
+ 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;
+
+ if (!pui_module || !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)
{
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)
{
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_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
ecore_wl2_init();
_pui_event_init();