diff options
author | emersion <contact@emersion.fr> | 2018-03-24 18:30:28 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-03-24 23:48:32 -0400 |
commit | c63d94483b1e52817ca01ca82a867a78ebd39fa6 (patch) | |
tree | 46ec0a24a43aeff6513ca7a8a8ec25eb0c70e8e7 /backend/drm/renderer.c | |
parent | 80d3561d325335e92b196f7cb5797eea9d71d17d (diff) |
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.
Diffstat (limited to 'backend/drm/renderer.c')
-rw-r--r-- | backend/drm/renderer.c | 48 |
1 files changed, 17 insertions, 31 deletions
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; } |