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 | 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 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 | 2571 |
2572 layer_tree_host()->SetRootLayer(root); | 2572 layer_tree_host()->SetRootLayer(root); |
2573 LayerTreeHostTest::SetupTree(); | 2573 LayerTreeHostTest::SetupTree(); |
2574 } | 2574 } |
2575 | 2575 |
2576 virtual void BeginTest() OVERRIDE { | 2576 virtual void BeginTest() OVERRIDE { |
2577 PostSetNeedsCommitToMainThread(); | 2577 PostSetNeedsCommitToMainThread(); |
2578 } | 2578 } |
2579 | 2579 |
2580 virtual void DidCommitAndDrawFrame() { | 2580 virtual void DidCommitAndDrawFrame() { |
| 2581 WaitForCallback(); |
| 2582 } |
| 2583 |
| 2584 void WaitForCallback() { |
| 2585 base::MessageLoop::current()->PostTask( |
| 2586 FROM_HERE, |
| 2587 base::Bind( |
| 2588 &LayerTreeHostTestAsyncReadback::NextStep, |
| 2589 base::Unretained(this))); |
| 2590 } |
| 2591 |
| 2592 void NextStep() { |
2581 int frame = layer_tree_host()->commit_number(); | 2593 int frame = layer_tree_host()->commit_number(); |
2582 switch (frame) { | 2594 switch (frame) { |
2583 case 1: | 2595 case 1: |
2584 child->RequestCopyAsBitmap(base::Bind( | 2596 child->RequestCopyAsBitmap(base::Bind( |
2585 &LayerTreeHostTestAsyncReadback::BitmapCallback, | 2597 &LayerTreeHostTestAsyncReadback::BitmapCallback, |
2586 base::Unretained(this))); | 2598 base::Unretained(this))); |
2587 EXPECT_EQ(0u, callbacks_.size()); | 2599 EXPECT_EQ(0u, callbacks_.size()); |
2588 break; | 2600 break; |
2589 case 2: | 2601 case 2: |
2590 // Flush the message loops and make sure the callbacks run. | 2602 if (callbacks_.size() < 1u) { |
2591 layer_tree_host()->SetNeedsCommit(); | 2603 WaitForCallback(); |
2592 break; | 2604 return; |
2593 case 3: | 2605 } |
2594 ASSERT_EQ(1u, callbacks_.size()); | 2606 EXPECT_EQ(1u, callbacks_.size()); |
2595 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); | 2607 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString()); |
2596 | 2608 |
2597 child->RequestCopyAsBitmap(base::Bind( | 2609 child->RequestCopyAsBitmap(base::Bind( |
2598 &LayerTreeHostTestAsyncReadback::BitmapCallback, | 2610 &LayerTreeHostTestAsyncReadback::BitmapCallback, |
2599 base::Unretained(this))); | 2611 base::Unretained(this))); |
2600 root->RequestCopyAsBitmap(base::Bind( | 2612 root->RequestCopyAsBitmap(base::Bind( |
2601 &LayerTreeHostTestAsyncReadback::BitmapCallback, | 2613 &LayerTreeHostTestAsyncReadback::BitmapCallback, |
2602 base::Unretained(this))); | 2614 base::Unretained(this))); |
2603 child->RequestCopyAsBitmap(base::Bind( | 2615 child->RequestCopyAsBitmap(base::Bind( |
2604 &LayerTreeHostTestAsyncReadback::BitmapCallback, | 2616 &LayerTreeHostTestAsyncReadback::BitmapCallback, |
2605 base::Unretained(this))); | 2617 base::Unretained(this))); |
2606 EXPECT_EQ(1u, callbacks_.size()); | 2618 EXPECT_EQ(1u, callbacks_.size()); |
2607 break; | 2619 break; |
2608 case 4: | 2620 case 3: |
2609 // Flush the message loops and make sure the callbacks run. | 2621 if (callbacks_.size() < 4u) { |
2610 layer_tree_host()->SetNeedsCommit(); | 2622 WaitForCallback(); |
2611 break; | 2623 return; |
2612 case 5: | 2624 } |
2613 ASSERT_EQ(4u, callbacks_.size()); | 2625 EXPECT_EQ(4u, callbacks_.size()); |
2614 // The child was copied to a bitmap and passed back twice. | 2626 // The child was copied to a bitmap and passed back twice. |
2615 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString()); | 2627 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString()); |
2616 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[2].ToString()); | 2628 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[2].ToString()); |
2617 // The root was copied to a bitmap and passed back also. | 2629 // The root was copied to a bitmap and passed back also. |
2618 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[3].ToString()); | 2630 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[3].ToString()); |
2619 EndTest(); | 2631 EndTest(); |
2620 break; | 2632 break; |
2621 } | 2633 } |
2622 } | 2634 } |
2623 | 2635 |
2624 void BitmapCallback(scoped_ptr<SkBitmap> bitmap) { | 2636 void BitmapCallback(scoped_ptr<SkBitmap> bitmap) { |
2625 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 2637 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
2626 EXPECT_TRUE(bitmap); | 2638 EXPECT_TRUE(bitmap); |
2627 callbacks_.push_back(gfx::Size(bitmap->width(), bitmap->height())); | 2639 callbacks_.push_back(gfx::Size(bitmap->width(), bitmap->height())); |
2628 } | 2640 } |
2629 | 2641 |
2630 virtual void AfterTest() {} | 2642 virtual void AfterTest() { |
| 2643 EXPECT_EQ(4u, callbacks_.size()); |
| 2644 } |
2631 | 2645 |
2632 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { | 2646 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { |
2633 if (use_gl_renderer_) | 2647 if (use_gl_renderer_) |
2634 return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); | 2648 return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); |
2635 return FakeOutputSurface::CreateSoftware( | 2649 return FakeOutputSurface::CreateSoftware( |
2636 make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>(); | 2650 make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>(); |
2637 } | 2651 } |
2638 | 2652 |
2639 bool use_gl_renderer_; | 2653 bool use_gl_renderer_; |
2640 std::vector<gfx::Size> callbacks_; | 2654 std::vector<gfx::Size> callbacks_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2747 FakeContentLayerClient client_; | 2761 FakeContentLayerClient client_; |
2748 scoped_refptr<FakeContentLayer> root_; | 2762 scoped_refptr<FakeContentLayer> root_; |
2749 scoped_refptr<FakeContentLayer> main_destroyed_; | 2763 scoped_refptr<FakeContentLayer> main_destroyed_; |
2750 scoped_refptr<FakeContentLayer> impl_destroyed_; | 2764 scoped_refptr<FakeContentLayer> impl_destroyed_; |
2751 }; | 2765 }; |
2752 | 2766 |
2753 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncReadbackLayerDestroyed); | 2767 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncReadbackLayerDestroyed); |
2754 | 2768 |
2755 } // namespace | 2769 } // namespace |
2756 } // namespace cc | 2770 } // namespace cc |
OLD | NEW |