Skip to content

Commit 058d38a

Browse files
committed
Enabling Hardware Acceleration on RDP
1 parent f5be928 commit 058d38a

File tree

9 files changed

+83
-11
lines changed

9 files changed

+83
-11
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaSystem.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ public static bool Startup(MediaContext mc)
7979
}
8080
s_refCount++;
8181
}
82+
83+
/// <summary>
84+
/// Set renderOption if Hardware acceleration is enabled for RDP
85+
// </summary>
86+
87+
bool isHardwareAccelerationEnabledForRDP = false;
88+
AppContext.TryGetSwitch("System.Windows.Media.IsHardwareAccelerationEnabledForRDP", out isHardwareAccelerationEnabledForRDP);
89+
if(isHardwareAccelerationEnabledForRDP)
90+
{
91+
UnsafeNativeMethods.RenderOptions_EnableGraphicHwAccelerationForRDP(isHardwareAccelerationEnabledForRDP);
92+
}
8293
// Consider making MediaSystem.ConnectTransport return the state of transport connectedness so
8394
// that we can initialize the media system to a disconnected state.
8495

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/UnsafeNativeMethodsMilCoreApi.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ internal unsafe static extern void RenderOptions_ForceSoftwareRenderingModeForPr
208208
bool fForce);
209209

210210
[DllImport(DllImport.MilCore, EntryPoint = "RenderOptions_IsSoftwareRenderingForcedForProcess")]
211-
internal unsafe static extern bool RenderOptions_IsSoftwareRenderingForcedForProcess();
211+
internal unsafe static extern bool RenderOptions_IsSoftwareRenderingForcedForProcess();
212+
213+
[DllImport(DllImport.MilCore, EntryPoint = "RenderOptions_EnableGraphicHwAccelerationForRDP")]
214+
internal unsafe static extern bool RenderOptions_EnableGraphicHwAccelerationForRDP(bool value);
212215

213216
[DllImport(DllImport.MilCore, EntryPoint = "MilResource_CreateCWICWrapperBitmap")]
214217
internal unsafe static extern int /* HRESULT */ CreateCWICWrapperBitmap(

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/d3dutils.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,19 @@ GetMinimalTextureDesc(
232232
}
233233

234234
// If format is ok, restore HR from width/height check
235-
if (hr == S_OK)
235+
if (RenderOptions::IsGraphicHWAccelerationForRDPEnabled())
236236
{
237-
hr = hrWH;
237+
if(SUCCEEDED(hr))
238+
{
239+
hr = hrWH;
240+
}
241+
} else {
242+
if (hr == S_OK)
243+
{
244+
hr = hrWH;
245+
}
238246
}
247+
239248
}
240249

241250
#if DBG
@@ -315,8 +324,3 @@ GetSuperiorSurfaceFormat(
315324

316325
return D3DFMT_UNKNOWN;
317326
}
318-
319-
320-
321-
322-

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ CDisplaySet::GetGraphicsAccelerationCaps(
21252125
*pulDisplayUniqueness = m_ulDisplayUniquenessLoader;
21262126
}
21272127

2128-
if (m_rgpDisplays.GetCount() == 0 || m_fNonLocalDevicePresent)
2128+
if (m_rgpDisplays.GetCount() == 0 || (!RenderOptions::IsGraphicHWAccelerationForRDPEnabled() && m_fNonLocalDevicePresent))
21292129
{
21302130
//
21312131
// No display - no acceleration

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/renderoptions.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ RenderOptions_IsSoftwareRenderingForcedForProcess()
2323
return RenderOptions::IsSoftwareRenderingForcedForProcess();
2424
}
2525

26+
void WINAPI
27+
RenderOptions_EnableGraphicHwAccelerationForRDP(BOOL value)
28+
{
29+
RenderOptions::EnableGraphicHwAccelerationForRDP(value);
30+
}
31+
2632
// m_cs must be entered before accessing m_fForceSoftware because multiple
2733
// managed threads plus the render thread could try to access it
2834
static CCriticalSection m_cs;
2935
static bool m_fForceSoftware;
36+
static bool m_fHwAccelerationForRDPEnabled;
3037

3138
//+---------------------------------------------------------------------------------
3239
//
@@ -41,6 +48,7 @@ HRESULT
4148
RenderOptions::Init()
4249
{
4350
m_fForceSoftware = false;
51+
m_fHwAccelerationForRDPEnabled = false;
4452
RRETURN(m_cs.Init());
4553
}
4654

@@ -94,4 +102,30 @@ RenderOptions::IsSoftwareRenderingForcedForProcess()
94102
return m_fForceSoftware;
95103
}
96104

105+
//+---------------------------------------------------------------------------------
106+
//
107+
// RenderOptions::EnableGraphicHwAccelerationForRDP
108+
//
109+
// Synopsis: Sets whether or not Hardware Acceleration should be enabled for RDP.
110+
//
111+
//----------------------------------------------------------------------------------
112+
void
113+
RenderOptions::EnableGraphicHwAccelerationForRDP(BOOL value)
114+
{
115+
CGuard<CCriticalSection> guard(m_cs);
116+
m_fHwAccelerationForRDPEnabled = !!value;
117+
}
118+
119+
//+---------------------------------------------------------------------------------
120+
//
121+
// RenderOptions::IsGraphicHWAccelerationForRDPEnabled
122+
//
123+
// Synopsis: return whether or not Hardware Acceleration for RDP is enabled.
124+
//
125+
//----------------------------------------------------------------------------------
126+
BOOL
127+
RenderOptions::IsGraphicHWAccelerationForRDPEnabled()
128+
{
129+
return m_fHwAccelerationForRDPEnabled;
130+
}
97131

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/common/renderoptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace RenderOptions
1818
void ForceSoftwareRenderingForProcess(BOOL fForce);
1919

2020
BOOL IsSoftwareRenderingForcedForProcess();
21+
22+
void EnableGraphicHwAccelerationForRDP(BOOL value);
23+
24+
BOOL IsGraphicHWAccelerationForRDPEnabled();
2125
};
2226

2327

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/dll/wpfgfx.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ EXPORTS
137137

138138
RenderOptions_ForceSoftwareRenderingModeForProcess
139139
RenderOptions_IsSoftwareRenderingForcedForProcess
140+
RenderOptions_EnableGraphicHwAccelerationForRDP
140141

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/hw/hwbitmapcolorsource.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,20 @@ CHwBitmapColorSource::ComputeRealizationParameters(
14211421
&uLevels
14221422
);
14231423

1424-
Assert(pDevice->GetMinimalTextureDesc(
1424+
if(RenderOptions::IsGraphicHWAccelerationForRDPEnabled())
1425+
{
1426+
Assert(SUCCEEDED(pDevice->GetMinimalTextureDesc(
1427+
&d3dsdRequired,
1428+
TRUE,
1429+
(GMTD_CHECK_ALL |
1430+
(TextureAddressingAllowsConditionalNonPower2Usage(
1431+
oRealizationParams.dlU.d3dta,
1432+
oRealizationParams.dlV.d3dta) ?
1433+
GMTD_NONPOW2CONDITIONAL_OK : 0)
1434+
)
1435+
)));
1436+
} else {
1437+
Assert(pDevice->GetMinimalTextureDesc(
14251438
&d3dsdRequired,
14261439
TRUE,
14271440
(GMTD_CHECK_ALL |
@@ -1431,6 +1444,8 @@ CHwBitmapColorSource::ComputeRealizationParameters(
14311444
GMTD_NONPOW2CONDITIONAL_OK : 0)
14321445
)
14331446
) == S_OK);
1447+
}
1448+
14341449
}
14351450
#endif
14361451

src/Microsoft.DotNet.Wpf/src/WpfGfx/core/meta/desktoprt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ HRESULT CDesktopRenderTarget::Create(
9393
// check whether any adapters don't support Hw acceleration or D3D is not
9494
// available.
9595
//
96-
if ( pDisplaySet->IsNonLocalDisplayPresent()
96+
if ( (!(RenderOptions::IsGraphicHWAccelerationForRDPEnabled()) && pDisplaySet->IsNonLocalDisplayPresent())
9797
|| !pDisplaySet->D3DObject())
9898
{
9999
// If possible, just revert to Sw. This simply prevents trying Hw and

0 commit comments

Comments
 (0)