How do you run Core Animation and Core Image toget

2019-07-14 21:32发布

Apple's Core Image Programming Guide, under the section "Getting the Best Performance" says

Avoid Core Animation animations while rendering CIImage objects with a GPU context.

If you need to use both simultaneously, you can set up both to use the CPU.

Can anyone explain this statement? Why it would be more efficient to run Core Animation and Core Image together on the CPU, rather than using the GPU?

How do you set up Core Animation to run on the CPU?

2条回答
戒情不戒烟
2楼-- · 2019-07-14 21:34

I had the same question and came across this WWDC 2013 session 509 comment, http://asciiwwdc.com/2013/sessions/509 :

"And also be aware that both Core Animation and Core Image both make extensive use of the GPU.

So if you want your Core Animations to be smooth, you want to either stagger your Core Image operations or use a CPU CIContext so that they don't put pressure on the GPU at the same time."

查看更多
走好不送
3楼-- · 2019-07-14 21:36

My guess they don't work simultaneously on GPU is they are both running on main thread when rendering on GPU, which will cause unpredicted problem and performance overhead, as for why they should both using CPU, should be to keep 'simultaneously'.

Since core graphics drawing is on CPU, you can draw the animation in drawRect and call setNeesDisplay periodically to performa animation on CPU.

查看更多
登录 后发表回答