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