| 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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 }; | 691 }; |
| 692 | 692 |
| 693 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); | 693 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); |
| 694 | 694 |
| 695 // This test verifies that LayerTreeHostImpl's current frame time gets | 695 // This test verifies that LayerTreeHostImpl's current frame time gets |
| 696 // updated in consecutive frames when it doesn't draw due to tree | 696 // updated in consecutive frames when it doesn't draw due to tree |
| 697 // activation failure. | 697 // activation failure. |
| 698 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails | 698 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails |
| 699 : public LayerTreeHostTest { | 699 : public LayerTreeHostTest { |
| 700 public: | 700 public: |
| 701 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() : frame_(0) {} | 701 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() |
| 702 : frame_count_with_pending_tree_(0) {} |
| 702 | 703 |
| 703 virtual void BeginTest() OVERRIDE { | 704 virtual void BeginTest() OVERRIDE { |
| 704 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); | 705 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
| 705 layer_tree_host()->set_background_color(SK_ColorGRAY); | 706 layer_tree_host()->set_background_color(SK_ColorGRAY); |
| 706 | 707 |
| 707 PostSetNeedsCommitToMainThread(); | 708 PostSetNeedsCommitToMainThread(); |
| 708 } | 709 } |
| 709 | 710 |
| 711 void WillBeginFrameOnThread(LayerTreeHostImpl* host_impl, |
| 712 const BeginFrameArgs &args) OVERRIDE { |
| 713 if (host_impl->pending_tree()) |
| 714 frame_count_with_pending_tree_++; |
| 715 } |
| 716 |
| 710 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 717 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 711 if (frame_ >= 1) { | 718 if (frame_count_with_pending_tree_ > 1) { |
| 712 EXPECT_NE(first_frame_time_, impl->CurrentFrameTimeTicks()); | 719 EXPECT_NE(first_frame_time_.ToInternalValue(), |
| 720 impl->CurrentFrameTimeTicks().ToInternalValue()); |
| 713 EndTest(); | 721 EndTest(); |
| 714 return; | 722 return; |
| 715 } | 723 } |
| 716 | 724 |
| 717 EXPECT_FALSE(impl->settings().impl_side_painting); | 725 EXPECT_FALSE(impl->settings().impl_side_painting); |
| 718 EndTest(); | 726 EndTest(); |
| 719 } | 727 } |
| 720 | 728 |
| 721 virtual bool CanActivatePendingTree(LayerTreeHostImpl* impl) OVERRIDE { | 729 virtual bool CanActivatePendingTree(LayerTreeHostImpl* impl) OVERRIDE { |
| 722 if (frame_ >= 1) | 730 return frame_count_with_pending_tree_ > 1; |
| 723 return true; | |
| 724 | |
| 725 return false; | |
| 726 } | 731 } |
| 727 | 732 |
| 728 virtual bool CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* impl) | 733 virtual bool CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* impl) |
| 729 OVERRIDE { | 734 OVERRIDE { |
| 730 frame_++; | 735 if (frame_count_with_pending_tree_ > 1) |
| 731 if (frame_ == 1) { | 736 return true; |
| 737 |
| 738 if (first_frame_time_.is_null()) { |
| 732 first_frame_time_ = impl->CurrentFrameTimeTicks(); | 739 first_frame_time_ = impl->CurrentFrameTimeTicks(); |
| 733 | 740 |
| 734 // Since base::TimeTicks::Now() uses a low-resolution clock on | 741 // Since base::TimeTicks::Now() uses a low-resolution clock on |
| 735 // Windows, we need to make sure that the clock has incremented past | 742 // Windows, we need to make sure that the clock has incremented past |
| 736 // first_frame_time_. | 743 // first_frame_time_. |
| 737 while (first_frame_time_ == base::TimeTicks::Now()) {} | 744 while (first_frame_time_ == base::TimeTicks::Now()) {} |
| 745 } |
| 746 return false; |
| 747 } |
| 738 | 748 |
| 739 return false; | 749 virtual void DidActivateTreeOnThread(LayerTreeHostImpl *impl) { |
| 740 } | 750 if (impl->settings().impl_side_painting) |
| 741 | 751 EXPECT_NE(frame_count_with_pending_tree_, 1); |
| 742 return true; | |
| 743 } | 752 } |
| 744 | 753 |
| 745 virtual void AfterTest() OVERRIDE {} | 754 virtual void AfterTest() OVERRIDE {} |
| 746 | 755 |
| 747 private: | 756 private: |
| 748 int frame_; | 757 int frame_count_with_pending_tree_; |
| 749 base::TimeTicks first_frame_time_; | 758 base::TimeTicks first_frame_time_; |
| 750 }; | 759 }; |
| 751 | 760 |
| 752 SINGLE_AND_MULTI_THREAD_TEST_F( | 761 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 753 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); | 762 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); |
| 754 | 763 |
| 755 // This test verifies that LayerTreeHostImpl's current frame time gets | 764 // This test verifies that LayerTreeHostImpl's current frame time gets |
| 756 // updated in consecutive frames when it draws in each frame. | 765 // updated in consecutive frames when it draws in each frame. |
| 757 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { | 766 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { |
| 758 public: | 767 public: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 impl->ProcessScrollDeltas(); | 840 impl->ProcessScrollDeltas(); |
| 832 // We get one commit before the first draw, and the animation doesn't happen | 841 // We get one commit before the first draw, and the animation doesn't happen |
| 833 // until the second draw. | 842 // until the second draw. |
| 834 switch (impl->active_tree()->source_frame_number()) { | 843 switch (impl->active_tree()->source_frame_number()) { |
| 835 case 0: | 844 case 0: |
| 836 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); | 845 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); |
| 837 // We'll start an animation when we get back to the main thread. | 846 // We'll start an animation when we get back to the main thread. |
| 838 break; | 847 break; |
| 839 case 1: | 848 case 1: |
| 840 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); | 849 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); |
| 841 PostSetNeedsRedrawToMainThread(); | |
| 842 break; | 850 break; |
| 843 case 2: | 851 case 2: |
| 844 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor()); | 852 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor()); |
| 845 EndTest(); | 853 EndTest(); |
| 846 break; | 854 break; |
| 847 default: | 855 default: |
| 848 NOTREACHED(); | 856 NOTREACHED(); |
| 849 } | 857 } |
| 850 } | 858 } |
| 851 | 859 |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 // surface. This prevents any contents drawing into surfaces | 1549 // surface. This prevents any contents drawing into surfaces |
| 1542 // from being allocated. | 1550 // from being allocated. |
| 1543 host_impl->SetMemoryPolicy( | 1551 host_impl->SetMemoryPolicy( |
| 1544 ManagedMemoryPolicy(100 * 100 * 4 * 2), true); | 1552 ManagedMemoryPolicy(100 * 100 * 4 * 2), true); |
| 1545 break; | 1553 break; |
| 1546 case 1: | 1554 case 1: |
| 1547 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( | 1555 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
| 1548 surface1_render_pass_id)); | 1556 surface1_render_pass_id)); |
| 1549 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( | 1557 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
| 1550 surface2_render_pass_id)); | 1558 surface2_render_pass_id)); |
| 1551 | |
| 1552 EndTest(); | 1559 EndTest(); |
| 1553 break; | 1560 break; |
| 1554 } | 1561 } |
| 1555 } | 1562 } |
| 1556 | 1563 |
| 1557 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1564 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 1558 if (!TestEnded()) | 1565 if (!TestEnded()) |
| 1559 root_layer_->SetNeedsDisplay(); | 1566 root_layer_->SetNeedsDisplay(); |
| 1560 } | 1567 } |
| 1561 | 1568 |
| 1562 virtual void AfterTest() OVERRIDE { | 1569 virtual void AfterTest() OVERRIDE { |
| 1563 EXPECT_EQ(3u, root_layer_->update_count()); | 1570 EXPECT_GE(root_layer_->update_count(), 2u); |
| 1564 EXPECT_EQ(3u, surface_layer1_->update_count()); | 1571 EXPECT_GE(surface_layer1_->update_count(), 2u); |
| 1565 EXPECT_EQ(3u, surface_layer2_->update_count()); | 1572 EXPECT_GE(surface_layer2_->update_count(), 2u); |
| 1566 } | 1573 } |
| 1567 | 1574 |
| 1568 private: | 1575 private: |
| 1569 FakeContentLayerClient client_; | 1576 FakeContentLayerClient client_; |
| 1570 scoped_refptr<FakeContentLayer> root_layer_; | 1577 scoped_refptr<FakeContentLayer> root_layer_; |
| 1571 scoped_refptr<FakeContentLayer> surface_layer1_; | 1578 scoped_refptr<FakeContentLayer> surface_layer1_; |
| 1572 scoped_refptr<FakeContentLayer> replica_layer1_; | 1579 scoped_refptr<FakeContentLayer> replica_layer1_; |
| 1573 scoped_refptr<FakeContentLayer> surface_layer2_; | 1580 scoped_refptr<FakeContentLayer> surface_layer2_; |
| 1574 scoped_refptr<FakeContentLayer> replica_layer2_; | 1581 scoped_refptr<FakeContentLayer> replica_layer2_; |
| 1575 }; | 1582 }; |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2309 private: | 2316 private: |
| 2310 base::TimeTicks frame_time_; | 2317 base::TimeTicks frame_time_; |
| 2311 }; | 2318 }; |
| 2312 | 2319 |
| 2313 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); | 2320 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); |
| 2314 | 2321 |
| 2315 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled | 2322 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled |
| 2316 : public LayerTreeHostTest { | 2323 : public LayerTreeHostTest { |
| 2317 public: | 2324 public: |
| 2318 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2325 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 2319 settings->begin_frame_scheduling_enabled = true; | 2326 settings->begin_frame_scheduling_enabled = false; |
| 2320 settings->using_synchronous_renderer_compositor = true; | 2327 settings->using_synchronous_renderer_compositor = true; |
| 2321 } | 2328 } |
| 2322 | 2329 |
| 2323 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 2330 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 2324 | 2331 |
| 2325 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 2332 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 2326 // The BeginFrame notification is turned off now but will get enabled | 2333 // The BeginFrame notification is turned off now but will get enabled |
| 2327 // once we return. End test while it's enabled. | 2334 // once we return. End test while it's enabled. |
| 2328 ImplThreadTaskRunner()->PostTask( | 2335 ImplThreadTaskRunner()->PostTask( |
| 2329 FROM_HERE, | 2336 FROM_HERE, base::Bind( |
| 2330 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest, | 2337 &LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled::EndTest, |
| 2331 base::Unretained(this))); | 2338 base::Unretained(this))); |
| 2332 } | 2339 } |
| 2333 | 2340 |
| 2334 virtual void AfterTest() OVERRIDE {} | 2341 virtual void AfterTest() OVERRIDE {} |
| 2335 }; | 2342 }; |
| 2336 | 2343 |
| 2337 MULTI_THREAD_TEST_F( | 2344 MULTI_THREAD_TEST_F( |
| 2338 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); | 2345 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); |
| 2339 | 2346 |
| 2340 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation | 2347 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation |
| 2341 : public LayerTreeHostTest { | 2348 : public LayerTreeHostTest { |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3042 layer_tree_host()->SetNeedsRedraw(); | 3049 layer_tree_host()->SetNeedsRedraw(); |
| 3043 break; | 3050 break; |
| 3044 case 3: | 3051 case 3: |
| 3045 // CompositeAndReadback in Round 4, first commit. | 3052 // CompositeAndReadback in Round 4, first commit. |
| 3046 EXPECT_EQ(2, frame_); | 3053 EXPECT_EQ(2, frame_); |
| 3047 break; | 3054 break; |
| 3048 case 4: | 3055 case 4: |
| 3049 // Round 4 done. | 3056 // Round 4 done. |
| 3050 EXPECT_EQ(2, frame_); | 3057 EXPECT_EQ(2, frame_); |
| 3051 layer_tree_host()->SetNeedsCommit(); | 3058 layer_tree_host()->SetNeedsCommit(); |
| 3059 // We cant SetNeedsRedraw immediately because it will race the commit. |
| 3060 break; |
| 3061 case 5: |
| 3062 EXPECT_EQ(2, frame_); |
| 3052 layer_tree_host()->SetNeedsRedraw(); | 3063 layer_tree_host()->SetNeedsRedraw(); |
| 3053 break; | 3064 break; |
| 3054 } | 3065 } |
| 3055 } | 3066 } |
| 3056 | 3067 |
| 3057 virtual void DidCompleteSwapBuffers() OVERRIDE { | 3068 virtual void DidCompleteSwapBuffers() OVERRIDE { |
| 3058 int commit = layer_tree_host()->commit_number(); | 3069 int commit = layer_tree_host()->commit_number(); |
| 3059 ++frame_; | 3070 ++frame_; |
| 3060 char pixels[4] = {0}; | 3071 char pixels[4] = {0}; |
| 3061 switch (frame_) { | 3072 switch (frame_) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3162 FakeContentLayerClient client_; | 3173 FakeContentLayerClient client_; |
| 3163 scoped_refptr<FakePictureLayer> layer_; | 3174 scoped_refptr<FakePictureLayer> layer_; |
| 3164 bool initialized_gl_; | 3175 bool initialized_gl_; |
| 3165 int num_draws_; | 3176 int num_draws_; |
| 3166 }; | 3177 }; |
| 3167 | 3178 |
| 3168 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); | 3179 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
| 3169 | 3180 |
| 3170 } // namespace | 3181 } // namespace |
| 3171 } // namespace cc | 3182 } // namespace cc |
| OLD | NEW |