When setBufferedToImage is set to true on a child component, and that component contains its own child components, the Direct2D renderer does not clear the buffered image correctly before repainting. This results in an accumulation of frames where past frames remain visible.
Using a custom CachedComponentImage with juce::SoftwareImageType() instead of the default juce::NativeImageType() prevents the issue. However, this causes an assertion failure in juce_RenderingHelpers.h on line 2203 when using high DPI screens with a scale greater than 1.0.
The issue can be demonstrated with a single JUCE slider component.
Direct2D renderer:
Custom CachedComponentImage using juce::SoftwareImageType():
With the code above, setting setBufferedToImage to true significantly increases CPU and GPU usage. When setBufferedToImage is false, CPU and GPU usage are below 1%. When setBufferedToImage is true, CPU usage increases up to 4x, and GPU usage increases up to 10x during repaints.
I found another bug when using setBufferedToImage(true) with the Direct2D renderer. If a parent component is semi-transparent and a child component is also transparent, the child component may turn opaque in specific situations, such as when dragging a slider.
The key to reproducing this bug, as well as the previous one I reported in this topic, is having the child component be a different size than the parent component. If both are the same size, the issue does not occur.
The images below demonstrate this issue while dragging a slider.
Direct2D renderer (JUCE 8 develop branch):
JUCE 7:
This issue doesn’t occur in JUCE 7 or when using a custom CachedComponentImage in JUCE 8 with juce::SoftwareImageType(), as shown in the images.
DocumentWindow has problems when it is transparent since JUCE8 that are apparently DAW-dependent. They’re quite different problem but both linked to transparency.
Thanks for reporting this issue, and for providing example code to reproduce the issue. Having examples always makes it much easier for us to track down issues.
In this particular case, I think we’re seeing some unexpected behaviour where Clear and D2D1_PRIMITIVE_BLEND_COPY don’t appear to replace alpha levels in the destination when rendering to a bitmap target while there’s a geometric clip layer active.
The examples you provided trigger this issue because a geometric clip was being used to reduce the drawing area before repainting regions of the buffered image.
I’ve pushed a change that seems to resolve the issue for me. It works by popping all active geometric clip layers and combining their clip regions into a single geometry, which we then fill using the BLEND_COPY mode. I’m not sure that this is the best solution - it’s still possible that I’ve missed some D2D setting that enables the expected behaviour, but I wasn’t able to find anything like that after a few days of experimenting and reading docs.
Please update to the latest develop branch to try out this change, and let us know if you’re still seeing issues. Thanks!