Saurabh 😎

WWDC 2010: Core Animation in Practice, Part 2

New and Overlooked APIs

Drop shadows - shadowOpacity, shadowRadius, shadowOffset
shadowPath was necessary for bringing drop shadows to iPhone (was originally only on Mac) since it lets the compositor cache a shadow bitmap, otherwise would have to recompute shadow on every frame

CAShapeLayer - more efficient than drawing into bitmap

Performance tradeoffs of CAShapeLayer:

Overall, best for a few semi-large elements - won't work with 1000s of them (CPU will be bottleneck)

Bitmap caching - motivated by larger resolution of iPad

Caveats to bitmap caching:

Cubic keyframes - kCAAnimationCubic
Uses Catmull-Rom spline

Key takeaways:

Mental model of performance

At high-level, GPU converts triangles to pixels

How does Core Animation use GPU?

GPU performance model:

Too much non-opaque content => limited by write bandwidth
Too many large images => limited by read bandwidth
Too many masked layers => limited by rendering passes

General performance methodology:
Measure fps
If fps < 60, then eliminate render passes, reduce read bandwidth, reduce write bandwidth (in that order)
Repeat until 60 fps

High-DPI

2x scale factor applied to root of UIWindow layer tree

When rasterizing, use layer.rasterizationScale = 2

contentsScale layer property - scaling factor between layer geometry and screen geometry

For precise native pixel layout, add 0.5x scale layer