Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/display/chromeos/display_configurator.h" | 5 #include "ui/display/chromeos/display_configurator.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/display/chromeos/test/action_logger_util.h" | 10 #include "ui/display/chromeos/test/action_logger_util.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 bool SoftwareMirroringEnabled() const override { | 105 bool SoftwareMirroringEnabled() const override { |
| 106 return software_mirroring_enabled_; | 106 return software_mirroring_enabled_; |
| 107 } | 107 } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 bool software_mirroring_enabled_; | 110 bool software_mirroring_enabled_; |
| 111 | 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); | 112 DISALLOW_COPY_AND_ASSIGN(TestMirroringController); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 } // namespace | |
| 116 | |
| 115 class DisplayConfiguratorTest : public testing::Test { | 117 class DisplayConfiguratorTest : public testing::Test { |
| 116 public: | 118 public: |
| 117 enum CallbackResult { | 119 enum CallbackResult { |
| 118 CALLBACK_FAILURE, | 120 CALLBACK_FAILURE, |
| 119 CALLBACK_SUCCESS, | 121 CALLBACK_SUCCESS, |
| 120 CALLBACK_NOT_CALLED, | 122 CALLBACK_NOT_CALLED, |
| 121 }; | 123 }; |
| 122 | 124 |
| 123 DisplayConfiguratorTest() | 125 DisplayConfiguratorTest() |
| 124 : small_mode_(gfx::Size(1366, 768), false, 60.0f), | 126 : small_mode_(gfx::Size(1366, 768), false, 60.0f), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 254 |
| 253 TestDisplaySnapshot outputs_[2]; | 255 TestDisplaySnapshot outputs_[2]; |
| 254 | 256 |
| 255 CallbackResult callback_result_; | 257 CallbackResult callback_result_; |
| 256 CallbackResult display_control_result_; | 258 CallbackResult display_control_result_; |
| 257 | 259 |
| 258 private: | 260 private: |
| 259 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); | 261 DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorTest); |
| 260 }; | 262 }; |
| 261 | 263 |
| 262 } // namespace | |
| 263 | |
| 264 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { | 264 TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { |
| 265 ScopedVector<const DisplayMode> modes; | 265 ScopedVector<const DisplayMode> modes; |
| 266 | 266 |
| 267 // Fields are width, height, interlaced, refresh rate. | 267 // Fields are width, height, interlaced, refresh rate. |
| 268 modes.push_back(new DisplayMode(gfx::Size(1920, 1200), false, 60.0)); | 268 modes.push_back(new DisplayMode(gfx::Size(1920, 1200), false, 60.0)); |
| 269 DisplayMode* native_mode = | 269 DisplayMode* native_mode = |
| 270 new DisplayMode(gfx::Size(1920, 1200), false, 50.0); | 270 new DisplayMode(gfx::Size(1920, 1200), false, 50.0); |
| 271 modes.push_back(native_mode); | 271 modes.push_back(native_mode); |
| 272 // Different rates. | 272 // Different rates. |
| 273 modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 30.0)); | 273 modes.push_back(new DisplayMode(gfx::Size(1920, 1080), false, 30.0)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 EXPECT_EQ(modes[15], | 330 EXPECT_EQ(modes[15], |
| 331 DisplayConfigurator::FindDisplayModeMatchingSize( | 331 DisplayConfigurator::FindDisplayModeMatchingSize( |
| 332 output, gfx::Size(320, 200))); | 332 output, gfx::Size(320, 200))); |
| 333 | 333 |
| 334 // No mode found. | 334 // No mode found. |
| 335 EXPECT_EQ(NULL, | 335 EXPECT_EQ(NULL, |
| 336 DisplayConfigurator::FindDisplayModeMatchingSize( | 336 DisplayConfigurator::FindDisplayModeMatchingSize( |
| 337 output, gfx::Size(1440, 900))); | 337 output, gfx::Size(1440, 900))); |
| 338 } | 338 } |
| 339 | 339 |
| 340 TEST_F(DisplayConfiguratorTest, EnableVirtualDisplay) { | |
| 341 InitWithSingleOutput(); | |
| 342 | |
| 343 observer_.Reset(); | |
| 344 const DisplayConfigurator::DisplayStateList* cached = | |
| 345 &configurator_.cached_displays(); | |
| 346 ASSERT_EQ(static_cast<size_t>(1), cached->size()); | |
| 347 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 348 | |
| 349 // Add virtual display. | |
| 350 int64_t virtual_display_id = | |
| 351 configurator_.AddVirtualDisplay(big_mode_.size()); | |
| 352 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | |
| 353 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 354 configurator_.display_state()); | |
| 355 | |
| 356 // Virtual should not trigger addition of added crtc but does change FB | |
| 357 // height. | |
| 358 const int kVirtualHeight = small_mode_.size().height() + | |
| 359 DisplayConfigurator::kVerticalGap + | |
| 360 big_mode_.size().height(); | |
| 361 EXPECT_EQ( | |
| 362 JoinActions( | |
| 363 kGrab, GetFramebufferAction( | |
| 364 gfx::Size(big_mode_.size().width(), kVirtualHeight), | |
| 365 &outputs_[0], NULL) | |
| 366 .c_str(), | |
| 367 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | |
| 368 kUngrab, NULL), | |
| 369 log_->GetActionsAndClear()); | |
| 370 EXPECT_EQ(1, observer_.num_changes()); | |
| 371 cached = &configurator_.cached_displays(); | |
| 372 ASSERT_EQ(static_cast<size_t>(2), cached->size()); | |
| 373 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 374 EXPECT_EQ(big_mode_.size(), (*cached)[1]->current_mode()->size()); | |
| 375 EXPECT_EQ(virtual_display_id, (*cached)[1]->display_id()); | |
| 376 | |
| 377 // Remove virtual display. | |
| 378 observer_.Reset(); | |
| 379 EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id)); | |
| 380 EXPECT_EQ( | |
| 381 JoinActions( | |
| 382 kGrab, | |
| 383 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | |
| 384 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | |
| 385 kUngrab, NULL), | |
| 386 log_->GetActionsAndClear()); | |
| 387 EXPECT_EQ(1, observer_.num_changes()); | |
| 388 cached = &configurator_.cached_displays(); | |
| 389 ASSERT_EQ(static_cast<size_t>(1), cached->size()); | |
| 390 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 391 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); | |
| 392 } | |
| 393 | |
| 394 TEST_F(DisplayConfiguratorTest, EnableTwoVirtualDisplays) { | |
| 395 InitWithSingleOutput(); | |
| 396 | |
| 397 observer_.Reset(); | |
| 398 const DisplayConfigurator::DisplayStateList* cached = | |
|
jdufault
2015/11/17 20:10:21
Any reason this is a pointer? Can we just copy cac
robert.bradford
2015/11/18 12:46:10
Good catch. As you spotted, I must have copied thi
| |
| 399 &configurator_.cached_displays(); | |
| 400 ASSERT_EQ(static_cast<size_t>(1), cached->size()); | |
| 401 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 402 | |
| 403 // Add 1st virtual display. | |
| 404 int64_t virtual_display_id_1 = | |
| 405 configurator_.AddVirtualDisplay(big_mode_.size()); | |
| 406 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | |
| 407 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 408 configurator_.display_state()); | |
| 409 | |
| 410 // Virtual should not trigger addition of added crtc but does change FB | |
| 411 // height. | |
| 412 const int kSingleVirtualHeight = small_mode_.size().height() + | |
| 413 DisplayConfigurator::kVerticalGap + | |
| 414 big_mode_.size().height(); | |
| 415 EXPECT_EQ( | |
| 416 JoinActions( | |
| 417 kGrab, GetFramebufferAction( | |
| 418 gfx::Size(big_mode_.size().width(), kSingleVirtualHeight), | |
| 419 &outputs_[0], NULL) | |
| 420 .c_str(), | |
| 421 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | |
| 422 kUngrab, NULL), | |
| 423 log_->GetActionsAndClear()); | |
| 424 EXPECT_EQ(1, observer_.num_changes()); | |
| 425 cached = &configurator_.cached_displays(); | |
|
jdufault
2015/11/17 20:10:21
If cached remains a pointer/reference, is this nee
robert.bradford
2015/11/18 12:46:10
Acknowledged.
| |
| 426 ASSERT_EQ(static_cast<size_t>(2), cached->size()); | |
| 427 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 428 EXPECT_EQ(big_mode_.size(), (*cached)[1]->current_mode()->size()); | |
| 429 EXPECT_EQ(virtual_display_id_1, (*cached)[1]->display_id()); | |
| 430 | |
| 431 // Add 2nd virtual display | |
| 432 int64_t virtual_display_id_2 = | |
| 433 configurator_.AddVirtualDisplay(big_mode_.size()); | |
| 434 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); | |
| 435 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED, | |
| 436 configurator_.display_state()); | |
| 437 | |
| 438 const int kDualVirtualHeight = | |
| 439 small_mode_.size().height() + | |
| 440 (DisplayConfigurator::kVerticalGap + big_mode_.size().height()) * 2; | |
| 441 EXPECT_EQ( | |
| 442 JoinActions( | |
| 443 kGrab, GetFramebufferAction( | |
| 444 gfx::Size(big_mode_.size().width(), kDualVirtualHeight), | |
| 445 &outputs_[0], NULL) | |
| 446 .c_str(), | |
| 447 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | |
| 448 kUngrab, NULL), | |
| 449 log_->GetActionsAndClear()); | |
| 450 EXPECT_EQ(2, observer_.num_changes()); | |
| 451 cached = &configurator_.cached_displays(); | |
| 452 ASSERT_EQ(static_cast<size_t>(3), cached->size()); | |
| 453 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 454 EXPECT_EQ(big_mode_.size(), (*cached)[1]->current_mode()->size()); | |
| 455 EXPECT_EQ(big_mode_.size(), (*cached)[2]->current_mode()->size()); | |
| 456 EXPECT_EQ(virtual_display_id_1, (*cached)[1]->display_id()); | |
| 457 EXPECT_EQ(virtual_display_id_2, (*cached)[2]->display_id()); | |
| 458 | |
| 459 // Remove 1st virtual display. | |
| 460 observer_.Reset(); | |
| 461 EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id_1)); | |
| 462 EXPECT_EQ( | |
| 463 JoinActions( | |
| 464 kGrab, GetFramebufferAction( | |
| 465 gfx::Size(big_mode_.size().width(), kSingleVirtualHeight), | |
| 466 &outputs_[0], NULL) | |
| 467 .c_str(), | |
| 468 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | |
| 469 kUngrab, NULL), | |
| 470 log_->GetActionsAndClear()); | |
| 471 EXPECT_EQ(1, observer_.num_changes()); | |
| 472 cached = &configurator_.cached_displays(); | |
| 473 ASSERT_EQ(static_cast<size_t>(2), cached->size()); | |
| 474 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 475 EXPECT_EQ(big_mode_.size(), (*cached)[1]->current_mode()->size()); | |
| 476 EXPECT_EQ(virtual_display_id_2, (*cached)[1]->display_id()); | |
| 477 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, | |
| 478 configurator_.display_state()); | |
| 479 | |
| 480 // Remove 2nd virtual display. | |
| 481 observer_.Reset(); | |
| 482 EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id_2)); | |
| 483 EXPECT_EQ( | |
| 484 JoinActions( | |
| 485 kGrab, | |
| 486 GetFramebufferAction(small_mode_.size(), &outputs_[0], NULL).c_str(), | |
| 487 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), | |
| 488 kUngrab, NULL), | |
| 489 log_->GetActionsAndClear()); | |
| 490 EXPECT_EQ(1, observer_.num_changes()); | |
| 491 cached = &configurator_.cached_displays(); | |
| 492 ASSERT_EQ(static_cast<size_t>(1), cached->size()); | |
| 493 EXPECT_EQ(small_mode_.size(), (*cached)[0]->current_mode()->size()); | |
| 494 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); | |
| 495 } | |
| 496 | |
| 340 TEST_F(DisplayConfiguratorTest, ConnectSecondOutput) { | 497 TEST_F(DisplayConfiguratorTest, ConnectSecondOutput) { |
| 341 InitWithSingleOutput(); | 498 InitWithSingleOutput(); |
| 342 | 499 |
| 343 // Connect a second output and check that the configurator enters | 500 // Connect a second output and check that the configurator enters |
| 344 // extended mode. | 501 // extended mode. |
| 345 observer_.Reset(); | 502 observer_.Reset(); |
| 346 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | 503 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| 347 UpdateOutputs(2, true); | 504 UpdateOutputs(2, true); |
| 348 const int kDualHeight = small_mode_.size().height() + | 505 const int kDualHeight = small_mode_.size().height() + |
| 349 DisplayConfigurator::kVerticalGap + | 506 DisplayConfigurator::kVerticalGap + |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1464 GetFramebufferAction(small_mode_.size(), &outputs_[0], | 1621 GetFramebufferAction(small_mode_.size(), &outputs_[0], |
| 1465 nullptr).c_str(), | 1622 nullptr).c_str(), |
| 1466 GetCrtcAction(outputs_[0], &small_mode_, | 1623 GetCrtcAction(outputs_[0], &small_mode_, |
| 1467 gfx::Point(0, 0)).c_str(), | 1624 gfx::Point(0, 0)).c_str(), |
| 1468 kUngrab, NULL), | 1625 kUngrab, NULL), |
| 1469 log_->GetActionsAndClear()); | 1626 log_->GetActionsAndClear()); |
| 1470 } | 1627 } |
| 1471 | 1628 |
| 1472 } // namespace test | 1629 } // namespace test |
| 1473 } // namespace ui | 1630 } // namespace ui |
| OLD | NEW |