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

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