• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2014 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 WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_
13 
14 #include "webrtc/modules/desktop_capture/screen_capturer.h"
15 
16 #include <windows.h>
17 
18 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h"
20 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h"
21 #include "webrtc/modules/desktop_capture/win/scoped_thread_desktop.h"
22 
23 namespace webrtc {
24 
25 class Differ;
26 
27 // ScreenCapturerWinGdi captures 32bit RGB using GDI.
28 //
29 // ScreenCapturerWinGdi is double-buffered as required by ScreenCapturer.
30 class ScreenCapturerWinGdi : public ScreenCapturer {
31  public:
32   explicit ScreenCapturerWinGdi(const DesktopCaptureOptions& options);
33   virtual ~ScreenCapturerWinGdi();
34 
35   // Overridden from ScreenCapturer:
36   void Start(Callback* callback) override;
37   void Capture(const DesktopRegion& region) override;
38   bool GetScreenList(ScreenList* screens) override;
39   bool SelectScreen(ScreenId id) override;
40 
41  private:
42   typedef HRESULT (WINAPI * DwmEnableCompositionFunc)(UINT);
43 
44   // Make sure that the device contexts match the screen configuration.
45   void PrepareCaptureResources();
46 
47   // Captures the current screen contents into the current buffer. Returns true
48   // if succeeded.
49   bool CaptureImage();
50 
51   // Capture the current cursor shape.
52   void CaptureCursor();
53 
54   Callback* callback_;
55   ScreenId current_screen_id_;
56   std::wstring current_device_key_;
57 
58   // A thread-safe list of invalid rectangles, and the size of the most
59   // recently captured screen.
60   ScreenCapturerHelper helper_;
61 
62   ScopedThreadDesktop desktop_;
63 
64   // GDI resources used for screen capture.
65   HDC desktop_dc_;
66   HDC memory_dc_;
67 
68   // Queue of the frames buffers.
69   ScreenCaptureFrameQueue queue_;
70 
71   // Rectangle describing the bounds of the desktop device context, relative to
72   // the primary display's top-left.
73   DesktopRect desktop_dc_rect_;
74 
75   // Class to calculate the difference between two screen bitmaps.
76   rtc::scoped_ptr<Differ> differ_;
77 
78   HMODULE dwmapi_library_;
79   DwmEnableCompositionFunc composition_func_;
80 
81   // Used to suppress duplicate logging of SetThreadExecutionState errors.
82   bool set_thread_execution_state_failed_;
83 
84   RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinGdi);
85 };
86 
87 }  // namespace webrtc
88 
89 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_
90