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; |
} |