| 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/manager/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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "ui/display/chromeos/apply_content_protection_task.h" | |
| 17 #include "ui/display/chromeos/display_layout_manager.h" | |
| 18 #include "ui/display/chromeos/display_snapshot_virtual.h" | |
| 19 #include "ui/display/chromeos/display_util.h" | |
| 20 #include "ui/display/chromeos/update_display_configuration_task.h" | |
| 21 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 22 #include "ui/display/display_switches.h" | 17 #include "ui/display/display_switches.h" |
| 18 #include "ui/display/manager/chromeos/apply_content_protection_task.h" |
| 19 #include "ui/display/manager/chromeos/display_layout_manager.h" |
| 20 #include "ui/display/manager/chromeos/display_snapshot_virtual.h" |
| 21 #include "ui/display/manager/chromeos/display_util.h" |
| 22 #include "ui/display/manager/chromeos/update_display_configuration_task.h" |
| 23 #include "ui/display/types/display_mode.h" | 23 #include "ui/display/types/display_mode.h" |
| 24 #include "ui/display/types/display_snapshot.h" | 24 #include "ui/display/types/display_snapshot.h" |
| 25 #include "ui/display/types/native_display_delegate.h" | 25 #include "ui/display/types/native_display_delegate.h" |
| 26 #include "ui/display/util/display_util.h" | 26 #include "ui/display/util/display_util.h" |
| 27 | 27 |
| 28 namespace ui { | 28 namespace ui { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 typedef std::vector<const DisplayMode*> DisplayModeList; | 32 typedef std::vector<const DisplayMode*> DisplayModeList; |
| 33 | 33 |
| 34 // The EDID specification marks the top bit of the manufacturer id as reserved. | 34 // The EDID specification marks the top bit of the manufacturer id as reserved. |
| 35 const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); | 35 const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); |
| 36 | 36 |
| 37 struct DisplayState { | 37 struct DisplayState { |
| 38 DisplaySnapshot* display = nullptr; // Not owned. | 38 DisplaySnapshot* display = nullptr; // Not owned. |
| 39 | 39 |
| 40 // User-selected mode for the display. | 40 // User-selected mode for the display. |
| 41 const DisplayMode* selected_mode = nullptr; | 41 const DisplayMode* selected_mode = nullptr; |
| 42 | 42 |
| 43 // Mode used when displaying the same desktop on multiple displays. | 43 // Mode used when displaying the same desktop on multiple displays. |
| 44 const DisplayMode* mirror_mode = nullptr; | 44 const DisplayMode* mirror_mode = nullptr; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 void DoNothing(bool status) { | 47 void DoNothing(bool status) {} |
| 48 } | |
| 49 | 48 |
| 50 } // namespace | 49 } // namespace |
| 51 | 50 |
| 52 const int DisplayConfigurator::kSetDisplayPowerNoFlags = 0; | 51 const int DisplayConfigurator::kSetDisplayPowerNoFlags = 0; |
| 53 const int DisplayConfigurator::kSetDisplayPowerForceProbe = 1 << 0; | 52 const int DisplayConfigurator::kSetDisplayPowerForceProbe = 1 << 0; |
| 54 const int | 53 const int DisplayConfigurator::kSetDisplayPowerOnlyIfSingleInternalDisplay = |
| 55 DisplayConfigurator::kSetDisplayPowerOnlyIfSingleInternalDisplay = 1 << 1; | 54 1 << 1; |
| 56 | 55 |
| 57 bool DisplayConfigurator::TestApi::TriggerConfigureTimeout() { | 56 bool DisplayConfigurator::TestApi::TriggerConfigureTimeout() { |
| 58 if (configurator_->configure_timer_.IsRunning()) { | 57 if (configurator_->configure_timer_.IsRunning()) { |
| 59 configurator_->configure_timer_.user_task().Run(); | 58 configurator_->configure_timer_.user_task().Run(); |
| 60 configurator_->configure_timer_.Stop(); | 59 configurator_->configure_timer_.Stop(); |
| 61 return true; | 60 return true; |
| 62 } else { | 61 } else { |
| 63 return false; | 62 return false; |
| 64 } | 63 } |
| 65 } | 64 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 bool try_panel_fitting, | 118 bool try_panel_fitting, |
| 120 bool preserve_aspect) const; | 119 bool preserve_aspect) const; |
| 121 | 120 |
| 122 DisplayConfigurator* configurator_; // Not owned. | 121 DisplayConfigurator* configurator_; // Not owned. |
| 123 | 122 |
| 124 DISALLOW_COPY_AND_ASSIGN(DisplayLayoutManagerImpl); | 123 DISALLOW_COPY_AND_ASSIGN(DisplayLayoutManagerImpl); |
| 125 }; | 124 }; |
| 126 | 125 |
| 127 DisplayConfigurator::DisplayLayoutManagerImpl::DisplayLayoutManagerImpl( | 126 DisplayConfigurator::DisplayLayoutManagerImpl::DisplayLayoutManagerImpl( |
| 128 DisplayConfigurator* configurator) | 127 DisplayConfigurator* configurator) |
| 129 : configurator_(configurator) { | 128 : configurator_(configurator) {} |
| 130 } | |
| 131 | 129 |
| 132 DisplayConfigurator::DisplayLayoutManagerImpl::~DisplayLayoutManagerImpl() { | 130 DisplayConfigurator::DisplayLayoutManagerImpl::~DisplayLayoutManagerImpl() {} |
| 133 } | |
| 134 | 131 |
| 135 DisplayConfigurator::SoftwareMirroringController* | 132 DisplayConfigurator::SoftwareMirroringController* |
| 136 DisplayConfigurator::DisplayLayoutManagerImpl::GetSoftwareMirroringController() | 133 DisplayConfigurator::DisplayLayoutManagerImpl::GetSoftwareMirroringController() |
| 137 const { | 134 const { |
| 138 return configurator_->mirroring_controller_; | 135 return configurator_->mirroring_controller_; |
| 139 } | 136 } |
| 140 | 137 |
| 141 DisplayConfigurator::StateController* | 138 DisplayConfigurator::StateController* |
| 142 DisplayConfigurator::DisplayLayoutManagerImpl::GetStateController() const { | 139 DisplayConfigurator::DisplayLayoutManagerImpl::GetStateController() const { |
| 143 return configurator_->state_controller_; | 140 return configurator_->state_controller_; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 bool can_fit = internal_native_info->size().width() >= | 403 bool can_fit = internal_native_info->size().width() >= |
| 407 external_mode->size().width() && | 404 external_mode->size().width() && |
| 408 internal_native_info->size().height() >= | 405 internal_native_info->size().height() >= |
| 409 external_mode->size().height() && | 406 external_mode->size().height() && |
| 410 !external_mode->is_interlaced(); | 407 !external_mode->is_interlaced(); |
| 411 if (can_fit) { | 408 if (can_fit) { |
| 412 configurator_->native_display_delegate_->AddMode( | 409 configurator_->native_display_delegate_->AddMode( |
| 413 *internal_display->display, external_mode.get()); | 410 *internal_display->display, external_mode.get()); |
| 414 internal_display->display->add_mode(external_mode.get()); | 411 internal_display->display->add_mode(external_mode.get()); |
| 415 internal_display->mirror_mode = | 412 internal_display->mirror_mode = |
| 416 internal_display->display->modes().back().get(); | 413 internal_display->display->modes().back().get(); |
| 417 external_display->mirror_mode = external_mode.get(); | 414 external_display->mirror_mode = external_mode.get(); |
| 418 return true; // Mirror mode created. | 415 return true; // Mirror mode created. |
| 419 } | 416 } |
| 420 } | 417 } |
| 421 } | 418 } |
| 422 | 419 |
| 423 return false; | 420 return false; |
| 424 } | 421 } |
| 425 | 422 |
| 426 //////////////////////////////////////////////////////////////////////////////// | 423 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 requested_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 473 requested_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 477 pending_power_state_(chromeos::DISPLAY_POWER_ALL_ON), | 474 pending_power_state_(chromeos::DISPLAY_POWER_ALL_ON), |
| 478 has_pending_power_state_(false), | 475 has_pending_power_state_(false), |
| 479 pending_power_flags_(kSetDisplayPowerNoFlags), | 476 pending_power_flags_(kSetDisplayPowerNoFlags), |
| 480 force_configure_(false), | 477 force_configure_(false), |
| 481 next_display_protection_client_id_(1), | 478 next_display_protection_client_id_(1), |
| 482 display_externally_controlled_(false), | 479 display_externally_controlled_(false), |
| 483 display_control_changing_(false), | 480 display_control_changing_(false), |
| 484 displays_suspended_(false), | 481 displays_suspended_(false), |
| 485 layout_manager_(new DisplayLayoutManagerImpl(this)), | 482 layout_manager_(new DisplayLayoutManagerImpl(this)), |
| 486 weak_ptr_factory_(this) { | 483 weak_ptr_factory_(this) {} |
| 487 } | |
| 488 | 484 |
| 489 DisplayConfigurator::~DisplayConfigurator() { | 485 DisplayConfigurator::~DisplayConfigurator() { |
| 490 if (native_display_delegate_) | 486 if (native_display_delegate_) |
| 491 native_display_delegate_->RemoveObserver(this); | 487 native_display_delegate_->RemoveObserver(this); |
| 492 | 488 |
| 493 CallAndClearInProgressCallbacks(false); | 489 CallAndClearInProgressCallbacks(false); |
| 494 CallAndClearQueuedCallbacks(false); | 490 CallAndClearQueuedCallbacks(false); |
| 495 | 491 |
| 496 while (!query_protection_callbacks_.empty()) { | 492 while (!query_protection_callbacks_.empty()) { |
| 497 query_protection_callbacks_.front().Run(QueryProtectionResponse()); | 493 query_protection_callbacks_.front().Run(QueryProtectionResponse()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 585 |
| 590 // Turn off the displays before releasing control since we're no longer using | 586 // Turn off the displays before releasing control since we're no longer using |
| 591 // them for output. | 587 // them for output. |
| 592 SetDisplayPowerInternal( | 588 SetDisplayPowerInternal( |
| 593 chromeos::DISPLAY_POWER_ALL_OFF, kSetDisplayPowerNoFlags, | 589 chromeos::DISPLAY_POWER_ALL_OFF, kSetDisplayPowerNoFlags, |
| 594 base::Bind(&DisplayConfigurator::SendRelinquishDisplayControl, | 590 base::Bind(&DisplayConfigurator::SendRelinquishDisplayControl, |
| 595 weak_ptr_factory_.GetWeakPtr(), callback)); | 591 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 596 } | 592 } |
| 597 | 593 |
| 598 void DisplayConfigurator::SendRelinquishDisplayControl( | 594 void DisplayConfigurator::SendRelinquishDisplayControl( |
| 599 const DisplayControlCallback& callback, bool success) { | 595 const DisplayControlCallback& callback, |
| 596 bool success) { |
| 600 if (success) { | 597 if (success) { |
| 601 // Set the flag early such that an incoming configuration event won't start | 598 // Set the flag early such that an incoming configuration event won't start |
| 602 // while we're releasing control of the displays. | 599 // while we're releasing control of the displays. |
| 603 display_externally_controlled_ = true; | 600 display_externally_controlled_ = true; |
| 604 native_display_delegate_->RelinquishDisplayControl( | 601 native_display_delegate_->RelinquishDisplayControl( |
| 605 base::Bind(&DisplayConfigurator::OnDisplayControlRelinquished, | 602 base::Bind(&DisplayConfigurator::OnDisplayControlRelinquished, |
| 606 weak_ptr_factory_.GetWeakPtr(), callback)); | 603 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 607 } else { | 604 } else { |
| 608 display_control_changing_ = false; | 605 display_control_changing_ = false; |
| 609 callback.Run(false); | 606 callback.Run(false); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 | 1022 |
| 1026 if (!ShouldRunConfigurationTask()) { | 1023 if (!ShouldRunConfigurationTask()) { |
| 1027 LOG(ERROR) << "Called RunPendingConfiguration without any changes" | 1024 LOG(ERROR) << "Called RunPendingConfiguration without any changes" |
| 1028 " requested"; | 1025 " requested"; |
| 1029 CallAndClearQueuedCallbacks(true); | 1026 CallAndClearQueuedCallbacks(true); |
| 1030 return; | 1027 return; |
| 1031 } | 1028 } |
| 1032 | 1029 |
| 1033 configuration_task_.reset(new UpdateDisplayConfigurationTask( | 1030 configuration_task_.reset(new UpdateDisplayConfigurationTask( |
| 1034 native_display_delegate_.get(), layout_manager_.get(), | 1031 native_display_delegate_.get(), layout_manager_.get(), |
| 1035 requested_display_state_, pending_power_state_, pending_power_flags_, | 1032 requested_display_state_, pending_power_state_, pending_power_flags_, 0, |
| 1036 0, force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, | 1033 force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, |
| 1037 weak_ptr_factory_.GetWeakPtr()))); | 1034 weak_ptr_factory_.GetWeakPtr()))); |
| 1038 configuration_task_->set_virtual_display_snapshots( | 1035 configuration_task_->set_virtual_display_snapshots( |
| 1039 virtual_display_snapshots_.get()); | 1036 virtual_display_snapshots_.get()); |
| 1040 | 1037 |
| 1041 // Reset the flags before running the task; otherwise it may end up scheduling | 1038 // Reset the flags before running the task; otherwise it may end up scheduling |
| 1042 // another configuration. | 1039 // another configuration. |
| 1043 force_configure_ = false; | 1040 force_configure_ = false; |
| 1044 pending_power_flags_ = kSetDisplayPowerNoFlags; | 1041 pending_power_flags_ = kSetDisplayPowerNoFlags; |
| 1045 has_pending_power_state_ = false; | 1042 has_pending_power_state_ = false; |
| 1046 requested_display_state_ = MULTIPLE_DISPLAY_STATE_INVALID; | 1043 requested_display_state_ = MULTIPLE_DISPLAY_STATE_INVALID; |
| 1047 | 1044 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 last_virtual_display_id_ = max_display_id & 0xff; | 1187 last_virtual_display_id_ = max_display_id & 0xff; |
| 1191 | 1188 |
| 1192 return true; | 1189 return true; |
| 1193 } | 1190 } |
| 1194 | 1191 |
| 1195 bool DisplayConfigurator::IsDisplayOn() const { | 1192 bool DisplayConfigurator::IsDisplayOn() const { |
| 1196 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; | 1193 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; |
| 1197 } | 1194 } |
| 1198 | 1195 |
| 1199 } // namespace ui | 1196 } // namespace ui |
| OLD | NEW |