OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/display/display_info.h" | 9 #include "ash/display/display_info.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
15 #include "ui/gfx/size_conversions.h" | 15 #include "ui/gfx/size_conversions.h" |
16 #include "ui/gfx/size_f.h" | 16 #include "ui/gfx/size_f.h" |
17 | 17 |
18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
19 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
20 #include "ui/gfx/win/dpi.h" | 20 #include "ui/gfx/win/dpi.h" |
21 #endif | 21 #endif |
22 | 22 |
23 namespace ash { | 23 namespace ash { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 Resolution::Resolution(const gfx::Size& size, bool interlaced) | 26 DisplayMode::DisplayMode() |
| 27 : refresh_rate(0.0f), interlaced(false), native(false) {} |
| 28 |
| 29 DisplayMode::DisplayMode(const gfx::Size& size, |
| 30 float refresh_rate, |
| 31 bool interlaced, |
| 32 bool native) |
27 : size(size), | 33 : size(size), |
28 interlaced(interlaced) { | 34 refresh_rate(refresh_rate), |
29 } | 35 interlaced(interlaced), |
| 36 native(native) {} |
30 | 37 |
31 // satic | 38 // satic |
32 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { | 39 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { |
33 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); | 40 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); |
34 } | 41 } |
35 | 42 |
36 // static | 43 // static |
37 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, | 44 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, |
38 int64 id) { | 45 int64 id) { |
39 // Default bounds for a display. | 46 // Default bounds for a display. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 &device_scale_factor) >= 4) { | 104 &device_scale_factor) >= 4) { |
98 bounds_in_native.SetRect(x, y, width, height); | 105 bounds_in_native.SetRect(x, y, width, height); |
99 } else { | 106 } else { |
100 #if defined(OS_WIN) | 107 #if defined(OS_WIN) |
101 if (gfx::IsHighDPIEnabled()) { | 108 if (gfx::IsHighDPIEnabled()) { |
102 device_scale_factor = gfx::GetModernUIScale(); | 109 device_scale_factor = gfx::GetModernUIScale(); |
103 } | 110 } |
104 #endif | 111 #endif |
105 } | 112 } |
106 | 113 |
107 std::vector<Resolution> resolutions; | 114 std::vector<DisplayMode> display_modes; |
108 if (Tokenize(main_spec, "#", &parts) == 2) { | 115 if (Tokenize(main_spec, "#", &parts) == 2) { |
| 116 size_t native_mode = 0; |
| 117 int largest_area = -1; |
| 118 float highest_refresh_rate = -1.0f; |
109 main_spec = parts[0]; | 119 main_spec = parts[0]; |
110 std::string resolution_list = parts[1]; | 120 std::string resolution_list = parts[1]; |
111 count = Tokenize(resolution_list, "|", &parts); | 121 count = Tokenize(resolution_list, "|", &parts); |
112 for (size_t i = 0; i < count; ++i) { | 122 for (size_t i = 0; i < count; ++i) { |
113 std::string resolution = parts[i]; | 123 std::string resolution = parts[i]; |
114 int width, height; | 124 int width, height; |
115 if (sscanf(resolution.c_str(), "%dx%d", &width, &height) == 2) | 125 float refresh_rate = 0.0f; |
116 resolutions.push_back(Resolution(gfx::Size(width, height), false)); | 126 if (sscanf(resolution.c_str(), |
| 127 "%dx%d%%%f", |
| 128 &width, |
| 129 &height, |
| 130 &refresh_rate) >= 2) { |
| 131 if (width * height >= largest_area && |
| 132 refresh_rate > highest_refresh_rate) { |
| 133 // Use mode with largest area and highest refresh rate as native. |
| 134 largest_area = width * height; |
| 135 highest_refresh_rate = refresh_rate; |
| 136 native_mode = i; |
| 137 } |
| 138 display_modes.push_back( |
| 139 DisplayMode(gfx::Size(width, height), refresh_rate, false, false)); |
| 140 } |
117 } | 141 } |
| 142 display_modes[native_mode].native = true; |
118 } | 143 } |
119 | 144 |
120 if (id == gfx::Display::kInvalidDisplayID) | 145 if (id == gfx::Display::kInvalidDisplayID) |
121 id = synthesized_display_id++; | 146 id = synthesized_display_id++; |
122 DisplayInfo display_info( | 147 DisplayInfo display_info( |
123 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); | 148 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); |
124 display_info.set_device_scale_factor(device_scale_factor); | 149 display_info.set_device_scale_factor(device_scale_factor); |
125 display_info.set_rotation(rotation); | 150 display_info.set_rotation(rotation); |
126 display_info.set_configured_ui_scale(ui_scale); | 151 display_info.set_configured_ui_scale(ui_scale); |
127 display_info.SetBounds(bounds_in_native); | 152 display_info.SetBounds(bounds_in_native); |
128 display_info.set_resolutions(resolutions); | 153 display_info.set_display_modes(display_modes); |
129 | 154 |
130 // To test the overscan, it creates the default 5% overscan. | 155 // To test the overscan, it creates the default 5% overscan. |
131 if (has_overscan) { | 156 if (has_overscan) { |
132 int width = bounds_in_native.width() / device_scale_factor / 40; | 157 int width = bounds_in_native.width() / device_scale_factor / 40; |
133 int height = bounds_in_native.height() / device_scale_factor / 40; | 158 int height = bounds_in_native.height() / device_scale_factor / 40; |
134 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); | 159 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); |
135 display_info.UpdateDisplaySize(); | 160 display_info.UpdateDisplaySize(); |
136 } | 161 } |
137 | 162 |
138 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() | 163 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 195 |
171 void DisplayInfo::Copy(const DisplayInfo& native_info) { | 196 void DisplayInfo::Copy(const DisplayInfo& native_info) { |
172 DCHECK(id_ == native_info.id_); | 197 DCHECK(id_ == native_info.id_); |
173 name_ = native_info.name_; | 198 name_ = native_info.name_; |
174 has_overscan_ = native_info.has_overscan_; | 199 has_overscan_ = native_info.has_overscan_; |
175 | 200 |
176 DCHECK(!native_info.bounds_in_native_.IsEmpty()); | 201 DCHECK(!native_info.bounds_in_native_.IsEmpty()); |
177 bounds_in_native_ = native_info.bounds_in_native_; | 202 bounds_in_native_ = native_info.bounds_in_native_; |
178 size_in_pixel_ = native_info.size_in_pixel_; | 203 size_in_pixel_ = native_info.size_in_pixel_; |
179 device_scale_factor_ = native_info.device_scale_factor_; | 204 device_scale_factor_ = native_info.device_scale_factor_; |
180 resolutions_ = native_info.resolutions_; | 205 display_modes_ = native_info.display_modes_; |
181 touch_support_ = native_info.touch_support_; | 206 touch_support_ = native_info.touch_support_; |
182 | 207 |
183 // Copy overscan_insets_in_dip_ if it's not empty. This is for test | 208 // Copy overscan_insets_in_dip_ if it's not empty. This is for test |
184 // cases which use "/o" annotation which sets the overscan inset | 209 // cases which use "/o" annotation which sets the overscan inset |
185 // to native, and that overscan has to be propagated. This does not | 210 // to native, and that overscan has to be propagated. This does not |
186 // happen on the real environment. | 211 // happen on the real environment. |
187 if (!native_info.overscan_insets_in_dip_.empty()) | 212 if (!native_info.overscan_insets_in_dip_.empty()) |
188 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; | 213 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; |
189 | 214 |
190 // Rotation_ and ui_scale_ are given by preference, or unit | 215 // Rotation_ and ui_scale_ are given by preference, or unit |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return base::StringPrintf( | 267 return base::StringPrintf( |
243 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " | 268 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " |
244 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s", | 269 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s", |
245 static_cast<long long int>(id_), | 270 static_cast<long long int>(id_), |
246 bounds_in_native_.ToString().c_str(), | 271 bounds_in_native_.ToString().c_str(), |
247 size_in_pixel_.ToString().c_str(), | 272 size_in_pixel_.ToString().c_str(), |
248 device_scale_factor_, | 273 device_scale_factor_, |
249 overscan_insets_in_dip_.ToString().c_str(), | 274 overscan_insets_in_dip_.ToString().c_str(), |
250 rotation_degree, | 275 rotation_degree, |
251 configured_ui_scale_, | 276 configured_ui_scale_, |
252 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE ? "yes" : | 277 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE |
253 touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE ? "no" : | 278 ? "yes" |
254 "unknown"); | 279 : touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE |
| 280 ? "no" |
| 281 : "unknown"); |
255 } | 282 } |
256 | 283 |
257 std::string DisplayInfo::ToFullString() const { | 284 std::string DisplayInfo::ToFullString() const { |
258 std::string resolutions_str; | 285 std::string display_modes_str; |
259 std::vector<Resolution>::const_iterator iter = resolutions_.begin(); | 286 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin(); |
260 for (; iter != resolutions_.end(); ++iter) { | 287 for (; iter != display_modes_.end(); ++iter) { |
261 if (!resolutions_str.empty()) | 288 if (!display_modes_str.empty()) |
262 resolutions_str += ","; | 289 display_modes_str += ","; |
263 resolutions_str += iter->size.ToString(); | 290 base::StringAppendF(&display_modes_str, |
264 if (iter->interlaced) | 291 "(%dx%d@%f%c%s)", |
265 resolutions_str += "(i)"; | 292 iter->size.width(), |
| 293 iter->size.height(), |
| 294 iter->refresh_rate, |
| 295 iter->interlaced ? 'I' : 'P', |
| 296 iter->native ? "(N)" : ""); |
266 } | 297 } |
267 return ToString() + ", resolutions=" + resolutions_str; | 298 return ToString() + ", display_modes==" + display_modes_str; |
268 } | 299 } |
269 | 300 |
270 } // namespace internal | 301 } // namespace internal |
271 } // namespace ash | 302 } // namespace ash |
OLD | NEW |