Hi everyone, I know this is a recurrent topic but I haven’t found an optimal solution yet.
There is a huge difference in performance using drawImage() between Windows and MacOS with Retina. I know that maybe using OpenGL would be the best solution but for now, I’m trying to avoid this. After some research, I’ve found that it seems to be a CoreGraphics problem and not only affects JUCE. Reading through forum topics I’ve found that using Desktop::getInstance().getDisplays().getMainDisplay().scale
and scaling the image using that scaling factor (double of the original resolution in the case of Retina) and then rescaling it to the original size before painting solves the performance problem. This approach seems to me a bit “hacky” and I don’t know if there exists a better solution.
First of all, the images are not painted in the message thread. These images are concurrently read (from message thread in order to paint them in the main context) and written(painted). The performance problem is not caused by concurrent accesses to the images because I’ve made them non-blocking and when I use the scaling “trick” the problem is solved.
I made a minimum working example if someone wants to check it out. It only contains the drawImage stuff but it’s enough for realizing that there is a huge difference:
Link: drawImage mwe
void MainComponent::paint(Graphics& g)
{
auto scale = 1;
//scale = Desktop::getInstance().getDisplays().getMainDisplay().scale;
// This is done in other thread
auto image = Image(Image::ARGB, getWidth() * scale, getHeight() * scale, true);
juce::Graphics imageContext(image);
imageContext.setColour(Colours::white);
if (pos >= image.getWidth())
pos = 0;
imageContext.fillRect(Rectangle<int>(pos, image.getHeight() / 2, 100 * scale, 100 * scale));
pos += 5 * scale; // initialized to 0 in .h
// This is done in message thread
g.drawImage(image, 0, 0, getWidth(), getHeight(), 0, 0, image.getWidth(), image.getHeight());
}
If scale = Desktop::getInstance()...
is uncommented the problem is totally solved and I can’t see no difference between MacOS and Win (no profiling done with the mwe).
Is there any way that I’m missing that JUCE can handle this? The problem of this trick is that this scaling factor is propagated to everything that is painted in these images (i.e. text, lines, rectangles…) in case you want to mantain the sizes of these objects between MacOS and Win. And btw, why this trick works?