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 Resolution::Resolution() : refresh_rate(0.0f), interlaced(false) {} |
27 : size(size), | 27 |
28 interlaced(interlaced) { | 28 Resolution::Resolution(const gfx::Size& size, |
29 } | 29 float refresh_rate, |
| 30 bool interlaced) |
| 31 : size(size), refresh_rate(refresh_rate), interlaced(interlaced) {} |
30 | 32 |
31 // satic | 33 // satic |
32 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { | 34 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { |
33 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); | 35 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); |
34 } | 36 } |
35 | 37 |
36 // static | 38 // static |
37 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, | 39 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, |
38 int64 id) { | 40 int64 id) { |
39 // Default bounds for a display. | 41 // Default bounds for a display. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 107 } |
106 | 108 |
107 std::vector<Resolution> resolutions; | 109 std::vector<Resolution> resolutions; |
108 if (Tokenize(main_spec, "#", &parts) == 2) { | 110 if (Tokenize(main_spec, "#", &parts) == 2) { |
109 main_spec = parts[0]; | 111 main_spec = parts[0]; |
110 std::string resolution_list = parts[1]; | 112 std::string resolution_list = parts[1]; |
111 count = Tokenize(resolution_list, "|", &parts); | 113 count = Tokenize(resolution_list, "|", &parts); |
112 for (size_t i = 0; i < count; ++i) { | 114 for (size_t i = 0; i < count; ++i) { |
113 std::string resolution = parts[i]; | 115 std::string resolution = parts[i]; |
114 int width, height; | 116 int width, height; |
115 if (sscanf(resolution.c_str(), "%dx%d", &width, &height) == 2) | 117 float refresh_rate = 0.0f; |
116 resolutions.push_back(Resolution(gfx::Size(width, height), false)); | 118 if (sscanf(resolution.c_str(), |
| 119 "%dx%d%%%f", |
| 120 &width, |
| 121 &height, |
| 122 &refresh_rate) >= 2) |
| 123 resolutions.push_back( |
| 124 Resolution(gfx::Size(width, height), refresh_rate, false)); |
117 } | 125 } |
118 } | 126 } |
119 | 127 |
120 if (id == gfx::Display::kInvalidDisplayID) | 128 if (id == gfx::Display::kInvalidDisplayID) |
121 id = synthesized_display_id++; | 129 id = synthesized_display_id++; |
122 DisplayInfo display_info( | 130 DisplayInfo display_info( |
123 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); | 131 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); |
124 display_info.set_device_scale_factor(device_scale_factor); | 132 display_info.set_device_scale_factor(device_scale_factor); |
125 display_info.set_rotation(rotation); | 133 display_info.set_rotation(rotation); |
126 display_info.set_configured_ui_scale(ui_scale); | 134 display_info.set_configured_ui_scale(ui_scale); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { | 240 void DisplayInfo::SetOverscanInsets(const gfx::Insets& insets_in_dip) { |
233 overscan_insets_in_dip_ = insets_in_dip; | 241 overscan_insets_in_dip_ = insets_in_dip; |
234 } | 242 } |
235 | 243 |
236 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { | 244 gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const { |
237 return overscan_insets_in_dip_.Scale(device_scale_factor_); | 245 return overscan_insets_in_dip_.Scale(device_scale_factor_); |
238 } | 246 } |
239 | 247 |
240 std::string DisplayInfo::ToString() const { | 248 std::string DisplayInfo::ToString() const { |
241 int rotation_degree = static_cast<int>(rotation_) * 90; | 249 int rotation_degree = static_cast<int>(rotation_) * 90; |
| 250 std::string resolutions; |
| 251 std::vector<Resolution>::const_iterator iter; |
| 252 for (iter = resolutions_.begin(); iter != resolutions_.end(); ++iter) { |
| 253 base::StringAppendF(&resolutions, |
| 254 "(%dx%d@%f%c), ", |
| 255 iter->size.width(), |
| 256 iter->size.height(), |
| 257 iter->refresh_rate, |
| 258 iter->interlaced ? 'I' : 'P'); |
| 259 } |
242 return base::StringPrintf( | 260 return base::StringPrintf( |
243 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " | 261 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " |
244 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s", | 262 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s, resolutions=[%s]", |
245 static_cast<long long int>(id_), | 263 static_cast<long long int>(id_), |
246 bounds_in_native_.ToString().c_str(), | 264 bounds_in_native_.ToString().c_str(), |
247 size_in_pixel_.ToString().c_str(), | 265 size_in_pixel_.ToString().c_str(), |
248 device_scale_factor_, | 266 device_scale_factor_, |
249 overscan_insets_in_dip_.ToString().c_str(), | 267 overscan_insets_in_dip_.ToString().c_str(), |
250 rotation_degree, | 268 rotation_degree, |
251 configured_ui_scale_, | 269 configured_ui_scale_, |
252 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE ? "yes" : | 270 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE |
253 touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE ? "no" : | 271 ? "yes" |
254 "unknown"); | 272 : touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE |
| 273 ? "no" |
| 274 : "unknown", |
| 275 resolutions.c_str()); |
255 } | 276 } |
256 | 277 |
257 std::string DisplayInfo::ToFullString() const { | 278 std::string DisplayInfo::ToFullString() const { |
258 std::string resolutions_str; | 279 std::string resolutions_str; |
259 std::vector<Resolution>::const_iterator iter = resolutions_.begin(); | 280 std::vector<Resolution>::const_iterator iter = resolutions_.begin(); |
260 for (; iter != resolutions_.end(); ++iter) { | 281 for (; iter != resolutions_.end(); ++iter) { |
261 if (!resolutions_str.empty()) | 282 if (!resolutions_str.empty()) |
262 resolutions_str += ","; | 283 resolutions_str += ","; |
263 resolutions_str += iter->size.ToString(); | 284 resolutions_str += iter->size.ToString(); |
264 if (iter->interlaced) | 285 if (iter->interlaced) |
265 resolutions_str += "(i)"; | 286 resolutions_str += "(i)"; |
266 } | 287 } |
267 return ToString() + ", resolutions=" + resolutions_str; | 288 return ToString() + ", resolutions=" + resolutions_str; |
268 } | 289 } |
269 | 290 |
270 } // namespace internal | 291 } // namespace internal |
271 } // namespace ash | 292 } // namespace ash |
OLD | NEW |