| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 is_panel_fitting_enabled_(false), | 467 is_panel_fitting_enabled_(false), |
| 468 configure_display_(base::SysInfo::IsRunningOnChromeOS()), | 468 configure_display_(base::SysInfo::IsRunningOnChromeOS()), |
| 469 current_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), | 469 current_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
| 470 current_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 470 current_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 471 requested_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), | 471 requested_display_state_(MULTIPLE_DISPLAY_STATE_INVALID), |
| 472 requested_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 472 requested_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 473 pending_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 473 pending_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 474 has_pending_power_state_(false), | 474 has_pending_power_state_(false), |
| 475 pending_power_flags_(kSetDisplayPowerNoFlags), | 475 pending_power_flags_(kSetDisplayPowerNoFlags), |
| 476 force_configure_(false), | 476 force_configure_(false), |
| 477 configure_cached_displays_(false), |
| 477 next_display_protection_client_id_(1), | 478 next_display_protection_client_id_(1), |
| 478 display_externally_controlled_(false), | 479 display_externally_controlled_(false), |
| 479 display_control_changing_(false), | 480 display_control_changing_(false), |
| 480 displays_suspended_(false), | 481 displays_suspended_(false), |
| 481 layout_manager_(new DisplayLayoutManagerImpl(this)), | 482 layout_manager_(new DisplayLayoutManagerImpl(this)), |
| 482 weak_ptr_factory_(this) { | 483 weak_ptr_factory_(this) { |
| 483 } | 484 } |
| 484 | 485 |
| 485 DisplayConfigurator::~DisplayConfigurator() { | 486 DisplayConfigurator::~DisplayConfigurator() { |
| 486 if (native_display_delegate_) | 487 if (native_display_delegate_) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 DCHECK(native_display_delegate_); | 609 DCHECK(native_display_delegate_); |
| 609 native_display_delegate_->Initialize(); | 610 native_display_delegate_->Initialize(); |
| 610 | 611 |
| 611 // ForceInitialConfigure should be the first configuration so there shouldn't | 612 // ForceInitialConfigure should be the first configuration so there shouldn't |
| 612 // be anything scheduled. | 613 // be anything scheduled. |
| 613 DCHECK(!configuration_task_); | 614 DCHECK(!configuration_task_); |
| 614 | 615 |
| 615 configuration_task_.reset(new UpdateDisplayConfigurationTask( | 616 configuration_task_.reset(new UpdateDisplayConfigurationTask( |
| 616 native_display_delegate_.get(), layout_manager_.get(), | 617 native_display_delegate_.get(), layout_manager_.get(), |
| 617 requested_display_state_, requested_power_state_, | 618 requested_display_state_, requested_power_state_, |
| 618 kSetDisplayPowerForceProbe, background_color_argb, true, | 619 kSetDisplayPowerForceProbe, background_color_argb, true, false, |
| 619 base::Bind(&DisplayConfigurator::OnConfigured, | 620 base::Bind(&DisplayConfigurator::OnConfigured, |
| 620 weak_ptr_factory_.GetWeakPtr()))); | 621 weak_ptr_factory_.GetWeakPtr()))); |
| 621 configuration_task_->Run(); | 622 configuration_task_->Run(); |
| 622 } | 623 } |
| 623 | 624 |
| 624 DisplayConfigurator::ContentProtectionClientId | 625 DisplayConfigurator::ContentProtectionClientId |
| 625 DisplayConfigurator::RegisterContentProtectionClient() { | 626 DisplayConfigurator::RegisterContentProtectionClient() { |
| 626 if (!configure_display_ || display_externally_controlled_) | 627 if (!configure_display_ || display_externally_controlled_) |
| 627 return kInvalidClientId; | 628 return kInvalidClientId; |
| 628 | 629 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 return false; | 836 return false; |
| 836 } | 837 } |
| 837 | 838 |
| 838 void DisplayConfigurator::PrepareForExit() { | 839 void DisplayConfigurator::PrepareForExit() { |
| 839 configure_display_ = false; | 840 configure_display_ = false; |
| 840 } | 841 } |
| 841 | 842 |
| 842 void DisplayConfigurator::SetDisplayPowerInternal( | 843 void DisplayConfigurator::SetDisplayPowerInternal( |
| 843 chromeos::DisplayPowerState power_state, | 844 chromeos::DisplayPowerState power_state, |
| 844 int flags, | 845 int flags, |
| 846 bool configure_cached_displays, |
| 845 const ConfigurationCallback& callback) { | 847 const ConfigurationCallback& callback) { |
| 846 if (power_state == current_power_state_ && | 848 if (power_state == current_power_state_ && |
| 847 !(flags & kSetDisplayPowerForceProbe)) { | 849 !(flags & kSetDisplayPowerForceProbe)) { |
| 848 callback.Run(true); | 850 callback.Run(true); |
| 849 return; | 851 return; |
| 850 } | 852 } |
| 851 | 853 |
| 852 pending_power_state_ = power_state; | 854 pending_power_state_ = power_state; |
| 853 has_pending_power_state_ = true; | 855 has_pending_power_state_ = true; |
| 854 pending_power_flags_ = flags; | 856 pending_power_flags_ = flags; |
| 857 configure_cached_displays_ = configure_cached_displays; |
| 855 queued_configuration_callbacks_.push_back(callback); | 858 queued_configuration_callbacks_.push_back(callback); |
| 856 | 859 |
| 857 RunPendingConfiguration(); | 860 RunPendingConfiguration(); |
| 858 } | 861 } |
| 859 | 862 |
| 860 void DisplayConfigurator::SetDisplayPower( | 863 void DisplayConfigurator::SetDisplayPower( |
| 861 chromeos::DisplayPowerState power_state, | 864 chromeos::DisplayPowerState power_state, |
| 862 int flags, | 865 int flags, |
| 863 const ConfigurationCallback& callback) { | 866 const ConfigurationCallback& callback) { |
| 864 if (!configure_display_ || display_externally_controlled_) { | 867 if (!configure_display_ || display_externally_controlled_) { |
| 865 callback.Run(false); | 868 callback.Run(false); |
| 866 return; | 869 return; |
| 867 } | 870 } |
| 868 | 871 |
| 869 VLOG(1) << "SetDisplayPower: power_state=" | 872 VLOG(1) << "SetDisplayPower: power_state=" |
| 870 << DisplayPowerStateToString(power_state) << " flags=" << flags | 873 << DisplayPowerStateToString(power_state) << " flags=" << flags |
| 871 << ", configure timer=" | 874 << ", configure timer=" |
| 872 << (configure_timer_.IsRunning() ? "Running" : "Stopped"); | 875 << (configure_timer_.IsRunning() ? "Running" : "Stopped"); |
| 873 | 876 |
| 874 requested_power_state_ = power_state; | 877 requested_power_state_ = power_state; |
| 875 SetDisplayPowerInternal(requested_power_state_, flags, callback); | 878 SetDisplayPowerInternal(requested_power_state_, flags, false, callback); |
| 876 } | 879 } |
| 877 | 880 |
| 878 void DisplayConfigurator::SetDisplayMode(MultipleDisplayState new_state) { | 881 void DisplayConfigurator::SetDisplayMode(MultipleDisplayState new_state) { |
| 879 if (!configure_display_ || display_externally_controlled_) | 882 if (!configure_display_ || display_externally_controlled_) |
| 880 return; | 883 return; |
| 881 | 884 |
| 882 VLOG(1) << "SetDisplayMode: state=" | 885 VLOG(1) << "SetDisplayMode: state=" |
| 883 << MultipleDisplayStateToString(new_state); | 886 << MultipleDisplayStateToString(new_state); |
| 884 if (current_display_state_ == new_state) { | 887 if (current_display_state_ == new_state) { |
| 885 // Cancel software mirroring if the state is moving from | 888 // Cancel software mirroring if the state is moving from |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 | 947 |
| 945 // Stop |configure_timer_| because we will force probe and configure all the | 948 // Stop |configure_timer_| because we will force probe and configure all the |
| 946 // displays at resume time anyway. | 949 // displays at resume time anyway. |
| 947 configure_timer_.Stop(); | 950 configure_timer_.Stop(); |
| 948 | 951 |
| 949 // Turn off the displays for suspend. This way, if we wake up for lucid sleep, | 952 // Turn off the displays for suspend. This way, if we wake up for lucid sleep, |
| 950 // the displays will not turn on (all displays should be off for lucid sleep | 953 // the displays will not turn on (all displays should be off for lucid sleep |
| 951 // unless explicitly requested by lucid sleep code). Use | 954 // unless explicitly requested by lucid sleep code). Use |
| 952 // SetDisplayPowerInternal so requested_power_state_ is maintained. | 955 // SetDisplayPowerInternal so requested_power_state_ is maintained. |
| 953 SetDisplayPowerInternal(chromeos::DISPLAY_POWER_ALL_OFF, | 956 SetDisplayPowerInternal(chromeos::DISPLAY_POWER_ALL_OFF, |
| 954 kSetDisplayPowerNoFlags, callback); | 957 kSetDisplayPowerNoFlags, false, callback); |
| 955 | 958 |
| 956 // We need to make sure that the monitor configuration we just did actually | 959 // We need to make sure that the monitor configuration we just did actually |
| 957 // completes before we return. | 960 // completes before we return. |
| 958 native_display_delegate_->SyncWithServer(); | 961 native_display_delegate_->SyncWithServer(); |
| 959 } | 962 } |
| 960 | 963 |
| 961 void DisplayConfigurator::ResumeDisplays() { | 964 void DisplayConfigurator::ResumeDisplays() { |
| 962 if (!configure_display_ || display_externally_controlled_) | 965 if (!configure_display_ || display_externally_controlled_) |
| 963 return; | 966 return; |
| 964 | 967 |
| 965 displays_suspended_ = false; | 968 displays_suspended_ = false; |
| 969 configure_cached_displays_ = true; |
| 966 | 970 |
| 967 // If requested_power_state_ is ALL_OFF due to idle suspend, powerd will turn | 971 // If requested_power_state_ is ALL_OFF due to idle suspend, powerd will turn |
| 968 // the display power on when it enables the backlight. | 972 // the display power on when it enables the backlight. |
| 969 SetDisplayPower(requested_power_state_, kSetDisplayPowerNoFlags, | 973 SetDisplayPowerInternal(requested_power_state_, kSetDisplayPowerNoFlags, true, |
| 970 base::Bind(&DoNothing)); | 974 base::Bind(&DoNothing)); |
| 971 } | 975 } |
| 972 | 976 |
| 973 void DisplayConfigurator::ConfigureDisplays() { | 977 void DisplayConfigurator::ConfigureDisplays() { |
| 974 if (!configure_display_ || display_externally_controlled_) | 978 if (!configure_display_ || display_externally_controlled_) |
| 975 return; | 979 return; |
| 976 | 980 |
| 977 force_configure_ = true; | 981 force_configure_ = true; |
| 978 RunPendingConfiguration(); | 982 RunPendingConfiguration(); |
| 979 } | 983 } |
| 980 | 984 |
| 981 void DisplayConfigurator::RunPendingConfiguration() { | 985 void DisplayConfigurator::RunPendingConfiguration() { |
| 982 // Configuration task is currently running. Do not start a second | 986 // Configuration task is currently running. Do not start a second |
| 983 // configuration. | 987 // configuration. |
| 984 if (configuration_task_) | 988 if (configuration_task_) |
| 985 return; | 989 return; |
| 986 | 990 |
| 987 if (!ShouldRunConfigurationTask()) { | 991 if (!ShouldRunConfigurationTask()) { |
| 988 LOG(ERROR) << "Called RunPendingConfiguration without any changes" | 992 LOG(ERROR) << "Called RunPendingConfiguration without any changes" |
| 989 " requested"; | 993 " requested"; |
| 990 CallAndClearQueuedCallbacks(true); | 994 CallAndClearQueuedCallbacks(true); |
| 991 return; | 995 return; |
| 992 } | 996 } |
| 993 | 997 |
| 994 configuration_task_.reset(new UpdateDisplayConfigurationTask( | 998 configuration_task_.reset(new UpdateDisplayConfigurationTask( |
| 995 native_display_delegate_.get(), layout_manager_.get(), | 999 native_display_delegate_.get(), layout_manager_.get(), |
| 996 requested_display_state_, pending_power_state_, pending_power_flags_, | 1000 requested_display_state_, pending_power_state_, pending_power_flags_, |
| 997 0, force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, | 1001 0, force_configure_, configure_cached_displays_, |
| 998 weak_ptr_factory_.GetWeakPtr()))); | 1002 base::Bind(&DisplayConfigurator::OnConfigured, |
| 1003 weak_ptr_factory_.GetWeakPtr()))); |
| 999 configuration_task_->set_virtual_display_snapshots( | 1004 configuration_task_->set_virtual_display_snapshots( |
| 1000 virtual_display_snapshots_.get()); | 1005 virtual_display_snapshots_.get()); |
| 1001 | 1006 |
| 1002 // Reset the flags before running the task; otherwise it may end up scheduling | 1007 // Reset the flags before running the task; otherwise it may end up scheduling |
| 1003 // another configuration. | 1008 // another configuration. |
| 1004 force_configure_ = false; | 1009 force_configure_ = false; |
| 1010 configure_cached_displays_ = false; |
| 1005 pending_power_flags_ = kSetDisplayPowerNoFlags; | 1011 pending_power_flags_ = kSetDisplayPowerNoFlags; |
| 1006 has_pending_power_state_ = false; | 1012 has_pending_power_state_ = false; |
| 1007 requested_display_state_ = MULTIPLE_DISPLAY_STATE_INVALID; | 1013 requested_display_state_ = MULTIPLE_DISPLAY_STATE_INVALID; |
| 1008 | 1014 |
| 1009 DCHECK(in_progress_configuration_callbacks_.empty()); | 1015 DCHECK(in_progress_configuration_callbacks_.empty()); |
| 1010 in_progress_configuration_callbacks_.swap(queued_configuration_callbacks_); | 1016 in_progress_configuration_callbacks_.swap(queued_configuration_callbacks_); |
| 1011 | 1017 |
| 1012 configuration_task_->Run(); | 1018 configuration_task_->Run(); |
| 1013 } | 1019 } |
| 1014 | 1020 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 last_virtual_display_id_ = max_display_id & 0xff; | 1158 last_virtual_display_id_ = max_display_id & 0xff; |
| 1153 | 1159 |
| 1154 return true; | 1160 return true; |
| 1155 } | 1161 } |
| 1156 | 1162 |
| 1157 bool DisplayConfigurator::IsDisplayOn() const { | 1163 bool DisplayConfigurator::IsDisplayOn() const { |
| 1158 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; | 1164 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; |
| 1159 } | 1165 } |
| 1160 | 1166 |
| 1161 } // namespace ui | 1167 } // namespace ui |
| OLD | NEW |