Re: subLayers - GPU - optimizing
Re: subLayers - GPU - optimizing
- Subject: Re: subLayers - GPU - optimizing
- From: rajesh <email@hidden>
- Date: Mon, 9 Mar 2009 16:10:53 +0100
Thanks Matt ,
I overlooked it completely .
simply changing
[CALayer layer]; to [[CALayer alloc] init]; solved the problem
after successfully making the changes I still see the problem exists.
CALayers are removed if they are no longer needed , but after adding
around 120 layers (I could see just 12 as the sublayers count in
total , accounting from Visible Rect) I see there's a GPU warning
again :(
what could be the problem ? Caching ?
Thanks
Rajesh
On Mar 9, 2009, at 3:24 PM, Matt Long wrote:
A crash when trying to add your layer again after a call to
removeFromSuperlayer suggests that you're not retaining the layer
and it's been autoreleased. You either need to re-allocate each time
or retain it yourself. How are you allocating your CALayer inside of
your Layer object?
-Matt
On Mar 9, 2009, at 7:43 AM, rajesh wrote:
Hi all,
sorry for bad subject line, again :)
I have a layer backed view, I am trying to add subLayers roughly
sized around 300 X 270 (in pixels ) to it,
its that the, sublayers count may reach upto the 1000 to 2000 in
number and not to mention each of sublayer is again scalable to
roughly 4280 X 1500 or more for starters.
So the problem is obviously that of a GPU constraint.
after adding around 100 subLayers sized 300 X 270 , there is a
warning " image is too large for GPU, ignoring" and that messing up
with my the layer display.
solution for such problem (from some mailing lists) was to use
CATiledLayer , but I can't make use of the tiledLayer due to the
complex requirement of the subLayer's display.
Is there a possibility of removingthe subLayers which don't fall
under VisibleRect of the view ?
I tried to "removeFromSuperlayer" and then adding it whenever
required , there's always a crash when I try to add the subLayer
back.
Is there any solution for tackling the problem ?
any help is appreciated.
Thanks
Rajesh
@ViewClass
-(IBAction)addLayer:(id)sender
{
Layer *l = [[Layer alloc] init];
CALayer *layer = [l page];
[contentArray addObject:page];
[drawLayer addSublayer:layer];
[self layout];
}
-(void)layout
{
NSEnumerator *pageEnumr = [contentArray objectEnumerator];
float widthMargin = [self frame].size.width;
CGRect rect;
float zoom = [self zoomFactor];
while(obj = [contentEnmr nextObject] )
{
[obj setZoomFactor:zoom];
CALayer *pg =(CALayer *)[obj page] ;
rect = pg.bounds;
if ( x + pg.bounds.size.width > widthMargin )
{
x = xOffset;
y += rect.size.height + spacing ;
}
rect.origin = CGPointMake(x,y);
[pg setFrame:rect];
[obj changeBounds];
//this is where i am trying to remove and add the sublayer
// NSRect VisibleRect = [self visibleRect];
// NSRect result =
NSIntersectionRect(VisibleRect,NSRectFromCGRect( rect));
// if( NSEqualRects (result ,NSZeroRect) )
// {
// [pg removeFromSuperlayer];
// }else
// {
// [drawLayer addSublayer:pg];
// [pg setFrame:rect];
// [pg setNeedsDisplay];
// }
x += ( rect.size.width + spacing);
}
NSRect viewRect = [self frame];
if(viewRect.size.height < ( y + rect.size.height + spacing ) )
viewRect.size.height = ( y + rect.size.height + spacing) ;
[self setFrameSize: viewRect.size];
}
@interface Layer : NSObject {
CALayer *page;
}
@property (retain) CALayer *page;
_______________________________________________
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