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