In my iPad app, I am rendering to an offscreen bitmap, and then drawing the bitmap to the screen. (This is because I want to re-use existing bitmap rendering code.) On the iPad 2, this works like a charm, but on the new iPad with Retina display, drawing the bitmap is really slow, even though its resolution is still the same.
To draw the bitmap, we use the regular Quartz 2D functions: CGImageCreate with a data provider created by CGDataProviderCreateWithData, 32-bit RGBA format with kCGImageAlphaNoneSkipLast. In the UIView that displays the bitmap, in drawRect:, we use CGContextDrawImage to draw it to the context returned by UIGraphicsGetCurrentContext.
Note that I’m not even trying to draw at double resolution: for now I’m fine with the same resolution as I was using on the iPad 2. It looks like CoreGraphics is internally doubling the pixels, and then sending that to the GPU, even though the CGImage that I’m making should be fine for passing to the GPU directly. Any ideas?
Pretty much. More accurately (in spirit at least):
CGBitmapContextthe size of your view’s bounds, in device pixelsCGImageinto that contextCGImagefrom the bitmap contextIf you want that to happen, you need to tell the system to do that, by cutting out some of the steps above.
(There is no link between UIKit, CoreAnimation, and CoreGraphics that provides a “fast path” like you are expecting.)
The easiest way would be to make a
UIImageView, and set itsimageto aUIImagewrapping yourCGImageRef.Or, set your
view.layer.contentsto yourCGImageRef. (And make sure to not override-drawRect:, not call-setNeedsDisplay, and make surecontentModeis notUIViewContentModeRedraw. Easier to just useUIImageView.)