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 <cmath> | 7 #include <cmath> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 return a.id() < b.id(); | 65 return a.id() < b.id(); |
66 } | 66 } |
67 }; | 67 }; |
68 | 68 |
69 struct DisplayInfoSortFunctor { | 69 struct DisplayInfoSortFunctor { |
70 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 70 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
71 return a.id() < b.id(); | 71 return a.id() < b.id(); |
72 } | 72 } |
73 }; | 73 }; |
74 | 74 |
| 75 struct ResolutionMatcher { |
| 76 ResolutionMatcher(const gfx::Size& size) : size(size) {} |
| 77 bool operator()(const Resolution& resolution) { |
| 78 return resolution.size == size; |
| 79 } |
| 80 gfx::Size size; |
| 81 }; |
| 82 |
75 struct ScaleComparator { | 83 struct ScaleComparator { |
76 ScaleComparator(float s) : scale(s) {} | 84 ScaleComparator(float s) : scale(s) {} |
77 | 85 |
78 bool operator()(float s) const { | 86 bool operator()(float s) const { |
79 const float kEpsilon = 0.0001f; | 87 const float kEpsilon = 0.0001f; |
80 return std::abs(scale - s) < kEpsilon; | 88 return std::abs(scale - s) < kEpsilon; |
81 } | 89 } |
82 float scale; | 90 float scale; |
83 }; | 91 }; |
84 | 92 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 327 } |
320 AddMirrorDisplayInfoIfAny(&display_info_list); | 328 AddMirrorDisplayInfoIfAny(&display_info_list); |
321 UpdateDisplays(display_info_list); | 329 UpdateDisplays(display_info_list); |
322 } | 330 } |
323 | 331 |
324 void DisplayManager::SetDisplayResolution(int64 display_id, | 332 void DisplayManager::SetDisplayResolution(int64 display_id, |
325 const gfx::Size& resolution) { | 333 const gfx::Size& resolution) { |
326 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); | 334 DCHECK_NE(gfx::Display::InternalDisplayId(), display_id); |
327 if (gfx::Display::InternalDisplayId() == display_id) | 335 if (gfx::Display::InternalDisplayId() == display_id) |
328 return; | 336 return; |
329 resolutions_[display_id] = resolution; | 337 const DisplayInfo& display_info = GetDisplayInfo(display_id); |
| 338 const std::vector<Resolution>& resolutions = display_info.resolutions(); |
| 339 DCHECK_NE(0u, resolutions.size()); |
| 340 std::vector<Resolution>::const_iterator iter = |
| 341 std::find_if(resolutions.begin(), |
| 342 resolutions.end(), |
| 343 ResolutionMatcher(resolution)); |
| 344 if (iter == resolutions.end()) { |
| 345 LOG(WARNING) << "Unsupported resolution was requested:" |
| 346 << resolution.ToString(); |
| 347 return; |
| 348 } else if (iter == resolutions.begin()) { |
| 349 // The best resolution was set, so forget it. |
| 350 resolutions_.erase(display_id); |
| 351 } else { |
| 352 resolutions_[display_id] = resolution; |
| 353 } |
330 #if defined(OS_CHROMEOS) && defined(USE_X11) | 354 #if defined(OS_CHROMEOS) && defined(USE_X11) |
331 if (base::chromeos::IsRunningOnChromeOS()) | 355 if (base::chromeos::IsRunningOnChromeOS()) |
332 Shell::GetInstance()->output_configurator()->ScheduleConfigureOutputs(); | 356 Shell::GetInstance()->output_configurator()->ScheduleConfigureOutputs(); |
333 #endif | 357 #endif |
334 } | 358 } |
335 | 359 |
336 void DisplayManager::RegisterDisplayProperty( | 360 void DisplayManager::RegisterDisplayProperty( |
337 int64 display_id, | 361 int64 display_id, |
338 gfx::Display::Rotation rotation, | 362 gfx::Display::Rotation rotation, |
339 float ui_scale, | 363 float ui_scale, |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 if (Shell::GetInstance()->output_configurator_animation()) { | 750 if (Shell::GetInstance()->output_configurator_animation()) { |
727 Shell::GetInstance()->output_configurator_animation()-> | 751 Shell::GetInstance()->output_configurator_animation()-> |
728 StartFadeInAnimation(); | 752 StartFadeInAnimation(); |
729 } | 753 } |
730 #endif | 754 #endif |
731 } | 755 } |
732 | 756 |
733 void DisplayManager::AddRemoveDisplay() { | 757 void DisplayManager::AddRemoveDisplay() { |
734 DCHECK(!displays_.empty()); | 758 DCHECK(!displays_.empty()); |
735 std::vector<DisplayInfo> new_display_info_list; | 759 std::vector<DisplayInfo> new_display_info_list; |
736 DisplayInfo first_display = GetDisplayInfo(displays_[0].id()); | 760 const DisplayInfo& first_display = GetDisplayInfo(displays_[0].id()); |
737 new_display_info_list.push_back(first_display); | 761 new_display_info_list.push_back(first_display); |
738 // Add if there is only one display connected. | 762 // Add if there is only one display connected. |
739 if (num_connected_displays() == 1) { | 763 if (num_connected_displays() == 1) { |
740 // Layout the 2nd display below the primary as with the real device. | 764 // Layout the 2nd display below the primary as with the real device. |
741 gfx::Rect host_bounds = first_display.bounds_in_pixel(); | 765 gfx::Rect host_bounds = first_display.bounds_in_pixel(); |
742 new_display_info_list.push_back(DisplayInfo::CreateFromSpec( | 766 new_display_info_list.push_back(DisplayInfo::CreateFromSpec( |
743 base::StringPrintf( | 767 base::StringPrintf( |
744 "%d+%d-500x400", host_bounds.x(), host_bounds.bottom()))); | 768 "%d+%d-500x400", host_bounds.x(), host_bounds.bottom()))); |
745 } | 769 } |
746 num_connected_displays_ = new_display_info_list.size(); | 770 num_connected_displays_ = new_display_info_list.size(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 break; | 928 break; |
905 } | 929 } |
906 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 930 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
907 secondary_display->set_bounds( | 931 secondary_display->set_bounds( |
908 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 932 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
909 secondary_display->UpdateWorkAreaFromInsets(insets); | 933 secondary_display->UpdateWorkAreaFromInsets(insets); |
910 } | 934 } |
911 | 935 |
912 } // namespace internal | 936 } // namespace internal |
913 } // namespace ash | 937 } // namespace ash |
OLD | NEW |