Layer-backed NSView performance with rendering directly in CALayer.drawInContext:

倖福魔咒の 提交于 2019-12-07 06:03:04

问题


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.

来源:https://stackoverflow.com/questions/29109137/layer-backed-nsview-performance-with-rendering-directly-in-calayer-drawincontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!