• 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/modules/desktop_capture/mouse_cursor_shape.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 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
23 
24 namespace webrtc {
25 
26 class Differ;
27 class MouseShapeObserver;
28 
29 // ScreenCapturerWinGdi captures 32bit RGB using GDI.
30 //
31 // ScreenCapturerWinGdi is double-buffered as required by ScreenCapturer.
32 class ScreenCapturerWinGdi : public ScreenCapturer {
33  public:
34   explicit ScreenCapturerWinGdi(const DesktopCaptureOptions& options);
35   virtual ~ScreenCapturerWinGdi();
36 
37   // Overridden from ScreenCapturer:
38   virtual void Start(Callback* callback) OVERRIDE;
39   virtual void Capture(const DesktopRegion& region) OVERRIDE;
40   virtual void SetMouseShapeObserver(
41       MouseShapeObserver* mouse_shape_observer) OVERRIDE;
42   virtual bool GetScreenList(ScreenList* screens) OVERRIDE;
43   virtual bool SelectScreen(ScreenId id) OVERRIDE;
44 
45  private:
46   typedef HRESULT (WINAPI * DwmEnableCompositionFunc)(UINT);
47 
48   // Make sure that the device contexts match the screen configuration.
49   void PrepareCaptureResources();
50 
51   // Captures the current screen contents into the current buffer. Returns true
52   // if succeeded.
53   bool CaptureImage();
54 
55   // Capture the current cursor shape.
56   void CaptureCursor();
57 
58   Callback* callback_;
59   MouseShapeObserver* mouse_shape_observer_;
60   ScreenId current_screen_id_;
61   std::wstring current_device_key_;
62 
63   // A thread-safe list of invalid rectangles, and the size of the most
64   // recently captured screen.
65   ScreenCapturerHelper helper_;
66 
67   // Snapshot of the last cursor bitmap we sent to the client. This is used
68   // to diff against the current cursor so we only send a cursor-change
69   // message when the shape has changed.
70   MouseCursorShape last_cursor_;
71 
72   ScopedThreadDesktop desktop_;
73 
74   // GDI resources used for screen capture.
75   HDC desktop_dc_;
76   HDC memory_dc_;
77 
78   // Queue of the frames buffers.
79   ScreenCaptureFrameQueue queue_;
80 
81   // Rectangle describing the bounds of the desktop device context, relative to
82   // the primary display's top-left.
83   DesktopRect desktop_dc_rect_;
84 
85   // Class to calculate the difference between two screen bitmaps.
86   scoped_ptr<Differ> differ_;
87 
88   HMODULE dwmapi_library_;
89   DwmEnableCompositionFunc composition_func_;
90 
91   // Used to suppress duplicate logging of SetThreadExecutionState errors.
92   bool set_thread_execution_state_failed_;
93 
94   DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinGdi);
95 };
96 
97 }  // namespace webrtc
98 
99 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_
100