Should opaque children repaint the parent?

Hi,

I’m attempting to improve the painting performance in a standalone app. My first step is to ensure that as many children become opaque. However, it appears that even when opaque children are repainted, the parent paint method is still invoked. The JUCE documentation states that “objects underneath opaque windows don’t need to be painted ,” leading me to assume that when children are repainted, the parent is not. However, upon enabling JUCE_ENABLE_REPAINT_DEBUGGING, I observed that the parent is indeed repainted when an opaque child undergoes repainting. Additionally, I’ve created a small example that logs the paint calls.

class MainComponent  : public juce::Component
{
public:
    MainComponent()
    {
        setSize (600, 400);
        
        addAndMakeVisible(rect);
        rect.setBounds(getLocalBounds().reduced(50));
    }

    void paint (juce::Graphics& g) override
    {
        DBG(juce::Time::getCurrentTime().toString(false, true) << " --- MainComponent::paint");
        g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
    }

    struct Rect : juce::Component, juce::Timer
    {
        Rect()
        {
            setOpaque(true);
            startTimerHz(1);
        }
        
        void paint(juce::Graphics& g) override
        {
            DBG(juce::Time::getCurrentTime().toString(false, true) << " --- Rect::paint");
            g.fillAll(juce::Colours::white);
        }
        
        void timerCallback() override
        {
            repaint();
        }
    };

    Rect rect;
};

Output:

3:27:58pm --- MainComponent::paint
3:27:58pm --- Rect::paint
3:27:59pm --- MainComponent::paint
3:27:59pm --- Rect::paint
3:28:00pm --- MainComponent::paint
3:28:00pm --- Rect::paint
3:28:01pm --- MainComponent::paint
3:28:01pm --- Rect::paint
3:28:02pm --- MainComponent::paint
3:28:02pm --- Rect::paint

I run this with JUCE 7.0.9 on an Apple M1 machine with macOS 14.2.1

Is this expected behaviour?

Best,

Jelle

Hey ! - I’ve exactly dealt with the same problem recently. But solved it with the following Preprocessor Directive “JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS=1” which I’ve included in the Jucer…

Thant solved my problem with opaque not working…

BR
Bo

2 Likes

We recently also discovered that we accidentally missed this define when switching from Projucer to cmake. This caused our plugin to lag horrifically, to the point that it slowed down drawing in the DAW as well.

Once we added the definition back, the drawing became butter-smooth again. This one is a doozy and should be enabled by default, IMO.

2 Likes