1 /* 2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_WIN_WINDOW_CAPTURER_WIN_GDI_H_ 12 #define MODULES_DESKTOP_CAPTURE_WIN_WINDOW_CAPTURER_WIN_GDI_H_ 13 14 #include <map> 15 #include <memory> 16 #include <vector> 17 18 #include "modules/desktop_capture/desktop_capture_options.h" 19 #include "modules/desktop_capture/desktop_capturer.h" 20 #include "modules/desktop_capture/win/window_capture_utils.h" 21 #include "modules/desktop_capture/window_finder_win.h" 22 23 namespace webrtc { 24 25 class WindowCapturerWinGdi : public DesktopCapturer { 26 public: 27 explicit WindowCapturerWinGdi(bool enumerate_current_process_windows); 28 29 // Disallow copy and assign 30 WindowCapturerWinGdi(const WindowCapturerWinGdi&) = delete; 31 WindowCapturerWinGdi& operator=(const WindowCapturerWinGdi&) = delete; 32 33 ~WindowCapturerWinGdi() override; 34 35 static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer( 36 const DesktopCaptureOptions& options); 37 38 // DesktopCapturer interface. 39 void Start(Callback* callback) override; 40 void CaptureFrame() override; 41 bool GetSourceList(SourceList* sources) override; 42 bool SelectSource(SourceId id) override; 43 bool FocusOnSelectedSource() override; 44 bool IsOccluded(const DesktopVector& pos) override; 45 46 private: 47 struct CaptureResults { 48 Result result; 49 std::unique_ptr<DesktopFrame> frame; 50 }; 51 52 CaptureResults CaptureFrame(bool capture_owned_windows); 53 54 Callback* callback_ = nullptr; 55 56 // HWND and HDC for the currently selected window or nullptr if window is not 57 // selected. 58 HWND window_ = nullptr; 59 60 DesktopSize previous_size_; 61 62 WindowCaptureHelperWin window_capture_helper_; 63 64 bool enumerate_current_process_windows_; 65 66 // This map is used to avoid flickering for the case when SelectWindow() calls 67 // are interleaved with Capture() calls. 68 std::map<HWND, DesktopSize> window_size_map_; 69 70 WindowFinderWin window_finder_; 71 72 std::vector<HWND> owned_windows_; 73 std::unique_ptr<WindowCapturerWinGdi> owned_window_capturer_; 74 }; 75 76 } // namespace webrtc 77 78 #endif // MODULES_DESKTOP_CAPTURE_WIN_WINDOW_CAPTURER_WIN_GDI_H_ 79