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

Side by Side Diff: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc

Issue 2345163002: Several minor improvements of DirectX capturer (Closed)
Patch Set: Created 4 years, 3 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
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 #include "webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h" 11 #include "webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h"
12 12
13 #include <windows.h> 13 #include <windows.h>
14 #include <ShellScalingApi.h>
14 15
15 #include <algorithm> 16 #include <algorithm>
16 17
17 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 21
22 namespace {
23
24 // A one-time initialization to disable Windows from scaling the resolution.
25 struct DpiAwareness {
26 DpiAwareness();
27 };
28
29 DpiAwareness::DpiAwareness() {
30 // for Windows 8 or earlier
31 SetProcessDPIAware();
32 // for Windows 8.1 or later
33 SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
Jamie 2016/09/16 21:54:10 According to https://msdn.microsoft.com/en-us/libr
Hzj_jie 2016/09/16 22:37:53 I have just talked with Joe, the manifest has alre
34 }
35
36 } // namespace
37
21 DxgiDuplicatorController::Context::~Context() { 38 DxgiDuplicatorController::Context::~Context() {
22 DxgiDuplicatorController::Instance()->Unregister(this); 39 DxgiDuplicatorController::Instance()->Unregister(this);
23 } 40 }
24 41
25 // static 42 // static
26 DxgiDuplicatorController* DxgiDuplicatorController::Instance() { 43 DxgiDuplicatorController* DxgiDuplicatorController::Instance() {
44 const static DpiAwareness one_time_initialization;
27 // The static instance won't be deleted to ensure it can be used by other 45 // The static instance won't be deleted to ensure it can be used by other
28 // threads even during program exiting. 46 // threads even during program exiting.
29 static DxgiDuplicatorController* instance = new DxgiDuplicatorController(); 47 static DxgiDuplicatorController* instance = new DxgiDuplicatorController();
30 return instance; 48 return instance;
31 } 49 }
32 50
33 DxgiDuplicatorController::DxgiDuplicatorController() = default; 51 DxgiDuplicatorController::DxgiDuplicatorController() = default;
34 52
35 DxgiDuplicatorController::~DxgiDuplicatorController() { 53 DxgiDuplicatorController::~DxgiDuplicatorController() {
36 rtc::CritScope lock(&lock_); 54 rtc::CritScope lock(&lock_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return true; 130 return true;
113 } 131 }
114 Deinitialize(); 132 Deinitialize();
115 return false; 133 return false;
116 } 134 }
117 135
118 bool DxgiDuplicatorController::DoInitialize() { 136 bool DxgiDuplicatorController::DoInitialize() {
119 RTC_DCHECK(desktop_rect_.is_empty()); 137 RTC_DCHECK(desktop_rect_.is_empty());
120 RTC_DCHECK(duplicators_.empty()); 138 RTC_DCHECK(duplicators_.empty());
121 139
140 // DPI is used by DxgiOutputDuplicator, so initialize it first.
141 HDC hdc = GetDC(nullptr);
142 // Use old DPI value if failed.
143 if (hdc) {
144 dpi_.set(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
145 ReleaseDC(nullptr, hdc);
146 }
147
122 std::vector<D3dDevice> devices = D3dDevice::EnumDevices(); 148 std::vector<D3dDevice> devices = D3dDevice::EnumDevices();
123 if (devices.empty()) { 149 if (devices.empty()) {
124 return false; 150 return false;
125 } 151 }
126 152
127 for (size_t i = 0; i < devices.size(); i++) { 153 for (size_t i = 0; i < devices.size(); i++) {
128 duplicators_.emplace_back(devices[i]); 154 duplicators_.emplace_back(devices[i]);
129 if (!duplicators_.back().Initialize()) { 155 if (!duplicators_.back().Initialize()) {
130 return false; 156 return false;
131 } 157 }
132 if (desktop_rect_.is_empty()) { 158 if (desktop_rect_.is_empty()) {
133 desktop_rect_ = duplicators_.back().desktop_rect(); 159 desktop_rect_ = duplicators_.back().desktop_rect();
134 } else { 160 } else {
135 const DesktopRect& left = desktop_rect_; 161 const DesktopRect& left = desktop_rect_;
136 const DesktopRect& right = duplicators_.back().desktop_rect(); 162 const DesktopRect& right = duplicators_.back().desktop_rect();
137 desktop_rect_ = 163 desktop_rect_ =
138 DesktopRect::MakeLTRB(std::min(left.left(), right.left()), 164 DesktopRect::MakeLTRB(std::min(left.left(), right.left()),
139 std::min(left.top(), right.top()), 165 std::min(left.top(), right.top()),
140 std::max(left.right(), right.right()), 166 std::max(left.right(), right.right()),
141 std::max(left.bottom(), right.bottom())); 167 std::max(left.bottom(), right.bottom()));
142 } 168 }
143 } 169 }
144 170
145 HDC hdc = GetDC(nullptr);
146 // Use old DPI value if failed.
147 if (hdc) {
148 dpi_.set(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
149 ReleaseDC(nullptr, hdc);
150 }
151
152 identity_++; 171 identity_++;
153 return true; 172 return true;
154 } 173 }
155 174
156 void DxgiDuplicatorController::Deinitialize() { 175 void DxgiDuplicatorController::Deinitialize() {
157 desktop_rect_ = DesktopRect(); 176 desktop_rect_ = DesktopRect();
158 duplicators_.clear(); 177 duplicators_.clear();
159 } 178 }
160 179
161 bool DxgiDuplicatorController::ContextExpired( 180 bool DxgiDuplicatorController::ContextExpired(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 Deinitialize(); 244 Deinitialize();
226 return false; 245 return false;
227 } 246 }
228 } 247 }
229 // id >= ScreenCount(). This is a user error, so we do not need to 248 // id >= ScreenCount(). This is a user error, so we do not need to
230 // deinitialize. 249 // deinitialize.
231 return false; 250 return false;
232 } 251 }
233 252
234 } // namespace webrtc 253 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/win/d3d_device.h ('k') | webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698