@@ -232,10 +232,19 @@ GetMinimalTextureDesc(
232
232
}
233
233
234
234
// If format is ok, restore HR from width/height check
235
- if (hr == S_OK )
235
+ if (:: IsGraphicHWAccelerationForRDPEnabled () )
236
236
{
237
- hr = hrWH;
237
+ if (SUCCEEDED (hr))
238
+ {
239
+ hr = hrWH;
240
+ }
241
+ } else {
242
+ if (hr == S_OK)
243
+ {
244
+ hr = hrWH;
245
+ }
238
246
}
247
+
239
248
}
240
249
241
250
#if DBG
@@ -316,7 +325,84 @@ GetSuperiorSurfaceFormat(
316
325
return D3DFMT_UNKNOWN;
317
326
}
318
327
328
+ // +------------------------------------------------------------------------
329
+ //
330
+ // Function: IsGraphicHWAccelerationForRDPEnabled
331
+ //
332
+ // Synopsis:
333
+ // Checks to see if user has enabled graphich hardware acceleration in remote connection.
334
+ // An app can opt-in to enable HW acceleration by setting a regkey in
335
+ // HKCU\Software\Microsoft\Avalon.Graphics\EnableRemoteHWAcceleration
336
+ // or
337
+ // HKLM\Software\Microsoft\Avalon.Graphics\EnableRemoteHWAcceleration
338
+ // whose name is the full path to the .exe that wants to opt-in, and whose DWORD value is 1.
339
+ //
340
+ // The regkey is checked in the first call to this function, and the
341
+ // value is cached for all future calls in this process.
342
+ //
343
+ // -------------------------------------------------------------------------
344
+ bool
345
+ IsGraphicHWAccelerationForRDPEnabled ()
346
+ {
347
+ enum IsRemoteHWAccelerationEnabledState
348
+ {
349
+ HWAcceleration_Uninitialized,
350
+ HWAcceleration_False,
351
+ HWAcceleration_True,
352
+ };
353
+ static IsRemoteHWAccelerationEnabledState s_hwAccelerationFlag = IsRemoteHWAccelerationEnabledState::HWAcceleration_Uninitialized;
354
+ if (s_hwAccelerationFlag == IsRemoteHWAccelerationEnabledState::HWAcceleration_Uninitialized)
355
+ {
356
+ TCHAR szFullPath[MAX_PATH];
357
+ DWORD cFullPath = GetModuleFileName (NULL , szFullPath, sizeof (szFullPath) / sizeof (szFullPath[0 ]));
319
358
320
-
321
-
322
-
359
+ if (cFullPath > 0 )
360
+ {
361
+ // First check for a value in HKCU (which should override any HKLM setting).
362
+ HKEY hKey = NULL ;
363
+ LONG r = RegOpenKeyEx (
364
+ HKEY_CURRENT_USER,
365
+ _T (" Software\\ Microsoft\\ Avalon.Graphics\\ EnableRemoteHWAcceleration" ),
366
+ 0 ,
367
+ KEY_QUERY_VALUE,
368
+ &hKey
369
+ );
370
+ if (r == ERROR_SUCCESS)
371
+ {
372
+ DWORD dwValue = 0 ; // default to false (don't ignore errors)
373
+ if (RegGetDword (hKey, szFullPath, &dwValue))
374
+ {
375
+ s_hwAccelerationFlag = (dwValue == 0 ) ? IsRemoteHWAccelerationEnabledState::HWAcceleration_False : IsRemoteHWAccelerationEnabledState::HWAcceleration_True;
376
+ }
377
+ RegCloseKey (hKey);
378
+ }
379
+ // If we didn't set a value from HKCU, try HKLM.
380
+ if (s_hwAccelerationFlag == IsRemoteHWAccelerationEnabledState::HWAcceleration_Uninitialized)
381
+ {
382
+ r = RegOpenKeyEx (
383
+ HKEY_LOCAL_MACHINE,
384
+ _T (" Software\\ Microsoft\\ Avalon.Graphics\\ EnableRemoteHWAcceleration" ),
385
+ 0 ,
386
+ KEY_QUERY_VALUE,
387
+ &hKey
388
+ );
389
+ if (r == ERROR_SUCCESS)
390
+ {
391
+ DWORD dwValue = 0 ; // default to false (don't ignore errors)
392
+ if (RegGetDword (hKey, szFullPath, &dwValue))
393
+ {
394
+ s_hwAccelerationFlag = (dwValue == 0 ) ? IsRemoteHWAccelerationEnabledState::HWAcceleration_False : IsRemoteHWAccelerationEnabledState::HWAcceleration_True;
395
+ }
396
+ RegCloseKey (hKey);
397
+ }
398
+ }
399
+ }
400
+ // If we still haven't set a value, then no value was set in the registry.
401
+ // Default to false (disable HW acceleration in remote connection).
402
+ if (s_hwAccelerationFlag == IsRemoteHWAccelerationEnabledState::HWAcceleration_Uninitialized)
403
+ {
404
+ s_hwAccelerationFlag = IsRemoteHWAccelerationEnabledState::HWAcceleration_False;
405
+ }
406
+ }
407
+ return (s_hwAccelerationFlag == IsRemoteHWAccelerationEnabledState::HWAcceleration_True);
408
+ }
0 commit comments