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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE { | 121 virtual scoped_refptr<ContextProvider> OffscreenContextProvider() OVERRIDE { |
122 if (!offscreen_contexts_.get() || | 122 if (!offscreen_contexts_.get() || |
123 offscreen_contexts_->DestroyedOnMainThread()) { | 123 offscreen_contexts_->DestroyedOnMainThread()) { |
124 offscreen_contexts_ = | 124 offscreen_contexts_ = |
125 TestContextProvider::Create(CreateOffscreenContext3d()); | 125 TestContextProvider::Create(CreateOffscreenContext3d()); |
126 } | 126 } |
127 return offscreen_contexts_; | 127 return offscreen_contexts_; |
128 } | 128 } |
129 | 129 |
130 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 130 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
131 LayerTreeHostImpl::FrameData* frame, | 131 LayerTreeHostImpl* host_impl, |
132 bool result) OVERRIDE { | 132 LayerTreeHostImpl::FrameData* frame, |
133 EXPECT_TRUE(result); | 133 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
| 134 EXPECT_EQ(DrawSwapReadbackResult::DID_DRAW, draw_result); |
134 if (!times_to_lose_during_draw_) | 135 if (!times_to_lose_during_draw_) |
135 return result; | 136 return draw_result; |
136 | 137 |
137 --times_to_lose_during_draw_; | 138 --times_to_lose_during_draw_; |
138 LoseContext(); | 139 LoseContext(); |
139 | 140 |
140 times_to_fail_create_ = times_to_fail_recreate_; | 141 times_to_fail_create_ = times_to_fail_recreate_; |
141 times_to_fail_recreate_ = 0; | 142 times_to_fail_recreate_ = 0; |
142 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; | 143 times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; |
143 times_to_fail_recreate_offscreen_ = 0; | 144 times_to_fail_recreate_offscreen_ = 0; |
144 | 145 |
145 return result; | 146 return draw_result; |
146 } | 147 } |
147 | 148 |
148 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 149 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
149 committed_at_least_once_ = true; | 150 committed_at_least_once_ = true; |
150 | 151 |
151 if (!times_to_lose_during_commit_) | 152 if (!times_to_lose_during_commit_) |
152 return; | 153 return; |
153 --times_to_lose_during_commit_; | 154 --times_to_lose_during_commit_; |
154 LoseContext(); | 155 LoseContext(); |
155 | 156 |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 | 1108 |
1108 if (host_impl->active_tree()->source_frame_number() == 3) { | 1109 if (host_impl->active_tree()->source_frame_number() == 3) { |
1109 // On the third commit we're recovering from context loss. Hardware | 1110 // On the third commit we're recovering from context loss. Hardware |
1110 // video frames should not be reused by the VideoFrameProvider, but | 1111 // video frames should not be reused by the VideoFrameProvider, but |
1111 // software frames can be. | 1112 // software frames can be. |
1112 hw_frame_provider_.set_frame(NULL); | 1113 hw_frame_provider_.set_frame(NULL); |
1113 scaled_hw_frame_provider_.set_frame(NULL); | 1114 scaled_hw_frame_provider_.set_frame(NULL); |
1114 } | 1115 } |
1115 } | 1116 } |
1116 | 1117 |
1117 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1118 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
1118 LayerTreeHostImpl::FrameData* frame, | 1119 LayerTreeHostImpl* host_impl, |
1119 bool result) OVERRIDE { | 1120 LayerTreeHostImpl::FrameData* frame, |
| 1121 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
1120 if (host_impl->active_tree()->source_frame_number() == 2) { | 1122 if (host_impl->active_tree()->source_frame_number() == 2) { |
1121 // Lose the context during draw on the second commit. This will cause | 1123 // Lose the context during draw on the second commit. This will cause |
1122 // a third commit to recover. | 1124 // a third commit to recover. |
1123 context3d_->set_times_bind_texture_succeeds(0); | 1125 context3d_->set_times_bind_texture_succeeds(0); |
1124 } | 1126 } |
1125 return true; | 1127 return DrawSwapReadbackResult::DID_DRAW; |
1126 } | 1128 } |
1127 | 1129 |
1128 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) | 1130 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
1129 OVERRIDE { | 1131 OVERRIDE { |
1130 // This will get called twice: | 1132 // This will get called twice: |
1131 // First when we create the initial output surface... | 1133 // First when we create the initial output surface... |
1132 if (layer_tree_host()->source_frame_number() > 0) { | 1134 if (layer_tree_host()->source_frame_number() > 0) { |
1133 // ... and then again after we forced the context to be lost on the third | 1135 // ... and then again after we forced the context to be lost on the third |
1134 // frame. Verify this assumption here. | 1136 // frame. Verify this assumption here. |
1135 lost_context_ = true; | 1137 lost_context_ = true; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 } | 1204 } |
1203 | 1205 |
1204 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } | 1206 virtual void DidCommitAndDrawFrame() OVERRIDE { EndTest(); } |
1205 | 1207 |
1206 virtual void AfterTest() OVERRIDE { | 1208 virtual void AfterTest() OVERRIDE { |
1207 // Should not try to create output surface again after successfully | 1209 // Should not try to create output surface again after successfully |
1208 // created by CompositeAndReadback. | 1210 // created by CompositeAndReadback. |
1209 EXPECT_EQ(1, times_output_surface_created_); | 1211 EXPECT_EQ(1, times_output_surface_created_); |
1210 } | 1212 } |
1211 | 1213 |
1212 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1214 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
1213 LayerTreeHostImpl::FrameData* frame_data, | 1215 LayerTreeHostImpl* host_impl, |
1214 bool result) OVERRIDE { | 1216 LayerTreeHostImpl::FrameData* frame_data, |
| 1217 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
1215 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); | 1218 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); |
1216 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); | 1219 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); |
1217 return true; | 1220 return DrawSwapReadbackResult::DID_DRAW; |
1218 } | 1221 } |
1219 | 1222 |
1220 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1223 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
1221 // We should only draw for the readback and the replacement commit. | 1224 // We should only draw for the readback and the replacement commit. |
1222 // The replacement commit will also be the first commit after output | 1225 // The replacement commit will also be the first commit after output |
1223 // surface initialization. | 1226 // surface initialization. |
1224 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); | 1227 EXPECT_GE(host_impl->active_tree()->source_frame_number(), 0); |
1225 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); | 1228 EXPECT_LE(host_impl->active_tree()->source_frame_number(), 1); |
1226 } | 1229 } |
1227 | 1230 |
(...skipping 25 matching lines...) Expand all Loading... |
1253 : did_react_to_first_commit_(false) {} | 1256 : did_react_to_first_commit_(false) {} |
1254 | 1257 |
1255 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1258 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1256 // This enables forced draws after a single prepare to draw failure. | 1259 // This enables forced draws after a single prepare to draw failure. |
1257 settings->timeout_and_draw_when_animation_checkerboards = true; | 1260 settings->timeout_and_draw_when_animation_checkerboards = true; |
1258 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 1261 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
1259 } | 1262 } |
1260 | 1263 |
1261 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1264 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
1262 | 1265 |
1263 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1266 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
1264 LayerTreeHostImpl::FrameData* frame_data, | 1267 LayerTreeHostImpl* host_impl, |
1265 bool result) OVERRIDE { | 1268 LayerTreeHostImpl::FrameData* frame_data, |
| 1269 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
1266 int sfn = host_impl->active_tree()->source_frame_number(); | 1270 int sfn = host_impl->active_tree()->source_frame_number(); |
1267 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || | 1271 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || |
1268 sfn == kSecondOutputSurfaceInitSourceFrameNumber || | 1272 sfn == kSecondOutputSurfaceInitSourceFrameNumber || |
1269 sfn == kReadbackSourceFrameNumber) | 1273 sfn == kReadbackSourceFrameNumber) |
1270 << sfn; | 1274 << sfn; |
1271 | 1275 |
1272 // Before we react to the failed draw by initiating the forced draw | 1276 // Before we react to the failed draw by initiating the forced draw |
1273 // sequence, start a readback on the main thread and then lose the context | 1277 // sequence, start a readback on the main thread and then lose the context |
1274 // to start output surface initialization all at the same time. | 1278 // to start output surface initialization all at the same time. |
1275 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && | 1279 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && |
1276 !did_react_to_first_commit_) { | 1280 !did_react_to_first_commit_) { |
1277 did_react_to_first_commit_ = true; | 1281 did_react_to_first_commit_ = true; |
1278 PostReadbackToMainThread(); | 1282 PostReadbackToMainThread(); |
1279 LoseContext(); | 1283 LoseContext(); |
1280 } | 1284 } |
1281 | 1285 |
1282 return false; | 1286 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
1283 } | 1287 } |
1284 | 1288 |
1285 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, | 1289 virtual void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, |
1286 bool success) OVERRIDE { | 1290 bool success) OVERRIDE { |
1287 // -1 is for the first output surface initialization. | 1291 // -1 is for the first output surface initialization. |
1288 int sfn = host_impl->active_tree()->source_frame_number(); | 1292 int sfn = host_impl->active_tree()->source_frame_number(); |
1289 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber) | 1293 EXPECT_TRUE(sfn == -1 || sfn == kReadbackReplacementSourceFrameNumber) |
1290 << sfn; | 1294 << sfn; |
1291 } | 1295 } |
1292 | 1296 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 : did_lose_context_(false) {} | 1335 : did_lose_context_(false) {} |
1332 | 1336 |
1333 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1337 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
1334 // This enables forced draws after a single prepare to draw failure. | 1338 // This enables forced draws after a single prepare to draw failure. |
1335 settings->timeout_and_draw_when_animation_checkerboards = true; | 1339 settings->timeout_and_draw_when_animation_checkerboards = true; |
1336 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 1340 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
1337 } | 1341 } |
1338 | 1342 |
1339 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1343 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
1340 | 1344 |
1341 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1345 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( |
1342 LayerTreeHostImpl::FrameData* frame_data, | 1346 LayerTreeHostImpl* host_impl, |
1343 bool result) OVERRIDE { | 1347 LayerTreeHostImpl::FrameData* frame_data, |
| 1348 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { |
1344 int sfn = host_impl->active_tree()->source_frame_number(); | 1349 int sfn = host_impl->active_tree()->source_frame_number(); |
1345 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || | 1350 EXPECT_TRUE(sfn == kFirstOutputSurfaceInitSourceFrameNumber || |
1346 sfn == kSecondOutputSurfaceInitSourceFrameNumber || | 1351 sfn == kSecondOutputSurfaceInitSourceFrameNumber || |
1347 sfn == kReadbackSourceFrameNumber) | 1352 sfn == kReadbackSourceFrameNumber) |
1348 << sfn; | 1353 << sfn; |
1349 | 1354 |
1350 // Before we react to the failed draw by initiating the forced draw | 1355 // Before we react to the failed draw by initiating the forced draw |
1351 // sequence, start a readback on the main thread and then lose the context | 1356 // sequence, start a readback on the main thread and then lose the context |
1352 // to start output surface initialization all at the same time. | 1357 // to start output surface initialization all at the same time. |
1353 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) { | 1358 if (sfn == kFirstOutputSurfaceInitSourceFrameNumber && !did_lose_context_) { |
1354 did_lose_context_ = true; | 1359 did_lose_context_ = true; |
1355 LoseContext(); | 1360 LoseContext(); |
1356 } | 1361 } |
1357 | 1362 |
1358 // Returning false will result in a forced draw. | 1363 // Returning false will result in a forced draw. |
1359 return false; | 1364 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
1360 } | 1365 } |
1361 | 1366 |
1362 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { | 1367 virtual void DidInitializeOutputSurface(bool succeeded) OVERRIDE { |
1363 EXPECT_TRUE(succeeded); | 1368 EXPECT_TRUE(succeeded); |
1364 if (layer_tree_host()->source_frame_number() > 0) { | 1369 if (layer_tree_host()->source_frame_number() > 0) { |
1365 // Perform a readback right after the second output surface | 1370 // Perform a readback right after the second output surface |
1366 // initialization. | 1371 // initialization. |
1367 char pixels[4]; | 1372 char pixels[4]; |
1368 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); | 1373 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1)); |
1369 } | 1374 } |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 | 1984 |
1980 protected: | 1985 protected: |
1981 FakeContentLayerClient client_; | 1986 FakeContentLayerClient client_; |
1982 scoped_refptr<FakeContentLayer> layer_; | 1987 scoped_refptr<FakeContentLayer> layer_; |
1983 }; | 1988 }; |
1984 | 1989 |
1985 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 1990 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
1986 | 1991 |
1987 } // namespace | 1992 } // namespace |
1988 } // namespace cc | 1993 } // namespace cc |
OLD | NEW |