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_OUTPUT_DUPLICATOR_H_ |
| 12 #define MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ |
| 13 |
| 14 #include <comdef.h> |
| 15 #include <wrl/client.h> |
| 16 #include <DXGI.h> |
| 17 #include <DXGI1_2.h> |
| 18 |
| 19 #include <memory> |
| 20 #include <vector> |
| 21 |
| 22 #include "webrtc/base/criticalsection.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" |
| 26 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 27 #include "webrtc/modules/desktop_capture/win/d3d_device.h" |
| 28 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" |
| 29 |
| 30 namespace webrtc { |
| 31 |
| 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. |
| 34 // TODO(zijiehe): Understand the meaning of rotation. |
| 35 class DxgiOutputDuplicator { |
| 36 public: |
| 37 // Creates an instance of DxgiOutputDuplicator from a D3dDevice and one of its |
| 38 // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it |
| 39 // outlives this instance. |
| 40 DxgiOutputDuplicator(const D3dDevice& device, |
| 41 const Microsoft::WRL::ComPtr<IDXGIOutput1>& output, |
| 42 const DXGI_OUTPUT_DESC& desc); |
| 43 |
| 44 // To allow this class to use with vector. |
| 45 DxgiOutputDuplicator(DxgiOutputDuplicator&& other); |
| 46 |
| 47 // Destructs this instance. We need to make sure texture_ has been released |
| 48 // before duplication_. |
| 49 ~DxgiOutputDuplicator(); |
| 50 |
| 51 // Initializes duplication_ object. |
| 52 bool Initialize(); |
| 53 |
| 54 // Copies the content of current IDXGIOutput to the |target|. To improve the |
| 55 // performance, this function copies only regions merged from |
| 56 // |last_frame|.updated_region and DetectUpdatedRegion. The offset decides the |
| 57 // offset in the |target| where the content should be copied to. i.e. this |
| 58 // function copies the content to the rectangle of (offset.x(), offset.y()) to |
| 59 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()). |
| 60 // The |last_frame| is always expected to be translated by the same offset. |
| 61 // Returns false if this function failed to execute Windows APIs. |
| 62 bool Duplicate(DesktopFrame* target, |
| 63 const DesktopFrame* last_frame, |
| 64 const DesktopVector offset); |
| 65 |
| 66 // Returns the desktop rect covered by this DxgiOutputDuplicator. |
| 67 DesktopRect desktop_rect() const { |
| 68 return desktop_rect_; |
| 69 } |
| 70 |
| 71 private: |
| 72 // Detects updated region translated by offset from IDXGIOutput1. This |
| 73 // function will set the updated_region_ as entire DesktopRect starts from |
| 74 // offset if it failed to execute Windows APIs. |
| 75 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 76 const DesktopVector offset); |
| 77 |
| 78 // Returns untranslated updated region, which are directly returned by Windows |
| 79 // APIs. Returns false if this function failed to execute Windows APIs. |
| 80 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| 81 DesktopRegion* updated_region); |
| 82 |
| 83 bool ReleaseFrame(); |
| 84 |
| 85 // Initializes duplication_ instance. Expects duplication_ is in empty status. |
| 86 // Returns false if system does not support IDXGIOutputDuplication. |
| 87 bool DuplicateOutput(); |
| 88 |
| 89 // Returns a DesktopRect with the same size of desktop_size_, but translated |
| 90 // by offset. |
| 91 DesktopRect TranslatedDesktopRect(const DesktopVector offset); |
| 92 |
| 93 const D3dDevice& device_; |
| 94 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_; |
| 95 const DesktopRect desktop_rect_; |
| 96 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; |
| 97 DXGI_OUTDUPL_DESC desc_; |
| 98 std::vector<uint8_t> metadata; |
| 99 std::unique_ptr<DxgiTexture> texture_; |
| 100 // The updated region from DXGI_OUTDUPL_FRAME_INFO. |
| 101 DesktopRegion updated_region_; |
| 102 }; |
| 103 |
| 104 } // namespace webrtc |
| 105 |
| 106 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_ |
OLD | NEW |