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