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

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

Issue 14060015: cc: Async readback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "cc/animation/timing_function.h" 10 #include "cc/animation/timing_function.h"
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 2552
2553 virtual void AfterTest() OVERRIDE {} 2553 virtual void AfterTest() OVERRIDE {}
2554 2554
2555 int io_surface_id_; 2555 int io_surface_id_;
2556 MockIOSurfaceWebGraphicsContext3D* mock_context_; 2556 MockIOSurfaceWebGraphicsContext3D* mock_context_;
2557 gfx::Size io_surface_size_; 2557 gfx::Size io_surface_size_;
2558 }; 2558 };
2559 2559
2560 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing); 2560 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing);
2561 2561
2562 class LayerTreeHostTestAsyncReadback : public LayerTreeHostTest {
2563 protected:
2564 virtual void SetupTree() OVERRIDE {
2565 root = FakeContentLayer::Create(&client_);
2566 root->SetBounds(gfx::Size(20, 20));
2567
2568 child = FakeContentLayer::Create(&client_);
2569 child->SetBounds(gfx::Size(10, 10));
2570 root->AddChild(child);
2571
2572 layer_tree_host()->SetRootLayer(root);
2573 LayerTreeHostTest::SetupTree();
2574 }
2575
2576 virtual void BeginTest() OVERRIDE {
2577 PostSetNeedsCommitToMainThread();
2578 }
2579
2580 virtual void DidCommitAndDrawFrame() {
2581 int frame = layer_tree_host()->commit_number();
2582 switch (frame) {
2583 case 1:
2584 child->RequestCopyAsBitmap(base::Bind(
2585 &LayerTreeHostTestAsyncReadback::BitmapCallback,
2586 base::Unretained(this)));
2587 EXPECT_EQ(0u, callbacks_.size());
2588 break;
2589 case 2:
2590 // Flush the message loops and make sure the callbacks run.
2591 layer_tree_host()->SetNeedsCommit();
2592 break;
2593 case 3:
2594 ASSERT_EQ(1u, callbacks_.size());
2595 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString());
2596
2597 child->RequestCopyAsBitmap(base::Bind(
2598 &LayerTreeHostTestAsyncReadback::BitmapCallback,
2599 base::Unretained(this)));
2600 root->RequestCopyAsBitmap(base::Bind(
2601 &LayerTreeHostTestAsyncReadback::BitmapCallback,
2602 base::Unretained(this)));
2603 child->RequestCopyAsBitmap(base::Bind(
2604 &LayerTreeHostTestAsyncReadback::BitmapCallback,
2605 base::Unretained(this)));
2606 EXPECT_EQ(1u, callbacks_.size());
2607 break;
2608 case 4:
2609 // Flush the message loops and make sure the callbacks run.
2610 layer_tree_host()->SetNeedsCommit();
2611 break;
2612 case 5:
2613 ASSERT_EQ(4u, callbacks_.size());
2614 // The child was copied to a bitmap and passed back twice.
2615 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString());
2616 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[2].ToString());
2617 // The root was copied to a bitmap and passed back also.
2618 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[3].ToString());
2619 EndTest();
2620 break;
2621 }
2622 }
2623
2624 void BitmapCallback(scoped_ptr<SkBitmap> bitmap) {
2625 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
2626 EXPECT_TRUE(bitmap);
2627 callbacks_.push_back(gfx::Size(bitmap->width(), bitmap->height()));
2628 }
2629
2630 virtual void AfterTest() {}
2631
2632 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE {
2633 if (use_gl_renderer_)
2634 return FakeOutputSurface::Create3d().PassAs<OutputSurface>();
2635 return FakeOutputSurface::CreateSoftware(
2636 make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>();
2637 }
2638
2639 bool use_gl_renderer_;
2640 std::vector<gfx::Size> callbacks_;
2641 FakeContentLayerClient client_;
2642 scoped_refptr<FakeContentLayer> root;
2643 scoped_refptr<FakeContentLayer> child;
2644 };
2645
2646 TEST_F(LayerTreeHostTestAsyncReadback, GLRenderer_RunSingleThread) {
2647 use_gl_renderer_ = true;
2648 RunTest(false);
2649 }
2650
2651 TEST_F(LayerTreeHostTestAsyncReadback, GLRenderer_RunMultiThread) {
2652 use_gl_renderer_ = true;
2653 RunTest(true);
2654 }
2655
2656 TEST_F(LayerTreeHostTestAsyncReadback, SoftwareRenderer_RunSingleThread) {
2657 use_gl_renderer_ = false;
2658 RunTest(false);
2659 }
2660
2661 TEST_F(LayerTreeHostTestAsyncReadback, SoftwareRenderer_RunMultiThread) {
2662 use_gl_renderer_ = false;
2663 RunTest(true);
2664 }
2665
2666 class LayerTreeHostTestAsyncReadbackLayerDestroyed : public LayerTreeHostTest {
2667 protected:
2668 virtual void SetupTree() OVERRIDE {
2669 root_ = FakeContentLayer::Create(&client_);
2670 root_->SetBounds(gfx::Size(20, 20));
2671
2672 main_destroyed_ = FakeContentLayer::Create(&client_);
2673 main_destroyed_->SetBounds(gfx::Size(15, 15));
2674 root_->AddChild(main_destroyed_);
2675
2676 impl_destroyed_ = FakeContentLayer::Create(&client_);
2677 impl_destroyed_->SetBounds(gfx::Size(10, 10));
2678 root_->AddChild(impl_destroyed_);
2679
2680 layer_tree_host()->SetRootLayer(root_);
2681 LayerTreeHostTest::SetupTree();
2682 }
2683
2684 virtual void BeginTest() OVERRIDE {
2685 callback_count_ = 0;
2686 PostSetNeedsCommitToMainThread();
2687 }
2688
2689 virtual void DidCommit() {
2690 int frame = layer_tree_host()->commit_number();
2691 switch (frame) {
2692 case 1:
2693 main_destroyed_->RequestCopyAsBitmap(base::Bind(
2694 &LayerTreeHostTestAsyncReadbackLayerDestroyed::BitmapCallback,
2695 base::Unretained(this)));
2696 impl_destroyed_->RequestCopyAsBitmap(base::Bind(
2697 &LayerTreeHostTestAsyncReadbackLayerDestroyed::BitmapCallback,
2698 base::Unretained(this)));
2699 EXPECT_EQ(0, callback_count_);
2700
2701 // Destroy the main thread layer right away.
2702 main_destroyed_->RemoveFromParent();
2703 main_destroyed_ = NULL;
2704
2705 // Should callback with a NULL bitmap.
2706 EXPECT_EQ(1, callback_count_);
2707
2708 // Prevent drawing so we can't make a copy of the impl_destroyed layer.
2709 layer_tree_host()->SetViewportSize(gfx::Size());
2710 break;
2711 case 2:
2712 // Flush the message loops and make sure the callbacks run.
2713 layer_tree_host()->SetNeedsCommit();
2714 break;
2715 case 3:
2716 // No drawing means no readback yet.
2717 EXPECT_EQ(1, callback_count_);
2718
2719 // Destroy the impl thread layer.
2720 impl_destroyed_->RemoveFromParent();
2721 impl_destroyed_ = NULL;
2722
2723 // No callback yet because it's on the impl side.
2724 EXPECT_EQ(1, callback_count_);
2725 break;
2726 case 4:
2727 // Flush the message loops and make sure the callbacks run.
2728 layer_tree_host()->SetNeedsCommit();
2729 break;
2730 case 5:
2731 // We should get another callback with a NULL bitmap.
2732 EXPECT_EQ(2, callback_count_);
2733 EndTest();
2734 break;
2735 }
2736 }
2737
2738 void BitmapCallback(scoped_ptr<SkBitmap> bitmap) {
2739 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
2740 EXPECT_FALSE(bitmap);
2741 ++callback_count_;
2742 }
2743
2744 virtual void AfterTest() {}
2745
2746 int callback_count_;
2747 FakeContentLayerClient client_;
2748 scoped_refptr<FakeContentLayer> root_;
2749 scoped_refptr<FakeContentLayer> main_destroyed_;
2750 scoped_refptr<FakeContentLayer> impl_destroyed_;
2751 };
2752
2753 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncReadbackLayerDestroyed);
2754
2562 } // namespace 2755 } // namespace
2563 } // namespace cc 2756 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698