> On Oct 23, 2020, at 8:54 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> Thanks, but once again, I still need a throttle because I obviously don't 
> want to call -setNeedsDisplay as often as the CPU permits, thereby causing 
> 100% CPU load. I still need some timer mechanism that only calls 
> -setNeedsDisplay every once in a while. So should I setup a timer based on 
> the monitor's refresh frequency rate that calls -setNeedsDisplay in intervals 
> of the monitor's vertical refresh rate or how is that supposed to be 
> implemented?
> 
> On 19.10.2020 at 01:22 David Duncan wrote:
> 
>> On Oct 18, 2020, at 2:37 AM, Andreas Falkenhahn via Cocoa-dev
>> <cocoa-dev@lists.apple.com> wrote:
> 
>> Not quite. AppKit throttle view refresh to 60fps but it certainly
>> won't throttle code that changes the gfx more often than that, i.e. 
>> something like this
> 
>>   for(;;) view.layer.contents = (id) getNextFrame();
> 
>> will hog the CPU. So I need some external timing mechanism to set
>> layer.contents not more often than necessary. I need to see if CADisplayLink 
>> can do that…
> 

It isn’t likely that code like "for(;;) view.layer.contents = (id) 
getNextFrame()” will actually work in a typical GUI based application. In 
particular, this setup prevents Core Animation from doing its “commit” phase, 
and so nothing will appear on screen (or if it does, it will appear by side 
effect, such as by doing this on a background thread and the main thread going 
a commit at effectively random intervals relative to this).

So yes, you should run a timer. But at the same time I would expect your code 
to know what the appropriate timing for calling “getNextFrame()” should be. If 
that method can literally be called at any time to generate a newly advanced 
frame, then just pick an upper limit and call -setNeedsDisplay as mentioned 
previously. This will allow you to effectively match what the built in commit 
logic can handle.

If you have precise timing needs, you can use a CVDisplayLink[Ref] to manage 
the timing. If you don’t, a simple NSTimer running at some target frequency 
should be plenty.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to