From 3dbff4025c8c7a371f3e6c0589398c0aca216f99 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 26 Jun 2024 19:42:39 +0200 Subject: [PATCH] allocator: allow format-less allocations will pick a format --- include/aquamarine/allocator/Swapchain.hpp | 2 +- src/allocator/GBM.cpp | 22 ++++++++++++---------- src/allocator/Swapchain.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/aquamarine/allocator/Swapchain.hpp b/include/aquamarine/allocator/Swapchain.hpp index 85cbe2b..efc7217 100644 --- a/include/aquamarine/allocator/Swapchain.hpp +++ b/include/aquamarine/allocator/Swapchain.hpp @@ -9,7 +9,7 @@ namespace Aquamarine { struct SSwapchainOptions { size_t length = 0; Hyprutils::Math::Vector2D size; - uint32_t format = DRM_FORMAT_INVALID; + uint32_t format = DRM_FORMAT_INVALID; // if you leave this on invalid, the swapchain will choose an appropriate format (and modifier) for you. bool scanout = false, cursor = false /* requires scanout = true */; }; diff --git a/src/allocator/GBM.cpp b/src/allocator/GBM.cpp index 6f285ba..f26db4a 100644 --- a/src/allocator/GBM.cpp +++ b/src/allocator/GBM.cpp @@ -21,9 +21,6 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti const bool CURSOR = params.cursor && params.scanout; - if (CURSOR) - allocator->backend->log(AQ_LOG_WARNING, "GBM: Allocating a cursor buffer"); - const auto FORMATS = CURSOR ? swapchain->backendImpl->getCursorFormats() : swapchain->backendImpl->getRenderFormats(); std::vector explicitModifiers; @@ -31,15 +28,25 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti // check if we can use modifiers. If the requested support has any explicit modifier // supported by the primary backend, we can. for (auto& f : FORMATS) { - if (f.drmFormat != params.format) + if (f.drmFormat != attrs.format && attrs.format != DRM_FORMAT_INVALID) continue; for (auto& m : f.modifiers) { - if (m == DRM_FORMAT_MOD_LINEAR || m == DRM_FORMAT_MOD_INVALID) + if (m == DRM_FORMAT_MOD_INVALID) continue; explicitModifiers.push_back(m); } + + if (attrs.format == DRM_FORMAT_INVALID) { + allocator->backend->log(AQ_LOG_WARNING, std::format("GBM: Automatically selected format {} for new GBM buffer", fourccToName(f.drmFormat))); + attrs.format = f.drmFormat; + } + } + + if (attrs.format == DRM_FORMAT_INVALID) { + allocator->backend->log(AQ_LOG_ERROR, "GBM: Failed to allocate a GBM buffer: no format found"); + return; } if (explicitModifiers.empty()) { @@ -163,11 +170,6 @@ SP Aquamarine::CGBMAllocator::acquire(const SAllocatorBufferParams& par return nullptr; } - if (params.format == DRM_FORMAT_INVALID) { - backend->log(AQ_LOG_ERROR, "Couldn't allocate a gbm buffer with invalid format"); - return nullptr; - } - auto newBuffer = SP(new CGBMBuffer(params, self, swapchain_)); if (!newBuffer->good()) { diff --git a/src/allocator/Swapchain.cpp b/src/allocator/Swapchain.cpp index 21118a9..f268f92 100644 --- a/src/allocator/Swapchain.cpp +++ b/src/allocator/Swapchain.cpp @@ -30,10 +30,10 @@ bool Aquamarine::CSwapchain::reconfigure(const SSwapchainOptions& options_) { return true; } - if (options_.format == options.format && options_.size == options.size && options_.length == options.length) + if ((options_.format == options.format || options_.format == DRM_FORMAT_INVALID) && options_.size == options.size && options_.length == options.length) return true; // no need to reconfigure - if (options_.format == options.format && options_.size == options.size) { + if ((options_.format == options.format || options_.format == DRM_FORMAT_INVALID) && options_.size == options.size) { bool ok = resize(options_.length); if (!ok) return false; @@ -49,6 +49,8 @@ bool Aquamarine::CSwapchain::reconfigure(const SSwapchainOptions& options_) { return false; options = options_; + if (options.format == DRM_FORMAT_INVALID) + options.format = buffers.at(0)->dmabuf().format; allocator->getBackend()->log(AQ_LOG_DEBUG, std::format("Swapchain: Reconfigured a swapchain to {} {} of length {}", options.size, fourccToName(options.format), options.length));