diff --git a/src/allocator/GBM.cpp b/src/allocator/GBM.cpp index 72e7d456..59480256 100644 --- a/src/allocator/GBM.cpp +++ b/src/allocator/GBM.cpp @@ -101,6 +101,17 @@ Aquamarine::CGBMBuffer::CGBMBuffer(const SAllocatorBufferParams& params, Hypruti return; } + // Scanout planes that offer only the alpha variant of an 8 bpc format (Apple M5 internal panel): + // allocate the A variant when the X variant is requested but not offered. + if (params.scanout && !CURSOR) { + const auto hasFmt = [&FORMATS](uint32_t fmt) { return std::ranges::any_of(FORMATS, [fmt](const auto& f) { return f.drmFormat == fmt; }); }; + const uint32_t alt = opaqueToAlphaFormat(attrs.format); + if (alt != DRM_FORMAT_INVALID && !hasFmt(attrs.format) && hasFmt(alt)) { + allocator->backend->log(AQ_LOG_DEBUG, std::format("GBM: {} not offered by the scanout plane, using {}", fourccToName(attrs.format), fourccToName(alt))); + attrs.format = alt; + } + } + bool foundFormat = false; // check if we can use modifiers. If the requested support has any explicit modifier // supported by the primary backend, we can. diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index e2e9b7c0..6d8174a3 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -2547,7 +2547,7 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) { // verify the format is valid for the primary plane bool ok = false; for (auto const& f : getRenderFormats()) { - if (f.drmFormat == STATE.drmFormat) { + if (f.drmFormat == STATE.drmFormat || f.drmFormat == opaqueToAlphaFormat(STATE.drmFormat)) { ok = true; break; } @@ -2767,7 +2767,7 @@ bool Aquamarine::CDRMOutput::commitState(bool onlyTest) { // sometimes, our consumer could f up the swapchain format and change it without the state changing bool formatMismatch = false; if (data.mainFB) { - if (const auto params = data.mainFB->buffer->dmabuf(); params.success && params.format != STATE.drmFormat) { + if (const auto params = data.mainFB->buffer->dmabuf(); params.success && params.format != STATE.drmFormat && params.format != opaqueToAlphaFormat(STATE.drmFormat)) { // formats mismatch. Update the state format and roll with it backend->backend->log(AQ_LOG_WARNING, std::format("drm: Formats mismatch in commit, buffer is {} but output is set to {}. Modesetting to {}", fourccToName(params.format), @@ -3167,7 +3167,7 @@ Aquamarine::IOutput::SCommitSubmission Aquamarine::CDRMOutput::commitAsync(const const auto MAIN_BUFFER = data.mainFB ? data.mainFB->buffer.lock() : nullptr; const auto ATTRS = MAIN_BUFFER ? MAIN_BUFFER->dmabuf() : SDMABUFAttrs{}; - if (ATTRS.success && ATTRS.format != STATE.drmFormat) + if (ATTRS.success && ATTRS.format != STATE.drmFormat && ATTRS.format != opaqueToAlphaFormat(STATE.drmFormat)) return {.error = ENOTSUP}; if (options.lateCursor && cursorVisible && connector->crtc->cursor) diff --git a/src/include/FormatUtils.hpp b/src/include/FormatUtils.hpp index 75c8733c..ea2ab0af 100644 --- a/src/include/FormatUtils.hpp +++ b/src/include/FormatUtils.hpp @@ -2,6 +2,16 @@ #include #include +#include std::string fourccToName(uint32_t drmFormat); std::string drmModifierToName(uint64_t drmModifier); + +// Alpha variant of an opaque 8 bpc format, or DRM_FORMAT_INVALID. Used when a scanout plane offers only the alpha variant. +inline uint32_t opaqueToAlphaFormat(uint32_t fmt) { + if (fmt == DRM_FORMAT_XRGB8888) + return DRM_FORMAT_ARGB8888; + if (fmt == DRM_FORMAT_XBGR8888) + return DRM_FORMAT_ABGR8888; + return DRM_FORMAT_INVALID; +}