summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-12-14 17:48:57 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-01-25 17:21:54 +0100
commitfdc7eb80dd5753bc1fc145dc9bd0689cd65e251d (patch)
treef8f80675b1187cb899c2bab90f3d53f950ca9108 /src/plugins
parent4e2a94236998cd05753167953d9167793baf9942 (diff)
Add QPlatformScreen::colorSpace()
Added for macOS and X11 screens Task-number: QTBUG-90535 Change-Id: Ifafe7a07ee2abc3c42cd12785db2d7329878375b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoascreen.h2
-rw-r--r--src/plugins/platforms/cocoa/qcocoascreen.mm5
-rw-r--r--src/plugins/platforms/xcb/qxcbatom.cpp1
-rw-r--r--src/plugins/platforms/xcb/qxcbatom.h2
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.cpp34
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.h2
6 files changed, 46 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h
index ffbb67b677..b109c24f63 100644
--- a/src/plugins/platforms/cocoa/qcocoascreen.h
+++ b/src/plugins/platforms/cocoa/qcocoascreen.h
@@ -66,6 +66,7 @@ public:
QRect availableGeometry() const override { return m_availableGeometry; }
int depth() const override { return m_depth; }
QImage::Format format() const override { return m_format; }
+ QColorSpace colorSpace() const override { return m_colorSpace; }
qreal devicePixelRatio() const override { return m_devicePixelRatio; }
QSizeF physicalSize() const override { return m_physicalSize; }
QDpi logicalDpi() const override { return m_logicalDpi; }
@@ -122,6 +123,7 @@ private:
int m_depth = 0;
QString m_name;
QImage::Format m_format;
+ QColorSpace m_colorSpace;
QSizeF m_physicalSize;
QCocoaCursor *m_cursor;
qreal m_devicePixelRatio = 0;
diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm
index 70d02d1a0d..77de751102 100644
--- a/src/plugins/platforms/cocoa/qcocoascreen.mm
+++ b/src/plugins/platforms/cocoa/qcocoascreen.mm
@@ -330,6 +330,11 @@ void QCocoaScreen::update(CGDirectDisplayID displayId)
m_format = QImage::Format_RGB32;
m_depth = NSBitsPerPixelFromDepth(nsScreen.depth);
+ m_colorSpace = QColorSpace::fromIccProfile(QByteArray::fromNSData(nsScreen.colorSpace.ICCProfileData));
+ if (!m_colorSpace.isValid()) {
+ qWarning() << "macOS generated a color-profile Qt couldn't parse. This shouldn't happen.";
+ m_colorSpace = QColorSpace::SRgb;
+ }
CGSize size = CGDisplayScreenSize(m_displayId);
m_physicalSize = QSizeF(size.width, size.height);
diff --git a/src/plugins/platforms/xcb/qxcbatom.cpp b/src/plugins/platforms/xcb/qxcbatom.cpp
index 780816605a..60da23cfac 100644
--- a/src/plugins/platforms/xcb/qxcbatom.cpp
+++ b/src/plugins/platforms/xcb/qxcbatom.cpp
@@ -234,6 +234,7 @@ static const char *xcb_atomnames = {
"EDID\0"
"EDID_DATA\0"
"XFree86_DDC_EDID1_RAWDATA\0"
+ "_ICC_PROFILE\0"
// \0\0 terminates loop.
};
diff --git a/src/plugins/platforms/xcb/qxcbatom.h b/src/plugins/platforms/xcb/qxcbatom.h
index 9cf93ec314..c9e5c0fd25 100644
--- a/src/plugins/platforms/xcb/qxcbatom.h
+++ b/src/plugins/platforms/xcb/qxcbatom.h
@@ -240,6 +240,8 @@ public:
EDID_DATA,
XFree86_DDC_EDID1_RAWDATA,
+ _ICC_PROFILE,
+
NAtoms
};
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
index 9f20df9b35..3c57ffc7b0 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.cpp
+++ b/src/plugins/platforms/xcb/qxcbscreen.cpp
@@ -547,6 +547,17 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDe
m_cursor = new QXcbCursor(connection, this);
+ {
+ // Read colord ICC data (from GNOME settings)
+ auto reply = Q_XCB_REPLY_UNCHECKED(xcb_get_property, xcb_connection(),
+ false, screen()->root,
+ connection->atom(QXcbAtom::_ICC_PROFILE),
+ XCB_ATOM_CARDINAL, 0, 8192);
+ if (reply->format == 8 && reply->type == XCB_ATOM_CARDINAL) {
+ QByteArray data(reinterpret_cast<const char *>(xcb_get_property_value(reply.get())), reply->value_len);
+ m_colorSpace = QColorSpace::fromIccProfile(data);
+ }
+ }
if (connection->hasXRandr()) { // Parse EDID
QByteArray edid = getEdid();
if (m_edid.parse(edid)) {
@@ -558,6 +569,27 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDe
m_edid.model.toLatin1().constData(),
m_edid.serialNumber.toLatin1().constData(),
m_edid.physicalSize.width(), m_edid.physicalSize.height());
+ if (!m_colorSpace.isValid()) {
+ if (m_edid.sRgb)
+ m_colorSpace = QColorSpace::SRgb;
+ else {
+ if (!m_edid.useTables) {
+ m_colorSpace = QColorSpace(m_edid.whiteChromaticity, m_edid.redChromaticity,
+ m_edid.greenChromaticity, m_edid.blueChromaticity,
+ QColorSpace::TransferFunction::Gamma, m_edid.gamma);
+ } else {
+ if (m_edid.tables.length() == 1) {
+ m_colorSpace = QColorSpace(m_edid.whiteChromaticity, m_edid.redChromaticity,
+ m_edid.greenChromaticity, m_edid.blueChromaticity,
+ m_edid.tables[0]);
+ } else if (m_edid.tables.length() == 3) {
+ m_colorSpace = QColorSpace(m_edid.whiteChromaticity, m_edid.redChromaticity,
+ m_edid.greenChromaticity, m_edid.blueChromaticity,
+ m_edid.tables[0], m_edid.tables[1], m_edid.tables[2]);
+ }
+ }
+ }
+ }
} else {
// This property is defined by the xrandr spec. Parsing failure indicates a valid error,
// but keep this as debug, for details see 4f515815efc318ddc909a0399b71b8a684962f38.
@@ -565,6 +597,8 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDe
"edid data: " << edid;
}
}
+ if (!m_colorSpace.isValid())
+ m_colorSpace = QColorSpace::SRgb;
}
QXcbScreen::~QXcbScreen()
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
index aabf227a09..9ca68d1eca 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
@@ -160,6 +160,7 @@ public:
QRect availableGeometry() const override;
int depth() const override { return screen()->root_depth; }
QImage::Format format() const override;
+ QColorSpace colorSpace() const override { return m_colorSpace; }
QSizeF physicalSize() const override { return m_sizeMillimeters; }
QDpi logicalDpi() const override;
QDpi logicalBaseDpi() const override { return QDpi(96, 96); }
@@ -226,6 +227,7 @@ private:
QSizeF m_sizeMillimeters;
QRect m_geometry;
QRect m_availableGeometry;
+ QColorSpace m_colorSpace;
Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation;
QXcbCursor *m_cursor;
qreal m_refreshRate = 60.0;