OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/display_configurator.h" | 5 #include "ui/display/chromeos/display_configurator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 510 |
511 NotifyObservers(success, new_state); | 511 NotifyObservers(success, new_state); |
512 return success; | 512 return success; |
513 } | 513 } |
514 | 514 |
515 void DisplayConfigurator::OnConfigurationChanged() { | 515 void DisplayConfigurator::OnConfigurationChanged() { |
516 // Configure displays with |kConfigureDelayMs| delay, | 516 // Configure displays with |kConfigureDelayMs| delay, |
517 // so that time-consuming ConfigureDisplays() won't be called multiple times. | 517 // so that time-consuming ConfigureDisplays() won't be called multiple times. |
518 if (configure_timer_.IsRunning()) { | 518 if (configure_timer_.IsRunning()) { |
519 // Note: when the timer is running it is possible that a different task | 519 // Note: when the timer is running it is possible that a different task |
520 // (SetDisplayPower()) is scheduled. In these cases, prefer the already | 520 // (RestoreRequestedPowerStateAfterResume()) is scheduled. In these cases, |
521 // scheduled task to ConfigureDisplays() since ConfigureDisplays() performs | 521 // prefer the already scheduled task to ConfigureDisplays() since |
522 // only basic configuration while SetDisplayPower() will perform additional | 522 // ConfigureDisplays() performs only basic configuration while |
| 523 // RestoreRequestedPowerStateAfterResume() will perform additional |
523 // operations. | 524 // operations. |
524 configure_timer_.Reset(); | 525 configure_timer_.Reset(); |
525 } else { | 526 } else { |
526 configure_timer_.Start( | 527 configure_timer_.Start( |
527 FROM_HERE, | 528 FROM_HERE, |
528 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | 529 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), |
529 this, | 530 this, |
530 &DisplayConfigurator::ConfigureDisplays); | 531 &DisplayConfigurator::ConfigureDisplays); |
531 } | 532 } |
532 } | 533 } |
(...skipping 17 matching lines...) Expand all Loading... |
550 kSetDisplayPowerOnlyIfSingleInternalDisplay); | 551 kSetDisplayPowerOnlyIfSingleInternalDisplay); |
551 | 552 |
552 // We need to make sure that the monitor configuration we just did actually | 553 // We need to make sure that the monitor configuration we just did actually |
553 // completes before we return, because otherwise the X message could be | 554 // completes before we return, because otherwise the X message could be |
554 // racing with the HandleSuspendReadiness message. | 555 // racing with the HandleSuspendReadiness message. |
555 native_display_delegate_->SyncWithServer(); | 556 native_display_delegate_->SyncWithServer(); |
556 } | 557 } |
557 } | 558 } |
558 | 559 |
559 void DisplayConfigurator::ResumeDisplays() { | 560 void DisplayConfigurator::ResumeDisplays() { |
560 // Force probing to ensure that we pick up any changes that were made | |
561 // while the system was suspended. | |
562 configure_timer_.Start( | 561 configure_timer_.Start( |
563 FROM_HERE, | 562 FROM_HERE, |
564 base::TimeDelta::FromMilliseconds(kResumeDelayMs), | 563 base::TimeDelta::FromMilliseconds(kResumeDelayMs), |
565 base::Bind(base::IgnoreResult(&DisplayConfigurator::SetDisplayPower), | 564 base::Bind(&DisplayConfigurator::RestoreRequestedPowerStateAfterResume, |
566 base::Unretained(this), | 565 base::Unretained(this))); |
567 requested_power_state_, | |
568 kSetDisplayPowerForceProbe)); | |
569 } | 566 } |
570 | 567 |
571 void DisplayConfigurator::UpdateCachedDisplays() { | 568 void DisplayConfigurator::UpdateCachedDisplays() { |
572 std::vector<DisplaySnapshot*> snapshots = | 569 std::vector<DisplaySnapshot*> snapshots = |
573 native_display_delegate_->GetDisplays(); | 570 native_display_delegate_->GetDisplays(); |
574 | 571 |
575 cached_displays_.clear(); | 572 cached_displays_.clear(); |
576 for (size_t i = 0; i < snapshots.size(); ++i) { | 573 for (size_t i = 0; i < snapshots.size(); ++i) { |
577 DisplayState display_state; | 574 DisplayState display_state; |
578 display_state.display = snapshots[i]; | 575 display_state.display = snapshots[i]; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 UpdateCachedDisplays(); | 715 UpdateCachedDisplays(); |
719 const MultipleDisplayState new_state = ChooseDisplayState( | 716 const MultipleDisplayState new_state = ChooseDisplayState( |
720 requested_power_state_); | 717 requested_power_state_); |
721 const bool success = EnterStateOrFallBackToSoftwareMirroring( | 718 const bool success = EnterStateOrFallBackToSoftwareMirroring( |
722 new_state, requested_power_state_); | 719 new_state, requested_power_state_); |
723 native_display_delegate_->UngrabServer(); | 720 native_display_delegate_->UngrabServer(); |
724 | 721 |
725 NotifyObservers(success, new_state); | 722 NotifyObservers(success, new_state); |
726 } | 723 } |
727 | 724 |
| 725 void DisplayConfigurator::RestoreRequestedPowerStateAfterResume() { |
| 726 // Force probing to ensure that we pick up any changes that were made while |
| 727 // the system was suspended. |
| 728 SetDisplayPower(requested_power_state_, kSetDisplayPowerForceProbe); |
| 729 } |
| 730 |
728 void DisplayConfigurator::NotifyObservers( | 731 void DisplayConfigurator::NotifyObservers( |
729 bool success, | 732 bool success, |
730 MultipleDisplayState attempted_state) { | 733 MultipleDisplayState attempted_state) { |
731 if (success) { | 734 if (success) { |
732 FOR_EACH_OBSERVER( | 735 FOR_EACH_OBSERVER( |
733 Observer, observers_, OnDisplayModeChanged(cached_displays_)); | 736 Observer, observers_, OnDisplayModeChanged(cached_displays_)); |
734 } else { | 737 } else { |
735 FOR_EACH_OBSERVER( | 738 FOR_EACH_OBSERVER( |
736 Observer, observers_, OnDisplayModeChangeFailed(attempted_state)); | 739 Observer, observers_, OnDisplayModeChangeFailed(attempted_state)); |
737 } | 740 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 return state_controller_->GetStateForDisplayIds(display_ids); | 969 return state_controller_->GetStateForDisplayIds(display_ids); |
967 } | 970 } |
968 } | 971 } |
969 default: | 972 default: |
970 NOTREACHED(); | 973 NOTREACHED(); |
971 } | 974 } |
972 return MULTIPLE_DISPLAY_STATE_INVALID; | 975 return MULTIPLE_DISPLAY_STATE_INVALID; |
973 } | 976 } |
974 | 977 |
975 } // namespace ui | 978 } // namespace ui |
OLD | NEW |