#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>
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) {
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.");
bufmgr->use_hal_tbm = 1;
- TBM_INFO("use hal tbm");
+ 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;
}
}
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();
+
hal_tbm_put_backend(bufmgr->hal_backend);
bufmgr->hal_backend = NULL;
bufmgr->hal_bufmgr = NULL;
TBM_BUFMGR_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(gBufMgr), 0);
if (bufmgr->use_hal_tbm) {
- error = (tbm_error_e)hal_tbm_bufmgr_bind_native_display(bufmgr->hal_bufmgr, (hal_tbm_native_display *)native_display);
- if (error == TBM_ERROR_NOT_SUPPORTED) {
- 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;
- } else if (error != TBM_ERROR_NONE) {
- 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;
+ 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) {
}
int
-tbm_drm_helper_wl_auth_server_init(void *wl_display, int fd, const char *device_name, uint32_t flags)
+tbm_drm_helper_wl_auth_server_init(void *wl_display, int fd, const char *device_name, uint32_t flags)
{
if (!tbm_drm_auth_srv) {
TBM_RETURN_VAL_IF_FAIL(wl_display != NULL, 0);
TBM_RETURN_VAL_IF_FAIL(tbm_drm_auth_srv != NULL, 0);
tbm_drm_auth_srv->display = (struct wl_display *)wl_display;
- tbm_drm_auth_srv->device_name = strdup(device_name);
+ if (!device_name) {
+ tbm_drm_auth_srv->device_name = drmGetDeviceNameFromFd(fd);
+ if (!tbm_drm_auth_srv->device_name) {
+ TBM_ERR("fail to get device name!\n");
+ return 0;
+ }
+ } else {
+ tbm_drm_auth_srv->device_name = strdup(device_name);
+ }
tbm_drm_auth_srv->fd = fd;
tbm_drm_auth_srv->flags = flags;