[NSImage setTemplate:] discrete GPU issue on some MacBook models

Problem:


On some MacBook models (e.g. MacBook Pro 15-inch, Late 2011), the discrete GPU is enabled when you call setTemplate: on a NSImage instance.


This is a bit problematic considering that if you're writing a NSStatusItem, this is, AFAIK, the way to make sure the icon will be drawn correctly when you click the status item in the menu bar.


Discussion:


- Yes, I'm sure the problem happens with the setTemplate: method. It's problably due to the fact this method is calling some CoreImage stuff behind the scene.


- It's not related to the type of images, this problem occurs with both PNGs and the PDF images from Apple own menu extras.


- Something strange is while this problem occurs with my status item, this problem does not apparently occur with Apple menu extras (e.g. the Display one which calls setTemplate: on the PDF image used for the icon).


Question:


Is there a way to avoid turning on the discrete GPU when calling - [NSImage setTemplate:] from a 3rd party application?


Note:


This does not happen with a MacBook Pro Retina for instance.

Replies

The suggested solution in the QA article below seems to fix the issue:


https://developer.apple.com/library/content/qa/qa1734/_index.html