backend/drm: support multi-planar DMA-BUFs when exporting

This commit is contained in:
emersion 2018-05-22 23:07:15 +01:00
parent 36bd4795d4
commit bd430b8620
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
3 changed files with 28 additions and 10 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -52,7 +52,7 @@ struct gbm_bo *get_drm_surface_front(struct wlr_drm_surface *surf);
void post_drm_surface(struct wlr_drm_surface *surf);
struct gbm_bo *copy_drm_surface_mgpu(struct wlr_drm_surface *dest,
struct gbm_bo *src);
void export_drm_bo(struct gbm_bo *bo,
bool export_drm_bo(struct gbm_bo *bo,
struct wlr_dmabuf_buffer_attribs *attribs);
#endif