Skip to content

Instantly share code, notes, and snippets.

@hartbit
Created May 20, 2011 16:26
Show Gist options
  • Select an option

  • Save hartbit/983269 to your computer and use it in GitHub Desktop.

Select an option

Save hartbit/983269 to your computer and use it in GitHub Desktop.
Postponed Rendering
- (void)display
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, NULL);
dispatch_async(queue, ^{
size_t contextWidth = [self boundsWidth];
size_t contextHeight = [self boundsHeight];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, contextWidth, contextHeight, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
[self drawInContext:context];
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRelease(context);
dispatch_async(dispatch_get_main_queue(), ^{
[self setContents:(id)image];
CGImageRelease(image);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment