I am implementing switching between graphics for high and standard DPI displays in my plugin.
On OS X, on my 15" retina MacBook Pro, the main display (Desktop::getInstance ().getDisplays ().getMainDisplay ()) is reported to have a DPI of 144, while it is in fact ~220.
Why is that and is this a reliable way to switch between graphics (auto-scaling the larger images just doesn’t cut it, so I need to have 2 versions of all graphic resources of the plugin)?
JUCE uses a system of “logical” rather than “physical” pixels to calculate UI sizes, so it will report the same logical sizes for objects across DPI settings while scaling in the background to match different physical pixel counts.
I’m not sure why auto-scaling images wouldn’t work for you (assuming you’re starting from a sufficiently high resolution image to match your highest supported DPI), but I suppose like you said you could include multiple acceptable sizes of your image resources. That’s how rasterized resources are handled in Apple products, FWIW.
Use Desktop::getInstance().getDisplays() to get an Displays object which contains an Array of Display structs, one for each display. Figure out which display your window is on via Display::getDisplayContaining with the desktop position of your window (via the window’s ::getPosition() method). You can then use the dpi member of the Display struct to get the display’s DPI.
A handy shortcut for quick testing is to just assume the main display’s DPI everywhere by using the single call Desktop::getInstance().getDisplays().getMainDisplay().dpi.