aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-05-30 14:18:07 +0100
committeremersion <contact@emersion.fr>2018-05-30 17:08:15 +0100
commit135721118a719ecacfd2bd83524a9c53c6ca6015 (patch)
tree5079957bc4cae37edfbd78a9d6b708a6000e1438
parent41e53d14997de21fbad80d420acb358bec4341e8 (diff)
render: remove wlr_renderer_check_import_dmabuf
It's possible to implement it outside the renderer, by creating a texture and destroying it right away. This reduces the API surface of the renderer.
-rw-r--r--include/wlr/render/egl.h7
-rw-r--r--include/wlr/render/interface.h2
-rw-r--r--include/wlr/render/wlr_renderer.h6
-rw-r--r--render/egl.c29
-rw-r--r--render/gles2/renderer.c7
-rw-r--r--render/gles2/texture.c16
-rw-r--r--render/wlr_renderer.c12
-rw-r--r--types/wlr_linux_dmabuf.c16
8 files changed, 32 insertions, 63 deletions
diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h
index 7cd5c5ca..6d79cbd2 100644
--- a/include/wlr/render/egl.h
+++ b/include/wlr/render/egl.h
@@ -68,13 +68,6 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_attributes *attributes);
/**
- * Try to import the given dmabuf. On success return true false otherwise.
- * If this succeeds the dmabuf can be used for rendering on a texture
- */
-bool wlr_egl_check_import_dmabuf(struct wlr_egl *egl,
- struct wlr_dmabuf_attributes *attributes);
-
-/**
* Get the available dmabuf formats
*/
int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl, int **formats);
diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h
index 87b3c929..80788858 100644
--- a/include/wlr/render/interface.h
+++ b/include/wlr/render/interface.h
@@ -30,8 +30,6 @@ struct wlr_renderer_impl {
struct wl_resource *resource);
void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer,
struct wl_resource *buffer, int *width, int *height);
- bool (*check_import_dmabuf)(struct wlr_renderer *renderer,
- struct wlr_dmabuf_attributes *attribs);
int (*get_dmabuf_formats)(struct wlr_renderer *renderer, int **formats);
int (*get_dmabuf_modifiers)(struct wlr_renderer *renderer, int format,
uint64_t **modifiers);
diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h
index dd62944f..c715e4b0 100644
--- a/include/wlr/render/wlr_renderer.h
+++ b/include/wlr/render/wlr_renderer.h
@@ -85,12 +85,6 @@ int wlr_renderer_get_dmabuf_formats(struct wlr_renderer *renderer,
int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *renderer, int format,
uint64_t **modifiers);
/**
- * Try to import the given dmabuf. On success return true false otherwise.
- * If this succeeds the dmabuf can be used for rendering on a texture
- */
-bool wlr_renderer_check_import_dmabuf(struct wlr_renderer *renderer,
- struct wlr_dmabuf_attributes *attributes);
-/**
* Reads out of pixels of the currently bound surface into data. `stride` is in
* bytes.
*/
diff --git a/render/egl.c b/render/egl.c
index 6ac3ee2a..676a0208 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -413,35 +413,6 @@ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
EGL_LINUX_DMA_BUF_EXT, NULL, attribs);
}
-#ifndef DRM_FORMAT_BIG_ENDIAN
-#define DRM_FORMAT_BIG_ENDIAN 0x80000000
-#endif
-bool wlr_egl_check_import_dmabuf(struct wlr_egl *egl,
- struct wlr_dmabuf_attributes *attribs) {
- switch (attribs->format & ~DRM_FORMAT_BIG_ENDIAN) {
- /* TODO: YUV based formats not yet supported, require multiple
- * wlr_create_image_from_dmabuf */
- case WL_SHM_FORMAT_YUYV:
- case WL_SHM_FORMAT_YVYU:
- case WL_SHM_FORMAT_UYVY:
- case WL_SHM_FORMAT_VYUY:
- case WL_SHM_FORMAT_AYUV:
- return false;
- default:
- break;
- }
-
- EGLImage egl_image = wlr_egl_create_image_from_dmabuf(egl, attribs);
- if (egl_image) {
- /* We can import the image, good. No need to keep it
- since wlr_texture_upload_dmabuf will import it again */
- wlr_egl_destroy_image(egl, egl_image);
- return true;
- }
- /* TODO: import yuv dmabufs */
- return false;
-}
-
int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl,
int **formats) {
if (!egl->egl_exts.dmabuf_import ||
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index e68bb83f..ed12fc7c 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -242,12 +242,6 @@ static int gles2_get_dmabuf_modifiers(struct wlr_renderer *wlr_renderer,
return wlr_egl_get_dmabuf_modifiers(renderer->egl, format, modifiers);
}
-static bool gles2_check_import_dmabuf(struct wlr_renderer *wlr_renderer,
- struct wlr_dmabuf_attributes *attribs) {
- struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
- return wlr_egl_check_import_dmabuf(renderer->egl, attribs);
-}
-
static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
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,
@@ -348,7 +342,6 @@ static const struct wlr_renderer_impl renderer_impl = {
.wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size,
.get_dmabuf_formats = gles2_get_dmabuf_formats,
.get_dmabuf_modifiers = gles2_get_dmabuf_modifiers,
- .check_import_dmabuf = gles2_check_import_dmabuf,
.read_pixels = gles2_read_pixels,
.format_supported = gles2_format_supported,
.texture_from_pixels = gles2_texture_from_pixels,
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index 2627e292..89a175c4 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -198,6 +198,10 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
return &texture->wlr_texture;
}
+#ifndef DRM_FORMAT_BIG_ENDIAN
+#define DRM_FORMAT_BIG_ENDIAN 0x80000000
+#endif
+
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_attributes *attribs) {
assert(wlr_egl_is_current(egl));
@@ -212,6 +216,18 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
return NULL;
}
+ switch (attribs->format & ~DRM_FORMAT_BIG_ENDIAN) {
+ case WL_SHM_FORMAT_YUYV:
+ case WL_SHM_FORMAT_YVYU:
+ case WL_SHM_FORMAT_UYVY:
+ case WL_SHM_FORMAT_VYUY:
+ case WL_SHM_FORMAT_AYUV:
+ // TODO: YUV based formats not yet supported, require multiple images
+ return false;
+ default:
+ break;
+ }
+
struct wlr_gles2_texture *texture =
calloc(1, sizeof(struct wlr_gles2_texture));
if (texture == NULL) {
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index 32b0a779..98c91132 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -135,14 +135,6 @@ int wlr_renderer_get_dmabuf_modifiers(struct wlr_renderer *r, int format,
return r->impl->get_dmabuf_modifiers(r, format, modifiers);
}
-bool wlr_renderer_check_import_dmabuf(struct wlr_renderer *r,
- struct wlr_dmabuf_attributes *attribs) {
- if (!r->impl->check_import_dmabuf) {
- return false;
- }
- return r->impl->check_import_dmabuf(r, attribs);
-}
-
bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format 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,
@@ -187,8 +179,8 @@ void wlr_renderer_init_wl_display(struct wlr_renderer *r,
}
struct wlr_renderer *wlr_renderer_autocreate(struct wlr_egl *egl,
- EGLenum platform, void *remote_display, EGLint *config_attribs, EGLint visual_id) {
-
+ EGLenum platform, void *remote_display, EGLint *config_attribs,
+ EGLint visual_id) {
if (!wlr_egl_init(egl, platform, remote_display, config_attribs, visual_id)) {
wlr_log(L_ERROR, "Could not initialize EGL");
return NULL;
diff --git a/types/wlr_linux_dmabuf.c b/types/wlr_linux_dmabuf.c
index fd4bd334..542f8cbc 100644
--- a/types/wlr_linux_dmabuf.c
+++ b/types/wlr_linux_dmabuf.c
@@ -121,6 +121,19 @@ static void buffer_handle_resource_destroy(struct wl_resource *buffer_resource)
linux_dmabuf_buffer_destroy(buffer);
}
+static bool check_import_dmabuf(struct wlr_dmabuf_buffer *buffer) {
+ struct wlr_texture *texture =
+ wlr_texture_from_dmabuf(buffer->renderer, &buffer->attributes);
+ if (texture == NULL) {
+ return false;
+ }
+
+ // We can import the image, good. No need to keep it since wlr_surface will
+ // import it again on commit.
+ wlr_texture_destroy(texture);
+ return true;
+}
+
static void params_create_common(struct wl_client *client,
struct wl_resource *params_resource, uint32_t buffer_id, int32_t width,
int32_t height, uint32_t format, uint32_t flags) {
@@ -229,8 +242,7 @@ static void params_create_common(struct wl_client *client,
}
/* Check if dmabuf is usable */
- if (!wlr_renderer_check_import_dmabuf(buffer->renderer,
- &buffer->attributes)) {
+ if (!check_import_dmabuf(buffer)) {
goto err_failed;
}