| 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/gfx/screen_win.h" | 5 #include "ui/gfx/screen_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/hash.h" | 12 #include "base/hash.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
| 16 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 17 #include "ui/gfx/win/dpi.h" | 17 #include "ui/gfx/win/dpi.h" |
| 18 #include "ui/gfx/win/physical_size.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { | 22 MONITORINFOEX GetMonitorInfoForMonitor(HMONITOR monitor) { |
| 22 MONITORINFOEX monitor_info; | 23 MONITORINFOEX monitor_info; |
| 23 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); | 24 ZeroMemory(&monitor_info, sizeof(MONITORINFOEX)); |
| 24 monitor_info.cbSize = sizeof(monitor_info); | 25 monitor_info.cbSize = sizeof(monitor_info); |
| 25 GetMonitorInfo(monitor, &monitor_info); | 26 GetMonitorInfo(monitor, &monitor_info); |
| 26 return monitor_info; | 27 return monitor_info; |
| 27 } | 28 } |
| 28 | 29 |
| 30 int64_t GenerateDisplayId(const std::string& str) { |
| 31 return static_cast<int64_t>(base::Hash(str)); |
| 32 } |
| 33 |
| 29 gfx::Display GetDisplay(const MONITORINFOEX& monitor_info) { | 34 gfx::Display GetDisplay(const MONITORINFOEX& monitor_info) { |
| 30 int64_t id = | 35 int64_t id = GenerateDisplayId(base::WideToUTF8(monitor_info.szDevice)); |
| 31 static_cast<int64_t>(base::Hash(base::WideToUTF8(monitor_info.szDevice))); | |
| 32 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); | 36 gfx::Rect bounds = gfx::Rect(monitor_info.rcMonitor); |
| 33 gfx::Display display(id); | 37 gfx::Display display(id); |
| 34 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); | 38 display.set_bounds(gfx::win::ScreenToDIPRect(bounds)); |
| 35 display.set_work_area( | 39 display.set_work_area( |
| 36 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); | 40 gfx::win::ScreenToDIPRect(gfx::Rect(monitor_info.rcWork))); |
| 37 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); | 41 display.SetScaleAndBounds(gfx::GetDPIScale(), bounds); |
| 38 | 42 |
| 43 int width_mm = 0; |
| 44 int height_mm = 0; |
| 45 std::vector<gfx::PhysicalDisplaySize> display_sizes = |
| 46 gfx::GetPhysicalSizeForDisplays(); |
| 47 for (const auto& display_size : display_sizes) { |
| 48 int64_t interface_id = GenerateDisplayId(display_size.display_name); |
| 49 if (interface_id == id) { |
| 50 width_mm = display_size.width_mm; |
| 51 height_mm = display_size.height_mm; |
| 52 } |
| 53 } |
| 54 display.SetPhysicalSizeMm(gfx::Size(width_mm, height_mm)); |
| 55 |
| 39 DEVMODE mode; | 56 DEVMODE mode; |
| 40 memset(&mode, 0, sizeof(DEVMODE)); | 57 memset(&mode, 0, sizeof(DEVMODE)); |
| 41 mode.dmSize = sizeof(DEVMODE); | 58 mode.dmSize = sizeof(DEVMODE); |
| 42 mode.dmDriverExtra = 0; | 59 mode.dmDriverExtra = 0; |
| 43 if (EnumDisplaySettings(monitor_info.szDevice, | 60 if (EnumDisplaySettings(monitor_info.szDevice, |
| 44 ENUM_CURRENT_SETTINGS, | 61 ENUM_CURRENT_SETTINGS, |
| 45 &mode)) { | 62 &mode)) { |
| 46 switch (mode.dmDisplayOrientation) { | 63 switch (mode.dmDisplayOrientation) { |
| 47 case DMDO_DEFAULT: | 64 case DMDO_DEFAULT: |
| 48 display.set_rotation(gfx::Display::ROTATE_0); | 65 display.set_rotation(gfx::Display::ROTATE_0); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos( | 224 std::vector<gfx::Display> ScreenWin::GetDisplaysForMonitorInfos( |
| 208 const std::vector<MONITORINFOEX>& monitor_infos) { | 225 const std::vector<MONITORINFOEX>& monitor_infos) { |
| 209 std::vector<gfx::Display> displays; | 226 std::vector<gfx::Display> displays; |
| 210 for (const MONITORINFOEX& monitor_info : monitor_infos) | 227 for (const MONITORINFOEX& monitor_info : monitor_infos) |
| 211 displays.push_back(GetDisplay(monitor_info)); | 228 displays.push_back(GetDisplay(monitor_info)); |
| 212 | 229 |
| 213 return displays; | 230 return displays; |
| 214 } | 231 } |
| 215 | 232 |
| 216 } // namespace gfx | 233 } // namespace gfx |
| OLD | NEW |