summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-01-27 18:30:36 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-01-27 18:38:25 +0100
commita3322cb171fed42bc3d15adc84d03cf560fc0fc9 (patch)
tree74edbe0858f1d7ee0e5c65438864286900e5dba9 /video
parentfddba2d529c7d37b58a176525f45e5d4fc2c80b4 (diff)
downloadmpv-a3322cb171fed42bc3d15adc84d03cf560fc0fc9.tar.bz2
mpv-a3322cb171fed42bc3d15adc84d03cf560fc0fc9.tar.xz
osx_common: cache OSX version number
This commit makes `is_osx_version_at_least` cache the result of reading `/System/Library/CoreServices/SystemVersion.plist`. Since that is a file read operation it was bad to use this function frequently (i.e.: when processing user events). Remove `is_lion_or_above` (introduced in c9396c0a) as that was a more specialized wrapper which had the only advantage of adding it's own cache.
Diffstat (limited to 'video')
-rw-r--r--video/out/cocoa_common.m15
-rw-r--r--video/out/osx_common.m56
2 files changed, 34 insertions, 37 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 217321d593..27f8380112 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -147,20 +147,10 @@ static struct vo_cocoa_state *vo_cocoa_init_state(struct vo *vo)
return s;
}
-static bool is_lion_or_above()
-{
- static bool result = false, checked = false;
- if (!checked) {
- result = is_osx_version_at_least(10, 7, 0);
- checked = true;
- }
- return result;
-}
-
static bool supports_hidpi(NSView *view)
{
SEL hdpi_selector = @selector(setWantsBestResolutionOpenGLSurface:);
- return is_lion_or_above() && view &&
+ return is_osx_version_at_least(10, 7, 0) && view &&
[view respondsToSelector:hdpi_selector];
}
@@ -765,7 +755,8 @@ void create_menu()
delta = - [theEvent deltaX];
}
- if (is_lion_or_above() && [theEvent hasPreciseScrollingDeltas]) {
+ if (is_osx_version_at_least(10, 7, 0) &&
+ [theEvent hasPreciseScrollingDeltas]) {
s->accumulated_scroll += delta;
static const CGFloat threshold = 10;
while (s->accumulated_scroll >= threshold) {
diff --git a/video/out/osx_common.m b/video/out/osx_common.m
index 2d22fc52dc..38b3868f2c 100644
--- a/video/out/osx_common.m
+++ b/video/out/osx_common.m
@@ -124,33 +124,39 @@ int convert_key(unsigned key, unsigned charcode)
*/
int is_osx_version_at_least(int majorv, int minorv, int bugfixv)
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *plist = @"/System/Library/CoreServices/SystemVersion.plist";
- NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:plist];
- NSString *version = [dict objectForKey:@"ProductVersion"];
- NSArray *components = [version componentsSeparatedByString:@"."];
- int rv = 0;
-
- // All the above code just sends messages to nil. If anything failed,
- // we just end up with an invalid components array.
- if ([components count] != 3) {
- mp_msg(MSGT_VO, MSGL_ERR, "[osx] Failed to get your system version. "
- "Please open a bug report.\n");
- goto cleanup_and_return;
+ // Initialize cache
+ static int c_majorv = -1, c_minorv = -1, c_bugfixv = -1;
+
+ // If version cache is empty, fill it
+ if (c_majorv < 0 && c_minorv < 0 && c_bugfixv < 0) {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSString *plist = @"/System/Library/CoreServices/SystemVersion.plist";
+ NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:plist];
+ NSString *version = [dict objectForKey:@"ProductVersion"];
+ NSArray *components = [version componentsSeparatedByString:@"."];
+
+ // All the above code just sends messages to nil. If anything failed,
+ // we just end up with an invalid components array.
+ if ([components count] != 3) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[osx] Failed to get your system version. "
+ "Please open a bug report.\n");
+ [pool release];
+ return -1;
+ }
+
+ c_majorv = [[components objectAtIndex:0] intValue];
+ c_minorv = [[components objectAtIndex:1] intValue];
+ c_bugfixv = [[components objectAtIndex:2] intValue];
+
+ [pool release];
}
- int major = [[components objectAtIndex:0] intValue];
- int minor = [[components objectAtIndex:1] intValue];
- int bugfix = [[components objectAtIndex:2] intValue];
-
- if(major > majorv ||
- (major == majorv && (minor > minorv ||
- (minor == minorv && bugfix >= bugfixv))))
- rv = 1;
-
-cleanup_and_return:
- [pool release];
- return rv;
+ if(c_majorv > majorv ||
+ (c_majorv == majorv && (c_minorv > minorv ||
+ (c_minorv == minorv && c_bugfixv >= bugfixv))))
+ return 1;
+ else
+ return 0;
}
struct escape_couple {