| 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 | |
| 5 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 6 | 5 |
| 7 #include <string> | 6 #include <string> |
| 8 #include <vector> | 7 #include <vector> |
| 9 | 8 |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "cc/test/scheduler_test_common.h" | 10 #include "cc/test/scheduler_test_common.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Scheduler Implementation. | 70 // Scheduler Implementation. |
| 72 virtual void SetNeedsBeginFrameOnImplThread(bool enable) OVERRIDE { | 71 virtual void SetNeedsBeginFrameOnImplThread(bool enable) OVERRIDE { |
| 73 actions_.push_back("SetNeedsBeginFrameOnImplThread"); | 72 actions_.push_back("SetNeedsBeginFrameOnImplThread"); |
| 74 states_.push_back(scheduler_->StateAsStringForTesting()); | 73 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 75 needs_begin_frame_ = enable; | 74 needs_begin_frame_ = enable; |
| 76 } | 75 } |
| 77 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE { | 76 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE { |
| 78 actions_.push_back("ScheduledActionSendBeginFrameToMainThread"); | 77 actions_.push_back("ScheduledActionSendBeginFrameToMainThread"); |
| 79 states_.push_back(scheduler_->StateAsStringForTesting()); | 78 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 80 } | 79 } |
| 81 virtual ScheduledActionDrawAndSwapResult | 80 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 82 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 81 OVERRIDE { |
| 83 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 82 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
| 84 states_.push_back(scheduler_->StateAsStringForTesting()); | 83 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 85 num_draws_++; | 84 num_draws_++; |
| 86 return ScheduledActionDrawAndSwapResult(draw_will_happen_, | 85 return DrawSwapReadbackResult( |
| 87 draw_will_happen_ && | 86 draw_will_happen_, |
| 88 swap_will_happen_if_draw_happens_); | 87 draw_will_happen_ && swap_will_happen_if_draw_happens_, |
| 88 false); |
| 89 } | 89 } |
| 90 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 90 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() |
| 91 OVERRIDE { | 91 OVERRIDE { |
| 92 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 92 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
| 93 states_.push_back(scheduler_->StateAsStringForTesting()); | 93 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 94 return ScheduledActionDrawAndSwapResult(true, | 94 return DrawSwapReadbackResult( |
| 95 swap_will_happen_if_draw_happens_); | 95 true, swap_will_happen_if_draw_happens_, false); |
| 96 } |
| 97 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() |
| 98 OVERRIDE { |
| 99 actions_.push_back("ScheduledActionDrawAndReadback"); |
| 100 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 101 return DrawSwapReadbackResult(true, false, true); |
| 96 } | 102 } |
| 97 virtual void ScheduledActionCommit() OVERRIDE { | 103 virtual void ScheduledActionCommit() OVERRIDE { |
| 98 actions_.push_back("ScheduledActionCommit"); | 104 actions_.push_back("ScheduledActionCommit"); |
| 99 states_.push_back(scheduler_->StateAsStringForTesting()); | 105 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 100 } | 106 } |
| 101 virtual void ScheduledActionCheckForCompletedTileUploads() OVERRIDE { | 107 virtual void ScheduledActionCheckForCompletedTileUploads() OVERRIDE { |
| 102 actions_.push_back("ScheduledActionCheckForCompletedTileUploads"); | 108 actions_.push_back("ScheduledActionCheckForCompletedTileUploads"); |
| 103 states_.push_back(scheduler_->StateAsStringForTesting()); | 109 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 104 } | 110 } |
| 105 virtual void ScheduledActionActivatePendingTreeIfNeeded() OVERRIDE { | 111 virtual void ScheduledActionActivatePendingTreeIfNeeded() OVERRIDE { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 118 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | 124 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
| 119 return base::TimeDelta(); | 125 return base::TimeDelta(); |
| 120 } | 126 } |
| 121 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { | 127 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { |
| 122 return base::TimeDelta(); | 128 return base::TimeDelta(); |
| 123 } | 129 } |
| 124 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 130 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
| 125 return base::TimeDelta(); | 131 return base::TimeDelta(); |
| 126 } | 132 } |
| 127 | 133 |
| 134 virtual void PostBeginFrameDeadline(const base::Closure& closure, |
| 135 base::TimeTicks deadline) OVERRIDE { |
| 136 actions_.push_back("PostBeginFrameDeadlineTask"); |
| 137 states_.push_back(scheduler_->StateAsStringForTesting()); |
| 138 } |
| 139 |
| 140 virtual void DidBeginFrameDeadlineOnImplThread() OVERRIDE { |
| 141 } |
| 142 |
| 128 protected: | 143 protected: |
| 129 bool needs_begin_frame_; | 144 bool needs_begin_frame_; |
| 130 bool draw_will_happen_; | 145 bool draw_will_happen_; |
| 131 bool swap_will_happen_if_draw_happens_; | 146 bool swap_will_happen_if_draw_happens_; |
| 132 int num_draws_; | 147 int num_draws_; |
| 133 std::vector<const char*> actions_; | 148 std::vector<const char*> actions_; |
| 134 std::vector<std::string> states_; | 149 std::vector<std::string> states_; |
| 135 scoped_ptr<Scheduler> scheduler_; | 150 scoped_ptr<Scheduler> scheduler_; |
| 136 }; | 151 }; |
| 137 | 152 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 154 SchedulerSettings default_scheduler_settings; | 169 SchedulerSettings default_scheduler_settings; |
| 155 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 170 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 156 scheduler->SetCanStart(); | 171 scheduler->SetCanStart(); |
| 157 scheduler->SetVisible(true); | 172 scheduler->SetVisible(true); |
| 158 scheduler->SetCanDraw(true); | 173 scheduler->SetCanDraw(true); |
| 159 | 174 |
| 160 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 175 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 161 client.Reset(); | 176 client.Reset(); |
| 162 scheduler->DidCreateAndInitializeOutputSurface(); | 177 scheduler->DidCreateAndInitializeOutputSurface(); |
| 163 | 178 |
| 164 // SetNeedsCommit should begin the frame. | 179 // SetNeedsCommit should begin the frame on the next BeginFrame. |
| 165 scheduler->SetNeedsCommit(); | 180 scheduler->SetNeedsCommit(); |
| 181 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 182 EXPECT_TRUE(client.needs_begin_frame()); |
| 183 client.Reset(); |
| 184 |
| 185 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 166 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 186 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 167 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 187 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 188 EXPECT_TRUE(client.needs_begin_frame()); |
| 189 client.Reset(); |
| 190 |
| 191 // If we don't swap on the deadline, we need to request another BeginFrame. |
| 192 scheduler->OnBeginFrameDeadline(); |
| 193 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 168 EXPECT_TRUE(client.needs_begin_frame()); | 194 EXPECT_TRUE(client.needs_begin_frame()); |
| 169 client.Reset(); | 195 client.Reset(); |
| 170 | 196 |
| 171 // FinishCommit should commit | 197 // FinishCommit should commit |
| 172 scheduler->FinishCommit(); | 198 scheduler->FinishCommit(); |
| 173 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); | 199 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 174 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | |
| 175 EXPECT_TRUE(client.needs_begin_frame()); | 200 EXPECT_TRUE(client.needs_begin_frame()); |
| 176 client.Reset(); | 201 client.Reset(); |
| 177 | 202 |
| 178 // BeginFrame should draw. | 203 // BeginFrame should prepare the draw. |
| 179 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 204 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 180 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 205 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 181 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 206 EXPECT_TRUE(client.needs_begin_frame()); |
| 207 client.Reset(); |
| 208 |
| 209 // BeginFrame deadline should draw. |
| 210 scheduler->OnBeginFrameDeadline(); |
| 211 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 212 client.Reset(); |
| 213 |
| 214 // The following BeginFrame deadline should SetNeedsBeginFrame(false) to avoid |
| 215 // excessive toggles. |
| 216 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 217 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 218 client.Reset(); |
| 219 |
| 220 scheduler->OnBeginFrameDeadline(); |
| 221 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 182 EXPECT_FALSE(client.needs_begin_frame()); | 222 EXPECT_FALSE(client.needs_begin_frame()); |
| 183 client.Reset(); | 223 client.Reset(); |
| 184 } | 224 } |
| 185 | 225 |
| 186 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { | 226 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { |
| 187 FakeSchedulerClient client; | 227 FakeSchedulerClient client; |
| 188 SchedulerSettings default_scheduler_settings; | 228 SchedulerSettings default_scheduler_settings; |
| 189 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 229 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 190 scheduler->SetCanStart(); | 230 scheduler->SetCanStart(); |
| 191 scheduler->SetVisible(true); | 231 scheduler->SetVisible(true); |
| 192 scheduler->SetCanDraw(true); | 232 scheduler->SetCanDraw(true); |
| 193 | 233 |
| 194 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 234 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 195 client.Reset(); | |
| 196 scheduler->DidCreateAndInitializeOutputSurface(); | 235 scheduler->DidCreateAndInitializeOutputSurface(); |
| 197 | |
| 198 // SetNedsCommit should begin the frame. | |
| 199 scheduler->SetNeedsCommit(); | |
| 200 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | |
| 201 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | |
| 202 client.Reset(); | 236 client.Reset(); |
| 203 | 237 |
| 204 // Now SetNeedsCommit again. Calling here means we need a second frame. | 238 // SetNeddsCommit should begin the frame. |
| 205 scheduler->SetNeedsCommit(); | 239 scheduler->SetNeedsCommit(); |
| 206 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 1); | 240 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 241 client.Reset(); |
| 242 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 243 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 244 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 245 EXPECT_TRUE(client.needs_begin_frame()); |
| 207 client.Reset(); | 246 client.Reset(); |
| 208 | 247 |
| 209 // Since another commit is needed, FinishCommit should commit, | 248 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 210 // then begin another frame. | 249 scheduler->SetNeedsCommit(); |
| 250 EXPECT_EQ(client.num_actions_(), 0); |
| 251 client.Reset(); |
| 252 |
| 253 // Finish the first commit. |
| 211 scheduler->FinishCommit(); | 254 scheduler->FinishCommit(); |
| 212 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); | 255 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 213 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 256 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 257 client.Reset(); |
| 258 scheduler->OnBeginFrameDeadline(); |
| 259 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 214 client.Reset(); | 260 client.Reset(); |
| 215 | 261 |
| 216 // Tick should draw but then begin another frame. | 262 // Since another commit is needed, the next BeginFrame should initiate |
| 263 // the second commit. |
| 217 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 264 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 218 EXPECT_TRUE(client.needs_begin_frame()); | 265 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 219 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 266 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 220 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); | |
| 221 client.Reset(); | 267 client.Reset(); |
| 222 | 268 |
| 223 // Go back to quiescent state and verify we no longer request BeginFrames. | 269 // Finishing the commit before the deadline should post a new deadline task |
| 270 // to trigger the deadline early. |
| 224 scheduler->FinishCommit(); | 271 scheduler->FinishCommit(); |
| 272 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 273 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 274 client.Reset(); |
| 275 scheduler->OnBeginFrameDeadline(); |
| 276 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 277 EXPECT_TRUE(client.needs_begin_frame()); |
| 278 |
| 279 // On the next BeginFrame, go back to quiescent state and verify we no longer |
| 280 // request BeginFrames. |
| 225 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 281 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 282 scheduler->OnBeginFrameDeadline(); |
| 226 EXPECT_FALSE(client.needs_begin_frame()); | 283 EXPECT_FALSE(client.needs_begin_frame()); |
| 284 client.Reset(); |
| 227 } | 285 } |
| 228 | 286 |
| 229 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | 287 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| 230 FakeSchedulerClient client; | 288 FakeSchedulerClient client; |
| 231 SchedulerSettings default_scheduler_settings; | 289 SchedulerSettings default_scheduler_settings; |
| 232 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 290 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 233 scheduler->SetCanStart(); | 291 scheduler->SetCanStart(); |
| 234 scheduler->SetVisible(true); | 292 scheduler->SetVisible(true); |
| 235 scheduler->SetCanDraw(true); | 293 scheduler->SetCanDraw(true); |
| 236 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 294 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 237 | 295 |
| 238 client.Reset(); | 296 client.Reset(); |
| 239 scheduler->DidCreateAndInitializeOutputSurface(); | 297 scheduler->DidCreateAndInitializeOutputSurface(); |
| 240 scheduler->SetNeedsRedraw(); | 298 scheduler->SetNeedsRedraw(); |
| 241 EXPECT_TRUE(scheduler->RedrawPending()); | 299 EXPECT_TRUE(scheduler->RedrawPending()); |
| 242 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 300 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 243 EXPECT_TRUE(client.needs_begin_frame()); | 301 EXPECT_TRUE(client.needs_begin_frame()); |
| 244 | 302 |
| 245 client.Reset(); | 303 client.Reset(); |
| 246 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 304 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 247 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 305 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 248 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 306 |
| 307 client.Reset(); |
| 308 scheduler->OnBeginFrameDeadline(); |
| 309 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 249 EXPECT_FALSE(scheduler->RedrawPending()); | 310 EXPECT_FALSE(scheduler->RedrawPending()); |
| 250 EXPECT_FALSE(client.needs_begin_frame()); | |
| 251 | 311 |
| 252 client.Reset(); | 312 client.Reset(); |
| 253 scheduler->SetMainThreadNeedsLayerTextures(); | 313 scheduler->SetMainThreadNeedsLayerTextures(); |
| 254 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 314 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 255 client); | 315 client); |
| 256 | 316 |
| 257 // We should request a BeginFrame in anticipation of a draw. | 317 // We should request a BeginFrame in anticipation of a draw. |
| 258 client.Reset(); | 318 client.Reset(); |
| 259 scheduler->SetNeedsRedraw(); | 319 scheduler->SetNeedsRedraw(); |
| 260 EXPECT_TRUE(scheduler->RedrawPending()); | 320 EXPECT_TRUE(scheduler->RedrawPending()); |
| 261 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 321 EXPECT_EQ(0, client.num_actions_()); |
| 262 EXPECT_TRUE(client.needs_begin_frame()); | |
| 263 | 322 |
| 264 // No draw happens since the textures are acquired by the main thread. | 323 // No draw happens since the textures are acquired by the main thread. |
| 265 client.Reset(); | 324 client.Reset(); |
| 266 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 325 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 326 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 327 |
| 328 client.Reset(); |
| 329 scheduler->OnBeginFrameDeadline(); |
| 267 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 330 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 268 EXPECT_TRUE(scheduler->RedrawPending()); | 331 EXPECT_TRUE(scheduler->RedrawPending()); |
| 269 EXPECT_TRUE(client.needs_begin_frame()); | 332 EXPECT_TRUE(client.needs_begin_frame()); |
| 270 | 333 |
| 334 client.Reset(); |
| 271 scheduler->SetNeedsCommit(); | 335 scheduler->SetNeedsCommit(); |
| 272 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); | 336 EXPECT_EQ(0, client.num_actions_()); |
| 273 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); | 337 |
| 274 EXPECT_TRUE(client.needs_begin_frame()); | 338 client.Reset(); |
| 339 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 340 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 341 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 275 | 342 |
| 276 // Commit will release the texture. | 343 // Commit will release the texture. |
| 277 client.Reset(); | 344 client.Reset(); |
| 278 scheduler->FinishCommit(); | 345 scheduler->FinishCommit(); |
| 279 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 346 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 347 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 280 EXPECT_TRUE(scheduler->RedrawPending()); | 348 EXPECT_TRUE(scheduler->RedrawPending()); |
| 281 EXPECT_TRUE(client.needs_begin_frame()); | |
| 282 | 349 |
| 283 // Now we can draw again after the commit happens. | 350 // Now we can draw again after the commit happens. |
| 284 client.Reset(); | 351 client.Reset(); |
| 352 scheduler->OnBeginFrameDeadline(); |
| 353 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); |
| 354 EXPECT_FALSE(scheduler->RedrawPending()); |
| 355 |
| 356 // SetNeedsBeginFrame(false) should be deferred to the end of the next |
| 357 // BeginFrame to avoid excessive toggling. |
| 358 EXPECT_TRUE(client.needs_begin_frame()); |
| 285 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 359 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 286 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 360 scheduler->OnBeginFrameDeadline(); |
| 287 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | |
| 288 EXPECT_FALSE(scheduler->RedrawPending()); | |
| 289 EXPECT_FALSE(client.needs_begin_frame()); | 361 EXPECT_FALSE(client.needs_begin_frame()); |
| 290 client.Reset(); | |
| 291 } | 362 } |
| 292 | 363 |
| 293 TEST(SchedulerTest, TextureAcquisitionCollision) { | 364 TEST(SchedulerTest, TextureAcquisitionCollision) { |
| 294 FakeSchedulerClient client; | 365 FakeSchedulerClient client; |
| 295 SchedulerSettings default_scheduler_settings; | 366 SchedulerSettings default_scheduler_settings; |
| 296 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 367 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 297 scheduler->SetCanStart(); | 368 scheduler->SetCanStart(); |
| 298 scheduler->SetVisible(true); | 369 scheduler->SetVisible(true); |
| 299 scheduler->SetCanDraw(true); | 370 scheduler->SetCanDraw(true); |
| 300 | 371 |
| 301 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 372 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 373 |
| 302 client.Reset(); | 374 client.Reset(); |
| 303 scheduler->DidCreateAndInitializeOutputSurface(); | 375 scheduler->DidCreateAndInitializeOutputSurface(); |
| 304 | |
| 305 scheduler->SetNeedsCommit(); | 376 scheduler->SetNeedsCommit(); |
| 306 scheduler->SetMainThreadNeedsLayerTextures(); | 377 scheduler->SetMainThreadNeedsLayerTextures(); |
| 307 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 4); | 378 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); |
| 308 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 4); | |
| 309 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 379 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 310 client, | 380 client, |
| 311 2, | 381 1, |
| 312 4); | 382 2); |
| 313 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 3, 4); | 383 |
| 314 client.Reset(); | 384 client.Reset(); |
| 385 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 386 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 387 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 388 |
| 389 client.Reset(); |
| 390 scheduler->OnBeginFrameDeadline(); |
| 391 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 315 | 392 |
| 316 // Although the compositor cannot draw because textures are locked by main | 393 // Although the compositor cannot draw because textures are locked by main |
| 317 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the | 394 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the |
| 318 // unlock. | 395 // unlock. |
| 319 EXPECT_TRUE(client.needs_begin_frame()); | 396 EXPECT_TRUE(client.needs_begin_frame()); |
| 320 | 397 |
| 321 // Trigger the commit | 398 // Trigger the commit |
| 322 scheduler->FinishCommit(); | 399 scheduler->FinishCommit(); |
| 323 EXPECT_TRUE(client.needs_begin_frame()); | 400 EXPECT_TRUE(client.needs_begin_frame()); |
| 324 client.Reset(); | |
| 325 | 401 |
| 326 // Between commit and draw, texture acquisition for main thread delayed, | 402 // Between commit and draw, texture acquisition for main thread delayed, |
| 327 // and main thread blocks. | 403 // and main thread blocks. |
| 404 client.Reset(); |
| 328 scheduler->SetMainThreadNeedsLayerTextures(); | 405 scheduler->SetMainThreadNeedsLayerTextures(); |
| 329 EXPECT_EQ(0, client.num_actions_()); | 406 EXPECT_EQ(0, client.num_actions_()); |
| 330 client.Reset(); | |
| 331 | 407 |
| 332 // No implicit commit is expected. | 408 // No implicit commit is expected. |
| 409 client.Reset(); |
| 333 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 410 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 334 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 411 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 412 |
| 413 client.Reset(); |
| 414 scheduler->OnBeginFrameDeadline(); |
| 415 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 335 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 416 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 336 client, | 417 client, |
| 337 1, | 418 1, |
| 338 3); | 419 2); |
| 339 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | |
| 340 client.Reset(); | |
| 341 | 420 |
| 342 // Compositor not scheduled to draw because textures are locked by main | 421 // Although the compositor is not scheduled to draw because textures are |
| 343 // thread. | 422 // locked by main thread, we proactively request the begin frame. |
| 344 EXPECT_FALSE(client.needs_begin_frame()); | 423 EXPECT_TRUE(client.needs_begin_frame()); |
| 345 | 424 |
| 346 // Needs an explicit commit from the main thread. | 425 // Needs an explicit commit from the main thread. |
| 426 client.Reset(); |
| 347 scheduler->SetNeedsCommit(); | 427 scheduler->SetNeedsCommit(); |
| 428 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 348 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 429 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 349 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 430 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 350 client.Reset(); | 431 client.Reset(); |
| 351 | 432 |
| 352 // Trigger the commit | 433 // Trigger the commit |
| 353 scheduler->FinishCommit(); | 434 scheduler->FinishCommit(); |
| 354 EXPECT_TRUE(client.needs_begin_frame()); | 435 EXPECT_TRUE(client.needs_begin_frame()); |
| 355 } | 436 } |
| 356 | 437 |
| 357 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 438 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| 358 FakeSchedulerClient client; | 439 FakeSchedulerClient client; |
| 359 SchedulerSettings default_scheduler_settings; | 440 SchedulerSettings default_scheduler_settings; |
| 360 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 441 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 361 scheduler->SetCanStart(); | 442 scheduler->SetCanStart(); |
| 362 scheduler->SetVisible(true); | 443 scheduler->SetVisible(true); |
| 363 scheduler->SetCanDraw(true); | 444 scheduler->SetCanDraw(true); |
| 364 | 445 |
| 365 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 446 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 366 client.Reset(); | 447 client.Reset(); |
| 367 scheduler->DidCreateAndInitializeOutputSurface(); | 448 scheduler->DidCreateAndInitializeOutputSurface(); |
| 368 | 449 |
| 369 scheduler->SetNeedsCommit(); | 450 scheduler->SetNeedsCommit(); |
| 451 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 452 scheduler->OnBeginFrameDeadline(); |
| 370 scheduler->FinishCommit(); | 453 scheduler->FinishCommit(); |
| 371 scheduler->SetMainThreadNeedsLayerTextures(); | 454 scheduler->SetMainThreadNeedsLayerTextures(); |
| 372 scheduler->SetNeedsCommit(); | 455 scheduler->SetNeedsCommit(); |
| 373 client.Reset(); | 456 client.Reset(); |
| 374 // Verify that pending texture acquisition fires when visibility | 457 // Verify that pending texture acquisition fires when visibility |
| 375 // is lost in order to avoid a deadlock. | 458 // is lost in order to avoid a deadlock. |
| 376 scheduler->SetVisible(false); | 459 scheduler->SetVisible(false); |
| 377 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 460 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 378 client); | 461 client); |
| 379 client.Reset(); | |
| 380 | 462 |
| 381 // Regaining visibility with textures acquired by main thread while | 463 // Regaining visibility with textures acquired by main thread while |
| 382 // compositor is waiting for first draw should result in a request | 464 // compositor is waiting for first draw should result in a request |
| 383 // for a new frame in order to escape a deadlock. | 465 // for a new frame in order to escape a deadlock. |
| 384 scheduler->SetVisible(true); | 466 scheduler->SetVisible(true); |
| 385 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginFrameToMainThread", client); | 467 EXPECT_TRUE(client.needs_begin_frame()); |
| 468 |
| 386 client.Reset(); | 469 client.Reset(); |
| 470 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 471 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 472 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 387 } | 473 } |
| 388 | 474 |
| 389 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 475 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 390 public: | 476 public: |
| 391 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} | 477 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} |
| 392 virtual ScheduledActionDrawAndSwapResult | 478 virtual DrawSwapReadbackResult |
| 393 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 479 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { |
| 394 // Only SetNeedsRedraw the first time this is called | 480 // Only SetNeedsRedraw the first time this is called |
| 395 if (!num_draws_) | 481 if (!num_draws_) |
| 396 scheduler_->SetNeedsRedraw(); | 482 scheduler_->SetNeedsRedraw(); |
| 397 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 483 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 398 } | 484 } |
| 399 | 485 |
| 400 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 486 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() |
| 401 OVERRIDE { | 487 OVERRIDE { |
| 402 NOTREACHED(); | 488 NOTREACHED(); |
| 403 return ScheduledActionDrawAndSwapResult(true, true); | 489 return DrawSwapReadbackResult(true, true, false); |
| 404 } | 490 } |
| 405 | 491 |
| 406 virtual void ScheduledActionCommit() OVERRIDE {} | 492 virtual void ScheduledActionCommit() OVERRIDE {} |
| 407 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 493 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
| 408 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 494 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
| 409 }; | 495 }; |
| 410 | 496 |
| 411 // Tests for two different situations: | 497 // Tests for two different situations: |
| 412 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 498 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 413 // a ScheduledActionDrawAndSwap | 499 // a ScheduledActionDrawAndSwap |
| 414 // 2. the scheduler drawing twice inside a single tick | 500 // 2. the scheduler drawing twice inside a single tick |
| 415 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 501 TEST(SchedulerTest, RequestRedrawInsideDraw) { |
| 416 SchedulerClientThatsetNeedsDrawInsideDraw client; | 502 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 417 SchedulerSettings default_scheduler_settings; | 503 SchedulerSettings default_scheduler_settings; |
| 418 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 504 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 419 scheduler->SetCanStart(); | 505 scheduler->SetCanStart(); |
| 420 scheduler->SetVisible(true); | 506 scheduler->SetVisible(true); |
| 421 scheduler->SetCanDraw(true); | 507 scheduler->SetCanDraw(true); |
| 422 scheduler->DidCreateAndInitializeOutputSurface(); | 508 scheduler->DidCreateAndInitializeOutputSurface(); |
| 423 | 509 |
| 424 scheduler->SetNeedsRedraw(); | 510 scheduler->SetNeedsRedraw(); |
| 425 EXPECT_TRUE(scheduler->RedrawPending()); | 511 EXPECT_TRUE(scheduler->RedrawPending()); |
| 426 EXPECT_TRUE(client.needs_begin_frame()); | 512 EXPECT_TRUE(client.needs_begin_frame()); |
| 427 EXPECT_EQ(0, client.num_draws()); | 513 EXPECT_EQ(0, client.num_draws()); |
| 428 | 514 |
| 429 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 515 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 516 scheduler->OnBeginFrameDeadline(); |
| 430 EXPECT_EQ(1, client.num_draws()); | 517 EXPECT_EQ(1, client.num_draws()); |
| 431 EXPECT_TRUE(scheduler->RedrawPending()); | 518 EXPECT_TRUE(scheduler->RedrawPending()); |
| 432 EXPECT_TRUE(client.needs_begin_frame()); | 519 EXPECT_TRUE(client.needs_begin_frame()); |
| 433 | 520 |
| 434 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 521 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 522 scheduler->OnBeginFrameDeadline(); |
| 435 EXPECT_EQ(2, client.num_draws()); | 523 EXPECT_EQ(2, client.num_draws()); |
| 436 EXPECT_FALSE(scheduler->RedrawPending()); | 524 EXPECT_FALSE(scheduler->RedrawPending()); |
| 525 EXPECT_TRUE(client.needs_begin_frame()); |
| 526 |
| 527 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 528 scheduler->OnBeginFrameDeadline(); |
| 437 EXPECT_FALSE(client.needs_begin_frame()); | 529 EXPECT_FALSE(client.needs_begin_frame()); |
| 438 } | 530 } |
| 439 | 531 |
| 440 // Test that requesting redraw inside a failed draw doesn't lose the request. | 532 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 441 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 533 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 442 SchedulerClientThatsetNeedsDrawInsideDraw client; | 534 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 443 SchedulerSettings default_scheduler_settings; | 535 SchedulerSettings default_scheduler_settings; |
| 444 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 536 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 445 scheduler->SetCanStart(); | 537 scheduler->SetCanStart(); |
| 446 scheduler->SetVisible(true); | 538 scheduler->SetVisible(true); |
| 447 scheduler->SetCanDraw(true); | 539 scheduler->SetCanDraw(true); |
| 448 scheduler->DidCreateAndInitializeOutputSurface(); | 540 scheduler->DidCreateAndInitializeOutputSurface(); |
| 449 | 541 |
| 450 client.SetDrawWillHappen(false); | 542 client.SetDrawWillHappen(false); |
| 451 | 543 |
| 452 scheduler->SetNeedsRedraw(); | 544 scheduler->SetNeedsRedraw(); |
| 453 EXPECT_TRUE(scheduler->RedrawPending()); | 545 EXPECT_TRUE(scheduler->RedrawPending()); |
| 454 EXPECT_TRUE(client.needs_begin_frame()); | 546 EXPECT_TRUE(client.needs_begin_frame()); |
| 455 EXPECT_EQ(0, client.num_draws()); | 547 EXPECT_EQ(0, client.num_draws()); |
| 456 | 548 |
| 457 // Fail the draw. | 549 // Fail the draw. |
| 458 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 550 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 551 scheduler->OnBeginFrameDeadline(); |
| 459 EXPECT_EQ(1, client.num_draws()); | 552 EXPECT_EQ(1, client.num_draws()); |
| 460 | 553 |
| 461 // We have a commit pending and the draw failed, and we didn't lose the redraw | 554 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 462 // request. | 555 // request. |
| 463 EXPECT_TRUE(scheduler->CommitPending()); | 556 EXPECT_TRUE(scheduler->CommitPending()); |
| 464 EXPECT_TRUE(scheduler->RedrawPending()); | 557 EXPECT_TRUE(scheduler->RedrawPending()); |
| 465 EXPECT_TRUE(client.needs_begin_frame()); | 558 EXPECT_TRUE(client.needs_begin_frame()); |
| 466 | 559 |
| 467 // Fail the draw again. | 560 // Fail the draw again. |
| 468 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 561 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 562 scheduler->OnBeginFrameDeadline(); |
| 469 EXPECT_EQ(2, client.num_draws()); | 563 EXPECT_EQ(2, client.num_draws()); |
| 470 EXPECT_TRUE(scheduler->CommitPending()); | 564 EXPECT_TRUE(scheduler->CommitPending()); |
| 471 EXPECT_TRUE(scheduler->RedrawPending()); | 565 EXPECT_TRUE(scheduler->RedrawPending()); |
| 472 EXPECT_TRUE(client.needs_begin_frame()); | 566 EXPECT_TRUE(client.needs_begin_frame()); |
| 473 | 567 |
| 474 // Draw successfully. | 568 // Draw successfully. |
| 475 client.SetDrawWillHappen(true); | 569 client.SetDrawWillHappen(true); |
| 476 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 570 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 571 scheduler->OnBeginFrameDeadline(); |
| 477 EXPECT_EQ(3, client.num_draws()); | 572 EXPECT_EQ(3, client.num_draws()); |
| 478 EXPECT_TRUE(scheduler->CommitPending()); | 573 EXPECT_TRUE(scheduler->CommitPending()); |
| 479 EXPECT_FALSE(scheduler->RedrawPending()); | 574 EXPECT_FALSE(scheduler->RedrawPending()); |
| 480 EXPECT_TRUE(client.needs_begin_frame()); | 575 EXPECT_TRUE(client.needs_begin_frame()); |
| 481 } | 576 } |
| 482 | 577 |
| 483 class SchedulerClientThatsetNeedsCommitInsideDraw : public FakeSchedulerClient { | 578 class SchedulerClientThatsetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 484 public: | 579 public: |
| 485 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} | 580 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} |
| 486 virtual ScheduledActionDrawAndSwapResult | 581 virtual DrawSwapReadbackResult |
| 487 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { | 582 ScheduledActionDrawAndSwapIfPossible() OVERRIDE { |
| 488 // Only SetNeedsCommit the first time this is called | 583 // Only SetNeedsCommit the first time this is called |
| 489 if (!num_draws_) | 584 if (!num_draws_) |
| 490 scheduler_->SetNeedsCommit(); | 585 scheduler_->SetNeedsCommit(); |
| 491 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 586 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 492 } | 587 } |
| 493 | 588 |
| 494 virtual ScheduledActionDrawAndSwapResult ScheduledActionDrawAndSwapForced() | 589 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() |
| 495 OVERRIDE { | 590 OVERRIDE { |
| 496 NOTREACHED(); | 591 NOTREACHED(); |
| 497 return ScheduledActionDrawAndSwapResult(true, true); | 592 return DrawSwapReadbackResult(true, true, false); |
| 498 } | 593 } |
| 499 | 594 |
| 500 virtual void ScheduledActionCommit() OVERRIDE {} | 595 virtual void ScheduledActionCommit() OVERRIDE {} |
| 501 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 596 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
| 502 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 597 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
| 503 }; | 598 }; |
| 504 | 599 |
| 505 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 600 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
| 506 // happen inside a ScheduledActionDrawAndSwap | 601 // happen inside a ScheduledActionDrawAndSwap |
| 507 TEST(SchedulerTest, RequestCommitInsideDraw) { | 602 TEST(SchedulerTest, RequestCommitInsideDraw) { |
| 508 SchedulerClientThatsetNeedsCommitInsideDraw client; | 603 SchedulerClientThatsetNeedsCommitInsideDraw client; |
| 509 SchedulerSettings default_scheduler_settings; | 604 SchedulerSettings default_scheduler_settings; |
| 510 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 605 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 511 scheduler->SetCanStart(); | 606 scheduler->SetCanStart(); |
| 512 scheduler->SetVisible(true); | 607 scheduler->SetVisible(true); |
| 513 scheduler->SetCanDraw(true); | 608 scheduler->SetCanDraw(true); |
| 514 scheduler->DidCreateAndInitializeOutputSurface(); | 609 scheduler->DidCreateAndInitializeOutputSurface(); |
| 515 | 610 |
| 516 scheduler->SetNeedsRedraw(); | 611 scheduler->SetNeedsRedraw(); |
| 517 EXPECT_TRUE(scheduler->RedrawPending()); | 612 EXPECT_TRUE(scheduler->RedrawPending()); |
| 518 EXPECT_EQ(0, client.num_draws()); | 613 EXPECT_EQ(0, client.num_draws()); |
| 519 EXPECT_TRUE(client.needs_begin_frame()); | 614 EXPECT_TRUE(client.needs_begin_frame()); |
| 520 | 615 |
| 521 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 616 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 617 scheduler->OnBeginFrameDeadline(); |
| 522 EXPECT_EQ(1, client.num_draws()); | 618 EXPECT_EQ(1, client.num_draws()); |
| 523 EXPECT_TRUE(scheduler->CommitPending()); | 619 EXPECT_TRUE(scheduler->CommitPending()); |
| 524 EXPECT_TRUE(client.needs_begin_frame()); | 620 EXPECT_TRUE(client.needs_begin_frame()); |
| 525 scheduler->FinishCommit(); | 621 scheduler->FinishCommit(); |
| 526 | 622 |
| 527 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 623 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 624 scheduler->OnBeginFrameDeadline(); |
| 528 EXPECT_EQ(2, client.num_draws());; | 625 EXPECT_EQ(2, client.num_draws());; |
| 529 EXPECT_FALSE(scheduler->RedrawPending()); | 626 EXPECT_FALSE(scheduler->RedrawPending()); |
| 530 EXPECT_FALSE(scheduler->CommitPending()); | 627 EXPECT_FALSE(scheduler->CommitPending()); |
| 628 EXPECT_TRUE(client.needs_begin_frame()); |
| 629 |
| 630 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 631 scheduler->OnBeginFrameDeadline(); |
| 531 EXPECT_FALSE(client.needs_begin_frame()); | 632 EXPECT_FALSE(client.needs_begin_frame()); |
| 532 } | 633 } |
| 533 | 634 |
| 534 // Tests that when a draw fails then the pending commit should not be dropped. | 635 // Tests that when a draw fails then the pending commit should not be dropped. |
| 535 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 636 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 536 SchedulerClientThatsetNeedsDrawInsideDraw client; | 637 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 537 SchedulerSettings default_scheduler_settings; | 638 SchedulerSettings default_scheduler_settings; |
| 538 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 639 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 539 scheduler->SetCanStart(); | 640 scheduler->SetCanStart(); |
| 540 scheduler->SetVisible(true); | 641 scheduler->SetVisible(true); |
| 541 scheduler->SetCanDraw(true); | 642 scheduler->SetCanDraw(true); |
| 542 scheduler->DidCreateAndInitializeOutputSurface(); | 643 scheduler->DidCreateAndInitializeOutputSurface(); |
| 543 | 644 |
| 544 client.SetDrawWillHappen(false); | 645 client.SetDrawWillHappen(false); |
| 545 | 646 |
| 546 scheduler->SetNeedsRedraw(); | 647 scheduler->SetNeedsRedraw(); |
| 547 EXPECT_TRUE(scheduler->RedrawPending()); | 648 EXPECT_TRUE(scheduler->RedrawPending()); |
| 548 EXPECT_TRUE(client.needs_begin_frame()); | 649 EXPECT_TRUE(client.needs_begin_frame()); |
| 549 EXPECT_EQ(0, client.num_draws()); | 650 EXPECT_EQ(0, client.num_draws()); |
| 550 | 651 |
| 551 // Fail the draw. | 652 // Fail the draw. |
| 552 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 653 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 654 scheduler->OnBeginFrameDeadline(); |
| 553 EXPECT_EQ(1, client.num_draws()); | 655 EXPECT_EQ(1, client.num_draws()); |
| 554 | 656 |
| 555 // We have a commit pending and the draw failed, and we didn't lose the commit | 657 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 556 // request. | 658 // request. |
| 557 EXPECT_TRUE(scheduler->CommitPending()); | 659 EXPECT_TRUE(scheduler->CommitPending()); |
| 558 EXPECT_TRUE(scheduler->RedrawPending()); | 660 EXPECT_TRUE(scheduler->RedrawPending()); |
| 559 EXPECT_TRUE(client.needs_begin_frame()); | 661 EXPECT_TRUE(client.needs_begin_frame()); |
| 560 | 662 |
| 561 // Fail the draw again. | 663 // Fail the draw again. |
| 562 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 664 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 665 scheduler->OnBeginFrameDeadline(); |
| 563 EXPECT_EQ(2, client.num_draws()); | 666 EXPECT_EQ(2, client.num_draws()); |
| 564 EXPECT_TRUE(scheduler->CommitPending()); | 667 EXPECT_TRUE(scheduler->CommitPending()); |
| 565 EXPECT_TRUE(scheduler->RedrawPending()); | 668 EXPECT_TRUE(scheduler->RedrawPending()); |
| 566 EXPECT_TRUE(client.needs_begin_frame()); | 669 EXPECT_TRUE(client.needs_begin_frame()); |
| 567 | 670 |
| 568 // Draw successfully. | 671 // Draw successfully. |
| 569 client.SetDrawWillHappen(true); | 672 client.SetDrawWillHappen(true); |
| 570 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 673 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 674 scheduler->OnBeginFrameDeadline(); |
| 571 EXPECT_EQ(3, client.num_draws()); | 675 EXPECT_EQ(3, client.num_draws()); |
| 572 EXPECT_TRUE(scheduler->CommitPending()); | 676 EXPECT_TRUE(scheduler->CommitPending()); |
| 573 EXPECT_FALSE(scheduler->RedrawPending()); | 677 EXPECT_FALSE(scheduler->RedrawPending()); |
| 574 EXPECT_TRUE(client.needs_begin_frame()); | 678 EXPECT_TRUE(client.needs_begin_frame()); |
| 575 } | 679 } |
| 576 | 680 |
| 577 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 681 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| 578 SchedulerClientThatsetNeedsCommitInsideDraw client; | 682 SchedulerClientThatsetNeedsCommitInsideDraw client; |
| 579 SchedulerSettings default_scheduler_settings; | 683 SchedulerSettings default_scheduler_settings; |
| 580 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 684 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 581 scheduler->SetCanStart(); | 685 scheduler->SetCanStart(); |
| 582 scheduler->SetVisible(true); | 686 scheduler->SetVisible(true); |
| 583 scheduler->SetCanDraw(true); | 687 scheduler->SetCanDraw(true); |
| 584 scheduler->DidCreateAndInitializeOutputSurface(); | 688 scheduler->DidCreateAndInitializeOutputSurface(); |
| 585 | 689 |
| 586 scheduler->SetNeedsRedraw(); | 690 scheduler->SetNeedsRedraw(); |
| 587 EXPECT_TRUE(scheduler->RedrawPending()); | 691 EXPECT_TRUE(scheduler->RedrawPending()); |
| 588 EXPECT_TRUE(client.needs_begin_frame()); | 692 EXPECT_TRUE(client.needs_begin_frame()); |
| 589 EXPECT_EQ(0, client.num_draws()); | 693 EXPECT_EQ(0, client.num_draws()); |
| 590 | 694 |
| 591 // Draw successfully, this starts a new frame. | 695 // Draw successfully, this starts a new frame. |
| 592 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 696 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 697 scheduler->OnBeginFrameDeadline(); |
| 593 EXPECT_EQ(1, client.num_draws()); | 698 EXPECT_EQ(1, client.num_draws()); |
| 594 | 699 |
| 595 scheduler->SetNeedsRedraw(); | 700 scheduler->SetNeedsRedraw(); |
| 596 EXPECT_TRUE(scheduler->RedrawPending()); | 701 EXPECT_TRUE(scheduler->RedrawPending()); |
| 597 EXPECT_TRUE(client.needs_begin_frame()); | 702 EXPECT_TRUE(client.needs_begin_frame()); |
| 598 | 703 |
| 599 // Fail to draw, this should not start a frame. | 704 // Fail to draw, this should not start a frame. |
| 600 client.SetDrawWillHappen(false); | 705 client.SetDrawWillHappen(false); |
| 601 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 706 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 707 scheduler->OnBeginFrameDeadline(); |
| 602 EXPECT_EQ(2, client.num_draws()); | 708 EXPECT_EQ(2, client.num_draws()); |
| 603 } | 709 } |
| 604 | 710 |
| 605 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { | 711 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { |
| 606 FakeSchedulerClient client; | 712 FakeSchedulerClient client; |
| 607 SchedulerSettings default_scheduler_settings; | 713 SchedulerSettings default_scheduler_settings; |
| 608 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 714 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 609 | 715 |
| 610 // Tell the client that it will fail to swap. | 716 // Tell the client that it will fail to swap. |
| 611 client.SetDrawWillHappen(true); | 717 client.SetDrawWillHappen(true); |
| 612 client.SetSwapWillHappenIfDrawHappens(false); | 718 client.SetSwapWillHappenIfDrawHappens(false); |
| 613 | 719 |
| 614 // Get the compositor to do a ScheduledActionDrawAndSwapForced. | 720 // Get the compositor to do a ScheduledActionDrawAndReadback. |
| 615 scheduler->SetCanDraw(true); | 721 scheduler->SetCanDraw(true); |
| 616 scheduler->SetNeedsRedraw(); | 722 scheduler->SetNeedsRedraw(); |
| 617 scheduler->SetNeedsForcedRedraw(); | 723 scheduler->SetNeedsForcedCommitForReadback(); |
| 618 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapForced")); | 724 scheduler->FinishCommit(); |
| 725 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
| 619 } | 726 } |
| 620 | 727 |
| 621 } // namespace | 728 } // namespace |
| 622 } // namespace cc | 729 } // namespace cc |
| OLD | NEW |