| 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 <cstdarg> | 7 #include <cstdarg> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 std::vector<OutputConfigurator::OutputSnapshot> outputs_; | 185 std::vector<OutputConfigurator::OutputSnapshot> outputs_; |
| 186 | 186 |
| 187 std::string actions_; | 187 std::string actions_; |
| 188 | 188 |
| 189 // Return value returned by ConfigureCrtc(). | 189 // Return value returned by ConfigureCrtc(). |
| 190 bool configure_crtc_result_; | 190 bool configure_crtc_result_; |
| 191 | 191 |
| 192 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 192 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 class TestObserver : public OutputConfigurator::Observer { |
| 196 public: |
| 197 explicit TestObserver(OutputConfigurator* configurator) |
| 198 : configurator_(configurator) { |
| 199 Reset(); |
| 200 configurator_->AddObserver(this); |
| 201 } |
| 202 ~TestObserver() { |
| 203 configurator_->RemoveObserver(this); |
| 204 } |
| 205 |
| 206 int num_changes() const { return num_changes_; } |
| 207 int num_failures() const { return num_failures_; } |
| 208 std::vector<OutputConfigurator::OutputSnapshot> latest_outputs() const { |
| 209 return latest_outputs_; |
| 210 } |
| 211 OutputState latest_failed_state() const { return latest_failed_state_; } |
| 212 |
| 213 void Reset() { |
| 214 num_changes_ = 0; |
| 215 num_failures_ = 0; |
| 216 latest_outputs_.clear(); |
| 217 latest_failed_state_ = STATE_INVALID; |
| 218 } |
| 219 |
| 220 // OutputConfigurator::Observer overrides: |
| 221 virtual void OnDisplayModeChanged( |
| 222 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) OVERRIDE { |
| 223 num_changes_++; |
| 224 latest_outputs_ = outputs; |
| 225 } |
| 226 |
| 227 virtual void OnDisplayModeChangeFailed(OutputState failed_new_state) { |
| 228 num_failures_++; |
| 229 latest_failed_state_ = failed_new_state; |
| 230 } |
| 231 |
| 232 private: |
| 233 OutputConfigurator* configurator_; // Not owned. |
| 234 |
| 235 // Number of times that OnDisplayMode*() has been called. |
| 236 int num_changes_; |
| 237 int num_failures_; |
| 238 |
| 239 // Parameters most recently passed to OnDisplayMode*(). |
| 240 std::vector<OutputConfigurator::OutputSnapshot> latest_outputs_; |
| 241 OutputState latest_failed_state_; |
| 242 |
| 243 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 244 }; |
| 245 |
| 195 class TestStateController : public OutputConfigurator::StateController { | 246 class TestStateController : public OutputConfigurator::StateController { |
| 196 public: | 247 public: |
| 197 TestStateController() : state_(STATE_DUAL_EXTENDED) {} | 248 TestStateController() : state_(STATE_DUAL_EXTENDED) {} |
| 198 virtual ~TestStateController() {} | 249 virtual ~TestStateController() {} |
| 199 | 250 |
| 200 void set_state(OutputState state) { state_ = state; } | 251 void set_state(OutputState state) { state_ = state; } |
| 201 | 252 |
| 202 // OutputConfigurator::StateController overrides: | 253 // OutputConfigurator::StateController overrides: |
| 203 virtual OutputState GetStateForDisplayIds( | 254 virtual OutputState GetStateForDisplayIds( |
| 204 const std::vector<int64>& outputs) const OVERRIDE { return state_; } | 255 const std::vector<int64>& outputs) const OVERRIDE { return state_; } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 231 | 282 |
| 232 private: | 283 private: |
| 233 bool software_mirroring_enabled_; | 284 bool software_mirroring_enabled_; |
| 234 | 285 |
| 235 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); | 286 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); |
| 236 }; | 287 }; |
| 237 | 288 |
| 238 class OutputConfiguratorTest : public testing::Test { | 289 class OutputConfiguratorTest : public testing::Test { |
| 239 public: | 290 public: |
| 240 OutputConfiguratorTest() | 291 OutputConfiguratorTest() |
| 241 : test_api_(&configurator_, TestDelegate::kXRandREventBase) {} | 292 : observer_(&configurator_), |
| 293 test_api_(&configurator_, TestDelegate::kXRandREventBase) {} |
| 242 virtual ~OutputConfiguratorTest() {} | 294 virtual ~OutputConfiguratorTest() {} |
| 243 | 295 |
| 244 virtual void SetUp() OVERRIDE { | 296 virtual void SetUp() OVERRIDE { |
| 245 delegate_ = new TestDelegate(); | 297 delegate_ = new TestDelegate(); |
| 246 configurator_.SetDelegateForTesting( | 298 configurator_.SetDelegateForTesting( |
| 247 scoped_ptr<OutputConfigurator::Delegate>(delegate_)); | 299 scoped_ptr<OutputConfigurator::Delegate>(delegate_)); |
| 248 configurator_.set_state_controller(&state_controller_); | 300 configurator_.set_state_controller(&state_controller_); |
| 249 configurator_.set_mirroring_controller(&mirroring_controller_); | 301 configurator_.set_mirroring_controller(&mirroring_controller_); |
| 250 | 302 |
| 251 OutputConfigurator::ModeInfo small_mode_info; | 303 OutputConfigurator::ModeInfo small_mode_info; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, | 392 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, |
| 341 outputs_[0].output).c_str(), | 393 outputs_[0].output).c_str(), |
| 342 kForceDPMS, kUngrab, kProjectingOff, NULL), | 394 kForceDPMS, kUngrab, kProjectingOff, NULL), |
| 343 delegate_->GetActionsAndClear()); | 395 delegate_->GetActionsAndClear()); |
| 344 } | 396 } |
| 345 | 397 |
| 346 base::MessageLoop message_loop_; | 398 base::MessageLoop message_loop_; |
| 347 TestStateController state_controller_; | 399 TestStateController state_controller_; |
| 348 TestMirroringController mirroring_controller_; | 400 TestMirroringController mirroring_controller_; |
| 349 OutputConfigurator configurator_; | 401 OutputConfigurator configurator_; |
| 402 TestObserver observer_; |
| 350 TestDelegate* delegate_; // not owned | 403 TestDelegate* delegate_; // not owned |
| 351 OutputConfigurator::TestApi test_api_; | 404 OutputConfigurator::TestApi test_api_; |
| 352 | 405 |
| 353 OutputConfigurator::OutputSnapshot outputs_[2]; | 406 OutputConfigurator::OutputSnapshot outputs_[2]; |
| 354 | 407 |
| 355 private: | 408 private: |
| 356 DISALLOW_COPY_AND_ASSIGN(OutputConfiguratorTest); | 409 DISALLOW_COPY_AND_ASSIGN(OutputConfiguratorTest); |
| 357 }; | 410 }; |
| 358 | 411 |
| 359 } // namespace | 412 } // namespace |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, | 512 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, |
| 460 outputs_[0].output).c_str(), | 513 outputs_[0].output).c_str(), |
| 461 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, | 514 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, |
| 462 outputs_[1].output).c_str(), | 515 outputs_[1].output).c_str(), |
| 463 kUngrab, kProjectingOn, NULL), | 516 kUngrab, kProjectingOn, NULL), |
| 464 delegate_->GetActionsAndClear()); | 517 delegate_->GetActionsAndClear()); |
| 465 EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled()); | 518 EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled()); |
| 466 | 519 |
| 467 // Turning off the internal display should switch the external display to | 520 // Turning off the internal display should switch the external display to |
| 468 // its native mode. | 521 // its native mode. |
| 522 observer_.Reset(); |
| 469 configurator_.SetDisplayPower(DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, | 523 configurator_.SetDisplayPower(DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON, |
| 470 OutputConfigurator::kSetDisplayPowerNoFlags); | 524 OutputConfigurator::kSetDisplayPowerNoFlags); |
| 471 EXPECT_EQ(JoinActions(kGrab, | 525 EXPECT_EQ(JoinActions(kGrab, |
| 472 GetFramebufferAction(kBigModeWidth, kBigModeHeight, | 526 GetFramebufferAction(kBigModeWidth, kBigModeHeight, |
| 473 outputs_[0].crtc, outputs_[1].crtc).c_str(), | 527 outputs_[0].crtc, outputs_[1].crtc).c_str(), |
| 474 GetCrtcAction(outputs_[0].crtc, 0, 0, 0, | 528 GetCrtcAction(outputs_[0].crtc, 0, 0, 0, |
| 475 outputs_[0].output).c_str(), | 529 outputs_[0].output).c_str(), |
| 476 GetCrtcAction(outputs_[1].crtc, 0, 0, kBigModeId, | 530 GetCrtcAction(outputs_[1].crtc, 0, 0, kBigModeId, |
| 477 outputs_[1].output).c_str(), | 531 outputs_[1].output).c_str(), |
| 478 kForceDPMS, kUngrab, NULL), | 532 kForceDPMS, kUngrab, NULL), |
| 479 delegate_->GetActionsAndClear()); | 533 delegate_->GetActionsAndClear()); |
| 480 EXPECT_EQ(STATE_SINGLE, configurator_.output_state()); | 534 EXPECT_EQ(STATE_SINGLE, configurator_.output_state()); |
| 535 EXPECT_EQ(1, observer_.num_changes()); |
| 481 | 536 |
| 482 // When all displays are turned off, the framebuffer should switch back | 537 // When all displays are turned off, the framebuffer should switch back |
| 483 // to the mirrored size. | 538 // to the mirrored size. |
| 539 observer_.Reset(); |
| 484 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_OFF, | 540 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_OFF, |
| 485 OutputConfigurator::kSetDisplayPowerNoFlags); | 541 OutputConfigurator::kSetDisplayPowerNoFlags); |
| 486 EXPECT_EQ(JoinActions(kGrab, | 542 EXPECT_EQ(JoinActions(kGrab, |
| 487 GetFramebufferAction(kSmallModeWidth, kSmallModeHeight, | 543 GetFramebufferAction(kSmallModeWidth, kSmallModeHeight, |
| 488 outputs_[0].crtc, outputs_[1].crtc).c_str(), | 544 outputs_[0].crtc, outputs_[1].crtc).c_str(), |
| 489 GetCrtcAction(outputs_[0].crtc, 0, 0, 0, | 545 GetCrtcAction(outputs_[0].crtc, 0, 0, 0, |
| 490 outputs_[0].output).c_str(), | 546 outputs_[0].output).c_str(), |
| 491 GetCrtcAction(outputs_[1].crtc, 0, 0, 0, | 547 GetCrtcAction(outputs_[1].crtc, 0, 0, 0, |
| 492 outputs_[1].output).c_str(), | 548 outputs_[1].output).c_str(), |
| 493 kUngrab, NULL), | 549 kUngrab, NULL), |
| 494 delegate_->GetActionsAndClear()); | 550 delegate_->GetActionsAndClear()); |
| 495 EXPECT_EQ(STATE_DUAL_MIRROR, configurator_.output_state()); | 551 EXPECT_EQ(STATE_DUAL_MIRROR, configurator_.output_state()); |
| 552 EXPECT_EQ(1, observer_.num_changes()); |
| 496 EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled()); | 553 EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled()); |
| 497 | 554 |
| 498 // Turn all displays on and check that mirroring is still used. | 555 // Turn all displays on and check that mirroring is still used. |
| 556 observer_.Reset(); |
| 499 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_ON, | 557 configurator_.SetDisplayPower(DISPLAY_POWER_ALL_ON, |
| 500 OutputConfigurator::kSetDisplayPowerNoFlags); | 558 OutputConfigurator::kSetDisplayPowerNoFlags); |
| 501 EXPECT_EQ(JoinActions(kGrab, | 559 EXPECT_EQ(JoinActions(kGrab, |
| 502 GetFramebufferAction(kSmallModeWidth, kSmallModeHeight, | 560 GetFramebufferAction(kSmallModeWidth, kSmallModeHeight, |
| 503 outputs_[0].crtc, outputs_[1].crtc).c_str(), | 561 outputs_[0].crtc, outputs_[1].crtc).c_str(), |
| 504 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, | 562 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, |
| 505 outputs_[0].output).c_str(), | 563 outputs_[0].output).c_str(), |
| 506 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, | 564 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, |
| 507 outputs_[1].output).c_str(), | 565 outputs_[1].output).c_str(), |
| 508 kForceDPMS, kUngrab, NULL), | 566 kForceDPMS, kUngrab, NULL), |
| 509 delegate_->GetActionsAndClear()); | 567 delegate_->GetActionsAndClear()); |
| 510 EXPECT_EQ(STATE_DUAL_MIRROR, configurator_.output_state()); | 568 EXPECT_EQ(STATE_DUAL_MIRROR, configurator_.output_state()); |
| 569 EXPECT_EQ(1, observer_.num_changes()); |
| 511 EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled()); | 570 EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled()); |
| 512 | 571 |
| 513 // Software Mirroring | 572 // Software Mirroring |
| 514 DisableNativeMirroring(); | 573 DisableNativeMirroring(); |
| 515 state_controller_.set_state(STATE_DUAL_MIRROR); | 574 state_controller_.set_state(STATE_DUAL_MIRROR); |
| 516 UpdateOutputs(2, true); | 575 UpdateOutputs(2, true); |
| 517 const int kDualHeight = | 576 const int kDualHeight = |
| 518 kSmallModeHeight + OutputConfigurator::kVerticalGap + kBigModeHeight; | 577 kSmallModeHeight + OutputConfigurator::kVerticalGap + kBigModeHeight; |
| 519 EXPECT_EQ(JoinActions(kUpdateXRandR, kGrab, | 578 EXPECT_EQ(JoinActions(kUpdateXRandR, kGrab, |
| 520 GetFramebufferAction(kBigModeWidth, kDualHeight, | 579 GetFramebufferAction(kBigModeWidth, kDualHeight, |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 outputs_[0].crtc, outputs_[1].crtc).c_str(), | 912 outputs_[0].crtc, outputs_[1].crtc).c_str(), |
| 854 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, | 913 GetCrtcAction(outputs_[0].crtc, 0, 0, kSmallModeId, |
| 855 outputs_[0].output).c_str(), | 914 outputs_[0].output).c_str(), |
| 856 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, | 915 GetCrtcAction(outputs_[1].crtc, 0, 0, kSmallModeId, |
| 857 outputs_[1].output).c_str(), | 916 outputs_[1].output).c_str(), |
| 858 kUngrab, kProjectingOn, NULL), | 917 kUngrab, kProjectingOn, NULL), |
| 859 delegate_->GetActionsAndClear()); | 918 delegate_->GetActionsAndClear()); |
| 860 } | 919 } |
| 861 | 920 |
| 862 } // namespace chromeos | 921 } // namespace chromeos |
| OLD | NEW |