--- /dev/null
+1. Function names
+ 1) all internal function names should start with '__tpl'
+ 2) externally exposed function names should start with 'tpl'
+
+2. Input argument checking
+ 1) internal functions should TPL_ASSERT on non-null for all pointer type
+ argumentxs
+ Exception:
+ - NULL is valid value
+ - function is a validity checking function
+ 2) internal functions should not check for non-null for pointer type
+ arguments with conditional branching
+ Execption: function is a validity checking function
+ 3) externally exposed functions should check for non-null for all
+ pointer type arguments with 'if' statement
+ Execption: NULL is valid value
+ 4) when externally exposed function is return due to error, TPL_ERR
+ should be called with appropriate error message
+
+3. Function calling
+ 1) before calling internal function, caller function *MUST* check for
+ value validity before passing it to the callee
+ (internal functions do not check for input validity)
+
+4. Return value
+ 1) functions should return a value
+ Exception:
+ - failure is ignorable
+ - failure not possible
+ 2) default return values should be TPL_TRUE on success and TPL_FALSE on
+ failure
+ 3) functions that return pointer value *MUST* return NULL on error
+ 4) other functions which return values useful to other callee may return
+ that value
+
+5. Documentation
+ 1) *ALL* functions in libtpl-egl *MUST* be documented in Doxygen format
+ 2) functions *MUST* have at least brief, param, and return sections
+
+6. Enumeration type
+ 1) *ALL* enums *MUST* start with error code, 'xxx_ERROR' and assigned
+ value of -1
+ 2) *ALL* enums *MUST* have identifier named 'xxx_MAX' to signify the end
+ of the enum list (i.e. 'TPL_OBJECT_MAX')
%define TPL_VER_MAJOR 0
-%define TPL_VER_MINOR 7
+%define TPL_VER_MINOR 8
%define TPL_RELEASE 1
%define TPL_VERSION %{TPL_VER_MAJOR}.%{TPL_VER_MINOR}
%define TPL_VER_FULL %{TPL_VERSION}.%{TPL_RELEASE}
static tpl_runtime_t *runtime = NULL;
static pthread_mutex_t runtime_mutex = PTHREAD_MUTEX_INITIALIZER;
-static void
+static tpl_bool_t
__tpl_runtime_init()
{
if (runtime == NULL)
{
- runtime = (tpl_runtime_t *)calloc(1, sizeof(tpl_runtime_t));
- TPL_ASSERT(runtime != NULL);
+ runtime = (tpl_runtime_t *) calloc(1, sizeof(tpl_runtime_t));
+ if (runtime == NULL)
+ return TPL_FALSE;
}
+
+ return TPL_TRUE;
}
static void __attribute__((destructor))
for (i = 0; i < TPL_BACKEND_COUNT; i++)
{
if (runtime->displays[i] != NULL)
- tpl_hashlist_destroy(&(runtime->displays[i]));
+ __tpl_hashlist_destroy(&(runtime->displays[i]));
}
free(runtime);
}
/* Begin: OS dependent function definition */
-void tpl_util_sys_yield(void)
+void __tpl_util_sys_yield(void)
{
int status;
+
status = sched_yield();
+
if (0 != status)
{
/* non-fatal on error, warning is enough */
}
}
-int tpl_util_clz(int val)
+int __tpl_util_clz(int val)
{
return __builtin_clz( val );
}
-int tpl_util_atomic_get(const tpl_util_atomic_uint * const atom)
+int __tpl_util_atomic_get(const tpl_util_atomic_uint * const atom)
{
unsigned int ret;
- if (!atom)
- abort();
+ TPL_ASSERT(atom);
TPL_DMB();
ret = *atom;
return ret;
}
-void tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val)
+void __tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val)
{
- if (!atom)
- abort();
+ TPL_ASSERT(atom);
TPL_DMB();
*atom = val;
TPL_DMB();
}
-int tpl_util_atomic_inc(tpl_util_atomic_uint * const atom )
+unsigned int __tpl_util_atomic_inc(tpl_util_atomic_uint * const atom )
{
- if (!atom)
- abort();
+ TPL_ASSERT(atom);
return __sync_add_and_fetch(atom, 1);
}
-int tpl_util_atomic_dec( tpl_util_atomic_uint * const atom )
+unsigned int __tpl_util_atomic_dec( tpl_util_atomic_uint * const atom )
{
- if (!atom)
- abort();
+ TPL_ASSERT(atom);
return __sync_sub_and_fetch(atom, 1);
}
{
if (runtime->displays[type] != NULL)
{
- display = (tpl_display_t *) tpl_hashlist_lookup(runtime->displays[type],
+ display = (tpl_display_t *) __tpl_hashlist_lookup(runtime->displays[type],
(size_t) native_display);
}
}
{
if (runtime->displays[i] != NULL)
{
- display = (tpl_display_t *) tpl_hashlist_lookup(runtime->displays[i],
+ display = (tpl_display_t *) __tpl_hashlist_lookup(runtime->displays[i],
(size_t) native_display);
}
if (display != NULL) break;
return display;
}
-void
+tpl_bool_t
__tpl_runtime_add_display(tpl_display_t *display)
{
tpl_bool_t ret;
- tpl_handle_t handle = display->native_handle;
- tpl_backend_type_t type = display->backend.type;
+ tpl_handle_t handle;
+ tpl_backend_type_t type;
- pthread_mutex_lock(&runtime_mutex);
- __tpl_runtime_init();
+ TPL_ASSERT(display);
- if (type != TPL_BACKEND_UNKNOWN)
+ handle = display->native_handle;
+ type = display->backend.type;
+
+ TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type);
+
+ if (0 != pthread_mutex_lock(&runtime_mutex))
+ return TPL_FALSE;
+
+ if (TPL_TRUE != __tpl_runtime_init())
+ return TPL_FALSE;
+
+ if (NULL == runtime->displays[type])
{
- if (runtime->displays[type] == NULL)
- runtime->displays[type] = tpl_hashlist_create();
+ runtime->displays[type] = __tpl_hashlist_create();
+ if (NULL == runtime->displays[type])
+ return TPL_FALSE;
+ }
- ret = tpl_hashlist_insert(runtime->displays[type], (size_t) handle, (void *) display);
- TPL_ASSERT(ret == TPL_TRUE);
+ ret = __tpl_hashlist_insert(runtime->displays[type], (size_t) handle, (void *) display);
+ if (TPL_TRUE != ret)
+ {
+ __tpl_hashlist_destroy(&runtime->displays[type]);
+ return TPL_FALSE;
}
pthread_mutex_unlock(&runtime_mutex);
+
+ return TPL_TRUE;
}
void
if (type != TPL_BACKEND_UNKNOWN)
{
if (runtime != NULL && runtime->displays[type] != NULL)
- tpl_hashlist_delete(runtime->displays[type], (size_t) handle);
+ __tpl_hashlist_delete(runtime->displays[type], (size_t) handle);
}
pthread_mutex_unlock(&runtime_mutex);
for (i = 0; i < TPL_BACKEND_COUNT; i++)
{
if (runtime->displays[i] != NULL)
- tpl_hashlist_do_for_all_nodes(runtime->displays[i],
+ __tpl_hashlist_do_for_all_nodes(runtime->displays[i],
__tpl_runtime_flush_cb);
}
void
__tpl_display_init_backend(tpl_display_t *display, tpl_backend_type_t type)
{
+ TPL_ASSERT(display);
+ TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type);
+
switch (type)
{
#ifdef TPL_WINSYS_WL
#endif
default:
TPL_ASSERT(TPL_FALSE);
- break;
}
}
void
__tpl_surface_init_backend(tpl_surface_t *surface, tpl_backend_type_t type)
{
+ TPL_ASSERT(surface);
+ TPL_ASSERT(0 <= type && TPL_BACKEND_COUNT > type);
+
switch (type)
{
#ifdef TPL_WINSYS_WL
#endif
default:
TPL_ASSERT(TPL_FALSE);
- break;
}
}
*/
typedef enum
{
+ TPL_OBJECT_ERROR = -1,
TPL_OBJECT_DISPLAY,
TPL_OBJECT_SURFACE,
- TPL_OBJECT_BUFFER
+ TPL_OBJECT_BUFFER,
+ TPL_OBJECT_MAX
} tpl_object_type_t;
/**
*/
typedef enum
{
+ TPL_SURFACE_ERROR = -1,
TPL_SURFACE_TYPE_WINDOW, /**< surface gets displayed by the display server. */
- TPL_SURFACE_TYPE_PIXMAP /**< surface is an offscreen pixmap. */
+ TPL_SURFACE_TYPE_PIXMAP, /**< surface is an offscreen pixmap. */
+ TPL_SURFACE_MAX
} tpl_surface_type_t;
/**
*/
typedef enum
{
+ TPL_BACKEND_ERROR = -1,
TPL_BACKEND_WAYLAND,
TPL_BACKEND_X11_DRI2,
TPL_BACKEND_X11_DRI3,
TPL_BACKEND_COUNT,
- TPL_BACKEND_UNKNOWN
+ TPL_BACKEND_UNKNOWN,
+ TPL_BACKEND_MAX
} tpl_backend_type_t;
/**
* creatation. When the reference count drops to 0, the object will be freed.
*
* @param object object which will be referenced.
- * @return reference count after reference.
+ * @return reference count after reference on success, -1 on error.
*
* @see tpl_object_unreference()
* @see tpl_object_get_reference()
* Decrease reference count of a TPL object.
*
* @param object object which will be unreferenced.
- * @return reference count after unreference.
+ * @return reference count after unreference on success, -1 on error.
*
* @see tpl_object_reference()
* @see tpl_object_get_reference()
* Get reference count of a TPL object.
*
* @oaram object object to get reference count.
- * @return reference count.
+ * @return reference count on success, -1 on error.
*
* @see tpl_object_reference()
* @see tpl_object_get_reference()
* Get the type of a TPL object.
*
* @param object object to get type.
- * @return type of the given object. one of tpl_object_type_t
+ * @return actual type of the object on success, TPL_OBJECT_ERROR on error.
*/
tpl_object_type_t tpl_object_get_type(tpl_object_t *object);
* @param object object to set user data to.
* @param data pointer to the user data.
* @param free_func free function which is used for freeing the user data when the object is destroyed.
+ * @return TPL_TRUE on success, TPL_FALSE on error.
*
* @see tpl_object_get_user_data()
*/
-void tpl_object_set_user_data(tpl_object_t *object,
+tpl_bool_t tpl_object_set_user_data(tpl_object_t *object,
void *data,
tpl_free_func_t free_func);
* Get registered user data of a TPL object.
*
* @param object object to get user data.
- * @return pointer to the registered user data.
+ * @return pointer to the registered user data on success, NULL on error.
*
* @see tpl_object_set_user_data()
*/
* @param width pointer to receive width value.
* @param height pointer to receive height value.
*/
-void tpl_surface_get_size(tpl_surface_t *surface,
+tpl_bool_t tpl_surface_get_size(tpl_surface_t *surface,
int *width,
int *height);
* @see tpl_surface_post()
* @see tpl_surface_get_buffer()
*/
-void tpl_surface_begin_frame(tpl_surface_t *surface);
+tpl_bool_t tpl_surface_begin_frame(tpl_surface_t *surface);
/**
* End the current frame of the given TPL surface.
* @see tpl_surface_set_post_interval()
* @see tpl_surface_set_damage()
*/
-void tpl_surface_end_frame(tpl_surface_t *surface);
+tpl_bool_t tpl_surface_end_frame(tpl_surface_t *surface);
/**
* Validate current frame of the given TPL surface.
* @see tpl_surface_begin_frame()
* @see tpl_surface_end_frame()
*/
-int tpl_surface_post(tpl_surface_t *surface);
+tpl_bool_t tpl_surface_post(tpl_surface_t *surface);
/**
* Set frame interval of the given TPL surface.
*
* @see tpl_surface_get_post_interval()
*/
-void tpl_surface_set_post_interval(tpl_surface_t *surface,
+tpl_bool_t tpl_surface_set_post_interval(tpl_surface_t *surface,
int interval);
/**
*
* @see tpl_surface_get_damage()
*/
-void tpl_surface_set_damage(tpl_surface_t *surface,
+tpl_bool_t tpl_surface_set_damage(tpl_surface_t *surface,
int num_rects,
const int *rects);
*
* @see tpl_surface_set_damage()
*/
-void tpl_surface_get_damage(tpl_surface_t *surface,
+tpl_bool_t tpl_surface_get_damage(tpl_surface_t *surface,
int *num_rects,
const int **rects);
* @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.
*/
-void tpl_buffer_get_size(tpl_buffer_t *buffer,
+tpl_bool_t tpl_buffer_get_size(tpl_buffer_t *buffer,
int *width,
int *height);
int *height,
tpl_format_t *format);
-void tpl_display_wait_native(tpl_display_t *dpy);
+void tpl_display_wait_native(tpl_display_t *display);
#endif /* TPL_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_LOG(3, "buffer(%p)", buffer);
- __tpl_buffer_fini((tpl_buffer_t *)buffer);
+ TPL_ASSERT(buffer);
+
+ __tpl_buffer_fini((tpl_buffer_t *) buffer);
free(buffer);
}
int depth, int pitch)
{
tpl_buffer_t *buffer;
+ tpl_bool_t ret;
- TPL_ASSERT(surface != NULL);
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
buffer = (tpl_buffer_t *)calloc(1, sizeof(tpl_buffer_t));
- TPL_ASSERT(buffer != NULL);
+ if (NULL == buffer)
+ return NULL;
- __tpl_object_init(&buffer->base, TPL_OBJECT_BUFFER, __tpl_buffer_free);
+ ret = __tpl_object_init(&buffer->base, TPL_OBJECT_BUFFER, __tpl_buffer_free);
+ if (TPL_TRUE != ret)
+ return NULL;
buffer->surface = surface;
buffer->key = key;
/* Backend initialization. */
__tpl_buffer_init_backend(buffer, surface->display->backend.type);
- if (!buffer->backend.init(buffer))
+ if (TPL_TRUE != buffer->backend.init(buffer))
{
- TPL_ERR("backend init");
- tpl_object_unreference((tpl_object_t *)buffer);
+ tpl_object_unreference((tpl_object_t *) buffer);
return NULL;
}
void
__tpl_buffer_set_surface(tpl_buffer_t *buffer, tpl_surface_t *surface)
{
+ TPL_ASSERT(buffer);
+
buffer->surface = surface;
}
{
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);
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 result;
+ if (NULL == buffer)
+ {
+ TPL_ERR("buffer is NULL!");
+ return TPL_FALSE;
+ }
+
TPL_OBJECT_LOCK(buffer);
result = buffer->backend.lock(buffer, usage);
TPL_OBJECT_UNLOCK(buffer);
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);
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 age;
- TPL_OBJECT_LOCK((tpl_buffer_t *)buffer);
- age = buffer->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)
else
age = buffer->age;
- TPL_OBJECT_UNLOCK((tpl_buffer_t *)buffer);
+ 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;
}
-void
+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;
}
void *
tpl_buffer_create_native_buffer(tpl_buffer_t *buffer)
{
- if (buffer->backend.create_native_buffer != NULL)
- return buffer->backend.create_native_buffer(buffer);
- return NULL;
+ 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);
}
\ No newline at end of file
void
__tpl_display_flush(tpl_display_t *display)
{
- display->backend.flush(display);
+ TPL_ASSERT(display);
+
+ if (display->backend.flush)
+ display->backend.flush(display);
}
static void
__tpl_display_fini(tpl_display_t *display)
{
- display->backend.fini(display);
+ TPL_ASSERT(display);
+
+ if (display->backend.fini)
+ display->backend.fini(display);
+
__tpl_runtime_remove_display(display);
}
static void
__tpl_display_free(void *display)
{
+ TPL_ASSERT(display);
+
__tpl_display_fini((tpl_display_t *)display);
free(display);
}
tpl_display_get(tpl_backend_type_t type, tpl_handle_t native_dpy)
{
tpl_display_t *display;
+ tpl_bool_t ret;
+
+ if (0 > type || TPL_BACKEND_COUNT == type || TPL_BACKEND_MAX <= type)
+ {
+ TPL_ERR("Invalid backend type!");
+ return NULL;
+ }
/* Search for an already connected display for the given native display. */
display = __tpl_runtime_find_display(type, native_dpy);
- if (display != NULL)
+ /* exact match found, can return immediately */
+ if (NULL != display)
return display;
- if (type == TPL_BACKEND_UNKNOWN)
+ /* if backend is unknown, try to find the best match from the list of supported types */
+ if (TPL_BACKEND_UNKNOWN == type)
type = __tpl_display_choose_backend(native_dpy);
- if (type == TPL_BACKEND_UNKNOWN)
+ /* if still not found, then there's no compatible display */
+ if (TPL_BACKEND_UNKNOWN == type)
+ {
+ TPL_ERR("Invalid backend type!");
return NULL;
+ }
display = (tpl_display_t *)calloc(1, sizeof(tpl_display_t));
- TPL_ASSERT(display != NULL);
+ if (NULL == display)
+ {
+ TPL_ERR("Failed to allocate memory for display!");
+ return NULL;
+ }
/* Initialize object base class. */
- __tpl_object_init(&display->base, TPL_OBJECT_DISPLAY, __tpl_display_free);
+ ret = __tpl_object_init(&display->base, TPL_OBJECT_DISPLAY, __tpl_display_free);
+ if (TPL_TRUE != ret)
+ {
+ TPL_ERR("Failed to initialize display's base class!");
+ free(display);
+ return NULL;
+ }
/* Initialize display object. */
display->native_handle = native_dpy;
if (!display->backend.init(display))
{
- tpl_object_unreference((tpl_object_t *)display);
+ TPL_ERR("Failed to initialize display's backend!");
+ tpl_object_unreference((tpl_object_t *) display);
return NULL;
}
/* Add it to the runtime. */
- __tpl_runtime_add_display(display);
+ ret = __tpl_runtime_add_display(display);
+ if (TPL_TRUE != ret)
+ {
+ TPL_ERR("Failed to add display to runtime list!");
+ tpl_object_unreference((tpl_object_t *) display);
+ return NULL;
+ }
return display;
}
tpl_bool_t
tpl_display_bind_client_display_handle(tpl_display_t *display, tpl_handle_t native_dpy)
{
- if (display->backend.bind_client_display_handle != NULL)
- return display->backend.bind_client_display_handle(display, native_dpy);
- return TPL_FALSE;
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.bind_client_display_handle)
+ {
+ TPL_ERR("display is invalid!");
+ return TPL_FALSE;
+ }
+
+ if (NULL == native_dpy)
+ {
+ TPL_ERR("native_dpy is NULL!");
+ return TPL_FALSE;
+ }
+
+ return display->backend.bind_client_display_handle(display, native_dpy);
}
tpl_bool_t
tpl_display_unbind_client_display_handle(tpl_display_t *display, tpl_handle_t native_dpy)
{
- if (display->backend.unbind_client_display_handle != NULL)
- return display->backend.unbind_client_display_handle(display, native_dpy);
- return TPL_FALSE;
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.unbind_client_display_handle)
+ {
+ TPL_ERR("display is invalid!");
+ return TPL_FALSE;
+ }
+
+ if (NULL == native_dpy)
+ {
+ TPL_ERR("native_dpy is NULL!");
+ return TPL_FALSE;
+ }
+
+ return display->backend.unbind_client_display_handle(display, native_dpy);
}
tpl_backend_type_t
tpl_display_get_backend_type(tpl_display_t *display)
{
- TPL_ASSERT(__tpl_object_is_valid(&display->base));
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base))
+ {
+ TPL_ERR("display is invalid!");
+ return TPL_BACKEND_UNKNOWN;
+ }
+
return display->backend.type;
}
int
tpl_display_get_bufmgr_fd(tpl_display_t *display)
{
- TPL_ASSERT(__tpl_object_is_valid(&display->base));
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base))
+ {
+ TPL_ERR("display is invalid!");
+ return -1;
+ }
+
return display->bufmgr_fd;
}
tpl_handle_t
tpl_display_get_native_handle(tpl_display_t *display)
{
- TPL_ASSERT(__tpl_object_is_valid(&display->base));
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base))
+ {
+ TPL_ERR("display is invalid!");
+ return NULL;
+ }
+
return display->native_handle;
}
int *native_visual_id,
tpl_bool_t *is_slow)
{
- TPL_ASSERT(__tpl_object_is_valid(&display->base));
- return display->backend.query_config(display,
- surface_type,
- red_size, green_size, blue_size, alpha_size,
- depth_size, native_visual_id, is_slow);
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.query_config)
+ {
+ TPL_ERR("display is invalid!");
+ return TPL_FALSE;
+ }
+
+ return display->backend.query_config(display, surface_type, red_size, green_size, blue_size, alpha_size, depth_size, native_visual_id, is_slow);
}
tpl_bool_t
-tpl_display_filter_config(tpl_display_t *display,
- int *visual_id,
- int alpha_size)
+tpl_display_filter_config(tpl_display_t *display, int *visual_id, int alpha_size)
{
- TPL_ASSERT(__tpl_object_is_valid(&display->base));
- if(display->backend.filter_config != NULL)
- return display->backend.filter_config(display, visual_id, alpha_size);
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base) || NULL == display->backend.filter_config)
+ {
+ TPL_ERR("display is invalid!");
+ return TPL_FALSE;
+ }
- return TPL_FALSE;
+ return display->backend.filter_config(display, visual_id, alpha_size);
}
void
}
void
-tpl_display_wait_native(tpl_display_t *dpy)
+tpl_display_wait_native(tpl_display_t *display)
{
- TPL_ASSERT(dpy != NULL);
+ if(NULL == display || TPL_TRUE != __tpl_object_is_valid(&display->base))
+ {
+ TPL_ERR("display is invalid!");
+ return;
+ }
- dpy->backend.wait_native(dpy);
-}
\ No newline at end of file
+ display->backend.wait_native(display);
+}
tpl_frame_t *frame;
frame = (tpl_frame_t *)calloc(1, sizeof(tpl_frame_t));
- TPL_ASSERT(frame != NULL);
+
+ __tpl_region_init(&frame->damage);
return frame;
}
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);
+ __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);
typedef enum
{
+ TPL_FRAME_ERROR = -1,
TPL_FRAME_STATE_INVALID,
TPL_FRAME_STATE_READY,
TPL_FRAME_STATE_QUEUED,
- TPL_FRAME_STATE_POSTED
+ TPL_FRAME_STATE_POSTED,
+ TPL_FRAME_MAX
} tpl_frame_state_t;
struct _tpl_frame
tpl_bool_t (*init)(tpl_surface_t *surface);
void (*fini)(tpl_surface_t *surface);
- void (*begin_frame)(tpl_surface_t *surface);
- void (*end_frame)(tpl_surface_t *surface);
+ tpl_bool_t (*begin_frame)(tpl_surface_t *surface);
+ 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);
tpl_buffer_backend_t backend;
};
-/* Object functions. */
-tpl_bool_t __tpl_object_is_valid(tpl_object_t *object);
-void __tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t free_func);
-void __tpl_object_lock(tpl_object_t *object);
-void __tpl_object_unlock(tpl_object_t *object);
+/*******************************************************************************
+* TPL object functions
+*******************************************************************************/
+
+/** brief check wether a TPL object is valid
+ * @param object the TPL object to check
+ * @return TPL_TRUE on success, TPL_FALSE on error
+ */
+tpl_bool_t __tpl_object_is_valid(tpl_object_t *object);
+
+/** brief initialize a TPL object
+ * @param object the TPL object to initialize
+ * @param type type of the TPL object
+ * @param free_func customized deallocation routine for this TPL object
+ * @return TPL_TRUE on success, TPL_FALSE on error
+ */
+tpl_bool_t __tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t free_func);
+
+/** brief destroy a TPL object
+ * @param object the TPL object to destroy
+ * @return TPL_TRUE on success, TPL_FALSE on error
+ * @warning this function is automatically called when the reference count reaches 0, therefore it should not be expliclity called
+ */
+tpl_bool_t __tpl_object_fini(tpl_object_t *object);
+
+/** brief lock a TPL object
+ * @param object the TPL object to lock
+ * @return TPL_TRUE on success, TPL_FALSE on error
+ */
+tpl_bool_t __tpl_object_lock(tpl_object_t *object);
+
+/** brief unlock a TPL object
+ * @param object the TPL object to unlock
+ */
+void __tpl_object_unlock(tpl_object_t *object);
/* Frame functions. */
tpl_frame_t * __tpl_frame_alloc();
/* Runtime functions. */
tpl_display_t * __tpl_runtime_find_display(tpl_backend_type_t type, tpl_handle_t native_display);
-void __tpl_runtime_add_display(tpl_display_t *display);
+tpl_bool_t __tpl_runtime_add_display(tpl_display_t *display);
void __tpl_runtime_remove_display(tpl_display_t *display);
void __tpl_runtime_flush_all_display();
void __tpl_buffer_init_backend_x11_dri2(tpl_buffer_backend_t *backend);
void __tpl_buffer_init_backend_x11_dri3(tpl_buffer_backend_t *backend);
-/* OS related functions */
-void tpl_util_sys_yield(void);
-int tpl_util_clz(int input);
+/* Region functions. */
+void __tpl_region_init(tpl_region_t *region);
+void __tpl_region_fini(tpl_region_t *region);
+tpl_region_t * __tpl_region_alloc();
+void __tpl_region_free(tpl_region_t **region);
+tpl_bool_t __tpl_region_is_empty(const tpl_region_t *region);
+tpl_bool_t __tpl_region_copy(tpl_region_t *dst, const tpl_region_t *src);
+tpl_bool_t __tpl_region_set_rects(tpl_region_t *region, int num_rects, const int *rects);
-int tpl_util_atomic_get(const tpl_util_atomic_uint * const atom);
-void tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val);
-int tpl_util_atomic_inc(tpl_util_atomic_uint * const atom );
-int tpl_util_atomic_dec(tpl_util_atomic_uint * const atom );
+/* OS related functions */
+void __tpl_util_sys_yield(void);
+int __tpl_util_clz(int input);
+
+/** brief get the atomic variable's value
+ * @param atom storage for the value to retrieve of
+ * @return value stored on success, 0 or error
+*/
+int __tpl_util_atomic_get(const tpl_util_atomic_uint * const atom);
+
+/** brief set the atomic variable's value
+ * @param atom storage for the value to set of
+ * @param val the value to set
+ * @return TPL_TRUE on succes, TPL_FALSE on error
+*/
+void __tpl_util_atomic_set(tpl_util_atomic_uint * const atom, unsigned int val);
+unsigned int __tpl_util_atomic_inc(tpl_util_atomic_uint * const atom );
+unsigned int __tpl_util_atomic_dec(tpl_util_atomic_uint * const atom );
/* Data structure functions */
-tpl_hlist_t * tpl_hashlist_create();
-void tpl_hashlist_destroy(tpl_hlist_t **list);
-tpl_bool_t tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data);
-void tpl_hashlist_delete(tpl_hlist_t *list, size_t key);
-void tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *));
-void * tpl_hashlist_lookup(tpl_hlist_t *list, size_t key);
+tpl_hlist_t * __tpl_hashlist_create();
+void __tpl_hashlist_destroy(tpl_hlist_t **list);
+tpl_bool_t __tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data);
+void __tpl_hashlist_delete(tpl_hlist_t *list, size_t key);
+void __tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *));
+void * __tpl_hashlist_lookup(tpl_hlist_t *list, size_t key);
#endif /* TPL_INTERNAL_H */
tpl_bool_t
__tpl_object_is_valid(tpl_object_t *object)
{
- return tpl_util_atomic_get(&object->reference) != 0;
+ if (NULL == object)
+ return TPL_FALSE;
+
+ return (0 != __tpl_util_atomic_get(&object->reference));
}
-void
+tpl_bool_t
__tpl_object_init(tpl_object_t *object, tpl_object_type_t type, tpl_free_func_t free_func)
{
+ TPL_ASSERT(object);
+ TPL_ASSERT(type >= 0 && type < TPL_OBJECT_MAX);
+
object->type = type;
object->free = free_func;
- tpl_util_atomic_set(&object->reference, 1);
- pthread_mutex_init(&object->mutex, NULL);
+
+ __tpl_util_atomic_set(&object->reference, 1);
+
+ if (0 != pthread_mutex_init(&object->mutex, NULL))
+ return TPL_FALSE;
+
+ return TPL_TRUE;
}
-void
+tpl_bool_t
__tpl_object_fini(tpl_object_t *object)
{
- pthread_mutex_destroy(&object->mutex);
+ TPL_ASSERT(object);
+
+ if (0 != pthread_mutex_destroy(&object->mutex))
+ return TPL_FALSE;
if (object->user_data.free)
object->user_data.free(object->user_data.data);
+
+ return TPL_TRUE;
}
-void
+tpl_bool_t
__tpl_object_lock(tpl_object_t *object)
{
- TPL_ASSERT(__tpl_object_is_valid(object));
- pthread_mutex_lock(&object->mutex);
+ TPL_ASSERT(object);
+
+ if (0 != pthread_mutex_lock(&object->mutex))
+ return TPL_FALSE;
+
+ return TPL_TRUE;
}
void
__tpl_object_unlock(tpl_object_t *object)
{
- TPL_ASSERT(__tpl_object_is_valid(object));
+ TPL_ASSERT(object);
+
pthread_mutex_unlock(&object->mutex);
}
int
tpl_object_reference(tpl_object_t *object)
{
- TPL_ASSERT(__tpl_object_is_valid(object));
- return (int) tpl_util_atomic_inc(&object->reference);
+ if (TPL_TRUE != __tpl_object_is_valid(object))
+ {
+ TPL_ERR("input object is invalid!");
+ return -1;
+ }
+
+ return (int) __tpl_util_atomic_inc(&object->reference);
}
int
tpl_object_unreference(tpl_object_t *object)
{
- int reference;
+ unsigned int reference;
- TPL_ASSERT(__tpl_object_is_valid(object));
+ if (TPL_TRUE != __tpl_object_is_valid(object))
+ {
+ TPL_ERR("input object is invalid!");
+ return -1;
+ }
- reference = (int)tpl_util_atomic_dec(&object->reference);
+ reference = __tpl_util_atomic_dec(&object->reference);
- if (reference == 0)
+ if (0 == reference)
{
__tpl_object_fini(object);
object->free(object);
}
- return reference;
+ return (int) reference;
}
int
tpl_object_get_reference(tpl_object_t *object)
{
- TPL_ASSERT(__tpl_object_is_valid(object));
- return (int)tpl_util_atomic_get(&object->reference);
+ if (TPL_TRUE != __tpl_object_is_valid(object))
+ {
+ TPL_ERR("input object is invalid!");
+ return -1;
+ }
+
+ return (int) __tpl_util_atomic_get(&object->reference);
}
tpl_object_type_t
tpl_object_get_type(tpl_object_t *object)
{
- TPL_ASSERT(__tpl_object_is_valid(object));
+ if (TPL_TRUE != __tpl_object_is_valid(object))
+ {
+ TPL_ERR("input object is invalid!");
+ return TPL_OBJECT_ERROR;
+ }
+
return object->type;
}
-void
+tpl_bool_t
tpl_object_set_user_data(tpl_object_t *object, void *data, tpl_free_func_t free_func)
{
- TPL_ASSERT(__tpl_object_is_valid(object));
+ if (TPL_TRUE != __tpl_object_is_valid(object))
+ {
+ TPL_ERR("input object is invalid!");
+ return TPL_FALSE;
+ }
__tpl_object_lock(object);
object->user_data.data = data;
object->user_data.free = free_func;
__tpl_object_unlock(object);
+
+ return TPL_TRUE;
}
void *
{
void *data;
- TPL_ASSERT(__tpl_object_is_valid(object));
+ if (TPL_TRUE != __tpl_object_is_valid(object))
+ {
+ TPL_ERR("input object is invalid!");
+ return NULL;
+ }
+
__tpl_object_lock(object);
data = object->user_data.data;
__tpl_object_unlock(object);
-#include "tpl_utils.h"
#include <string.h>
+#include "tpl_internal.h"
void
-tpl_region_init(tpl_region_t *region)
+__tpl_region_init(tpl_region_t *region)
{
+ TPL_ASSERT(region);
+
region->num_rects = 0;
/* tpl_region_t will initially provide TPL_MIN_REGION_RECTS number of
}
void
-tpl_region_fini(tpl_region_t *region)
+__tpl_region_fini(tpl_region_t *region)
{
+ TPL_ASSERT(region);
+ TPL_ASSERT(region->rects);
+
TPL_LOG(3, "region:%p {%d, %p, %p, %d}", region, region->num_rects, region->rects,
®ion->rects_static[0], region->num_rects_allocated);
- if (region != NULL && region->rects != NULL &&
- region->rects != ®ion->rects_static[0])
- {
+ if (region->rects != ®ion->rects_static[0])
free(region->rects);
- }
}
tpl_region_t *
-tpl_region_alloc()
+__tpl_region_alloc()
{
tpl_region_t *region;
- region = (tpl_region_t *)calloc(1, sizeof(tpl_region_t));
-
- if (region == NULL)
- {
- TPL_ASSERT(TPL_FALSE);
+ region = (tpl_region_t *) calloc(1, sizeof(tpl_region_t));
+ if (NULL == region)
return NULL;
- }
- tpl_region_init(region);
+ __tpl_region_init(region);
+
return region;
}
void
-tpl_region_free(tpl_region_t **region)
+__tpl_region_free(tpl_region_t **region)
{
- if (*region == NULL)
- return;
+ TPL_ASSERT(region);
+ TPL_ASSERT(*region);
- tpl_region_fini(*region);
+ __tpl_region_fini(*region);
free(*region);
+
*region = NULL;
}
tpl_bool_t
-tpl_region_is_empty(const tpl_region_t *region)
+__tpl_region_is_empty(const tpl_region_t *region)
{
+ TPL_ASSERT(region);
+
TPL_LOG(3, "region:%p {%d, %p, %p, %d}\n", region, region->num_rects,
region->rects, ®ion->rects_static[0], region->num_rects_allocated);
return (region->num_rects == 0);
}
-void
-tpl_region_copy(tpl_region_t *dst, const tpl_region_t *src)
+tpl_bool_t
+__tpl_region_copy(tpl_region_t *dst, const tpl_region_t *src)
{
- tpl_region_set_rects(dst, src->num_rects, src->rects);
+ TPL_ASSERT(src);
+ TPL_ASSERT(dst);
+
+ return __tpl_region_set_rects(dst, src->num_rects, src->rects);
}
-void
-tpl_region_set_rects(tpl_region_t *region, int num_rects, const int *rects)
+tpl_bool_t
+__tpl_region_set_rects(tpl_region_t *region, int num_rects, const int *rects)
{
+ TPL_ASSERT(region);
+ TPL_ASSERT(rects);
+ TPL_ASSERT(num_rects >= 0);
+
TPL_LOG(3, "region:%p {%d, %p, %p, %d}, num_rects:%d, rects:%p\n", region,
region->num_rects, region->rects, ®ion->rects_static[0],
region->num_rects_allocated, num_rects, rects);
if (region->rects != ®ion->rects_static[0])
free(region->rects);
- region->rects = (int *)malloc(num_rects * 4 * sizeof(int));
-
- if (region->rects == NULL)
- {
- TPL_ASSERT(TPL_FALSE);
- return;
- }
+ region->rects = (int *) malloc(num_rects * 4 * sizeof(int));
+ if (NULL == region->rects)
+ return TPL_FALSE;
region->num_rects_allocated = num_rects;
}
region->num_rects = num_rects;
- memcpy(region->rects, rects, num_rects * 4 * sizeof(int));
+
+ if (0 < num_rects)
+ memcpy(region->rects, rects, num_rects * 4 * sizeof(int));
+
+ return TPL_TRUE;
}
static void
__tpl_surface_fini(tpl_surface_t *surface)
{
- tpl_region_fini(&surface->damage);
- tpl_list_fini(&surface->frame_queue, (tpl_free_func_t)__tpl_frame_free);
+ TPL_ASSERT(surface);
+
+ __tpl_region_fini(&surface->damage);
+ __tpl_list_fini(&surface->frame_queue, (tpl_free_func_t) __tpl_frame_free);
if (surface->frame)
__tpl_frame_free(surface->frame);
static void
__tpl_surface_free(void *data)
{
- __tpl_surface_fini((tpl_surface_t *)data);
+ TPL_ASSERT(data);
+
+ __tpl_surface_fini((tpl_surface_t *) data);
free(data);
}
-static void
+static tpl_bool_t
__tpl_surface_enqueue_frame(tpl_surface_t *surface)
{
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->frame);
+
/* Set swap attributes. */
surface->frame->interval = surface->post_interval;
- tpl_region_copy(&surface->frame->damage, &surface->damage);
+ if (TPL_TRUE != __tpl_region_copy(&surface->frame->damage, &surface->damage))
+ return TPL_FALSE;
/* Enqueue the frame object. */
- tpl_list_push_back(&surface->frame_queue, surface->frame);
+ if (TPL_TRUE != __tpl_list_push_back(&surface->frame_queue, surface->frame))
+ return TPL_FALSE;
+
surface->frame->state = TPL_FRAME_STATE_QUEUED;
/* Reset surface frame to NULL. */
- surface->backend.end_frame(surface);
+ if (surface->backend.end_frame)
+ surface->backend.end_frame(surface);
+
surface->frame = NULL;
+
+ return TPL_TRUE;
}
tpl_frame_t *
__tpl_surface_get_latest_frame(tpl_surface_t *surface)
{
- if (tpl_list_is_empty(&surface->frame_queue))
+ TPL_ASSERT(surface);
+
+ if (__tpl_list_is_empty(&surface->frame_queue))
return NULL;
- return (tpl_frame_t *)tpl_list_get_back(&surface->frame_queue);
+ return (tpl_frame_t *) __tpl_list_get_back(&surface->frame_queue);
}
void
__tpl_surface_wait_all_frames(tpl_surface_t *surface)
{
- while (!tpl_list_is_empty(&surface->frame_queue))
+ TPL_ASSERT(surface);
+
+ while (!__tpl_list_is_empty(&surface->frame_queue))
{
TPL_OBJECT_UNLOCK(surface);
- tpl_util_sys_yield();
+ __tpl_util_sys_yield();
TPL_OBJECT_LOCK(surface);
}
}
{
tpl_surface_t *surface;
- TPL_ASSERT(display != NULL);
+ if (NULL == display)
+ {
+ TPL_ERR("Display is NULL!");
+ return NULL;
+ }
+
+ if (NULL == handle)
+ {
+ TPL_ERR("Handle is NULL!");
+ return NULL;
+ }
- surface = (tpl_surface_t *)calloc(1, sizeof(tpl_surface_t));
- TPL_ASSERT(surface != NULL);
+ surface = (tpl_surface_t *) calloc(1, sizeof(tpl_surface_t));
+ if (NULL == surface)
+ {
+ TPL_ERR("Failed to allocate memory for surface!");
+ return NULL;
+ }
TPL_LOG(3, "surface->damage:%p {%d, %p, %p, %d}\n", &surface->damage, surface->damage.num_rects,
surface->damage.rects, &surface->damage.rects_static[0], surface->damage.num_rects_allocated);
- __tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, __tpl_surface_free);
+ if (TPL_TRUE != __tpl_object_init(&surface->base, TPL_OBJECT_SURFACE, __tpl_surface_free))
+ {
+ TPL_ERR("Failed to initialize surface's base class!");
+ free(surface);
+ return NULL;
+ }
surface->display = display;
surface->native_handle = handle;
surface->frame = NULL;
surface->post_interval = 1;
- tpl_region_init(&surface->damage);
- tpl_list_init(&surface->frame_queue);
+ __tpl_region_init(&surface->damage);
+ __tpl_list_init(&surface->frame_queue);
/* Intialize backend. */
__tpl_surface_init_backend(surface, display->backend.type);
- if (!surface->backend.init(surface))
+ if (NULL == surface->backend.init || TPL_TRUE != surface->backend.init(surface))
{
+ TPL_ERR("Failed to initialize surface's backend!");
tpl_object_unreference(&surface->base);
return NULL;
}
tpl_display_t *
tpl_surface_get_display(tpl_surface_t *surface)
{
+ if (NULL == surface)
+ {
+ TPL_ERR("Surface is NULL!");
+ return NULL;
+ }
+
return surface->display;
}
tpl_handle_t
tpl_surface_get_native_handle(tpl_surface_t *surface)
{
+ if (NULL == surface)
+ {
+ TPL_ERR("Surface is NULL!");
+ return NULL;
+ }
+
return surface->native_handle;
}
tpl_surface_type_t
tpl_surface_get_type(tpl_surface_t *surface)
{
+ if (NULL == surface)
+ {
+ TPL_ERR("Surface is NULL!");
+ return TPL_SURFACE_ERROR;
+ }
+
return surface->type;
}
-void
+tpl_bool_t
tpl_surface_get_size(tpl_surface_t *surface, int *width, int *height)
{
+ if (NULL == surface)
+ {
+ TPL_ERR("Surface is NULL!");
+ return TPL_FALSE;
+ }
+
if (width)
*width = surface->width;
if (height)
*height = surface->height;
+
+ return TPL_TRUE;
}
-void
+tpl_bool_t
tpl_surface_begin_frame(tpl_surface_t *surface)
{
- TRACE_BEGIN("TPL:BEGINFRAME");
+ if (NULL == surface)
+ {
+ TPL_ERR("Surface is NULL!");
+ return TPL_FALSE;
+ }
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
+ if (TPL_SURFACE_TYPE_WINDOW != surface->type)
{
- TRACE_END();
- return;
+ TPL_ERR("Surface is not of type window!");
+ return TPL_FALSE;
}
+ TRACE_BEGIN("TPL:BEGINFRAME");
TPL_OBJECT_LOCK(surface);
/* Queue previous frame if it has not been queued. */
if (surface->frame)
- __tpl_surface_enqueue_frame(surface);
+ {
+ if (TPL_TRUE != __tpl_surface_enqueue_frame(surface))
+ {
+ TPL_OBJECT_UNLOCK(surface);
+ TRACE_END();
+ TPL_ERR("Failed to enqueue frame!");
+ return TPL_FALSE;
+ }
+ }
/* Allocate a new frame. */
surface->frame = __tpl_frame_alloc();
- TPL_ASSERT(surface->frame != NULL);
+ if (NULL == surface->frame)
+ {
+ TPL_OBJECT_UNLOCK(surface);
+ TRACE_END();
+ TPL_ERR("Failed to allocate frame!");
+ return TPL_FALSE;
+ }
surface->frame->state = TPL_FRAME_STATE_READY;
* it will be just removed from the queue. */
/* Let backend handle the new frame event. */
- surface->backend.begin_frame(surface);
+ if (surface->backend.begin_frame)
+ surface->backend.begin_frame(surface);
TPL_OBJECT_UNLOCK(surface);
TRACE_END();
+
+ return TPL_TRUE;
}
-void
+tpl_bool_t
tpl_surface_end_frame(tpl_surface_t *surface)
{
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
- return;
-
- TRACE_BEGIN("TPL:ENDFRAME");
- TPL_OBJECT_LOCK(surface);
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
+ {
+ TPL_ERR("Invalid surface!");
+ return TPL_FALSE;
+ }
TPL_LOG(3, "surface->frame:%p, surface->damage:%p, surface->frame->damage:%p",
surface->frame, &surface->damage, (surface->frame)?(&surface->frame->damage):NULL);
+ TRACE_BEGIN("TPL:ENDFRAME");
+ TPL_OBJECT_LOCK(surface);
+
if (surface->frame)
- __tpl_surface_enqueue_frame(surface);
+ {
+ if (TPL_TRUE != __tpl_surface_enqueue_frame(surface))
+ {
+ TPL_OBJECT_UNLOCK(surface);
+ TRACE_END();
+ TPL_ERR("Failed to enqueue frame!");
+ return TPL_FALSE;
+ }
+ }
TPL_OBJECT_UNLOCK(surface);
TRACE_END();
+
+ return TPL_TRUE;
}
tpl_bool_t
{
tpl_bool_t was_valid = TPL_TRUE;
- TRACE_BEGIN("TPL:VALIDATEFRAME");
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
+ {
+ TPL_ERR("Invalid surface!");
+ return TPL_FALSE;
+ }
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
- {
- TRACE_END();
- return was_valid;
- }
+ if (NULL == surface->frame)
+ {
+ TPL_ERR("Frame not registered in surface!");
+ return TPL_FALSE;
+ }
+ if (NULL == surface->backend.validate_frame)
+ {
+ TPL_ERR("Backend for surface has not been initialized!");
+ return TPL_FALSE;
+ }
+
+ TRACE_BEGIN("TPL:VALIDATEFRAME");
TPL_OBJECT_LOCK(surface);
- TPL_ASSERT(surface->frame != NULL);
if (!surface->backend.validate_frame(surface))
was_valid = TPL_FALSE;
TPL_OBJECT_UNLOCK(surface);
TRACE_END();
+
return was_valid;
}
-void
+tpl_bool_t
tpl_surface_set_post_interval(tpl_surface_t *surface, int interval)
{
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
- return;
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
+ {
+ TPL_ERR("Invalid surface!");
+ return TPL_FALSE;
+ }
TPL_OBJECT_LOCK(surface);
surface->post_interval = interval;
TPL_OBJECT_UNLOCK(surface);
+
+ return TPL_TRUE;
}
int
{
int interval;
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
- return 0;
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
+ {
+ TPL_ERR("Invalid surface!");
+ return -1;
+ }
TPL_OBJECT_LOCK(surface);
interval = surface->post_interval;
return interval;
}
-void
+tpl_bool_t
tpl_surface_set_damage(tpl_surface_t *surface, int num_rects, const int *rects)
{
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
- return;
+ tpl_bool_t ret;
+
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
+ {
+ TPL_ERR("Invalid surface!");
+ return TPL_FALSE;
+ }
TPL_OBJECT_LOCK(surface);
- tpl_region_set_rects(&surface->damage, num_rects, rects);
+ ret = __tpl_region_set_rects(&surface->damage, num_rects, rects);
TPL_OBJECT_UNLOCK(surface);
+
+ return ret;
}
-void
+tpl_bool_t
tpl_surface_get_damage(tpl_surface_t *surface, int *num_rects, const int **rects)
{
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
{
+ TPL_ERR("Invalid surface!");
*num_rects = 0;
*rects = NULL;
- return;
+ return TPL_FALSE;
}
TPL_OBJECT_LOCK(surface);
*num_rects = surface->damage.num_rects;
*rects = surface->damage.rects;
TPL_OBJECT_UNLOCK(surface);
+
+ return TPL_TRUE;
}
tpl_buffer_t *
{
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);
return buffer;
}
-int
+tpl_bool_t
tpl_surface_post(tpl_surface_t *surface)
{
tpl_frame_t *frame;
- TRACE_BEGIN("TPL:POST");
- if (surface->type != TPL_SURFACE_TYPE_WINDOW)
+ if (NULL == surface || TPL_SURFACE_TYPE_WINDOW != surface->type)
{
- TRACE_END();
+ TPL_ERR("Invalid surface!");
return TPL_FALSE;
}
- TPL_OBJECT_LOCK(surface);
-
TPL_LOG(3, "surface->frame:%p, surface->damage:%p, surface->frame->damage:%p",
surface->frame, &surface->damage, (surface->frame)?(&surface->frame->damage):NULL);
- if (tpl_list_is_empty(&surface->frame_queue))
+ TRACE_BEGIN("TPL:POST");
+ TPL_OBJECT_LOCK(surface);
+
+ if (__tpl_list_is_empty(&surface->frame_queue))
{
/* Queue is empty and swap is called.
* This means that current frame is not enqueued yet
* and there's no pending frames.
* So, this post is for the current frame. */
- TPL_ASSERT(surface->frame != NULL);
-
- __tpl_surface_enqueue_frame(surface);
+ if (NULL == surface->frame)
+ {
+ TPL_OBJECT_UNLOCK(surface);
+ TRACE_END();
+ TPL_ERR("Frame not registered in surface!");
+ return TPL_FALSE;
+ }
+
+ if (TPL_TRUE != __tpl_surface_enqueue_frame(surface))
+ {
+ TPL_OBJECT_UNLOCK(surface);
+ TRACE_END();
+ TPL_ERR("Failed to enqueue frame!");
+ return TPL_FALSE;
+ }
}
/* Dequeue a frame from the queue. */
- frame = (tpl_frame_t *)tpl_list_pop_front(&surface->frame_queue, NULL);
+ frame = (tpl_frame_t *) __tpl_list_pop_front(&surface->frame_queue, NULL);
+
+ if (NULL == frame)
+ {
+ TPL_OBJECT_UNLOCK(surface);
+ TRACE_END();
+ TPL_ERR("Frame to post received from the queue is invalid!");
+ return TPL_FALSE;
+ }
if (frame->buffer == NULL)
{
__tpl_frame_free(frame);
TPL_OBJECT_UNLOCK(surface);
TRACE_END();
-
+ TPL_ERR("Buffer not initialized for frame!");
return TPL_FALSE;
}
/* Call backend post if it has not been called for the frame. */
- if (frame->state != TPL_FRAME_STATE_POSTED)
+ if (TPL_FRAME_STATE_POSTED != frame->state)
surface->backend.post(surface, frame);
__tpl_frame_free(frame);
#define TRACE_MARK(name,...)
#endif
-#define TPL_DEBUG 1
-#if TPL_DEBUG
+#ifndef NDEBUG
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
typedef struct _tpl_list tpl_list_t;
typedef struct _tpl_region tpl_region_t;
-enum _tpl_occurance
+enum _tpl_occurrence
{
TPL_FIRST,
TPL_LAST,
};
static TPL_INLINE int
-tpl_list_get_count(const tpl_list_t *list)
+__tpl_list_get_count(const tpl_list_t *list)
{
+ TPL_ASSERT(list);
+
return list->count;
}
static TPL_INLINE tpl_bool_t
-tpl_list_is_empty(const tpl_list_t *list)
+__tpl_list_is_empty(const tpl_list_t *list)
{
+ TPL_ASSERT(list);
+
return list->count == 0;
}
static TPL_INLINE void
-tpl_list_init(tpl_list_t *list)
+__tpl_list_init(tpl_list_t *list)
{
+ TPL_ASSERT(list);
+
list->head.list = list;
list->tail.list = list;
}
static TPL_INLINE void
-tpl_list_fini(tpl_list_t *list, tpl_free_func_t func)
+__tpl_list_fini(tpl_list_t *list, tpl_free_func_t func)
{
- tpl_list_node_t *node = list->head.next;
+ tpl_list_node_t *node;
+
+ TPL_ASSERT(list);
+
+ node = list->head.next;
while (node != &list->tail)
{
tpl_list_node_t *free_node = node;
node = node->next;
+ TPL_ASSERT(free_node);
+
if (func)
func(free_node->data);
free(free_node);
}
- tpl_list_init(list);
+ __tpl_list_init(list);
}
static TPL_INLINE tpl_list_t *
-tpl_list_alloc()
+__tpl_list_alloc()
{
tpl_list_t *list;
- list = (tpl_list_t *)malloc(sizeof(tpl_list_t));
- TPL_ASSERT(list != NULL);
+ list = (tpl_list_t *) malloc(sizeof(tpl_list_t));
+ if (NULL == list)
+ return NULL;
- tpl_list_init(list);
+ __tpl_list_init(list);
return list;
}
static TPL_INLINE void
-tpl_list_free(tpl_list_t *list, tpl_free_func_t func)
+__tpl_list_free(tpl_list_t *list, tpl_free_func_t func)
{
- tpl_list_fini(list, func);
+ TPL_ASSERT(list);
+
+ __tpl_list_fini(list, func);
free(list);
}
static TPL_INLINE void *
-tpl_list_node_get_data(const tpl_list_node_t *node)
+__tpl_list_node_get_data(const tpl_list_node_t *node)
{
+ TPL_ASSERT(node);
+
return node->data;
}
static TPL_INLINE tpl_list_node_t *
-tpl_list_get_front_node(tpl_list_t *list)
+__tpl_list_get_front_node(tpl_list_t *list)
{
- if (tpl_list_is_empty(list))
+ TPL_ASSERT(list);
+
+ if (__tpl_list_is_empty(list))
return NULL;
return list->head.next;
}
static TPL_INLINE tpl_list_node_t *
-tpl_list_get_back_node(tpl_list_t *list)
+__tpl_list_get_back_node(tpl_list_t *list)
{
- if (tpl_list_is_empty(list))
+ TPL_ASSERT(list);
+
+ if (__tpl_list_is_empty(list))
return NULL;
return list->tail.prev;
}
static TPL_INLINE tpl_list_node_t *
-tpl_list_node_prev(tpl_list_node_t *node)
+__tpl_list_node_prev(tpl_list_node_t *node)
{
+ TPL_ASSERT(node);
+ TPL_ASSERT(node->list);
+
if (node->prev != &node->list->head)
return (tpl_list_node_t *)node->prev;
}
static TPL_INLINE tpl_list_node_t *
-tpl_list_node_next(tpl_list_node_t *node)
+__tpl_list_node_next(tpl_list_node_t *node)
{
+ TPL_ASSERT(node);
+ TPL_ASSERT(node->list);
+
if (node->next != &node->list->tail)
return node->next;
}
static TPL_INLINE void *
-tpl_list_get_front(const tpl_list_t *list)
+__tpl_list_get_front(const tpl_list_t *list)
{
- if (tpl_list_is_empty(list))
+ TPL_ASSERT(list);
+
+ if (__tpl_list_is_empty(list))
return NULL;
+ TPL_ASSERT(list->head.next);
+
return list->head.next->data;
}
static TPL_INLINE void *
-tpl_list_get_back(const tpl_list_t *list)
+__tpl_list_get_back(const tpl_list_t *list)
{
- if (tpl_list_is_empty(list))
+ TPL_ASSERT(list);
+
+ if (__tpl_list_is_empty(list))
return NULL;
+ TPL_ASSERT(list->tail.prev);
+
return list->tail.prev->data;
}
static TPL_INLINE void
-tpl_list_remove(tpl_list_node_t *node, tpl_free_func_t func)
+__tpl_list_remove(tpl_list_node_t *node, tpl_free_func_t func)
{
+ TPL_ASSERT(node);
+ TPL_ASSERT(node->prev);
+ TPL_ASSERT(node->next);
+
node->prev->next = node->next;
node->next->prev = node->prev;
free(node);
}
-static TPL_INLINE void
-tpl_list_insert(tpl_list_node_t *pos, void *data)
+static TPL_INLINE tpl_bool_t
+__tpl_list_insert(tpl_list_node_t *pos, void *data)
{
tpl_list_node_t *node = (tpl_list_node_t *)malloc(sizeof(tpl_list_node_t));
- TPL_ASSERT(node != NULL);
+ if (NULL == node)
+ return TPL_FALSE;
node->data = data;
node->list = pos->list;
node->prev = pos;
pos->list->count++;
+
+ return TPL_TRUE;
}
static TPL_INLINE void
-tpl_list_remove_data(tpl_list_t *list, void *data, int occurance, tpl_free_func_t func)
+__tpl_list_remove_data(tpl_list_t *list, void *data, int occurrence, tpl_free_func_t func)
{
tpl_list_node_t *node;
- if (occurance == TPL_FIRST)
+ TPL_ASSERT(list);
+
+ if (occurrence == TPL_FIRST)
{
node = list->head.next;
while (node != &list->tail)
{
- tpl_list_node_t *curr = node;
+ tpl_list_node_t *curr;
+
+ curr = node;
node = node->next;
+ TPL_ASSERT(curr);
+ TPL_ASSERT(node);
+
if (curr->data == data)
{
if (func)
func(data);
- tpl_list_remove(curr, func);
+ __tpl_list_remove(curr, func);
return;
}
}
}
- else if (occurance == TPL_LAST)
+ else if (occurrence == TPL_LAST)
{
node = list->tail.prev;
while (node != &list->head)
{
- tpl_list_node_t *curr = node;
+ tpl_list_node_t *curr;
+
+ curr = node;
node = node->prev;
+ TPL_ASSERT(curr);
+ TPL_ASSERT(node);
+
if (curr->data == data)
{
if (func)
func(data);
- tpl_list_remove(curr, func);
+ __tpl_list_remove(curr, func);
return;
}
}
}
- else if (occurance == TPL_ALL)
+ else if (occurrence == TPL_ALL)
{
node = list->head.next;
while (node != &list->tail)
{
- tpl_list_node_t *curr = node;
+ tpl_list_node_t *curr;
+
+ curr = node;
node = node->next;
+ TPL_ASSERT(curr);
+ TPL_ASSERT(node);
+
if (curr->data == data)
{
if (func)
func(data);
- tpl_list_remove(curr, func);
+ __tpl_list_remove(curr, func);
}
}
}
}
static TPL_INLINE void
-tpl_list_push_front(tpl_list_t *list, void *data)
+__tpl_list_push_front(tpl_list_t *list, void *data)
{
- tpl_list_insert(&list->head, data);
+ TPL_ASSERT(list);
+
+ __tpl_list_insert(&list->head, data);
}
-static TPL_INLINE void
-tpl_list_push_back(tpl_list_t *list, void *data)
+static TPL_INLINE tpl_bool_t
+__tpl_list_push_back(tpl_list_t *list, void *data)
{
- tpl_list_insert(list->tail.prev, data);
+ TPL_ASSERT(list);
+
+ return __tpl_list_insert(list->tail.prev, data);
}
static TPL_INLINE void *
-tpl_list_pop_front(tpl_list_t *list, tpl_free_func_t func)
+__tpl_list_pop_front(tpl_list_t *list, tpl_free_func_t func)
{
- void *data;
+ void *data;
- if (tpl_list_is_empty(list))
+ TPL_ASSERT(list);
+
+ if (__tpl_list_is_empty(list))
return NULL;
data = list->head.next->data;
- tpl_list_remove(list->head.next, func);
+ __tpl_list_remove(list->head.next, func);
return data;
}
static TPL_INLINE void *
tpl_list_pop_back(tpl_list_t *list, tpl_free_func_t func)
{
- void *data;
+ void *data;
- if (tpl_list_is_empty(list))
+ TPL_ASSERT(list);
+
+ if (__tpl_list_is_empty(list))
return NULL;
data = list->tail.prev->data;
- tpl_list_remove(list->tail.prev, func);
+ __tpl_list_remove(list->tail.prev, func);
return data;
}
-/* Region functions. */
-void tpl_region_init(tpl_region_t *region);
-void tpl_region_fini(tpl_region_t *region);
-tpl_region_t * tpl_region_alloc();
-void tpl_region_free(tpl_region_t **region);
-tpl_bool_t tpl_region_is_empty(const tpl_region_t *region);
-void tpl_region_copy(tpl_region_t *dst, const tpl_region_t *src);
-void tpl_region_set_rects(tpl_region_t *region, int num_rects, const int *rects);
-
#endif /* TPL_UTILS_H */
}
/* Definitions for exposed hash list functions */
-tpl_hlist_t * tpl_hashlist_create()
+tpl_hlist_t * __tpl_hashlist_create()
{
tpl_hlist_t *list;
return list;
}
-void tpl_hashlist_destroy(tpl_hlist_t **list)
+void __tpl_hashlist_destroy(tpl_hlist_t **list)
{
int i;
tpl_hlist_node_t *pos;
*list = NULL;
}
-tpl_bool_t tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data)
+tpl_bool_t __tpl_hashlist_insert(tpl_hlist_t *list, size_t key, void *data)
{
size_t hash;
tpl_hlist_node_t *prev_node;
return TPL_TRUE;
}
-void tpl_hashlist_delete(tpl_hlist_t *list, size_t key)
+void __tpl_hashlist_delete(tpl_hlist_t *list, size_t key)
{
tpl_hlist_node_t *node;
free(node);
}
-void tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *))
+void __tpl_hashlist_do_for_all_nodes(tpl_hlist_t *list, void (*cb_func)(void *))
{
tpl_hlist_node_t *pos;
size_t hidx;
}
}
-void * tpl_hashlist_lookup(tpl_hlist_t *list, size_t key)
+void * __tpl_hashlist_lookup(tpl_hlist_t *list, size_t key)
{
tpl_hlist_node_t *node;
#endif
#define TPL_BUFFER_CACHE_MAX_ENTRIES 40
-static TPL_INLINE void
+static TPL_INLINE tpl_bool_t
__tpl_wayland_surface_buffer_cache_add(tpl_list_t *buffer_cache, tpl_buffer_t *buffer)
{
tpl_buffer_t *evict = NULL;
- if (tpl_list_get_count(buffer_cache) >= TPL_BUFFER_CACHE_MAX_ENTRIES)
+ TPL_ASSERT(buffer_cache);
+ TPL_ASSERT(buffer);
+
+ if (__tpl_list_get_count(buffer_cache) >= TPL_BUFFER_CACHE_MAX_ENTRIES)
{
- evict = tpl_list_pop_front(buffer_cache, NULL);
+ evict = __tpl_list_pop_front(buffer_cache, NULL);
+
+ TPL_ASSERT(evict);
tpl_object_unreference(&evict->base);
}
- tpl_object_reference(&buffer->base);
- tpl_list_push_back(buffer_cache, (void *)buffer);
-
TPL_LOG(3, "buf:%10p buf->base:%10p evict:%10p", buffer, &buffer->base, evict);
+
+ if (-1 == tpl_object_reference(&buffer->base))
+ return TPL_FALSE;
+
+ return __tpl_list_push_back(buffer_cache, (void *)buffer);
}
static TPL_INLINE void
__tpl_wayland_surface_buffer_cache_remove(tpl_list_t *buffer_cache, size_t name)
{
- tpl_list_node_t *node = tpl_list_get_front_node(buffer_cache);
+ tpl_list_node_t *node;
+
+ TPL_ASSERT(buffer_cache);
+
+ node = __tpl_list_get_front_node(buffer_cache);
while (node)
{
- tpl_buffer_t *buffer = (tpl_buffer_t *)tpl_list_node_get_data(node);
+ tpl_buffer_t *buffer = (tpl_buffer_t *)__tpl_list_node_get_data(node);
+
+ TPL_ASSERT(buffer);
if (buffer->key == name)
{
tpl_object_unreference(&buffer->base);
- tpl_list_remove(node, NULL);
+ __tpl_list_remove(node, NULL);
TPL_LOG(3, "name:%zu buf:%10p buf->base:%10p", name, buffer, &buffer->base);
return;
}
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
TPL_LOG(3, "Buffer named %zu not found in cache", name);
static TPL_INLINE tpl_buffer_t *
__tpl_wayland_surface_buffer_cache_find(tpl_list_t *buffer_cache, size_t name)
{
- tpl_list_node_t *node = tpl_list_get_front_node(buffer_cache);
+ tpl_list_node_t *node;
+
+ TPL_ASSERT(buffer_cache);
+
+ node = __tpl_list_get_front_node(buffer_cache);
while (node)
{
- tpl_buffer_t *buffer = (tpl_buffer_t *)tpl_list_node_get_data(node);
+ tpl_buffer_t *buffer = (tpl_buffer_t *)__tpl_list_node_get_data(node);
+
+ TPL_ASSERT(buffer);
if (buffer->key == name)
{
return buffer;
}
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
TPL_LOG(3, "Buffer named %zu not found in cache", name);
static TPL_INLINE tpl_bool_t
__tpl_wayland_display_is_wl_display(tpl_handle_t native_dpy)
{
+ TPL_ASSERT(native_dpy);
+
/* MAGIC CHECK: A native display handle is a wl_display if the de-referenced first value
is a memory address pointing the structure of wl_display_interface. */
- if (*(void **)native_dpy == &wl_display_interface) return TPL_TRUE;
+ if (*(void **)native_dpy == &wl_display_interface)
+ return TPL_TRUE;
+
return TPL_FALSE;
}
static TPL_INLINE tpl_bool_t
__tpl_wayland_display_is_gbm_device(tpl_handle_t native_dpy)
{
+ TPL_ASSERT(native_dpy);
+
/* MAGIC CHECK: A native display handle is a gbm_device if the de-referenced first value
is a memory address pointing gbm_create_surface(). */
- if (*(void **)native_dpy == gbm_create_device) return TPL_TRUE;
+ if (*(void **)native_dpy == gbm_create_device)
+ return TPL_TRUE;
+
return TPL_FALSE;
}
static int
__tpl_wayland_display_roundtrip(tpl_display_t *display)
{
- struct wl_display *wl_dpy = (struct wl_display *)display->native_handle;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ struct wl_display *wl_dpy;
+ tpl_wayland_display_t *wayland_display;
struct wl_callback *callback;
int done = 0, ret = 0;
+ TPL_ASSERT(display);
+ TPL_ASSERT(display->native_handle);
+ TPL_ASSERT(display->backend.data);
+
+ wl_dpy = (struct wl_display *) display->native_handle;
+ wayland_display = (tpl_wayland_display_t *) display->backend.data;
+
callback = wl_display_sync(wl_dpy);
wl_callback_add_listener(callback, &sync_listener, &done);
- wl_proxy_set_queue((struct wl_proxy *)callback, wayland_display->proc.app.wl_queue);
+ wl_proxy_set_queue((struct wl_proxy *) callback, wayland_display->proc.app.wl_queue);
+
while (ret != -1 && !done)
{
ret = wl_display_dispatch_queue(wl_dpy, wayland_display->proc.app.wl_queue);
}
+
return ret;
}
{
tpl_wayland_display_t *wayland_display = NULL;
+ TPL_ASSERT(display);
+
/* Do not allow default display in wayland. */
if (display->native_handle == NULL)
return TPL_FALSE;
- wayland_display = (tpl_wayland_display_t *)calloc(1, sizeof(tpl_wayland_display_t));
+ wayland_display = (tpl_wayland_display_t *) calloc(1, sizeof(tpl_wayland_display_t));
if (wayland_display == NULL)
return TPL_FALSE;
display->backend.data = wayland_display;
-
display->bufmgr_fd = -1;
if (__tpl_wayland_display_is_wl_display(display->native_handle))
struct wl_display *wl_dpy = (struct wl_display *)display->native_handle;
wayland_display->proc.app.wl_queue = wl_display_create_queue(wl_dpy);
+ if (NULL == wayland_display->proc.app.wl_queue)
+ goto free_wl_display;
+
wayland_display->proc.app.wl_registry = wl_display_get_registry(wl_dpy);
+ if (NULL == wayland_display->proc.app.wl_registry)
+ goto destroy_queue;
+
wl_proxy_set_queue((struct wl_proxy *)wayland_display->proc.app.wl_registry, wayland_display->proc.app.wl_queue);
- wl_registry_add_listener(wayland_display->proc.app.wl_registry, ®istry_listener, display);
+ if (0 != wl_registry_add_listener(wayland_display->proc.app.wl_registry, ®istry_listener, display))
+ goto reset_queue;
/* Initialization roundtrip steps */
- if (__tpl_wayland_display_roundtrip(display) < 0 || wayland_display->wl_drm == NULL) goto error;
- if (__tpl_wayland_display_roundtrip(display) < 0 || display->bufmgr_fd == -1) goto error;
- if (__tpl_wayland_display_roundtrip(display) < 0 || wayland_display->proc.app.authenticated == TPL_FALSE) goto error;
+ if (__tpl_wayland_display_roundtrip(display) < 0 || wayland_display->wl_drm == NULL)
+ goto reset_queue;
+ if (__tpl_wayland_display_roundtrip(display) < 0 || display->bufmgr_fd == -1)
+ goto reset_queue;
+ if (__tpl_wayland_display_roundtrip(display) < 0 || wayland_display->proc.app.authenticated == TPL_FALSE)
+ goto reset_queue;
wayland_display->bufmgr = tbm_bufmgr_init(display->bufmgr_fd);
+ if (NULL == wayland_display->bufmgr)
+ goto reset_queue;
}
else if (__tpl_wayland_display_is_gbm_device(display->native_handle))
{
gbm_tbm_device_set_callback_surface_lock_front_buffer(gbm_tbm, __cb_server_gbm_surface_lock_front_buffer);
gbm_tbm_device_set_callback_surface_release_buffer(gbm_tbm, __cb_server_gbm_surface_release_buffer);
- tpl_list_init(&wayland_display->proc.comp.cached_buffers);
+ __tpl_list_init(&wayland_display->proc.comp.cached_buffers);
}
else
- goto error;
+ goto free_wl_display;
return TPL_TRUE;
-error:
+reset_queue:
+ wl_proxy_set_queue((struct wl_proxy *) wayland_display->proc.app.wl_registry, NULL);
+destroy_queue:
+ wl_event_queue_destroy(wayland_display->proc.app.wl_queue);
+free_wl_display:
if (wayland_display != NULL)
{
free(wayland_display);
static void
__tpl_wayland_display_fini(tpl_display_t *display)
{
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_wayland_display_t *wayland_display;
+
+ TPL_ASSERT(display);
+ wayland_display = (tpl_wayland_display_t *)display->backend.data;
if (wayland_display != NULL)
{
if (__tpl_wayland_display_is_wl_display(display->native_handle))
gbm_tbm_device_set_callback_surface_lock_front_buffer(gbm_tbm, NULL);
gbm_tbm_device_set_callback_surface_release_buffer(gbm_tbm, NULL);
- tpl_list_fini(&wayland_display->proc.comp.cached_buffers, (tpl_free_func_t) tpl_object_unreference);
+ __tpl_list_fini(&wayland_display->proc.comp.cached_buffers, (tpl_free_func_t) tpl_object_unreference);
}
free(wayland_display);
int red_size, int green_size, int blue_size, int alpha_size,
int color_depth, int *native_visual_id, tpl_bool_t *is_slow)
{
+ TPL_ASSERT(display);
+
if (surface_type == TPL_SURFACE_TYPE_WINDOW &&
red_size == 8 &&
green_size == 8 &&
{
TPL_IGNORE(display);
- if (*visual_id == GBM_FORMAT_ARGB8888 && alpha_size == 0)
+ if (visual_id != NULL && *visual_id == GBM_FORMAT_ARGB8888 && alpha_size == 0)
{
*visual_id = GBM_FORMAT_XRGB8888;
return TPL_TRUE;
__tpl_wayland_display_get_window_info(tpl_display_t *display, tpl_handle_t window,
int *width, int *height, tpl_format_t *format, int depth, int a_size)
{
+ TPL_ASSERT(display);
+ TPL_ASSERT(window);
+
if (__tpl_wayland_display_is_wl_display(display->native_handle))
{
struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)window;
__tpl_wayland_display_get_pixmap_info(tpl_display_t *display, tpl_handle_t pixmap,
int *width, int *height, tpl_format_t *format)
{
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_wayland_display_t *wayland_display;
struct wl_drm_buffer *drm_buffer = NULL;
+ TPL_ASSERT(display);
+ TPL_ASSERT(display->backend.data);
+
+ wayland_display = (tpl_wayland_display_t *)display->backend.data;
+
if (wayland_display->wl_drm == NULL)
return TPL_FALSE;
drm_buffer = wayland_drm_buffer_get(wayland_display->wl_drm, (struct wl_resource *)pixmap);
-
if (drm_buffer != NULL)
{
if (format != NULL)
tpl_wayland_surface_t *wayland_surface = NULL;
int i;
- wayland_surface = (tpl_wayland_surface_t *)calloc(1, sizeof(tpl_wayland_surface_t));
- TPL_CHECK_ON_NULL_RETURN_VAL(wayland_surface, TPL_FALSE);
+ TPL_ASSERT(surface);
+
+ wayland_surface = (tpl_wayland_surface_t *) calloc(1, sizeof(tpl_wayland_surface_t));
+ if (NULL == wayland_surface)
+ return TPL_FALSE;
surface->backend.data = (void *)wayland_surface;
- tpl_list_init(&wayland_surface->able_rendering_queue);
- tpl_list_init(&wayland_surface->done_rendering_queue);
+ __tpl_list_init(&wayland_surface->able_rendering_queue);
+ __tpl_list_init(&wayland_surface->done_rendering_queue);
if (surface->type == TPL_SURFACE_TYPE_WINDOW)
{
/* Create renderable buffer queue. Fill with empty(=NULL) buffers. */
for (i = 0; i < TPL_BUFFER_ALLOC_SIZE_APP; i++)
{
- tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL);
+ if (TPL_TRUE != __tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL))
+ goto error;
}
}
if (__tpl_wayland_display_is_gbm_device(surface->display->native_handle))
/* Create renderable buffer queue. Fill with empty(=NULL) buffers. */
for (i = 0; i < TPL_BUFFER_ALLOC_SIZE_COMPOSITOR; i++)
{
- tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL);
+ if (TPL_TRUE != __tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL))
+ goto error;
}
}
- __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
- &surface->width, &surface->height, NULL, 0, 0);
+ if (TPL_TRUE != __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
+ &surface->width, &surface->height, NULL, 0, 0))
+ goto error;
TPL_LOG(3, "window(%p, %p) %dx%d", surface, surface->native_handle, surface->width, surface->height);
return TPL_TRUE;
}
-
- if (surface->type == TPL_SURFACE_TYPE_PIXMAP)
+ else if (surface->type == TPL_SURFACE_TYPE_PIXMAP)
{
- __tpl_wayland_display_get_pixmap_info(surface->display, surface->native_handle,
- &surface->width, &surface->height, NULL);
+ if (TPL_TRUE != __tpl_wayland_display_get_pixmap_info(surface->display, surface->native_handle,
+ &surface->width, &surface->height, NULL))
+ goto error;
+
return TPL_TRUE;
}
+error:
+ __tpl_list_free(&wayland_surface->able_rendering_queue, NULL);
+ free(wayland_surface);
+
return TPL_FALSE;
}
if (buffer != NULL)
{
__tpl_buffer_set_surface(buffer, NULL);
- tpl_object_unreference((tpl_object_t *)buffer);
+ tpl_object_unreference((tpl_object_t *) buffer);
}
}
static void
__tpl_wayland_surface_fini(tpl_surface_t *surface)
{
- tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
+ tpl_wayland_surface_t *wayland_surface;
+
+ TPL_ASSERT(surface);
+
+ wayland_surface = (tpl_wayland_surface_t *) surface->backend.data;
+ if (NULL == wayland_surface)
+ return;
- TPL_CHECK_ON_NULL_RETURN(wayland_surface);
TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle);
- while (!tpl_list_is_empty(&surface->frame_queue))
+ while (!__tpl_list_is_empty(&surface->frame_queue))
{
- tpl_util_sys_yield();
+ __tpl_util_sys_yield();
}
- if (wayland_surface != NULL)
- {
- TPL_LOG(3, "free buffers able(%d), current:%d, done:%d",
- tpl_list_get_count(&wayland_surface->able_rendering_queue),
- wayland_surface->current_rendering_buffer?1:0,
- tpl_list_get_count(&wayland_surface->done_rendering_queue));
+ TPL_LOG(3, "free buffers able(%d), current:%d, done:%d",
+ __tpl_list_get_count(&wayland_surface->able_rendering_queue),
+ wayland_surface->current_rendering_buffer?1:0,
+ __tpl_list_get_count(&wayland_surface->done_rendering_queue));
- tpl_list_fini(&wayland_surface->able_rendering_queue, (tpl_free_func_t)__tpl_wayland_surface_buffer_free);
+ __tpl_list_fini(&wayland_surface->able_rendering_queue, (tpl_free_func_t)__tpl_wayland_surface_buffer_free);
+ if (wayland_surface->current_rendering_buffer)
__tpl_wayland_surface_buffer_free(wayland_surface->current_rendering_buffer);
- tpl_list_fini(&wayland_surface->done_rendering_queue, (tpl_free_func_t)__tpl_wayland_surface_buffer_free);
+ __tpl_list_fini(&wayland_surface->done_rendering_queue, (tpl_free_func_t)__tpl_wayland_surface_buffer_free);
- if (surface->type == TPL_SURFACE_TYPE_WINDOW)
+ if (surface->type == TPL_SURFACE_TYPE_WINDOW)
+ {
+ if (__tpl_wayland_display_is_wl_display(surface->display->native_handle))
{
- if (__tpl_wayland_display_is_wl_display(surface->display->native_handle))
- {
- struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle;
- wl_egl_window->private = NULL;
+ struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)surface->native_handle;
- /* Detach all pending buffers */
- if (wl_egl_window->surface && wl_egl_window->width == wl_egl_window->attached_width &&
- wl_egl_window->height == wl_egl_window->attached_height)
- {
- wl_surface_attach(wl_egl_window->surface, NULL, 0, 0);
- wl_surface_commit(wl_egl_window->surface);
- }
+ TPL_ASSERT(wl_egl_window);
+ /* TPL_ASSERT(wl_egl_window->surface); */ /* to be enabled once evas/gl patch is in place */
- wl_display_flush(surface->display->native_handle);
- __tpl_wayland_display_roundtrip(surface->display);
- }
+ wl_egl_window->private = NULL;
- if (__tpl_wayland_display_is_gbm_device(surface->display->native_handle))
+ /* Detach all pending buffers */
+ if (wl_egl_window->surface && /* if-statement to be removed once evas/gl patch is in place */
+ wl_egl_window->width == wl_egl_window->attached_width &&
+ wl_egl_window->height == wl_egl_window->attached_height)
{
- struct gbm_surface *gbm_surface = surface->native_handle;
- struct gbm_tbm_surface *gbm_tbm_surface = (struct gbm_tbm_surface *)gbm_surface;
-
- gbm_tbm_surface_set_user_data(gbm_tbm_surface, NULL);
+ wl_surface_attach(wl_egl_window->surface, NULL, 0, 0);
+ wl_surface_commit(wl_egl_window->surface);
}
+
+ wl_display_flush(surface->display->native_handle);
+ __tpl_wayland_display_roundtrip(surface->display);
}
- free(wayland_surface);
+ if (__tpl_wayland_display_is_gbm_device(surface->display->native_handle))
+ {
+ struct gbm_surface *gbm_surface = surface->native_handle;
+ struct gbm_tbm_surface *gbm_tbm_surface = (struct gbm_tbm_surface *)gbm_surface;
+
+ gbm_tbm_surface_set_user_data(gbm_tbm_surface, NULL);
+ }
}
+
+ free(wayland_surface);
surface->backend.data = NULL;
}
static void
__tpl_wayland_surface_post(tpl_surface_t *surface, tpl_frame_t *frame)
{
- TPL_ASSERT(frame->buffer != NULL);
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+ TPL_ASSERT(surface->display->native_handle);
+ TPL_ASSERT(frame);
+ TPL_ASSERT(frame->buffer);
+
TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle);
if (__tpl_wayland_display_is_wl_display(surface->display->native_handle))
int i;
TPL_LOG(3, "\t buffer(%p, %p) key:%zu", frame->buffer, wayland_buffer->proc.app.wl_resource, frame->buffer->key);
+
wl_egl_window = (struct wl_egl_window *)surface->native_handle;
+
tpl_object_reference((tpl_object_t *)frame->buffer);
wl_surface_attach(wl_egl_window->surface,
(void *)wayland_buffer->proc.app.wl_resource,
}
}
-static void
+static tpl_bool_t
__tpl_wayland_surface_begin_frame(tpl_surface_t *surface)
{
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)surface->display->backend.data;
- tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
+ tpl_wayland_display_t *wayland_display;
+ tpl_wayland_surface_t *wayland_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+
+ wayland_display = (tpl_wayland_display_t *) surface->display->backend.data;
+ wayland_surface = (tpl_wayland_surface_t *) surface->backend.data;
TPL_ASSERT(wayland_surface->current_rendering_buffer == NULL);
+
TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle);
if (__tpl_wayland_display_is_wl_display(surface->display->native_handle))
__tpl_wayland_display_roundtrip(surface->display);
- while (tpl_list_is_empty(&wayland_surface->able_rendering_queue))
+ while (__tpl_list_is_empty(&wayland_surface->able_rendering_queue))
{
/* Application sent all buffers to the server. Wait for server response. */
if (wl_display_dispatch_queue(surface->display->native_handle, wayland_display->proc.app.wl_queue) == -1)
{
TPL_OBJECT_LOCK(surface);
- return;
+ return TPL_FALSE;
}
}
{
while (1)
{
- if (!tpl_list_is_empty(&wayland_surface->able_rendering_queue))
+ if (!__tpl_list_is_empty(&wayland_surface->able_rendering_queue))
{
tpl_buffer_t *buffer = NULL;
tpl_wayland_buffer_t *wayland_buffer = NULL;
- buffer = tpl_list_get_front(&wayland_surface->able_rendering_queue);
- if (buffer == NULL) break;
+ buffer = __tpl_list_get_front(&wayland_surface->able_rendering_queue);
+ if (buffer == NULL)
+ break;
- wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
- if (wayland_buffer->proc.comp.posted) break;
+ wayland_buffer = (tpl_wayland_buffer_t *) buffer->backend.data;
+ if (wayland_buffer->proc.comp.posted)
+ break;
}
/* Compositor over-drawed all buffers, but no buffer has done yet. Wait for frame post. */
TPL_OBJECT_UNLOCK(surface);
- tpl_util_sys_yield();
+ __tpl_util_sys_yield();
TPL_OBJECT_LOCK(surface);
}
}
/* MOVE BUFFER : [able queue] --> (current buffer) */
- wayland_surface->current_rendering_buffer = tpl_list_pop_front(&wayland_surface->able_rendering_queue, NULL);
+ wayland_surface->current_rendering_buffer = __tpl_list_pop_front(&wayland_surface->able_rendering_queue, NULL);
TPL_LOG(3, "set current buffer(%p)", wayland_surface->current_rendering_buffer);
+
+ return TPL_TRUE;
}
static tpl_bool_t
return TPL_TRUE;
}
-static void
+static tpl_bool_t
__tpl_wayland_surface_end_frame(tpl_surface_t *surface)
{
- tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
+ tpl_wayland_surface_t *wayland_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+
+ wayland_surface = (tpl_wayland_surface_t *) surface->backend.data;
TPL_LOG(3, "window(%p, %p)", surface, surface->native_handle);
if (__tpl_wayland_display_is_gbm_device(surface->display->native_handle))
{
- tpl_wayland_buffer_t *wayland_buffer = (tpl_wayland_buffer_t *)wayland_surface->current_rendering_buffer->backend.data;
+ tpl_wayland_buffer_t *wayland_buffer = (tpl_wayland_buffer_t *) wayland_surface->current_rendering_buffer->backend.data;
/* Current GBM front buffer is moved to back when calling eglSwapBuffers()=end_frame(). */
- if (!tpl_list_is_empty(&wayland_surface->done_rendering_queue))
+ if (!__tpl_list_is_empty(&wayland_surface->done_rendering_queue))
{
+ void *buf;
+
/* MOVE BUFFER : [done queue] --> [able queue] */
- tpl_list_push_back(&wayland_surface->able_rendering_queue, tpl_list_pop_front(&wayland_surface->done_rendering_queue, NULL));
+ buf = __tpl_list_pop_front(&wayland_surface->done_rendering_queue, NULL);
+ if (TPL_TRUE != __tpl_list_push_back(&wayland_surface->able_rendering_queue, buf))
+ return TPL_FALSE;
}
/* Prepare to check post for current GBM back buffer. */
}
/* MOVE BUFFER : (current buffer) --> [done queue] */
- tpl_list_push_back(&wayland_surface->done_rendering_queue, wayland_surface->current_rendering_buffer);
+ if (TPL_TRUE != __tpl_list_push_back(&wayland_surface->done_rendering_queue, wayland_surface->current_rendering_buffer))
+ return TPL_FALSE;
+
wayland_surface->current_rendering_buffer = NULL;
+ return TPL_TRUE;
}
static tpl_buffer_t *
int width, height, depth, stride;
tpl_format_t format;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)surface->display->backend.data;
+ tpl_wayland_display_t *wayland_display;
struct wl_resource *wl_resource = NULL;
unsigned int name = -1;
uint32_t wl_format = 0;
- __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
- &width, &height, &format, 0, 0);
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+ TPL_ASSERT(surface->native_handle);
+ TPL_ASSERT(surface->display->backend.data);
+
+ wayland_display = (tpl_wayland_display_t *) surface->display->backend.data;
+
+ if (TPL_TRUE != __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
+ &width, &height, &format, 0, 0))
+ {
+ TPL_ERR("Failed to get window info!");
+ return NULL;
+ }
- depth = 32;//TPL_FORMAT_GET_DEPTH(format);
+ depth = 32; /*TPL_FORMAT_GET_DEPTH(format); */
stride = ALIGN_TO_64BYTE(width * depth / 8);
/* Allocate a buffer */
bo = tbm_bo_alloc(wayland_display->bufmgr, stride * height, TBM_BO_DEFAULT);
- TPL_CHECK_ON_NULL_RETURN_VAL(bo, NULL);
+ if (NULL == bo)
+ {
+ TPL_ERR("TBM bo alloc failed!");
+ return NULL;
+ }
/* Create tpl buffer. */
bo_handle = tbm_bo_get_handle(bo, TBM_DEVICE_3D);
+ if (bo_handle.ptr == NULL)
+ {
+ TPL_ERR("TBM bo get handle failed!");
+ tbm_bo_unref(bo);
+ return NULL;
+ }
name = tbm_bo_export(bo);
buffer = __tpl_buffer_alloc(surface, (size_t) name, (int) bo_handle.u32, width, height, depth, stride);
- TPL_CHECK_ON_NULL_RETURN_VAL(buffer, NULL);
+ if (NULL == buffer)
+ {
+ TPL_ERR("TPL buffer alloc failed!");
+ tbm_bo_unref(bo);
+ return NULL;
+ }
- wayland_buffer = (tpl_wayland_buffer_t *)calloc(1, sizeof(tpl_wayland_buffer_t));
+ wayland_buffer = (tpl_wayland_buffer_t *) calloc(1, sizeof(tpl_wayland_buffer_t));
if (wayland_buffer == NULL)
{
- TPL_ERR("wayland_buffer==NULL");
-
+ TPL_ERR("Mem alloc for wayland_buffer failed!");
tbm_bo_unref(bo);
- tpl_object_unreference((tpl_object_t *)buffer);
+ tpl_object_unreference((tpl_object_t *) buffer);
return NULL;
}
- buffer->backend.data = (void *)wayland_buffer;
+
+ buffer->backend.data = (void *) wayland_buffer;
surface->format = TPL_FORMAT_ARGB8888;
/* Post process : Create a wl_drm_buffer and notify the buffer to the server. */
switch (surface->format)
{
- case TPL_FORMAT_ARGB8888: wl_format = WL_DRM_FORMAT_ARGB8888; break;
- case TPL_FORMAT_XRGB8888: wl_format = WL_DRM_FORMAT_XRGB8888; break;
- case TPL_FORMAT_RGB565: wl_format = WL_DRM_FORMAT_RGB565; break;
+ case TPL_FORMAT_ARGB8888:
+ wl_format = WL_DRM_FORMAT_ARGB8888;
+ break;
+ case TPL_FORMAT_XRGB8888:
+ wl_format = WL_DRM_FORMAT_XRGB8888;
+ break;
+ case TPL_FORMAT_RGB565:
+ wl_format = WL_DRM_FORMAT_RGB565;
+ break;
default:
- TPL_ERR("surface->format==Unknown");
-
+ TPL_ERR("Unsupported format found in surface!");
tbm_bo_unref(bo);
tpl_object_unreference((tpl_object_t *)buffer);
+ free(wayland_buffer);
return NULL;
}
- wl_resource = (struct wl_resource *)wl_drm_create_buffer(wayland_display->wl_drm, (uint32_t)name, width, height,
+ wl_resource = (struct wl_resource *) wl_drm_create_buffer(wayland_display->wl_drm, (uint32_t)name, width, height,
stride, wl_format);
+ if (wl_resource == NULL)
+ {
+ TPL_ERR("Failed to create DRM buffer!");
+ tbm_bo_unref(bo);
+ tpl_object_unreference((tpl_object_t *)buffer);
+ free(wayland_buffer);
+ return NULL;
+ }
wl_proxy_set_queue((struct wl_proxy *)wl_resource, wayland_display->proc.app.wl_queue);
wl_buffer_add_listener((void *)wl_resource, &buffer_release_listener, buffer);
int width, height, depth, stride;
tpl_format_t format;
- struct gbm_device *gbm = (struct gbm_device *)surface->display->native_handle;
- struct gbm_surface *gbm_surface = surface->native_handle;
- struct gbm_tbm_surface *gbm_tbm_surface = (struct gbm_tbm_surface *)gbm_surface;
+ struct gbm_device *gbm;
+ struct gbm_tbm_surface *gbm_tbm_surface;
struct gbm_bo *gbm_bo = NULL;
struct gbm_tbm_bo *gbm_tbm_bo = NULL;
- __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
- &width, &height, &format, 0, 0);
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->native_handle);
+ TPL_ASSERT(surface->display);
+ TPL_ASSERT(surface->display->native_handle);
+
+ gbm = (struct gbm_device *)surface->display->native_handle;
+ gbm_tbm_surface = (struct gbm_tbm_surface *) surface->native_handle;
- depth = 32;//TPL_FORMAT_GET_DEPTH(format);
+ if (TPL_TRUE != __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
+ &width, &height, &format, 0, 0))
+ {
+ TPL_ERR("Failed to get window info!");
+ return NULL;
+ }
+
+ depth = 32; /* TPL_FORMAT_GET_DEPTH(format); */
stride = ALIGN_TO_64BYTE(width * depth / 8);
/* gbm does not support stride so we must ensure the width is same as stride. */
if (width > 1 && (width * depth / 8 != stride) )
{
- TPL_WARN("Unsupported stride %d", stride);
+ TPL_ERR("Unsupported stride %d", stride);
return NULL;
}
gbm_bo = gbm_bo_create(gbm, width, height,
gbm_tbm_surface_get_format(gbm_tbm_surface),
gbm_tbm_surface_get_flags(gbm_tbm_surface));
-
if (gbm_bo == NULL)
{
- TPL_WARN("Failed to allocate gbm_bo | gbm:%p %dx%d", gbm, width, height);
+ TPL_ERR("Failed to allocate gbm_bo | gbm:%p %dx%d", gbm, width, height);
return NULL;
}
- gbm_tbm_bo = (struct gbm_tbm_bo *)(gbm_bo);
+ gbm_tbm_bo = (struct gbm_tbm_bo *) gbm_bo;
bo = tbm_bo_ref(gbm_tbm_bo_get_tbm_bo(gbm_tbm_bo));
/* Create tpl buffer. */
(int)bo_handle.u32, width, height, depth, stride);
if (buffer == NULL)
{
- tbm_bo_unref(bo);
- TPL_WARN("Failed to allocate tpl buffer | surf:%p bo_hnd:%d WxHxD:%dx%dx%d",
+ TPL_ERR("Failed to allocate tpl buffer | surf:%p bo_hnd:%d WxHxD:%dx%dx%d",
surface, (int) bo_handle.u32, width, height, depth);
+ tbm_bo_unref(bo);
return NULL;
}
- wayland_buffer = (tpl_wayland_buffer_t *)calloc(1, sizeof(tpl_wayland_buffer_t));
+ wayland_buffer = (tpl_wayland_buffer_t *) calloc(1, sizeof(tpl_wayland_buffer_t));
if (wayland_buffer == NULL)
{
+ TPL_ERR("Mem alloc for wayland_buffer failed!");
tbm_bo_unref(bo);
- tpl_object_unreference((tpl_object_t *)buffer);
- TPL_WARN("Failed to allocate wayland buffer (calloc)");
+ tpl_object_unreference((tpl_object_t *) buffer);
return NULL;
}
+
buffer->backend.data = (void *)wayland_buffer;
/* Post process */
tpl_format_t format = TPL_FORMAT_INVALID;
size_t key = 0;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)surface->display->backend.data;
+ tpl_wayland_display_t *wayland_display;
struct wl_drm_buffer *drm_buffer = NULL;
- TPL_ASSERT(wayland_display->wl_drm != NULL);
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+
+ wayland_display = (tpl_wayland_display_t *) surface->display->backend.data;
+
+ TPL_ASSERT(wayland_display->wl_drm);
/* Get the allocated buffer */
drm_buffer = wayland_drm_buffer_get(wayland_display->wl_drm, (struct wl_resource *)surface->native_handle);
+ if (NULL == drm_buffer)
+ {
+ TPL_ERR("Failed to get DRM buffer!");
+ return NULL;
+ }
buffer = __tpl_wayland_surface_buffer_cache_find(&wayland_display->proc.comp.cached_buffers, (size_t) drm_buffer);
if (buffer != NULL)
{
__tpl_buffer_set_surface(buffer, surface);
- tpl_object_reference((tpl_object_t *)buffer);
+ tpl_object_reference((tpl_object_t *) buffer);
}
else
{
- __tpl_wayland_display_get_pixmap_info(surface->display, surface->native_handle,
- &width, &height, &format);
-
- depth = 32;//TPL_FORMAT_GET_DEPTH(format);
+ if (TPL_TRUE != __tpl_wayland_display_get_pixmap_info(surface->display, surface->native_handle,
+ &width, &height, &format))
+ {
+ TPL_ERR("Failed to get window info!");
+ return NULL;
+ }
+ depth = 32; /* TPL_FORMAT_GET_DEPTH(format); */
stride = drm_buffer->stride[0];
bo = tbm_bo_ref((tbm_bo)wayland_drm_buffer_get_buffer(drm_buffer));
+ if (NULL == bo)
+ {
+ TPL_ERR("Failed to reference bo!");
+ return NULL;
+ }
/* Create tpl buffer. */
bo_handle = tbm_bo_get_handle(bo, TBM_DEVICE_3D);
+ if (NULL == bo_handle.ptr)
+ {
+ TPL_ERR("Failed to get bo handle!");
+ tbm_bo_unref(bo);
+ return NULL;
+ }
+
key = (size_t) drm_buffer;
buffer = __tpl_buffer_alloc(surface, key,
(int) bo_handle.u32, width, height, depth, stride);
if (buffer == NULL)
{
+ TPL_ERR("Failed to alloc TPL buffer!");
tbm_bo_unref(bo);
return NULL;
}
- wayland_buffer = (tpl_wayland_buffer_t *)calloc(1, sizeof(tpl_wayland_buffer_t));
+ wayland_buffer = (tpl_wayland_buffer_t *) calloc(1, sizeof(tpl_wayland_buffer_t));
if (wayland_buffer == NULL)
{
+ TPL_ERR("Mem alloc failed for wayland buffer!");
tbm_bo_unref(bo);
- tpl_object_unreference((tpl_object_t *)buffer);
+ tpl_object_unreference((tpl_object_t *) buffer);
return NULL;
}
buffer->backend.data = (void *)wayland_buffer;
wayland_buffer->display = surface->display;
wayland_buffer->bo = bo;
buffer->key = key;
- __tpl_wayland_surface_buffer_cache_add(&wayland_display->proc.comp.cached_buffers, buffer); /* TODO: do we need error handle? */
+
+ if (TPL_TRUE != __tpl_wayland_surface_buffer_cache_add(&wayland_display->proc.comp.cached_buffers, buffer))
+ {
+ TPL_ERR("Adding surface to buffer cache failed!");
+ tbm_bo_unref(bo);
+ tpl_object_unreference((tpl_object_t *) buffer);
+ free(wayland_buffer);
+ return NULL;
+ }
}
if (reset_buffers != NULL)
static tpl_buffer_t *
__tpl_wayland_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers)
{
- tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
int i;
+ tpl_wayland_surface_t *wayland_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
+
+ wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
if (reset_buffers != NULL)
*reset_buffers = TPL_FALSE;
{
int width, height;
- __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
- &width, &height, NULL, 0, 0);
+ if (TPL_TRUE != __tpl_wayland_display_get_window_info(surface->display, surface->native_handle,
+ &width, &height, NULL, 0, 0))
+ {
+ TPL_ERR("Failed to get window info!");
+ return NULL;
+ }
/* Check whether the surface was resized by wayland_egl */
if (width != wayland_surface->current_rendering_buffer->width ||
height != wayland_surface->current_rendering_buffer->height)
{
int count;
+ tpl_buffer_t *node_buffer;
+ tpl_wayland_buffer_t *node_wayland_buffer;
+
TPL_LOG(3, "window(%p, %p) size changed: %dx%d -> %dx%d", surface, surface->native_handle,
wayland_surface->current_rendering_buffer->width, wayland_surface->current_rendering_buffer->height,
width, height);
/* Marks 'resized' on done queue. Rendered buffers can be used by server(other process).
So these buffers will be destroyed when reuse. */
- tpl_list_node_t *node = tpl_list_get_front_node(&wayland_surface->done_rendering_queue);
+ tpl_list_node_t *node = __tpl_list_get_front_node(&wayland_surface->done_rendering_queue);
while (node != NULL)
{
- tpl_buffer_t *node_buffer = (tpl_buffer_t *)tpl_list_node_get_data(node);
- tpl_wayland_buffer_t *node_wayland_buffer = (tpl_wayland_buffer_t *)node_buffer->backend.data;
+ node_buffer = (tpl_buffer_t *) __tpl_list_node_get_data(node);
+ TPL_ASSERT(node_buffer);
+
+ node_wayland_buffer = (tpl_wayland_buffer_t *) node_buffer->backend.data;
node_wayland_buffer->proc.app.resized = TPL_TRUE;
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
/* Throw away all able queue. (these are completely free buffers.)
And reconstruct renderable buffer queue */
- count = tpl_list_get_count(&wayland_surface->able_rendering_queue);
- tpl_list_fini(&wayland_surface->able_rendering_queue, (tpl_free_func_t)__tpl_wayland_surface_buffer_free);
+ count = __tpl_list_get_count(&wayland_surface->able_rendering_queue);
+ __tpl_list_fini(&wayland_surface->able_rendering_queue, (tpl_free_func_t)__tpl_wayland_surface_buffer_free);
+
for (i = 0; i < count; i++)
{
- tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL);
+ __tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL);
}
/* Replace current current buffer */
TPL_LOG(3, "free current buffer(%p)", wayland_surface->current_rendering_buffer);
+
__tpl_wayland_surface_buffer_free(wayland_surface->current_rendering_buffer);
wayland_surface->current_rendering_buffer =
__tpl_wayland_surface_create_buffer_from_wl_egl(surface, reset_buffers);
if (surface->type == TPL_SURFACE_TYPE_WINDOW)
{
- tpl_wayland_buffer_t *tpl_wayland_buffer;
-
- tpl_wayland_buffer = (tpl_wayland_buffer_t *)wayland_surface->current_rendering_buffer->backend.data;
- tpl_wayland_buffer->reused = reused;
+ TPL_ASSERT(wayland_surface->current_rendering_buffer);
+ ((tpl_wayland_buffer_t *) wayland_surface->current_rendering_buffer->backend.data)->reused = reused;
}
}
static void
__tpl_wayland_buffer_fini(tpl_buffer_t *buffer)
{
+ TPL_ASSERT(buffer);
+
TPL_LOG(3, "tpl_buffer(%p) key:%zu fd:%d %dx%d", buffer, buffer->key, buffer->fd, buffer->width, buffer->height);
if (buffer->backend.data)
static void *
__tpl_wayland_buffer_map(tpl_buffer_t *buffer, int size)
{
- tpl_wayland_buffer_t *wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+ tpl_wayland_buffer_t *wayland_buffer;
tbm_bo_handle handle;
- TPL_ASSERT(wayland_buffer != NULL);
- TPL_ASSERT(wayland_buffer->bo != NULL);
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
+
+ wayland_buffer = (tpl_wayland_buffer_t *) buffer->backend.data;
+
+ TPL_ASSERT(wayland_buffer->bo);
handle = tbm_bo_get_handle(wayland_buffer->bo, TBM_DEVICE_CPU);
return handle.ptr;
static tpl_bool_t
__tpl_wayland_buffer_lock(tpl_buffer_t *buffer, tpl_lock_usage_t usage)
{
- tpl_wayland_buffer_t *wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+ tpl_wayland_buffer_t *wayland_buffer;
tbm_bo_handle handle;
- TPL_ASSERT(wayland_buffer != NULL);
- TPL_ASSERT(wayland_buffer->bo != NULL);
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
+
+ wayland_buffer = (tpl_wayland_buffer_t *) buffer->backend.data;
+
+ TPL_ASSERT(wayland_buffer->bo);
TPL_OBJECT_UNLOCK(buffer);
handle = tbm_bo_map(wayland_buffer->bo, TBM_DEVICE_CPU, TBM_OPTION_WRITE);
break;
default:
- TPL_ASSERT(TPL_FALSE);
+ TPL_ERR("Unsupported buffer usage!");
+ TPL_OBJECT_LOCK(buffer);
return TPL_FALSE;
}
static void
__tpl_wayland_buffer_unlock(tpl_buffer_t *buffer)
{
- tpl_wayland_buffer_t *wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+ tpl_wayland_buffer_t *wayland_buffer;
+
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
- TPL_ASSERT(wayland_buffer != NULL);
- TPL_ASSERT(wayland_buffer->bo != NULL);
+ wayland_buffer = (tpl_wayland_buffer_t *) buffer->backend.data;
+
+ TPL_ASSERT(wayland_buffer->bo);
TPL_OBJECT_UNLOCK(buffer);
tbm_bo_unmap(wayland_buffer->bo);
static void *
__tpl_wayland_buffer_create_native_buffer(tpl_buffer_t *buffer)
{
- tpl_surface_t *surface = buffer->surface;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)surface->display->backend.data;
- tpl_wayland_buffer_t *wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+ tpl_surface_t *surface;
+ tpl_wayland_display_t *wayland_display;
+ tpl_wayland_buffer_t *wayland_buffer;
struct wl_resource *wl_resource = NULL;
uint32_t wl_format = 0;
unsigned int name = 0;
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->surface);
+ TPL_ASSERT(buffer->surface->display);
+ TPL_ASSERT(buffer->backend.data);
+
+ surface = buffer->surface;
+ wayland_display = (tpl_wayland_display_t *)surface->display->backend.data;
+ wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+
if (wayland_display->wl_drm == NULL)
- return TPL_FALSE;
+ {
+ TPL_ERR("Wayland DRM is NULL!");
+ return NULL;
+ }
switch (surface->format)
{
- case TPL_FORMAT_ARGB8888: wl_format = WL_DRM_FORMAT_ARGB8888; break;
- case TPL_FORMAT_XRGB8888: wl_format = WL_DRM_FORMAT_XRGB8888; break;
- case TPL_FORMAT_RGB565: wl_format = WL_DRM_FORMAT_RGB565; break;
- default: return TPL_FALSE;
+ case TPL_FORMAT_ARGB8888:
+ wl_format = WL_DRM_FORMAT_ARGB8888;
+ break;
+ case TPL_FORMAT_XRGB8888:
+ wl_format = WL_DRM_FORMAT_XRGB8888;
+ break;
+ case TPL_FORMAT_RGB565:
+ wl_format = WL_DRM_FORMAT_RGB565;
+ break;
+ default:
+ TPL_ERR("Unsupported surface format!");
+ return NULL;
}
name = tbm_bo_export(wayland_buffer->bo);
tpl_bool_t
__tpl_display_choose_backend_wayland(tpl_handle_t native_dpy)
{
- if (native_dpy == NULL) return TPL_FALSE;
+ if (native_dpy == NULL)
+ return TPL_FALSE;
- if (__tpl_wayland_display_is_wl_display(native_dpy)) return TPL_TRUE;
- if (__tpl_wayland_display_is_gbm_device(native_dpy)) return TPL_TRUE;
+ if (__tpl_wayland_display_is_wl_display(native_dpy))
+ return TPL_TRUE;
+
+ if (__tpl_wayland_display_is_gbm_device(native_dpy))
+ return TPL_TRUE;
return TPL_FALSE;
}
void
__tpl_display_init_backend_wayland(tpl_display_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_WAYLAND;
backend->data = NULL;
backend->fini = __tpl_wayland_display_fini;
backend->query_config = __tpl_wayland_display_query_config;
backend->filter_config = __tpl_wayland_display_filter_config;
- backend->get_window_info = __tpl_wayland_display_get_window_info;
- backend->get_pixmap_info = __tpl_wayland_display_get_pixmap_info;
+ backend->get_window_info = __tpl_wayland_display_get_window_info;
+ backend->get_pixmap_info = __tpl_wayland_display_get_pixmap_info;
backend->flush = __tpl_wayland_display_flush;
#ifdef EGL_BIND_WL_DISPLAY
backend->bind_client_display_handle = __tpl_wayland_display_bind_client_display;
void
__tpl_surface_init_backend_wayland(tpl_surface_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_WAYLAND;
backend->data = NULL;
void
__tpl_buffer_init_backend_wayland(tpl_buffer_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_WAYLAND;
backend->data = NULL;
backend->create_native_buffer = __tpl_wayland_buffer_create_native_buffer;
}
-/**********************************************************************************/
-
static void
__cb_client_wayland_drm_handle_device(void *user_data, struct wl_drm *drm, const char *device)
{
- tpl_display_t *display = (tpl_display_t *)user_data;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_display_t *display;
+ tpl_wayland_display_t *wayland_display;
drm_magic_t magic;
+ TPL_ASSERT(user_data);
+
+ display = (tpl_display_t *) user_data;
+ wayland_display = (tpl_wayland_display_t *) display->backend.data;
+
+ TPL_ASSERT(wayland_display);
+
TPL_IGNORE(drm);
display->bufmgr_fd = open(device, O_RDWR | O_CLOEXEC);
static void
__cb_client_wayland_drm_handle_authenticated(void *user_data, struct wl_drm *drm)
{
- tpl_display_t *display = (tpl_display_t *)user_data;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_display_t *display;
+ tpl_wayland_display_t *wayland_display;
+
+ TPL_ASSERT(user_data);
+
+ display = (tpl_display_t *) user_data;
+ wayland_display = (tpl_wayland_display_t *) display->backend.data;
+
+ TPL_ASSERT(wayland_display);
TPL_IGNORE(drm);
__cb_client_registry_handle_global(void *user_data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version)
{
- tpl_display_t *display = (tpl_display_t *)user_data;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_display_t *display;
+ tpl_wayland_display_t *wayland_display;
+
+ TPL_ASSERT(user_data);
+
+ display = (tpl_display_t *) user_data;
+ wayland_display = (tpl_wayland_display_t *) display->backend.data;
+
+ TPL_ASSERT(wayland_display);
if (strcmp(interface, "wl_drm") == 0)
{
static void
__cb_client_sync_callback(void *data, struct wl_callback *callback, uint32_t serial)
{
- int *done = data;
+ int *done;
- *done = 1;
- wl_callback_destroy(callback);
+ TPL_ASSERT(data);
+
+ done = data;
+ *done = 1;
+
+ wl_callback_destroy(callback);
}
static const struct wl_callback_listener sync_listener =
{
- __cb_client_sync_callback
+ __cb_client_sync_callback
};
static void
static void
__cb_client_buffer_release_callback(void *data, struct wl_resource *resource)
{
- tpl_buffer_t *buffer = (tpl_buffer_t *)data;
- tpl_surface_t *surface = buffer->surface;
+ tpl_buffer_t *buffer;
+ tpl_surface_t *surface;
+
+ TPL_ASSERT(data);
+
+ buffer = (tpl_buffer_t *) data;
+ surface = buffer->surface;
TPL_LOG(3, "release window(%p, %p), buffer(%p), key:%zu",
- surface, surface?surface->native_handle:NULL,
- buffer, buffer->key);
+ surface, surface?surface->native_handle:NULL,
+ buffer, buffer->key);
if (surface != NULL)
{
/* MOVE BUFFER : [done queue] --> [able queue] */
{
tpl_wayland_surface_t *wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
- tpl_list_node_t *node = tpl_list_get_front_node(&wayland_surface->done_rendering_queue);
+ tpl_list_node_t *node = __tpl_list_get_front_node(&wayland_surface->done_rendering_queue);
while (node != NULL)
{
- tpl_buffer_t *node_buffer = (tpl_buffer_t *)tpl_list_node_get_data(node);
+ tpl_buffer_t *node_buffer = (tpl_buffer_t *)__tpl_list_node_get_data(node);
if (node_buffer == buffer)
{
/* Delete the buffer that had been created before resized. */
__tpl_wayland_surface_buffer_free(buffer);
- tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL);
+ __tpl_list_push_back(&wayland_surface->able_rendering_queue, NULL);
}
else
{
/* Reuse the buffer because the buffer size is not changed and reusable. */
- tpl_list_push_back(&wayland_surface->able_rendering_queue, buffer);
+ __tpl_list_push_back(&wayland_surface->able_rendering_queue, buffer);
}
- tpl_list_remove(node, NULL);
+ __tpl_list_remove(node, NULL);
break;
}
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
- TPL_ASSERT(node != NULL);
}
TPL_OBJECT_UNLOCK(surface);
}
(void *)__cb_client_buffer_release_callback,
};
-/**********************************************************************************/
-
static struct gbm_bo *
__cb_server_gbm_surface_lock_front_buffer(struct gbm_surface *gbm_surf)
{
- struct gbm_tbm_surface *gbm_tbm_surf = (struct gbm_tbm_surface *)gbm_surf;
- tpl_surface_t *surface = (tpl_surface_t *)gbm_tbm_surface_get_user_data(gbm_tbm_surf);
+ struct gbm_tbm_surface *gbm_tbm_surf;
+ tpl_surface_t *surface;
tpl_wayland_surface_t *wayland_surface = NULL;
tpl_buffer_t *buffer = NULL;
tpl_wayland_buffer_t *wayland_buffer = NULL;
+ tbm_bo_handle bo_handle;
+
+ TPL_ASSERT(gbm_surf);
- TPL_ASSERT(surface != NULL);
+ gbm_tbm_surf = (struct gbm_tbm_surface *) gbm_surf;
+ surface = (tpl_surface_t *)gbm_tbm_surface_get_user_data(gbm_tbm_surf);
+
+ TPL_ASSERT(surface);
TPL_OBJECT_LOCK(surface);
while (1)
{
/* Wait for posted to prevent locking not-rendered buffer. */
- if (!tpl_list_is_empty(&wayland_surface->done_rendering_queue))
+ if (!__tpl_list_is_empty(&wayland_surface->done_rendering_queue))
{
- buffer = tpl_list_get_front(&wayland_surface->done_rendering_queue);
- wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+ buffer = __tpl_list_get_front(&wayland_surface->done_rendering_queue);
+
+ TPL_ASSERT(buffer);
+
+ wayland_buffer = (tpl_wayland_buffer_t *) buffer->backend.data;
if (wayland_buffer->proc.comp.posted)
break;
}
TPL_OBJECT_UNLOCK(surface);
- tpl_util_sys_yield();
+ __tpl_util_sys_yield();
TPL_OBJECT_LOCK(surface);
}
TPL_ASSERT(buffer != NULL);
wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
+ if (NULL == wayland_buffer)
+ {
+ TPL_ERR("Wayland buffer is NULL!");
+ TPL_OBJECT_UNLOCK(surface);
+ return NULL;
+ }
- tbm_bo_map(wayland_buffer->bo, TBM_DEVICE_MM, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ bo_handle = tbm_bo_map(wayland_buffer->bo, TBM_DEVICE_MM, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ if (NULL == bo_handle.ptr)
+ {
+ TPL_ERR("TBM bo map failed!");
+ TPL_OBJECT_UNLOCK(surface);
+ return NULL;
+ }
TPL_OBJECT_UNLOCK(surface);
static void
__cb_server_gbm_surface_release_buffer(struct gbm_surface *gbm_surf, struct gbm_bo *gbm_bo)
{
- struct gbm_tbm_bo *gbm_tbm_bo = (struct gbm_tbm_bo *)gbm_bo;
+ struct gbm_tbm_bo *gbm_tbm_bo;
tbm_bo bo;
+ TPL_ASSERT(gbm_bo);
+
TPL_IGNORE(gbm_surf);
+ gbm_tbm_bo = (struct gbm_tbm_bo *) gbm_bo;
+
bo = gbm_tbm_bo_get_tbm_bo(gbm_tbm_bo);
TPL_ASSERT(bo);
static int
__cb_server_gbm_surface_has_free_buffers(struct gbm_surface *gbm_surf)
{
- struct gbm_tbm_surface *gbm_tbm_surf = (struct gbm_tbm_surface *)gbm_surf;
- tpl_surface_t *surface = (tpl_surface_t *)gbm_tbm_surface_get_user_data(gbm_tbm_surf);
+ struct gbm_tbm_surface *gbm_tbm_surf;
+ tpl_surface_t *surface;
tpl_wayland_surface_t *wayland_surface = NULL;
tpl_buffer_t *buffer = NULL;
tpl_wayland_buffer_t *wayland_buffer = NULL;
- TPL_ASSERT(surface != NULL);
+ TPL_ASSERT(gbm_surf);
+
+ gbm_tbm_surf = (struct gbm_tbm_surface *) gbm_surf;
+ surface = (tpl_surface_t *) gbm_tbm_surface_get_user_data(gbm_tbm_surf);
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
TPL_OBJECT_LOCK(surface);
- wayland_surface = (tpl_wayland_surface_t *)surface->backend.data;
+ wayland_surface = (tpl_wayland_surface_t *) surface->backend.data;
- if (tpl_list_is_empty(&wayland_surface->done_rendering_queue)) {
+ if (__tpl_list_is_empty(&wayland_surface->done_rendering_queue)) {
TPL_OBJECT_UNLOCK(surface);
return 0;
}
- buffer = tpl_list_get_front(&wayland_surface->done_rendering_queue);
+ buffer = __tpl_list_get_front(&wayland_surface->done_rendering_queue);
wayland_buffer = (tpl_wayland_buffer_t *)buffer->backend.data;
if (wayland_buffer->proc.comp.posted) {
static int
__cb_server_wayland_drm_display_authenticate(void *user_data, uint32_t magic)
{
- tpl_display_t *display = (tpl_display_t *)user_data;
+ tpl_display_t *display;
+
+ TPL_ASSERT(user_data);
+
+ display = (tpl_display_t *) user_data;
return drmAuthMagic(display->bufmgr_fd, magic);
}
static void
__cb_server_wayland_drm_reference_buffer(void *user_data, uint32_t name, int fd, struct wl_drm_buffer *buffer)
{
- tpl_display_t *display = (tpl_display_t *)user_data;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_display_t *display;
+ tpl_wayland_display_t *wayland_display;
+
+ TPL_ASSERT(user_data);
+
+ display = (tpl_display_t *)user_data;
+ wayland_display = (tpl_wayland_display_t *) display->backend.data;
TPL_IGNORE(name);
TPL_IGNORE(fd);
buffer->driver_buffer = tbm_bo_import(wayland_display->bufmgr, name);
+ if (NULL == buffer->driver_buffer)
+ {
+ TPL_ERR("TBM bo import failed!");
+ return;
+ }
}
static void
__cb_server_wayland_drm_unreference_buffer(void *user_data, struct wl_drm_buffer *buffer)
{
- tpl_display_t *display = (tpl_display_t *)user_data;
- tpl_wayland_display_t *wayland_display = (tpl_wayland_display_t *)display->backend.data;
+ tpl_display_t *display;
+ tpl_wayland_display_t *wayland_display;
+
+ TPL_ASSERT(user_data);
+ TPL_ASSERT(buffer);
+
+ display = (tpl_display_t *) user_data;
+ wayland_display = (tpl_wayland_display_t *) display->backend.data;
tbm_bo_unref(buffer->driver_buffer);
buffer->driver_buffer = NULL;
#ifdef EGL_BIND_WL_DISPLAY
unsigned int __tpl_wayland_display_bind_client_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy)
{
- struct wl_display *wayland_display = (struct wl_display *)native_dpy;
- tpl_wayland_display_t *tpl_wayland_display = (tpl_wayland_display_t *)tpl_display->backend.data;
+ struct wl_display *wayland_display;
+ tpl_wayland_display_t *tpl_wayland_display;
char *device_name = NULL;
+ TPL_ASSERT(tpl_display);
+ TPL_ASSERT(native_dpy);
+
+ wayland_display = (struct wl_display *) native_dpy;
+ tpl_wayland_display = (tpl_wayland_display_t *) tpl_display->backend.data;
+
tpl_display->bufmgr_fd = dup(gbm_device_get_fd(tpl_display->native_handle));
tpl_wayland_display->bufmgr = tbm_bufmgr_init(tpl_display->bufmgr_fd);
+ if (NULL == tpl_wayland_display->bufmgr)
+ {
+ TPL_ERR("TBM buffer manager initialization failed!");
+ return TPL_FALSE;
+ }
device_name = drmGetDeviceNameFromFd(tpl_display->bufmgr_fd);
- tpl_wayland_display->wl_drm = wayland_drm_init((struct wl_display *)wayland_display, device_name, &wl_drm_server_listener, tpl_display, 0);
+ tpl_wayland_display->wl_drm = wayland_drm_init((struct wl_display *) wayland_display, device_name, &wl_drm_server_listener, tpl_display, 0);
+ if (NULL == tpl_wayland_display->wl_drm)
+ {
+ TPL_ERR("Wayland DRM initialization failed!");
+ return TPL_FALSE;
+ }
return TPL_TRUE;
}
unsigned int __tpl_wayland_display_unbind_client_display(tpl_display_t *tpl_display, tpl_handle_t native_dpy)
{
- tpl_wayland_display_t *tpl_wayland_display = (tpl_wayland_display_t *)tpl_display->backend.data;
+ tpl_wayland_display_t *tpl_wayland_display;
+
+ TPL_ASSERT(tpl_display);
+
+ tpl_wayland_display = (tpl_wayland_display_t *) tpl_display->backend.data;
if (tpl_wayland_display->wl_drm == NULL)
+ {
+ TPL_ERR("Wayland DRM is NULL!");
return TPL_FALSE;
+ }
wayland_drm_uninit(tpl_wayland_display->wl_drm);
tbm_bufmgr_deinit(tpl_wayland_display->bufmgr);
{
int swap_type;
+ TPL_ASSERT(type);
+
if (str == NULL)
return;
tpl_buffer_t *
__tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, unsigned int name)
{
- tpl_list_node_t *node = tpl_list_get_front_node(buffer_cache);
+ tpl_list_node_t *node;
+
+ TPL_ASSERT(buffer_cache);
+
+ node = __tpl_list_get_front_node(buffer_cache);
while (node)
{
- tpl_buffer_t *buffer = (tpl_buffer_t *)tpl_list_node_get_data(node);
+ tpl_buffer_t *buffer = (tpl_buffer_t *) __tpl_list_node_get_data(node);
+
+ TPL_ASSERT(buffer);
if (buffer->key == name)
return buffer;
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
return NULL;
}
void
-__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int name)
+__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int name)
{
- tpl_list_node_t *node = tpl_list_get_front_node(buffer_cache);
+ tpl_list_node_t *node;
+
+ TPL_ASSERT(buffer_cache);
+
+ node = __tpl_list_get_front_node(buffer_cache);
while (node)
{
- tpl_buffer_t *buffer = (tpl_buffer_t *)tpl_list_node_get_data(node);
+ tpl_buffer_t *buffer = (tpl_buffer_t *) __tpl_list_node_get_data(node);
+
+ TPL_ASSERT(buffer);
if (buffer->key == name)
{
tpl_object_unreference(&buffer->base);
- tpl_list_remove(node, NULL);
+ __tpl_list_remove(node, NULL);
return;
}
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
}
-void
+tpl_bool_t
__tpl_x11_surface_buffer_cache_add(tpl_list_t *buffer_cache, tpl_buffer_t *buffer)
{
- if (tpl_list_get_count(buffer_cache) >= TPL_BUFFER_CACHE_MAX_ENTRIES)
+ TPL_ASSERT(buffer_cache);
+ TPL_ASSERT(buffer);
+
+ if (__tpl_list_get_count(buffer_cache) >= TPL_BUFFER_CACHE_MAX_ENTRIES)
{
- tpl_buffer_t *evict = tpl_list_pop_front(buffer_cache, NULL);
+ tpl_buffer_t *evict = __tpl_list_pop_front(buffer_cache, NULL);
+
+ TPL_ASSERT(evict);
+
tpl_object_unreference(&evict->base);
}
- tpl_object_reference(&buffer->base);
- tpl_list_push_back(buffer_cache, (void *)buffer);
+ if (-1 == tpl_object_reference(&buffer->base))
+ return TPL_FALSE;
+
+ return __tpl_list_push_back(buffer_cache, (void *)buffer);
}
void
__tpl_x11_surface_buffer_cache_clear(tpl_list_t *buffer_cache)
{
- tpl_list_fini(buffer_cache, (tpl_free_func_t)tpl_object_unreference);
+ TPL_ASSERT(buffer_cache);
+
+ __tpl_list_fini(buffer_cache, (tpl_free_func_t)tpl_object_unreference);
}
{
Display *native_display;
- TPL_IGNORE(alpha_size);
+ TPL_IGNORE(alpha_size);
+
+ TPL_ASSERT(display);
+ TPL_ASSERT(display->native_handle);
native_display = (Display *)display->native_handle;
int clz[3];
int col_size[3];
- clz[0] = tpl_util_clz(visual_formats[i].red_mask);
- clz[1] = tpl_util_clz(visual_formats[i].green_mask);
- clz[2] = tpl_util_clz(visual_formats[i].blue_mask);
+ clz[0] = __tpl_util_clz(visual_formats[i].red_mask);
+ clz[1] = __tpl_util_clz(visual_formats[i].green_mask);
+ clz[2] = __tpl_util_clz(visual_formats[i].blue_mask);
col_size[0] = clz[1] - clz[0];
col_size[1] = clz[2] - clz[1];
__tpl_x11_display_get_window_info(tpl_display_t *display, tpl_handle_t window,
int *width, int *height, tpl_format_t *format, int depth, int a_size)
{
- TPL_IGNORE(depth);
- TPL_IGNORE(a_size);
Status x_res;
XWindowAttributes att;
+ TPL_IGNORE(depth);
+ TPL_IGNORE(a_size);
+
+ TPL_ASSERT(display);
+ TPL_ASSERT(display->native_handle);
+
x_res = XGetWindowAttributes((Display *)display->native_handle, (Window)window, &att);
if (x_res != BadWindow)
}
return TPL_FALSE;
-
}
tpl_bool_t
int x, y;
unsigned int w, h, bw, d;
+ TPL_ASSERT(display);
+ TPL_ASSERT(display->native_handle);
+
x_res = XGetGeometry((Display *)display->native_handle, (Pixmap)pixmap, &root,
&x, &y, &w, &h, &bw, &d);
void
__tpl_x11_display_flush(tpl_display_t *display)
{
- Display *native_display = (Display *)display->native_handle;
+ Display *native_display;
+
+ TPL_ASSERT(display);
+ TPL_ASSERT(display->native_handle);
+
+ native_display = (Display *) display->native_handle;
XFlush(native_display);
XSync(native_display, False);
}
-
tpl_bool_t
__tpl_x11_buffer_init(tpl_buffer_t *buffer)
{
TPL_IGNORE(buffer);
+
return TPL_TRUE;
}
void
__tpl_x11_buffer_fini(tpl_buffer_t *buffer)
{
+ TPL_ASSERT(buffer);
+
if (buffer->backend.data)
{
tbm_bo_map((tbm_bo)buffer->backend.data, TBM_DEVICE_3D, TBM_OPTION_READ);
tbm_bo bo;
tbm_bo_handle handle;
- bo = (tbm_bo)buffer->backend.data;
- TPL_ASSERT(bo);
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
+ bo = (tbm_bo) buffer->backend.data;
handle = tbm_bo_get_handle(bo, TBM_DEVICE_CPU);
+
return handle.ptr;
}
tbm_bo bo;
tbm_bo_handle handle;
- bo = (tbm_bo)buffer->backend.data;
- TPL_ASSERT(bo);
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
+
+ bo = (tbm_bo) buffer->backend.data;
TPL_OBJECT_UNLOCK(buffer);
{
tbm_bo bo;
- bo = (tbm_bo)buffer->backend.data;
- TPL_ASSERT(bo);
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
+
+ bo = (tbm_bo) buffer->backend.data;
TPL_OBJECT_UNLOCK(buffer);
tbm_bo_unmap(bo);
tpl_bool_t __tpl_x11_buffer_get_reused_flag(tpl_buffer_t *buffer)
{
+ TPL_ASSERT(buffer);
+
if (DRI2_BUFFER_IS_REUSED(buffer->backend.flags))
return TPL_TRUE;
else
void __tpl_x11_display_wait_native(tpl_display_t *display)
{
- Display *xlib_display = NULL;
- xlib_display = (Display *)display->native_handle;
- if (xlib_display != NULL)
- {
+ Display *xlib_display;
+ TPL_ASSERT(display);
+ xlib_display = (Display *) display->native_handle;
+ if (xlib_display != NULL)
+ {
/* Leave events in the queue since we only care they have arrived. */
XSync(xlib_display, 0);
-
- }
+ }
}
XRectangle xrects_stack[TPL_STACK_XRECTANGLE_SIZE];
int interval = frame->interval;
+ TPL_ASSERT(frame);
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
+
x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data;
if (is_worker)
x11_surface->latest_post_interval = interval;
}
- if (tpl_region_is_empty(&frame->damage))
+ if (__tpl_region_is_empty(&frame->damage))
{
DRI2SwapBuffers(display, drawable, 0, 0, 0, &swap_count);
}
if (frame->damage.num_rects > TPL_STACK_XRECTANGLE_SIZE)
{
- xrects = (XRectangle *)malloc(sizeof(XRectangle) *
+ xrects = (XRectangle *) malloc(sizeof(XRectangle) *
frame->damage.num_rects);
}
else
static tpl_bool_t
__tpl_x11_dri2_display_init(tpl_display_t *display)
{
- pthread_mutex_t mutex = __tpl_x11_get_global_mutex();
+ pthread_mutex_t mutex;
+
+ TPL_ASSERT(display);
+
+ mutex = __tpl_x11_get_global_mutex();
+
if (display->native_handle == NULL)
{
display->native_handle = XOpenDisplay(NULL);
- TPL_ASSERT(display->native_handle != NULL);
+ if (NULL == display->native_handle)
+ {
+ TPL_ERR("XOpenDisplay failed!");
+ return TPL_FALSE;
+ }
}
- display->xcb_connection = XGetXCBConnection( (Display*)display->native_handle );
- if( NULL == display->xcb_connection )
+
+ display->xcb_connection = XGetXCBConnection( (Display*)display->native_handle );
+ if( NULL == display->xcb_connection )
{
TPL_WARN("XGetXCBConnection failed");
}
/* Open a dummy display connection. */
global.worker_display = XOpenDisplay(NULL);
- TPL_ASSERT(global.worker_display != NULL);
+ if (NULL == global.worker_display)
+ {
+ TPL_ERR("XOpenDisplay failed!");
+ return TPL_FALSE;
+ }
/* Get default root window. */
root = DefaultRootWindow(global.worker_display);
/* Initialize DRI2. */
xres = DRI2QueryExtension(global.worker_display, &event_base, &error_base);
- TPL_ASSERT(xres == True);
+ if (True != xres)
+ {
+ TPL_ERR("DRI2QueryExtension failed!");
+ return TPL_FALSE;
+ }
xres = DRI2QueryVersion(global.worker_display, &major, &minor);
- TPL_ASSERT(xres == True);
+ if (True != xres)
+ {
+ TPL_ERR("DRI2QueryVersion failed!");
+ return TPL_FALSE;
+ }
xres = DRI2Connect(global.worker_display, root, &drv, &dev);
- TPL_ASSERT(xres == True);
+ if (True != xres)
+ {
+ TPL_ERR("DRI2Connect failed!");
+ return TPL_FALSE;
+ }
/* Initialize buffer manager. */
global.bufmgr_fd = open(dev, O_RDWR);
/* DRI2 authentication. */
xres = DRI2Authenticate(global.worker_display, root, magic);
- TPL_ASSERT(xres == True);
+ if (True != xres)
+ {
+ TPL_ERR("DRI2Authenciate failed!");
+ return TPL_FALSE;
+ }
/* Initialize swap type configuration. */
__tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_WINDOW_SWAP_TYPE_ENV_NAME),
{
pthread_mutex_t mutex = __tpl_x11_get_global_mutex();
+
TPL_IGNORE(display);
+
pthread_mutex_lock(&mutex);
if (--global.display_count == 0)
tpl_x11_dri2_surface_t *x11_surface;
tpl_format_t format = TPL_FORMAT_INVALID;
+ TPL_ASSERT(surface);
+
if (surface->type == TPL_SURFACE_TYPE_WINDOW)
{
if (!__tpl_x11_display_get_window_info(surface->display, surface->native_handle,
return TPL_FALSE;
}
- x11_surface = (tpl_x11_dri2_surface_t *)calloc(1, sizeof(tpl_x11_dri2_surface_t));
+ x11_surface = (tpl_x11_dri2_surface_t *) calloc(1, sizeof(tpl_x11_dri2_surface_t));
if (x11_surface == NULL)
{
- TPL_ASSERT(TPL_FALSE);
+ TPL_ERR("Failed to allocate memory for X11 surface!");
return TPL_FALSE;
}
Drawable drawable;
tpl_x11_dri2_surface_t *x11_surface;
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+ TPL_ASSERT(surface->display->native_handle);
+
display = (Display *)surface->display->native_handle;
drawable = (Drawable)surface->native_handle;
x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data;
static void
__tpl_x11_dri2_surface_post(tpl_surface_t *surface, tpl_frame_t *frame)
{
+ TPL_ASSERT(frame);
+ TPL_ASSERT(surface);
+
__tpl_x11_dri2_surface_post_internal(surface, frame, TPL_TRUE);
}
{
tpl_frame_t *prev_frame;
+ TPL_ASSERT(surface);
+
if (surface->type != TPL_SURFACE_TYPE_WINDOW)
+ {
+ TPL_ERR("Surface type is not of window type!");
return;
+ }
prev_frame = __tpl_surface_get_latest_frame(surface);
static tpl_bool_t
__tpl_x11_surface_validate_frame(tpl_surface_t *surface)
{
- tpl_x11_dri2_surface_t *x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data;
+ tpl_x11_dri2_surface_t *x11_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
+
+ x11_surface = (tpl_x11_dri2_surface_t *) surface->backend.data;
if (surface->type != TPL_SURFACE_TYPE_WINDOW)
return TPL_TRUE;
- if (surface->frame == NULL)
+ if (NULL == surface->frame)
return TPL_TRUE;
if ((DRI2_BUFFER_IS_FB(surface->frame->buffer->backend.flags) &&
static void
__tpl_x11_surface_end_frame(tpl_surface_t *surface)
{
- tpl_frame_t *frame = __tpl_surface_get_latest_frame(surface);
- tpl_x11_dri2_surface_t *x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data;
+ tpl_frame_t *frame;
+ tpl_x11_dri2_surface_t *x11_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
+
+ frame = __tpl_surface_get_latest_frame(surface);
+ x11_surface = (tpl_x11_dri2_surface_t *) surface->backend.data;
if (frame)
{
tbm_bo bo;
tbm_bo_handle bo_handle;
int width, height, num_buffers;
- tpl_x11_dri2_surface_t *x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data;
+ tpl_x11_dri2_surface_t *x11_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
+
+ x11_surface = (tpl_x11_dri2_surface_t *)surface->backend.data;
if (surface->type == TPL_SURFACE_TYPE_PIXMAP)
attachments[0] = DRI2BufferFrontLeft;
dri2_buffers = DRI2GetBuffers(display, drawable,
&width, &height, attachments, 1, &num_buffers);
if (dri2_buffers == NULL)
+ {
+ TPL_ERR("DRI2GetBuffers failed!");
goto err_buffer;
+ }
if (DRI2_BUFFER_IS_REUSED(dri2_buffers[0].flags))
{
if (bo == NULL)
{
- TPL_ASSERT(TPL_FALSE);
+ TPL_ERR("TBM bo import failed!");
goto done;
}
/* Create tpl buffer. */
buffer = __tpl_buffer_alloc(surface, (size_t) dri2_buffers[0].name, (int) bo_handle.u32,
width, height, dri2_buffers[0].cpp * 8, dri2_buffers[0].pitch);
+ if (NULL == buffer)
+ {
+ TPL_ERR("TPL buffer alloc failed!");
+ goto err_buffer;
+ }
#if (TIZEN_FEATURES_ENABLE)
buffer->age = DRI2_BUFFER_GET_AGE(dri2_buffers[0].flags);
void
__tpl_display_init_backend_x11_dri2(tpl_display_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_X11_DRI2;
backend->data = NULL;
- backend->init = __tpl_x11_dri2_display_init;
- backend->fini = __tpl_x11_dri2_display_fini;
- backend->query_config = __tpl_x11_display_query_config;
+ backend->init = __tpl_x11_dri2_display_init;
+ backend->fini = __tpl_x11_dri2_display_fini;
+ backend->query_config = __tpl_x11_display_query_config;
backend->get_window_info = __tpl_x11_display_get_window_info;
backend->get_pixmap_info = __tpl_x11_display_get_pixmap_info;
- backend->flush = __tpl_x11_display_flush;
- backend->wait_native = __tpl_x11_display_wait_native;
+ backend->flush = __tpl_x11_display_flush;
+ backend->wait_native = __tpl_x11_display_wait_native;
}
void
__tpl_surface_init_backend_x11_dri2(tpl_surface_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_X11_DRI2;
backend->data = NULL;
- backend->init = __tpl_x11_dri2_surface_init;
- backend->fini = __tpl_x11_dri2_surface_fini;
- backend->begin_frame = __tpl_x11_surface_begin_frame;
- backend->end_frame = __tpl_x11_surface_end_frame;
+ backend->init = __tpl_x11_dri2_surface_init;
+ backend->fini = __tpl_x11_dri2_surface_fini;
+ backend->begin_frame = __tpl_x11_surface_begin_frame;
+ backend->end_frame = __tpl_x11_surface_end_frame;
backend->validate_frame = __tpl_x11_surface_validate_frame;
- backend->get_buffer = __tpl_x11_dri2_surface_get_buffer;
- backend->post = __tpl_x11_dri2_surface_post;
+ backend->get_buffer = __tpl_x11_dri2_surface_get_buffer;
+ backend->post = __tpl_x11_dri2_surface_post;
}
void
__tpl_buffer_init_backend_x11_dri2(tpl_buffer_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_X11_DRI2;
backend->data = NULL;
{
xcb_dri3_open_cookie_t cookie;
xcb_dri3_open_reply_t *reply;
- xcb_connection_t *c = XGetXCBConnection(dpy);
+ xcb_connection_t *c;
int fd;
+ TPL_ASSERT(dpy);
+
+ c = XGetXCBConnection(dpy);
+
cookie = xcb_dri3_open(c,
root,
provider);
reply = xcb_dri3_open_reply(c, cookie, NULL);
if (!reply)
{
+ TPL_ERR("XCB DRI3 open failed!");
return -1;
}
if (reply->nfd != 1)
{
+ TPL_ERR("XCB DRI3 open reply failed!");
free(reply);
return -1;
}
dri3_display_init(Display *dpy)
{
/* Initialize DRI3 & DRM */
- xcb_connection_t *c = XGetXCBConnection(dpy);
+ xcb_connection_t *c;
xcb_dri3_query_version_cookie_t dri3_cookie;
xcb_dri3_query_version_reply_t *dri3_reply;
xcb_present_query_version_cookie_t present_cookie;
xcb_extension_t xcb_dri3_id = { "DRI3", 0 };
xcb_extension_t xcb_present_id = { "Present", 0 };
+ TPL_ASSERT(dpy);
+
+ c = XGetXCBConnection(dpy);
+
xcb_prefetch_extension_data(c, &xcb_dri3_id);
xcb_prefetch_extension_data(c, &xcb_present_id);
extension = xcb_get_extension_data(c, &xcb_dri3_id);
if (!(extension && extension->present))
{
+ TPL_ERR("XCB get extension failed!");
return TPL_FALSE;
}
extension = xcb_get_extension_data(c, &xcb_present_id);
if (!(extension && extension->present))
{
+ TPL_ERR("XCB get extension failed!");
return TPL_FALSE;
}
dri3_reply = xcb_dri3_query_version_reply(c, dri3_cookie, &error);
if (!dri3_reply)
{
+ TPL_ERR("XCB version query failed!");
free(error);
return TPL_FALSE;
}
present_reply = xcb_present_query_version_reply(c, present_cookie, &error);
if (!present_reply)
{
+ TPL_ERR("Present version query failed!");
free(error);
return TPL_FALSE;
}
dri3_create_drawable(Display *dpy, XID xDrawable)
{
dri3_drawable *pdraw = NULL;
- xcb_connection_t *c = XGetXCBConnection(dpy);
+ xcb_connection_t *c;
xcb_get_geometry_cookie_t geom_cookie;
xcb_get_geometry_reply_t *geom_reply;
int i;
tpl_list_node_t *node;
dri3_drawable_node *drawable_node;
+ TPL_ASSERT(dpy);
+
+ c = XGetXCBConnection(dpy);
+
/* Check drawable list to find that if it has been created*/
- node = tpl_list_get_front_node(&dri3_drawable_list);
+ node = __tpl_list_get_front_node(&dri3_drawable_list);
while (node)
{
- dri3_drawable_node *drawable = (dri3_drawable_node *)tpl_list_node_get_data(node);
+ dri3_drawable_node *drawable = (dri3_drawable_node *) __tpl_list_node_get_data(node);
if (drawable->xDrawable == xDrawable)
{
pdraw = drawable->drawable;
return (void *)pdraw;/* Reuse old drawable */
}
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
pdraw = calloc(1, sizeof(*pdraw));
- TPL_ASSERT(pdraw != NULL);
+ if (NULL == pdraw)
+ {
+ TPL_ERR("Failed to allocate memory!");
+ return NULL;
+ }
geom_cookie = xcb_get_geometry(c, xDrawable);
geom_reply = xcb_get_geometry_reply(c, geom_cookie, NULL);
- TPL_ASSERT(geom_reply != NULL);
+ if (NULL == geom_reply)
+ {
+ TPL_ERR("XCB get geometry failed!");
+ free(pdraw);
+ return NULL;
+ }
pdraw->bufmgr = global.bufmgr;
pdraw->width = geom_reply->width;
pdraw->is_pixmap = TPL_FALSE;
free(geom_reply);
- pdraw->dpy = global.worker_display;
+ pdraw->dpy = global.worker_display;
pdraw->xDrawable = xDrawable;
for (i = 0; i < dri3_max_back + 1;i++)
/* Add new allocated drawable to drawable list */
drawable_node = calloc(1, sizeof(dri3_drawable_node));
+ if (NULL == drawable_node)
+ {
+ TPL_ERR("Failed to allocate memory for drawable node!");
+ free(pdraw);
+ return NULL;
+ }
+
drawable_node->drawable = pdraw;
drawable_node->xDrawable = xDrawable;
- tpl_list_push_back(&dri3_drawable_list, (void *)drawable_node);
+ if (TPL_TRUE != __tpl_list_push_back(&dri3_drawable_list, (void *)drawable_node))
+ {
+ TPL_ERR("List operation failed!");
+ free(pdraw);
+ free(drawable_node);
+ return NULL;
+ }
return (void*)pdraw;
}
dri3_destroy_drawable(Display *dpy, XID xDrawable)
{
dri3_drawable *pdraw;
- xcb_connection_t *c = XGetXCBConnection(dpy);
+ xcb_connection_t *c;
int i;
tpl_list_node_t *node;
dri3_drawable_node *drawable;
+ TPL_ASSERT(dpy);
+
+ c = XGetXCBConnection(dpy);
+
/* Remove drawable from list */
- node = tpl_list_get_front_node(&dri3_drawable_list);
+ node = __tpl_list_get_front_node(&dri3_drawable_list);
while (node)
{
- drawable = (dri3_drawable_node *)tpl_list_node_get_data(node);
+ drawable = (dri3_drawable_node *) __tpl_list_node_get_data(node);
if (drawable->xDrawable== xDrawable)
{
xcb_unregister_for_special_event(c, pdraw->special_event);
free(pdraw);
pdraw = NULL;
- tpl_list_remove(node, free);
+ __tpl_list_remove(node, free);
return;
}
- node = tpl_list_node_next(node);
+ node = __tpl_list_node_next(node);
}
/* If didn't find the drawable, means it is already free*/
dri3_update_drawable(void *loaderPrivate)
{
dri3_drawable *priv = loaderPrivate;
- xcb_connection_t *c = XGetXCBConnection(priv->dpy);
+ xcb_connection_t *c;
xcb_extension_t xcb_present_id = { "Present", 0 };
+ TPL_ASSERT(priv);
+ TPL_ASSERT(priv->dpy);
+
+ c = XGetXCBConnection(priv->dpy);
+
/* First time through, go get the current drawable geometry
*/ /*TODO*/
if (priv->special_event == NULL)
geom_cookie = xcb_get_geometry(c, priv->xDrawable);
geom_reply = xcb_get_geometry_reply(c, geom_cookie, NULL);
- TPL_ASSERT(geom_reply != NULL);
+ if (NULL == geom_reply)
+ {
+ TPL_ERR("Failed to get geometry reply!");
+ return TPL_FALSE;
+ }
priv->width = geom_reply->width;
priv->height = geom_reply->height;
* dri3_handle_present_event
* Process Present event from xserver
*****************************************/
-void
+static void
dri3_handle_present_event(dri3_drawable *priv, xcb_present_generic_event_t *ge)
{
- switch (ge->evtype)
+ TPL_ASSERT(priv);
+ TPL_ASSERT(ge);
+
+ switch (ge->evtype)
{
case XCB_PRESENT_CONFIGURE_NOTIFY:
{
- TRACE_BEGIN("DRI3:PRESENT_CONFIGURE_NOTIFY");
- xcb_present_configure_notify_event_t *ce = (void *) ge;
- priv->width = ce->width;
- priv->height = ce->height;
- TRACE_END();
- break;
+ TRACE_BEGIN("DRI3:PRESENT_CONFIGURE_NOTIFY");
+ xcb_present_configure_notify_event_t *ce = (void *) ge;
+ priv->width = ce->width;
+ priv->height = ce->height;
+ TRACE_END();
+ break;
}
case XCB_PRESENT_COMPLETE_NOTIFY:
{
- TRACE_BEGIN("DRI3:PRESENT_COMPLETE_NOTIFY");
+ TRACE_BEGIN("DRI3:PRESENT_COMPLETE_NOTIFY");
xcb_present_complete_notify_event_t *ce = (void *) ge;
/* Compute the processed SBC number from the received
* 32-bit serial number merged with the upper 32-bits
- * of the sent 64-bit serial number while checking for
- * wrap
- */
+ * of the sent 64-bit serial number while checking for
+ * wrap
+ */
if (ce->kind == XCB_PRESENT_COMPLETE_KIND_PIXMAP)
{
priv->recv_sbc =
break;
}
}
- else
- {
- priv->recv_msc_serial = ce->serial;
- }
- priv->ust = ce->ust;
- priv->msc = ce->msc;
- TRACE_END();
- break;
- }
+ else
+ {
+ priv->recv_msc_serial = ce->serial;
+ }
+
+ priv->ust = ce->ust;
+ priv->msc = ce->msc;
+ TRACE_END();
+ break;
+ }
case XCB_PRESENT_EVENT_IDLE_NOTIFY:
{
if (buf && buf->pixmap == ie->pixmap)
{
- TRACE_MARK("IDLE:%d",tbm_bo_export(priv->buffers[b]->tbo));
+ TRACE_MARK("IDLE:%d",tbm_bo_export(priv->buffers[b]->tbo));
buf->status = dri3_buffer_idle;
- break;
+ break;
}
}
- break;
+ break;
}
}
free(ge);
static void
dri3_flush_present_events(dri3_drawable *priv)
{
- xcb_connection_t *c = XGetXCBConnection(priv->dpy);
+ xcb_connection_t *c;
+
+ TPL_ASSERT(priv);
+ TPL_ASSERT(priv->dpy);
+
+ c = XGetXCBConnection(priv->dpy);
TRACE_BEGIN("DRI3:FLUSH_PRESENT_EVENTS");
/* Check to see if any configuration changes have occurred
dri3_handle_present_event(priv, ge);
}
}
- TRACE_END();
+ TRACE_END();
}
static tpl_bool_t
dri3_wait_for_notify(xcb_connection_t *c, dri3_drawable *priv)
{
- xcb_generic_event_t *ev;
+ xcb_generic_event_t *ev;
xcb_present_generic_event_t *ge;
- TRACE_BEGIN("TPL:DRI3:WAIT_FOR_NOTIFY");
-
- if (((uint32_t)priv->send_sbc) == 0)
- {
- TRACE_END();
- return TPL_TRUE;
- }
- for (;;)
- {
- if( (uint32_t)priv->send_sbc <= (uint32_t)priv->recv_sbc )
- {
- TRACE_END();
- return TPL_TRUE;
- }
-
- xcb_flush(c);
- ev = xcb_wait_for_special_event(c, priv->special_event);
- if (!ev)
- {
- TRACE_END();
- return TPL_FALSE;
- }
- ge = (void *) ev;
+ TPL_ASSERT(c);
+ TPL_ASSERT(priv);
+
+ TRACE_BEGIN("TPL:DRI3:WAIT_FOR_NOTIFY");
+
+ if (((uint32_t)priv->send_sbc) == 0)
+ {
+ TRACE_END();
+ return TPL_TRUE;
+ }
+ for (;;)
+ {
+ if( (uint32_t)priv->send_sbc <= (uint32_t)priv->recv_sbc )
+ {
+ TRACE_END();
+ return TPL_TRUE;
+ }
+
+ xcb_flush(c);
+ ev = xcb_wait_for_special_event(c, priv->special_event);
+ if (!ev)
+ {
+ TRACE_END();
+ return TPL_FALSE;
+ }
+ ge = (void *) ev;
dri3_handle_present_event(priv, ge);
- }
+ }
}
/** dri3_find_back
xcb_generic_event_t *ev;
xcb_present_generic_event_t *ge;
+ TPL_ASSERT(c);
+ TPL_ASSERT(priv);
+
for (;;)
{
for (b = 0; b < dri3_max_back; b++)
{
int id = (b + priv->cur_back + 1) % dri3_max_back;
- int pre_id = (id + dri3_max_back - 2) % dri3_max_back;
+ int pre_id = (id + dri3_max_back - 2) % dri3_max_back;
dri3_buffer *buffer = priv->buffers[id];
- dri3_buffer *pre_buffer = priv->buffers[pre_id];
+ dri3_buffer *pre_buffer = priv->buffers[pre_id];
- if (pre_buffer && pre_buffer->status != dri3_buffer_posted)
- pre_buffer->status = dri3_buffer_idle;
+ if (pre_buffer && pre_buffer->status != dri3_buffer_posted)
+ pre_buffer->status = dri3_buffer_idle;
- if (!buffer || buffer->status == dri3_buffer_idle)
- {
- priv->cur_back = id;
- return id;
+ if (!buffer || buffer->status == dri3_buffer_idle)
+ {
+ priv->cur_back = id;
+ return id;
}
}
xcb_flush(c);
- TRACE_BEGIN("DDK:DRI3:XCBWAIT");
+ TRACE_BEGIN("DDK:DRI3:XCBWAIT");
ev = xcb_wait_for_special_event(c, priv->special_event);
- TRACE_END();
+ TRACE_END();
+
if (!ev)
- {
+ {
return -1;
- }
+ }
+
ge = (void *) ev;
dri3_handle_present_event(priv, ge);
}
dri3_alloc_render_buffer(dri3_drawable *priv,
int width, int height, int depth, int cpp)
{
- Display *dpy = priv->dpy;
- Drawable draw = priv->xDrawable;
+ Display *dpy;
+ Drawable draw;
dri3_buffer *buffer = NULL;
- xcb_connection_t *c = XGetXCBConnection(dpy);
+ xcb_connection_t *c;
xcb_pixmap_t pixmap = 0;
int buffer_fd;
int size;
xcb_void_cookie_t cookie;
xcb_generic_error_t *error;
+ TPL_ASSERT(priv);
+ TPL_ASSERT(priv->dpy);
+
+ dpy = priv->dpy;
+ draw = priv->xDrawable;
+
+ c = XGetXCBConnection(dpy);
+
/* Allocate the image from the driver
*/
buffer = calloc(1, sizeof (dri3_buffer));
if (!buffer)
{
+ TPL_ERR("Failed to allocate buffer!");
goto no_buffer;
}
/* size = height * width * depth/8;*/
/* size = ((width * 32)>>5) * 4 * height; */
- /* [BEGIN: 20141125-xing.huang] calculate pitch and size
- * by input parameter cpp */
+ /* calculate pitch and size by input parameter cpp */
/* buffer->pitch = width*(cpp/8); */
- /* 2015-04-15 joonbum.ko@samsung.com */
- /* Modify the calculation of pitch (strdie) */
- buffer->pitch = SIZE_ALIGN((width * cpp)>>3, ALIGNMENT_PITCH_ARGB);
+ /* Modify the calculation of pitch (strdie) */
+ buffer->pitch = SIZE_ALIGN((width * cpp)>>3, ALIGNMENT_PITCH_ARGB);
size = buffer->pitch*height;
- /* [END:20141125-xing.huang] */
buffer->tbo = tbm_bo_alloc(priv->bufmgr, size, TBM_BO_DEFAULT);
if (NULL == buffer->tbo)
{
+ TPL_ERR("TBM bo alloc failed!");
+ free(buffer);
goto no_buffer;
}
/* dup tbo, because X will close it */
- /* 2015-04-08 joonbum.ko@samsung.com */
- /* delete tbm_bo_get_handle function call and
- add tbm_bo_export_fd function call */
+ /* 2015-04-08 joonbum.ko@samsung.com */
+ /* delete tbm_bo_get_handle function call and
+ add tbm_bo_export_fd function call */
- handle = tbm_bo_get_handle(buffer->tbo, TBM_DEVICE_3D);
- buffer_fd = dup(handle.u32);
+ handle = tbm_bo_get_handle(buffer->tbo, TBM_DEVICE_3D);
+ buffer_fd = dup(handle.u32);
- /* buffer_fd = tbm_bo_export_fd(buffer->tbo);*/
- /* 2015-04-08 joonbum.ko@samsung.com */
- /* disable the value dma_buf_fd */
+ /* buffer_fd = tbm_bo_export_fd(buffer->tbo);*/
+ /* 2015-04-08 joonbum.ko@samsung.com */
+ /* disable the value dma_buf_fd */
buffer->dma_buf_fd = handle.u32;
buffer->size = size;
cookie = xcb_dri3_pixmap_from_buffer_checked(c,
depth, cpp,
buffer_fd);
error = xcb_request_check( c, cookie);
- /* 2015-04-08 joonbum.ko@samsung.com */
- /* buffer_fd is unuseful */
- /* close(buffer_fd);*/
+ /* 2015-04-08 joonbum.ko@samsung.com */
+ /* buffer_fd is unuseful */
+ /* close(buffer_fd);*/
if (error)
{
+ TPL_ERR("No pixmap!");
goto no_pixmap;
}
if (0 == pixmap)
{
+ TPL_ERR("No pixmap!");
goto no_pixmap;
}
static void
dri3_free_render_buffer(dri3_drawable *pdraw, dri3_buffer *buffer)
{
- xcb_connection_t *c = XGetXCBConnection(pdraw->dpy);
+ xcb_connection_t *c;
- /* 2015-04-08 joonbum.ko@samsung.com */
- /* if drawable type is pixmap, it requires only free buffer */
- if (!pdraw->is_pixmap)
- {
- if (buffer->own_pixmap)
- xcb_free_pixmap(c, buffer->pixmap);
+ TPL_ASSERT(pdraw);
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(pdraw->dpy);
+
+ c = XGetXCBConnection(pdraw->dpy);
+
+ /* 2015-04-08 joonbum.ko@samsung.com */
+ /* if drawable type is pixmap, it requires only free buffer */
+ if (!pdraw->is_pixmap)
+ {
+ if (buffer->own_pixmap)
+ xcb_free_pixmap(c, buffer->pixmap);
tbm_bo_unref(buffer->tbo);
- /* added a ref when created and unref while free, see dri3_get_pixmap_buffer */
- }
+ /* added a ref when created and unref while free, see dri3_get_pixmap_buffer */
+ }
- buffer = NULL;
+ buffer = NULL;
}
dri3_get_window_buffer(void *loaderPrivate, int cpp)
{
dri3_drawable *priv = loaderPrivate;
- xcb_connection_t *c = XGetXCBConnection(priv->dpy);
+ xcb_connection_t *c;
dri3_buffer *backbuffer = NULL;
int back_buf_id,reuse = 1;
- uint32_t old_bo_name = 0;
+ uint32_t old_bo_name = 0;
+
+ TPL_ASSERT(priv);
+ TPL_ASSERT(priv->dpy);
+
+ c = XGetXCBConnection(priv->dpy);
- TRACE_BEGIN("DDK:DRI3:GETBUFFERS:WINDOW");
- TRACE_BEGIN("DDK:DRI3:FINDBACK");
+ TRACE_BEGIN("DDK:DRI3:GETBUFFERS:WINDOW");
+ TRACE_BEGIN("DDK:DRI3:FINDBACK");
back_buf_id = dri3_find_back(c, priv);
- TRACE_END();
+ TRACE_END();
backbuffer = priv->buffers[back_buf_id];
/* Allocate the new buffers
*/
- TRACE_BEGIN("DDK:DRI3:ALLOCRENDERBUFFER");
+ TRACE_BEGIN("DDK:DRI3:ALLOCRENDERBUFFER");
new_buffer = dri3_alloc_render_buffer(priv,
priv->width, priv->height, priv->depth, cpp);
- TRACE_END();
+ TRACE_END();
if (!new_buffer)
{
- TRACE_END();
+ TRACE_END();
return NULL;
}
if (backbuffer)
/* [BEGIN: 20141125-xuelian.bai] Size not match,this buffer
* must be removed from buffer cache, so we have to save
* dma_buf_fd of old buffer.*/
- old_bo_name = tbm_bo_export(backbuffer->tbo);
+ old_bo_name = tbm_bo_export(backbuffer->tbo);
/* [END: 20141125-xuelian.bai] */
- TRACE_BEGIN("DDK:DRI3:FREERENDERBUFFER");
+ TRACE_BEGIN("DDK:DRI3:FREERENDERBUFFER");
dri3_free_render_buffer(priv, backbuffer);
- TRACE_END();
+ TRACE_END();
}
backbuffer = new_buffer;
backbuffer->buffer_type = dri3_buffer_back;
backbuffer->old_bo_name = old_bo_name;
- priv->buffers[back_buf_id] = backbuffer;
- reuse = 0;
+ priv->buffers[back_buf_id] = backbuffer;
+ reuse = 0;
}
backbuffer->flags = DRI2_BUFFER_FB;
- backbuffer->status = dri3_buffer_busy;
- if(reuse)
+ backbuffer->status = dri3_buffer_busy;
+ if(reuse)
{
backbuffer->flags |= DRI2_BUFFER_REUSED;
}
/* Return the requested buffer */
- TRACE_END();
+ TRACE_END();
- TRACE_MARK("%d",tbm_bo_export(backbuffer->tbo));
+ TRACE_MARK("%d",tbm_bo_export(backbuffer->tbo));
return backbuffer;
}
dri3_get_pixmap_buffer(void *loaderPrivate, Pixmap pixmap, int cpp)/*TODO:format*/
{
dri3_drawable *pdraw = loaderPrivate;
- dri3_buffer *buffer = NULL;
+ dri3_buffer *buffer = NULL;
xcb_dri3_buffer_from_pixmap_cookie_t bp_cookie;
xcb_dri3_buffer_from_pixmap_reply_t *bp_reply;
int *fds;
xcb_connection_t *c;
tbm_bo tbo = NULL;
- TRACE_BEGIN("DDK:DRI3:GETBUFFERS:PIXMAP");
+ TPL_ASSERT(pdraw);
+ TPL_ASSERT(pdraw->dpy);
+
+ TRACE_BEGIN("DDK:DRI3:GETBUFFERS:PIXMAP");
- dpy = pdraw->dpy;
+ dpy = pdraw->dpy;
c = XGetXCBConnection(dpy);
/* Get an FD for the pixmap object
bp_cookie = xcb_dri3_buffer_from_pixmap(c, pixmap);
bp_reply = xcb_dri3_buffer_from_pixmap_reply(c, bp_cookie, NULL);
if (!bp_reply)
- {
+ {
goto no_image;
- }
+ }
fds = xcb_dri3_buffer_from_pixmap_reply_fds(c, bp_reply);
- tbo = tbm_bo_import_fd(pdraw->bufmgr,(tbm_fd)(*fds));
+ tbo = tbm_bo_import_fd(pdraw->bufmgr,(tbm_fd)(*fds));
- if (!buffer)
- {
- buffer = calloc(1, sizeof (dri3_buffer));
- if (!buffer)
- goto no_buffer;
- }
+ if (!buffer)
+ {
+ buffer = calloc(1, sizeof (dri3_buffer));
+ if (!buffer)
+ goto no_buffer;
+ }
buffer->tbo = tbo;
- /* 2015-04-08 joonbum.ko@samsung.com */
- /* disable the value dma_buf_fd */
+ /* 2015-04-08 joonbum.ko@samsung.com */
+ /* disable the value dma_buf_fd */
buffer->dma_buf_fd = *fds;
buffer->pixmap = pixmap;
buffer->own_pixmap = TPL_FALSE;
buffer->width = bp_reply->width;
buffer->height = bp_reply->height;
buffer->buffer_type = dri3_buffer_front;
- buffer->flags = DRI3_BUFFER_REUSED;
- /* 2015-04-07 joonbum.ko@samsung.com */
- /* add buffer information(cpp, pitch, size) */
- buffer->cpp = cpp;
- buffer->pitch = bp_reply->stride;
- buffer->size = buffer->pitch * bp_reply->height;
+ buffer->flags = DRI3_BUFFER_REUSED;
+ /* 2015-04-07 joonbum.ko@samsung.com */
+ /* add buffer information(cpp, pitch, size) */
+ buffer->cpp = cpp;
+ buffer->pitch = bp_reply->stride;
+ buffer->size = buffer->pitch * bp_reply->height;
pdraw->buffers[dri3_max_back] = buffer;
- /* 2015-04-08 joonbum.ko@samsung.com */
- /* fds is unuseful */
- close(*fds);
- TRACE_END();
+ /* 2015-04-08 joonbum.ko@samsung.com */
+ /* fds is unuseful */
+ close(*fds);
+ TRACE_END();
return buffer;
/* 2015-04-09 joonbum.ko@samsung.com */
/* change the lable order */
no_image:
- if (buffer)
- free(buffer);
+ if (buffer)
+ free(buffer);
no_buffer:
- TRACE_END();
+ TRACE_END();
return NULL;
}
static dri3_buffer *dri3_get_buffers(XID drawable, void *loaderPrivate,
- int *width, int *height, unsigned int *attachments,
- int cpp)
+ unsigned int *attachments, int cpp)
{
dri3_drawable *priv = loaderPrivate;
dri3_buffer *buffer = NULL;
- TRACE_BEGIN("DDK:DRI3:GETBUFFERS");
+ TPL_ASSERT(priv);
+ TPL_ASSERT(attachments);
+
+ TRACE_BEGIN("DDK:DRI3:GETBUFFERS");
if (drawable != priv->xDrawable)
{
- TRACE_END();
+ TPL_ERR("Drawable mismatch!");
+ TRACE_END();
return NULL;
}
if (!dri3_update_drawable(loaderPrivate))
{
- TRACE_END();
+ TPL_ERR("Update drawable failed!");
+ TRACE_END();
return NULL;
}
else
buffer = dri3_get_window_buffer(loaderPrivate, cpp);
- *width = (int)buffer->width;
- *height = (int)buffer->height;
+ if (NULL == buffer)
+ {
+ TPL_ERR("Get buffer failed!");
+ return NULL;
+ }
- TRACE_END();
+ TRACE_END();
return buffer;
}
int64_t target_msc = 0;
int64_t divisor = 0;
int64_t remainder = 0;
- xcb_connection_t *c = XGetXCBConnection(dpy);
- dri3_drawable *pDrawable = (dri3_drawable*)priv;
+ xcb_connection_t *c;
+ dri3_drawable *pDrawable;
dri3_buffer *back = NULL;
- int i = 0;
+ int i = 0;
+
+ TPL_ASSERT(dpy);
+ TPL_ASSERT(priv);
+ TPL_ASSERT(frame_buffer);
+
+ c = XGetXCBConnection(dpy);
- back = (dri3_buffer*)frame_buffer->backend.data;
+ pDrawable = (dri3_drawable*) priv;
+ back = (dri3_buffer*) frame_buffer->backend.data;
- if ((back == NULL)||(pDrawable == NULL)||(pDrawable->is_pixmap != 0))
+ if ((back == NULL)||(pDrawable == NULL)||(pDrawable->is_pixmap != 0))
{
- TRACE_END();
+ TRACE_END();
return ret;
}
- /* Process any present events that have been received from the X
+ /* Process any present events that have been received from the X
* server until receive complete notify.
*/
- if (!dri3_wait_for_notify(c, pDrawable))
- {
- TRACE_END();
- return ret;
- }
- /* [BEGIN: 20140119-leiba.sun] Add support for buffer age
- * When swap buffer, increase buffer age of every back buffer */
- for(i = 0; i < dri3_max_back; i++)
- {
- if((pDrawable->buffers[i] != NULL)&&(pDrawable->buffers[i]->buffer_age > 0))
- pDrawable->buffers[i]->buffer_age++;
- }
- back->buffer_age = 1;
- /* [END:20150119-leiba.sun] */
- /* set busy flag */
+ if (!dri3_wait_for_notify(c, pDrawable))
+ {
+ TRACE_END();
+ return ret;
+ }
+ /* [BEGIN: 20140119-leiba.sun] Add support for buffer age
+ * When swap buffer, increase buffer age of every back buffer */
+ for(i = 0; i < dri3_max_back; i++)
+ {
+ if((pDrawable->buffers[i] != NULL)&&(pDrawable->buffers[i]->buffer_age > 0))
+ pDrawable->buffers[i]->buffer_age++;
+ }
+ back->buffer_age = 1;
+ /* [END:20150119-leiba.sun] */
+ /* set busy flag */
back->status = dri3_buffer_posted;
/* Compute when we want the frame shown by taking the last known
back->last_swap = pDrawable->send_sbc;
- TRACE_MARK("SWAP:%d", tbm_bo_export(back->tbo)) ;
+ TRACE_MARK("SWAP:%d", tbm_bo_export(back->tbo)) ;
xcb_present_pixmap(c,
pDrawable->xDrawable, /* dst */
back->pixmap, /* src */
0, /* y_off */
None, /* target_crtc */
None,
- 0,
+ 0,
XCB_PRESENT_OPTION_NONE,
/*target_msc*/0,
divisor,
void
__tpl_x11_dri3_buffer_fini(tpl_buffer_t *buffer)
{
- dri3_buffer* back = (dri3_buffer*)buffer->backend.data;
+ dri3_buffer* back;
+
+ TPL_ASSERT(buffer);
+
+ back = (dri3_buffer*)buffer->backend.data;
+
if (back)
{
- tbm_bo bo = back->tbo;
+ tbm_bo bo = back->tbo;
tbm_bo_map(bo, TBM_DEVICE_3D, TBM_OPTION_READ);
tbm_bo_unmap(bo);
tbm_bo_unref(bo);
buffer->backend.data = NULL;
- free(back);
+ free(back);
}
}
tbm_bo bo;
tbm_bo_handle handle;
+ TPL_ASSERT(buffer);
+
TPL_IGNORE(size);
bo = ((dri3_buffer*)buffer->backend.data)->tbo;
TPL_ASSERT(bo);
{
tbm_bo bo;
tbm_bo_handle handle;
- dri3_buffer* back = (dri3_buffer*)buffer->backend.data;
+ dri3_buffer* back;
- bo = back->tbo;
- TPL_ASSERT(bo);
- TRACE_BEGIN("TPL:BUFFERLOCK:%d",tbm_bo_export(bo));
+ TPL_ASSERT(buffer);
+ TPL_ASSERT(buffer->backend.data);
- TPL_OBJECT_UNLOCK(buffer);
+ back = (dri3_buffer*) buffer->backend.data;
+ bo = back->tbo;
+
+ if (NULL == bo)
+ {
+ TPL_ERR("bo is NULL!");
+ return TPL_FALSE;
+ }
+
+ TRACE_BEGIN("TPL:BUFFERLOCK:%d",tbm_bo_export(bo));
+
+ TPL_OBJECT_UNLOCK(buffer);
switch (usage)
{
return TPL_FALSE;
}
- TPL_OBJECT_LOCK(buffer);
+ TPL_OBJECT_LOCK(buffer);
if (handle.u32 != 0 || handle.ptr != NULL)
- {
- TRACE_END();
+ {
+ TRACE_END();
return TPL_FALSE;
- }
- TRACE_END();
+ }
+ TRACE_END();
return TPL_TRUE;
}
void
__tpl_x11_dri3_buffer_unlock(tpl_buffer_t *buffer)
{
- dri3_buffer* back = (dri3_buffer*)buffer->backend.data;
- tbm_bo bo = back->tbo;
- TPL_ASSERT(bo);
+ dri3_buffer *back;
+ tbm_bo bo;
+
+ TPL_ASSERT(buffer);
+
+ back = (dri3_buffer*) buffer->backend.data;
+ bo = back->tbo;
- TRACE_BEGIN("TPL:BUFFERUNLOCK:%d",tbm_bo_export(back->tbo));
+ if (NULL == bo)
+ {
+ TPL_ERR("bo is NULL!");
+ return;
+ }
- TPL_OBJECT_UNLOCK(buffer);
+ TRACE_BEGIN("TPL:BUFFERUNLOCK:%d",tbm_bo_export(back->tbo));
+
+ TPL_OBJECT_UNLOCK(buffer);
tbm_bo_unmap(bo);
- TPL_OBJECT_LOCK(buffer);
+ TPL_OBJECT_LOCK(buffer);
- TRACE_END();
+ TRACE_END();
}
-
static Display *
__tpl_x11_dri3_get_worker_display()
{
- Display *display;
- pthread_mutex_t mutex = __tpl_x11_get_global_mutex();
+ Display *display;
+ pthread_mutex_t mutex = __tpl_x11_get_global_mutex();
pthread_mutex_lock(&mutex);
TPL_ASSERT(global.display_count > 0);
{
pthread_mutex_t mutex = __tpl_x11_get_global_mutex();
+ TPL_ASSERT(display);
+
XInitThreads();
if (display->native_handle == NULL)
{
drmGetMagic(global.bufmgr_fd, &magic);
global.bufmgr = tbm_bufmgr_init(global.bufmgr_fd);
- tpl_list_init(&dri3_drawable_list);
+ __tpl_list_init(&dri3_drawable_list);
/* [BEGIN: 20141125-xuelian.bai] Add env for setting number of back buffers*/
{
global.bufmgr_fd = -1;
global.bufmgr = NULL;
- tpl_list_fini(&dri3_drawable_list, NULL);
+ __tpl_list_fini(&dri3_drawable_list, NULL);
}
pthread_mutex_unlock(&mutex);
static tpl_bool_t
__tpl_x11_dri3_surface_init(tpl_surface_t *surface)
{
- Display *display = NULL;
- XID drawable;
+ Display *display = NULL;
+ XID drawable;
tpl_x11_dri3_surface_t *x11_surface;
- x11_surface = (tpl_x11_dri3_surface_t *)calloc(1,
- sizeof(tpl_x11_dri3_surface_t));
+ TPL_ASSERT(surface);
+ x11_surface = (tpl_x11_dri3_surface_t *)calloc(1, sizeof(tpl_x11_dri3_surface_t));
if (x11_surface == NULL)
{
- TPL_ASSERT(TPL_FALSE);
+ TPL_ERR("Failed to allocate buffer!");
return TPL_FALSE;
}
x11_surface->latest_post_interval = -1;
- tpl_list_init(&x11_surface->buffer_cache);
+ __tpl_list_init(&x11_surface->buffer_cache);
display = (Display *)surface->display->native_handle;
drawable = (XID)surface->native_handle;
static void
__tpl_x11_dri3_surface_fini(tpl_surface_t *surface)
{
- Display *display
- = (Display *)surface->display->native_handle;
- tpl_x11_dri3_surface_t *x11_surface
- = (tpl_x11_dri3_surface_t *)surface->backend.data;
+ Display *display;
+ tpl_x11_dri3_surface_t *x11_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->display);
+ TPL_ASSERT(surface->display->native_handle);
+
+ display = (Display *) surface->display->native_handle;
+ x11_surface = (tpl_x11_dri3_surface_t *) surface->backend.data;
dri3_destroy_drawable(display, (XID)surface->native_handle);
XRectangle *xrects;
XRectangle xrects_stack[TPL_STACK_XRECTANGLE_SIZE];
- TRACE_BEGIN("DDK:DRI3:SWAPBUFFERS");
+ TPL_ASSERT(surface);
+ TPL_ASSERT(frame);
+
+ TRACE_BEGIN("DDK:DRI3:SWAPBUFFERS");
x11_surface = (tpl_x11_dri3_surface_t *)surface->backend.data;
- display = __tpl_x11_dri3_get_worker_display();
+ display = __tpl_x11_dri3_get_worker_display();
if (frame->interval != x11_surface->latest_post_interval)
{
x11_surface->latest_post_interval = frame->interval;/*FIXME:set interval?*/
}
- if (tpl_region_is_empty(&frame->damage))
+ if (__tpl_region_is_empty(&frame->damage))
{
dri3_swap_buffers(display, x11_surface->drawable, frame->buffer, 0,0);
}
}
frame->state = TPL_FRAME_STATE_POSTED;
- TRACE_END();
+ TRACE_END();
}
-
static void
__tpl_x11_dri3_surface_post(tpl_surface_t *surface, tpl_frame_t *frame)
{
+ TPL_ASSERT(surface);
+ TPL_ASSERT(frame);
+
__tpl_x11_dri3_surface_post_internal(surface, frame, TPL_TRUE);
}
-static void
+static tpl_bool_t
__tpl_x11_dri3_surface_begin_frame(tpl_surface_t *surface)
{
tpl_frame_t *prev_frame;
+ TPL_ASSERT(surface);
+
if (surface->type != TPL_SURFACE_TYPE_WINDOW)
- return;
+ return TPL_TRUE;
prev_frame = __tpl_surface_get_latest_frame(surface);
global.win_swap_type == TPL_X11_SWAP_TYPE_SYNC))
{
__tpl_surface_wait_all_frames(surface);
- }
+ }
}
+
+ return TPL_TRUE;
}
static tpl_bool_t
__tpl_x11_dri3_surface_validate_frame(tpl_surface_t *surface)
{
- tpl_frame_t *prev_frame;
+ tpl_frame_t *prev_frame;
if (surface->type != TPL_SURFACE_TYPE_WINDOW)
return TPL_TRUE;
if (surface->frame == NULL)
return TPL_TRUE;
- prev_frame = __tpl_surface_get_latest_frame(surface);
+ prev_frame = __tpl_surface_get_latest_frame(surface);
if (prev_frame && prev_frame->state != TPL_FRAME_STATE_POSTED)
{
if ((DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) &&
- global.fb_swap_type == TPL_X11_SWAP_TYPE_LAZY) ||
- (!DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) &&
- global.win_swap_type == TPL_X11_SWAP_TYPE_LAZY))
+ global.fb_swap_type == TPL_X11_SWAP_TYPE_LAZY) ||
+ (!DRI2_BUFFER_IS_FB(prev_frame->buffer->backend.flags) &&
+ global.win_swap_type == TPL_X11_SWAP_TYPE_LAZY))
{
__tpl_surface_wait_all_frames(surface);
- return TPL_TRUE;
+ return TPL_TRUE;
}
}
return TPL_TRUE;
}
-static void
+static tpl_bool_t
__tpl_x11_dri3_surface_end_frame(tpl_surface_t *surface)
{
- tpl_frame_t *frame = __tpl_surface_get_latest_frame(surface);
- tpl_x11_dri3_surface_t *x11_surface = (tpl_x11_dri3_surface_t *)surface->backend.data;
+ tpl_frame_t *frame;
+ tpl_x11_dri3_surface_t *x11_surface;
+
+ TPL_ASSERT(surface);
+ TPL_ASSERT(surface->backend.data);
+
+ frame = __tpl_surface_get_latest_frame(surface);
+ x11_surface = (tpl_x11_dri3_surface_t *) surface->backend.data;
if (frame)
{
x11_surface->latest_render_target = frame->buffer;
if ((DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) &&
- global.fb_swap_type == TPL_X11_SWAP_TYPE_ASYNC) ||
- (!DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) &&
- global.win_swap_type == TPL_X11_SWAP_TYPE_ASYNC))
+ global.fb_swap_type == TPL_X11_SWAP_TYPE_ASYNC) ||
+ (!DRI2_BUFFER_IS_FB(frame->buffer->backend.flags) &&
+ global.win_swap_type == TPL_X11_SWAP_TYPE_ASYNC))
{
__tpl_x11_dri3_surface_post_internal(surface, frame, TPL_FALSE);
}
}
+
+ return TPL_TRUE;
}
/* 2015-04-08 joonbum.ko@samsung.com */
static tpl_buffer_t *
__tpl_x11_dri3_surface_get_buffer(tpl_surface_t *surface, tpl_bool_t *reset_buffers)
{
- Drawable drawable;
- dri3_buffer *buffer = NULL;
- tpl_buffer_t *tpl_buffer = NULL;
- uint32_t attachments[1] = { dri3_buffer_back };
- tbm_bo bo;
- tbm_bo_handle bo_handle;
- int width, height;
- tpl_x11_dri3_surface_t *x11_surface =
- (tpl_x11_dri3_surface_t *)surface->backend.data;
+ Drawable drawable;
+ dri3_buffer *buffer = NULL;
+ tpl_buffer_t *tpl_buffer = NULL;
+ uint32_t attachments[1] = { dri3_buffer_back };
+ tbm_bo bo;
+ tbm_bo_handle bo_handle;
+ tpl_x11_dri3_surface_t *x11_surface;
int cpp = 0;
- if (surface->type == TPL_SURFACE_TYPE_PIXMAP)
+ TPL_ASSERT(surface);
+
+ x11_surface = (tpl_x11_dri3_surface_t *)surface->backend.data;
+
+ if (surface->type == TPL_SURFACE_TYPE_PIXMAP)
{
attachments[0] = dri3_buffer_front;
}
cpp = 32;/*_mali_surface_specifier_bpp(&(surface->sformat)); cpp get from mali is not right */
/* [END: 20141125-xing.huang] */
- buffer = dri3_get_buffers(drawable, x11_surface->drawable, &width,
- &height, attachments, cpp);
+ buffer = dri3_get_buffers(drawable, x11_surface->drawable, attachments, cpp);
if (DRI2_BUFFER_IS_REUSED(buffer->flags))
{
&x11_surface->buffer_cache,
tbm_bo_export(buffer->tbo));
- if (tpl_buffer)
+ if (tpl_buffer)
{
/* If the buffer name is reused and there's a cache
* entry for that name, just update the buffer age
* and return. */
- /* [BEGIN: 20140119-leiba.sun] Add support for buffer age */
- tpl_buffer->age = buffer->buffer_age;
- /* [END:20150119-leiba.sun] */
+ /* [BEGIN: 20140119-leiba.sun] Add support for buffer age */
+ tpl_buffer->age = buffer->buffer_age;
+ /* [END:20150119-leiba.sun] */
if (surface->type == TPL_SURFACE_TYPE_PIXMAP)
- tbm_bo_unref (buffer->tbo);
+ tbm_bo_unref (buffer->tbo);
- goto done;
+ goto done;
}
-
}
- if (!tpl_buffer)
+ if (!tpl_buffer)
{
/* Remove the buffer from the cache. */
__tpl_x11_surface_buffer_cache_remove(
&x11_surface->buffer_cache,
tbm_bo_export(buffer->tbo));
- if(buffer->old_bo_name != 0)
+ if(buffer->old_bo_name != 0)
{
__tpl_x11_surface_buffer_cache_remove(
&x11_surface->buffer_cache,
buffer->old_bo_name);
- buffer->old_bo_name = 0;
+ buffer->old_bo_name = 0;
}
}
if (bo == NULL)
{
- TPL_ASSERT(TPL_FALSE);
+ TPL_ERR("bo is NULL!");
goto done;
}
/* Create tpl buffer. */
tpl_buffer = __tpl_buffer_alloc(surface, (size_t) tbm_bo_export(buffer->tbo),
(int)bo_handle.u32,
- width, height, buffer->cpp * 8, buffer->pitch);
+ buffer->width, buffer->height, buffer->cpp * 8, buffer->pitch);
+ if (NULL == tpl_buffer)
+ {
+ TPL_ERR("TPL buffer alloc failed!");
+ goto done;
+ }
- if (surface->type != TPL_SURFACE_TYPE_PIXMAP)
- tbm_bo_ref(buffer->tbo);
+ if (surface->type != TPL_SURFACE_TYPE_PIXMAP)
+ tbm_bo_ref(buffer->tbo);
tpl_buffer->age = DRI2_BUFFER_GET_AGE(buffer->flags);
tpl_buffer->backend.data = (void *)buffer;
tpl_buffer->backend.flags = buffer->flags;
- /* [BEGIN: 20140119-leiba.sun] Add support for buffer age
- * save surface for later use */
- tpl_buffer->surface = surface;
- /* [END:20150119-leiba.sun] */
+ /* [BEGIN: 20140119-leiba.sun] Add support for buffer age
+ * save surface for later use */
+ tpl_buffer->surface = surface;
+ /* [END:20150119-leiba.sun] */
__tpl_x11_surface_buffer_cache_add(&x11_surface->buffer_cache, tpl_buffer);
tpl_object_unreference(&tpl_buffer->base);
{
/* Users use this output value to check if they have to reset previous buffers. */
*reset_buffers = !DRI2_BUFFER_IS_REUSED(buffer->flags) ||
- width != surface->width || height != surface->height;
+ buffer->width != surface->width || buffer->height != surface->height;
}
return tpl_buffer;
int
__tpl_x11_dri3_get_buffer_age(tpl_buffer_t *buffer)
{
- dri3_buffer *back = (dri3_buffer*)buffer->backend.data;
+ dri3_buffer *back;
+
+ TPL_ASSERT(buffer);
+
+ back = (dri3_buffer*) buffer->backend.data;
+
+ TPL_ASSERT(back);
+
return back->buffer_age;
}
/* [END:20150119-leiba.sun] */
void
__tpl_display_init_backend_x11_dri3(tpl_display_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_X11_DRI3;
backend->data = NULL;
backend->fini = __tpl_x11_dri3_display_fini;
backend->query_config = __tpl_x11_display_query_config;
backend->filter_config = NULL;
- backend->get_window_info = __tpl_x11_display_get_window_info;
- backend->get_pixmap_info = __tpl_x11_display_get_pixmap_info;
+ backend->get_window_info = __tpl_x11_display_get_window_info;
+ backend->get_pixmap_info = __tpl_x11_display_get_pixmap_info;
backend->flush = __tpl_x11_display_flush;
}
void
__tpl_surface_init_backend_x11_dri3(tpl_surface_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_X11_DRI3;
backend->data = NULL;
void
__tpl_buffer_init_backend_x11_dri3(tpl_buffer_backend_t *backend)
{
+ TPL_ASSERT(backend);
+
backend->type = TPL_BACKEND_X11_DRI3;
backend->data = NULL;
backend->lock = __tpl_x11_dri3_buffer_lock;
backend->unlock = __tpl_x11_dri3_buffer_unlock;
/* [BEGIN: 20140119-leiba.sun] Add support for buffer age */
- backend->get_buffer_age = __tpl_x11_dri3_get_buffer_age;
+ backend->get_buffer_age = __tpl_x11_dri3_get_buffer_age;
/* [END:20150119-leiba.sun] */
}
-
-
typedef enum
{
+ TPL_X11_SWAP_TYPE_ERROR = -1,
TPL_X11_SWAP_TYPE_SYNC = 0,
TPL_X11_SWAP_TYPE_ASYNC,
TPL_X11_SWAP_TYPE_LAZY,
+ TPL_X11_SWAP_TYPE_MAX
} tpl_x11_swap_type_t;
struct _tpl_x11_global
__tpl_x11_surface_buffer_cache_find(tpl_list_t *buffer_cache, unsigned int name);
void
__tpl_x11_surface_buffer_cache_remove(tpl_list_t *buffer_cache, unsigned int name);
-void
+tpl_bool_t
__tpl_x11_surface_buffer_cache_add(tpl_list_t *buffer_cache, tpl_buffer_t *buffer);
void
__tpl_x11_surface_buffer_cache_clear(tpl_list_t *buffer_cache);