iOS: Respect QSurfaceFormat::colorSpace() when using Metal

Unlike on macOS, there's no colorSpace property on UIWindow or UIView,
but CAMetalLayer has one, which allows us to tell Core Animation that
the layer targets a specific color space, and Core Animation will then
do the rest of the color matching to the target display.

Now that we use Metal to flush raster content, this is even more useful.

Task-number: QTBUG-108094
Pick-to: 6.5
Change-Id: Ib04b42d9baa296b608983db38faf0398430db093
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-02-28 16:25:42 +01:00
parent d57ff481fc
commit e7d038c027

View File

@ -108,6 +108,17 @@ inline ulong getTimeStamp(UIEvent *event)
m_lastScrollDelta = CGPointZero;
m_lastScrollCursorPos = CGPointZero;
[self addGestureRecognizer:m_scrollGestureRecognizer];
if ([self.layer isKindOfClass:CAMetalLayer.class]) {
QWindow *window = self.platformWindow->window();
if (QColorSpace colorSpace = window->format().colorSpace(); colorSpace.isValid()) {
QCFType<CFDataRef> iccData = colorSpace.iccProfile().toCFData();
QCFType<CGColorSpaceRef> cgColorSpace = CGColorSpaceCreateWithICCData(iccData);
CAMetalLayer *metalLayer = static_cast<CAMetalLayer *>(self.layer);
metalLayer.colorspace = cgColorSpace;
qCDebug(lcQpaWindow) << "Set" << self << "color space to" << metalLayer.colorspace;
}
}
}
return self;