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" |
11 #include "ui/display/chromeos/test/test_display_snapshot.h" | 11 #include "ui/display/chromeos/test/test_display_snapshot.h" |
12 #include "ui/display/chromeos/test/test_native_display_delegate.h" | 12 #include "ui/display/chromeos/test/test_native_display_delegate.h" |
| 13 #include "ui/display/util/display_util.h" |
13 | 14 |
14 namespace ui { | 15 namespace ui { |
15 namespace test { | 16 namespace test { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 class TestObserver : public DisplayConfigurator::Observer { | 20 class TestObserver : public DisplayConfigurator::Observer { |
20 public: | 21 public: |
21 explicit TestObserver(DisplayConfigurator* configurator) | 22 explicit TestObserver(DisplayConfigurator* configurator) |
22 : configurator_(configurator) { | 23 : configurator_(configurator) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 EXPECT_EQ(modes[15], | 331 EXPECT_EQ(modes[15], |
331 DisplayConfigurator::FindDisplayModeMatchingSize( | 332 DisplayConfigurator::FindDisplayModeMatchingSize( |
332 output, gfx::Size(320, 200))); | 333 output, gfx::Size(320, 200))); |
333 | 334 |
334 // No mode found. | 335 // No mode found. |
335 EXPECT_EQ(NULL, | 336 EXPECT_EQ(NULL, |
336 DisplayConfigurator::FindDisplayModeMatchingSize( | 337 DisplayConfigurator::FindDisplayModeMatchingSize( |
337 output, gfx::Size(1440, 900))); | 338 output, gfx::Size(1440, 900))); |
338 } | 339 } |
339 | 340 |
| 341 TEST_F(DisplayConfiguratorTest, EnableVirtualDisplay) { |
| 342 InitWithSingleOutput(); |
| 343 |
| 344 observer_.Reset(); |
| 345 const DisplayConfigurator::DisplayStateList& cached = |
| 346 configurator_.cached_displays(); |
| 347 ASSERT_EQ(static_cast<size_t>(1u), cached.size()); |
| 348 EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); |
| 349 |
| 350 // Add virtual display. |
| 351 int64_t virtual_display_id = |
| 352 configurator_.AddVirtualDisplay(big_mode_.size()); |
| 353 EXPECT_EQ(GenerateDisplayID(0x8000, 0x0, 1), virtual_display_id); |
| 354 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 355 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 356 configurator_.display_state()); |
| 357 |
| 358 // Virtual should not trigger addition of added crtc but does change FB |
| 359 // height. |
| 360 const int kVirtualHeight = small_mode_.size().height() + |
| 361 DisplayConfigurator::kVerticalGap + |
| 362 big_mode_.size().height(); |
| 363 EXPECT_EQ( |
| 364 JoinActions( |
| 365 kGrab, GetFramebufferAction( |
| 366 gfx::Size(big_mode_.size().width(), kVirtualHeight), |
| 367 &outputs_[0], nullptr) |
| 368 .c_str(), |
| 369 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 370 kUngrab, nullptr), |
| 371 log_->GetActionsAndClear()); |
| 372 EXPECT_EQ(1, observer_.num_changes()); |
| 373 ASSERT_EQ(static_cast<size_t>(2u), cached.size()); |
| 374 EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); |
| 375 EXPECT_EQ(big_mode_.size(), cached[1]->current_mode()->size()); |
| 376 EXPECT_EQ(virtual_display_id, cached[1]->display_id()); |
| 377 |
| 378 // Remove virtual display. |
| 379 observer_.Reset(); |
| 380 EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id)); |
| 381 EXPECT_EQ( |
| 382 JoinActions( |
| 383 kGrab, GetFramebufferAction(small_mode_.size(), &outputs_[0], nullptr) |
| 384 .c_str(), |
| 385 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 386 kUngrab, nullptr), |
| 387 log_->GetActionsAndClear()); |
| 388 EXPECT_EQ(1, observer_.num_changes()); |
| 389 ASSERT_EQ(static_cast<size_t>(1u), 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 = |
| 399 configurator_.cached_displays(); |
| 400 ASSERT_EQ(static_cast<size_t>(1u), 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_EQ(GenerateDisplayID(0x8000, 0x0, 1), virtual_display_id_1); |
| 407 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 408 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 409 configurator_.display_state()); |
| 410 |
| 411 // Virtual should not trigger addition of added crtc but does change FB |
| 412 // height. |
| 413 const int kSingleVirtualHeight = small_mode_.size().height() + |
| 414 DisplayConfigurator::kVerticalGap + |
| 415 big_mode_.size().height(); |
| 416 EXPECT_EQ( |
| 417 JoinActions( |
| 418 kGrab, GetFramebufferAction( |
| 419 gfx::Size(big_mode_.size().width(), kSingleVirtualHeight), |
| 420 &outputs_[0], nullptr) |
| 421 .c_str(), |
| 422 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 423 kUngrab, nullptr), |
| 424 log_->GetActionsAndClear()); |
| 425 EXPECT_EQ(1, observer_.num_changes()); |
| 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_EQ(GenerateDisplayID(0x8000, 0x0, 2), virtual_display_id_2); |
| 435 EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); |
| 436 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED, |
| 437 configurator_.display_state()); |
| 438 |
| 439 const int kDualVirtualHeight = |
| 440 small_mode_.size().height() + |
| 441 (DisplayConfigurator::kVerticalGap + big_mode_.size().height()) * 2; |
| 442 EXPECT_EQ( |
| 443 JoinActions( |
| 444 kGrab, GetFramebufferAction( |
| 445 gfx::Size(big_mode_.size().width(), kDualVirtualHeight), |
| 446 &outputs_[0], nullptr) |
| 447 .c_str(), |
| 448 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 449 kUngrab, nullptr), |
| 450 log_->GetActionsAndClear()); |
| 451 EXPECT_EQ(2, observer_.num_changes()); |
| 452 ASSERT_EQ(static_cast<size_t>(3u), 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], nullptr) |
| 467 .c_str(), |
| 468 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 469 kUngrab, nullptr), |
| 470 log_->GetActionsAndClear()); |
| 471 EXPECT_EQ(1, observer_.num_changes()); |
| 472 ASSERT_EQ(static_cast<size_t>(2u), cached.size()); |
| 473 EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); |
| 474 EXPECT_EQ(big_mode_.size(), cached[1]->current_mode()->size()); |
| 475 EXPECT_EQ(virtual_display_id_2, cached[1]->display_id()); |
| 476 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, |
| 477 configurator_.display_state()); |
| 478 |
| 479 // Remove 2nd virtual display. |
| 480 observer_.Reset(); |
| 481 EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id_2)); |
| 482 EXPECT_EQ( |
| 483 JoinActions( |
| 484 kGrab, GetFramebufferAction(small_mode_.size(), &outputs_[0], nullptr) |
| 485 .c_str(), |
| 486 GetCrtcAction(outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), |
| 487 kUngrab, nullptr), |
| 488 log_->GetActionsAndClear()); |
| 489 EXPECT_EQ(1, observer_.num_changes()); |
| 490 ASSERT_EQ(static_cast<size_t>(1), cached.size()); |
| 491 EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); |
| 492 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); |
| 493 } |
| 494 |
340 TEST_F(DisplayConfiguratorTest, ConnectSecondOutput) { | 495 TEST_F(DisplayConfiguratorTest, ConnectSecondOutput) { |
341 InitWithSingleOutput(); | 496 InitWithSingleOutput(); |
342 | 497 |
343 // Connect a second output and check that the configurator enters | 498 // Connect a second output and check that the configurator enters |
344 // extended mode. | 499 // extended mode. |
345 observer_.Reset(); | 500 observer_.Reset(); |
346 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); | 501 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
347 UpdateOutputs(2, true); | 502 UpdateOutputs(2, true); |
348 const int kDualHeight = small_mode_.size().height() + | 503 const int kDualHeight = small_mode_.size().height() + |
349 DisplayConfigurator::kVerticalGap + | 504 DisplayConfigurator::kVerticalGap + |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 TEST_F(DisplayConfiguratorTest, GetMultipleDisplayStateForMirroredDisplays) { | 1053 TEST_F(DisplayConfiguratorTest, GetMultipleDisplayStateForMirroredDisplays) { |
899 UpdateOutputs(2, false); | 1054 UpdateOutputs(2, false); |
900 configurator_.Init(false); | 1055 configurator_.Init(false); |
901 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); | 1056 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR); |
902 configurator_.ForceInitialConfigure(0); | 1057 configurator_.ForceInitialConfigure(0); |
903 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); | 1058 EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_MIRROR, configurator_.display_state()); |
904 } | 1059 } |
905 | 1060 |
906 TEST_F(DisplayConfiguratorTest, UpdateCachedOutputsEvenAfterFailure) { | 1061 TEST_F(DisplayConfiguratorTest, UpdateCachedOutputsEvenAfterFailure) { |
907 InitWithSingleOutput(); | 1062 InitWithSingleOutput(); |
908 const DisplayConfigurator::DisplayStateList* cached = | 1063 const DisplayConfigurator::DisplayStateList& cached = |
909 &configurator_.cached_displays(); | 1064 configurator_.cached_displays(); |
910 ASSERT_EQ(static_cast<size_t>(1), cached->size()); | 1065 ASSERT_EQ(static_cast<size_t>(1), cached.size()); |
911 EXPECT_EQ(outputs_[0].current_mode(), (*cached)[0]->current_mode()); | 1066 EXPECT_EQ(outputs_[0].current_mode(), cached[0]->current_mode()); |
912 | 1067 |
913 // After connecting a second output, check that it shows up in | 1068 // After connecting a second output, check that it shows up in |
914 // |cached_displays_| even if an invalid state is requested. | 1069 // |cached_displays_| even if an invalid state is requested. |
915 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); | 1070 state_controller_.set_state(MULTIPLE_DISPLAY_STATE_SINGLE); |
916 UpdateOutputs(2, true); | 1071 UpdateOutputs(2, true); |
917 cached = &configurator_.cached_displays(); | 1072 ASSERT_EQ(static_cast<size_t>(2), cached.size()); |
918 ASSERT_EQ(static_cast<size_t>(2), cached->size()); | 1073 EXPECT_EQ(outputs_[0].current_mode(), cached[0]->current_mode()); |
919 EXPECT_EQ(outputs_[0].current_mode(), (*cached)[0]->current_mode()); | 1074 EXPECT_EQ(outputs_[1].current_mode(), cached[1]->current_mode()); |
920 EXPECT_EQ(outputs_[1].current_mode(), (*cached)[1]->current_mode()); | |
921 } | 1075 } |
922 | 1076 |
923 TEST_F(DisplayConfiguratorTest, PanelFitting) { | 1077 TEST_F(DisplayConfiguratorTest, PanelFitting) { |
924 // Configure the internal display to support only the big mode and the | 1078 // Configure the internal display to support only the big mode and the |
925 // external display to support only the small mode. | 1079 // external display to support only the small mode. |
926 outputs_[0].set_current_mode(&big_mode_); | 1080 outputs_[0].set_current_mode(&big_mode_); |
927 outputs_[0].set_native_mode(&big_mode_); | 1081 outputs_[0].set_native_mode(&big_mode_); |
928 outputs_[0].set_modes(std::vector<const DisplayMode*>(1, &big_mode_)); | 1082 outputs_[0].set_modes(std::vector<const DisplayMode*>(1, &big_mode_)); |
929 | 1083 |
930 outputs_[1].set_current_mode(&small_mode_); | 1084 outputs_[1].set_current_mode(&small_mode_); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 GetFramebufferAction(small_mode_.size(), &outputs_[0], | 1618 GetFramebufferAction(small_mode_.size(), &outputs_[0], |
1465 nullptr).c_str(), | 1619 nullptr).c_str(), |
1466 GetCrtcAction(outputs_[0], &small_mode_, | 1620 GetCrtcAction(outputs_[0], &small_mode_, |
1467 gfx::Point(0, 0)).c_str(), | 1621 gfx::Point(0, 0)).c_str(), |
1468 kUngrab, NULL), | 1622 kUngrab, NULL), |
1469 log_->GetActionsAndClear()); | 1623 log_->GetActionsAndClear()); |
1470 } | 1624 } |
1471 | 1625 |
1472 } // namespace test | 1626 } // namespace test |
1473 } // namespace ui | 1627 } // namespace ui |
OLD | NEW |