Layer-backed NSView performance with rendering dir

2019-04-30 12:52发布

I have many layer-backed views contained in a NSScrollview and am predominantly concerned with scrolling performance. The documentView and higher are layer-backed hence their subviews are also layer-backed.

The following are the three natural places that display/rendering code could go:

  1. override NSView.wantsUpdateLayer to return false (or don't do anything because this is the default) & do drawing in NSView's drawRect method
  2. override NSView.wantsUpdateLayer to return true & do drawing in NSView's updateLayer method
  3. do NO drawing in NSView at all & perform all drawing in CALayer's drawInContext method

From the WWDC 2013 Session 215 talk it was stated that (2) is more performant than (1) because the view then doesn't need to create a temporary store for the drawRect output. Firstly, I don't have 100% clarity on when "backing stores" are made and when not and Secondly how do (2) and (3) compare and when might you use one over the other?

In particular, I have to draw text into my view. How would I go about doing that in the updateLayer call? The only examples of drawing text seem to need to get hold of a context - which isn't naturally available in updateLayer.

0条回答
登录 后发表回答