diff --git a/plugins/platforms/fbdev/fb_backend.h b/plugins/platforms/fbdev/fb_backend.h --- a/plugins/platforms/fbdev/fb_backend.h +++ b/plugins/platforms/fbdev/fb_backend.h @@ -71,10 +71,17 @@ return m_bitsPerPixel; } QImage::Format imageFormat() const; + /** + * @returns whether the imageFormat is BGR instead of RGB. + **/ + bool isBGR() const { + return m_bgr; + } private: void openFrameBuffer(); bool queryScreenInfo(); + void initImageFormat(); QSize m_resolution; QSize m_physicalSize; QByteArray m_id; @@ -91,6 +98,8 @@ quint32 m_bufferLength = 0; int m_bytesPerLine = 0; void *m_memory = nullptr; + QImage::Format m_imageFormat = QImage::Format_Invalid; + bool m_bgr = false; }; } diff --git a/plugins/platforms/fbdev/fb_backend.cpp b/plugins/platforms/fbdev/fb_backend.cpp --- a/plugins/platforms/fbdev/fb_backend.cpp +++ b/plugins/platforms/fbdev/fb_backend.cpp @@ -92,6 +92,7 @@ } m_fd = fd; queryScreenInfo(); + initImageFormat(); setReady(true); emit screensQueried(); } @@ -154,8 +155,13 @@ QImage::Format FramebufferBackend::imageFormat() const { + return m_imageFormat; +} + +void FramebufferBackend::initImageFormat() +{ if (m_fd < 0) { - return QImage::Format_Invalid; + return; } qCDebug(KWIN_FB) << "Bits Per Pixel: " << m_bitsPerPixel; @@ -178,28 +184,28 @@ m_green.offset == 8 && m_red.offset == 16) { qCDebug(KWIN_FB) << "Framebuffer format is RGB32"; - return QImage::Format_RGB32; + m_imageFormat = QImage::Format_RGB32; } else if (m_bitsPerPixel == 24 && m_red.length == 8 && m_green.length == 8 && m_blue.length == 8 && m_blue.offset == 0 && m_green.offset == 8 && m_red.offset == 16) { qCDebug(KWIN_FB) << "Framebuffer Format is RGB888"; - return QImage::Format_RGB888; + m_bgr = true; + m_imageFormat = QImage::Format_RGB888; } else if (m_bitsPerPixel == 16 && m_red.length == 5 && m_green.length == 6 && m_blue.length == 5 && m_blue.offset == 0 && m_green.offset == 5 && m_red.offset == 11) { qCDebug(KWIN_FB) << "Framebuffer Format is RGB16"; - return QImage::Format_RGB16; + m_imageFormat = QImage::Format_RGB16; } qCWarning(KWIN_FB) << "Framebuffer format is unknown"; - return QImage::Format_Invalid; } } diff --git a/plugins/platforms/fbdev/scene_qpainter_fb_backend.cpp b/plugins/platforms/fbdev/scene_qpainter_fb_backend.cpp --- a/plugins/platforms/fbdev/scene_qpainter_fb_backend.cpp +++ b/plugins/platforms/fbdev/scene_qpainter_fb_backend.cpp @@ -79,7 +79,7 @@ return; } QPainter p(&m_backBuffer); - p.drawImage(QPoint(0, 0), m_renderBuffer); + p.drawImage(QPoint(0, 0), m_backend->isBGR() ? m_renderBuffer.rgbSwapped() : m_renderBuffer); } bool FramebufferQPainterBackend::usesOverlayWindow() const