diff options
Diffstat (limited to 'modules/desktop_capture/win/wgc_capture_source.cc')
-rw-r--r-- | modules/desktop_capture/win/wgc_capture_source.cc | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/modules/desktop_capture/win/wgc_capture_source.cc b/modules/desktop_capture/win/wgc_capture_source.cc index f894a1ec3c..9786ca67b5 100644 --- a/modules/desktop_capture/win/wgc_capture_source.cc +++ b/modules/desktop_capture/win/wgc_capture_source.cc @@ -11,6 +11,8 @@ #include "modules/desktop_capture/win/wgc_capture_source.h" #include <windows.graphics.capture.interop.h> +#include <windows.h> + #include <utility> #include "modules/desktop_capture/win/screen_capture_utils.h" @@ -26,6 +28,18 @@ WgcCaptureSource::WgcCaptureSource(DesktopCapturer::SourceId source_id) : source_id_(source_id) {} WgcCaptureSource::~WgcCaptureSource() = default; +bool WgcCaptureSource::IsCapturable() { + // If we can create a capture item, then we can capture it. Unfortunately, + // we can't cache this item because it may be created in a different COM + // apartment than where capture will eventually start from. + ComPtr<WGC::IGraphicsCaptureItem> item; + return SUCCEEDED(CreateCaptureItem(&item)); +} + +bool WgcCaptureSource::FocusOnSource() { + return false; +} + HRESULT WgcCaptureSource::GetCaptureItem( ComPtr<WGC::IGraphicsCaptureItem>* result) { HRESULT hr = S_OK; @@ -36,14 +50,6 @@ HRESULT WgcCaptureSource::GetCaptureItem( return hr; } -bool WgcCaptureSource::IsCapturable() { - // If we can create a capture item, then we can capture it. Unfortunately, - // we can't cache this item because it may be created in a different COM - // apartment than where capture will eventually start from. - ComPtr<WGC::IGraphicsCaptureItem> item; - return SUCCEEDED(CreateCaptureItem(&item)); -} - WgcCaptureSourceFactory::~WgcCaptureSourceFactory() = default; WgcWindowSourceFactory::WgcWindowSourceFactory() = default; @@ -66,6 +72,14 @@ WgcWindowSource::WgcWindowSource(DesktopCapturer::SourceId source_id) : WgcCaptureSource(source_id) {} WgcWindowSource::~WgcWindowSource() = default; +DesktopVector WgcWindowSource::GetTopLeft() { + DesktopRect window_rect; + if (!GetWindowRect(reinterpret_cast<HWND>(GetSourceId()), &window_rect)) + return DesktopVector(); + + return window_rect.top_left(); +} + bool WgcWindowSource::IsCapturable() { if (!IsWindowValidAndVisible(reinterpret_cast<HWND>(GetSourceId()))) return false; @@ -73,6 +87,14 @@ bool WgcWindowSource::IsCapturable() { return WgcCaptureSource::IsCapturable(); } +bool WgcWindowSource::FocusOnSource() { + if (!IsWindowValidAndVisible(reinterpret_cast<HWND>(GetSourceId()))) + return false; + + return ::BringWindowToTop(reinterpret_cast<HWND>(GetSourceId())) && + ::SetForegroundWindow(reinterpret_cast<HWND>(GetSourceId())); +} + HRESULT WgcWindowSource::CreateCaptureItem( ComPtr<WGC::IGraphicsCaptureItem>* result) { if (!ResolveCoreWinRTDelayload()) @@ -99,17 +121,26 @@ HRESULT WgcWindowSource::CreateCaptureItem( } WgcScreenSource::WgcScreenSource(DesktopCapturer::SourceId source_id) - : WgcCaptureSource(source_id) {} + : WgcCaptureSource(source_id) { + // Getting the HMONITOR could fail if the source_id is invalid. In that case, + // we leave hmonitor_ uninitialized and |IsCapturable()| will fail. + HMONITOR hmon; + if (GetHmonitorFromDeviceIndex(GetSourceId(), &hmon)) + hmonitor_ = hmon; +} + WgcScreenSource::~WgcScreenSource() = default; -bool WgcScreenSource::IsCapturable() { - if (!hmonitor_) { - HMONITOR hmon; - if (!GetHmonitorFromDeviceIndex(GetSourceId(), &hmon)) - return false; +DesktopVector WgcScreenSource::GetTopLeft() { + if (!hmonitor_) + return DesktopVector(); - hmonitor_ = hmon; - } + return GetMonitorRect(*hmonitor_).top_left(); +} + +bool WgcScreenSource::IsCapturable() { + if (!hmonitor_) + return false; if (!IsMonitorValid(*hmonitor_)) return false; |