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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 if (display_power) | 82 if (display_power) |
83 (*display_power)[i] = on; | 83 (*display_power)[i] = on; |
84 if (on) | 84 if (on) |
85 num_on_displays++; | 85 num_on_displays++; |
86 } | 86 } |
87 return num_on_displays; | 87 return num_on_displays; |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 | |
93 // static | |
Daniel Erat
2014/08/12 21:00:03
nit: don't need "static" comments here; it's obvio
dnicoara
2014/08/12 21:46:20
Done.
| |
94 const int DisplayConfigurator::kSetDisplayPowerNoFlags = 0; | |
95 // static | |
96 const int DisplayConfigurator::kSetDisplayPowerForceProbe = 1 << 0; | |
97 // static | |
98 const int | |
99 DisplayConfigurator::kSetDisplayPowerOnlyIfSingleInternalDisplay = 1 << 1; | |
100 | |
92 DisplayConfigurator::DisplayState::DisplayState() | 101 DisplayConfigurator::DisplayState::DisplayState() |
93 : display(NULL), | 102 : display(NULL), |
94 touch_device_id(0), | 103 touch_device_id(0), |
95 selected_mode(NULL), | 104 selected_mode(NULL), |
96 mirror_mode(NULL) {} | 105 mirror_mode(NULL) {} |
97 | 106 |
98 bool DisplayConfigurator::TestApi::TriggerConfigureTimeout() { | 107 bool DisplayConfigurator::TestApi::TriggerConfigureTimeout() { |
99 if (configurator_->configure_timer_.get() && | 108 if (configurator_->configure_timer_.get() && |
100 configurator_->configure_timer_->IsRunning()) { | 109 configurator_->configure_timer_->IsRunning()) { |
101 configurator_->configure_timer_.reset(); | 110 configurator_->configure_timer_->user_task().Run(); |
102 configurator_->ConfigureDisplays(); | |
103 return true; | 111 return true; |
104 } else { | 112 } else { |
105 return false; | 113 return false; |
106 } | 114 } |
107 } | 115 } |
108 | 116 |
109 // static | 117 // static |
110 const DisplayMode* DisplayConfigurator::FindDisplayModeMatchingSize( | 118 const DisplayMode* DisplayConfigurator::FindDisplayModeMatchingSize( |
111 const DisplaySnapshot& display, | 119 const DisplaySnapshot& display, |
112 const gfx::Size& size) { | 120 const gfx::Size& size) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 return false; | 432 return false; |
425 } | 433 } |
426 | 434 |
427 void DisplayConfigurator::PrepareForExit() { | 435 void DisplayConfigurator::PrepareForExit() { |
428 configure_display_ = false; | 436 configure_display_ = false; |
429 } | 437 } |
430 | 438 |
431 bool DisplayConfigurator::SetDisplayPower( | 439 bool DisplayConfigurator::SetDisplayPower( |
432 chromeos::DisplayPowerState power_state, | 440 chromeos::DisplayPowerState power_state, |
433 int flags) { | 441 int flags) { |
442 configure_timer_.reset(); | |
443 | |
434 if (!configure_display_) | 444 if (!configure_display_) |
435 return false; | 445 return false; |
436 | 446 |
437 VLOG(1) << "SetDisplayPower: power_state=" | 447 VLOG(1) << "SetDisplayPower: power_state=" |
438 << DisplayPowerStateToString(power_state) << " flags=" << flags | 448 << DisplayPowerStateToString(power_state) << " flags=" << flags |
439 << ", configure timer=" | 449 << ", configure timer=" |
440 << ((configure_timer_.get() && configure_timer_->IsRunning()) ? | 450 << ((configure_timer_.get() && configure_timer_->IsRunning()) ? |
441 "Running" : "Stopped"); | 451 "Running" : "Stopped"); |
442 if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe)) | 452 if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe)) |
443 return true; | 453 return true; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_.get()) { |
503 configure_timer_->Reset(); | 513 configure_timer_->Reset(); |
Daniel Erat
2014/08/12 21:00:04
is this broken? if configure_timer_ holds a SetDis
oshima
2014/08/12 21:05:17
Reset uses the same task, so it will still call Se
dnicoara
2014/08/12 21:46:20
Removed scoped_ptr.
Yes, resetting will just upda
| |
504 } else { | 514 } else { |
505 configure_timer_.reset(new base::OneShotTimer<DisplayConfigurator>()); | 515 configure_timer_.reset(new base::OneShotTimer<DisplayConfigurator>()); |
506 configure_timer_->Start( | 516 configure_timer_->Start( |
507 FROM_HERE, | 517 FROM_HERE, |
508 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | 518 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), |
509 this, | 519 this, |
510 &DisplayConfigurator::ConfigureDisplays); | 520 &DisplayConfigurator::ConfigureDisplays); |
511 } | 521 } |
512 } | 522 } |
513 | 523 |
(...skipping 18 matching lines...) Expand all Loading... | |
532 // We need to make sure that the monitor configuration we just did actually | 542 // 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 | 543 // completes before we return, because otherwise the X message could be |
534 // racing with the HandleSuspendReadiness message. | 544 // racing with the HandleSuspendReadiness message. |
535 native_display_delegate_->SyncWithServer(); | 545 native_display_delegate_->SyncWithServer(); |
536 } | 546 } |
537 } | 547 } |
538 | 548 |
539 void DisplayConfigurator::ResumeDisplays() { | 549 void DisplayConfigurator::ResumeDisplays() { |
540 // Force probing to ensure that we pick up any changes that were made | 550 // Force probing to ensure that we pick up any changes that were made |
541 // while the system was suspended. | 551 // while the system was suspended. |
542 SetDisplayPower(power_state_, kSetDisplayPowerForceProbe); | 552 configure_timer_.reset(new base::OneShotTimer<DisplayConfigurator>()); |
553 configure_timer_->Start( | |
554 FROM_HERE, | |
555 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | |
Daniel Erat
2014/08/12 21:00:03
please add a new constant for this with a comment
dnicoara
2014/08/12 21:46:20
Done.
| |
556 base::Bind(base::IgnoreResult(&DisplayConfigurator::SetDisplayPower), | |
557 base::Unretained(this), | |
558 power_state_, | |
559 kSetDisplayPowerForceProbe)); | |
543 } | 560 } |
544 | 561 |
545 void DisplayConfigurator::UpdateCachedDisplays() { | 562 void DisplayConfigurator::UpdateCachedDisplays() { |
546 std::vector<DisplaySnapshot*> snapshots = | 563 std::vector<DisplaySnapshot*> snapshots = |
547 native_display_delegate_->GetDisplays(); | 564 native_display_delegate_->GetDisplays(); |
548 | 565 |
549 cached_displays_.clear(); | 566 cached_displays_.clear(); |
550 for (size_t i = 0; i < snapshots.size(); ++i) { | 567 for (size_t i = 0; i < snapshots.size(); ++i) { |
551 DisplayState display_state; | 568 DisplayState display_state; |
552 display_state.display = snapshots[i]; | 569 display_state.display = snapshots[i]; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 return state_controller_->GetStateForDisplayIds(display_ids); | 957 return state_controller_->GetStateForDisplayIds(display_ids); |
941 } | 958 } |
942 } | 959 } |
943 default: | 960 default: |
944 NOTREACHED(); | 961 NOTREACHED(); |
945 } | 962 } |
946 return MULTIPLE_DISPLAY_STATE_INVALID; | 963 return MULTIPLE_DISPLAY_STATE_INVALID; |
947 } | 964 } |
948 | 965 |
949 } // namespace ui | 966 } // namespace ui |
OLD | NEW |