Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[CHANGE] Use NSOperation and NSOperationQueue to multithread the load…
…ing of images
- Loading branch information
Showing
7 changed files
with
124 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// MBCoverFlowImageLoadOperation.h | ||
// MBCoverFlowView | ||
// | ||
// Created by Matt Ball on 3/28/09. | ||
// Copyright 2009 Daybreak Apps. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
@interface MBCoverFlowImageLoadOperation : NSOperation { | ||
CALayer *_layer; | ||
NSString *_imageKeyPath; | ||
} | ||
|
||
@property (nonatomic, retain) CALayer *layer; | ||
@property (nonatomic, copy) NSString *imageKeyPath; | ||
|
||
- (id)initWithLayer:(CALayer *)layer imageKeyPath:(NSString *)imageKeyPath; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// MBCoverFlowImageLoadOperation.m | ||
// MBCoverFlowView | ||
// | ||
// Created by Matt Ball on 3/28/09. | ||
// Copyright 2009 Daybreak Apps. All rights reserved. | ||
// | ||
|
||
#import "MBCoverFlowImageLoadOperation.h" | ||
|
||
#import "NSImage+MBCoverFlowAdditions.h" | ||
|
||
@implementation MBCoverFlowImageLoadOperation | ||
|
||
@synthesize layer=_layer, imageKeyPath=_imageKeyPath; | ||
|
||
- (id)initWithLayer:(CALayer *)layer imageKeyPath:(NSString *)imageKeyPath; | ||
{ | ||
if (self = [super init]) { | ||
_layer = [layer retain]; | ||
_imageKeyPath = [imageKeyPath copy]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
self.layer = nil; | ||
self.imageKeyPath = nil; | ||
[super dealloc]; | ||
} | ||
|
||
- (BOOL)isConcurrent | ||
{ | ||
return NO; | ||
} | ||
|
||
- (void)main | ||
{ | ||
@try { | ||
NSImage *image; | ||
NSObject *object = [self.layer valueForKey:@"representedObject"]; | ||
|
||
if (self.imageKeyPath != nil) { | ||
image = [object valueForKeyPath:self.imageKeyPath]; | ||
} else if ([object isKindOfClass:[NSImage class]]) { | ||
image = (NSImage *)object; | ||
} | ||
|
||
CGImageRef imageRef = [image imageRef]; | ||
|
||
CALayer *imageLayer = [[self.layer sublayers] objectAtIndex:0]; | ||
CALayer *reflectionLayer = [[imageLayer sublayers] objectAtIndex:0]; | ||
|
||
imageLayer.contents = (id)imageRef; | ||
reflectionLayer.contents = (id)imageRef; | ||
imageLayer.backgroundColor = NULL; | ||
reflectionLayer.backgroundColor = NULL; | ||
} @catch (NSException *e) { | ||
// If the key path isn't valid, do nothing | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ | |
BOOL _autoresizesItems; | ||
|
||
NSString *_imageKeyPath; | ||
|
||
NSOperationQueue *_imageLoadQueue; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters