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

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

Issue 279013002: Remove CompositeAndReadback from LayerTreeHost(Impl) and the Proxys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm-cnr-lth-proxy-renderer: rebase-on-drawresult 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 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 scoped_refptr<VideoFrame> hw_video_frame_; 908 scoped_refptr<VideoFrame> hw_video_frame_;
909 scoped_refptr<VideoFrame> scaled_hw_video_frame_; 909 scoped_refptr<VideoFrame> scaled_hw_video_frame_;
910 910
911 FakeVideoFrameProvider color_frame_provider_; 911 FakeVideoFrameProvider color_frame_provider_;
912 FakeVideoFrameProvider hw_frame_provider_; 912 FakeVideoFrameProvider hw_frame_provider_;
913 FakeVideoFrameProvider scaled_hw_frame_provider_; 913 FakeVideoFrameProvider scaled_hw_frame_provider_;
914 }; 914 };
915 915
916 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources); 916 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources);
917 917
918 class LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit
919 : public LayerTreeHostContextTest {
920 public:
921 virtual void BeginTest() OVERRIDE {
922 // This must be called immediately after creating LTH, before the first
923 // OutputSurface is initialized.
924 ASSERT_TRUE(layer_tree_host()->output_surface_lost());
925
926 times_output_surface_created_ = 0;
927
928 // Post the SetNeedsCommit before the readback to make sure it is run
929 // on the main thread before the readback's replacement commit when
930 // we have a threaded compositor.
931 PostSetNeedsCommitToMainThread();
932
933 char pixels[4];
934 bool result =
935 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(1, 1));
936 EXPECT_EQ(!delegating_renderer(), result);
937 EXPECT_EQ(1, times_output_surface_created_);
938 }
939
940 virtual void DidInitializeOutputSurface() OVERRIDE {
941 ++times_output_surface_created_;
942 }
943
944 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); }
945
946 virtual void AfterTest() OVERRIDE {
947 // Should not try to create output surface again after successfully
948 // created by CompositeAndReadback.
949 EXPECT_EQ(1, times_output_surface_created_);
950 }
951
952 virtual DrawResult PrepareToDrawOnThread(
953 LayerTreeHostImpl* host_impl,
954 LayerTreeHostImpl::FrameData* frame_data,
955 DrawResult draw_result) OVERRIDE {
956 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
957 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1);
958 return draw_result;
959 }
960
961 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
962 // We should only draw for the readback and the replacement commit.
963 // The replacement commit will also be the first commit after output
964 // surface initialization.
965 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0);
966 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1);
967 }
968
969 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
970 bool result) OVERRIDE {
971 // We should only swap for the replacement commit.
972 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1);
973 EndTest();
974 }
975
976 private:
977 int times_output_surface_created_;
978 };
979
980 SINGLE_AND_MULTI_THREAD_TEST_F(
981 LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit);
982
983 // This test verifies that losing an output surface during a
984 // simultaneous readback and forced redraw works and does not deadlock.
985 class LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw
986 : public LayerTreeHostContextTest {
987 protected:
988 static const int kFirstOutputSurfaceInitSourceFrameNumber = 0;
989 static const int kReadbackSourceFrameNumber = 1;
990 static const int kReadbackReplacementSourceFrameNumber = 2;
991 static const int kSecondOutputSurfaceInitSourceFrameNumber = 3;
992
993 LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw()
994 : did_react_to_first_commit_(false) {}
995
996 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
997 // This enables forced draws after a single prepare to draw failure.
998 settings->timeout_and_draw_when_animation_checkerboards = true;
999 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
1000 }
1001
1002 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1003
1004 virtual DrawResult PrepareToDrawOnThread(
1005 LayerTreeHostImpl* host_impl,
1006 LayerTreeHostImpl::FrameData* frame_data,
1007 DrawResult draw_result) OVERRIDE {
1008 int sfn = host_impl->active_tree()->source_frame_number();
1009 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber ||
1010 sfn == kSecondOutputSurfaceInitSourceFrameNumber ||
1011 sfn == kReadbackSourceFrameNumber)
1012 << sfn;
1013
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
1016 // to start output surface initialization all at the same time.
1017 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber &&
1018 !did_react_to_first_commit_) {
1019 did_react_to_first_commit_ = true;
1020 PostReadbackToMainThread();
1021 LoseContext();
1022 }
1023
1024 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
1025 }
1026
1027 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
1028 bool success) OVERRIDE {
1029 // -1 is for the first output surface initialization.
1030 int sfn = host_impl->active_tree()->source_frame_number();
1031 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber)
1032 << sfn;
1033 }
1034
1035 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1036 // We should only draw the first commit after output surface initialization
1037 // and attempt to draw the readback commit (which will fail).
1038 // All others should abort because the output surface is lost.
1039 int sfn = host_impl->active_tree()->source_frame_number();
1040 EXPECT_TRUE(sfn == kSecondOutputSurfaceInitSourceFrameNumber ||
1041 sfn == kReadbackSourceFrameNumber)
1042 << sfn;
1043 }
1044
1045 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1046 bool result) OVERRIDE {
1047 // We should only swap the first commit after the second output surface
1048 // initialization.
1049 int sfn = host_impl->active_tree()->source_frame_number();
1050 EXPECT_TRUE(sfn == kSecondOutputSurfaceInitSourceFrameNumber) << sfn;
1051 EndTest();
1052 }
1053
1054 virtual void AfterTest() OVERRIDE {}
1055
1056 int did_react_to_first_commit_;
1057 };
1058
1059 MULTI_THREAD_TEST_F(
1060 LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw);
1061
1062 // This test verifies that losing an output surface right before a
1063 // simultaneous readback and forced redraw works and does not deadlock.
1064 class LayerTreeHostContextTestReadbackWithForcedDrawAndOutputSurfaceInit
1065 : public LayerTreeHostContextTest {
1066 protected:
1067 static const int kFirstOutputSurfaceInitSourceFrameNumber = 0;
1068 static const int kReadbackSourceFrameNumber = 1;
1069 static const int kForcedDrawCommitSourceFrameNumber = 2;
1070 static const int kSecondOutputSurfaceInitSourceFrameNumber = 2;
1071
1072 LayerTreeHostContextTestReadbackWithForcedDrawAndOutputSurfaceInit()
1073 : did_lose_context_(false) {}
1074
1075 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1076 // This enables forced draws after a single prepare to draw failure.
1077 settings->timeout_and_draw_when_animation_checkerboards = true;
1078 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
1079 }
1080
1081 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1082
1083 virtual DrawResult PrepareToDrawOnThread(
1084 LayerTreeHostImpl* host_impl,
1085 LayerTreeHostImpl::FrameData* frame_data,
1086 DrawResult draw_result) OVERRIDE {
1087 int sfn = host_impl->active_tree()->source_frame_number();
1088 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber ||
1089 sfn == kSecondOutputSurfaceInitSourceFrameNumber ||
1090 sfn == kReadbackSourceFrameNumber)
1091 << sfn;
1092
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
1095 // to start output surface initialization all at the same time.
1096 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) {
1097 did_lose_context_ = true;
1098 LoseContext();
1099 }
1100
1101 // Returning false will result in a forced draw.
1102 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
1103 }
1104
1105 virtual void DidInitializeOutputSurface() OVERRIDE {
1106 if (layer_tree_host()->source_frame_number() > 0) {
1107 // Perform a readback right after the second output surface
1108 // initialization.
1109 char pixels[4];
1110 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
1111 }
1112 }
1113
1114 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
1115 bool success) OVERRIDE {
1116 // -1 is for the first output surface initialization.
1117 int sfn = host_impl->active_tree()->source_frame_number();
1118 EXPECT_TRUE(sfn == -1 || sfn == kFirstOutputSurfaceInitSourceFrameNumber)
1119 << sfn;
1120 }
1121
1122 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1123 // We should only draw the first commit after output surface initialization
1124 // and attempt to draw the readback commit (which will fail).
1125 // All others should abort because the output surface is lost.
1126 int sfn = host_impl->active_tree()->source_frame_number();
1127 EXPECT_TRUE(sfn == kForcedDrawCommitSourceFrameNumber ||
1128 sfn == kReadbackSourceFrameNumber)
1129 << sfn;
1130 }
1131
1132 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1133 bool result) OVERRIDE {
1134 // We should only swap the first commit after the second output surface
1135 // initialization.
1136 int sfn = host_impl->active_tree()->source_frame_number();
1137 EXPECT_TRUE(sfn == kForcedDrawCommitSourceFrameNumber) << sfn;
1138 EndTest();
1139 }
1140
1141 virtual void AfterTest() OVERRIDE {}
1142
1143 int did_lose_context_;
1144 };
1145
1146 MULTI_THREAD_TEST_F(
1147 LayerTreeHostContextTestReadbackWithForcedDrawAndOutputSurfaceInit);
1148
1149 class ImplSidePaintingLayerTreeHostContextTest 918 class ImplSidePaintingLayerTreeHostContextTest
1150 : public LayerTreeHostContextTest { 919 : public LayerTreeHostContextTest {
1151 public: 920 public:
1152 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 921 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1153 settings->impl_side_painting = true; 922 settings->impl_side_painting = true;
1154 } 923 }
1155 }; 924 };
1156 925
1157 class LayerTreeHostContextTestImplSidePainting 926 class LayerTreeHostContextTestImplSidePainting
1158 : public ImplSidePaintingLayerTreeHostContextTest { 927 : public ImplSidePaintingLayerTreeHostContextTest {
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 1483
1715 protected: 1484 protected:
1716 FakeContentLayerClient client_; 1485 FakeContentLayerClient client_;
1717 scoped_refptr<FakeContentLayer> layer_; 1486 scoped_refptr<FakeContentLayer> layer_;
1718 }; 1487 };
1719 1488
1720 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 1489 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
1721 1490
1722 } // namespace 1491 } // namespace
1723 } // namespace cc 1492 } // 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