| 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 <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
| 47 #include "base/sys_info.h" | 47 #include "base/sys_info.h" |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 51 #include "base/win/windows_version.h" | 51 #include "base/win/windows_version.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 namespace ash { | 54 namespace ash { |
| 55 typedef std::vector<gfx::Display> DisplayList; | |
| 56 typedef std::vector<DisplayInfo> DisplayInfoList; | 55 typedef std::vector<DisplayInfo> DisplayInfoList; |
| 57 | 56 |
| 58 namespace { | 57 namespace { |
| 59 | 58 |
| 60 // We need to keep this in order for unittests to tell if | 59 // We need to keep this in order for unittests to tell if |
| 61 // the object in gfx::Screen::GetScreenByType is for shutdown. | 60 // the object in gfx::Screen::GetScreenByType is for shutdown. |
| 62 gfx::Screen* screen_for_shutdown = nullptr; | 61 gfx::Screen* screen_for_shutdown = nullptr; |
| 63 | 62 |
| 64 // The number of pixels to overlap between the primary and secondary displays, | 63 // The number of pixels to overlap between the primary and secondary displays, |
| 65 // in case that the offset value is too large. | 64 // in case that the offset value is too large. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 110 |
| 112 gfx::Size GetMaxNativeSize(const DisplayInfo& info) { | 111 gfx::Size GetMaxNativeSize(const DisplayInfo& info) { |
| 113 gfx::Size size; | 112 gfx::Size size; |
| 114 for (auto& mode : info.display_modes()) { | 113 for (auto& mode : info.display_modes()) { |
| 115 if (mode.size.GetArea() > size.GetArea()) | 114 if (mode.size.GetArea() > size.GetArea()) |
| 116 size = mode.size; | 115 size = mode.size; |
| 117 } | 116 } |
| 118 return size; | 117 return size; |
| 119 } | 118 } |
| 120 | 119 |
| 121 gfx::Display* FindDisplayById(DisplayList* display_list, int64_t id) { | 120 gfx::Display* FindDisplayById(display::DisplayList* display_list, int64_t id) { |
| 122 auto iter = std::find_if( | 121 auto iter = std::find_if( |
| 123 display_list->begin(), display_list->end(), | 122 display_list->begin(), display_list->end(), |
| 124 [id](const gfx::Display& display) { return display.id() == id; }); | 123 [id](const gfx::Display& display) { return display.id() == id; }); |
| 125 return &(*iter); | 124 return &(*iter); |
| 126 } | 125 } |
| 127 | 126 |
| 128 } // namespace | 127 } // namespace |
| 129 | 128 |
| 130 using std::string; | 129 using std::string; |
| 131 using std::vector; | 130 using std::vector; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 float largest_device_scale_factor = 1.0f; | 203 float largest_device_scale_factor = 1.0f; |
| 205 for (const gfx::Display& display : active_display_list_) { | 204 for (const gfx::Display& display : active_display_list_) { |
| 206 const ash::DisplayInfo& info = display_info_[display.id()]; | 205 const ash::DisplayInfo& info = display_info_[display.id()]; |
| 207 largest_device_scale_factor = std::max( | 206 largest_device_scale_factor = std::max( |
| 208 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); | 207 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); |
| 209 } | 208 } |
| 210 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); | 209 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); |
| 211 #endif // OS_CHROMEOS | 210 #endif // OS_CHROMEOS |
| 212 } | 211 } |
| 213 | 212 |
| 214 const DisplayLayout& DisplayManager::GetCurrentDisplayLayout() const { | 213 const display::DisplayLayout& DisplayManager::GetCurrentDisplayLayout() const { |
| 215 DCHECK_LE(2U, num_connected_displays()); | 214 DCHECK_LE(2U, num_connected_displays()); |
| 216 if (num_connected_displays() > 1) { | 215 if (num_connected_displays() > 1) { |
| 217 DisplayIdList list = GetCurrentDisplayIdList(); | 216 display::DisplayIdList list = GetCurrentDisplayIdList(); |
| 218 return layout_store_->GetRegisteredDisplayLayout(list); | 217 return layout_store_->GetRegisteredDisplayLayout(list); |
| 219 } | 218 } |
| 220 LOG(ERROR) << "DisplayLayout is requested for single display"; | 219 LOG(ERROR) << "DisplayLayout is requested for single display"; |
| 221 // On release build, just fallback to default instead of blowing up. | 220 // On release build, just fallback to default instead of blowing up. |
| 222 static DisplayLayout layout; | 221 static display::DisplayLayout layout; |
| 223 layout.primary_id = active_display_list_[0].id(); | 222 layout.primary_id = active_display_list_[0].id(); |
| 224 return layout; | 223 return layout; |
| 225 } | 224 } |
| 226 | 225 |
| 227 DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { | 226 display::DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { |
| 228 if (IsInUnifiedMode()) { | 227 if (IsInUnifiedMode()) { |
| 229 return CreateDisplayIdList(software_mirroring_display_list_); | 228 return CreateDisplayIdList(software_mirroring_display_list_); |
| 230 } else if (IsInMirrorMode()) { | 229 } else if (IsInMirrorMode()) { |
| 231 if (software_mirroring_enabled()) { | 230 if (software_mirroring_enabled()) { |
| 232 CHECK_EQ(2u, num_connected_displays()); | 231 CHECK_EQ(2u, num_connected_displays()); |
| 233 // This comment is to make it easy to distinguish the crash | 232 // This comment is to make it easy to distinguish the crash |
| 234 // between two checks. | 233 // between two checks. |
| 235 CHECK_EQ(1u, active_display_list_.size()); | 234 CHECK_EQ(1u, active_display_list_.size()); |
| 236 } | 235 } |
| 237 int64_t ids[] = {active_display_list_[0].id(), mirroring_display_id_}; | 236 int64_t ids[] = {active_display_list_[0].id(), mirroring_display_id_}; |
| 238 return ash::GenerateDisplayIdList(std::begin(ids), std::end(ids)); | 237 return ash::GenerateDisplayIdList(std::begin(ids), std::end(ids)); |
| 239 } else { | 238 } else { |
| 240 CHECK_LE(2u, active_display_list_.size()); | 239 CHECK_LE(2u, active_display_list_.size()); |
| 241 return CreateDisplayIdList(active_display_list_); | 240 return CreateDisplayIdList(active_display_list_); |
| 242 } | 241 } |
| 243 } | 242 } |
| 244 | 243 |
| 245 void DisplayManager::SetLayoutForCurrentDisplays( | 244 void DisplayManager::SetLayoutForCurrentDisplays( |
| 246 scoped_ptr<DisplayLayout> layout) { | 245 scoped_ptr<display::DisplayLayout> layout) { |
| 247 if (GetNumDisplays() == 1) | 246 if (GetNumDisplays() == 1) |
| 248 return; | 247 return; |
| 249 const DisplayIdList list = GetCurrentDisplayIdList(); | 248 const display::DisplayIdList list = GetCurrentDisplayIdList(); |
| 250 | 249 |
| 251 DCHECK(DisplayLayout::Validate(list, *layout)); | 250 DCHECK(display::DisplayLayout::Validate(list, *layout)); |
| 252 | 251 |
| 253 const DisplayLayout& current_layout = | 252 const display::DisplayLayout& current_layout = |
| 254 layout_store_->GetRegisteredDisplayLayout(list); | 253 layout_store_->GetRegisteredDisplayLayout(list); |
| 255 | 254 |
| 256 if (layout->HasSamePlacementList(current_layout)) | 255 if (layout->HasSamePlacementList(current_layout)) |
| 257 return; | 256 return; |
| 258 | 257 |
| 259 layout_store_->RegisterLayoutForDisplayIdList(list, std::move(layout)); | 258 layout_store_->RegisterLayoutForDisplayIdList(list, std::move(layout)); |
| 260 if (delegate_) | 259 if (delegate_) |
| 261 delegate_->PreDisplayConfigurationChange(false); | 260 delegate_->PreDisplayConfigurationChange(false); |
| 262 | 261 |
| 263 // TODO(oshima): Call UpdateDisplays instead. | 262 // TODO(oshima): Call UpdateDisplays instead. |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 display_info_[gfx::Display::InternalDisplayId()].GetRotation( | 606 display_info_[gfx::Display::InternalDisplayId()].GetRotation( |
| 608 gfx::Display::ROTATION_SOURCE_USER); | 607 gfx::Display::ROTATION_SOURCE_USER); |
| 609 display_info_[gfx::Display::InternalDisplayId()].SetRotation( | 608 display_info_[gfx::Display::InternalDisplayId()].SetRotation( |
| 610 user_rotation, gfx::Display::ROTATION_SOURCE_USER); | 609 user_rotation, gfx::Display::ROTATION_SOURCE_USER); |
| 611 } | 610 } |
| 612 } | 611 } |
| 613 | 612 |
| 614 #if defined(OS_CHROMEOS) | 613 #if defined(OS_CHROMEOS) |
| 615 if (!base::SysInfo::IsRunningOnChromeOS() && | 614 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 616 new_display_info_list.size() > 1) { | 615 new_display_info_list.size() > 1) { |
| 617 DisplayIdList list = GenerateDisplayIdList( | 616 display::DisplayIdList list = GenerateDisplayIdList( |
| 618 new_display_info_list.begin(), new_display_info_list.end(), | 617 new_display_info_list.begin(), new_display_info_list.end(), |
| 619 [](const DisplayInfo& info) { return info.id(); }); | 618 [](const DisplayInfo& info) { return info.id(); }); |
| 620 | 619 |
| 621 const DisplayLayout& layout = | 620 const display::DisplayLayout& layout = |
| 622 layout_store_->GetRegisteredDisplayLayout(list); | 621 layout_store_->GetRegisteredDisplayLayout(list); |
| 623 // Mirror mode is set by DisplayConfigurator on the device. | 622 // Mirror mode is set by DisplayConfigurator on the device. |
| 624 // Emulate it when running on linux desktop. | 623 // Emulate it when running on linux desktop. |
| 625 if (layout.mirrored) | 624 if (layout.mirrored) |
| 626 SetMultiDisplayMode(MIRRORING); | 625 SetMultiDisplayMode(MIRRORING); |
| 627 } | 626 } |
| 628 #endif | 627 #endif |
| 629 | 628 |
| 630 UpdateDisplaysWith(new_display_info_list); | 629 UpdateDisplaysWith(new_display_info_list); |
| 631 } | 630 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 647 #endif | 646 #endif |
| 648 | 647 |
| 649 DisplayInfoList new_display_info_list = updated_display_info_list; | 648 DisplayInfoList new_display_info_list = updated_display_info_list; |
| 650 std::sort(active_display_list_.begin(), active_display_list_.end(), | 649 std::sort(active_display_list_.begin(), active_display_list_.end(), |
| 651 DisplaySortFunctor()); | 650 DisplaySortFunctor()); |
| 652 std::sort(new_display_info_list.begin(), | 651 std::sort(new_display_info_list.begin(), |
| 653 new_display_info_list.end(), | 652 new_display_info_list.end(), |
| 654 DisplayInfoSortFunctor()); | 653 DisplayInfoSortFunctor()); |
| 655 | 654 |
| 656 if (new_display_info_list.size() > 1) { | 655 if (new_display_info_list.size() > 1) { |
| 657 DisplayIdList list = GenerateDisplayIdList( | 656 display::DisplayIdList list = GenerateDisplayIdList( |
| 658 new_display_info_list.begin(), new_display_info_list.end(), | 657 new_display_info_list.begin(), new_display_info_list.end(), |
| 659 [](const DisplayInfo& info) { return info.id(); }); | 658 [](const DisplayInfo& info) { return info.id(); }); |
| 660 const DisplayLayout& layout = | 659 const display::DisplayLayout& layout = |
| 661 layout_store_->GetRegisteredDisplayLayout(list); | 660 layout_store_->GetRegisteredDisplayLayout(list); |
| 662 current_default_multi_display_mode_ = | 661 current_default_multi_display_mode_ = |
| 663 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED | 662 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED |
| 664 : EXTENDED; | 663 : EXTENDED; |
| 665 } | 664 } |
| 666 | 665 |
| 667 if (multi_display_mode_ != MIRRORING) | 666 if (multi_display_mode_ != MIRRORING) |
| 668 multi_display_mode_ = current_default_multi_display_mode_; | 667 multi_display_mode_ = current_default_multi_display_mode_; |
| 669 | 668 |
| 670 CreateSoftwareMirroringDisplayInfo(&new_display_info_list); | 669 CreateSoftwareMirroringDisplayInfo(&new_display_info_list); |
| 671 | 670 |
| 672 // Close the mirroring window if any here to avoid creating two compositor on | 671 // Close the mirroring window if any here to avoid creating two compositor on |
| 673 // one display. | 672 // one display. |
| 674 if (delegate_) | 673 if (delegate_) |
| 675 delegate_->CloseMirroringDisplayIfNotNecessary(); | 674 delegate_->CloseMirroringDisplayIfNotNecessary(); |
| 676 | 675 |
| 677 DisplayList new_displays; | 676 display::DisplayList new_displays; |
| 678 DisplayList removed_displays; | 677 display::DisplayList removed_displays; |
| 679 std::map<size_t, uint32_t> display_changes; | 678 std::map<size_t, uint32_t> display_changes; |
| 680 std::vector<size_t> added_display_indices; | 679 std::vector<size_t> added_display_indices; |
| 681 | 680 |
| 682 DisplayList::iterator curr_iter = active_display_list_.begin(); | 681 display::DisplayList::iterator curr_iter = active_display_list_.begin(); |
| 683 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin(); | 682 DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin(); |
| 684 | 683 |
| 685 while (curr_iter != active_display_list_.end() || | 684 while (curr_iter != active_display_list_.end() || |
| 686 new_info_iter != new_display_info_list.end()) { | 685 new_info_iter != new_display_info_list.end()) { |
| 687 if (curr_iter == active_display_list_.end()) { | 686 if (curr_iter == active_display_list_.end()) { |
| 688 // more displays in new list. | 687 // more displays in new list. |
| 689 added_display_indices.push_back(new_displays.size()); | 688 added_display_indices.push_back(new_displays.size()); |
| 690 InsertAndUpdateDisplayInfo(*new_info_iter); | 689 InsertAndUpdateDisplayInfo(*new_info_iter); |
| 691 new_displays.push_back( | 690 new_displays.push_back( |
| 692 CreateDisplayFromDisplayInfoById(new_info_iter->id())); | 691 CreateDisplayFromDisplayInfoById(new_info_iter->id())); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } | 846 } |
| 848 | 847 |
| 849 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { | 848 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { |
| 850 DCHECK_LT(index, active_display_list_.size()); | 849 DCHECK_LT(index, active_display_list_.size()); |
| 851 return active_display_list_[index]; | 850 return active_display_list_[index]; |
| 852 } | 851 } |
| 853 | 852 |
| 854 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { | 853 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { |
| 855 if (GetNumDisplays() != 2) | 854 if (GetNumDisplays() != 2) |
| 856 return active_display_list_[0]; | 855 return active_display_list_[0]; |
| 857 const DisplayLayout& layout = | 856 const display::DisplayLayout& layout = |
| 858 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); | 857 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); |
| 859 return GetDisplayForId(layout.primary_id); | 858 return GetDisplayForId(layout.primary_id); |
| 860 } | 859 } |
| 861 | 860 |
| 862 size_t DisplayManager::GetNumDisplays() const { | 861 size_t DisplayManager::GetNumDisplays() const { |
| 863 return active_display_list_.size(); | 862 return active_display_list_.size(); |
| 864 } | 863 } |
| 865 | 864 |
| 866 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { | 865 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { |
| 867 return std::find_if(active_display_list_.begin(), active_display_list_.end(), | 866 return std::find_if(active_display_list_.begin(), active_display_list_.end(), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 } | 963 } |
| 965 num_connected_displays_ = new_display_info_list.size(); | 964 num_connected_displays_ = new_display_info_list.size(); |
| 966 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 965 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; |
| 967 software_mirroring_display_list_.clear(); | 966 software_mirroring_display_list_.clear(); |
| 968 UpdateDisplaysWith(new_display_info_list); | 967 UpdateDisplaysWith(new_display_info_list); |
| 969 } | 968 } |
| 970 | 969 |
| 971 void DisplayManager::ToggleDisplayScaleFactor() { | 970 void DisplayManager::ToggleDisplayScaleFactor() { |
| 972 DCHECK(!active_display_list_.empty()); | 971 DCHECK(!active_display_list_.empty()); |
| 973 std::vector<DisplayInfo> new_display_info_list; | 972 std::vector<DisplayInfo> new_display_info_list; |
| 974 for (DisplayList::const_iterator iter = active_display_list_.begin(); | 973 for (display::DisplayList::const_iterator iter = active_display_list_.begin(); |
| 975 iter != active_display_list_.end(); ++iter) { | 974 iter != active_display_list_.end(); ++iter) { |
| 976 DisplayInfo display_info = GetDisplayInfo(iter->id()); | 975 DisplayInfo display_info = GetDisplayInfo(iter->id()); |
| 977 display_info.set_device_scale_factor( | 976 display_info.set_device_scale_factor( |
| 978 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); | 977 display_info.device_scale_factor() == 1.0f ? 2.0f : 1.0f); |
| 979 new_display_info_list.push_back(display_info); | 978 new_display_info_list.push_back(display_info); |
| 980 } | 979 } |
| 981 AddMirrorDisplayInfoIfAny(&new_display_info_list); | 980 AddMirrorDisplayInfoIfAny(&new_display_info_list); |
| 982 UpdateDisplaysWith(new_display_info_list); | 981 UpdateDisplaysWith(new_display_info_list); |
| 983 } | 982 } |
| 984 | 983 |
| 985 #if defined(OS_CHROMEOS) | 984 #if defined(OS_CHROMEOS) |
| 986 void DisplayManager::SetSoftwareMirroring(bool enabled) { | 985 void DisplayManager::SetSoftwareMirroring(bool enabled) { |
| 987 SetMultiDisplayMode(enabled ? MIRRORING | 986 SetMultiDisplayMode(enabled ? MIRRORING |
| 988 : current_default_multi_display_mode_); | 987 : current_default_multi_display_mode_); |
| 989 } | 988 } |
| 990 | 989 |
| 991 bool DisplayManager::SoftwareMirroringEnabled() const { | 990 bool DisplayManager::SoftwareMirroringEnabled() const { |
| 992 return software_mirroring_enabled(); | 991 return software_mirroring_enabled(); |
| 993 } | 992 } |
| 994 #endif | 993 #endif |
| 995 | 994 |
| 996 void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( | 995 void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( |
| 997 MultiDisplayMode mode) { | 996 MultiDisplayMode mode) { |
| 998 DCHECK_NE(MIRRORING, mode); | 997 DCHECK_NE(MIRRORING, mode); |
| 999 DisplayIdList list = GetCurrentDisplayIdList(); | 998 display::DisplayIdList list = GetCurrentDisplayIdList(); |
| 1000 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), | 999 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), |
| 1001 mode == UNIFIED); | 1000 mode == UNIFIED); |
| 1002 ReconfigureDisplays(); | 1001 ReconfigureDisplays(); |
| 1003 } | 1002 } |
| 1004 | 1003 |
| 1005 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { | 1004 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { |
| 1006 multi_display_mode_ = mode; | 1005 multi_display_mode_ = mode; |
| 1007 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 1006 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; |
| 1008 software_mirroring_display_list_.clear(); | 1007 software_mirroring_display_list_.clear(); |
| 1009 } | 1008 } |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 | 1274 |
| 1276 gfx::Display new_display(display_info.id()); | 1275 gfx::Display new_display(display_info.id()); |
| 1277 new_display.SetScaleAndBounds( | 1276 new_display.SetScaleAndBounds( |
| 1278 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( | 1277 1.0f, gfx::Rect(origin, gfx::ScaleToFlooredSize( |
| 1279 display_info.size_in_pixel(), scale))); | 1278 display_info.size_in_pixel(), scale))); |
| 1280 new_display.set_touch_support(display_info.touch_support()); | 1279 new_display.set_touch_support(display_info.touch_support()); |
| 1281 return new_display; | 1280 return new_display; |
| 1282 } | 1281 } |
| 1283 | 1282 |
| 1284 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( | 1283 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( |
| 1285 DisplayList* display_list, | 1284 display::DisplayList* display_list, |
| 1286 std::vector<size_t>* updated_indices) { | 1285 std::vector<size_t>* updated_indices) { |
| 1287 if (display_list->size() == 1u) | 1286 if (display_list->size() == 1u) |
| 1288 return; | 1287 return; |
| 1289 | 1288 |
| 1290 const DisplayLayout& layout = layout_store_->GetRegisteredDisplayLayout( | 1289 const display::DisplayLayout& layout = |
| 1291 CreateDisplayIdList(*display_list)); | 1290 layout_store_->GetRegisteredDisplayLayout( |
| 1291 CreateDisplayIdList(*display_list)); |
| 1292 | 1292 |
| 1293 // Ignore if a user has a old format (should be extremely rare) | 1293 // Ignore if a user has a old format (should be extremely rare) |
| 1294 // and this will be replaced with DCHECK. | 1294 // and this will be replaced with DCHECK. |
| 1295 if (layout.primary_id == gfx::Display::kInvalidDisplayID) | 1295 if (layout.primary_id == gfx::Display::kInvalidDisplayID) |
| 1296 return; | 1296 return; |
| 1297 | 1297 |
| 1298 std::vector<int64_t> ids; | 1298 std::vector<int64_t> ids; |
| 1299 ApplyDisplayLayout(layout, display_list, &ids); | 1299 ApplyDisplayLayout(layout, display_list, &ids); |
| 1300 for (int64_t display_id : ids) { | 1300 for (int64_t display_id : ids) { |
| 1301 DCHECK_NE(gfx::Display::kInvalidDisplayID, display_id); | 1301 DCHECK_NE(gfx::Display::kInvalidDisplayID, display_id); |
| 1302 const auto iter = std::find_if(display_list->begin(), display_list->end(), | 1302 const auto iter = std::find_if(display_list->begin(), display_list->end(), |
| 1303 [display_id](const gfx::Display& display) { | 1303 [display_id](const gfx::Display& display) { |
| 1304 return display.id() == display_id; | 1304 return display.id() == display_id; |
| 1305 }); | 1305 }); |
| 1306 DCHECK(display_list->end() != iter); | 1306 DCHECK(display_list->end() != iter); |
| 1307 updated_indices->push_back(iter - display_list->begin()); | 1307 updated_indices->push_back(iter - display_list->begin()); |
| 1308 } | 1308 } |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 void DisplayManager::CreateMirrorWindowIfAny() { | 1311 void DisplayManager::CreateMirrorWindowIfAny() { |
| 1312 if (software_mirroring_display_list_.empty() || !delegate_) | 1312 if (software_mirroring_display_list_.empty() || !delegate_) |
| 1313 return; | 1313 return; |
| 1314 DisplayInfoList list; | 1314 DisplayInfoList list; |
| 1315 for (auto& display : software_mirroring_display_list_) | 1315 for (auto& display : software_mirroring_display_list_) |
| 1316 list.push_back(GetDisplayInfo(display.id())); | 1316 list.push_back(GetDisplayInfo(display.id())); |
| 1317 delegate_->CreateOrUpdateMirroringDisplay(list); | 1317 delegate_->CreateOrUpdateMirroringDisplay(list); |
| 1318 } | 1318 } |
| 1319 | 1319 |
| 1320 void DisplayManager::ApplyDisplayLayout(const DisplayLayout& layout, | 1320 void DisplayManager::ApplyDisplayLayout(const display::DisplayLayout& layout, |
| 1321 DisplayList* display_list, | 1321 display::DisplayList* display_list, |
| 1322 std::vector<int64_t>* updated_ids) { | 1322 std::vector<int64_t>* updated_ids) { |
| 1323 // Layout from primary, then dependent displays. | 1323 // Layout from primary, then dependent displays. |
| 1324 std::set<int64_t> parents; | 1324 std::set<int64_t> parents; |
| 1325 parents.insert(layout.primary_id); | 1325 parents.insert(layout.primary_id); |
| 1326 while (parents.size()) { | 1326 while (parents.size()) { |
| 1327 int64_t parent_id = *parents.begin(); | 1327 int64_t parent_id = *parents.begin(); |
| 1328 parents.erase(parent_id); | 1328 parents.erase(parent_id); |
| 1329 for (const DisplayPlacement& placement : layout.placement_list) { | 1329 for (const display::DisplayPlacement& placement : layout.placement_list) { |
| 1330 if (placement.parent_display_id == parent_id) { | 1330 if (placement.parent_display_id == parent_id) { |
| 1331 if (ApplyDisplayPlacement(placement, display_list) && updated_ids) | 1331 if (ApplyDisplayPlacement(placement, display_list) && updated_ids) |
| 1332 updated_ids->push_back(placement.display_id); | 1332 updated_ids->push_back(placement.display_id); |
| 1333 parents.insert(placement.display_id); | 1333 parents.insert(placement.display_id); |
| 1334 } | 1334 } |
| 1335 } | 1335 } |
| 1336 } | 1336 } |
| 1337 } | 1337 } |
| 1338 | 1338 |
| 1339 bool DisplayManager::ApplyDisplayPlacement(const DisplayPlacement& placement, | 1339 bool DisplayManager::ApplyDisplayPlacement( |
| 1340 DisplayList* display_list) { | 1340 const display::DisplayPlacement& placement, |
| 1341 display::DisplayList* display_list) { |
| 1341 const gfx::Display& parent_display = | 1342 const gfx::Display& parent_display = |
| 1342 *FindDisplayById(display_list, placement.parent_display_id); | 1343 *FindDisplayById(display_list, placement.parent_display_id); |
| 1343 DCHECK(parent_display.is_valid()); | 1344 DCHECK(parent_display.is_valid()); |
| 1344 gfx::Display* target_display = | 1345 gfx::Display* target_display = |
| 1345 FindDisplayById(display_list, placement.display_id); | 1346 FindDisplayById(display_list, placement.display_id); |
| 1346 DCHECK(target_display); | 1347 DCHECK(target_display); |
| 1347 | 1348 |
| 1348 const gfx::Rect& parent_bounds = parent_display.bounds(); | 1349 const gfx::Rect& parent_bounds = parent_display.bounds(); |
| 1349 const gfx::Rect& target_bounds = target_display->bounds(); | 1350 const gfx::Rect& target_bounds = target_display->bounds(); |
| 1350 gfx::Point new_target_origin = parent_bounds.origin(); | 1351 gfx::Point new_target_origin = parent_bounds.origin(); |
| 1351 | 1352 |
| 1352 DisplayPlacement::Position position = placement.position; | 1353 display::DisplayPlacement::Position position = placement.position; |
| 1353 | 1354 |
| 1354 // Ignore the offset in case the target display doesn't share edges with | 1355 // Ignore the offset in case the target display doesn't share edges with |
| 1355 // the parent display. | 1356 // the parent display. |
| 1356 int offset = placement.offset; | 1357 int offset = placement.offset; |
| 1357 if (position == DisplayPlacement::TOP || | 1358 if (position == display::DisplayPlacement::TOP || |
| 1358 position == DisplayPlacement::BOTTOM) { | 1359 position == display::DisplayPlacement::BOTTOM) { |
| 1359 offset = std::min( | 1360 offset = std::min( |
| 1360 offset, parent_bounds.width() - kMinimumOverlapForInvalidOffset); | 1361 offset, parent_bounds.width() - kMinimumOverlapForInvalidOffset); |
| 1361 offset = std::max( | 1362 offset = std::max( |
| 1362 offset, -target_bounds.width() + kMinimumOverlapForInvalidOffset); | 1363 offset, -target_bounds.width() + kMinimumOverlapForInvalidOffset); |
| 1363 } else { | 1364 } else { |
| 1364 offset = std::min( | 1365 offset = std::min( |
| 1365 offset, parent_bounds.height() - kMinimumOverlapForInvalidOffset); | 1366 offset, parent_bounds.height() - kMinimumOverlapForInvalidOffset); |
| 1366 offset = std::max( | 1367 offset = std::max( |
| 1367 offset, -target_bounds.height() + kMinimumOverlapForInvalidOffset); | 1368 offset, -target_bounds.height() + kMinimumOverlapForInvalidOffset); |
| 1368 } | 1369 } |
| 1369 switch (position) { | 1370 switch (position) { |
| 1370 case DisplayPlacement::TOP: | 1371 case display::DisplayPlacement::TOP: |
| 1371 new_target_origin.Offset(offset, -target_bounds.height()); | 1372 new_target_origin.Offset(offset, -target_bounds.height()); |
| 1372 break; | 1373 break; |
| 1373 case DisplayPlacement::RIGHT: | 1374 case display::DisplayPlacement::RIGHT: |
| 1374 new_target_origin.Offset(parent_bounds.width(), offset); | 1375 new_target_origin.Offset(parent_bounds.width(), offset); |
| 1375 break; | 1376 break; |
| 1376 case DisplayPlacement::BOTTOM: | 1377 case display::DisplayPlacement::BOTTOM: |
| 1377 new_target_origin.Offset(offset, parent_bounds.height()); | 1378 new_target_origin.Offset(offset, parent_bounds.height()); |
| 1378 break; | 1379 break; |
| 1379 case DisplayPlacement::LEFT: | 1380 case display::DisplayPlacement::LEFT: |
| 1380 new_target_origin.Offset(-target_bounds.width(), offset); | 1381 new_target_origin.Offset(-target_bounds.width(), offset); |
| 1381 break; | 1382 break; |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1384 // This function may be called before the secondary display is | 1385 // This function may be called before the secondary display is |
| 1385 // registered, in which case, the function should return true. | 1386 // registered, in which case, the function should return true. |
| 1386 gfx::Display* old_display = FindDisplayForId(placement.display_id); | 1387 gfx::Display* old_display = FindDisplayForId(placement.display_id); |
| 1387 gfx::Rect old_bounds; | 1388 gfx::Rect old_bounds; |
| 1388 if (old_display) | 1389 if (old_display) |
| 1389 old_bounds = old_display->bounds(); | 1390 old_bounds = old_display->bounds(); |
| 1390 | 1391 |
| 1391 gfx::Insets insets = target_display->GetWorkAreaInsets(); | 1392 gfx::Insets insets = target_display->GetWorkAreaInsets(); |
| 1392 target_display->set_bounds( | 1393 target_display->set_bounds( |
| 1393 gfx::Rect(new_target_origin, target_bounds.size())); | 1394 gfx::Rect(new_target_origin, target_bounds.size())); |
| 1394 target_display->UpdateWorkAreaFromInsets(insets); | 1395 target_display->UpdateWorkAreaFromInsets(insets); |
| 1395 | 1396 |
| 1396 return old_bounds != target_display->bounds(); | 1397 return old_bounds != target_display->bounds(); |
| 1397 } | 1398 } |
| 1398 | 1399 |
| 1399 void DisplayManager::RunPendingTasksForTest() { | 1400 void DisplayManager::RunPendingTasksForTest() { |
| 1400 if (!software_mirroring_display_list_.empty()) | 1401 if (!software_mirroring_display_list_.empty()) |
| 1401 base::RunLoop().RunUntilIdle(); | 1402 base::RunLoop().RunUntilIdle(); |
| 1402 } | 1403 } |
| 1403 | 1404 |
| 1404 } // namespace ash | 1405 } // namespace ash |
| OLD | NEW |