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

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

Issue 246753008: cc: Unify use of DidSwapBuffers() and did_request_swap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 7 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 | Annotate | Revision Log
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 "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
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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 848
849 if (host_impl->active_tree()->source_frame_number() == 3) { 849 if (host_impl->active_tree()->source_frame_number() == 3) {
850 // On the third commit we're recovering from context loss. Hardware 850 // On the third commit we're recovering from context loss. Hardware
851 // video frames should not be reused by the VideoFrameProvider, but 851 // video frames should not be reused by the VideoFrameProvider, but
852 // software frames can be. 852 // software frames can be.
853 hw_frame_provider_.set_frame(NULL); 853 hw_frame_provider_.set_frame(NULL);
854 scaled_hw_frame_provider_.set_frame(NULL); 854 scaled_hw_frame_provider_.set_frame(NULL);
855 } 855 }
856 } 856 }
857 857
858 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( 858 virtual DrawResult PrepareToDrawOnThread(
859 LayerTreeHostImpl* host_impl, 859 LayerTreeHostImpl* host_impl,
860 LayerTreeHostImpl::FrameData* frame, 860 LayerTreeHostImpl::FrameData* frame,
861 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { 861 DrawResult draw_result) OVERRIDE {
862 if (host_impl->active_tree()->source_frame_number() == 2) { 862 if (host_impl->active_tree()->source_frame_number() == 2) {
863 // Lose the context during draw on the second commit. This will cause 863 // Lose the context during draw on the second commit. This will cause
864 // a third commit to recover. 864 // a third commit to recover.
865 context3d_->set_times_bind_texture_succeeds(0); 865 context3d_->set_times_bind_texture_succeeds(0);
866 } 866 }
867 return draw_result; 867 return draw_result;
868 } 868 }
869 869
870 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 870 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback)
871 OVERRIDE { 871 OVERRIDE {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 942 }
943 943
944 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } 944 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); }
945 945
946 virtual void AfterTest() OVERRIDE { 946 virtual void AfterTest() OVERRIDE {
947 // Should not try to create output surface again after successfully 947 // Should not try to create output surface again after successfully
948 // created by CompositeAndReadback. 948 // created by CompositeAndReadback.
949 EXPECT_EQ(1, times_output_surface_created_); 949 EXPECT_EQ(1, times_output_surface_created_);
950 } 950 }
951 951
952 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( 952 virtual DrawResult PrepareToDrawOnThread(
953 LayerTreeHostImpl* host_impl, 953 LayerTreeHostImpl* host_impl,
954 LayerTreeHostImpl::FrameData* frame_data, 954 LayerTreeHostImpl::FrameData* frame_data,
955 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { 955 DrawResult draw_result) OVERRIDE {
956 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); 956 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
957 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); 957 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1);
958 return draw_result; 958 return draw_result;
959 } 959 }
960 960
961 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 961 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
962 // We should only draw for the readback and the replacement commit. 962 // We should only draw for the readback and the replacement commit.
963 // The replacement commit will also be the first commit after output 963 // The replacement commit will also be the first commit after output
964 // surface initialization. 964 // surface initialization.
965 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); 965 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
(...skipping 28 matching lines...) Expand all
994 : did_react_to_first_commit_(false) {} 994 : did_react_to_first_commit_(false) {}
995 995
996 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 996 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
997 // This enables forced draws after a single prepare to draw failure. 997 // This enables forced draws after a single prepare to draw failure.
998 settings->timeout_and_draw_when_animation_checkerboards = true; 998 settings->timeout_and_draw_when_animation_checkerboards = true;
999 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 999 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
1000 } 1000 }
1001 1001
1002 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 1002 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1003 1003
1004 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( 1004 virtual DrawResult PrepareToDrawOnThread(
1005 LayerTreeHostImpl* host_impl, 1005 LayerTreeHostImpl* host_impl,
1006 LayerTreeHostImpl::FrameData* frame_data, 1006 LayerTreeHostImpl::FrameData* frame_data,
1007 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { 1007 DrawResult draw_result) OVERRIDE {
1008 int sfn = host_impl->active_tree()->source_frame_number(); 1008 int sfn = host_impl->active_tree()->source_frame_number();
1009 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || 1009 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber ||
1010 sfn == kSecondOutputSurfaceInitSourceFrameNumber || 1010 sfn == kSecondOutputSurfaceInitSourceFrameNumber ||
1011 sfn == kReadbackSourceFrameNumber) 1011 sfn == kReadbackSourceFrameNumber)
1012 << sfn; 1012 << sfn;
1013 1013
1014 // Before we react to the failed draw by initiating the forced draw 1014 // Before we react to the failed draw by initiating the forced draw
1015 // sequence, start a readback on the main thread and then lose the context 1015 // sequence, start a readback on the main thread and then lose the context
1016 // to start output surface initialization all at the same time. 1016 // to start output surface initialization all at the same time.
1017 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && 1017 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber &&
1018 !did_react_to_first_commit_) { 1018 !did_react_to_first_commit_) {
1019 did_react_to_first_commit_ = true; 1019 did_react_to_first_commit_ = true;
1020 PostReadbackToMainThread(); 1020 PostReadbackToMainThread();
1021 LoseContext(); 1021 LoseContext();
1022 } 1022 }
1023 1023
1024 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; 1024 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
1025 } 1025 }
1026 1026
1027 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, 1027 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
1028 bool success) OVERRIDE { 1028 bool success) OVERRIDE {
1029 // -1 is for the first output surface initialization. 1029 // -1 is for the first output surface initialization.
1030 int sfn = host_impl->active_tree()->source_frame_number(); 1030 int sfn = host_impl->active_tree()->source_frame_number();
1031 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber) 1031 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber)
1032 << sfn; 1032 << sfn;
1033 } 1033 }
1034 1034
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 : did_lose_context_(false) {} 1073 : did_lose_context_(false) {}
1074 1074
1075 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 1075 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1076 // This enables forced draws after a single prepare to draw failure. 1076 // This enables forced draws after a single prepare to draw failure.
1077 settings->timeout_and_draw_when_animation_checkerboards = true; 1077 settings->timeout_and_draw_when_animation_checkerboards = true;
1078 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 1078 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
1079 } 1079 }
1080 1080
1081 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 1081 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1082 1082
1083 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( 1083 virtual DrawResult PrepareToDrawOnThread(
1084 LayerTreeHostImpl* host_impl, 1084 LayerTreeHostImpl* host_impl,
1085 LayerTreeHostImpl::FrameData* frame_data, 1085 LayerTreeHostImpl::FrameData* frame_data,
1086 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { 1086 DrawResult draw_result) OVERRIDE {
1087 int sfn = host_impl->active_tree()->source_frame_number(); 1087 int sfn = host_impl->active_tree()->source_frame_number();
1088 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || 1088 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber ||
1089 sfn == kSecondOutputSurfaceInitSourceFrameNumber || 1089 sfn == kSecondOutputSurfaceInitSourceFrameNumber ||
1090 sfn == kReadbackSourceFrameNumber) 1090 sfn == kReadbackSourceFrameNumber)
1091 << sfn; 1091 << sfn;
1092 1092
1093 // Before we react to the failed draw by initiating the forced draw 1093 // Before we react to the failed draw by initiating the forced draw
1094 // sequence, start a readback on the main thread and then lose the context 1094 // sequence, start a readback on the main thread and then lose the context
1095 // to start output surface initialization all at the same time. 1095 // to start output surface initialization all at the same time.
1096 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) { 1096 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) {
1097 did_lose_context_ = true; 1097 did_lose_context_ = true;
1098 LoseContext(); 1098 LoseContext();
1099 } 1099 }
1100 1100
1101 // Returning false will result in a forced draw. 1101 // Returning false will result in a forced draw.
1102 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; 1102 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
1103 } 1103 }
1104 1104
1105 virtual void DidInitializeOutputSurface() OVERRIDE { 1105 virtual void DidInitializeOutputSurface() OVERRIDE {
1106 if (layer_tree_host()->source_frame_number() > 0) { 1106 if (layer_tree_host()->source_frame_number() > 0) {
1107 // Perform a readback right after the second output surface 1107 // Perform a readback right after the second output surface
1108 // initialization. 1108 // initialization.
1109 char pixels[4]; 1109 char pixels[4];
1110 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); 1110 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
1111 } 1111 }
1112 } 1112 }
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 1714
1715 protected: 1715 protected:
1716 FakeContentLayerClient client_; 1716 FakeContentLayerClient client_;
1717 scoped_refptr<FakeContentLayer> layer_; 1717 scoped_refptr<FakeContentLayer> layer_;
1718 }; 1718 };
1719 1719
1720 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 1720 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
1721 1721
1722 } // namespace 1722 } // namespace
1723 } // namespace cc 1723 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_animation.cc ('k') | cc/trees/layer_tree_host_unittest_damage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698