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