| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 struct DisplayInfoSortFunctor { | 75 struct DisplayInfoSortFunctor { |
| 76 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { | 76 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { |
| 77 return a.id() < b.id(); | 77 return a.id() < b.id(); |
| 78 } | 78 } |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 struct ResolutionMatcher { | 81 struct ResolutionMatcher { |
| 82 ResolutionMatcher(const gfx::Size& size) : size(size) {} | 82 explicit ResolutionMatcher(const gfx::Size& size) : size(size) {} |
| 83 bool operator()(const Resolution& resolution) { | 83 bool operator()(const Resolution& resolution) { |
| 84 return resolution.size == size; | 84 return resolution.size == size; |
| 85 } | 85 } |
| 86 gfx::Size size; | 86 gfx::Size size; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 struct ScaleComparator { | 89 struct ScaleComparator { |
| 90 ScaleComparator(float s) : scale(s) {} | 90 explicit ScaleComparator(float s) : scale(s) {} |
| 91 | 91 |
| 92 bool operator()(float s) const { | 92 bool operator()(float s) const { |
| 93 const float kEpsilon = 0.0001f; | 93 const float kEpsilon = 0.0001f; |
| 94 return std::abs(scale - s) < kEpsilon; | 94 return std::abs(scale - s) < kEpsilon; |
| 95 } | 95 } |
| 96 float scale; | 96 float scale; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 gfx::Display& GetInvalidDisplay() { | 99 gfx::Display& GetInvalidDisplay() { |
| 100 static gfx::Display* invalid_display = new gfx::Display(); | 100 static gfx::Display* invalid_display = new gfx::Display(); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 Shell::GetInstance()->output_configurator()->ScheduleConfigureOutputs(); | 467 Shell::GetInstance()->output_configurator()->ScheduleConfigureOutputs(); |
| 468 #endif | 468 #endif |
| 469 } | 469 } |
| 470 | 470 |
| 471 void DisplayManager::RegisterDisplayProperty( | 471 void DisplayManager::RegisterDisplayProperty( |
| 472 int64 display_id, | 472 int64 display_id, |
| 473 gfx::Display::Rotation rotation, | 473 gfx::Display::Rotation rotation, |
| 474 float ui_scale, | 474 float ui_scale, |
| 475 const gfx::Insets* overscan_insets, | 475 const gfx::Insets* overscan_insets, |
| 476 const gfx::Size& resolution_in_pixels) { | 476 const gfx::Size& resolution_in_pixels) { |
| 477 if (display_info_.find(display_id) == display_info_.end()) { | 477 if (display_info_.find(display_id) == display_info_.end()) |
| 478 display_info_[display_id] = | 478 display_info_[display_id] = DisplayInfo(display_id, std::string(), false); |
| 479 DisplayInfo(display_id, std::string(""), false); | |
| 480 } | |
| 481 | 479 |
| 482 display_info_[display_id].set_rotation(rotation); | 480 display_info_[display_id].set_rotation(rotation); |
| 483 // Just in case the preference file was corrupted. | 481 // Just in case the preference file was corrupted. |
| 484 if (0.5f <= ui_scale && ui_scale <= 2.0f) | 482 if (0.5f <= ui_scale && ui_scale <= 2.0f) |
| 485 display_info_[display_id].set_configured_ui_scale(ui_scale); | 483 display_info_[display_id].set_configured_ui_scale(ui_scale); |
| 486 if (overscan_insets) | 484 if (overscan_insets) |
| 487 display_info_[display_id].SetOverscanInsets(*overscan_insets); | 485 display_info_[display_id].SetOverscanInsets(*overscan_insets); |
| 488 if (!resolution_in_pixels.IsEmpty()) | 486 if (!resolution_in_pixels.IsEmpty()) |
| 489 resolutions_[display_id] = resolution_in_pixels; | 487 resolutions_[display_id] = resolution_in_pixels; |
| 490 } | 488 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 current_display_info.bounds_in_native() != | 696 current_display_info.bounds_in_native() != |
| 699 new_display_info.bounds_in_native(); | 697 new_display_info.bounds_in_native(); |
| 700 | 698 |
| 701 if (force_bounds_changed_ || | 699 if (force_bounds_changed_ || |
| 702 host_window_bounds_changed || | 700 host_window_bounds_changed || |
| 703 (current_display.device_scale_factor() != | 701 (current_display.device_scale_factor() != |
| 704 new_display.device_scale_factor()) || | 702 new_display.device_scale_factor()) || |
| 705 (current_display_info.size_in_pixel() != | 703 (current_display_info.size_in_pixel() != |
| 706 new_display.GetSizeInPixel()) || | 704 new_display.GetSizeInPixel()) || |
| 707 (current_display.rotation() != new_display.rotation())) { | 705 (current_display.rotation() != new_display.rotation())) { |
| 708 | |
| 709 changed_display_indices.push_back(new_displays.size()); | 706 changed_display_indices.push_back(new_displays.size()); |
| 710 } | 707 } |
| 711 | 708 |
| 712 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); | 709 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets()); |
| 713 new_displays.push_back(new_display); | 710 new_displays.push_back(new_display); |
| 714 ++curr_iter; | 711 ++curr_iter; |
| 715 ++new_info_iter; | 712 ++new_info_iter; |
| 716 } else if (curr_iter->id() < new_info_iter->id()) { | 713 } else if (curr_iter->id() < new_info_iter->id()) { |
| 717 // more displays in current list between ids, which means it is deleted. | 714 // more displays in current list between ids, which means it is deleted. |
| 718 removed_displays.push_back(*curr_iter); | 715 removed_displays.push_back(*curr_iter); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 | 965 |
| 969 void DisplayManager::AddMirrorDisplayInfoIfAny( | 966 void DisplayManager::AddMirrorDisplayInfoIfAny( |
| 970 std::vector<DisplayInfo>* display_info_list) { | 967 std::vector<DisplayInfo>* display_info_list) { |
| 971 if (software_mirroring_enabled() && IsMirrored()) | 968 if (software_mirroring_enabled() && IsMirrored()) |
| 972 display_info_list->push_back(GetDisplayInfo(mirrored_display_id_)); | 969 display_info_list->push_back(GetDisplayInfo(mirrored_display_id_)); |
| 973 } | 970 } |
| 974 | 971 |
| 975 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { | 972 void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) { |
| 976 std::map<int64, DisplayInfo>::iterator info = | 973 std::map<int64, DisplayInfo>::iterator info = |
| 977 display_info_.find(new_info.id()); | 974 display_info_.find(new_info.id()); |
| 978 if (info != display_info_.end()) | 975 if (info != display_info_.end()) { |
| 979 info->second.Copy(new_info); | 976 info->second.Copy(new_info); |
| 980 else { | 977 } else { |
| 981 display_info_[new_info.id()] = new_info; | 978 display_info_[new_info.id()] = new_info; |
| 982 display_info_[new_info.id()].set_native(false); | 979 display_info_[new_info.id()].set_native(false); |
| 983 } | 980 } |
| 984 display_info_[new_info.id()].UpdateDisplaySize(); | 981 display_info_[new_info.id()].UpdateDisplaySize(); |
| 985 } | 982 } |
| 986 | 983 |
| 987 gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64 id) { | 984 gfx::Display DisplayManager::CreateDisplayFromDisplayInfoById(int64 id) { |
| 988 DCHECK(display_info_.find(id) != display_info_.end()); | 985 DCHECK(display_info_.find(id) != display_info_.end()); |
| 989 const DisplayInfo& display_info = display_info_[id]; | 986 const DisplayInfo& display_info = display_info_[id]; |
| 990 | 987 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1008 DisplayList* displays, | 1005 DisplayList* displays, |
| 1009 size_t* updated_index) const { | 1006 size_t* updated_index) const { |
| 1010 if (displays->size() != 2U) | 1007 if (displays->size() != 2U) |
| 1011 return false; | 1008 return false; |
| 1012 | 1009 |
| 1013 int64 id_at_zero = displays->at(0).id(); | 1010 int64 id_at_zero = displays->at(0).id(); |
| 1014 DisplayIdPair pair = | 1011 DisplayIdPair pair = |
| 1015 (id_at_zero == first_display_id_ || | 1012 (id_at_zero == first_display_id_ || |
| 1016 id_at_zero == gfx::Display::InternalDisplayId()) ? | 1013 id_at_zero == gfx::Display::InternalDisplayId()) ? |
| 1017 std::make_pair(id_at_zero, displays->at(1).id()) : | 1014 std::make_pair(id_at_zero, displays->at(1).id()) : |
| 1018 std::make_pair(displays->at(1).id(), id_at_zero) ; | 1015 std::make_pair(displays->at(1).id(), id_at_zero); |
| 1019 DisplayLayout layout = | 1016 DisplayLayout layout = |
| 1020 layout_store_->ComputeDisplayLayoutForDisplayIdPair(pair); | 1017 layout_store_->ComputeDisplayLayoutForDisplayIdPair(pair); |
| 1021 | 1018 |
| 1022 // Ignore if a user has a old format (should be extremely rare) | 1019 // Ignore if a user has a old format (should be extremely rare) |
| 1023 // and this will be replaced with DCHECK. | 1020 // and this will be replaced with DCHECK. |
| 1024 if (layout.primary_id != gfx::Display::kInvalidDisplayID) { | 1021 if (layout.primary_id != gfx::Display::kInvalidDisplayID) { |
| 1025 size_t primary_index, secondary_index; | 1022 size_t primary_index, secondary_index; |
| 1026 if (displays->at(0).id() == layout.primary_id) { | 1023 if (displays->at(0).id() == layout.primary_id) { |
| 1027 primary_index = 0; | 1024 primary_index = 0; |
| 1028 secondary_index = 1; | 1025 secondary_index = 1; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 break; | 1082 break; |
| 1086 } | 1083 } |
| 1087 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); | 1084 gfx::Insets insets = secondary_display->GetWorkAreaInsets(); |
| 1088 secondary_display->set_bounds( | 1085 secondary_display->set_bounds( |
| 1089 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1086 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 1090 secondary_display->UpdateWorkAreaFromInsets(insets); | 1087 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 1091 } | 1088 } |
| 1092 | 1089 |
| 1093 } // namespace internal | 1090 } // namespace internal |
| 1094 } // namespace ash | 1091 } // namespace ash |
| OLD | NEW |