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

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

Issue 2661523003: cc: Merge LayerTree into the LayerTreeHost. (Closed)
Patch Set: auto Created 3 years, 10 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 recovered_context_ = false; 216 recovered_context_ = false;
217 if (NextTestCase()) 217 if (NextTestCase())
218 InvalidateAndSetNeedsCommit(); 218 InvalidateAndSetNeedsCommit();
219 else 219 else
220 EndTest(); 220 EndTest();
221 } 221 }
222 222
223 virtual void InvalidateAndSetNeedsCommit() { 223 virtual void InvalidateAndSetNeedsCommit() {
224 // Cause damage so we try to draw. 224 // Cause damage so we try to draw.
225 layer_tree()->root_layer()->SetNeedsDisplay(); 225 layer_tree_host()->root_layer()->SetNeedsDisplay();
226 layer_tree_host()->SetNeedsCommit(); 226 layer_tree_host()->SetNeedsCommit();
227 } 227 }
228 228
229 bool NextTestCase() { 229 bool NextTestCase() {
230 static const TestCase kTests[] = { 230 static const TestCase kTests[] = {
231 // Losing the context and failing to recreate it (or losing it again 231 // Losing the context and failing to recreate it (or losing it again
232 // immediately) a small number of times should succeed. 232 // immediately) a small number of times should succeed.
233 { 233 {
234 1, // times_to_lose_during_commit 234 1, // times_to_lose_during_commit
235 0, // times_to_lose_during_draw 235 0, // times_to_lose_during_draw
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 SkPaint paint; 612 SkPaint paint;
613 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); 613 paint.setColor(SkColorSetARGB(100, 80, 200, 200));
614 client_.add_draw_rect(gfx::Rect(5, 5), paint); 614 client_.add_draw_rect(gfx::Rect(5, 5), paint);
615 615
616 layer_ = FakePictureLayer::Create(&client_); 616 layer_ = FakePictureLayer::Create(&client_);
617 layer_->SetBounds(gfx::Size(10, 10)); 617 layer_->SetBounds(gfx::Size(10, 10));
618 layer_->SetIsDrawable(true); 618 layer_->SetIsDrawable(true);
619 619
620 root_->AddChild(layer_); 620 root_->AddChild(layer_);
621 621
622 layer_tree()->SetRootLayer(root_); 622 layer_tree_host()->SetRootLayer(root_);
623 LayerTreeHostContextTest::SetupTree(); 623 LayerTreeHostContextTest::SetupTree();
624 client_.set_bounds(root_->bounds()); 624 client_.set_bounds(root_->bounds());
625 } 625 }
626 626
627 void InvalidateAndSetNeedsCommit() override { 627 void InvalidateAndSetNeedsCommit() override {
628 // Invalidate the render surface so we don't try to use a cached copy of the 628 // Invalidate the render surface so we don't try to use a cached copy of the
629 // surface. We want to make sure to test the drawing paths for drawing to 629 // surface. We want to make sure to test the drawing paths for drawing to
630 // a child surface. 630 // a child surface.
631 layer_->SetNeedsDisplay(); 631 layer_->SetNeedsDisplay();
632 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); 632 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 void SetupTree() override { 689 void SetupTree() override {
690 // Paint non-solid color. 690 // Paint non-solid color.
691 SkPaint paint; 691 SkPaint paint;
692 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); 692 paint.setColor(SkColorSetARGB(100, 80, 200, 200));
693 client_.add_draw_rect(gfx::Rect(5, 5), paint); 693 client_.add_draw_rect(gfx::Rect(5, 5), paint);
694 694
695 scoped_refptr<FakePictureLayer> picture_layer = 695 scoped_refptr<FakePictureLayer> picture_layer =
696 FakePictureLayer::Create(&client_); 696 FakePictureLayer::Create(&client_);
697 picture_layer->SetBounds(gfx::Size(10, 20)); 697 picture_layer->SetBounds(gfx::Size(10, 20));
698 client_.set_bounds(picture_layer->bounds()); 698 client_.set_bounds(picture_layer->bounds());
699 layer_tree()->SetRootLayer(picture_layer); 699 layer_tree_host()->SetRootLayer(picture_layer);
700 700
701 LayerTreeHostContextTest::SetupTree(); 701 LayerTreeHostContextTest::SetupTree();
702 } 702 }
703 703
704 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 704 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
705 705
706 void PostEvictTextures() { 706 void PostEvictTextures() {
707 if (HasImplThread()) { 707 if (HasImplThread()) {
708 ImplThreadTaskRunner()->PostTask( 708 ImplThreadTaskRunner()->PostTask(
709 FROM_HERE, 709 FROM_HERE,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 : LayerTreeHostContextTest(), num_commits_(0) {} 797 : LayerTreeHostContextTest(), num_commits_(0) {}
798 798
799 void SetupTree() override { 799 void SetupTree() override {
800 root_ = FakePictureLayer::Create(&client_); 800 root_ = FakePictureLayer::Create(&client_);
801 child_ = FakePictureLayer::Create(&client_); 801 child_ = FakePictureLayer::Create(&client_);
802 grandchild_ = FakePictureLayer::Create(&client_); 802 grandchild_ = FakePictureLayer::Create(&client_);
803 803
804 root_->AddChild(child_); 804 root_->AddChild(child_);
805 child_->AddChild(grandchild_); 805 child_->AddChild(grandchild_);
806 806
807 layer_tree()->SetRootLayer(root_); 807 layer_tree_host()->SetRootLayer(root_);
808 LayerTreeHostContextTest::SetupTree(); 808 LayerTreeHostContextTest::SetupTree();
809 client_.set_bounds(root_->bounds()); 809 client_.set_bounds(root_->bounds());
810 } 810 }
811 811
812 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 812 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
813 813
814 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 814 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
815 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); 815 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl);
816 816
817 FakePictureLayerImpl* root_picture = NULL; 817 FakePictureLayerImpl* root_picture = NULL;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 debug_state.show_property_changed_rects = true; 968 debug_state.show_property_changed_rects = true;
969 layer_tree_host()->SetDebugState(debug_state); 969 layer_tree_host()->SetDebugState(debug_state);
970 970
971 scoped_refptr<PaintedScrollbarLayer> scrollbar = 971 scoped_refptr<PaintedScrollbarLayer> scrollbar =
972 PaintedScrollbarLayer::Create( 972 PaintedScrollbarLayer::Create(
973 std::unique_ptr<Scrollbar>(new FakeScrollbar), layer->id()); 973 std::unique_ptr<Scrollbar>(new FakeScrollbar), layer->id());
974 scrollbar->SetBounds(gfx::Size(10, 10)); 974 scrollbar->SetBounds(gfx::Size(10, 10));
975 scrollbar->SetIsDrawable(true); 975 scrollbar->SetIsDrawable(true);
976 root->AddChild(scrollbar); 976 root->AddChild(scrollbar);
977 977
978 layer_tree()->SetRootLayer(root); 978 layer_tree_host()->SetRootLayer(root);
979 LayerTreeHostContextTest::SetupTree(); 979 LayerTreeHostContextTest::SetupTree();
980 } 980 }
981 981
982 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 982 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
983 983
984 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 984 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
985 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); 985 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl);
986 986
987 if (host_impl->active_tree()->source_frame_number() == 3) { 987 if (host_impl->active_tree()->source_frame_number() == 3) {
988 // On the third commit we're recovering from context loss. Hardware 988 // On the third commit we're recovering from context loss. Hardware
(...skipping 19 matching lines...) Expand all
1008 // This will get called twice: 1008 // This will get called twice:
1009 // First when we create the initial CompositorFrameSink... 1009 // First when we create the initial CompositorFrameSink...
1010 if (layer_tree_host()->SourceFrameNumber() > 0) { 1010 if (layer_tree_host()->SourceFrameNumber() > 0) {
1011 // ... and then again after we forced the context to be lost. 1011 // ... and then again after we forced the context to be lost.
1012 lost_context_ = true; 1012 lost_context_ = true;
1013 } 1013 }
1014 LayerTreeHostContextTest::RequestNewCompositorFrameSink(); 1014 LayerTreeHostContextTest::RequestNewCompositorFrameSink();
1015 } 1015 }
1016 1016
1017 void DidCommitAndDrawFrame() override { 1017 void DidCommitAndDrawFrame() override {
1018 ASSERT_TRUE(layer_tree()->hud_layer()); 1018 ASSERT_TRUE(layer_tree_host()->hud_layer());
1019 // End the test once we know the 3nd frame drew. 1019 // End the test once we know the 3nd frame drew.
1020 if (layer_tree_host()->SourceFrameNumber() < 5) { 1020 if (layer_tree_host()->SourceFrameNumber() < 5) {
1021 layer_tree()->root_layer()->SetNeedsDisplay(); 1021 layer_tree_host()->root_layer()->SetNeedsDisplay();
1022 layer_tree_host()->SetNeedsCommit(); 1022 layer_tree_host()->SetNeedsCommit();
1023 } else { 1023 } else {
1024 EndTest(); 1024 EndTest();
1025 } 1025 }
1026 } 1026 }
1027 1027
1028 void AfterTest() override { EXPECT_TRUE(lost_context_); } 1028 void AfterTest() override { EXPECT_TRUE(lost_context_); }
1029 1029
1030 private: 1030 private:
1031 FakeContentLayerClient client_; 1031 FakeContentLayerClient client_;
(...skipping 21 matching lines...) Expand all
1053 scoped_refptr<Layer> root = Layer::Create(); 1053 scoped_refptr<Layer> root = Layer::Create();
1054 root->SetBounds(gfx::Size(10, 10)); 1054 root->SetBounds(gfx::Size(10, 10));
1055 root->SetIsDrawable(true); 1055 root->SetIsDrawable(true);
1056 1056
1057 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_); 1057 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_);
1058 picture->SetBounds(gfx::Size(10, 10)); 1058 picture->SetBounds(gfx::Size(10, 10));
1059 client_.set_bounds(picture->bounds()); 1059 client_.set_bounds(picture->bounds());
1060 picture->SetIsDrawable(true); 1060 picture->SetIsDrawable(true);
1061 root->AddChild(picture); 1061 root->AddChild(picture);
1062 1062
1063 layer_tree()->SetRootLayer(root); 1063 layer_tree_host()->SetRootLayer(root);
1064 LayerTreeHostContextTest::SetupTree(); 1064 LayerTreeHostContextTest::SetupTree();
1065 } 1065 }
1066 1066
1067 void BeginTest() override { 1067 void BeginTest() override {
1068 times_to_lose_during_commit_ = 1; 1068 times_to_lose_during_commit_ = 1;
1069 PostSetNeedsCommitToMainThread(); 1069 PostSetNeedsCommitToMainThread();
1070 } 1070 }
1071 1071
1072 void AfterTest() override {} 1072 void AfterTest() override {}
1073 1073
1074 void DidInitializeCompositorFrameSink() override { EndTest(); } 1074 void DidInitializeCompositorFrameSink() override { EndTest(); }
1075 1075
1076 private: 1076 private:
1077 FakeContentLayerClient client_; 1077 FakeContentLayerClient client_;
1078 }; 1078 };
1079 1079
1080 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting); 1080 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting);
1081 1081
1082 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { 1082 class ScrollbarLayerLostContext : public LayerTreeHostContextTest {
1083 public: 1083 public:
1084 ScrollbarLayerLostContext() : commits_(0) {} 1084 ScrollbarLayerLostContext() : commits_(0) {}
1085 1085
1086 void BeginTest() override { 1086 void BeginTest() override {
1087 scoped_refptr<Layer> scroll_layer = Layer::Create(); 1087 scoped_refptr<Layer> scroll_layer = Layer::Create();
1088 scrollbar_layer_ = 1088 scrollbar_layer_ =
1089 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id()); 1089 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id());
1090 scrollbar_layer_->SetBounds(gfx::Size(10, 100)); 1090 scrollbar_layer_->SetBounds(gfx::Size(10, 100));
1091 layer_tree()->root_layer()->AddChild(scrollbar_layer_); 1091 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
1092 layer_tree()->root_layer()->AddChild(scroll_layer); 1092 layer_tree_host()->root_layer()->AddChild(scroll_layer);
1093 PostSetNeedsCommitToMainThread(); 1093 PostSetNeedsCommitToMainThread();
1094 } 1094 }
1095 1095
1096 void AfterTest() override {} 1096 void AfterTest() override {}
1097 1097
1098 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1098 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1099 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1099 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1100 1100
1101 ++commits_; 1101 ++commits_;
1102 switch (commits_) { 1102 switch (commits_) {
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 protected: 1603 protected:
1604 void SetupTree() override { 1604 void SetupTree() override {
1605 SkPaint paint; 1605 SkPaint paint;
1606 client_.set_fill_with_nonsolid_color(true); 1606 client_.set_fill_with_nonsolid_color(true);
1607 client_.add_draw_rect(gfx::Rect(5, 5), paint); 1607 client_.add_draw_rect(gfx::Rect(5, 5), paint);
1608 1608
1609 scoped_refptr<FakePictureLayer> picture_layer = 1609 scoped_refptr<FakePictureLayer> picture_layer =
1610 FakePictureLayer::Create(&client_); 1610 FakePictureLayer::Create(&client_);
1611 picture_layer->SetBounds(gfx::Size(10, 20)); 1611 picture_layer->SetBounds(gfx::Size(10, 20));
1612 client_.set_bounds(picture_layer->bounds()); 1612 client_.set_bounds(picture_layer->bounds());
1613 layer_tree()->SetRootLayer(picture_layer); 1613 layer_tree_host()->SetRootLayer(picture_layer);
1614 1614
1615 LayerTreeTest::SetupTree(); 1615 LayerTreeTest::SetupTree();
1616 } 1616 }
1617 1617
1618 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1618 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1619 1619
1620 void WillPrepareTilesOnThread(LayerTreeHostImpl* host_impl) override { 1620 void WillPrepareTilesOnThread(LayerTreeHostImpl* host_impl) override {
1621 ContextProvider::ScopedContextLock scoped_context( 1621 ContextProvider::ScopedContextLock scoped_context(
1622 host_impl->compositor_frame_sink()->worker_context_provider()); 1622 host_impl->compositor_frame_sink()->worker_context_provider());
1623 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 1623 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
(...skipping 11 matching lines...) Expand all
1635 1635
1636 FakeContentLayerClient client_; 1636 FakeContentLayerClient client_;
1637 int num_draws_ = 0; 1637 int num_draws_ = 0;
1638 }; 1638 };
1639 1639
1640 MULTI_THREAD_TEST_F( 1640 MULTI_THREAD_TEST_F(
1641 LayerTreeHostContextTestLoseWorkerContextDuringPrepareTiles); 1641 LayerTreeHostContextTestLoseWorkerContextDuringPrepareTiles);
1642 1642
1643 } // namespace 1643 } // namespace
1644 } // namespace cc 1644 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_animation.cc ('k') | cc/trees/layer_tree_host_unittest_copyrequest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698