[vlc-commits] [Git][videolan/vlc][master] 4 commits: caopengllayer: try to select low power gpu on macos

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Sep 8 15:06:10 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
6ce5935d by Jérémy Demeule at 2023-09-08T14:45:56+00:00
caopengllayer: try to select low power gpu on macos

VLC is not very demanding in OpenGL usage. Try to use low power GPU
even if it is not the default one selected by the OS.

- - - - -
df30e842 by Jérémy Demeule at 2023-09-08T14:45:56+00:00
Rename kCGLRendererIntelFamilly to kRendererIntelFamillyMask
Stop looking for low device on 1st match.
Fix typo

- - - - -
d5dfecbb by Jérémy Demeule at 2023-09-08T14:45:56+00:00
Fix typo

- - - - -
1ba609a0 by Jérémy Demeule at 2023-09-08T14:45:56+00:00
Change vlc_IsLowPowerDevice implementation

As the list of Apple machine on Intel platform is not a close set,
match only the known ones instead of deducing a pattern.

- - - - -


1 changed file:

- modules/video_output/caopengllayer.m


Changes:

=====================================
modules/video_output/caopengllayer.m
=====================================
@@ -119,6 +119,69 @@ typedef struct vout_display_sys_t {
 #pragma mark -
 #pragma mark OpenGL context helpers
 
+// kCGLRenderer* enum value define card value, but family is enough here.
+// However they follow some pattern by familly.
+#define kRendererIntelFamilyMask 0x00024000
+
+/*
+ * GL API does not provide a way to know if a device is a lowpower one.
+ * We could make some guess here:
+ * On a MacBookPro (intel):
+ *   - GeForce and Radeon card could be discrete or external.
+ *   - Intel could be integrated or external.
+ * To be check MacPro or MacMini or ARM ones.
+ */
+static bool vlc_IsLowPowerDevice(GLint renderer_id) {
+    int renderer_vendor = renderer_id & kCGLRendererIDMatchingMask;
+    // Consider Intel familly card as low power devices.
+    return renderer_vendor == kCGLRendererIntel900ID ||
+           renderer_vendor == kCGLRendererIntelX3100ID ||
+           renderer_vendor == kCGLRendererIntelHDID ||
+           renderer_vendor == kCGLRendererIntelHD4000ID ||
+           renderer_vendor == kCGLRendererIntelHD5000ID;
+}
+
+/*
+ * Search for a low power device.
+ * Without proper API (like Metal), here we try to look on all the available
+ * renderer and filter them.
+ * We are looking for the one attached to the main display, accelerated, and
+ * with low power consumption.
+ * Without any match, we let CGLChoosePixelFormat/CGLCreateContext do as before.
+ */
+static GLint vlc_SearchGLRendererId() {
+    CGLRendererInfoObj renderer_info = NULL;
+    GLint renderer_count = 0;
+    if (CGLQueryRendererInfo((GLuint)-1, &renderer_info, &renderer_count) !=
+        kCGLNoError)
+      return -1;
+
+    GLint best_match = -1;
+    for (GLint i = 0; i < renderer_count && best_match == -1; ++i) {
+      GLint renderer_id = -1;
+      if (CGLDescribeRenderer(renderer_info, i, kCGLRPRendererID,
+                              &renderer_id) != kCGLNoError)
+        break;
+      GLint accelerated = 0;
+      if (CGLDescribeRenderer(renderer_info, i, kCGLRPAccelerated,
+                              &accelerated) != kCGLNoError)
+        break;
+      if (!accelerated)
+        continue; // avoid not accelerated device
+      GLint display = -1;
+      if (CGLDescribeRenderer(renderer_info, i, kCGLRPDisplayMask, &display) !=
+          kCGLNoError)
+        break;
+      CGDirectDisplayID display_id = CGOpenGLDisplayMaskToDisplayID(display);
+      if (display_id != CGMainDisplayID())
+        continue;
+      if (vlc_IsLowPowerDevice(renderer_id))
+        best_match = renderer_id;
+    }
+    CGLDestroyRendererInfo(renderer_info);
+    return best_match;
+}
+
 /**
  * Create a new CGLContextObj for use by VLC
  * This function may try various pixel formats until it finds a suitable/compatible
@@ -132,7 +195,10 @@ CGLContextObj vlc_CreateCGLContext()
     CGLPixelFormatObj pix;
     CGLContextObj ctx;
 
-    CGLPixelFormatAttribute attribs[12] = {
+    GLint renderer_id = vlc_SearchGLRendererId();
+
+    CGLPixelFormatAttribute attribs[15] = {
+        kCGLPFAAllRenderers,
         kCGLPFAAllowOfflineRenderers,
         kCGLPFADoubleBuffer,
         kCGLPFAAccelerated,
@@ -148,6 +214,12 @@ CGLContextObj vlc_CreateCGLContext()
         0
     };
 
+    // A low power renderer was found, ask to use it.
+    if (renderer_id != -1) {
+        attribs[12] = kCGLPFARendererID;
+        attribs[13] = renderer_id;
+        attribs[14] = 0;
+    }
     err = CGLChoosePixelFormat(attribs, &pix, &npix);
     if (err != kCGLNoError || pix == NULL) {
         return NULL;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/728a7c40925a31d2c8dea92d7e3e93401790c087...1ba609a02886c55e28a08d27cb04bd98764a0aa9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/728a7c40925a31d2c8dea92d7e3e93401790c087...1ba609a02886c55e28a08d27cb04bd98764a0aa9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list