- This patch is operated in Wayland/GBM backends.
- TODO: It has to be applied to x11 backend.
Change-Id: Ie206dd43fbb93e7cf7c131360f9f667e98a6abb6
TPL_HEADERS += $(SRC_DIR)/tpl_utils.h
TPL_SRCS += $(SRC_DIR)/tpl.c
-TPL_SRCS += $(SRC_DIR)/tpl_buffer.c
TPL_SRCS += $(SRC_DIR)/tpl_display.c
TPL_SRCS += $(SRC_DIR)/tpl_frame.c
TPL_SRCS += $(SRC_DIR)/tpl_object.c
}
}
-void
-__tpl_buffer_init_backend(tpl_buffer_t *buffer, tpl_backend_type_t type)
-{
- switch (type)
- {
-#ifdef TPL_WINSYS_WL
- case TPL_BACKEND_GBM:
- __tpl_buffer_init_backend_gbm(&buffer->backend);
- break;
- case TPL_BACKEND_WAYLAND:
- __tpl_buffer_init_backend_wayland(&buffer->backend);
- break;
-#endif
-#ifdef TPL_WINSYS_DRI2
- case TPL_BACKEND_X11_DRI2:
- __tpl_buffer_init_backend_x11_dri2(&buffer->backend);
- break;
-#endif
-#ifdef TPL_WINSYS_DRI3
- case TPL_BACKEND_X11_DRI3:
- __tpl_buffer_init_backend_x11_dri3(&buffer->backend);
- break;
-#endif
- default:
- TPL_ASSERT(TPL_FALSE);
- break;
- }
-}
-
tpl_bool_t
tpl_get_native_window_info(tpl_display_t *display, tpl_handle_t window,
int *width, int *height, tpl_format_t *format, int depth, int a_size)
typedef struct _tpl_surface tpl_surface_t;
/**
- * A structure representing TPL buffer object.
- *
- * TPL buffer is an object representing a set of pixels which is usually a
- * block of memories.
- */
-typedef struct _tpl_buffer tpl_buffer_t;
-
-/**
* Function type used for freeing some data.
*/
typedef void (*tpl_free_func_t)(void *data);
* @see tpl_surface_begin_frame()
* @see tpl_surface_end_frame()
*/
-#if TPL_WINSYS_WL
tbm_surface_h tpl_surface_get_buffer(tpl_surface_t *surface,
tpl_bool_t *reset_buffers);
-#else
-tpl_buffer_t * tpl_surface_get_buffer(tpl_surface_t *surface,
- tpl_bool_t *reset_buffers);
-#endif
/**
* Post a frame from the frame queue of the given surface.
*
tpl_bool_t tpl_surface_update_cached_buffers(tpl_surface_t *surface);
-/**
- * Map the given buffer to the user space address.
- *
- * Users can do CPU access to the buffer memory by using this function. It is
- * recommended to lock the buffer first with appropriate lock usage to avoid
- * cache coherency problems.
- *
- * @param buffer buffer to map.
- * @param size Size of the area to be mapped. Give 0 for entire buffer.
- * @return Pointer to the mapped buffer memory.
- *
- * @see tpl_buffer_unmap()
- */
-void * tpl_buffer_map(tpl_buffer_t *buffer,
- int size);
-
-/**
- * Unmap the given buffer from the user space address.
- *
- * @param buffer buffer to unmap
- * @param ptr Pointer to the mapped memory. Give NULL if the entire buffer was mapped.
- * @param size Size of the mapped memory. Give 0 if the entire buffer was mapped.
- *
- * @see tpl_buffer_map()
- */
-void tpl_buffer_unmap(tpl_buffer_t *buffer,
- void *ptr,
- int size);
-
-/**
- * Lock the given buffer.
- *
- * Buffer lock is used for synchronizations. The locking is actually done to
- * the low-level buffer object like dma_buf. So, it is possible that locking
- * call is blocked although no locking is ever called for the TPL buffer. Other
- * TPL buffer pointing to the same low-level buffer might be locked or other
- * process might be holding the lock for the same low-level buffer.
- *
- * The lock might work as R/W lock depending on backend.
- *
- * @param buffer buffer to lock.
- * @param usage purpose of the lock.
- * @return TPL_TRUE on success, TPL_FALSE otherwise.
- *
- * @see tpl_buffer_unlock()
- */
-tpl_bool_t tpl_buffer_lock(tpl_buffer_t *buffer,
- tpl_lock_usage_t usage);
-
-/**
- * Unlock the given buffer.
- *
- * @param buffer buffer to unlock.
- *
- * @see tpl_buffer_lock()
- */
-void tpl_buffer_unlock(tpl_buffer_t *buffer);
-
-/**
- * Create a native buffer of the given TPL buffer.
- *
- * This function can be used to export a TPL buffer by the returned native
- * buffer. Some windowing system need a extra buffer export mechanism between
- * compositor and application.
- *
- * @param buffer buffer to export.
- * @return A native buffer from the buffer. NULL on error.
- */
-void *tpl_buffer_create_native_buffer(tpl_buffer_t *buffer);
-
-/**
- * Get the low-level buffer key of the given TPL buffer.
- *
- * It is a common method representing buffers with 32bits or 64bits key. A TPL
- * buffer internally indicate a platform dependent low-level buffer like
- * dma_buf. This function retrieves such key to the low-level buffer.
- *
- * @param buffer buffer to retrieve the key.
- * @return Key to the low-level buffer.
- *
- * @see tpl_buffer_get_fd()
- */
-size_t tpl_buffer_get_key(tpl_buffer_t *buffer);
-
-/**
- * Get the low-level buffer fd of the given TPL buffer.
- *
- * It is also a common method accessing a buffer via file system. This function
- * returns file descriptor for the low-level buffer.
- *
- * @param buffer buffer to retrieve fd.
- * @return file descriptor of the low-level buffer.
- *
- * @see tpl_buffer_get_key()
- */
-int tpl_buffer_get_fd(tpl_buffer_t *buffer);
-
-/**
- * Get the age of the given TPL buffer.
- *
- * Buffer age gives us information on content which is already rendered on the
- * buffer. It is used to do partial update which is an optimization techinique
- * that renders only different area between current frame and previously
- * rendered buffer content.
- *
- * @param buffer buffer to get age.
- * @return age of the buffer..
- */
-int tpl_buffer_get_age(tpl_buffer_t *buffer);
-
-/**
- * Get the TPL surface where the given TPL buffer belongs to.
- *
- * @param buffer buffer to get the belonging surface.
- * @return surface where the given buffer belongs to.
- *
- * @see tpl_surface_get_buffer()
- */
-tpl_surface_t * tpl_buffer_get_surface(tpl_buffer_t *buffer);
-
-/**
- * Get the size of the given TPL buffer.
- *
- * @param buffer buffer to get the size.
- * @param width pointer to receive the width value.
- * @param height pointer to receive the height value.
- * @return TPL_TRUE on success, TPL_FALSE on error.
- */
-tpl_bool_t tpl_buffer_get_size(tpl_buffer_t *buffer,
- int *width,
- int *height);
-
-/**
- * Get the color depth of the given TPL buffer.
- *
- * @param buffer buffer to get the color depth.
- * @return color depth of the given buffer.
- */
-int tpl_buffer_get_depth(tpl_buffer_t *buffer);
-
-/**
- * Get the pitch value (in bytes) of the given TPL buffer.
- *
- * @param buffer buffer to get the pitch.
- * @return pitch of the given buffer in bytes.
- */
-int tpl_buffer_get_pitch(tpl_buffer_t *buffer);
-
-int tpl_buffer_get_map_cnt(tpl_buffer_t *buffer);
-/**
- * Get the ID of the given TPL buffer.
- *
- * @param buffer buffer to get the id.
- * @return id of the given buffer.
- */
-
-unsigned int tpl_buffer_get_id(tpl_buffer_t *buffer);
-
-
-int tpl_buffer_get_map_cnt(tpl_buffer_t *buffer);
/**
* Query information on the given native window.
+++ /dev/null
-#include "tpl_internal.h"
-
-static void
-__tpl_buffer_fini(tpl_buffer_t *buffer)
-{
- TPL_ASSERT(buffer);
- TPL_ASSERT(buffer->backend.fini);
-
- buffer->backend.fini(buffer);
-}
-
-static void
-__tpl_buffer_free(void *buffer)
-{
- TPL_ASSERT(buffer);
-
- __tpl_buffer_fini((tpl_buffer_t *) buffer);
- free(buffer);
-}
-
-tpl_buffer_t *
-__tpl_buffer_alloc(tpl_surface_t *surface, size_t key, int fd, int width, int height,
- int depth, int pitch)
-{
- tpl_buffer_t *buffer;
- tpl_bool_t ret;
-
- TPL_ASSERT(surface);
- TPL_ASSERT(surface->display);
-
- buffer = (tpl_buffer_t *)calloc(1, sizeof(tpl_buffer_t));
- if (NULL == buffer)
- return NULL;
-
- ret = __tpl_object_init(&buffer->base, TPL_OBJECT_BUFFER, __tpl_buffer_free);
- if (TPL_TRUE != ret)
- return NULL;
-
- buffer->surface = surface;
- buffer->key = key;
- buffer->fd = fd;
- buffer->age = -1;
-
- buffer->width = width;
- buffer->height = height;
- buffer->depth = depth;
- buffer->pitch = pitch;
- buffer->map_cnt = 0;
-
- /* Backend initialization. */
- __tpl_buffer_init_backend(buffer, surface->display->backend.type);
-
- if (TPL_TRUE != buffer->backend.init(buffer))
- {
- tpl_object_unreference((tpl_object_t *) buffer);
- return NULL;
- }
-
- TPL_LOG(3, "buffer(%p) surface(%p, %p) key:%zu fd:%d %dx%d", (void *) buffer, surface, surface->native_handle, key, fd, width, height);
- return buffer;
-}
-
-void
-__tpl_buffer_set_surface(tpl_buffer_t *buffer, tpl_surface_t *surface)
-{
- TPL_ASSERT(buffer);
-
- buffer->surface = surface;
-}
-
-void *
-tpl_buffer_map(tpl_buffer_t *buffer, int size)
-{
- void *ptr;
-
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return NULL;
- }
-
- TPL_OBJECT_LOCK(buffer);
- ptr = buffer->backend.map(buffer, size);
- TPL_OBJECT_UNLOCK(buffer);
-
- return ptr;
-}
-
-void
-tpl_buffer_unmap(tpl_buffer_t *buffer, void *ptr, int size)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return;
- }
-
- TPL_OBJECT_LOCK(buffer);
- buffer->backend.unmap(buffer, ptr, size);
- TPL_OBJECT_UNLOCK(buffer);
-}
-
-tpl_bool_t
-tpl_buffer_lock(tpl_buffer_t *buffer, tpl_lock_usage_t usage)
-{
- tpl_bool_t result;
-
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return TPL_FALSE;
- }
-
- TPL_OBJECT_LOCK(buffer);
- result = buffer->backend.lock(buffer, usage);
- buffer->map_cnt++;
- TPL_OBJECT_UNLOCK(buffer);
-
- return result;
-}
-
-void
-tpl_buffer_unlock(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return;
- }
-
- TPL_OBJECT_LOCK(buffer);
- buffer->backend.unlock(buffer);
- buffer->map_cnt--;
- TPL_OBJECT_UNLOCK(buffer);
-}
-
-size_t
-tpl_buffer_get_key(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return -1;
- }
-
- return buffer->key;
-}
-
-int
-tpl_buffer_get_fd(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return -1;
- }
-
- return buffer->fd;
-}
-
-int
-tpl_buffer_get_age(tpl_buffer_t *buffer)
-{
- int age;
-
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return -1;
- }
-
- TPL_OBJECT_LOCK(buffer);
-
- /* Get buffer age from TPL */
- if (buffer->backend.get_buffer_age != NULL)
- age = buffer->backend.get_buffer_age(buffer);
- else
- age = buffer->age;
-
- TPL_OBJECT_UNLOCK(buffer);
-
- return age;
-}
-
-tpl_surface_t *
-tpl_buffer_get_surface(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return NULL;
- }
-
- return buffer->surface;
-}
-
-tpl_bool_t
-tpl_buffer_get_size(tpl_buffer_t *buffer, int *width, int *height)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return TPL_FALSE;
- }
-
- if (width)
- *width = buffer->width;
-
- if (height)
- *height = buffer->height;
-
- return TPL_TRUE;
-}
-
-int
-tpl_buffer_get_depth(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return -1;
- }
-
- return buffer->depth;
-}
-
-int
-tpl_buffer_get_pitch(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return -1;
- }
-
- return buffer->pitch;
-}
-
-int
-tpl_buffer_get_map_cnt(tpl_buffer_t *buffer)
-{
- return buffer->map_cnt;
-}
-void *
-tpl_buffer_create_native_buffer(tpl_buffer_t *buffer)
-{
- if (NULL == buffer)
- {
- TPL_ERR("buffer is NULL!");
- return NULL;
- }
-
- if (NULL == buffer->backend.create_native_buffer)
- return NULL;
-
- return buffer->backend.create_native_buffer(buffer);
-}
return frame;
}
-
-
-#if TPL_WINSYS_WL
void
__tpl_frame_free(tpl_frame_t *frame)
{
tbm_surface_internal_ref(tbm_surface);
frame->tbm_surface = tbm_surface;
}
-#else
-void
-__tpl_frame_free(tpl_frame_t *frame)
-{
- TPL_ASSERT(frame);
-
- if (frame->buffer)
- tpl_object_unreference((tpl_object_t *)frame->buffer);
-
- __tpl_region_fini(&frame->damage);
- free(frame);
-}
-
-void
-__tpl_frame_set_buffer(tpl_frame_t *frame, tpl_buffer_t *buffer)
-{
- TPL_ASSERT(frame);
- TPL_ASSERT(buffer);
-
- if (frame->buffer)
- tpl_object_unreference((tpl_object_t *)frame->buffer);
-
- tpl_object_reference((tpl_object_t *)buffer);
- frame->buffer = buffer;
-}
-#endif
unsigned int __tpl_gbm_display_unbind_client_wayland_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy);
#endif
-#define TPL_BUFFER_CACHE_MAX_ENTRIES 40
-
static int tpl_gbm_buffer_key;
#define KEY_TPL_GBM_BUFFER (unsigned long)(&tpl_gbm_buffer_key)
#include "tpl_utils.h"
-#if TPL_WINSYS_WL
#include <tbm_bufmgr.h>
#include <tbm_surface.h>
#include <tbm_surface_internal.h>
-#endif
#define TPL_OBJECT_LOCK(object) __tpl_object_lock((tpl_object_t *)(object))
#define TPL_OBJECT_UNLOCK(object) __tpl_object_unlock((tpl_object_t *)(object))
typedef struct _tpl_runtime tpl_runtime_t;
typedef struct _tpl_display_backend tpl_display_backend_t;
typedef struct _tpl_surface_backend tpl_surface_backend_t;
-typedef struct _tpl_buffer_backend tpl_buffer_backend_t;
typedef struct _tpl_frame tpl_frame_t;
typedef struct tpl_hlist tpl_hlist_t;
struct _tpl_frame
{
-#if TPL_WINSYS_WL
tbm_surface_h tbm_surface;
-#else
- tpl_buffer_t *buffer;
-#endif
int interval;
tpl_region_t damage;
tpl_frame_state_t state;
tpl_bool_t (*end_frame)(tpl_surface_t *surface);
tpl_bool_t (*validate_frame)(tpl_surface_t *surface);
- tpl_buffer_t * (*get_buffer)(tpl_surface_t *surface, tpl_bool_t *reset_buffers);
+ tbm_surface_h (*get_buffer)(tpl_surface_t *surface, tpl_bool_t *reset_buffers);
void (*post)(tpl_surface_t *surface, tpl_frame_t *frame);
tpl_bool_t (*destroy_cached_buffers)(tpl_surface_t *surface);
tpl_bool_t (*update_cached_buffers)(tpl_surface_t *surface);
};
-struct _tpl_buffer_backend
-{
- tpl_backend_type_t type;
- void *data;
- unsigned int flags;
-
- tpl_bool_t (*init)(tpl_buffer_t *buffer);
- void (*fini)(tpl_buffer_t *buffer);
-
- void * (*map)(tpl_buffer_t *buffer, int size);
- void (*unmap)(tpl_buffer_t *buffer, void *ptr, int size);
-
- tpl_bool_t (*lock)(tpl_buffer_t *buffer, tpl_lock_usage_t usage);
- void (*unlock)(tpl_buffer_t *buffer);
-
- void * (*create_native_buffer)(tpl_buffer_t *buffer);
- int (*get_buffer_age)(tpl_buffer_t *buffer);
-};
-
struct _tpl_object
{
tpl_object_type_t type;
tpl_surface_backend_t backend;
};
-struct _tpl_buffer
-{
- tpl_object_t base;
-
- tpl_surface_t *surface;
- size_t key;
- int fd;
- int age;
-
- int width;
- int height;
- int depth;
- int pitch;
-
- int map_cnt;
- tpl_buffer_backend_t backend;
-};
-
/*******************************************************************************
* TPL object functions
*******************************************************************************/
/* Frame functions. */
tpl_frame_t * __tpl_frame_alloc();
void __tpl_frame_free(tpl_frame_t *frame);
-
-#if TPL_WINSYS_WL
void __tpl_frame_set_buffer(tpl_frame_t *frame, tbm_surface_h tbm_surface);
-#else
-void __tpl_frame_set_buffer(tpl_frame_t *frame, tpl_buffer_t *buffer);
-#endif
+
/* Display functions. */
tpl_handle_t __tpl_display_get_native_handle(tpl_display_t *display);
void __tpl_display_flush(tpl_display_t *display);
void __tpl_surface_set_backend_data(tpl_surface_t *surface, void *data);
void * __tpl_surface_get_backend_data(tpl_surface_t *surface);
-/* Buffer functions. */
-tpl_buffer_t * __tpl_buffer_alloc(tpl_surface_t *surface, size_t key, int fd, int width, int height, int depth, int pitch);
-void __tpl_buffer_set_surface(tpl_buffer_t *buffer, tpl_surface_t *surface);
-
/* Runtime functions. */
tpl_display_t * __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display);
tpl_bool_t __tpl_runtime_add_display(tpl_display_t *display);
void __tpl_display_init_backend(tpl_display_t *display, tpl_backend_type_t type);
void __tpl_surface_init_backend(tpl_surface_t *surface, tpl_backend_type_t type);
-void __tpl_buffer_init_backend(tpl_buffer_t *buffer, tpl_backend_type_t type);
void __tpl_display_init_backend_gbm(tpl_display_backend_t *backend);
void __tpl_display_init_backend_wayland(tpl_display_backend_t *backend);
void __tpl_surface_init_backend_x11_dri2(tpl_surface_backend_t *backend);
void __tpl_surface_init_backend_x11_dri3(tpl_surface_backend_t *backend);
-void __tpl_buffer_init_backend_gbm(tpl_buffer_backend_t *backend);
-void __tpl_buffer_init_backend_wayland(tpl_buffer_backend_t *backend);
-void __tpl_buffer_init_backend_x11_dri2(tpl_buffer_backend_t *backend);
-void __tpl_buffer_init_backend_x11_dri3(tpl_buffer_backend_t *backend);
-
/* Region functions. */
void __tpl_region_init(tpl_region_t *region);
void __tpl_region_fini(tpl_region_t *region);
return TPL_TRUE;
}
-#if TPL_WINSYS_WL
tbm_surface_h
tpl_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers)
{
return (void*)tbm_surface;
}
-#else
-tpl_buffer_t *
-tpl_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers)
-{
- tpl_buffer_t *buffer = NULL;
-
- if (NULL == surface)
- {
- TPL_ERR("Invalid surface!");
- return NULL;
- }
-
- if (NULL == surface->backend.get_buffer)
- {
- TPL_ERR("TPL surface has not been initialized correctly!");
- return NULL;
- }
-
- TRACE_BEGIN("TPL:GETBUFFER");
- TPL_OBJECT_LOCK(surface);
-
- buffer = surface->backend.get_buffer(surface, reset_buffers);
-
- if(buffer != NULL)
- {
- /* Update size of the surface. */
- surface->width = buffer->width;
- surface->height = buffer->height;
-
- if (surface->frame)
- __tpl_frame_set_buffer(surface->frame, buffer);
- }
-
- TPL_OBJECT_UNLOCK(surface);
- TRACE_END();
-
- return buffer;
-}
-#endif
-
tpl_bool_t
tpl_surface_destroy_cached_buffers(tpl_surface_t *surface)
{
return TPL_FALSE;
}
-#if TPL_WINSYS_WL
if (frame->tbm_surface == NULL)
-#else
- if (frame->buffer == NULL)
-#endif
{
__tpl_frame_free(frame);
TPL_OBJECT_UNLOCK(surface);