diff options
Diffstat (limited to 'render')
-rw-r--r-- | render/egl.c | 51 | ||||
-rw-r--r-- | render/gles2/texture.c | 17 | ||||
-rw-r--r-- | render/meson.build | 8 | ||||
-rw-r--r-- | render/wlr_texture.c | 8 |
4 files changed, 63 insertions, 21 deletions
diff --git a/render/egl.c b/render/egl.c index 96e48c06..cfa37f20 100644 --- a/render/egl.c +++ b/render/egl.c @@ -3,6 +3,7 @@ #include <EGL/egl.h> #include <EGL/eglext.h> #include <stdlib.h> +#include <drm_fourcc.h> #include <wlr/render/egl.h> #include <wlr/util/log.h> #include "glapi.h" @@ -120,7 +121,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, if (platform == EGL_PLATFORM_SURFACELESS_MESA) { assert(remote_display == NULL); - egl->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + egl->display = eglGetPlatformDisplayEXT(platform, EGL_DEFAULT_DISPLAY, NULL); } else { egl->display = eglGetPlatformDisplayEXT(platform, remote_display, NULL); } @@ -382,13 +383,21 @@ EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl, EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, struct wlr_dmabuf_attributes *attributes) { - if (!egl->exts.image_base_khr) { + if (!egl->exts.image_base_khr || !egl->exts.image_dmabuf_import_ext) { + wlr_log(WLR_ERROR, "dmabuf import extension not present"); return NULL; } bool has_modifier = false; - if (attributes->modifier != DRM_FORMAT_MOD_INVALID) { + + // we assume the same way we assumed formats without the import_modifiers + // extension that mod_linear is supported. The special mod mod_invalid + // is sometimes used to signal modifier unawareness which is what we + // have here + if (attributes->modifier != DRM_FORMAT_MOD_INVALID && + attributes->modifier != DRM_FORMAT_MOD_LINEAR) { if (!egl->exts.image_dmabuf_import_modifiers_ext) { + wlr_log(WLR_ERROR, "dmabuf modifiers extension not present"); return NULL; } has_modifier = true; @@ -460,12 +469,34 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl, int **formats) { - if (!egl->exts.image_dmabuf_import_ext || - !egl->exts.image_dmabuf_import_modifiers_ext) { - wlr_log(WLR_DEBUG, "dmabuf extension not present"); + if (!egl->exts.image_dmabuf_import_ext) { + wlr_log(WLR_DEBUG, "dmabuf import extension not present"); return -1; } + // when we only have the image_dmabuf_import extension we can't query + // which formats are supported. These two are on almost always + // supported; it's the intended way to just try to create buffers. + // Just a guess but better than not supporting dmabufs at all, + // given that the modifiers extension isn't supported everywhere. + if (!egl->exts.image_dmabuf_import_modifiers_ext) { + static const int fallback_formats[] = { + DRM_FORMAT_ARGB8888, + DRM_FORMAT_XRGB8888, + }; + static unsigned num = sizeof(fallback_formats) / + sizeof(fallback_formats[0]); + + *formats = calloc(num, sizeof(int)); + if (!*formats) { + wlr_log_errno(WLR_ERROR, "Allocation failed"); + return -1; + } + + memcpy(*formats, fallback_formats, num * sizeof(**formats)); + return num; + } + EGLint num; if (!eglQueryDmaBufFormatsEXT(egl->display, 0, NULL, &num)) { wlr_log(WLR_ERROR, "failed to query number of dmabuf formats"); @@ -488,12 +519,16 @@ int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl, int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl, int format, uint64_t **modifiers) { - if (!egl->exts.image_dmabuf_import_ext || - !egl->exts.image_dmabuf_import_modifiers_ext) { + if (!egl->exts.image_dmabuf_import_ext) { wlr_log(WLR_DEBUG, "dmabuf extension not present"); return -1; } + if(!egl->exts.image_dmabuf_import_modifiers_ext) { + *modifiers = NULL; + return 0; + } + EGLint num; if (!eglQueryDmaBufModifiersEXT(egl->display, format, 0, NULL, NULL, &num)) { diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 22d02cde..d035841e 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -44,9 +44,9 @@ static bool gles2_texture_is_opaque(struct wlr_texture *wlr_texture) { } static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture, - enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, - uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, - uint32_t dst_y, const void *data) { + uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + const void *data) { struct wlr_gles2_texture *texture = get_gles2_texture_in_context(wlr_texture); @@ -55,11 +55,9 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture, return false; } - const struct wlr_gles2_pixel_format *fmt = get_gles2_format_from_wl(wl_fmt); - if (fmt == NULL) { - wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIu32, wl_fmt); - return false; - } + const struct wlr_gles2_pixel_format *fmt = + get_gles2_format_from_wl(texture->wl_format); + assert(fmt); // TODO: what if the unpack subimage extension isn't supported? PUSH_GLES2_DEBUG; @@ -167,6 +165,7 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl, texture->height = height; texture->type = WLR_GLES2_TEXTURE_GLTEX; texture->has_alpha = fmt->has_alpha; + texture->wl_format = fmt->wl_format; PUSH_GLES2_DEBUG; @@ -203,6 +202,7 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, texture->wl_drm = data; EGLint fmt; + texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways texture->image = wlr_egl_create_image_from_wl_drm(egl, data, &fmt, &texture->width, &texture->height, &texture->inverted_y); if (texture->image == NULL) { @@ -283,6 +283,7 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, texture->height = attribs->height; texture->type = WLR_GLES2_TEXTURE_DMABUF; texture->has_alpha = true; + texture->wl_format = 0xFFFFFFFF; // texture can't be written anyways texture->inverted_y = (attribs->flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT) != 0; diff --git a/render/meson.build b/render/meson.build index ab66eab0..e45ea90b 100644 --- a/render/meson.build +++ b/render/meson.build @@ -22,7 +22,13 @@ lib_wlr_render = static_library( ), glapi, include_directories: wlr_inc, - dependencies: [egl, glesv2, pixman, wayland_server], + dependencies: [ + egl, + drm.partial_dependency(compile_args: true), # <drm_fourcc.h> + glesv2, + pixman, + wayland_server + ], ) wlr_render = declare_dependency( diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 06872f1e..833032c9 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -55,10 +55,10 @@ bool wlr_texture_is_opaque(struct wlr_texture *texture) { } bool wlr_texture_write_pixels(struct wlr_texture *texture, - enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, - uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, - uint32_t dst_y, const void *data) { - return texture->impl->write_pixels(texture, wl_fmt, stride, width, height, + uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + const void *data) { + return texture->impl->write_pixels(texture, stride, width, height, src_x, src_y, dst_x, dst_y, data); } |