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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "cc/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
9 #include "cc/layers/delegated_frame_provider.h" | 9 #include "cc/layers/delegated_frame_provider.h" |
10 #include "cc/layers/delegated_frame_resource_collection.h" | 10 #include "cc/layers/delegated_frame_resource_collection.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 using media::VideoFrame; | 47 using media::VideoFrame; |
48 | 48 |
49 namespace cc { | 49 namespace cc { |
50 namespace { | 50 namespace { |
51 | 51 |
52 // These tests deal with losing the 3d graphics context. | 52 // These tests deal with losing the 3d graphics context. |
53 class LayerTreeHostContextTest : public LayerTreeTest { | 53 class LayerTreeHostContextTest : public LayerTreeTest { |
54 public: | 54 public: |
55 LayerTreeHostContextTest() | 55 LayerTreeHostContextTest() |
56 : LayerTreeTest(), | 56 : LayerTreeTest(), |
57 context3d_(NULL), | 57 context3d_(nullptr), |
58 times_to_fail_create_(0), | 58 times_to_fail_create_(0), |
59 times_to_lose_during_commit_(0), | 59 times_to_lose_during_commit_(0), |
60 times_to_lose_during_draw_(0), | 60 times_to_lose_during_draw_(0), |
61 times_to_fail_recreate_(0), | 61 times_to_fail_recreate_(0), |
62 times_to_expect_create_failed_(0), | 62 times_to_expect_create_failed_(0), |
63 times_create_failed_(0), | 63 times_create_failed_(0), |
64 committed_at_least_once_(false), | 64 committed_at_least_once_(false), |
65 context_should_support_io_surface_(false), | 65 context_should_support_io_surface_(false), |
66 fallback_context_works_(false), | 66 fallback_context_works_(false), |
67 async_output_surface_creation_(false) { | 67 async_output_surface_creation_(false) { |
68 media::InitializeMediaLibraryForTesting(); | 68 media::InitializeMediaLibraryForTesting(); |
69 } | 69 } |
70 | 70 |
71 void LoseContext() { | 71 void LoseContext() { |
72 // For sanity-checking tests, they should only call this when the | 72 // For sanity-checking tests, they should only call this when the |
73 // context is not lost. | 73 // context is not lost. |
74 CHECK(context3d_); | 74 CHECK(context3d_); |
75 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 75 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
76 GL_INNOCENT_CONTEXT_RESET_ARB); | 76 GL_INNOCENT_CONTEXT_RESET_ARB); |
77 context3d_ = NULL; | 77 context3d_ = nullptr; |
78 } | 78 } |
79 | 79 |
80 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { | 80 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { |
81 return TestWebGraphicsContext3D::Create(); | 81 return TestWebGraphicsContext3D::Create(); |
82 } | 82 } |
83 | 83 |
84 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 84 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
85 override { | 85 override { |
86 if (times_to_fail_create_) { | 86 if (times_to_fail_create_) { |
87 --times_to_fail_create_; | 87 --times_to_fail_create_; |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 763 |
764 layer_tree_host()->SetRootLayer(root_); | 764 layer_tree_host()->SetRootLayer(root_); |
765 LayerTreeHostContextTest::SetupTree(); | 765 LayerTreeHostContextTest::SetupTree(); |
766 } | 766 } |
767 | 767 |
768 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 768 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
769 | 769 |
770 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 770 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
771 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); | 771 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); |
772 | 772 |
773 FakePictureLayerImpl* root_picture = NULL; | 773 FakePictureLayerImpl* root_picture = nullptr; |
774 FakePictureLayerImpl* child_picture = NULL; | 774 FakePictureLayerImpl* child_picture = nullptr; |
775 FakePictureLayerImpl* grandchild_picture = NULL; | 775 FakePictureLayerImpl* grandchild_picture = nullptr; |
776 FakeContentLayerImpl* root_content = NULL; | 776 FakeContentLayerImpl* root_content = nullptr; |
777 FakeContentLayerImpl* child_content = NULL; | 777 FakeContentLayerImpl* child_content = nullptr; |
778 FakeContentLayerImpl* grandchild_content = NULL; | 778 FakeContentLayerImpl* grandchild_content = nullptr; |
779 | 779 |
780 if (layer_tree_host()->settings().impl_side_painting) { | 780 if (layer_tree_host()->settings().impl_side_painting) { |
781 root_picture = static_cast<FakePictureLayerImpl*>( | 781 root_picture = static_cast<FakePictureLayerImpl*>( |
782 host_impl->active_tree()->root_layer()); | 782 host_impl->active_tree()->root_layer()); |
783 child_picture = | 783 child_picture = |
784 static_cast<FakePictureLayerImpl*>(root_picture->children()[0]); | 784 static_cast<FakePictureLayerImpl*>(root_picture->children()[0]); |
785 grandchild_picture = | 785 grandchild_picture = |
786 static_cast<FakePictureLayerImpl*>(child_picture->children()[0]); | 786 static_cast<FakePictureLayerImpl*>(child_picture->children()[0]); |
787 | 787 |
788 } else { | 788 } else { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 public: | 847 public: |
848 LayerTreeHostContextTestDontUseLostResources() : lost_context_(false) { | 848 LayerTreeHostContextTestDontUseLostResources() : lost_context_(false) { |
849 context_should_support_io_surface_ = true; | 849 context_should_support_io_surface_ = true; |
850 | 850 |
851 child_output_surface_ = FakeOutputSurface::Create3d(); | 851 child_output_surface_ = FakeOutputSurface::Create3d(); |
852 child_output_surface_->BindToClient(&output_surface_client_); | 852 child_output_surface_->BindToClient(&output_surface_client_); |
853 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 853 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
854 child_resource_provider_ = | 854 child_resource_provider_ = |
855 ResourceProvider::Create(child_output_surface_.get(), | 855 ResourceProvider::Create(child_output_surface_.get(), |
856 shared_bitmap_manager_.get(), | 856 shared_bitmap_manager_.get(), |
857 NULL, | 857 nullptr, |
858 0, | 858 0, |
859 false, | 859 false, |
860 1, | 860 1, |
861 false); | 861 false); |
862 } | 862 } |
863 | 863 |
864 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {} | 864 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {} |
865 | 865 |
866 virtual void SetupTree() override { | 866 virtual void SetupTree() override { |
867 gpu::gles2::GLES2Interface* gl = | 867 gpu::gles2::GLES2Interface* gl = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 | 917 |
918 scoped_refptr<Layer> layer; | 918 scoped_refptr<Layer> layer; |
919 if (layer_tree_host()->settings().impl_side_painting) | 919 if (layer_tree_host()->settings().impl_side_painting) |
920 layer = PictureLayer::Create(&client_); | 920 layer = PictureLayer::Create(&client_); |
921 else | 921 else |
922 layer = ContentLayer::Create(&client_); | 922 layer = ContentLayer::Create(&client_); |
923 layer->SetBounds(gfx::Size(10, 10)); | 923 layer->SetBounds(gfx::Size(10, 10)); |
924 layer->SetIsDrawable(true); | 924 layer->SetIsDrawable(true); |
925 root->AddChild(layer); | 925 root->AddChild(layer); |
926 | 926 |
927 scoped_refptr<TextureLayer> texture = TextureLayer::CreateForMailbox(NULL); | 927 scoped_refptr<TextureLayer> texture = |
| 928 TextureLayer::CreateForMailbox(nullptr); |
928 texture->SetBounds(gfx::Size(10, 10)); | 929 texture->SetBounds(gfx::Size(10, 10)); |
929 texture->SetIsDrawable(true); | 930 texture->SetIsDrawable(true); |
930 texture->SetTextureMailbox( | 931 texture->SetTextureMailbox( |
931 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), | 932 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
932 SingleReleaseCallback::Create( | 933 SingleReleaseCallback::Create( |
933 base::Bind(&LayerTreeHostContextTestDontUseLostResources:: | 934 base::Bind(&LayerTreeHostContextTestDontUseLostResources:: |
934 EmptyReleaseCallback))); | 935 EmptyReleaseCallback))); |
935 root->AddChild(texture); | 936 root->AddChild(texture); |
936 | 937 |
937 scoped_refptr<Layer> mask; | 938 scoped_refptr<Layer> mask; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1022 |
1022 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1023 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1023 | 1024 |
1024 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1025 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1025 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); | 1026 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); |
1026 | 1027 |
1027 if (host_impl->active_tree()->source_frame_number() == 3) { | 1028 if (host_impl->active_tree()->source_frame_number() == 3) { |
1028 // On the third commit we're recovering from context loss. Hardware | 1029 // On the third commit we're recovering from context loss. Hardware |
1029 // video frames should not be reused by the VideoFrameProvider, but | 1030 // video frames should not be reused by the VideoFrameProvider, but |
1030 // software frames can be. | 1031 // software frames can be. |
1031 hw_frame_provider_.set_frame(NULL); | 1032 hw_frame_provider_.set_frame(nullptr); |
1032 scaled_hw_frame_provider_.set_frame(NULL); | 1033 scaled_hw_frame_provider_.set_frame(nullptr); |
1033 } | 1034 } |
1034 } | 1035 } |
1035 | 1036 |
1036 virtual DrawResult PrepareToDrawOnThread( | 1037 virtual DrawResult PrepareToDrawOnThread( |
1037 LayerTreeHostImpl* host_impl, | 1038 LayerTreeHostImpl* host_impl, |
1038 LayerTreeHostImpl::FrameData* frame, | 1039 LayerTreeHostImpl::FrameData* frame, |
1039 DrawResult draw_result) override { | 1040 DrawResult draw_result) override { |
1040 if (host_impl->active_tree()->source_frame_number() == 2) { | 1041 if (host_impl->active_tree()->source_frame_number() == 2) { |
1041 // Lose the context during draw on the second commit. This will cause | 1042 // Lose the context during draw on the second commit. This will cause |
1042 // a third commit to recover. | 1043 // a third commit to recover. |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 virtual void AfterTest() override {} | 1714 virtual void AfterTest() override {} |
1714 | 1715 |
1715 bool deferred_; | 1716 bool deferred_; |
1716 }; | 1717 }; |
1717 | 1718 |
1718 SINGLE_AND_MULTI_THREAD_TEST_F( | 1719 SINGLE_AND_MULTI_THREAD_TEST_F( |
1719 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1720 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1720 | 1721 |
1721 } // namespace | 1722 } // namespace |
1722 } // namespace cc | 1723 } // namespace cc |
OLD | NEW |