| 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 "cc/test/scheduler_test_common.h" | 9 #include "cc/test/scheduler_test_common.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using namespace cc; | 13 using namespace cc; |
| 14 using namespace WebKitTests; | 14 using namespace WebKitTests; |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class FakeCCSchedulerClient : public CCSchedulerClient { | 18 class FakeSchedulerClient : public SchedulerClient { |
| 19 public: | 19 public: |
| 20 FakeCCSchedulerClient() { reset(); } | 20 FakeSchedulerClient() { reset(); } |
| 21 void reset() | 21 void reset() |
| 22 { | 22 { |
| 23 m_actions.clear(); | 23 m_actions.clear(); |
| 24 m_drawWillHappen = true; | 24 m_drawWillHappen = true; |
| 25 m_swapWillHappenIfDrawHappens = true; | 25 m_swapWillHappenIfDrawHappens = true; |
| 26 m_numDraws = 0; | 26 m_numDraws = 0; |
| 27 } | 27 } |
| 28 | 28 |
| 29 int numDraws() const { return m_numDraws; } | 29 int numDraws() const { return m_numDraws; } |
| 30 int numActions() const { return static_cast<int>(m_actions.size()); } | 30 int numActions() const { return static_cast<int>(m_actions.size()); } |
| 31 const char* action(int i) const { return m_actions[i]; } | 31 const char* action(int i) const { return m_actions[i]; } |
| 32 | 32 |
| 33 bool hasAction(const char* action) const | 33 bool hasAction(const char* action) const |
| 34 { | 34 { |
| 35 for (size_t i = 0; i < m_actions.size(); i++) | 35 for (size_t i = 0; i < m_actions.size(); i++) |
| 36 if (!strcmp(m_actions[i], action)) | 36 if (!strcmp(m_actions[i], action)) |
| 37 return true; | 37 return true; |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual void scheduledActionBeginFrame() OVERRIDE { m_actions.push_back("sch
eduledActionBeginFrame"); } | 41 virtual void scheduledActionBeginFrame() OVERRIDE { m_actions.push_back("sch
eduledActionBeginFrame"); } |
| 42 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi
ble() OVERRIDE | 42 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossibl
e() OVERRIDE |
| 43 { | 43 { |
| 44 m_actions.push_back("scheduledActionDrawAndSwapIfPossible"); | 44 m_actions.push_back("scheduledActionDrawAndSwapIfPossible"); |
| 45 m_numDraws++; | 45 m_numDraws++; |
| 46 return CCScheduledActionDrawAndSwapResult(m_drawWillHappen, m_drawWillHa
ppen && m_swapWillHappenIfDrawHappens); | 46 return ScheduledActionDrawAndSwapResult(m_drawWillHappen, m_drawWillHapp
en && m_swapWillHappenIfDrawHappens); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced(
) OVERRIDE | 49 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced()
OVERRIDE |
| 50 { | 50 { |
| 51 m_actions.push_back("scheduledActionDrawAndSwapForced"); | 51 m_actions.push_back("scheduledActionDrawAndSwapForced"); |
| 52 return CCScheduledActionDrawAndSwapResult(true, m_swapWillHappenIfDrawHa
ppens); | 52 return ScheduledActionDrawAndSwapResult(true, m_swapWillHappenIfDrawHapp
ens); |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void scheduledActionCommit() OVERRIDE { m_actions.push_back("schedul
edActionCommit"); } | 55 virtual void scheduledActionCommit() OVERRIDE { m_actions.push_back("schedul
edActionCommit"); } |
| 56 virtual void scheduledActionBeginContextRecreation() OVERRIDE { m_actions.pu
sh_back("scheduledActionBeginContextRecreation"); } | 56 virtual void scheduledActionBeginContextRecreation() OVERRIDE { m_actions.pu
sh_back("scheduledActionBeginContextRecreation"); } |
| 57 virtual void scheduledActionAcquireLayerTexturesForMainThread() OVERRIDE { m
_actions.push_back("scheduledActionAcquireLayerTexturesForMainThread"); } | 57 virtual void scheduledActionAcquireLayerTexturesForMainThread() OVERRIDE { m
_actions.push_back("scheduledActionAcquireLayerTexturesForMainThread"); } |
| 58 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { } | 58 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { } |
| 59 | 59 |
| 60 void setDrawWillHappen(bool drawWillHappen) { m_drawWillHappen = drawWillHap
pen; } | 60 void setDrawWillHappen(bool drawWillHappen) { m_drawWillHappen = drawWillHap
pen; } |
| 61 void setSwapWillHappenIfDrawHappens(bool swapWillHappenIfDrawHappens) { m_sw
apWillHappenIfDrawHappens = swapWillHappenIfDrawHappens; } | 61 void setSwapWillHappenIfDrawHappens(bool swapWillHappenIfDrawHappens) { m_sw
apWillHappenIfDrawHappens = swapWillHappenIfDrawHappens; } |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 bool m_drawWillHappen; | 64 bool m_drawWillHappen; |
| 65 bool m_swapWillHappenIfDrawHappens; | 65 bool m_swapWillHappenIfDrawHappens; |
| 66 int m_numDraws; | 66 int m_numDraws; |
| 67 std::vector<const char*> m_actions; | 67 std::vector<const char*> m_actions; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TEST(CCSchedulerTest, RequestCommit) | 70 TEST(SchedulerTest, RequestCommit) |
| 71 { | 71 { |
| 72 FakeCCSchedulerClient client; | 72 FakeSchedulerClient client; |
| 73 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 73 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 74 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 74 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 75 scheduler->setCanBeginFrame(true); | 75 scheduler->setCanBeginFrame(true); |
| 76 scheduler->setVisible(true); | 76 scheduler->setVisible(true); |
| 77 scheduler->setCanDraw(true); | 77 scheduler->setCanDraw(true); |
| 78 | 78 |
| 79 // SetNeedsCommit should begin the frame. | 79 // SetNeedsCommit should begin the frame. |
| 80 scheduler->setNeedsCommit(); | 80 scheduler->setNeedsCommit(); |
| 81 EXPECT_EQ(1, client.numActions()); | 81 EXPECT_EQ(1, client.numActions()); |
| 82 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 82 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
| 83 EXPECT_FALSE(timeSource->active()); | 83 EXPECT_FALSE(timeSource->active()); |
| 84 client.reset(); | 84 client.reset(); |
| 85 | 85 |
| 86 // beginFrameComplete should commit | 86 // beginFrameComplete should commit |
| 87 scheduler->beginFrameComplete(); | 87 scheduler->beginFrameComplete(); |
| 88 EXPECT_EQ(1, client.numActions()); | 88 EXPECT_EQ(1, client.numActions()); |
| 89 EXPECT_STREQ("scheduledActionCommit", client.action(0)); | 89 EXPECT_STREQ("scheduledActionCommit", client.action(0)); |
| 90 EXPECT_TRUE(timeSource->active()); | 90 EXPECT_TRUE(timeSource->active()); |
| 91 client.reset(); | 91 client.reset(); |
| 92 | 92 |
| 93 // Tick should draw. | 93 // Tick should draw. |
| 94 timeSource->tick(); | 94 timeSource->tick(); |
| 95 EXPECT_EQ(1, client.numActions()); | 95 EXPECT_EQ(1, client.numActions()); |
| 96 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); | 96 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); |
| 97 EXPECT_FALSE(timeSource->active()); | 97 EXPECT_FALSE(timeSource->active()); |
| 98 client.reset(); | 98 client.reset(); |
| 99 | 99 |
| 100 // Timer should be off. | 100 // Timer should be off. |
| 101 EXPECT_FALSE(timeSource->active()); | 101 EXPECT_FALSE(timeSource->active()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST(CCSchedulerTest, RequestCommitAfterBeginFrame) | 104 TEST(SchedulerTest, RequestCommitAfterBeginFrame) |
| 105 { | 105 { |
| 106 FakeCCSchedulerClient client; | 106 FakeSchedulerClient client; |
| 107 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 107 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 108 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 108 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 109 scheduler->setCanBeginFrame(true); | 109 scheduler->setCanBeginFrame(true); |
| 110 scheduler->setVisible(true); | 110 scheduler->setVisible(true); |
| 111 scheduler->setCanDraw(true); | 111 scheduler->setCanDraw(true); |
| 112 | 112 |
| 113 // SetNedsCommit should begin the frame. | 113 // SetNedsCommit should begin the frame. |
| 114 scheduler->setNeedsCommit(); | 114 scheduler->setNeedsCommit(); |
| 115 EXPECT_EQ(1, client.numActions()); | 115 EXPECT_EQ(1, client.numActions()); |
| 116 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 116 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
| 117 client.reset(); | 117 client.reset(); |
| 118 | 118 |
| 119 // Now setNeedsCommit again. Calling here means we need a second frame. | 119 // Now setNeedsCommit again. Calling here means we need a second frame. |
| 120 scheduler->setNeedsCommit(); | 120 scheduler->setNeedsCommit(); |
| 121 | 121 |
| 122 // Since, another commit is needed, beginFrameComplete should commit, | 122 // Since, another commit is needed, beginFrameComplete should commit, |
| 123 // then begin another frame. | 123 // then begin another frame. |
| 124 scheduler->beginFrameComplete(); | 124 scheduler->beginFrameComplete(); |
| 125 EXPECT_EQ(1, client.numActions()); | 125 EXPECT_EQ(1, client.numActions()); |
| 126 EXPECT_STREQ("scheduledActionCommit", client.action(0)); | 126 EXPECT_STREQ("scheduledActionCommit", client.action(0)); |
| 127 client.reset(); | 127 client.reset(); |
| 128 | 128 |
| 129 // Tick should draw but then begin another frame. | 129 // Tick should draw but then begin another frame. |
| 130 timeSource->tick(); | 130 timeSource->tick(); |
| 131 EXPECT_FALSE(timeSource->active()); | 131 EXPECT_FALSE(timeSource->active()); |
| 132 EXPECT_EQ(2, client.numActions()); | 132 EXPECT_EQ(2, client.numActions()); |
| 133 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); | 133 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); |
| 134 EXPECT_STREQ("scheduledActionBeginFrame", client.action(1)); | 134 EXPECT_STREQ("scheduledActionBeginFrame", client.action(1)); |
| 135 client.reset(); | 135 client.reset(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST(CCSchedulerTest, TextureAcquisitionCollision) | 138 TEST(SchedulerTest, TextureAcquisitionCollision) |
| 139 { | 139 { |
| 140 FakeCCSchedulerClient client; | 140 FakeSchedulerClient client; |
| 141 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 141 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 142 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 142 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 143 scheduler->setCanBeginFrame(true); | 143 scheduler->setCanBeginFrame(true); |
| 144 scheduler->setVisible(true); | 144 scheduler->setVisible(true); |
| 145 scheduler->setCanDraw(true); | 145 scheduler->setCanDraw(true); |
| 146 | 146 |
| 147 scheduler->setNeedsCommit(); | 147 scheduler->setNeedsCommit(); |
| 148 scheduler->setMainThreadNeedsLayerTextures(); | 148 scheduler->setMainThreadNeedsLayerTextures(); |
| 149 EXPECT_EQ(2, client.numActions()); | 149 EXPECT_EQ(2, client.numActions()); |
| 150 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 150 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
| 151 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); | 151 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); |
| 152 client.reset(); | 152 client.reset(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 | 167 |
| 168 // Once compositor draw complete, the delayed texture acquisition fires. | 168 // Once compositor draw complete, the delayed texture acquisition fires. |
| 169 timeSource->tick(); | 169 timeSource->tick(); |
| 170 EXPECT_EQ(3, client.numActions()); | 170 EXPECT_EQ(3, client.numActions()); |
| 171 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); | 171 EXPECT_STREQ("scheduledActionDrawAndSwapIfPossible", client.action(0)); |
| 172 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); | 172 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(1)); |
| 173 EXPECT_STREQ("scheduledActionBeginFrame", client.action(2)); | 173 EXPECT_STREQ("scheduledActionBeginFrame", client.action(2)); |
| 174 client.reset(); | 174 client.reset(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST(CCSchedulerTest, VisibilitySwitchWithTextureAcquisition) | 177 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) |
| 178 { | 178 { |
| 179 FakeCCSchedulerClient client; | 179 FakeSchedulerClient client; |
| 180 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 180 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 181 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 181 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 182 scheduler->setCanBeginFrame(true); | 182 scheduler->setCanBeginFrame(true); |
| 183 scheduler->setVisible(true); | 183 scheduler->setVisible(true); |
| 184 scheduler->setCanDraw(true); | 184 scheduler->setCanDraw(true); |
| 185 | 185 |
| 186 scheduler->setNeedsCommit(); | 186 scheduler->setNeedsCommit(); |
| 187 scheduler->beginFrameComplete(); | 187 scheduler->beginFrameComplete(); |
| 188 scheduler->setMainThreadNeedsLayerTextures(); | 188 scheduler->setMainThreadNeedsLayerTextures(); |
| 189 client.reset(); | 189 client.reset(); |
| 190 // Verify that pending texture acquisition fires when visibility | 190 // Verify that pending texture acquisition fires when visibility |
| 191 // is lost in order to avoid a deadlock. | 191 // is lost in order to avoid a deadlock. |
| 192 scheduler->setVisible(false); | 192 scheduler->setVisible(false); |
| 193 EXPECT_EQ(1, client.numActions()); | 193 EXPECT_EQ(1, client.numActions()); |
| 194 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(0)); | 194 EXPECT_STREQ("scheduledActionAcquireLayerTexturesForMainThread", client.acti
on(0)); |
| 195 client.reset(); | 195 client.reset(); |
| 196 | 196 |
| 197 // Regaining visibility with textures acquired by main thread while | 197 // Regaining visibility with textures acquired by main thread while |
| 198 // compositor is waiting for first draw should result in a request | 198 // compositor is waiting for first draw should result in a request |
| 199 // for a new frame in order to escape a deadlock. | 199 // for a new frame in order to escape a deadlock. |
| 200 scheduler->setVisible(true); | 200 scheduler->setVisible(true); |
| 201 EXPECT_EQ(1, client.numActions()); | 201 EXPECT_EQ(1, client.numActions()); |
| 202 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); | 202 EXPECT_STREQ("scheduledActionBeginFrame", client.action(0)); |
| 203 client.reset(); | 203 client.reset(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 class SchedulerClientThatSetNeedsDrawInsideDraw : public FakeCCSchedulerClient { | 206 class SchedulerClientThatSetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 207 public: | 207 public: |
| 208 SchedulerClientThatSetNeedsDrawInsideDraw() | 208 SchedulerClientThatSetNeedsDrawInsideDraw() |
| 209 : m_scheduler(0) { } | 209 : m_scheduler(0) { } |
| 210 | 210 |
| 211 void setScheduler(CCScheduler* scheduler) { m_scheduler = scheduler; } | 211 void setScheduler(Scheduler* scheduler) { m_scheduler = scheduler; } |
| 212 | 212 |
| 213 virtual void scheduledActionBeginFrame() OVERRIDE { } | 213 virtual void scheduledActionBeginFrame() OVERRIDE { } |
| 214 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi
ble() OVERRIDE | 214 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossibl
e() OVERRIDE |
| 215 { | 215 { |
| 216 // Only setNeedsRedraw the first time this is called | 216 // Only setNeedsRedraw the first time this is called |
| 217 if (!m_numDraws) | 217 if (!m_numDraws) |
| 218 m_scheduler->setNeedsRedraw(); | 218 m_scheduler->setNeedsRedraw(); |
| 219 return FakeCCSchedulerClient::scheduledActionDrawAndSwapIfPossible(); | 219 return FakeSchedulerClient::scheduledActionDrawAndSwapIfPossible(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced(
) OVERRIDE | 222 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced()
OVERRIDE |
| 223 { | 223 { |
| 224 ASSERT_NOT_REACHED(); | 224 ASSERT_NOT_REACHED(); |
| 225 return CCScheduledActionDrawAndSwapResult(true, true); | 225 return ScheduledActionDrawAndSwapResult(true, true); |
| 226 } | 226 } |
| 227 | 227 |
| 228 virtual void scheduledActionCommit() OVERRIDE { } | 228 virtual void scheduledActionCommit() OVERRIDE { } |
| 229 virtual void scheduledActionBeginContextRecreation() OVERRIDE { } | 229 virtual void scheduledActionBeginContextRecreation() OVERRIDE { } |
| 230 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { } | 230 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { } |
| 231 | 231 |
| 232 protected: | 232 protected: |
| 233 CCScheduler* m_scheduler; | 233 Scheduler* m_scheduler; |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 // Tests for two different situations: | 236 // Tests for two different situations: |
| 237 // 1. the scheduler dropping setNeedsRedraw requests that happen inside | 237 // 1. the scheduler dropping setNeedsRedraw requests that happen inside |
| 238 // a scheduledActionDrawAndSwap | 238 // a scheduledActionDrawAndSwap |
| 239 // 2. the scheduler drawing twice inside a single tick | 239 // 2. the scheduler drawing twice inside a single tick |
| 240 TEST(CCSchedulerTest, RequestRedrawInsideDraw) | 240 TEST(SchedulerTest, RequestRedrawInsideDraw) |
| 241 { | 241 { |
| 242 SchedulerClientThatSetNeedsDrawInsideDraw client; | 242 SchedulerClientThatSetNeedsDrawInsideDraw client; |
| 243 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 243 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 244 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 244 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 245 client.setScheduler(scheduler.get()); | 245 client.setScheduler(scheduler.get()); |
| 246 scheduler->setCanBeginFrame(true); | 246 scheduler->setCanBeginFrame(true); |
| 247 scheduler->setVisible(true); | 247 scheduler->setVisible(true); |
| 248 scheduler->setCanDraw(true); | 248 scheduler->setCanDraw(true); |
| 249 | 249 |
| 250 scheduler->setNeedsRedraw(); | 250 scheduler->setNeedsRedraw(); |
| 251 EXPECT_TRUE(scheduler->redrawPending()); | 251 EXPECT_TRUE(scheduler->redrawPending()); |
| 252 EXPECT_TRUE(timeSource->active()); | 252 EXPECT_TRUE(timeSource->active()); |
| 253 EXPECT_EQ(0, client.numDraws()); | 253 EXPECT_EQ(0, client.numDraws()); |
| 254 | 254 |
| 255 timeSource->tick(); | 255 timeSource->tick(); |
| 256 EXPECT_EQ(1, client.numDraws()); | 256 EXPECT_EQ(1, client.numDraws()); |
| 257 EXPECT_TRUE(scheduler->redrawPending()); | 257 EXPECT_TRUE(scheduler->redrawPending()); |
| 258 EXPECT_TRUE(timeSource->active()); | 258 EXPECT_TRUE(timeSource->active()); |
| 259 | 259 |
| 260 timeSource->tick(); | 260 timeSource->tick(); |
| 261 EXPECT_EQ(2, client.numDraws()); | 261 EXPECT_EQ(2, client.numDraws()); |
| 262 EXPECT_FALSE(scheduler->redrawPending()); | 262 EXPECT_FALSE(scheduler->redrawPending()); |
| 263 EXPECT_FALSE(timeSource->active()); | 263 EXPECT_FALSE(timeSource->active()); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Test that requesting redraw inside a failed draw doesn't lose the request. | 266 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 267 TEST(CCSchedulerTest, RequestRedrawInsideFailedDraw) | 267 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) |
| 268 { | 268 { |
| 269 SchedulerClientThatSetNeedsDrawInsideDraw client; | 269 SchedulerClientThatSetNeedsDrawInsideDraw client; |
| 270 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 270 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 271 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 271 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 272 client.setScheduler(scheduler.get()); | 272 client.setScheduler(scheduler.get()); |
| 273 scheduler->setCanBeginFrame(true); | 273 scheduler->setCanBeginFrame(true); |
| 274 scheduler->setVisible(true); | 274 scheduler->setVisible(true); |
| 275 scheduler->setCanDraw(true); | 275 scheduler->setCanDraw(true); |
| 276 client.setDrawWillHappen(false); | 276 client.setDrawWillHappen(false); |
| 277 | 277 |
| 278 scheduler->setNeedsRedraw(); | 278 scheduler->setNeedsRedraw(); |
| 279 EXPECT_TRUE(scheduler->redrawPending()); | 279 EXPECT_TRUE(scheduler->redrawPending()); |
| 280 EXPECT_TRUE(timeSource->active()); | 280 EXPECT_TRUE(timeSource->active()); |
| 281 EXPECT_EQ(0, client.numDraws()); | 281 EXPECT_EQ(0, client.numDraws()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 298 | 298 |
| 299 // Draw successfully. | 299 // Draw successfully. |
| 300 client.setDrawWillHappen(true); | 300 client.setDrawWillHappen(true); |
| 301 timeSource->tick(); | 301 timeSource->tick(); |
| 302 EXPECT_EQ(3, client.numDraws()); | 302 EXPECT_EQ(3, client.numDraws()); |
| 303 EXPECT_TRUE(scheduler->commitPending()); | 303 EXPECT_TRUE(scheduler->commitPending()); |
| 304 EXPECT_FALSE(scheduler->redrawPending()); | 304 EXPECT_FALSE(scheduler->redrawPending()); |
| 305 EXPECT_FALSE(timeSource->active()); | 305 EXPECT_FALSE(timeSource->active()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeCCSchedulerClient
{ | 308 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 309 public: | 309 public: |
| 310 SchedulerClientThatSetNeedsCommitInsideDraw() | 310 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 311 : m_scheduler(0) { } | 311 : m_scheduler(0) { } |
| 312 | 312 |
| 313 void setScheduler(CCScheduler* scheduler) { m_scheduler = scheduler; } | 313 void setScheduler(Scheduler* scheduler) { m_scheduler = scheduler; } |
| 314 | 314 |
| 315 virtual void scheduledActionBeginFrame() OVERRIDE { } | 315 virtual void scheduledActionBeginFrame() OVERRIDE { } |
| 316 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi
ble() OVERRIDE | 316 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossibl
e() OVERRIDE |
| 317 { | 317 { |
| 318 // Only setNeedsCommit the first time this is called | 318 // Only setNeedsCommit the first time this is called |
| 319 if (!m_numDraws) | 319 if (!m_numDraws) |
| 320 m_scheduler->setNeedsCommit(); | 320 m_scheduler->setNeedsCommit(); |
| 321 return FakeCCSchedulerClient::scheduledActionDrawAndSwapIfPossible(); | 321 return FakeSchedulerClient::scheduledActionDrawAndSwapIfPossible(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced(
) OVERRIDE | 324 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced()
OVERRIDE |
| 325 { | 325 { |
| 326 ASSERT_NOT_REACHED(); | 326 ASSERT_NOT_REACHED(); |
| 327 return CCScheduledActionDrawAndSwapResult(true, true); | 327 return ScheduledActionDrawAndSwapResult(true, true); |
| 328 } | 328 } |
| 329 | 329 |
| 330 virtual void scheduledActionCommit() OVERRIDE { } | 330 virtual void scheduledActionCommit() OVERRIDE { } |
| 331 virtual void scheduledActionBeginContextRecreation() OVERRIDE { } | 331 virtual void scheduledActionBeginContextRecreation() OVERRIDE { } |
| 332 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { } | 332 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE { } |
| 333 | 333 |
| 334 protected: | 334 protected: |
| 335 CCScheduler* m_scheduler; | 335 Scheduler* m_scheduler; |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 // Tests for the scheduler infinite-looping on setNeedsCommit requests that | 338 // Tests for the scheduler infinite-looping on setNeedsCommit requests that |
| 339 // happen inside a scheduledActionDrawAndSwap | 339 // happen inside a scheduledActionDrawAndSwap |
| 340 TEST(CCSchedulerTest, RequestCommitInsideDraw) | 340 TEST(SchedulerTest, RequestCommitInsideDraw) |
| 341 { | 341 { |
| 342 SchedulerClientThatSetNeedsCommitInsideDraw client; | 342 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 343 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 343 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 344 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 344 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 345 client.setScheduler(scheduler.get()); | 345 client.setScheduler(scheduler.get()); |
| 346 scheduler->setCanBeginFrame(true); | 346 scheduler->setCanBeginFrame(true); |
| 347 scheduler->setVisible(true); | 347 scheduler->setVisible(true); |
| 348 scheduler->setCanDraw(true); | 348 scheduler->setCanDraw(true); |
| 349 | 349 |
| 350 scheduler->setNeedsRedraw(); | 350 scheduler->setNeedsRedraw(); |
| 351 EXPECT_TRUE(scheduler->redrawPending()); | 351 EXPECT_TRUE(scheduler->redrawPending()); |
| 352 EXPECT_EQ(0, client.numDraws()); | 352 EXPECT_EQ(0, client.numDraws()); |
| 353 EXPECT_TRUE(timeSource->active()); | 353 EXPECT_TRUE(timeSource->active()); |
| 354 | 354 |
| 355 timeSource->tick(); | 355 timeSource->tick(); |
| 356 EXPECT_FALSE(timeSource->active()); | 356 EXPECT_FALSE(timeSource->active()); |
| 357 EXPECT_EQ(1, client.numDraws()); | 357 EXPECT_EQ(1, client.numDraws()); |
| 358 EXPECT_TRUE(scheduler->commitPending()); | 358 EXPECT_TRUE(scheduler->commitPending()); |
| 359 scheduler->beginFrameComplete(); | 359 scheduler->beginFrameComplete(); |
| 360 | 360 |
| 361 timeSource->tick(); | 361 timeSource->tick(); |
| 362 EXPECT_EQ(2, client.numDraws()); | 362 EXPECT_EQ(2, client.numDraws()); |
| 363 EXPECT_FALSE(timeSource->active()); | 363 EXPECT_FALSE(timeSource->active()); |
| 364 EXPECT_FALSE(scheduler->redrawPending()); | 364 EXPECT_FALSE(scheduler->redrawPending()); |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Tests that when a draw fails then the pending commit should not be dropped. | 367 // Tests that when a draw fails then the pending commit should not be dropped. |
| 368 TEST(CCSchedulerTest, RequestCommitInsideFailedDraw) | 368 TEST(SchedulerTest, RequestCommitInsideFailedDraw) |
| 369 { | 369 { |
| 370 SchedulerClientThatSetNeedsDrawInsideDraw client; | 370 SchedulerClientThatSetNeedsDrawInsideDraw client; |
| 371 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 371 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 372 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, make_scoped
_ptr(new CCFrameRateController(timeSource))); | 372 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, make_scoped_ptr
(new FrameRateController(timeSource))); |
| 373 client.setScheduler(scheduler.get()); | 373 client.setScheduler(scheduler.get()); |
| 374 scheduler->setCanBeginFrame(true); | 374 scheduler->setCanBeginFrame(true); |
| 375 scheduler->setVisible(true); | 375 scheduler->setVisible(true); |
| 376 scheduler->setCanDraw(true); | 376 scheduler->setCanDraw(true); |
| 377 client.setDrawWillHappen(false); | 377 client.setDrawWillHappen(false); |
| 378 | 378 |
| 379 scheduler->setNeedsRedraw(); | 379 scheduler->setNeedsRedraw(); |
| 380 EXPECT_TRUE(scheduler->redrawPending()); | 380 EXPECT_TRUE(scheduler->redrawPending()); |
| 381 EXPECT_TRUE(timeSource->active()); | 381 EXPECT_TRUE(timeSource->active()); |
| 382 EXPECT_EQ(0, client.numDraws()); | 382 EXPECT_EQ(0, client.numDraws()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 399 | 399 |
| 400 // Draw successfully. | 400 // Draw successfully. |
| 401 client.setDrawWillHappen(true); | 401 client.setDrawWillHappen(true); |
| 402 timeSource->tick(); | 402 timeSource->tick(); |
| 403 EXPECT_EQ(3, client.numDraws()); | 403 EXPECT_EQ(3, client.numDraws()); |
| 404 EXPECT_TRUE(scheduler->commitPending()); | 404 EXPECT_TRUE(scheduler->commitPending()); |
| 405 EXPECT_FALSE(scheduler->redrawPending()); | 405 EXPECT_FALSE(scheduler->redrawPending()); |
| 406 EXPECT_FALSE(timeSource->active()); | 406 EXPECT_FALSE(timeSource->active()); |
| 407 } | 407 } |
| 408 | 408 |
| 409 TEST(CCSchedulerTest, NoBeginFrameWhenDrawFails) | 409 TEST(SchedulerTest, NoBeginFrameWhenDrawFails) |
| 410 { | 410 { |
| 411 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 411 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 412 SchedulerClientThatSetNeedsCommitInsideDraw client; | 412 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 413 scoped_ptr<FakeCCFrameRateController> controller(new FakeCCFrameRateControll
er(timeSource)); | 413 scoped_ptr<FakeFrameRateController> controller(new FakeFrameRateController(t
imeSource)); |
| 414 FakeCCFrameRateController* controllerPtr = controller.get(); | 414 FakeFrameRateController* controllerPtr = controller.get(); |
| 415 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, controller.
PassAs<CCFrameRateController>()); | 415 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, controller.Pass
As<FrameRateController>()); |
| 416 client.setScheduler(scheduler.get()); | 416 client.setScheduler(scheduler.get()); |
| 417 scheduler->setCanBeginFrame(true); | 417 scheduler->setCanBeginFrame(true); |
| 418 scheduler->setVisible(true); | 418 scheduler->setVisible(true); |
| 419 scheduler->setCanDraw(true); | 419 scheduler->setCanDraw(true); |
| 420 | 420 |
| 421 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 421 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
| 422 | 422 |
| 423 scheduler->setNeedsRedraw(); | 423 scheduler->setNeedsRedraw(); |
| 424 EXPECT_TRUE(scheduler->redrawPending()); | 424 EXPECT_TRUE(scheduler->redrawPending()); |
| 425 EXPECT_TRUE(timeSource->active()); | 425 EXPECT_TRUE(timeSource->active()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 436 EXPECT_TRUE(scheduler->redrawPending()); | 436 EXPECT_TRUE(scheduler->redrawPending()); |
| 437 EXPECT_TRUE(timeSource->active()); | 437 EXPECT_TRUE(timeSource->active()); |
| 438 | 438 |
| 439 // Fail to draw, this should not start a frame. | 439 // Fail to draw, this should not start a frame. |
| 440 client.setDrawWillHappen(false); | 440 client.setDrawWillHappen(false); |
| 441 timeSource->tick(); | 441 timeSource->tick(); |
| 442 EXPECT_EQ(2, client.numDraws()); | 442 EXPECT_EQ(2, client.numDraws()); |
| 443 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 443 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST(CCSchedulerTest, NoBeginFrameWhenSwapFailsDuringForcedCommit) | 446 TEST(SchedulerTest, NoBeginFrameWhenSwapFailsDuringForcedCommit) |
| 447 { | 447 { |
| 448 scoped_refptr<FakeCCTimeSource> timeSource(new FakeCCTimeSource()); | 448 scoped_refptr<FakeTimeSource> timeSource(new FakeTimeSource()); |
| 449 FakeCCSchedulerClient client; | 449 FakeSchedulerClient client; |
| 450 scoped_ptr<FakeCCFrameRateController> controller(new FakeCCFrameRateControll
er(timeSource)); | 450 scoped_ptr<FakeFrameRateController> controller(new FakeFrameRateController(t
imeSource)); |
| 451 FakeCCFrameRateController* controllerPtr = controller.get(); | 451 FakeFrameRateController* controllerPtr = controller.get(); |
| 452 scoped_ptr<CCScheduler> scheduler = CCScheduler::create(&client, controller.
PassAs<CCFrameRateController>()); | 452 scoped_ptr<Scheduler> scheduler = Scheduler::create(&client, controller.Pass
As<FrameRateController>()); |
| 453 | 453 |
| 454 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 454 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
| 455 | 455 |
| 456 // Tell the client that it will fail to swap. | 456 // Tell the client that it will fail to swap. |
| 457 client.setDrawWillHappen(true); | 457 client.setDrawWillHappen(true); |
| 458 client.setSwapWillHappenIfDrawHappens(false); | 458 client.setSwapWillHappenIfDrawHappens(false); |
| 459 | 459 |
| 460 // Get the compositor to do a scheduledActionDrawAndSwapForced. | 460 // Get the compositor to do a scheduledActionDrawAndSwapForced. |
| 461 scheduler->setNeedsRedraw(); | 461 scheduler->setNeedsRedraw(); |
| 462 scheduler->setNeedsForcedRedraw(); | 462 scheduler->setNeedsForcedRedraw(); |
| 463 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced")); | 463 EXPECT_TRUE(client.hasAction("scheduledActionDrawAndSwapForced")); |
| 464 | 464 |
| 465 // We should not have told the frame rate controller that we began a frame. | 465 // We should not have told the frame rate controller that we began a frame. |
| 466 EXPECT_EQ(0, controllerPtr->numFramesPending()); | 466 EXPECT_EQ(0, controllerPtr->numFramesPending()); |
| 467 } | 467 } |
| 468 | 468 |
| 469 } | 469 } |
| OLD | NEW |