Re: Throttling drawing to vertical refresh
Re: Throttling drawing to vertical refresh
- Subject: Re: Throttling drawing to vertical refresh
- From: David Duncan via Cocoa-dev <email@hidden>
- Date: Fri, 23 Oct 2020 09:47:06 -0700
> On Oct 23, 2020, at 8:54 AM, Andreas Falkenhahn <email@hidden>
> 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
>> <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden