Skip to content

Fix RenderTargetBitmap looses effects#20790

Open
timunie wants to merge 9 commits intoAvaloniaUI:masterfrom
timunie:fix/RTB_ignores_Shadow
Open

Fix RenderTargetBitmap looses effects#20790
timunie wants to merge 9 commits intoAvaloniaUI:masterfrom
timunie:fix/RTB_ignores_Shadow

Conversation

@timunie
Copy link
Collaborator

@timunie timunie commented Mar 2, 2026

What does the pull request do?

RTB currently does not render effects such as BoxShadow. This is caused by immediate renderer which has no API for it.

What is the current behavior?

Effects are excluded from the RTB

What is the updated/expected behavior with this PR?

RTB can also save effects

How was the solution implemented (if it's not obvious)?

Added the needed Push / Pop-Effect methods

Checklist

Breaking changes

this adds Effect as a new API member

Obsoletions / Deprecations

Fixed issues

Fixes #20779
Fixes #19519 (cc @evanchen6185 if you want to add some feedback on this topic)

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062807-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug area-rendering backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Mar 2, 2026
@kekekeks kekekeks requested a review from Copilot March 2, 2026 17:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes missing effect rendering (e.g., DropShadowEffect/BoxShadow) when rendering via RenderTargetBitmap.Render by introducing effect push/pop support in DrawingContext implementations and wiring effects into the immediate renderer/recording paths.

Changes:

  • Added DrawingContext.PushEffect(...) / PopEffectCore() plumbing across platform and composition drawing contexts.
  • Updated ImmediateRenderer to apply Visual.Effect during immediate (RTB) rendering.
  • Added/updated Skia render tests + expected PNGs to cover RTB effects and DrawingGroup effects.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Avalonia.Base/Media/DrawingContext.cs Adds public PushEffect + new abstract core methods and restore-state handling.
src/Avalonia.Base/Rendering/ImmediateRenderer.cs Pushes Visual.Effect during immediate tree traversal.
src/Avalonia.Base/Media/PlatformDrawingContext.cs Implements effect push/pop for platform contexts that support effects.
src/Avalonia.Base/Rendering/Composition/Drawing/RenderDataDrawingContext.cs Records effect nodes into composition render data.
src/Avalonia.Base/Rendering/Composition/Drawing/Nodes/RenderDataNodes.cs Adds a render-data node to push/pop effects at playback time.
src/Avalonia.Base/Media/DrawingGroup.cs Adds Effect property and records effect pushes when building drawing groups.
tests/Avalonia.RenderTests/Media/RenderTargetBitmapTests.cs Adds RTB regression test for DropShadow rendering.
tests/Avalonia.RenderTests/Media/DrawingContextTests.cs Adds render test for DrawingGroup with an effect push.
tests/Avalonia.Controls.UnitTests/Shapes/ShapeTests.cs Updates test drawing context stub for new abstract methods.
tests/TestFiles/.../*.expected.png Adds/updates expected outputs for new effect rendering behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062839-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@timunie timunie force-pushed the fix/RTB_ignores_Shadow branch from 32413df to 4f36cf4 Compare March 5, 2026 18:59
@timunie timunie requested a review from Copilot March 5, 2026 19:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063040-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/Avalonia.Base/Rendering/ImmediateRenderer.cs:73

  • ImmediateRenderer still uses visualBounds = rect.TransformToAABB(totalTransform) for culling, which ignores the extra pixels produced by visual.Effect (blur/drop shadow). This can cause a visual to be skipped entirely when its original bounds are outside clipRect but its effect output would intersect it. Consider inflating rect (or visualBounds) by effect.GetEffectOutputPadding() before the intersection test, similar to how compositor subtree bounds are inflated for effects.
            var totalTransform = transform * parentTransform;
            var visualBounds = rect.TransformToAABB(totalTransform);

            if (visualBounds.Intersects(clipRect))
            {
                visual.Render(context);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063090-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@emmauss emmauss requested review from MrJul and Copilot March 19, 2026 13:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

timunie and others added 2 commits March 19, 2026 19:29
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-rendering backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RenderTargetBitmap.Render does not render DropShadowEffect on controls PushEffect on DrawingContext

4 participants