[vlc-devel] [PATCH 05/13] VLCKit: migrate VLCVideoCommon to ARC

Florent Pillet fpillet at gmail.com
Mon Jul 7 12:41:20 CEST 2014


With enhanced thread-safety
---
 Headers/Internal/VLCVideoCommon.h |  9 +++------
 Sources/VLCVideoCommon.m          | 27 ++++++++++++++-------------
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/Headers/Internal/VLCVideoCommon.h b/Headers/Internal/VLCVideoCommon.h
index 182e855..5e70ba4 100644
--- a/Headers/Internal/VLCVideoCommon.h
+++ b/Headers/Internal/VLCVideoCommon.h
@@ -28,15 +28,12 @@
  * TODO: Documentation
  */
 @interface VLCVideoLayoutManager : NSObject
-{
-    CGSize originalVideoSize;
-    BOOL  fillScreenEntirely;
-}
 
 /* Factories */
 + (id)layoutManager;
 
 /* Properties */
- at property BOOL  fillScreenEntirely;
- at property CGSize originalVideoSize;
+ at property (nonatomic) BOOL  fillScreenEntirely;
+ at property (nonatomic) CGSize originalVideoSize;
+
 @end
diff --git a/Sources/VLCVideoCommon.m b/Sources/VLCVideoCommon.m
index f12ec5b..39741f1 100644
--- a/Sources/VLCVideoCommon.m
+++ b/Sources/VLCVideoCommon.m
@@ -32,13 +32,17 @@
 
 @implementation VLCVideoLayoutManager
 
-/* Factories */
 + (id)layoutManager
 {
-    return [[[self alloc] init] autorelease];
+	static id sLayoutManager = nil;
+	static dispatch_once_t onceToken;
+	dispatch_once(&onceToken, ^{
+		sLayoutManager = [[self alloc] init];
+	});
+    return sLayoutManager;
 }
 
-/* CALayoutManager Impelmentation */
+/* CALayoutManager Implementation */
 - (void)layoutSublayersOfLayer:(CALayer *)layer
 {
     /* After having done everything normally resize the vlcopengllayer */
@@ -47,15 +51,15 @@
         CALayer * videolayer = [[layer sublayers] objectAtIndex:0];
         CGRect bounds = layer.bounds;
         CGRect videoRect = bounds;
-
-        if (originalVideoSize.height > 0 && originalVideoSize.width > 0)
+		CGSize original = self.originalVideoSize;
+        if (original.height > 0 && original.width > 0)
         {
-            CGFloat xRatio = CGRectGetWidth(bounds) / originalVideoSize.width;
-            CGFloat yRatio = CGRectGetHeight(bounds) / originalVideoSize.height;
-            CGFloat ratio = fillScreenEntirely ? MAX(xRatio, yRatio) : MIN(xRatio, yRatio);
+            CGFloat xRatio = CGRectGetWidth(bounds) / original.width;
+            CGFloat yRatio = CGRectGetHeight(bounds) / original.height;
+            CGFloat ratio = self.fillScreenEntirely ? MAX(xRatio, yRatio) : MIN(xRatio, yRatio);
 
-            videoRect.size.width = ratio * originalVideoSize.width;
-            videoRect.size.height = ratio * originalVideoSize.height;
+            videoRect.size.width = ratio * original.width;
+            videoRect.size.height = ratio * original.height;
             videoRect.origin.x += (CGRectGetWidth(bounds) - CGRectGetWidth(videoRect)) / 2.0;
             videoRect.origin.y += (CGRectGetHeight(bounds) - CGRectGetHeight(videoRect)) / 2.0;
         }
@@ -63,7 +67,4 @@
     }
 }
 
-/* Properties */
- at synthesize fillScreenEntirely;
- at synthesize originalVideoSize;
 @end
-- 
1.8.5.2 (Apple Git-48)




More information about the vlc-devel mailing list