UIView snapshot rendering should support wide gamut on Simulator

Originator:argentumko
Number:rdar://45031324 Date Originated:October 5, 2018
Status:Open Resolved:
Product:UIKit Product Version:iOS 10+
Classification:UI/Usability Reproducible:Always
 
Summary:
When using UIView's drawViewHierarchyInRect:afterScreenUpdates: method to render a view's snapshot, calling it on Simulator always produces a standard-gamut image, even when simulating a device with Display P3 screen and rendering into a context with wide-gamut (Extended sRGB or Display P3) color space. This may be confusing during development of apps that manipulate wide-gamut content and use snapshotting.
On physical devices this method produces expected results.

Steps to Reproduce:
1. Make a simple app that renders wide-gamut content in a certain view.
2. Setup a UIGraphicsImageRenderer with preferred extended range, and call drawViewHierarchyInRect:afterScreenUpdates: method on the view with wide-gamut content in the actions block.
3. Run this app in an iPhone X Simulator (or other simulated device with Device P3 screen). Compare the resulting snapshot image with the original content (either inside the app, or by exporting the snapshot into a PNG file).

Expected Results:
Snapshot is identical to the original content. Minor color conversion errors are normal.

Actual Results:
Even though the snapshot is made into a wide-gamut context, its contents are clipped to standard sRGB, which is noticeable by comparing to the original.

Version/Build:
iOS 10+

Configuration:
iPhone X Simulator, or any other simulated device with P3 screen

Additional Info:
It seems like this limitation extends to the Simulator itself: even when running on a modern MacBook Pro with wide-gamut display, Simulator app presents the wide-gamut content clipped to standard sRGB. And looks like UIKit's private _UIRenderingBufferCreateCGImage function specifically uses Device RGB color space and 8 bits per component when interpreting the render server buffer contents on Simulator, but on device it preserves the color space specified via IOSurface. So looks like this problem extends beyond just UIKit.

The attached sample project demonstrates the issue: it renders a difference between the original wide-gamut image and the snapshot, which is noticeable when running in e.g. iPhone X Simulator.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!