diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index d6189acd..e6bebdfd 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -445,10 +445,29 @@ SP CPointerManager::renderHWCursorBuffer(SPresource(); auto& shmBuffer = CCursorSurfaceRole::cursorPixelData(SURFACE); + bool flipRB = false; + + if (SURFACE->current.texture) { + Debug::log(TRACE, "Cursor CPU surface: format {}, expecting AR24", FormatUtils::drmFormatName(SURFACE->current.texture->m_iDrmFormat)); + if (SURFACE->current.texture->m_iDrmFormat == DRM_FORMAT_ABGR8888) { + Debug::log(TRACE, "Cursor CPU surface format AB24, will flip. WARNING: this will break on big endian!"); + flipRB = true; + } else if (SURFACE->current.texture->m_iDrmFormat != DRM_FORMAT_ARGB8888) { + Debug::log(TRACE, "Cursor CPU surface format rejected, falling back to sw"); + return nullptr; + } + } + if (shmBuffer.data()) texData = shmBuffer; else texData = {texture->m_vSize.x * 4 * texture->m_vSize.y, 0}; + + if (flipRB) { + for (size_t i = 0; i < shmBuffer.size(); i += 4) { + std::swap(shmBuffer.at(i), shmBuffer.at(i + 2)); // little-endian!!!!!! + } + } } else { Debug::log(TRACE, "Cannot use dumb copy on dmabuf cursor buffers"); return nullptr; diff --git a/src/render/Texture.cpp b/src/render/Texture.cpp index 4231dc17..633f0212 100644 --- a/src/render/Texture.cpp +++ b/src/render/Texture.cpp @@ -17,7 +17,7 @@ CTexture::~CTexture() { destroyTexture(); } -CTexture::CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size_, bool keepDataCopy) : m_bKeepDataCopy(keepDataCopy) { +CTexture::CTexture(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size_, bool keepDataCopy) : m_iDrmFormat(drmFormat), m_bKeepDataCopy(keepDataCopy) { createFromShm(drmFormat, pixels, stride, size_); } @@ -44,6 +44,8 @@ CTexture::CTexture(const SP buffer, bool keepDataCopy) : m_ auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0); + m_iDrmFormat = fmt; + createFromShm(fmt, pixelData, bufLen, shm.size); return; } diff --git a/src/render/Texture.hpp b/src/render/Texture.hpp index 8b98e2a0..f814e06b 100644 --- a/src/render/Texture.hpp +++ b/src/render/Texture.hpp @@ -43,6 +43,7 @@ class CTexture { void* m_pEglImage = nullptr; eTransform m_eTransform = HYPRUTILS_TRANSFORM_NORMAL; bool m_bOpaque = false; + uint32_t m_iDrmFormat = DRM_FORMAT_INVALID; // for shm private: void createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size);