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... > Instead of directly setting layer contents, call -setNeedsDisplay > and set contents in either an override of -[CALayer display] or in > the delegate’s -displayLayer: callout. This should have you only > update once per commit cycle (which is typically coordinated with the refresh > rate). > On 16.10.2020 at 00:48 Graham Cox wrote: > Appkit already throttles view refreshes to 60fps. There’s nothing you need to > do. > —Graham > On 16 Oct 2020, at 6:13 am, Andreas Falkenhahn via Cocoa-dev > <cocoa-dev@lists.apple.com> wrote: > I'm drawing inside an NSView by simply setting its layer's contents > to a CGImage which is updated for every frame, e.g. something like this: > dp = CGDataProviderCreateWithData(NULL, frameBuf, frameBufSize, NULL); > im = CGImageCreate(frameWidth, frameHeight, 8, 32, > frameStride, theColorSpace, (CGBitmapInfo) > kCGImageAlphaNoneSkipFirst, dp, NULL, FALSE, kCGRenderingIntentDefault); > view.layer.contents = (id) im; > CGImageRelease(im); > CGDataProviderRelease(dp); > This works fine except that there is no throttle so this will draw > as fast as the CPU allows, which of course is a waste of CPU cycles > because the monitor only refreshes a certain amount of times per second. > So is there a convenient way to throttle drawing to the monitor's > refresh rate or does this have to be done the hard way by querying > the monitor's refresh rate and then setting up a timer which draws > in exactly those refresh intervals or how should this be done? > Note that I'd like to avoid using OpenGL or Metal or whatever is > the standard nowadays but I'm mainly interested in an AppKit solution... > -- > Best regards, > Andreas Falkenhahn mailto:andr...@falkenhahn.com > _______________________________________________ > 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/graham.cox%40bigpond.com > This email sent to graham....@bigpond.com -- Best regards, Andreas Falkenhahn mailto:andr...@falkenhahn.com _______________________________________________ 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