• 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: Possible blunder with CALayers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible blunder with CALayers


  • Subject: Re: Possible blunder with CALayers
  • From: rajesh <email@hidden>
  • Date: Fri, 27 Feb 2009 10:29:38 +0100

Sorry forgot to mention: the gray boxes flicker a lot could be Root Layer delayed resizing.
On Feb 27, 2009, at 10:25 AM, rajesh wrote:


Hi All,

I recently posted a message with subject "View with Subviews + Drawing on top of everything" and I got convinced to use CALayers in my view instead of NSView's.

summary: I added few CALayers to myView and tried to resize myView and result was rusty and snaggy.
When I used NSView's (initially) even adding 120-150 NSView's was faster and responsive.
I assumed using CALayer (instead of NSView's) makes my app faster and more responsive with appealing looks and animations but my code seems made the opposite of fast (http://theocacao.com/document.page/595 )
There could be some possible flaw or I misunderstood the concept.


but the code is simple as of now ( I have to do lot of animation and image additions in future ) still myView is slow ,
Shark app shows (If, of any use )
8.0% 8.0% CoreGraphics sseCGSFill8by1
3.0% 3.0% CoreGraphics sse64CGSFill8by1
2.6% 2.6% ATIRadeonX1000GLDriver gldInitDispatch
2.4% 2.4% mach_kernel ml_set_interrupts_enabled
1.9% 1.9% ATIRadeonX1000GLDriver gldUpdateDispatch


Quartz Debug.app shows a too much delay in updating the myView.
Any help is appreciated.

Thanks
Rajesh

Code:
@implementation MyView
-(void)awakeFromNib
{
pages = [[NSMutableArray alloc] init];
rootLayer = [[CALayer layer] retain];
rootLayer.name = @"root";
rootLayer.backgroundColor = CGColorCreateGenericRGB(1.0,1.0,1.0,1.0);
[self setLayer:rootLayer];
[self setWantsLayer:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleFrameChange:) name:NSViewFrameDidChangeNotification object:self];


}

- (id)initWithFrame:(NSRect)frame {
   self = [super initWithFrame:frame];
   if (self) {
   }
   return self;
}
- (void)handleFrameChange:(NSNotification *)aNotification
{
	[self layout];
}
-(IBAction)addPage:(id)sender
{
	CALayer *page = [PageLayer create];
	[pages addObject:page];
	page.name = [NSString stringWithFormat:@"%d",[pages count]+1];
	[self layout];

}
- (BOOL)isFlipped
{
	return YES;
}
- (void) mouseDown: (NSEvent*)ev
{
	NSPoint pt = [ev locationInWindow];
	CALayer *layer = [rootLayer hitTest:NSPointToCGPoint(pt)];
}

-(void)layout
{
	NSEnumerator *pageEnumr = [pages objectEnumerator];
	id pg;
	float widthMargin = [self frame].size.width;
	NSRect rect;
	while(pg = [pageEnumr nextObject])
	{

		rect = [pg bounds];
		rect.origin.x = x;
		rect.origin.y = y;
		[pg setFrame:rect];

		x += rect.size.width + spacing;
		if ( x  >= widthMargin )
		{
			x = xOffset;
			y += rect.size.height + spacing ;
		}
		[rootLayer addSublayer:pg];
	}

}
@end


@implementation PageLayer +(CALayer *)create { CALayer* myLayer = [CALayer layer]; myLayer.bounds = CGRectMake(0, 0, 150, 200); myLayer.borderWidth = 1.0f ; myLayer.borderColor = CGColorCreateGenericRGB(0.0,0.0,0.0,0.9); myLayer.backgroundColor = CGColorCreateGenericGray(0.7, 1.0); myLayer.name = @"page"; return myLayer; }

_______________________________________________

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

_______________________________________________

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: Possible blunder with CALayers
      • From: Patrick Mau <email@hidden>
References: 
 >Possible blunder with CALayers (From: rajesh <email@hidden>)

  • Prev by Date: Possible blunder with CALayers
  • Next by Date: Re: Possible blunder with CALayers
  • Previous by thread: Possible blunder with CALayers
  • Next by thread: Re: Possible blunder with CALayers
  • Index(es):
    • Date
    • Thread