Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: ash/rotator/screen_rotation_animator_unittest.cc

Issue 2780823002: Uses copy request to flatten the layers to do screen rotation animation. (Closed)
Patch Set: Resolve merge conflicts. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | chrome/browser/about_flags.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm_shell.h" 7 #include "ash/common/wm_shell.h"
7 #include "ash/rotator/screen_rotation_animator_observer.h" 8 #include "ash/rotator/screen_rotation_animator_observer.h"
8 #include "ash/rotator/test/screen_rotation_animator_test_api.h" 9 #include "ash/rotator/test/screen_rotation_animator_test_api.h"
9 #include "ash/shell.h" 10 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "base/callback_forward.h"
13 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/run_loop.h"
16 #include "cc/output/copy_output_request.h"
17 #include "cc/output/copy_output_result.h"
12 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
13 #include "ui/display/display.h" 19 #include "ui/display/display.h"
14 #include "ui/display/manager/display_manager.h" 20 #include "ui/display/manager/display_manager.h"
15 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
16 22
17 namespace ash { 23 namespace ash {
18 24
19 namespace { 25 namespace {
20 26
21 display::Display::Rotation GetDisplayRotation(int64_t display_id) { 27 display::Display::Rotation GetDisplayRotation(int64_t display_id) {
(...skipping 20 matching lines...) Expand all
42 ScreenRotationAnimator* animator) override { 48 ScreenRotationAnimator* animator) override {
43 notified_ = true; 49 notified_ = true;
44 } 50 }
45 51
46 private: 52 private:
47 bool notified_ = false; 53 bool notified_ = false;
48 54
49 DISALLOW_COPY_AND_ASSIGN(AnimationObserver); 55 DISALLOW_COPY_AND_ASSIGN(AnimationObserver);
50 }; 56 };
51 57
58 class TestScreenRotationAnimator : public ScreenRotationAnimator {
59 public:
60 TestScreenRotationAnimator(int64_t display_id, const base::Closure& callback);
61 ~TestScreenRotationAnimator() override {}
62
63 private:
64 CopyCallback CreateAfterCopyCallback(
65 std::unique_ptr<ScreenRotationRequest> rotation_request) override;
66
67 void IntersectBefore(CopyCallback next_callback,
68 std::unique_ptr<cc::CopyOutputResult> result);
69
70 base::Closure intersect_callback_;
71
72 DISALLOW_COPY_AND_ASSIGN(TestScreenRotationAnimator);
73 };
74
75 TestScreenRotationAnimator::TestScreenRotationAnimator(
76 int64_t display_id,
77 const base::Closure& callback)
78 : ScreenRotationAnimator(display_id), intersect_callback_(callback) {}
79
80 ScreenRotationAnimator::CopyCallback
81 TestScreenRotationAnimator::CreateAfterCopyCallback(
82 std::unique_ptr<ScreenRotationRequest> rotation_request) {
83 CopyCallback next_callback = ScreenRotationAnimator::CreateAfterCopyCallback(
84 std::move(rotation_request));
85 return base::Bind(&TestScreenRotationAnimator::IntersectBefore,
86 base::Unretained(this), next_callback);
87 }
88
89 void TestScreenRotationAnimator::IntersectBefore(
90 CopyCallback next_callback,
91 std::unique_ptr<cc::CopyOutputResult> result) {
92 intersect_callback_.Run();
93 next_callback.Run(std::move(result));
94 }
95
52 } // namespace 96 } // namespace
53 97
54 class ScreenRotationAnimatorTest : public test::AshTestBase { 98 class ScreenRotationAnimatorTest : public test::AshTestBase {
55 public: 99 public:
56 ScreenRotationAnimatorTest() {} 100 ScreenRotationAnimatorTest() {}
57 ~ScreenRotationAnimatorTest() override {} 101 ~ScreenRotationAnimatorTest() override {}
58 102
59 // AshTestBase: 103 // AshTestBase:
60 void SetUp() override; 104 void SetUp() override;
61 105
106 void RemoveSecondaryDisplay(const std::string& specs);
107
62 protected: 108 protected:
63 int64_t display_id() const { return display_.id(); } 109 int64_t display_id() const { return display_.id(); }
64 110
65 ScreenRotationAnimator* animator() { return animator_.get(); } 111 TestScreenRotationAnimator* animator() { return animator_.get(); }
112
113 void SetScreenRotationAnimator(int64_t display_id,
114 const base::Closure& callback);
66 115
67 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } 116 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); }
68 117
69 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; 118 void WaitForCopyCallback();
119
120 std::unique_ptr<base::RunLoop> run_loop_;
70 121
71 private: 122 private:
72 display::Display display_; 123 display::Display display_;
73 124
74 std::unique_ptr<ScreenRotationAnimator> animator_; 125 std::unique_ptr<TestScreenRotationAnimator> animator_;
75 126
76 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; 127 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_;
77 128
129 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
130
78 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); 131 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest);
79 }; 132 };
80 133
134 void ScreenRotationAnimatorTest::RemoveSecondaryDisplay(
135 const std::string& specs) {
136 UpdateDisplay(specs);
137 run_loop_->QuitWhenIdle();
138 }
139
81 void ScreenRotationAnimatorTest::SetUp() { 140 void ScreenRotationAnimatorTest::SetUp() {
82 AshTestBase::SetUp(); 141 AshTestBase::SetUp();
83 142
84 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); 143 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
85 animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id()); 144 run_loop_ = base::MakeUnique<base::RunLoop>();
86 test_api_ = 145 SetScreenRotationAnimator(display_.id(), run_loop_->QuitWhenIdleClosure());
87 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
88 test_api()->DisableAnimationTimers();
89 non_zero_duration_mode_ = 146 non_zero_duration_mode_ =
90 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( 147 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
91 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 148 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
92 } 149 }
93 150
151 void ScreenRotationAnimatorTest::SetScreenRotationAnimator(
152 int64_t display_id,
153 const base::Closure& callback) {
154 animator_ =
155 base::MakeUnique<TestScreenRotationAnimator>(display_id, callback);
156 test_api_ =
157 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
158 test_api()->DisableAnimationTimers();
159 }
160
161 void ScreenRotationAnimatorTest::WaitForCopyCallback() {
162 run_loop_->Run();
163 }
164
94 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { 165 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) {
95 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 166 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
96 if (WmShell::Get()->IsRunningInMash()) { 167 if (WmShell::Get()->IsRunningInMash()) {
97 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 168 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
98 display_id()); 169 display_id());
99 return; 170 return;
100 } 171 }
101 172
102 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 173 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
103 AnimationObserver observer; 174 AnimationObserver observer;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 287
217 animator()->Rotate(display::Display::ROTATE_270, 288 animator()->Rotate(display::Display::ROTATE_270,
218 display::Display::RotationSource::ROTATION_SOURCE_USER); 289 display::Display::RotationSource::ROTATION_SOURCE_USER);
219 EXPECT_TRUE(test_api()->HasActiveAnimations()); 290 EXPECT_TRUE(test_api()->HasActiveAnimations());
220 291
221 test_api()->CompleteAnimations(); 292 test_api()->CompleteAnimations();
222 EXPECT_FALSE(test_api()->HasActiveAnimations()); 293 EXPECT_FALSE(test_api()->HasActiveAnimations());
223 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); 294 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id()));
224 } 295 }
225 296
297 // Test enable smooth screen rotation code path.
298 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
299 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
300 if (WmShell::Get()->IsRunningInMash()) {
301 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
302 display_id());
303 return;
304 }
305
306 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
307 base::CommandLine::ForCurrentProcess()->AppendSwitch(
308 switches::kAshEnableSmoothScreenRotation);
309 animator()->Rotate(display::Display::ROTATE_90,
310 display::Display::RotationSource::ROTATION_SOURCE_USER);
311 WaitForCopyCallback();
312 EXPECT_TRUE(test_api()->HasActiveAnimations());
313
314 test_api()->CompleteAnimations();
315 EXPECT_FALSE(test_api()->HasActiveAnimations());
316 }
317
318 // If the external display is removed, it should not crash.
319 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
320 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
321 if (WmShell::Get()->IsRunningInMash()) {
322 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
323 display_id());
324 return;
325 }
326
327 UpdateDisplay("640x480,800x600");
328 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
329
330 const unsigned int primary_display_id =
331 display_manager()->GetDisplayAt(0).id();
332 SetScreenRotationAnimator(
333 display_manager()->GetDisplayAt(1).id(),
334 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
335 base::Unretained(this), "640x480"));
336 base::CommandLine::ForCurrentProcess()->AppendSwitch(
337 switches::kAshEnableSmoothScreenRotation);
338 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
339 display::Display::ROTATE_0);
340 animator()->Rotate(display::Display::ROTATE_90,
341 display::Display::RotationSource::ROTATION_SOURCE_USER);
342 WaitForCopyCallback();
343 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
344 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
345 }
346
226 } // namespace ash 347 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animator.cc ('k') | chrome/browser/about_flags.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698