OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 debug_state.show_property_changed_rects = true; | 1006 debug_state.show_property_changed_rects = true; |
1007 layer_tree_host()->SetDebugState(debug_state); | 1007 layer_tree_host()->SetDebugState(debug_state); |
1008 | 1008 |
1009 scoped_refptr<PaintedScrollbarLayer> scrollbar = | 1009 scoped_refptr<PaintedScrollbarLayer> scrollbar = |
1010 PaintedScrollbarLayer::Create( | 1010 PaintedScrollbarLayer::Create( |
1011 std::unique_ptr<Scrollbar>(new FakeScrollbar), layer->id()); | 1011 std::unique_ptr<Scrollbar>(new FakeScrollbar), layer->id()); |
1012 scrollbar->SetBounds(gfx::Size(10, 10)); | 1012 scrollbar->SetBounds(gfx::Size(10, 10)); |
1013 scrollbar->SetIsDrawable(true); | 1013 scrollbar->SetIsDrawable(true); |
1014 root->AddChild(scrollbar); | 1014 root->AddChild(scrollbar); |
1015 | 1015 |
1016 layer_tree_host()->SetRootLayer(root); | 1016 layer_tree()->SetRootLayer(root); |
1017 LayerTreeHostContextTest::SetupTree(); | 1017 LayerTreeHostContextTest::SetupTree(); |
1018 } | 1018 } |
1019 | 1019 |
1020 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1020 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1021 | 1021 |
1022 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1022 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1023 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); | 1023 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); |
1024 | 1024 |
1025 if (host_impl->active_tree()->source_frame_number() == 3) { | 1025 if (host_impl->active_tree()->source_frame_number() == 3) { |
1026 // On the third commit we're recovering from context loss. Hardware | 1026 // On the third commit we're recovering from context loss. Hardware |
(...skipping 19 matching lines...) Expand all Loading... |
1046 // This will get called twice: | 1046 // This will get called twice: |
1047 // First when we create the initial output surface... | 1047 // First when we create the initial output surface... |
1048 if (layer_tree_host()->source_frame_number() > 0) { | 1048 if (layer_tree_host()->source_frame_number() > 0) { |
1049 // ... and then again after we forced the context to be lost. | 1049 // ... and then again after we forced the context to be lost. |
1050 lost_context_ = true; | 1050 lost_context_ = true; |
1051 } | 1051 } |
1052 LayerTreeHostContextTest::RequestNewOutputSurface(); | 1052 LayerTreeHostContextTest::RequestNewOutputSurface(); |
1053 } | 1053 } |
1054 | 1054 |
1055 void DidCommitAndDrawFrame() override { | 1055 void DidCommitAndDrawFrame() override { |
1056 ASSERT_TRUE(layer_tree_host()->hud_layer()); | 1056 ASSERT_TRUE(layer_tree()->hud_layer()); |
1057 // End the test once we know the 3nd frame drew. | 1057 // End the test once we know the 3nd frame drew. |
1058 if (layer_tree_host()->source_frame_number() < 5) { | 1058 if (layer_tree_host()->source_frame_number() < 5) { |
1059 layer_tree_host()->root_layer()->SetNeedsDisplay(); | 1059 layer_tree()->root_layer()->SetNeedsDisplay(); |
1060 layer_tree_host()->SetNeedsCommit(); | 1060 layer_tree_host()->SetNeedsCommit(); |
1061 } else { | 1061 } else { |
1062 EndTest(); | 1062 EndTest(); |
1063 } | 1063 } |
1064 } | 1064 } |
1065 | 1065 |
1066 void AfterTest() override { EXPECT_TRUE(lost_context_); } | 1066 void AfterTest() override { EXPECT_TRUE(lost_context_); } |
1067 | 1067 |
1068 private: | 1068 private: |
1069 FakeContentLayerClient client_; | 1069 FakeContentLayerClient client_; |
(...skipping 22 matching lines...) Expand all Loading... |
1092 scoped_refptr<Layer> root = Layer::Create(); | 1092 scoped_refptr<Layer> root = Layer::Create(); |
1093 root->SetBounds(gfx::Size(10, 10)); | 1093 root->SetBounds(gfx::Size(10, 10)); |
1094 root->SetIsDrawable(true); | 1094 root->SetIsDrawable(true); |
1095 | 1095 |
1096 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_); | 1096 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&client_); |
1097 picture->SetBounds(gfx::Size(10, 10)); | 1097 picture->SetBounds(gfx::Size(10, 10)); |
1098 client_.set_bounds(picture->bounds()); | 1098 client_.set_bounds(picture->bounds()); |
1099 picture->SetIsDrawable(true); | 1099 picture->SetIsDrawable(true); |
1100 root->AddChild(picture); | 1100 root->AddChild(picture); |
1101 | 1101 |
1102 layer_tree_host()->SetRootLayer(root); | 1102 layer_tree()->SetRootLayer(root); |
1103 LayerTreeHostContextTest::SetupTree(); | 1103 LayerTreeHostContextTest::SetupTree(); |
1104 } | 1104 } |
1105 | 1105 |
1106 void BeginTest() override { | 1106 void BeginTest() override { |
1107 times_to_lose_during_commit_ = 1; | 1107 times_to_lose_during_commit_ = 1; |
1108 PostSetNeedsCommitToMainThread(); | 1108 PostSetNeedsCommitToMainThread(); |
1109 } | 1109 } |
1110 | 1110 |
1111 void AfterTest() override {} | 1111 void AfterTest() override {} |
1112 | 1112 |
1113 void DidInitializeOutputSurface() override { EndTest(); } | 1113 void DidInitializeOutputSurface() override { EndTest(); } |
1114 | 1114 |
1115 private: | 1115 private: |
1116 FakeContentLayerClient client_; | 1116 FakeContentLayerClient client_; |
1117 }; | 1117 }; |
1118 | 1118 |
1119 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting); | 1119 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestImplSidePainting); |
1120 | 1120 |
1121 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { | 1121 class ScrollbarLayerLostContext : public LayerTreeHostContextTest { |
1122 public: | 1122 public: |
1123 ScrollbarLayerLostContext() : commits_(0) {} | 1123 ScrollbarLayerLostContext() : commits_(0) {} |
1124 | 1124 |
1125 void BeginTest() override { | 1125 void BeginTest() override { |
1126 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 1126 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
1127 scrollbar_layer_ = | 1127 scrollbar_layer_ = |
1128 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id()); | 1128 FakePaintedScrollbarLayer::Create(false, true, scroll_layer->id()); |
1129 scrollbar_layer_->SetBounds(gfx::Size(10, 100)); | 1129 scrollbar_layer_->SetBounds(gfx::Size(10, 100)); |
1130 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); | 1130 layer_tree()->root_layer()->AddChild(scrollbar_layer_); |
1131 layer_tree_host()->root_layer()->AddChild(scroll_layer); | 1131 layer_tree()->root_layer()->AddChild(scroll_layer); |
1132 PostSetNeedsCommitToMainThread(); | 1132 PostSetNeedsCommitToMainThread(); |
1133 } | 1133 } |
1134 | 1134 |
1135 void AfterTest() override {} | 1135 void AfterTest() override {} |
1136 | 1136 |
1137 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 1137 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
1138 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1138 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1139 | 1139 |
1140 ++commits_; | 1140 ++commits_; |
1141 switch (commits_) { | 1141 switch (commits_) { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 void AfterTest() override {} | 1579 void AfterTest() override {} |
1580 | 1580 |
1581 bool deferred_; | 1581 bool deferred_; |
1582 }; | 1582 }; |
1583 | 1583 |
1584 SINGLE_AND_MULTI_THREAD_TEST_F( | 1584 SINGLE_AND_MULTI_THREAD_TEST_F( |
1585 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1585 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1586 | 1586 |
1587 } // namespace | 1587 } // namespace |
1588 } // namespace cc | 1588 } // namespace cc |
OLD | NEW |