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 MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_ 12 #define MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_ 13 14 #include <windows.h> 15 16 #include <memory> 17 18 #include "modules/desktop_capture/desktop_capturer.h" 19 #include "modules/desktop_capture/screen_capture_frame_queue.h" 20 #include "modules/desktop_capture/shared_desktop_frame.h" 21 #include "modules/desktop_capture/win/display_configuration_monitor.h" 22 #include "modules/desktop_capture/win/scoped_thread_desktop.h" 23 24 namespace webrtc { 25 26 // ScreenCapturerWinGdi captures 32bit RGB using GDI. 27 // 28 // ScreenCapturerWinGdi is double-buffered as required by ScreenCapturer. 29 // This class does not detect DesktopFrame::updated_region(), the field is 30 // always set to the entire frame rectangle. ScreenCapturerDifferWrapper should 31 // be used if that functionality is necessary. 32 class ScreenCapturerWinGdi : public DesktopCapturer { 33 public: 34 explicit ScreenCapturerWinGdi(const DesktopCaptureOptions& options); 35 ~ScreenCapturerWinGdi() override; 36 37 ScreenCapturerWinGdi(const ScreenCapturerWinGdi&) = delete; 38 ScreenCapturerWinGdi& operator=(const ScreenCapturerWinGdi&) = delete; 39 40 // Overridden from ScreenCapturer: 41 void Start(Callback* callback) override; 42 void SetSharedMemoryFactory( 43 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; 44 void CaptureFrame() override; 45 bool GetSourceList(SourceList* sources) override; 46 bool SelectSource(SourceId id) override; 47 48 private: 49 typedef HRESULT(WINAPI* DwmEnableCompositionFunc)(UINT); 50 51 // Make sure that the device contexts match the screen configuration. 52 void PrepareCaptureResources(); 53 54 // Captures the current screen contents into the current buffer. Returns true 55 // if succeeded. 56 bool CaptureImage(); 57 58 // Capture the current cursor shape. 59 void CaptureCursor(); 60 61 Callback* callback_ = nullptr; 62 std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; 63 SourceId current_screen_id_ = kFullDesktopScreenId; 64 std::wstring current_device_key_; 65 66 ScopedThreadDesktop desktop_; 67 68 // GDI resources used for screen capture. 69 HDC desktop_dc_ = NULL; 70 HDC memory_dc_ = NULL; 71 72 // Queue of the frames buffers. 73 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; 74 75 DisplayConfigurationMonitor display_configuration_monitor_; 76 77 HMODULE dwmapi_library_ = NULL; 78 DwmEnableCompositionFunc composition_func_ = nullptr; 79 }; 80 81 } // namespace webrtc 82 83 #endif // MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_GDI_H_ 84