OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/win/physical_size.h" | 5 #include "ui/gfx/win/physical_size.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <setupapi.h> | 8 #include <setupapi.h> |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
| 11 #include <memory> |
11 | 12 |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/free_deleter.h" | 14 #include "base/memory/free_deleter.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/scoped_generic.h" | 15 #include "base/scoped_generic.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/win/registry.h" | 17 #include "base/win/registry.h" |
18 | 18 |
19 // This GUID {E6F07B5F-EE97-4A90-B076-33F57BF4EAA7} was taken from | 19 // This GUID {E6F07B5F-EE97-4A90-B076-33F57BF4EAA7} was taken from |
20 // https://msdn.microsoft.com/en-us/library/windows/hardware/ff545901.aspx | 20 // https://msdn.microsoft.com/en-us/library/windows/hardware/ff545901.aspx |
21 const GUID GUID_DEVICEINTERFACE_MONITOR = { | 21 const GUID GUID_DEVICEINTERFACE_MONITOR = { |
22 0xE6F07B5F, | 22 0xE6F07B5F, |
23 0xEE97, | 23 0xEE97, |
24 0x4A90, | 24 0x4A90, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 *width_mm = w; | 66 *width_mm = w; |
67 *height_mm = h; | 67 *height_mm = h; |
68 | 68 |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 bool GetInterfaceDetailAndDeviceInfo( | 72 bool GetInterfaceDetailAndDeviceInfo( |
73 HDEVINFO device_info_list, | 73 HDEVINFO device_info_list, |
74 SP_DEVICE_INTERFACE_DATA* interface_data, | 74 SP_DEVICE_INTERFACE_DATA* interface_data, |
75 scoped_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA, base::FreeDeleter>* | 75 std::unique_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA, base::FreeDeleter>* |
76 interface_detail, | 76 interface_detail, |
77 SP_DEVINFO_DATA* device_info) { | 77 SP_DEVINFO_DATA* device_info) { |
78 DCHECK_EQ(sizeof(*device_info), device_info->cbSize); | 78 DCHECK_EQ(sizeof(*device_info), device_info->cbSize); |
79 DWORD buffer_size; | 79 DWORD buffer_size; |
80 // This call populates device_info. It will also fail, but if the error is | 80 // This call populates device_info. It will also fail, but if the error is |
81 // "insufficient buffer" then it will set buffer_size and we can call again | 81 // "insufficient buffer" then it will set buffer_size and we can call again |
82 // with an allocated buffer. | 82 // with an allocated buffer. |
83 SetupDiGetDeviceInterfaceDetail(device_info_list, interface_data, nullptr, 0, | 83 SetupDiGetDeviceInterfaceDetail(device_info_list, interface_data, nullptr, 0, |
84 &buffer_size, device_info); | 84 &buffer_size, device_info); |
85 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) | 85 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) |
(...skipping 26 matching lines...) Expand all Loading... |
112 | 112 |
113 if (!device_info_list.is_valid()) | 113 if (!device_info_list.is_valid()) |
114 return out; | 114 return out; |
115 | 115 |
116 SP_DEVICE_INTERFACE_DATA interface_data = {}; | 116 SP_DEVICE_INTERFACE_DATA interface_data = {}; |
117 interface_data.cbSize = sizeof(interface_data); | 117 interface_data.cbSize = sizeof(interface_data); |
118 int interface_index = 0; | 118 int interface_index = 0; |
119 while (SetupDiEnumDeviceInterfaces(device_info_list.get(), nullptr, | 119 while (SetupDiEnumDeviceInterfaces(device_info_list.get(), nullptr, |
120 &GUID_DEVICEINTERFACE_MONITOR, | 120 &GUID_DEVICEINTERFACE_MONITOR, |
121 interface_index++, &interface_data)) { | 121 interface_index++, &interface_data)) { |
122 scoped_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA, base::FreeDeleter> | 122 std::unique_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA, base::FreeDeleter> |
123 interface_detail; | 123 interface_detail; |
124 SP_DEVINFO_DATA device_info = {}; | 124 SP_DEVINFO_DATA device_info = {}; |
125 device_info.cbSize = sizeof(device_info); | 125 device_info.cbSize = sizeof(device_info); |
126 bool get_info_succeeded = | 126 bool get_info_succeeded = |
127 GetInterfaceDetailAndDeviceInfo(device_info_list.get(), &interface_data, | 127 GetInterfaceDetailAndDeviceInfo(device_info_list.get(), &interface_data, |
128 &interface_detail, &device_info); | 128 &interface_detail, &device_info); |
129 if (!get_info_succeeded) | 129 if (!get_info_succeeded) |
130 continue; | 130 continue; |
131 | 131 |
132 DISPLAY_DEVICE display_device = {}; | 132 DISPLAY_DEVICE display_device = {}; |
(...skipping 21 matching lines...) Expand all Loading... |
154 } | 154 } |
155 break; | 155 break; |
156 } | 156 } |
157 } | 157 } |
158 } | 158 } |
159 } | 159 } |
160 return out; | 160 return out; |
161 } | 161 } |
162 | 162 |
163 } // namespace gfx | 163 } // namespace gfx |
OLD | NEW |