OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/layer_tree_host.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "cc/content_layer.h" |
| 9 #include "cc/delegated_renderer_layer.h" |
| 10 #include "cc/delegated_renderer_layer_impl.h" |
| 11 #include "cc/heads_up_display_layer.h" |
| 12 #include "cc/io_surface_layer.h" |
| 13 #include "cc/layer_impl.h" |
| 14 #include "cc/layer_tree_host_impl.h" |
| 15 #include "cc/layer_tree_impl.h" |
| 16 #include "cc/scrollbar_layer.h" |
| 17 #include "cc/single_thread_proxy.h" |
| 18 #include "cc/test/fake_content_layer.h" |
| 19 #include "cc/test/fake_content_layer_client.h" |
| 20 #include "cc/test/fake_content_layer_impl.h" |
| 21 #include "cc/test/fake_output_surface.h" |
| 22 #include "cc/test/fake_scrollbar_theme_painter.h" |
| 23 #include "cc/test/fake_video_frame.h" |
| 24 #include "cc/test/fake_video_frame_provider.h" |
| 25 #include "cc/test/fake_web_graphics_context_3d.h" |
| 26 #include "cc/test/fake_web_scrollbar.h" |
| 27 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
| 28 #include "cc/test/layer_tree_test_common.h" |
| 29 #include "cc/test/render_pass_test_common.h" |
| 30 #include "cc/texture_layer.h" |
| 31 #include "cc/video_layer.h" |
| 32 #include "cc/video_layer_impl.h" |
| 33 #include "media/base/media.h" |
| 34 |
| 35 using media::VideoFrame; |
| 36 using WebKit::WebGraphicsContext3D; |
| 37 |
| 38 namespace cc { |
| 39 namespace { |
| 40 |
| 41 // These tests deal with losing the 3d graphics context. |
| 42 class LayerTreeHostContextTest : public ThreadedTest { |
| 43 public: |
| 44 LayerTreeHostContextTest() |
| 45 : ThreadedTest(), |
| 46 context3d_(NULL), |
| 47 times_to_fail_create_(0), |
| 48 times_to_create_and_lose_(0), |
| 49 times_to_lose_during_commit_(0), |
| 50 times_to_repeat_loss_(0), |
| 51 times_to_fail_recreate_(0) { |
| 52 media::InitializeMediaLibraryForTesting(); |
| 53 } |
| 54 |
| 55 void LoseContext() { |
| 56 context3d_->loseContextCHROMIUM(); |
| 57 context3d_ = NULL; |
| 58 } |
| 59 |
| 60 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { |
| 61 return FakeWebGraphicsContext3D::Create(); |
| 62 } |
| 63 |
| 64 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { |
| 65 if (times_to_fail_create_) { |
| 66 --times_to_fail_create_; |
| 67 return scoped_ptr<OutputSurface>(); |
| 68 } |
| 69 |
| 70 scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d(); |
| 71 context3d_ = context3d.get(); |
| 72 |
| 73 if (times_to_create_and_lose_) { |
| 74 --times_to_create_and_lose_; |
| 75 // Make the context get lost during reinitialization. |
| 76 // The number of times MakeCurrent succeeds is not important, and |
| 77 // can be changed if needed to make this pass with future changes. |
| 78 context3d_->set_times_make_current_succeeds(2); |
| 79 } |
| 80 |
| 81 return FakeOutputSurface::Create3d( |
| 82 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
| 83 } |
| 84 |
| 85 virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { |
| 86 if (!times_to_lose_during_commit_) |
| 87 return; |
| 88 --times_to_lose_during_commit_; |
| 89 LoseContext(); |
| 90 |
| 91 times_to_create_and_lose_ = times_to_repeat_loss_; |
| 92 times_to_repeat_loss_ = 0; |
| 93 times_to_fail_create_ = times_to_fail_recreate_; |
| 94 times_to_fail_recreate_ = 0; |
| 95 } |
| 96 |
| 97 protected: |
| 98 FakeWebGraphicsContext3D* context3d_; |
| 99 int times_to_fail_create_; |
| 100 int times_to_create_and_lose_; |
| 101 int times_to_lose_during_commit_; |
| 102 int times_to_repeat_loss_; |
| 103 int times_to_fail_recreate_; |
| 104 }; |
| 105 |
| 106 class LayerTreeHostContextTestLostContextSucceeds : |
| 107 public LayerTreeHostContextTest { |
| 108 public: |
| 109 LayerTreeHostContextTestLostContextSucceeds() |
| 110 : LayerTreeHostContextTest(), |
| 111 test_case_(0), |
| 112 num_losses_(0) { |
| 113 } |
| 114 |
| 115 virtual void beginTest() OVERRIDE { |
| 116 postSetNeedsCommitToMainThread(); |
| 117 } |
| 118 |
| 119 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 120 EXPECT_TRUE(succeeded); |
| 121 ++num_losses_; |
| 122 } |
| 123 |
| 124 virtual void afterTest() OVERRIDE { |
| 125 EXPECT_EQ(3, test_case_); |
| 126 EXPECT_EQ(3, num_losses_); |
| 127 } |
| 128 |
| 129 bool SourceFrameHasContextLoss(int source_frame) const { |
| 130 return source_frame % 2 == 1; |
| 131 } |
| 132 |
| 133 virtual void didCommitAndDrawFrame() OVERRIDE { |
| 134 // If the last frame had a context loss, then we'll commit again to |
| 135 // recover. |
| 136 if (SourceFrameHasContextLoss(m_layerTreeHost->commitNumber()) - 1) |
| 137 return; |
| 138 |
| 139 if (NextTestCase()) |
| 140 m_layerTreeHost->setNeedsCommit(); |
| 141 else |
| 142 endTest(); |
| 143 } |
| 144 |
| 145 bool NextTestCase() { |
| 146 static const TestCase kTests[] = { |
| 147 // Losing the context and failing to recreate it (or losing it again |
| 148 // immediately) a small number of times should succeed. |
| 149 { 1, // times_to_lose_during_commit |
| 150 0, // times_to_repeat_loss |
| 151 0, // times_to_fail_recreate |
| 152 }, |
| 153 { 1, |
| 154 3, // times_to_repeat_loss |
| 155 0, // times_to_fail_recreate |
| 156 }, |
| 157 { 1, |
| 158 0, // times_to_repeat_loss |
| 159 3, // times_to_fail_recreate |
| 160 }, |
| 161 }; |
| 162 |
| 163 if (test_case_ >= arraysize(kTests)) |
| 164 return false; |
| 165 |
| 166 times_to_lose_during_commit_ = |
| 167 kTests[test_case_].times_to_lose_during_commit; |
| 168 times_to_repeat_loss_ = kTests[test_case_].times_to_repeat_loss; |
| 169 times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; |
| 170 ++test_case_; |
| 171 return true; |
| 172 } |
| 173 |
| 174 struct TestCase { |
| 175 int times_to_lose_during_commit; |
| 176 int times_to_repeat_loss; |
| 177 int times_to_fail_recreate; |
| 178 }; |
| 179 |
| 180 private: |
| 181 size_t test_case_; |
| 182 int num_losses_; |
| 183 }; |
| 184 |
| 185 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds) |
| 186 |
| 187 class LayerTreeHostContextTestLostContextSucceedsWithContent : |
| 188 public LayerTreeHostContextTestLostContextSucceeds { |
| 189 public: |
| 190 |
| 191 LayerTreeHostContextTestLostContextSucceedsWithContent() |
| 192 : LayerTreeHostContextTestLostContextSucceeds() { |
| 193 } |
| 194 |
| 195 virtual void setupTree() OVERRIDE { |
| 196 scoped_refptr<Layer> root_ = Layer::create(); |
| 197 root_->setBounds(gfx::Size(10, 10)); |
| 198 root_->setAnchorPoint(gfx::PointF()); |
| 199 root_->setIsDrawable(true); |
| 200 |
| 201 scoped_refptr<FakeContentLayer> content_ = |
| 202 FakeContentLayer::Create(&client_); |
| 203 content_->setBounds(gfx::Size(10, 10)); |
| 204 content_->setAnchorPoint(gfx::PointF()); |
| 205 content_->setIsDrawable(true); |
| 206 if (use_surface_) |
| 207 content_->setForceRenderSurface(true); |
| 208 root_->addChild(content_); |
| 209 |
| 210 m_layerTreeHost->setRootLayer(root_); |
| 211 LayerTreeHostContextTest::setupTree(); |
| 212 } |
| 213 |
| 214 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) { |
| 215 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( |
| 216 host_impl->rootLayer()->children()[0]); |
| 217 // Even though the context was lost, we should have a resource. The |
| 218 // FakeWebGraphicsContext3D ensures that this resource is created with |
| 219 // the active context. |
| 220 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
| 221 } |
| 222 |
| 223 protected: |
| 224 bool use_surface_; |
| 225 FakeContentLayerClient client_; |
| 226 scoped_refptr<Layer> root_; |
| 227 scoped_refptr<ContentLayer> content_; |
| 228 }; |
| 229 |
| 230 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
| 231 NoSurface_SingleThread) { |
| 232 use_surface_ = false; |
| 233 runTest(false); |
| 234 } |
| 235 |
| 236 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
| 237 NoSurface_MultiThread) { |
| 238 use_surface_ = false; |
| 239 runTest(true); |
| 240 } |
| 241 |
| 242 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
| 243 WithSurface_SingleThread) { |
| 244 use_surface_ = true; |
| 245 runTest(false); |
| 246 } |
| 247 |
| 248 TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
| 249 WithSurface_MultiThread) { |
| 250 use_surface_ = true; |
| 251 runTest(true); |
| 252 } |
| 253 |
| 254 class LayerTreeHostContextTestLostContextFails : |
| 255 public LayerTreeHostContextTest { |
| 256 public: |
| 257 LayerTreeHostContextTestLostContextFails() |
| 258 : LayerTreeHostContextTest(), |
| 259 num_commits_(0) { |
| 260 times_to_lose_during_commit_ = 1; |
| 261 } |
| 262 |
| 263 virtual void beginTest() OVERRIDE { |
| 264 postSetNeedsCommitToMainThread(); |
| 265 } |
| 266 |
| 267 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 268 EXPECT_FALSE(succeeded); |
| 269 endTest(); |
| 270 } |
| 271 |
| 272 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 273 LayerTreeHostContextTest::commitCompleteOnThread(host_impl); |
| 274 |
| 275 ++num_commits_; |
| 276 if (num_commits_ == 1) { |
| 277 // When the context is ok, we should have these things. |
| 278 EXPECT_TRUE(host_impl->outputSurface()); |
| 279 EXPECT_TRUE(host_impl->renderer()); |
| 280 EXPECT_TRUE(host_impl->resourceProvider()); |
| 281 return; |
| 282 } |
| 283 |
| 284 // When context recreation fails we shouldn't be left with any of them. |
| 285 EXPECT_FALSE(host_impl->outputSurface()); |
| 286 EXPECT_FALSE(host_impl->renderer()); |
| 287 EXPECT_FALSE(host_impl->resourceProvider()); |
| 288 } |
| 289 |
| 290 virtual void afterTest() OVERRIDE {} |
| 291 |
| 292 private: |
| 293 int num_commits_; |
| 294 }; |
| 295 |
| 296 TEST_F(LayerTreeHostContextTestLostContextFails, RepeatLoss100_SingleThread) { |
| 297 times_to_repeat_loss_ = 100; |
| 298 times_to_fail_recreate_ = 0; |
| 299 runTest(false); |
| 300 } |
| 301 |
| 302 TEST_F(LayerTreeHostContextTestLostContextFails, RepeatLoss100_MultiThread) { |
| 303 times_to_repeat_loss_ = 100; |
| 304 times_to_fail_recreate_ = 0; |
| 305 runTest(true); |
| 306 } |
| 307 |
| 308 TEST_F(LayerTreeHostContextTestLostContextFails, FailRecreate100_SingleThread) { |
| 309 times_to_repeat_loss_ = 0; |
| 310 times_to_fail_recreate_ = 100; |
| 311 runTest(false); |
| 312 } |
| 313 |
| 314 TEST_F(LayerTreeHostContextTestLostContextFails, FailRecreate100_MultiThread) { |
| 315 times_to_repeat_loss_ = 0; |
| 316 times_to_fail_recreate_ = 100; |
| 317 runTest(true); |
| 318 } |
| 319 |
| 320 class LayerTreeHostContextTestFinishAllRenderingAfterLoss : |
| 321 public LayerTreeHostContextTest { |
| 322 public: |
| 323 virtual void beginTest() OVERRIDE { |
| 324 // Lose the context until the compositor gives up on it. |
| 325 times_to_lose_during_commit_ = 1; |
| 326 times_to_repeat_loss_ = 10; |
| 327 postSetNeedsCommitToMainThread(); |
| 328 } |
| 329 |
| 330 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 331 EXPECT_FALSE(succeeded); |
| 332 m_layerTreeHost->finishAllRendering(); |
| 333 endTest(); |
| 334 } |
| 335 |
| 336 virtual void afterTest() OVERRIDE {} |
| 337 }; |
| 338 |
| 339 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 340 LayerTreeHostContextTestFinishAllRenderingAfterLoss) |
| 341 |
| 342 class LayerTreeHostContextTestLostContextAndEvictTextures : |
| 343 public LayerTreeHostContextTest { |
| 344 public: |
| 345 LayerTreeHostContextTestLostContextAndEvictTextures() |
| 346 : LayerTreeHostContextTest(), |
| 347 layer_(FakeContentLayer::Create(&client_)), |
| 348 impl_host_(0), |
| 349 num_commits_(0) { |
| 350 } |
| 351 |
| 352 virtual void setupTree() OVERRIDE { |
| 353 layer_->setBounds(gfx::Size(10, 20)); |
| 354 m_layerTreeHost->setRootLayer(layer_); |
| 355 LayerTreeHostContextTest::setupTree(); |
| 356 } |
| 357 |
| 358 virtual void beginTest() OVERRIDE { |
| 359 postSetNeedsCommitToMainThread(); |
| 360 } |
| 361 |
| 362 void PostEvictTextures() { |
| 363 if (implThread()) { |
| 364 implThread()->postTask( |
| 365 base::Bind( |
| 366 &LayerTreeHostContextTestLostContextAndEvictTextures:: |
| 367 EvictTexturesOnImplThread, |
| 368 base::Unretained(this))); |
| 369 } else { |
| 370 DebugScopedSetImplThread impl(proxy()); |
| 371 EvictTexturesOnImplThread(); |
| 372 } |
| 373 } |
| 374 |
| 375 void EvictTexturesOnImplThread() { |
| 376 impl_host_->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); |
| 377 if (lose_after_evict_) |
| 378 LoseContext(); |
| 379 } |
| 380 |
| 381 virtual void didCommitAndDrawFrame() OVERRIDE { |
| 382 if (num_commits_ > 1) |
| 383 return; |
| 384 EXPECT_TRUE(layer_->HaveBackingAt(0, 0)); |
| 385 PostEvictTextures(); |
| 386 } |
| 387 |
| 388 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 389 if (num_commits_ > 1) |
| 390 return; |
| 391 ++num_commits_; |
| 392 if (!lose_after_evict_) |
| 393 LoseContext(); |
| 394 impl_host_ = impl; |
| 395 } |
| 396 |
| 397 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 398 EXPECT_TRUE(succeeded); |
| 399 endTest(); |
| 400 } |
| 401 |
| 402 virtual void afterTest() OVERRIDE {} |
| 403 |
| 404 protected: |
| 405 bool lose_after_evict_; |
| 406 FakeContentLayerClient client_; |
| 407 scoped_refptr<FakeContentLayer> layer_; |
| 408 LayerTreeHostImpl* impl_host_; |
| 409 int num_commits_; |
| 410 }; |
| 411 |
| 412 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, |
| 413 LoseAfterEvict_SingleThread) { |
| 414 lose_after_evict_ = true; |
| 415 runTest(false); |
| 416 } |
| 417 |
| 418 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, |
| 419 LoseAfterEvict_MultiThread) { |
| 420 lose_after_evict_ = true; |
| 421 runTest(true); |
| 422 } |
| 423 |
| 424 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, |
| 425 LoseBeforeEvict_SingleThread) { |
| 426 lose_after_evict_ = false; |
| 427 runTest(false); |
| 428 } |
| 429 |
| 430 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, |
| 431 LoseBeforeEvict_MultiThread) { |
| 432 lose_after_evict_ = false; |
| 433 runTest(true); |
| 434 } |
| 435 |
| 436 class LayerTreeHostContextTestLostContextWhileUpdatingResources : |
| 437 public LayerTreeHostContextTest { |
| 438 public: |
| 439 LayerTreeHostContextTestLostContextWhileUpdatingResources() |
| 440 : parent_(FakeContentLayer::Create(&client_)), |
| 441 num_children_(50), |
| 442 times_to_lose_on_end_query_(3) { |
| 443 } |
| 444 |
| 445 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { |
| 446 scoped_ptr<FakeWebGraphicsContext3D> context = |
| 447 LayerTreeHostContextTest::CreateContext3d(); |
| 448 if (times_to_lose_on_end_query_) { |
| 449 --times_to_lose_on_end_query_; |
| 450 context->set_times_end_query_succeeds(5); |
| 451 } |
| 452 return context.Pass(); |
| 453 } |
| 454 |
| 455 virtual void setupTree() { |
| 456 parent_->setBounds(gfx::Size(num_children_, 1)); |
| 457 |
| 458 for (int i = 0; i < num_children_; i++) { |
| 459 scoped_refptr<FakeContentLayer> child = |
| 460 FakeContentLayer::Create(&client_); |
| 461 child->setPosition(gfx::PointF(i, 0.f)); |
| 462 child->setBounds(gfx::Size(1, 1)); |
| 463 parent_->addChild(child); |
| 464 } |
| 465 |
| 466 m_layerTreeHost->setRootLayer(parent_); |
| 467 LayerTreeHostContextTest::setupTree(); |
| 468 } |
| 469 |
| 470 virtual void beginTest() { |
| 471 postSetNeedsCommitToMainThread(); |
| 472 } |
| 473 |
| 474 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) { |
| 475 endTest(); |
| 476 } |
| 477 |
| 478 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 479 EXPECT_TRUE(succeeded); |
| 480 } |
| 481 |
| 482 virtual void afterTest() { |
| 483 EXPECT_EQ(0, times_to_lose_on_end_query_); |
| 484 } |
| 485 |
| 486 private: |
| 487 FakeContentLayerClient client_; |
| 488 scoped_refptr<FakeContentLayer> parent_; |
| 489 int num_children_; |
| 490 int times_to_lose_on_end_query_; |
| 491 }; |
| 492 |
| 493 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 494 LayerTreeHostContextTestLostContextWhileUpdatingResources) |
| 495 |
| 496 class LayerTreeHostContextTestLayersNotified : |
| 497 public LayerTreeHostContextTest { |
| 498 public: |
| 499 LayerTreeHostContextTestLayersNotified() |
| 500 : LayerTreeHostContextTest(), |
| 501 num_commits_(0) { |
| 502 } |
| 503 |
| 504 virtual void setupTree() OVERRIDE { |
| 505 root_ = FakeContentLayer::Create(&client_); |
| 506 child_ = FakeContentLayer::Create(&client_); |
| 507 grandchild_ = FakeContentLayer::Create(&client_); |
| 508 |
| 509 root_->addChild(child_); |
| 510 child_->addChild(grandchild_); |
| 511 |
| 512 m_layerTreeHost->setRootLayer(root_); |
| 513 LayerTreeHostContextTest::setupTree(); |
| 514 } |
| 515 |
| 516 virtual void beginTest() OVERRIDE { |
| 517 postSetNeedsCommitToMainThread(); |
| 518 } |
| 519 |
| 520 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 521 FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>( |
| 522 host_impl->rootLayer()); |
| 523 FakeContentLayerImpl* child = static_cast<FakeContentLayerImpl*>( |
| 524 root->children()[0]); |
| 525 FakeContentLayerImpl* grandchild = static_cast<FakeContentLayerImpl*>( |
| 526 child->children()[0]); |
| 527 |
| 528 ++num_commits_; |
| 529 switch (num_commits_) { |
| 530 case 1: |
| 531 EXPECT_EQ(0u, root->lost_output_surface_count()); |
| 532 EXPECT_EQ(0u, child->lost_output_surface_count()); |
| 533 EXPECT_EQ(0u, grandchild->lost_output_surface_count()); |
| 534 // Lose the context and struggle to recreate it. |
| 535 LoseContext(); |
| 536 times_to_fail_create_ = 1; |
| 537 break; |
| 538 case 2: |
| 539 EXPECT_EQ(1u, root->lost_output_surface_count()); |
| 540 EXPECT_EQ(1u, child->lost_output_surface_count()); |
| 541 EXPECT_EQ(1u, grandchild->lost_output_surface_count()); |
| 542 // Lose the context and again during recreate. |
| 543 LoseContext(); |
| 544 times_to_create_and_lose_ = 1; |
| 545 break; |
| 546 case 3: |
| 547 EXPECT_EQ(3u, root->lost_output_surface_count()); |
| 548 EXPECT_EQ(3u, child->lost_output_surface_count()); |
| 549 EXPECT_EQ(3u, grandchild->lost_output_surface_count()); |
| 550 endTest(); |
| 551 break; |
| 552 default: |
| 553 NOTREACHED(); |
| 554 } |
| 555 } |
| 556 |
| 557 virtual void afterTest() OVERRIDE {} |
| 558 |
| 559 private: |
| 560 int num_commits_; |
| 561 |
| 562 FakeContentLayerClient client_; |
| 563 scoped_refptr<FakeContentLayer> root_; |
| 564 scoped_refptr<FakeContentLayer> child_; |
| 565 scoped_refptr<FakeContentLayer> grandchild_; |
| 566 }; |
| 567 |
| 568 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified) |
| 569 |
| 570 class LayerTreeHostContextTestDontUseLostResources : |
| 571 public LayerTreeHostContextTest { |
| 572 public: |
| 573 virtual void setupTree() OVERRIDE { |
| 574 context3d_->set_have_extension_io_surface(true); |
| 575 context3d_->set_have_extension_egl_image(true); |
| 576 |
| 577 scoped_refptr<Layer> root_ = Layer::create(); |
| 578 root_->setBounds(gfx::Size(10, 10)); |
| 579 root_->setAnchorPoint(gfx::PointF()); |
| 580 root_->setIsDrawable(true); |
| 581 |
| 582 scoped_refptr<DelegatedRendererLayer> delegated_ = |
| 583 DelegatedRendererLayer::create(); |
| 584 delegated_->setBounds(gfx::Size(10, 10)); |
| 585 delegated_->setAnchorPoint(gfx::PointF()); |
| 586 delegated_->setIsDrawable(true); |
| 587 root_->addChild(delegated_); |
| 588 |
| 589 scoped_refptr<ContentLayer> content_ = ContentLayer::create(&client_); |
| 590 content_->setBounds(gfx::Size(10, 10)); |
| 591 content_->setAnchorPoint(gfx::PointF()); |
| 592 content_->setIsDrawable(true); |
| 593 root_->addChild(content_); |
| 594 |
| 595 scoped_refptr<TextureLayer> texture_ = TextureLayer::create(NULL); |
| 596 texture_->setBounds(gfx::Size(10, 10)); |
| 597 texture_->setAnchorPoint(gfx::PointF()); |
| 598 texture_->setTextureId(FakeWebGraphicsContext3D::kExternalTextureId); |
| 599 texture_->setIsDrawable(true); |
| 600 root_->addChild(texture_); |
| 601 |
| 602 scoped_refptr<ContentLayer> mask_ = ContentLayer::create(&client_); |
| 603 mask_->setBounds(gfx::Size(10, 10)); |
| 604 mask_->setAnchorPoint(gfx::PointF()); |
| 605 |
| 606 scoped_refptr<ContentLayer> content_with_mask_ = |
| 607 ContentLayer::create(&client_); |
| 608 content_with_mask_->setBounds(gfx::Size(10, 10)); |
| 609 content_with_mask_->setAnchorPoint(gfx::PointF()); |
| 610 content_with_mask_->setIsDrawable(true); |
| 611 content_with_mask_->setMaskLayer(mask_.get()); |
| 612 root_->addChild(content_with_mask_); |
| 613 |
| 614 VideoLayerImpl::FrameUnwrapper unwrapper = |
| 615 base::Bind(FakeVideoFrame::ToVideoFrame); |
| 616 |
| 617 scoped_refptr<VideoLayer> video_color_ = VideoLayer::create( |
| 618 &color_frame_provider_, unwrapper); |
| 619 video_color_->setBounds(gfx::Size(10, 10)); |
| 620 video_color_->setAnchorPoint(gfx::PointF()); |
| 621 video_color_->setIsDrawable(true); |
| 622 root_->addChild(video_color_); |
| 623 |
| 624 scoped_refptr<VideoLayer> video_hw_ = VideoLayer::create( |
| 625 &hw_frame_provider_, unwrapper); |
| 626 video_hw_->setBounds(gfx::Size(10, 10)); |
| 627 video_hw_->setAnchorPoint(gfx::PointF()); |
| 628 video_hw_->setIsDrawable(true); |
| 629 root_->addChild(video_hw_); |
| 630 |
| 631 scoped_refptr<VideoLayer> video_scaled_hw_ = VideoLayer::create( |
| 632 &scaled_hw_frame_provider_, unwrapper); |
| 633 video_scaled_hw_->setBounds(gfx::Size(10, 10)); |
| 634 video_scaled_hw_->setAnchorPoint(gfx::PointF()); |
| 635 video_scaled_hw_->setIsDrawable(true); |
| 636 root_->addChild(video_scaled_hw_); |
| 637 |
| 638 scoped_refptr<IOSurfaceLayer> io_surface_ = IOSurfaceLayer::create(); |
| 639 io_surface_->setBounds(gfx::Size(10, 10)); |
| 640 io_surface_->setAnchorPoint(gfx::PointF()); |
| 641 io_surface_->setIsDrawable(true); |
| 642 io_surface_->setIOSurfaceProperties(1, gfx::Size(10, 10)); |
| 643 root_->addChild(io_surface_); |
| 644 |
| 645 scoped_refptr<HeadsUpDisplayLayer> hud_ = HeadsUpDisplayLayer::create(); |
| 646 hud_->setBounds(gfx::Size(10, 10)); |
| 647 hud_->setAnchorPoint(gfx::PointF()); |
| 648 hud_->setIsDrawable(true); |
| 649 root_->addChild(hud_); |
| 650 // Enable the hud. |
| 651 LayerTreeDebugState debug_state; |
| 652 debug_state.showFPSCounter = true; |
| 653 m_layerTreeHost->setDebugState(debug_state); |
| 654 |
| 655 bool paint_scrollbar = true; |
| 656 bool has_thumb = true; |
| 657 scoped_refptr<ScrollbarLayer> scrollbar_ = ScrollbarLayer::create( |
| 658 FakeWebScrollbar::create().PassAs<WebKit::WebScrollbar>(), |
| 659 FakeScrollbarThemePainter::Create(paint_scrollbar) |
| 660 .PassAs<ScrollbarThemePainter>(), |
| 661 FakeWebScrollbarThemeGeometry::create(has_thumb) |
| 662 .PassAs<WebKit::WebScrollbarThemeGeometry>(), |
| 663 content_->id()); |
| 664 scrollbar_->setBounds(gfx::Size(10, 10)); |
| 665 scrollbar_->setAnchorPoint(gfx::PointF()); |
| 666 scrollbar_->setIsDrawable(true); |
| 667 root_->addChild(scrollbar_); |
| 668 |
| 669 m_layerTreeHost->setRootLayer(root_); |
| 670 LayerTreeHostContextTest::setupTree(); |
| 671 } |
| 672 |
| 673 virtual void beginTest() OVERRIDE { |
| 674 postSetNeedsCommitToMainThread(); |
| 675 } |
| 676 |
| 677 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 678 ResourceProvider* resource_provider = host_impl->resourceProvider(); |
| 679 |
| 680 if (host_impl->activeTree()->source_frame_number() == 0) { |
| 681 // Set up impl resources on the first commit. |
| 682 |
| 683 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); |
| 684 pass_for_quad->SetNew( |
| 685 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. |
| 686 RenderPass::Id(1, 1), |
| 687 gfx::Rect(0, 0, 10, 10), |
| 688 gfx::Rect(0, 0, 10, 10), |
| 689 gfx::Transform()); |
| 690 |
| 691 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
| 692 pass->SetNew( |
| 693 RenderPass::Id(2, 1), |
| 694 gfx::Rect(0, 0, 10, 10), |
| 695 gfx::Rect(0, 0, 10, 10), |
| 696 gfx::Transform()); |
| 697 pass->AppendOneOfEveryQuadType(resource_provider); |
| 698 |
| 699 ScopedPtrVector<RenderPass> pass_list; |
| 700 pass_list.append(pass_for_quad.PassAs<RenderPass>()); |
| 701 pass_list.append(pass.PassAs<RenderPass>()); |
| 702 |
| 703 // First child is the delegated layer. |
| 704 DelegatedRendererLayerImpl* delegated_impl = |
| 705 static_cast<DelegatedRendererLayerImpl*>( |
| 706 host_impl->rootLayer()->children()[0]); |
| 707 delegated_impl->setRenderPasses(pass_list); |
| 708 EXPECT_TRUE(pass_list.isEmpty()); |
| 709 |
| 710 color_video_frame_ = make_scoped_ptr(new FakeVideoFrame( |
| 711 VideoFrame::CreateColorFrame( |
| 712 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()))); |
| 713 hw_video_frame_ = make_scoped_ptr(new FakeVideoFrame( |
| 714 VideoFrame::WrapNativeTexture( |
| 715 resource_provider->graphicsContext3D()->createTexture(), |
| 716 GL_TEXTURE_2D, |
| 717 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4), |
| 718 base::TimeDelta(), |
| 719 VideoFrame::ReadPixelsCB(), |
| 720 base::Closure()))); |
| 721 scaled_hw_video_frame_ = make_scoped_ptr(new FakeVideoFrame( |
| 722 VideoFrame::WrapNativeTexture( |
| 723 resource_provider->graphicsContext3D()->createTexture(), |
| 724 GL_TEXTURE_2D, |
| 725 gfx::Size(4, 4), gfx::Rect(0, 0, 3, 2), gfx::Size(4, 4), |
| 726 base::TimeDelta(), |
| 727 VideoFrame::ReadPixelsCB(), |
| 728 base::Closure()))); |
| 729 |
| 730 color_frame_provider_.set_frame(color_video_frame_.get()); |
| 731 hw_frame_provider_.set_frame(hw_video_frame_.get()); |
| 732 scaled_hw_frame_provider_.set_frame(scaled_hw_video_frame_.get()); |
| 733 return; |
| 734 } |
| 735 |
| 736 if (host_impl->activeTree()->source_frame_number() == 3) { |
| 737 // On the third commit we're recovering from context loss. Hardware |
| 738 // video frames should not be reused by the VideoFrameProvider, but |
| 739 // software frames can be. |
| 740 hw_frame_provider_.set_frame(NULL); |
| 741 scaled_hw_frame_provider_.set_frame(NULL); |
| 742 } |
| 743 } |
| 744 |
| 745 virtual bool prepareToDrawOnThread(LayerTreeHostImpl* host_impl) { |
| 746 if (host_impl->activeTree()->source_frame_number() == 2) { |
| 747 // Lose the context during draw on the second commit. This will cause |
| 748 // a third commit to recover. |
| 749 if (context3d_) |
| 750 context3d_->set_times_bind_texture_succeeds(4); |
| 751 } |
| 752 return true; |
| 753 } |
| 754 |
| 755 virtual void didCommitAndDrawFrame() OVERRIDE { |
| 756 // End the test once we know the 3nd frame drew. |
| 757 if (m_layerTreeHost->commitNumber() == 4) |
| 758 endTest(); |
| 759 } |
| 760 |
| 761 virtual void afterTest() OVERRIDE {} |
| 762 |
| 763 private: |
| 764 FakeContentLayerClient client_; |
| 765 |
| 766 scoped_refptr<Layer> root_; |
| 767 scoped_refptr<DelegatedRendererLayer> delegated_; |
| 768 scoped_refptr<ContentLayer> content_; |
| 769 scoped_refptr<TextureLayer> texture_; |
| 770 scoped_refptr<ContentLayer> mask_; |
| 771 scoped_refptr<ContentLayer> content_with_mask_; |
| 772 scoped_refptr<VideoLayer> video_color_; |
| 773 scoped_refptr<VideoLayer> video_hw_; |
| 774 scoped_refptr<VideoLayer> video_scaled_hw_; |
| 775 scoped_refptr<IOSurfaceLayer> io_surface_; |
| 776 scoped_refptr<HeadsUpDisplayLayer> hud_; |
| 777 scoped_refptr<ScrollbarLayer> scrollbar_; |
| 778 |
| 779 scoped_ptr<FakeVideoFrame> color_video_frame_; |
| 780 scoped_ptr<FakeVideoFrame> hw_video_frame_; |
| 781 scoped_ptr<FakeVideoFrame> scaled_hw_video_frame_; |
| 782 |
| 783 FakeVideoFrameProvider color_frame_provider_; |
| 784 FakeVideoFrameProvider hw_frame_provider_; |
| 785 FakeVideoFrameProvider scaled_hw_frame_provider_; |
| 786 }; |
| 787 |
| 788 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources) |
| 789 |
| 790 } // namespace |
| 791 } // namespace cc |
OLD | NEW |