From b358bb41f0a281fb2403e75621c208e180b12bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 15 Jun 2018 17:54:21 +0200 Subject: [PATCH] virgl_renderer_callbacks: add get_drm_fd() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow the caller to provide a pre-opened DRM file descriptor, to be used by the EGL context. Bump callback interface version for compatibility. Signed-off-by: Marc-André Lureau Signed-off-by: Dave Airlie --- src/virgl_egl.h | 2 +- src/virgl_egl_context.c | 8 ++++++-- src/virglrenderer.c | 8 ++++++-- src/virglrenderer.h | 4 ++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/virgl_egl.h b/src/virgl_egl.h index 1a651a0..3bda418 100644 --- a/src/virgl_egl.h +++ b/src/virgl_egl.h @@ -27,7 +27,7 @@ #include "vrend_renderer.h" struct virgl_egl; -struct virgl_egl *virgl_egl_init(void); +struct virgl_egl *virgl_egl_init(int fd); void virgl_egl_destroy(struct virgl_egl *ve); virgl_renderer_gl_context virgl_egl_create_context(struct virgl_egl *ve, struct virgl_gl_ctx_param *vparams); diff --git a/src/virgl_egl_context.c b/src/virgl_egl_context.c index 6195394..04f300c 100644 --- a/src/virgl_egl_context.c +++ b/src/virgl_egl_context.c @@ -123,7 +123,7 @@ static bool virgl_egl_has_extension_in_string(const char *haystack, const char * return false; } -struct virgl_egl *virgl_egl_init(void) +struct virgl_egl *virgl_egl_init(int fd) { static const EGLint conf_att[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, @@ -148,7 +148,11 @@ struct virgl_egl *virgl_egl_init(void) if (!d) return NULL; - d->fd = egl_rendernode_open(); + if (fd >= 0) { + d->fd = fd; + } else { + d->fd = egl_rendernode_open(); + } if (d->fd == -1) goto fail; d->gbm_dev = gbm_create_device(d->fd); diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 252355d..86824f8 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -303,7 +303,7 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks if (!cookie || !cbs) return -1; - if (cbs->version != 1) + if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION) return -1; dev_cookie = cookie; @@ -311,7 +311,11 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks if (flags & VIRGL_RENDERER_USE_EGL) { #ifdef HAVE_EPOXY_EGL_H - egl_info = virgl_egl_init(); + int fd = -1; + if (cbs->version >= 2 && cbs->get_drm_fd) { + fd = cbs->get_drm_fd(cookie); + } + egl_info = virgl_egl_init(fd); if (!egl_info) return -1; use_context = CONTEXT_EGL; diff --git a/src/virglrenderer.h b/src/virglrenderer.h index 4b79d39..5baecdd 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -44,6 +44,8 @@ struct virgl_renderer_gl_ctx_param { int minor_ver; }; +#define VIRGL_RENDERER_CALLBACKS_VERSION 2 + struct virgl_renderer_callbacks { int version; void (*write_fence)(void *cookie, uint32_t fence); @@ -52,6 +54,8 @@ struct virgl_renderer_callbacks { virgl_renderer_gl_context (*create_gl_context)(void *cookie, int scanout_idx, struct virgl_renderer_gl_ctx_param *param); void (*destroy_gl_context)(void *cookie, virgl_renderer_gl_context ctx); int (*make_current)(void *cookie, int scanout_idx, virgl_renderer_gl_context ctx); + + int (*get_drm_fd)(void *cookie); /* v2, used with flags & VIRGL_RENDERER_USE_EGL */ }; /* virtio-gpu compatible interface */