| 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_OUTPUT_DUPLICATOR_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ |
| 13 | 13 |
| 14 #include <comdef.h> | 14 #include <comdef.h> |
| 15 #include <wrl/client.h> | 15 #include <wrl/client.h> |
| 16 #include <DXGI.h> | 16 #include <DXGI.h> |
| 17 #include <DXGI1_2.h> | 17 #include <DXGI1_2.h> |
| 18 | 18 |
| 19 #include <memory> | 19 #include <memory> |
| 20 #include <vector> | 20 #include <vector> |
| 21 | 21 |
| 22 #include "webrtc/base/criticalsection.h" | 22 #include "webrtc/base/criticalsection.h" |
| 23 #include "webrtc/base/thread_annotations.h" | 23 #include "webrtc/base/thread_annotations.h" |
| 24 #include "webrtc/modules/desktop_capture/desktop_frame.h" | |
| 25 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 24 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 26 #include "webrtc/modules/desktop_capture/desktop_region.h" | 25 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 26 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
| 27 #include "webrtc/modules/desktop_capture/win/d3d_device.h" | 27 #include "webrtc/modules/desktop_capture/win/d3d_device.h" |
| 28 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" | 28 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" |
| 29 | 29 |
| 30 namespace webrtc { | 30 namespace webrtc { |
| 31 | 31 |
| 32 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one | 32 // Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one |
| 33 // video card. None of functions in this class is thread-safe. | 33 // video card. None of functions in this class is thread-safe. |
| 34 // TODO(zijiehe): Understand the meaning of rotation. | 34 // TODO(zijiehe): Understand the meaning of rotation. |
| 35 class DxgiOutputDuplicator { | 35 class DxgiOutputDuplicator { |
| 36 public: | 36 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 // Destructs this instance. We need to make sure texture_ has been released | 54 // Destructs this instance. We need to make sure texture_ has been released |
| 55 // before duplication_. | 55 // before duplication_. |
| 56 ~DxgiOutputDuplicator(); | 56 ~DxgiOutputDuplicator(); |
| 57 | 57 |
| 58 // Initializes duplication_ object. | 58 // Initializes duplication_ object. |
| 59 bool Initialize(); | 59 bool Initialize(); |
| 60 | 60 |
| 61 // Copies the content of current IDXGIOutput to the |target|. To improve the | 61 // Copies the content of current IDXGIOutput to the |target|. To improve the |
| 62 // performance, this function copies only regions merged from | 62 // performance, this function copies only regions merged from |
| 63 // |last_frame|.updated_region and DetectUpdatedRegion(). The |offset| decides | 63 // |context|->updated_region and DetectUpdatedRegion(). The |offset| |
| 64 // the | 64 // decides the offset in the |target| where the content should be copied to. |
| 65 // offset in the |target| where the content should be copied to. i.e. this | 65 // i.e. this function copies the content to the rectangle of |
| 66 // function copies the content to the rectangle of (offset.x(), offset.y()) to | 66 // (offset.x(), offset.y()) to |
| 67 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()). | 67 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()). |
| 68 // The |last_frame| is always expected to be translated by the same offset. | |
| 69 // Returns false in case of a failure. | 68 // Returns false in case of a failure. |
| 70 bool Duplicate(Context* context, | 69 bool Duplicate(Context* context, |
| 71 const DesktopFrame* last_frame, | |
| 72 const DesktopVector offset, | 70 const DesktopVector offset, |
| 73 DesktopFrame* target); | 71 SharedDesktopFrame* target); |
| 74 | 72 |
| 75 // Returns the desktop rect covered by this DxgiOutputDuplicator. | 73 // Returns the desktop rect covered by this DxgiOutputDuplicator. |
| 76 DesktopRect desktop_rect() const { return desktop_rect_; } | 74 DesktopRect desktop_rect() const { return desktop_rect_; } |
| 77 | 75 |
| 78 private: | 76 private: |
| 79 friend class DxgiAdapterDuplicator; | 77 friend class DxgiAdapterDuplicator; |
| 80 | 78 |
| 81 // Detects updated region translated by offset from IDXGIOutput1. This | 79 // Detects updated region translated by offset from IDXGIOutput1. This |
| 82 // function will set the |updated_region| as entire DesktopRect starts from | 80 // function will set the |updated_region| as entire DesktopRect starts from |
| 83 // offset if it failed to execute Windows APIs. | 81 // offset if it failed to execute Windows APIs. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 114 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; | 112 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; |
| 115 DXGI_OUTDUPL_DESC desc_; | 113 DXGI_OUTDUPL_DESC desc_; |
| 116 std::vector<uint8_t> metadata; | 114 std::vector<uint8_t> metadata; |
| 117 std::unique_ptr<DxgiTexture> texture_; | 115 std::unique_ptr<DxgiTexture> texture_; |
| 118 | 116 |
| 119 // After each AcquireNextFrame() function call, updated_region_(s) of all | 117 // After each AcquireNextFrame() function call, updated_region_(s) of all |
| 120 // active Context(s) need to be updated. Since they have missed the | 118 // active Context(s) need to be updated. Since they have missed the |
| 121 // change this time. And during next Duplicate() function call, their | 119 // change this time. And during next Duplicate() function call, their |
| 122 // updated_region_ will be merged and copied. | 120 // updated_region_ will be merged and copied. |
| 123 std::vector<Context*> contexts_; | 121 std::vector<Context*> contexts_; |
| 122 |
| 123 // The last full frame of this output and its offset. If one |
| 124 // AcquireNextFrame() failed because of timeout, i.e. no update, we can copy |
| 125 // content from |last_frame_|. |
| 126 std::unique_ptr<SharedDesktopFrame> last_frame_; |
| 127 DesktopVector last_frame_offset_; |
| 124 }; | 128 }; |
| 125 | 129 |
| 126 } // namespace webrtc | 130 } // namespace webrtc |
| 127 | 131 |
| 128 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ | 132 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ |
| OLD | NEW |