microsoft / microsoft/microsoft-ui-xaml
WinUI3: Why doesn't Microsoft::UI::Compostion::ICompositionDrawingSurfaceInterop work well on RDP after migrating from UWP?
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
Drawing a custom DataGrid control using DirectX in conjunction with CompositionDrawingSurface worked well in a UWP application. However, after migrating to WinUI3, it no longer works efficiently on RDP. Therefore, we consider this a bug.
### Why is this important?
Most of our clients run on RDP. The new version of the ERP application we migrated from UWP to WinUI3 has lost performance when browsing data. This is a very significant issue. We've wasted a significant amount of resources migrating to WinUI3, and it's proving fruitless.
### Steps to reproduce the bug
I draw content using DirectX (ID2D1DeviceContext) in a bound XAML control.
I do this using Microsoft::UI::Compostion::ICompositionDrawingSurfaceInterop (m_drawingSurfaceInterop).
I have a XAML element (m_grid) bound to the CompositionDrawingSurface like this:
```
SpriteVisual spriteVisual{ m_compositor.CreateSpriteVisual() };
CompositionSurfaceBrush surfaceBrush{
m_compositor.CreateSurfaceBrush(m_drawingSurfaceInterop.as()) };
surfaceBrush.Scale({ 96.0f / dpx,96.0f / dpx });
surfaceBrush.HorizontalAlignmentRatio(0);
surfaceBrush.VerticalAlignmentRatio(0);
surfaceBrush.Stretch(CompositionStretch::None);
spriteVisual.Brush(surfaceBrush);
spriteVisual.RelativeSizeAdjustment({ 1.0f,1.0f });
spriteVisual.Offset({ 0,0,0 });
MUX:Hosting::ElementCompositionPreview::SetElementChildVisual(m_grid, spriteVisual);
```
### Actual behavior
1. Very importantly, why did this solution work efficiently on UWP on remote RDP desktops, but not on RDP after migrating to WinUI3 (NS Microsoft.UI). Drawing is about 80 times slower on RDP than on the local desktop. For example, scrolling is terrible; it's impossible to work. I'd appreciate some help with the CompositionDrawingSurface architecture, as even converting it to SwapChain doesn't provide the same rendering performance on RDP as it did on UWP using CompositionDrawingSurface. There's also no way to bind SwapChain to CompositionDrawingSurface in WinUI3.
2. I also don't understand why I have to scale the surface to maintain the correct resolution of rendered text. (The scaling method in the code above works, but the question is why this code is needed, since the CompositionDrawingSurface is retrieved from the Composer's device and it knows the resolution.)
### Expected behavior
1. We are testing the same code on UWP and WinUI3 (another Microsoft NS.UI).
WinUI3 renders using CompositionDrawingSurface on RDP on average 80 times slower than the same code on UWP. Performance should be similar.
2. Drawing and rendering graphics using ID2D1DeviceContext should not be subject to target surface scaling distortions by default.
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.8.0: 1.8.250907003
### Windows version
_No response_
### Additional context
_No response_
Contributor guide
Research direction
The issue names no repository files or tests; start with the custom DataGrid path using ID2D1DeviceContext, ICompositionDrawingSurfaceInterop, CompositionDrawingSurface, and ElementCompositionPreview. Build a minimal WinUI 3 1.8 RDP reproduction and compare it with the stated UWP behavior, including the surface scaling code. Done should mean a confirmed cause and documented expected behavior or a narrowly defined fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100