Re: Request for guidance re. CALayer
Re: Request for guidance re. CALayer
- Subject: Re: Request for guidance re. CALayer
- From: Graham Cox <email@hidden>
- Date: Thu, 08 Jan 2015 10:04:24 +1100
> On 8 Jan 2015, at 2:02 am, Luc Van Bogaert <email@hidden> wrote:
>
> I also have implemented a custom view class CanvasView representing the app’s drawing canvas. I realise I could do all the drawing using this view’s drawRect: method. But somehow I keep having this feeling that I should pursue the usage of CALayer objects, possibly using them to form a composite object as part of my Layer class. What I have been trying to do so far is adding a CALayer property to my Layer class, so I can add a real CALayer object as a sublayer in my custom CanvasView reating a one-on-one relation between my Layers (that would contain the graphics data) and real CALayer objects (to display the graphics). I have assigned the Layer object as the CALayer object’s delegate…
> I’m exactly not sure why, but to me this seems to be a good strategy for performance considerations and possibly offering other advantages later on...
>
> However, I am not at all sure if this is the best route to take, so I would welcome any help or recommendations on this.
>
Is your drawing app for vector drawing?
If so, I've found CALayer a poor fit for vector objects, as it's essentially a pixel-pushing technology. It's very hard to scale a view and have CALayers draw without pixelisation, and even using CAShapeLayer, which appears to be designed to capture vector drawing, doesn't scale up well. I ran into severe limitations with these layers exceeding hard OpenGL limits when zooming in, though of course there's always the possibility I was Doing It Wrong™.
A more fruitful approach might be to use CATileLayers to break your canvas up into tileable regions which will improve rendering performance by eliminating unneeded drawing when zooming in, much like the Maps app. It's a good idea to design the entry point into drawing your canvas with this in mind by allowing it to render to an arbitrary CGContext rather than assuming that it's drawing in a view. Then it's easy to adapt to rendering to a layer or view with trivial changes to your drawing code.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden