Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 5b3e530

Browse files
authored
Merge pull request #144 from svga/2.5.5
2.5.5
2 parents f870676 + 2e3f3c8 commit 5b3e530

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

Diff for: SVGAPlayer.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = "SVGAPlayer"
4-
s.version = "2.5.4"
4+
s.version = "2.5.5"
55
s.summary = "SVGAPlayer 是一个高性能的动画播放器"
66
s.description = <<-DESC
77
SVGA 是一种全新的动画格式,由 YY UED 团队主导开发;

Diff for: SVGAPlayer/ViewController.m

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ - (IBAction)onChange:(id)sender {
5050
@"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true",
5151
];
5252
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
53+
// parser.enabledMemoryCache = YES;
5354
[parser parseWithURL:[NSURL URLWithString:items[arc4random() % items.count]]
5455
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
5556
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
@@ -66,6 +67,8 @@ - (IBAction)onChange:(id)sender {
6667
NSParagraphStyleAttributeName: para,
6768
}];
6869
[self.aPlayer setAttributedText:str forKey:@"banner"];
70+
71+
// self.aPlayer.mianRunLoopMode = NSDefaultRunLoopMode;
6972
[self.aPlayer startAnimation];
7073
}
7174
} failureBlock:nil];

Diff for: Source/SVGAPlayer.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ typedef void(^SVGAPlayerDynamicDrawingBlock)(CALayer *contentLayer, NSInteger fr
2828
@property (nonatomic, assign) IBInspectable int loops;
2929
@property (nonatomic, assign) IBInspectable BOOL clearsAfterStop;
3030
@property (nonatomic, copy) NSString *fillMode;
31+
@property (nonatomic, copy) NSRunLoopMode mainRunLoopMode;
3132

3233
- (void)startAnimation;
3334
- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse;

Diff for: Source/SVGAPlayer.m

+9-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ - (void)startAnimation {
8484
}
8585
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)];
8686
self.displayLink.frameInterval = 60 / self.videoItem.FPS;
87-
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
87+
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode];
8888
self.forwardAnimating = !self.reversing;
8989
}
9090

@@ -156,7 +156,7 @@ - (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay {
156156
}
157157
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)];
158158
self.displayLink.frameInterval = 60 / self.videoItem.FPS;
159-
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
159+
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode];
160160
}
161161
}
162162

@@ -523,4 +523,11 @@ - (NSDictionary *)dynamicHiddens {
523523
return _dynamicDrawings;
524524
}
525525

526+
- (NSRunLoopMode)mainRunLoopMode {
527+
if (!_mainRunLoopMode) {
528+
_mainRunLoopMode = NSRunLoopCommonModes;
529+
}
530+
return _mainRunLoopMode;
531+
}
532+
526533
@end

Diff for: Source/SVGAVideoEntity.m

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ @implementation SVGAVideoEntity
3232

3333
static NSCache *videoCache;
3434
static NSMapTable * weakCache;
35+
static dispatch_semaphore_t videoSemaphore;
3536

3637
+ (void)load {
3738
static dispatch_once_t onceToken;
@@ -40,6 +41,7 @@ + (void)load {
4041
weakCache = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory
4142
valueOptions:NSPointerFunctionsWeakMemory
4243
capacity:64];
44+
videoSemaphore = dispatch_semaphore_create(1);
4345
});
4446
}
4547

@@ -209,19 +211,26 @@ - (void)resetAudiosWithProtoObject:(SVGAProtoMovieEntity *)protoObject {
209211
}
210212

211213
+ (SVGAVideoEntity *)readCache:(NSString *)cacheKey {
214+
dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER);
212215
SVGAVideoEntity * object = [videoCache objectForKey:cacheKey];
213216
if (!object) {
214217
object = [weakCache objectForKey:cacheKey];
215218
}
216-
return object;
219+
dispatch_semaphore_signal(videoSemaphore);
220+
221+
return object;
217222
}
218223

219224
- (void)saveCache:(NSString *)cacheKey {
225+
dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER);
220226
[videoCache setObject:self forKey:cacheKey];
227+
dispatch_semaphore_signal(videoSemaphore);
221228
}
222229

223230
- (void)saveWeakCache:(NSString *)cacheKey {
231+
dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER);
224232
[weakCache setObject:self forKey:cacheKey];
233+
dispatch_semaphore_signal(videoSemaphore);
225234
}
226235

227236
@end

0 commit comments

Comments
 (0)