OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCScheduler.h" | 7 #include "CCScheduler.h" |
8 | 8 |
9 #include "CCSchedulerTestCommon.h" | 9 #include "CCSchedulerTestCommon.h" |
10 #include <gmock/gmock.h> | 10 #include <gmock/gmock.h> |
11 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
12 #include <wtf/OwnPtr.h> | 12 #include <wtf/OwnPtr.h> |
13 | 13 |
14 using namespace WTF; | 14 using namespace WTF; |
15 using namespace WebCore; | 15 using namespace WebCore; |
16 using namespace WebKitTests; | 16 using namespace WebKitTests; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class FakeCCSchedulerClient : public CCSchedulerClient { | 20 class FakeCCSchedulerClient : public CCSchedulerClient { |
21 public: | 21 public: |
22 FakeCCSchedulerClient() { reset(); } | 22 FakeCCSchedulerClient() { reset(); } |
23 void reset() | 23 void reset() |
24 { | 24 { |
25 m_actions.clear(); | 25 m_actions.clear(); |
26 m_hasMoreResourceUpdates = false; | |
27 m_drawWillHappen = true; | 26 m_drawWillHappen = true; |
28 m_swapWillHappenIfDrawHappens = true; | 27 m_swapWillHappenIfDrawHappens = true; |
29 m_numDraws = 0; | 28 m_numDraws = 0; |
30 } | 29 } |
31 | 30 |
32 void setHasMoreResourceUpdates(bool b) { m_hasMoreResourceUpdates = b; } | |
33 | |
34 int numDraws() const { return m_numDraws; } | 31 int numDraws() const { return m_numDraws; } |
35 int numActions() const { return static_cast<int>(m_actions.size()); } | 32 int numActions() const { return static_cast<int>(m_actions.size()); } |
36 const char* action(int i) const { return m_actions[i]; } | 33 const char* action(int i) const { return m_actions[i]; } |
37 | 34 |
38 bool hasAction(const char* action) const | 35 bool hasAction(const char* action) const |
39 { | 36 { |
40 for (size_t i = 0; i < m_actions.size(); i++) | 37 for (size_t i = 0; i < m_actions.size(); i++) |
41 if (!strcmp(m_actions[i], action)) | 38 if (!strcmp(m_actions[i], action)) |
42 return true; | 39 return true; |
43 return false; | 40 return false; |
44 } | 41 } |
45 | 42 |
46 virtual bool hasMoreResourceUpdates() const OVERRIDE { return m_hasMoreResou
rceUpdates; } | |
47 | |
48 virtual void scheduledActionBeginFrame() OVERRIDE { m_actions.push_back("sch
eduledActionBeginFrame"); } | 43 virtual void scheduledActionBeginFrame() OVERRIDE { m_actions.push_back("sch
eduledActionBeginFrame"); } |
49 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi
ble() OVERRIDE | 44 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi
ble() OVERRIDE |
50 { | 45 { |
51 m_actions.push_back("scheduledActionDrawAndSwapIfPossible"); | 46 m_actions.push_back("scheduledActionDrawAndSwapIfPossible"); |
52 m_numDraws++; | 47 m_numDraws++; |
53 return CCScheduledActionDrawAndSwapResult(m_drawWillHappen, m_drawWillHa
ppen && m_swapWillHappenIfDrawHappens); | 48 return CCScheduledActionDrawAndSwapResult(m_drawWillHappen, m_drawWillHa
ppen && m_swapWillHappenIfDrawHappens); |
54 } | 49 } |
55 | 50 |
56 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced(
) OVERRIDE | 51 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced(
) OVERRIDE |
57 { | 52 { |
(...skipping 26 matching lines...) Expand all Loading... |
84 scheduler->setVisible(true); | 79 scheduler->setVisible(true); |
85 scheduler->setCanDraw(true); | 80 scheduler->setCanDraw(true); |
86 | 81 |
87 // SetNeedsCommit should begin the frame. | 82 // SetNeedsCommit should begin the frame. |
88 scheduler->setNeedsCommit(); | 83 scheduler->setNeedsCommit(); |
89 EXPECT_EQ(1, client.numActions()); | 84 EXPECT_EQ(1, client.numActions()); |
90 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 85 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
91 EXPECT_FALSE(timeSource->active()); | 86 EXPECT_FALSE(timeSource->active()); |
92 client.reset(); | 87 client.reset(); |
93 | 88 |
94 // Since, hasMoreResourceUpdates is set to false, | 89 // Since, hasResourceUpdates is false, |
95 // beginFrameComplete should commit | 90 // beginFrameComplete should commit |
96 scheduler->beginFrameComplete(); | 91 scheduler->beginFrameComplete(false); |
97 EXPECT_EQ(1, client.numActions()); | 92 EXPECT_EQ(1, client.numActions()); |
98 EXPECT_STREQ("scheduledActionCommit", client.action(0)); | 93 EXPECT_STREQ("scheduledActionCommit", client.action(0)); |
99 EXPECT_TRUE(timeSource->active()); | 94 EXPECT_TRUE(timeSource->active()); |
100 client.reset(); | 95 client.reset(); |
101 | 96 |
102 // Tick should draw. | 97 // Tick should draw. |
103 timeSource->tick(); | 98 timeSource->tick(); |
104 EXPECT_EQ(1, client.numActions()); | 99 EXPECT_EQ(1, client.numActions()); |
105 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); | 100 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); |
106 EXPECT_FALSE(timeSource->active()); | 101 EXPECT_FALSE(timeSource->active()); |
(...skipping 14 matching lines...) Expand all Loading... |
121 | 116 |
122 // SetNedsCommit should begin the frame. | 117 // SetNedsCommit should begin the frame. |
123 scheduler->setNeedsCommit(); | 118 scheduler->setNeedsCommit(); |
124 EXPECT_EQ(1, client.numActions()); | 119 EXPECT_EQ(1, client.numActions()); |
125 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 120 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
126 client.reset(); | 121 client.reset(); |
127 | 122 |
128 // Now setNeedsCommit again. Calling here means we need a second frame. | 123 // Now setNeedsCommit again. Calling here means we need a second frame. |
129 scheduler->setNeedsCommit(); | 124 scheduler->setNeedsCommit(); |
130 | 125 |
131 // Since, hasMoreResourceUpdates is set to false, and another commit is | 126 // Since, hasResourceUpdates is false, and another commit is |
132 // needed, beginFrameComplete should commit, then begin another frame. | 127 // needed, beginFrameComplete should commit, then begin another frame. |
133 scheduler->beginFrameComplete(); | 128 scheduler->beginFrameComplete(false); |
134 EXPECT_EQ(1, client.numActions()); | 129 EXPECT_EQ(1, client.numActions()); |
135 EXPECT_STREQ("scheduledActionCommit", client.action(0)); | 130 EXPECT_STREQ("scheduledActionCommit", client.action(0)); |
136 client.reset(); | 131 client.reset(); |
137 | 132 |
138 // Tick should draw but then begin another frame. | 133 // Tick should draw but then begin another frame. |
139 timeSource->tick(); | 134 timeSource->tick(); |
140 EXPECT_FALSE(timeSource->active()); | 135 EXPECT_FALSE(timeSource->active()); |
141 EXPECT_EQ(2, client.numActions()); | 136 EXPECT_EQ(2, client.numActions()); |
142 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); | 137 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); |
143 EXPECT_STREQ("scheduledActionBeginFrame", client.action(1)); | 138 EXPECT_STREQ("scheduledActionBeginFrame", client.action(1)); |
(...skipping 13 matching lines...) Expand all Loading... |
157 scheduler->setMainThreadNeedsLayerTextures(); | 152 scheduler->setMainThreadNeedsLayerTextures(); |
158 EXPECT_EQ(2, client.numActions()); | 153 EXPECT_EQ(2, client.numActions()); |
159 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 154 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
160 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); | 155 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); |
161 client.reset(); | 156 client.reset(); |
162 | 157 |
163 // Compositor not scheduled to draw because textures are locked by main thre
ad | 158 // Compositor not scheduled to draw because textures are locked by main thre
ad |
164 EXPECT_FALSE(timeSource->active()); | 159 EXPECT_FALSE(timeSource->active()); |
165 | 160 |
166 // Trigger the commit | 161 // Trigger the commit |
167 scheduler->beginFrameComplete(); | 162 scheduler->beginFrameComplete(false); |
168 EXPECT_TRUE(timeSource->active()); | 163 EXPECT_TRUE(timeSource->active()); |
169 client.reset(); | 164 client.reset(); |
170 | 165 |
171 // Between commit and draw, texture acquisition for main thread delayed, | 166 // Between commit and draw, texture acquisition for main thread delayed, |
172 // and main thread blocks. | 167 // and main thread blocks. |
173 scheduler->setMainThreadNeedsLayerTextures(); | 168 scheduler->setMainThreadNeedsLayerTextures(); |
174 EXPECT_EQ(0, client.numActions()); | 169 EXPECT_EQ(0, client.numActions()); |
175 client.reset(); | 170 client.reset(); |
176 | 171 |
177 // Once compositor draw complete, the delayed texture acquisition fires. | 172 // Once compositor draw complete, the delayed texture acquisition fires. |
178 timeSource->tick(); | 173 timeSource->tick(); |
179 EXPECT_EQ(3, client.numActions()); | 174 EXPECT_EQ(3, client.numActions()); |
180 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); | 175 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); |
181 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); | 176 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); |
182 EXPECT_STREQ("scheduledActionBeginFrame", client.action(2)); | 177 EXPECT_STREQ("scheduledActionBeginFrame", client.action(2)); |
183 client.reset(); | 178 client.reset(); |
184 } | 179 } |
185 | 180 |
186 TEST(CCSchedulerTest, VisibilitySwitchWithTextureAcquisition) | 181 TEST(CCSchedulerTest, VisibilitySwitchWithTextureAcquisition) |
187 { | 182 { |
188 FakeCCSchedulerClient client; | 183 FakeCCSchedulerClient client; |
189 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); | 184 RefPtr<FakeCCTimeSource> timeSource = adoptRef(new FakeCCTimeSource()); |
190 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); | 185 OwnPtr<CCScheduler> scheduler = CCScheduler::create(&client, adoptPtr(new CC
FrameRateController(timeSource))); |
191 scheduler->setCanBeginFrame(true); | 186 scheduler->setCanBeginFrame(true); |
192 scheduler->setVisible(true); | 187 scheduler->setVisible(true); |
193 scheduler->setCanDraw(true); | 188 scheduler->setCanDraw(true); |
194 | 189 |
195 scheduler->setNeedsCommit(); | 190 scheduler->setNeedsCommit(); |
196 scheduler->beginFrameComplete(); | 191 scheduler->beginFrameComplete(false); |
197 scheduler->setMainThreadNeedsLayerTextures(); | 192 scheduler->setMainThreadNeedsLayerTextures(); |
198 client.reset(); | 193 client.reset(); |
199 // Verify that pending texture acquisition fires when visibility | 194 // Verify that pending texture acquisition fires when visibility |
200 // is lost in order to avoid a deadlock. | 195 // is lost in order to avoid a deadlock. |
201 scheduler->setVisible(false); | 196 scheduler->setVisible(false); |
202 EXPECT_EQ(1, client.numActions()); | 197 EXPECT_EQ(1, client.numActions()); |
203 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(0)); | 198 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(0)); |
204 client.reset(); | 199 client.reset(); |
205 | 200 |
206 // Regaining visibility with textures acquired by main thread while | 201 // Regaining visibility with textures acquired by main thread while |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 353 |
359 scheduler->setNeedsRedraw(); | 354 scheduler->setNeedsRedraw(); |
360 EXPECT_TRUE(scheduler->redrawPending()); | 355 EXPECT_TRUE(scheduler->redrawPending()); |
361 EXPECT_EQ(0, client.numDraws()); | 356 EXPECT_EQ(0, client.numDraws()); |
362 EXPECT_TRUE(timeSource->active()); | 357 EXPECT_TRUE(timeSource->active()); |
363 | 358 |
364 timeSource->tick(); | 359 timeSource->tick(); |
365 EXPECT_FALSE(timeSource->active()); | 360 EXPECT_FALSE(timeSource->active()); |
366 EXPECT_EQ(1, client.numDraws()); | 361 EXPECT_EQ(1, client.numDraws()); |
367 EXPECT_TRUE(scheduler->commitPending()); | 362 EXPECT_TRUE(scheduler->commitPending()); |
368 scheduler->beginFrameComplete(); | 363 scheduler->beginFrameComplete(false); |
369 | 364 |
370 timeSource->tick(); | 365 timeSource->tick(); |
371 EXPECT_EQ(2, client.numDraws()); | 366 EXPECT_EQ(2, client.numDraws()); |
372 EXPECT_FALSE(timeSource->active()); | 367 EXPECT_FALSE(timeSource->active()); |
373 EXPECT_FALSE(scheduler->redrawPending()); | 368 EXPECT_FALSE(scheduler->redrawPending()); |
374 } | 369 } |
375 | 370 |
376 // Tests that when a draw fails then the pending commit should not be dropped. | 371 // Tests that when a draw fails then the pending commit should not be dropped. |
377 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw) | 372 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw) |
378 { | 373 { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Get the compositor to do a scheduledActionDrawAndSwapForced. | 464 // Get the compositor to do a scheduledActionDrawAndSwapForced. |
470 scheduler->setNeedsRedraw(); | 465 scheduler->setNeedsRedraw(); |
471 scheduler->setNeedsForcedRedraw(); | 466 scheduler->setNeedsForcedRedraw(); |
472 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced")); | 467 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced")); |
473 | 468 |
474 // We should not have told the frame rate controller that we began a frame. | 469 // We should not have told the frame rate controller that we began a frame. |
475 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 470 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
476 } | 471 } |
477 | 472 |
478 } | 473 } |
OLD | NEW |