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/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 }; | 690 }; |
691 | 691 |
692 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); | 692 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); |
693 | 693 |
694 // This test verifies that LayerTreeHostImpl's current frame time gets | 694 // This test verifies that LayerTreeHostImpl's current frame time gets |
695 // updated in consecutive frames when it doesn't draw due to tree | 695 // updated in consecutive frames when it doesn't draw due to tree |
696 // activation failure. | 696 // activation failure. |
697 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails | 697 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails |
698 : public LayerTreeHostTest { | 698 : public LayerTreeHostTest { |
699 public: | 699 public: |
700 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() : frame_(0) {} | 700 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() |
| 701 : frame_count_with_pending_tree_(0) {} |
701 | 702 |
702 virtual void BeginTest() OVERRIDE { | 703 virtual void BeginTest() OVERRIDE { |
703 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); | 704 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
704 layer_tree_host()->set_background_color(SK_ColorGRAY); | 705 layer_tree_host()->set_background_color(SK_ColorGRAY); |
705 | 706 |
706 PostSetNeedsCommitToMainThread(); | 707 PostSetNeedsCommitToMainThread(); |
707 } | 708 } |
708 | 709 |
| 710 virtual void WillBeginFrameOnThread(LayerTreeHostImpl* host_impl, |
| 711 const BeginFrameArgs &args) OVERRIDE { |
| 712 if (host_impl->pending_tree()) |
| 713 frame_count_with_pending_tree_++; |
| 714 } |
| 715 |
709 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 716 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
710 if (frame_ >= 1) { | 717 if (frame_count_with_pending_tree_ > 1) { |
711 EXPECT_NE(first_frame_time_, impl->CurrentFrameTimeTicks()); | 718 EXPECT_NE(first_frame_time_.ToInternalValue(), |
| 719 impl->CurrentFrameTimeTicks().ToInternalValue()); |
712 EndTest(); | 720 EndTest(); |
713 return; | 721 return; |
714 } | 722 } |
715 | 723 |
716 EXPECT_FALSE(impl->settings().impl_side_painting); | 724 EXPECT_FALSE(impl->settings().impl_side_painting); |
717 EndTest(); | 725 EndTest(); |
718 } | 726 } |
719 | 727 |
720 virtual bool CanActivatePendingTree(LayerTreeHostImpl* impl) OVERRIDE { | 728 virtual bool CanActivatePendingTree(LayerTreeHostImpl* impl) OVERRIDE { |
721 if (frame_ >= 1) | 729 return frame_count_with_pending_tree_ > 1; |
722 return true; | |
723 | |
724 return false; | |
725 } | 730 } |
726 | 731 |
727 virtual bool CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* impl) | 732 virtual bool CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* impl) |
728 OVERRIDE { | 733 OVERRIDE { |
729 frame_++; | 734 if (frame_count_with_pending_tree_ > 1) |
730 if (frame_ == 1) { | 735 return true; |
| 736 |
| 737 if (first_frame_time_.is_null()) { |
731 first_frame_time_ = impl->CurrentFrameTimeTicks(); | 738 first_frame_time_ = impl->CurrentFrameTimeTicks(); |
732 | 739 |
733 // Since base::TimeTicks::Now() uses a low-resolution clock on | 740 // Since base::TimeTicks::Now() uses a low-resolution clock on |
734 // Windows, we need to make sure that the clock has incremented past | 741 // Windows, we need to make sure that the clock has incremented past |
735 // first_frame_time_. | 742 // first_frame_time_. |
736 while (first_frame_time_ == base::TimeTicks::Now()) {} | 743 while (first_frame_time_ == base::TimeTicks::Now()) {} |
| 744 } |
| 745 return false; |
| 746 } |
737 | 747 |
738 return false; | 748 virtual void DidActivateTreeOnThread(LayerTreeHostImpl *impl) OVERRIDE { |
739 } | 749 if (impl->settings().impl_side_painting) |
740 | 750 EXPECT_NE(frame_count_with_pending_tree_, 1); |
741 return true; | |
742 } | 751 } |
743 | 752 |
744 virtual void AfterTest() OVERRIDE {} | 753 virtual void AfterTest() OVERRIDE {} |
745 | 754 |
746 private: | 755 private: |
747 int frame_; | 756 int frame_count_with_pending_tree_; |
748 base::TimeTicks first_frame_time_; | 757 base::TimeTicks first_frame_time_; |
749 }; | 758 }; |
750 | 759 |
751 SINGLE_AND_MULTI_THREAD_TEST_F( | 760 SINGLE_AND_MULTI_THREAD_TEST_F( |
752 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); | 761 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); |
753 | 762 |
754 // This test verifies that LayerTreeHostImpl's current frame time gets | 763 // This test verifies that LayerTreeHostImpl's current frame time gets |
755 // updated in consecutive frames when it draws in each frame. | 764 // updated in consecutive frames when it draws in each frame. |
756 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { | 765 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { |
757 public: | 766 public: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 impl->ProcessScrollDeltas(); | 839 impl->ProcessScrollDeltas(); |
831 // We get one commit before the first draw, and the animation doesn't happen | 840 // We get one commit before the first draw, and the animation doesn't happen |
832 // until the second draw. | 841 // until the second draw. |
833 switch (impl->active_tree()->source_frame_number()) { | 842 switch (impl->active_tree()->source_frame_number()) { |
834 case 0: | 843 case 0: |
835 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); | 844 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); |
836 // We'll start an animation when we get back to the main thread. | 845 // We'll start an animation when we get back to the main thread. |
837 break; | 846 break; |
838 case 1: | 847 case 1: |
839 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); | 848 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); |
840 PostSetNeedsRedrawToMainThread(); | |
841 break; | 849 break; |
842 case 2: | 850 case 2: |
843 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor()); | 851 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor()); |
844 EndTest(); | 852 EndTest(); |
845 break; | 853 break; |
846 default: | 854 default: |
847 NOTREACHED(); | 855 NOTREACHED(); |
848 } | 856 } |
849 } | 857 } |
850 | 858 |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 // surface. This prevents any contents drawing into surfaces | 1546 // surface. This prevents any contents drawing into surfaces |
1539 // from being allocated. | 1547 // from being allocated. |
1540 host_impl->SetMemoryPolicy( | 1548 host_impl->SetMemoryPolicy( |
1541 ManagedMemoryPolicy(100 * 100 * 4 * 2), true); | 1549 ManagedMemoryPolicy(100 * 100 * 4 * 2), true); |
1542 break; | 1550 break; |
1543 case 1: | 1551 case 1: |
1544 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( | 1552 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
1545 surface1_render_pass_id)); | 1553 surface1_render_pass_id)); |
1546 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( | 1554 EXPECT_FALSE(renderer->HaveCachedResourcesForRenderPassId( |
1547 surface2_render_pass_id)); | 1555 surface2_render_pass_id)); |
1548 | |
1549 EndTest(); | 1556 EndTest(); |
1550 break; | 1557 break; |
1551 } | 1558 } |
1552 } | 1559 } |
1553 | 1560 |
1554 virtual void DidCommitAndDrawFrame() OVERRIDE { | 1561 virtual void DidCommitAndDrawFrame() OVERRIDE { |
1555 if (layer_tree_host()->commit_number() < 2) | 1562 if (layer_tree_host()->commit_number() < 2) |
1556 root_layer_->SetNeedsDisplay(); | 1563 root_layer_->SetNeedsDisplay(); |
1557 } | 1564 } |
1558 | 1565 |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 private: | 2243 private: |
2237 base::TimeTicks frame_time_; | 2244 base::TimeTicks frame_time_; |
2238 }; | 2245 }; |
2239 | 2246 |
2240 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); | 2247 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); |
2241 | 2248 |
2242 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled | 2249 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled |
2243 : public LayerTreeHostTest { | 2250 : public LayerTreeHostTest { |
2244 public: | 2251 public: |
2245 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2252 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
2246 settings->begin_frame_scheduling_enabled = true; | 2253 settings->begin_frame_scheduling_enabled = false; |
2247 settings->using_synchronous_renderer_compositor = true; | 2254 settings->using_synchronous_renderer_compositor = true; |
2248 } | 2255 } |
2249 | 2256 |
2250 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 2257 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
2251 | 2258 |
2252 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 2259 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
2253 // The BeginFrame notification is turned off now but will get enabled | 2260 // The BeginFrame notification is turned off now but will get enabled |
2254 // once we return. End test while it's enabled. | 2261 // once we return. End test while it's enabled. |
2255 ImplThreadTaskRunner()->PostTask( | 2262 ImplThreadTaskRunner()->PostTask( |
2256 FROM_HERE, | 2263 FROM_HERE, base::Bind( |
2257 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest, | 2264 &LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled::EndTest, |
2258 base::Unretained(this))); | 2265 base::Unretained(this))); |
2259 } | 2266 } |
2260 | 2267 |
2261 virtual void AfterTest() OVERRIDE {} | 2268 virtual void AfterTest() OVERRIDE {} |
2262 }; | 2269 }; |
2263 | 2270 |
2264 MULTI_THREAD_TEST_F( | 2271 MULTI_THREAD_TEST_F( |
2265 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); | 2272 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); |
2266 | 2273 |
2267 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation | 2274 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation |
2268 : public LayerTreeHostTest { | 2275 : public LayerTreeHostTest { |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2969 layer_tree_host()->SetNeedsRedraw(); | 2976 layer_tree_host()->SetNeedsRedraw(); |
2970 break; | 2977 break; |
2971 case 3: | 2978 case 3: |
2972 // CompositeAndReadback in Round 4, first commit. | 2979 // CompositeAndReadback in Round 4, first commit. |
2973 EXPECT_EQ(2, frame_); | 2980 EXPECT_EQ(2, frame_); |
2974 break; | 2981 break; |
2975 case 4: | 2982 case 4: |
2976 // Round 4 done. | 2983 // Round 4 done. |
2977 EXPECT_EQ(2, frame_); | 2984 EXPECT_EQ(2, frame_); |
2978 layer_tree_host()->SetNeedsCommit(); | 2985 layer_tree_host()->SetNeedsCommit(); |
| 2986 // We cant SetNeedsRedraw immediately because it will race the commit. |
| 2987 break; |
| 2988 case 5: |
| 2989 EXPECT_EQ(2, frame_); |
2979 layer_tree_host()->SetNeedsRedraw(); | 2990 layer_tree_host()->SetNeedsRedraw(); |
2980 break; | 2991 break; |
2981 } | 2992 } |
2982 } | 2993 } |
2983 | 2994 |
2984 virtual void DidCompleteSwapBuffers() OVERRIDE { | 2995 virtual void DidCompleteSwapBuffers() OVERRIDE { |
2985 int commit = layer_tree_host()->commit_number(); | 2996 int commit = layer_tree_host()->commit_number(); |
2986 ++frame_; | 2997 ++frame_; |
2987 char pixels[4] = {0}; | 2998 char pixels[4] = {0}; |
2988 switch (frame_) { | 2999 switch (frame_) { |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3812 break; | 3823 break; |
3813 } | 3824 } |
3814 } | 3825 } |
3815 }; | 3826 }; |
3816 | 3827 |
3817 MULTI_THREAD_TEST_F( | 3828 MULTI_THREAD_TEST_F( |
3818 LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent); | 3829 LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent); |
3819 | 3830 |
3820 } // namespace | 3831 } // namespace |
3821 } // namespace cc | 3832 } // namespace cc |
OLD | NEW |