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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 : LayerTreeTest(), | 53 : LayerTreeTest(), |
54 context3d_(NULL), | 54 context3d_(NULL), |
55 times_to_fail_create_(0), | 55 times_to_fail_create_(0), |
56 times_to_lose_during_commit_(0), | 56 times_to_lose_during_commit_(0), |
57 times_to_lose_during_draw_(0), | 57 times_to_lose_during_draw_(0), |
58 times_to_fail_recreate_(0), | 58 times_to_fail_recreate_(0), |
59 times_to_expect_create_failed_(0), | 59 times_to_expect_create_failed_(0), |
60 times_create_failed_(0), | 60 times_create_failed_(0), |
61 committed_at_least_once_(false), | 61 committed_at_least_once_(false), |
62 context_should_support_io_surface_(false), | 62 context_should_support_io_surface_(false), |
63 fallback_context_works_(false) { | 63 fallback_context_works_(false), |
| 64 async_output_surface_creation_(false) { |
64 media::InitializeMediaLibraryForTesting(); | 65 media::InitializeMediaLibraryForTesting(); |
65 } | 66 } |
66 | 67 |
67 void LoseContext() { | 68 void LoseContext() { |
68 // For sanity-checking tests, they should only call this when the | 69 // For sanity-checking tests, they should only call this when the |
69 // context is not lost. | 70 // context is not lost. |
70 CHECK(context3d_); | 71 CHECK(context3d_); |
71 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 72 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
72 GL_INNOCENT_CONTEXT_RESET_ARB); | 73 GL_INNOCENT_CONTEXT_RESET_ARB); |
73 context3d_ = NULL; | 74 context3d_ = NULL; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 TestWebGraphicsContext3D* context3d_; | 144 TestWebGraphicsContext3D* context3d_; |
144 int times_to_fail_create_; | 145 int times_to_fail_create_; |
145 int times_to_lose_during_commit_; | 146 int times_to_lose_during_commit_; |
146 int times_to_lose_during_draw_; | 147 int times_to_lose_during_draw_; |
147 int times_to_fail_recreate_; | 148 int times_to_fail_recreate_; |
148 int times_to_expect_create_failed_; | 149 int times_to_expect_create_failed_; |
149 int times_create_failed_; | 150 int times_create_failed_; |
150 bool committed_at_least_once_; | 151 bool committed_at_least_once_; |
151 bool context_should_support_io_surface_; | 152 bool context_should_support_io_surface_; |
152 bool fallback_context_works_; | 153 bool fallback_context_works_; |
| 154 bool async_output_surface_creation_; |
153 }; | 155 }; |
154 | 156 |
155 class LayerTreeHostContextTestLostContextSucceeds | 157 class LayerTreeHostContextTestLostContextSucceeds |
156 : public LayerTreeHostContextTest { | 158 : public LayerTreeHostContextTest { |
157 public: | 159 public: |
158 LayerTreeHostContextTestLostContextSucceeds() | 160 LayerTreeHostContextTestLostContextSucceeds() |
159 : LayerTreeHostContextTest(), | 161 : LayerTreeHostContextTest(), |
160 test_case_(0), | 162 test_case_(0), |
161 num_losses_(0), | 163 num_losses_(0), |
162 num_losses_last_test_case_(-1), | 164 num_losses_last_test_case_(-1), |
163 recovered_context_(true), | 165 recovered_context_(true), |
164 first_initialized_(false) {} | 166 first_initialized_(false) {} |
165 | 167 |
166 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 168 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
167 | 169 |
| 170 virtual void RequestNewOutputSurface(bool fallback) OVERRIDE { |
| 171 if (async_output_surface_creation_) { |
| 172 MainThreadTaskRunner()->PostTask( |
| 173 FROM_HERE, |
| 174 base::Bind(&LayerTreeHostContextTestLostContextSucceeds:: |
| 175 CreateAndSetOutputSurface, |
| 176 base::Unretained(this), |
| 177 fallback)); |
| 178 } else { |
| 179 CreateAndSetOutputSurface(fallback); |
| 180 } |
| 181 } |
| 182 |
| 183 void CreateAndSetOutputSurface(bool fallback) { |
| 184 layer_tree_host()->SetOutputSurface( |
| 185 LayerTreeHostContextTest::CreateOutputSurface(fallback)); |
| 186 } |
| 187 |
168 virtual void DidInitializeOutputSurface() OVERRIDE { | 188 virtual void DidInitializeOutputSurface() OVERRIDE { |
169 if (first_initialized_) | 189 if (first_initialized_) |
170 ++num_losses_; | 190 ++num_losses_; |
171 else | 191 else |
172 first_initialized_ = true; | 192 first_initialized_ = true; |
173 | 193 |
174 recovered_context_ = true; | 194 recovered_context_ = true; |
175 } | 195 } |
176 | 196 |
177 virtual void AfterTest() OVERRIDE { EXPECT_EQ(7u, test_case_); } | 197 virtual void AfterTest() OVERRIDE { EXPECT_EQ(11u, test_case_); } |
178 | 198 |
179 virtual void DidCommitAndDrawFrame() OVERRIDE { | 199 virtual void DidCommitAndDrawFrame() OVERRIDE { |
180 // If the last frame had a context loss, then we'll commit again to | 200 // If the last frame had a context loss, then we'll commit again to |
181 // recover. | 201 // recover. |
182 if (!recovered_context_) | 202 if (!recovered_context_) |
183 return; | 203 return; |
184 if (times_to_lose_during_commit_) | 204 if (times_to_lose_during_commit_) |
185 return; | 205 return; |
186 if (times_to_lose_during_draw_) | 206 if (times_to_lose_during_draw_) |
187 return; | 207 return; |
(...skipping 13 matching lines...) Expand all Loading... |
201 | 221 |
202 bool NextTestCase() { | 222 bool NextTestCase() { |
203 static const TestCase kTests[] = { | 223 static const TestCase kTests[] = { |
204 // Losing the context and failing to recreate it (or losing it again | 224 // Losing the context and failing to recreate it (or losing it again |
205 // immediately) a small number of times should succeed. | 225 // immediately) a small number of times should succeed. |
206 { | 226 { |
207 1, // times_to_lose_during_commit | 227 1, // times_to_lose_during_commit |
208 0, // times_to_lose_during_draw | 228 0, // times_to_lose_during_draw |
209 0, // times_to_fail_recreate | 229 0, // times_to_fail_recreate |
210 false, // fallback_context_works | 230 false, // fallback_context_works |
| 231 false, // async_output_surface_creation |
211 }, | 232 }, |
212 { | 233 { |
213 0, // times_to_lose_during_commit | 234 0, // times_to_lose_during_commit |
214 1, // times_to_lose_during_draw | 235 1, // times_to_lose_during_draw |
215 0, // times_to_fail_recreate | 236 0, // times_to_fail_recreate |
216 false, // fallback_context_works | 237 false, // fallback_context_works |
| 238 false, // async_output_surface_creation |
217 }, | 239 }, |
218 { | 240 { |
219 1, // times_to_lose_during_commit | 241 1, // times_to_lose_during_commit |
220 0, // times_to_lose_during_draw | 242 0, // times_to_lose_during_draw |
221 3, // times_to_fail_recreate | 243 3, // times_to_fail_recreate |
222 false, // fallback_context_works | 244 false, // fallback_context_works |
| 245 false, // async_output_surface_creation |
223 }, | 246 }, |
224 { | 247 { |
225 0, // times_to_lose_during_commit | 248 0, // times_to_lose_during_commit |
226 1, // times_to_lose_during_draw | 249 1, // times_to_lose_during_draw |
227 3, // times_to_fail_recreate | 250 3, // times_to_fail_recreate |
228 false, // fallback_context_works | 251 false, // fallback_context_works |
| 252 false, // async_output_surface_creation |
| 253 }, |
| 254 { |
| 255 0, // times_to_lose_during_commit |
| 256 1, // times_to_lose_during_draw |
| 257 3, // times_to_fail_recreate |
| 258 false, // fallback_context_works |
| 259 true, // async_output_surface_creation |
229 }, | 260 }, |
230 // Losing the context and recreating it any number of times should | 261 // Losing the context and recreating it any number of times should |
231 // succeed. | 262 // succeed. |
232 { | 263 { |
233 10, // times_to_lose_during_commit | 264 10, // times_to_lose_during_commit |
234 0, // times_to_lose_during_draw | 265 0, // times_to_lose_during_draw |
235 0, // times_to_fail_recreate | 266 0, // times_to_fail_recreate |
236 false, // fallback_context_works | 267 false, // fallback_context_works |
| 268 false, // async_output_surface_creation |
237 }, | 269 }, |
238 { | 270 { |
239 0, // times_to_lose_during_commit | 271 0, // times_to_lose_during_commit |
240 10, // times_to_lose_during_draw | 272 10, // times_to_lose_during_draw |
241 0, // times_to_fail_recreate | 273 0, // times_to_fail_recreate |
242 false, // fallback_context_works | 274 false, // fallback_context_works |
| 275 false, // async_output_surface_creation |
| 276 }, |
| 277 { |
| 278 10, // times_to_lose_during_commit |
| 279 0, // times_to_lose_during_draw |
| 280 0, // times_to_fail_recreate |
| 281 false, // fallback_context_works |
| 282 true, // async_output_surface_creation |
| 283 }, |
| 284 { |
| 285 0, // times_to_lose_during_commit |
| 286 10, // times_to_lose_during_draw |
| 287 0, // times_to_fail_recreate |
| 288 false, // fallback_context_works |
| 289 true, // async_output_surface_creation |
243 }, | 290 }, |
244 // Losing the context, failing to reinitialize it, and making a fallback | 291 // Losing the context, failing to reinitialize it, and making a fallback |
245 // context should work. | 292 // context should work. |
246 { | 293 { |
| 294 0, // times_to_lose_during_commit |
| 295 1, // times_to_lose_during_draw |
| 296 0, // times_to_fail_recreate |
| 297 true, // fallback_context_works |
| 298 false, // async_output_surface_creation |
| 299 }, |
| 300 { |
247 0, // times_to_lose_during_commit | 301 0, // times_to_lose_during_commit |
248 1, // times_to_lose_during_draw | 302 1, // times_to_lose_during_draw |
249 0, // times_to_fail_recreate | 303 0, // times_to_fail_recreate |
250 true, // fallback_context_works | 304 true, // fallback_context_works |
| 305 true, // async_output_surface_creation |
251 }, | 306 }, |
252 }; | 307 }; |
253 | 308 |
254 if (test_case_ >= arraysize(kTests)) | 309 if (test_case_ >= arraysize(kTests)) |
255 return false; | 310 return false; |
256 // Make sure that we lost our context at least once in the last test run so | 311 // Make sure that we lost our context at least once in the last test run so |
257 // the test did something. | 312 // the test did something. |
258 EXPECT_GT(num_losses_, num_losses_last_test_case_); | 313 EXPECT_GT(num_losses_, num_losses_last_test_case_); |
259 num_losses_last_test_case_ = num_losses_; | 314 num_losses_last_test_case_ = num_losses_; |
260 | 315 |
261 times_to_lose_during_commit_ = | 316 times_to_lose_during_commit_ = |
262 kTests[test_case_].times_to_lose_during_commit; | 317 kTests[test_case_].times_to_lose_during_commit; |
263 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw; | 318 times_to_lose_during_draw_ = kTests[test_case_].times_to_lose_during_draw; |
264 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; | 319 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; |
265 fallback_context_works_ = kTests[test_case_].fallback_context_works; | 320 fallback_context_works_ = kTests[test_case_].fallback_context_works; |
| 321 async_output_surface_creation_ = |
| 322 kTests[test_case_].async_output_surface_creation; |
266 ++test_case_; | 323 ++test_case_; |
267 return true; | 324 return true; |
268 } | 325 } |
269 | 326 |
270 struct TestCase { | 327 struct TestCase { |
271 int times_to_lose_during_commit; | 328 int times_to_lose_during_commit; |
272 int times_to_lose_during_draw; | 329 int times_to_lose_during_draw; |
273 int times_to_fail_recreate; | 330 int times_to_fail_recreate; |
274 bool fallback_context_works; | 331 bool fallback_context_works; |
| 332 bool async_output_surface_creation; |
275 }; | 333 }; |
276 | 334 |
277 protected: | 335 protected: |
278 size_t test_case_; | 336 size_t test_case_; |
279 int num_losses_; | 337 int num_losses_; |
280 int num_losses_last_test_case_; | 338 int num_losses_last_test_case_; |
281 bool recovered_context_; | 339 bool recovered_context_; |
282 bool first_initialized_; | 340 bool first_initialized_; |
283 }; | 341 }; |
284 | 342 |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 virtual void AfterTest() OVERRIDE {} | 1573 virtual void AfterTest() OVERRIDE {} |
1516 | 1574 |
1517 bool deferred_; | 1575 bool deferred_; |
1518 }; | 1576 }; |
1519 | 1577 |
1520 SINGLE_AND_MULTI_THREAD_TEST_F( | 1578 SINGLE_AND_MULTI_THREAD_TEST_F( |
1521 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1579 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1522 | 1580 |
1523 } // namespace | 1581 } // namespace |
1524 } // namespace cc | 1582 } // namespace cc |
OLD | NEW |