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

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

Issue 2183403002: cc: Move data to LayerTree from LayerTreeHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@layer_tree_change
Patch Set: Missed one test. Created 4 years, 4 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "cc/layers/heads_up_display_layer.h" 9 #include "cc/layers/heads_up_display_layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 223
224 recovered_context_ = false; 224 recovered_context_ = false;
225 if (NextTestCase()) 225 if (NextTestCase())
226 InvalidateAndSetNeedsCommit(); 226 InvalidateAndSetNeedsCommit();
227 else 227 else
228 EndTest(); 228 EndTest();
229 } 229 }
230 230
231 virtual void InvalidateAndSetNeedsCommit() { 231 virtual void InvalidateAndSetNeedsCommit() {
232 // Cause damage so we try to draw. 232 // Cause damage so we try to draw.
233 layer_tree_host()->root_layer()->SetNeedsDisplay(); 233 layer_tree()->root_layer()->SetNeedsDisplay();
234 layer_tree_host()->SetNeedsCommit(); 234 layer_tree_host()->SetNeedsCommit();
235 } 235 }
236 236
237 bool NextTestCase() { 237 bool NextTestCase() {
238 static const TestCase kTests[] = { 238 static const TestCase kTests[] = {
239 // Losing the context and failing to recreate it (or losing it again 239 // Losing the context and failing to recreate it (or losing it again
240 // immediately) a small number of times should succeed. 240 // immediately) a small number of times should succeed.
241 { 241 {
242 1, // times_to_lose_during_commit 242 1, // times_to_lose_during_commit
243 0, // times_to_lose_during_draw 243 0, // times_to_lose_during_draw
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 SkPaint paint; 627 SkPaint paint;
628 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); 628 paint.setColor(SkColorSetARGB(100, 80, 200, 200));
629 client_.add_draw_rect(gfx::Rect(5, 5), paint); 629 client_.add_draw_rect(gfx::Rect(5, 5), paint);
630 630
631 layer_ = FakePictureLayer::Create(&client_); 631 layer_ = FakePictureLayer::Create(&client_);
632 layer_->SetBounds(gfx::Size(10, 10)); 632 layer_->SetBounds(gfx::Size(10, 10));
633 layer_->SetIsDrawable(true); 633 layer_->SetIsDrawable(true);
634 634
635 root_->AddChild(layer_); 635 root_->AddChild(layer_);
636 636
637 layer_tree_host()->SetRootLayer(root_); 637 layer_tree()->SetRootLayer(root_);
638 LayerTreeHostContextTest::SetupTree(); 638 LayerTreeHostContextTest::SetupTree();
639 client_.set_bounds(root_->bounds()); 639 client_.set_bounds(root_->bounds());
640 } 640 }
641 641
642 void InvalidateAndSetNeedsCommit() override { 642 void InvalidateAndSetNeedsCommit() override {
643 // Invalidate the render surface so we don't try to use a cached copy of the 643 // Invalidate the render surface so we don't try to use a cached copy of the
644 // surface. We want to make sure to test the drawing paths for drawing to 644 // surface. We want to make sure to test the drawing paths for drawing to
645 // a child surface. 645 // a child surface.
646 layer_->SetNeedsDisplay(); 646 layer_->SetNeedsDisplay();
647 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); 647 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 void SetupTree() override { 704 void SetupTree() override {
705 // Paint non-solid color. 705 // Paint non-solid color.
706 SkPaint paint; 706 SkPaint paint;
707 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); 707 paint.setColor(SkColorSetARGB(100, 80, 200, 200));
708 client_.add_draw_rect(gfx::Rect(5, 5), paint); 708 client_.add_draw_rect(gfx::Rect(5, 5), paint);
709 709
710 scoped_refptr<FakePictureLayer> picture_layer = 710 scoped_refptr<FakePictureLayer> picture_layer =
711 FakePictureLayer::Create(&client_); 711 FakePictureLayer::Create(&client_);
712 picture_layer->SetBounds(gfx::Size(10, 20)); 712 picture_layer->SetBounds(gfx::Size(10, 20));
713 client_.set_bounds(picture_layer->bounds()); 713 client_.set_bounds(picture_layer->bounds());
714 layer_tree_host()->SetRootLayer(picture_layer); 714 layer_tree()->SetRootLayer(picture_layer);
715 715
716 LayerTreeHostContextTest::SetupTree(); 716 LayerTreeHostContextTest::SetupTree();
717 } 717 }
718 718
719 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 719 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
720 720
721 void PostEvictTextures() { 721 void PostEvictTextures() {
722 if (HasImplThread()) { 722 if (HasImplThread()) {
723 ImplThreadTaskRunner()->PostTask( 723 ImplThreadTaskRunner()->PostTask(
724 FROM_HERE, 724 FROM_HERE,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 : LayerTreeHostContextTest(), num_commits_(0) {} 812 : LayerTreeHostContextTest(), num_commits_(0) {}
813 813
814 void SetupTree() override { 814 void SetupTree() override {
815 root_ = FakePictureLayer::Create(&client_); 815 root_ = FakePictureLayer::Create(&client_);
816 child_ = FakePictureLayer::Create(&client_); 816 child_ = FakePictureLayer::Create(&client_);
817 grandchild_ = FakePictureLayer::Create(&client_); 817 grandchild_ = FakePictureLayer::Create(&client_);
818 818
819 root_->AddChild(child_); 819 root_->AddChild(child_);
820 child_->AddChild(grandchild_); 820 child_->AddChild(grandchild_);
821 821
822 layer_tree_host()->SetRootLayer(root_); 822 layer_tree()->SetRootLayer(root_);
823 LayerTreeHostContextTest::SetupTree(); 823 LayerTreeHostContextTest::SetupTree();
824 client_.set_bounds(root_->bounds()); 824 client_.set_bounds(root_->bounds());
825 } 825 }
826 826
827 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 827 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
828 828
829 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 829 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
830 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); 830 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl);
831 831
832 FakePictureLayerImpl* root_picture = NULL; 832 FakePictureLayerImpl* root_picture = NULL;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 debug_state.show_property_changed_rects = true; 1005 debug_state.show_property_changed_rects = true;
1006 layer_tree_host()->SetDebugState(debug_state); 1006 layer_tree_host()->SetDebugState(debug_state);
1007 1007
1008 scoped_refptr<PaintedScrollbarLayer> scrollbar = 1008 scoped_refptr<PaintedScrollbarLayer> scrollbar =
1009 PaintedScrollbarLayer::Create( 1009 PaintedScrollbarLayer::Create(
1010 std::unique_ptr<Scrollbar>(new FakeScrollbar), layer->id()); 1010 std::unique_ptr<Scrollbar>(new FakeScrollbar), layer->id());
1011 scrollbar->SetBounds(gfx::Size(10, 10)); 1011 scrollbar->SetBounds(gfx::Size(10, 10));
1012 scrollbar->SetIsDrawable(true); 1012 scrollbar->SetIsDrawable(true);
1013 root->AddChild(scrollbar); 1013 root->AddChild(scrollbar);
1014 1014
1015 layer_tree_host()->SetRootLayer(root); 1015 layer_tree()->SetRootLayer(root);
1016 LayerTreeHostContextTest::SetupTree(); 1016 LayerTreeHostContextTest::SetupTree();
1017 } 1017 }
1018 1018
1019 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1019 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1020 1020
1021 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 1021 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
1022 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); 1022 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl);
1023 1023
1024 if (host_impl->active_tree()->source_frame_number() == 3) { 1024 if (host_impl->active_tree()->source_frame_number() == 3) {
1025 // On the third commit we're recovering from context loss. Hardware 1025 // On the third commit we're recovering from context loss. Hardware
(...skipping 19 matching lines...) Expand all
1045 // This will get called twice: 1045 // This will get called twice:
1046 // First when we create the initial output surface... 1046 // First when we create the initial output surface...
1047 if (layer_tree_host()->source_frame_number() > 0) { 1047 if (layer_tree_host()->source_frame_number() > 0) {
1048 // ... and then again after we forced the context to be lost. 1048 // ... and then again after we forced the context to be lost.
1049 lost_context_ = true; 1049 lost_context_ = true;
1050 } 1050 }
1051 LayerTreeHostContextTest::RequestNewOutputSurface(); 1051 LayerTreeHostContextTest::RequestNewOutputSurface();
1052 } 1052 }
1053 1053
1054 void DidCommitAndDrawFrame() override { 1054 void DidCommitAndDrawFrame() override {
1055 ASSERT_TRUE(layer_tree_host()->hud_layer()); 1055 ASSERT_TRUE(layer_tree()->hud_layer());
1056 // End the test once we know the 3nd frame drew. 1056 // End the test once we know the 3nd frame drew.
1057 if (layer_tree_host()->source_frame_number() < 5) { 1057 if (layer_tree_host()->source_frame_number() < 5) {
1058 layer_tree_host()->root_layer()->SetNeedsDisplay(); 1058 layer_tree()->root_layer()->SetNeedsDisplay();
1059 layer_tree_host()->SetNeedsCommit(); 1059 layer_tree_host()->SetNeedsCommit();
1060 } else { 1060 } else {
1061 EndTest(); 1061 EndTest();
1062 } 1062 }
1063 } 1063 }
1064 1064
1065 void AfterTest() override { EXPECT_TRUE(lost_context_); } 1065 void AfterTest() override { EXPECT_TRUE(lost_context_); }
1066 1066
1067 private: 1067 private:
1068 FakeContentLayerClient client_; 1068 FakeContentLayerClient client_;
(...skipping 22 matching lines...) Expand all
1091 scoped_refptr<Layer> root = Layer::Create(); 1091 scoped_refptr<Layer> root = Layer::Create();
1092 root->SetBounds(gfx::Size(10, 10)); 1092 root->SetBounds(gfx::Size(10, 10));
1093 root->SetIsDrawable(true); 1093 root->SetIsDrawable(true);
1094 1094
1095 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_); 1095 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_);
1096 picture->SetBounds(gfx::Size(10, 10)); 1096 picture->SetBounds(gfx::Size(10, 10));
1097 client_.set_bounds(picture->bounds()); 1097 client_.set_bounds(picture->bounds());
1098 picture->SetIsDrawable(true); 1098 picture->SetIsDrawable(true);
1099 root->AddChild(picture); 1099 root->AddChild(picture);
1100 1100
1101 layer_tree_host()->SetRootLayer(root); 1101 layer_tree()->SetRootLayer(root);
1102 LayerTreeHostContextTest::SetupTree(); 1102 LayerTreeHostContextTest::SetupTree();
1103 } 1103 }
1104 1104
1105 void BeginTest() override { 1105 void BeginTest() override {
1106 times_to_lose_during_commit_ = 1; 1106 times_to_lose_during_commit_ = 1;
1107 PostSetNeedsCommitToMainThread(); 1107 PostSetNeedsCommitToMainThread();
1108 } 1108 }
1109 1109
1110 void AfterTest() override {} 1110 void AfterTest() override {}
1111 1111
1112 void DidInitializeOutputSurface() override { EndTest(); } 1112 void DidInitializeOutputSurface() override { EndTest(); }
1113 1113
1114 private: 1114 private:
1115 FakeContentLayerClient client_; 1115 FakeContentLayerClient client_;
1116 }; 1116 };
1117 1117
1118 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting); 1118 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting);
1119 1119
1120 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { 1120 class ScrollbarLayerLostContext : public LayerTreeHostContextTest {
1121 public: 1121 public:
1122 ScrollbarLayerLostContext() : commits_(0) {} 1122 ScrollbarLayerLostContext() : commits_(0) {}
1123 1123
1124 void BeginTest() override { 1124 void BeginTest() override {
1125 scoped_refptr<Layer> scroll_layer = Layer::Create(); 1125 scoped_refptr<Layer> scroll_layer = Layer::Create();
1126 scrollbar_layer_ = 1126 scrollbar_layer_ =
1127 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id()); 1127 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id());
1128 scrollbar_layer_->SetBounds(gfx::Size(10, 100)); 1128 scrollbar_layer_->SetBounds(gfx::Size(10, 100));
1129 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 1129 layer_tree()->root_layer()->AddChild(scrollbar_layer_);
1130 layer_tree_host()->root_layer()->AddChild(scroll_layer); 1130 layer_tree()->root_layer()->AddChild(scroll_layer);
1131 PostSetNeedsCommitToMainThread(); 1131 PostSetNeedsCommitToMainThread();
1132 } 1132 }
1133 1133
1134 void AfterTest() override {} 1134 void AfterTest() override {}
1135 1135
1136 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1136 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1137 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1137 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1138 1138
1139 ++commits_; 1139 ++commits_;
1140 switch (commits_) { 1140 switch (commits_) {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 void AfterTest() override {} 1578 void AfterTest() override {}
1579 1579
1580 bool deferred_; 1580 bool deferred_;
1581 }; 1581 };
1582 1582
1583 SINGLE_AND_MULTI_THREAD_TEST_F( 1583 SINGLE_AND_MULTI_THREAD_TEST_F(
1584 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); 1584 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame);
1585 1585
1586 } // namespace 1586 } // namespace
1587 } // namespace cc 1587 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698