How is CAShapeLayer implemented

Hello,

I want to create a painting app for iOS and I saw many examples use a CAShapeLayer to draw a UIBezierPath.

As I understand CoreAnimation uses the GPU so I was wondering how is this implemented on the GPU? Or in other words, how would you do it with Metal or OpenGL?

I can only think of continuously updating a texture in response to the user's drawing but that would be a very resource intensive operation...

Thanks

Answered by DTS Engineer in 803807022

We're unable to validate any assumptions about Core Animation implementation, particularly based on third party citations, but we are able to offer you sample code showing how you might implement your own solution on the GPU.

For examples of rendering parametric curves with Metal you'll want to check out the following:

These samples run on the Simulator. You would need to adapt input for iOS.

A simpler "stamping" approach using Core Image and OpenGL (iOS and macOS) can be found here:

The only alternative to updating a texture as the user paints would be to render all paint strokes on each frame. Either way this is a resource intensive operation, and optimizing your data structures and your renderer will be a critical part of your development process.

Accepted Answer

As I understand CoreAnimation uses the GPU so I was wondering how is this implemented on the GPU? Or in other words, how would you do it with Metal or OpenGL?

My assumption has always been that it uses this sort of approach:

https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-25-rendering-vector-art-gpu

But of course Apple don't tell us how it works, so if you care about how it is done you should implement it yourself.

We're unable to validate any assumptions about Core Animation implementation, particularly based on third party citations, but we are able to offer you sample code showing how you might implement your own solution on the GPU.

For examples of rendering parametric curves with Metal you'll want to check out the following:

These samples run on the Simulator. You would need to adapt input for iOS.

A simpler "stamping" approach using Core Image and OpenGL (iOS and macOS) can be found here:

How is CAShapeLayer implemented
 
 
Q