render/gles2: use wlr_drm for wl_drm implementation

This allows use to remove all of our special wl_drm support code.
This commit is contained in:
Simon Ser 2021-02-02 23:37:31 +01:00 committed by Simon Zeni
parent d7b19fb294
commit 4e07d4cbf9
2 changed files with 4 additions and 113 deletions

View file

@ -12,6 +12,7 @@
#include <wlr/render/egl.h> #include <wlr/render/egl.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_drm.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h> #include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
@ -368,34 +369,6 @@ static const uint32_t *gles2_get_shm_texture_formats(
return get_gles2_shm_formats(len); return get_gles2_shm_formats(len);
} }
static bool gles2_resource_is_wl_drm_buffer(struct wlr_renderer *wlr_renderer,
struct wl_resource *resource) {
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
if (!renderer->egl->exts.bind_wayland_display_wl) {
return false;
}
EGLint fmt;
return renderer->egl->procs.eglQueryWaylandBufferWL(renderer->egl->display,
resource, EGL_TEXTURE_FORMAT, &fmt);
}
static void gles2_wl_drm_buffer_get_size(struct wlr_renderer *wlr_renderer,
struct wl_resource *buffer, int *width, int *height) {
struct wlr_gles2_renderer *renderer =
gles2_get_renderer(wlr_renderer);
if (!renderer->egl->exts.bind_wayland_display_wl) {
return;
}
renderer->egl->procs.eglQueryWaylandBufferWL(renderer->egl->display,
buffer, EGL_WIDTH, width);
renderer->egl->procs.eglQueryWaylandBufferWL(renderer->egl->display,
buffer, EGL_HEIGHT, height);
}
static const struct wlr_drm_format_set *gles2_get_dmabuf_texture_formats( static const struct wlr_drm_format_set *gles2_get_dmabuf_texture_formats(
struct wlr_renderer *wlr_renderer) { struct wlr_renderer *wlr_renderer) {
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
@ -498,16 +471,12 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
static bool gles2_init_wl_display(struct wlr_renderer *wlr_renderer, static bool gles2_init_wl_display(struct wlr_renderer *wlr_renderer,
struct wl_display *wl_display) { struct wl_display *wl_display) {
struct wlr_gles2_renderer *renderer = if (wlr_renderer_get_drm_fd(wlr_renderer) >= 0) {
gles2_get_renderer(wlr_renderer); if (wlr_drm_create(wl_display, wlr_renderer) == NULL) {
if (renderer->egl->exts.bind_wayland_display_wl) {
if (!wlr_egl_bind_display(renderer->egl, wl_display)) {
wlr_log(WLR_ERROR, "Failed to bind wl_display to EGL");
return false; return false;
} }
} else { } else {
wlr_log(WLR_INFO, "EGL_WL_bind_wayland_display is not supported"); wlr_log(WLR_INFO, "Cannot get renderer DRM FD, disabling wl_drm");
} }
if (wlr_linux_dmabuf_v1_create(wl_display, wlr_renderer) == NULL) { if (wlr_linux_dmabuf_v1_create(wl_display, wlr_renderer) == NULL) {
@ -585,13 +554,10 @@ static const struct wlr_renderer_impl renderer_impl = {
.render_subtexture_with_matrix = gles2_render_subtexture_with_matrix, .render_subtexture_with_matrix = gles2_render_subtexture_with_matrix,
.render_quad_with_matrix = gles2_render_quad_with_matrix, .render_quad_with_matrix = gles2_render_quad_with_matrix,
.get_shm_texture_formats = gles2_get_shm_texture_formats, .get_shm_texture_formats = gles2_get_shm_texture_formats,
.resource_is_wl_drm_buffer = gles2_resource_is_wl_drm_buffer,
.wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size,
.get_dmabuf_texture_formats = gles2_get_dmabuf_texture_formats, .get_dmabuf_texture_formats = gles2_get_dmabuf_texture_formats,
.get_render_formats = gles2_get_render_formats, .get_render_formats = gles2_get_render_formats,
.preferred_read_format = gles2_preferred_read_format, .preferred_read_format = gles2_preferred_read_format,
.read_pixels = gles2_read_pixels, .read_pixels = gles2_read_pixels,
.texture_from_wl_drm = gles2_texture_from_wl_drm,
.init_wl_display = gles2_init_wl_display, .init_wl_display = gles2_init_wl_display,
.get_drm_fd = gles2_get_drm_fd, .get_drm_fd = gles2_get_drm_fd,
.get_render_buffer_caps = gles2_get_render_buffer_caps, .get_render_buffer_caps = gles2_get_render_buffer_caps,

View file

@ -234,81 +234,6 @@ static struct wlr_texture *gles2_texture_from_pixels(
return &texture->wlr_texture; return &texture->wlr_texture;
} }
struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer,
struct wl_resource *resource) {
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
if (!renderer->procs.glEGLImageTargetTexture2DOES) {
return NULL;
}
struct wlr_egl_context prev_ctx;
wlr_egl_save_context(&prev_ctx);
wlr_egl_make_current(renderer->egl);
EGLint fmt;
int width, height;
bool inverted_y;
EGLImageKHR image = wlr_egl_create_image_from_wl_drm(renderer->egl, resource,
&fmt, &width, &height, &inverted_y);
if (image == EGL_NO_IMAGE_KHR) {
wlr_log(WLR_ERROR, "Failed to create EGL image from wl_drm resource");
goto error_ctx;
}
struct wlr_gles2_texture *texture =
gles2_texture_create(renderer, width, height);
if (texture == NULL) {
goto error_image;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
texture->renderer = renderer;
texture->drm_format = DRM_FORMAT_INVALID; // texture can't be written anyways
texture->image = image;
texture->inverted_y = inverted_y;
switch (fmt) {
case EGL_TEXTURE_RGB:
texture->has_alpha = false;
break;
case EGL_TEXTURE_RGBA:
case EGL_TEXTURE_EXTERNAL_WL:
texture->has_alpha = true;
break;
default:
wlr_log(WLR_ERROR, "Invalid or unsupported EGL buffer format");
goto error_texture;
}
texture->target = GL_TEXTURE_EXTERNAL_OES;
push_gles2_debug(renderer);
glGenTextures(1, &texture->tex);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->tex);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
renderer->procs.glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
texture->image);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
pop_gles2_debug(renderer);
wlr_egl_restore_context(&prev_ctx);
return &texture->wlr_texture;
error_texture:
wl_list_remove(&texture->link);
free(texture);
error_image:
wlr_egl_destroy_image(renderer->egl, image);
error_ctx:
wlr_egl_restore_context(&prev_ctx);
return NULL;
}
static struct wlr_texture *gles2_texture_from_dmabuf( static struct wlr_texture *gles2_texture_from_dmabuf(
struct wlr_renderer *wlr_renderer, struct wlr_renderer *wlr_renderer,
struct wlr_dmabuf_attributes *attribs) { struct wlr_dmabuf_attributes *attribs) {