mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-20 06:47:19 -04:00
render/swapchain: switch to init()/finish()
This commit is contained in:
parent
ef49909da8
commit
53757b18bd
8 changed files with 62 additions and 71 deletions
|
|
@ -260,9 +260,8 @@ 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) {
|
||||
if (output->cursor_swapchain.width != width ||
|
||||
output->cursor_swapchain.height != height) {
|
||||
struct wlr_drm_format *format =
|
||||
output_pick_cursor_format(output);
|
||||
if (format == NULL) {
|
||||
|
|
@ -270,18 +269,19 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
wlr_swapchain_destroy(output->cursor_swapchain);
|
||||
output->cursor_swapchain = wlr_swapchain_create(allocator,
|
||||
wlr_swapchain_finish(&output->cursor_swapchain);
|
||||
bool ok = wlr_swapchain_init(&output->cursor_swapchain, allocator,
|
||||
width, height, format);
|
||||
free(format);
|
||||
if (output->cursor_swapchain == NULL) {
|
||||
if (!ok) {
|
||||
memset(&output->cursor_swapchain, 0, sizeof(output->cursor_swapchain));
|
||||
wlr_log(WLR_ERROR, "Failed to create cursor swapchain");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
struct wlr_buffer *buffer =
|
||||
wlr_swapchain_acquire(output->cursor_swapchain, NULL);
|
||||
wlr_swapchain_acquire(&output->cursor_swapchain, NULL);
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
#include <drm_fourcc.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
#include <wlr/render/swapchain.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_output_layer.h>
|
||||
|
|
@ -248,11 +247,10 @@ void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width,
|
|||
|
||||
output->refresh = refresh;
|
||||
|
||||
if (output->swapchain != NULL &&
|
||||
(output->swapchain->width != output->width ||
|
||||
output->swapchain->height != output->height)) {
|
||||
wlr_swapchain_destroy(output->swapchain);
|
||||
output->swapchain = NULL;
|
||||
if (output->swapchain.width != output->width ||
|
||||
output->swapchain.height != output->height) {
|
||||
wlr_swapchain_finish(&output->swapchain);
|
||||
memset(&output->swapchain, 0, sizeof(output->swapchain));
|
||||
}
|
||||
|
||||
struct wl_resource *resource;
|
||||
|
|
@ -396,10 +394,10 @@ void wlr_output_destroy(struct wlr_output *output) {
|
|||
wlr_output_layer_destroy(layer);
|
||||
}
|
||||
|
||||
wlr_swapchain_destroy(output->cursor_swapchain);
|
||||
wlr_swapchain_finish(&output->cursor_swapchain);
|
||||
wlr_buffer_unlock(output->cursor_front_buffer);
|
||||
|
||||
wlr_swapchain_destroy(output->swapchain);
|
||||
wlr_swapchain_finish(&output->swapchain);
|
||||
|
||||
if (output->idle_frame != NULL) {
|
||||
wl_event_source_remove(output->idle_frame);
|
||||
|
|
@ -822,10 +820,10 @@ bool wlr_output_commit_state(struct wlr_output *output,
|
|||
|
||||
// Destroy the swapchains when an output is disabled
|
||||
if ((pending.committed & WLR_OUTPUT_STATE_ENABLED) && !pending.enabled) {
|
||||
wlr_swapchain_destroy(output->swapchain);
|
||||
output->swapchain = NULL;
|
||||
wlr_swapchain_destroy(output->cursor_swapchain);
|
||||
output->cursor_swapchain = NULL;
|
||||
wlr_swapchain_finish(&output->swapchain);
|
||||
memset(&output->swapchain, 0, sizeof(output->swapchain));
|
||||
wlr_swapchain_finish(&output->cursor_swapchain);
|
||||
memset(&output->cursor_swapchain, 0, sizeof(output->cursor_swapchain));
|
||||
}
|
||||
|
||||
if (pending.committed & WLR_OUTPUT_STATE_BUFFER) {
|
||||
|
|
@ -843,8 +841,8 @@ bool wlr_output_commit_state(struct wlr_output *output,
|
|||
}
|
||||
|
||||
if ((pending.committed & WLR_OUTPUT_STATE_BUFFER) &&
|
||||
output->swapchain != NULL) {
|
||||
wlr_swapchain_set_buffer_submitted(output->swapchain, pending.buffer);
|
||||
output->swapchain.width != 0) {
|
||||
wlr_swapchain_set_buffer_submitted(&output->swapchain, pending.buffer);
|
||||
}
|
||||
|
||||
struct wlr_output_event_commit event = {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/render/swapchain.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <xf86drm.h>
|
||||
#include "backend/backend.h"
|
||||
|
|
@ -31,11 +30,11 @@ bool wlr_output_init_render(struct wlr_output *output,
|
|||
return false;
|
||||
}
|
||||
|
||||
wlr_swapchain_destroy(output->swapchain);
|
||||
output->swapchain = NULL;
|
||||
wlr_swapchain_finish(&output->swapchain);
|
||||
memset(&output->swapchain, 0, sizeof(output->swapchain));
|
||||
|
||||
wlr_swapchain_destroy(output->cursor_swapchain);
|
||||
output->cursor_swapchain = NULL;
|
||||
wlr_swapchain_finish(&output->cursor_swapchain);
|
||||
memset(&output->cursor_swapchain, 0, sizeof(output->cursor_swapchain));
|
||||
|
||||
output->allocator = allocator;
|
||||
output->renderer = renderer;
|
||||
|
|
@ -68,10 +67,10 @@ static bool output_create_swapchain(struct wlr_output *output,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (output->swapchain != NULL && output->swapchain->width == width &&
|
||||
output->swapchain->height == height &&
|
||||
output->swapchain->format->format == format->format &&
|
||||
(allow_modifiers || output->swapchain->format->len == 0)) {
|
||||
if (output->swapchain.width == width &&
|
||||
output->swapchain.height == height &&
|
||||
output->swapchain.format->format == format->format &&
|
||||
(allow_modifiers || output->swapchain.format->len == 0)) {
|
||||
// no change, keep existing swapchain
|
||||
free(format);
|
||||
return true;
|
||||
|
|
@ -93,17 +92,15 @@ static bool output_create_swapchain(struct wlr_output *output,
|
|||
wlr_drm_format_add(&format, DRM_FORMAT_MOD_INVALID);
|
||||
}
|
||||
|
||||
struct wlr_swapchain *swapchain =
|
||||
wlr_swapchain_create(allocator, width, height, format);
|
||||
wlr_swapchain_finish(&output->swapchain);
|
||||
bool ok = wlr_swapchain_init(&output->swapchain, allocator, width, height, format);
|
||||
free(format);
|
||||
if (swapchain == NULL) {
|
||||
if (!ok) {
|
||||
memset(&output->swapchain, 0, sizeof(output->swapchain));
|
||||
wlr_log(WLR_ERROR, "Failed to create output swapchain");
|
||||
return false;
|
||||
}
|
||||
|
||||
wlr_swapchain_destroy(output->swapchain);
|
||||
output->swapchain = swapchain;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +116,7 @@ static bool output_attach_back_buffer(struct wlr_output *output,
|
|||
assert(renderer != NULL);
|
||||
|
||||
struct wlr_buffer *buffer =
|
||||
wlr_swapchain_acquire(output->swapchain, buffer_age);
|
||||
wlr_swapchain_acquire(&output->swapchain, buffer_age);
|
||||
if (buffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -247,7 +244,7 @@ bool output_ensure_buffer(struct wlr_output *output,
|
|||
|
||||
output_clear_back_buffer(output);
|
||||
|
||||
if (output->swapchain->format->len == 0) {
|
||||
if (output->swapchain.format->len == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -274,8 +271,8 @@ error_destroy_swapchain:
|
|||
// Destroy the modifierless swapchain so that the output does not get stuck
|
||||
// without modifiers. A new swapchain with modifiers will be created when
|
||||
// needed by output_attach_back_buffer().
|
||||
wlr_swapchain_destroy(output->swapchain);
|
||||
output->swapchain = NULL;
|
||||
wlr_swapchain_finish(&output->swapchain);
|
||||
memset(&output->swapchain, 0, sizeof(output->swapchain));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -358,12 +355,12 @@ uint32_t wlr_output_preferred_read_format(struct wlr_output *output) {
|
|||
|
||||
bool output_is_direct_scanout(struct wlr_output *output,
|
||||
struct wlr_buffer *buffer) {
|
||||
if (output->swapchain == NULL) {
|
||||
if (output->swapchain.width == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
if (output->swapchain->slots[i].buffer == buffer) {
|
||||
if (output->swapchain.slots[i].buffer == buffer) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue