| 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 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 base::Bind(&DisplayConfigurator::OnDisplayControlTaken, | 550 base::Bind(&DisplayConfigurator::OnDisplayControlTaken, |
| 551 weak_ptr_factory_.GetWeakPtr(), callback)); | 551 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 552 } | 552 } |
| 553 | 553 |
| 554 void DisplayConfigurator::OnDisplayControlTaken( | 554 void DisplayConfigurator::OnDisplayControlTaken( |
| 555 const DisplayControlCallback& callback, | 555 const DisplayControlCallback& callback, |
| 556 bool success) { | 556 bool success) { |
| 557 display_control_changing_ = false; | 557 display_control_changing_ = false; |
| 558 display_externally_controlled_ = !success; | 558 display_externally_controlled_ = !success; |
| 559 if (success) { | 559 if (success) { |
| 560 // Force a configuration since the display configuration may have changed. |
| 560 force_configure_ = true; | 561 force_configure_ = true; |
| 561 RunPendingConfiguration(); | 562 // Restore the last power state used before releasing control. |
| 563 SetDisplayPower(requested_power_state_, kSetDisplayPowerNoFlags, |
| 564 base::Bind(&DoNothing)); |
| 562 } | 565 } |
| 563 | 566 |
| 564 callback.Run(success); | 567 callback.Run(success); |
| 565 } | 568 } |
| 566 | 569 |
| 567 void DisplayConfigurator::RelinquishControl( | 570 void DisplayConfigurator::RelinquishControl( |
| 568 const DisplayControlCallback& callback) { | 571 const DisplayControlCallback& callback) { |
| 569 if (display_control_changing_) { | 572 if (display_control_changing_) { |
| 570 callback.Run(false); | 573 callback.Run(false); |
| 571 return; | 574 return; |
| 572 } | 575 } |
| 573 | 576 |
| 574 if (display_externally_controlled_) { | 577 if (display_externally_controlled_) { |
| 575 callback.Run(true); | 578 callback.Run(true); |
| 576 return; | 579 return; |
| 577 } | 580 } |
| 578 | 581 |
| 579 // For simplicity, just fail if in the middle of a display configuration. | 582 // For simplicity, just fail if in the middle of a display configuration. |
| 580 if (configuration_task_) { | 583 if (configuration_task_) { |
| 581 callback.Run(false); | 584 callback.Run(false); |
| 582 return; | 585 return; |
| 583 } | 586 } |
| 584 | 587 |
| 585 // Set the flag early such that an incoming configuration event won't start | |
| 586 // while we're releasing control of the displays. | |
| 587 display_control_changing_ = true; | 588 display_control_changing_ = true; |
| 588 display_externally_controlled_ = true; | 589 |
| 589 native_display_delegate_->RelinquishDisplayControl( | 590 // Turn off the displays before releasing control since we're no longer using |
| 590 base::Bind(&DisplayConfigurator::OnDisplayControlRelinquished, | 591 // them for output. |
| 592 SetDisplayPowerInternal( |
| 593 chromeos::DISPLAY_POWER_ALL_OFF, kSetDisplayPowerNoFlags, |
| 594 base::Bind(&DisplayConfigurator::SendRelinquishDisplayControl, |
| 591 weak_ptr_factory_.GetWeakPtr(), callback)); | 595 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 592 } | 596 } |
| 593 | 597 |
| 598 void DisplayConfigurator::SendRelinquishDisplayControl( |
| 599 const DisplayControlCallback& callback, bool success) { |
| 600 if (success) { |
| 601 // Set the flag early such that an incoming configuration event won't start |
| 602 // while we're releasing control of the displays. |
| 603 display_externally_controlled_ = true; |
| 604 native_display_delegate_->RelinquishDisplayControl( |
| 605 base::Bind(&DisplayConfigurator::OnDisplayControlRelinquished, |
| 606 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 607 } else { |
| 608 display_control_changing_ = false; |
| 609 callback.Run(false); |
| 610 } |
| 611 } |
| 612 |
| 594 void DisplayConfigurator::OnDisplayControlRelinquished( | 613 void DisplayConfigurator::OnDisplayControlRelinquished( |
| 595 const DisplayControlCallback& callback, | 614 const DisplayControlCallback& callback, |
| 596 bool success) { | 615 bool success) { |
| 597 display_control_changing_ = false; | 616 display_control_changing_ = false; |
| 598 display_externally_controlled_ = success; | 617 display_externally_controlled_ = success; |
| 599 if (!success) { | 618 if (!success) { |
| 600 force_configure_ = true; | 619 force_configure_ = true; |
| 601 RunPendingConfiguration(); | 620 RunPendingConfiguration(); |
| 602 } | 621 } |
| 603 | 622 |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 last_virtual_display_id_ = max_display_id & 0xff; | 1190 last_virtual_display_id_ = max_display_id & 0xff; |
| 1172 | 1191 |
| 1173 return true; | 1192 return true; |
| 1174 } | 1193 } |
| 1175 | 1194 |
| 1176 bool DisplayConfigurator::IsDisplayOn() const { | 1195 bool DisplayConfigurator::IsDisplayOn() const { |
| 1177 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; | 1196 return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; |
| 1178 } | 1197 } |
| 1179 | 1198 |
| 1180 } // namespace ui | 1199 } // namespace ui |
| OLD | NEW |