Re: CALayer -drawInContext and GCD
After much (private) talk with David, we are both at the loss with this issue. I'll investigate further but, meanwhile, does somebody here on the list have tried to refresh CALayer within GCD blocks? If yes, does it work? Thanks, Vincent___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
David, Yes. I have put a NSLog in both -display and -drawInContext. The first is run, the second never... Vincent ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
On Sep 3, 2010, at 7:50 AM, Vincent Habchi wrote: >> I have implemented what you suggested. I get a strange behavior: the first >> time I enqueue a request for display, everything is fine. But then I cannot >> draw any further: any subsequent call, albeit correctly enqueued in the >> block, does nothing: the -(void)display > > Read: "at any subsequent call, albeit the block is correctly enqueued, > nothing is done: …" Are you sure the block was executed? I've done this before in various incarnations and never seen what you describe... -- David Duncan ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
> I have implemented what you suggested. I get a strange behavior: the first > time I enqueue a request for display, everything is fine. But then I cannot > draw any further: any subsequent call, albeit correctly enqueued in the > block, does nothing: the -(void)display Read: "at any subsequent call, albeit the block is correctly enqueued, nothing is done: …" Sorry for the gibberish. Vincent___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
Le 3 sept. 2010 à 00:17, David Duncan a écrit : > Doing so would cause you all manners of pain and suffering, the most common > of which is things "mostly" working but occasionally your drawing going into > the wrong view. Basically *never* use the context given to you in > -drawInContext: outside of that invocation. Understood. I have implemented what you suggested. I get a strange behavior: the first time I enqueue a request for display, everything is fine. But then I cannot draw any further: any subsequent call, albeit correctly enqueued in the block, does nothing: the -(void)display method is called, but it does not forward to -(void)drawInContext. As if there were some initialization or finalization step lacking. Any idea? Vincent___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
On Sep 2, 2010, at 3:17 PM, David Duncan wrote: > On Sep 2, 2010, at 11:29 AM, vincent habchi wrote: > >> You mean I shall use your dispatch_async invocation instead of calling >> [layer setNeedsDisplay]? > > Calling -setNeedsDisplay arranges for -display to later be called on the > current runloop. As such using -setNeedsDisplay is reliant on a runloop > running (and running regularly) neither of which you have on a GCD queue. > >> I was thinking of calling dispatch_async () inside -drawInContext, but, if I >> understand your example correctly, this is wrong. > > Doing so would cause you all manners of pain and suffering, the most common > of which is things "mostly" working but occasionally your drawing going into > the wrong view. Basically *never* use the context given to you in > -drawInContext: outside of that invocation. More generally, -draw…: methods should never have side effects, whether we're talking about a layer, a view, or what have you. -jcr ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
On Sep 2, 2010, at 11:29 AM, vincent habchi wrote: > You mean I shall use your dispatch_async invocation instead of calling [layer > setNeedsDisplay]? Calling -setNeedsDisplay arranges for -display to later be called on the current runloop. As such using -setNeedsDisplay is reliant on a runloop running (and running regularly) neither of which you have on a GCD queue. > I was thinking of calling dispatch_async () inside -drawInContext, but, if I > understand your example correctly, this is wrong. Doing so would cause you all manners of pain and suffering, the most common of which is things "mostly" working but occasionally your drawing going into the wrong view. Basically *never* use the context given to you in -drawInContext: outside of that invocation. -- David Duncan ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
Hi Vincent, On 2 Sep 2010, at 11:29 AM, vincent habchi wrote: > I promise I did not plan to start an Apple internal quarrel! ;) I don't think there's any real quarrel here; David and I are looking at this from two distinct points of view. :) The docs for +[CATransaction flush] make the statement that you shouldn't call it in the general main run loop case, but you should call it yourself if you have no run loop in place. In your case: dispatch_async(queue, ^{ [layer display]; [CATransaction flush]; } As David says, this is fine if you own and control the dispatch queue yourself and thus you know you're the only one setting up transactions on that queue. In the above code, if 'queue' were the main queue, you'd likely be interfering with whatever the AppKit or UIKit might have in flight. Typical symptoms might include animations happening "early" or out of order from when you expect, or starting from odd locations. If you're going to be doing a high transaction rate, you probably don't want to be calling +[CATransaction flush] after every one of them. You'll likely want to simulate what the run loop implementations do and fire it off after a preset number, or after a group of related displays/animations. .chris ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
David, Chris, I promise I did not plan to start an Apple internal quarrel! ;) >>> dispatch_async(queue, ^{ >>> [layer display]; >>> [CATransaction flush]; >>> } >> >> There is (almost) never any reason for anyone to be calling +[CATransaction >> flush] directly. You'll cause all sorts of unexpected things to happen >> w.r.t. extant CATransactions. You should let +flush be called at the end of >> the run loop on its own. > > The work is occurring on a GCD queue, which has no runloop running, as such > it won't be called on its own and there are no other extant transactions to > be affected. Assuming 'queue' isn't the main thread queue that is. You mean I shall use your dispatch_async invocation instead of calling [layer setNeedsDisplay]? I was thinking of calling dispatch_async () inside -drawInContext, but, if I understand your example correctly, this is wrong. Thanks for taking the time to answer me, Vincent___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
On Sep 2, 2010, at 9:40 AM, Chris Parker wrote: > On 2 Sep 2010, at 8:52 AM, David Duncan wrote: > >> On Sep 2, 2010, at 7:39 AM, Vincent Habchi wrote: >> >>> I just wanted to know someone has already tried to successfully send a >>> CALayer -drawInContext method to a GCD dispatch queue. I suspect this is >>> not possible, because of main loop related issue, but this is unclear. >> >> This can be done, but you have to ensure that your layer's drawing is >> threadsafe. Should be as simple as this with that precondition met: >> >> dispatch_async(queue, ^{ >> [layer display]; >> [CATransaction flush]; >> } > > There is (almost) never any reason for anyone to be calling +[CATransaction > flush] directly. You'll cause all sorts of unexpected things to happen w.r.t. > extant CATransactions. You should let +flush be called at the end of the run > loop on its own. The work is occurring on a GCD queue, which has no runloop running, as such it won't be called on its own and there are no other extant transactions to be affected. Assuming 'queue' isn't the main thread queue that is. -- David Duncan ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
On 2 Sep 2010, at 8:52 AM, David Duncan wrote: > On Sep 2, 2010, at 7:39 AM, Vincent Habchi wrote: > >> I just wanted to know someone has already tried to successfully send a >> CALayer -drawInContext method to a GCD dispatch queue. I suspect this is not >> possible, because of main loop related issue, but this is unclear. > > This can be done, but you have to ensure that your layer's drawing is > threadsafe. Should be as simple as this with that precondition met: > > dispatch_async(queue, ^{ > [layer display]; > [CATransaction flush]; > } There is (almost) never any reason for anyone to be calling +[CATransaction flush] directly. You'll cause all sorts of unexpected things to happen w.r.t. extant CATransactions. You should let +flush be called at the end of the run loop on its own. .chris ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: CALayer -drawInContext and GCD
On Sep 2, 2010, at 7:39 AM, Vincent Habchi wrote: > I just wanted to know someone has already tried to successfully send a > CALayer -drawInContext method to a GCD dispatch queue. I suspect this is not > possible, because of main loop related issue, but this is unclear. This can be done, but you have to ensure that your layer's drawing is threadsafe. Should be as simple as this with that precondition met: dispatch_async(queue, ^{ [layer display]; [CATransaction flush]; } -- David Duncan ___ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com