Skip to content

Commit

Permalink
Add support for Windows 11 24H2 Graphics Capture features
Browse files Browse the repository at this point in the history
The required SDK comes with some caveats with the current build setup and as such is not used by default (Desktop+ will stay a VS2019 project for the time being).

- Add support for automatically enabling IncludeSecondaryWindows property if possible
- Add support for using MinUpdateInterval property instead of our own update limiter if possible
- Add DPWinRT_IsIncludeSecondaryWindowsPropertySupported() & DPWinRT_IsMinUpdateIntervalPropertySupported() to log capabilities on launch
- Use winrt::name_of<winrt::GraphicsCaptureSession>() instead of L"Windows.Graphics.Capture.GraphicsCaptureSession" when querying property availability
  • Loading branch information
elvissteinjr committed Sep 13, 2024
1 parent 16a2250 commit ed565f8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
30 changes: 29 additions & 1 deletion src/DesktopPlusWinRT/DesktopPlusWinRT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,35 @@ bool DPWinRT_IsBorderRequiredPropertySupported()
{
#ifndef DPLUSWINRT_STUB
#if WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION >= 0xc0000
if (winrt::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Graphics.Capture.GraphicsCaptureSession", L"IsBorderRequired"))
if (winrt::Metadata::ApiInformation::IsPropertyPresent(winrt::name_of<winrt::GraphicsCaptureSession>(), L"IsBorderRequired"))
{
return true;
}
#endif
#endif

return false;
}

bool DPWinRT_IsIncludeSecondaryWindowsPropertySupported()
{
#ifndef DPLUSWINRT_STUB
#if WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION >= 0x130000
if (winrt::Metadata::ApiInformation::IsPropertyPresent(winrt::name_of<winrt::GraphicsCaptureSession>(), L"IncludeSecondaryWindows"))
{
return true;
}
#endif
#endif

return false;
}

bool DPWinRT_IsMinUpdateIntervalPropertySupported()
{
#ifndef DPLUSWINRT_STUB
#if WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION >= 0x130000
if (winrt::Metadata::ApiInformation::IsPropertyPresent(winrt::name_of<winrt::GraphicsCaptureSession>(), L"MinUpdateInterval"))
{
return true;
}
Expand Down
15 changes: 10 additions & 5 deletions src/DesktopPlusWinRT/DesktopPlusWinRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
//This is the part of Desktop+ using Windows Runtime functions, separated from rest of the codebase as a DLL
//Windows SDK 10.0.19041.0 or newer is required to build this, 10.0.20348.0 or newer recommended to allow removing the capture border
//
//Windows SDK 10.0.26100.0 or newer is required for Windows 11 24H2 features, but not selected by default, as it appears incompatible with the VS2019/v142 compiler
//So while official builds do include the features, nightly builds do not, and they need to be manually enabled by selecting the SDK and platform toolset version before building
//
//If you wish to build Desktop+ without support for the functionality provided by this library, define DPLUSWINRT_STUB for the project,
//remove the package references and adjust the project's Windows SDK version if needed

Expand Down Expand Up @@ -44,11 +47,13 @@ extern "C" {

DPLUSWINRT_API void DPWinRT_Init();

DPLUSWINRT_API bool DPWinRT_IsCaptureSupported(); //Build 1903 (1803 in theory, but picker is no longer supported by this library)
DPLUSWINRT_API bool DPWinRT_IsCaptureFromHandleSupported(); //Build 1903
DPLUSWINRT_API bool DPWinRT_IsCaptureFromCombinedDesktopSupported(); //Build 2004
DPLUSWINRT_API bool DPWinRT_IsCaptureCursorEnabledPropertySupported(); //Build 2004
DPLUSWINRT_API bool DPWinRT_IsBorderRequiredPropertySupported(); //Windows 11
DPLUSWINRT_API bool DPWinRT_IsCaptureSupported(); //Build 1903 (1803 in theory, but picker is no longer supported by this library)
DPLUSWINRT_API bool DPWinRT_IsCaptureFromHandleSupported(); //Build 1903
DPLUSWINRT_API bool DPWinRT_IsCaptureFromCombinedDesktopSupported(); //Build 2004
DPLUSWINRT_API bool DPWinRT_IsCaptureCursorEnabledPropertySupported(); //Build 2004
DPLUSWINRT_API bool DPWinRT_IsBorderRequiredPropertySupported(); //Windows 11
DPLUSWINRT_API bool DPWinRT_IsIncludeSecondaryWindowsPropertySupported(); //Windows 11 24H2
DPLUSWINRT_API bool DPWinRT_IsMinUpdateIntervalPropertySupported(); //Windows 11 24H2

DPLUSWINRT_API bool DPWinRT_StartCaptureFromHWND(vr::VROverlayHandle_t overlay_handle, HWND handle);
DPLUSWINRT_API bool DPWinRT_StartCaptureFromDesktop(vr::VROverlayHandle_t overlay_handle, int desktop_id); //-1 is combined desktop, as usual
Expand Down
25 changes: 22 additions & 3 deletions src/DesktopPlusWinRT/OverlayCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ OverlayCapture::OverlayCapture(winrt::IDirect3DDevice const& device, winrt::Grap

//Disable yellow capture border if possible (Windows SDK 10.0.20348.0 or newer + running on Windows 11)
#if WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION >= 0xc0000
if (winrt::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Graphics.Capture.GraphicsCaptureSession", L"IsBorderRequired"))
if (DPWinRT_IsBorderRequiredPropertySupported())
{
//Request access... except it doesn't appear to prompt the user at all and just returns AppCapabilityAccessStatus_Allowed straight away when supported
//Still need to do it though
Expand All @@ -52,6 +52,17 @@ OverlayCapture::OverlayCapture(winrt::IDirect3DDevice const& device, winrt::Grap
}
#endif

//Include secondary windows if possible (Windows SDK 10.0.26100.0 or newer + running on Windows 11 24H2)
#if WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION >= 0x130000
if (DPWinRT_IsIncludeSecondaryWindowsPropertySupported())
{
m_Session.IncludeSecondaryWindows(true);
}
#endif

//Use native GraphicsCapture API update limiter if possible (Windows SDK 10.0.26100.0 or newer + running on Windows 11 24H2)
m_UseMinIntervalLimiter = DPWinRT_IsMinUpdateIntervalPropertySupported();

//Send size updates for all overlays to default them to -1 until we get the real size on the first frame update
for (const auto& overlay : m_Overlays)
{
Expand Down Expand Up @@ -135,6 +146,14 @@ void OverlayCapture::OnOverlayDataRefresh()
}
}

//Apply delay right away if we're using the GraphicsCapture limiter
#if WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION >= 0x130000
if (m_UseMinIntervalLimiter)
{
m_Session.MinUpdateInterval(std::chrono::microseconds(m_UpdateLimiterDelay.QuadPart));
}
#endif

//Adjust OUConverter cache size as needed
m_OUConverters.resize(ou_count);

Expand Down Expand Up @@ -176,8 +195,8 @@ void OverlayCapture::OnFrameArrived(winrt::Direct3D11CaptureFramePool const& sen
return;

//Update limiter/skipper
bool update_limiter_active = (m_UpdateLimiterDelay.QuadPart != 0);
bool update_limiter_active = ((!m_UseMinIntervalLimiter) && (m_UpdateLimiterDelay.QuadPart != 0));

if (update_limiter_active)
{
LARGE_INTEGER UpdateLimiterEndingTime, UpdateLimiterElapsedMicroseconds;
Expand Down
1 change: 1 addition & 0 deletions src/DesktopPlusWinRT/OverlayCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class OverlayCapture
winrt::Windows::Graphics::SizeInt32 m_LastTextureSize { 0, 0 };
bool m_RestartPending = false;

bool m_UseMinIntervalLimiter = false; //True if MinUpdateInterval is being used instead of our own limiter
LARGE_INTEGER m_UpdateLimiterStartingTime = {INT_MAX, INT_MAX}; //Init to high value so the first frame is never falls below the minimum interval
LARGE_INTEGER m_UpdateLimiterFrequency = {0, 0};
LARGE_INTEGER m_UpdateLimiterDelay = {0, 0};
Expand Down
8 changes: 5 additions & 3 deletions src/Shared/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ void DPLog_DPWinRT_SupportInfo()
if (DPWinRT_IsCaptureSupported())
{
LOG_SCOPE_F(INFO, "Graphics Capture Support");
LOG_F(INFO, "Combined Desktop: %s", (DPWinRT_IsCaptureFromCombinedDesktopSupported()) ? "Yes" : "No");
LOG_F(INFO, "Disabling Cursor: %s", (DPWinRT_IsCaptureCursorEnabledPropertySupported()) ? "Yes" : "No");
LOG_F(INFO, "Disabling Border: %s", (DPWinRT_IsBorderRequiredPropertySupported()) ? "Yes" : "No");
LOG_F(INFO, "Combined Desktop: %s", (DPWinRT_IsCaptureFromCombinedDesktopSupported()) ? "Yes" : "No");
LOG_F(INFO, "Disabling Cursor: %s", (DPWinRT_IsCaptureCursorEnabledPropertySupported()) ? "Yes" : "No");
LOG_F(INFO, "Disabling Border: %s", (DPWinRT_IsBorderRequiredPropertySupported()) ? "Yes" : "No");
LOG_F(INFO, "Capture Secondary Windows: %s", (DPWinRT_IsIncludeSecondaryWindowsPropertySupported()) ? "Yes" : "No");
LOG_F(INFO, "Native Update Limiter: %s", (DPWinRT_IsMinUpdateIntervalPropertySupported()) ? "Yes" : "No");
}
else
{
Expand Down

0 comments on commit ed565f8

Please sign in to comment.