gco / xee

Automatically exported from code.google.com/p/xee
72 stars 8 forks source link

Don't force using the dedicated GPU #346

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Xee (both 2 and 3) is currently forcing a GPU switch to the dedicated GPU, on 
machines that have both an integrated and dedicated GPU and can switch between 
the two on demand. This impacts battery life and seems a bit unneeded for 
viewing images.

I attempted to fix this for Xee 2 (since 3 is no longer open-source – bought 
it already through Paddle, by the way!), by reading the documentation available 
here https://developer.apple.com/library/mac/#qa/qa1734/_index.html and 
http://developer.apple.com/library/mac/#technotes/tn2229/_index.html, followed 
by eventually asking the Apple mailing lists for help here: 
http://lists.apple.com/archives/cocoa-dev/2013/Jun/thrd2.html#00135

It seems that setting the OpenGL pixel format NSOpenGLPFAAllowOfflineRenderers 
when initializing the OpenGL context(s) and setting the 
NSSupportsAutomaticGraphicsSwitching property in the app's Info.plist is all 
that is needed to do the trick. This is the corresponding change at the 
beginning of the initWithFrame method in XeeView:

    NSOpenGLPixelFormatAttribute attribs[] =
    {
        NSOpenGLPFAAllowOfflineRenderers,
        (NSOpenGLPixelFormatAttribute)0
    };

    NSOpenGLPixelFormat *format=  [[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs] autorelease];

    if(self=[super initWithFrame:frameRect pixelFormat:format])

And in Info.plist, of course:

    <key>NSSupportsAutomaticGraphicsSwitching</key>
    <true/>

I don't know if you're still using (a subclass of) NSOpenGLView in Xee 3, but 
if you are, hopefully you can fix it in this way as well! 

Original issue reported on code.google.com by miguelpontes on 12 Jun 2013 at 12:43

GoogleCodeExporter commented 9 years ago
Oh, interesting.

I can't test this myself, but when I do some updates again I will try adding 
it, and send you back a version to test.

Original comment by paracel...@gmail.com on 12 Jun 2013 at 12:47

GoogleCodeExporter commented 9 years ago
Yep, thanks!

I managed to compile a build of Xee 2 with that fix and everything seems to 
work properly without switching the GPU, so hopefully the fix will be the same 
(or similar) in 3.

Original comment by miguelpontes on 12 Jun 2013 at 1:03

GoogleCodeExporter commented 9 years ago
Can you test http://wakaba.c3.cx/stuff/Xee3.0.7-test.zip ? There is an option 
in the preferences to turn it on and off, try to see if that works too.

Original comment by paracel...@gmail.com on 8 Jul 2013 at 9:19

GoogleCodeExporter commented 9 years ago
Nope, checkbox makes no difference. It triggers the discrete GPU on both 
states, unfortunately.

Original comment by miguelpontes on 8 Jul 2013 at 9:27

GoogleCodeExporter commented 9 years ago
Hmm, then I am a bit lost. Does the Info.plist look correct?

Original comment by paracel...@gmail.com on 8 Jul 2013 at 9:30

GoogleCodeExporter commented 9 years ago
Yeah, it looks fine. NSSupportsAutomaticGraphicsSwitching = YES and 
NSOpenGLPFAAllowOfflineRenderers as the single attribute to NSOpenGLPixelFormat 
was enough for it to not trigger the discrete GPU for me on Xee 2.

Perhaps I should add that with Xee 2, the discrete GPU only kicks in once an 
image is loaded, while with Xee 3, the discrete GPU kicks in as soon as the app 
launches, even without any visible window at all (strange!). So perhaps there's 
something at the application's init that's causing the switch?

Original comment by miguelpontes on 8 Jul 2013 at 9:36

GoogleCodeExporter commented 9 years ago
Oh, that is a good clue. I think I am doing some testing for OpenGL context 
features on startup that might trigger something. Let's see.

Original comment by paracel...@gmail.com on 8 Jul 2013 at 10:05

GoogleCodeExporter commented 9 years ago
Try http://wakaba.c3.cx/stuff/Xee3.0.7-test2.zip 

Original comment by paracel...@gmail.com on 8 Jul 2013 at 10:23

GoogleCodeExporter commented 9 years ago
Yep, that does it! Checkbox does what it's supposed to do now.

Well, if you trigger the discrete GPU once, you need to quit and relaunch the 
app in order to go back, but I think that's how OS X behaves in general. As 
long as one starts the program with the box unticked, it seems like it won't 
trigger the discrete GPU at all.

Thanks!

Original comment by miguelpontes on 8 Jul 2013 at 10:38

GoogleCodeExporter commented 9 years ago
Yes, that sounds about right.  And thanks for the help getting this working!

Original comment by paracel...@gmail.com on 8 Jul 2013 at 10:43

GoogleCodeExporter commented 9 years ago
Seems like Mavericks breaks this.

I have "use discrete GPU if available" unchecked, but when loading certain 
kinds of images, Xee uses the discrete GPU anyway. JPEG uses dedicated. GIF 
does not.

I'm running Xee 3.3 on 10.9 Mavericks on a 2013 15" retina MacBook Pro.

Original comment by Aktariel on 5 Dec 2013 at 6:35

GoogleCodeExporter commented 9 years ago
No, it's 3.3 that breaks it. It uses the GPU more but I forgot to include code 
to handle the discrete GPU stuff. Will be fixed next version.

Original comment by paracel...@gmail.com on 5 Dec 2013 at 9:51

GoogleCodeExporter commented 9 years ago
Any way to downgrade to 3.2 in the meantime?

Original comment by Aktariel on 28 Feb 2014 at 8:01

GoogleCodeExporter commented 9 years ago
There are old versions in http://wakaba.c3.cx/releases/mac/old/

If you bought it through the App Store, I'm not sure if there's a way. I recall 
Apple adding something for that recently but haven't looked at it.

Original comment by paracel...@gmail.com on 28 Feb 2014 at 10:46

GoogleCodeExporter commented 9 years ago
Hopefully fixed now. Can't really test it, so report back and tell me if it's 
not working once the next version is out.

Original comment by paracel...@gmail.com on 6 Jul 2014 at 9:42