aboutsummaryrefslogtreecommitdiff
path: root/backend/drm
diff options
context:
space:
mode:
Diffstat (limited to 'backend/drm')
-rw-r--r--backend/drm/drm.c3
-rw-r--r--backend/drm/renderer.c33
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) {