UIView's drawRect called with 16 bit pixel format on Wide Color ignoring contentsFormat. Workaround by stubbing out layerWillDraw

Originator:bridgeyman
Number:rdar://32702889 Date Originated:June 11, 2017
Status:Open Resolved:
Product:iOS Product Version:11?
Classification: Reproducible:Always
 
I'm trying to create CGBitmapContexts which match the pixel format of the CGContext in UIView's drawView. I tried to force them to be 8 bit on Wide Color devices by using self.layer.contentsFormat, but that setting is ignored. In fact, it incorrectly reports "RGBA8" when queried on a Wide Color device even though the context in drawView is reports 16 bits per component.

There is a bizarre workaround. By simply implementing an empty implementation of layerWillDraw(_ layer: CALayer) then the context will receive an 8 bit backed context on Wide Color devices.

Set the contentsFormat of a view's layer on a Wide Color device. Observe that within drawView, "UIGraphicsGetCurrentContext().bitsPerComponent" will return 16 no matter what the layer's contentsFormat is set to.

Now, add an empty implementation of layerWillDraw(_ layer: CALayer). Even on a Wide Color device now when drawView is called "UIGraphicsGetCurrentContext().bitsPerComponent" will return 8.

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!