| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ash/rotator/screen_rotation_animator.h" | 5 #include "ash/rotator/screen_rotation_animator.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/public/cpp/config.h" | 9 #include "ash/public/cpp/config.h" |
| 9 #include "ash/rotator/screen_rotation_animator_observer.h" | 10 #include "ash/rotator/screen_rotation_animator_observer.h" |
| 10 #include "ash/rotator/test/screen_rotation_animator_test_api.h" | 11 #include "ash/rotator/test/screen_rotation_animator_test_api.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/shell_port.h" | 13 #include "ash/shell_port.h" |
| 13 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 14 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 53 } |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 bool notified_ = false; | 56 bool notified_ = false; |
| 56 | 57 |
| 57 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); | 58 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 class TestScreenRotationAnimator : public ScreenRotationAnimator { | 61 class TestScreenRotationAnimator : public ScreenRotationAnimator { |
| 61 public: | 62 public: |
| 62 TestScreenRotationAnimator(int64_t display_id, const base::Closure& callback); | 63 TestScreenRotationAnimator(int64_t display_id, |
| 64 const base::Closure& before_callback, |
| 65 const base::Closure& after_callback); |
| 63 ~TestScreenRotationAnimator() override {} | 66 ~TestScreenRotationAnimator() override {} |
| 64 | 67 |
| 65 private: | 68 private: |
| 66 CopyCallback CreateAfterCopyCallback( | 69 CopyCallback CreateAfterCopyCallbackBeforeRotation( |
| 70 std::unique_ptr<ScreenRotationRequest> rotation_request) override; |
| 71 CopyCallback CreateAfterCopyCallbackAfterRotation( |
| 67 std::unique_ptr<ScreenRotationRequest> rotation_request) override; | 72 std::unique_ptr<ScreenRotationRequest> rotation_request) override; |
| 68 | 73 |
| 69 void IntersectBefore(CopyCallback next_callback, | 74 void IntersectBefore(CopyCallback next_callback, |
| 70 std::unique_ptr<cc::CopyOutputResult> result); | 75 std::unique_ptr<cc::CopyOutputResult> result); |
| 76 void IntersectAfter(CopyCallback next_callback, |
| 77 std::unique_ptr<cc::CopyOutputResult> result); |
| 71 | 78 |
| 72 base::Closure intersect_callback_; | 79 base::Closure intersect_before_callback_; |
| 80 base::Closure intersect_after_callback_; |
| 73 | 81 |
| 74 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); | 82 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator); |
| 75 }; | 83 }; |
| 76 | 84 |
| 77 TestScreenRotationAnimator::TestScreenRotationAnimator( | 85 TestScreenRotationAnimator::TestScreenRotationAnimator( |
| 78 int64_t display_id, | 86 int64_t display_id, |
| 79 const base::Closure& callback) | 87 const base::Closure& before_callback, |
| 80 : ScreenRotationAnimator(display_id), intersect_callback_(callback) {} | 88 const base::Closure& after_callback) |
| 89 : ScreenRotationAnimator(display_id), |
| 90 intersect_before_callback_(before_callback), |
| 91 intersect_after_callback_(after_callback) {} |
| 81 | 92 |
| 82 ScreenRotationAnimator::CopyCallback | 93 ScreenRotationAnimator::CopyCallback |
| 83 TestScreenRotationAnimator::CreateAfterCopyCallback( | 94 TestScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( |
| 84 std::unique_ptr<ScreenRotationRequest> rotation_request) { | 95 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 85 CopyCallback next_callback = ScreenRotationAnimator::CreateAfterCopyCallback( | 96 CopyCallback next_callback = |
| 86 std::move(rotation_request)); | 97 ScreenRotationAnimator::CreateAfterCopyCallbackBeforeRotation( |
| 98 std::move(rotation_request)); |
| 87 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, | 99 return base::Bind(&TestScreenRotationAnimator::IntersectBefore, |
| 88 base::Unretained(this), next_callback); | 100 base::Unretained(this), next_callback); |
| 89 } | 101 } |
| 90 | 102 |
| 103 ScreenRotationAnimator::CopyCallback |
| 104 TestScreenRotationAnimator::CreateAfterCopyCallbackAfterRotation( |
| 105 std::unique_ptr<ScreenRotationRequest> rotation_request) { |
| 106 CopyCallback next_callback = |
| 107 ScreenRotationAnimator::CreateAfterCopyCallbackAfterRotation( |
| 108 std::move(rotation_request)); |
| 109 return base::Bind(&TestScreenRotationAnimator::IntersectAfter, |
| 110 base::Unretained(this), next_callback); |
| 111 } |
| 112 |
| 91 void TestScreenRotationAnimator::IntersectBefore( | 113 void TestScreenRotationAnimator::IntersectBefore( |
| 92 CopyCallback next_callback, | 114 CopyCallback next_callback, |
| 93 std::unique_ptr<cc::CopyOutputResult> result) { | 115 std::unique_ptr<cc::CopyOutputResult> result) { |
| 94 intersect_callback_.Run(); | 116 intersect_before_callback_.Run(); |
| 95 next_callback.Run(std::move(result)); | 117 next_callback.Run(std::move(result)); |
| 96 } | 118 } |
| 97 | 119 |
| 120 void TestScreenRotationAnimator::IntersectAfter( |
| 121 CopyCallback next_callback, |
| 122 std::unique_ptr<cc::CopyOutputResult> result) { |
| 123 intersect_after_callback_.Run(); |
| 124 next_callback.Run(std::move(result)); |
| 125 } |
| 126 |
| 98 } // namespace | 127 } // namespace |
| 99 | 128 |
| 100 class ScreenRotationAnimatorTest : public test::AshTestBase { | 129 class ScreenRotationAnimatorTest : public test::AshTestBase { |
| 101 public: | 130 public: |
| 102 ScreenRotationAnimatorTest() {} | 131 ScreenRotationAnimatorTest() {} |
| 103 ~ScreenRotationAnimatorTest() override {} | 132 ~ScreenRotationAnimatorTest() override {} |
| 104 | 133 |
| 105 // AshTestBase: | 134 // AshTestBase: |
| 106 void SetUp() override; | 135 void SetUp() override; |
| 107 | 136 |
| 108 void RemoveSecondaryDisplay(const std::string& specs); | 137 void RemoveSecondaryDisplay(const std::string& specs); |
| 138 void QuitWaitForCopyCallback(); |
| 109 | 139 |
| 110 protected: | 140 protected: |
| 111 int64_t display_id() const { return display_.id(); } | 141 int64_t display_id() const { return display_.id(); } |
| 112 | 142 |
| 113 TestScreenRotationAnimator* animator() { return animator_.get(); } | 143 TestScreenRotationAnimator* animator() { return animator_.get(); } |
| 114 | 144 |
| 115 void SetScreenRotationAnimator(int64_t display_id, | 145 void SetScreenRotationAnimator(int64_t display_id, |
| 116 const base::Closure& callback); | 146 const base::Closure& before_callback, |
| 147 |
| 148 const base::Closure& after_callback); |
| 117 | 149 |
| 118 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } | 150 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } |
| 119 | 151 |
| 120 void WaitForCopyCallback(); | 152 void WaitForCopyCallback(); |
| 121 | 153 |
| 122 std::unique_ptr<base::RunLoop> run_loop_; | 154 std::unique_ptr<base::RunLoop> run_loop_; |
| 123 | 155 |
| 124 private: | 156 private: |
| 125 display::Display display_; | 157 display::Display display_; |
| 126 | 158 |
| 127 std::unique_ptr<TestScreenRotationAnimator> animator_; | 159 std::unique_ptr<TestScreenRotationAnimator> animator_; |
| 128 | 160 |
| 129 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; | 161 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; |
| 130 | 162 |
| 131 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; | 163 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; |
| 132 | 164 |
| 133 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); | 165 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); |
| 134 }; | 166 }; |
| 135 | 167 |
| 136 void ScreenRotationAnimatorTest::RemoveSecondaryDisplay( | 168 void ScreenRotationAnimatorTest::RemoveSecondaryDisplay( |
| 137 const std::string& specs) { | 169 const std::string& specs) { |
| 138 UpdateDisplay(specs); | 170 UpdateDisplay(specs); |
| 171 QuitWaitForCopyCallback(); |
| 172 } |
| 173 |
| 174 void ScreenRotationAnimatorTest::QuitWaitForCopyCallback() { |
| 139 run_loop_->QuitWhenIdle(); | 175 run_loop_->QuitWhenIdle(); |
| 140 } | 176 } |
| 141 | 177 |
| 142 void ScreenRotationAnimatorTest::SetUp() { | 178 void ScreenRotationAnimatorTest::SetUp() { |
| 143 AshTestBase::SetUp(); | 179 AshTestBase::SetUp(); |
| 144 | 180 |
| 145 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); | 181 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 146 run_loop_ = base::MakeUnique<base::RunLoop>(); | 182 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 147 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure()); | 183 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure(), |
| 184 run_loop_->QuitWhenIdleClosure()); |
| 148 non_zero_duration_mode_ = | 185 non_zero_duration_mode_ = |
| 149 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( | 186 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( |
| 150 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); | 187 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 151 } | 188 } |
| 152 | 189 |
| 153 void ScreenRotationAnimatorTest::SetScreenRotationAnimator( | 190 void ScreenRotationAnimatorTest::SetScreenRotationAnimator( |
| 154 int64_t display_id, | 191 int64_t display_id, |
| 155 const base::Closure& callback) { | 192 const base::Closure& before_callback, |
| 156 animator_ = | 193 const base::Closure& after_callback) { |
| 157 base::MakeUnique<TestScreenRotationAnimator>(display_id, callback); | 194 animator_ = base::MakeUnique<TestScreenRotationAnimator>( |
| 195 display_id, before_callback, after_callback); |
| 158 test_api_ = | 196 test_api_ = |
| 159 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); | 197 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); |
| 160 test_api()->DisableAnimationTimers(); | 198 test_api()->DisableAnimationTimers(); |
| 161 } | 199 } |
| 162 | 200 |
| 163 void ScreenRotationAnimatorTest::WaitForCopyCallback() { | 201 void ScreenRotationAnimatorTest::WaitForCopyCallback() { |
| 202 run_loop_.reset(new base::RunLoop()); |
| 164 run_loop_->Run(); | 203 run_loop_->Run(); |
| 165 } | 204 } |
| 166 | 205 |
| 167 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { | 206 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { |
| 168 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 207 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 169 if (Shell::GetAshConfig() == Config::MASH) { | 208 if (Shell::GetAshConfig() == Config::MASH) { |
| 170 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 209 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 171 display_id()); | 210 display_id()); |
| 172 return; | 211 return; |
| 173 } | 212 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 337 |
| 299 // Test enable smooth screen rotation code path. | 338 // Test enable smooth screen rotation code path. |
| 300 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) { | 339 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) { |
| 301 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 340 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 302 if (Shell::GetAshConfig() == Config::MASH) { | 341 if (Shell::GetAshConfig() == Config::MASH) { |
| 303 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 342 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 304 display_id()); | 343 display_id()); |
| 305 return; | 344 return; |
| 306 } | 345 } |
| 307 | 346 |
| 347 SetScreenRotationAnimator( |
| 348 display_manager()->GetDisplayAt(0).id(), run_loop_->QuitWhenIdleClosure(), |
| 349 base::Bind(&ScreenRotationAnimatorTest::QuitWaitForCopyCallback, |
| 350 base::Unretained(this))); |
| 308 SetDisplayRotation(display_id(), display::Display::ROTATE_0); | 351 SetDisplayRotation(display_id(), display::Display::ROTATE_0); |
| 309 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 352 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 310 switches::kAshEnableSmoothScreenRotation); | 353 switches::kAshEnableSmoothScreenRotation); |
| 311 animator()->Rotate(display::Display::ROTATE_90, | 354 animator()->Rotate(display::Display::ROTATE_90, |
| 312 display::Display::RotationSource::ROTATION_SOURCE_USER); | 355 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 313 WaitForCopyCallback(); | 356 WaitForCopyCallback(); |
| 314 EXPECT_TRUE(test_api()->HasActiveAnimations()); | 357 EXPECT_TRUE(test_api()->HasActiveAnimations()); |
| 315 | 358 |
| 316 test_api()->CompleteAnimations(); | 359 test_api()->CompleteAnimations(); |
| 317 EXPECT_FALSE(test_api()->HasActiveAnimations()); | 360 EXPECT_FALSE(test_api()->HasActiveAnimations()); |
| 318 } | 361 } |
| 319 | 362 |
| 320 // If the external display is removed, it should not crash. | 363 // If the external secondary display is removed, it should not crash. |
| 321 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) { | 364 TEST_F(ScreenRotationAnimatorTest, |
| 365 RemoveExternalSecondaryDisplayAfterCopyCallback) { |
| 322 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. | 366 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 323 if (Shell::GetAshConfig() == Config::MASH) { | 367 if (Shell::GetAshConfig() == Config::MASH) { |
| 324 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != | 368 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 325 display_id()); | 369 display_id()); |
| 326 return; | 370 return; |
| 327 } | 371 } |
| 328 | 372 |
| 329 UpdateDisplay("640x480,800x600"); | 373 UpdateDisplay("640x480,800x600"); |
| 330 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | 374 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 331 | 375 |
| 332 const unsigned int primary_display_id = | 376 const unsigned int primary_display_id = |
| 333 display_manager()->GetDisplayAt(0).id(); | 377 display_manager()->GetDisplayAt(0).id(); |
| 334 SetScreenRotationAnimator( | 378 SetScreenRotationAnimator( |
| 335 display_manager()->GetDisplayAt(1).id(), | 379 display_manager()->GetDisplayAt(1).id(), |
| 336 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, | 380 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, |
| 337 base::Unretained(this), "640x480")); | 381 base::Unretained(this), "640x480"), |
| 382 run_loop_->QuitWhenIdleClosure()); |
| 338 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 383 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 339 switches::kAshEnableSmoothScreenRotation); | 384 switches::kAshEnableSmoothScreenRotation); |
| 340 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), | 385 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
| 341 display::Display::ROTATE_0); | 386 display::Display::ROTATE_0); |
| 342 animator()->Rotate(display::Display::ROTATE_90, | 387 animator()->Rotate(display::Display::ROTATE_90, |
| 343 display::Display::RotationSource::ROTATION_SOURCE_USER); | 388 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 344 WaitForCopyCallback(); | 389 WaitForCopyCallback(); |
| 345 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 390 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 346 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); | 391 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 347 } | 392 } |
| 348 | 393 |
| 394 // If the external primary display is removed, it should not crash. |
| 395 TEST_F(ScreenRotationAnimatorTest, |
| 396 RemoveExternalPrimaryDisplayAfterCopyCallback) { |
| 397 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. |
| 398 if (Shell::GetAshConfig() == Config::MASH) { |
| 399 ASSERT_TRUE(ShellPort::Get()->GetDisplayInfo(display_id()).id() != |
| 400 display_id()); |
| 401 return; |
| 402 } |
| 403 |
| 404 UpdateDisplay("640x480,800x600"); |
| 405 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); |
| 406 |
| 407 Shell::Get()->window_tree_host_manager()->SetPrimaryDisplayId( |
| 408 display_manager()->GetDisplayAt(1).id()); |
| 409 const unsigned int secondary_display_id = |
| 410 display_manager()->GetDisplayAt(0).id(); |
| 411 SetScreenRotationAnimator( |
| 412 display_manager()->GetDisplayAt(1).id(), |
| 413 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay, |
| 414 base::Unretained(this), "640x480"), |
| 415 run_loop_->QuitWhenIdleClosure()); |
| 416 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 417 switches::kAshEnableSmoothScreenRotation); |
| 418 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(), |
| 419 display::Display::ROTATE_0); |
| 420 animator()->Rotate(display::Display::ROTATE_90, |
| 421 display::Display::RotationSource::ROTATION_SOURCE_USER); |
| 422 WaitForCopyCallback(); |
| 423 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 424 EXPECT_EQ(secondary_display_id, display_manager()->GetDisplayAt(0).id()); |
| 425 } |
| 349 } // namespace ash | 426 } // namespace ash |
| OLD | NEW |