diff options
author | emersion <contact@emersion.fr> | 2018-05-22 23:07:15 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-05-29 18:47:17 +0100 |
commit | bd430b8620f5dec485e49269d6add8dc3c20a8ab (patch) | |
tree | 5ad0661e9b7e89848734f0703df8dd2ed8f375cb /backend | |
parent | 36bd4795d4fe2282dfcc59f26863bac2896a4a3f (diff) |
backend/drm: support multi-planar DMA-BUFs when exporting
Diffstat (limited to 'backend')
-rw-r--r-- | backend/drm/drm.c | 3 | ||||
-rw-r--r-- | backend/drm/renderer.c | 33 |
2 files changed, 27 insertions, 9 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 5b6054d3..d54c93f8 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -270,8 +270,7 @@ static bool drm_connector_export_dmabuf(struct wlr_output *output, struct wlr_drm_plane *plane = crtc->primary; struct wlr_drm_surface *surf = &plane->surf; - export_drm_bo(surf->back, attribs); - return true; + return export_drm_bo(surf->back, attribs); } static void drm_connector_start_renderer(struct wlr_drm_connector *conn) { diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 2cb47a12..15cf8cce 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -160,17 +160,33 @@ void post_drm_surface(struct wlr_drm_surface *surf) { } } -void export_drm_bo(struct gbm_bo *bo, +bool export_drm_bo(struct gbm_bo *bo, struct wlr_dmabuf_buffer_attribs *attribs) { memset(attribs, 0, sizeof(struct wlr_dmabuf_buffer_attribs)); - attribs->n_planes = 1; + + attribs->n_planes = gbm_bo_get_plane_count(bo); + if (attribs->n_planes > WLR_LINUX_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->offset[0] = 0; - attribs->stride[0] = gbm_bo_get_stride_for_plane(bo, 0); - attribs->modifier[0] = DRM_FORMAT_MOD_LINEAR; - attribs->fd[0] = gbm_bo_get_fd(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->modifier[i] = gbm_bo_get_modifier(bo); + 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 { @@ -200,7 +216,10 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, } struct wlr_dmabuf_buffer_attribs attribs; - export_drm_bo(bo, &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) { |