seedante/OptimizationForOffscreenRender

Question about mask & rasterize

Closed this issue · 7 comments

xilin commented
  1. What's the best way to do mask if the background is a image so that we cannot use blended way? Is there some background thread way to set it?
  2. Could you explain more detail about rasterize? I'm not quite sure about when to use it. Can I say I should set rasterize to YES only when the cell's layout/size/subviews will no change? For example, if I have a cell showing image and the cell's size is changing based on the size of image, may I set it to YES?

Thanks.

  1. Why cannot use blend way in this situation? Blend way just add a view upon view which need to be mask.
  2. About rasterization: https://developer.apple.com/videos/play/wwdc2014/419/. Any improvement to performance need to measure, why not try?

为什么不看 README 里留下的博客呢?

xilin commented

是先拜读了博客才提问的哈。
追问一下:

  1. 我的意思是如果背景图是一张非纯色的图片,blend就不好做了吧?文中有提到blend的遮挡部分应该和背景同色?
  2. 教育的是,我去做点实验验证一下。谢谢!

你说的这样情况很少见啊,如果真是这样,Blend 的方式是不合适。「文中有提到blend的遮挡部分应该和背景同色?」这张图应该够解释了。

xilin commented

我没表述清楚。。我是看到了文中说应该同色所以才觉得blend不能用只能用mask。

应用场景是聊天界面,聊天背景用户是可以自定义的,聊天内容是图片的时候需要用气泡做一次mask。

@xilin 说到具体的场景就好办了,不然我只能脑补,说应用场景少然后被打脸。聊天界面+自定义背景这种场景,我没写过,也不便花时间去查看用什么方案来写,粗略分析一下,先不说聊天内容尺寸不一导致 Blend 方式太麻烦,从效果来讲,Blend 方式比较适合能与周围环境颜色融为一体的效果,不然就格格不入了,聊天界面+自定义场景确实不适合。如果你用 mask 的话,mask + CAShapeLayer 应该是比较合适的方法,需要针对每次的聊天内容来计算路径,要优化的话,mask 的选择少,还是 rasterization 比较好,虽然说要看 GPU Driver 的数据,就我对 Rasterization 的测试来看,即使针对动态内容的视图,优化效果也是比较给力的,不过计算 CAShapeLayer 的路径可能会对 CPU 造成较大压力,具体只能看数据了。我没有写聊天界面的经验,仅作参考,也许有专业的解决方案,我好像 star 过一个开源的框架。

还有关于 Rasterization,之前 objc.io 的那篇文章我看了几次,那个 WWDC 的视频也看过几次,我还是不怎么懂这个方案。你动手把这个 demo 运行一下,然后 GPU Driver + Core Animation Instrument 开启「Color Hits Green and Misses Red」来查看 rasterization 的效果,你会理解这个方案到底是怎么回事。光看是理解不了的,至少我是这样。

xilin commented

感谢这么详细的回复!
我这几天再好好看看材料再动手实验下。
有结果了再来汇报哈!