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