• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   WindowCapturerWinGdi();
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   // This map is used to avoid flickering for the case when SelectWindow() calls
65   // are interleaved with Capture() calls.
66   std::map<HWND, DesktopSize> window_size_map_;
67 
68   WindowFinderWin window_finder_;
69 
70   std::vector<HWND> owned_windows_;
71   std::unique_ptr<WindowCapturerWinGdi> owned_window_capturer_;
72 };
73 
74 }  // namespace webrtc
75 
76 #endif  // MODULES_DESKTOP_CAPTURE_WIN_WINDOW_CAPTURER_WIN_GDI_H_
77