/* LCOV_EXCL_START */
+static void
+_tbm_bufmgr_check_bo_cnt(tbm_bufmgr bufmgr)
+{
+ static int last_chk_bo_cnt = 0;
+
+ if ((bufmgr->bo_cnt >= 500) && ((bufmgr->bo_cnt % 20) == 0) &&
+ (bufmgr->bo_cnt > last_chk_bo_cnt)) {
+ TBM_DBG("============TBM BO CNT DEBUG: bo_cnt=%d\n", bufmgr->bo_cnt);
+ tbm_bufmgr_debug_show(bufmgr);
+ last_chk_bo_cnt = bufmgr->bo_cnt;
+ }
+}
+
+static void
+_tbm_bufmgr_initialize_bo(tbm_bufmgr bufmgr, tbm_bo bo, int flags)
+{
+ bo->bufmgr = bufmgr;
+ bo->flags = flags;
+ bo->magic = TBM_BO_MAGIC;
+ bo->ref_cnt = 1;
+
+ LIST_INITHEAD(&bo->user_data_list);
+
+ bufmgr->bo_cnt++;
+ LIST_ADD(&bo->item_link, &bufmgr->bo_list);
+}
+
void
_tbm_bufmgr_mutex_lock(void)
{
static tbm_bufmgr
_tbm_bufmgr_init(int fd, int server)
{
+ tbm_error_e error = TBM_ERROR_NONE;
+
#ifdef TBM_BUFMGR_INIT_TIME
struct timeval start_tv, end_tv;
#endif
_tbm_bufmgr_copy_module_data(gBufMgr, gBufMgr->module, 0);
/* check the essential capabilities of tbm_module */
- gBufMgr->capabilities = tbm_module_bufmgr_get_capabilities(gBufMgr->module);
- if (gBufMgr->capabilities == HAL_TBM_BUFMGR_CAPABILITY_NONE) {
+ gBufMgr->capabilities = tbm_module_bufmgr_get_capabilities(gBufMgr->module, &error);
+ if (gBufMgr->capabilities == TBM_BUFMGR_CAPABILITY_NONE) {
TBM_ERR("The capabilities of the backend module is TBM_BUFMGR_CAPABILITY_NONE.");
TBM_ERR("TBM_BUFMGR_CAPABILITY_SHARE_FD is the essential capability.");
tbm_module_unload(gBufMgr->module);
- _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
+ _tbm_set_last_result(error);
free(gBufMgr);
gBufMgr = NULL;
pthread_mutex_unlock(&gLock);
return NULL;
}
- if (!(gBufMgr->capabilities & HAL_TBM_BUFMGR_CAPABILITY_SHARE_FD)) {
+ if (!(gBufMgr->capabilities & TBM_BUFMGR_CAPABILITY_SHARE_FD)) {
TBM_ERR("The capabilities of the backend module had no TBM_BUFMGR_CAPABILITY_SHARE_FD.");
TBM_ERR("The tbm backend has to get TBM_BUFMGR_CAPABILITY_SHARE_FD. ");
tbm_module_unload(gBufMgr->module);
int
tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
{
- int ret;
tbm_error_e error;
_tbm_bufmgr_mutex_lock();
_tbm_set_last_result(TBM_ERROR_NONE);
- TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
-
- if (bufmgr->use_hal_tbm) {
- if (hal_tbm_backend_has_drm_device(bufmgr->hal_backend, &ret)) {
- int fd = tbm_drm_helper_get_fd(); // this must be the auth drm_fd.(master drm_fd);
- if (fd < -1) {
- TBM_ERR("error: tbm_bufmgr(%p) native_display(%p)\n", bufmgr, native_display);
- _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
-
- // make the wayland server socket for sending the authenticated drm_fd to wayland clients.
- if (!tbm_drm_helper_wl_auth_server_init(native_display, fd, NULL, 0)) {
- TBM_ERR("error: tbm_drm_helper_wl_auth_server_init failed\n", bufmgr, native_display);
- close(fd);
- _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
- TBM_INFO("tbm creates a wayland socket for authentication of drm_fd.");
-
- bufmgr->auth_wl_socket_created = 1;
- bufmgr->auth_fd = fd;
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), 0);
- // TODO: this duplication will be removed after refactoring tbm_module
- bufmgr->module->auth_wl_socket_created = 1;
- bufmgr->module->auth_fd = fd;
- }
- } else if (bufmgr->backend_module_data) {
- if (!bufmgr->bufmgr_func->bufmgr_bind_native_display) {
- TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n",
- bufmgr, native_display);
- _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
- _tbm_bufmgr_mutex_unlock();
- return 1;
- }
+ error = tbm_module_bufmgr_bind_native_display(bufmgr->module, native_display);
+ if (error != TBM_ERROR_NONE) {
+ _tbm_set_last_result(error);
+ _tbm_bufmgr_mutex_unlock();
- error = bufmgr->bufmgr_func->bufmgr_bind_native_display(bufmgr->bufmgr_data, (tbm_native_display *)native_display);
- if (error != TBM_ERROR_NONE) {
- TBM_ERR("error: tbm_bufmgr(%p) native_display(%p) error(%d)\n",
- bufmgr, native_display, error);
- _tbm_set_last_result(error);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
- ret = 1;
- } else {
- if (!bufmgr->backend->bufmgr_bind_native_display) {
- TBM_WRN("skip: tbm_bufmgr(%p) native_display(%p)\n",
- bufmgr, native_display);
- _tbm_set_last_result(TBM_ERROR_NOT_SUPPORTED);
- _tbm_bufmgr_mutex_unlock();
+ if (error == TBM_ERROR_NOT_SUPPORTED) {
+ TBM_WRN("Not supported, so skip: tbm_bufmgr(%p) native_display(%p)", bufmgr, native_display);
return 1;
}
- ret = bufmgr->backend->bufmgr_bind_native_display(bufmgr, native_display);
- if (!ret) {
- TBM_ERR("error: tbm_bufmgr(%p) native_display(%p)\n",
- bufmgr, native_display);
- _tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
- _tbm_bufmgr_mutex_unlock();
- return 0;
- }
+ return 0;
}
TBM_INFO("tbm_bufmgr(%p) native_display(%p)\n", bufmgr, native_display);
{
return gBufMgr;
}
+
+
+tbm_bo
+tbm_bufmgr_internal_find_bo(tbm_bufmgr bufmgr, tbm_bo bo)
+{
+ tbm_bo bo2 = NULL;
+
+ TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), NULL);
+ TBM_RETURN_VAL_IF_FAIL(bufmgr == gBufMgr, NULL);
+
+ if (LIST_IS_EMPTY(&bufmgr->bo_list))
+ return NULL;
+
+ LIST_FOR_EACH_ENTRY(bo2, &bufmgr->bo_list, item_link) {
+ if (bo2->bo_data == bo->bo_data) {
+ return bo2;
+ }
+ }
+
+ return NULL;
+}
+
+/* LCOV_EXCL_START */
+
+tbm_bo
+tbm_bufmgr_internal_alloc_bo_with_format(tbm_bufmgr bufmgr, int format, int bo_idx, int width,
+ int height, int bpp, tbm_bo_memory_type flags, tbm_error_e *error)
+{
+ tbm_bo bo = NULL;
+
+ _tbm_bufmgr_mutex_lock();
+ _tbm_set_last_result(TBM_ERROR_NONE);
+
+ TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
+
+ _tbm_bufmgr_check_bo_cnt(bufmgr);
+
+ bo = calloc(1, sizeof(struct _tbm_bo));
+ if (!bo) {
+ /* LCOV_EXCL_START */
+ TBM_ERR("memory allocationc failed.");
+ _tbm_set_last_result(TBM_ERROR_OUT_OF_MEMORY);
+ /* LCOV_EXCL_STOP */
+ goto fail;
+ }
+
+ bo->bo_data = tbm_module_bufmgr_bo_alloc_with_format(bufmgr->module, format, bo_idx, width, height, bpp, flags, error);
+ if (!bo->bo_data) {
+ /* LCOV_EXCL_START */
+ _tbm_set_last_result(*error);
+ /* LCOV_EXCL_STOP */
+ goto fail;
+ }
+
+ _tbm_bufmgr_initialize_bo(bufmgr, bo, flags);
+
+ _tbm_bufmgr_mutex_unlock();
+
+ return bo;
+
+fail:
+ if (bo)
+ free(bo);
+ _tbm_bufmgr_mutex_unlock();
+
+ return NULL;
+}
+
/* LCOV_EXCL_STOP */