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

Side by Side Diff: cc/vsync_time_source_unittest.cc

Issue 11854013: Use input events to improve vsync scheduling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't set last-input-for-vsync bit on pages with touch handlers. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/vsync_time_source.h" 5 #include "cc/vsync_time_source.h"
6 6
7 #include "cc/test/scheduler_test_common.h" 7 #include "cc/test/scheduler_test_common.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace cc { 10 namespace cc {
(...skipping 13 matching lines...) Expand all
24 24
25 void Trigger(base::TimeTicks frame_time) { 25 void Trigger(base::TimeTicks frame_time) {
26 if (client_) 26 if (client_)
27 client_->DidVSync(frame_time); 27 client_->DidVSync(frame_time);
28 } 28 }
29 29
30 private: 30 private:
31 VSyncClient* client_; 31 VSyncClient* client_;
32 }; 32 };
33 33
34 class FakeVSyncTimeSource : public cc::VSyncTimeSource {
35 public:
36 static scoped_refptr<FakeVSyncTimeSource> create(VSyncProvider* provider) {
37 return make_scoped_refptr(new FakeVSyncTimeSource(provider));
38 }
39
40 void SetNow(base::TimeTicks time) { now_ = time; }
41 virtual base::TimeTicks Now() const OVERRIDE { return now_; }
42
43 protected:
44 explicit FakeVSyncTimeSource(VSyncProvider* provider)
45 : VSyncTimeSource(provider) {}
46 virtual ~FakeVSyncTimeSource() {}
47
48 base::TimeTicks now_;
49 };
50
34 class VSyncTimeSourceTest : public testing::Test { 51 class VSyncTimeSourceTest : public testing::Test {
35 public: 52 public:
36 VSyncTimeSourceTest() 53 VSyncTimeSourceTest()
37 : timer_(VSyncTimeSource::create(&provider_)) { 54 : timer_(FakeVSyncTimeSource::create(&provider_)) {
38 timer_->setClient(&client_); 55 timer_->setClient(&client_);
39 } 56 }
40 57
41 protected: 58 protected:
42 FakeTimeSourceClient client_; 59 FakeTimeSourceClient client_;
43 FakeVSyncProvider provider_; 60 FakeVSyncProvider provider_;
44 scoped_refptr<VSyncTimeSource> timer_; 61 scoped_refptr<FakeVSyncTimeSource> timer_;
45 }; 62 };
46 63
47 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled) 64 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled)
48 { 65 {
49 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); 66 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled());
50 67
51 timer_->setActive(true); 68 timer_->setActive(true);
52 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); 69 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled());
53 70
54 base::TimeTicks frame_time = base::TimeTicks::Now(); 71 base::TimeTicks frame_time = base::TimeTicks::Now();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ASSERT_EQ(timer_->nextTickTime(), base::TimeTicks()); 109 ASSERT_EQ(timer_->nextTickTime(), base::TimeTicks());
93 110
94 timer_->setActive(true); 111 timer_->setActive(true);
95 provider_.Trigger(frame_time); 112 provider_.Trigger(frame_time);
96 ASSERT_EQ(timer_->nextTickTime(), frame_time); 113 ASSERT_EQ(timer_->nextTickTime(), frame_time);
97 114
98 timer_->setTimebaseAndInterval(frame_time, interval); 115 timer_->setTimebaseAndInterval(frame_time, interval);
99 ASSERT_EQ(timer_->nextTickTime(), frame_time + interval); 116 ASSERT_EQ(timer_->nextTickTime(), frame_time + interval);
100 } 117 }
101 118
119 TEST_F(VSyncTimeSourceTest, SynthesizeVSyncFromInput)
120 {
121 base::TimeTicks current_time;
122 base::TimeDelta interval = base::TimeDelta::FromSeconds(1);
123
124 // Establish a time base and interval.
125 timer_->setTimebaseAndInterval(current_time, interval);
126
127 // An input event when the timer is inactive should do nothing.
128 timer_->DidReceiveLastInputEventForVSync();
129 EXPECT_FALSE(client_.tickCalled());
130 ASSERT_EQ(timer_->lastTickTime(), base::TimeTicks());
131
132 // An input event should synthesize a vsync event with a frame time estimated
133 // from the current time.
134 current_time += interval;
135 timer_->SetNow(current_time);
136 timer_->setActive(true);
137 timer_->DidReceiveLastInputEventForVSync();
138 EXPECT_TRUE(client_.tickCalled());
139 ASSERT_EQ(timer_->lastTickTime(), current_time);
140 client_.reset();
141
142 // A vsync notification immediately following the input should be ignored.
143 provider_.Trigger(current_time);
144 EXPECT_FALSE(client_.tickCalled());
145
146 // A vsync notification for the next frame should not be ignored.
147 current_time += interval;
148 provider_.Trigger(current_time);
149 EXPECT_TRUE(client_.tickCalled());
150 ASSERT_EQ(timer_->lastTickTime(), current_time);
151 client_.reset();
152
153 // The next input event should also trigger a tick, because it signifies a
154 // start of a new frame.
155 current_time += interval;
156 provider_.Trigger(current_time);
157 EXPECT_TRUE(client_.tickCalled());
158 ASSERT_EQ(timer_->lastTickTime(), current_time);
159 }
160
102 } // namespace 161 } // namespace
103 } // namespace cc 162 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698