render: introduce wlr_renderer_get_drm_fd

This commit is contained in:
Simon Ser 2020-06-10 14:47:12 +02:00
parent c8d95acc37
commit eb8360bda3
5 changed files with 34 additions and 0 deletions

View File

@ -35,6 +35,7 @@ struct wlr_gles2_renderer {
struct wlr_renderer wlr_renderer; struct wlr_renderer wlr_renderer;
struct wlr_egl *egl; struct wlr_egl *egl;
int drm_fd;
const char *exts_str; const char *exts_str;
struct { struct {

View File

@ -72,6 +72,7 @@ struct wlr_renderer_impl {
bool (*blit_dmabuf)(struct wlr_renderer *renderer, bool (*blit_dmabuf)(struct wlr_renderer *renderer,
struct wlr_dmabuf_attributes *dst, struct wlr_dmabuf_attributes *dst,
struct wlr_dmabuf_attributes *src); struct wlr_dmabuf_attributes *src);
int (*get_drm_fd)(struct wlr_renderer *renderer);
}; };
void wlr_renderer_init(struct wlr_renderer *renderer, void wlr_renderer_init(struct wlr_renderer *renderer,

View File

@ -131,6 +131,13 @@ bool wlr_renderer_format_supported(struct wlr_renderer *r,
bool wlr_renderer_init_wl_display(struct wlr_renderer *r, bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
struct wl_display *wl_display); struct wl_display *wl_display);
/**
* Obtains the FD of the DRM device used for rendering, or -1 if unavailable.
*
* The caller doesn't have ownership of the FD, it must not close it.
*/
int wlr_renderer_get_drm_fd(struct wlr_renderer *r);
/** /**
* Destroys this wlr_renderer. Textures must be destroyed separately. * Destroys this wlr_renderer. Textures must be destroyed separately.
*/ */

View File

@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <wayland-server-protocol.h> #include <wayland-server-protocol.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <wlr/render/egl.h> #include <wlr/render/egl.h>
@ -644,6 +645,17 @@ static bool gles2_init_wl_display(struct wlr_renderer *wlr_renderer,
return true; return true;
} }
static int gles2_get_drm_fd(struct wlr_renderer *wlr_renderer) {
struct wlr_gles2_renderer *renderer =
gles2_get_renderer(wlr_renderer);
if (renderer->drm_fd < 0) {
renderer->drm_fd = wlr_egl_dup_drm_fd(renderer->egl);
}
return renderer->drm_fd;
}
struct wlr_egl *wlr_gles2_renderer_get_egl(struct wlr_renderer *wlr_renderer) { struct wlr_egl *wlr_gles2_renderer_get_egl(struct wlr_renderer *wlr_renderer) {
struct wlr_gles2_renderer *renderer = struct wlr_gles2_renderer *renderer =
gles2_get_renderer(wlr_renderer); gles2_get_renderer(wlr_renderer);
@ -675,6 +687,10 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
wlr_egl_unset_current(renderer->egl); wlr_egl_unset_current(renderer->egl);
if (renderer->drm_fd >= 0) {
close(renderer->drm_fd);
}
free(renderer); free(renderer);
} }
@ -700,6 +716,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.texture_from_dmabuf = gles2_texture_from_dmabuf, .texture_from_dmabuf = gles2_texture_from_dmabuf,
.init_wl_display = gles2_init_wl_display, .init_wl_display = gles2_init_wl_display,
.blit_dmabuf = gles2_blit_dmabuf, .blit_dmabuf = gles2_blit_dmabuf,
.get_drm_fd = gles2_get_drm_fd,
}; };
void push_gles2_debug_(struct wlr_gles2_renderer *renderer, void push_gles2_debug_(struct wlr_gles2_renderer *renderer,
@ -856,6 +873,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
renderer->egl = egl; renderer->egl = egl;
renderer->exts_str = exts_str; renderer->exts_str = exts_str;
renderer->drm_fd = -1;
wlr_log(WLR_INFO, "Using %s", glGetString(GL_VERSION)); wlr_log(WLR_INFO, "Using %s", glGetString(GL_VERSION));
wlr_log(WLR_INFO, "GL vendor: %s", glGetString(GL_VENDOR)); wlr_log(WLR_INFO, "GL vendor: %s", glGetString(GL_VENDOR));

View File

@ -269,3 +269,10 @@ struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl,
return renderer; return renderer;
} }
int wlr_renderer_get_drm_fd(struct wlr_renderer *r) {
if (!r->impl->get_drm_fd) {
return -1;
}
return r->impl->get_drm_fd(r);
}