Chromium Code Reviews| Index: webrtc/modules/desktop_capture/win/dxgi_duplicator.h |
| diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator.h b/webrtc/modules/desktop_capture/win/dxgi_duplicator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ff14f40cb42c38a3d388d8c2b0d2dce08bcec05 |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator.h |
| @@ -0,0 +1,116 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_H_ |
| +#define MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_H_ |
| + |
| +#include <comdef.h> |
| +#include <wrl/client.h> |
| +#include <DXGI.h> |
| +#include <DXGI1_2.h> |
| + |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "webrtc/base/criticalsection.h" |
| +#include "webrtc/base/thread_annotations.h" |
| +#include "webrtc/modules/desktop_capture/desktop_frame.h" |
| +#include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| +#include "webrtc/modules/desktop_capture/desktop_region.h" |
| +#include "webrtc/modules/desktop_capture/win/d3d_device.h" |
| +#include "webrtc/modules/desktop_capture/win/dxgi_texture.h" |
| + |
| +namespace webrtc { |
| + |
| +// Duplicates the content on one IDXGIOutput, i.e. one monitor attached to one |
| +// video card. None of functions in this class is thread-safe. |
| +// TODO(zijiehe): Understand the meaning of rotation. |
| +class DxgiDuplicator { |
|
Sergey Ulanov
2016/07/08 22:36:54
Call this DxgiOutputDuplicator to make it clear ho
Hzj_jie
2016/07/11 00:55:00
Done.
|
| + public: |
| + // Creates an instance of DxgiDuplicator from a D3dDevice and one of its |
| + // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it |
| + // outlives this instance. |
| + DxgiDuplicator(const D3dDevice& device, |
| + const Microsoft::WRL::ComPtr<IDXGIOutput1>& output, |
| + const DXGI_OUTPUT_DESC& desc); |
| + |
| + // To allow this class to use with vector. |
| + DxgiDuplicator(DxgiDuplicator&& other) = default; |
|
Sergey Ulanov
2016/07/08 22:36:54
move =default to the .cc file. (otherwise the comp
Hzj_jie
2016/07/11 00:55:00
Done.
|
| + |
| + // Destructs this instance. We need to make sure texture_ has been released |
| + // before duplication_. |
| + ~DxgiDuplicator(); |
| + |
| + // Initializes duplication_ object. |
| + bool Initialize(); |
| + |
| + // Copies the content of current IDXGIOutput to the target. To improve the |
|
Sergey Ulanov
2016/07/08 22:36:54
s/target/|target|/
Hzj_jie
2016/07/11 00:55:00
Done.
|
| + // performance, this function copies only regions merged from |
| + // |last_frame|.updated_region and DetectUpdatedRegion. The offset decides the |
| + // offset in the target where the content should be copied to. i.e. this |
| + // function copies the content to the rectangle of (offset.x(), offset.y()) to |
| + // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()). |
| + // The |last_frame| is always expected to be translated by the same offset. |
| + // Returns false if this function failed to execute Windows APIs. |
| + bool Duplicate(DesktopFrame* target, |
| + const DesktopFrame* last_frame, |
| + const DesktopVector& offset); |
|
Sergey Ulanov
2016/07/08 22:36:54
nit: pass DesktopVector by value instead of refere
Hzj_jie
2016/07/11 00:55:00
Done.
|
| + |
| + // A shortcut to execute the Duplicate function with desktop_rect_.top_left(). |
| + bool Duplicate(DesktopFrame* target, |
| + const DesktopFrame* last_frame) { |
|
Sergey Ulanov
2016/07/08 22:36:54
override methods are discouraged. I suggest removi
Hzj_jie
2016/07/11 00:55:00
Done.
|
| + return Duplicate(target, last_frame, desktop_rect_.top_left()); |
| + } |
| + |
| + // Returns the desktop rect covered by this DxgiDuplicator. |
| + DesktopRect desktop_rect() const { |
| + return desktop_rect_; |
| + } |
| + |
| + private: |
| + // Detects updated region translated by offset from IDXGIOutput1. This |
| + // function will set the updated_region_ as entire DesktopRect starts from |
| + // offset if it failed to execute Windows APIs. |
| + void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| + const DesktopVector& offset); |
| + |
| + // Returns untranslated updated region, which are directly returned by Windows |
| + // APIs. Returns false if this function failed to execute Windows APIs. |
| + bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
| + DesktopRegion* updated_region); |
| + |
| + bool DoDuplicate(DesktopFrame* target, |
| + const DesktopFrame* last_frame, |
| + const DesktopVector& offset); |
| + |
| + bool ReleaseFrame(); |
| + |
| + // Initializes duplication_ instance. Expects duplication_ is in empty status. |
| + // Returns false if system does not support IDXGIOutputDuplication. |
| + bool DuplicateOutput(); |
| + |
| + // Returns a DesktopRect with the same size of desktop_size_, but translated |
| + // by offset. |
| + DesktopRect TranslatedDesktopRect(const DesktopVector& offset); |
| + |
| + const D3dDevice& device_; |
| + const Microsoft::WRL::ComPtr<IDXGIOutput1> output_; |
| + const DesktopRect desktop_rect_; |
| + Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_; |
| + DXGI_OUTDUPL_DESC desc_; |
| + std::vector<uint8_t> metadata; |
| + std::unique_ptr<DxgiTexture> texture_; |
| + // The updated region from DXGI_OUTDUPL_FRAME_INFO. |
| + DesktopRegion updated_region_; |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_DUPLICATOR_H_ |