| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/display/win/screen_win.h" | 5 #include "ui/display/win/screen_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellscalingapi.h> | 8 #include <shellscalingapi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 Display primary_display(g_screen_win_instance->GetPrimaryDisplay()); | 306 Display primary_display(g_screen_win_instance->GetPrimaryDisplay()); |
| 307 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric); | 307 int system_metrics_result = g_screen_win_instance->GetSystemMetrics(metric); |
| 308 | 308 |
| 309 float metrics_relative_scale_factor = hwnd | 309 float metrics_relative_scale_factor = hwnd |
| 310 ? GetScaleFactorForHWND(hwnd) / primary_display.device_scale_factor() | 310 ? GetScaleFactorForHWND(hwnd) / primary_display.device_scale_factor() |
| 311 : 1.0f; | 311 : 1.0f; |
| 312 return static_cast<int>(std::round( | 312 return static_cast<int>(std::round( |
| 313 system_metrics_result * metrics_relative_scale_factor)); | 313 system_metrics_result * metrics_relative_scale_factor)); |
| 314 } | 314 } |
| 315 | 315 |
| 316 // static |
| 317 float ScreenWin::GetScaleFactorForHWND(HWND hwnd) { |
| 318 if (!g_screen_win_instance) |
| 319 return ScreenWinDisplay().display().device_scale_factor(); |
| 320 |
| 321 DCHECK(hwnd); |
| 322 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); |
| 323 ScreenWinDisplay screen_win_display = |
| 324 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); |
| 325 return screen_win_display.display().device_scale_factor(); |
| 326 } |
| 327 |
| 316 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { | 328 HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { |
| 317 NOTREACHED(); | 329 NOTREACHED(); |
| 318 return nullptr; | 330 return nullptr; |
| 319 } | 331 } |
| 320 | 332 |
| 321 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { | 333 gfx::NativeWindow ScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { |
| 322 NOTREACHED(); | 334 NOTREACHED(); |
| 323 return nullptr; | 335 return nullptr; |
| 324 } | 336 } |
| 325 | 337 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 return screen_win_display; | 534 return screen_win_display; |
| 523 } | 535 } |
| 524 // There is 1:1 correspondence between MONITORINFOEX and ScreenWinDisplay. | 536 // There is 1:1 correspondence between MONITORINFOEX and ScreenWinDisplay. |
| 525 // If we make it here, it means we have no displays and we should hand out the | 537 // If we make it here, it means we have no displays and we should hand out the |
| 526 // default display. | 538 // default display. |
| 527 DCHECK_EQ(screen_win_displays_.size(), 0u); | 539 DCHECK_EQ(screen_win_displays_.size(), 0u); |
| 528 return ScreenWinDisplay(); | 540 return ScreenWinDisplay(); |
| 529 } | 541 } |
| 530 | 542 |
| 531 // static | 543 // static |
| 532 float ScreenWin::GetScaleFactorForHWND(HWND hwnd) { | |
| 533 if (!g_screen_win_instance) | |
| 534 return ScreenWinDisplay().display().device_scale_factor(); | |
| 535 | |
| 536 DCHECK(hwnd); | |
| 537 HWND rootHwnd = g_screen_win_instance->GetRootWindow(hwnd); | |
| 538 ScreenWinDisplay screen_win_display = | |
| 539 g_screen_win_instance->GetScreenWinDisplayNearestHWND(rootHwnd); | |
| 540 return screen_win_display.display().device_scale_factor(); | |
| 541 } | |
| 542 | |
| 543 // static | |
| 544 template <typename Getter, typename GetterType> | 544 template <typename Getter, typename GetterType> |
| 545 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, | 545 ScreenWinDisplay ScreenWin::GetScreenWinDisplayVia(Getter getter, |
| 546 GetterType value) { | 546 GetterType value) { |
| 547 if (!g_screen_win_instance) | 547 if (!g_screen_win_instance) |
| 548 return ScreenWinDisplay(); | 548 return ScreenWinDisplay(); |
| 549 | 549 |
| 550 return (g_screen_win_instance->*getter)(value); | 550 return (g_screen_win_instance->*getter)(value); |
| 551 } | 551 } |
| 552 | 552 |
| 553 void ScreenWin::RecordDisplayScaleFactors() const { | 553 void ScreenWin::RecordDisplayScaleFactors() const { |
| 554 std::vector<int> unique_scale_factors; | 554 std::vector<int> unique_scale_factors; |
| 555 for (const auto& screen_win_display : screen_win_displays_) { | 555 for (const auto& screen_win_display : screen_win_displays_) { |
| 556 const float scale_factor = | 556 const float scale_factor = |
| 557 screen_win_display.display().device_scale_factor(); | 557 screen_win_display.display().device_scale_factor(); |
| 558 // Multiply the reported value by 100 to display it as a percentage. Clamp | 558 // Multiply the reported value by 100 to display it as a percentage. Clamp |
| 559 // it so that if it's wildly out-of-band we won't send it to the backend. | 559 // it so that if it's wildly out-of-band we won't send it to the backend. |
| 560 const int reported_scale = std::min( | 560 const int reported_scale = std::min( |
| 561 std::max(base::checked_cast<int>(scale_factor * 100), 0), 1000); | 561 std::max(base::checked_cast<int>(scale_factor * 100), 0), 1000); |
| 562 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), | 562 if (std::find(unique_scale_factors.begin(), unique_scale_factors.end(), |
| 563 reported_scale) == unique_scale_factors.end()) { | 563 reported_scale) == unique_scale_factors.end()) { |
| 564 unique_scale_factors.push_back(reported_scale); | 564 unique_scale_factors.push_back(reported_scale); |
| 565 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); | 565 UMA_HISTOGRAM_SPARSE_SLOWLY("UI.DeviceScale", reported_scale); |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 | 569 |
| 570 } // namespace win | 570 } // namespace win |
| 571 } // namespace display | 571 } // namespace display |
| OLD | NEW |