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

Commit

Permalink
types/output: use request_swapchain signal to create swapchain
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ckb0ne committed Sep 29, 2021
1 parent 09e9da5 commit ef79230
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions types/wlr_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/box.h>
Expand All @@ -21,6 +20,7 @@
#include "render/drm_format_set.h"
#include "render/swapchain.h"
#include "render/wlr_renderer.h"
#include "types/wlr_output.h"
#include "util/global.h"
#include "util/signal.h"

Expand Down Expand Up @@ -499,45 +499,26 @@ static bool output_create_swapchain(struct wlr_output *output,
return true;
}

struct wlr_allocator *allocator = backend_get_allocator(output->backend);
if (allocator == NULL) {
wlr_log(WLR_ERROR, "Failed to get backend allocator");
return false;
}
wlr_log(WLR_DEBUG, "output '%s' requesting swapchain of size %dx%d",
output->name, width, height);

const struct wlr_drm_format_set *display_formats = NULL;
if (output->impl->get_primary_formats) {
display_formats =
output->impl->get_primary_formats(output, allocator->buffer_caps);
if (display_formats == NULL) {
wlr_log(WLR_ERROR, "Failed to get primary display formats");
return false;
}
}

struct wlr_drm_format *format = output_pick_format(output, display_formats);
if (format == NULL) {
wlr_log(WLR_ERROR, "Failed to pick primary buffer format for output '%s'",
output->name);
return false;
}
wlr_log(WLR_DEBUG, "Choosing primary buffer format 0x%"PRIX32" for output '%s'",
format->format, output->name);
struct wlr_output_swapchain_request request = {
.output = output,
.width = width,
.height = height,
.allow_modifiers = allow_modifiers,
.swapchain = NULL,
};

if (!allow_modifiers && (format->len != 1 || format->modifiers[0] != DRM_FORMAT_MOD_LINEAR)) {
format->len = 0;
}
wlr_signal_emit_safe(&output->events.request_swapchain, &request);

struct wlr_swapchain *swapchain =
wlr_swapchain_create(allocator, width, height, format);
free(format);
if (swapchain == NULL) {
if (request.swapchain == NULL) {
wlr_log(WLR_ERROR, "Failed to create output swapchain");
return false;
}

wlr_swapchain_destroy(output->swapchain);
output->swapchain = swapchain;
output->swapchain = request.swapchain;

return true;
}
Expand Down

0 comments on commit ef79230

Please sign in to comment.