From 886d6366d23456d16edc87da44f92342331d4cd2 Mon Sep 17 00:00:00 2001
From: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
Date: Tue, 29 Jan 2019 15:39:43 -0800
Subject: [PATCH] egl_kms: Modify the default color format to RGB565

DP supports RGB565 hence modify the default color format to RGB565.

Signed-off-by: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
Upstream-Status: Inappropriate [Xilinx specific]
---
 src/platformsupport/kmsconvenience/qkmsdevice.cpp        |  4 ++--
 .../deviceintegration/eglfs_kms/qeglfskmsgbmcursor.cpp   |  6 +++---
 .../eglfs_kms/qeglfskmsgbmintegration.cpp                |  2 +-
 .../eglfs_kms_support/qeglfskmsintegration.cpp           | 16 +++++++++++++---
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/platformsupport/kmsconvenience/qkmsdevice.cpp b/src/platformsupport/kmsconvenience/qkmsdevice.cpp
index a589555..585c078 100644
--- a/src/platformsupport/kmsconvenience/qkmsdevice.cpp
+++ b/src/platformsupport/kmsconvenience/qkmsdevice.cpp
@@ -334,7 +334,7 @@ QPlatformScreen *QKmsDevice::createScreenForConnector(drmModeResPtr resources,
     }
     qCDebug(qLcKmsDebug) << "Physical size is" << physSize << "mm" << "for output" << connectorName;
 
-    const QByteArray formatStr = userConnectorConfig.value(QStringLiteral("format"), QStringLiteral("xrgb8888"))
+    const QByteArray formatStr = userConnectorConfig.value(QStringLiteral("format"), QStringLiteral("rgb565"))
             .toByteArray().toLower();
     uint32_t drmFormat;
     if (formatStr == "xrgb8888") {
@@ -359,7 +359,7 @@ QPlatformScreen *QKmsDevice::createScreenForConnector(drmModeResPtr resources,
         drmFormat = DRM_FORMAT_ABGR2101010;
     } else {
         qWarning("Invalid pixel format \"%s\" for output %s", formatStr.constData(), connectorName.constData());
-        drmFormat = DRM_FORMAT_XRGB8888;
+        drmFormat = DRM_FORMAT_RGB565;
     }
 
     const QString cloneSource = userConnectorConfig.value(QStringLiteral("clones")).toString();
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.cpp
index 4d0cf0c..842cf53 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.cpp
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.cpp
@@ -87,7 +87,7 @@ QEglFSKmsGbmCursor::QEglFSKmsGbmCursor(QEglFSKmsGbmScreen *screen)
     }
 
     m_bo = gbm_bo_create(static_cast<QEglFSKmsGbmDevice *>(m_screen->device())->gbmDevice(), m_cursorSize.width(), m_cursorSize.height(),
-                         GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE);
+			 DRM_FORMAT_RGB565, GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE);
     if (!m_bo) {
         qWarning("Could not create buffer for cursor!");
     } else {
@@ -197,7 +197,7 @@ void QEglFSKmsGbmCursor::changeCursor(QCursor *windowCursor, QWindow *window)
     if (m_cursorImage.image()->width() > m_cursorSize.width() || m_cursorImage.image()->height() > m_cursorSize.height())
         qWarning("Cursor larger than %dx%d, cursor will be clipped.", m_cursorSize.width(), m_cursorSize.height());
 
-    QImage cursorImage(m_cursorSize, QImage::Format_ARGB32);
+    QImage cursorImage(m_cursorSize, QImage::Format_RGB16);
     cursorImage.fill(Qt::transparent);
 
     QPainter painter;
@@ -282,7 +282,7 @@ void QEglFSKmsGbmCursor::initCursorAtlas()
         m_cursorAtlas.hotSpots << hotSpot;
     }
 
-    QImage image = QImage(atlas).convertToFormat(QImage::Format_ARGB32);
+    QImage image = QImage(atlas).convertToFormat(QImage::Format_RGB16);
     m_cursorAtlas.cursorWidth = image.width() / m_cursorAtlas.cursorsPerRow;
     m_cursorAtlas.cursorHeight = image.height() / ((Qt::LastCursor + cursorsPerRow) / cursorsPerRow);
     m_cursorAtlas.width = image.width();
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp
index 4023381..6f4805b 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp
@@ -99,7 +99,7 @@ EGLNativeWindowType QEglFSKmsGbmIntegration::createNativeOffscreenWindow(const Q
 
     gbm_surface *surface = gbm_surface_create(static_cast<QEglFSKmsGbmDevice *>(device())->gbmDevice(),
                                               1, 1,
-                                              GBM_FORMAT_XRGB8888,
+                                              DRM_FORMAT_RGB565,
                                               GBM_BO_USE_RENDERING);
 
     return reinterpret_cast<EGLNativeWindowType>(surface);
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp
index 06bc272..415a3aa 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp
@@ -102,9 +102,19 @@ QSurfaceFormat QEglFSKmsIntegration::surfaceFormatFor(const QSurfaceFormat &inpu
     QSurfaceFormat format(inputFormat);
     format.setRenderableType(QSurfaceFormat::OpenGLES);
     format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
-    format.setRedBufferSize(8);
-    format.setGreenBufferSize(8);
-    format.setBlueBufferSize(8);
+
+    static const bool force888 = qEnvironmentVariableIntValue("QT_QPA_EGLFS_FORCE888");
+    if (force888){
+        format.setRedBufferSize(8);
+        format.setGreenBufferSize(8);
+        format.setBlueBufferSize(8);
+    }
+    else{
+        format.setRedBufferSize(5);
+        format.setGreenBufferSize(6);
+        format.setBlueBufferSize(5);
+    }
+
     return format;
 }
 
-- 
2.7.4

