Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 23503003: cc: Add readback and forced draw states to the Scheduler (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedReorg3
Patch Set: Address enne's commetns Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 496
497 virtual void AfterTest() OVERRIDE {} 497 virtual void AfterTest() OVERRIDE {}
498 498
499 private: 499 private:
500 int num_commits_; 500 int num_commits_;
501 }; 501 };
502 502
503 MULTI_THREAD_TEST_F( 503 MULTI_THREAD_TEST_F(
504 LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws); 504 LayerTreeHostTestCompositeAndReadbackBeforePreviousCommitDraws);
505 505
506 class LayerTreeHostTestCompositeAndReadbackDuringForcedDraw
507 : public LayerTreeHostTest {
508 protected:
509 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
510 // This enables forced draws after a single prepare to draw failure.
511 settings->timeout_and_draw_when_animation_checkerboards = true;
512 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
513 }
514
515 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
516
517 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
518 LayerTreeHostImpl::FrameData* frame_data,
519 bool result) OVERRIDE {
520 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
521 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 2);
522
523 // Before we react to the failed draw by initiating the forced draw
524 // sequence, start a readback on the main thread.
525 if (host_impl->active_tree()->source_frame_number() == 0)
526 PostReadbackToMainThread();
527
528 // Returning false will eventually result in a forced draw.
529 return false;
530 }
531
532 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
533 // We should only draw for the readback and the forced draw.
534 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 1);
535 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 2);
536 }
537
538 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
539 bool result) OVERRIDE {
540 // We should only swap for the forced draw.
541 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 2);
542 EndTest();
543 }
544
545 virtual void AfterTest() OVERRIDE {}
546 };
547
548 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackDuringForcedDraw);
549
550 class LayerTreeHostTestCompositeAndReadbackAfterForcedDraw
551 : public LayerTreeHostTest {
552 protected:
553 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
554 // This enables forced draws after a single prepare to draw failure.
555 settings->timeout_and_draw_when_animation_checkerboards = true;
556 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
557 }
558
559 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
560
561 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
562 LayerTreeHostImpl::FrameData* frame_data,
563 bool result) OVERRIDE {
564 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
565 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 3);
566
567 // Returning false will eventually result in a forced draw.
568 return false;
569 }
570
571 virtual void DidCommit() OVERRIDE {
572 if (layer_tree_host()->source_frame_number() == 1) {
573 // Avoid aborting the forced draw commit so source_frame_number
574 // increments.
575 layer_tree_host()->SetNeedsCommit();
576 } else if (layer_tree_host()->source_frame_number() == 2) {
577 // Perform a readback immediately after the forced draw's commit.
578 char pixels[4];
579 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
580 }
581 }
582
583 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
584 // We should only draw for the the forced draw, readback, and
585 // replacement commit.
586 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 1);
587 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 3);
588 }
589
590 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
591 bool result) OVERRIDE {
592 // We should only swap for the forced draw and replacement commit.
593 EXPECT_TRUE(host_impl->active_tree()->source_frame_number() == 1 ||
594 host_impl->active_tree()->source_frame_number() == 3);
595 if (host_impl->active_tree()->source_frame_number() == 3)
596 EndTest();
597 }
598
599 virtual void AfterTest() OVERRIDE {}
600 };
601
602 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackAfterForcedDraw);
603
506 // If the layerTreeHost says it can't draw, Then we should not try to draw. 604 // If the layerTreeHost says it can't draw, Then we should not try to draw.
507 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest { 605 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest {
508 public: 606 public:
509 LayerTreeHostTestCanDrawBlocksDrawing() : num_commits_(0), done_(false) {} 607 LayerTreeHostTestCanDrawBlocksDrawing() : num_commits_(0), done_(false) {}
510 608
511 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 609 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
512 610
513 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 611 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
514 if (done_) 612 if (done_)
515 return; 613 return;
(...skipping 3944 matching lines...) Expand 10 before | Expand all | Expand 10 after
4460 int num_will_begin_frames_; 4558 int num_will_begin_frames_;
4461 int num_impl_commits_; 4559 int num_impl_commits_;
4462 }; 4560 };
4463 4561
4464 // Commits can only be aborted when using the thread proxy. 4562 // Commits can only be aborted when using the thread proxy.
4465 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); 4563 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures);
4466 4564
4467 } // namespace 4565 } // namespace
4468 4566
4469 } // namespace cc 4567 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698