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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
index 0276f6b94155065c3b9898789332c4da8ba63165..edf054d6efcc55026bbcfc6ca3dcffa40d5bdd4e 100644
--- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
+++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
@@ -11,6 +11,7 @@
#include "webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h"
#include <windows.h>
+#include <ShellScalingApi.h>
#include <algorithm>
@@ -18,12 +19,29 @@
namespace webrtc {
+namespace {
+
+// A one-time initialization to disable Windows from scaling the resolution.
+struct DpiAwareness {
+ DpiAwareness();
+};
+
+DpiAwareness::DpiAwareness() {
+ // for Windows 8 or earlier
+ SetProcessDPIAware();
+ // for Windows 8.1 or later
+ 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
+}
+
+} // namespace
+
DxgiDuplicatorController::Context::~Context() {
DxgiDuplicatorController::Instance()->Unregister(this);
}
// static
DxgiDuplicatorController* DxgiDuplicatorController::Instance() {
+ const static DpiAwareness one_time_initialization;
// The static instance won't be deleted to ensure it can be used by other
// threads even during program exiting.
static DxgiDuplicatorController* instance = new DxgiDuplicatorController();
@@ -119,6 +137,14 @@ bool DxgiDuplicatorController::DoInitialize() {
RTC_DCHECK(desktop_rect_.is_empty());
RTC_DCHECK(duplicators_.empty());
+ // DPI is used by DxgiOutputDuplicator, so initialize it first.
+ HDC hdc = GetDC(nullptr);
+ // Use old DPI value if failed.
+ if (hdc) {
+ dpi_.set(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
+ ReleaseDC(nullptr, hdc);
+ }
+
std::vector<D3dDevice> devices = D3dDevice::EnumDevices();
if (devices.empty()) {
return false;
@@ -142,13 +168,6 @@ bool DxgiDuplicatorController::DoInitialize() {
}
}
- HDC hdc = GetDC(nullptr);
- // Use old DPI value if failed.
- if (hdc) {
- dpi_.set(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
- ReleaseDC(nullptr, hdc);
- }
-
identity_++;
return true;
}
« 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