Skip to content

Commit

Permalink
backend/drm: use modifiers for our GBM buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion authored and ascent12 committed Oct 11, 2019
1 parent 11bf87d commit 2bdd1d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 6 additions & 4 deletions backend/drm/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,22 +680,24 @@ static bool drm_connector_set_cursor(struct wlr_output *output,
ret = drmGetCap(drm->fd, DRM_CAP_CURSOR_HEIGHT, &h);
h = ret ? 64 : h;


if (!drm->parent) {
if (!init_drm_surface(&plane->surf, &drm->renderer, w, h,
drm->renderer.gbm_format, GBM_BO_USE_LINEAR | GBM_BO_USE_SCANOUT)) {
drm->renderer.gbm_format, NULL,
GBM_BO_USE_LINEAR | GBM_BO_USE_SCANOUT)) {
wlr_log(WLR_ERROR, "Cannot allocate cursor resources");
return false;
}
} else {
if (!init_drm_surface(&plane->surf, &drm->parent->renderer, w, h,
drm->parent->renderer.gbm_format, GBM_BO_USE_LINEAR)) {
drm->parent->renderer.gbm_format, NULL,
GBM_BO_USE_LINEAR)) {
wlr_log(WLR_ERROR, "Cannot allocate cursor resources");
return false;
}

if (!init_drm_surface(&plane->mgpu_surf, &drm->renderer, w, h,
drm->renderer.gbm_format, GBM_BO_USE_LINEAR | GBM_BO_USE_SCANOUT)) {
drm->renderer.gbm_format, NULL,
GBM_BO_USE_LINEAR | GBM_BO_USE_SCANOUT)) {
wlr_log(WLR_ERROR, "Cannot allocate cursor resources");
return false;
}
Expand Down
23 changes: 17 additions & 6 deletions backend/drm/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer) {

bool init_drm_surface(struct wlr_drm_surface *surf,
struct wlr_drm_renderer *renderer, uint32_t width, uint32_t height,
uint32_t format, uint32_t flags) {
uint32_t format, struct wlr_drm_format_set *set, uint32_t flags) {
if (surf->width == width && surf->height == height) {
return true;
}
Expand All @@ -84,8 +84,19 @@ bool init_drm_surface(struct wlr_drm_surface *surf,
}
wlr_egl_destroy_surface(&surf->renderer->egl, surf->egl);

surf->gbm = gbm_surface_create(renderer->gbm, width, height,
format, GBM_BO_USE_RENDERING | flags);
if (!(flags & GBM_BO_USE_LINEAR) && set != NULL) {
const struct wlr_drm_format *drm_format =
wlr_drm_format_set_get(set, format);
if (drm_format != NULL) {
surf->gbm = gbm_surface_create_with_modifiers(renderer->gbm,
width, height, format, drm_format->modifiers, drm_format->len);
}
}

if (surf->gbm == NULL) {
surf->gbm = gbm_surface_create(renderer->gbm, width, height,
format, GBM_BO_USE_RENDERING | flags);
}
if (!surf->gbm) {
wlr_log_errno(WLR_ERROR, "Failed to create GBM surface");
goto error_zero;
Expand Down Expand Up @@ -279,16 +290,16 @@ bool init_drm_plane_surfaces(struct wlr_drm_plane *plane,
uint32_t format) {
if (!drm->parent) {
return init_drm_surface(&plane->surf, &drm->renderer, width, height,
format, GBM_BO_USE_SCANOUT);
format, &plane->formats, GBM_BO_USE_SCANOUT);
}

if (!init_drm_surface(&plane->surf, &drm->parent->renderer,
width, height, format, GBM_BO_USE_LINEAR)) {
width, height, format, NULL, GBM_BO_USE_LINEAR)) {
return false;
}

if (!init_drm_surface(&plane->mgpu_surf, &drm->renderer,
width, height, format, GBM_BO_USE_SCANOUT)) {
width, height, format, &plane->formats, GBM_BO_USE_SCANOUT)) {
finish_drm_surface(&plane->surf);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion include/backend/drm/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer);

bool init_drm_surface(struct wlr_drm_surface *surf,
struct wlr_drm_renderer *renderer, uint32_t width, uint32_t height,
uint32_t format, uint32_t flags);
uint32_t format, struct wlr_drm_format_set *set, uint32_t flags);

bool init_drm_plane_surfaces(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm, int32_t width, uint32_t height,
Expand Down

0 comments on commit 2bdd1d0

Please sign in to comment.