Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SVG layer generation in background thread
  • Loading branch information
djphoenix committed May 14, 2015
1 parent 1b31385 commit a578322
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pxSVG/pxSVGLayer.m
Expand Up @@ -103,10 +103,23 @@ - (void)loadString:(NSString *)string
- (void)loadImage:(pxSVGImage*)image
{
[self clean];
[self addSublayer:[image makeLayer]];
self.contentRect = image.bounds;
if ([self.svgDelegate respondsToSelector:@selector(svgLayerDidLoadImage:)])
[self.svgDelegate svgLayerDidLoadImage:self];
__weak pxSVGLayer *weakself = self;
__block NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
CALayer *img = [image makeLayer];
if ([op isCancelled]) return;
NSBlockOperation *sync = [NSBlockOperation blockOperationWithBlock:^{
if ([op isCancelled]) return;
if (!weakself) return;
[weakself addSublayer:img];
weakself.parseOperation = nil;
weakself.contentRect = image.bounds;
if ([weakself.svgDelegate respondsToSelector:@selector(svgLayerDidLoadImage:)])
[weakself.svgDelegate svgLayerDidLoadImage:weakself];
}];
[[NSOperationQueue mainQueue] addOperations:@[sync] waitUntilFinished:YES];
}];
op.threadPriority = 0.1f;
[[self.class parseQueue] addOperation:self.parseOperation=op];
}

- (void)loadError:(NSError *)error
Expand Down

0 comments on commit a578322

Please sign in to comment.