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