diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-06-24 18:16:42 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-06-24 18:16:42 -0400 |
commit | e8c0996b93c2d184d9d68ae4bee92dd4c469685c (patch) | |
tree | de9e94484a8f341836231af6d8a7daa3cd32d06e /backend/drm/renderer.c | |
parent | 28d718c0ddd8f2ba083be374f3d97e4836f615d9 (diff) | |
parent | e459fe0ec713ea65b35b966f9bb3c6c70c9504aa (diff) |
Merge branch 'master' into cancel-grab-on-focus-change
Diffstat (limited to 'backend/drm/renderer.c')
-rw-r--r-- | backend/drm/renderer.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 72a0254b..0ab63c86 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -160,6 +160,34 @@ void post_drm_surface(struct wlr_drm_surface *surf) { } } +bool export_drm_bo(struct gbm_bo *bo, struct wlr_dmabuf_attributes *attribs) { + memset(attribs, 0, sizeof(struct wlr_dmabuf_attributes)); + + attribs->n_planes = gbm_bo_get_plane_count(bo); + if (attribs->n_planes > WLR_DMABUF_MAX_PLANES) { + return false; + } + + attribs->width = gbm_bo_get_width(bo); + attribs->height = gbm_bo_get_height(bo); + attribs->format = gbm_bo_get_format(bo); + attribs->modifier = gbm_bo_get_modifier(bo); + + for (int i = 0; i < attribs->n_planes; ++i) { + attribs->offset[i] = gbm_bo_get_offset(bo, i); + attribs->stride[i] = gbm_bo_get_stride_for_plane(bo, i); + attribs->fd[i] = gbm_bo_get_fd(bo); + if (attribs->fd[i] < 0) { + for (int j = 0; j < i; ++j) { + close(attribs->fd[j]); + } + return false; + } + } + + return true; +} + struct tex { struct wlr_egl *egl; EGLImageKHR img; @@ -186,16 +214,11 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, return NULL; } - struct wlr_dmabuf_attributes attribs = { - .n_planes = 1, - .width = gbm_bo_get_width(bo), - .height = gbm_bo_get_height(bo), - .format = gbm_bo_get_format(bo), - .modifier = DRM_FORMAT_MOD_LINEAR, - }; - attribs.offset[0] = 0; - attribs.stride[0] = gbm_bo_get_stride_for_plane(bo, 0); - attribs.fd[0] = gbm_bo_get_fd(bo); + struct wlr_dmabuf_attributes attribs; + if (!export_drm_bo(bo, &attribs)) { + free(tex); + return NULL; + } tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs); if (tex->tex == NULL) { |