Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 508373002: cc: Single-threaded impl-side painting for unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Swap promise unit test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 virtual void AfterTest() override { EXPECT_EQ(5, num_draws_); } 522 virtual void AfterTest() override { EXPECT_EQ(5, num_draws_); }
523 523
524 private: 524 private:
525 int num_draws_; 525 int num_draws_;
526 const gfx::Size bounds_; 526 const gfx::Size bounds_;
527 const gfx::Rect invalid_rect_; 527 const gfx::Rect invalid_rect_;
528 FakeContentLayerClient client_; 528 FakeContentLayerClient client_;
529 scoped_refptr<ContentLayer> root_layer_; 529 scoped_refptr<ContentLayer> root_layer_;
530 }; 530 };
531 531
532 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw); 532 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F(
533 LayerTreeHostTestSetNextCommitForcesRedraw);
533 534
534 // Tests that if a layer is not drawn because of some reason in the parent then 535 // Tests that if a layer is not drawn because of some reason in the parent then
535 // its damage is preserved until the next time it is drawn. 536 // its damage is preserved until the next time it is drawn.
536 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { 537 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest {
537 public: 538 public:
538 LayerTreeHostTestUndrawnLayersDamageLater() 539 LayerTreeHostTestUndrawnLayersDamageLater()
539 : root_layer_(ContentLayer::Create(&client_)) {} 540 : root_layer_(ContentLayer::Create(&client_)) {}
540 541
541 virtual void SetupTree() override { 542 virtual void SetupTree() override {
542 root_layer_->SetIsDrawable(true); 543 root_layer_->SetIsDrawable(true);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 731
731 virtual void BeginTest() override { 732 virtual void BeginTest() override {
732 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); 733 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
733 layer_tree_host()->set_background_color(SK_ColorGRAY); 734 layer_tree_host()->set_background_color(SK_ColorGRAY);
734 735
735 PostSetNeedsCommitToMainThread(); 736 PostSetNeedsCommitToMainThread();
736 } 737 }
737 738
738 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override { 739 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
739 EXPECT_EQ(frame_count_with_pending_tree_, 0); 740 EXPECT_EQ(frame_count_with_pending_tree_, 0);
740 impl->BlockNotifyReadyToActivateForTesting(true); 741 if (impl->settings().impl_side_painting)
742 impl->BlockNotifyReadyToActivateForTesting(true);
741 } 743 }
742 744
743 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl, 745 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
744 const BeginFrameArgs& args) override { 746 const BeginFrameArgs& args) override {
745 if (impl->pending_tree()) 747 if (impl->pending_tree())
746 frame_count_with_pending_tree_++; 748 frame_count_with_pending_tree_++;
747 749
748 if (frame_count_with_pending_tree_ == 1) { 750 if (frame_count_with_pending_tree_ == 1) {
749 EXPECT_EQ(first_frame_time_.ToInternalValue(), 0); 751 EXPECT_EQ(first_frame_time_.ToInternalValue(), 0);
750 first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time; 752 first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time;
751 } else if (frame_count_with_pending_tree_ == 2) { 753 } else if (frame_count_with_pending_tree_ == 2 &&
754 impl->settings().impl_side_painting) {
752 impl->BlockNotifyReadyToActivateForTesting(false); 755 impl->BlockNotifyReadyToActivateForTesting(false);
753 } 756 }
754 } 757 }
755 758
756 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 759 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
757 if (frame_count_with_pending_tree_ > 1) { 760 if (frame_count_with_pending_tree_ > 1) {
758 EXPECT_NE(first_frame_time_.ToInternalValue(), 0); 761 EXPECT_NE(first_frame_time_.ToInternalValue(), 0);
759 EXPECT_NE(first_frame_time_.ToInternalValue(), 762 EXPECT_NE(first_frame_time_.ToInternalValue(),
760 impl->CurrentBeginFrameArgs().frame_time.ToInternalValue()); 763 impl->CurrentBeginFrameArgs().frame_time.ToInternalValue());
761 EndTest(); 764 EndTest();
762 return; 765 return;
763 } 766 }
764 767
765 EXPECT_FALSE(impl->settings().impl_side_painting); 768 EXPECT_FALSE(impl->settings().impl_side_painting);
766 EndTest(); 769 EndTest();
767 } 770 }
768 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 771 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
769 if (impl->settings().impl_side_painting) 772 if (impl->settings().impl_side_painting)
770 EXPECT_NE(frame_count_with_pending_tree_, 1); 773 EXPECT_NE(frame_count_with_pending_tree_, 1);
771 } 774 }
772 775
773 virtual void AfterTest() override {} 776 virtual void AfterTest() override {}
774 777
775 private: 778 private:
776 int frame_count_with_pending_tree_; 779 int frame_count_with_pending_tree_;
777 base::TimeTicks first_frame_time_; 780 base::TimeTicks first_frame_time_;
778 }; 781 };
779 782
780 SINGLE_AND_MULTI_THREAD_TEST_F( 783 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F(
781 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); 784 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails);
782 785
783 // This test verifies that LayerTreeHostImpl's current frame time gets 786 // This test verifies that LayerTreeHostImpl's current frame time gets
784 // updated in consecutive frames when it draws in each frame. 787 // updated in consecutive frames when it draws in each frame.
785 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { 788 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest {
786 public: 789 public:
787 LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {} 790 LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {}
788 791
789 virtual void BeginTest() override { 792 virtual void BeginTest() override {
790 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); 793 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 2402
2400 virtual bool FillsBoundsCompletely() const override { return false; } 2403 virtual bool FillsBoundsCompletely() const override { return false; }
2401 2404
2402 private: 2405 private:
2403 Layer* layer_; 2406 Layer* layer_;
2404 }; 2407 };
2405 2408
2406 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} 2409 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
2407 2410
2408 virtual void SetupTree() override { 2411 virtual void SetupTree() override {
2409 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_); 2412 if (layer_tree_host()->settings().impl_side_painting) {
2413 scoped_refptr<PictureLayer> root_layer = PictureLayer::Create(&client_);
2414 layer_tree_host()->SetRootLayer(root_layer);
2415 } else {
2416 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_);
2417 layer_tree_host()->SetRootLayer(root_layer);
2418 }
2419 Layer* root_layer = layer_tree_host()->root_layer();
2410 root_layer->SetIsDrawable(true); 2420 root_layer->SetIsDrawable(true);
2411 root_layer->SetBounds(gfx::Size(1, 1)); 2421 root_layer->SetBounds(gfx::Size(1, 1));
2412 2422
2413 layer_tree_host()->SetRootLayer(root_layer); 2423 client_.set_layer(root_layer);
2414 client_.set_layer(root_layer.get());
2415 2424
2416 LayerTreeHostTest::SetupTree(); 2425 LayerTreeHostTest::SetupTree();
2417 } 2426 }
2418 2427
2419 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2428 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2420 virtual void AfterTest() override {} 2429 virtual void AfterTest() override {}
2421 2430
2422 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 2431 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2423 num_commits_++; 2432 num_commits_++;
2424 if (num_commits_ == 1) { 2433 if (num_commits_ == 1) {
2425 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); 2434 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
2426 EXPECT_SIZE_EQ(gfx::SizeF(1, 1), root_layer->bounds()); 2435 EXPECT_SIZE_EQ(gfx::SizeF(1, 1), root_layer->bounds());
2427 } else { 2436 } else {
2428 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); 2437 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
2429 EXPECT_SIZE_EQ(gfx::SizeF(2, 2), root_layer->bounds()); 2438 EXPECT_SIZE_EQ(gfx::SizeF(2, 2), root_layer->bounds());
2430 EndTest(); 2439 EndTest();
2431 } 2440 }
2432 } 2441 }
2433 2442
2434 private: 2443 private:
2435 SetBoundsClient client_; 2444 SetBoundsClient client_;
2436 int num_commits_; 2445 int num_commits_;
2437 }; 2446 };
2438 2447
2439 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents); 2448 SINGLE_AND_MULTI_THREAD_TEST_F(
2449 LayerTreeHostTestChangeLayerPropertiesInPaintContents);
2440 2450
2441 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { 2451 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D {
2442 public: 2452 public:
2443 MockIOSurfaceWebGraphicsContext3D() { 2453 MockIOSurfaceWebGraphicsContext3D() {
2444 test_capabilities_.gpu.iosurface = true; 2454 test_capabilities_.gpu.iosurface = true;
2445 test_capabilities_.gpu.texture_rectangle = true; 2455 test_capabilities_.gpu.texture_rectangle = true;
2446 } 2456 }
2447 2457
2448 virtual GLuint createTexture() override { 2458 virtual GLuint createTexture() override {
2449 return 1; 2459 return 1;
(...skipping 2622 matching lines...) Expand 10 before | Expand all | Expand 10 after
5072 int activation_count_; 5082 int activation_count_;
5073 bool visible_; 5083 bool visible_;
5074 5084
5075 FakeContentLayerClient client_; 5085 FakeContentLayerClient client_;
5076 scoped_refptr<FakePictureLayer> picture_layer_; 5086 scoped_refptr<FakePictureLayer> picture_layer_;
5077 }; 5087 };
5078 5088
5079 // TODO(vmpstr): Enable with single thread impl-side painting. 5089 // TODO(vmpstr): Enable with single thread impl-side painting.
5080 MULTI_THREAD_TEST_F(LayerTreeHostTestActivateOnInvisible); 5090 MULTI_THREAD_TEST_F(LayerTreeHostTestActivateOnInvisible);
5081 5091
5092 // Do a synchronous composite and assert that the swap promise succeeds.
5093 class LayerTreeHostTestSynchronousCompositeSwapPromise
5094 : public LayerTreeHostTest {
5095 public:
5096 LayerTreeHostTestSynchronousCompositeSwapPromise() : commit_count_(0) {}
5097
5098 virtual void InitializeSettings(LayerTreeSettings* settings) override {
5099 settings->single_thread_proxy_scheduler = false;
5100 }
5101
5102 virtual void BeginTest() override {
5103 // Successful composite.
5104 scoped_ptr<SwapPromise> swap_promise0(
5105 new TestSwapPromise(&swap_promise_result_[0]));
5106 layer_tree_host()->QueueSwapPromise(swap_promise0.Pass());
5107 layer_tree_host()->Composite(gfx::FrameTime::Now());
5108
5109 // Fail to swap.
danakj 2014/10/08 19:45:14 add "(no damage)"
5110 scoped_ptr<SwapPromise> swap_promise1(
5111 new TestSwapPromise(&swap_promise_result_[1]));
5112 layer_tree_host()->QueueSwapPromise(swap_promise1.Pass());
5113 layer_tree_host()->SetNeedsCommit();
5114 layer_tree_host()->Composite(gfx::FrameTime::Now());
5115
5116 // Fail to draw.
5117 scoped_ptr<SwapPromise> swap_promise2(
5118 new TestSwapPromise(&swap_promise_result_[2]));
5119 layer_tree_host()->QueueSwapPromise(swap_promise2.Pass());
5120 layer_tree_host()->SetNeedsDisplayOnAllLayers();
5121 layer_tree_host()->SetVisible(false);
5122 layer_tree_host()->Composite(gfx::FrameTime::Now());
5123
5124 EndTest();
5125 }
5126
5127 virtual void DidCommit() override {
5128 commit_count_++;
5129 ASSERT_LE(commit_count_, 3);
5130 }
5131
5132 virtual void AfterTest() override {
5133 EXPECT_EQ(3, commit_count_);
5134
5135 // Initial swap promise should have succeded.
5136 {
5137 base::AutoLock lock(swap_promise_result_[0].lock);
5138 EXPECT_TRUE(swap_promise_result_[0].did_swap_called);
5139 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called);
5140 EXPECT_TRUE(swap_promise_result_[0].dtor_called);
5141 }
5142
5143 // Second swap promise fails to swap.
5144 {
5145 base::AutoLock lock(swap_promise_result_[1].lock);
5146 EXPECT_FALSE(swap_promise_result_[1].did_swap_called);
5147 EXPECT_TRUE(swap_promise_result_[1].did_not_swap_called);
5148 EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[1].reason);
5149 EXPECT_TRUE(swap_promise_result_[1].dtor_called);
5150 }
5151
5152 // Third swap promises also fails to swap (and draw).
5153 {
5154 base::AutoLock lock(swap_promise_result_[2].lock);
5155 EXPECT_FALSE(swap_promise_result_[2].did_swap_called);
5156 EXPECT_TRUE(swap_promise_result_[2].did_not_swap_called);
5157 EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[2].reason);
5158 EXPECT_TRUE(swap_promise_result_[2].dtor_called);
5159 }
5160 }
5161
5162 int commit_count_;
5163 TestSwapPromiseResult swap_promise_result_[3];
5164 };
5165
5166 // Impl-side painting is not supported for synchronous compositing.
5167 SINGLE_THREAD_NOIMPL_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise);
5168
5082 } // namespace cc 5169 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698