[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 5 | #include "ui/display/chromeos/display_configurator.h" |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 6 | |
[email protected] | 08b47ca | 2014-03-28 13:46:20 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
[email protected] | 06b20fe | 2013-11-13 19:18:38 | [diff] [blame] | 9 | #include <cmath> |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 10 | #include <cstdarg> |
| 11 | #include <map> |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 12 | #include <string> |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 13 | #include <vector> |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 14 | |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | a20ff0f | 2014-03-19 16:56:49 | [diff] [blame] | 16 | #include "base/format_macros.h" |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 17 | #include "base/memory/scoped_vector.h" |
[email protected] | f129d250 | 2013-07-17 22:45:50 | [diff] [blame] | 18 | #include "base/message_loop/message_loop.h" |
[email protected] | afa339d7 | 2013-06-11 06:32:51 | [diff] [blame] | 19 | #include "base/strings/stringprintf.h" |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 20 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 21 | #include "ui/display/chromeos/test/test_display_snapshot.h" |
spang | cef1097 | 2014-09-18 15:47:10 | [diff] [blame] | 22 | #include "ui/display/types/display_mode.h" |
| 23 | #include "ui/display/types/native_display_delegate.h" |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 24 | |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 25 | namespace ui { |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 26 | |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 27 | namespace { |
| 28 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 29 | // Strings returned by TestNativeDisplayDelegate::GetActionsAndClear() to |
| 30 | // describe various actions that were performed. |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 31 | const char kInitXRandR[] = "init"; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 32 | const char kGrab[] = "grab"; |
| 33 | const char kUngrab[] = "ungrab"; |
| 34 | const char kSync[] = "sync"; |
| 35 | const char kForceDPMS[] = "dpms"; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 36 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 37 | // String returned by TestNativeDisplayDelegate::GetActionsAndClear() if no |
| 38 | // actions were requested. |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 39 | const char kNoActions[] = ""; |
| 40 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 41 | std::string DisplaySnapshotToString(const DisplaySnapshot& output) { |
[email protected] | a20ff0f | 2014-03-19 16:56:49 | [diff] [blame] | 42 | return base::StringPrintf("id=%" PRId64, output.display_id()); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 43 | } |
| 44 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 45 | // Returns a string describing a TestNativeDisplayDelegate::SetBackgroundColor() |
| 46 | // call. |
[email protected] | 08b47ca | 2014-03-28 13:46:20 | [diff] [blame] | 47 | std::string GetBackgroundAction(uint32_t color_argb) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 48 | return base::StringPrintf("background(0x%x)", color_argb); |
| 49 | } |
| 50 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 51 | // Returns a string describing a TestNativeDisplayDelegate::AddOutputMode() |
| 52 | // call. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 53 | std::string GetAddOutputModeAction(const DisplaySnapshot& output, |
| 54 | const DisplayMode* mode) { |
[email protected] | a20ff0f | 2014-03-19 16:56:49 | [diff] [blame] | 55 | return base::StringPrintf("add_mode(output=%" PRId64 ",mode=%s)", |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 56 | output.display_id(), |
[email protected] | 311063ab | 2014-03-19 22:10:09 | [diff] [blame] | 57 | mode->ToString().c_str()); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 3d1cd60 | 2014-02-26 23:39:18 | [diff] [blame] | 60 | // Returns a string describing a TestNativeDisplayDelegate::Configure() |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 61 | // call. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 62 | std::string GetCrtcAction(const DisplaySnapshot& output, |
| 63 | const DisplayMode* mode, |
| 64 | const gfx::Point& origin) { |
| 65 | return base::StringPrintf("crtc(display=[%s],x=%d,y=%d,mode=[%s])", |
| 66 | DisplaySnapshotToString(output).c_str(), |
| 67 | origin.x(), |
| 68 | origin.y(), |
[email protected] | 311063ab | 2014-03-19 22:10:09 | [diff] [blame] | 69 | mode ? mode->ToString().c_str() : "NULL"); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 72 | // Returns a string describing a TestNativeDisplayDelegate::CreateFramebuffer() |
| 73 | // call. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 74 | std::string GetFramebufferAction(const gfx::Size& size, |
| 75 | const DisplaySnapshot* out1, |
| 76 | const DisplaySnapshot* out2) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 77 | return base::StringPrintf( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 78 | "framebuffer(width=%d,height=%d,display1=%s,display2=%s)", |
| 79 | size.width(), |
| 80 | size.height(), |
| 81 | out1 ? DisplaySnapshotToString(*out1).c_str() : "NULL", |
| 82 | out2 ? DisplaySnapshotToString(*out2).c_str() : "NULL"); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 83 | } |
| 84 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 85 | // Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 86 | std::string GetSetHDCPStateAction(const DisplaySnapshot& output, |
| 87 | HDCPState state) { |
| 88 | return base::StringPrintf( |
[email protected] | a20ff0f | 2014-03-19 16:56:49 | [diff] [blame] | 89 | "set_hdcp(id=%" PRId64 ",state=%d)", output.display_id(), state); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 92 | // Joins a sequence of strings describing actions (e.g. kScreenDim) such |
| 93 | // that they can be compared against a string returned by |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 94 | // ActionLogger::GetActionsAndClear(). The list of actions must be |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 95 | // terminated by a NULL pointer. |
| 96 | std::string JoinActions(const char* action, ...) { |
| 97 | std::string actions; |
| 98 | |
| 99 | va_list arg_list; |
| 100 | va_start(arg_list, action); |
| 101 | while (action) { |
| 102 | if (!actions.empty()) |
| 103 | actions += ","; |
| 104 | actions += action; |
| 105 | action = va_arg(arg_list, const char*); |
| 106 | } |
| 107 | va_end(arg_list); |
| 108 | return actions; |
| 109 | } |
| 110 | |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 111 | class ActionLogger { |
| 112 | public: |
| 113 | ActionLogger() {} |
| 114 | |
| 115 | void AppendAction(const std::string& action) { |
| 116 | if (!actions_.empty()) |
| 117 | actions_ += ","; |
| 118 | actions_ += action; |
| 119 | } |
| 120 | |
| 121 | // Returns a comma-separated string describing the actions that were |
| 122 | // requested since the previous call to GetActionsAndClear() (i.e. |
| 123 | // results are non-repeatable). |
| 124 | std::string GetActionsAndClear() { |
| 125 | std::string actions = actions_; |
| 126 | actions_.clear(); |
| 127 | return actions; |
| 128 | } |
| 129 | |
| 130 | private: |
| 131 | std::string actions_; |
| 132 | |
| 133 | DISALLOW_COPY_AND_ASSIGN(ActionLogger); |
| 134 | }; |
| 135 | |
[email protected] | 3d1cd60 | 2014-02-26 23:39:18 | [diff] [blame] | 136 | class TestNativeDisplayDelegate : public NativeDisplayDelegate { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 137 | public: |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 138 | // Ownership of |log| remains with the caller. |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 139 | explicit TestNativeDisplayDelegate(ActionLogger* log) |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 140 | : max_configurable_pixels_(0), |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 141 | hdcp_state_(HDCP_STATE_UNDESIRED), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 142 | log_(log) {} |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 143 | virtual ~TestNativeDisplayDelegate() {} |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 144 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 145 | const std::vector<DisplaySnapshot*>& outputs() const { return outputs_; } |
| 146 | void set_outputs(const std::vector<DisplaySnapshot*>& outputs) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 147 | outputs_ = outputs; |
| 148 | } |
| 149 | |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 150 | void set_max_configurable_pixels(int pixels) { |
| 151 | max_configurable_pixels_ = pixels; |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 154 | void set_hdcp_state(HDCPState state) { hdcp_state_ = state; } |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 155 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 156 | // DisplayConfigurator::Delegate overrides: |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 157 | virtual void Initialize() OVERRIDE { log_->AppendAction(kInitXRandR); } |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 158 | virtual void GrabServer() OVERRIDE { log_->AppendAction(kGrab); } |
| 159 | virtual void UngrabServer() OVERRIDE { log_->AppendAction(kUngrab); } |
| 160 | virtual void SyncWithServer() OVERRIDE { log_->AppendAction(kSync); } |
[email protected] | 08b47ca | 2014-03-28 13:46:20 | [diff] [blame] | 161 | virtual void SetBackgroundColor(uint32_t color_argb) OVERRIDE { |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 162 | log_->AppendAction(GetBackgroundAction(color_argb)); |
| 163 | } |
| 164 | virtual void ForceDPMSOn() OVERRIDE { log_->AppendAction(kForceDPMS); } |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 165 | virtual std::vector<DisplaySnapshot*> GetDisplays() OVERRIDE { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 166 | return outputs_; |
| 167 | } |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 168 | virtual void AddMode(const DisplaySnapshot& output, |
| 169 | const DisplayMode* mode) OVERRIDE { |
| 170 | log_->AppendAction(GetAddOutputModeAction(output, mode)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 171 | } |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 172 | virtual bool Configure(const DisplaySnapshot& output, |
| 173 | const DisplayMode* mode, |
| 174 | const gfx::Point& origin) OVERRIDE { |
| 175 | log_->AppendAction(GetCrtcAction(output, mode, origin)); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 176 | |
| 177 | if (max_configurable_pixels_ == 0) |
| 178 | return true; |
| 179 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 180 | if (!mode) |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 181 | return false; |
| 182 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 183 | return mode->size().GetArea() <= max_configurable_pixels_; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 184 | } |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 185 | virtual void CreateFrameBuffer(const gfx::Size& size) OVERRIDE { |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 186 | log_->AppendAction( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 187 | GetFramebufferAction(size, |
| 188 | outputs_.size() >= 1 ? outputs_[0] : NULL, |
| 189 | outputs_.size() >= 2 ? outputs_[1] : NULL)); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 190 | } |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 191 | virtual bool GetHDCPState(const DisplaySnapshot& output, |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 192 | HDCPState* state) OVERRIDE { |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 193 | *state = hdcp_state_; |
[email protected] | a1ab6d8 | 2013-09-28 13:49:54 | [diff] [blame] | 194 | return true; |
| 195 | } |
| 196 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 197 | virtual bool SetHDCPState(const DisplaySnapshot& output, |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 198 | HDCPState state) OVERRIDE { |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 199 | log_->AppendAction(GetSetHDCPStateAction(output, state)); |
[email protected] | a1ab6d8 | 2013-09-28 13:49:54 | [diff] [blame] | 200 | return true; |
| 201 | } |
| 202 | |
[email protected] | 3847246 | 2014-03-22 07:01:50 | [diff] [blame] | 203 | virtual std::vector<ui::ColorCalibrationProfile> |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 204 | GetAvailableColorCalibrationProfiles(const DisplaySnapshot& output) OVERRIDE { |
[email protected] | 3847246 | 2014-03-22 07:01:50 | [diff] [blame] | 205 | return std::vector<ui::ColorCalibrationProfile>(); |
| 206 | } |
| 207 | |
[email protected] | 29fb7a27 | 2014-03-20 06:22:08 | [diff] [blame] | 208 | virtual bool SetColorCalibrationProfile( |
| 209 | const DisplaySnapshot& output, |
| 210 | ui::ColorCalibrationProfile new_profile) OVERRIDE { |
| 211 | return false; |
| 212 | } |
| 213 | |
[email protected] | 3d1cd60 | 2014-02-26 23:39:18 | [diff] [blame] | 214 | virtual void AddObserver(NativeDisplayObserver* observer) OVERRIDE {} |
| 215 | |
| 216 | virtual void RemoveObserver(NativeDisplayObserver* observer) OVERRIDE {} |
| 217 | |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 218 | private: |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 219 | // Outputs to be returned by GetDisplays(). |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 220 | std::vector<DisplaySnapshot*> outputs_; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 221 | |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 222 | // |max_configurable_pixels_| represents the maximum number of pixels that |
[email protected] | 3d1cd60 | 2014-02-26 23:39:18 | [diff] [blame] | 223 | // Configure will support. Tests can use this to force Configure |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 224 | // to fail if attempting to set a resolution that is higher than what |
| 225 | // a device might support under a given circumstance. |
[email protected] | 3d1cd60 | 2014-02-26 23:39:18 | [diff] [blame] | 226 | // A value of 0 means that no limit is enforced and Configure will |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 227 | // return success regardless of the resolution. |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 228 | int max_configurable_pixels_; |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 229 | |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 230 | // Result value of GetHDCPState(). |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 231 | HDCPState hdcp_state_; |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 232 | |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 233 | ActionLogger* log_; // Not owned. |
| 234 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 235 | DISALLOW_COPY_AND_ASSIGN(TestNativeDisplayDelegate); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 236 | }; |
| 237 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 238 | class TestObserver : public DisplayConfigurator::Observer { |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 239 | public: |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 240 | explicit TestObserver(DisplayConfigurator* configurator) |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 241 | : configurator_(configurator) { |
| 242 | Reset(); |
| 243 | configurator_->AddObserver(this); |
| 244 | } |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 245 | virtual ~TestObserver() { configurator_->RemoveObserver(this); } |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 246 | |
| 247 | int num_changes() const { return num_changes_; } |
| 248 | int num_failures() const { return num_failures_; } |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 249 | const DisplayConfigurator::DisplayStateList& latest_outputs() const { |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 250 | return latest_outputs_; |
| 251 | } |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 252 | MultipleDisplayState latest_failed_state() const { |
| 253 | return latest_failed_state_; |
| 254 | } |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 255 | |
| 256 | void Reset() { |
| 257 | num_changes_ = 0; |
| 258 | num_failures_ = 0; |
| 259 | latest_outputs_.clear(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 260 | latest_failed_state_ = MULTIPLE_DISPLAY_STATE_INVALID; |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 261 | } |
| 262 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 263 | // DisplayConfigurator::Observer overrides: |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 264 | virtual void OnDisplayModeChanged( |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 265 | const DisplayConfigurator::DisplayStateList& outputs) OVERRIDE { |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 266 | num_changes_++; |
| 267 | latest_outputs_ = outputs; |
| 268 | } |
| 269 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 270 | virtual void OnDisplayModeChangeFailed(MultipleDisplayState failed_new_state) |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 271 | OVERRIDE { |
| 272 | num_failures_++; |
| 273 | latest_failed_state_ = failed_new_state; |
| 274 | } |
| 275 | |
| 276 | private: |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 277 | DisplayConfigurator* configurator_; // Not owned. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 278 | |
| 279 | // Number of times that OnDisplayMode*() has been called. |
| 280 | int num_changes_; |
| 281 | int num_failures_; |
| 282 | |
| 283 | // Parameters most recently passed to OnDisplayMode*(). |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 284 | DisplayConfigurator::DisplayStateList latest_outputs_; |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 285 | MultipleDisplayState latest_failed_state_; |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 286 | |
| 287 | DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 288 | }; |
| 289 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 290 | class TestStateController : public DisplayConfigurator::StateController { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 291 | public: |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 292 | TestStateController() : state_(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) {} |
[email protected] | 4209190 | 2013-05-02 02:24:12 | [diff] [blame] | 293 | virtual ~TestStateController() {} |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 294 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 295 | void set_state(MultipleDisplayState state) { state_ = state; } |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 296 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 297 | // DisplayConfigurator::StateController overrides: |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 298 | virtual MultipleDisplayState GetStateForDisplayIds( |
[email protected] | 08b47ca | 2014-03-28 13:46:20 | [diff] [blame] | 299 | const std::vector<int64_t>& outputs) const OVERRIDE { |
[email protected] | c9750510 | 2014-02-12 14:50:26 | [diff] [blame] | 300 | return state_; |
| 301 | } |
[email protected] | 08b47ca | 2014-03-28 13:46:20 | [diff] [blame] | 302 | virtual bool GetResolutionForDisplayId(int64_t display_id, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 303 | gfx::Size* size) const OVERRIDE { |
[email protected] | a5792d3 | 2013-08-01 11:18:21 | [diff] [blame] | 304 | return false; |
| 305 | } |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 306 | |
| 307 | private: |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 308 | MultipleDisplayState state_; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 309 | |
| 310 | DISALLOW_COPY_AND_ASSIGN(TestStateController); |
| 311 | }; |
| 312 | |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 313 | class TestMirroringController |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 314 | : public DisplayConfigurator::SoftwareMirroringController { |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 315 | public: |
| 316 | TestMirroringController() : software_mirroring_enabled_(false) {} |
| 317 | virtual ~TestMirroringController() {} |
| 318 | |
| 319 | virtual void SetSoftwareMirroring(bool enabled) OVERRIDE { |
| 320 | software_mirroring_enabled_ = enabled; |
| 321 | } |
| 322 | |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 323 | virtual bool SoftwareMirroringEnabled() const OVERRIDE { |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 324 | return software_mirroring_enabled_; |
| 325 | } |
| 326 | |
| 327 | private: |
| 328 | bool software_mirroring_enabled_; |
| 329 | |
| 330 | DISALLOW_COPY_AND_ASSIGN(TestMirroringController); |
| 331 | }; |
| 332 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 333 | class DisplayConfiguratorTest : public testing::Test { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 334 | public: |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 335 | DisplayConfiguratorTest() |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 336 | : small_mode_(gfx::Size(1366, 768), false, 60.0f), |
| 337 | big_mode_(gfx::Size(2560, 1600), false, 60.0f), |
| 338 | observer_(&configurator_), |
| 339 | test_api_(&configurator_) {} |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 340 | virtual ~DisplayConfiguratorTest() {} |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 341 | |
| 342 | virtual void SetUp() OVERRIDE { |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 343 | log_.reset(new ActionLogger()); |
| 344 | |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 345 | native_display_delegate_ = new TestNativeDisplayDelegate(log_.get()); |
dnicoara | 6754802 | 2014-09-12 19:05:21 | [diff] [blame] | 346 | configurator_.SetDelegateForTesting( |
| 347 | scoped_ptr<NativeDisplayDelegate>(native_display_delegate_)); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 348 | |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 349 | configurator_.set_state_controller(&state_controller_); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 350 | configurator_.set_mirroring_controller(&mirroring_controller_); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 351 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 352 | std::vector<const DisplayMode*> modes; |
| 353 | modes.push_back(&small_mode_); |
[email protected] | 5d99ee6 | 2013-08-16 19:56:47 | [diff] [blame] | 354 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 355 | TestDisplaySnapshot* o = &outputs_[0]; |
| 356 | o->set_current_mode(&small_mode_); |
| 357 | o->set_native_mode(&small_mode_); |
| 358 | o->set_modes(modes); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 359 | o->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 360 | o->set_is_aspect_preserving_scaling(true); |
| 361 | o->set_display_id(123); |
| 362 | o->set_has_proper_display_id(true); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 363 | |
| 364 | o = &outputs_[1]; |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 365 | o->set_current_mode(&big_mode_); |
| 366 | o->set_native_mode(&big_mode_); |
| 367 | modes.push_back(&big_mode_); |
| 368 | o->set_modes(modes); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 369 | o->set_type(DISPLAY_CONNECTION_TYPE_HDMI); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 370 | o->set_is_aspect_preserving_scaling(true); |
| 371 | o->set_display_id(456); |
| 372 | o->set_has_proper_display_id(true); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 373 | |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 374 | UpdateOutputs(2, false); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 377 | // Predefined modes that can be used by outputs. |
| 378 | const DisplayMode small_mode_; |
| 379 | const DisplayMode big_mode_; |
| 380 | |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 381 | protected: |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 382 | // Configures |native_display_delegate_| to return the first |num_outputs| |
| 383 | // entries from |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 384 | // |outputs_|. If |send_events| is true, also sends screen-change and |
| 385 | // output-change events to |configurator_| and triggers the configure |
| 386 | // timeout if one was scheduled. |
| 387 | void UpdateOutputs(size_t num_outputs, bool send_events) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 388 | ASSERT_LE(num_outputs, arraysize(outputs_)); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 389 | std::vector<DisplaySnapshot*> outputs; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 390 | for (size_t i = 0; i < num_outputs; ++i) |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 391 | outputs.push_back(&outputs_[i]); |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 392 | native_display_delegate_->set_outputs(outputs); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 393 | |
| 394 | if (send_events) { |
[email protected] | 3d1cd60 | 2014-02-26 23:39:18 | [diff] [blame] | 395 | configurator_.OnConfigurationChanged(); |
[email protected] | e6a5824e | 2014-08-13 14:53:41 | [diff] [blame] | 396 | EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 397 | } |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // Initializes |configurator_| with a single internal display. |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 401 | void InitWithSingleOutput() { |
| 402 | UpdateOutputs(1, false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 403 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | d30dac8 | 2013-07-31 16:17:30 | [diff] [blame] | 404 | configurator_.Init(false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 405 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 406 | configurator_.ForceInitialConfigure(0); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 407 | EXPECT_EQ( |
| 408 | JoinActions( |
| 409 | kGrab, |
| 410 | kInitXRandR, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 411 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 412 | .c_str(), |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 413 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 414 | kForceDPMS, |
| 415 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 416 | NULL), |
| 417 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | base::MessageLoop message_loop_; |
| 421 | TestStateController state_controller_; |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 422 | TestMirroringController mirroring_controller_; |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 423 | DisplayConfigurator configurator_; |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 424 | TestObserver observer_; |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 425 | scoped_ptr<ActionLogger> log_; |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 426 | TestNativeDisplayDelegate* native_display_delegate_; // not owned |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 427 | DisplayConfigurator::TestApi test_api_; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 428 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 429 | TestDisplaySnapshot outputs_[2]; |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 430 | |
| 431 | private: |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 432 | DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | } // namespace |
[email protected] | 6d980bc | 2012-09-10 19:28:45 | [diff] [blame] | 436 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 437 | TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 438 | ScopedVector<const DisplayMode> modes; |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 439 | |
| 440 | // Fields are width, height, interlaced, refresh rate. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 441 | modes.push_back(new DisplayMode(gfx::Size(1920, 1200), false, 60.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 442 | // Different rates. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 443 | modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 30.0)); |
| 444 | modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 50.0)); |
| 445 | modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 40.0)); |
| 446 | modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 0.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 447 | // Interlaced vs non-interlaced. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 448 | modes.push_back(new DisplayMode(gfx::Size(1280, 720), true, 60.0)); |
| 449 | modes.push_back(new DisplayMode(gfx::Size(1280, 720), false, 40.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 450 | // Interlaced only. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 451 | modes.push_back(new DisplayMode(gfx::Size(1024, 768), true, 0.0)); |
| 452 | modes.push_back(new DisplayMode(gfx::Size(1024, 768), true, 40.0)); |
| 453 | modes.push_back(new DisplayMode(gfx::Size(1024, 768), true, 60.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 454 | // Mixed. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 455 | modes.push_back(new DisplayMode(gfx::Size(1024, 600), true, 60.0)); |
| 456 | modes.push_back(new DisplayMode(gfx::Size(1024, 600), false, 40.0)); |
| 457 | modes.push_back(new DisplayMode(gfx::Size(1024, 600), false, 50.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 458 | // Just one interlaced mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 459 | modes.push_back(new DisplayMode(gfx::Size(640, 480), true, 60.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 460 | // Refresh rate not available. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 461 | modes.push_back(new DisplayMode(gfx::Size(320, 200), false, 0.0)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 462 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 463 | TestDisplaySnapshot output; |
| 464 | output.set_modes(modes.get()); |
| 465 | |
| 466 | EXPECT_EQ(modes[0], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 467 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 468 | output, gfx::Size(1920, 1200))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 469 | |
| 470 | // Should pick highest refresh rate. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 471 | EXPECT_EQ(modes[2], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 472 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 473 | output, gfx::Size(1920, 1080))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 474 | |
| 475 | // Should pick non-interlaced mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 476 | EXPECT_EQ(modes[6], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 477 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 478 | output, gfx::Size(1280, 720))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 479 | |
| 480 | // Interlaced only. Should pick one with the highest refresh rate in |
| 481 | // interlaced mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 482 | EXPECT_EQ(modes[9], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 483 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 484 | output, gfx::Size(1024, 768))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 485 | |
| 486 | // Mixed: Should pick one with the highest refresh rate in |
| 487 | // interlaced mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 488 | EXPECT_EQ(modes[12], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 489 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 490 | output, gfx::Size(1024, 600))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 491 | |
| 492 | // Just one interlaced mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 493 | EXPECT_EQ(modes[13], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 494 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 495 | output, gfx::Size(640, 480))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 496 | |
| 497 | // Refresh rate not available. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 498 | EXPECT_EQ(modes[14], |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 499 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 500 | output, gfx::Size(320, 200))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 501 | |
| 502 | // No mode found. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 503 | EXPECT_EQ(NULL, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 504 | DisplayConfigurator::FindDisplayModeMatchingSize( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 505 | output, gfx::Size(1440, 900))); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 506 | } |
| 507 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 508 | TEST_F(DisplayConfiguratorTest, ConnectSecondOutput) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 509 | InitWithSingleOutput(); |
| 510 | |
| 511 | // Connect a second output and check that the configurator enters |
| 512 | // extended mode. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 513 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 514 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 515 | UpdateOutputs(2, true); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 516 | const int kDualHeight = small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 517 | DisplayConfigurator::kVerticalGap + |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 518 | big_mode_.size().height(); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 519 | EXPECT_EQ( |
| 520 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 521 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 522 | GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 523 | &outputs_[0], |
| 524 | &outputs_[1]).c_str(), |
| 525 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 526 | GetCrtcAction(outputs_[1], |
| 527 | &big_mode_, |
| 528 | gfx::Point(0, |
| 529 | small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 530 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 531 | .c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 532 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 533 | NULL), |
| 534 | log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 535 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 536 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 537 | |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 538 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 539 | EXPECT_TRUE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 540 | EXPECT_EQ( |
| 541 | JoinActions( |
| 542 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 543 | GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 544 | .c_str(), |
| 545 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 546 | GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 547 | kUngrab, |
| 548 | NULL), |
| 549 | log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 550 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 551 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 552 | |
| 553 | // Disconnect the second output. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 554 | observer_.Reset(); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 555 | UpdateOutputs(1, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 556 | EXPECT_EQ( |
| 557 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 558 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 559 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 560 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 561 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 562 | NULL), |
| 563 | log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 564 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 565 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 566 | |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 567 | // Get rid of shared modes to force software mirroring. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 568 | outputs_[1].set_modes(std::vector<const DisplayMode*>(1, &big_mode_)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 569 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 570 | UpdateOutputs(2, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 571 | EXPECT_EQ( |
| 572 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 573 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 574 | GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 575 | &outputs_[0], |
| 576 | &outputs_[1]).c_str(), |
| 577 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 578 | GetCrtcAction(outputs_[1], |
| 579 | &big_mode_, |
| 580 | gfx::Point(0, |
| 581 | small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 582 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 583 | .c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 584 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 585 | NULL), |
| 586 | log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 587 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 588 | |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 589 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 590 | EXPECT_TRUE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 591 | EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 592 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 593 | configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 594 | EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 595 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 596 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 597 | // Setting MULTIPLE_DISPLAY_STATE_DUAL_MIRROR should try to reconfigure. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 598 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 599 | EXPECT_TRUE( |
| 600 | configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED)); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 601 | EXPECT_EQ(JoinActions(NULL), log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 602 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 603 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | 57bed4d | 2013-06-08 20:54:18 | [diff] [blame] | 604 | |
| 605 | // Set back to software mirror mode. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 606 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 607 | EXPECT_TRUE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 608 | EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 609 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 610 | configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 611 | EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 612 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | 57bed4d | 2013-06-08 20:54:18 | [diff] [blame] | 613 | |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 614 | // Disconnect the second output. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 615 | observer_.Reset(); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 616 | UpdateOutputs(1, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 617 | EXPECT_EQ( |
| 618 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 619 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 620 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 621 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 622 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 623 | NULL), |
| 624 | log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 625 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 626 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 629 | TEST_F(DisplayConfiguratorTest, SetDisplayPower) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 630 | InitWithSingleOutput(); |
| 631 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 632 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 633 | observer_.Reset(); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 634 | UpdateOutputs(2, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 635 | EXPECT_EQ( |
| 636 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 637 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 638 | GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 639 | .c_str(), |
| 640 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 641 | GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 642 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 643 | NULL), |
| 644 | log_->GetActionsAndClear()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 645 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 646 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 647 | |
| 648 | // Turning off the internal display should switch the external display to |
| 649 | // its native mode. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 650 | observer_.Reset(); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 651 | configurator_.SetDisplayPower( |
| 652 | chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 653 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 654 | EXPECT_EQ( |
| 655 | JoinActions( |
| 656 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 657 | GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 658 | .c_str(), |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 659 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 660 | GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 661 | kForceDPMS, |
| 662 | kUngrab, |
| 663 | NULL), |
| 664 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 665 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 666 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 667 | |
| 668 | // When all displays are turned off, the framebuffer should switch back |
| 669 | // to the mirrored size. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 670 | observer_.Reset(); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 671 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 672 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 673 | EXPECT_EQ( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 674 | JoinActions(kGrab, |
| 675 | GetFramebufferAction( |
| 676 | small_mode_.size(), &outputs_[0], &outputs_[1]).c_str(), |
| 677 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 678 | GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), |
| 679 | kUngrab, |
| 680 | NULL), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 681 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 682 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 683 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 684 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 685 | |
| 686 | // Turn all displays on and check that mirroring is still used. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 687 | observer_.Reset(); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 688 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 689 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 690 | EXPECT_EQ( |
| 691 | JoinActions( |
| 692 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 693 | GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 694 | .c_str(), |
| 695 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 696 | GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 697 | kForceDPMS, |
| 698 | kUngrab, |
| 699 | NULL), |
| 700 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 701 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 702 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 703 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 704 | |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 705 | // Get rid of shared modes to force software mirroring. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 706 | outputs_[1].set_modes(std::vector<const DisplayMode*>(1, &big_mode_)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 707 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 708 | observer_.Reset(); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 709 | UpdateOutputs(2, true); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 710 | const int kDualHeight = small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 711 | DisplayConfigurator::kVerticalGap + |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 712 | big_mode_.size().height(); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 713 | EXPECT_EQ( |
| 714 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 715 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 716 | GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 717 | &outputs_[0], |
| 718 | &outputs_[1]).c_str(), |
| 719 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 720 | GetCrtcAction(outputs_[1], |
| 721 | &big_mode_, |
| 722 | gfx::Point(0, |
| 723 | small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 724 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 725 | .c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 726 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 727 | NULL), |
| 728 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 729 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 730 | configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 731 | EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 732 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 733 | |
| 734 | // Turning off the internal display should switch the external display to |
| 735 | // its native mode. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 736 | observer_.Reset(); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 737 | configurator_.SetDisplayPower( |
| 738 | chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 739 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 740 | EXPECT_EQ( |
| 741 | JoinActions( |
| 742 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 743 | GetFramebufferAction(big_mode_.size(), &outputs_[0], &outputs_[1]) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 744 | .c_str(), |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 745 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 746 | GetCrtcAction(outputs_[1], &big_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 747 | kForceDPMS, |
| 748 | kUngrab, |
| 749 | NULL), |
| 750 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 751 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 752 | EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 753 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 754 | |
| 755 | // When all displays are turned off, the framebuffer should switch back |
| 756 | // to the extended + software mirroring. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 757 | observer_.Reset(); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 758 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 759 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 760 | EXPECT_EQ( |
| 761 | JoinActions( |
| 762 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 763 | GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 764 | &outputs_[0], |
| 765 | &outputs_[1]).c_str(), |
| 766 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 767 | GetCrtcAction(outputs_[1], |
| 768 | NULL, |
| 769 | gfx::Point(0, |
| 770 | small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 771 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 772 | .c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 773 | kUngrab, |
| 774 | NULL), |
| 775 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 776 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 777 | configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 778 | EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 779 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | c1f30dc | 2013-05-22 17:27:45 | [diff] [blame] | 780 | |
| 781 | // Turn all displays on and check that mirroring is still used. |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 782 | observer_.Reset(); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 783 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 784 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 785 | EXPECT_EQ( |
| 786 | JoinActions( |
| 787 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 788 | GetFramebufferAction(gfx::Size(big_mode_.size().width(), kDualHeight), |
| 789 | &outputs_[0], |
| 790 | &outputs_[1]).c_str(), |
| 791 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 792 | GetCrtcAction(outputs_[1], |
| 793 | &big_mode_, |
| 794 | gfx::Point(0, |
| 795 | small_mode_.size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 796 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 797 | .c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 798 | kForceDPMS, |
| 799 | kUngrab, |
| 800 | NULL), |
| 801 | log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 802 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 803 | configurator_.display_state()); |
[email protected] | 857f47c | 2014-05-17 18:21:06 | [diff] [blame] | 804 | EXPECT_TRUE(mirroring_controller_.SoftwareMirroringEnabled()); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 805 | EXPECT_EQ(1, observer_.num_changes()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 806 | } |
| 807 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 808 | TEST_F(DisplayConfiguratorTest, SuspendAndResume) { |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 809 | InitWithSingleOutput(); |
| 810 | |
| 811 | // No preparation is needed before suspending when the display is already |
| 812 | // on. The configurator should still reprobe on resume in case a display |
| 813 | // was connected while suspended. |
| 814 | configurator_.SuspendDisplays(); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 815 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 816 | configurator_.ResumeDisplays(); |
[email protected] | e6a5824e | 2014-08-13 14:53:41 | [diff] [blame] | 817 | EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 818 | EXPECT_EQ( |
| 819 | JoinActions( |
| 820 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 821 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 822 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 823 | kForceDPMS, |
| 824 | kUngrab, |
| 825 | NULL), |
| 826 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 827 | |
| 828 | // Now turn the display off before suspending and check that the |
| 829 | // configurator turns it back on and syncs with the server. |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 830 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 831 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 832 | EXPECT_EQ( |
| 833 | JoinActions( |
| 834 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 835 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 836 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 837 | kUngrab, |
| 838 | NULL), |
| 839 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 840 | |
| 841 | configurator_.SuspendDisplays(); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 842 | EXPECT_EQ( |
| 843 | JoinActions( |
| 844 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 845 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 846 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 847 | kForceDPMS, |
| 848 | kUngrab, |
| 849 | kSync, |
| 850 | NULL), |
| 851 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 852 | |
| 853 | configurator_.ResumeDisplays(); |
[email protected] | e6a5824e | 2014-08-13 14:53:41 | [diff] [blame] | 854 | EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 855 | EXPECT_EQ( |
| 856 | JoinActions( |
| 857 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 858 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 859 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 860 | kForceDPMS, |
| 861 | kUngrab, |
| 862 | NULL), |
| 863 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 864 | |
| 865 | // If a second, external display is connected, the displays shouldn't be |
| 866 | // powered back on before suspending. |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 867 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 868 | UpdateOutputs(2, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 869 | EXPECT_EQ( |
| 870 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 871 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 872 | GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 873 | .c_str(), |
| 874 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 875 | GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 876 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 877 | NULL), |
| 878 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 879 | |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 880 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 881 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 882 | EXPECT_EQ( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 883 | JoinActions(kGrab, |
| 884 | GetFramebufferAction( |
| 885 | small_mode_.size(), &outputs_[0], &outputs_[1]).c_str(), |
| 886 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
| 887 | GetCrtcAction(outputs_[1], NULL, gfx::Point(0, 0)).c_str(), |
| 888 | kUngrab, |
| 889 | NULL), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 890 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 891 | |
| 892 | configurator_.SuspendDisplays(); |
| 893 | EXPECT_EQ(JoinActions(kGrab, kUngrab, kSync, NULL), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 894 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 895 | |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 896 | // If a display is disconnected while suspended, the configurator should |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 897 | // pick up the change. |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 898 | UpdateOutputs(1, false); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 899 | configurator_.ResumeDisplays(); |
[email protected] | e6a5824e | 2014-08-13 14:53:41 | [diff] [blame] | 900 | EXPECT_TRUE(test_api_.TriggerConfigureTimeout()); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 901 | EXPECT_EQ( |
| 902 | JoinActions( |
| 903 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 904 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 905 | GetCrtcAction(outputs_[0], NULL, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 906 | kUngrab, |
| 907 | NULL), |
| 908 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 909 | } |
| 910 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 911 | TEST_F(DisplayConfiguratorTest, Headless) { |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 912 | UpdateOutputs(0, false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 913 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | d30dac8 | 2013-07-31 16:17:30 | [diff] [blame] | 914 | configurator_.Init(false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 915 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 916 | configurator_.ForceInitialConfigure(0); |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 917 | EXPECT_EQ(JoinActions(kGrab, kInitXRandR, kForceDPMS, kUngrab, NULL), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 918 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 919 | |
| 920 | // Not much should happen when the display power state is changed while |
| 921 | // no displays are connected. |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 922 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_OFF, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 923 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 924 | EXPECT_EQ(JoinActions(kGrab, kUngrab, NULL), log_->GetActionsAndClear()); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 925 | configurator_.SetDisplayPower(chromeos::DISPLAY_POWER_ALL_ON, |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 926 | DisplayConfigurator::kSetDisplayPowerNoFlags); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 927 | EXPECT_EQ(JoinActions(kGrab, kForceDPMS, kUngrab, NULL), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 928 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 929 | |
| 930 | // Connect an external display and check that it's configured correctly. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 931 | outputs_[0].set_current_mode(outputs_[1].current_mode()); |
| 932 | outputs_[0].set_native_mode(outputs_[1].native_mode()); |
| 933 | outputs_[0].set_modes(outputs_[1].modes()); |
| 934 | outputs_[0].set_type(outputs_[1].type()); |
| 935 | |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 936 | UpdateOutputs(1, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 937 | EXPECT_EQ( |
| 938 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 939 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 940 | GetFramebufferAction(big_mode_.size(), &outputs_[0], NULL).c_str(), |
| 941 | GetCrtcAction(outputs_[0], &big_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 942 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 943 | NULL), |
| 944 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 945 | } |
| 946 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 947 | TEST_F(DisplayConfiguratorTest, StartWithTwoOutputs) { |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 948 | UpdateOutputs(2, false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 949 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | d30dac8 | 2013-07-31 16:17:30 | [diff] [blame] | 950 | configurator_.Init(false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 951 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 952 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 953 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 954 | configurator_.ForceInitialConfigure(0); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 955 | EXPECT_EQ( |
| 956 | JoinActions( |
| 957 | kGrab, |
| 958 | kInitXRandR, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 959 | GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 960 | .c_str(), |
| 961 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 962 | GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 963 | kForceDPMS, |
| 964 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 965 | NULL), |
| 966 | log_->GetActionsAndClear()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 967 | } |
| 968 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 969 | TEST_F(DisplayConfiguratorTest, InvalidMultipleDisplayStates) { |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 970 | UpdateOutputs(0, false); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 971 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | d30dac8 | 2013-07-31 16:17:30 | [diff] [blame] | 972 | configurator_.Init(false); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 973 | configurator_.ForceInitialConfigure(0); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 974 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 975 | EXPECT_TRUE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_HEADLESS)); |
| 976 | EXPECT_FALSE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_SINGLE)); |
| 977 | EXPECT_FALSE( |
| 978 | configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)); |
| 979 | EXPECT_FALSE( |
| 980 | configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED)); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 981 | EXPECT_EQ(1, observer_.num_changes()); |
| 982 | EXPECT_EQ(3, observer_.num_failures()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 983 | |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 984 | UpdateOutputs(1, true); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 985 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 986 | EXPECT_FALSE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_HEADLESS)); |
| 987 | EXPECT_TRUE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_SINGLE)); |
| 988 | EXPECT_FALSE( |
| 989 | configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)); |
| 990 | EXPECT_FALSE( |
| 991 | configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED)); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 992 | EXPECT_EQ(1, observer_.num_changes()); |
| 993 | EXPECT_EQ(3, observer_.num_failures()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 994 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 995 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 996 | UpdateOutputs(2, true); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 997 | observer_.Reset(); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 998 | EXPECT_FALSE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_HEADLESS)); |
| 999 | EXPECT_FALSE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_SINGLE)); |
| 1000 | EXPECT_TRUE(configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)); |
| 1001 | EXPECT_TRUE( |
| 1002 | configurator_.SetDisplayMode(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED)); |
[email protected] | 0b1b283b | 2013-08-17 13:32:18 | [diff] [blame] | 1003 | EXPECT_EQ(2, observer_.num_changes()); |
| 1004 | EXPECT_EQ(2, observer_.num_failures()); |
[email protected] | acb217ed | 2013-04-09 21:52:36 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1007 | TEST_F(DisplayConfiguratorTest, GetMultipleDisplayStateForDisplaysWithoutId) { |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1008 | outputs_[0].set_has_proper_display_id(false); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 1009 | UpdateOutputs(2, false); |
[email protected] | d30dac8 | 2013-07-31 16:17:30 | [diff] [blame] | 1010 | configurator_.Init(false); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1011 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 1012 | configurator_.ForceInitialConfigure(0); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1013 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 1014 | configurator_.display_state()); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 1015 | } |
[email protected] | 2c8a0aa7 | 2013-05-16 06:24:48 | [diff] [blame] | 1016 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1017 | TEST_F(DisplayConfiguratorTest, GetMultipleDisplayStateForDisplaysWithId) { |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1018 | outputs_[0].set_has_proper_display_id(true); |
[email protected] | edc1c80 | 2013-08-14 03:55:04 | [diff] [blame] | 1019 | UpdateOutputs(2, false); |
| 1020 | configurator_.Init(false); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1021 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 1022 | configurator_.ForceInitialConfigure(0); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1023 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); |
[email protected] | 2c8a0aa7 | 2013-05-16 06:24:48 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1026 | TEST_F(DisplayConfiguratorTest, UpdateCachedOutputsEvenAfterFailure) { |
[email protected] | 3d1df54 | 2013-09-24 04:26:22 | [diff] [blame] | 1027 | InitWithSingleOutput(); |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1028 | const DisplayConfigurator::DisplayStateList* cached = |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1029 | &configurator_.cached_displays(); |
[email protected] | 3d1df54 | 2013-09-24 04:26:22 | [diff] [blame] | 1030 | ASSERT_EQ(static_cast<size_t>(1), cached->size()); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1031 | EXPECT_EQ(outputs_[0].current_mode(), (*cached)[0].display->current_mode()); |
[email protected] | 3d1df54 | 2013-09-24 04:26:22 | [diff] [blame] | 1032 | |
| 1033 | // After connecting a second output, check that it shows up in |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1034 | // |cached_displays_| even if an invalid state is requested. |
| 1035 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); |
[email protected] | 3d1df54 | 2013-09-24 04:26:22 | [diff] [blame] | 1036 | UpdateOutputs(2, true); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1037 | cached = &configurator_.cached_displays(); |
[email protected] | 3d1df54 | 2013-09-24 04:26:22 | [diff] [blame] | 1038 | ASSERT_EQ(static_cast<size_t>(2), cached->size()); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1039 | EXPECT_EQ(outputs_[0].current_mode(), (*cached)[0].display->current_mode()); |
| 1040 | EXPECT_EQ(outputs_[1].current_mode(), (*cached)[1].display->current_mode()); |
[email protected] | 3d1df54 | 2013-09-24 04:26:22 | [diff] [blame] | 1041 | } |
| 1042 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1043 | TEST_F(DisplayConfiguratorTest, PanelFitting) { |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1044 | // Configure the internal display to support only the big mode and the |
| 1045 | // external display to support only the small mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1046 | outputs_[0].set_current_mode(&big_mode_); |
| 1047 | outputs_[0].set_native_mode(&big_mode_); |
| 1048 | outputs_[0].set_modes(std::vector<const DisplayMode*>(1, &big_mode_)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1049 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1050 | outputs_[1].set_current_mode(&small_mode_); |
| 1051 | outputs_[1].set_native_mode(&small_mode_); |
| 1052 | outputs_[1].set_modes(std::vector<const DisplayMode*>(1, &small_mode_)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1053 | |
| 1054 | // The small mode should be added to the internal output when requesting |
| 1055 | // mirrored mode. |
| 1056 | UpdateOutputs(2, false); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1057 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1058 | configurator_.Init(true /* is_panel_fitting_enabled */); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 1059 | configurator_.ForceInitialConfigure(0); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1060 | EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1061 | EXPECT_EQ( |
| 1062 | JoinActions( |
| 1063 | kGrab, |
| 1064 | kInitXRandR, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1065 | GetAddOutputModeAction(outputs_[0], &small_mode_).c_str(), |
| 1066 | GetFramebufferAction(small_mode_.size(), &outputs_[0], &outputs_[1]) |
| 1067 | .c_str(), |
| 1068 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1069 | GetCrtcAction(outputs_[1], &small_mode_, gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1070 | kForceDPMS, |
| 1071 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1072 | NULL), |
| 1073 | log_->GetActionsAndClear()); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1074 | |
| 1075 | // Both outputs should be using the small mode. |
| 1076 | ASSERT_EQ(1, observer_.num_changes()); |
| 1077 | ASSERT_EQ(static_cast<size_t>(2), observer_.latest_outputs().size()); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1078 | EXPECT_EQ(&small_mode_, observer_.latest_outputs()[0].mirror_mode); |
| 1079 | EXPECT_EQ(&small_mode_, |
| 1080 | observer_.latest_outputs()[0].display->current_mode()); |
| 1081 | EXPECT_EQ(&small_mode_, observer_.latest_outputs()[1].mirror_mode); |
| 1082 | EXPECT_EQ(&small_mode_, |
| 1083 | observer_.latest_outputs()[1].display->current_mode()); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1084 | |
| 1085 | // Also check that the newly-added small mode is present in the internal |
| 1086 | // snapshot that was passed to the observer (http://crbug.com/289159). |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1087 | const DisplayConfigurator::DisplayState& state = |
| 1088 | observer_.latest_outputs()[0]; |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1089 | ASSERT_NE(state.display->modes().end(), |
| 1090 | std::find(state.display->modes().begin(), |
| 1091 | state.display->modes().end(), |
| 1092 | &small_mode_)); |
[email protected] | 6eebb90b | 2013-09-17 18:30:27 | [diff] [blame] | 1093 | } |
| 1094 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1095 | TEST_F(DisplayConfiguratorTest, ContentProtection) { |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1096 | configurator_.Init(false); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 1097 | configurator_.ForceInitialConfigure(0); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1098 | EXPECT_NE(kNoActions, log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1099 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1100 | DisplayConfigurator::ContentProtectionClientId id = |
| 1101 | configurator_.RegisterContentProtectionClient(); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1102 | EXPECT_NE(0u, id); |
| 1103 | |
| 1104 | // One output. |
| 1105 | UpdateOutputs(1, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1106 | EXPECT_NE(kNoActions, log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1107 | uint32_t link_mask = 0; |
| 1108 | uint32_t protection_mask = 0; |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1109 | EXPECT_TRUE(configurator_.QueryContentProtectionStatus( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1110 | id, outputs_[0].display_id(), &link_mask, &protection_mask)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1111 | EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_INTERNAL), link_mask); |
| 1112 | EXPECT_EQ(static_cast<uint32_t>(CONTENT_PROTECTION_METHOD_NONE), |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1113 | protection_mask); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1114 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1115 | |
| 1116 | // Two outputs. |
| 1117 | UpdateOutputs(2, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1118 | EXPECT_NE(kNoActions, log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1119 | EXPECT_TRUE(configurator_.QueryContentProtectionStatus( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1120 | id, outputs_[1].display_id(), &link_mask, &protection_mask)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1121 | EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_HDMI), link_mask); |
| 1122 | EXPECT_EQ(static_cast<uint32_t>(CONTENT_PROTECTION_METHOD_NONE), |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1123 | protection_mask); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1124 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1125 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1126 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1127 | id, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_HDCP)); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1128 | EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_DESIRED), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1129 | log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1130 | |
| 1131 | // Enable protection. |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 1132 | native_display_delegate_->set_hdcp_state(HDCP_STATE_ENABLED); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1133 | EXPECT_TRUE(configurator_.QueryContentProtectionStatus( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1134 | id, outputs_[1].display_id(), &link_mask, &protection_mask)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1135 | EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_HDMI), link_mask); |
| 1136 | EXPECT_EQ(static_cast<uint32_t>(CONTENT_PROTECTION_METHOD_HDCP), |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1137 | protection_mask); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1138 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | 67e6a68 | 2013-10-31 10:00:41 | [diff] [blame] | 1139 | |
| 1140 | // Protections should be disabled after unregister. |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1141 | configurator_.UnregisterContentProtectionClient(id); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1142 | EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_UNDESIRED), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1143 | log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1144 | } |
| 1145 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1146 | TEST_F(DisplayConfiguratorTest, ContentProtectionTwoClients) { |
| 1147 | DisplayConfigurator::ContentProtectionClientId client1 = |
| 1148 | configurator_.RegisterContentProtectionClient(); |
| 1149 | DisplayConfigurator::ContentProtectionClientId client2 = |
| 1150 | configurator_.RegisterContentProtectionClient(); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1151 | EXPECT_NE(client1, client2); |
| 1152 | |
| 1153 | configurator_.Init(false); |
[email protected] | 806f954 | 2014-02-28 18:35:55 | [diff] [blame] | 1154 | configurator_.ForceInitialConfigure(0); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1155 | UpdateOutputs(2, true); |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1156 | EXPECT_NE(kNoActions, log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1157 | |
| 1158 | // Clients never know state enableness for methods that they didn't request. |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1159 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1160 | client1, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_HDCP)); |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1161 | EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_DESIRED).c_str(), |
| 1162 | log_->GetActionsAndClear()); |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 1163 | native_display_delegate_->set_hdcp_state(HDCP_STATE_ENABLED); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1164 | |
| 1165 | uint32_t link_mask = 0; |
| 1166 | uint32_t protection_mask = 0; |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1167 | EXPECT_TRUE(configurator_.QueryContentProtectionStatus( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1168 | client1, outputs_[1].display_id(), &link_mask, &protection_mask)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1169 | EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_HDMI), link_mask); |
| 1170 | EXPECT_EQ(CONTENT_PROTECTION_METHOD_HDCP, protection_mask); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1171 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1172 | EXPECT_TRUE(configurator_.QueryContentProtectionStatus( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1173 | client2, outputs_[1].display_id(), &link_mask, &protection_mask)); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1174 | EXPECT_EQ(static_cast<uint32_t>(DISPLAY_CONNECTION_TYPE_HDMI), link_mask); |
| 1175 | EXPECT_EQ(CONTENT_PROTECTION_METHOD_NONE, protection_mask); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1176 | |
| 1177 | // Protections will be disabled only if no more clients request them. |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1178 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1179 | client2, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_NONE)); |
kcwu | 7bf0d74 | 2014-09-24 15:39:47 | [diff] [blame] | 1180 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1181 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1182 | client1, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_NONE)); |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1183 | EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_UNDESIRED).c_str(), |
| 1184 | log_->GetActionsAndClear()); |
[email protected] | a931884 | 2013-10-02 07:21:13 | [diff] [blame] | 1185 | } |
| 1186 | |
kcwu | 7bf0d74 | 2014-09-24 15:39:47 | [diff] [blame] | 1187 | TEST_F(DisplayConfiguratorTest, ContentProtectionTwoClientsEnable) { |
| 1188 | DisplayConfigurator::ContentProtectionClientId client1 = |
| 1189 | configurator_.RegisterContentProtectionClient(); |
| 1190 | DisplayConfigurator::ContentProtectionClientId client2 = |
| 1191 | configurator_.RegisterContentProtectionClient(); |
| 1192 | EXPECT_NE(client1, client2); |
| 1193 | |
| 1194 | configurator_.Init(false); |
| 1195 | configurator_.ForceInitialConfigure(0); |
| 1196 | UpdateOutputs(2, true); |
| 1197 | log_->GetActionsAndClear(); |
| 1198 | |
| 1199 | // Only enable once if HDCP is enabling. |
| 1200 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1201 | client1, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_HDCP)); |
| 1202 | native_display_delegate_->set_hdcp_state(HDCP_STATE_DESIRED); |
| 1203 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1204 | client2, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_HDCP)); |
| 1205 | EXPECT_EQ(GetSetHDCPStateAction(outputs_[1], HDCP_STATE_DESIRED).c_str(), |
| 1206 | log_->GetActionsAndClear()); |
| 1207 | native_display_delegate_->set_hdcp_state(HDCP_STATE_ENABLED); |
| 1208 | |
| 1209 | // Don't enable again if HDCP is already active. |
| 1210 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1211 | client1, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_HDCP)); |
| 1212 | EXPECT_TRUE(configurator_.EnableContentProtection( |
| 1213 | client2, outputs_[1].display_id(), CONTENT_PROTECTION_METHOD_HDCP)); |
| 1214 | EXPECT_EQ(kNoActions, log_->GetActionsAndClear()); |
| 1215 | } |
| 1216 | |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1217 | TEST_F(DisplayConfiguratorTest, HandleConfigureCrtcFailure) { |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1218 | InitWithSingleOutput(); |
| 1219 | |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1220 | ScopedVector<const DisplayMode> modes; |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1221 | // The first mode is the mode we are requesting DisplayConfigurator to choose. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1222 | // The test will be setup so that this mode will fail and it will have to |
| 1223 | // choose the next best option. |
| 1224 | modes.push_back(new DisplayMode(gfx::Size(2560, 1600), false, 60.0)); |
| 1225 | modes.push_back(new DisplayMode(gfx::Size(1024, 768), false, 60.0)); |
| 1226 | modes.push_back(new DisplayMode(gfx::Size(1280, 720), false, 60.0)); |
| 1227 | modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 60.0)); |
| 1228 | modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 40.0)); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1229 | |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1230 | for (unsigned int i = 0; i < arraysize(outputs_); i++) { |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1231 | outputs_[i].set_modes(modes.get()); |
| 1232 | outputs_[i].set_current_mode(modes[0]); |
| 1233 | outputs_[i].set_native_mode(modes[0]); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1234 | } |
| 1235 | |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1236 | // First test simply fails in MULTIPLE_DISPLAY_STATE_SINGLE mode. This is |
| 1237 | // probably unrealistic but we want to make sure any assumptions don't creep |
| 1238 | // in. |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 1239 | native_display_delegate_->set_max_configurable_pixels( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1240 | modes[2]->size().GetArea()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1241 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1242 | UpdateOutputs(1, true); |
| 1243 | |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1244 | EXPECT_EQ( |
| 1245 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1246 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1247 | GetFramebufferAction(big_mode_.size(), &outputs_[0], NULL).c_str(), |
| 1248 | GetCrtcAction(outputs_[0], modes[0], gfx::Point(0, 0)).c_str(), |
| 1249 | GetCrtcAction(outputs_[0], modes[3], gfx::Point(0, 0)).c_str(), |
| 1250 | GetCrtcAction(outputs_[0], modes[2], gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1251 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1252 | NULL), |
| 1253 | log_->GetActionsAndClear()); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1254 | |
| 1255 | // This test should attempt to configure a mirror mode that will not succeed |
| 1256 | // and should end up in extended mode. |
[email protected] | 72bce52 | 2014-02-10 21:11:26 | [diff] [blame] | 1257 | native_display_delegate_->set_max_configurable_pixels( |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1258 | modes[3]->size().GetArea()); |
[email protected] | bcec7fb | 2014-04-08 20:59:09 | [diff] [blame] | 1259 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1260 | UpdateOutputs(2, true); |
| 1261 | |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1262 | EXPECT_EQ( |
| 1263 | JoinActions( |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1264 | kGrab, |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1265 | GetFramebufferAction(modes[0]->size(), &outputs_[0], &outputs_[1]) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1266 | .c_str(), |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1267 | GetCrtcAction(outputs_[0], modes[0], gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1268 | // First mode tried is expected to fail and it will |
| 1269 | // retry wil the 4th mode in the list. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1270 | GetCrtcAction(outputs_[0], modes[3], gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1271 | // Then attempt to configure crtc1 with the first mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1272 | GetCrtcAction(outputs_[1], modes[0], gfx::Point(0, 0)).c_str(), |
| 1273 | GetCrtcAction(outputs_[1], modes[3], gfx::Point(0, 0)).c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1274 | // Since it was requested to go into mirror mode |
| 1275 | // and the configured modes were different, it |
| 1276 | // should now try and setup a valid configurable |
| 1277 | // extended mode. |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1278 | GetFramebufferAction( |
| 1279 | gfx::Size(modes[0]->size().width(), |
| 1280 | modes[0]->size().height() + modes[0]->size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1281 | DisplayConfigurator::kVerticalGap), |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1282 | &outputs_[0], |
| 1283 | &outputs_[1]).c_str(), |
| 1284 | GetCrtcAction(outputs_[0], modes[0], gfx::Point(0, 0)).c_str(), |
| 1285 | GetCrtcAction(outputs_[0], modes[3], gfx::Point(0, 0)).c_str(), |
| 1286 | GetCrtcAction(outputs_[1], |
| 1287 | modes[0], |
| 1288 | gfx::Point(0, |
| 1289 | modes[0]->size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1290 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1291 | .c_str(), |
[email protected] | 71da07e | 2014-03-18 21:16:04 | [diff] [blame] | 1292 | GetCrtcAction(outputs_[1], |
| 1293 | modes[3], |
| 1294 | gfx::Point(0, |
| 1295 | modes[0]->size().height() + |
[email protected] | 1e31cbd | 2014-04-07 20:06:11 | [diff] [blame] | 1296 | DisplayConfigurator::kVerticalGap)) |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1297 | .c_str(), |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1298 | kUngrab, |
[email protected] | b036effd | 2014-02-05 16:24:54 | [diff] [blame] | 1299 | NULL), |
| 1300 | log_->GetActionsAndClear()); |
[email protected] | 63da7fb | 2014-01-10 00:35:31 | [diff] [blame] | 1301 | } |
| 1302 | |
derat | 4a06278 | 2014-09-25 21:46:13 | [diff] [blame] | 1303 | // Tests that power state requests are saved after failed configuration attempts |
| 1304 | // so they can be reused later: http://crosbug.com/p/31571 |
| 1305 | TEST_F(DisplayConfiguratorTest, SaveDisplayPowerStateOnConfigFailure) { |
| 1306 | // Start out with two displays in extended mode. |
| 1307 | state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 1308 | configurator_.Init(false); |
| 1309 | configurator_.ForceInitialConfigure(0); |
| 1310 | log_->GetActionsAndClear(); |
| 1311 | |
| 1312 | // Turn off the internal display, simulating docked mode. |
| 1313 | EXPECT_TRUE(configurator_.SetDisplayPower( |
| 1314 | chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 1315 | DisplayConfigurator::kSetDisplayPowerNoFlags)); |
| 1316 | log_->GetActionsAndClear(); |
| 1317 | |
| 1318 | // Make all subsequent configuration requests fail and try to turn the |
| 1319 | // internal display back on. |
| 1320 | native_display_delegate_->set_max_configurable_pixels(1); |
| 1321 | EXPECT_FALSE(configurator_.SetDisplayPower( |
| 1322 | chromeos::DISPLAY_POWER_ALL_ON, |
| 1323 | DisplayConfigurator::kSetDisplayPowerNoFlags)); |
| 1324 | log_->GetActionsAndClear(); |
| 1325 | |
| 1326 | // Simulate the external display getting disconnected and check that the |
| 1327 | // internal display is turned on (i.e. DISPLAY_POWER_ALL_ON is used) rather |
| 1328 | // than the earlier DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON state. |
| 1329 | native_display_delegate_->set_max_configurable_pixels(0); |
| 1330 | UpdateOutputs(1, true); |
| 1331 | EXPECT_EQ( |
| 1332 | JoinActions( |
| 1333 | kGrab, |
| 1334 | GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), |
| 1335 | GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 1336 | kUngrab, |
| 1337 | NULL), |
| 1338 | log_->GetActionsAndClear()); |
| 1339 | } |
| 1340 | |
[email protected] | 29957af | 2014-03-14 21:08:56 | [diff] [blame] | 1341 | } // namespace ui |