| 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 "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 12 #include "cc/test/scheduler_test_common.h" | 11 #include "cc/test/scheduler_test_common.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 28 | 27 |
| 29 namespace cc { | 28 namespace cc { |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { | 31 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { |
| 33 scheduler->DidCreateAndInitializeOutputSurface(); | 32 scheduler->DidCreateAndInitializeOutputSurface(); |
| 34 scheduler->SetNeedsCommit(); | 33 scheduler->SetNeedsCommit(); |
| 35 scheduler->FinishCommit(); | 34 scheduler->FinishCommit(); |
| 36 // Go through the motions to draw the commit. | 35 // Go through the motions to draw the commit. |
| 37 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 36 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 38 // We need another BeginFrame so scheduler calls SetNeedsBeginFrame(false). | 37 scheduler->OnBeginFrameDeadline(); |
| 38 // We need another BeginFrame so Scheduler calls SetNeedsBeginFrame(false). |
| 39 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 39 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 40 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 40 scheduler->OnBeginFrameDeadline(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 class FakeSchedulerClient : public SchedulerClient { | 43 class FakeSchedulerClient : public SchedulerClient { |
| 44 public: | 44 public: |
| 45 FakeSchedulerClient() | 45 FakeSchedulerClient() |
| 46 : needs_begin_frame_(false) { | 46 : needs_begin_frame_(false) { |
| 47 Reset(); | 47 Reset(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void Reset() { | 50 void Reset() { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | 149 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { |
| 150 return base::TimeDelta(); | 150 return base::TimeDelta(); |
| 151 } | 151 } |
| 152 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { | 152 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { |
| 153 return base::TimeDelta(); | 153 return base::TimeDelta(); |
| 154 } | 154 } |
| 155 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 155 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
| 156 return base::TimeDelta(); | 156 return base::TimeDelta(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual void PostBeginFrameDeadline(const base::Closure& closure, |
| 160 base::TimeTicks deadline) OVERRIDE { |
| 161 actions_.push_back("PostBeginFrameDeadlineTask"); |
| 162 states_.push_back(scheduler_->StateAsValue().release()); |
| 163 } |
| 164 |
| 165 virtual void DidBeginFrameDeadlineOnImplThread() OVERRIDE {} |
| 166 |
| 159 protected: | 167 protected: |
| 160 bool needs_begin_frame_; | 168 bool needs_begin_frame_; |
| 161 bool draw_will_happen_; | 169 bool draw_will_happen_; |
| 162 bool swap_will_happen_if_draw_happens_; | 170 bool swap_will_happen_if_draw_happens_; |
| 163 int num_draws_; | 171 int num_draws_; |
| 164 std::vector<const char*> actions_; | 172 std::vector<const char*> actions_; |
| 165 ScopedVector<base::Value> states_; | 173 ScopedVector<base::Value> states_; |
| 166 scoped_ptr<Scheduler> scheduler_; | 174 scoped_ptr<Scheduler> scheduler_; |
| 167 }; | 175 }; |
| 168 | 176 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 184 FakeSchedulerClient client; | 192 FakeSchedulerClient client; |
| 185 SchedulerSettings default_scheduler_settings; | 193 SchedulerSettings default_scheduler_settings; |
| 186 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 194 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 187 scheduler->SetCanStart(); | 195 scheduler->SetCanStart(); |
| 188 scheduler->SetVisible(true); | 196 scheduler->SetVisible(true); |
| 189 scheduler->SetCanDraw(true); | 197 scheduler->SetCanDraw(true); |
| 190 | 198 |
| 191 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 199 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 192 InitializeOutputSurfaceAndFirstCommit(scheduler); | 200 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 193 | 201 |
| 194 // SetNeedsCommit should begin the frame. | 202 // SetNeedsCommit should begin the frame on the next BeginFrame. |
| 195 client.Reset(); | 203 client.Reset(); |
| 196 scheduler->SetNeedsCommit(); | 204 scheduler->SetNeedsCommit(); |
| 197 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | |
| 198 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | |
| 199 EXPECT_TRUE(client.needs_begin_frame()); | 205 EXPECT_TRUE(client.needs_begin_frame()); |
| 200 client.Reset(); | 206 client.Reset(); |
| 201 | 207 |
| 208 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 209 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 210 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 211 EXPECT_TRUE(client.needs_begin_frame()); |
| 212 client.Reset(); |
| 213 |
| 214 // If we don't swap on the deadline, we need to request another BeginFrame. |
| 215 scheduler->OnBeginFrameDeadline(); |
| 216 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 217 EXPECT_TRUE(client.needs_begin_frame()); |
| 218 client.Reset(); |
| 219 |
| 202 // FinishCommit should commit | 220 // FinishCommit should commit |
| 203 scheduler->FinishCommit(); | 221 scheduler->FinishCommit(); |
| 204 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 222 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 205 EXPECT_TRUE(client.needs_begin_frame()); | 223 EXPECT_TRUE(client.needs_begin_frame()); |
| 206 client.Reset(); | 224 client.Reset(); |
| 207 | 225 |
| 208 // BeginFrame should draw. | 226 // BeginFrame should prepare the draw. |
| 209 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 227 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 228 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 229 EXPECT_TRUE(client.needs_begin_frame()); |
| 230 client.Reset(); |
| 231 |
| 232 // BeginFrame deadline should draw. |
| 233 scheduler->OnBeginFrameDeadline(); |
| 210 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 234 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 211 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 235 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 212 EXPECT_TRUE(client.needs_begin_frame()); | 236 EXPECT_TRUE(client.needs_begin_frame()); |
| 213 client.Reset(); | 237 client.Reset(); |
| 238 |
| 239 // The following BeginFrame deadline should SetNeedsBeginFrame(false) to avoid |
| 240 // excessive toggles. |
| 241 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 242 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 243 client.Reset(); |
| 244 |
| 245 scheduler->OnBeginFrameDeadline(); |
| 246 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 247 EXPECT_FALSE(client.needs_begin_frame()); |
| 248 client.Reset(); |
| 214 } | 249 } |
| 215 | 250 |
| 216 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { | 251 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { |
| 217 FakeSchedulerClient client; | 252 FakeSchedulerClient client; |
| 218 SchedulerSettings default_scheduler_settings; | 253 SchedulerSettings default_scheduler_settings; |
| 219 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 254 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 220 scheduler->SetCanStart(); | 255 scheduler->SetCanStart(); |
| 221 scheduler->SetVisible(true); | 256 scheduler->SetVisible(true); |
| 222 scheduler->SetCanDraw(true); | 257 scheduler->SetCanDraw(true); |
| 223 | 258 |
| 224 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 259 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 225 InitializeOutputSurfaceAndFirstCommit(scheduler); | 260 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 226 client.Reset(); | 261 client.Reset(); |
| 227 | 262 |
| 228 // SetNedsCommit should begin the frame. | 263 // SetNeddsCommit should begin the frame. |
| 229 scheduler->SetNeedsCommit(); | 264 scheduler->SetNeedsCommit(); |
| 265 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 266 client.Reset(); |
| 267 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 230 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 268 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 231 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 269 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 270 EXPECT_TRUE(client.needs_begin_frame()); |
| 232 client.Reset(); | 271 client.Reset(); |
| 233 | 272 |
| 234 // Now SetNeedsCommit again. Calling here means we need a second frame. | 273 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 235 scheduler->SetNeedsCommit(); | 274 scheduler->SetNeedsCommit(); |
| 236 | 275 EXPECT_EQ(client.num_actions_(), 0); |
| 237 // Finish the commit for the first frame. | |
| 238 scheduler->FinishCommit(); | |
| 239 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
| 240 client.Reset(); | 276 client.Reset(); |
| 241 | 277 |
| 242 // Tick should draw but then begin another frame for the second commit. | 278 // Finish the first commit. |
| 279 scheduler->FinishCommit(); |
| 280 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 281 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 282 client.Reset(); |
| 283 scheduler->OnBeginFrameDeadline(); |
| 284 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 285 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 286 |
| 243 // Because we just swapped, the Scheduler should also request the next | 287 // Because we just swapped, the Scheduler should also request the next |
| 244 // BeginFrame from the OutputSurface. | 288 // BeginFrame from the OutputSurface. |
| 245 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | |
| 246 EXPECT_TRUE(client.needs_begin_frame()); | 289 EXPECT_TRUE(client.needs_begin_frame()); |
| 247 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | |
| 248 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3); | |
| 249 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | |
| 250 client.Reset(); | 290 client.Reset(); |
| 251 | 291 |
| 252 // Finish the second commit. | 292 // Since another commit is needed, the next BeginFrame should initiate |
| 293 // the second commit. |
| 294 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 295 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 296 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 297 client.Reset(); |
| 298 |
| 299 // Finishing the commit before the deadline should post a new deadline task |
| 300 // to trigger the deadline early. |
| 253 scheduler->FinishCommit(); | 301 scheduler->FinishCommit(); |
| 254 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 302 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 255 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 303 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 256 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 3); | 304 client.Reset(); |
| 257 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | 305 scheduler->OnBeginFrameDeadline(); |
| 306 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 307 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 258 EXPECT_TRUE(client.needs_begin_frame()); | 308 EXPECT_TRUE(client.needs_begin_frame()); |
| 259 client.Reset(); | 309 client.Reset(); |
| 260 | 310 |
| 261 // On the next BeginFrame, verify we go back to a quiescent state and | 311 // On the next BeginFrame, verify we go back to a quiescent state and |
| 262 // no longer request BeginFrames. | 312 // no longer request BeginFrames. |
| 263 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 313 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 314 scheduler->OnBeginFrameDeadline(); |
| 264 EXPECT_FALSE(client.needs_begin_frame()); | 315 EXPECT_FALSE(client.needs_begin_frame()); |
| 316 client.Reset(); |
| 265 } | 317 } |
| 266 | 318 |
| 267 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | 319 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| 268 FakeSchedulerClient client; | 320 FakeSchedulerClient client; |
| 269 SchedulerSettings default_scheduler_settings; | 321 SchedulerSettings default_scheduler_settings; |
| 270 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 322 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 271 scheduler->SetCanStart(); | 323 scheduler->SetCanStart(); |
| 272 scheduler->SetVisible(true); | 324 scheduler->SetVisible(true); |
| 273 scheduler->SetCanDraw(true); | 325 scheduler->SetCanDraw(true); |
| 274 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 326 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 275 | 327 |
| 276 InitializeOutputSurfaceAndFirstCommit(scheduler); | 328 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 277 client.Reset(); | 329 client.Reset(); |
| 278 scheduler->SetNeedsRedraw(); | 330 scheduler->SetNeedsRedraw(); |
| 279 EXPECT_TRUE(scheduler->RedrawPending()); | 331 EXPECT_TRUE(scheduler->RedrawPending()); |
| 280 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 332 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 281 EXPECT_TRUE(client.needs_begin_frame()); | 333 EXPECT_TRUE(client.needs_begin_frame()); |
| 282 | 334 |
| 283 client.Reset(); | 335 client.Reset(); |
| 284 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 336 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 337 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 338 client.Reset(); |
| 339 scheduler->OnBeginFrameDeadline(); |
| 285 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 340 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 286 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 341 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 287 EXPECT_FALSE(scheduler->RedrawPending()); | 342 EXPECT_FALSE(scheduler->RedrawPending()); |
| 288 EXPECT_TRUE(client.needs_begin_frame()); | 343 EXPECT_TRUE(client.needs_begin_frame()); |
| 289 | 344 |
| 290 client.Reset(); | 345 client.Reset(); |
| 291 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 346 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 347 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 348 client.Reset(); |
| 349 scheduler->OnBeginFrameDeadline(); |
| 292 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 350 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 293 EXPECT_FALSE(scheduler->RedrawPending()); | 351 EXPECT_FALSE(scheduler->RedrawPending()); |
| 294 EXPECT_FALSE(client.needs_begin_frame()); | 352 EXPECT_FALSE(client.needs_begin_frame()); |
| 295 | 353 |
| 296 client.Reset(); | 354 client.Reset(); |
| 297 scheduler->SetMainThreadNeedsLayerTextures(); | 355 scheduler->SetMainThreadNeedsLayerTextures(); |
| 298 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 356 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 299 client); | 357 client); |
| 300 | 358 |
| 301 // We should request a BeginFrame in anticipation of a draw. | 359 // We should request a BeginFrame in anticipation of a draw. |
| 302 client.Reset(); | 360 client.Reset(); |
| 303 scheduler->SetNeedsRedraw(); | 361 scheduler->SetNeedsRedraw(); |
| 304 EXPECT_TRUE(scheduler->RedrawPending()); | 362 EXPECT_TRUE(scheduler->RedrawPending()); |
| 305 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 363 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 306 EXPECT_TRUE(client.needs_begin_frame()); | 364 EXPECT_TRUE(client.needs_begin_frame()); |
| 307 | 365 |
| 308 // No draw happens since the textures are acquired by the main thread. | 366 // No draw happens since the textures are acquired by the main thread. |
| 309 client.Reset(); | 367 client.Reset(); |
| 310 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 368 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 369 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 370 client.Reset(); |
| 371 scheduler->OnBeginFrameDeadline(); |
| 311 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 372 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 312 EXPECT_TRUE(scheduler->RedrawPending()); | 373 EXPECT_TRUE(scheduler->RedrawPending()); |
| 313 EXPECT_TRUE(client.needs_begin_frame()); | 374 EXPECT_TRUE(client.needs_begin_frame()); |
| 314 | 375 |
| 376 client.Reset(); |
| 315 scheduler->SetNeedsCommit(); | 377 scheduler->SetNeedsCommit(); |
| 316 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); | 378 EXPECT_EQ(0, client.num_actions_()); |
| 317 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); | 379 |
| 318 EXPECT_TRUE(client.needs_begin_frame()); | 380 client.Reset(); |
| 381 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 382 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 383 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 319 | 384 |
| 320 // Commit will release the texture. | 385 // Commit will release the texture. |
| 321 client.Reset(); | 386 client.Reset(); |
| 322 scheduler->FinishCommit(); | 387 scheduler->FinishCommit(); |
| 323 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 388 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 389 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 324 EXPECT_TRUE(scheduler->RedrawPending()); | 390 EXPECT_TRUE(scheduler->RedrawPending()); |
| 325 EXPECT_TRUE(client.needs_begin_frame()); | |
| 326 | 391 |
| 327 // Now we can draw again after the commit happens. | 392 // Now we can draw again after the commit happens. |
| 328 client.Reset(); | 393 client.Reset(); |
| 329 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 394 scheduler->OnBeginFrameDeadline(); |
| 330 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 395 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 331 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 396 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 332 EXPECT_FALSE(scheduler->RedrawPending()); | 397 EXPECT_FALSE(scheduler->RedrawPending()); |
| 333 EXPECT_TRUE(client.needs_begin_frame()); | 398 EXPECT_TRUE(client.needs_begin_frame()); |
| 334 | 399 |
| 335 // Make sure we stop requesting BeginFrames if we don't swap. | 400 // Make sure we stop requesting BeginFrames if we don't swap. |
| 336 client.Reset(); | 401 client.Reset(); |
| 337 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 402 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 403 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 404 client.Reset(); |
| 405 scheduler->OnBeginFrameDeadline(); |
| 338 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 406 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 339 EXPECT_FALSE(client.needs_begin_frame()); | 407 EXPECT_FALSE(client.needs_begin_frame()); |
| 340 } | 408 } |
| 341 | 409 |
| 342 TEST(SchedulerTest, TextureAcquisitionCollision) { | 410 TEST(SchedulerTest, TextureAcquisitionCollision) { |
| 343 FakeSchedulerClient client; | 411 FakeSchedulerClient client; |
| 344 SchedulerSettings default_scheduler_settings; | 412 SchedulerSettings default_scheduler_settings; |
| 345 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 413 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 346 scheduler->SetCanStart(); | 414 scheduler->SetCanStart(); |
| 347 scheduler->SetVisible(true); | 415 scheduler->SetVisible(true); |
| 348 scheduler->SetCanDraw(true); | 416 scheduler->SetCanDraw(true); |
| 349 | 417 |
| 350 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 418 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 351 InitializeOutputSurfaceAndFirstCommit(scheduler); | 419 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 352 | 420 |
| 353 client.Reset(); | 421 client.Reset(); |
| 354 scheduler->SetNeedsCommit(); | 422 scheduler->SetNeedsCommit(); |
| 355 scheduler->SetMainThreadNeedsLayerTextures(); | 423 scheduler->SetMainThreadNeedsLayerTextures(); |
| 356 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 3); | 424 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); |
| 357 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 3); | |
| 358 EXPECT_ACTION( | 425 EXPECT_ACTION( |
| 359 "ScheduledActionAcquireLayerTexturesForMainThread", client, 2, 3); | 426 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 2); |
| 427 |
| 360 client.Reset(); | 428 client.Reset(); |
| 429 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 430 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 431 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 432 |
| 433 client.Reset(); |
| 434 scheduler->OnBeginFrameDeadline(); |
| 435 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 361 | 436 |
| 362 // Although the compositor cannot draw because textures are locked by main | 437 // Although the compositor cannot draw because textures are locked by main |
| 363 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the | 438 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the |
| 364 // unlock. | 439 // unlock. |
| 365 EXPECT_TRUE(client.needs_begin_frame()); | 440 EXPECT_TRUE(client.needs_begin_frame()); |
| 366 | 441 |
| 367 // Trigger the commit | 442 // Trigger the commit |
| 368 scheduler->FinishCommit(); | 443 scheduler->FinishCommit(); |
| 369 EXPECT_TRUE(client.needs_begin_frame()); | 444 EXPECT_TRUE(client.needs_begin_frame()); |
| 370 client.Reset(); | |
| 371 | 445 |
| 372 // Between commit and draw, texture acquisition for main thread delayed, | 446 // Between commit and draw, texture acquisition for main thread delayed, |
| 373 // and main thread blocks. | 447 // and main thread blocks. |
| 448 client.Reset(); |
| 374 scheduler->SetMainThreadNeedsLayerTextures(); | 449 scheduler->SetMainThreadNeedsLayerTextures(); |
| 375 EXPECT_EQ(0, client.num_actions_()); | 450 EXPECT_EQ(0, client.num_actions_()); |
| 376 client.Reset(); | |
| 377 | 451 |
| 378 // No implicit commit is expected. | 452 // No implicit commit is expected. |
| 453 client.Reset(); |
| 379 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 454 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 455 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 456 |
| 457 client.Reset(); |
| 458 scheduler->OnBeginFrameDeadline(); |
| 380 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 459 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
| 381 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 460 EXPECT_ACTION( |
| 382 client, | 461 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); |
| 383 1, | |
| 384 3); | |
| 385 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | 462 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); |
| 386 EXPECT_TRUE(client.needs_begin_frame()); | 463 EXPECT_TRUE(client.needs_begin_frame()); |
| 387 client.Reset(); | 464 client.Reset(); |
| 388 | 465 |
| 389 // Compositor not scheduled to draw because textures are locked by main | 466 // The compositor should not draw because textures are locked by main |
| 390 // thread. | 467 // thread. |
| 391 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 468 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 469 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 470 client.Reset(); |
| 471 scheduler->OnBeginFrameDeadline(); |
| 392 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 472 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 393 EXPECT_FALSE(client.needs_begin_frame()); | 473 EXPECT_FALSE(client.needs_begin_frame()); |
| 394 client.Reset(); | 474 client.Reset(); |
| 395 | 475 |
| 396 // Needs an explicit commit from the main thread. | 476 // The impl thread need an explicit commit from the main thread to lock |
| 477 // the textures. |
| 397 scheduler->SetNeedsCommit(); | 478 scheduler->SetNeedsCommit(); |
| 479 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 480 EXPECT_TRUE(client.needs_begin_frame()); |
| 481 client.Reset(); |
| 482 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 398 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 483 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 399 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 484 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 400 client.Reset(); | 485 client.Reset(); |
| 401 | 486 |
| 402 // Trigger the commit | 487 // Trigger the commit, which will trigger the deadline task early. |
| 403 scheduler->FinishCommit(); | 488 scheduler->FinishCommit(); |
| 404 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 489 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); |
| 490 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 405 EXPECT_TRUE(client.needs_begin_frame()); | 491 EXPECT_TRUE(client.needs_begin_frame()); |
| 406 client.Reset(); | 492 client.Reset(); |
| 407 | 493 |
| 408 // Verify we draw on the next BeginFrame. | 494 // Verify we draw on the next BeginFrame deadline |
| 409 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 495 scheduler->OnBeginFrameDeadline(); |
| 410 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 496 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 411 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 497 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 412 EXPECT_TRUE(client.needs_begin_frame()); | 498 EXPECT_TRUE(client.needs_begin_frame()); |
| 413 client.Reset(); | 499 client.Reset(); |
| 414 } | 500 } |
| 415 | 501 |
| 416 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 502 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| 417 FakeSchedulerClient client; | 503 FakeSchedulerClient client; |
| 418 SchedulerSettings default_scheduler_settings; | 504 SchedulerSettings default_scheduler_settings; |
| 419 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 505 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 420 scheduler->SetCanStart(); | 506 scheduler->SetCanStart(); |
| 421 scheduler->SetVisible(true); | 507 scheduler->SetVisible(true); |
| 422 scheduler->SetCanDraw(true); | 508 scheduler->SetCanDraw(true); |
| 423 | 509 |
| 424 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 510 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 425 client.Reset(); | 511 client.Reset(); |
| 426 scheduler->DidCreateAndInitializeOutputSurface(); | 512 scheduler->DidCreateAndInitializeOutputSurface(); |
| 427 | 513 |
| 428 scheduler->SetNeedsCommit(); | 514 scheduler->SetNeedsCommit(); |
| 515 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 516 scheduler->OnBeginFrameDeadline(); |
| 429 scheduler->FinishCommit(); | 517 scheduler->FinishCommit(); |
| 430 scheduler->SetMainThreadNeedsLayerTextures(); | 518 scheduler->SetMainThreadNeedsLayerTextures(); |
| 431 scheduler->SetNeedsCommit(); | 519 scheduler->SetNeedsCommit(); |
| 432 client.Reset(); | 520 client.Reset(); |
| 433 // Verify that pending texture acquisition fires when visibility | 521 // Verify that pending texture acquisition fires when visibility |
| 434 // is lost in order to avoid a deadlock. | 522 // is lost in order to avoid a deadlock. |
| 435 scheduler->SetVisible(false); | 523 scheduler->SetVisible(false); |
| 436 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 524 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 437 client); | 525 client); |
| 438 client.Reset(); | |
| 439 | 526 |
| 440 // Already sent a begin frame on this current frame, so wait. | 527 // Already sent a begin frame on this current frame, so wait. |
| 528 client.Reset(); |
| 441 scheduler->SetVisible(true); | 529 scheduler->SetVisible(true); |
| 442 EXPECT_EQ(0, client.num_actions_()); | 530 EXPECT_EQ(0, client.num_actions_()); |
| 443 client.Reset(); | 531 EXPECT_TRUE(client.needs_begin_frame()); |
| 444 | 532 |
| 445 // Regaining visibility with textures acquired by main thread while | 533 // Regaining visibility with textures acquired by main thread while |
| 446 // compositor is waiting for first draw should result in a request | 534 // compositor is waiting for first draw should result in a request |
| 447 // for a new frame in order to escape a deadlock. | 535 // for a new frame in order to escape a deadlock. |
| 536 client.Reset(); |
| 448 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 537 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 449 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 538 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 450 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 539 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2); |
| 451 } | 540 } |
| 452 | 541 |
| 453 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 542 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 454 public: | 543 public: |
| 455 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} | 544 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} |
| 456 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 545 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 457 OVERRIDE { | 546 OVERRIDE { |
| 458 // Only SetNeedsRedraw the first time this is called | 547 // Only SetNeedsRedraw the first time this is called |
| 459 if (!num_draws_) | 548 if (!num_draws_) |
| 460 scheduler_->SetNeedsRedraw(); | 549 scheduler_->SetNeedsRedraw(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 487 scheduler->SetCanDraw(true); | 576 scheduler->SetCanDraw(true); |
| 488 InitializeOutputSurfaceAndFirstCommit(scheduler); | 577 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 489 client.Reset(); | 578 client.Reset(); |
| 490 | 579 |
| 491 scheduler->SetNeedsRedraw(); | 580 scheduler->SetNeedsRedraw(); |
| 492 EXPECT_TRUE(scheduler->RedrawPending()); | 581 EXPECT_TRUE(scheduler->RedrawPending()); |
| 493 EXPECT_TRUE(client.needs_begin_frame()); | 582 EXPECT_TRUE(client.needs_begin_frame()); |
| 494 EXPECT_EQ(0, client.num_draws()); | 583 EXPECT_EQ(0, client.num_draws()); |
| 495 | 584 |
| 496 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 585 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 586 scheduler->OnBeginFrameDeadline(); |
| 497 EXPECT_EQ(1, client.num_draws()); | 587 EXPECT_EQ(1, client.num_draws()); |
| 498 EXPECT_TRUE(scheduler->RedrawPending()); | 588 EXPECT_TRUE(scheduler->RedrawPending()); |
| 499 EXPECT_TRUE(client.needs_begin_frame()); | 589 EXPECT_TRUE(client.needs_begin_frame()); |
| 500 | 590 |
| 501 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 591 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 592 scheduler->OnBeginFrameDeadline(); |
| 502 EXPECT_EQ(2, client.num_draws()); | 593 EXPECT_EQ(2, client.num_draws()); |
| 503 EXPECT_FALSE(scheduler->RedrawPending()); | 594 EXPECT_FALSE(scheduler->RedrawPending()); |
| 504 EXPECT_TRUE(client.needs_begin_frame()); | 595 EXPECT_TRUE(client.needs_begin_frame()); |
| 505 | 596 |
| 506 // We stop requesting BeginFrames after a BeginFrame where we don't swap. | 597 // We stop requesting BeginFrames after a BeginFrame where we don't swap. |
| 507 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 598 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 599 scheduler->OnBeginFrameDeadline(); |
| 508 EXPECT_EQ(2, client.num_draws()); | 600 EXPECT_EQ(2, client.num_draws()); |
| 509 EXPECT_FALSE(scheduler->RedrawPending()); | 601 EXPECT_FALSE(scheduler->RedrawPending()); |
| 510 EXPECT_FALSE(client.needs_begin_frame()); | 602 EXPECT_FALSE(client.needs_begin_frame()); |
| 511 } | 603 } |
| 512 | 604 |
| 513 // Test that requesting redraw inside a failed draw doesn't lose the request. | 605 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 514 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 606 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 515 SchedulerClientThatsetNeedsDrawInsideDraw client; | 607 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 516 SchedulerSettings default_scheduler_settings; | 608 SchedulerSettings default_scheduler_settings; |
| 517 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 609 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 518 scheduler->SetCanStart(); | 610 scheduler->SetCanStart(); |
| 519 scheduler->SetVisible(true); | 611 scheduler->SetVisible(true); |
| 520 scheduler->SetCanDraw(true); | 612 scheduler->SetCanDraw(true); |
| 521 InitializeOutputSurfaceAndFirstCommit(scheduler); | 613 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 522 client.Reset(); | 614 client.Reset(); |
| 523 | 615 |
| 524 client.SetDrawWillHappen(false); | 616 client.SetDrawWillHappen(false); |
| 525 | 617 |
| 526 scheduler->SetNeedsRedraw(); | 618 scheduler->SetNeedsRedraw(); |
| 527 EXPECT_TRUE(scheduler->RedrawPending()); | 619 EXPECT_TRUE(scheduler->RedrawPending()); |
| 528 EXPECT_TRUE(client.needs_begin_frame()); | 620 EXPECT_TRUE(client.needs_begin_frame()); |
| 529 EXPECT_EQ(0, client.num_draws()); | 621 EXPECT_EQ(0, client.num_draws()); |
| 530 | 622 |
| 531 // Fail the draw. | 623 // Fail the draw. |
| 532 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 624 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 625 scheduler->OnBeginFrameDeadline(); |
| 533 EXPECT_EQ(1, client.num_draws()); | 626 EXPECT_EQ(1, client.num_draws()); |
| 534 | 627 |
| 535 // We have a commit pending and the draw failed, and we didn't lose the redraw | 628 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 536 // request. | 629 // request. |
| 537 EXPECT_TRUE(scheduler->CommitPending()); | 630 EXPECT_TRUE(scheduler->CommitPending()); |
| 538 EXPECT_TRUE(scheduler->RedrawPending()); | 631 EXPECT_TRUE(scheduler->RedrawPending()); |
| 539 EXPECT_TRUE(client.needs_begin_frame()); | 632 EXPECT_TRUE(client.needs_begin_frame()); |
| 540 | 633 |
| 541 // Fail the draw again. | 634 // Fail the draw again. |
| 542 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 635 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 636 scheduler->OnBeginFrameDeadline(); |
| 543 EXPECT_EQ(2, client.num_draws()); | 637 EXPECT_EQ(2, client.num_draws()); |
| 544 EXPECT_TRUE(scheduler->CommitPending()); | 638 EXPECT_TRUE(scheduler->CommitPending()); |
| 545 EXPECT_TRUE(scheduler->RedrawPending()); | 639 EXPECT_TRUE(scheduler->RedrawPending()); |
| 546 EXPECT_TRUE(client.needs_begin_frame()); | 640 EXPECT_TRUE(client.needs_begin_frame()); |
| 547 | 641 |
| 548 // Draw successfully. | 642 // Draw successfully. |
| 549 client.SetDrawWillHappen(true); | 643 client.SetDrawWillHappen(true); |
| 550 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 644 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 645 scheduler->OnBeginFrameDeadline(); |
| 551 EXPECT_EQ(3, client.num_draws()); | 646 EXPECT_EQ(3, client.num_draws()); |
| 552 EXPECT_TRUE(scheduler->CommitPending()); | 647 EXPECT_TRUE(scheduler->CommitPending()); |
| 553 EXPECT_FALSE(scheduler->RedrawPending()); | 648 EXPECT_FALSE(scheduler->RedrawPending()); |
| 554 EXPECT_TRUE(client.needs_begin_frame()); | 649 EXPECT_TRUE(client.needs_begin_frame()); |
| 555 } | 650 } |
| 556 | 651 |
| 557 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 652 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 558 public: | 653 public: |
| 559 SchedulerClientThatSetNeedsCommitInsideDraw() | 654 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 560 : set_needs_commit_on_next_draw_(false) {} | 655 : set_needs_commit_on_next_draw_(false) {} |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 TEST(SchedulerTest, RequestCommitInsideDraw) { | 688 TEST(SchedulerTest, RequestCommitInsideDraw) { |
| 594 SchedulerClientThatSetNeedsCommitInsideDraw client; | 689 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 595 SchedulerSettings default_scheduler_settings; | 690 SchedulerSettings default_scheduler_settings; |
| 596 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 691 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 597 scheduler->SetCanStart(); | 692 scheduler->SetCanStart(); |
| 598 scheduler->SetVisible(true); | 693 scheduler->SetVisible(true); |
| 599 scheduler->SetCanDraw(true); | 694 scheduler->SetCanDraw(true); |
| 600 InitializeOutputSurfaceAndFirstCommit(scheduler); | 695 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 601 client.Reset(); | 696 client.Reset(); |
| 602 | 697 |
| 698 EXPECT_FALSE(client.needs_begin_frame()); |
| 603 scheduler->SetNeedsRedraw(); | 699 scheduler->SetNeedsRedraw(); |
| 604 EXPECT_TRUE(scheduler->RedrawPending()); | 700 EXPECT_TRUE(scheduler->RedrawPending()); |
| 605 EXPECT_EQ(0, client.num_draws()); | 701 EXPECT_EQ(0, client.num_draws()); |
| 606 EXPECT_TRUE(client.needs_begin_frame()); | 702 EXPECT_TRUE(client.needs_begin_frame()); |
| 607 | 703 |
| 608 client.SetNeedsCommitOnNextDraw(); | 704 client.SetNeedsCommitOnNextDraw(); |
| 609 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 705 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 706 client.SetNeedsCommitOnNextDraw(); |
| 707 scheduler->OnBeginFrameDeadline(); |
| 610 EXPECT_EQ(1, client.num_draws()); | 708 EXPECT_EQ(1, client.num_draws()); |
| 611 EXPECT_TRUE(scheduler->CommitPending()); | 709 EXPECT_TRUE(scheduler->CommitPending()); |
| 612 EXPECT_TRUE(client.needs_begin_frame()); | 710 EXPECT_TRUE(client.needs_begin_frame()); |
| 613 scheduler->FinishCommit(); | 711 scheduler->FinishCommit(); |
| 614 | 712 |
| 615 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 713 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 616 EXPECT_EQ(2, client.num_draws());; | 714 scheduler->OnBeginFrameDeadline(); |
| 715 EXPECT_EQ(2, client.num_draws()); |
| 716 |
| 617 EXPECT_FALSE(scheduler->RedrawPending()); | 717 EXPECT_FALSE(scheduler->RedrawPending()); |
| 618 EXPECT_FALSE(scheduler->CommitPending()); | 718 EXPECT_FALSE(scheduler->CommitPending()); |
| 619 EXPECT_TRUE(client.needs_begin_frame()); | 719 EXPECT_TRUE(client.needs_begin_frame()); |
| 620 | 720 |
| 621 // We stop requesting BeginFrames after a BeginFrame where we don't swap. | 721 // We stop requesting BeginFrames after a BeginFrame where we don't swap. |
| 622 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 722 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 723 scheduler->OnBeginFrameDeadline(); |
| 623 EXPECT_EQ(2, client.num_draws()); | 724 EXPECT_EQ(2, client.num_draws()); |
| 624 EXPECT_FALSE(scheduler->RedrawPending()); | 725 EXPECT_FALSE(scheduler->RedrawPending()); |
| 625 EXPECT_FALSE(scheduler->CommitPending()); | 726 EXPECT_FALSE(scheduler->CommitPending()); |
| 626 EXPECT_FALSE(client.needs_begin_frame()); | 727 EXPECT_FALSE(client.needs_begin_frame()); |
| 627 } | 728 } |
| 628 | 729 |
| 629 // Tests that when a draw fails then the pending commit should not be dropped. | 730 // Tests that when a draw fails then the pending commit should not be dropped. |
| 630 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 731 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 631 SchedulerClientThatsetNeedsDrawInsideDraw client; | 732 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 632 SchedulerSettings default_scheduler_settings; | 733 SchedulerSettings default_scheduler_settings; |
| 633 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 734 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 634 scheduler->SetCanStart(); | 735 scheduler->SetCanStart(); |
| 635 scheduler->SetVisible(true); | 736 scheduler->SetVisible(true); |
| 636 scheduler->SetCanDraw(true); | 737 scheduler->SetCanDraw(true); |
| 637 InitializeOutputSurfaceAndFirstCommit(scheduler); | 738 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 638 client.Reset(); | 739 client.Reset(); |
| 639 | 740 |
| 640 client.SetDrawWillHappen(false); | 741 client.SetDrawWillHappen(false); |
| 641 | 742 |
| 642 scheduler->SetNeedsRedraw(); | 743 scheduler->SetNeedsRedraw(); |
| 643 EXPECT_TRUE(scheduler->RedrawPending()); | 744 EXPECT_TRUE(scheduler->RedrawPending()); |
| 644 EXPECT_TRUE(client.needs_begin_frame()); | 745 EXPECT_TRUE(client.needs_begin_frame()); |
| 645 EXPECT_EQ(0, client.num_draws()); | 746 EXPECT_EQ(0, client.num_draws()); |
| 646 | 747 |
| 647 // Fail the draw. | 748 // Fail the draw. |
| 648 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 749 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 750 scheduler->OnBeginFrameDeadline(); |
| 649 EXPECT_EQ(1, client.num_draws()); | 751 EXPECT_EQ(1, client.num_draws()); |
| 650 | 752 |
| 651 // We have a commit pending and the draw failed, and we didn't lose the commit | 753 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 652 // request. | 754 // request. |
| 653 EXPECT_TRUE(scheduler->CommitPending()); | 755 EXPECT_TRUE(scheduler->CommitPending()); |
| 654 EXPECT_TRUE(scheduler->RedrawPending()); | 756 EXPECT_TRUE(scheduler->RedrawPending()); |
| 655 EXPECT_TRUE(client.needs_begin_frame()); | 757 EXPECT_TRUE(client.needs_begin_frame()); |
| 656 | 758 |
| 657 // Fail the draw again. | 759 // Fail the draw again. |
| 658 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 760 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 761 scheduler->OnBeginFrameDeadline(); |
| 659 EXPECT_EQ(2, client.num_draws()); | 762 EXPECT_EQ(2, client.num_draws()); |
| 660 EXPECT_TRUE(scheduler->CommitPending()); | 763 EXPECT_TRUE(scheduler->CommitPending()); |
| 661 EXPECT_TRUE(scheduler->RedrawPending()); | 764 EXPECT_TRUE(scheduler->RedrawPending()); |
| 662 EXPECT_TRUE(client.needs_begin_frame()); | 765 EXPECT_TRUE(client.needs_begin_frame()); |
| 663 | 766 |
| 664 // Draw successfully. | 767 // Draw successfully. |
| 665 client.SetDrawWillHappen(true); | 768 client.SetDrawWillHappen(true); |
| 666 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 769 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 770 scheduler->OnBeginFrameDeadline(); |
| 667 EXPECT_EQ(3, client.num_draws()); | 771 EXPECT_EQ(3, client.num_draws()); |
| 668 EXPECT_TRUE(scheduler->CommitPending()); | 772 EXPECT_TRUE(scheduler->CommitPending()); |
| 669 EXPECT_FALSE(scheduler->RedrawPending()); | 773 EXPECT_FALSE(scheduler->RedrawPending()); |
| 670 EXPECT_TRUE(client.needs_begin_frame()); | 774 EXPECT_TRUE(client.needs_begin_frame()); |
| 671 } | 775 } |
| 672 | 776 |
| 673 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 777 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| 674 SchedulerClientThatSetNeedsCommitInsideDraw client; | 778 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 675 SchedulerSettings default_scheduler_settings; | 779 SchedulerSettings default_scheduler_settings; |
| 676 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 780 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 677 scheduler->SetCanStart(); | 781 scheduler->SetCanStart(); |
| 678 scheduler->SetVisible(true); | 782 scheduler->SetVisible(true); |
| 679 scheduler->SetCanDraw(true); | 783 scheduler->SetCanDraw(true); |
| 680 InitializeOutputSurfaceAndFirstCommit(scheduler); | 784 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 681 client.Reset(); | 785 client.Reset(); |
| 682 | 786 |
| 683 scheduler->SetNeedsRedraw(); | 787 scheduler->SetNeedsRedraw(); |
| 684 EXPECT_TRUE(scheduler->RedrawPending()); | 788 EXPECT_TRUE(scheduler->RedrawPending()); |
| 685 EXPECT_TRUE(client.needs_begin_frame()); | 789 EXPECT_TRUE(client.needs_begin_frame()); |
| 686 EXPECT_EQ(0, client.num_draws()); | 790 EXPECT_EQ(0, client.num_draws()); |
| 687 | 791 |
| 688 // Draw successfully, this starts a new frame. | 792 // Draw successfully, this starts a new frame. |
| 689 client.SetNeedsCommitOnNextDraw(); | 793 client.SetNeedsCommitOnNextDraw(); |
| 690 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 794 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 795 scheduler->OnBeginFrameDeadline(); |
| 691 EXPECT_EQ(1, client.num_draws()); | 796 EXPECT_EQ(1, client.num_draws()); |
| 692 | 797 |
| 693 scheduler->SetNeedsRedraw(); | 798 scheduler->SetNeedsRedraw(); |
| 694 EXPECT_TRUE(scheduler->RedrawPending()); | 799 EXPECT_TRUE(scheduler->RedrawPending()); |
| 695 EXPECT_TRUE(client.needs_begin_frame()); | 800 EXPECT_TRUE(client.needs_begin_frame()); |
| 696 | 801 |
| 697 // Fail to draw, this should not start a frame. | 802 // Fail to draw, this should not start a frame. |
| 698 client.SetDrawWillHappen(false); | 803 client.SetDrawWillHappen(false); |
| 699 client.SetNeedsCommitOnNextDraw(); | 804 client.SetNeedsCommitOnNextDraw(); |
| 700 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 805 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 806 scheduler->OnBeginFrameDeadline(); |
| 701 EXPECT_EQ(2, client.num_draws()); | 807 EXPECT_EQ(2, client.num_draws()); |
| 702 } | 808 } |
| 703 | 809 |
| 704 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { | 810 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { |
| 705 FakeSchedulerClient client; | 811 FakeSchedulerClient client; |
| 706 SchedulerSettings default_scheduler_settings; | 812 SchedulerSettings default_scheduler_settings; |
| 707 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 813 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 708 | 814 |
| 709 // Tell the client that it will fail to swap. | 815 // Tell the client that it will fail to swap. |
| 710 client.SetDrawWillHappen(true); | 816 client.SetDrawWillHappen(true); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 // be trigged until BeginFrame. | 873 // be trigged until BeginFrame. |
| 768 client.Reset(); | 874 client.Reset(); |
| 769 scheduler->SetNeedsManageTiles(); | 875 scheduler->SetNeedsManageTiles(); |
| 770 scheduler->SetNeedsRedraw(); | 876 scheduler->SetNeedsRedraw(); |
| 771 EXPECT_TRUE(scheduler->RedrawPending()); | 877 EXPECT_TRUE(scheduler->RedrawPending()); |
| 772 EXPECT_TRUE(scheduler->ManageTilesPending()); | 878 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 773 EXPECT_TRUE(client.needs_begin_frame()); | 879 EXPECT_TRUE(client.needs_begin_frame()); |
| 774 EXPECT_EQ(0, client.num_draws()); | 880 EXPECT_EQ(0, client.num_draws()); |
| 775 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 881 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 776 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 882 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 883 |
| 884 // We have no immediate actions to perform, so the BeginFrame should post |
| 885 // the deadline task. |
| 886 client.Reset(); |
| 777 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 887 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 778 // The actions should have occured, in the right order. | 888 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 889 |
| 890 // On the deadline, he actions should have occured in the right order. |
| 891 client.Reset(); |
| 892 scheduler->OnBeginFrameDeadline(); |
| 779 EXPECT_EQ(1, client.num_draws()); | 893 EXPECT_EQ(1, client.num_draws()); |
| 780 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 894 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 781 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 895 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 782 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 896 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 783 client.ActionIndex("ScheduledActionManageTiles")); | 897 client.ActionIndex("ScheduledActionManageTiles")); |
| 784 EXPECT_FALSE(scheduler->RedrawPending()); | 898 EXPECT_FALSE(scheduler->RedrawPending()); |
| 785 EXPECT_FALSE(scheduler->ManageTilesPending()); | 899 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 786 | 900 |
| 787 // Request a draw. We don't need a ManageTiles yet. | 901 // Request a draw. We don't need a ManageTiles yet. |
| 788 client.Reset(); | 902 client.Reset(); |
| 789 scheduler->SetNeedsRedraw(); | 903 scheduler->SetNeedsRedraw(); |
| 790 EXPECT_TRUE(scheduler->RedrawPending()); | 904 EXPECT_TRUE(scheduler->RedrawPending()); |
| 791 EXPECT_FALSE(scheduler->ManageTilesPending()); | 905 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 792 EXPECT_TRUE(client.needs_begin_frame()); | 906 EXPECT_TRUE(client.needs_begin_frame()); |
| 793 EXPECT_EQ(0, client.num_draws()); | 907 EXPECT_EQ(0, client.num_draws()); |
| 794 | 908 |
| 909 // We have no immediate actions to perform, so the BeginFrame should post |
| 910 // the deadline task. |
| 911 client.Reset(); |
| 912 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 913 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 914 |
| 795 // Draw. The draw will trigger SetNeedsManageTiles, and | 915 // Draw. The draw will trigger SetNeedsManageTiles, and |
| 796 // then the ManageTiles action will be triggered after the Draw. | 916 // then the ManageTiles action will be triggered after the Draw. |
| 797 // Afterwards, neither a draw nor ManageTiles are pending. | 917 // Afterwards, neither a draw nor ManageTiles are pending. |
| 798 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 918 client.Reset(); |
| 919 scheduler->OnBeginFrameDeadline(); |
| 799 EXPECT_EQ(1, client.num_draws()); | 920 EXPECT_EQ(1, client.num_draws()); |
| 800 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 921 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 801 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 922 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 802 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 923 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 803 client.ActionIndex("ScheduledActionManageTiles")); | 924 client.ActionIndex("ScheduledActionManageTiles")); |
| 804 EXPECT_FALSE(scheduler->RedrawPending()); | 925 EXPECT_FALSE(scheduler->RedrawPending()); |
| 805 EXPECT_FALSE(scheduler->ManageTilesPending()); | 926 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 806 | 927 |
| 807 // We need a BeginFrame where we don't swap to go idle. | 928 // We need a BeginFrame where we don't swap to go idle. |
| 808 client.Reset(); | 929 client.Reset(); |
| 809 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 930 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 810 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 931 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 932 client.Reset(); |
| 933 scheduler->OnBeginFrameDeadline(); |
| 934 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);; |
| 811 EXPECT_EQ(0, client.num_draws()); | 935 EXPECT_EQ(0, client.num_draws()); |
| 812 | 936 |
| 813 // Now trigger a ManageTiles outside of a draw. We will then need | 937 // Now trigger a ManageTiles outside of a draw. We will then need |
| 814 // a begin-frame for the ManageTiles, but we don't need a draw. | 938 // a begin-frame for the ManageTiles, but we don't need a draw. |
| 815 client.Reset(); | 939 client.Reset(); |
| 816 EXPECT_FALSE(client.needs_begin_frame()); | 940 EXPECT_FALSE(client.needs_begin_frame()); |
| 817 scheduler->SetNeedsManageTiles(); | 941 scheduler->SetNeedsManageTiles(); |
| 818 EXPECT_TRUE(client.needs_begin_frame()); | 942 EXPECT_TRUE(client.needs_begin_frame()); |
| 819 EXPECT_TRUE(scheduler->ManageTilesPending()); | 943 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 820 EXPECT_FALSE(scheduler->RedrawPending()); | 944 EXPECT_FALSE(scheduler->RedrawPending()); |
| 821 | 945 |
| 822 // BeginFrame. There will be no draw, only ManageTiles. | 946 // BeginFrame. There will be no draw, only ManageTiles. |
| 947 client.Reset(); |
| 823 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 948 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 949 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client); |
| 950 client.Reset(); |
| 951 scheduler->OnBeginFrameDeadline(); |
| 824 EXPECT_EQ(0, client.num_draws()); | 952 EXPECT_EQ(0, client.num_draws()); |
| 825 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 953 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 826 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 954 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 827 } | 955 } |
| 828 | 956 |
| 829 } // namespace | 957 } // namespace |
| 830 } // namespace cc | 958 } // namespace cc |
| OLD | NEW |