| 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 "ash/display/display_manager.h" | 5 #include "ash/display/display_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 7 #include <cmath> | 8 #include <cmath> |
| 8 #include <set> | 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "ash/ash_switches.h" | 13 #include "ash/ash_switches.h" |
| 13 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
| 14 #include "ash/display/screen_ash.h" | 15 #include "ash/display/screen_ash.h" |
| 15 #include "ash/screen_util.h" | 16 #include "ash/screen_util.h" |
| 16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 62 |
| 62 // List of value UI Scale values. Scales for 2x are equivalent to 640, | 63 // List of value UI Scale values. Scales for 2x are equivalent to 640, |
| 63 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on | 64 // 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on |
| 64 // 2560 pixel width 2x density display. Please see crbug.com/233375 | 65 // 2560 pixel width 2x density display. Please see crbug.com/233375 |
| 65 // for the full list of resolutions. | 66 // for the full list of resolutions. |
| 66 const float kUIScalesFor2x[] = | 67 const float kUIScalesFor2x[] = |
| 67 {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; | 68 {0.5f, 0.625f, 0.8f, 1.0f, 1.125f, 1.25f, 1.5f, 2.0f}; |
| 68 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f }; | 69 const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f }; |
| 69 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f }; | 70 const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f }; |
| 70 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f }; | 71 const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f }; |
| 72 const float kDeviceScaleFactorsFor4k[] = {1.0f, 1.25f, 2.0f}; |
| 71 | 73 |
| 72 struct DisplaySortFunctor { | 74 struct DisplaySortFunctor { |
| 73 bool operator()(const gfx::Display& a, const gfx::Display& b) { | 75 bool operator()(const gfx::Display& a, const gfx::Display& b) { |
| 74 return a.id() < b.id(); | 76 return a.id() < b.id(); |
| 75 } | 77 } |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 struct DisplayInfoSortFunctor { | 80 struct DisplayInfoSortFunctor { |
| 79 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 81 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
| 80 return a.id() < b.id(); | 82 return a.id() < b.id(); |
| 81 } | 83 } |
| 82 }; | 84 }; |
| 83 | 85 |
| 84 struct DisplayModeMatcher { | 86 struct DisplayModeMatcher { |
| 85 DisplayModeMatcher(const gfx::Size& size) : size(size) {} | 87 DisplayModeMatcher(const gfx::Size& size) : size(size) {} |
| 86 bool operator()(const DisplayMode& mode) { return mode.size == size; } | 88 bool operator()(const DisplayMode& mode) { return mode.size == size; } |
| 87 gfx::Size size; | 89 gfx::Size size; |
| 88 }; | 90 }; |
| 89 | 91 |
| 92 bool CompareDisplayModeBySize(const DisplayMode& m1, const DisplayMode& m2) { |
| 93 return m1.size.GetArea() < m2.size.GetArea(); |
| 94 } |
| 95 |
| 90 struct ScaleComparator { | 96 struct ScaleComparator { |
| 91 explicit ScaleComparator(float s) : scale(s) {} | 97 explicit ScaleComparator(float s) : scale(s) {} |
| 92 | 98 |
| 93 bool operator()(float s) const { | 99 bool operator()(float s) const { |
| 94 const float kEpsilon = 0.0001f; | 100 const float kEpsilon = 0.0001f; |
| 95 return std::abs(scale - s) < kEpsilon; | 101 return std::abs(scale - s) < kEpsilon; |
| 96 } | 102 } |
| 97 float scale; | 103 float scale; |
| 98 }; | 104 }; |
| 99 | 105 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 ASSIGN_ARRAY(ret, kUIScalesFor1280); | 212 ASSIGN_ARRAY(ret, kUIScalesFor1280); |
| 207 #if defined(OS_CHROMEOS) | 213 #if defined(OS_CHROMEOS) |
| 208 if (base::SysInfo::IsRunningOnChromeOS()) | 214 if (base::SysInfo::IsRunningOnChromeOS()) |
| 209 NOTREACHED() << "Unknown resolution:" << info.ToString(); | 215 NOTREACHED() << "Unknown resolution:" << info.ToString(); |
| 210 #endif | 216 #endif |
| 211 } | 217 } |
| 212 return ret; | 218 return ret; |
| 213 } | 219 } |
| 214 | 220 |
| 215 // static | 221 // static |
| 222 std::vector<float> DisplayManager::GetDeviceScaleFactorsForDisplay( |
| 223 const DisplayInfo& info) { |
| 224 // This method is currently only used for external displays. |
| 225 std::vector<float> scale_factors; |
| 226 scale_factors.push_back(1.0f); |
| 227 if (gfx::Display::InternalDisplayId() == info.id()) |
| 228 return scale_factors; |
| 229 |
| 230 const std::vector<DisplayMode>& display_modes = info.display_modes(); |
| 231 std::vector<DisplayMode>::const_iterator iter = |
| 232 std::max_element(display_modes.begin(), display_modes.end(), |
| 233 CompareDisplayModeBySize); |
| 234 if (iter != display_modes.end() && iter->size.width() >= 3840) |
| 235 ASSIGN_ARRAY(scale_factors, kDeviceScaleFactorsFor4k); |
| 236 return scale_factors; |
| 237 } |
| 238 |
| 239 // static |
| 216 float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { | 240 float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { |
| 217 float scale = info.configured_ui_scale(); | 241 float scale = info.configured_ui_scale(); |
| 218 std::vector<float> scales = GetScalesForDisplay(info); | 242 std::vector<float> scales = GetScalesForDisplay(info); |
| 219 for (size_t i = 0; i < scales.size(); ++i) { | 243 for (size_t i = 0; i < scales.size(); ++i) { |
| 220 if (ScaleComparator(scales[i])(scale)) { | 244 if (ScaleComparator(scales[i])(scale)) { |
| 221 if (up && i != scales.size() - 1) | 245 if (up && i != scales.size() - 1) |
| 222 return scales[i + 1]; | 246 return scales[i + 1]; |
| 223 if (!up && i != 0) | 247 if (!up && i != 0) |
| 224 return scales[i - 1]; | 248 return scales[i - 1]; |
| 225 return scales[i]; | 249 return scales[i]; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 << resolution.ToString(); | 489 << resolution.ToString(); |
| 466 return; | 490 return; |
| 467 } | 491 } |
| 468 display_modes_[display_id] = *iter; | 492 display_modes_[display_id] = *iter; |
| 469 #if defined(OS_CHROMEOS) | 493 #if defined(OS_CHROMEOS) |
| 470 if (base::SysInfo::IsRunningOnChromeOS()) | 494 if (base::SysInfo::IsRunningOnChromeOS()) |
| 471 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); | 495 Shell::GetInstance()->display_configurator()->OnConfigurationChanged(); |
| 472 #endif | 496 #endif |
| 473 } | 497 } |
| 474 | 498 |
| 499 void DisplayManager::SetDisplayDeviceScaleFactor(int64 display_id, |
| 500 float device_scale_factor) { |
| 501 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); |
| 502 if (gfx::Display::InternalDisplayId() == display_id) |
| 503 return; |
| 504 |
| 505 DisplayInfoList display_info_list; |
| 506 for (DisplayList::const_iterator iter = displays_.begin(); |
| 507 iter != displays_.end(); ++iter) { |
| 508 DisplayInfo info = GetDisplayInfo(iter->id()); |
| 509 if (info.id() == display_id) { |
| 510 if (info.device_scale_factor() == device_scale_factor) |
| 511 return; |
| 512 std::vector<float> scales = GetDeviceScaleFactorsForDisplay(info); |
| 513 ScaleComparator comparator(device_scale_factor); |
| 514 if (std::find_if(scales.begin(), scales.end(), comparator) == |
| 515 scales.end()) { |
| 516 return; |
| 517 } |
| 518 info.set_device_scale_factor(device_scale_factor); |
| 519 } |
| 520 display_info_list.push_back(info); |
| 521 } |
| 522 UpdateDisplays(display_info_list); |
| 523 } |
| 524 |
| 475 void DisplayManager::RegisterDisplayProperty( | 525 void DisplayManager::RegisterDisplayProperty( |
| 476 int64 display_id, | 526 int64 display_id, |
| 477 gfx::Display::Rotation rotation, | 527 gfx::Display::Rotation rotation, |
| 478 float ui_scale, | 528 float ui_scale, |
| 479 const gfx::Insets* overscan_insets, | 529 const gfx::Insets* overscan_insets, |
| 480 const gfx::Size& resolution_in_pixels, | 530 const gfx::Size& resolution_in_pixels, |
| 481 ui::ColorCalibrationProfile color_profile) { | 531 ui::ColorCalibrationProfile color_profile) { |
| 482 if (display_info_.find(display_id) == display_info_.end()) | 532 if (display_info_.find(display_id) == display_info_.end()) |
| 483 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); | 533 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); |
| 484 | 534 |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 new_secondary_origin.Offset(-secondary_bounds.width(), offset); | 1194 new_secondary_origin.Offset(-secondary_bounds.width(), offset); |
| 1145 break; | 1195 break; |
| 1146 } | 1196 } |
| 1147 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1197 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 1148 secondary_display->set_bounds( | 1198 secondary_display->set_bounds( |
| 1149 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1199 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 1150 secondary_display->UpdateWorkAreaFromInsets(insets); | 1200 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 1151 } | 1201 } |
| 1152 | 1202 |
| 1153 } // namespace ash | 1203 } // namespace ash |
| OLD | NEW |