| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); | 201 largest_device_scale_factor, info.GetEffectiveDeviceScaleFactor()); |
| 202 } | 202 } |
| 203 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); | 203 gfx::SetFontRenderParamsDeviceScaleFactor(largest_device_scale_factor); |
| 204 #endif // OS_CHROMEOS | 204 #endif // OS_CHROMEOS |
| 205 } | 205 } |
| 206 | 206 |
| 207 DisplayLayout DisplayManager::GetCurrentDisplayLayout() { | 207 DisplayLayout DisplayManager::GetCurrentDisplayLayout() { |
| 208 DCHECK_LE(2U, num_connected_displays()); | 208 DCHECK_LE(2U, num_connected_displays()); |
| 209 // Invert if the primary was swapped. | 209 // Invert if the primary was swapped. |
| 210 if (num_connected_displays() == 2) { | 210 if (num_connected_displays() == 2) { |
| 211 DisplayIdPair pair = GetCurrentDisplayIdPair(); | 211 DisplayIdList list = GetCurrentDisplayIdList(); |
| 212 return layout_store_->ComputeDisplayLayoutForDisplayIdPair(pair); | 212 return layout_store_->ComputeDisplayLayoutForDisplayIdList(list); |
| 213 } else if (num_connected_displays() > 2) { | 213 } else if (num_connected_displays() > 2) { |
| 214 // Return fixed horizontal layout for >= 3 displays. | 214 // Return fixed horizontal layout for >= 3 displays. |
| 215 DisplayLayout layout(DisplayLayout::RIGHT, 0); | 215 DisplayLayout layout(DisplayLayout::RIGHT, 0); |
| 216 return layout; | 216 return layout; |
| 217 } | 217 } |
| 218 NOTREACHED() << "DisplayLayout is requested for single display"; | 218 NOTREACHED() << "DisplayLayout is requested for single display"; |
| 219 // On release build, just fallback to default instead of blowing up. | 219 // On release build, just fallback to default instead of blowing up. |
| 220 DisplayLayout layout = | 220 DisplayLayout layout = |
| 221 layout_store_->default_display_layout(); | 221 layout_store_->default_display_layout(); |
| 222 layout.primary_id = active_display_list_[0].id(); | 222 layout.primary_id = active_display_list_[0].id(); |
| 223 return layout; | 223 return layout; |
| 224 } | 224 } |
| 225 | 225 |
| 226 DisplayIdPair DisplayManager::GetCurrentDisplayIdPair() const { | 226 DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { |
| 227 if (IsInUnifiedMode()) { | 227 if (IsInUnifiedMode()) { |
| 228 return CreateDisplayIdPair(software_mirroring_display_list_[0].id(), | 228 return CreateDisplayIdList(software_mirroring_display_list_[0].id(), |
| 229 software_mirroring_display_list_[1].id()); | 229 software_mirroring_display_list_[1].id()); |
| 230 } else if (IsInMirrorMode()) { | 230 } else if (IsInMirrorMode()) { |
| 231 if (software_mirroring_enabled()) { | 231 if (software_mirroring_enabled()) { |
| 232 CHECK_EQ(2u, num_connected_displays()); | 232 CHECK_EQ(2u, num_connected_displays()); |
| 233 // This comment is to make it easy to distinguish the crash | 233 // This comment is to make it easy to distinguish the crash |
| 234 // between two checks. | 234 // between two checks. |
| 235 CHECK_EQ(1u, active_display_list_.size()); | 235 CHECK_EQ(1u, active_display_list_.size()); |
| 236 } | 236 } |
| 237 return CreateDisplayIdPair(active_display_list_[0].id(), | 237 return CreateDisplayIdList(active_display_list_[0].id(), |
| 238 mirroring_display_id_); | 238 mirroring_display_id_); |
| 239 } else { | 239 } else { |
| 240 CHECK_LE(2u, active_display_list_.size()); | 240 CHECK_LE(2u, active_display_list_.size()); |
| 241 return CreateDisplayIdPair(active_display_list_[0].id(), | 241 return CreateDisplayIdList(active_display_list_[0].id(), |
| 242 active_display_list_[1].id()); | 242 active_display_list_[1].id()); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 void DisplayManager::SetLayoutForCurrentDisplays( | 246 void DisplayManager::SetLayoutForCurrentDisplays( |
| 247 const DisplayLayout& layout_relative_to_primary) { | 247 const DisplayLayout& layout_relative_to_primary) { |
| 248 if (GetNumDisplays() != 2) | 248 if (GetNumDisplays() != 2) |
| 249 return; | 249 return; |
| 250 const gfx::Display& primary = screen_->GetPrimaryDisplay(); | 250 const gfx::Display& primary = screen_->GetPrimaryDisplay(); |
| 251 const DisplayIdPair pair = GetCurrentDisplayIdPair(); | 251 const DisplayIdList list = GetCurrentDisplayIdList(); |
| 252 // Invert if the primary was swapped. | 252 // Invert if the primary was swapped. |
| 253 DisplayLayout to_set = pair.first == primary.id() ? | 253 DisplayLayout to_set = list[0] == primary.id() |
| 254 layout_relative_to_primary : layout_relative_to_primary.Invert(); | 254 ? layout_relative_to_primary |
| 255 : layout_relative_to_primary.Invert(); |
| 255 | 256 |
| 256 DisplayLayout current_layout = | 257 DisplayLayout current_layout = |
| 257 layout_store_->GetRegisteredDisplayLayout(pair); | 258 layout_store_->GetRegisteredDisplayLayout(list); |
| 258 if (to_set.position != current_layout.position || | 259 if (to_set.position != current_layout.position || |
| 259 to_set.offset != current_layout.offset) { | 260 to_set.offset != current_layout.offset) { |
| 260 to_set.primary_id = primary.id(); | 261 to_set.primary_id = primary.id(); |
| 261 layout_store_->RegisterLayoutForDisplayIdPair( | 262 layout_store_->RegisterLayoutForDisplayIdList(list[0], list[1], to_set); |
| 262 pair.first, pair.second, to_set); | |
| 263 if (delegate_) | 263 if (delegate_) |
| 264 delegate_->PreDisplayConfigurationChange(false); | 264 delegate_->PreDisplayConfigurationChange(false); |
| 265 // PreDisplayConfigurationChange(false); | 265 // PreDisplayConfigurationChange(false); |
| 266 // TODO(oshima): Call UpdateDisplays instead. | 266 // TODO(oshima): Call UpdateDisplays instead. |
| 267 const DisplayLayout layout = GetCurrentDisplayLayout(); | 267 const DisplayLayout layout = GetCurrentDisplayLayout(); |
| 268 UpdateDisplayBoundsForLayout( | 268 UpdateDisplayBoundsForLayout( |
| 269 layout, primary, | 269 layout, primary, |
| 270 FindDisplayForId(ScreenUtil::GetSecondaryDisplay().id())); | 270 FindDisplayForId(ScreenUtil::GetSecondaryDisplay().id())); |
| 271 | 271 |
| 272 // Primary's bounds stay the same. Just notify bounds change | 272 // Primary's bounds stay the same. Just notify bounds change |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 display_info_[gfx::Display::InternalDisplayId()].GetRotation( | 612 display_info_[gfx::Display::InternalDisplayId()].GetRotation( |
| 613 gfx::Display::ROTATION_SOURCE_USER); | 613 gfx::Display::ROTATION_SOURCE_USER); |
| 614 display_info_[gfx::Display::InternalDisplayId()].SetRotation( | 614 display_info_[gfx::Display::InternalDisplayId()].SetRotation( |
| 615 user_rotation, gfx::Display::ROTATION_SOURCE_USER); | 615 user_rotation, gfx::Display::ROTATION_SOURCE_USER); |
| 616 } | 616 } |
| 617 } | 617 } |
| 618 | 618 |
| 619 #if defined(OS_CHROMEOS) | 619 #if defined(OS_CHROMEOS) |
| 620 if (!base::SysInfo::IsRunningOnChromeOS() && | 620 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 621 new_display_info_list.size() > 1) { | 621 new_display_info_list.size() > 1) { |
| 622 DisplayIdPair pair = CreateDisplayIdPair(new_display_info_list[0].id(), | 622 DisplayIdList list = CreateDisplayIdList(new_display_info_list[0].id(), |
| 623 new_display_info_list[1].id()); | 623 new_display_info_list[1].id()); |
| 624 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(pair); | 624 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(list); |
| 625 // Mirror mode is set by DisplayConfigurator on the device. | 625 // Mirror mode is set by DisplayConfigurator on the device. |
| 626 // Emulate it when running on linux desktop. | 626 // Emulate it when running on linux desktop. |
| 627 if (layout.mirrored) | 627 if (layout.mirrored) |
| 628 SetMultiDisplayMode(MIRRORING); | 628 SetMultiDisplayMode(MIRRORING); |
| 629 } | 629 } |
| 630 #endif | 630 #endif |
| 631 | 631 |
| 632 UpdateDisplaysWith(new_display_info_list); | 632 UpdateDisplaysWith(new_display_info_list); |
| 633 } | 633 } |
| 634 | 634 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 649 #endif | 649 #endif |
| 650 | 650 |
| 651 DisplayInfoList new_display_info_list = updated_display_info_list; | 651 DisplayInfoList new_display_info_list = updated_display_info_list; |
| 652 std::sort(active_display_list_.begin(), active_display_list_.end(), | 652 std::sort(active_display_list_.begin(), active_display_list_.end(), |
| 653 DisplaySortFunctor()); | 653 DisplaySortFunctor()); |
| 654 std::sort(new_display_info_list.begin(), | 654 std::sort(new_display_info_list.begin(), |
| 655 new_display_info_list.end(), | 655 new_display_info_list.end(), |
| 656 DisplayInfoSortFunctor()); | 656 DisplayInfoSortFunctor()); |
| 657 | 657 |
| 658 if (new_display_info_list.size() > 1) { | 658 if (new_display_info_list.size() > 1) { |
| 659 DisplayIdPair pair = CreateDisplayIdPair(new_display_info_list[0].id(), | 659 DisplayIdList list = CreateDisplayIdList(new_display_info_list[0].id(), |
| 660 new_display_info_list[1].id()); | 660 new_display_info_list[1].id()); |
| 661 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(pair); | 661 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout(list); |
| 662 current_default_multi_display_mode_ = | 662 current_default_multi_display_mode_ = |
| 663 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED | 663 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED |
| 664 : EXTENDED; | 664 : EXTENDED; |
| 665 } | 665 } |
| 666 | 666 |
| 667 if (multi_display_mode_ != MIRRORING) | 667 if (multi_display_mode_ != MIRRORING) |
| 668 multi_display_mode_ = current_default_multi_display_mode_; | 668 multi_display_mode_ = current_default_multi_display_mode_; |
| 669 | 669 |
| 670 CreateSoftwareMirroringDisplayInfo(&new_display_info_list); | 670 CreateSoftwareMirroringDisplayInfo(&new_display_info_list); |
| 671 | 671 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 } | 851 } |
| 852 | 852 |
| 853 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { | 853 const gfx::Display& DisplayManager::GetDisplayAt(size_t index) const { |
| 854 DCHECK_LT(index, active_display_list_.size()); | 854 DCHECK_LT(index, active_display_list_.size()); |
| 855 return active_display_list_[index]; | 855 return active_display_list_[index]; |
| 856 } | 856 } |
| 857 | 857 |
| 858 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { | 858 const gfx::Display& DisplayManager::GetPrimaryDisplayCandidate() const { |
| 859 if (GetNumDisplays() != 2) | 859 if (GetNumDisplays() != 2) |
| 860 return active_display_list_[0]; | 860 return active_display_list_[0]; |
| 861 DisplayLayout layout = layout_store_->GetRegisteredDisplayLayout( | 861 DisplayLayout layout = |
| 862 GetCurrentDisplayIdPair()); | 862 layout_store_->GetRegisteredDisplayLayout(GetCurrentDisplayIdList()); |
| 863 return GetDisplayForId(layout.primary_id); | 863 return GetDisplayForId(layout.primary_id); |
| 864 } | 864 } |
| 865 | 865 |
| 866 size_t DisplayManager::GetNumDisplays() const { | 866 size_t DisplayManager::GetNumDisplays() const { |
| 867 return active_display_list_.size(); | 867 return active_display_list_.size(); |
| 868 } | 868 } |
| 869 | 869 |
| 870 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { | 870 bool DisplayManager::IsActiveDisplayId(int64_t display_id) const { |
| 871 return std::find_if(active_display_list_.begin(), active_display_list_.end(), | 871 return std::find_if(active_display_list_.begin(), active_display_list_.end(), |
| 872 [display_id](const gfx::Display& display) { | 872 [display_id](const gfx::Display& display) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 } | 992 } |
| 993 | 993 |
| 994 bool DisplayManager::SoftwareMirroringEnabled() const { | 994 bool DisplayManager::SoftwareMirroringEnabled() const { |
| 995 return software_mirroring_enabled(); | 995 return software_mirroring_enabled(); |
| 996 } | 996 } |
| 997 #endif | 997 #endif |
| 998 | 998 |
| 999 void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( | 999 void DisplayManager::SetDefaultMultiDisplayModeForCurrentDisplays( |
| 1000 MultiDisplayMode mode) { | 1000 MultiDisplayMode mode) { |
| 1001 DCHECK_NE(MIRRORING, mode); | 1001 DCHECK_NE(MIRRORING, mode); |
| 1002 DisplayIdPair pair = GetCurrentDisplayIdPair(); | 1002 DisplayIdList list = GetCurrentDisplayIdList(); |
| 1003 layout_store_->UpdateMultiDisplayState(pair, IsInMirrorMode(), | 1003 layout_store_->UpdateMultiDisplayState(list, IsInMirrorMode(), |
| 1004 mode == UNIFIED); | 1004 mode == UNIFIED); |
| 1005 ReconfigureDisplays(); | 1005 ReconfigureDisplays(); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { | 1008 void DisplayManager::SetMultiDisplayMode(MultiDisplayMode mode) { |
| 1009 multi_display_mode_ = mode; | 1009 multi_display_mode_ = mode; |
| 1010 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; | 1010 mirroring_display_id_ = gfx::Display::kInvalidDisplayID; |
| 1011 software_mirroring_display_list_.clear(); | 1011 software_mirroring_display_list_.clear(); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 gfx::Point origin = gfx::Point(x_offset, 0); | 1300 gfx::Point origin = gfx::Point(x_offset, 0); |
| 1301 gfx::Insets insets = display.GetWorkAreaInsets(); | 1301 gfx::Insets insets = display.GetWorkAreaInsets(); |
| 1302 display.set_bounds(gfx::Rect(origin, bounds.size())); | 1302 display.set_bounds(gfx::Rect(origin, bounds.size())); |
| 1303 display.UpdateWorkAreaFromInsets(insets); | 1303 display.UpdateWorkAreaFromInsets(insets); |
| 1304 x_offset += bounds.width(); | 1304 x_offset += bounds.width(); |
| 1305 updated_indices->push_back(i); | 1305 updated_indices->push_back(i); |
| 1306 } | 1306 } |
| 1307 return true; | 1307 return true; |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 DisplayLayout layout = layout_store_->ComputeDisplayLayoutForDisplayIdPair( | 1310 DisplayLayout layout = layout_store_->ComputeDisplayLayoutForDisplayIdList( |
| 1311 CreateDisplayIdPair(displays->at(0).id(), displays->at(1).id())); | 1311 CreateDisplayIdList(displays->at(0).id(), displays->at(1).id())); |
| 1312 | 1312 |
| 1313 // Ignore if a user has a old format (should be extremely rare) | 1313 // Ignore if a user has a old format (should be extremely rare) |
| 1314 // and this will be replaced with DCHECK. | 1314 // and this will be replaced with DCHECK. |
| 1315 if (layout.primary_id != gfx::Display::kInvalidDisplayID) { | 1315 if (layout.primary_id != gfx::Display::kInvalidDisplayID) { |
| 1316 size_t primary_index, secondary_index; | 1316 size_t primary_index, secondary_index; |
| 1317 if (displays->at(0).id() == layout.primary_id) { | 1317 if (displays->at(0).id() == layout.primary_id) { |
| 1318 primary_index = 0; | 1318 primary_index = 0; |
| 1319 secondary_index = 1; | 1319 secondary_index = 1; |
| 1320 } else { | 1320 } else { |
| 1321 primary_index = 1; | 1321 primary_index = 1; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 1389 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
| 1390 secondary_display->UpdateWorkAreaFromInsets(insets); | 1390 secondary_display->UpdateWorkAreaFromInsets(insets); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 void DisplayManager::RunPendingTasksForTest() { | 1393 void DisplayManager::RunPendingTasksForTest() { |
| 1394 if (!software_mirroring_display_list_.empty()) | 1394 if (!software_mirroring_display_list_.empty()) |
| 1395 base::RunLoop().RunUntilIdle(); | 1395 base::RunLoop().RunUntilIdle(); |
| 1396 } | 1396 } |
| 1397 | 1397 |
| 1398 } // namespace ash | 1398 } // namespace ash |
| OLD | NEW |