From c63d94483b1e52817ca01ca82a867a78ebd39fa6 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 24 Mar 2018 18:30:28 -0400 Subject: Redesign wlr_texture - Textures are now immutable (apart from those created from raw pixels), no more invalid textures - Move all wl_drm stuff in wlr_renderer - Most of wlr_texture fields are now private - Remove some duplicated DMA-BUF code in the DRM backend - Add more assertions - Stride is now always given as bytes rather than pixels - Drop wl_shm functions Fun fact: this patch has been written 10,000 meters up in the air. --- backend/drm/renderer.c | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) (limited to 'backend/drm/renderer.c') diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index b2998b5f..2b50bb79 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -178,47 +178,33 @@ static void free_eglimage(struct gbm_bo *bo, void *data) { static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, struct gbm_bo *bo) { struct tex *tex = gbm_bo_get_user_data(bo); - if (tex) { + if (tex != NULL) { return tex->tex; } - // TODO: use wlr_texture_upload_dmabuf instead - - tex = malloc(sizeof(*tex)); - if (!tex) { - wlr_log_errno(L_ERROR, "Allocation failed"); + tex = calloc(1, sizeof(struct tex)); + if (tex == NULL) { return NULL; } - tex->egl = &renderer->egl; - - int dmabuf_fd = gbm_bo_get_fd(bo); - uint32_t width = gbm_bo_get_width(bo); - uint32_t height = gbm_bo_get_height(bo); - - EGLint attribs[] = { - EGL_WIDTH, width, - EGL_HEIGHT, height, - EGL_LINUX_DRM_FOURCC_EXT, gbm_bo_get_format(bo), - EGL_DMA_BUF_PLANE0_FD_EXT, dmabuf_fd, - EGL_DMA_BUF_PLANE0_OFFSET_EXT, gbm_bo_get_offset(bo, 0), - EGL_DMA_BUF_PLANE0_PITCH_EXT, gbm_bo_get_stride_for_plane(bo, 0), - EGL_IMAGE_PRESERVED_KHR, EGL_FALSE, - EGL_NONE, + struct wlr_dmabuf_buffer_attribs attribs = { + .n_planes = 1, + .width = gbm_bo_get_width(bo), + .height = gbm_bo_get_height(bo), + .format = gbm_bo_get_format(bo), }; - - tex->img = eglCreateImageKHR(renderer->egl.display, EGL_NO_CONTEXT, - EGL_LINUX_DMA_BUF_EXT, NULL, attribs); - if (!tex->img) { - wlr_log(L_ERROR, "Failed to create EGL image"); - abort(); + attribs.offset[0] = 0; + attribs.stride[0] = gbm_bo_get_stride_for_plane(bo, 0); + attribs.modifier[0] = 0; + attribs.fd[0] = gbm_bo_get_fd(bo); + + tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs); + if (tex->tex == NULL) { + free(tex); + return NULL; } - tex->tex = wlr_render_texture_create(renderer->wlr_rend); - wlr_texture_upload_eglimage(tex->tex, tex->img, width, height); - gbm_bo_set_user_data(bo, tex, free_eglimage); - return tex->tex; } -- cgit v1.2.3 From 3bda7e2ef8db955bb56e9dbf700974de06a2836b Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 12:00:08 -0400 Subject: Use DRM_FORMAT_MOD_LINEAR instead of a hardcoded constant --- backend/drm/renderer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'backend/drm/renderer.c') diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 2b50bb79..c1531ce3 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -14,6 +14,10 @@ #include "backend/drm/drm.h" #include "glapi.h" +#ifndef DRM_FORMAT_MOD_LINEAR +#define DRM_FORMAT_MOD_LINEAR 0 +#endif + bool wlr_drm_renderer_init(struct wlr_drm_backend *drm, struct wlr_drm_renderer *renderer) { renderer->gbm = gbm_create_device(drm->fd); @@ -195,7 +199,7 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, }; attribs.offset[0] = 0; attribs.stride[0] = gbm_bo_get_stride_for_plane(bo, 0); - attribs.modifier[0] = 0; + attribs.modifier[0] = DRM_FORMAT_MOD_LINEAR; attribs.fd[0] = gbm_bo_get_fd(bo); tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs); -- cgit v1.2.3 From 33a2eb4b7775d1a3ab2b767739c1f1f054683d22 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 18:49:43 -0400 Subject: Untie wlr_backend from wlr_renderer --- backend/drm/renderer.c | 2 +- backend/headless/backend.c | 2 +- backend/wayland/backend.c | 2 +- backend/x11/backend.c | 2 +- examples/output-layout.c | 3 ++- examples/rotation.c | 3 ++- examples/tablet.c | 3 ++- examples/touch.c | 3 ++- include/wlr/render/gles2.h | 3 ++- render/gles2/renderer.c | 5 ++--- 10 files changed, 16 insertions(+), 12 deletions(-) (limited to 'backend/drm/renderer.c') diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index c1531ce3..f06de1ee 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -31,7 +31,7 @@ bool wlr_drm_renderer_init(struct wlr_drm_backend *drm, goto error_gbm; } - renderer->wlr_rend = wlr_gles2_renderer_create(&drm->backend); + renderer->wlr_rend = wlr_gles2_renderer_create(&renderer->egl); if (!renderer->wlr_rend) { wlr_log(L_ERROR, "Failed to create WLR renderer"); goto error_egl; diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 663bc13b..5bc48240 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -114,7 +114,7 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) { return NULL; } - backend->renderer = wlr_gles2_renderer_create(&backend->backend); + backend->renderer = wlr_gles2_renderer_create(&backend->egl); if (backend->renderer == NULL) { wlr_log(L_ERROR, "Failed to create renderer"); } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index abb25df5..0135f7c5 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -212,7 +212,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, const char backend->remote_display, NULL, WL_SHM_FORMAT_ARGB8888); wlr_egl_bind_display(&backend->egl, backend->local_display); - backend->renderer = wlr_gles2_renderer_create(&backend->backend); + backend->renderer = wlr_gles2_renderer_create(&backend->egl); if (backend->renderer == NULL) { wlr_log_errno(L_ERROR, "Could not create renderer"); } diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 90658f26..f598aea1 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -314,7 +314,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, goto error_event; } - x11->renderer = wlr_gles2_renderer_create(&x11->backend); + x11->renderer = wlr_gles2_renderer_create(&x11->egl); if (x11->renderer == NULL) { wlr_log(L_ERROR, "Failed to create renderer"); goto error_egl; diff --git a/examples/output-layout.c b/examples/output-layout.c index c1392a30..53aae7f0 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -196,7 +196,8 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); state.cat_texture = wlr_texture_from_pixels(state.renderer, WL_SHM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data); diff --git a/examples/rotation.c b/examples/rotation.c index dfafeeca..37873797 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -137,7 +137,8 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); diff --git a/examples/tablet.c b/examples/tablet.c index be428f86..d80b4b2f 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -192,7 +192,8 @@ int main(int argc, char *argv[]) { }; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); diff --git a/examples/touch.c b/examples/touch.c index e9dcf29c..16024fc8 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -108,7 +108,8 @@ int main(int argc, char *argv[]) { }; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index b3b43ab2..a59956bd 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -5,6 +5,7 @@ #include struct wlr_egl; -struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend); + +struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl); #endif diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index c8094847..77af0ab7 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -400,7 +399,7 @@ extern const GLchar tex_fragment_src_rgba[]; extern const GLchar tex_fragment_src_rgbx[]; extern const GLchar tex_fragment_src_external[]; -struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { +struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) { struct wlr_gles2_renderer *renderer = calloc(1, sizeof(struct wlr_gles2_renderer)); if (renderer == NULL) { @@ -408,7 +407,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { } wlr_renderer_init(&renderer->wlr_renderer, &renderer_impl); - renderer->egl = wlr_backend_get_egl(backend); + renderer->egl = egl; wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL); renderer->exts_str = (const char*) glGetString(GL_EXTENSIONS); -- cgit v1.2.3