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 <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 return true; | 478 return true; |
479 } | 479 } |
480 | 480 |
481 bool DisplayManager::IsDisplayUIScalingEnabled() const { | 481 bool DisplayManager::IsDisplayUIScalingEnabled() const { |
482 return GetDisplayIdForUIScaling() != display::Display::kInvalidDisplayID; | 482 return GetDisplayIdForUIScaling() != display::Display::kInvalidDisplayID; |
483 } | 483 } |
484 | 484 |
485 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { | 485 gfx::Insets DisplayManager::GetOverscanInsets(int64_t display_id) const { |
486 std::map<int64_t, DisplayInfo>::const_iterator it = | 486 std::map<int64_t, DisplayInfo>::const_iterator it = |
487 display_info_.find(display_id); | 487 display_info_.find(display_id); |
488 return (it != display_info_.end()) ? | 488 return (it != display_info_.end()) ? it->second.overscan_insets_in_dip() |
489 it->second.overscan_insets_in_dip() : gfx::Insets(); | 489 : gfx::Insets(); |
490 } | 490 } |
491 | 491 |
492 void DisplayManager::SetColorCalibrationProfile( | 492 void DisplayManager::SetColorCalibrationProfile( |
493 int64_t display_id, | 493 int64_t display_id, |
494 ui::ColorCalibrationProfile profile) { | 494 ui::ColorCalibrationProfile profile) { |
495 #if defined(OS_CHROMEOS) | 495 #if defined(OS_CHROMEOS) |
496 if (!display_info_[display_id].IsColorProfileAvailable(profile)) | 496 if (!display_info_[display_id].IsColorProfileAvailable(profile)) |
497 return; | 497 return; |
498 | 498 |
499 if (delegate_) | 499 if (delegate_) |
500 delegate_->PreDisplayConfigurationChange(false); | 500 delegate_->PreDisplayConfigurationChange(false); |
501 // Just sets color profile if it's not running on ChromeOS (like tests). | 501 // Just sets color profile if it's not running on ChromeOS (like tests). |
502 if (!base::SysInfo::IsRunningOnChromeOS() || | 502 if (!base::SysInfo::IsRunningOnChromeOS() || |
503 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile( | 503 Shell::GetInstance()->display_configurator()->SetColorCalibrationProfile( |
504 display_id, profile)) { | 504 display_id, profile)) { |
505 display_info_[display_id].SetColorProfile(profile); | 505 display_info_[display_id].SetColorProfile(profile); |
506 UMA_HISTOGRAM_ENUMERATION( | 506 UMA_HISTOGRAM_ENUMERATION("ChromeOS.Display.ColorProfile", profile, |
507 "ChromeOS.Display.ColorProfile", profile, ui::NUM_COLOR_PROFILES); | 507 ui::NUM_COLOR_PROFILES); |
508 } | 508 } |
509 if (delegate_) | 509 if (delegate_) |
510 delegate_->PostDisplayConfigurationChange(); | 510 delegate_->PostDisplayConfigurationChange(); |
511 #endif | 511 #endif |
512 } | 512 } |
513 | 513 |
514 void DisplayManager::OnNativeDisplaysChanged( | 514 void DisplayManager::OnNativeDisplaysChanged( |
515 const std::vector<DisplayInfo>& updated_displays) { | 515 const std::vector<DisplayInfo>& updated_displays) { |
516 if (updated_displays.empty()) { | 516 if (updated_displays.empty()) { |
517 VLOG(1) << "OnNativeDisplaysChanged(0): # of current displays=" | 517 VLOG(1) << "OnNativeDisplaysChanged(0): # of current displays=" |
(...skipping 30 matching lines...) Expand all Loading... |
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_ = display::Display::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(); | 558 iter != updated_displays.end(); ++iter) { |
559 ++iter) { | |
560 if (!internal_display_connected) | 559 if (!internal_display_connected) |
561 internal_display_connected = | 560 internal_display_connected = |
562 display::Display::IsInternalDisplayId(iter->id()); | 561 display::Display::IsInternalDisplayId(iter->id()); |
563 // Mirrored monitors have the same origins. | 562 // Mirrored monitors have the same origins. |
564 gfx::Point origin = iter->bounds_in_native().origin(); | 563 gfx::Point origin = iter->bounds_in_native().origin(); |
565 if (origins.find(origin) != origins.end()) { | 564 if (origins.find(origin) != origins.end()) { |
566 InsertAndUpdateDisplayInfo(*iter); | 565 InsertAndUpdateDisplayInfo(*iter); |
567 mirroring_display_id_ = iter->id(); | 566 mirroring_display_id_ = iter->id(); |
568 } else { | 567 } else { |
569 origins.insert(origin); | 568 origins.insert(origin); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 DisplayInfoList display_info_list; | 631 DisplayInfoList display_info_list; |
633 for (const auto& display : active_display_list_) | 632 for (const auto& display : active_display_list_) |
634 display_info_list.push_back(GetDisplayInfo(display.id())); | 633 display_info_list.push_back(GetDisplayInfo(display.id())); |
635 AddMirrorDisplayInfoIfAny(&display_info_list); | 634 AddMirrorDisplayInfoIfAny(&display_info_list); |
636 UpdateDisplaysWith(display_info_list); | 635 UpdateDisplaysWith(display_info_list); |
637 } | 636 } |
638 | 637 |
639 void DisplayManager::UpdateDisplaysWith( | 638 void DisplayManager::UpdateDisplaysWith( |
640 const std::vector<DisplayInfo>& updated_display_info_list) { | 639 const std::vector<DisplayInfo>& updated_display_info_list) { |
641 #if defined(OS_WIN) | 640 #if defined(OS_WIN) |
642 DCHECK_EQ(1u, updated_display_info_list.size()) << | 641 DCHECK_EQ(1u, updated_display_info_list.size()) |
643 ": Multiple display test does not work on Windows bots. Please " | 642 << ": Multiple display test does not work on Windows bots. Please " |
644 "skip (don't disable) the test using SupportsMultipleDisplays()"; | 643 "skip (don't disable) the test using SupportsMultipleDisplays()"; |
645 #endif | 644 #endif |
646 | 645 |
647 DisplayInfoList new_display_info_list = updated_display_info_list; | 646 DisplayInfoList new_display_info_list = updated_display_info_list; |
648 std::sort(active_display_list_.begin(), active_display_list_.end(), | 647 std::sort(active_display_list_.begin(), active_display_list_.end(), |
649 DisplaySortFunctor()); | 648 DisplaySortFunctor()); |
650 std::sort(new_display_info_list.begin(), | 649 std::sort(new_display_info_list.begin(), new_display_info_list.end(), |
651 new_display_info_list.end(), | |
652 DisplayInfoSortFunctor()); | 650 DisplayInfoSortFunctor()); |
653 | 651 |
654 if (new_display_info_list.size() > 1) { | 652 if (new_display_info_list.size() > 1) { |
655 display::DisplayIdList list = GenerateDisplayIdList( | 653 display::DisplayIdList list = GenerateDisplayIdList( |
656 new_display_info_list.begin(), new_display_info_list.end(), | 654 new_display_info_list.begin(), new_display_info_list.end(), |
657 [](const DisplayInfo& info) { return info.id(); }); | 655 [](const DisplayInfo& info) { return info.id(); }); |
658 const display::DisplayLayout& layout = | 656 const display::DisplayLayout& layout = |
659 layout_store_->GetRegisteredDisplayLayout(list); | 657 layout_store_->GetRegisteredDisplayLayout(list); |
660 current_default_multi_display_mode_ = | 658 current_default_multi_display_mode_ = |
661 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED | 659 (layout.default_unified && unified_desktop_enabled_) ? UNIFIED |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 CreateDisplayFromDisplayInfoById(new_info_iter->id()); | 702 CreateDisplayFromDisplayInfoById(new_info_iter->id()); |
705 const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id()); | 703 const DisplayInfo& new_display_info = GetDisplayInfo(new_display.id()); |
706 | 704 |
707 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_NONE; | 705 uint32_t metrics = display::DisplayObserver::DISPLAY_METRIC_NONE; |
708 | 706 |
709 // At that point the new Display objects we have are not entirely updated, | 707 // At that point the new Display objects we have are not entirely updated, |
710 // they are missing the translation related to the Display disposition in | 708 // they are missing the translation related to the Display disposition in |
711 // the layout. | 709 // the layout. |
712 // Using display.bounds() and display.work_area() would fail most of the | 710 // Using display.bounds() and display.work_area() would fail most of the |
713 // time. | 711 // time. |
714 if (force_bounds_changed_ || | 712 if (force_bounds_changed_ || (current_display_info.bounds_in_native() != |
715 (current_display_info.bounds_in_native() != | 713 new_display_info.bounds_in_native()) || |
716 new_display_info.bounds_in_native()) || | |
717 (current_display_info.GetOverscanInsetsInPixel() != | 714 (current_display_info.GetOverscanInsetsInPixel() != |
718 new_display_info.GetOverscanInsetsInPixel()) || | 715 new_display_info.GetOverscanInsetsInPixel()) || |
719 current_display.size() != new_display.size()) { | 716 current_display.size() != new_display.size()) { |
720 metrics |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS | | 717 metrics |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS | |
721 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; | 718 display::DisplayObserver::DISPLAY_METRIC_WORK_AREA; |
722 } | 719 } |
723 | 720 |
724 if (current_display.device_scale_factor() != | 721 if (current_display.device_scale_factor() != |
725 new_display.device_scale_factor()) { | 722 new_display.device_scale_factor()) { |
726 metrics |= display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | 723 metrics |= display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 791 |
795 for (size_t index : added_display_indices) | 792 for (size_t index : added_display_indices) |
796 screen_->NotifyDisplayAdded(active_display_list_[index]); | 793 screen_->NotifyDisplayAdded(active_display_list_[index]); |
797 | 794 |
798 active_display_list_.resize(active_display_list_size); | 795 active_display_list_.resize(active_display_list_size); |
799 | 796 |
800 bool notify_primary_change = | 797 bool notify_primary_change = |
801 delegate_ ? old_primary.id() != screen_->GetPrimaryDisplay().id() : false; | 798 delegate_ ? old_primary.id() != screen_->GetPrimaryDisplay().id() : false; |
802 | 799 |
803 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin(); | 800 for (std::map<size_t, uint32_t>::iterator iter = display_changes.begin(); |
804 iter != display_changes.end(); | 801 iter != display_changes.end(); ++iter) { |
805 ++iter) { | |
806 uint32_t metrics = iter->second; | 802 uint32_t metrics = iter->second; |
807 const display::Display& updated_display = active_display_list_[iter->first]; | 803 const display::Display& updated_display = active_display_list_[iter->first]; |
808 | 804 |
809 if (notify_primary_change && | 805 if (notify_primary_change && |
810 updated_display.id() == screen_->GetPrimaryDisplay().id()) { | 806 updated_display.id() == screen_->GetPrimaryDisplay().id()) { |
811 metrics |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY; | 807 metrics |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY; |
812 notify_primary_change = false; | 808 notify_primary_change = false; |
813 } | 809 } |
814 screen_->NotifyMetricsChanged(updated_display, metrics); | 810 screen_->NotifyMetricsChanged(updated_display, metrics); |
815 } | 811 } |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; | 1260 DCHECK(display_info_.find(id) != display_info_.end()) << "id=" << id; |
1265 const DisplayInfo& display_info = display_info_[id]; | 1261 const DisplayInfo& display_info = display_info_[id]; |
1266 | 1262 |
1267 display::Display new_display(display_info.id()); | 1263 display::Display new_display(display_info.id()); |
1268 gfx::Rect bounds_in_native(display_info.size_in_pixel()); | 1264 gfx::Rect bounds_in_native(display_info.size_in_pixel()); |
1269 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); | 1265 float device_scale_factor = display_info.GetEffectiveDeviceScaleFactor(); |
1270 | 1266 |
1271 // Simply set the origin to (0,0). The primary display's origin is | 1267 // Simply set the origin to (0,0). The primary display's origin is |
1272 // always (0,0) and the bounds of non-primary display(s) will be updated | 1268 // always (0,0) and the bounds of non-primary display(s) will be updated |
1273 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. | 1269 // in |UpdateNonPrimaryDisplayBoundsForLayout| called in |UpdateDisplay|. |
1274 new_display.SetScaleAndBounds( | 1270 new_display.SetScaleAndBounds(device_scale_factor, |
1275 device_scale_factor, gfx::Rect(bounds_in_native.size())); | 1271 gfx::Rect(bounds_in_native.size())); |
1276 new_display.set_rotation(display_info.GetActiveRotation()); | 1272 new_display.set_rotation(display_info.GetActiveRotation()); |
1277 new_display.set_touch_support(display_info.touch_support()); | 1273 new_display.set_touch_support(display_info.touch_support()); |
1278 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); | 1274 new_display.set_maximum_cursor_size(display_info.maximum_cursor_size()); |
1279 return new_display; | 1275 return new_display; |
1280 } | 1276 } |
1281 | 1277 |
1282 display::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( | 1278 display::Display DisplayManager::CreateMirroringDisplayFromDisplayInfoById( |
1283 int64_t id, | 1279 int64_t id, |
1284 const gfx::Point& origin, | 1280 const gfx::Point& origin, |
1285 float scale) { | 1281 float scale) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 layout.ApplyToDisplayList(display_list, updated_ids, | 1334 layout.ApplyToDisplayList(display_list, updated_ids, |
1339 kMinimumOverlapForInvalidOffset); | 1335 kMinimumOverlapForInvalidOffset); |
1340 } | 1336 } |
1341 | 1337 |
1342 void DisplayManager::RunPendingTasksForTest() { | 1338 void DisplayManager::RunPendingTasksForTest() { |
1343 if (!software_mirroring_display_list_.empty()) | 1339 if (!software_mirroring_display_list_.empty()) |
1344 base::RunLoop().RunUntilIdle(); | 1340 base::RunLoop().RunUntilIdle(); |
1345 } | 1341 } |
1346 | 1342 |
1347 } // namespace ash | 1343 } // namespace ash |
OLD | NEW |