OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "cc/layers/layer_iterator.h" | 8 #include "cc/layers/layer_iterator.h" |
8 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
9 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
10 #include "cc/test/fake_content_layer_client.h" | 11 #include "cc/test/fake_content_layer_client.h" |
11 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
12 #include "cc/test/fake_picture_layer.h" | 13 #include "cc/test/fake_picture_layer.h" |
13 #include "cc/test/layer_tree_test.h" | 14 #include "cc/test/layer_tree_test.h" |
14 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
15 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
16 | 17 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString()); | 105 EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[1].ToString()); |
105 // The |root| was copied to a bitmap and passed back also in Case 2. | 106 // The |root| was copied to a bitmap and passed back also in Case 2. |
106 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[2].ToString()); | 107 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[2].ToString()); |
107 // The |grand_child| was copied to a bitmap and passed back in Case 2. | 108 // The |grand_child| was copied to a bitmap and passed back in Case 2. |
108 EXPECT_EQ(gfx::Size(5, 5).ToString(), callbacks_[3].ToString()); | 109 EXPECT_EQ(gfx::Size(5, 5).ToString(), callbacks_[3].ToString()); |
109 EndTest(); | 110 EndTest(); |
110 break; | 111 break; |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
114 void CopyOutputCallback(size_t id, scoped_ptr<CopyOutputResult> result) { | 115 void CopyOutputCallback(size_t id, std::unique_ptr<CopyOutputResult> result) { |
115 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 116 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
116 EXPECT_TRUE(result->HasBitmap()); | 117 EXPECT_TRUE(result->HasBitmap()); |
117 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); | 118 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
118 EXPECT_EQ(result->size().ToString(), | 119 EXPECT_EQ(result->size().ToString(), |
119 gfx::Size(bitmap->width(), bitmap->height()).ToString()); | 120 gfx::Size(bitmap->width(), bitmap->height()).ToString()); |
120 callbacks_[id] = result->size(); | 121 callbacks_[id] = result->size(); |
121 } | 122 } |
122 | 123 |
123 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } | 124 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } |
124 | 125 |
125 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | 126 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
126 if (!use_gl_renderer_) { | 127 if (!use_gl_renderer_) { |
127 return FakeOutputSurface::CreateSoftware( | 128 return FakeOutputSurface::CreateSoftware( |
128 make_scoped_ptr(new SoftwareOutputDevice)); | 129 base::WrapUnique(new SoftwareOutputDevice)); |
129 } | 130 } |
130 scoped_ptr<FakeOutputSurface> output_surface = | 131 std::unique_ptr<FakeOutputSurface> output_surface = |
131 FakeOutputSurface::Create3d(); | 132 FakeOutputSurface::Create3d(); |
132 TestContextSupport* context_support = static_cast<TestContextSupport*>( | 133 TestContextSupport* context_support = static_cast<TestContextSupport*>( |
133 output_surface->context_provider()->ContextSupport()); | 134 output_surface->context_provider()->ContextSupport()); |
134 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); | 135 context_support->set_out_of_order_callbacks(out_of_order_callbacks_); |
135 return output_surface; | 136 return output_surface; |
136 } | 137 } |
137 | 138 |
138 bool use_gl_renderer_; | 139 bool use_gl_renderer_; |
139 bool out_of_order_callbacks_ = false; | 140 bool out_of_order_callbacks_ = false; |
140 std::map<size_t, gfx::Size> callbacks_; | 141 std::map<size_t, gfx::Size> callbacks_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 case 2: | 217 case 2: |
217 // This commit is triggered by the copy request. | 218 // This commit is triggered by the copy request. |
218 break; | 219 break; |
219 case 3: | 220 case 3: |
220 // This commit is triggered by the completion of the copy request. | 221 // This commit is triggered by the completion of the copy request. |
221 EndTest(); | 222 EndTest(); |
222 break; | 223 break; |
223 } | 224 } |
224 } | 225 } |
225 | 226 |
226 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 227 static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
227 EXPECT_FALSE(result->IsEmpty()); | 228 EXPECT_FALSE(result->IsEmpty()); |
228 } | 229 } |
229 | 230 |
230 void AfterTest() override {} | 231 void AfterTest() override {} |
231 | 232 |
232 FakeContentLayerClient client_; | 233 FakeContentLayerClient client_; |
233 scoped_refptr<FakePictureLayer> root_; | 234 scoped_refptr<FakePictureLayer> root_; |
234 scoped_refptr<FakePictureLayer> layer_; | 235 scoped_refptr<FakePictureLayer> layer_; |
235 }; | 236 }; |
236 | 237 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 layer_tree_host()->SetNeedsCommit(); | 307 layer_tree_host()->SetNeedsCommit(); |
307 break; | 308 break; |
308 case 5: | 309 case 5: |
309 // We should get another callback with a NULL bitmap. | 310 // We should get another callback with a NULL bitmap. |
310 EXPECT_EQ(2, callback_count_); | 311 EXPECT_EQ(2, callback_count_); |
311 EndTest(); | 312 EndTest(); |
312 break; | 313 break; |
313 } | 314 } |
314 } | 315 } |
315 | 316 |
316 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 317 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
317 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 318 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
318 EXPECT_TRUE(result->IsEmpty()); | 319 EXPECT_TRUE(result->IsEmpty()); |
319 ++callback_count_; | 320 ++callback_count_; |
320 } | 321 } |
321 | 322 |
322 void AfterTest() override {} | 323 void AfterTest() override {} |
323 | 324 |
324 int callback_count_; | 325 int callback_count_; |
325 FakeContentLayerClient client_; | 326 FakeContentLayerClient client_; |
326 scoped_refptr<FakePictureLayer> root_; | 327 scoped_refptr<FakePictureLayer> root_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 base::Unretained(this)))); | 364 base::Unretained(this)))); |
364 } | 365 } |
365 | 366 |
366 void BeginTest() override { | 367 void BeginTest() override { |
367 callback_count_ = 0; | 368 callback_count_ = 0; |
368 PostSetNeedsCommitToMainThread(); | 369 PostSetNeedsCommitToMainThread(); |
369 | 370 |
370 AddCopyRequest(copy_layer_.get()); | 371 AddCopyRequest(copy_layer_.get()); |
371 } | 372 } |
372 | 373 |
373 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 374 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
374 ++callback_count_; | 375 ++callback_count_; |
375 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 376 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
376 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()) | 377 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()) |
377 << callback_count_; | 378 << callback_count_; |
378 switch (callback_count_) { | 379 switch (callback_count_) { |
379 case 1: | 380 case 1: |
380 // Hide the copy request layer. | 381 // Hide the copy request layer. |
381 grand_parent_layer_->SetHideLayerAndSubtree(false); | 382 grand_parent_layer_->SetHideLayerAndSubtree(false); |
382 parent_layer_->SetHideLayerAndSubtree(false); | 383 parent_layer_->SetHideLayerAndSubtree(false); |
383 copy_layer_->SetHideLayerAndSubtree(true); | 384 copy_layer_->SetHideLayerAndSubtree(true); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 did_draw_ = false; | 462 did_draw_ = false; |
462 PostSetNeedsCommitToMainThread(); | 463 PostSetNeedsCommitToMainThread(); |
463 | 464 |
464 copy_layer_->RequestCopyOfOutput( | 465 copy_layer_->RequestCopyOfOutput( |
465 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 466 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
466 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: | 467 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: |
467 CopyOutputCallback, | 468 CopyOutputCallback, |
468 base::Unretained(this)))); | 469 base::Unretained(this)))); |
469 } | 470 } |
470 | 471 |
471 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 472 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
472 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 473 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
473 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); | 474 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); |
474 EndTest(); | 475 EndTest(); |
475 } | 476 } |
476 | 477 |
477 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 478 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
478 Renderer* renderer = host_impl->renderer(); | 479 Renderer* renderer = host_impl->renderer(); |
479 | 480 |
480 LayerImpl* root = host_impl->active_tree()->root_layer(); | 481 LayerImpl* root = host_impl->active_tree()->root_layer(); |
481 LayerImpl* grand_parent = root->children()[0]; | 482 LayerImpl* grand_parent = root->children()[0]; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 539 } |
539 | 540 |
540 void BeginTest() override { | 541 void BeginTest() override { |
541 PostSetNeedsCommitToMainThread(); | 542 PostSetNeedsCommitToMainThread(); |
542 | 543 |
543 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 544 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
544 base::Bind(&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback, | 545 base::Bind(&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback, |
545 base::Unretained(this)))); | 546 base::Unretained(this)))); |
546 } | 547 } |
547 | 548 |
548 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 549 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
549 // We should still get the content even if the copy requested layer was | 550 // We should still get the content even if the copy requested layer was |
550 // completely clipped away. | 551 // completely clipped away. |
551 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 552 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
552 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); | 553 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); |
553 EndTest(); | 554 EndTest(); |
554 } | 555 } |
555 | 556 |
556 void AfterTest() override {} | 557 void AfterTest() override {} |
557 | 558 |
558 FakeContentLayerClient client_; | 559 FakeContentLayerClient client_; |
(...skipping 25 matching lines...) Expand all Loading... |
584 copy_layer_->AddChild(child_layer_); | 585 copy_layer_->AddChild(child_layer_); |
585 | 586 |
586 layer_tree_host()->SetRootLayer(root_); | 587 layer_tree_host()->SetRootLayer(root_); |
587 LayerTreeHostCopyRequestTest::SetupTree(); | 588 LayerTreeHostCopyRequestTest::SetupTree(); |
588 client_.set_bounds(root_->bounds()); | 589 client_.set_bounds(root_->bounds()); |
589 } | 590 } |
590 | 591 |
591 void BeginTest() override { | 592 void BeginTest() override { |
592 PostSetNeedsCommitToMainThread(); | 593 PostSetNeedsCommitToMainThread(); |
593 | 594 |
594 scoped_ptr<CopyOutputRequest> request = | 595 std::unique_ptr<CopyOutputRequest> request = |
595 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 596 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
596 &LayerTreeHostCopyRequestTestScaledLayer::CopyOutputCallback, | 597 &LayerTreeHostCopyRequestTestScaledLayer::CopyOutputCallback, |
597 base::Unretained(this))); | 598 base::Unretained(this))); |
598 request->set_area(gfx::Rect(5, 5)); | 599 request->set_area(gfx::Rect(5, 5)); |
599 copy_layer_->RequestCopyOfOutput(std::move(request)); | 600 copy_layer_->RequestCopyOfOutput(std::move(request)); |
600 } | 601 } |
601 | 602 |
602 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 603 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
603 // The request area is expressed in layer space, but the result's size takes | 604 // The request area is expressed in layer space, but the result's size takes |
604 // into account the transform from layer space to surface space. | 605 // into account the transform from layer space to surface space. |
605 EXPECT_EQ(gfx::Size(10, 10), result->size()); | 606 EXPECT_EQ(gfx::Size(10, 10), result->size()); |
606 EndTest(); | 607 EndTest(); |
607 } | 608 } |
608 | 609 |
609 void AfterTest() override {} | 610 void AfterTest() override {} |
610 | 611 |
611 FakeContentLayerClient client_; | 612 FakeContentLayerClient client_; |
612 scoped_refptr<Layer> root_; | 613 scoped_refptr<Layer> root_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 | 662 |
662 void DidCommit() override { | 663 void DidCommit() override { |
663 if (layer_tree_host()->source_frame_number() == 1) { | 664 if (layer_tree_host()->source_frame_number() == 1) { |
664 // Allow drawing. | 665 // Allow drawing. |
665 layer_tree_host()->SetViewportSize(gfx::Size(root_->bounds())); | 666 layer_tree_host()->SetViewportSize(gfx::Size(root_->bounds())); |
666 | 667 |
667 AddCopyRequest(copy_layer_.get()); | 668 AddCopyRequest(copy_layer_.get()); |
668 } | 669 } |
669 } | 670 } |
670 | 671 |
671 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 672 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
672 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 673 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
673 | 674 |
674 // The first frame can't be drawn. | 675 // The first frame can't be drawn. |
675 switch (callback_count_) { | 676 switch (callback_count_) { |
676 case 0: | 677 case 0: |
677 EXPECT_TRUE(result->IsEmpty()); | 678 EXPECT_TRUE(result->IsEmpty()); |
678 EXPECT_EQ(gfx::Size(), result->size()); | 679 EXPECT_EQ(gfx::Size(), result->size()); |
679 break; | 680 break; |
680 case 1: | 681 case 1: |
681 EXPECT_FALSE(result->IsEmpty()); | 682 EXPECT_FALSE(result->IsEmpty()); |
(...skipping 16 matching lines...) Expand all Loading... |
698 scoped_refptr<FakePictureLayer> root_; | 699 scoped_refptr<FakePictureLayer> root_; |
699 scoped_refptr<FakePictureLayer> copy_layer_; | 700 scoped_refptr<FakePictureLayer> copy_layer_; |
700 }; | 701 }; |
701 | 702 |
702 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 703 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
703 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); | 704 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); |
704 | 705 |
705 class LayerTreeHostCopyRequestTestLostOutputSurface | 706 class LayerTreeHostCopyRequestTestLostOutputSurface |
706 : public LayerTreeHostCopyRequestTest { | 707 : public LayerTreeHostCopyRequestTest { |
707 protected: | 708 protected: |
708 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | 709 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
709 if (!first_context_provider_) { | 710 if (!first_context_provider_) { |
710 first_context_provider_ = TestContextProvider::Create(); | 711 first_context_provider_ = TestContextProvider::Create(); |
711 return FakeOutputSurface::Create3d(first_context_provider_); | 712 return FakeOutputSurface::Create3d(first_context_provider_); |
712 } | 713 } |
713 | 714 |
714 EXPECT_FALSE(second_context_provider_); | 715 EXPECT_FALSE(second_context_provider_); |
715 second_context_provider_ = TestContextProvider::Create(); | 716 second_context_provider_ = TestContextProvider::Create(); |
716 return FakeOutputSurface::Create3d(second_context_provider_); | 717 return FakeOutputSurface::Create3d(second_context_provider_); |
717 } | 718 } |
718 | 719 |
719 void SetupTree() override { | 720 void SetupTree() override { |
720 root_ = FakePictureLayer::Create(&client_); | 721 root_ = FakePictureLayer::Create(&client_); |
721 root_->SetBounds(gfx::Size(20, 20)); | 722 root_->SetBounds(gfx::Size(20, 20)); |
722 | 723 |
723 copy_layer_ = FakePictureLayer::Create(&client_); | 724 copy_layer_ = FakePictureLayer::Create(&client_); |
724 copy_layer_->SetBounds(gfx::Size(10, 10)); | 725 copy_layer_->SetBounds(gfx::Size(10, 10)); |
725 root_->AddChild(copy_layer_); | 726 root_->AddChild(copy_layer_); |
726 | 727 |
727 layer_tree_host()->SetRootLayer(root_); | 728 layer_tree_host()->SetRootLayer(root_); |
728 LayerTreeHostCopyRequestTest::SetupTree(); | 729 LayerTreeHostCopyRequestTest::SetupTree(); |
729 client_.set_bounds(root_->bounds()); | 730 client_.set_bounds(root_->bounds()); |
730 } | 731 } |
731 | 732 |
732 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 733 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
733 | 734 |
734 void ReceiveCopyRequestOutputAndCommit(scoped_ptr<CopyOutputResult> result) { | 735 void ReceiveCopyRequestOutputAndCommit( |
| 736 std::unique_ptr<CopyOutputResult> result) { |
735 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); | 737 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
736 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); | 738 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); |
737 EXPECT_TRUE(result->HasTexture()); | 739 EXPECT_TRUE(result->HasTexture()); |
738 | 740 |
739 // Save the result for later. | 741 // Save the result for later. |
740 EXPECT_FALSE(result_); | 742 EXPECT_FALSE(result_); |
741 result_ = std::move(result); | 743 result_ = std::move(result); |
742 | 744 |
743 // Post a commit to lose the output surface. | 745 // Post a commit to lose the output surface. |
744 layer_tree_host()->SetNeedsCommit(); | 746 layer_tree_host()->SetNeedsCommit(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 825 |
824 void AfterTest() override {} | 826 void AfterTest() override {} |
825 | 827 |
826 scoped_refptr<TestContextProvider> first_context_provider_; | 828 scoped_refptr<TestContextProvider> first_context_provider_; |
827 scoped_refptr<TestContextProvider> second_context_provider_; | 829 scoped_refptr<TestContextProvider> second_context_provider_; |
828 size_t num_textures_without_readback_ = 0; | 830 size_t num_textures_without_readback_ = 0; |
829 size_t num_textures_after_loss_ = 0; | 831 size_t num_textures_after_loss_ = 0; |
830 FakeContentLayerClient client_; | 832 FakeContentLayerClient client_; |
831 scoped_refptr<FakePictureLayer> root_; | 833 scoped_refptr<FakePictureLayer> root_; |
832 scoped_refptr<FakePictureLayer> copy_layer_; | 834 scoped_refptr<FakePictureLayer> copy_layer_; |
833 scoped_ptr<CopyOutputResult> result_; | 835 std::unique_ptr<CopyOutputResult> result_; |
834 }; | 836 }; |
835 | 837 |
836 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 838 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
837 LayerTreeHostCopyRequestTestLostOutputSurface); | 839 LayerTreeHostCopyRequestTestLostOutputSurface); |
838 | 840 |
839 class LayerTreeHostCopyRequestTestCountTextures | 841 class LayerTreeHostCopyRequestTestCountTextures |
840 : public LayerTreeHostCopyRequestTest { | 842 : public LayerTreeHostCopyRequestTest { |
841 protected: | 843 protected: |
842 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | 844 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
843 context_provider_ = TestContextProvider::Create(); | 845 context_provider_ = TestContextProvider::Create(); |
844 return FakeOutputSurface::Create3d(context_provider_); | 846 return FakeOutputSurface::Create3d(context_provider_); |
845 } | 847 } |
846 | 848 |
847 void SetupTree() override { | 849 void SetupTree() override { |
848 client_.set_fill_with_nonsolid_color(true); | 850 client_.set_fill_with_nonsolid_color(true); |
849 | 851 |
850 root_ = FakePictureLayer::Create(&client_); | 852 root_ = FakePictureLayer::Create(&client_); |
851 root_->SetBounds(gfx::Size(20, 20)); | 853 root_->SetBounds(gfx::Size(20, 20)); |
852 | 854 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 : public LayerTreeHostCopyRequestTestCountTextures { | 917 : public LayerTreeHostCopyRequestTestCountTextures { |
916 protected: | 918 protected: |
917 void RequestCopy(Layer* layer) override { | 919 void RequestCopy(Layer* layer) override { |
918 // Request a normal texture copy. This should create a new texture. | 920 // Request a normal texture copy. This should create a new texture. |
919 copy_layer_->RequestCopyOfOutput( | 921 copy_layer_->RequestCopyOfOutput( |
920 CopyOutputRequest::CreateRequest(base::Bind( | 922 CopyOutputRequest::CreateRequest(base::Bind( |
921 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, | 923 &LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback, |
922 base::Unretained(this)))); | 924 base::Unretained(this)))); |
923 } | 925 } |
924 | 926 |
925 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 927 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
926 EXPECT_FALSE(result->IsEmpty()); | 928 EXPECT_FALSE(result->IsEmpty()); |
927 EXPECT_TRUE(result->HasTexture()); | 929 EXPECT_TRUE(result->HasTexture()); |
928 | 930 |
929 TextureMailbox mailbox; | 931 TextureMailbox mailbox; |
930 scoped_ptr<SingleReleaseCallback> release; | 932 std::unique_ptr<SingleReleaseCallback> release; |
931 result->TakeTexture(&mailbox, &release); | 933 result->TakeTexture(&mailbox, &release); |
932 EXPECT_TRUE(release); | 934 EXPECT_TRUE(release); |
933 | 935 |
934 release->Run(gpu::SyncToken(), false); | 936 release->Run(gpu::SyncToken(), false); |
935 } | 937 } |
936 | 938 |
937 void AfterTest() override { | 939 void AfterTest() override { |
938 // No sync point was needed. | 940 // No sync point was needed. |
939 EXPECT_FALSE(waited_sync_token_after_readback_.HasData()); | 941 EXPECT_FALSE(waited_sync_token_after_readback_.HasData()); |
940 // Except the copy to have made another texture. | 942 // Except the copy to have made another texture. |
941 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); | 943 EXPECT_EQ(num_textures_without_readback_ + 1, num_textures_with_readback_); |
942 } | 944 } |
943 }; | 945 }; |
944 | 946 |
945 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 947 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
946 LayerTreeHostCopyRequestTestCreatesTexture); | 948 LayerTreeHostCopyRequestTestCreatesTexture); |
947 | 949 |
948 class LayerTreeHostCopyRequestTestProvideTexture | 950 class LayerTreeHostCopyRequestTestProvideTexture |
949 : public LayerTreeHostCopyRequestTestCountTextures { | 951 : public LayerTreeHostCopyRequestTestCountTextures { |
950 protected: | 952 protected: |
951 void BeginTest() override { | 953 void BeginTest() override { |
952 external_context_provider_ = TestContextProvider::Create(); | 954 external_context_provider_ = TestContextProvider::Create(); |
953 EXPECT_TRUE(external_context_provider_->BindToCurrentThread()); | 955 EXPECT_TRUE(external_context_provider_->BindToCurrentThread()); |
954 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); | 956 LayerTreeHostCopyRequestTestCountTextures::BeginTest(); |
955 } | 957 } |
956 | 958 |
957 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 959 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
958 EXPECT_FALSE(result->IsEmpty()); | 960 EXPECT_FALSE(result->IsEmpty()); |
959 EXPECT_TRUE(result->HasTexture()); | 961 EXPECT_TRUE(result->HasTexture()); |
960 | 962 |
961 TextureMailbox mailbox; | 963 TextureMailbox mailbox; |
962 scoped_ptr<SingleReleaseCallback> release; | 964 std::unique_ptr<SingleReleaseCallback> release; |
963 result->TakeTexture(&mailbox, &release); | 965 result->TakeTexture(&mailbox, &release); |
964 EXPECT_FALSE(release); | 966 EXPECT_FALSE(release); |
965 } | 967 } |
966 | 968 |
967 void RequestCopy(Layer* layer) override { | 969 void RequestCopy(Layer* layer) override { |
968 // Request a copy to a provided texture. This should not create a new | 970 // Request a copy to a provided texture. This should not create a new |
969 // texture. | 971 // texture. |
970 scoped_ptr<CopyOutputRequest> request = | 972 std::unique_ptr<CopyOutputRequest> request = |
971 CopyOutputRequest::CreateRequest(base::Bind( | 973 CopyOutputRequest::CreateRequest(base::Bind( |
972 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, | 974 &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback, |
973 base::Unretained(this))); | 975 base::Unretained(this))); |
974 | 976 |
975 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); | 977 gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL(); |
976 gpu::Mailbox mailbox; | 978 gpu::Mailbox mailbox; |
977 gl->GenMailboxCHROMIUM(mailbox.name); | 979 gl->GenMailboxCHROMIUM(mailbox.name); |
978 | 980 |
979 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | 981 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
980 gl->ShallowFlushCHROMIUM(); | 982 gl->ShallowFlushCHROMIUM(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 layer_tree_host()->SetRootLayer(root_); | 1018 layer_tree_host()->SetRootLayer(root_); |
1017 LayerTreeHostCopyRequestTest::SetupTree(); | 1019 LayerTreeHostCopyRequestTest::SetupTree(); |
1018 client_.set_bounds(root_->bounds()); | 1020 client_.set_bounds(root_->bounds()); |
1019 } | 1021 } |
1020 | 1022 |
1021 void BeginTest() override { | 1023 void BeginTest() override { |
1022 callback_count_ = 0; | 1024 callback_count_ = 0; |
1023 PostSetNeedsCommitToMainThread(); | 1025 PostSetNeedsCommitToMainThread(); |
1024 } | 1026 } |
1025 | 1027 |
1026 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 1028 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
1027 EXPECT_TRUE(result->IsEmpty()); | 1029 EXPECT_TRUE(result->IsEmpty()); |
1028 ++callback_count_; | 1030 ++callback_count_; |
1029 } | 1031 } |
1030 | 1032 |
1031 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1033 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1032 MainThreadTaskRunner()->PostTask( | 1034 MainThreadTaskRunner()->PostTask( |
1033 FROM_HERE, | 1035 FROM_HERE, |
1034 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::DidActivate, | 1036 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::DidActivate, |
1035 base::Unretained(this))); | 1037 base::Unretained(this))); |
1036 } | 1038 } |
1037 | 1039 |
1038 void DidActivate() { | 1040 void DidActivate() { |
1039 switch (layer_tree_host()->source_frame_number()) { | 1041 switch (layer_tree_host()->source_frame_number()) { |
1040 case 1: { | 1042 case 1: { |
1041 EXPECT_EQ(0, callback_count_); | 1043 EXPECT_EQ(0, callback_count_); |
1042 // Put a copy request on the layer, but then don't allow any | 1044 // Put a copy request on the layer, but then don't allow any |
1043 // drawing to take place. | 1045 // drawing to take place. |
1044 scoped_ptr<CopyOutputRequest> request = | 1046 std::unique_ptr<CopyOutputRequest> request = |
1045 CopyOutputRequest::CreateRequest( | 1047 CopyOutputRequest::CreateRequest( |
1046 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy:: | 1048 base::Bind(&LayerTreeHostCopyRequestTestDestroyBeforeCopy:: |
1047 CopyOutputCallback, | 1049 CopyOutputCallback, |
1048 base::Unretained(this))); | 1050 base::Unretained(this))); |
1049 copy_layer_->RequestCopyOfOutput(std::move(request)); | 1051 copy_layer_->RequestCopyOfOutput(std::move(request)); |
1050 | 1052 |
1051 layer_tree_host()->SetViewportSize(gfx::Size()); | 1053 layer_tree_host()->SetViewportSize(gfx::Size()); |
1052 break; | 1054 break; |
1053 } | 1055 } |
1054 case 2: | 1056 case 2: |
1055 EXPECT_EQ(0, callback_count_); | 1057 EXPECT_EQ(0, callback_count_); |
1056 // Remove the copy layer before we were able to draw. | 1058 // Remove the copy layer before we were able to draw. |
1057 copy_layer_->RemoveFromParent(); | 1059 copy_layer_->RemoveFromParent(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 layer_tree_host()->SetRootLayer(root_); | 1096 layer_tree_host()->SetRootLayer(root_); |
1095 LayerTreeHostCopyRequestTest::SetupTree(); | 1097 LayerTreeHostCopyRequestTest::SetupTree(); |
1096 client_.set_bounds(root_->bounds()); | 1098 client_.set_bounds(root_->bounds()); |
1097 } | 1099 } |
1098 | 1100 |
1099 void BeginTest() override { | 1101 void BeginTest() override { |
1100 callback_count_ = 0; | 1102 callback_count_ = 0; |
1101 PostSetNeedsCommitToMainThread(); | 1103 PostSetNeedsCommitToMainThread(); |
1102 } | 1104 } |
1103 | 1105 |
1104 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 1106 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
1105 EXPECT_TRUE(result->IsEmpty()); | 1107 EXPECT_TRUE(result->IsEmpty()); |
1106 ++callback_count_; | 1108 ++callback_count_; |
1107 } | 1109 } |
1108 | 1110 |
1109 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { | 1111 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
1110 MainThreadTaskRunner()->PostTask( | 1112 MainThreadTaskRunner()->PostTask( |
1111 FROM_HERE, | 1113 FROM_HERE, |
1112 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::DidActivate, | 1114 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::DidActivate, |
1113 base::Unretained(this))); | 1115 base::Unretained(this))); |
1114 } | 1116 } |
1115 | 1117 |
1116 void DidActivate() { | 1118 void DidActivate() { |
1117 switch (layer_tree_host()->source_frame_number()) { | 1119 switch (layer_tree_host()->source_frame_number()) { |
1118 case 1: { | 1120 case 1: { |
1119 EXPECT_EQ(0, callback_count_); | 1121 EXPECT_EQ(0, callback_count_); |
1120 // Put a copy request on the layer, but then don't allow any | 1122 // Put a copy request on the layer, but then don't allow any |
1121 // drawing to take place. | 1123 // drawing to take place. |
1122 scoped_ptr<CopyOutputRequest> request = | 1124 std::unique_ptr<CopyOutputRequest> request = |
1123 CopyOutputRequest::CreateRequest( | 1125 CopyOutputRequest::CreateRequest( |
1124 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy:: | 1126 base::Bind(&LayerTreeHostCopyRequestTestShutdownBeforeCopy:: |
1125 CopyOutputCallback, | 1127 CopyOutputCallback, |
1126 base::Unretained(this))); | 1128 base::Unretained(this))); |
1127 copy_layer_->RequestCopyOfOutput(std::move(request)); | 1129 copy_layer_->RequestCopyOfOutput(std::move(request)); |
1128 | 1130 |
1129 layer_tree_host()->SetViewportSize(gfx::Size()); | 1131 layer_tree_host()->SetViewportSize(gfx::Size()); |
1130 break; | 1132 break; |
1131 } | 1133 } |
1132 case 2: | 1134 case 2: |
1133 DestroyLayerTreeHost(); | 1135 DestroyLayerTreeHost(); |
1134 // End the test after the copy result has had a chance to get back to | 1136 // End the test after the copy result has had a chance to get back to |
1135 // the main thread. | 1137 // the main thread. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 FROM_HERE, | 1240 FROM_HERE, |
1239 base::Bind( | 1241 base::Bind( |
1240 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest:: | 1242 &LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest:: |
1241 TryEndTest, | 1243 TryEndTest, |
1242 base::Unretained(this))); | 1244 base::Unretained(this))); |
1243 break; | 1245 break; |
1244 } | 1246 } |
1245 return draw_result; | 1247 return draw_result; |
1246 } | 1248 } |
1247 | 1249 |
1248 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 1250 void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) { |
1249 EXPECT_FALSE(TestEnded()); | 1251 EXPECT_FALSE(TestEnded()); |
1250 copy_happened_ = true; | 1252 copy_happened_ = true; |
1251 TryEndTest(); | 1253 TryEndTest(); |
1252 } | 1254 } |
1253 | 1255 |
1254 void TryEndTest() { | 1256 void TryEndTest() { |
1255 if (draw_happened_ && copy_happened_) | 1257 if (draw_happened_ && copy_happened_) |
1256 EndTest(); | 1258 EndTest(); |
1257 } | 1259 } |
1258 | 1260 |
1259 void AfterTest() override {} | 1261 void AfterTest() override {} |
1260 | 1262 |
1261 scoped_refptr<FakePictureLayer> child_; | 1263 scoped_refptr<FakePictureLayer> child_; |
1262 FakeContentLayerClient client_; | 1264 FakeContentLayerClient client_; |
1263 int num_draws_; | 1265 int num_draws_; |
1264 bool copy_happened_; | 1266 bool copy_happened_; |
1265 bool draw_happened_; | 1267 bool draw_happened_; |
1266 }; | 1268 }; |
1267 | 1269 |
1268 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1270 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1269 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1271 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
1270 | 1272 |
1271 } // namespace | 1273 } // namespace |
1272 } // namespace cc | 1274 } // namespace cc |
OLD | NEW |