Best way to draw text in CAOpenGLLayer
Best way to draw text in CAOpenGLLayer
- Subject: Best way to draw text in CAOpenGLLayer
- From: Anshul jain <email@hidden>
- Date: Thu, 21 May 2009 15:53:15 +0530
HI All,
I am trying to scroll text in CAOpenGLLayer. Every thing is working
fine. But the scrolling is not smooth and the CPU usage was 60 % -
80%. I think application is taking time to convert NSString into a
CGImage. Is there a better way of displaying text in CAOpenGLLayer.
This is how i am creating the CGBitmap context
- (void)setUpContext
{
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
size_t width, height, bytesPerRow;
CGDataProviderRef bitmapContextDataProvider;
width = floor(self.bounds.size.width);
height = floor(self.bounds.size.height);
bytesPerRow = (width * 4 + 63) & ~63;
bitmapData = calloc(bytesPerRow * height, 1);
bitmapContext = CGBitmapContextCreate(bitmapData, width, height,
8 ,bytesPerRow, colorspace, kCGImageAlphaPremultipliedLast);
graphicsContext = [[NSGraphicsContext
graphicsContextWithGraphicsPort:bitmapContext flipped:NO] retain];
bitmapContextDataProvider = CGDataProviderCreateWithData(nil,
bitmapData, bytesPerRow * height, nil);
bitmapImage = CGImageCreate(width,
height,
8,
32,
bytesPerRow,
colorspace,
kCGImageAlphaPremultipliedLast,
bitmapContextDataProvider,
nil,
false,
kCGRenderingIntentDefault);
CGDataProviderRelease(bitmapContextDataProvider);
CGColorSpaceRelease(colorspace);
}
this is how i am converting it to image
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
CGContextClearRect(bitmapContext,self.bounds);
[NSGraphicsContext setCurrentContext:graphicsContext];
NSRect rect = NSRectFromCGRect(self.bounds);
if (startCrawler) {
NSRect frameRect;
frameRect.size = NSMakeSize(0, self.frame.size.height - 10);
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setObject:font forKey:NSFontAttributeName];
[attributes setObject:textColor
forKey:NSForegroundColorAttributeName];
for (int i = 0 ; i < [dispalyTitleArray count] ; i++ ) {
RSSDisplayItem *currentDisplayItem = [dispalyTitleArray
objectAtIndex:i];
frameRect.size.width = [currentDisplayItem size].width +
kTextPadding;
frameRect.origin.x = [currentDisplayItem xLocation];
[[currentDisplayItem title] drawInRect:frameRect
withAttributes:attributes];
}
}
[NSGraphicsContext setCurrentContext:previousContext];
Regards,
Anshul jain
Regards,
Anshul jain
Software Engineer
Prithvi Information Solutions Ltd
10Q3A1, Cyber Towers
HITEC City, Madhapur
Hyderabad - 500 081
_______________________________________________
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