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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_TRUE(succeeded); | 207 EXPECT_TRUE(succeeded); |
208 | 208 |
209 if (first_initialized_) | 209 if (first_initialized_) |
210 ++num_losses_; | 210 ++num_losses_; |
211 else | 211 else |
212 first_initialized_ = true; | 212 first_initialized_ = true; |
213 | 213 |
214 recovered_context_ = true; | 214 recovered_context_ = true; |
215 } | 215 } |
216 | 216 |
217 virtual void AfterTest() OVERRIDE { EXPECT_EQ(9u, test_case_); } | 217 virtual void AfterTest() OVERRIDE { EXPECT_EQ(7u, test_case_); } |
218 | 218 |
219 virtual void DidCommitAndDrawFrame() OVERRIDE { | 219 virtual void DidCommitAndDrawFrame() OVERRIDE { |
220 // If the last frame had a context loss, then we'll commit again to | 220 // If the last frame had a context loss, then we'll commit again to |
221 // recover. | 221 // recover. |
222 if (!recovered_context_) | 222 if (!recovered_context_) |
223 return; | 223 return; |
224 if (times_to_lose_during_commit_) | 224 if (times_to_lose_during_commit_) |
225 return; | 225 return; |
226 if (times_to_lose_during_draw_) | 226 if (times_to_lose_during_draw_) |
227 return; | 227 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 3, // times_to_fail_recreate | 260 3, // times_to_fail_recreate |
261 0, // times_to_fail_recreate_offscreen | 261 0, // times_to_fail_recreate_offscreen |
262 false, // fallback_context_works | 262 false, // fallback_context_works |
263 }, | 263 }, |
264 {0, // times_to_lose_during_commit | 264 {0, // times_to_lose_during_commit |
265 1, // times_to_lose_during_draw | 265 1, // times_to_lose_during_draw |
266 3, // times_to_fail_recreate | 266 3, // times_to_fail_recreate |
267 0, // times_to_fail_recreate_offscreen | 267 0, // times_to_fail_recreate_offscreen |
268 false, // fallback_context_works | 268 false, // fallback_context_works |
269 }, | 269 }, |
270 {1, // times_to_lose_during_commit | |
271 0, // times_to_lose_during_draw | |
272 0, // times_to_fail_recreate | |
273 3, // times_to_fail_recreate_offscreen | |
274 false, // fallback_context_works | |
275 }, | |
276 {0, // times_to_lose_during_commit | |
277 1, // times_to_lose_during_draw | |
278 0, // times_to_fail_recreate | |
279 3, // times_to_fail_recreate_offscreen | |
280 false, // fallback_context_works | |
281 }, | |
282 // Losing the context and recreating it any number of times should | 270 // Losing the context and recreating it any number of times should |
283 // succeed. | 271 // succeed. |
284 {10, // times_to_lose_during_commit | 272 {10, // times_to_lose_during_commit |
285 0, // times_to_lose_during_draw | 273 0, // times_to_lose_during_draw |
286 0, // times_to_fail_recreate | 274 0, // times_to_fail_recreate |
287 0, // times_to_fail_recreate_offscreen | 275 0, // times_to_fail_recreate_offscreen |
288 false, // fallback_context_works | 276 false, // fallback_context_works |
289 }, | 277 }, |
290 {0, // times_to_lose_during_commit | 278 {0, // times_to_lose_during_commit |
291 10, // times_to_lose_during_draw | 279 10, // times_to_lose_during_draw |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 353 |
366 virtual void AfterTest() OVERRIDE { | 354 virtual void AfterTest() OVERRIDE { |
367 } | 355 } |
368 }; | 356 }; |
369 | 357 |
370 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); | 358 MULTI_THREAD_TEST_F(LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); |
371 | 359 |
372 class LayerTreeHostContextTestLostContextSucceedsWithContent | 360 class LayerTreeHostContextTestLostContextSucceedsWithContent |
373 : public LayerTreeHostContextTestLostContextSucceeds { | 361 : public LayerTreeHostContextTestLostContextSucceeds { |
374 public: | 362 public: |
375 LayerTreeHostContextTestLostContextSucceedsWithContent() | |
376 : LayerTreeHostContextTestLostContextSucceeds() {} | |
377 | |
378 virtual void SetupTree() OVERRIDE { | 363 virtual void SetupTree() OVERRIDE { |
379 root_ = Layer::Create(); | 364 root_ = Layer::Create(); |
380 root_->SetBounds(gfx::Size(10, 10)); | 365 root_->SetBounds(gfx::Size(10, 10)); |
381 root_->SetAnchorPoint(gfx::PointF()); | 366 root_->SetAnchorPoint(gfx::PointF()); |
382 root_->SetIsDrawable(true); | 367 root_->SetIsDrawable(true); |
383 | 368 |
384 content_ = FakeContentLayer::Create(&client_); | 369 content_ = FakeContentLayer::Create(&client_); |
385 content_->SetBounds(gfx::Size(10, 10)); | 370 content_->SetBounds(gfx::Size(10, 10)); |
386 content_->SetAnchorPoint(gfx::PointF()); | 371 content_->SetAnchorPoint(gfx::PointF()); |
387 content_->SetIsDrawable(true); | 372 content_->SetIsDrawable(true); |
388 if (use_surface_) { | |
389 content_->SetForceRenderSurface(true); | |
390 // Filters require us to create an offscreen context. | |
391 FilterOperations filters; | |
392 filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f)); | |
393 content_->SetFilters(filters); | |
394 content_->SetBackgroundFilters(filters); | |
395 } | |
396 | 373 |
397 root_->AddChild(content_); | 374 root_->AddChild(content_); |
398 | 375 |
399 layer_tree_host()->SetRootLayer(root_); | 376 layer_tree_host()->SetRootLayer(root_); |
400 LayerTreeHostContextTest::SetupTree(); | 377 LayerTreeHostContextTest::SetupTree(); |
401 } | 378 } |
402 | 379 |
403 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { | 380 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { |
404 // Invalidate the render surface so we don't try to use a cached copy of the | 381 // Invalidate the render surface so we don't try to use a cached copy of the |
405 // surface. We want to make sure to test the drawing paths for drawing to | 382 // surface. We want to make sure to test the drawing paths for drawing to |
406 // a child surface. | 383 // a child surface. |
407 content_->SetNeedsDisplay(); | 384 content_->SetNeedsDisplay(); |
408 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); | 385 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); |
409 } | 386 } |
410 | 387 |
411 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 388 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
412 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( | 389 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( |
413 host_impl->active_tree()->root_layer()->children()[0]); | 390 host_impl->active_tree()->root_layer()->children()[0]); |
414 // Even though the context was lost, we should have a resource. The | 391 // Even though the context was lost, we should have a resource. The |
415 // TestWebGraphicsContext3D ensures that this resource is created with | 392 // TestWebGraphicsContext3D ensures that this resource is created with |
416 // the active context. | 393 // the active context. |
417 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); | 394 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
418 | |
419 ContextProvider* contexts = host_impl->offscreen_context_provider(); | |
420 if (use_surface_) { | |
421 ASSERT_TRUE(contexts); | |
422 EXPECT_TRUE(contexts->ContextGL()); | |
423 // TODO(danakj): Make a fake GrContext. | |
424 // EXPECT_TRUE(contexts->GrContext()); | |
425 } else { | |
426 EXPECT_FALSE(contexts); | |
427 } | |
428 } | |
429 | |
430 virtual void AfterTest() OVERRIDE { | |
431 LayerTreeHostContextTestLostContextSucceeds::AfterTest(); | |
432 if (use_surface_) { | |
433 // 1 create to start with + | |
434 // 4 from test cases that lose the offscreen context directly + | |
435 // 2 from test cases that create a fallback + | |
436 // All the test cases that recreate both contexts only once | |
437 // per time it is lost. | |
438 EXPECT_EQ(4 + 1 + 2 + num_losses_, times_offscreen_created_); | |
439 } else { | |
440 EXPECT_EQ(0, times_offscreen_created_); | |
441 } | |
442 } | 395 } |
443 | 396 |
444 protected: | 397 protected: |
445 bool use_surface_; | |
446 FakeContentLayerClient client_; | 398 FakeContentLayerClient client_; |
447 scoped_refptr<Layer> root_; | 399 scoped_refptr<Layer> root_; |
448 scoped_refptr<ContentLayer> content_; | 400 scoped_refptr<ContentLayer> content_; |
449 }; | 401 }; |
450 | 402 |
451 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | 403 // This test uses TiledLayer to check for a working context. |
452 NoSurface_SingleThread_DirectRenderer) { | 404 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
453 use_surface_ = false; | 405 LayerTreeHostContextTestLostContextSucceedsWithContent); |
454 RunTest(false, false, false); | |
455 } | |
456 | |
457 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | |
458 NoSurface_SingleThread_DelegatingRenderer) { | |
459 use_surface_ = false; | |
460 RunTest(false, true, false); | |
461 } | |
462 | |
463 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | |
464 NoSurface_MultiThread_DirectRenderer_MainThreadPaint) { | |
465 use_surface_ = false; | |
466 RunTest(true, false, false); | |
467 } | |
468 | |
469 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | |
470 NoSurface_MultiThread_DelegatingRenderer_MainThreadPaint) { | |
471 use_surface_ = false; | |
472 RunTest(true, true, false); | |
473 } | |
474 | |
475 // Surfaces don't exist with a delegating renderer. | |
476 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | |
477 WithSurface_SingleThread_DirectRenderer) { | |
478 use_surface_ = true; | |
479 RunTest(false, false, false); | |
480 } | |
481 | |
482 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, | |
483 WithSurface_MultiThread_DirectRenderer_MainThreadPaint) { | |
484 use_surface_ = true; | |
485 RunTest(true, false, false); | |
486 } | |
487 | 406 |
488 class LayerTreeHostContextTestCreateOutputSurfaceFails | 407 class LayerTreeHostContextTestCreateOutputSurfaceFails |
489 : public LayerTreeHostContextTest { | 408 : public LayerTreeHostContextTest { |
490 public: | 409 public: |
491 // Run a test that initially fails OutputSurface creation |times_to_fail| | 410 // Run a test that initially fails OutputSurface creation |times_to_fail| |
492 // times. If |expect_fallback_attempt| is |true|, an attempt to create a | 411 // times. If |expect_fallback_attempt| is |true|, an attempt to create a |
493 // fallback/software OutputSurface is expected to occur. | 412 // fallback/software OutputSurface is expected to occur. |
494 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, | 413 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, |
495 bool expect_fallback_attempt, | 414 bool expect_fallback_attempt, |
496 bool expect_to_give_up) | 415 bool expect_to_give_up) |
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 | 1898 |
1980 protected: | 1899 protected: |
1981 FakeContentLayerClient client_; | 1900 FakeContentLayerClient client_; |
1982 scoped_refptr<FakeContentLayer> layer_; | 1901 scoped_refptr<FakeContentLayer> layer_; |
1983 }; | 1902 }; |
1984 | 1903 |
1985 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 1904 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
1986 | 1905 |
1987 } // namespace | 1906 } // namespace |
1988 } // namespace cc | 1907 } // namespace cc |
OLD | NEW |