Re: Weird Threads (repost)
Re: Weird Threads (repost)
- Subject: Re: Weird Threads (repost)
- From: "Glen Low" <email@hidden>
- Date: Thu, 12 Feb 2004 22:10:44 -0500
>
Let me make sure I know what you're saying...
>
Do you mean I should just have a thread that runs whenever the image
>
needs to be rendered, then when drawRect is called draw that image?If
>
so, how would I display the image as it was drawing? (Is this even
>
possible?) Thanks for your help!
>
>> I am trying to use an NSThread for a complex drawing operation. In
>
>> my custom view, when drawRect is called, I detach to another method
>
>> in myself. The view draws fine. The problem is that the app still
>
>> acts like it's not multithreaded, the interface still locks up until
>
>> the drawing is complete. Any ideas?
>
>>
>
>> Here is the drawRect function:
>
>> - (void)drawRect:(NSRect)rect {
>
>> [NSThread detachNewThreadSelector:@selector(drawRectThreaded:)
>
>> toTarget:self withObject:NSStringFromRect(rect)];
>
>> return;
>
>> }
I suspect the design of Cocoa (and most other GUI frameworks) means that "visible" window drawing and event handling must happen in the same, main thread. The question then becomes: can you effectively separate rendering i.e. creating the objects necessary for display, from drawing i.e. actually outputting them to the window? (These objects could be bitmap caches, and the drawing a simple blit, for example.)
If rendering is slow and drawing is fast, and you want to see periodic drawing, then put the rendering in the secondary thread, have it send messages to the main thread containing the object(s) to draw, the main thread accumulates the objects(s) it receives (bitmaps could be composited together or something), invalidates that part of the window, which eventually gets drawRect to draw it.
If rendering is fast and drawing is slow, or the two are irretreivably intertwined, threading will not solve anything. You have to draw to the window in the main thread in any case, and impact your event handling.
Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.