What's the magic behind CAReplicatorLayer?

2019-03-15 00:22发布

What I find interesting with CAReplicatorLayer:

  • It is able to display a CALayer multiple times with different transforms very efficiently (how?)
  • It seems like it somehow reuses the "backing store" for the replicated layer and even apply some color tints to it (how?)

I would like to get hands on either the source code or get some knowledge of the magic behind CAReplicatorLayer. I would like to have a CALayer class similar to CAReplicatorLayer, but with more control. I would like to have control on the transform individually for each replicated instance.

So asked in a totally different manner: is it possible to get the "backing store" for a CALayer and display it however I want as many times I want?

(by "backing store" I mean the rendered texture for the CALayer/UIView. I don't know much about what's happening under the hoods of CoreAnimation/QuartzCore).


Why I'm not looking at alternatives like e.g. rendering the CALayer to a UIImage:

  • Performance
  • Content is dynamic/changing pretty frequently under the transitions
  • It would be hands down awesome to do it the other way!

1条回答
beautiful°
2楼-- · 2019-03-15 00:51

The special-purpose CALayers like CAReplicatorLayer or CAGradientLayer are able (via private APIs) do execute their drawing directly on the GPU using fast filling or copying. In a sense they are different such that the backing store is not in normal RAM, but directly on the GPU.

查看更多
登录 后发表回答