3

What is the best way to make NSView drawRect: render content that is drawn and updated by a background thread continuously?

  1. Background thread updates backing store & flags view for update
  2. macOS calls drawRect: to render backing store to screen

The background thread is running permanently.

Up until SDK 10.13 it was possible to have the background thread lockFocus / unlockFocus on NSView, which very efficiently populated the view's backing store. Rendering that backing store to screen in drawRect: was a snap.

With SDK 10.14 this no longer works (view remains black).

While it's possible to use a bitmap as a backing store, I'd prefer to avoid dealing with screen resolution and other specifics. I hope there's a more transparent and lean way (layers?)

2
  • Hey, do you already have an answer to that question? Nov 27, 2019 at 16:59
  • @return-true A solution is to use NSView's bitmapImageRepForCachingDisplayInRect: to create a resolution agnostic backing store. [NSGraphicsContext graphicsContextWithBitmapImageRep: backingStore] then gives the background thread a graphics context to paint on it. NSView drawRect: then draws the backingStore with drawInRect:...
    – Anders
    Nov 28, 2019 at 17:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.