Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/allocator/GBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/include/FormatUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

#include <string>
#include <cstdint>
#include <drm_fourcc.h>

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;
}
Loading