Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving performance of AttachedCardShadow by clipping inner content via CompositionMaskBrush #4410

Closed
michael-hawker opened this issue Dec 1, 2021 Discussed in #4396 · 2 comments · Fixed by #4404
Closed

Comments

@michael-hawker
Copy link
Member

Discussed in #4396

Originally posted by Ryken100 November 24, 2021
DWM can struggle to clip visuals using rounded rectangle geometry, which leads to reduced framerates on lower end devices when lots of elements with CornerRadius set rendered are on screen at once. Clipping AttachedCardShadow with CompositionGeometricClip can double this performance burden, where you have a Control with CornerRadius set, and then a shadow on top with its corners being rounded and clipped in a similar manner.

To improve performance in this area, I've started working on a feature to mask shadows with CompositionMaskBrush, instead of clipping them with CompositionGeometricClip, via the following steps:

  • Create a ShapeVisual with rounded rectangle geometry that has a thick outline and no fill (similar to the geometry we currently use to clip shadows)
  • Create a CompositionVisualSurface + CompositionSurfaceBrush from the ShapeVisual created in the previous step
  • Create a CompositionVisualSurface + CompositionSurfaceBrush from the SpriteVisual that hosts the DropShadow
  • Create a CompositionMaskBrush
    • Set Mask to the CompositionSurfaceBrush made from the ShapeVisual
    • Set Source to the CompositionSurfaceBrush made from the SpriteVisual that hosts the DropShadow
  • Create a new SpriteVisual and set its Brush to the CompositionMaskBrush from the previous step
  • Set the SpriteVisual from the previous step as the child of the UIElement the AttachedCardShadow is being attached to

Following these steps, the inner content of the AttachedCardShadow will be masked out with a texture rather than clipped out with geometry, while maintaining a similar visual effect. While there is still geometry involved, the geometry is part of a visual, rather than part of a clip, so DWM handles it better performance-wise (for some reason).

One drawback of using this method is that the corners of the shadow will appear more aliased, this is mostly unnoticeable on a low opacity shadow, but may be more apparent when the shadow's opacity is higher. So I'm including an API to choose clipping/masking methods, between CompositionGeometricClip and CompositionMaskBrush.

Please chip in if you have any ideas or suggestions to add :D

@ghost ghost added the needs triage 🔍 label Dec 1, 2021
@ghost
Copy link

ghost commented Dec 1, 2021

Hello michael-hawker, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

@michael-hawker
Copy link
Member Author

FYI @Ryken100 (need to ping you to assign to you)

@ghost ghost added Completed 🔥 and removed In-PR 🚀 labels May 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2022
@michael-hawker michael-hawker modified the milestones: 8.0, 7.1.3 Jul 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
1 participant