Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h

Issue 2099123002: [Chromoting] Improve DirectX capturer to support multiple outputs (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_context.h"
29 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h"
30
31 namespace webrtc {
32
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.
35 // TODO(zijiehe): Understand the meaning of rotation.
36 class DxgiOutputDuplicator {
37 public:
38 // Creates an instance of DxgiOutputDuplicator from a D3dDevice and one of its
39 // IDXGIOutput1. Caller must maintain the lifetime of device, to make sure it
40 // outlives this instance.
41 DxgiOutputDuplicator(const D3dDevice& device,
42 const Microsoft::WRL::ComPtr<IDXGIOutput1>& output,
43 const DXGI_OUTPUT_DESC& desc);
44
45 // To allow this class to use with vector.
46 DxgiOutputDuplicator(DxgiOutputDuplicator&& other);
47
48 // Destructs this instance. We need to make sure texture_ has been released
49 // before duplication_.
50 ~DxgiOutputDuplicator();
51
52 // Initializes duplication_ object.
53 bool Initialize();
54
55 // Copies the content of current IDXGIOutput to the |target|. To improve the
56 // performance, this function copies only regions merged from
57 // |last_frame|.updated_region and DetectUpdatedRegion. The offset decides the
58 // offset in the |target| where the content should be copied to. i.e. this
59 // function copies the content to the rectangle of (offset.x(), offset.y()) to
60 // (offset.x() + desktop_rect_.width(), offset.y() + desktop_rect_.height()).
61 // The |last_frame| is always expected to be translated by the same offset.
62 // Returns false if this function failed to execute Windows APIs.
63 bool Duplicate(DxgiContext* context,
64 DesktopFrame* target,
65 const DesktopFrame* last_frame,
66 const DesktopVector offset);
67
68 // Returns the desktop rect covered by this DxgiOutputDuplicator.
69 DesktopRect desktop_rect() const {
70 return desktop_rect_;
71 }
72
73 private:
74 friend class DxgiAdapterDuplicator;
75
76 // Detects updated region translated by offset from IDXGIOutput1. This
77 // function will set the |updated_region| as entire DesktopRect starts from
78 // offset if it failed to execute Windows APIs.
79 void DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
80 const DesktopVector offset,
81 DesktopRegion* updated_region);
82
83 // Returns untranslated updated region, which are directly returned by Windows
84 // APIs. Returns false if this function failed to execute Windows APIs.
85 bool DoDetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
86 DesktopRegion* updated_region);
87
88 bool ReleaseFrame();
89
90 // Initializes duplication_ instance. Expects duplication_ is in empty status.
91 // Returns false if system does not support IDXGIOutputDuplication.
92 bool DuplicateOutput();
93
94 // Returns a DesktopRect with the same size of desktop_size_, but translated
95 // by offset.
96 DesktopRect TranslatedDesktopRect(const DesktopVector offset);
97
98 void Setup(DxgiContext* context);
99
100 const D3dDevice& device_;
101 const Microsoft::WRL::ComPtr<IDXGIOutput1> output_;
102 const DesktopRect desktop_rect_;
103 Microsoft::WRL::ComPtr<IDXGIOutputDuplication> duplication_;
104 DXGI_OUTDUPL_DESC desc_;
105 std::vector<uint8_t> metadata;
106 std::unique_ptr<DxgiTexture> texture_;
107 };
108
109 } // namespace webrtc
110
111 #endif // MODULES_DESKTOP_CAPTURE_WIN_DXGI_OUTPUT_DUPLICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698