wlr_drm_format: Rework wlr_drm_format_intersect

Now it takes a reference to a destination format
This commit is contained in:
Alexander Orzechowski 2023-05-04 19:24:44 -04:00 committed by Simon Ser
parent 340700cb70
commit 90d08f8f1c
10 changed files with 93 additions and 104 deletions

View file

@ -242,7 +242,8 @@ static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
wlr_box_intersection(&intersection, &output_box, &cursor_box);
}
static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *output) {
static bool output_pick_cursor_format(struct wlr_output *output,
struct wlr_drm_format *format) {
struct wlr_allocator *allocator = output->allocator;
assert(allocator != NULL);
@ -252,11 +253,11 @@ static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *outpu
output->impl->get_cursor_formats(output, allocator->buffer_caps);
if (display_formats == NULL) {
wlr_log(WLR_DEBUG, "Failed to get cursor display formats");
return NULL;
return false;
}
}
return output_pick_format(output, display_formats, DRM_FORMAT_ARGB8888);
return output_pick_format(output, display_formats, format, DRM_FORMAT_ARGB8888);
}
static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) {
@ -289,18 +290,16 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
if (output->cursor_swapchain == NULL ||
output->cursor_swapchain->width != width ||
output->cursor_swapchain->height != height) {
struct wlr_drm_format *format =
output_pick_cursor_format(output);
if (format == NULL) {
struct wlr_drm_format format = {0};
if (!output_pick_cursor_format(output, &format)) {
wlr_log(WLR_DEBUG, "Failed to pick cursor format");
return NULL;
}
wlr_swapchain_destroy(output->cursor_swapchain);
output->cursor_swapchain = wlr_swapchain_create(allocator,
width, height, format);
wlr_drm_format_finish(format);
free(format);
width, height, &format);
wlr_drm_format_finish(&format);
if (output->cursor_swapchain == NULL) {
wlr_log(WLR_ERROR, "Failed to create cursor swapchain");
return NULL;

View file

@ -602,15 +602,13 @@ static bool output_basic_test(struct wlr_output *output,
const struct wlr_drm_format_set *display_formats =
wlr_output_get_primary_formats(output, allocator->buffer_caps);
struct wlr_drm_format *format = output_pick_format(output, display_formats,
state->render_format);
if (format == NULL) {
struct wlr_drm_format format = {0};
if (!output_pick_format(output, display_formats, &format, state->render_format)) {
wlr_log(WLR_ERROR, "Failed to pick primary buffer format for output");
return false;
}
wlr_drm_format_finish(format);
free(format);
wlr_drm_format_finish(&format);
}
bool enabled = output->enabled;

View file

@ -179,9 +179,9 @@ void wlr_output_lock_attach_render(struct wlr_output *output, bool lock) {
output->attach_render_locks);
}
struct wlr_drm_format *output_pick_format(struct wlr_output *output,
bool output_pick_format(struct wlr_output *output,
const struct wlr_drm_format_set *display_formats,
uint32_t fmt) {
struct wlr_drm_format *format, uint32_t fmt) {
struct wlr_renderer *renderer = output->renderer;
struct wlr_allocator *allocator = output->allocator;
assert(renderer != NULL && allocator != NULL);
@ -190,43 +190,37 @@ struct wlr_drm_format *output_pick_format(struct wlr_output *output,
wlr_renderer_get_render_formats(renderer);
if (render_formats == NULL) {
wlr_log(WLR_ERROR, "Failed to get render formats");
return NULL;
return false;
}
const struct wlr_drm_format *render_format =
wlr_drm_format_set_get(render_formats, fmt);
if (render_format == NULL) {
wlr_log(WLR_DEBUG, "Renderer doesn't support format 0x%"PRIX32, fmt);
return NULL;
return false;
}
struct wlr_drm_format *format = NULL;
if (display_formats != NULL) {
const struct wlr_drm_format *display_format =
wlr_drm_format_set_get(display_formats, fmt);
if (display_format == NULL) {
wlr_log(WLR_DEBUG, "Output doesn't support format 0x%"PRIX32, fmt);
return NULL;
}
format = wlr_drm_format_intersect(display_format, render_format);
} else {
format = calloc(1, sizeof(*format));
if (!format) {
return false;
}
if (!wlr_drm_format_intersect(format, display_format, render_format)) {
wlr_log(WLR_DEBUG, "Failed to intersect display and render "
"modifiers for format 0x%"PRIX32 " on output %s",
fmt, output->name);
return false;
}
} else {
// The output can display any format
wlr_drm_format_copy(format, render_format);
if (!wlr_drm_format_copy(format, render_format)) {
return false;
}
}
if (format == NULL) {
wlr_log(WLR_DEBUG, "Failed to intersect display and render "
"modifiers for format 0x%"PRIX32 " on output %s",
fmt, output->name);
return NULL;
}
return format;
return true;
}
uint32_t wlr_output_preferred_read_format(struct wlr_output *output) {

View file

@ -16,34 +16,35 @@ static struct wlr_swapchain *create_swapchain(struct wlr_output *output,
const struct wlr_drm_format_set *display_formats =
wlr_output_get_primary_formats(output, allocator->buffer_caps);
struct wlr_drm_format *format = output_pick_format(output, display_formats,
output->render_format);
if (format == NULL) {
struct wlr_drm_format format = {0};
if (!output_pick_format(output, display_formats, &format, output->render_format)) {
wlr_log(WLR_ERROR, "Failed to pick primary buffer format for output '%s'",
output->name);
return NULL;
}
char *format_name = drmGetFormatName(format->format);
char *format_name = drmGetFormatName(format.format);
wlr_log(WLR_DEBUG, "Choosing primary buffer format %s (0x%08"PRIX32") for output '%s'",
format_name ? format_name : "<unknown>", format->format, output->name);
format_name ? format_name : "<unknown>", format.format, output->name);
free(format_name);
if (!allow_modifiers && (format->len != 1 || format->modifiers[0] != DRM_FORMAT_MOD_LINEAR)) {
if (!wlr_drm_format_has(format, DRM_FORMAT_MOD_INVALID)) {
if (!allow_modifiers && (format.len != 1 || format.modifiers[0] != DRM_FORMAT_MOD_LINEAR)) {
if (!wlr_drm_format_has(&format, DRM_FORMAT_MOD_INVALID)) {
wlr_log(WLR_DEBUG, "Implicit modifiers not supported");
wlr_drm_format_finish(format);
free(format);
wlr_drm_format_finish(&format);
return NULL;
}
format->len = 0;
wlr_drm_format_add(format, DRM_FORMAT_MOD_INVALID);
format.len = 0;
if (!wlr_drm_format_add(&format, DRM_FORMAT_MOD_INVALID)) {
wlr_log(WLR_DEBUG, "Failed to add implicit modifier to format");
wlr_drm_format_finish(&format);
return NULL;
}
}
struct wlr_swapchain *swapchain = wlr_swapchain_create(allocator, width, height, format);
wlr_drm_format_finish(format);
free(format);
struct wlr_swapchain *swapchain = wlr_swapchain_create(allocator, width, height, &format);
wlr_drm_format_finish(&format);
return swapchain;
}