| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ |
| 13 | 13 |
| 14 #include <D3DCommon.h> | 14 #include <D3DCommon.h> |
| 15 | 15 |
| 16 #include <memory> | 16 #include <atomic> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
| 20 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 21 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 21 #include "webrtc/modules/desktop_capture/resolution_change_detector.h" | 22 #include "webrtc/modules/desktop_capture/resolution_change_detector.h" |
| 22 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 23 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
| 23 #include "webrtc/modules/desktop_capture/win/d3d_device.h" | 24 #include "webrtc/modules/desktop_capture/win/d3d_device.h" |
| 24 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" | 25 #include "webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.h" |
| 25 #include "webrtc/modules/desktop_capture/win/dxgi_context.h" | 26 #include "webrtc/modules/desktop_capture/win/dxgi_context.h" |
| 26 #include "webrtc/modules/desktop_capture/win/dxgi_frame.h" | 27 #include "webrtc/modules/desktop_capture/win/dxgi_frame.h" |
| 27 | 28 |
| 28 namespace webrtc { | 29 namespace webrtc { |
| 29 | 30 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 59 | 60 |
| 60 enum class Result { | 61 enum class Result { |
| 61 SUCCEEDED, | 62 SUCCEEDED, |
| 62 FRAME_PREPARE_FAILED, | 63 FRAME_PREPARE_FAILED, |
| 63 INITIALIZATION_FAILED, | 64 INITIALIZATION_FAILED, |
| 64 DUPLICATION_FAILED, | 65 DUPLICATION_FAILED, |
| 65 INVALID_MONITOR_ID, | 66 INVALID_MONITOR_ID, |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 // Returns the singleton instance of DxgiDuplicatorController. | 69 // Returns the singleton instance of DxgiDuplicatorController. |
| 69 static DxgiDuplicatorController* Instance(); | 70 static rtc::scoped_refptr<DxgiDuplicatorController> Instance(); |
| 70 | |
| 71 // Destructs current instance. We need to make sure COM components and their | |
| 72 // containers are destructed in correct order. This function calls | |
| 73 // Deinitialize() to do the real work. | |
| 74 ~DxgiDuplicatorController(); | |
| 75 | 71 |
| 76 // All the following public functions implicitly call Initialize() function. | 72 // All the following public functions implicitly call Initialize() function. |
| 77 | 73 |
| 78 // Detects whether the system supports DXGI based capturer. | 74 // Detects whether the system supports DXGI based capturer. |
| 79 bool IsSupported(); | 75 bool IsSupported(); |
| 80 | 76 |
| 81 // Returns a copy of D3dInfo composed by last Initialize() function call. | 77 // Returns a copy of D3dInfo composed by last Initialize() function call. |
| 82 bool RetrieveD3dInfo(D3dInfo* info); | 78 bool RetrieveD3dInfo(D3dInfo* info); |
| 83 | 79 |
| 84 // Captures current screen and writes into |frame|. | 80 // Captures current screen and writes into |frame|. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 100 // Returns the count of screens on the system. These screens can be retrieved | 96 // Returns the count of screens on the system. These screens can be retrieved |
| 101 // by an integer in the range of [0, ScreenCount()). If system does not | 97 // by an integer in the range of [0, ScreenCount()). If system does not |
| 102 // support DXGI based capturer, this function returns 0. | 98 // support DXGI based capturer, this function returns 0. |
| 103 int ScreenCount(); | 99 int ScreenCount(); |
| 104 | 100 |
| 105 private: | 101 private: |
| 106 // DxgiFrameContext calls private Unregister(Context*) function during | 102 // DxgiFrameContext calls private Unregister(Context*) function during |
| 107 // destructing. | 103 // destructing. |
| 108 friend DxgiFrameContext::~DxgiFrameContext(); | 104 friend DxgiFrameContext::~DxgiFrameContext(); |
| 109 | 105 |
| 106 // scoped_refptr<DxgiDuplicatorController> accesses private AddRef() and |
| 107 // Release() functions. |
| 108 friend class rtc::scoped_refptr<DxgiDuplicatorController>; |
| 109 |
| 110 // A private constructor to ensure consumers to use | 110 // A private constructor to ensure consumers to use |
| 111 // DxgiDuplicatorController::Instance(). | 111 // DxgiDuplicatorController::Instance(). |
| 112 DxgiDuplicatorController(); | 112 DxgiDuplicatorController(); |
| 113 | 113 |
| 114 // Not implemented: The singleton DxgiDuplicatorController instance should not |
| 115 // be deleted. |
| 116 ~DxgiDuplicatorController(); |
| 117 |
| 118 // RefCountedInterface implementations. |
| 119 void AddRef(); |
| 120 void Release(); |
| 121 |
| 114 // Does the real duplication work. Setting |monitor_id| < 0 to capture entire | 122 // Does the real duplication work. Setting |monitor_id| < 0 to capture entire |
| 115 // screen. This function calls Initialize(). And if the duplication failed, | 123 // screen. This function calls Initialize(). And if the duplication failed, |
| 116 // this function calls Deinitialize() to ensure the Dxgi components can be | 124 // this function calls Deinitialize() to ensure the Dxgi components can be |
| 117 // reinitialized next time. | 125 // reinitialized next time. |
| 118 Result DoDuplicate(DxgiFrame* frame, int monitor_id); | 126 Result DoDuplicate(DxgiFrame* frame, int monitor_id); |
| 119 | 127 |
| 128 // Unload all the DXGI components and releases the resources. This function |
| 129 // wraps Deinitialize() with |lock_|. |
| 130 void Unload(); |
| 131 |
| 120 // Unregisters Context from this instance and all DxgiAdapterDuplicator(s) | 132 // Unregisters Context from this instance and all DxgiAdapterDuplicator(s) |
| 121 // it owns. | 133 // it owns. |
| 122 void Unregister(const Context* const context); | 134 void Unregister(const Context* const context); |
| 123 | 135 |
| 124 // All functions below should be called in |lock_| locked scope and should be | 136 // All functions below should be called in |lock_| locked scope and should be |
| 125 // after a successful Initialize(). | 137 // after a successful Initialize(). |
| 126 | 138 |
| 127 // If current instance has not been initialized, executes DoInitialize() | 139 // If current instance has not been initialized, executes DoInitialize() |
| 128 // function, and returns initialize result. Otherwise directly returns true. | 140 // function, and returns initialize result. Otherwise directly returns true. |
| 129 // This function may calls Deinitialize() if initialization failed. | 141 // This function may calls Deinitialize() if initialization failed. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // According to http://crbug.com/682112, dxgi capturer returns a black frame | 190 // According to http://crbug.com/682112, dxgi capturer returns a black frame |
| 179 // during first several capture attempts. | 191 // during first several capture attempts. |
| 180 bool EnsureFrameCaptured(Context* context, SharedDesktopFrame* target); | 192 bool EnsureFrameCaptured(Context* context, SharedDesktopFrame* target); |
| 181 | 193 |
| 182 // Moves |desktop_rect_| and all underlying |duplicators_|, putting top left | 194 // Moves |desktop_rect_| and all underlying |duplicators_|, putting top left |
| 183 // corner of the desktop at (0, 0). This is necessary because DXGI_OUTPUT_DESC | 195 // corner of the desktop at (0, 0). This is necessary because DXGI_OUTPUT_DESC |
| 184 // may return negative coordinates. Called from DoInitialize() after all | 196 // may return negative coordinates. Called from DoInitialize() after all |
| 185 // DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized. | 197 // DxgiAdapterDuplicator and DxgiOutputDuplicator instances are initialized. |
| 186 void TranslateRect(); | 198 void TranslateRect(); |
| 187 | 199 |
| 200 // The count of references which are now "living". |
| 201 std::atomic_int refcount_; |
| 202 |
| 188 // This lock must be locked whenever accessing any of the following objects. | 203 // This lock must be locked whenever accessing any of the following objects. |
| 189 rtc::CriticalSection lock_; | 204 rtc::CriticalSection lock_; |
| 190 | 205 |
| 191 // A self-incremented integer to compare with the one in Context. It ensures | 206 // A self-incremented integer to compare with the one in Context. It ensures |
| 192 // a Context instance is always initialized after DxgiDuplicatorController. | 207 // a Context instance is always initialized after DxgiDuplicatorController. |
| 193 int identity_ = 0; | 208 int identity_ = 0; |
| 194 DesktopRect desktop_rect_; | 209 DesktopRect desktop_rect_; |
| 195 DesktopVector dpi_; | 210 DesktopVector dpi_; |
| 196 std::vector<DxgiAdapterDuplicator> duplicators_; | 211 std::vector<DxgiAdapterDuplicator> duplicators_; |
| 197 D3dInfo d3d_info_; | 212 D3dInfo d3d_info_; |
| 198 ResolutionChangeDetector resolution_change_detector_; | 213 ResolutionChangeDetector resolution_change_detector_; |
| 199 }; | 214 }; |
| 200 | 215 |
| 201 } // namespace webrtc | 216 } // namespace webrtc |
| 202 | 217 |
| 203 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ | 218 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_CONTROLLER_H_ |
| OLD | NEW |