| 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 bool use_surface) |
| 193 : LayerTreeHostContextTestLostContextSucceeds(), |
| 194 use_surface_(use_surface) { |
| 195 } |
| 196 |
| 197 virtual void setupTree() OVERRIDE { |
| 198 scoped_refptr<Layer> root_ = Layer::create(); |
| 199 root_->setBounds(gfx::Size(10, 10)); |
| 200 root_->setAnchorPoint(gfx::PointF()); |
| 201 root_->setIsDrawable(true); |
| 202 |
| 203 scoped_refptr<FakeContentLayer> content_ = |
| 204 FakeContentLayer::Create(&client_); |
| 205 content_->setBounds(gfx::Size(10, 10)); |
| 206 content_->setAnchorPoint(gfx::PointF()); |
| 207 content_->setIsDrawable(true); |
| 208 if (use_surface_) |
| 209 content_->setForceRenderSurface(true); |
| 210 root_->addChild(content_); |
| 211 |
| 212 m_layerTreeHost->setRootLayer(root_); |
| 213 LayerTreeHostContextTest::setupTree(); |
| 214 } |
| 215 |
| 216 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) { |
| 217 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( |
| 218 host_impl->rootLayer()->children()[0]); |
| 219 // Even though the context was lost, we should have a resource. The |
| 220 // FakeWebGraphicsContext3D ensures that this resource is created with |
| 221 // the active context. |
| 222 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
| 223 } |
| 224 |
| 225 protected: |
| 226 bool use_surface_; |
| 227 FakeContentLayerClient client_; |
| 228 scoped_refptr<Layer> root_; |
| 229 scoped_refptr<ContentLayer> content_; |
| 230 }; |
| 231 |
| 232 SINGLE_AND_MULTI_THREAD_TEST_P1( |
| 233 LayerTreeHostContextTestLostContextSucceedsWithContent, |
| 234 NoSurface, false) |
| 235 SINGLE_AND_MULTI_THREAD_TEST_P1( |
| 236 LayerTreeHostContextTestLostContextSucceedsWithContent, |
| 237 WithSurface, true) |
| 238 |
| 239 class LayerTreeHostContextTestLostContextFails : |
| 240 public LayerTreeHostContextTest { |
| 241 public: |
| 242 LayerTreeHostContextTestLostContextFails( |
| 243 int times_to_repeat_loss, |
| 244 int times_to_fail_recreate) |
| 245 : LayerTreeHostContextTest(), |
| 246 num_commits_(0) { |
| 247 times_to_lose_during_commit_ = 1; |
| 248 times_to_repeat_loss_ = times_to_repeat_loss; |
| 249 times_to_fail_recreate_ = times_to_fail_recreate; |
| 250 } |
| 251 |
| 252 virtual void beginTest() OVERRIDE { |
| 253 postSetNeedsCommitToMainThread(); |
| 254 } |
| 255 |
| 256 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 257 EXPECT_FALSE(succeeded); |
| 258 endTest(); |
| 259 } |
| 260 |
| 261 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 262 LayerTreeHostContextTest::commitCompleteOnThread(host_impl); |
| 263 |
| 264 ++num_commits_; |
| 265 if (num_commits_ == 1) { |
| 266 // When the context is ok, we should have these things. |
| 267 EXPECT_TRUE(host_impl->outputSurface()); |
| 268 EXPECT_TRUE(host_impl->renderer()); |
| 269 EXPECT_TRUE(host_impl->resourceProvider()); |
| 270 return; |
| 271 } |
| 272 |
| 273 // When context recreation fails we shouldn't be left with any of them. |
| 274 EXPECT_FALSE(host_impl->outputSurface()); |
| 275 EXPECT_FALSE(host_impl->renderer()); |
| 276 EXPECT_FALSE(host_impl->resourceProvider()); |
| 277 } |
| 278 |
| 279 virtual void afterTest() OVERRIDE {} |
| 280 |
| 281 private: |
| 282 int num_commits_; |
| 283 }; |
| 284 |
| 285 SINGLE_AND_MULTI_THREAD_TEST_P2(LayerTreeHostContextTestLostContextFails, |
| 286 RepeatLoss100, 100, , 0) |
| 287 SINGLE_AND_MULTI_THREAD_TEST_P2(LayerTreeHostContextTestLostContextFails, |
| 288 , 0, FailRecreate100, 100) |
| 289 |
| 290 class LayerTreeHostContextTestFinishAllRenderingAfterLoss : |
| 291 public LayerTreeHostContextTest { |
| 292 public: |
| 293 virtual void beginTest() OVERRIDE { |
| 294 // Lose the context until the compositor gives up on it. |
| 295 times_to_lose_during_commit_ = 1; |
| 296 times_to_repeat_loss_ = 10; |
| 297 postSetNeedsCommitToMainThread(); |
| 298 } |
| 299 |
| 300 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 301 EXPECT_FALSE(succeeded); |
| 302 m_layerTreeHost->finishAllRendering(); |
| 303 endTest(); |
| 304 } |
| 305 |
| 306 virtual void afterTest() OVERRIDE {} |
| 307 }; |
| 308 |
| 309 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 310 LayerTreeHostContextTestFinishAllRenderingAfterLoss) |
| 311 |
| 312 class LayerTreeHostContextTestLostContextAndEvictTextures : |
| 313 public LayerTreeHostContextTest { |
| 314 public: |
| 315 LayerTreeHostContextTestLostContextAndEvictTextures(bool after_evict) |
| 316 : LayerTreeHostContextTest(), |
| 317 layer_(FakeContentLayer::Create(&client_)), |
| 318 after_evict_(after_evict), |
| 319 impl_host_(0), |
| 320 num_commits_(0) { |
| 321 } |
| 322 |
| 323 virtual void setupTree() OVERRIDE { |
| 324 layer_->setBounds(gfx::Size(10, 20)); |
| 325 m_layerTreeHost->setRootLayer(layer_); |
| 326 LayerTreeHostContextTest::setupTree(); |
| 327 } |
| 328 |
| 329 virtual void beginTest() OVERRIDE { |
| 330 postSetNeedsCommitToMainThread(); |
| 331 } |
| 332 |
| 333 void PostEvictTextures() { |
| 334 if (implThread()) { |
| 335 implThread()->postTask( |
| 336 base::Bind( |
| 337 &LayerTreeHostContextTestLostContextAndEvictTextures:: |
| 338 EvictTexturesOnImplThread, |
| 339 base::Unretained(this))); |
| 340 } else { |
| 341 DebugScopedSetImplThread impl(proxy()); |
| 342 EvictTexturesOnImplThread(); |
| 343 } |
| 344 } |
| 345 |
| 346 void EvictTexturesOnImplThread() { |
| 347 impl_host_->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); |
| 348 if (after_evict_) |
| 349 LoseContext(); |
| 350 } |
| 351 |
| 352 virtual void didCommitAndDrawFrame() OVERRIDE { |
| 353 if (num_commits_ > 1) |
| 354 return; |
| 355 EXPECT_TRUE(layer_->HaveBackingAt(0, 0)); |
| 356 PostEvictTextures(); |
| 357 } |
| 358 |
| 359 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 360 if (num_commits_ > 1) |
| 361 return; |
| 362 ++num_commits_; |
| 363 if (!after_evict_) |
| 364 LoseContext(); |
| 365 impl_host_ = impl; |
| 366 } |
| 367 |
| 368 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 369 EXPECT_TRUE(succeeded); |
| 370 endTest(); |
| 371 } |
| 372 |
| 373 virtual void afterTest() OVERRIDE {} |
| 374 |
| 375 private: |
| 376 FakeContentLayerClient client_; |
| 377 scoped_refptr<FakeContentLayer> layer_; |
| 378 bool after_evict_; |
| 379 LayerTreeHostImpl* impl_host_; |
| 380 int num_commits_; |
| 381 }; |
| 382 |
| 383 SINGLE_AND_MULTI_THREAD_TEST_P1( |
| 384 LayerTreeHostContextTestLostContextAndEvictTextures, |
| 385 AfterEvict, true) |
| 386 SINGLE_AND_MULTI_THREAD_TEST_P1( |
| 387 LayerTreeHostContextTestLostContextAndEvictTextures, |
| 388 BeforeEvict, false) |
| 389 |
| 390 class LayerTreeHostContextTestLostContextWhileUpdatingResources : |
| 391 public LayerTreeHostContextTest { |
| 392 public: |
| 393 LayerTreeHostContextTestLostContextWhileUpdatingResources() |
| 394 : parent_(FakeContentLayer::Create(&client_)), |
| 395 num_children_(50), |
| 396 times_to_lose_on_end_query_(3) { |
| 397 } |
| 398 |
| 399 virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { |
| 400 scoped_ptr<FakeWebGraphicsContext3D> context = |
| 401 LayerTreeHostContextTest::CreateContext3d(); |
| 402 if (times_to_lose_on_end_query_) { |
| 403 --times_to_lose_on_end_query_; |
| 404 context->set_times_end_query_succeeds(5); |
| 405 } |
| 406 return context.Pass(); |
| 407 } |
| 408 |
| 409 virtual void setupTree() { |
| 410 parent_->setBounds(gfx::Size(num_children_, 1)); |
| 411 |
| 412 for (int i = 0; i < num_children_; i++) { |
| 413 scoped_refptr<FakeContentLayer> child = |
| 414 FakeContentLayer::Create(&client_); |
| 415 child->setPosition(gfx::PointF(i, 0.f)); |
| 416 child->setBounds(gfx::Size(1, 1)); |
| 417 parent_->addChild(child); |
| 418 } |
| 419 |
| 420 m_layerTreeHost->setRootLayer(parent_); |
| 421 LayerTreeHostContextTest::setupTree(); |
| 422 } |
| 423 |
| 424 virtual void beginTest() { |
| 425 postSetNeedsCommitToMainThread(); |
| 426 } |
| 427 |
| 428 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) { |
| 429 endTest(); |
| 430 } |
| 431 |
| 432 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE { |
| 433 EXPECT_TRUE(succeeded); |
| 434 } |
| 435 |
| 436 virtual void afterTest() { |
| 437 EXPECT_EQ(0, times_to_lose_on_end_query_); |
| 438 } |
| 439 |
| 440 private: |
| 441 FakeContentLayerClient client_; |
| 442 scoped_refptr<FakeContentLayer> parent_; |
| 443 int num_children_; |
| 444 int times_to_lose_on_end_query_; |
| 445 }; |
| 446 |
| 447 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 448 LayerTreeHostContextTestLostContextWhileUpdatingResources) |
| 449 |
| 450 class LayerTreeHostContextTestLayersNotified : |
| 451 public LayerTreeHostContextTest { |
| 452 public: |
| 453 LayerTreeHostContextTestLayersNotified() |
| 454 : LayerTreeHostContextTest(), |
| 455 num_commits_(0) { |
| 456 } |
| 457 |
| 458 virtual void setupTree() OVERRIDE { |
| 459 root_ = FakeContentLayer::Create(&client_); |
| 460 child_ = FakeContentLayer::Create(&client_); |
| 461 grandchild_ = FakeContentLayer::Create(&client_); |
| 462 |
| 463 root_->addChild(child_); |
| 464 child_->addChild(grandchild_); |
| 465 |
| 466 m_layerTreeHost->setRootLayer(root_); |
| 467 LayerTreeHostContextTest::setupTree(); |
| 468 } |
| 469 |
| 470 virtual void beginTest() OVERRIDE { |
| 471 postSetNeedsCommitToMainThread(); |
| 472 } |
| 473 |
| 474 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 475 FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>( |
| 476 host_impl->rootLayer()); |
| 477 FakeContentLayerImpl* child = static_cast<FakeContentLayerImpl*>( |
| 478 root->children()[0]); |
| 479 FakeContentLayerImpl* grandchild = static_cast<FakeContentLayerImpl*>( |
| 480 child->children()[0]); |
| 481 |
| 482 ++num_commits_; |
| 483 switch (num_commits_) { |
| 484 case 1: |
| 485 EXPECT_EQ(0u, root->lost_output_surface_count()); |
| 486 EXPECT_EQ(0u, child->lost_output_surface_count()); |
| 487 EXPECT_EQ(0u, grandchild->lost_output_surface_count()); |
| 488 // Lose the context and struggle to recreate it. |
| 489 LoseContext(); |
| 490 times_to_fail_create_ = 1; |
| 491 break; |
| 492 case 2: |
| 493 EXPECT_EQ(1u, root->lost_output_surface_count()); |
| 494 EXPECT_EQ(1u, child->lost_output_surface_count()); |
| 495 EXPECT_EQ(1u, grandchild->lost_output_surface_count()); |
| 496 // Lose the context and again during recreate. |
| 497 LoseContext(); |
| 498 times_to_create_and_lose_ = 1; |
| 499 break; |
| 500 case 3: |
| 501 EXPECT_EQ(3u, root->lost_output_surface_count()); |
| 502 EXPECT_EQ(3u, child->lost_output_surface_count()); |
| 503 EXPECT_EQ(3u, grandchild->lost_output_surface_count()); |
| 504 endTest(); |
| 505 break; |
| 506 default: |
| 507 NOTREACHED(); |
| 508 } |
| 509 } |
| 510 |
| 511 virtual void afterTest() OVERRIDE {} |
| 512 |
| 513 private: |
| 514 int num_commits_; |
| 515 |
| 516 FakeContentLayerClient client_; |
| 517 scoped_refptr<FakeContentLayer> root_; |
| 518 scoped_refptr<FakeContentLayer> child_; |
| 519 scoped_refptr<FakeContentLayer> grandchild_; |
| 520 }; |
| 521 |
| 522 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified) |
| 523 |
| 524 class LayerTreeHostContextTestDontUseLostResources : |
| 525 public LayerTreeHostContextTest { |
| 526 public: |
| 527 virtual void setupTree() OVERRIDE { |
| 528 context3d_->set_have_extension_io_surface(true); |
| 529 context3d_->set_have_extension_egl_image(true); |
| 530 |
| 531 scoped_refptr<Layer> root_ = Layer::create(); |
| 532 root_->setBounds(gfx::Size(10, 10)); |
| 533 root_->setAnchorPoint(gfx::PointF()); |
| 534 root_->setIsDrawable(true); |
| 535 |
| 536 scoped_refptr<DelegatedRendererLayer> delegated_ = |
| 537 DelegatedRendererLayer::create(); |
| 538 delegated_->setBounds(gfx::Size(10, 10)); |
| 539 delegated_->setAnchorPoint(gfx::PointF()); |
| 540 delegated_->setIsDrawable(true); |
| 541 root_->addChild(delegated_); |
| 542 |
| 543 scoped_refptr<ContentLayer> content_ = ContentLayer::create(&client_); |
| 544 content_->setBounds(gfx::Size(10, 10)); |
| 545 content_->setAnchorPoint(gfx::PointF()); |
| 546 content_->setIsDrawable(true); |
| 547 root_->addChild(content_); |
| 548 |
| 549 scoped_refptr<TextureLayer> texture_ = TextureLayer::create(NULL); |
| 550 texture_->setBounds(gfx::Size(10, 10)); |
| 551 texture_->setAnchorPoint(gfx::PointF()); |
| 552 texture_->setTextureId(FakeWebGraphicsContext3D::kExternalTextureId); |
| 553 texture_->setIsDrawable(true); |
| 554 root_->addChild(texture_); |
| 555 |
| 556 scoped_refptr<ContentLayer> mask_ = ContentLayer::create(&client_); |
| 557 mask_->setBounds(gfx::Size(10, 10)); |
| 558 mask_->setAnchorPoint(gfx::PointF()); |
| 559 |
| 560 scoped_refptr<ContentLayer> content_with_mask_ = |
| 561 ContentLayer::create(&client_); |
| 562 content_with_mask_->setBounds(gfx::Size(10, 10)); |
| 563 content_with_mask_->setAnchorPoint(gfx::PointF()); |
| 564 content_with_mask_->setIsDrawable(true); |
| 565 content_with_mask_->setMaskLayer(mask_.get()); |
| 566 root_->addChild(content_with_mask_); |
| 567 |
| 568 VideoLayerImpl::FrameUnwrapper unwrapper = |
| 569 base::Bind(FakeVideoFrame::ToVideoFrame); |
| 570 |
| 571 scoped_refptr<VideoLayer> video_color_ = VideoLayer::create( |
| 572 &color_frame_provider_, unwrapper); |
| 573 video_color_->setBounds(gfx::Size(10, 10)); |
| 574 video_color_->setAnchorPoint(gfx::PointF()); |
| 575 video_color_->setIsDrawable(true); |
| 576 root_->addChild(video_color_); |
| 577 |
| 578 scoped_refptr<VideoLayer> video_hw_ = VideoLayer::create( |
| 579 &hw_frame_provider_, unwrapper); |
| 580 video_hw_->setBounds(gfx::Size(10, 10)); |
| 581 video_hw_->setAnchorPoint(gfx::PointF()); |
| 582 video_hw_->setIsDrawable(true); |
| 583 root_->addChild(video_hw_); |
| 584 |
| 585 scoped_refptr<VideoLayer> video_scaled_hw_ = VideoLayer::create( |
| 586 &scaled_hw_frame_provider_, unwrapper); |
| 587 video_scaled_hw_->setBounds(gfx::Size(10, 10)); |
| 588 video_scaled_hw_->setAnchorPoint(gfx::PointF()); |
| 589 video_scaled_hw_->setIsDrawable(true); |
| 590 root_->addChild(video_scaled_hw_); |
| 591 |
| 592 scoped_refptr<IOSurfaceLayer> io_surface_ = IOSurfaceLayer::create(); |
| 593 io_surface_->setBounds(gfx::Size(10, 10)); |
| 594 io_surface_->setAnchorPoint(gfx::PointF()); |
| 595 io_surface_->setIsDrawable(true); |
| 596 io_surface_->setIOSurfaceProperties(1, gfx::Size(10, 10)); |
| 597 root_->addChild(io_surface_); |
| 598 |
| 599 scoped_refptr<HeadsUpDisplayLayer> hud_ = HeadsUpDisplayLayer::create(); |
| 600 hud_->setBounds(gfx::Size(10, 10)); |
| 601 hud_->setAnchorPoint(gfx::PointF()); |
| 602 hud_->setIsDrawable(true); |
| 603 root_->addChild(hud_); |
| 604 // Enable the hud. |
| 605 LayerTreeDebugState debug_state; |
| 606 debug_state.showFPSCounter = true; |
| 607 m_layerTreeHost->setDebugState(debug_state); |
| 608 |
| 609 bool paint_scrollbar = true; |
| 610 bool has_thumb = true; |
| 611 scoped_refptr<ScrollbarLayer> scrollbar_ = ScrollbarLayer::create( |
| 612 FakeWebScrollbar::create().PassAs<WebKit::WebScrollbar>(), |
| 613 FakeScrollbarThemePainter::Create(paint_scrollbar) |
| 614 .PassAs<ScrollbarThemePainter>(), |
| 615 FakeWebScrollbarThemeGeometry::create(has_thumb) |
| 616 .PassAs<WebKit::WebScrollbarThemeGeometry>(), |
| 617 content_->id()); |
| 618 scrollbar_->setBounds(gfx::Size(10, 10)); |
| 619 scrollbar_->setAnchorPoint(gfx::PointF()); |
| 620 scrollbar_->setIsDrawable(true); |
| 621 root_->addChild(scrollbar_); |
| 622 |
| 623 m_layerTreeHost->setRootLayer(root_); |
| 624 LayerTreeHostContextTest::setupTree(); |
| 625 } |
| 626 |
| 627 virtual void beginTest() OVERRIDE { |
| 628 postSetNeedsCommitToMainThread(); |
| 629 } |
| 630 |
| 631 virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 632 ResourceProvider* resource_provider = host_impl->resourceProvider(); |
| 633 |
| 634 if (host_impl->activeTree()->source_frame_number() == 0) { |
| 635 // Set up impl resources on the first commit. |
| 636 |
| 637 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); |
| 638 pass_for_quad->SetNew( |
| 639 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. |
| 640 RenderPass::Id(1, 1), |
| 641 gfx::Rect(0, 0, 10, 10), |
| 642 gfx::Rect(0, 0, 10, 10), |
| 643 gfx::Transform()); |
| 644 |
| 645 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
| 646 pass->SetNew( |
| 647 RenderPass::Id(2, 1), |
| 648 gfx::Rect(0, 0, 10, 10), |
| 649 gfx::Rect(0, 0, 10, 10), |
| 650 gfx::Transform()); |
| 651 pass->AppendOneOfEveryQuadType(resource_provider); |
| 652 |
| 653 ScopedPtrVector<RenderPass> pass_list; |
| 654 pass_list.append(pass_for_quad.PassAs<RenderPass>()); |
| 655 pass_list.append(pass.PassAs<RenderPass>()); |
| 656 |
| 657 // First child is the delegated layer. |
| 658 DelegatedRendererLayerImpl* delegated_impl = |
| 659 static_cast<DelegatedRendererLayerImpl*>( |
| 660 host_impl->rootLayer()->children()[0]); |
| 661 delegated_impl->setRenderPasses(pass_list); |
| 662 EXPECT_TRUE(pass_list.isEmpty()); |
| 663 |
| 664 color_video_frame_ = make_scoped_ptr(new FakeVideoFrame( |
| 665 VideoFrame::CreateColorFrame( |
| 666 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()))); |
| 667 hw_video_frame_ = make_scoped_ptr(new FakeVideoFrame( |
| 668 VideoFrame::WrapNativeTexture( |
| 669 resource_provider->graphicsContext3D()->createTexture(), |
| 670 GL_TEXTURE_2D, |
| 671 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4), |
| 672 base::TimeDelta(), |
| 673 VideoFrame::ReadPixelsCB(), |
| 674 base::Closure()))); |
| 675 scaled_hw_video_frame_ = make_scoped_ptr(new FakeVideoFrame( |
| 676 VideoFrame::WrapNativeTexture( |
| 677 resource_provider->graphicsContext3D()->createTexture(), |
| 678 GL_TEXTURE_2D, |
| 679 gfx::Size(4, 4), gfx::Rect(0, 0, 3, 2), gfx::Size(4, 4), |
| 680 base::TimeDelta(), |
| 681 VideoFrame::ReadPixelsCB(), |
| 682 base::Closure()))); |
| 683 |
| 684 color_frame_provider_.set_frame(color_video_frame_.get()); |
| 685 hw_frame_provider_.set_frame(hw_video_frame_.get()); |
| 686 scaled_hw_frame_provider_.set_frame(scaled_hw_video_frame_.get()); |
| 687 return; |
| 688 } |
| 689 |
| 690 if (host_impl->activeTree()->source_frame_number() == 3) { |
| 691 // On the third commit we're recovering from context loss. Hardware |
| 692 // video frames should not be reused by the VideoFrameProvider, but |
| 693 // software frames can be. |
| 694 hw_frame_provider_.set_frame(NULL); |
| 695 scaled_hw_frame_provider_.set_frame(NULL); |
| 696 } |
| 697 } |
| 698 |
| 699 virtual bool prepareToDrawOnThread(LayerTreeHostImpl* host_impl) { |
| 700 if (host_impl->activeTree()->source_frame_number() == 2) { |
| 701 // Lose the context during draw on the second commit. This will cause |
| 702 // a third commit to recover. |
| 703 if (context3d_) |
| 704 context3d_->set_times_bind_texture_succeeds(4); |
| 705 } |
| 706 return true; |
| 707 } |
| 708 |
| 709 virtual void didCommitAndDrawFrame() OVERRIDE { |
| 710 // End the test once we know the 3nd frame drew. |
| 711 if (m_layerTreeHost->commitNumber() == 4) |
| 712 endTest(); |
| 713 } |
| 714 |
| 715 virtual void afterTest() OVERRIDE {} |
| 716 |
| 717 private: |
| 718 FakeContentLayerClient client_; |
| 719 |
| 720 scoped_refptr<Layer> root_; |
| 721 scoped_refptr<DelegatedRendererLayer> delegated_; |
| 722 scoped_refptr<ContentLayer> content_; |
| 723 scoped_refptr<TextureLayer> texture_; |
| 724 scoped_refptr<ContentLayer> mask_; |
| 725 scoped_refptr<ContentLayer> content_with_mask_; |
| 726 scoped_refptr<VideoLayer> video_color_; |
| 727 scoped_refptr<VideoLayer> video_hw_; |
| 728 scoped_refptr<VideoLayer> video_scaled_hw_; |
| 729 scoped_refptr<IOSurfaceLayer> io_surface_; |
| 730 scoped_refptr<HeadsUpDisplayLayer> hud_; |
| 731 scoped_refptr<ScrollbarLayer> scrollbar_; |
| 732 |
| 733 scoped_ptr<FakeVideoFrame> color_video_frame_; |
| 734 scoped_ptr<FakeVideoFrame> hw_video_frame_; |
| 735 scoped_ptr<FakeVideoFrame> scaled_hw_video_frame_; |
| 736 |
| 737 FakeVideoFrameProvider color_frame_provider_; |
| 738 FakeVideoFrameProvider hw_frame_provider_; |
| 739 FakeVideoFrameProvider scaled_hw_frame_provider_; |
| 740 }; |
| 741 |
| 742 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources) |
| 743 |
| 744 } // namespace |
| 745 } // namespace cc |
| OLD | NEW |