Browse Source

Add platform functions to request high performance modes

Specifically, this disables App Nap and related features
on OSX 10.9+
Palana 11 years ago
parent
commit
571dd0f166
4 changed files with 59 additions and 0 deletions
  1. 29 0
      libobs/util/platform-cocoa.m
  2. 14 0
      libobs/util/platform-nix.c
  3. 12 0
      libobs/util/platform-windows.c
  4. 4 0
      libobs/util/platform.h

+ 29 - 0
libobs/util/platform-cocoa.m

@@ -185,3 +185,32 @@ void os_cpu_usage_info_destroy(os_cpu_usage_info_t info)
 	if (info)
 		bfree(info);
 }
+
+os_performance_token_t os_request_high_performance(const char *reason)
+{
+	@autoreleasepool {
+		NSProcessInfo *pi = [NSProcessInfo processInfo];
+		SEL sel = @selector(beginActivityWithOptions:reason:);
+		if (![pi respondsToSelector:sel])
+			return nil;
+
+		//taken from http://stackoverflow.com/a/20100906
+		id activity = [pi beginActivityWithOptions:0x00FFFFFF 
+						    reason:@(reason)];
+
+		return CFBridgingRetain(activity);
+	}
+}
+
+void os_end_high_performance(os_performance_token_t token)
+{
+	@autoreleasepool {
+		NSProcessInfo *pi = [NSProcessInfo processInfo];
+		SEL sel = @selector(beginActivityWithOptions:reason:);
+		if (![pi respondsToSelector:sel])
+			return;
+
+		[pi endActivity:CFBridgingRelease(token)];
+	}
+}
+

+ 14 - 0
libobs/util/platform-nix.c

@@ -294,3 +294,17 @@ int os_mkdir(const char *path)
 
 	return (errno == EEXIST) ? MKDIR_EXISTS : MKDIR_ERROR;
 }
+
+#if !defined(__APPLE__)
+os_performance_token_t os_request_high_performance(const char *reason)
+{
+	UNUSED_PARAMETER(reason);
+	return NULL;
+}
+
+void os_end_high_performance(os_performance_token_t token)
+{
+	UNUSED_PARAMETER(token);
+}
+#endif
+

+ 12 - 0
libobs/util/platform-windows.c

@@ -432,3 +432,15 @@ BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
 	UNUSED_PARAMETER(reserved);
 	return true;
 }
+
+os_performance_token_t os_request_high_performance(const char *reason)
+{
+	UNUSED_PARAMETER(reason);
+	return NULL;
+}
+
+void os_end_high_performance(os_performance_token_t token)
+{
+	UNUSED_PARAMETER(token);
+}
+

+ 4 - 0
libobs/util/platform.h

@@ -76,6 +76,10 @@ EXPORT os_cpu_usage_info_t os_cpu_usage_info_start(void);
 EXPORT double              os_cpu_usage_info_query(os_cpu_usage_info_t info);
 EXPORT void                os_cpu_usage_info_destroy(os_cpu_usage_info_t info);
 
+typedef const void *os_performance_token_t;
+EXPORT os_performance_token_t os_request_high_performance(const char *reason);
+EXPORT void                   os_end_high_performance(os_performance_token_t);
+
 /**
  * Sleeps to a specific time (in nanoseconds).  Doesn't have to be super
  * accurate in terms of actual slept time because the target time is ensured.