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