OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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_DXGI_DUPLICATOR_CONTAINER_H_ |
| 12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTAINER_H_ |
| 13 |
| 14 #include <vector> |
| 15 |
| 16 #include "webrtc/base/criticalsection.h" |
| 17 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 18 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 20 #include "webrtc/modules/desktop_capture/win/d3d_device.h" |
| 21 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" |
| 22 |
| 23 namespace webrtc { |
| 24 |
| 25 // A container for all the objects we need to call Windows DirectX based capture |
| 26 // APIs. Note, one application can only have one IDXGIOutputDuplication instance |
| 27 // per output, so this class should be singleton. |
| 28 class DxgiDuplicatorContainer { |
| 29 public: |
| 30 // Creates or retrieves the singleton instance of DxgiDuplicatorContainer. |
| 31 static DxgiDuplicatorContainer* Instance(); |
| 32 |
| 33 // Destructs current instance. We need to make sure COM components and their |
| 34 // containers are destructed in correct order. |
| 35 ~DxgiDuplicatorContainer(); |
| 36 |
| 37 // Initializes all the components. Returns false if system does not support |
| 38 // DirectX based capture, or system resource is not enough to support to |
| 39 // capture all monitors. By default, only four applications can capture the |
| 40 // screen with DirectX based capture simultaneously. Returns true if this |
| 41 // instance has been initialized already. Consumers should call this function |
| 42 // each time before calling Duplicate functions. |
| 43 bool Prepare(); |
| 44 |
| 45 // Captures current screen and writes into target. Since we are using double |
| 46 // buffering, |last_frame|.updated_region() is used to represent the not |
| 47 // updated regions in current |target| frame, which should also be copied this |
| 48 // time. |
| 49 // TODO(zijiehe): Windows cannot guarantee the frames returned by each |
| 50 // IDXGIOutputDuplication are synchronized. But we are using a totally |
| 51 // different threading model than the way Windows suggested, it's hard to |
| 52 // synchronize them manually. But we should find a way to do it. |
| 53 bool Duplicate(DesktopFrame* target, |
| 54 const DesktopFrame* last_frame); |
| 55 |
| 56 // Captures one screen and writes into target. If id < 0 or greater than |
| 57 // the total screen count of all the Duplicators, this function returns false. |
| 58 bool Duplicate(int id, |
| 59 DesktopFrame* target, |
| 60 const DesktopFrame* last_frame); |
| 61 |
| 62 DesktopVector dpi() const { |
| 63 return dpi_; |
| 64 } |
| 65 |
| 66 // Returns entire desktop size. |
| 67 DesktopRect desktop_rect() const { |
| 68 return desktop_rect_; |
| 69 } |
| 70 |
| 71 // Returns a DesktopSize to cover entire desktop_rect. This may be different |
| 72 // than desktop_rect().size(), since top-left screen does not need to start |
| 73 // from (0, 0). |
| 74 DesktopSize desktop_size() const { |
| 75 return DesktopSize(desktop_rect_.right(), desktop_rect_.bottom()); |
| 76 } |
| 77 |
| 78 // Returns the size of one screen. If id < 0 or greater than the total screen |
| 79 // count of all the Duplicators, this function returns an empty DesktopRect. |
| 80 DesktopRect ScreenRect(int id) const; |
| 81 |
| 82 // Returns the count of screens on the system. These screens can be retrieved |
| 83 // by an integer in the range of [0, ScreenCount()). |
| 84 int ScreenCount() const; |
| 85 |
| 86 private: |
| 87 // A class to allow only one thread to enter. This class is used to make sure |
| 88 // only one Initialize function call is being performed. |
| 89 class SingleEntry { |
| 90 public: |
| 91 bool Enter(); |
| 92 void Exit(); |
| 93 bool Hold() const; |
| 94 |
| 95 private: |
| 96 rtc::CriticalSection lock_; |
| 97 bool entered_ = false; |
| 98 }; |
| 99 |
| 100 // A helper class to execute SingleEntry::Exit in its destructor. |
| 101 class AutoExit; |
| 102 |
| 103 bool DoInitialize(); |
| 104 |
| 105 // Clears all COM components referred by this instance. So next Prepare() |
| 106 // call will eventually initialize this instance again. |
| 107 void Deinitialize(); |
| 108 |
| 109 rtc::CriticalSection lock_; |
| 110 SingleEntry initializing_; |
| 111 DesktopRect desktop_rect_; |
| 112 DesktopVector dpi_; |
| 113 std::vector<D3dDevice> devices_; |
| 114 std::vector<DxgiAdapterDuplicator> duplicators_; |
| 115 }; |
| 116 |
| 117 } // namespace webrtc |
| 118 |
| 119 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTAINER_H_ |
OLD | NEW |