backend/drm: introduce drm_fb_create

This commit is contained in:
Simon Ser 2020-12-22 17:44:22 +01:00
parent 5b1b43c68c
commit cd64610c66
2 changed files with 37 additions and 23 deletions

View file

@ -363,38 +363,32 @@ static struct gbm_bo *get_bo_for_dmabuf(struct gbm_device *gbm,
} }
} }
bool drm_fb_import(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm, static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm,
struct wlr_buffer *buf, struct wlr_drm_surface *mgpu, struct wlr_buffer *buf, struct wlr_buffer *mgpu_buf,
struct wlr_drm_format_set *set) { const struct wlr_drm_format_set *formats) {
struct wlr_drm_fb *fb = calloc(1, sizeof(*fb)); struct wlr_drm_fb *fb = calloc(1, sizeof(*fb));
if (!fb) { if (!fb) {
return false; return NULL;
} }
fb->wlr_buf = wlr_buffer_lock(buf); fb->wlr_buf = wlr_buffer_lock(buf);
if (mgpu_buf) {
if (drm->parent && mgpu) { fb->mgpu_wlr_buf = wlr_buffer_lock(mgpu_buf);
// Perform a copy across GPUs
fb->mgpu_wlr_buf = drm_surface_blit(mgpu, buf);
if (!fb->mgpu_wlr_buf) {
wlr_log(WLR_ERROR, "Failed to blit buffer across GPUs");
goto error_mgpu_wlr_buf;
}
buf = fb->mgpu_wlr_buf;
} }
struct wlr_buffer *local_buf = mgpu_buf ? mgpu_buf : buf;
struct wlr_dmabuf_attributes attribs; struct wlr_dmabuf_attributes attribs;
if (!wlr_buffer_get_dmabuf(buf, &attribs)) { if (!wlr_buffer_get_dmabuf(local_buf, &attribs)) {
wlr_log(WLR_ERROR, "Failed to get DMA-BUF from buffer"); wlr_log(WLR_ERROR, "Failed to get DMA-BUF from buffer");
goto error_get_dmabuf; goto error_get_dmabuf;
} }
if (set && !wlr_drm_format_set_has(set, attribs.format, attribs.modifier)) { if (formats && !wlr_drm_format_set_has(formats, attribs.format,
attribs.modifier)) {
// The format isn't supported by the plane. Try stripping the alpha // The format isn't supported by the plane. Try stripping the alpha
// channel, if any. // channel, if any.
uint32_t format = strip_alpha_channel(attribs.format); uint32_t format = strip_alpha_channel(attribs.format);
if (wlr_drm_format_set_has(set, format, attribs.modifier)) { if (wlr_drm_format_set_has(formats, format, attribs.modifier)) {
attribs.format = format; attribs.format = format;
} else { } else {
wlr_log(WLR_ERROR, "Buffer format 0x%"PRIX32" cannot be scanned out", wlr_log(WLR_ERROR, "Buffer format 0x%"PRIX32" cannot be scanned out",
@ -415,19 +409,39 @@ bool drm_fb_import(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm,
goto error_get_fb_for_bo; goto error_get_fb_for_bo;
} }
drm_fb_move(fb_ptr, &fb); return fb;
return true;
error_get_fb_for_bo: error_get_fb_for_bo:
gbm_bo_destroy(fb->bo); gbm_bo_destroy(fb->bo);
error_get_dmabuf: error_get_dmabuf:
wlr_buffer_unlock(fb->mgpu_wlr_buf); wlr_buffer_unlock(fb->mgpu_wlr_buf);
error_mgpu_wlr_buf:
wlr_buffer_unlock(fb->wlr_buf); wlr_buffer_unlock(fb->wlr_buf);
free(fb); free(fb);
return NULL;
}
bool drm_fb_import(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm,
struct wlr_buffer *buf, struct wlr_drm_surface *mgpu,
const struct wlr_drm_format_set *formats) {
struct wlr_buffer *mgpu_buf = NULL;
if (drm->parent && mgpu) {
// Perform a copy across GPUs
mgpu_buf = drm_surface_blit(mgpu, buf);
if (!mgpu_buf) {
wlr_log(WLR_ERROR, "Failed to blit buffer across GPUs");
return false; return false;
} }
}
struct wlr_drm_fb *fb = drm_fb_create(drm, buf, mgpu_buf, formats);
wlr_buffer_unlock(mgpu_buf);
if (!fb) {
return false;
}
drm_fb_move(fb_ptr, &fb);
return true;
}
void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old) { void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old) {
drm_fb_clear(new); drm_fb_clear(new);

View file

@ -49,7 +49,7 @@ bool drm_fb_lock_surface(struct wlr_drm_fb **fb, struct wlr_drm_backend *drm,
struct wlr_drm_surface *surf, struct wlr_drm_surface *mgpu); struct wlr_drm_surface *surf, struct wlr_drm_surface *mgpu);
bool drm_fb_import(struct wlr_drm_fb **fb, struct wlr_drm_backend *drm, bool drm_fb_import(struct wlr_drm_fb **fb, struct wlr_drm_backend *drm,
struct wlr_buffer *buf, struct wlr_drm_surface *mgpu, struct wlr_buffer *buf, struct wlr_drm_surface *mgpu,
struct wlr_drm_format_set *set); const struct wlr_drm_format_set *formats);
void drm_fb_clear(struct wlr_drm_fb **fb); void drm_fb_clear(struct wlr_drm_fb **fb);
void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old); void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old);