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 "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/display/display_controller.h" | 9 #include "ash/display/display_controller.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 int64 display_id = gfx::Display::kInvalidDisplayID; | 48 int64 display_id = gfx::Display::kInvalidDisplayID; |
49 if (!base::StringToInt64(id_value, &display_id)) { | 49 if (!base::StringToInt64(id_value, &display_id)) { |
50 LOG(ERROR) << "Invalid display id: " << id_value; | 50 LOG(ERROR) << "Invalid display id: " << id_value; |
51 return gfx::Display::kInvalidDisplayID; | 51 return gfx::Display::kInvalidDisplayID; |
52 } | 52 } |
53 | 53 |
54 return display_id; | 54 return display_id; |
55 } | 55 } |
56 | 56 |
57 bool CompareResolution(ash::internal::Resolution r1, | 57 bool CompareDisplayMode(ash::internal::DisplayMode d1, |
58 ash::internal::Resolution r2) { | 58 ash::internal::DisplayMode d2) { |
59 return r1.size.GetArea() < r2.size.GetArea(); | 59 if (d1.size.GetArea() == d2.size.GetArea()) |
| 60 return d1.refresh_rate < d2.refresh_rate; |
| 61 return d1.size.GetArea() < d2.size.GetArea(); |
60 } | 62 } |
61 | 63 |
62 } // namespace | 64 } // namespace |
63 | 65 |
64 DisplayOptionsHandler::DisplayOptionsHandler() { | 66 DisplayOptionsHandler::DisplayOptionsHandler() { |
65 ash::Shell::GetInstance()->display_controller()->AddObserver(this); | 67 ash::Shell::GetInstance()->display_controller()->AddObserver(this); |
66 } | 68 } |
67 | 69 |
68 DisplayOptionsHandler::~DisplayOptionsHandler() { | 70 DisplayOptionsHandler::~DisplayOptionsHandler() { |
69 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); | 71 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 js_display->SetInteger("x", bounds.x()); | 182 js_display->SetInteger("x", bounds.x()); |
181 js_display->SetInteger("y", bounds.y()); | 183 js_display->SetInteger("y", bounds.y()); |
182 js_display->SetInteger("width", bounds.width()); | 184 js_display->SetInteger("width", bounds.width()); |
183 js_display->SetInteger("height", bounds.height()); | 185 js_display->SetInteger("height", bounds.height()); |
184 js_display->SetString("name", | 186 js_display->SetString("name", |
185 display_manager->GetDisplayNameForId(display.id())); | 187 display_manager->GetDisplayNameForId(display.id())); |
186 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 188 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
187 js_display->SetBoolean("isInternal", display.IsInternal()); | 189 js_display->SetBoolean("isInternal", display.IsInternal()); |
188 js_display->SetInteger("orientation", | 190 js_display->SetInteger("orientation", |
189 static_cast<int>(display_info.rotation())); | 191 static_cast<int>(display_info.rotation())); |
190 std::vector<ash::internal::Resolution> resolutions; | 192 std::vector<ash::internal::DisplayMode> display_modes; |
191 std::vector<float> ui_scales; | 193 std::vector<float> ui_scales; |
192 if (display.IsInternal()) { | 194 if (display.IsInternal()) { |
193 ui_scales = DisplayManager::GetScalesForDisplay(display_info); | 195 ui_scales = DisplayManager::GetScalesForDisplay(display_info); |
194 gfx::SizeF base_size = display_info.bounds_in_native().size(); | 196 gfx::SizeF base_size = display_info.bounds_in_native().size(); |
195 base_size.Scale(1.0f / display_info.device_scale_factor()); | 197 base_size.Scale(1.0f / display_info.device_scale_factor()); |
196 if (display_info.rotation() == gfx::Display::ROTATE_90 || | 198 if (display_info.rotation() == gfx::Display::ROTATE_90 || |
197 display_info.rotation() == gfx::Display::ROTATE_270) { | 199 display_info.rotation() == gfx::Display::ROTATE_270) { |
198 float tmp = base_size.width(); | 200 float tmp = base_size.width(); |
199 base_size.set_width(base_size.height()); | 201 base_size.set_width(base_size.height()); |
200 base_size.set_height(tmp); | 202 base_size.set_height(tmp); |
201 } | 203 } |
202 for (size_t i = 0; i < ui_scales.size(); ++i) { | 204 for (size_t i = 0; i < ui_scales.size(); ++i) { |
203 gfx::SizeF new_size = base_size; | 205 gfx::SizeF new_size = base_size; |
204 new_size.Scale(ui_scales[i]); | 206 new_size.Scale(ui_scales[i]); |
205 resolutions.push_back(ash::internal::Resolution( | 207 display_modes.push_back(ash::internal::DisplayMode( |
206 gfx::ToFlooredSize(new_size), false /* interlaced */)); | 208 gfx::ToFlooredSize(new_size), -1.0f, false, false)); |
207 } | 209 } |
208 } else { | 210 } else { |
209 for (size_t i = 0; i < display_info.resolutions().size(); ++i) | 211 for (size_t i = 0; i < display_info.display_modes().size(); ++i) |
210 resolutions.push_back(display_info.resolutions()[i]); | 212 display_modes.push_back(display_info.display_modes()[i]); |
211 } | 213 } |
212 std::sort(resolutions.begin(), resolutions.end(), CompareResolution); | 214 std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode); |
213 | 215 |
214 base::ListValue* js_resolutions = new base::ListValue(); | 216 base::ListValue* js_resolutions = new base::ListValue(); |
215 gfx::Size current_size = display_info.bounds_in_native().size(); | 217 gfx::Size current_size = display_info.bounds_in_native().size(); |
216 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | 218 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); |
217 for (size_t i = 0; i < resolutions.size(); ++i) { | 219 for (size_t i = 0; i < display_modes.size(); ++i) { |
218 base::DictionaryValue* resolution_info = new base::DictionaryValue(); | 220 base::DictionaryValue* resolution_info = new base::DictionaryValue(); |
219 gfx::Size resolution = resolutions[i].size; | 221 gfx::Size resolution = display_modes[i].size; |
220 if (!ui_scales.empty()) { | 222 if (!ui_scales.empty()) { |
221 resolution_info->SetDouble("scale", ui_scales[i]); | 223 resolution_info->SetDouble("scale", ui_scales[i]); |
222 if (ui_scales[i] == 1.0f) | 224 if (ui_scales[i] == 1.0f) |
223 resolution_info->SetBoolean("isBest", true); | 225 resolution_info->SetBoolean("isBest", true); |
224 resolution_info->SetBoolean( | 226 resolution_info->SetBoolean( |
225 "selected", display_info.configured_ui_scale() == ui_scales[i]); | 227 "selected", display_info.configured_ui_scale() == ui_scales[i]); |
226 } else { | 228 } else { |
227 // Picks the largest one as the "best", which is the last element | 229 // Picks the largest one as the "best", which is the last element |
228 // because |resolutions| is sorted by its area. | 230 // because |display_modes| is sorted by its area. |
229 if (i == resolutions.size() - 1) | 231 if (i == display_modes.size() - 1) |
230 resolution_info->SetBoolean("isBest", true); | 232 resolution_info->SetBoolean("isBest", true); |
231 resolution_info->SetBoolean("selected", (resolution == current_size)); | 233 resolution_info->SetBoolean("selected", (resolution == current_size)); |
232 resolution.Enlarge( | 234 resolution.Enlarge( |
233 -current_overscan.width(), -current_overscan.height()); | 235 -current_overscan.width(), -current_overscan.height()); |
234 } | 236 } |
235 resolution_info->SetInteger("width", resolution.width()); | 237 resolution_info->SetInteger("width", resolution.width()); |
236 resolution_info->SetInteger("height", resolution.height()); | 238 resolution_info->SetInteger("height", resolution.height()); |
| 239 if (display_modes[i].refresh_rate > 0.0f) { |
| 240 resolution_info->SetDouble("refreshRate", |
| 241 display_modes[i].refresh_rate); |
| 242 } |
237 js_resolutions->Append(resolution_info); | 243 js_resolutions->Append(resolution_info); |
238 } | 244 } |
239 js_display->Set("resolutions", js_resolutions); | 245 js_display->Set("resolutions", js_resolutions); |
240 js_displays.Append(js_display); | 246 js_displays.Append(js_display); |
241 } | 247 } |
242 | 248 |
243 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); | 249 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); |
244 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); | 250 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); |
245 if (display_manager->GetNumDisplays() > 1) { | 251 if (display_manager->GetNumDisplays() > 1) { |
246 const ash::DisplayLayout layout = | 252 const ash::DisplayLayout layout = |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 351 } |
346 | 352 |
347 const ash::internal::DisplayInfo& display_info = | 353 const ash::internal::DisplayInfo& display_info = |
348 GetDisplayManager()->GetDisplayInfo(display_id); | 354 GetDisplayManager()->GetDisplayInfo(display_id); |
349 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | 355 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); |
350 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); | 356 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); |
351 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); | 357 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); |
352 gfx::Size old_resolution = display_info.bounds_in_native().size(); | 358 gfx::Size old_resolution = display_info.bounds_in_native().size(); |
353 bool has_new_resolution = false; | 359 bool has_new_resolution = false; |
354 bool has_old_resolution = false; | 360 bool has_old_resolution = false; |
355 for (size_t i = 0; i < display_info.resolutions().size(); ++i) { | 361 for (size_t i = 0; i < display_info.display_modes().size(); ++i) { |
356 ash::internal::Resolution resolution = display_info.resolutions()[i]; | 362 ash::internal::DisplayMode display_mode = display_info.display_modes()[i]; |
357 if (resolution.size == new_resolution) | 363 if (display_mode.size == new_resolution) |
358 has_new_resolution = true; | 364 has_new_resolution = true; |
359 if (resolution.size == old_resolution) | 365 if (display_mode.size == old_resolution) |
360 has_old_resolution = true; | 366 has_old_resolution = true; |
361 } | 367 } |
362 if (!has_new_resolution) { | 368 if (!has_new_resolution) { |
363 LOG(ERROR) << "No new resolution " << new_resolution.ToString() | 369 LOG(ERROR) << "No new resolution " << new_resolution.ToString() |
364 << " is found in the display info " << display_info.ToString(); | 370 << " is found in the display info " << display_info.ToString(); |
365 return; | 371 return; |
366 } | 372 } |
367 if (!has_old_resolution) { | 373 if (!has_old_resolution) { |
368 LOG(ERROR) << "No old resolution " << old_resolution.ToString() | 374 LOG(ERROR) << "No old resolution " << old_resolution.ToString() |
369 << " is found in the display info " << display_info.ToString(); | 375 << " is found in the display info " << display_info.ToString(); |
(...skipping 26 matching lines...) Expand all Loading... |
396 else if (rotation_value == "270") | 402 else if (rotation_value == "270") |
397 new_rotation = gfx::Display::ROTATE_270; | 403 new_rotation = gfx::Display::ROTATE_270; |
398 else if (rotation_value != "0") | 404 else if (rotation_value != "0") |
399 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; | 405 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
400 | 406 |
401 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); | 407 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); |
402 } | 408 } |
403 | 409 |
404 } // namespace options | 410 } // namespace options |
405 } // namespace chromeos | 411 } // namespace chromeos |
OLD | NEW |