uint32_t capabilities;
};
+static int tbm_drm_fd = -1;
+
/* LCOV_EXCL_START */
static void
handle_tbm_drm_authentication_info(void *data, struct wl_tbm_drm_auth *wl_tbm_drm_auth, const char *device_name, uint32_t capabilities, int32_t auth_fd)
return 1;
}
-/* LCOV_EXCL_STOP */
+
+void
+tbm_drm_helper_set_fd(int fd)
+{
+ int fd_max = tbm_bufmgr_get_fd_limit();
+
+ if (tbm_drm_fd == fd)
+ return;
+
+ if (fd < 0 || fd > fd_max) {
+ TBM_LOG_E("%d out of fd range\n", fd);
+ return;
+ }
+
+ if (tbm_drm_fd != -1)
+ TBM_LOG_W("already has TBM_DRM_FD: %d\n", tbm_drm_fd);
+
+ tbm_drm_fd = fd;
+
+ TBM_LOG_I("TBM_DRM_FD: %d\n", tbm_drm_fd);
+}
+
+void
+tbm_drm_helper_unset_fd(void)
+{
+ tbm_drm_fd = -1;
+ TBM_LOG_I("TBM_DRM_FD: %d\n", tbm_drm_fd);
+}
+
+int
+tbm_drm_helper_get_fd(void)
+{
+ int new_fd, flags;
+
+ if (tbm_drm_fd == -1) {
+ TBM_LOG_E("no drm fd");
+ return -1;
+ }
+
+ TBM_LOG_I("TBM_DRM_FD: %d\n", tbm_drm_fd);
+
+ flags = fcntl(tbm_drm_fd, F_GETFD);
+ if (flags == -1) {
+ TBM_LOG_E("fcntl failed: %m");
+ return -1;
+ }
+
+ new_fd = dup(tbm_drm_fd);
+ if (new_fd < 0) {
+ TBM_LOG_E("dup failed: %m");
+ return -1;
+ }
+
+ if (fcntl(new_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
+ TBM_LOG_E("failed to set fd\n");
+ close(new_fd);
+ return -1;
+ }
+
+ TBM_LOG_I("Return TBM_FD: %d\n", new_fd);
+
+ return new_fd;
+}
+
+/* LCOV_EXCL_STOP */