• 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
Re: drawing in a separate thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: drawing in a separate thread


  • Subject: Re: drawing in a separate thread
  • From: Graham Cox <email@hidden>
  • Date: Sat, 3 May 2008 22:52:28 +1000


On 3 May 2008, at 9:36 pm, Duncan wrote:

If you're going to do your drawing in a separate thread, you'll need to remember WHAT to draw. I wouldn't call it "hackish", I'd call it the cost of doing business that way.

If you implement a job queue, add the list of dirty rectangles to each job object. -drawRect would be where you'd add your jobs to the queue. It cold call getRectsBeingDrawn:count to get the list of dirty rects, then add that list to the job object. Then when the worker thread picks up a job, it would get the list of dirty rectangles from the job object instead of calling getRectsBeingDrawn:count. That should be pretty straightforward.

This is pretty much what I've done. When the need to draw is flagged, it copies the rects from getRectsBeingDrawn: and saves them in the invocation which is queued. When the thread invokes drawing, it passes the rects back to the view which now overrides needsToDrawRect: and uses these saved rects to figure out what needs to draw. Lower level drawing code is none the wiser.


That's all working pretty well as such now, performance seems as least on a par with synchronous drawing, possibly better though I've yet to measure it.

Now another issue rears its head ;-)

Consider the user dragging an object. Because drawRect: returns quickly now, the user is able to move the object beyond the update area before the thread gets a chance to draw it - so I'm seeing edges of objects are being clipped out during fast motion. I can't think of any way around this at the moment - any ideas? (I tried triggering the draw thread on a setNeedsDisplayInRect: but that's much worse - it queues so many updates it has an eerie slo-mo effect! It catches up eventually, but it's clearly not a solution).


G. _______________________________________________

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: drawing in a separate thread
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Re: drawing in a separate thread (From: Duncan <email@hidden>)

  • Prev by Date: Re: Update NSMenuItem while displaying
  • Next by Date: Implementing fast enumeration
  • Previous by thread: Re: drawing in a separate thread
  • Next by thread: Re: drawing in a separate thread
  • Index(es):
    • Date
    • Thread