What's the magic behind CAReplicatorLayer?
Asked Answered
L

1

19

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!
Loris answered 12/12, 2012 at 14:1 Comment(1)
Been wondering this myself. Hope someone smarter than us comes along haha.Prolongation
P
10

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.

Pacificas answered 13/12, 2012 at 6:12 Comment(3)
Thanks for the response. That does not sound promising for what I was hoping to do, but indeed clarifies some aspects. :)Loris
you can always use an EAGLLayer and draw on that with OpenGL with shaders. This would be the fasted way to do custom drawing.Pacificas
I suppose I can't do that backed by UIViews? Or in my case: I'm doing something as bold as replicating a UIWebView. I would very much like something similar to CAReplicatorLayer, but with control over each individual instance' transform (instead of the incremental one CAReplicatorLayer offers). If OpenGL/EAGLLayer offers that I would be more than happy.Loris

© 2022 - 2024 — McMap. All rights reserved.