Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Require INVALID for implicit format modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Mar 31, 2021
1 parent 99fd980 commit 4ad970a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 50 deletions.
18 changes: 8 additions & 10 deletions backend/drm/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ static bool add_plane(struct wlr_drm_backend *drm,
p->id = drm_plane->plane_id;
p->props = *props;

for (size_t j = 0; j < drm_plane->count_formats; ++j) {
wlr_drm_format_set_add(&p->formats, drm_plane->formats[j],
DRM_FORMAT_MOD_INVALID);
for (size_t i = 0; i < drm_plane->count_formats; ++i) {
// Force a LINEAR layout for the cursor if the driver doesn't support
// modifiers
uint64_t mod = DRM_FORMAT_MOD_INVALID;
if (type == DRM_PLANE_TYPE_CURSOR) {
mod = DRM_FORMAT_MOD_LINEAR;
}
wlr_drm_format_set_add(&p->formats, drm_plane->formats[i], mod);
}

if (p->props.in_formats && drm->addfb2_modifiers) {
Expand Down Expand Up @@ -133,13 +138,6 @@ static bool add_plane(struct wlr_drm_backend *drm,
}

drmModeFreePropertyBlob(blob);
} else if (type == DRM_PLANE_TYPE_CURSOR) {
// Force a LINEAR layout for the cursor if the driver doesn't support
// modifiers
for (size_t i = 0; i < p->formats.len; ++i) {
wlr_drm_format_set_add(&p->formats, p->formats.formats[i]->format,
DRM_FORMAT_MOD_LINEAR);
}
}

switch (type) {
Expand Down
13 changes: 8 additions & 5 deletions backend/drm/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ void drm_plane_finish_surface(struct wlr_drm_plane *plane) {
finish_drm_surface(&plane->mgpu_surf);
}

static struct wlr_drm_format *create_linear_format(uint32_t format) {
static struct wlr_drm_format *create_single_mod_format(uint32_t format,
uint64_t modifier) {
struct wlr_drm_format *fmt = wlr_drm_format_create(format);
if (fmt == NULL) {
return NULL;
}
if (!wlr_drm_format_add(&fmt, DRM_FORMAT_MOD_LINEAR)) {
if (!wlr_drm_format_add(&fmt, modifier)) {
free(fmt);
return NULL;
}
Expand All @@ -204,7 +205,7 @@ static struct wlr_drm_format *create_linear_format(uint32_t format) {
bool drm_plane_init_surface(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm, int32_t width, uint32_t height,
uint32_t format, bool with_modifiers) {
if (!wlr_drm_format_set_has(&plane->formats, format, DRM_FORMAT_MOD_INVALID)) {
if (wlr_drm_format_set_get(&plane->formats, format) == NULL) {
const struct wlr_pixel_format_info *info =
drm_get_pixel_format_info(format);
if (!info) {
Expand Down Expand Up @@ -240,7 +241,8 @@ bool drm_plane_init_surface(struct wlr_drm_plane *plane,

struct wlr_drm_format *format_implicit_modifier = NULL;
if (!with_modifiers) {
format_implicit_modifier = wlr_drm_format_create(format);
format_implicit_modifier =
create_single_mod_format(format, DRM_FORMAT_MOD_INVALID);
render_format = format_implicit_modifier;
}

Expand All @@ -261,7 +263,8 @@ bool drm_plane_init_surface(struct wlr_drm_plane *plane,
ok = init_drm_surface(&plane->surf, &drm->renderer,
width, height, drm_format);
} else {
struct wlr_drm_format *drm_format_linear = create_linear_format(format);
struct wlr_drm_format *drm_format_linear =
create_single_mod_format(format, DRM_FORMAT_MOD_LINEAR);
if (drm_format_linear == NULL) {
free(drm_format);
free(format_implicit_modifier);
Expand Down
1 change: 1 addition & 0 deletions backend/x11/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ static bool query_dri3_formats(struct wlr_x11_backend *x11) {

const struct wlr_x11_format *format = x11_format_from_depth(depth);
if (format != NULL) {
// TODO: this assumes implicit modifiers are always supported
wlr_drm_format_set_add(&x11->dri3_formats, format->drm,
DRM_FORMAT_MOD_INVALID);

Expand Down
31 changes: 12 additions & 19 deletions render/drm_format_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set,
if (!fmt) {
return false;
}

if (modifier == DRM_FORMAT_MOD_INVALID) {
return true;
}

return wlr_drm_format_has(fmt, modifier);
}

Expand Down Expand Up @@ -112,10 +107,6 @@ bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) {
bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) {
struct wlr_drm_format *fmt = *fmt_ptr;

if (modifier == DRM_FORMAT_MOD_INVALID) {
return true;
}

if (wlr_drm_format_has(fmt, modifier)) {
return true;
}
Expand Down Expand Up @@ -153,15 +144,17 @@ struct wlr_drm_format *wlr_drm_format_intersect(
const struct wlr_drm_format *a, const struct wlr_drm_format *b) {
assert(a->format == b->format);

// Special case: if a format only supports LINEAR and the other doesn't
// support any modifier, force LINEAR. This will force the allocator to
// create a buffer with a LINEAR layout instead of an implicit modifier.
if (a->len == 0 && b->len == 1 && b->modifiers[0] == DRM_FORMAT_MOD_LINEAR) {
return wlr_drm_format_dup(b);
}
if (b->len == 0 && a->len == 1 && a->modifiers[0] == DRM_FORMAT_MOD_LINEAR) {
// Special case: if a format only supports LINEAR and the other supports
// implicit modifiers, force LINEAR. This will force the allocator to
// create a buffer with a linear layout instead of an implicit modifier.
if (a->len == 1 && a->modifiers[0] == DRM_FORMAT_MOD_LINEAR &&
wlr_drm_format_has(b, DRM_FORMAT_MOD_INVALID)) {
return wlr_drm_format_dup(a);
}
if (b->len == 1 && b->modifiers[0] == DRM_FORMAT_MOD_LINEAR &&
wlr_drm_format_has(a, DRM_FORMAT_MOD_INVALID)) {
return wlr_drm_format_dup(b);
}

size_t format_cap = a->len < b->len ? a->len : b->len;
size_t format_size = sizeof(struct wlr_drm_format) +
Expand All @@ -185,9 +178,9 @@ struct wlr_drm_format *wlr_drm_format_intersect(
}
}

// If both formats support modifiers, but the intersection is empty, then
// the formats aren't compatible with each other
if (format->len == 0 && a->len > 0 && b->len > 0) {
// If the intersection is empty, then the formats aren't compatible with
// each other.
if (format->len == 0) {
free(format);
return NULL;
}
Expand Down
11 changes: 5 additions & 6 deletions render/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ static void init_dmabuf_formats(struct wlr_egl *egl) {

has_modifiers = has_modifiers || modifiers_len > 0;

if (modifiers_len == 0) {
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,
DRM_FORMAT_MOD_INVALID);
wlr_drm_format_set_add(&egl->dmabuf_render_formats, fmt,
DRM_FORMAT_MOD_INVALID);
}
// EGL always supports implicit modifiers
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,
DRM_FORMAT_MOD_INVALID);
wlr_drm_format_set_add(&egl->dmabuf_render_formats, fmt,
DRM_FORMAT_MOD_INVALID);

for (int j = 0; j < modifiers_len; j++) {
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,
Expand Down
14 changes: 9 additions & 5 deletions render/gbm_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <unistd.h>
#include <wlr/util/log.h>
#include <xf86drm.h>
#include "render/drm_format_set.h"
#include "render/gbm_allocator.h"

static const struct wlr_buffer_impl buffer_impl;
Expand Down Expand Up @@ -78,17 +79,20 @@ static struct wlr_gbm_buffer *create_buffer(struct wlr_gbm_allocator *alloc,
int width, int height, const struct wlr_drm_format *format) {
struct gbm_device *gbm_device = alloc->gbm_device;

struct gbm_bo *bo = NULL;
assert(format->len > 0);

bool has_modifier = true;
if (format->len > 0) {
bo = gbm_bo_create_with_modifiers(gbm_device, width, height,
format->format, format->modifiers, format->len);
}
struct gbm_bo *bo = gbm_bo_create_with_modifiers(gbm_device, width, height,
format->format, format->modifiers, format->len);
if (bo == NULL) {
uint32_t usage = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
if (format->len == 1 &&
format->modifiers[0] == DRM_FORMAT_MOD_LINEAR) {
usage |= GBM_BO_USE_LINEAR;
} else if (!wlr_drm_format_has(format, DRM_FORMAT_MOD_INVALID)) {
// If the format doesn't accept an implicit modifier, bail out.
wlr_log(WLR_ERROR, "gbm_bo_create_with_modifiers failed");
return NULL;
}
bo = gbm_bo_create(gbm_device, width, height, format->format, usage);
has_modifier = false;
Expand Down
9 changes: 4 additions & 5 deletions types/wlr_linux_dmabuf_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/util/log.h>
#include "linux-dmabuf-unstable-v1-protocol.h"
#include "render/drm_format_set.h"
#include "util/signal.h"

#define LINUX_DMABUF_VERSION 3
Expand Down Expand Up @@ -388,7 +389,9 @@ struct wlr_linux_dmabuf_v1 *wlr_linux_dmabuf_v1_from_resource(
static void linux_dmabuf_send_modifiers(struct wl_resource *resource,
const struct wlr_drm_format *fmt) {
if (wl_resource_get_version(resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) {
zwp_linux_dmabuf_v1_send_format(resource, fmt->format);
if (wlr_drm_format_has(fmt, DRM_FORMAT_MOD_INVALID)) {
zwp_linux_dmabuf_v1_send_format(resource, fmt->format);
}
return;
}

Expand All @@ -397,10 +400,6 @@ static void linux_dmabuf_send_modifiers(struct wl_resource *resource,
zwp_linux_dmabuf_v1_send_modifier(resource, fmt->format,
mod >> 32, mod & 0xFFFFFFFF);
}

// We always support buffers with an implicit modifier
zwp_linux_dmabuf_v1_send_modifier(resource, fmt->format,
DRM_FORMAT_MOD_INVALID >> 32, DRM_FORMAT_MOD_INVALID & 0xFFFFFFFF);
}

static void linux_dmabuf_send_formats(struct wlr_linux_dmabuf_v1 *linux_dmabuf,
Expand Down

0 comments on commit 4ad970a

Please sign in to comment.