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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 FakeTextureLayerClient() : context_(TestWebGraphicsContext3D::Create()) {} | 243 FakeTextureLayerClient() : context_(TestWebGraphicsContext3D::Create()) {} |
244 | 244 |
245 virtual unsigned PrepareTexture() OVERRIDE { | 245 virtual unsigned PrepareTexture() OVERRIDE { |
246 return 0; | 246 return 0; |
247 } | 247 } |
248 | 248 |
249 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 249 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
250 return context_.get(); | 250 return context_.get(); |
251 } | 251 } |
252 | 252 |
253 virtual bool PrepareTextureMailbox(TextureMailbox* mailbox, | 253 virtual bool PrepareTextureMailbox( |
254 bool use_shared_memory) OVERRIDE { | 254 TextureMailbox* mailbox, |
| 255 scoped_ptr<ScopedReleaseCallback>* release_callback, |
| 256 bool use_shared_memory) OVERRIDE { |
255 *mailbox = TextureMailbox(); | 257 *mailbox = TextureMailbox(); |
| 258 *release_callback = scoped_ptr<ScopedReleaseCallback>(); |
256 return true; | 259 return true; |
257 } | 260 } |
258 | 261 |
259 private: | 262 private: |
260 scoped_ptr<TestWebGraphicsContext3D> context_; | 263 scoped_ptr<TestWebGraphicsContext3D> context_; |
261 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | 264 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
262 }; | 265 }; |
263 | 266 |
264 TEST_F(TextureLayerTest, RateLimiter) { | 267 TEST_F(TextureLayerTest, RateLimiter) { |
265 FakeTextureLayerClient client; | 268 FakeTextureLayerClient client; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 sync_point2_(2), | 331 sync_point2_(2), |
329 shared_memory_(new base::SharedMemory) { | 332 shared_memory_(new base::SharedMemory) { |
330 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | 333 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
331 base::Unretained(&mock_callback_), | 334 base::Unretained(&mock_callback_), |
332 mailbox_name1_); | 335 mailbox_name1_); |
333 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | 336 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
334 base::Unretained(&mock_callback_), | 337 base::Unretained(&mock_callback_), |
335 mailbox_name2_); | 338 mailbox_name2_); |
336 gpu::Mailbox m1; | 339 gpu::Mailbox m1; |
337 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); | 340 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); |
338 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_); | 341 mailbox1_ = TextureMailbox(m1, sync_point1_); |
339 gpu::Mailbox m2; | 342 gpu::Mailbox m2; |
340 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); | 343 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); |
341 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_); | 344 mailbox2_ = TextureMailbox(m2, sync_point2_); |
342 | 345 |
343 gfx::Size size(128, 128); | 346 gfx::Size size(128, 128); |
344 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | 347 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); |
345 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | 348 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, |
346 base::Unretained(&mock_callback_), | 349 base::Unretained(&mock_callback_), |
347 shared_memory_.get()); | 350 shared_memory_.get()); |
348 mailbox3_ = TextureMailbox(shared_memory_.get(), size, release_mailbox3_); | 351 mailbox3_ = TextureMailbox(shared_memory_.get(), size); |
349 } | 352 } |
350 | 353 |
351 std::string mailbox_name1_; | 354 std::string mailbox_name1_; |
352 std::string mailbox_name2_; | 355 std::string mailbox_name2_; |
353 MockMailboxCallback mock_callback_; | 356 MockMailboxCallback mock_callback_; |
354 TextureMailbox::ReleaseCallback release_mailbox1_; | 357 ReleaseCallback release_mailbox1_; |
355 TextureMailbox::ReleaseCallback release_mailbox2_; | 358 ReleaseCallback release_mailbox2_; |
356 TextureMailbox::ReleaseCallback release_mailbox3_; | 359 ReleaseCallback release_mailbox3_; |
357 TextureMailbox mailbox1_; | 360 TextureMailbox mailbox1_; |
358 TextureMailbox mailbox2_; | 361 TextureMailbox mailbox2_; |
359 TextureMailbox mailbox3_; | 362 TextureMailbox mailbox3_; |
360 unsigned sync_point1_; | 363 unsigned sync_point1_; |
361 unsigned sync_point2_; | 364 unsigned sync_point2_; |
362 scoped_ptr<base::SharedMemory> shared_memory_; | 365 scoped_ptr<base::SharedMemory> shared_memory_; |
363 }; | 366 }; |
364 | 367 |
365 class TestMailboxHolder : public TextureLayer::MailboxHolder { | 368 class TestMailboxHolder : public TextureLayer::MailboxHolder { |
366 public: | 369 public: |
(...skipping 21 matching lines...) Expand all Loading... |
388 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 391 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
389 ASSERT_TRUE(test_layer.get()); | 392 ASSERT_TRUE(test_layer.get()); |
390 | 393 |
391 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 394 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
392 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 395 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
393 layer_tree_host_->SetRootLayer(test_layer); | 396 layer_tree_host_->SetRootLayer(test_layer); |
394 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 397 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
395 | 398 |
396 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 399 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
397 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 400 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
398 test_layer->SetTextureMailbox(test_data_.mailbox1_); | 401 test_layer->SetTextureMailbox( |
| 402 test_data_.mailbox1_, |
| 403 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
399 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 404 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
400 | 405 |
401 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 406 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
402 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 407 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
403 EXPECT_CALL(test_data_.mock_callback_, | 408 EXPECT_CALL(test_data_.mock_callback_, |
404 Release(test_data_.mailbox_name1_, | 409 Release(test_data_.mailbox_name1_, |
405 test_data_.sync_point1_, | 410 test_data_.sync_point1_, |
406 false)) | 411 false)) |
407 .Times(1); | 412 .Times(1); |
408 test_layer->SetTextureMailbox(test_data_.mailbox2_); | 413 test_layer->SetTextureMailbox( |
| 414 test_data_.mailbox2_, |
| 415 ScopedReleaseCallback::Create(test_data_.release_mailbox2_)); |
409 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 416 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
410 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 417 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
411 | 418 |
412 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 419 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
413 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 420 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
414 EXPECT_CALL(test_data_.mock_callback_, | 421 EXPECT_CALL(test_data_.mock_callback_, |
415 Release(test_data_.mailbox_name2_, | 422 Release(test_data_.mailbox_name2_, |
416 test_data_.sync_point2_, | 423 test_data_.sync_point2_, |
417 false)) | 424 false)) |
418 .Times(1); | 425 .Times(1); |
419 test_layer->SetTextureMailbox(TextureMailbox()); | 426 test_layer->SetTextureMailbox(TextureMailbox(), |
| 427 scoped_ptr<ScopedReleaseCallback>()); |
420 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 428 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
421 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 429 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
422 | 430 |
423 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 431 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
424 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 432 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
425 test_layer->SetTextureMailbox(test_data_.mailbox3_); | 433 test_layer->SetTextureMailbox( |
| 434 test_data_.mailbox3_, |
| 435 ScopedReleaseCallback::Create(test_data_.release_mailbox3_)); |
426 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 436 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
427 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 437 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
428 | 438 |
429 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 439 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
430 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 440 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
431 EXPECT_CALL(test_data_.mock_callback_, | 441 EXPECT_CALL(test_data_.mock_callback_, |
432 Release2(test_data_.shared_memory_.get(), | 442 Release2(test_data_.shared_memory_.get(), |
433 0, false)) | 443 0, false)) |
434 .Times(1); | 444 .Times(1); |
435 test_layer->SetTextureMailbox(TextureMailbox()); | 445 test_layer->SetTextureMailbox(TextureMailbox(), |
| 446 scoped_ptr<ScopedReleaseCallback>()); |
436 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 447 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
437 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 448 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
438 | 449 |
439 // Test destructor. | 450 // Test destructor. |
440 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 451 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
441 test_layer->SetTextureMailbox(test_data_.mailbox1_); | 452 test_layer->SetTextureMailbox( |
| 453 test_data_.mailbox1_, |
| 454 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
442 } | 455 } |
443 | 456 |
444 class TextureLayerMailboxHolderTest : public TextureLayerTest { | 457 class TextureLayerMailboxHolderTest : public TextureLayerTest { |
445 public: | 458 public: |
446 TextureLayerMailboxHolderTest() | 459 TextureLayerMailboxHolderTest() |
447 : main_thread_("MAIN") { | 460 : main_thread_("MAIN") { |
448 main_thread_.Start(); | 461 main_thread_.Start(); |
449 } | 462 } |
450 | 463 |
451 void Wait(const base::Thread& thread) { | 464 void Wait(const base::Thread& thread) { |
452 bool manual_reset = false; | 465 bool manual_reset = false; |
453 bool initially_signaled = false; | 466 bool initially_signaled = false; |
454 base::WaitableEvent event(manual_reset, initially_signaled); | 467 base::WaitableEvent event(manual_reset, initially_signaled); |
455 thread.message_loop()->PostTask( | 468 thread.message_loop()->PostTask( |
456 FROM_HERE, | 469 FROM_HERE, |
457 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 470 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
458 event.Wait(); | 471 event.Wait(); |
459 } | 472 } |
460 | 473 |
461 void CreateMainRef() { | 474 void CreateMainRef() { |
462 main_ref_ = TestMailboxHolder::Create( | 475 main_ref_ = TestMailboxHolder::Create( |
463 test_data_.mailbox1_).Pass(); | 476 test_data_.mailbox1_, |
| 477 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)).Pass(); |
464 } | 478 } |
465 | 479 |
466 void ReleaseMainRef() { | 480 void ReleaseMainRef() { |
467 main_ref_.reset(); | 481 main_ref_.reset(); |
468 } | 482 } |
469 | 483 |
470 void CreateImplRef(TextureMailbox::ReleaseCallback* impl_ref) { | 484 void CreateImplRef(scoped_ptr<ScopedReleaseCallback>* impl_ref) { |
471 *impl_ref = main_ref_->holder()->GetCallbackForImplThread(); | 485 *impl_ref = main_ref_->holder()->GetCallbackForImplThread(); |
472 } | 486 } |
473 | 487 |
474 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture, | 488 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture, |
475 base::WaitableEvent* wait_for_capture, | 489 base::WaitableEvent* wait_for_capture, |
476 base::WaitableEvent* stop_capture) { | 490 base::WaitableEvent* stop_capture) { |
477 begin_capture->Wait(); | 491 begin_capture->Wait(); |
478 BlockingTaskRunner::CapturePostTasks capture; | 492 BlockingTaskRunner::CapturePostTasks capture; |
479 wait_for_capture->Signal(); | 493 wait_for_capture->Signal(); |
480 stop_capture->Wait(); | 494 stop_capture->Wait(); |
(...skipping 12 matching lines...) Expand all Loading... |
493 | 507 |
494 main_thread_.message_loop()->PostTask( | 508 main_thread_.message_loop()->PostTask( |
495 FROM_HERE, | 509 FROM_HERE, |
496 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 510 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
497 base::Unretained(this))); | 511 base::Unretained(this))); |
498 | 512 |
499 Wait(main_thread_); | 513 Wait(main_thread_); |
500 | 514 |
501 // The texture layer is attached to compositor1, and passes a reference to its | 515 // The texture layer is attached to compositor1, and passes a reference to its |
502 // impl tree. | 516 // impl tree. |
503 TextureMailbox::ReleaseCallback compositor1; | 517 scoped_ptr<ScopedReleaseCallback> compositor1; |
504 main_thread_.message_loop()->PostTask( | 518 main_thread_.message_loop()->PostTask( |
505 FROM_HERE, | 519 FROM_HERE, |
506 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 520 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
507 base::Unretained(this), | 521 base::Unretained(this), |
508 &compositor1)); | 522 &compositor1)); |
509 | 523 |
510 // Then the texture layer is removed and attached to compositor2, and passes a | 524 // Then the texture layer is removed and attached to compositor2, and passes a |
511 // reference to its impl tree. | 525 // reference to its impl tree. |
512 TextureMailbox::ReleaseCallback compositor2; | 526 scoped_ptr<ScopedReleaseCallback> compositor2; |
513 main_thread_.message_loop()->PostTask( | 527 main_thread_.message_loop()->PostTask( |
514 FROM_HERE, | 528 FROM_HERE, |
515 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 529 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
516 base::Unretained(this), | 530 base::Unretained(this), |
517 &compositor2)); | 531 &compositor2)); |
518 | 532 |
519 Wait(main_thread_); | 533 Wait(main_thread_); |
520 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 534 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
521 | 535 |
522 // The compositors both destroy their impl trees before the main thread layer | 536 // The compositors both destroy their impl trees before the main thread layer |
523 // is destroyed. | 537 // is destroyed. |
524 compositor1.Run(100, false); | 538 compositor1->Run(100, false); |
525 compositor2.Run(200, false); | 539 compositor2->Run(200, false); |
526 | 540 |
527 Wait(main_thread_); | 541 Wait(main_thread_); |
528 | 542 |
529 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 543 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
530 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 544 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
531 | 545 |
532 // The main thread ref is the last one, so the mailbox is released back to the | 546 // The main thread ref is the last one, so the mailbox is released back to the |
533 // embedder, with the last sync point provided by the impl trees. | 547 // embedder, with the last sync point provided by the impl trees. |
534 EXPECT_CALL(test_data_.mock_callback_, | 548 EXPECT_CALL(test_data_.mock_callback_, |
535 Release(test_data_.mailbox_name1_, 200, false)).Times(1); | 549 Release(test_data_.mailbox_name1_, 200, false)).Times(1); |
(...skipping 12 matching lines...) Expand all Loading... |
548 | 562 |
549 main_thread_.message_loop()->PostTask( | 563 main_thread_.message_loop()->PostTask( |
550 FROM_HERE, | 564 FROM_HERE, |
551 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 565 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
552 base::Unretained(this))); | 566 base::Unretained(this))); |
553 | 567 |
554 Wait(main_thread_); | 568 Wait(main_thread_); |
555 | 569 |
556 // The texture layer is attached to compositor1, and passes a reference to its | 570 // The texture layer is attached to compositor1, and passes a reference to its |
557 // impl tree. | 571 // impl tree. |
558 TextureMailbox::ReleaseCallback compositor1; | 572 scoped_ptr<ScopedReleaseCallback> compositor1; |
559 main_thread_.message_loop()->PostTask( | 573 main_thread_.message_loop()->PostTask( |
560 FROM_HERE, | 574 FROM_HERE, |
561 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 575 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
562 base::Unretained(this), | 576 base::Unretained(this), |
563 &compositor1)); | 577 &compositor1)); |
564 | 578 |
565 // Then the texture layer is removed and attached to compositor2, and passes a | 579 // Then the texture layer is removed and attached to compositor2, and passes a |
566 // reference to its impl tree. | 580 // reference to its impl tree. |
567 TextureMailbox::ReleaseCallback compositor2; | 581 scoped_ptr<ScopedReleaseCallback> compositor2; |
568 main_thread_.message_loop()->PostTask( | 582 main_thread_.message_loop()->PostTask( |
569 FROM_HERE, | 583 FROM_HERE, |
570 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 584 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
571 base::Unretained(this), | 585 base::Unretained(this), |
572 &compositor2)); | 586 &compositor2)); |
573 | 587 |
574 Wait(main_thread_); | 588 Wait(main_thread_); |
575 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 589 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
576 | 590 |
577 // One compositor destroys their impl tree. | 591 // One compositor destroys their impl tree. |
578 compositor1.Run(100, false); | 592 compositor1->Run(100, false); |
579 | 593 |
580 // Then the main thread reference is destroyed. | 594 // Then the main thread reference is destroyed. |
581 main_thread_.message_loop()->PostTask( | 595 main_thread_.message_loop()->PostTask( |
582 FROM_HERE, | 596 FROM_HERE, |
583 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, | 597 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
584 base::Unretained(this))); | 598 base::Unretained(this))); |
585 | 599 |
586 Wait(main_thread_); | 600 Wait(main_thread_); |
587 | 601 |
588 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 602 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
589 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 603 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
590 | 604 |
591 // The second impl reference is destroyed last, causing the mailbox to be | 605 // The second impl reference is destroyed last, causing the mailbox to be |
592 // released back to the embedder with the last sync point from the impl tree. | 606 // released back to the embedder with the last sync point from the impl tree. |
593 EXPECT_CALL(test_data_.mock_callback_, | 607 EXPECT_CALL(test_data_.mock_callback_, |
594 Release(test_data_.mailbox_name1_, 200, true)).Times(1); | 608 Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
595 | 609 |
596 compositor2.Run(200, true); | 610 compositor2->Run(200, true); |
597 Wait(main_thread_); | 611 Wait(main_thread_); |
598 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 612 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
599 } | 613 } |
600 | 614 |
601 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { | 615 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { |
602 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 616 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
603 ASSERT_TRUE(test_layer.get()); | 617 ASSERT_TRUE(test_layer.get()); |
604 | 618 |
605 main_thread_.message_loop()->PostTask( | 619 main_thread_.message_loop()->PostTask( |
606 FROM_HERE, | 620 FROM_HERE, |
607 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 621 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
608 base::Unretained(this))); | 622 base::Unretained(this))); |
609 | 623 |
610 Wait(main_thread_); | 624 Wait(main_thread_); |
611 | 625 |
612 // The texture layer is attached to compositor1, and passes a reference to its | 626 // The texture layer is attached to compositor1, and passes a reference to its |
613 // impl tree. | 627 // impl tree. |
614 TextureMailbox::ReleaseCallback compositor1; | 628 scoped_ptr<ScopedReleaseCallback> compositor1; |
615 main_thread_.message_loop()->PostTask( | 629 main_thread_.message_loop()->PostTask( |
616 FROM_HERE, | 630 FROM_HERE, |
617 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 631 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
618 base::Unretained(this), | 632 base::Unretained(this), |
619 &compositor1)); | 633 &compositor1)); |
620 | 634 |
621 // Then the texture layer is removed and attached to compositor2, and passes a | 635 // Then the texture layer is removed and attached to compositor2, and passes a |
622 // reference to its impl tree. | 636 // reference to its impl tree. |
623 TextureMailbox::ReleaseCallback compositor2; | 637 scoped_ptr<ScopedReleaseCallback> compositor2; |
624 main_thread_.message_loop()->PostTask( | 638 main_thread_.message_loop()->PostTask( |
625 FROM_HERE, | 639 FROM_HERE, |
626 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 640 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
627 base::Unretained(this), | 641 base::Unretained(this), |
628 &compositor2)); | 642 &compositor2)); |
629 | 643 |
630 Wait(main_thread_); | 644 Wait(main_thread_); |
631 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 645 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
632 | 646 |
633 // The main thread reference is destroyed first. | 647 // The main thread reference is destroyed first. |
634 main_thread_.message_loop()->PostTask( | 648 main_thread_.message_loop()->PostTask( |
635 FROM_HERE, | 649 FROM_HERE, |
636 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, | 650 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
637 base::Unretained(this))); | 651 base::Unretained(this))); |
638 | 652 |
639 // One compositor destroys their impl tree. | 653 // One compositor destroys their impl tree. |
640 compositor2.Run(200, false); | 654 compositor2->Run(200, false); |
641 | 655 |
642 Wait(main_thread_); | 656 Wait(main_thread_); |
643 | 657 |
644 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 658 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
645 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 659 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
646 | 660 |
647 // The second impl reference is destroyed last, causing the mailbox to be | 661 // The second impl reference is destroyed last, causing the mailbox to be |
648 // released back to the embedder with the last sync point from the impl tree. | 662 // released back to the embedder with the last sync point from the impl tree. |
649 EXPECT_CALL(test_data_.mock_callback_, | 663 EXPECT_CALL(test_data_.mock_callback_, |
650 Release(test_data_.mailbox_name1_, 100, true)).Times(1); | 664 Release(test_data_.mailbox_name1_, 100, true)).Times(1); |
651 | 665 |
652 compositor1.Run(100, true); | 666 compositor1->Run(100, true); |
653 Wait(main_thread_); | 667 Wait(main_thread_); |
654 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 668 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
655 } | 669 } |
656 | 670 |
657 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { | 671 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { |
658 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 672 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
659 ASSERT_TRUE(test_layer.get()); | 673 ASSERT_TRUE(test_layer.get()); |
660 | 674 |
661 main_thread_.message_loop()->PostTask( | 675 main_thread_.message_loop()->PostTask( |
662 FROM_HERE, | 676 FROM_HERE, |
663 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 677 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
664 base::Unretained(this))); | 678 base::Unretained(this))); |
665 | 679 |
666 Wait(main_thread_); | 680 Wait(main_thread_); |
667 | 681 |
668 // The texture layer is attached to compositor1, and passes a reference to its | 682 // The texture layer is attached to compositor1, and passes a reference to its |
669 // impl tree. | 683 // impl tree. |
670 TextureMailbox::ReleaseCallback compositor1; | 684 scoped_ptr<ScopedReleaseCallback> compositor1; |
671 main_thread_.message_loop()->PostTask( | 685 main_thread_.message_loop()->PostTask( |
672 FROM_HERE, | 686 FROM_HERE, |
673 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 687 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
674 base::Unretained(this), | 688 base::Unretained(this), |
675 &compositor1)); | 689 &compositor1)); |
676 | 690 |
677 // Then the texture layer is removed and attached to compositor2, and passes a | 691 // Then the texture layer is removed and attached to compositor2, and passes a |
678 // reference to its impl tree. | 692 // reference to its impl tree. |
679 TextureMailbox::ReleaseCallback compositor2; | 693 scoped_ptr<ScopedReleaseCallback> compositor2; |
680 main_thread_.message_loop()->PostTask( | 694 main_thread_.message_loop()->PostTask( |
681 FROM_HERE, | 695 FROM_HERE, |
682 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 696 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
683 base::Unretained(this), | 697 base::Unretained(this), |
684 &compositor2)); | 698 &compositor2)); |
685 | 699 |
686 Wait(main_thread_); | 700 Wait(main_thread_); |
687 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 701 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
688 | 702 |
689 // The main thread reference is destroyed first. | 703 // The main thread reference is destroyed first. |
(...skipping 17 matching lines...) Expand all Loading... |
707 FROM_HERE, | 721 FROM_HERE, |
708 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait, | 722 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait, |
709 base::Unretained(this), | 723 base::Unretained(this), |
710 &begin_capture, | 724 &begin_capture, |
711 &wait_for_capture, | 725 &wait_for_capture, |
712 &stop_capture)); | 726 &stop_capture)); |
713 | 727 |
714 // Before the main thread capturing starts, one compositor destroys their | 728 // Before the main thread capturing starts, one compositor destroys their |
715 // impl reference. Since capturing did not start, this gets post-tasked to | 729 // impl reference. Since capturing did not start, this gets post-tasked to |
716 // the main thread. | 730 // the main thread. |
717 compositor1.Run(100, false); | 731 compositor1->Run(100, false); |
718 | 732 |
719 // Start capturing on the main thread. | 733 // Start capturing on the main thread. |
720 begin_capture.Signal(); | 734 begin_capture.Signal(); |
721 wait_for_capture.Wait(); | 735 wait_for_capture.Wait(); |
722 | 736 |
723 // Meanwhile, the second compositor released its impl reference, but this task | 737 // Meanwhile, the second compositor released its impl reference, but this task |
724 // gets shortcutted directly to the main thread. This means the reference is | 738 // gets shortcutted directly to the main thread. This means the reference is |
725 // released before compositor1, whose reference will be released later when | 739 // released before compositor1, whose reference will be released later when |
726 // the post-task is serviced. But since it was destroyed _on the impl thread_ | 740 // the post-task is serviced. But since it was destroyed _on the impl thread_ |
727 // last, its sync point values should be used. | 741 // last, its sync point values should be used. |
728 compositor2.Run(200, true); | 742 compositor2->Run(200, true); |
729 | 743 |
730 stop_capture.Signal(); | 744 stop_capture.Signal(); |
731 Wait(main_thread_); | 745 Wait(main_thread_); |
732 | 746 |
733 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 747 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
734 } | 748 } |
735 | 749 |
736 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { | 750 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
737 public: | 751 public: |
738 TextureLayerImplWithMailboxThreadedCallback() | 752 TextureLayerImplWithMailboxThreadedCallback() |
739 : callback_count_(0), | 753 : callback_count_(0), |
740 commit_count_(0) {} | 754 commit_count_(0) {} |
741 | 755 |
742 // Make sure callback is received on main and doesn't block the impl thread. | 756 // Make sure callback is received on main and doesn't block the impl thread. |
743 void ReleaseCallback(unsigned sync_point, bool lost_resource) { | 757 void ReleaseCallback(unsigned sync_point, bool lost_resource) { |
744 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 758 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
745 EXPECT_FALSE(lost_resource); | 759 EXPECT_FALSE(lost_resource); |
746 ++callback_count_; | 760 ++callback_count_; |
747 } | 761 } |
748 | 762 |
749 void SetMailbox(char mailbox_char) { | 763 void SetMailbox(char mailbox_char) { |
750 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 764 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
751 TextureMailbox mailbox( | 765 TextureMailbox mailbox(std::string(64, mailbox_char)); |
752 std::string(64, mailbox_char), | 766 scoped_ptr<ScopedReleaseCallback> callback = ScopedReleaseCallback::Create( |
753 base::Bind( | 767 base::Bind( |
754 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, | 768 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback, |
755 base::Unretained(this))); | 769 base::Unretained(this))); |
756 layer_->SetTextureMailbox(mailbox); | 770 layer_->SetTextureMailbox(mailbox, callback.Pass()); |
757 } | 771 } |
758 | 772 |
759 virtual void BeginTest() OVERRIDE { | 773 virtual void BeginTest() OVERRIDE { |
760 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 774 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
761 | 775 |
762 gfx::Size bounds(100, 100); | 776 gfx::Size bounds(100, 100); |
763 root_ = Layer::Create(); | 777 root_ = Layer::Create(); |
764 root_->SetAnchorPoint(gfx::PointF()); | 778 root_->SetAnchorPoint(gfx::PointF()); |
765 root_->SetBounds(bounds); | 779 root_->SetBounds(bounds); |
766 | 780 |
(...skipping 29 matching lines...) Expand all Loading... |
796 EXPECT_EQ(2, callback_count_); | 810 EXPECT_EQ(2, callback_count_); |
797 // Case #3: change mailbox when the layer doesn't draw. The old | 811 // Case #3: change mailbox when the layer doesn't draw. The old |
798 // mailbox should be released during the next commit. | 812 // mailbox should be released during the next commit. |
799 layer_->SetBounds(gfx::Size()); | 813 layer_->SetBounds(gfx::Size()); |
800 SetMailbox('4'); | 814 SetMailbox('4'); |
801 break; | 815 break; |
802 case 3: | 816 case 3: |
803 EXPECT_EQ(3, callback_count_); | 817 EXPECT_EQ(3, callback_count_); |
804 // Case #4: release mailbox that was committed but never drawn. The | 818 // Case #4: release mailbox that was committed but never drawn. The |
805 // old mailbox should be released during the next commit. | 819 // old mailbox should be released during the next commit. |
806 layer_->SetTextureMailbox(TextureMailbox()); | 820 layer_->SetTextureMailbox(TextureMailbox(), |
| 821 scoped_ptr<ScopedReleaseCallback>()); |
807 break; | 822 break; |
808 case 4: | 823 case 4: |
809 if (layer_tree_host()->settings().impl_side_painting) { | 824 if (layer_tree_host()->settings().impl_side_painting) { |
810 // With impl painting, the texture mailbox will still be on the impl | 825 // With impl painting, the texture mailbox will still be on the impl |
811 // thread when the commit finishes, because the layer is not drawble | 826 // thread when the commit finishes, because the layer is not drawble |
812 // when it has no texture mailbox, and thus does not block the commit | 827 // when it has no texture mailbox, and thus does not block the commit |
813 // on activation. So, we wait for activation. | 828 // on activation. So, we wait for activation. |
814 // TODO(danakj): fix this. crbug.com/277953 | 829 // TODO(danakj): fix this. crbug.com/277953 |
815 layer_tree_host()->SetNeedsCommit(); | 830 layer_tree_host()->SetNeedsCommit(); |
816 break; | 831 break; |
(...skipping 18 matching lines...) Expand all Loading... |
835 // block the commit on activation anymore. So, we wait for activation. | 850 // block the commit on activation anymore. So, we wait for activation. |
836 // TODO(danakj): fix this. crbug.com/277953 | 851 // TODO(danakj): fix this. crbug.com/277953 |
837 layer_tree_host()->SetNeedsCommit(); | 852 layer_tree_host()->SetNeedsCommit(); |
838 break; | 853 break; |
839 } else { | 854 } else { |
840 ++commit_count_; | 855 ++commit_count_; |
841 } | 856 } |
842 case 8: | 857 case 8: |
843 EXPECT_EQ(4, callback_count_); | 858 EXPECT_EQ(4, callback_count_); |
844 // Resetting the mailbox will call the callback now. | 859 // Resetting the mailbox will call the callback now. |
845 layer_->SetTextureMailbox(TextureMailbox()); | 860 layer_->SetTextureMailbox(TextureMailbox(), |
| 861 scoped_ptr<ScopedReleaseCallback>()); |
846 EXPECT_EQ(5, callback_count_); | 862 EXPECT_EQ(5, callback_count_); |
847 EndTest(); | 863 EndTest(); |
848 break; | 864 break; |
849 default: | 865 default: |
850 NOTREACHED(); | 866 NOTREACHED(); |
851 break; | 867 break; |
852 } | 868 } |
853 } | 869 } |
854 | 870 |
855 virtual void AfterTest() OVERRIDE {} | 871 virtual void AfterTest() OVERRIDE {} |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 } | 912 } |
897 | 913 |
898 // TextureLayerClient implementation. | 914 // TextureLayerClient implementation. |
899 virtual unsigned PrepareTexture() OVERRIDE { | 915 virtual unsigned PrepareTexture() OVERRIDE { |
900 return OffscreenContextProviderForMainThread() | 916 return OffscreenContextProviderForMainThread() |
901 ->Context3d()->createTexture(); | 917 ->Context3d()->createTexture(); |
902 } | 918 } |
903 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 919 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
904 return OffscreenContextProviderForMainThread()->Context3d(); | 920 return OffscreenContextProviderForMainThread()->Context3d(); |
905 } | 921 } |
906 virtual bool PrepareTextureMailbox(TextureMailbox* mailbox, | 922 virtual bool PrepareTextureMailbox( |
907 bool use_shared_memory) OVERRIDE { | 923 TextureMailbox* mailbox, |
| 924 scoped_ptr<ScopedReleaseCallback>* release_callback, |
| 925 bool use_shared_memory) OVERRIDE { |
908 return false; | 926 return false; |
909 } | 927 } |
910 | 928 |
911 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 929 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
912 // Slow down activation so the main thread DidCommit() will run if | 930 // Slow down activation so the main thread DidCommit() will run if |
913 // not blocked. | 931 // not blocked. |
914 wait_thread_.message_loop()->PostDelayedTask( | 932 wait_thread_.message_loop()->PostDelayedTask( |
915 FROM_HERE, | 933 FROM_HERE, |
916 base::Bind(&base::WaitableEvent::Signal, | 934 base::Bind(&base::WaitableEvent::Signal, |
917 base::Unretained(&wait_event_)), | 935 base::Unretained(&wait_event_)), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 protected: | 1009 protected: |
992 TextureLayerMailboxIsActivatedDuringCommit() | 1010 TextureLayerMailboxIsActivatedDuringCommit() |
993 : wait_thread_("WAIT"), | 1011 : wait_thread_("WAIT"), |
994 wait_event_(false, false) { | 1012 wait_event_(false, false) { |
995 wait_thread_.Start(); | 1013 wait_thread_.Start(); |
996 } | 1014 } |
997 | 1015 |
998 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} | 1016 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} |
999 | 1017 |
1000 void SetMailbox(char mailbox_char) { | 1018 void SetMailbox(char mailbox_char) { |
1001 TextureMailbox mailbox( | 1019 TextureMailbox mailbox(std::string(64, mailbox_char)); |
1002 std::string(64, mailbox_char), | 1020 scoped_ptr<ScopedReleaseCallback> callback = ScopedReleaseCallback::Create( |
1003 base::Bind( | 1021 base::Bind( |
1004 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); | 1022 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); |
1005 layer_->SetTextureMailbox(mailbox); | 1023 layer_->SetTextureMailbox(mailbox, callback.Pass()); |
1006 } | 1024 } |
1007 | 1025 |
1008 virtual void BeginTest() OVERRIDE { | 1026 virtual void BeginTest() OVERRIDE { |
1009 activate_count_ = 0; | 1027 activate_count_ = 0; |
1010 | 1028 |
1011 gfx::Size bounds(100, 100); | 1029 gfx::Size bounds(100, 100); |
1012 root_ = Layer::Create(); | 1030 root_ = Layer::Create(); |
1013 root_->SetAnchorPoint(gfx::PointF()); | 1031 root_->SetAnchorPoint(gfx::PointF()); |
1014 root_->SetBounds(bounds); | 1032 root_->SetBounds(bounds); |
1015 | 1033 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 test_data_.sync_point1_, | 1154 test_data_.sync_point1_, |
1137 false)) | 1155 false)) |
1138 .Times(AnyNumber()); | 1156 .Times(AnyNumber()); |
1139 EXPECT_CALL(test_data_.mock_callback_, | 1157 EXPECT_CALL(test_data_.mock_callback_, |
1140 Release2(test_data_.shared_memory_.get(), 0, false)) | 1158 Release2(test_data_.shared_memory_.get(), 0, false)) |
1141 .Times(AnyNumber()); | 1159 .Times(AnyNumber()); |
1142 // Hardware mode. | 1160 // Hardware mode. |
1143 { | 1161 { |
1144 scoped_ptr<TextureLayerImpl> impl_layer = | 1162 scoped_ptr<TextureLayerImpl> impl_layer = |
1145 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1163 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1146 impl_layer->SetTextureMailbox(test_data_.mailbox1_); | 1164 impl_layer->SetTextureMailbox( |
| 1165 test_data_.mailbox1_, |
| 1166 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1147 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 1167 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
1148 } | 1168 } |
1149 | 1169 |
1150 { | 1170 { |
1151 scoped_ptr<TextureLayerImpl> impl_layer = | 1171 scoped_ptr<TextureLayerImpl> impl_layer = |
1152 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1172 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1153 impl_layer->SetTextureMailbox(TextureMailbox()); | 1173 impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1174 scoped_ptr<ScopedReleaseCallback>()); |
1154 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 1175 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
1155 } | 1176 } |
1156 | 1177 |
1157 { | 1178 { |
1158 // Software resource. | 1179 // Software resource. |
1159 scoped_ptr<TextureLayerImpl> impl_layer = | 1180 scoped_ptr<TextureLayerImpl> impl_layer = |
1160 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1181 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1161 impl_layer->SetTextureMailbox(test_data_.mailbox3_); | 1182 impl_layer->SetTextureMailbox( |
| 1183 test_data_.mailbox3_, |
| 1184 ScopedReleaseCallback::Create(test_data_.release_mailbox3_)); |
1162 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 1185 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
1163 } | 1186 } |
1164 | 1187 |
1165 { | 1188 { |
1166 scoped_ptr<TextureLayerImpl> impl_layer = | 1189 scoped_ptr<TextureLayerImpl> impl_layer = |
1167 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 1190 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
1168 ContextProvider* context_provider = | 1191 ContextProvider* context_provider = |
1169 host_impl_.output_surface()->context_provider(); | 1192 host_impl_.output_surface()->context_provider(); |
1170 unsigned texture = | 1193 unsigned texture = |
1171 context_provider->Context3d()->createTexture(); | 1194 context_provider->Context3d()->createTexture(); |
1172 impl_layer->set_texture_id(texture); | 1195 impl_layer->set_texture_id(texture); |
1173 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 1196 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
1174 } | 1197 } |
1175 | 1198 |
1176 { | 1199 { |
1177 scoped_ptr<TextureLayerImpl> impl_layer = | 1200 scoped_ptr<TextureLayerImpl> impl_layer = |
1178 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 1201 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
1179 impl_layer->set_texture_id(0); | 1202 impl_layer->set_texture_id(0); |
1180 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 1203 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
1181 } | 1204 } |
1182 | 1205 |
1183 // Software mode. | 1206 // Software mode. |
1184 { | 1207 { |
1185 scoped_ptr<TextureLayerImpl> impl_layer = | 1208 scoped_ptr<TextureLayerImpl> impl_layer = |
1186 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1209 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1187 impl_layer->SetTextureMailbox(test_data_.mailbox1_); | 1210 impl_layer->SetTextureMailbox( |
| 1211 test_data_.mailbox1_, |
| 1212 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1188 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 1213 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
1189 } | 1214 } |
1190 | 1215 |
1191 { | 1216 { |
1192 scoped_ptr<TextureLayerImpl> impl_layer = | 1217 scoped_ptr<TextureLayerImpl> impl_layer = |
1193 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1218 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1194 impl_layer->SetTextureMailbox(TextureMailbox()); | 1219 impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1220 scoped_ptr<ScopedReleaseCallback>()); |
1195 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 1221 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
1196 } | 1222 } |
1197 | 1223 |
1198 { | 1224 { |
1199 // Software resource. | 1225 // Software resource. |
1200 scoped_ptr<TextureLayerImpl> impl_layer = | 1226 scoped_ptr<TextureLayerImpl> impl_layer = |
1201 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1227 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1202 impl_layer->SetTextureMailbox(test_data_.mailbox3_); | 1228 impl_layer->SetTextureMailbox( |
| 1229 test_data_.mailbox3_, |
| 1230 ScopedReleaseCallback::Create(test_data_.release_mailbox3_)); |
1203 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 1231 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
1204 } | 1232 } |
1205 | 1233 |
1206 { | 1234 { |
1207 scoped_ptr<TextureLayerImpl> impl_layer = | 1235 scoped_ptr<TextureLayerImpl> impl_layer = |
1208 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 1236 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
1209 ContextProvider* context_provider = | 1237 ContextProvider* context_provider = |
1210 host_impl_.output_surface()->context_provider(); | 1238 host_impl_.output_surface()->context_provider(); |
1211 unsigned texture = | 1239 unsigned texture = |
1212 context_provider->Context3d()->createTexture(); | 1240 context_provider->Context3d()->createTexture(); |
1213 impl_layer->set_texture_id(texture); | 1241 impl_layer->set_texture_id(texture); |
1214 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 1242 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
1215 } | 1243 } |
1216 | 1244 |
1217 { | 1245 { |
1218 scoped_ptr<TextureLayerImpl> impl_layer = | 1246 scoped_ptr<TextureLayerImpl> impl_layer = |
1219 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 1247 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
1220 impl_layer->set_texture_id(0); | 1248 impl_layer->set_texture_id(0); |
1221 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 1249 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
1222 } | 1250 } |
1223 | 1251 |
1224 // Resourceless software mode. | 1252 // Resourceless software mode. |
1225 { | 1253 { |
1226 scoped_ptr<TextureLayerImpl> impl_layer = | 1254 scoped_ptr<TextureLayerImpl> impl_layer = |
1227 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1255 TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1228 impl_layer->SetTextureMailbox(test_data_.mailbox1_); | 1256 impl_layer->SetTextureMailbox( |
| 1257 test_data_.mailbox1_, |
| 1258 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1229 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); | 1259 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); |
1230 } | 1260 } |
1231 | 1261 |
1232 { | 1262 { |
1233 scoped_ptr<TextureLayerImpl> impl_layer = | 1263 scoped_ptr<TextureLayerImpl> impl_layer = |
1234 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 1264 TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); |
1235 ContextProvider* context_provider = | 1265 ContextProvider* context_provider = |
1236 host_impl_.output_surface()->context_provider(); | 1266 host_impl_.output_surface()->context_provider(); |
1237 unsigned texture = | 1267 unsigned texture = |
1238 context_provider->Context3d()->createTexture(); | 1268 context_provider->Context3d()->createTexture(); |
1239 impl_layer->set_texture_id(texture); | 1269 impl_layer->set_texture_id(texture); |
1240 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); | 1270 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); |
1241 } | 1271 } |
1242 } | 1272 } |
1243 | 1273 |
1244 TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { | 1274 TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { |
1245 host_impl_.CreatePendingTree(); | 1275 host_impl_.CreatePendingTree(); |
1246 scoped_ptr<TextureLayerImpl> pending_layer; | 1276 scoped_ptr<TextureLayerImpl> pending_layer; |
1247 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1, true); | 1277 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1, true); |
1248 ASSERT_TRUE(pending_layer); | 1278 ASSERT_TRUE(pending_layer); |
1249 | 1279 |
1250 scoped_ptr<LayerImpl> active_layer( | 1280 scoped_ptr<LayerImpl> active_layer( |
1251 pending_layer->CreateLayerImpl(host_impl_.active_tree())); | 1281 pending_layer->CreateLayerImpl(host_impl_.active_tree())); |
1252 ASSERT_TRUE(active_layer); | 1282 ASSERT_TRUE(active_layer); |
1253 | 1283 |
1254 pending_layer->SetTextureMailbox(test_data_.mailbox1_); | 1284 pending_layer->SetTextureMailbox( |
| 1285 test_data_.mailbox1_, |
| 1286 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1255 | 1287 |
1256 // Test multiple commits without an activation. | 1288 // Test multiple commits without an activation. |
1257 EXPECT_CALL(test_data_.mock_callback_, | 1289 EXPECT_CALL(test_data_.mock_callback_, |
1258 Release(test_data_.mailbox_name1_, | 1290 Release(test_data_.mailbox_name1_, |
1259 test_data_.sync_point1_, | 1291 test_data_.sync_point1_, |
1260 false)) | 1292 false)) |
1261 .Times(1); | 1293 .Times(1); |
1262 pending_layer->SetTextureMailbox(test_data_.mailbox2_); | 1294 pending_layer->SetTextureMailbox( |
| 1295 test_data_.mailbox2_, |
| 1296 ScopedReleaseCallback::Create(test_data_.release_mailbox2_)); |
1263 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1297 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
1264 | 1298 |
1265 // Test callback after activation. | 1299 // Test callback after activation. |
1266 pending_layer->PushPropertiesTo(active_layer.get()); | 1300 pending_layer->PushPropertiesTo(active_layer.get()); |
1267 active_layer->DidBecomeActive(); | 1301 active_layer->DidBecomeActive(); |
1268 | 1302 |
1269 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 1303 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
1270 pending_layer->SetTextureMailbox(test_data_.mailbox1_); | 1304 pending_layer->SetTextureMailbox( |
| 1305 test_data_.mailbox1_, |
| 1306 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1271 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1307 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
1272 | 1308 |
1273 EXPECT_CALL(test_data_.mock_callback_, | 1309 EXPECT_CALL(test_data_.mock_callback_, |
1274 Release(test_data_.mailbox_name2_, _, false)) | 1310 Release(test_data_.mailbox_name2_, _, false)) |
1275 .Times(1); | 1311 .Times(1); |
1276 pending_layer->PushPropertiesTo(active_layer.get()); | 1312 pending_layer->PushPropertiesTo(active_layer.get()); |
1277 active_layer->DidBecomeActive(); | 1313 active_layer->DidBecomeActive(); |
1278 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1314 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
1279 | 1315 |
1280 // Test resetting the mailbox. | 1316 // Test resetting the mailbox. |
1281 EXPECT_CALL(test_data_.mock_callback_, | 1317 EXPECT_CALL(test_data_.mock_callback_, |
1282 Release(test_data_.mailbox_name1_, _, false)) | 1318 Release(test_data_.mailbox_name1_, _, false)) |
1283 .Times(1); | 1319 .Times(1); |
1284 pending_layer->SetTextureMailbox(TextureMailbox()); | 1320 pending_layer->SetTextureMailbox(TextureMailbox(), |
| 1321 scoped_ptr<ScopedReleaseCallback>()); |
1285 pending_layer->PushPropertiesTo(active_layer.get()); | 1322 pending_layer->PushPropertiesTo(active_layer.get()); |
1286 active_layer->DidBecomeActive(); | 1323 active_layer->DidBecomeActive(); |
1287 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1324 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
1288 | 1325 |
1289 // Test destructor. | 1326 // Test destructor. |
1290 EXPECT_CALL(test_data_.mock_callback_, | 1327 EXPECT_CALL(test_data_.mock_callback_, |
1291 Release(test_data_.mailbox_name1_, | 1328 Release(test_data_.mailbox_name1_, |
1292 test_data_.sync_point1_, | 1329 test_data_.sync_point1_, |
1293 false)) | 1330 false)) |
1294 .Times(1); | 1331 .Times(1); |
1295 pending_layer->SetTextureMailbox(test_data_.mailbox1_); | 1332 pending_layer->SetTextureMailbox( |
| 1333 test_data_.mailbox1_, |
| 1334 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1296 } | 1335 } |
1297 | 1336 |
1298 TEST_F(TextureLayerImplWithMailboxTest, | 1337 TEST_F(TextureLayerImplWithMailboxTest, |
1299 TestDestructorCallbackOnCreatedResource) { | 1338 TestDestructorCallbackOnCreatedResource) { |
1300 scoped_ptr<TextureLayerImpl> impl_layer; | 1339 scoped_ptr<TextureLayerImpl> impl_layer; |
1301 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); | 1340 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, true); |
1302 ASSERT_TRUE(impl_layer); | 1341 ASSERT_TRUE(impl_layer); |
1303 | 1342 |
1304 EXPECT_CALL(test_data_.mock_callback_, | 1343 EXPECT_CALL(test_data_.mock_callback_, |
1305 Release(test_data_.mailbox_name1_, _, false)) | 1344 Release(test_data_.mailbox_name1_, _, false)) |
1306 .Times(1); | 1345 .Times(1); |
1307 impl_layer->SetTextureMailbox(test_data_.mailbox1_); | 1346 impl_layer->SetTextureMailbox( |
| 1347 test_data_.mailbox1_, |
| 1348 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1308 impl_layer->DidBecomeActive(); | 1349 impl_layer->DidBecomeActive(); |
1309 EXPECT_TRUE(impl_layer->WillDraw( | 1350 EXPECT_TRUE(impl_layer->WillDraw( |
1310 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider())); | 1351 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider())); |
1311 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider()); | 1352 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
1312 impl_layer->SetTextureMailbox(TextureMailbox()); | 1353 impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1354 scoped_ptr<ScopedReleaseCallback>()); |
1313 } | 1355 } |
1314 | 1356 |
1315 TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) { | 1357 TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) { |
1316 ResourceProvider* provider = host_impl_.active_tree()->resource_provider(); | 1358 ResourceProvider* provider = host_impl_.active_tree()->resource_provider(); |
1317 ResourceProvider::ResourceId id = | 1359 ResourceProvider::ResourceId id = |
1318 provider->CreateResourceFromTextureMailbox(test_data_.mailbox1_); | 1360 provider->CreateResourceFromTextureMailbox( |
| 1361 test_data_.mailbox1_, |
| 1362 ScopedReleaseCallback::Create(test_data_.release_mailbox1_)); |
1319 provider->AllocateForTesting(id); | 1363 provider->AllocateForTesting(id); |
1320 | 1364 |
1321 // Transfer some resources to the parent. | 1365 // Transfer some resources to the parent. |
1322 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1366 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
1323 resource_ids_to_transfer.push_back(id); | 1367 resource_ids_to_transfer.push_back(id); |
1324 TransferableResourceArray list; | 1368 TransferableResourceArray list; |
1325 provider->PrepareSendToParent(resource_ids_to_transfer, &list); | 1369 provider->PrepareSendToParent(resource_ids_to_transfer, &list); |
1326 EXPECT_TRUE(provider->InUseByConsumer(id)); | 1370 EXPECT_TRUE(provider->InUseByConsumer(id)); |
1327 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 1371 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
1328 provider->DeleteResource(id); | 1372 provider->DeleteResource(id); |
(...skipping 30 matching lines...) Expand all Loading... |
1359 | 1403 |
1360 virtual unsigned PrepareTexture() OVERRIDE { | 1404 virtual unsigned PrepareTexture() OVERRIDE { |
1361 return texture_; | 1405 return texture_; |
1362 } | 1406 } |
1363 | 1407 |
1364 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 1408 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
1365 return context_; | 1409 return context_; |
1366 } | 1410 } |
1367 | 1411 |
1368 virtual bool PrepareTextureMailbox( | 1412 virtual bool PrepareTextureMailbox( |
1369 cc::TextureMailbox* mailbox, bool use_shared_memory) OVERRIDE { | 1413 TextureMailbox* mailbox, |
| 1414 scoped_ptr<ScopedReleaseCallback>* release_callback, |
| 1415 bool use_shared_memory) OVERRIDE { |
1370 return false; | 1416 return false; |
1371 } | 1417 } |
1372 | 1418 |
1373 virtual void SetupTree() OVERRIDE { | 1419 virtual void SetupTree() OVERRIDE { |
1374 scoped_refptr<Layer> root = Layer::Create(); | 1420 scoped_refptr<Layer> root = Layer::Create(); |
1375 root->SetBounds(gfx::Size(10, 10)); | 1421 root->SetBounds(gfx::Size(10, 10)); |
1376 root->SetAnchorPoint(gfx::PointF()); | 1422 root->SetAnchorPoint(gfx::PointF()); |
1377 root->SetIsDrawable(true); | 1423 root->SetIsDrawable(true); |
1378 | 1424 |
1379 texture_layer_ = TextureLayer::Create(this); | 1425 texture_layer_ = TextureLayer::Create(this); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 GL_INNOCENT_CONTEXT_RESET_ARB); | 1521 GL_INNOCENT_CONTEXT_RESET_ARB); |
1476 } | 1522 } |
1477 return texture_; | 1523 return texture_; |
1478 } | 1524 } |
1479 | 1525 |
1480 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | 1526 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
1481 return texture_context_.get(); | 1527 return texture_context_.get(); |
1482 } | 1528 } |
1483 | 1529 |
1484 virtual bool PrepareTextureMailbox( | 1530 virtual bool PrepareTextureMailbox( |
1485 cc::TextureMailbox* mailbox, bool use_shared_memory) OVERRIDE { | 1531 TextureMailbox* mailbox, |
| 1532 scoped_ptr<ScopedReleaseCallback>* release_callback, |
| 1533 bool use_shared_memory) OVERRIDE { |
1486 return false; | 1534 return false; |
1487 } | 1535 } |
1488 | 1536 |
1489 virtual void SetupTree() OVERRIDE { | 1537 virtual void SetupTree() OVERRIDE { |
1490 scoped_refptr<Layer> root = Layer::Create(); | 1538 scoped_refptr<Layer> root = Layer::Create(); |
1491 root->SetBounds(gfx::Size(10, 10)); | 1539 root->SetBounds(gfx::Size(10, 10)); |
1492 root->SetIsDrawable(true); | 1540 root->SetIsDrawable(true); |
1493 | 1541 |
1494 texture_layer_ = TextureLayer::Create(this); | 1542 texture_layer_ = TextureLayer::Create(this); |
1495 texture_layer_->SetBounds(gfx::Size(10, 10)); | 1543 texture_layer_->SetBounds(gfx::Size(10, 10)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 public: | 1584 public: |
1537 void ReleaseCallback(unsigned sync_point, bool lost_resource) { | 1585 void ReleaseCallback(unsigned sync_point, bool lost_resource) { |
1538 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 1586 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
1539 EXPECT_FALSE(lost_resource); | 1587 EXPECT_FALSE(lost_resource); |
1540 ++callback_count_; | 1588 ++callback_count_; |
1541 EndTest(); | 1589 EndTest(); |
1542 } | 1590 } |
1543 | 1591 |
1544 void SetMailbox(char mailbox_char) { | 1592 void SetMailbox(char mailbox_char) { |
1545 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 1593 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
1546 TextureMailbox mailbox( | 1594 TextureMailbox mailbox(std::string(64, mailbox_char)); |
1547 std::string(64, mailbox_char), | 1595 scoped_ptr<ScopedReleaseCallback> callback = ScopedReleaseCallback::Create( |
1548 base::Bind( | 1596 base::Bind( |
1549 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, | 1597 &TextureLayerWithMailboxMainThreadDeleted::ReleaseCallback, |
1550 base::Unretained(this))); | 1598 base::Unretained(this))); |
1551 layer_->SetTextureMailbox(mailbox); | 1599 layer_->SetTextureMailbox(mailbox, callback.Pass()); |
1552 } | 1600 } |
1553 | 1601 |
1554 virtual void SetupTree() OVERRIDE { | 1602 virtual void SetupTree() OVERRIDE { |
1555 gfx::Size bounds(100, 100); | 1603 gfx::Size bounds(100, 100); |
1556 root_ = Layer::Create(); | 1604 root_ = Layer::Create(); |
1557 root_->SetAnchorPoint(gfx::PointF()); | 1605 root_->SetAnchorPoint(gfx::PointF()); |
1558 root_->SetBounds(bounds); | 1606 root_->SetBounds(bounds); |
1559 | 1607 |
1560 layer_ = TextureLayer::CreateForMailbox(NULL); | 1608 layer_ = TextureLayer::CreateForMailbox(NULL); |
1561 layer_->SetIsDrawable(true); | 1609 layer_->SetIsDrawable(true); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 public: | 1656 public: |
1609 void ReleaseCallback(unsigned sync_point, bool lost_resource) { | 1657 void ReleaseCallback(unsigned sync_point, bool lost_resource) { |
1610 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 1658 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
1611 EXPECT_FALSE(lost_resource); | 1659 EXPECT_FALSE(lost_resource); |
1612 ++callback_count_; | 1660 ++callback_count_; |
1613 EndTest(); | 1661 EndTest(); |
1614 } | 1662 } |
1615 | 1663 |
1616 void SetMailbox(char mailbox_char) { | 1664 void SetMailbox(char mailbox_char) { |
1617 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); | 1665 EXPECT_EQ(true, main_thread_.CalledOnValidThread()); |
1618 TextureMailbox mailbox( | 1666 TextureMailbox mailbox(std::string(64, mailbox_char)); |
1619 std::string(64, mailbox_char), | 1667 scoped_ptr<ScopedReleaseCallback> callback = ScopedReleaseCallback::Create( |
1620 base::Bind( | 1668 base::Bind( |
1621 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, | 1669 &TextureLayerWithMailboxImplThreadDeleted::ReleaseCallback, |
1622 base::Unretained(this))); | 1670 base::Unretained(this))); |
1623 layer_->SetTextureMailbox(mailbox); | 1671 layer_->SetTextureMailbox(mailbox, callback.Pass()); |
1624 } | 1672 } |
1625 | 1673 |
1626 virtual void SetupTree() OVERRIDE { | 1674 virtual void SetupTree() OVERRIDE { |
1627 gfx::Size bounds(100, 100); | 1675 gfx::Size bounds(100, 100); |
1628 root_ = Layer::Create(); | 1676 root_ = Layer::Create(); |
1629 root_->SetAnchorPoint(gfx::PointF()); | 1677 root_->SetAnchorPoint(gfx::PointF()); |
1630 root_->SetBounds(bounds); | 1678 root_->SetBounds(bounds); |
1631 | 1679 |
1632 layer_ = TextureLayer::CreateForMailbox(NULL); | 1680 layer_ = TextureLayer::CreateForMailbox(NULL); |
1633 layer_->SetIsDrawable(true); | 1681 layer_->SetIsDrawable(true); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 int callback_count_; | 1722 int callback_count_; |
1675 scoped_refptr<Layer> root_; | 1723 scoped_refptr<Layer> root_; |
1676 scoped_refptr<TextureLayer> layer_; | 1724 scoped_refptr<TextureLayer> layer_; |
1677 }; | 1725 }; |
1678 | 1726 |
1679 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1727 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1680 TextureLayerWithMailboxImplThreadDeleted); | 1728 TextureLayerWithMailboxImplThreadDeleted); |
1681 | 1729 |
1682 } // namespace | 1730 } // namespace |
1683 } // namespace cc | 1731 } // namespace cc |
OLD | NEW |