From d3bacb4600a5ceb2ca34c495815d7988f013c38c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 4 Jul 2024 23:13:23 +0200 Subject: [PATCH] swapchain: add rollback --- include/aquamarine/allocator/Swapchain.hpp | 5 +++++ src/allocator/Swapchain.cpp | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/aquamarine/allocator/Swapchain.hpp b/include/aquamarine/allocator/Swapchain.hpp index efc7217..3bf2074 100644 --- a/include/aquamarine/allocator/Swapchain.hpp +++ b/include/aquamarine/allocator/Swapchain.hpp @@ -24,6 +24,11 @@ namespace Aquamarine { Hyprutils::Memory::CSharedPointer next(int* age); const SSwapchainOptions& currentOptions(); + // rolls the buffers back, marking the last consumed as the next valid. + // useful if e.g. a commit fails and we don't wanna write to the previous buffer that is + // in use. + void rollback(); + private: CSwapchain(Hyprutils::Memory::CSharedPointer allocator_, Hyprutils::Memory::CSharedPointer backendImpl_); diff --git a/src/allocator/Swapchain.cpp b/src/allocator/Swapchain.cpp index f268f92..633d38a 100644 --- a/src/allocator/Swapchain.cpp +++ b/src/allocator/Swapchain.cpp @@ -114,3 +114,9 @@ bool Aquamarine::CSwapchain::contains(Hyprutils::Memory::CSharedPointer const SSwapchainOptions& Aquamarine::CSwapchain::currentOptions() { return options; } + +void Aquamarine::CSwapchain::rollback() { + lastAcquired--; + if (lastAcquired < 0) + lastAcquired = options.length - 1; +}