| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 context3d_->set_have_extension_io_surface(true); | 89 context3d_->set_have_extension_io_surface(true); |
| 90 context3d_->set_have_extension_egl_image(true); | 90 context3d_->set_have_extension_egl_image(true); |
| 91 } | 91 } |
| 92 | 92 |
| 93 if (delegating_renderer()) | 93 if (delegating_renderer()) |
| 94 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); | 94 return FakeOutputSurface::CreateDelegating3d(context3d.Pass()); |
| 95 else | 95 else |
| 96 return FakeOutputSurface::Create3d(context3d.Pass()); | 96 return FakeOutputSurface::Create3d(context3d.Pass()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 99 virtual DrawResult PrepareToDrawOnThread( |
| 100 LayerTreeHostImpl* host_impl, | 100 LayerTreeHostImpl* host_impl, |
| 101 LayerTreeHostImpl::FrameData* frame, | 101 LayerTreeHostImpl::FrameData* frame, |
| 102 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 102 DrawResult draw_result) OVERRIDE { |
| 103 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 103 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 104 if (!times_to_lose_during_draw_) | 104 if (!times_to_lose_during_draw_) |
| 105 return draw_result; | 105 return draw_result; |
| 106 | 106 |
| 107 --times_to_lose_during_draw_; | 107 --times_to_lose_during_draw_; |
| 108 LoseContext(); | 108 LoseContext(); |
| 109 | 109 |
| 110 times_to_fail_create_ = times_to_fail_recreate_; | 110 times_to_fail_create_ = times_to_fail_recreate_; |
| 111 times_to_fail_recreate_ = 0; | 111 times_to_fail_recreate_ = 0; |
| 112 | 112 |
| 113 return draw_result; | 113 return draw_result; |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 | 847 |
| 848 if (host_impl->active_tree()->source_frame_number() == 3) { | 848 if (host_impl->active_tree()->source_frame_number() == 3) { |
| 849 // On the third commit we're recovering from context loss. Hardware | 849 // On the third commit we're recovering from context loss. Hardware |
| 850 // video frames should not be reused by the VideoFrameProvider, but | 850 // video frames should not be reused by the VideoFrameProvider, but |
| 851 // software frames can be. | 851 // software frames can be. |
| 852 hw_frame_provider_.set_frame(NULL); | 852 hw_frame_provider_.set_frame(NULL); |
| 853 scaled_hw_frame_provider_.set_frame(NULL); | 853 scaled_hw_frame_provider_.set_frame(NULL); |
| 854 } | 854 } |
| 855 } | 855 } |
| 856 | 856 |
| 857 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 857 virtual DrawResult PrepareToDrawOnThread( |
| 858 LayerTreeHostImpl* host_impl, | 858 LayerTreeHostImpl* host_impl, |
| 859 LayerTreeHostImpl::FrameData* frame, | 859 LayerTreeHostImpl::FrameData* frame, |
| 860 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 860 DrawResult draw_result) OVERRIDE { |
| 861 if (host_impl->active_tree()->source_frame_number() == 2) { | 861 if (host_impl->active_tree()->source_frame_number() == 2) { |
| 862 // Lose the context during draw on the second commit. This will cause | 862 // Lose the context during draw on the second commit. This will cause |
| 863 // a third commit to recover. | 863 // a third commit to recover. |
| 864 context3d_->set_times_bind_texture_succeeds(0); | 864 context3d_->set_times_bind_texture_succeeds(0); |
| 865 } | 865 } |
| 866 return draw_result; | 866 return draw_result; |
| 867 } | 867 } |
| 868 | 868 |
| 869 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 869 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
| 870 OVERRIDE { | 870 OVERRIDE { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 } | 941 } |
| 942 | 942 |
| 943 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } | 943 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } |
| 944 | 944 |
| 945 virtual void AfterTest() OVERRIDE { | 945 virtual void AfterTest() OVERRIDE { |
| 946 // Should not try to create output surface again after successfully | 946 // Should not try to create output surface again after successfully |
| 947 // created by CompositeAndReadback. | 947 // created by CompositeAndReadback. |
| 948 EXPECT_EQ(1, times_output_surface_created_); | 948 EXPECT_EQ(1, times_output_surface_created_); |
| 949 } | 949 } |
| 950 | 950 |
| 951 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 951 virtual DrawResult PrepareToDrawOnThread( |
| 952 LayerTreeHostImpl* host_impl, | 952 LayerTreeHostImpl* host_impl, |
| 953 LayerTreeHostImpl::FrameData* frame_data, | 953 LayerTreeHostImpl::FrameData* frame_data, |
| 954 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 954 DrawResult draw_result) OVERRIDE { |
| 955 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); | 955 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); |
| 956 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); | 956 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); |
| 957 return draw_result; | 957 return draw_result; |
| 958 } | 958 } |
| 959 | 959 |
| 960 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 960 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 961 // We should only draw for the readback and the replacement commit. | 961 // We should only draw for the readback and the replacement commit. |
| 962 // The replacement commit will also be the first commit after output | 962 // The replacement commit will also be the first commit after output |
| 963 // surface initialization. | 963 // surface initialization. |
| 964 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); | 964 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 993 : did_react_to_first_commit_(false) {} | 993 : did_react_to_first_commit_(false) {} |
| 994 | 994 |
| 995 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 995 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 996 // This enables forced draws after a single prepare to draw failure. | 996 // This enables forced draws after a single prepare to draw failure. |
| 997 settings->timeout_and_draw_when_animation_checkerboards = true; | 997 settings->timeout_and_draw_when_animation_checkerboards = true; |
| 998 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 998 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1001 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1002 | 1002 |
| 1003 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 1003 virtual DrawResult PrepareToDrawOnThread( |
| 1004 LayerTreeHostImpl* host_impl, | 1004 LayerTreeHostImpl* host_impl, |
| 1005 LayerTreeHostImpl::FrameData* frame_data, | 1005 LayerTreeHostImpl::FrameData* frame_data, |
| 1006 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 1006 DrawResult draw_result) OVERRIDE { |
| 1007 int sfn = host_impl->active_tree()->source_frame_number(); | 1007 int sfn = host_impl->active_tree()->source_frame_number(); |
| 1008 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || | 1008 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || |
| 1009 sfn == kSecondOutputSurfaceInitSourceFrameNumber || | 1009 sfn == kSecondOutputSurfaceInitSourceFrameNumber || |
| 1010 sfn == kReadbackSourceFrameNumber) | 1010 sfn == kReadbackSourceFrameNumber) |
| 1011 << sfn; | 1011 << sfn; |
| 1012 | 1012 |
| 1013 // Before we react to the failed draw by initiating the forced draw | 1013 // Before we react to the failed draw by initiating the forced draw |
| 1014 // sequence, start a readback on the main thread and then lose the context | 1014 // sequence, start a readback on the main thread and then lose the context |
| 1015 // to start output surface initialization all at the same time. | 1015 // to start output surface initialization all at the same time. |
| 1016 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && | 1016 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && |
| 1017 !did_react_to_first_commit_) { | 1017 !did_react_to_first_commit_) { |
| 1018 did_react_to_first_commit_ = true; | 1018 did_react_to_first_commit_ = true; |
| 1019 PostReadbackToMainThread(); | 1019 PostReadbackToMainThread(); |
| 1020 LoseContext(); | 1020 LoseContext(); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 1023 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, | 1026 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, |
| 1027 bool success) OVERRIDE { | 1027 bool success) OVERRIDE { |
| 1028 // -1 is for the first output surface initialization. | 1028 // -1 is for the first output surface initialization. |
| 1029 int sfn = host_impl->active_tree()->source_frame_number(); | 1029 int sfn = host_impl->active_tree()->source_frame_number(); |
| 1030 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber) | 1030 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber) |
| 1031 << sfn; | 1031 << sfn; |
| 1032 } | 1032 } |
| 1033 | 1033 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 : did_lose_context_(false) {} | 1072 : did_lose_context_(false) {} |
| 1073 | 1073 |
| 1074 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1074 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 1075 // This enables forced draws after a single prepare to draw failure. | 1075 // This enables forced draws after a single prepare to draw failure. |
| 1076 settings->timeout_and_draw_when_animation_checkerboards = true; | 1076 settings->timeout_and_draw_when_animation_checkerboards = true; |
| 1077 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 1077 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1080 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1081 | 1081 |
| 1082 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 1082 virtual DrawResult PrepareToDrawOnThread( |
| 1083 LayerTreeHostImpl* host_impl, | 1083 LayerTreeHostImpl* host_impl, |
| 1084 LayerTreeHostImpl::FrameData* frame_data, | 1084 LayerTreeHostImpl::FrameData* frame_data, |
| 1085 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 1085 DrawResult draw_result) OVERRIDE { |
| 1086 int sfn = host_impl->active_tree()->source_frame_number(); | 1086 int sfn = host_impl->active_tree()->source_frame_number(); |
| 1087 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || | 1087 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || |
| 1088 sfn == kSecondOutputSurfaceInitSourceFrameNumber || | 1088 sfn == kSecondOutputSurfaceInitSourceFrameNumber || |
| 1089 sfn == kReadbackSourceFrameNumber) | 1089 sfn == kReadbackSourceFrameNumber) |
| 1090 << sfn; | 1090 << sfn; |
| 1091 | 1091 |
| 1092 // Before we react to the failed draw by initiating the forced draw | 1092 // Before we react to the failed draw by initiating the forced draw |
| 1093 // sequence, start a readback on the main thread and then lose the context | 1093 // sequence, start a readback on the main thread and then lose the context |
| 1094 // to start output surface initialization all at the same time. | 1094 // to start output surface initialization all at the same time. |
| 1095 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) { | 1095 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) { |
| 1096 did_lose_context_ = true; | 1096 did_lose_context_ = true; |
| 1097 LoseContext(); | 1097 LoseContext(); |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 // Returning false will result in a forced draw. | 1100 // Returning false will result in a forced draw. |
| 1101 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 1101 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 virtual void DidInitializeOutputSurface() OVERRIDE { | 1104 virtual void DidInitializeOutputSurface() OVERRIDE { |
| 1105 if (layer_tree_host()->source_frame_number() > 0) { | 1105 if (layer_tree_host()->source_frame_number() > 0) { |
| 1106 // Perform a readback right after the second output surface | 1106 // Perform a readback right after the second output surface |
| 1107 // initialization. | 1107 // initialization. |
| 1108 char pixels[4]; | 1108 char pixels[4]; |
| 1109 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); | 1109 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); |
| 1110 } | 1110 } |
| 1111 } | 1111 } |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 | 1713 |
| 1714 protected: | 1714 protected: |
| 1715 FakeContentLayerClient client_; | 1715 FakeContentLayerClient client_; |
| 1716 scoped_refptr<FakeContentLayer> layer_; | 1716 scoped_refptr<FakeContentLayer> layer_; |
| 1717 }; | 1717 }; |
| 1718 | 1718 |
| 1719 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 1719 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
| 1720 | 1720 |
| 1721 } // namespace | 1721 } // namespace |
| 1722 } // namespace cc | 1722 } // namespace cc |
| OLD | NEW |