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

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: Change the test. 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
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 ScreenRotationTestAnimator : public ScreenRotationAnimator {
oshima 2017/04/05 01:55:43 nit: TestScreenRotationAnimator just to make it e
wutao 2017/04/05 07:41:57 Done.
59 public:
60 explicit ScreenRotationTestAnimator(int64_t display_id);
61 ~ScreenRotationTestAnimator() override {}
62
63 void set_intersect_callback(const base::Closure& intersect_callback) {
64 intersect_callback_ = intersect_callback;
65 }
66
67 protected:
68 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>
69 CreateAfterCopyCallback(
70 std::unique_ptr<ScreenRotationRequest> rotation_request) override;
71
72 private:
73 void IntersectBefore(
74 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>
75 next_callback,
76 std::unique_ptr<cc::CopyOutputResult> result);
77
78 base::Closure intersect_callback_;
79
80 DISALLOW_COPY_AND_ASSIGN(ScreenRotationTestAnimator);
81 };
82
83 ScreenRotationTestAnimator::ScreenRotationTestAnimator(int64_t display_id)
84 : ScreenRotationAnimator(display_id) {}
85
86 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>
87 ScreenRotationTestAnimator::CreateAfterCopyCallback(
88 std::unique_ptr<ScreenRotationRequest> rotation_request) {
89 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>
90 next_callback = ScreenRotationAnimator::CreateAfterCopyCallback(
91 std::move(rotation_request));
92 return base::Bind(&ScreenRotationTestAnimator::IntersectBefore,
93 base::Unretained(this), next_callback);
94 }
95
96 void ScreenRotationTestAnimator::IntersectBefore(
97 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>
98 next_callback,
99 std::unique_ptr<cc::CopyOutputResult> result) {
100 intersect_callback_.Run();
101 next_callback.Run(std::move(result));
102 }
103
52 } // namespace 104 } // namespace
53 105
54 class ScreenRotationAnimatorTest : public test::AshTestBase { 106 class ScreenRotationAnimatorTest : public test::AshTestBase {
55 public: 107 public:
56 ScreenRotationAnimatorTest() {} 108 ScreenRotationAnimatorTest() {}
57 ~ScreenRotationAnimatorTest() override {} 109 ~ScreenRotationAnimatorTest() override {}
58 110
59 // AshTestBase: 111 // AshTestBase:
60 void SetUp() override; 112 void SetUp() override;
61 113
114 void DoNothingCallback();
115
116 void RemoveSecondaryDisplay(const std::string& specs);
117
62 protected: 118 protected:
63 int64_t display_id() const { return display_.id(); } 119 int64_t display_id() const { return display_.id(); }
64 120
65 ScreenRotationAnimator* animator() { return animator_.get(); } 121 ScreenRotationTestAnimator* animator() { return animator_.get(); }
122
123 void SetSecreenRotatioAnimator(int64_t display_id);
oshima 2017/04/05 01:55:43 SetScreen... optional: you can pass the closure t
wutao 2017/04/05 07:41:57 Done.
66 124
67 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); } 125 test::ScreenRotationAnimatorTestApi* test_api() { return test_api_.get(); }
68 126
69 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_; 127 void AddSecondaryDisplay(const std::string& specs);
128
129 void WaitForCopyCallback();
70 130
71 private: 131 private:
72 display::Display display_; 132 display::Display display_;
73 133
74 std::unique_ptr<ScreenRotationAnimator> animator_; 134 std::unique_ptr<ScreenRotationTestAnimator> animator_;
75 135
76 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_; 136 std::unique_ptr<test::ScreenRotationAnimatorTestApi> test_api_;
77 137
138 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> non_zero_duration_mode_;
139
140 std::unique_ptr<base::RunLoop> run_loop_;
141
78 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest); 142 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimatorTest);
79 }; 143 };
80 144
145 void ScreenRotationAnimatorTest::DoNothingCallback() {
146 run_loop_->Quit();
147 }
148
149 void ScreenRotationAnimatorTest::RemoveSecondaryDisplay(
150 const std::string& specs) {
151 UpdateDisplay(specs);
152 run_loop_->Quit();
oshima 2017/04/05 01:55:42 QuitWhenIdle
wutao 2017/04/05 07:41:57 Done.
153 }
154
81 void ScreenRotationAnimatorTest::SetUp() { 155 void ScreenRotationAnimatorTest::SetUp() {
82 AshTestBase::SetUp(); 156 AshTestBase::SetUp();
83 157
84 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); 158 display_ = display::Screen::GetScreen()->GetPrimaryDisplay();
85 animator_ = base::MakeUnique<ScreenRotationAnimator>(display_.id()); 159 SetSecreenRotatioAnimator(display_.id());
160 }
161
162 void ScreenRotationAnimatorTest::SetSecreenRotatioAnimator(int64_t display_id) {
163 animator_ = base::MakeUnique<ScreenRotationTestAnimator>(display_id);
86 test_api_ = 164 test_api_ =
87 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get()); 165 base::MakeUnique<test::ScreenRotationAnimatorTestApi>(animator_.get());
88 test_api()->DisableAnimationTimers(); 166 test_api()->DisableAnimationTimers();
89 non_zero_duration_mode_ = 167 non_zero_duration_mode_ =
90 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>( 168 base::MakeUnique<ui::ScopedAnimationDurationScaleMode>(
91 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 169 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
92 } 170 }
93 171
172 void ScreenRotationAnimatorTest::AddSecondaryDisplay(const std::string& specs) {
173 UpdateDisplay(specs);
174 }
175
176 void ScreenRotationAnimatorTest::WaitForCopyCallback() {
177 run_loop_.reset(new base::RunLoop);
178 run_loop_->Run();
179 }
180
94 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) { 181 TEST_F(ScreenRotationAnimatorTest, ShouldNotifyObserver) {
95 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480. 182 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
96 if (WmShell::Get()->IsRunningInMash()) { 183 if (WmShell::Get()->IsRunningInMash()) {
97 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() != 184 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
98 display_id()); 185 display_id());
99 return; 186 return;
100 } 187 }
101 188
102 SetDisplayRotation(display_id(), display::Display::ROTATE_0); 189 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
103 AnimationObserver observer; 190 AnimationObserver observer;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 303
217 animator()->Rotate(display::Display::ROTATE_270, 304 animator()->Rotate(display::Display::ROTATE_270,
218 display::Display::RotationSource::ROTATION_SOURCE_USER); 305 display::Display::RotationSource::ROTATION_SOURCE_USER);
219 EXPECT_TRUE(test_api()->HasActiveAnimations()); 306 EXPECT_TRUE(test_api()->HasActiveAnimations());
220 307
221 test_api()->CompleteAnimations(); 308 test_api()->CompleteAnimations();
222 EXPECT_FALSE(test_api()->HasActiveAnimations()); 309 EXPECT_FALSE(test_api()->HasActiveAnimations());
223 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id())); 310 EXPECT_EQ(display::Display::ROTATE_270, GetDisplayRotation(display_id()));
224 } 311 }
225 312
313 // Test enable smooth screen rotation code path.
314 TEST_F(ScreenRotationAnimatorTest, RotatesToDifferentRotationWithCopyCallback) {
315 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
316 if (WmShell::Get()->IsRunningInMash()) {
317 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
318 display_id());
319 return;
320 }
321
322 SetDisplayRotation(display_id(), display::Display::ROTATE_0);
323 animator()->set_intersect_callback(base::Bind(
324 &ScreenRotationAnimatorTest::DoNothingCallback, base::Unretained(this)));
oshima 2017/04/05 01:55:43 run_loop->QuitWhenIdleClosure()
wutao 2017/04/05 07:41:57 Done.
325 base::CommandLine::ForCurrentProcess()->AppendSwitch(
326 switches::kAshEnableSmoothScreenRotation);
327 animator()->Rotate(display::Display::ROTATE_90,
328 display::Display::RotationSource::ROTATION_SOURCE_USER);
329 WaitForCopyCallback();
330 EXPECT_TRUE(test_api()->HasActiveAnimations());
331
332 test_api()->CompleteAnimations();
333 EXPECT_FALSE(test_api()->HasActiveAnimations());
334 }
335
336 // If the external display is removed, it should not crash.
337 TEST_F(ScreenRotationAnimatorTest, RemoveSecondaryDisplayAfterCopyCallback) {
338 // TODO(wutao): needs GetDisplayInfo http://crbug.com/622480.
339 if (WmShell::Get()->IsRunningInMash()) {
340 ASSERT_TRUE(WmShell::Get()->GetDisplayInfo(display_id()).id() !=
341 display_id());
342 return;
343 }
344
345 AddSecondaryDisplay("640x480,800x600");
oshima 2017/04/05 01:55:42 just call UpdateDisplay("640x480,800x600"); no
wutao 2017/04/05 07:41:57 Done.
346 EXPECT_EQ(2U, display_manager()->GetNumDisplays());
347
348 const unsigned int primary_display_id =
349 display_manager()->GetDisplayAt(0).id();
350 SetSecreenRotatioAnimator(display_manager()->GetDisplayAt(1).id());
351 animator()->set_intersect_callback(
352 base::Bind(&ScreenRotationAnimatorTest::RemoveSecondaryDisplay,
353 base::Unretained(this), "640x480"));
354 base::CommandLine::ForCurrentProcess()->AppendSwitch(
355 switches::kAshEnableSmoothScreenRotation);
356 SetDisplayRotation(display_manager()->GetDisplayAt(1).id(),
357 display::Display::ROTATE_0);
358 animator()->Rotate(display::Display::ROTATE_90,
359 display::Display::RotationSource::ROTATION_SOURCE_USER);
360 WaitForCopyCallback();
361 EXPECT_EQ(1U, display_manager()->GetNumDisplays());
362 EXPECT_EQ(primary_display_id, display_manager()->GetDisplayAt(0).id());
363 }
364
226 } // namespace ash 365 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698