Re: NSDrawNinePartImage draws slowly in CALayer

2009-03-08 Thread Sebastian Morsch

Thank you Jean-Daniel for your thoughts on this!


Shark revealed that the most time was spend inside  
NSDrawNinePartImage, so I replaced that function by a self-made  
lightweight version. Here I discovered that most time was spend on  
drawing the center image, which is scaled along both the X and Y axis.  
Luckily I didn't need that for my bezel.


It didn't seem to be a specific problem of CA though. I tried the same  
with a "traditional" non-layer-backed NSView subclass and redrawing  
performance was even worse than with the CALayer.



I still wonder how resizable 9-parts are supposed to be implemented.  
The documentation of NSDrawNinePartImage state that


"you should prefer the use of this function over your own custom code  
for handling multi-part images whose size can change".


(I don't want to rant and rave, I'm just curious...)


Sebastian



Am 06.03.2009 um 20:59 schrieb Jean-Daniel Dupas:



Le 6 mars 09 à 20:42, Jean-Daniel Dupas a écrit :



Le 6 mars 09 à 20:33, Sebastian Morsch a écrit :


Hello,

I wrote a delegate that draws a bezel inside a CALayer using  
NSDrawNinePartImage. The drawing happens inside the  
drawLayer:inContext: method and it works well. The only problem is  
that it redraws really slow when the layers frame is resized by  
the user.


The layer is simply attached to a custom view for testing the  
whole thing. This view is the only view of a window, and when I  
resize that window, my layer is resized too. But it feels very  
clunky.


I was wondering if I'm doing something really stupid here... Does  
anybody know if there's a better way to tackle this?


Thank you!
Sebastian





If you want to know why your code is slow, use the Xcode Debug Menu  
> Launch Using Performance Tool > Shark.




To be exact, this is the Menu

Run > Start With Performance Tool > Shark


Shark will give you better and more accurate answer.

My guess is that you are creating the images at each call, which  
require to read them from disk, and decode them and is very slow.


Just an other details, instead of creating the color at each call,  
you can use CGContextSetRGBFillColor(ctx, 0, 0, 1, .2).


___

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/sebastianmorsch%40mac.com

This email sent to sebastianmor...@mac.com


___

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: NSDrawNinePartImage draws slowly in CALayer

2009-03-06 Thread Jean-Daniel Dupas


Le 6 mars 09 à 20:42, Jean-Daniel Dupas a écrit :



Le 6 mars 09 à 20:33, Sebastian Morsch a écrit :


Hello,

I wrote a delegate that draws a bezel inside a CALayer using  
NSDrawNinePartImage. The drawing happens inside the  
drawLayer:inContext: method and it works well. The only problem is  
that it redraws really slow when the layers frame is resized by the  
user.


The layer is simply attached to a custom view for testing the whole  
thing. This view is the only view of a window, and when I resize  
that window, my layer is resized too. But it feels very clunky.


I was wondering if I'm doing something really stupid here... Does  
anybody know if there's a better way to tackle this?


Thank you!
Sebastian





If you want to know why your code is slow, use the Xcode Debug Menu  
> Launch Using Performance Tool > Shark.




To be exact, this is the Menu

Run > Start With Performance Tool > Shark


Shark will give you better and more accurate answer.

My guess is that you are creating the images at each call, which  
require to read them from disk, and decode them and is very slow.


Just an other details, instead of creating the color at each call,  
you can use CGContextSetRGBFillColor(ctx, 0, 0, 1, .2).


___

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: NSDrawNinePartImage draws slowly in CALayer

2009-03-06 Thread Jean-Daniel Dupas


Le 6 mars 09 à 20:33, Sebastian Morsch a écrit :


Hello,

I wrote a delegate that draws a bezel inside a CALayer using  
NSDrawNinePartImage. The drawing happens inside the  
drawLayer:inContext: method and it works well. The only problem is  
that it redraws really slow when the layers frame is resized by the  
user.


The layer is simply attached to a custom view for testing the whole  
thing. This view is the only view of a window, and when I resize  
that window, my layer is resized too. But it feels very clunky.


I was wondering if I'm doing something really stupid here... Does  
anybody know if there's a better way to tackle this?


Thank you!
Sebastian




There's no other code than these two methods in my custom view:

- (void)awakeFromNib {

CALayer *rootLayer = [CALayer layer];
rootLayer.delegate = self;
rootLayer.needsDisplayOnBoundsChange = YES;

[self setLayer:rootLayer];
[self setWantsLayer:YES];

[rootLayer setNeedsDisplay];
}

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {

CGRect boundsRect = CGContextGetClipBoundingBox(ctx);

// Draw colored interior
CGRect bgRect = CGRectInset(boundsRect, 1.0, 1.0);
CGColorRef color = CGColorCreateGenericRGB(0.0, 0.0, 1.0, 0.2);
CGContextSetFillColorWithColor(ctx, color);
CGContextFillRect(ctx, bgRect);

// Draw bezel
NSDrawNinePartImage(
NSRectFromCGRect(boundsRect),
[NSImage 
imageNamed:@"ClipFrame-N-TL"],
[NSImage 
imageNamed:@"ClipFrame-N-T"],
[NSImage 
imageNamed:@"ClipFrame-N-TR"],
[NSImage 
imageNamed:@"ClipFrame-N-L"],
[NSImage 
imageNamed:@"ClipFrame-N-C"],
[NSImage 
imageNamed:@"ClipFrame-N-R"],
[NSImage 
imageNamed:@"ClipFrame-N-BL"],
[NSImage 
imageNamed:@"ClipFrame-N-B"],
[NSImage 
imageNamed:@"ClipFrame-N-BR"],
NSCompositeSourceOver,
1.0,
NO);
}



If you want to know why your code is slow, use the Xcode Debug Menu >  
Launch Using Performance Tool > Shark.


Shark will give you better and more accurate answer.

My guess is that you are creating the images at each call, which  
require to read them from disk, and decode them and is very slow.


Just an other details, instead of creating the color at each call, you  
can use CGContextSetRGBFillColor(ctx, 0, 0, 1, .2).




___

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