| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "ui/display/display_switches.h" | 14 #include "ui/display/display_switches.h" |
| 15 #include "ui/display/types/chromeos/display_mode.h" | 15 #include "ui/display/types/chromeos/display_mode.h" |
| 16 #include "ui/display/types/chromeos/display_snapshot.h" | 16 #include "ui/display/types/chromeos/display_snapshot.h" |
| 17 #include "ui/display/types/chromeos/native_display_delegate.h" | 17 #include "ui/display/types/chromeos/native_display_delegate.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 typedef std::vector<const DisplayMode*> DisplayModeList; | 23 typedef std::vector<const DisplayMode*> DisplayModeList; |
| 24 | 24 |
| 25 // The delay to perform configuration after RRNotify. See the comment | 25 // The delay to perform configuration after RRNotify. See the comment for |
| 26 // in |Dispatch()|. | 26 // |configure_timer_|. |
| 27 const int kConfigureDelayMs = 500; | 27 const int kConfigureDelayMs = 500; |
| 28 | 28 |
| 29 // The delay spent before reading the display configuration after coming out of |
| 30 // suspend. While coming out of suspend the display state may be updating. This |
| 31 // is used to wait until the hardware had a chance to update the display state |
| 32 // such that we read an up to date state. |
| 33 const int kResumeDelayMs = 500; |
| 34 |
| 29 // Returns a string describing |state|. | 35 // Returns a string describing |state|. |
| 30 std::string DisplayPowerStateToString(chromeos::DisplayPowerState state) { | 36 std::string DisplayPowerStateToString(chromeos::DisplayPowerState state) { |
| 31 switch (state) { | 37 switch (state) { |
| 32 case chromeos::DISPLAY_POWER_ALL_ON: | 38 case chromeos::DISPLAY_POWER_ALL_ON: |
| 33 return "ALL_ON"; | 39 return "ALL_ON"; |
| 34 case chromeos::DISPLAY_POWER_ALL_OFF: | 40 case chromeos::DISPLAY_POWER_ALL_OFF: |
| 35 return "ALL_OFF"; | 41 return "ALL_OFF"; |
| 36 case chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON: | 42 case chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON: |
| 37 return "INTERNAL_OFF_EXTERNAL_ON"; | 43 return "INTERNAL_OFF_EXTERNAL_ON"; |
| 38 case chromeos::DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF: | 44 case chromeos::DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (display_power) | 88 if (display_power) |
| 83 (*display_power)[i] = on; | 89 (*display_power)[i] = on; |
| 84 if (on) | 90 if (on) |
| 85 num_on_displays++; | 91 num_on_displays++; |
| 86 } | 92 } |
| 87 return num_on_displays; | 93 return num_on_displays; |
| 88 } | 94 } |
| 89 | 95 |
| 90 } // namespace | 96 } // namespace |
| 91 | 97 |
| 98 |
| 99 const int DisplayConfigurator::kSetDisplayPowerNoFlags = 0; |
| 100 const int DisplayConfigurator::kSetDisplayPowerForceProbe = 1 << 0; |
| 101 const int |
| 102 DisplayConfigurator::kSetDisplayPowerOnlyIfSingleInternalDisplay = 1 << 1; |
| 103 |
| 92 DisplayConfigurator::DisplayState::DisplayState() | 104 DisplayConfigurator::DisplayState::DisplayState() |
| 93 : display(NULL), | 105 : display(NULL), |
| 94 touch_device_id(0), | 106 touch_device_id(0), |
| 95 selected_mode(NULL), | 107 selected_mode(NULL), |
| 96 mirror_mode(NULL) {} | 108 mirror_mode(NULL) {} |
| 97 | 109 |
| 98 bool DisplayConfigurator::TestApi::TriggerConfigureTimeout() { | 110 bool DisplayConfigurator::TestApi::TriggerConfigureTimeout() { |
| 99 if (configurator_->configure_timer_.get() && | 111 if (configurator_->configure_timer_.IsRunning()) { |
| 100 configurator_->configure_timer_->IsRunning()) { | 112 configurator_->configure_timer_.user_task().Run(); |
| 101 configurator_->configure_timer_.reset(); | 113 configurator_->configure_timer_.Stop(); |
| 102 configurator_->ConfigureDisplays(); | |
| 103 return true; | 114 return true; |
| 104 } else { | 115 } else { |
| 105 return false; | 116 return false; |
| 106 } | 117 } |
| 107 } | 118 } |
| 108 | 119 |
| 109 // static | 120 // static |
| 110 const DisplayMode* DisplayConfigurator::FindDisplayModeMatchingSize( | 121 const DisplayMode* DisplayConfigurator::FindDisplayModeMatchingSize( |
| 111 const DisplaySnapshot& display, | 122 const DisplaySnapshot& display, |
| 112 const gfx::Size& size) { | 123 const gfx::Size& size) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 441 |
| 431 bool DisplayConfigurator::SetDisplayPower( | 442 bool DisplayConfigurator::SetDisplayPower( |
| 432 chromeos::DisplayPowerState power_state, | 443 chromeos::DisplayPowerState power_state, |
| 433 int flags) { | 444 int flags) { |
| 434 if (!configure_display_) | 445 if (!configure_display_) |
| 435 return false; | 446 return false; |
| 436 | 447 |
| 437 VLOG(1) << "SetDisplayPower: power_state=" | 448 VLOG(1) << "SetDisplayPower: power_state=" |
| 438 << DisplayPowerStateToString(power_state) << " flags=" << flags | 449 << DisplayPowerStateToString(power_state) << " flags=" << flags |
| 439 << ", configure timer=" | 450 << ", configure timer=" |
| 440 << ((configure_timer_.get() && configure_timer_->IsRunning()) ? | 451 << (configure_timer_.IsRunning() ? "Running" : "Stopped"); |
| 441 "Running" : "Stopped"); | |
| 442 if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe)) | 452 if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe)) |
| 443 return true; | 453 return true; |
| 444 | 454 |
| 445 native_display_delegate_->GrabServer(); | 455 native_display_delegate_->GrabServer(); |
| 446 UpdateCachedDisplays(); | 456 UpdateCachedDisplays(); |
| 447 | 457 |
| 448 const MultipleDisplayState new_state = ChooseDisplayState(power_state); | 458 const MultipleDisplayState new_state = ChooseDisplayState(power_state); |
| 449 bool attempted_change = false; | 459 bool attempted_change = false; |
| 450 bool success = false; | 460 bool success = false; |
| 451 | 461 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 EnterStateOrFallBackToSoftwareMirroring(new_state, power_state_); | 502 EnterStateOrFallBackToSoftwareMirroring(new_state, power_state_); |
| 493 native_display_delegate_->UngrabServer(); | 503 native_display_delegate_->UngrabServer(); |
| 494 | 504 |
| 495 NotifyObservers(success, new_state); | 505 NotifyObservers(success, new_state); |
| 496 return success; | 506 return success; |
| 497 } | 507 } |
| 498 | 508 |
| 499 void DisplayConfigurator::OnConfigurationChanged() { | 509 void DisplayConfigurator::OnConfigurationChanged() { |
| 500 // Configure displays with |kConfigureDelayMs| delay, | 510 // Configure displays with |kConfigureDelayMs| delay, |
| 501 // so that time-consuming ConfigureDisplays() won't be called multiple times. | 511 // so that time-consuming ConfigureDisplays() won't be called multiple times. |
| 502 if (configure_timer_.get()) { | 512 if (configure_timer_.IsRunning()) { |
| 503 configure_timer_->Reset(); | 513 // Note: when the timer is running it is possible that a different task |
| 514 // (SetDisplayPower()) is scheduled. In these cases, prefer the already |
| 515 // scheduled task to ConfigureDisplays() since ConfigureDisplays() performs |
| 516 // only basic configuration while SetDisplayPower() will perform additional |
| 517 // operations. |
| 518 configure_timer_.Reset(); |
| 504 } else { | 519 } else { |
| 505 configure_timer_.reset(new base::OneShotTimer<DisplayConfigurator>()); | 520 configure_timer_.Start( |
| 506 configure_timer_->Start( | |
| 507 FROM_HERE, | 521 FROM_HERE, |
| 508 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | 522 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), |
| 509 this, | 523 this, |
| 510 &DisplayConfigurator::ConfigureDisplays); | 524 &DisplayConfigurator::ConfigureDisplays); |
| 511 } | 525 } |
| 512 } | 526 } |
| 513 | 527 |
| 514 void DisplayConfigurator::AddObserver(Observer* observer) { | 528 void DisplayConfigurator::AddObserver(Observer* observer) { |
| 515 observers_.AddObserver(observer); | 529 observers_.AddObserver(observer); |
| 516 } | 530 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 532 // We need to make sure that the monitor configuration we just did actually | 546 // We need to make sure that the monitor configuration we just did actually |
| 533 // completes before we return, because otherwise the X message could be | 547 // completes before we return, because otherwise the X message could be |
| 534 // racing with the HandleSuspendReadiness message. | 548 // racing with the HandleSuspendReadiness message. |
| 535 native_display_delegate_->SyncWithServer(); | 549 native_display_delegate_->SyncWithServer(); |
| 536 } | 550 } |
| 537 } | 551 } |
| 538 | 552 |
| 539 void DisplayConfigurator::ResumeDisplays() { | 553 void DisplayConfigurator::ResumeDisplays() { |
| 540 // Force probing to ensure that we pick up any changes that were made | 554 // Force probing to ensure that we pick up any changes that were made |
| 541 // while the system was suspended. | 555 // while the system was suspended. |
| 542 SetDisplayPower(power_state_, kSetDisplayPowerForceProbe); | 556 configure_timer_.Start( |
| 557 FROM_HERE, |
| 558 base::TimeDelta::FromMilliseconds(kResumeDelayMs), |
| 559 base::Bind(base::IgnoreResult(&DisplayConfigurator::SetDisplayPower), |
| 560 base::Unretained(this), |
| 561 power_state_, |
| 562 kSetDisplayPowerForceProbe)); |
| 543 } | 563 } |
| 544 | 564 |
| 545 void DisplayConfigurator::UpdateCachedDisplays() { | 565 void DisplayConfigurator::UpdateCachedDisplays() { |
| 546 std::vector<DisplaySnapshot*> snapshots = | 566 std::vector<DisplaySnapshot*> snapshots = |
| 547 native_display_delegate_->GetDisplays(); | 567 native_display_delegate_->GetDisplays(); |
| 548 | 568 |
| 549 cached_displays_.clear(); | 569 cached_displays_.clear(); |
| 550 for (size_t i = 0; i < snapshots.size(); ++i) { | 570 for (size_t i = 0; i < snapshots.size(); ++i) { |
| 551 DisplayState display_state; | 571 DisplayState display_state; |
| 552 display_state.display = snapshots[i]; | 572 display_state.display = snapshots[i]; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 external_display->mirror_mode = *external_it; | 700 external_display->mirror_mode = *external_it; |
| 681 return true; // Mirror mode created. | 701 return true; // Mirror mode created. |
| 682 } | 702 } |
| 683 } | 703 } |
| 684 } | 704 } |
| 685 | 705 |
| 686 return false; | 706 return false; |
| 687 } | 707 } |
| 688 | 708 |
| 689 void DisplayConfigurator::ConfigureDisplays() { | 709 void DisplayConfigurator::ConfigureDisplays() { |
| 690 configure_timer_.reset(); | |
| 691 | |
| 692 if (!configure_display_) | 710 if (!configure_display_) |
| 693 return; | 711 return; |
| 694 | 712 |
| 695 native_display_delegate_->GrabServer(); | 713 native_display_delegate_->GrabServer(); |
| 696 UpdateCachedDisplays(); | 714 UpdateCachedDisplays(); |
| 697 const MultipleDisplayState new_state = ChooseDisplayState(power_state_); | 715 const MultipleDisplayState new_state = ChooseDisplayState(power_state_); |
| 698 const bool success = | 716 const bool success = |
| 699 EnterStateOrFallBackToSoftwareMirroring(new_state, power_state_); | 717 EnterStateOrFallBackToSoftwareMirroring(new_state, power_state_); |
| 700 native_display_delegate_->UngrabServer(); | 718 native_display_delegate_->UngrabServer(); |
| 701 | 719 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 return state_controller_->GetStateForDisplayIds(display_ids); | 958 return state_controller_->GetStateForDisplayIds(display_ids); |
| 941 } | 959 } |
| 942 } | 960 } |
| 943 default: | 961 default: |
| 944 NOTREACHED(); | 962 NOTREACHED(); |
| 945 } | 963 } |
| 946 return MULTIPLE_DISPLAY_STATE_INVALID; | 964 return MULTIPLE_DISPLAY_STATE_INVALID; |
| 947 } | 965 } |
| 948 | 966 |
| 949 } // namespace ui | 967 } // namespace ui |
| OLD | NEW |