| 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" | |
| 11 #include "base/strings/stringprintf.h" | |
| 12 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 13 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "ui/display/chromeos/display_util.h" |
| 14 #include "ui/display/display_switches.h" | 13 #include "ui/display/display_switches.h" |
| 15 #include "ui/display/types/display_mode.h" | 14 #include "ui/display/types/display_mode.h" |
| 16 #include "ui/display/types/display_snapshot.h" | 15 #include "ui/display/types/display_snapshot.h" |
| 17 #include "ui/display/types/native_display_delegate.h" | 16 #include "ui/display/types/native_display_delegate.h" |
| 18 | 17 |
| 19 namespace ui { | 18 namespace ui { |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 typedef std::vector<const DisplayMode*> DisplayModeList; | 22 typedef std::vector<const DisplayMode*> DisplayModeList; |
| 24 | 23 |
| 25 // The delay to perform configuration after RRNotify. See the comment for | 24 // The delay to perform configuration after RRNotify. See the comment for |
| 26 // |configure_timer_|. | 25 // |configure_timer_|. |
| 27 const int kConfigureDelayMs = 500; | 26 const int kConfigureDelayMs = 500; |
| 28 | 27 |
| 29 // The delay spent before reading the display configuration after coming out of | 28 // 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 | 29 // 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 | 30 // 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. | 31 // such that we read an up to date state. |
| 33 const int kResumeDelayMs = 500; | 32 const int kResumeDelayMs = 500; |
| 34 | 33 |
| 35 // Returns a string describing |state|. | |
| 36 std::string DisplayPowerStateToString(chromeos::DisplayPowerState state) { | |
| 37 switch (state) { | |
| 38 case chromeos::DISPLAY_POWER_ALL_ON: | |
| 39 return "ALL_ON"; | |
| 40 case chromeos::DISPLAY_POWER_ALL_OFF: | |
| 41 return "ALL_OFF"; | |
| 42 case chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON: | |
| 43 return "INTERNAL_OFF_EXTERNAL_ON"; | |
| 44 case chromeos::DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF: | |
| 45 return "INTERNAL_ON_EXTERNAL_OFF"; | |
| 46 default: | |
| 47 return "unknown (" + base::IntToString(state) + ")"; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 // Returns a string describing |state|. | |
| 52 std::string DisplayStateToString(MultipleDisplayState state) { | |
| 53 switch (state) { | |
| 54 case MULTIPLE_DISPLAY_STATE_INVALID: | |
| 55 return "INVALID"; | |
| 56 case MULTIPLE_DISPLAY_STATE_HEADLESS: | |
| 57 return "HEADLESS"; | |
| 58 case MULTIPLE_DISPLAY_STATE_SINGLE: | |
| 59 return "SINGLE"; | |
| 60 case MULTIPLE_DISPLAY_STATE_DUAL_MIRROR: | |
| 61 return "DUAL_MIRROR"; | |
| 62 case MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED: | |
| 63 return "DUAL_EXTENDED"; | |
| 64 case MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED: | |
| 65 return "MULTI_EXTENDED"; | |
| 66 } | |
| 67 NOTREACHED() << "Unknown state " << state; | |
| 68 return "INVALID"; | |
| 69 } | |
| 70 | |
| 71 // Returns the number of displays in |displays| that should be turned on, per | |
| 72 // |state|. If |display_power| is non-NULL, it is updated to contain the | |
| 73 // on/off state of each corresponding entry in |displays|. | |
| 74 int GetDisplayPower( | |
| 75 const std::vector<DisplayConfigurator::DisplayState>& display_states, | |
| 76 chromeos::DisplayPowerState state, | |
| 77 std::vector<bool>* display_power) { | |
| 78 int num_on_displays = 0; | |
| 79 if (display_power) | |
| 80 display_power->resize(display_states.size()); | |
| 81 | |
| 82 for (size_t i = 0; i < display_states.size(); ++i) { | |
| 83 bool internal = | |
| 84 display_states[i].display->type() == DISPLAY_CONNECTION_TYPE_INTERNAL; | |
| 85 bool on = | |
| 86 state == chromeos::DISPLAY_POWER_ALL_ON || | |
| 87 (state == chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON && | |
| 88 !internal) || | |
| 89 (state == chromeos::DISPLAY_POWER_INTERNAL_ON_EXTERNAL_OFF && internal); | |
| 90 if (display_power) | |
| 91 (*display_power)[i] = on; | |
| 92 if (on) | |
| 93 num_on_displays++; | |
| 94 } | |
| 95 return num_on_displays; | |
| 96 } | |
| 97 | |
| 98 } // namespace | 34 } // namespace |
| 99 | 35 |
| 100 | 36 |
| 101 const int DisplayConfigurator::kSetDisplayPowerNoFlags = 0; | 37 const int DisplayConfigurator::kSetDisplayPowerNoFlags = 0; |
| 102 const int DisplayConfigurator::kSetDisplayPowerForceProbe = 1 << 0; | 38 const int DisplayConfigurator::kSetDisplayPowerForceProbe = 1 << 0; |
| 103 const int | 39 const int |
| 104 DisplayConfigurator::kSetDisplayPowerOnlyIfSingleInternalDisplay = 1 << 1; | 40 DisplayConfigurator::kSetDisplayPowerOnlyIfSingleInternalDisplay = 1 << 1; |
| 105 | 41 |
| 106 DisplayConfigurator::DisplayState::DisplayState() | 42 DisplayConfigurator::DisplayState::DisplayState() |
| 107 : display(NULL), | 43 : display(NULL), |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 native_display_delegate_->UngrabServer(); | 455 native_display_delegate_->UngrabServer(); |
| 520 if (attempted_change) | 456 if (attempted_change) |
| 521 NotifyObservers(success, new_state); | 457 NotifyObservers(success, new_state); |
| 522 return success; | 458 return success; |
| 523 } | 459 } |
| 524 | 460 |
| 525 bool DisplayConfigurator::SetDisplayMode(MultipleDisplayState new_state) { | 461 bool DisplayConfigurator::SetDisplayMode(MultipleDisplayState new_state) { |
| 526 if (!configure_display_ || display_externally_controlled_) | 462 if (!configure_display_ || display_externally_controlled_) |
| 527 return false; | 463 return false; |
| 528 | 464 |
| 529 VLOG(1) << "SetDisplayMode: state=" << DisplayStateToString(new_state); | 465 VLOG(1) << "SetDisplayMode: state=" |
| 466 << MultipleDisplayStateToString(new_state); |
| 530 if (display_state_ == new_state) { | 467 if (display_state_ == new_state) { |
| 531 // Cancel software mirroring if the state is moving from | 468 // Cancel software mirroring if the state is moving from |
| 532 // MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED to | 469 // MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED to |
| 533 // MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED. | 470 // MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED. |
| 534 if (mirroring_controller_ && | 471 if (mirroring_controller_ && |
| 535 new_state == MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) | 472 new_state == MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) |
| 536 mirroring_controller_->SetSoftwareMirroring(false); | 473 mirroring_controller_->SetSoftwareMirroring(false); |
| 537 NotifyObservers(true, new_state); | 474 NotifyObservers(true, new_state); |
| 538 return true; | 475 return true; |
| 539 } | 476 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 mirroring_controller_->SetSoftwareMirroring(enable_software_mirroring); | 728 mirroring_controller_->SetSoftwareMirroring(enable_software_mirroring); |
| 792 } | 729 } |
| 793 return success; | 730 return success; |
| 794 } | 731 } |
| 795 | 732 |
| 796 bool DisplayConfigurator::EnterState(MultipleDisplayState display_state, | 733 bool DisplayConfigurator::EnterState(MultipleDisplayState display_state, |
| 797 chromeos::DisplayPowerState power_state) { | 734 chromeos::DisplayPowerState power_state) { |
| 798 std::vector<bool> display_power; | 735 std::vector<bool> display_power; |
| 799 int num_on_displays = | 736 int num_on_displays = |
| 800 GetDisplayPower(cached_displays_, power_state, &display_power); | 737 GetDisplayPower(cached_displays_, power_state, &display_power); |
| 801 VLOG(1) << "EnterState: display=" << DisplayStateToString(display_state) | 738 VLOG(1) << "EnterState: display=" |
| 739 << MultipleDisplayStateToString(display_state) |
| 802 << " power=" << DisplayPowerStateToString(power_state); | 740 << " power=" << DisplayPowerStateToString(power_state); |
| 803 | 741 |
| 804 // Save the requested state so we'll try to use it next time even if we fail. | 742 // Save the requested state so we'll try to use it next time even if we fail. |
| 805 requested_power_state_ = power_state; | 743 requested_power_state_ = power_state; |
| 806 | 744 |
| 807 // Framebuffer dimensions. | 745 // Framebuffer dimensions. |
| 808 gfx::Size size; | 746 gfx::Size size; |
| 809 | 747 |
| 810 std::vector<gfx::Point> new_origins(cached_displays_.size(), gfx::Point()); | 748 std::vector<gfx::Point> new_origins(cached_displays_.size(), gfx::Point()); |
| 811 std::vector<const DisplayMode*> new_mode; | 749 std::vector<const DisplayMode*> new_mode; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 | 945 |
| 1008 return state_controller_->GetStateForDisplayIds(display_ids); | 946 return state_controller_->GetStateForDisplayIds(display_ids); |
| 1009 } | 947 } |
| 1010 NOTREACHED(); | 948 NOTREACHED(); |
| 1011 } | 949 } |
| 1012 } | 950 } |
| 1013 return MULTIPLE_DISPLAY_STATE_INVALID; | 951 return MULTIPLE_DISPLAY_STATE_INVALID; |
| 1014 } | 952 } |
| 1015 | 953 |
| 1016 } // namespace ui | 954 } // namespace ui |
| OLD | NEW |