mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-11-17 02:35:59 +01:00
allocator: allow format-less allocations
will pick a format
This commit is contained in:
parent
41b1b28ce1
commit
3dbff4025c
3 changed files with 17 additions and 13 deletions
|
@ -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 */;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<uint64_t> 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<IBuffer> 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<CGBMBuffer>(new CGBMBuffer(params, self, swapchain_));
|
||||
|
||||
if (!newBuffer->good()) {
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue