tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

screen_capturer_win_gdi.h (3066B)


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