• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Throttling drawing to vertical refresh
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Throttling drawing to vertical refresh


  • Subject: Throttling drawing to vertical refresh
  • From: Andreas Falkenhahn via Cocoa-dev <email@hidden>
  • Date: Thu, 15 Oct 2020 21:13:46 +0200

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:email@hidden

_______________________________________________

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

  • Follow-Ups:
    • Re: Throttling drawing to vertical refresh
      • From: Alex Zavatone via Cocoa-dev <email@hidden>
    • Re: Throttling drawing to vertical refresh
      • From: Mike Abdullah via Cocoa-dev <email@hidden>
  • Prev by Date: NSView draws unwanted "seams" for certain zoom factors
  • Next by Date: Re: Throttling drawing to vertical refresh
  • Previous by thread: NSView draws unwanted "seams" for certain zoom factors
  • Next by thread: Re: Throttling drawing to vertical refresh
  • Index(es):
    • Date
    • Thread