| 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 "ui/display/manager/display_manager.h" | 5 #include "ui/display/manager/display_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 scoped_refptr<display::ManagedDisplayMode> | 471 scoped_refptr<display::ManagedDisplayMode> |
| 472 DisplayManager::GetSelectedModeForDisplayId(int64_t id) const { | 472 DisplayManager::GetSelectedModeForDisplayId(int64_t id) const { |
| 473 std::map<int64_t, scoped_refptr<display::ManagedDisplayMode>>::const_iterator | 473 std::map<int64_t, scoped_refptr<display::ManagedDisplayMode>>::const_iterator |
| 474 iter = display_modes_.find(id); | 474 iter = display_modes_.find(id); |
| 475 if (iter == display_modes_.end()) | 475 if (iter == display_modes_.end()) |
| 476 return scoped_refptr<display::ManagedDisplayMode>(); | 476 return scoped_refptr<display::ManagedDisplayMode>(); |
| 477 return iter->second; | 477 return iter->second; |
| 478 } | 478 } |
| 479 | 479 |
| 480 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 480 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
| 481 return GetDisplayIdForUIScaling() != display::Display::kInvalidDisplayID; | 481 return GetDisplayIdForUIScaling() != kInvalidDisplayId; |
| 482 } | 482 } |
| 483 | 483 |
| 484 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { | 484 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { |
| 485 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator it = | 485 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator it = |
| 486 display_info_.find(display_id); | 486 display_info_.find(display_id); |
| 487 return (it != display_info_.end()) ? it->second.overscan_insets_in_dip() | 487 return (it != display_info_.end()) ? it->second.overscan_insets_in_dip() |
| 488 : gfx::Insets(); | 488 : gfx::Insets(); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void DisplayManager::SetColorCalibrationProfile( | 491 void DisplayManager::SetColorCalibrationProfile( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (updated_displays.size() == 1) { | 544 if (updated_displays.size() == 1) { |
| 545 VLOG(1) << "OnNativeDisplaysChanged(1):" << updated_displays[0].ToString(); | 545 VLOG(1) << "OnNativeDisplaysChanged(1):" << updated_displays[0].ToString(); |
| 546 } else { | 546 } else { |
| 547 VLOG(1) << "OnNativeDisplaysChanged(" << updated_displays.size() | 547 VLOG(1) << "OnNativeDisplaysChanged(" << updated_displays.size() |
| 548 << ") [0]=" << updated_displays[0].ToString() | 548 << ") [0]=" << updated_displays[0].ToString() |
| 549 << ", [1]=" << updated_displays[1].ToString(); | 549 << ", [1]=" << updated_displays[1].ToString(); |
| 550 } | 550 } |
| 551 | 551 |
| 552 bool internal_display_connected = false; | 552 bool internal_display_connected = false; |
| 553 num_connected_displays_ = updated_displays.size(); | 553 num_connected_displays_ = updated_displays.size(); |
| 554 mirroring_display_id_ = display::Display::kInvalidDisplayID; | 554 mirroring_display_id_ = kInvalidDisplayId; |
| 555 software_mirroring_display_list_.clear(); | 555 software_mirroring_display_list_.clear(); |
| 556 DisplayInfoList new_display_info_list; | 556 DisplayInfoList new_display_info_list; |
| 557 for (DisplayInfoList::const_iterator iter = updated_displays.begin(); | 557 for (DisplayInfoList::const_iterator iter = updated_displays.begin(); |
| 558 iter != updated_displays.end(); ++iter) { | 558 iter != updated_displays.end(); ++iter) { |
| 559 if (!internal_display_connected) | 559 if (!internal_display_connected) |
| 560 internal_display_connected = | 560 internal_display_connected = |
| 561 display::Display::IsInternalDisplayId(iter->id()); | 561 display::Display::IsInternalDisplayId(iter->id()); |
| 562 // Mirrored monitors have the same origins. | 562 // Mirrored monitors have the same origins. |
| 563 gfx::Point origin = iter->bounds_in_native().origin(); | 563 gfx::Point origin = iter->bounds_in_native().origin(); |
| 564 if (origins.find(origin) != origins.end()) { | 564 if (origins.find(origin) != origins.end()) { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 866 } |
| 867 | 867 |
| 868 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { | 868 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { |
| 869 return std::find_if(active_display_list_.begin(), active_display_list_.end(), | 869 return std::find_if(active_display_list_.begin(), active_display_list_.end(), |
| 870 [display_id](const display::Display& display) { | 870 [display_id](const display::Display& display) { |
| 871 return display.id() == display_id; | 871 return display.id() == display_id; |
| 872 }) != active_display_list_.end(); | 872 }) != active_display_list_.end(); |
| 873 } | 873 } |
| 874 | 874 |
| 875 bool DisplayManager::IsInMirrorMode() const { | 875 bool DisplayManager::IsInMirrorMode() const { |
| 876 return mirroring_display_id_ != display::Display::kInvalidDisplayID; | 876 return mirroring_display_id_ != kInvalidDisplayId; |
| 877 } | 877 } |
| 878 | 878 |
| 879 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { | 879 void DisplayManager::SetUnifiedDesktopEnabled(bool enable) { |
| 880 unified_desktop_enabled_ = enable; | 880 unified_desktop_enabled_ = enable; |
| 881 // There is no need to update the displays in mirror mode. Doing | 881 // There is no need to update the displays in mirror mode. Doing |
| 882 // this in hardware mirroring mode can cause crash because display | 882 // this in hardware mirroring mode can cause crash because display |
| 883 // info in hardware mirroring comes from DisplayConfigurator. | 883 // info in hardware mirroring comes from DisplayConfigurator. |
| 884 if (!IsInMirrorMode()) | 884 if (!IsInMirrorMode()) |
| 885 ReconfigureDisplays(); | 885 ReconfigureDisplays(); |
| 886 } | 886 } |
| 887 | 887 |
| 888 bool DisplayManager::IsInUnifiedMode() const { | 888 bool DisplayManager::IsInUnifiedMode() const { |
| 889 return multi_display_mode_ == UNIFIED && | 889 return multi_display_mode_ == UNIFIED && |
| 890 !software_mirroring_display_list_.empty(); | 890 !software_mirroring_display_list_.empty(); |
| 891 } | 891 } |
| 892 | 892 |
| 893 const display::ManagedDisplayInfo& DisplayManager::GetDisplayInfo( | 893 const display::ManagedDisplayInfo& DisplayManager::GetDisplayInfo( |
| 894 int64_t display_id) const { | 894 int64_t display_id) const { |
| 895 DCHECK_NE(display::Display::kInvalidDisplayID, display_id); | 895 DCHECK_NE(kInvalidDisplayId, display_id); |
| 896 | 896 |
| 897 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator iter = | 897 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator iter = |
| 898 display_info_.find(display_id); | 898 display_info_.find(display_id); |
| 899 CHECK(iter != display_info_.end()) << display_id; | 899 CHECK(iter != display_info_.end()) << display_id; |
| 900 return iter->second; | 900 return iter->second; |
| 901 } | 901 } |
| 902 | 902 |
| 903 const display::Display DisplayManager::GetMirroringDisplayById( | 903 const display::Display DisplayManager::GetMirroringDisplayById( |
| 904 int64_t display_id) const { | 904 int64_t display_id) const { |
| 905 auto iter = std::find_if(software_mirroring_display_list_.begin(), | 905 auto iter = std::find_if(software_mirroring_display_list_.begin(), |
| 906 software_mirroring_display_list_.end(), | 906 software_mirroring_display_list_.end(), |
| 907 [display_id](const display::Display& display) { | 907 [display_id](const display::Display& display) { |
| 908 return display.id() == display_id; | 908 return display.id() == display_id; |
| 909 }); | 909 }); |
| 910 return iter == software_mirroring_display_list_.end() ? display::Display() | 910 return iter == software_mirroring_display_list_.end() ? display::Display() |
| 911 : *iter; | 911 : *iter; |
| 912 } | 912 } |
| 913 | 913 |
| 914 std::string DisplayManager::GetDisplayNameForId(int64_t id) { | 914 std::string DisplayManager::GetDisplayNameForId(int64_t id) { |
| 915 if (id == display::Display::kInvalidDisplayID) | 915 if (id == kInvalidDisplayId) |
| 916 return delegate_->GetInternalDisplayNameString(); | 916 return delegate_->GetInternalDisplayNameString(); |
| 917 | 917 |
| 918 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator iter = | 918 std::map<int64_t, display::ManagedDisplayInfo>::const_iterator iter = |
| 919 display_info_.find(id); | 919 display_info_.find(id); |
| 920 if (iter != display_info_.end() && !iter->second.name().empty()) | 920 if (iter != display_info_.end() && !iter->second.name().empty()) |
| 921 return iter->second.name(); | 921 return iter->second.name(); |
| 922 | 922 |
| 923 return base::StringPrintf("Display %d", static_cast<int>(id)); | 923 return base::StringPrintf("Display %d", static_cast<int>(id)); |
| 924 } | 924 } |
| 925 | 925 |
| 926 int64_t DisplayManager::GetDisplayIdForUIScaling() const { | 926 int64_t DisplayManager::GetDisplayIdForUIScaling() const { |
| 927 // UI Scaling is effective on internal display. | 927 // UI Scaling is effective on internal display. |
| 928 return display::Display::HasInternalDisplay() | 928 return display::Display::HasInternalDisplay() |
| 929 ? display::Display::InternalDisplayId() | 929 ? display::Display::InternalDisplayId() |
| 930 : display::Display::kInvalidDisplayID; | 930 : kInvalidDisplayId; |
| 931 } | 931 } |
| 932 | 932 |
| 933 void DisplayManager::SetMirrorMode(bool mirror) { | 933 void DisplayManager::SetMirrorMode(bool mirror) { |
| 934 // TODO(oshima): Enable mirror mode for 2> displays. crbug.com/589319. | 934 // TODO(oshima): Enable mirror mode for 2> displays. crbug.com/589319. |
| 935 if (num_connected_displays() != 2) | 935 if (num_connected_displays() != 2) |
| 936 return; | 936 return; |
| 937 | 937 |
| 938 #if defined(OS_CHROMEOS) | 938 #if defined(OS_CHROMEOS) |
| 939 if (base::SysInfo::IsRunningOnChromeOS()) { | 939 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 940 ui::MultipleDisplayState new_state = | 940 ui::MultipleDisplayState new_state = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 961 if (num_connected_displays() == 1) { | 961 if (num_connected_displays() == 1) { |
| 962 const int kVerticalOffsetPx = 100; | 962 const int kVerticalOffsetPx = 100; |
| 963 // Layout the 2nd display below the primary as with the real device. | 963 // Layout the 2nd display below the primary as with the real device. |
| 964 gfx::Rect host_bounds = first_display.bounds_in_native(); | 964 gfx::Rect host_bounds = first_display.bounds_in_native(); |
| 965 new_display_info_list.push_back( | 965 new_display_info_list.push_back( |
| 966 display::ManagedDisplayInfo::CreateFromSpec(base::StringPrintf( | 966 display::ManagedDisplayInfo::CreateFromSpec(base::StringPrintf( |
| 967 "%d+%d-600x%d", host_bounds.x(), | 967 "%d+%d-600x%d", host_bounds.x(), |
| 968 host_bounds.bottom() + kVerticalOffsetPx, host_bounds.height()))); | 968 host_bounds.bottom() + kVerticalOffsetPx, host_bounds.height()))); |
| 969 } | 969 } |
| 970 num_connected_displays_ = new_display_info_list.size(); | 970 num_connected_displays_ = new_display_info_list.size(); |
| 971 mirroring_display_id_ = display::Display::kInvalidDisplayID; | 971 mirroring_display_id_ = kInvalidDisplayId; |
| 972 software_mirroring_display_list_.clear(); | 972 software_mirroring_display_list_.clear(); |
| 973 UpdateDisplaysWith(new_display_info_list); | 973 UpdateDisplaysWith(new_display_info_list); |
| 974 } | 974 } |
| 975 | 975 |
| 976 void DisplayManager::ToggleDisplayScaleFactor() { | 976 void DisplayManager::ToggleDisplayScaleFactor() { |
| 977 DCHECK(!active_display_list_.empty()); | 977 DCHECK(!active_display_list_.empty()); |
| 978 DisplayInfoList new_display_info_list; | 978 DisplayInfoList new_display_info_list; |
| 979 for (display::Displays::const_iterator iter = active_display_list_.begin(); | 979 for (display::Displays::const_iterator iter = active_display_list_.begin(); |
| 980 iter != active_display_list_.end(); ++iter) { | 980 iter != active_display_list_.end(); ++iter) { |
| 981 display::ManagedDisplayInfo display_info = GetDisplayInfo(iter->id()); | 981 display::ManagedDisplayInfo display_info = GetDisplayInfo(iter->id()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1002 MultiDisplayMode mode) { | 1002 MultiDisplayMode mode) { |
| 1003 DCHECK_NE(MIRRORING, mode); | 1003 DCHECK_NE(MIRRORING, mode); |
| 1004 display::DisplayIdList list = GetCurrentDisplayIdList(); | 1004 display::DisplayIdList list = GetCurrentDisplayIdList(); |
| 1005 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), | 1005 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), |
| 1006 mode == UNIFIED); | 1006 mode == UNIFIED); |
| 1007 ReconfigureDisplays(); | 1007 ReconfigureDisplays(); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { | 1010 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { |
| 1011 multi_display_mode_ = mode; | 1011 multi_display_mode_ = mode; |
| 1012 mirroring_display_id_ = display::Display::kInvalidDisplayID; | 1012 mirroring_display_id_ = kInvalidDisplayId; |
| 1013 software_mirroring_display_list_.clear(); | 1013 software_mirroring_display_list_.clear(); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 void DisplayManager::ReconfigureDisplays() { | 1016 void DisplayManager::ReconfigureDisplays() { |
| 1017 DisplayInfoList display_info_list; | 1017 DisplayInfoList display_info_list; |
| 1018 for (const display::Display& display : active_display_list_) { | 1018 for (const display::Display& display : active_display_list_) { |
| 1019 if (display.id() == kUnifiedDisplayId) | 1019 if (display.id() == kUnifiedDisplayId) |
| 1020 continue; | 1020 continue; |
| 1021 display_info_list.push_back(GetDisplayInfo(display.id())); | 1021 display_info_list.push_back(GetDisplayInfo(display.id())); |
| 1022 } | 1022 } |
| 1023 for (const display::Display& display : software_mirroring_display_list_) | 1023 for (const display::Display& display : software_mirroring_display_list_) |
| 1024 display_info_list.push_back(GetDisplayInfo(display.id())); | 1024 display_info_list.push_back(GetDisplayInfo(display.id())); |
| 1025 mirroring_display_id_ = display::Display::kInvalidDisplayID; | 1025 mirroring_display_id_ = kInvalidDisplayId; |
| 1026 software_mirroring_display_list_.clear(); | 1026 software_mirroring_display_list_.clear(); |
| 1027 UpdateDisplaysWith(display_info_list); | 1027 UpdateDisplaysWith(display_info_list); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 bool DisplayManager::UpdateDisplayBounds(int64_t display_id, | 1030 bool DisplayManager::UpdateDisplayBounds(int64_t display_id, |
| 1031 const gfx::Rect& new_bounds) { | 1031 const gfx::Rect& new_bounds) { |
| 1032 if (change_display_upon_host_resize_) { | 1032 if (change_display_upon_host_resize_) { |
| 1033 display_info_[display_id].SetBounds(new_bounds); | 1033 display_info_[display_id].SetBounds(new_bounds); |
| 1034 // Don't notify observers if the mirrored window has changed. | 1034 // Don't notify observers if the mirrored window has changed. |
| 1035 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) | 1035 if (software_mirroring_enabled() && mirroring_display_id_ == display_id) |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 std::vector<size_t>* updated_indices) { | 1345 std::vector<size_t>* updated_indices) { |
| 1346 if (display_list->size() == 1u) | 1346 if (display_list->size() == 1u) |
| 1347 return; | 1347 return; |
| 1348 | 1348 |
| 1349 const display::DisplayLayout& layout = | 1349 const display::DisplayLayout& layout = |
| 1350 layout_store_->GetRegisteredDisplayLayout( | 1350 layout_store_->GetRegisteredDisplayLayout( |
| 1351 display::CreateDisplayIdList(*display_list)); | 1351 display::CreateDisplayIdList(*display_list)); |
| 1352 | 1352 |
| 1353 // Ignore if a user has a old format (should be extremely rare) | 1353 // Ignore if a user has a old format (should be extremely rare) |
| 1354 // and this will be replaced with DCHECK. | 1354 // and this will be replaced with DCHECK. |
| 1355 if (layout.primary_id == display::Display::kInvalidDisplayID) | 1355 if (layout.primary_id == kInvalidDisplayId) |
| 1356 return; | 1356 return; |
| 1357 | 1357 |
| 1358 // display_list does not have translation set, so ApplyDisplayLayout cannot | 1358 // display_list does not have translation set, so ApplyDisplayLayout cannot |
| 1359 // provide accurate change information. We'll find the changes after the call. | 1359 // provide accurate change information. We'll find the changes after the call. |
| 1360 ApplyDisplayLayout(layout, display_list, nullptr); | 1360 ApplyDisplayLayout(layout, display_list, nullptr); |
| 1361 size_t num_displays = display_list->size(); | 1361 size_t num_displays = display_list->size(); |
| 1362 for (size_t index = 0; index < num_displays; ++index) { | 1362 for (size_t index = 0; index < num_displays; ++index) { |
| 1363 const display::Display& display = (*display_list)[index]; | 1363 const display::Display& display = (*display_list)[index]; |
| 1364 int64_t id = display.id(); | 1364 int64_t id = display.id(); |
| 1365 const display::Display* active_display = FindDisplayForId(id); | 1365 const display::Display* active_display = FindDisplayForId(id); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 | 1415 |
| 1416 const display::Display& DisplayManager::GetSecondaryDisplay() const { | 1416 const display::Display& DisplayManager::GetSecondaryDisplay() const { |
| 1417 CHECK_LE(2U, GetNumDisplays()); | 1417 CHECK_LE(2U, GetNumDisplays()); |
| 1418 return GetDisplayAt(0).id() == | 1418 return GetDisplayAt(0).id() == |
| 1419 display::Screen::GetScreen()->GetPrimaryDisplay().id() | 1419 display::Screen::GetScreen()->GetPrimaryDisplay().id() |
| 1420 ? GetDisplayAt(1) | 1420 ? GetDisplayAt(1) |
| 1421 : GetDisplayAt(0); | 1421 : GetDisplayAt(0); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 } // namespace display | 1424 } // namespace display |
| OLD | NEW |