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

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 139053002: cc: Release main thread earlier (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests broken by raciness Created 6 years, 11 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
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/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 scoped_refptr<ContentLayer> root_layer_; 808 scoped_refptr<ContentLayer> root_layer_;
809 scoped_refptr<FakeContentLayer> parent_layer_; 809 scoped_refptr<FakeContentLayer> parent_layer_;
810 scoped_refptr<FakeContentLayer> child_layer_; 810 scoped_refptr<FakeContentLayer> child_layer_;
811 }; 811 };
812 812
813 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); 813 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater);
814 814
815 // If the layerTreeHost says it can't draw, Then we should not try to draw. 815 // If the layerTreeHost says it can't draw, Then we should not try to draw.
816 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest { 816 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest {
817 public: 817 public:
818 LayerTreeHostTestCanDrawBlocksDrawing() : num_commits_(0), done_(false) {} 818 LayerTreeHostTestCanDrawBlocksDrawing() : done_(false) {}
819 819
820 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 820 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
821 821
822 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 822 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
823 if (done_) 823 if (done_)
824 return; 824 return;
825 // Only the initial draw should bring us here. 825 // Only the initial draw should bring us here.
826 EXPECT_TRUE(impl->CanDraw()); 826 EXPECT_TRUE(impl->CanDraw());
827 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); 827 EXPECT_EQ(0, impl->active_tree()->source_frame_number());
828 } 828 }
829 829
830 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 830 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
831 if (done_) 831 if (done_)
832 return; 832 return;
833 if (num_commits_ >= 1) { 833 if (LastCommittedSourceFrameNumber(impl) >= 1) {
834 // After the first commit, we should not be able to draw. 834 // After the first commit, we should not be able to draw.
835 EXPECT_FALSE(impl->CanDraw()); 835 EXPECT_FALSE(impl->CanDraw());
836 } 836 }
837 } 837 }
838 838
839 virtual void DidCommit() OVERRIDE { 839 virtual void DidCommit() OVERRIDE {
840 num_commits_++; 840 switch (layer_tree_host()->source_frame_number()) {
841 if (num_commits_ == 1) { 841 case 1:
842 // Make the viewport empty so the host says it can't draw. 842 // Make the viewport empty so the host says it can't draw.
843 layer_tree_host()->SetViewportSize(gfx::Size(0, 0)); 843 layer_tree_host()->SetViewportSize(gfx::Size(0, 0));
844 } else if (num_commits_ == 2) { 844 break;
845 char pixels[4]; 845 case 2: {
846 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); 846 char pixels[4];
847 } else if (num_commits_ == 3) { 847 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
848 // Let it draw so we go idle and end the test. 848 break;
849 layer_tree_host()->SetViewportSize(gfx::Size(1, 1)); 849 }
850 done_ = true; 850 case 3:
851 EndTest(); 851 // Let it draw so we go idle and end the test.
852 layer_tree_host()->SetViewportSize(gfx::Size(1, 1));
853 done_ = true;
854 EndTest();
855 break;
852 } 856 }
853 } 857 }
854 858
855 virtual void AfterTest() OVERRIDE {} 859 virtual void AfterTest() OVERRIDE {}
856 860
857 private: 861 private:
858 int num_commits_;
859 bool done_; 862 bool done_;
860 }; 863 };
861 864
862 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCanDrawBlocksDrawing); 865 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCanDrawBlocksDrawing);
863 866
864 // beginLayerWrite should prevent draws from executing until a commit occurs 867 // beginLayerWrite should prevent draws from executing until a commit occurs
865 class LayerTreeHostTestWriteLayersRedraw : public LayerTreeHostTest { 868 class LayerTreeHostTestWriteLayersRedraw : public LayerTreeHostTest {
866 public: 869 public:
867 LayerTreeHostTestWriteLayersRedraw() : num_commits_(0), num_draws_(0) {} 870 LayerTreeHostTestWriteLayersRedraw() : num_commits_(0), num_draws_(0) {}
868 871
(...skipping 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3072 bool did_initialize_gl_; 3075 bool did_initialize_gl_;
3073 bool did_release_gl_; 3076 bool did_release_gl_;
3074 int last_source_frame_number_drawn_; 3077 int last_source_frame_number_drawn_;
3075 }; 3078 };
3076 3079
3077 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); 3080 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize);
3078 3081
3079 // Test for UI Resource management. 3082 // Test for UI Resource management.
3080 class LayerTreeHostTestUIResource : public LayerTreeHostTest { 3083 class LayerTreeHostTestUIResource : public LayerTreeHostTest {
3081 public: 3084 public:
3082 LayerTreeHostTestUIResource() : num_ui_resources_(0), num_commits_(0) {} 3085 LayerTreeHostTestUIResource() : num_ui_resources_(0) {}
3083 3086
3084 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 3087 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
3085 settings->texture_id_allocation_chunk_size = 1; 3088 settings->texture_id_allocation_chunk_size = 1;
3086 } 3089 }
3087 3090
3088 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 3091 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
3089 3092
3090 virtual void DidCommit() OVERRIDE { 3093 virtual void DidCommit() OVERRIDE {
3091 int frame = num_commits_; 3094 int frame = layer_tree_host()->source_frame_number();
3092 switch (frame) { 3095 switch (frame) {
3093 case 1: 3096 case 1:
3094 CreateResource(); 3097 CreateResource();
3095 CreateResource(); 3098 CreateResource();
3096 PostSetNeedsCommitToMainThread(); 3099 PostSetNeedsCommitToMainThread();
3097 break; 3100 break;
3098 case 2: 3101 case 2:
3099 // Usually ScopedUIResource are deleted from the manager in their 3102 // Usually ScopedUIResource are deleted from the manager in their
3100 // destructor. Here we just want to test that a direct call to 3103 // destructor. Here we just want to test that a direct call to
3101 // DeleteUIResource works. 3104 // DeleteUIResource works.
(...skipping 13 matching lines...) Expand all
3115 case 5: 3118 case 5:
3116 ClearResources(); 3119 ClearResources();
3117 EndTest(); 3120 EndTest();
3118 break; 3121 break;
3119 } 3122 }
3120 } 3123 }
3121 3124
3122 void PerformTest(LayerTreeHostImpl* impl) { 3125 void PerformTest(LayerTreeHostImpl* impl) {
3123 TestWebGraphicsContext3D* context = TestContext(); 3126 TestWebGraphicsContext3D* context = TestContext();
3124 3127
3125 int frame = num_commits_; 3128 int frame = impl->active_tree()->source_frame_number();
3126 switch (frame) { 3129 switch (frame) {
3127 case 1: 3130 case 0:
3128 ASSERT_EQ(0u, context->NumTextures()); 3131 ASSERT_EQ(0u, context->NumTextures());
3129 break; 3132 break;
3130 case 2: 3133 case 1:
3131 // Created two textures. 3134 // Created two textures.
3132 ASSERT_EQ(2u, context->NumTextures()); 3135 ASSERT_EQ(2u, context->NumTextures());
3133 break; 3136 break;
3134 case 3: 3137 case 2:
3135 // One texture left after one deletion. 3138 // One texture left after one deletion.
3136 ASSERT_EQ(1u, context->NumTextures()); 3139 ASSERT_EQ(1u, context->NumTextures());
3137 break; 3140 break;
3138 case 4: 3141 case 3:
3139 // Resource manager state should not change when delete is called on an 3142 // Resource manager state should not change when delete is called on an
3140 // invalid id. 3143 // invalid id.
3141 ASSERT_EQ(1u, context->NumTextures()); 3144 ASSERT_EQ(1u, context->NumTextures());
3142 break; 3145 break;
3143 case 5: 3146 case 4:
3144 // Creation after deletion: two more creates should total up to 3147 // Creation after deletion: two more creates should total up to
3145 // three textures. 3148 // three textures.
3146 ASSERT_EQ(3u, context->NumTextures()); 3149 ASSERT_EQ(3u, context->NumTextures());
3147 break; 3150 break;
3148 } 3151 }
3149 } 3152 }
3150 3153
3151 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 3154 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
3152 ++num_commits_;
3153 if (!layer_tree_host()->settings().impl_side_painting) 3155 if (!layer_tree_host()->settings().impl_side_painting)
3154 PerformTest(impl); 3156 PerformTest(impl);
3155 } 3157 }
3156 3158
3157 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 3159 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
3158 if (layer_tree_host()->settings().impl_side_painting) 3160 if (layer_tree_host()->settings().impl_side_painting)
3159 PerformTest(impl); 3161 PerformTest(impl);
3160 } 3162 }
3161 3163
3162 virtual void AfterTest() OVERRIDE {} 3164 virtual void AfterTest() OVERRIDE {}
3163 3165
3164 private: 3166 private:
3165 // Must clear all resources before exiting. 3167 // Must clear all resources before exiting.
3166 void ClearResources() { 3168 void ClearResources() {
3167 for (int i = 0; i < num_ui_resources_; i++) 3169 for (int i = 0; i < num_ui_resources_; i++)
3168 ui_resources_[i].reset(); 3170 ui_resources_[i].reset();
3169 } 3171 }
3170 3172
3171 void CreateResource() { 3173 void CreateResource() {
3172 ui_resources_[num_ui_resources_++] = 3174 ui_resources_[num_ui_resources_++] =
3173 FakeScopedUIResource::Create(layer_tree_host()); 3175 FakeScopedUIResource::Create(layer_tree_host());
3174 } 3176 }
3175 3177
3176 scoped_ptr<FakeScopedUIResource> ui_resources_[5]; 3178 scoped_ptr<FakeScopedUIResource> ui_resources_[5];
3177 int num_ui_resources_; 3179 int num_ui_resources_;
3178 int num_commits_;
3179 }; 3180 };
3180 3181
3181 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource); 3182 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource);
3182 3183
3183 class PushPropertiesCountingLayerImpl : public LayerImpl { 3184 class PushPropertiesCountingLayerImpl : public LayerImpl {
3184 public: 3185 public:
3185 static scoped_ptr<PushPropertiesCountingLayerImpl> Create( 3186 static scoped_ptr<PushPropertiesCountingLayerImpl> Create(
3186 LayerTreeImpl* tree_impl, int id) { 3187 LayerTreeImpl* tree_impl, int id) {
3187 return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl, id)); 3188 return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl, id));
3188 } 3189 }
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes); 4484 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes);
4484 4485
4485 // Test ensuring that memory limits are sent to the prioritized resource 4486 // Test ensuring that memory limits are sent to the prioritized resource
4486 // manager. 4487 // manager.
4487 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest { 4488 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest {
4488 public: 4489 public:
4489 LayerTreeHostTestMemoryLimits() : num_commits_(0) {} 4490 LayerTreeHostTestMemoryLimits() : num_commits_(0) {}
4490 4491
4491 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4492 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4492 4493
4494 virtual void WillCommit() OVERRIDE {
4495 // Some commits are aborted, so increment number of attempted commits here.
4496 num_commits_++;
brianderson 2014/01/23 22:48:49 To handle the aborted commits, could we keep two c
enne (OOO) 2014/01/23 23:01:36 WillCommit is called when the main thread is block
4497 }
4498
4493 virtual void DidCommit() OVERRIDE { 4499 virtual void DidCommit() OVERRIDE {
4494 int frame = num_commits_; 4500 switch (num_commits_) {
4495 switch (frame) { 4501 case 1:
4496 case 0:
4497 // Verify default values. 4502 // Verify default values.
4498 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4503 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4499 layer_tree_host() 4504 layer_tree_host()
4500 ->contents_texture_manager() 4505 ->contents_texture_manager()
4501 ->MaxMemoryLimitBytes()); 4506 ->MaxMemoryLimitBytes());
4502 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(), 4507 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4503 layer_tree_host() 4508 layer_tree_host()
4504 ->contents_texture_manager() 4509 ->contents_texture_manager()
4505 ->ExternalPriorityCutoff()); 4510 ->ExternalPriorityCutoff());
4506 PostSetNeedsCommitToMainThread(); 4511 PostSetNeedsCommitToMainThread();
4507 break; 4512 break;
4508 case 1: 4513 case 2:
4509 // The values should remain the same until the commit after the policy 4514 // The values should remain the same until the commit after the policy
4510 // is changed. 4515 // is changed.
4511 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4516 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4512 layer_tree_host() 4517 layer_tree_host()
4513 ->contents_texture_manager() 4518 ->contents_texture_manager()
4514 ->MaxMemoryLimitBytes()); 4519 ->MaxMemoryLimitBytes());
4515 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(), 4520 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4516 layer_tree_host() 4521 layer_tree_host()
4517 ->contents_texture_manager() 4522 ->contents_texture_manager()
4518 ->ExternalPriorityCutoff()); 4523 ->ExternalPriorityCutoff());
4519 break; 4524 break;
4520 case 2: 4525 case 3:
4521 // Verify values were correctly passed. 4526 // Verify values were correctly passed.
4522 EXPECT_EQ(16u * 1024u * 1024u, 4527 EXPECT_EQ(16u * 1024u * 1024u,
4523 layer_tree_host() 4528 layer_tree_host()
4524 ->contents_texture_manager() 4529 ->contents_texture_manager()
4525 ->MaxMemoryLimitBytes()); 4530 ->MaxMemoryLimitBytes());
4526 EXPECT_EQ(PriorityCalculator::AllowVisibleAndNearbyCutoff(), 4531 EXPECT_EQ(PriorityCalculator::AllowVisibleAndNearbyCutoff(),
4527 layer_tree_host() 4532 layer_tree_host()
4528 ->contents_texture_manager() 4533 ->contents_texture_manager()
4529 ->ExternalPriorityCutoff()); 4534 ->ExternalPriorityCutoff());
4530 EndTest(); 4535 EndTest();
4531 break; 4536 break;
4532 case 3: 4537 case 4:
4533 // Make sure no extra commits happen. 4538 // Make sure no extra commits happen.
4534 NOTREACHED(); 4539 NOTREACHED();
4535 break; 4540 break;
4536 } 4541 }
4537
4538 ++num_commits_;
4539 } 4542 }
4540 4543
4541 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4544 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4542 int frame = num_commits_; 4545 switch (num_commits_) {
4543 switch (frame) { 4546 case 1:
4544 case 0:
4545 break; 4547 break;
4546 case 1: 4548 case 2:
4547 // This will trigger a commit because the priority cutoff has changed. 4549 // This will trigger a commit because the priority cutoff has changed.
4548 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4550 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4549 16u * 1024u * 1024u, 4551 16u * 1024u * 1024u,
4550 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4552 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4551 1000)); 4553 1000));
4552 break; 4554 break;
4553 case 2: 4555 case 3:
4554 // This will not trigger a commit because the priority cutoff has not 4556 // This will not trigger a commit because the priority cutoff has not
4555 // changed, and there is already enough memory for all allocations. 4557 // changed, and there is already enough memory for all allocations.
4556 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4558 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4557 32u * 1024u * 1024u, 4559 32u * 1024u * 1024u,
4558 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4560 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4559 1000)); 4561 1000));
4560 break; 4562 break;
4561 case 3: 4563 case 4:
4562 NOTREACHED(); 4564 NOTREACHED();
4563 break; 4565 break;
4564 } 4566 }
4565 } 4567 }
4566 4568
4567 virtual void AfterTest() OVERRIDE {} 4569 virtual void AfterTest() OVERRIDE {}
4568 4570
4569 private: 4571 private:
4570 int num_commits_; 4572 int num_commits_;
4571 }; 4573 };
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
4947 4949
4948 EndTest(); 4950 EndTest();
4949 } 4951 }
4950 4952
4951 virtual void AfterTest() OVERRIDE {} 4953 virtual void AfterTest() OVERRIDE {}
4952 }; 4954 };
4953 4955
4954 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); 4956 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor);
4955 4957
4956 } // namespace cc 4958 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698