#include "tbm_bufmgr.h"
#include "tbm_bufmgr_int.h"
#include "tbm_bufmgr_backend.h"
+#include "tbm_drm_helper.h"
#include "list.h"
#include <sys/resource.h>
}
static int
+_tbm_backend_load_hal_tbm(tbm_bufmgr bufmgr)
+{
+ hal_tbm_backend *hal_backend = NULL;
+ hal_tbm_bufmgr_capability capability;
+ hal_tbm_bufmgr *hal_bufmgr;
+ hal_tbm_error ret = HAL_TBM_ERROR_NONE;
+ hal_tbm_fd auth_drm_fd = -1;
+
+ hal_backend = hal_tbm_get_backend(&ret);
+ if (hal_backend == NULL || ret != HAL_TBM_ERROR_NONE) {
+ TBM_ERR("get backend fail");
+ return 0;
+ }
+
+ hal_bufmgr = hal_tbm_backend_get_bufmgr(hal_backend, &ret);
+ if (hal_bufmgr == NULL || ret != HAL_TBM_ERROR_NONE) {
+ TBM_ERR("get hal_bufmgr fail");
+ goto get_backend_fail;
+ }
+
+ if (hal_tbm_backend_has_drm_device(hal_backend, &ret)) {
+ auth_drm_fd = hal_tbm_backend_get_master_drm_fd(hal_backend, &ret);
+ if (auth_drm_fd < 0) {
+ TBM_INFO("tbm_backend has no master drm_fd.");
+
+ auth_drm_fd = tbm_drm_helper_get_master_fd();
+ if (auth_drm_fd < 0) {
+ TBM_INFO("libtbm requests an authenticated drm_fd to a process(display server).");
+ if (!tbm_drm_helper_get_auth_info(&auth_drm_fd, NULL, NULL)) {
+ TBM_ERR("get auth drm_fd fail");
+ goto get_backend_fail;
+ }
+ } else {
+ TBM_INFO("libtbm gets a master drm_fd from libtdm via tbm_drm_helper.");
+ }
+
+ TBM_INFO("libtbm sends a master drm_fd as an authentiated drm_fd to tbm_backend.");
+ ret = hal_tbm_backend_set_authenticated_drm_fd(hal_backend, auth_drm_fd);
+ if (ret != HAL_TBM_ERROR_NONE) {
+ TBM_ERR("hal_tbm_backend_set_authenticated_drm_fd failed.");
+ goto get_backend_fail;
+ }
+ } else {
+ TBM_INFO("tbm_backend has a master drm_fd.");
+
+ tbm_drm_helper_set_tbm_master_fd(auth_drm_fd);
+ }
+ tbm_drm_helper_set_fd(auth_drm_fd);
+ }
+
+ capability = hal_tbm_bufmgr_get_capabilities(hal_bufmgr, &ret);
+ if (ret != HAL_TBM_ERROR_NONE) {
+ TBM_ERR("hal_tbm_bufmgr_get_capabilities fail.");
+ goto get_backend_fail;
+ }
+
+ if (capability == HAL_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.");
+ goto get_backend_fail;
+ }
+ if (!(capability & HAL_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. ");
+ goto get_backend_fail;
+ }
+ bufmgr->capabilities = capability;
+
+ bufmgr->hal_backend = hal_backend;
+ bufmgr->hal_bufmgr = hal_bufmgr;
+
+ bufmgr->use_hal_tbm = 1;
+
+ TBM_INFO("use HAL-TBM_API");
+
+ return 1;
+
+get_backend_fail:
+ if (auth_drm_fd >= 0)
+ close(auth_drm_fd);
+ hal_tbm_put_backend(hal_backend);
+ return 0;
+}
+
+static int
_check_version(TBMModuleVersionInfo *data)
{
int backend_module_major, backend_module_minor;
bufmgr->backend_module_data = backend_module_data;
bufmgr->bufmgr_data = bufmgr_data;
- TBM_DBG("Success to load module(%s)\n", file);
- TBM_STDOUT_INFO("Success to load module(%s)", file);
+ TBM_INFO("Success to load module(%s)\n", file);
return 1;
struct dirent **namelist;
int ret = 0, n;
+ /* try to load the hal-tbm backend module */
+ ret = _tbm_backend_load_hal_tbm(bufmgr);
+ if (ret)
+ return 1;
+
/* try to load the new backend module */
ret = _tbm_backend_load_module(bufmgr, DEFAULT_LIB);
if (ret)
}
/* load bufmgr priv from env */
- TBM_STDOUT_INFO("loading backend module");
if (!_tbm_load_module(gBufMgr, gBufMgr->fd)) {
TBM_ERR("error : Fail to load bufmgr backend\n");
_tbm_set_last_result(TBM_ERROR_INVALID_OPERATION);
return NULL;
}
- TBM_STDOUT_INFO("loading backend module done");
/* LCOV_EXCL_STOP */
gBufMgr->ref_count = 1;
LIST_DELINIT(&bufmgr->surf_list);
}
- if (bufmgr->backend_module_data) {
- /* deinit and backend destroys the backend func and data */
- bufmgr->backend_module_data->deinit(bufmgr->bufmgr_data);
- bufmgr->bo_func = NULL;
- bufmgr->bufmgr_func = NULL;
- bufmgr->bufmgr_data = NULL;
- bufmgr->backend_module_data = NULL;
- } else {
- /* destroy bufmgr priv */
- bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
- bufmgr->backend->priv = NULL;
- tbm_backend_free(bufmgr->backend);
- bufmgr->backend = NULL;
- }
-
- TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr);
+ if (bufmgr->use_hal_tbm) {
+ if (bufmgr->auth_wl_socket_created) {
+ tbm_drm_helper_wl_auth_server_deinit();
+ close(bufmgr->auth_fd);
+ tbm_drm_helper_unset_tbm_master_fd();
+ }
+ tbm_drm_helper_unset_fd();
- dlclose(bufmgr->module_data);
+ hal_tbm_put_backend(bufmgr->hal_backend);
+ bufmgr->hal_backend = NULL;
+ bufmgr->hal_bufmgr = NULL;
+ bufmgr->use_hal_tbm = 0;
+ } else {
+ if (bufmgr->backend_module_data) {
+ /* deinit and backend destroys the backend func and data */
+ bufmgr->backend_module_data->deinit(bufmgr->bufmgr_data);
+ bufmgr->bo_func = NULL;
+ bufmgr->bufmgr_func = NULL;
+ bufmgr->bufmgr_data = NULL;
+ bufmgr->backend_module_data = NULL;
+ } else {
+ /* destroy bufmgr priv */
+ bufmgr->backend->bufmgr_deinit(bufmgr->backend->priv);
+ bufmgr->backend->priv = NULL;
+ tbm_backend_free(bufmgr->backend);
+ bufmgr->backend = NULL;
+ }
+ dlclose(bufmgr->module_data);
+ }
if (bufmgr->fd > 0)
close(bufmgr->fd);
+ TBM_INFO("destroy tbm_bufmgr(%p)\n", bufmgr);
+
free(bufmgr);
gBufMgr = NULL;
TBM_SNRPRINTF(str, len, c, "%s\n", data);
for (i = 0; i < surf->num_bos; i++) {
- if (bufmgr->backend_module_data) {
+ if (bufmgr->use_hal_tbm) {
+ size = hal_tbm_bo_get_size((hal_tbm_bo *)surf->bos[i]->bo_data, (hal_tbm_error *)&error);
+ if (error != TBM_ERROR_NONE)
+ TBM_WRN("fail to get the size of bo.");
+ } else if (bufmgr->backend_module_data) {
size = bufmgr->bo_func->bo_get_size(surf->bos[i]->bo_data, &error);
if (error != TBM_ERROR_NONE)
TBM_WRN("fail to get the size of bo.");
tbm_key key = 0;
LIST_FOR_EACH_ENTRY(bo, &bufmgr->bo_list, item_link) {
- if (bufmgr->backend_module_data) {
+ if (bo->bufmgr->use_hal_tbm) {
+ size = hal_tbm_bo_get_size((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
+ if (error != TBM_ERROR_NONE)
+ TBM_WRN("fail to get the size of bo.");
+ key = (tbm_key)hal_tbm_bo_export_key((hal_tbm_bo *)bo->bo_data, (hal_tbm_error *)&error);
+ } else if (bufmgr->backend_module_data) {
size = bufmgr->bo_func->bo_get_size(bo->bo_data, &error);
if (error != TBM_ERROR_NONE)
TBM_WRN("fail to get the size of bo.");
TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
- if (bufmgr->backend_module_data) {
+ 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;
+ }
+ } 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);