| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" | 29 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one | 33 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one |
| 34 // video card. None of functions in this class is thread-safe. | 34 // video card. None of functions in this class is thread-safe. |
| 35 class DxgiOutputDuplicator { | 35 class DxgiOutputDuplicator { |
| 36 public: | 36 public: |
| 37 struct Context { | 37 struct Context { |
| 38 // The updated region DxgiOutputDuplicator::DetectUpdatedRegion() output | 38 // The updated region DxgiOutputDuplicator::DetectUpdatedRegion() output |
| 39 // during last Duplicate() function call. It's a DesktopRegion translated by | 39 // during last Duplicate() function call. It's always relative to the |
| 40 // offset of each DxgiOutputDuplicator instance. | 40 // (0, 0). |
| 41 DesktopRegion updated_region; | 41 DesktopRegion updated_region; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Creates an instance of DxgiOutputDuplicator from a D3dDevice and one of its | 44 // Creates an instance of DxgiOutputDuplicator from a D3dDevice and one of its |
| 45 // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it | 45 // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it |
| 46 // outlives this instance. Only DxgiAdapterDuplicator can create an instance. | 46 // outlives this instance. Only DxgiAdapterDuplicator can create an instance. |
| 47 DxgiOutputDuplicator(const D3dDevice& device, | 47 DxgiOutputDuplicator(const D3dDevice& device, |
| 48 const Microsoft::WRL::ComPtr<IDXGIOutput1>& output, | 48 const Microsoft::WRL::ComPtr<IDXGIOutput1>& output, |
| 49 const DXGI_OUTPUT_DESC& desc); | 49 const DXGI_OUTPUT_DESC& desc); |
| 50 | 50 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 73 DesktopRect desktop_rect() const { return desktop_rect_; } | 73 DesktopRect desktop_rect() const { return desktop_rect_; } |
| 74 | 74 |
| 75 void Setup(Context* context); | 75 void Setup(Context* context); |
| 76 | 76 |
| 77 void Unregister(const Context* const context); | 77 void Unregister(const Context* const context); |
| 78 | 78 |
| 79 // How many frames have been captured by this DxigOutputDuplicator. | 79 // How many frames have been captured by this DxigOutputDuplicator. |
| 80 int64_t num_frames_captured() const; | 80 int64_t num_frames_captured() const; |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 // Detects updated region translated by offset from IDXGIOutput1. This | 83 // Calls DoDetectUpdatedRegion(). If it fails, this function sets the |
| 84 // function will set the |updated_region| as entire DesktopRect starts from | 84 // |updated_region| as entire UntranslatedDesktopRect(). |
| 85 // offset if it failed to execute Windows APIs. | |
| 86 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | 85 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 87 DesktopVector offset, | |
| 88 DesktopRegion* updated_region); | 86 DesktopRegion* updated_region); |
| 89 | 87 |
| 90 // Returns untranslated updated region, which are directly returned by Windows | 88 // Returns untranslated updated region, which are directly returned by Windows |
| 91 // APIs. Returns false in case of a failure. | 89 // APIs. Returns false in case of a failure. |
| 92 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | 90 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 93 DesktopRegion* updated_region); | 91 DesktopRegion* updated_region); |
| 94 | 92 |
| 95 bool ReleaseFrame(); | 93 bool ReleaseFrame(); |
| 96 | 94 |
| 97 // Initializes duplication_ instance. Expects duplication_ is in empty status. | 95 // Initializes duplication_ instance. Expects duplication_ is in empty status. |
| 98 // Returns false if system does not support IDXGIOutputDuplication. | 96 // Returns false if system does not support IDXGIOutputDuplication. |
| 99 bool DuplicateOutput(); | 97 bool DuplicateOutput(); |
| 100 | 98 |
| 101 // Returns a DesktopRect with the same size of desktop_size_, but translated | 99 // Returns a DesktopRect with the same size of desktop_size(), but translated |
| 102 // by offset. | 100 // by offset. |
| 103 DesktopRect TranslatedDesktopRect(DesktopVector offset); | 101 DesktopRect TranslatedDesktopRect(DesktopVector offset) const; |
| 102 |
| 103 // Returns a DesktopRect with the same size of desktop_size(), but starts from |
| 104 // (0, 0). |
| 105 DesktopRect UntranslatedDesktopRect() const; |
| 104 | 106 |
| 105 // Spreads changes from |context| to other registered Context(s) in | 107 // Spreads changes from |context| to other registered Context(s) in |
| 106 // contexts_. | 108 // contexts_. |
| 107 void SpreadContextChange(const Context* const context); | 109 void SpreadContextChange(const Context* const context); |
| 108 | 110 |
| 111 // Returns the size of desktop rectangle current instance representing. |
| 112 DesktopSize desktop_size() const; |
| 113 |
| 109 const D3dDevice device_; | 114 const D3dDevice device_; |
| 110 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_; | 115 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_; |
| 111 const DesktopRect desktop_rect_; | 116 const DesktopRect desktop_rect_; |
| 112 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; | 117 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; |
| 113 DXGI_OUTDUPL_DESC desc_; | 118 DXGI_OUTDUPL_DESC desc_; |
| 114 std::vector<uint8_t> metadata_; | 119 std::vector<uint8_t> metadata_; |
| 115 std::unique_ptr<DxgiTexture> texture_; | 120 std::unique_ptr<DxgiTexture> texture_; |
| 116 Rotation rotation_; | 121 Rotation rotation_; |
| 117 DesktopSize unrotated_size_; | 122 DesktopSize unrotated_size_; |
| 118 | 123 |
| 119 // After each AcquireNextFrame() function call, updated_region_(s) of all | 124 // After each AcquireNextFrame() function call, updated_region_(s) of all |
| 120 // active Context(s) need to be updated. Since they have missed the | 125 // active Context(s) need to be updated. Since they have missed the |
| 121 // change this time. And during next Duplicate() function call, their | 126 // change this time. And during next Duplicate() function call, their |
| 122 // updated_region_ will be merged and copied. | 127 // updated_region_ will be merged and copied. |
| 123 std::vector<Context*> contexts_; | 128 std::vector<Context*> contexts_; |
| 124 | 129 |
| 125 // The last full frame of this output and its offset. If on AcquireNextFrame() | 130 // The last full frame of this output and its offset. If on AcquireNextFrame() |
| 126 // failed because of timeout, i.e. no update, we can copy content from | 131 // failed because of timeout, i.e. no update, we can copy content from |
| 127 // |last_frame_|. | 132 // |last_frame_|. |
| 128 std::unique_ptr<SharedDesktopFrame> last_frame_; | 133 std::unique_ptr<SharedDesktopFrame> last_frame_; |
| 129 DesktopVector last_frame_offset_; | 134 DesktopVector last_frame_offset_; |
| 130 | 135 |
| 131 int64_t num_frames_captured_ = 0; | 136 int64_t num_frames_captured_ = 0; |
| 132 }; | 137 }; |
| 133 | 138 |
| 134 } // namespace webrtc | 139 } // namespace webrtc |
| 135 | 140 |
| 136 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ | 141 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ |
| OLD | NEW |