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

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

Issue 132163004: Remove WebGraphicsContext3D getter from cc::ContextProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "ui/gfx/vector2d_conversions.h" 58 #include "ui/gfx/vector2d_conversions.h"
59 59
60 using testing::_; 60 using testing::_;
61 using testing::AnyNumber; 61 using testing::AnyNumber;
62 using testing::AtLeast; 62 using testing::AtLeast;
63 using testing::Mock; 63 using testing::Mock;
64 64
65 namespace cc { 65 namespace cc {
66 namespace { 66 namespace {
67 67
68 class LayerTreeHostTest : public LayerTreeTest { 68 class LayerTreeHostTest : public LayerTreeTest {};
69 };
70 69
71 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 70 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
72 // draw with frame 0. 71 // draw with frame 0.
73 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { 72 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest {
74 public: 73 public:
75 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {} 74 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
76 75
77 virtual void BeginTest() OVERRIDE { 76 virtual void BeginTest() OVERRIDE {
78 PostSetNeedsCommitToMainThread(); 77 PostSetNeedsCommitToMainThread();
79 PostSetNeedsCommitToMainThread(); 78 PostSetNeedsCommitToMainThread();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); 268 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw);
270 269
271 // After setNeedsRedrawRect(invalid_rect) the final damage_rect 270 // After setNeedsRedrawRect(invalid_rect) the final damage_rect
272 // must contain invalid_rect. 271 // must contain invalid_rect.
273 class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { 272 class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest {
274 public: 273 public:
275 LayerTreeHostTestSetNeedsRedrawRect() 274 LayerTreeHostTestSetNeedsRedrawRect()
276 : num_draws_(0), 275 : num_draws_(0),
277 bounds_(50, 50), 276 bounds_(50, 50),
278 invalid_rect_(10, 10, 20, 20), 277 invalid_rect_(10, 10, 20, 20),
279 root_layer_(ContentLayer::Create(&client_)) { 278 root_layer_(ContentLayer::Create(&client_)) {}
280 }
281 279
282 virtual void BeginTest() OVERRIDE { 280 virtual void BeginTest() OVERRIDE {
283 root_layer_->SetIsDrawable(true); 281 root_layer_->SetIsDrawable(true);
284 root_layer_->SetBounds(bounds_); 282 root_layer_->SetBounds(bounds_);
285 layer_tree_host()->SetRootLayer(root_layer_); 283 layer_tree_host()->SetRootLayer(root_layer_);
286 layer_tree_host()->SetViewportSize(bounds_); 284 layer_tree_host()->SetViewportSize(bounds_);
287 PostSetNeedsCommitToMainThread(); 285 PostSetNeedsCommitToMainThread();
288 } 286 }
289 287
290 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 288 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
(...skipping 18 matching lines...) Expand all
309 307
310 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 308 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
311 if (!num_draws_) { 309 if (!num_draws_) {
312 PostSetNeedsRedrawRectToMainThread(invalid_rect_); 310 PostSetNeedsRedrawRectToMainThread(invalid_rect_);
313 } else { 311 } else {
314 EndTest(); 312 EndTest();
315 } 313 }
316 num_draws_++; 314 num_draws_++;
317 } 315 }
318 316
319 virtual void AfterTest() OVERRIDE { 317 virtual void AfterTest() OVERRIDE { EXPECT_EQ(2, num_draws_); }
320 EXPECT_EQ(2, num_draws_);
321 }
322 318
323 private: 319 private:
324 int num_draws_; 320 int num_draws_;
325 const gfx::Size bounds_; 321 const gfx::Size bounds_;
326 const gfx::Rect invalid_rect_; 322 const gfx::Rect invalid_rect_;
327 FakeContentLayerClient client_; 323 FakeContentLayerClient client_;
328 scoped_refptr<ContentLayer> root_layer_; 324 scoped_refptr<ContentLayer> root_layer_;
329 }; 325 };
330 326
331 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); 327 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect);
332 328
333 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { 329 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest {
334 public: 330 public:
335 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 331 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
336 settings->layer_transforms_should_scale_layer_contents = true; 332 settings->layer_transforms_should_scale_layer_contents = true;
337 } 333 }
338 334
339 virtual void SetupTree() OVERRIDE { 335 virtual void SetupTree() OVERRIDE {
340 root_layer_ = Layer::Create(); 336 root_layer_ = Layer::Create();
341 root_layer_->SetBounds(gfx::Size(10, 20)); 337 root_layer_->SetBounds(gfx::Size(10, 20));
342 338
343 scaled_layer_ = FakeContentLayer::Create(&client_); 339 scaled_layer_ = FakeContentLayer::Create(&client_);
344 scaled_layer_->SetBounds(gfx::Size(1, 1)); 340 scaled_layer_->SetBounds(gfx::Size(1, 1));
345 root_layer_->AddChild(scaled_layer_); 341 root_layer_->AddChild(scaled_layer_);
346 342
347 layer_tree_host()->SetRootLayer(root_layer_); 343 layer_tree_host()->SetRootLayer(root_layer_);
348 LayerTreeHostTest::SetupTree(); 344 LayerTreeHostTest::SetupTree();
349 } 345 }
350 346
351 virtual void BeginTest() OVERRIDE { 347 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
352 PostSetNeedsCommitToMainThread();
353 }
354 348
355 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 349 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
356 if (host_impl->active_tree()->source_frame_number() == 1) 350 if (host_impl->active_tree()->source_frame_number() == 1)
357 EndTest(); 351 EndTest();
358 } 352 }
359 353
360 virtual void DidCommit() OVERRIDE { 354 virtual void DidCommit() OVERRIDE {
361 switch (layer_tree_host()->source_frame_number()) { 355 switch (layer_tree_host()->source_frame_number()) {
362 case 1: 356 case 1:
363 // Changing the device scale factor causes a commit. It also changes 357 // Changing the device scale factor causes a commit. It also changes
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 paint_scrollbar, has_thumb, root_layer_->id()); 395 paint_scrollbar, has_thumb, root_layer_->id());
402 scrollbar_->SetPosition(gfx::Point(0, 10)); 396 scrollbar_->SetPosition(gfx::Point(0, 10));
403 scrollbar_->SetBounds(gfx::Size(10, 10)); 397 scrollbar_->SetBounds(gfx::Size(10, 10));
404 398
405 root_layer_->AddChild(scrollbar_); 399 root_layer_->AddChild(scrollbar_);
406 400
407 layer_tree_host()->SetRootLayer(root_layer_); 401 layer_tree_host()->SetRootLayer(root_layer_);
408 LayerTreeHostTest::SetupTree(); 402 LayerTreeHostTest::SetupTree();
409 } 403 }
410 404
411 virtual void BeginTest() OVERRIDE { 405 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
412 PostSetNeedsCommitToMainThread();
413 }
414 406
415 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 407 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
416 if (host_impl->active_tree()->source_frame_number() == 1) 408 if (host_impl->active_tree()->source_frame_number() == 1)
417 EndTest(); 409 EndTest();
418 } 410 }
419 411
420 virtual void DidCommit() OVERRIDE { 412 virtual void DidCommit() OVERRIDE {
421 switch (layer_tree_host()->source_frame_number()) { 413 switch (layer_tree_host()->source_frame_number()) {
422 case 1: 414 case 1:
423 // Changing the device scale factor causes a commit. It also changes 415 // Changing the device scale factor causes a commit. It also changes
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 }; 630 };
639 631
640 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackAfterForcedDraw); 632 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackAfterForcedDraw);
641 633
642 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { 634 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest {
643 public: 635 public:
644 LayerTreeHostTestSetNextCommitForcesRedraw() 636 LayerTreeHostTestSetNextCommitForcesRedraw()
645 : num_draws_(0), 637 : num_draws_(0),
646 bounds_(50, 50), 638 bounds_(50, 50),
647 invalid_rect_(10, 10, 20, 20), 639 invalid_rect_(10, 10, 20, 20),
648 root_layer_(ContentLayer::Create(&client_)) { 640 root_layer_(ContentLayer::Create(&client_)) {}
649 }
650 641
651 virtual void BeginTest() OVERRIDE { 642 virtual void BeginTest() OVERRIDE {
652 root_layer_->SetIsDrawable(true); 643 root_layer_->SetIsDrawable(true);
653 root_layer_->SetBounds(bounds_); 644 root_layer_->SetBounds(bounds_);
654 layer_tree_host()->SetRootLayer(root_layer_); 645 layer_tree_host()->SetRootLayer(root_layer_);
655 layer_tree_host()->SetViewportSize(bounds_); 646 layer_tree_host()->SetViewportSize(bounds_);
656 PostSetNeedsCommitToMainThread(); 647 PostSetNeedsCommitToMainThread();
657 } 648 }
658 649
659 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 650 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 case 3: 702 case 3:
712 host_impl->BlockNotifyReadyToActivateForTesting(false); 703 host_impl->BlockNotifyReadyToActivateForTesting(false);
713 break; 704 break;
714 default: 705 default:
715 EndTest(); 706 EndTest();
716 break; 707 break;
717 } 708 }
718 num_draws_++; 709 num_draws_++;
719 } 710 }
720 711
721 virtual void AfterTest() OVERRIDE { 712 virtual void AfterTest() OVERRIDE { EXPECT_EQ(5, num_draws_); }
722 EXPECT_EQ(5, num_draws_);
723 }
724 713
725 private: 714 private:
726 int num_draws_; 715 int num_draws_;
727 const gfx::Size bounds_; 716 const gfx::Size bounds_;
728 const gfx::Rect invalid_rect_; 717 const gfx::Rect invalid_rect_;
729 FakeContentLayerClient client_; 718 FakeContentLayerClient client_;
730 scoped_refptr<ContentLayer> root_layer_; 719 scoped_refptr<ContentLayer> root_layer_;
731 }; 720 };
732 721
733 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw); 722 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw);
734 723
735 // Tests that if a layer is not drawn because of some reason in the parent then 724 // Tests that if a layer is not drawn because of some reason in the parent then
736 // its damage is preserved until the next time it is drawn. 725 // its damage is preserved until the next time it is drawn.
737 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { 726 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest {
738 public: 727 public:
739 LayerTreeHostTestUndrawnLayersDamageLater() 728 LayerTreeHostTestUndrawnLayersDamageLater()
740 : root_layer_(ContentLayer::Create(&client_)) { 729 : root_layer_(ContentLayer::Create(&client_)) {}
741 }
742 730
743 virtual void SetupTree() OVERRIDE { 731 virtual void SetupTree() OVERRIDE {
744 root_layer_->SetIsDrawable(true); 732 root_layer_->SetIsDrawable(true);
745 root_layer_->SetBounds(gfx::Size(50, 50)); 733 root_layer_->SetBounds(gfx::Size(50, 50));
746 layer_tree_host()->SetRootLayer(root_layer_); 734 layer_tree_host()->SetRootLayer(root_layer_);
747 735
748 // The initially transparent layer has a larger child layer, which is 736 // The initially transparent layer has a larger child layer, which is
749 // not initially drawn because of the this (parent) layer. 737 // not initially drawn because of the this (parent) layer.
750 parent_layer_ = FakeContentLayer::Create(&client_); 738 parent_layer_ = FakeContentLayer::Create(&client_);
751 parent_layer_->SetBounds(gfx::Size(15, 15)); 739 parent_layer_->SetBounds(gfx::Size(15, 15));
752 parent_layer_->SetOpacity(0.0f); 740 parent_layer_->SetOpacity(0.0f);
753 root_layer_->AddChild(parent_layer_); 741 root_layer_->AddChild(parent_layer_);
754 742
755 child_layer_ = FakeContentLayer::Create(&client_); 743 child_layer_ = FakeContentLayer::Create(&client_);
756 child_layer_->SetBounds(gfx::Size(25, 25)); 744 child_layer_->SetBounds(gfx::Size(25, 25));
757 parent_layer_->AddChild(child_layer_); 745 parent_layer_->AddChild(child_layer_);
758 746
759 LayerTreeHostTest::SetupTree(); 747 LayerTreeHostTest::SetupTree();
760 } 748 }
761 749
762 virtual void BeginTest() OVERRIDE { 750 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
763 PostSetNeedsCommitToMainThread();
764 }
765 751
766 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 752 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
767 LayerTreeHostImpl::FrameData* frame_data, 753 LayerTreeHostImpl::FrameData* frame_data,
768 bool result) OVERRIDE { 754 bool result) OVERRIDE {
769 EXPECT_TRUE(result); 755 EXPECT_TRUE(result);
770 756
771 gfx::RectF root_damage_rect; 757 gfx::RectF root_damage_rect;
772 if (!frame_data->render_passes.empty()) 758 if (!frame_data->render_passes.empty())
773 root_damage_rect = frame_data->render_passes.back()->damage_rect; 759 root_damage_rect = frame_data->render_passes.back()->damage_rect;
774 760
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 parent_layer_->SetForceRenderSurface(true); 794 parent_layer_->SetForceRenderSurface(true);
809 break; 795 break;
810 case 4: 796 case 4:
811 EndTest(); 797 EndTest();
812 break; 798 break;
813 default: 799 default:
814 NOTREACHED(); 800 NOTREACHED();
815 } 801 }
816 } 802 }
817 803
818
819 virtual void AfterTest() OVERRIDE {} 804 virtual void AfterTest() OVERRIDE {}
820 805
821 private: 806 private:
822 FakeContentLayerClient client_; 807 FakeContentLayerClient client_;
823 scoped_refptr<ContentLayer> root_layer_; 808 scoped_refptr<ContentLayer> root_layer_;
824 scoped_refptr<FakeContentLayer> parent_layer_; 809 scoped_refptr<FakeContentLayer> parent_layer_;
825 scoped_refptr<FakeContentLayer> child_layer_; 810 scoped_refptr<FakeContentLayer> child_layer_;
826 }; 811 };
827 812
828 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); 813 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() 1011 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails()
1027 : frame_count_with_pending_tree_(0) {} 1012 : frame_count_with_pending_tree_(0) {}
1028 1013
1029 virtual void BeginTest() OVERRIDE { 1014 virtual void BeginTest() OVERRIDE {
1030 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); 1015 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
1031 layer_tree_host()->set_background_color(SK_ColorGRAY); 1016 layer_tree_host()->set_background_color(SK_ColorGRAY);
1032 1017
1033 PostSetNeedsCommitToMainThread(); 1018 PostSetNeedsCommitToMainThread();
1034 } 1019 }
1035 1020
1036 virtual void BeginCommitOnThread(LayerTreeHostImpl *impl) OVERRIDE { 1021 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1037 EXPECT_EQ(frame_count_with_pending_tree_, 0); 1022 EXPECT_EQ(frame_count_with_pending_tree_, 0);
1038 impl->BlockNotifyReadyToActivateForTesting(true); 1023 impl->BlockNotifyReadyToActivateForTesting(true);
1039 } 1024 }
1040 1025
1041 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl, 1026 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
1042 const BeginFrameArgs& args) OVERRIDE { 1027 const BeginFrameArgs& args) OVERRIDE {
1043 if (impl->pending_tree()) 1028 if (impl->pending_tree())
1044 frame_count_with_pending_tree_++; 1029 frame_count_with_pending_tree_++;
1045 1030
1046 if (frame_count_with_pending_tree_ == 2) 1031 if (frame_count_with_pending_tree_ == 2)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 } 1081 }
1097 1082
1098 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1083 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1099 frame_++; 1084 frame_++;
1100 if (frame_ == 1) { 1085 if (frame_ == 1) {
1101 first_frame_time_ = impl->CurrentFrameTimeTicks(); 1086 first_frame_time_ = impl->CurrentFrameTimeTicks();
1102 impl->SetNeedsRedraw(); 1087 impl->SetNeedsRedraw();
1103 1088
1104 // Since we might use a low-resolution clock on Windows, we need to 1089 // Since we might use a low-resolution clock on Windows, we need to
1105 // make sure that the clock has incremented past first_frame_time_. 1090 // make sure that the clock has incremented past first_frame_time_.
1106 while (first_frame_time_ == gfx::FrameTime::Now()) {} 1091 while (first_frame_time_ == gfx::FrameTime::Now()) {
1092 }
1107 1093
1108 return; 1094 return;
1109 } 1095 }
1110 1096
1111 EXPECT_NE(first_frame_time_, impl->CurrentFrameTimeTicks()); 1097 EXPECT_NE(first_frame_time_, impl->CurrentFrameTimeTicks());
1112 EndTest(); 1098 EndTest();
1113 } 1099 }
1114 1100
1115 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1101 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1116 // Ensure there isn't a commit between the two draws, to ensure that a 1102 // Ensure there isn't a commit between the two draws, to ensure that a
1117 // commit isn't required for updating the current frame time. We can 1103 // commit isn't required for updating the current frame time. We can
1118 // only check for this in the multi-threaded case, since in the single- 1104 // only check for this in the multi-threaded case, since in the single-
1119 // threaded case there will always be a commit between consecutive draws. 1105 // threaded case there will always be a commit between consecutive draws.
1120 if (HasImplThread()) 1106 if (HasImplThread())
1121 EXPECT_EQ(0, frame_); 1107 EXPECT_EQ(0, frame_);
1122 } 1108 }
1123 1109
1124 virtual void AfterTest() OVERRIDE {} 1110 virtual void AfterTest() OVERRIDE {}
1125 1111
1126 private: 1112 private:
1127 int frame_; 1113 int frame_;
1128 base::TimeTicks first_frame_time_; 1114 base::TimeTicks first_frame_time_;
1129 }; 1115 };
1130 1116
1131 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw); 1117 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw);
1132 1118
1133 // Verifies that StartPageScaleAnimation events propagate correctly 1119 // Verifies that StartPageScaleAnimation events propagate correctly
1134 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor. 1120 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor.
1135 class LayerTreeHostTestStartPageScaleAnimation 1121 class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest {
1136 : public LayerTreeHostTest {
1137 public: 1122 public:
1138 LayerTreeHostTestStartPageScaleAnimation() {} 1123 LayerTreeHostTestStartPageScaleAnimation() {}
1139 1124
1140 virtual void SetupTree() OVERRIDE { 1125 virtual void SetupTree() OVERRIDE {
1141 LayerTreeHostTest::SetupTree(); 1126 LayerTreeHostTest::SetupTree();
1142 1127
1143 if (layer_tree_host()->settings().impl_side_painting) { 1128 if (layer_tree_host()->settings().impl_side_painting) {
1144 scoped_refptr<FakePictureLayer> layer = 1129 scoped_refptr<FakePictureLayer> layer =
1145 FakePictureLayer::Create(&client_); 1130 FakePictureLayer::Create(&client_);
1146 layer->set_always_update_resources(true); 1131 layer->set_always_update_resources(true);
1147 scroll_layer_ = layer; 1132 scroll_layer_ = layer;
1148 } else { 1133 } else {
1149 scroll_layer_ = FakeContentLayer::Create(&client_); 1134 scroll_layer_ = FakeContentLayer::Create(&client_);
1150 } 1135 }
1151 1136
1152 scroll_layer_->SetScrollable(true); 1137 scroll_layer_->SetScrollable(true);
1153 scroll_layer_->SetScrollOffset(gfx::Vector2d()); 1138 scroll_layer_->SetScrollOffset(gfx::Vector2d());
1154 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 1139 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
1155 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 2.f); 1140 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 2.f);
1156 } 1141 }
1157 1142
1158 virtual void BeginTest() OVERRIDE { 1143 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1159 PostSetNeedsCommitToMainThread();
1160 }
1161 1144
1162 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 1145 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta,
1163 OVERRIDE { 1146 float scale) OVERRIDE {
1164 gfx::Vector2d offset = scroll_layer_->scroll_offset(); 1147 gfx::Vector2d offset = scroll_layer_->scroll_offset();
1165 scroll_layer_->SetScrollOffset(offset + scroll_delta); 1148 scroll_layer_->SetScrollOffset(offset + scroll_delta);
1166 layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f); 1149 layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f);
1167 } 1150 }
1168 1151
1169 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1152 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1170 // We get one commit before the first draw, and the animation doesn't happen 1153 // We get one commit before the first draw, and the animation doesn't happen
1171 // until the second draw. 1154 // until the second draw.
1172 switch (impl->active_tree()->source_frame_number()) { 1155 switch (impl->active_tree()->source_frame_number()) {
1173 case 0: 1156 case 0:
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 } 1455 }
1473 1456
1474 virtual void BeginTest() OVERRIDE { 1457 virtual void BeginTest() OVERRIDE {
1475 drew_frame_ = -1; 1458 drew_frame_ = -1;
1476 PostSetNeedsCommitToMainThread(); 1459 PostSetNeedsCommitToMainThread();
1477 } 1460 }
1478 1461
1479 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1462 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1480 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1463 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1481 1464
1482 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1465 TestWebGraphicsContext3D* context = TestContext();
1483 impl->output_surface()->context_provider()->Context3d());
1484 1466
1485 switch (impl->active_tree()->source_frame_number()) { 1467 switch (impl->active_tree()->source_frame_number()) {
1486 case 0: 1468 case 0:
1487 // Number of textures should be one for each layer 1469 // Number of textures should be one for each layer
1488 ASSERT_EQ(2u, context->NumTextures()); 1470 ASSERT_EQ(2u, context->NumTextures());
1489 // Number of textures used for commit should be one for each layer. 1471 // Number of textures used for commit should be one for each layer.
1490 EXPECT_EQ(2u, context->NumUsedTextures()); 1472 EXPECT_EQ(2u, context->NumUsedTextures());
1491 // Verify that used texture is correct. 1473 // Verify that used texture is correct.
1492 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1474 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1493 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1475 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 20 matching lines...) Expand all
1514 case 2: 1496 case 2:
1515 EndTest(); 1497 EndTest();
1516 break; 1498 break;
1517 default: 1499 default:
1518 NOTREACHED(); 1500 NOTREACHED();
1519 break; 1501 break;
1520 } 1502 }
1521 } 1503 }
1522 1504
1523 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1505 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1524 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1506 TestWebGraphicsContext3D* context = TestContext();
1525 impl->output_surface()->context_provider()->Context3d());
1526 1507
1527 if (drew_frame_ == impl->active_tree()->source_frame_number()) { 1508 if (drew_frame_ == impl->active_tree()->source_frame_number()) {
1528 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_; 1509 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_;
1529 return; 1510 return;
1530 } 1511 }
1531 drew_frame_ = impl->active_tree()->source_frame_number(); 1512 drew_frame_ = impl->active_tree()->source_frame_number();
1532 1513
1533 // We draw/ship one texture each frame for each layer. 1514 // We draw/ship one texture each frame for each layer.
1534 EXPECT_EQ(2u, context->NumUsedTextures()); 1515 EXPECT_EQ(2u, context->NumUsedTextures());
1535 context->ResetUsedTextures(); 1516 context->ResetUsedTextures();
(...skipping 15 matching lines...) Expand all
1551 1532
1552 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1533 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1553 LayerTreeHostTestDirectRendererAtomicCommit); 1534 LayerTreeHostTestDirectRendererAtomicCommit);
1554 1535
1555 class LayerTreeHostTestDelegatingRendererAtomicCommit 1536 class LayerTreeHostTestDelegatingRendererAtomicCommit
1556 : public LayerTreeHostTestDirectRendererAtomicCommit { 1537 : public LayerTreeHostTestDirectRendererAtomicCommit {
1557 public: 1538 public:
1558 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1539 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1559 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1540 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1560 1541
1561 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1542 TestWebGraphicsContext3D* context = TestContext();
1562 impl->output_surface()->context_provider()->Context3d());
1563 1543
1564 switch (impl->active_tree()->source_frame_number()) { 1544 switch (impl->active_tree()->source_frame_number()) {
1565 case 0: 1545 case 0:
1566 // Number of textures should be one for each layer 1546 // Number of textures should be one for each layer
1567 ASSERT_EQ(2u, context->NumTextures()); 1547 ASSERT_EQ(2u, context->NumTextures());
1568 // Number of textures used for commit should be one for each layer. 1548 // Number of textures used for commit should be one for each layer.
1569 EXPECT_EQ(2u, context->NumUsedTextures()); 1549 EXPECT_EQ(2u, context->NumUsedTextures());
1570 // Verify that used texture is correct. 1550 // Verify that used texture is correct.
1571 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1551 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1572 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1552 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 child_ = FakeContentLayer::Create(&client_); 1620 child_ = FakeContentLayer::Create(&client_);
1641 child_->SetPosition(gfx::Point(0, 10)); 1621 child_->SetPosition(gfx::Point(0, 10));
1642 child_->SetBounds(gfx::Size(3, 10)); 1622 child_->SetBounds(gfx::Size(3, 10));
1643 1623
1644 parent_->AddChild(child_); 1624 parent_->AddChild(child_);
1645 1625
1646 layer_tree_host()->SetRootLayer(parent_); 1626 layer_tree_host()->SetRootLayer(parent_);
1647 LayerTreeHostTest::SetupTree(); 1627 LayerTreeHostTest::SetupTree();
1648 } 1628 }
1649 1629
1650 virtual void BeginTest() OVERRIDE { 1630 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1651 PostSetNeedsCommitToMainThread();
1652 }
1653 1631
1654 virtual void DidCommitAndDrawFrame() OVERRIDE { 1632 virtual void DidCommitAndDrawFrame() OVERRIDE {
1655 switch (layer_tree_host()->source_frame_number()) { 1633 switch (layer_tree_host()->source_frame_number()) {
1656 case 1: 1634 case 1:
1657 parent_->SetNeedsDisplay(); 1635 parent_->SetNeedsDisplay();
1658 child_->SetNeedsDisplay(); 1636 child_->SetNeedsDisplay();
1659 break; 1637 break;
1660 case 2: 1638 case 2:
1661 // Damage part of layers. 1639 // Damage part of layers.
1662 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); 1640 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f));
(...skipping 11 matching lines...) Expand all
1674 break; 1652 break;
1675 default: 1653 default:
1676 NOTREACHED() << layer_tree_host()->source_frame_number(); 1654 NOTREACHED() << layer_tree_host()->source_frame_number();
1677 break; 1655 break;
1678 } 1656 }
1679 } 1657 }
1680 1658
1681 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1659 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1682 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); 1660 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates);
1683 1661
1684 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1662 TestWebGraphicsContext3D* context = TestContext();
1685 impl->output_surface()->context_provider()->Context3d());
1686 1663
1687 switch (impl->active_tree()->source_frame_number()) { 1664 switch (impl->active_tree()->source_frame_number()) {
1688 case 0: 1665 case 0:
1689 // Number of textures should be one for each layer. 1666 // Number of textures should be one for each layer.
1690 ASSERT_EQ(2u, context->NumTextures()); 1667 ASSERT_EQ(2u, context->NumTextures());
1691 // Number of textures used for commit should be one for each layer. 1668 // Number of textures used for commit should be one for each layer.
1692 EXPECT_EQ(2u, context->NumUsedTextures()); 1669 EXPECT_EQ(2u, context->NumUsedTextures());
1693 // Verify that used textures are correct. 1670 // Verify that used textures are correct.
1694 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1671 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1695 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1672 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 break; 1742 break;
1766 default: 1743 default:
1767 NOTREACHED(); 1744 NOTREACHED();
1768 break; 1745 break;
1769 } 1746 }
1770 } 1747 }
1771 1748
1772 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1749 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1773 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); 1750 EXPECT_LT(impl->active_tree()->source_frame_number(), 5);
1774 1751
1775 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1752 TestWebGraphicsContext3D* context = TestContext();
1776 impl->output_surface()->context_provider()->Context3d());
1777 1753
1778 // Number of textures used for drawing should one per layer except for 1754 // Number of textures used for drawing should one per layer except for
1779 // frame 3 where the viewport only contains one layer. 1755 // frame 3 where the viewport only contains one layer.
1780 if (impl->active_tree()->source_frame_number() == 3) { 1756 if (impl->active_tree()->source_frame_number() == 3) {
1781 EXPECT_EQ(1u, context->NumUsedTextures()); 1757 EXPECT_EQ(1u, context->NumUsedTextures());
1782 } else { 1758 } else {
1783 EXPECT_EQ(2u, context->NumUsedTextures()) << 1759 EXPECT_EQ(2u, context->NumUsedTextures())
1784 "For frame " << impl->active_tree()->source_frame_number(); 1760 << "For frame " << impl->active_tree()->source_frame_number();
1785 } 1761 }
1786 1762
1787 context->ResetUsedTextures(); 1763 context->ResetUsedTextures();
1788 } 1764 }
1789 1765
1790 virtual void AfterTest() OVERRIDE {} 1766 virtual void AfterTest() OVERRIDE {}
1791 1767
1792 private: 1768 private:
1793 FakeContentLayerClient client_; 1769 FakeContentLayerClient client_;
1794 scoped_refptr<FakeContentLayer> parent_; 1770 scoped_refptr<FakeContentLayer> parent_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 replica_layer1_ = FakeContentLayer::Create(&client_); 1857 replica_layer1_ = FakeContentLayer::Create(&client_);
1882 surface_layer1_->SetReplicaLayer(replica_layer1_.get()); 1858 surface_layer1_->SetReplicaLayer(replica_layer1_.get());
1883 1859
1884 replica_layer2_ = FakeContentLayer::Create(&client_); 1860 replica_layer2_ = FakeContentLayer::Create(&client_);
1885 surface_layer2_->SetReplicaLayer(replica_layer2_.get()); 1861 surface_layer2_->SetReplicaLayer(replica_layer2_.get());
1886 1862
1887 layer_tree_host()->SetRootLayer(root_layer_); 1863 layer_tree_host()->SetRootLayer(root_layer_);
1888 LayerTreeHostTest::SetupTree(); 1864 LayerTreeHostTest::SetupTree();
1889 } 1865 }
1890 1866
1891 virtual void BeginTest() OVERRIDE { 1867 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1892 PostSetNeedsCommitToMainThread();
1893 }
1894 1868
1895 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1869 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1896 Renderer* renderer = host_impl->renderer(); 1870 Renderer* renderer = host_impl->renderer();
1897 RenderPass::Id surface1_render_pass_id = host_impl->active_tree() 1871 RenderPass::Id surface1_render_pass_id = host_impl->active_tree()
1898 ->root_layer()->children()[0]->render_surface()->RenderPassId(); 1872 ->root_layer()
1899 RenderPass::Id surface2_render_pass_id = 1873 ->children()[0]
1900 host_impl->active_tree()->root_layer()->children()[0]->children()[0] 1874 ->render_surface()
1901 ->render_surface()->RenderPassId(); 1875 ->RenderPassId();
1876 RenderPass::Id surface2_render_pass_id = host_impl->active_tree()
1877 ->root_layer()
1878 ->children()[0]
1879 ->children()[0]
1880 ->render_surface()
1881 ->RenderPassId();
1902 1882
1903 switch (host_impl->active_tree()->source_frame_number()) { 1883 switch (host_impl->active_tree()->source_frame_number()) {
1904 case 0: 1884 case 0:
1905 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( 1885 EXPECT_TRUE(
1906 surface1_render_pass_id)); 1886 renderer->HasAllocatedResourcesForTesting(surface1_render_pass_id));
1907 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( 1887 EXPECT_TRUE(
1908 surface2_render_pass_id)); 1888 renderer->HasAllocatedResourcesForTesting(surface2_render_pass_id));
1909 1889
1910 // Reduce the memory limit to only fit the root layer and one render 1890 // Reduce the memory limit to only fit the root layer and one render
1911 // surface. This prevents any contents drawing into surfaces 1891 // surface. This prevents any contents drawing into surfaces
1912 // from being allocated. 1892 // from being allocated.
1913 host_impl->SetMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 * 2)); 1893 host_impl->SetMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 * 2));
1914 break; 1894 break;
1915 case 1: 1895 case 1:
1916 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( 1896 EXPECT_FALSE(
1917 surface1_render_pass_id)); 1897 renderer->HasAllocatedResourcesForTesting(surface1_render_pass_id));
1918 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( 1898 EXPECT_FALSE(
1919 surface2_render_pass_id)); 1899 renderer->HasAllocatedResourcesForTesting(surface2_render_pass_id));
1920 1900
1921 EndTest(); 1901 EndTest();
1922 break; 1902 break;
1923 } 1903 }
1924 } 1904 }
1925 1905
1926 virtual void DidCommitAndDrawFrame() OVERRIDE { 1906 virtual void DidCommitAndDrawFrame() OVERRIDE {
1927 if (layer_tree_host()->source_frame_number() < 2) 1907 if (layer_tree_host()->source_frame_number() < 2)
1928 root_layer_->SetNeedsDisplay(); 1908 root_layer_->SetNeedsDisplay();
1929 } 1909 }
(...skipping 15 matching lines...) Expand all
1945 // Surfaces don't exist with a delegated renderer. 1925 // Surfaces don't exist with a delegated renderer.
1946 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1926 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1947 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit); 1927 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit);
1948 1928
1949 class EvictionTestLayer : public Layer { 1929 class EvictionTestLayer : public Layer {
1950 public: 1930 public:
1951 static scoped_refptr<EvictionTestLayer> Create() { 1931 static scoped_refptr<EvictionTestLayer> Create() {
1952 return make_scoped_refptr(new EvictionTestLayer()); 1932 return make_scoped_refptr(new EvictionTestLayer());
1953 } 1933 }
1954 1934
1955 virtual bool Update(ResourceUpdateQueue*, 1935 virtual bool Update(ResourceUpdateQueue*, const OcclusionTracker*) OVERRIDE;
1956 const OcclusionTracker*) OVERRIDE;
1957 virtual bool DrawsContent() const OVERRIDE { return true; } 1936 virtual bool DrawsContent() const OVERRIDE { return true; }
1958 1937
1959 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 1938 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
1960 OVERRIDE; 1939 OVERRIDE;
1961 virtual void PushPropertiesTo(LayerImpl* impl) OVERRIDE; 1940 virtual void PushPropertiesTo(LayerImpl* impl) OVERRIDE;
1962 virtual void SetTexturePriorities(const PriorityCalculator&) OVERRIDE; 1941 virtual void SetTexturePriorities(const PriorityCalculator&) OVERRIDE;
1963 1942
1964 bool HaveBackingTexture() const { 1943 bool HaveBackingTexture() const {
1965 return texture_.get() ? texture_->have_backing_texture() : false; 1944 return texture_.get() ? texture_->have_backing_texture() : false;
1966 } 1945 }
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 2417
2439 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, 2418 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
2440 bool visible) OVERRIDE { 2419 bool visible) OVERRIDE {
2441 if (visible) { 2420 if (visible) {
2442 // One backing should remain unevicted. 2421 // One backing should remain unevicted.
2443 EXPECT_EQ( 2422 EXPECT_EQ(
2444 100u * 100u * 4u * 1u, 2423 100u * 100u * 4u * 1u,
2445 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2424 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2446 } else { 2425 } else {
2447 EXPECT_EQ( 2426 EXPECT_EQ(
2448 0u, 2427 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2449 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2450 } 2428 }
2451 2429
2452 // Make sure that contents textures are marked as having been 2430 // Make sure that contents textures are marked as having been
2453 // purged. 2431 // purged.
2454 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); 2432 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged());
2455 // End the test in this state. 2433 // End the test in this state.
2456 EndTest(); 2434 EndTest();
2457 } 2435 }
2458 2436
2459 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2437 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 2573 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
2596 settings->begin_impl_frame_scheduling_enabled = true; 2574 settings->begin_impl_frame_scheduling_enabled = true;
2597 } 2575 }
2598 2576
2599 virtual void BeginTest() OVERRIDE { 2577 virtual void BeginTest() OVERRIDE {
2600 // This will trigger a SetNeedsBeginImplFrame which will trigger a 2578 // This will trigger a SetNeedsBeginImplFrame which will trigger a
2601 // BeginImplFrame. 2579 // BeginImplFrame.
2602 PostSetNeedsCommitToMainThread(); 2580 PostSetNeedsCommitToMainThread();
2603 } 2581 }
2604 2582
2605 virtual bool PrepareToDrawOnThread( 2583 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2606 LayerTreeHostImpl* host_impl, 2584 LayerTreeHostImpl::FrameData* frame,
2607 LayerTreeHostImpl::FrameData* frame, 2585 bool result) OVERRIDE {
2608 bool result) OVERRIDE {
2609 EndTest(); 2586 EndTest();
2610 return true; 2587 return true;
2611 } 2588 }
2612 2589
2613 virtual void AfterTest() OVERRIDE {} 2590 virtual void AfterTest() OVERRIDE {}
2614 2591
2615 private: 2592 private:
2616 base::TimeTicks frame_time_; 2593 base::TimeTicks frame_time_;
2617 }; 2594 };
2618 2595
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 virtual void DidCommit() OVERRIDE { 2634 virtual void DidCommit() OVERRIDE {
2658 commit_count_++; 2635 commit_count_++;
2659 if (commit_count_ == 4) { 2636 if (commit_count_ == 4) {
2660 // After two aborted commits, request a real commit now to make sure a 2637 // After two aborted commits, request a real commit now to make sure a
2661 // real commit following an aborted commit will still complete and 2638 // real commit following an aborted commit will still complete and
2662 // end the test even when the Impl thread is idle. 2639 // end the test even when the Impl thread is idle.
2663 layer_tree_host()->SetNeedsCommit(); 2640 layer_tree_host()->SetNeedsCommit();
2664 } 2641 }
2665 } 2642 }
2666 2643
2667 virtual void BeginMainFrameAbortedOnThread( 2644 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
2668 LayerTreeHostImpl *host_impl, bool did_handle) OVERRIDE { 2645 bool did_handle) OVERRIDE {
2669 commit_abort_count_++; 2646 commit_abort_count_++;
2670 // Initiate another abortable commit. 2647 // Initiate another abortable commit.
2671 host_impl->SetNeedsCommit(); 2648 host_impl->SetNeedsCommit();
2672 } 2649 }
2673 2650
2674 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2651 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2675 commit_complete_count_++; 2652 commit_complete_count_++;
2676 if (commit_complete_count_ == 1) { 2653 if (commit_complete_count_ == 1) {
2677 // Initiate an abortable commit after the first commit. 2654 // Initiate an abortable commit after the first commit.
2678 host_impl->SetNeedsCommit(); 2655 host_impl->SetNeedsCommit();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 2699
2723 virtual void SetupTree() OVERRIDE { 2700 virtual void SetupTree() OVERRIDE {
2724 LayerTreeHostTest::SetupTree(); 2701 LayerTreeHostTest::SetupTree();
2725 2702
2726 scoped_refptr<Layer> layer = PictureLayer::Create(&client_); 2703 scoped_refptr<Layer> layer = PictureLayer::Create(&client_);
2727 layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); 2704 layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2728 layer->SetBounds(gfx::Size(10, 10)); 2705 layer->SetBounds(gfx::Size(10, 10));
2729 layer_tree_host()->root_layer()->AddChild(layer); 2706 layer_tree_host()->root_layer()->AddChild(layer);
2730 } 2707 }
2731 2708
2732 virtual void BeginTest() OVERRIDE { 2709 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
2733 PostSetNeedsCommitToMainThread();
2734 }
2735 2710
2736 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2711 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2737 EndTest(); 2712 EndTest();
2738 } 2713 }
2739 2714
2740 virtual void AfterTest() OVERRIDE { 2715 virtual void AfterTest() OVERRIDE {}
2741 }
2742 2716
2743 FakeContentLayerClient client_; 2717 FakeContentLayerClient client_;
2744 }; 2718 };
2745 2719
2746 MULTI_THREAD_TEST_F( 2720 MULTI_THREAD_TEST_F(
2747 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); 2721 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation);
2748 2722
2749 class LayerTreeHostTestChangeLayerPropertiesInPaintContents 2723 class LayerTreeHostTestChangeLayerPropertiesInPaintContents
2750 : public LayerTreeHostTest { 2724 : public LayerTreeHostTest {
2751 public: 2725 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 2776
2803 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents); 2777 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents);
2804 2778
2805 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { 2779 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D {
2806 public: 2780 public:
2807 MockIOSurfaceWebGraphicsContext3D() { 2781 MockIOSurfaceWebGraphicsContext3D() {
2808 test_capabilities_.iosurface = true; 2782 test_capabilities_.iosurface = true;
2809 test_capabilities_.texture_rectangle = true; 2783 test_capabilities_.texture_rectangle = true;
2810 } 2784 }
2811 2785
2812 virtual blink::WebGLId createTexture() OVERRIDE { 2786 virtual blink::WebGLId createTexture() OVERRIDE { return 1; }
2813 return 1;
2814 }
2815 2787
2816 MOCK_METHOD1(activeTexture, void(blink::WGC3Denum texture)); 2788 MOCK_METHOD1(activeTexture, void(blink::WGC3Denum texture));
2817 MOCK_METHOD2(bindTexture, void(blink::WGC3Denum target, 2789 MOCK_METHOD2(bindTexture,
2818 blink::WebGLId texture_id)); 2790 void(blink::WGC3Denum target, blink::WebGLId texture_id));
2819 MOCK_METHOD3(texParameteri, void(blink::WGC3Denum target, 2791 MOCK_METHOD3(texParameteri,
2820 blink::WGC3Denum pname, 2792 void(blink::WGC3Denum target,
2821 blink::WGC3Dint param)); 2793 blink::WGC3Denum pname,
2822 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(blink::WGC3Denum target, 2794 blink::WGC3Dint param));
2823 blink::WGC3Dint width, 2795 MOCK_METHOD5(texImageIOSurface2DCHROMIUM,
2824 blink::WGC3Dint height, 2796 void(blink::WGC3Denum target,
2825 blink::WGC3Duint ioSurfaceId, 2797 blink::WGC3Dint width,
2826 blink::WGC3Duint plane)); 2798 blink::WGC3Dint height,
2827 MOCK_METHOD4(drawElements, void(blink::WGC3Denum mode, 2799 blink::WGC3Duint ioSurfaceId,
2828 blink::WGC3Dsizei count, 2800 blink::WGC3Duint plane));
2829 blink::WGC3Denum type, 2801 MOCK_METHOD4(drawElements,
2830 blink::WGC3Dintptr offset)); 2802 void(blink::WGC3Denum mode,
2803 blink::WGC3Dsizei count,
2804 blink::WGC3Denum type,
2805 blink::WGC3Dintptr offset));
2831 MOCK_METHOD1(deleteTexture, void(blink::WGC3Denum texture)); 2806 MOCK_METHOD1(deleteTexture, void(blink::WGC3Denum texture));
2832 }; 2807 };
2833 2808
2834
2835 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { 2809 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
2836 protected: 2810 protected:
2837 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 2811 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurfaceForTest(
2838 OVERRIDE { 2812 bool fallback) OVERRIDE {
2839 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned( 2813 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned(
2840 new MockIOSurfaceWebGraphicsContext3D); 2814 new MockIOSurfaceWebGraphicsContext3D);
2841 mock_context_ = mock_context_owned.get(); 2815 mock_context_ = mock_context_owned.get();
2842 2816
2843 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 2817 return FakeOutputSurface::Create3d(
2844 mock_context_owned.PassAs<TestWebGraphicsContext3D>())); 2818 mock_context_owned.PassAs<TestWebGraphicsContext3D>());
2845 return output_surface.Pass();
2846 } 2819 }
2847 2820
2848 virtual void SetupTree() OVERRIDE { 2821 virtual void SetupTree() OVERRIDE {
2849 LayerTreeHostTest::SetupTree(); 2822 LayerTreeHostTest::SetupTree();
2850 2823
2851 layer_tree_host()->root_layer()->SetIsDrawable(false); 2824 layer_tree_host()->root_layer()->SetIsDrawable(false);
2852 2825
2853 io_surface_id_ = 9; 2826 io_surface_id_ = 9;
2854 io_surface_size_ = gfx::Size(6, 7); 2827 io_surface_size_ = gfx::Size(6, 7);
2855 2828
2856 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create(); 2829 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create();
2857 io_surface_layer->SetBounds(gfx::Size(10, 10)); 2830 io_surface_layer->SetBounds(gfx::Size(10, 10));
2858 io_surface_layer->SetAnchorPoint(gfx::PointF()); 2831 io_surface_layer->SetAnchorPoint(gfx::PointF());
2859 io_surface_layer->SetIsDrawable(true); 2832 io_surface_layer->SetIsDrawable(true);
2860 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); 2833 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_);
2861 layer_tree_host()->root_layer()->AddChild(io_surface_layer); 2834 layer_tree_host()->root_layer()->AddChild(io_surface_layer);
2862 } 2835 }
2863 2836
2864 virtual void BeginTest() OVERRIDE { 2837 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
2865 PostSetNeedsCommitToMainThread();
2866 }
2867 2838
2868 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2839 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2869 // In WillDraw, the IOSurfaceLayer sets up the io surface texture. 2840 // In WillDraw, the IOSurfaceLayer sets up the io surface texture.
2870 2841
2871 EXPECT_CALL(*mock_context_, activeTexture(_)) 2842 EXPECT_CALL(*mock_context_, activeTexture(_)).Times(0);
2872 .Times(0);
2873 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) 2843 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2874 .Times(AtLeast(1)); 2844 .Times(AtLeast(1));
2875 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2845 EXPECT_CALL(*mock_context_,
2876 GL_TEXTURE_MIN_FILTER, 2846 texParameteri(
2877 GL_LINEAR)) 2847 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR))
2878 .Times(1); 2848 .Times(1);
2879 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2849 EXPECT_CALL(*mock_context_,
2880 GL_TEXTURE_MAG_FILTER, 2850 texParameteri(
2881 GL_LINEAR)) 2851 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR))
2882 .Times(1); 2852 .Times(1);
2883 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2853 EXPECT_CALL(*mock_context_,
2884 GL_TEXTURE_WRAP_S, 2854 texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2885 GL_CLAMP_TO_EDGE)) 2855 GL_TEXTURE_WRAP_S,
2886 .Times(1); 2856 GL_CLAMP_TO_EDGE)).Times(1);
2887 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2857 EXPECT_CALL(*mock_context_,
2888 GL_TEXTURE_WRAP_T, 2858 texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2889 GL_CLAMP_TO_EDGE)) 2859 GL_TEXTURE_WRAP_T,
2890 .Times(1); 2860 GL_CLAMP_TO_EDGE)).Times(1);
2891 2861
2892 EXPECT_CALL(*mock_context_, texImageIOSurface2DCHROMIUM( 2862 EXPECT_CALL(*mock_context_,
2893 GL_TEXTURE_RECTANGLE_ARB, 2863 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB,
2894 io_surface_size_.width(), 2864 io_surface_size_.width(),
2895 io_surface_size_.height(), 2865 io_surface_size_.height(),
2896 io_surface_id_, 2866 io_surface_id_,
2897 0)) 2867 0)).Times(1);
2898 .Times(1);
2899 2868
2900 EXPECT_CALL(*mock_context_, bindTexture(_, 0)) 2869 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber());
2901 .Times(AnyNumber());
2902 } 2870 }
2903 2871
2904 virtual bool PrepareToDrawOnThread( 2872 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2905 LayerTreeHostImpl* host_impl, 2873 LayerTreeHostImpl::FrameData* frame,
2906 LayerTreeHostImpl::FrameData* frame, 2874 bool result) OVERRIDE {
2907 bool result) OVERRIDE {
2908 Mock::VerifyAndClearExpectations(&mock_context_); 2875 Mock::VerifyAndClearExpectations(&mock_context_);
2909 2876
2910 // The io surface layer's texture is drawn. 2877 // The io surface layer's texture is drawn.
2911 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)) 2878 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1));
2912 .Times(AtLeast(1));
2913 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) 2879 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2914 .Times(1); 2880 .Times(1);
2915 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) 2881 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _))
2916 .Times(AtLeast(1)); 2882 .Times(AtLeast(1));
2917 2883
2918 return result; 2884 return result;
2919 } 2885 }
2920 2886
2921 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2887 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2922 Mock::VerifyAndClearExpectations(&mock_context_); 2888 Mock::VerifyAndClearExpectations(&mock_context_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
3060 ImplThreadTaskRunner()->PostTask( 3026 ImplThreadTaskRunner()->PostTask(
3061 FROM_HERE, 3027 FROM_HERE,
3062 base::Bind( 3028 base::Bind(
3063 &LayerTreeHostTestDeferredInitialize::DeferredInitializeAndRedraw, 3029 &LayerTreeHostTestDeferredInitialize::DeferredInitializeAndRedraw,
3064 base::Unretained(this), 3030 base::Unretained(this),
3065 base::Unretained(host_impl))); 3031 base::Unretained(host_impl)));
3066 } else if (did_initialize_gl_ && !did_release_gl_) { 3032 } else if (did_initialize_gl_ && !did_release_gl_) {
3067 EXPECT_LE(2u, layer_impl->append_quads_count()); 3033 EXPECT_LE(2u, layer_impl->append_quads_count());
3068 ImplThreadTaskRunner()->PostTask( 3034 ImplThreadTaskRunner()->PostTask(
3069 FROM_HERE, 3035 FROM_HERE,
3070 base::Bind( 3036 base::Bind(&LayerTreeHostTestDeferredInitialize::ReleaseGLAndRedraw,
3071 &LayerTreeHostTestDeferredInitialize::ReleaseGLAndRedraw, 3037 base::Unretained(this),
3072 base::Unretained(this), 3038 base::Unretained(host_impl)));
3073 base::Unretained(host_impl)));
3074 } else if (did_initialize_gl_ && did_release_gl_) { 3039 } else if (did_initialize_gl_ && did_release_gl_) {
3075 EXPECT_LE(3u, layer_impl->append_quads_count()); 3040 EXPECT_LE(3u, layer_impl->append_quads_count());
3076 EndTest(); 3041 EndTest();
3077 } 3042 }
3078 } 3043 }
3079 3044
3080 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { 3045 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) {
3081 EXPECT_FALSE(did_initialize_gl_); 3046 EXPECT_FALSE(did_initialize_gl_);
3082 // SetAndInitializeContext3D calls SetNeedsCommit. 3047 // SetAndInitializeContext3D calls SetNeedsCommit.
3083 FakeOutputSurface* fake_output_surface = 3048 FakeOutputSurface* fake_output_surface =
3084 static_cast<FakeOutputSurface*>(host_impl->output_surface()); 3049 static_cast<FakeOutputSurface*>(host_impl->output_surface());
3085 scoped_refptr<TestContextProvider> context_provider = 3050 scoped_refptr<TestContextProvider> context_provider =
3086 TestContextProvider::Create(); // Not bound to thread. 3051 TestContextProvider::Create(); // Not bound to thread.
3087 EXPECT_TRUE(fake_output_surface->InitializeAndSetContext3d( 3052 EXPECT_TRUE(
3088 context_provider, NULL)); 3053 fake_output_surface->InitializeAndSetContext3d(context_provider, NULL));
3089 did_initialize_gl_ = true; 3054 did_initialize_gl_ = true;
3090 } 3055 }
3091 3056
3092 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { 3057 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) {
3093 EXPECT_TRUE(did_initialize_gl_); 3058 EXPECT_TRUE(did_initialize_gl_);
3094 EXPECT_FALSE(did_release_gl_); 3059 EXPECT_FALSE(did_release_gl_);
3095 // ReleaseGL calls SetNeedsCommit. 3060 // ReleaseGL calls SetNeedsCommit.
3096 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); 3061 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL();
3097 did_release_gl_ = true; 3062 did_release_gl_ = true;
3098 } 3063 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3149 PostSetNeedsCommitToMainThread(); 3114 PostSetNeedsCommitToMainThread();
3150 break; 3115 break;
3151 case 5: 3116 case 5:
3152 ClearResources(); 3117 ClearResources();
3153 EndTest(); 3118 EndTest();
3154 break; 3119 break;
3155 } 3120 }
3156 } 3121 }
3157 3122
3158 void PerformTest(LayerTreeHostImpl* impl) { 3123 void PerformTest(LayerTreeHostImpl* impl) {
3159 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 3124 TestWebGraphicsContext3D* context = TestContext();
3160 impl->output_surface()->context_provider()->Context3d());
3161 3125
3162 int frame = num_commits_; 3126 int frame = num_commits_;
3163 switch (frame) { 3127 switch (frame) {
3164 case 1: 3128 case 1:
3165 ASSERT_EQ(0u, context->NumTextures()); 3129 ASSERT_EQ(0u, context->NumTextures());
3166 break; 3130 break;
3167 case 2: 3131 case 2:
3168 // Created two textures. 3132 // Created two textures.
3169 ASSERT_EQ(2u, context->NumTextures()); 3133 ASSERT_EQ(2u, context->NumTextures());
3170 break; 3134 break;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3232 3196
3233 size_t push_properties_count() const { return push_properties_count_; } 3197 size_t push_properties_count() const { return push_properties_count_; }
3234 void reset_push_properties_count() { push_properties_count_ = 0; } 3198 void reset_push_properties_count() { push_properties_count_ = 0; }
3235 3199
3236 void set_persist_needs_push_properties(bool persist) { 3200 void set_persist_needs_push_properties(bool persist) {
3237 persist_needs_push_properties_ = persist; 3201 persist_needs_push_properties_ = persist;
3238 } 3202 }
3239 3203
3240 private: 3204 private:
3241 PushPropertiesCountingLayer() 3205 PushPropertiesCountingLayer()
3242 : push_properties_count_(0), 3206 : push_properties_count_(0), persist_needs_push_properties_(false) {
3243 persist_needs_push_properties_(false) {
3244 SetAnchorPoint(gfx::PointF()); 3207 SetAnchorPoint(gfx::PointF());
3245 SetBounds(gfx::Size(1, 1)); 3208 SetBounds(gfx::Size(1, 1));
3246 SetIsDrawable(true); 3209 SetIsDrawable(true);
3247 } 3210 }
3248 virtual ~PushPropertiesCountingLayer() {} 3211 virtual ~PushPropertiesCountingLayer() {}
3249 3212
3250 size_t push_properties_count_; 3213 size_t push_properties_count_;
3251 bool persist_needs_push_properties_; 3214 bool persist_needs_push_properties_;
3252 }; 3215 };
3253 3216
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 size_t expected_push_properties_grandchild_; 3402 size_t expected_push_properties_grandchild_;
3440 size_t expected_push_properties_other_root_; 3403 size_t expected_push_properties_other_root_;
3441 size_t expected_push_properties_leaf_layer_; 3404 size_t expected_push_properties_leaf_layer_;
3442 }; 3405 };
3443 3406
3444 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties); 3407 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties);
3445 3408
3446 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed 3409 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
3447 : public LayerTreeHostTest { 3410 : public LayerTreeHostTest {
3448 protected: 3411 protected:
3449 virtual void BeginTest() OVERRIDE { 3412 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
3450 PostSetNeedsCommitToMainThread();
3451 }
3452 3413
3453 virtual void SetupTree() OVERRIDE { 3414 virtual void SetupTree() OVERRIDE {
3454 root_ = Layer::Create(); 3415 root_ = Layer::Create();
3455 root_->SetBounds(gfx::Size(1, 1)); 3416 root_->SetBounds(gfx::Size(1, 1));
3456 3417
3457 bool paint_scrollbar = true; 3418 bool paint_scrollbar = true;
3458 bool has_thumb = false; 3419 bool has_thumb = false;
3459 scrollbar_layer_ = FakePaintedScrollbarLayer::Create( 3420 scrollbar_layer_ = FakePaintedScrollbarLayer::Create(
3460 paint_scrollbar, has_thumb, root_->id()); 3421 paint_scrollbar, has_thumb, root_->id());
3461 3422
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
3943 case 3: 3904 case 3:
3944 EXPECT_EQ(0, callback_count_); 3905 EXPECT_EQ(0, callback_count_);
3945 callback_count_ = 0; 3906 callback_count_ = 0;
3946 EndTest(); 3907 EndTest();
3947 break; 3908 break;
3948 default: 3909 default:
3949 ADD_FAILURE() << num_commits_; 3910 ADD_FAILURE() << num_commits_;
3950 EndTest(); 3911 EndTest();
3951 break; 3912 break;
3952 } 3913 }
3953 return LayerTreeHostTest::PrepareToDrawOnThread(host_impl, frame_data, 3914 return LayerTreeHostTest::PrepareToDrawOnThread(
3954 result); 3915 host_impl, frame_data, result);
3955 } 3916 }
3956 3917
3957 virtual void AfterTest() OVERRIDE { 3918 virtual void AfterTest() OVERRIDE { EXPECT_EQ(3, num_commits_); }
3958 EXPECT_EQ(3, num_commits_); 3919
3920 void SetCallback(bool enable) {
3921 output_surface()->SetTreeActivationCallback(
3922 enable
3923 ? base::Bind(
3924 &LayerTreeHostTestTreeActivationCallback::ActivationCallback,
3925 base::Unretained(this))
3926 : base::Closure());
3959 } 3927 }
3960 3928
3961 void SetCallback(bool enable) { 3929 void ActivationCallback() { ++callback_count_; }
3962 output_surface()->SetTreeActivationCallback(enable ?
3963 base::Bind(&LayerTreeHostTestTreeActivationCallback::ActivationCallback,
3964 base::Unretained(this)) :
3965 base::Closure());
3966 }
3967
3968 void ActivationCallback() {
3969 ++callback_count_;
3970 }
3971 3930
3972 int num_commits_; 3931 int num_commits_;
3973 int callback_count_; 3932 int callback_count_;
3974 }; 3933 };
3975 3934
3976 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { 3935 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) {
3977 RunTest(true, false, true); 3936 RunTest(true, false, true);
3978 } 3937 }
3979 3938
3980 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { 3939 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) {
3981 RunTest(true, true, true); 3940 RunTest(true, true, true);
3982 } 3941 }
3983 3942
3984 class LayerInvalidateCausesDraw : public LayerTreeHostTest { 3943 class LayerInvalidateCausesDraw : public LayerTreeHostTest {
3985 public: 3944 public:
3986 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {} 3945 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {}
3987 3946
3988 virtual void BeginTest() OVERRIDE { 3947 virtual void BeginTest() OVERRIDE {
3989 ASSERT_TRUE(!!invalidate_layer_) 3948 ASSERT_TRUE(!!invalidate_layer_)
3990 << "Derived tests must set this in SetupTree"; 3949 << "Derived tests must set this in SetupTree";
3991 3950
3992 // One initial commit. 3951 // One initial commit.
3993 PostSetNeedsCommitToMainThread(); 3952 PostSetNeedsCommitToMainThread();
3994 } 3953 }
3995 3954
3996 virtual void DidCommitAndDrawFrame() OVERRIDE { 3955 virtual void DidCommitAndDrawFrame() OVERRIDE {
3997 // After commit, invalidate the layer. This should cause a commit. 3956 // After commit, invalidate the layer. This should cause a commit.
3998 if (layer_tree_host()->source_frame_number() == 1) 3957 if (layer_tree_host()->source_frame_number() == 1)
3999 invalidate_layer_->SetNeedsDisplay(); 3958 invalidate_layer_->SetNeedsDisplay();
4000 } 3959 }
4001 3960
4002 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 3961 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4003 num_draws_++; 3962 num_draws_++;
4004 if (impl->active_tree()->source_frame_number() == 1) 3963 if (impl->active_tree()->source_frame_number() == 1)
4005 EndTest(); 3964 EndTest();
4006 } 3965 }
4007 3966
4008 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 3967 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4009 num_commits_++; 3968 num_commits_++;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4233 // Commits can only be aborted when using the thread proxy. 4192 // Commits can only be aborted when using the thread proxy.
4234 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); 4193 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures);
4235 4194
4236 class LayerTreeHostTestMaxTransferBufferUsageBytes : public LayerTreeHostTest { 4195 class LayerTreeHostTestMaxTransferBufferUsageBytes : public LayerTreeHostTest {
4237 protected: 4196 protected:
4238 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 4197 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
4239 settings->impl_side_painting = true; 4198 settings->impl_side_painting = true;
4240 settings->default_tile_size = gfx::Size(128, 128); 4199 settings->default_tile_size = gfx::Size(128, 128);
4241 } 4200 }
4242 4201
4243 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 4202 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurfaceForTest(
4244 OVERRIDE { 4203 bool fallback) OVERRIDE {
4245 scoped_refptr<TestContextProvider> context_provider = 4204 scoped_refptr<TestContextProvider> context_provider =
4246 TestContextProvider::Create(); 4205 TestContextProvider::Create();
4247 context_provider->SetMaxTransferBufferUsageBytes(1024 * 1024); 4206 context_provider->SetMaxTransferBufferUsageBytes(1024 * 1024);
4248 return FakeOutputSurface::Create3d(context_provider) 4207 return FakeOutputSurface::Create3d(context_provider);
4249 .PassAs<OutputSurface>();
4250 } 4208 }
4251 4209
4252 virtual void SetupTree() OVERRIDE { 4210 virtual void SetupTree() OVERRIDE {
4253 scoped_refptr<FakePictureLayer> root_layer = 4211 scoped_refptr<FakePictureLayer> root_layer =
4254 FakePictureLayer::Create(&client_); 4212 FakePictureLayer::Create(&client_);
4255 root_layer->SetBounds(gfx::Size(6000, 6000)); 4213 root_layer->SetBounds(gfx::Size(6000, 6000));
4256 root_layer->SetIsDrawable(true); 4214 root_layer->SetIsDrawable(true);
4257 4215
4258 layer_tree_host()->SetRootLayer(root_layer); 4216 layer_tree_host()->SetRootLayer(root_layer);
4259 LayerTreeHostTest::SetupTree(); 4217 LayerTreeHostTest::SetupTree();
4260 } 4218 }
4261 4219
4262 virtual void BeginTest() OVERRIDE { 4220 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4263 PostSetNeedsCommitToMainThread();
4264 }
4265 4221
4266 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4222 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4267 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 4223 TestWebGraphicsContext3D* context = TestContext();
4268 impl->output_surface()->context_provider()->Context3d());
4269 4224
4270 // Expect that the transfer buffer memory used is equal to the 4225 // Expect that the transfer buffer memory used is equal to the
4271 // MaxTransferBufferUsageBytes value set in CreateOutputSurface. 4226 // MaxTransferBufferUsageBytes value set in CreateOutputSurface.
4272 // NOTE: This is now 1/2 due to raster memory limit in TileManager. 4227 // NOTE: This is now 1/2 due to raster memory limit in TileManager.
4273 // Only half the limit will be reached unless the task set 4228 // Only half the limit will be reached unless the task set
4274 // thrashes to a completly new set of tiles. 4229 // thrashes to a completly new set of tiles.
4275 EXPECT_EQ(512 * 1024u, 4230 EXPECT_EQ(512 * 1024u, context->GetPeakTransferBufferMemoryUsedBytes());
4276 context->GetPeakTransferBufferMemoryUsedBytes());
4277 EndTest(); 4231 EndTest();
4278 } 4232 }
4279 4233
4280 virtual void AfterTest() OVERRIDE {} 4234 virtual void AfterTest() OVERRIDE {}
4281 4235
4282 private: 4236 private:
4283 FakeContentLayerClient client_; 4237 FakeContentLayerClient client_;
4284 }; 4238 };
4285 4239
4286 // Impl-side painting is a multi-threaded compositor feature. 4240 // Impl-side painting is a multi-threaded compositor feature.
4287 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes); 4241 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes);
4288 4242
4289 // Test ensuring that memory limits are sent to the prioritized resource 4243 // Test ensuring that memory limits are sent to the prioritized resource
4290 // manager. 4244 // manager.
4291 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest { 4245 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest {
4292 public: 4246 public:
4293 LayerTreeHostTestMemoryLimits() : num_commits_(0) {} 4247 LayerTreeHostTestMemoryLimits() : num_commits_(0) {}
4294 4248
4295 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4249 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4296 4250
4297 virtual void DidCommit() OVERRIDE { 4251 virtual void DidCommit() OVERRIDE {
4298 int frame = num_commits_; 4252 int frame = num_commits_;
4299 switch (frame) { 4253 switch (frame) {
4300 case 0: 4254 case 0:
4301 // Verify default values. 4255 // Verify default values.
4302 EXPECT_EQ( 4256 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4303 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4257 layer_tree_host()
4304 layer_tree_host()->contents_texture_manager()-> 4258 ->contents_texture_manager()
4305 MaxMemoryLimitBytes()); 4259 ->MaxMemoryLimitBytes());
4306 EXPECT_EQ( 4260 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4307 PriorityCalculator::AllowEverythingCutoff(), 4261 layer_tree_host()
4308 layer_tree_host()->contents_texture_manager()-> 4262 ->contents_texture_manager()
4309 ExternalPriorityCutoff()); 4263 ->ExternalPriorityCutoff());
4310 PostSetNeedsCommitToMainThread(); 4264 PostSetNeedsCommitToMainThread();
4311 break; 4265 break;
4312 case 1: 4266 case 1:
4313 // The values should remain the same until the commit after the policy 4267 // The values should remain the same until the commit after the policy
4314 // is changed. 4268 // is changed.
4315 EXPECT_EQ( 4269 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4316 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4270 layer_tree_host()
4317 layer_tree_host()->contents_texture_manager()-> 4271 ->contents_texture_manager()
4318 MaxMemoryLimitBytes()); 4272 ->MaxMemoryLimitBytes());
4319 EXPECT_EQ( 4273 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4320 PriorityCalculator::AllowEverythingCutoff(), 4274 layer_tree_host()
4321 layer_tree_host()->contents_texture_manager()-> 4275 ->contents_texture_manager()
4322 ExternalPriorityCutoff()); 4276 ->ExternalPriorityCutoff());
4323 break; 4277 break;
4324 case 2: 4278 case 2:
4325 // Verify values were correctly passed. 4279 // Verify values were correctly passed.
4326 EXPECT_EQ( 4280 EXPECT_EQ(16u * 1024u * 1024u,
4327 16u*1024u*1024u, 4281 layer_tree_host()
4328 layer_tree_host()->contents_texture_manager()-> 4282 ->contents_texture_manager()
4329 MaxMemoryLimitBytes()); 4283 ->MaxMemoryLimitBytes());
4330 EXPECT_EQ( 4284 EXPECT_EQ(PriorityCalculator::AllowVisibleAndNearbyCutoff(),
4331 PriorityCalculator::AllowVisibleAndNearbyCutoff(), 4285 layer_tree_host()
4332 layer_tree_host()->contents_texture_manager()-> 4286 ->contents_texture_manager()
4333 ExternalPriorityCutoff()); 4287 ->ExternalPriorityCutoff());
4334 EndTest(); 4288 EndTest();
4335 break; 4289 break;
4336 case 3: 4290 case 3:
4337 // Make sure no extra commits happen. 4291 // Make sure no extra commits happen.
4338 NOTREACHED(); 4292 NOTREACHED();
4339 break; 4293 break;
4340 } 4294 }
4341 4295
4342 ++num_commits_; 4296 ++num_commits_;
4343 } 4297 }
4344 4298
4345 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4299 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4346 int frame = num_commits_; 4300 int frame = num_commits_;
4347 switch (frame) { 4301 switch (frame) {
4348 case 0: 4302 case 0:
4349 break; 4303 break;
4350 case 1: 4304 case 1:
4351 // This will trigger a commit because the priority cutoff has changed. 4305 // This will trigger a commit because the priority cutoff has changed.
4352 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4306 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4353 16u*1024u*1024u, 4307 16u * 1024u * 1024u,
4354 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4308 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4355 1000)); 4309 1000));
4356 break; 4310 break;
4357 case 2: 4311 case 2:
4358 // This will not trigger a commit because the priority cutoff has not 4312 // This will not trigger a commit because the priority cutoff has not
4359 // changed, and there is already enough memory for all allocations. 4313 // changed, and there is already enough memory for all allocations.
4360 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4314 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4361 32u*1024u*1024u, 4315 32u * 1024u * 1024u,
4362 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4316 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4363 1000)); 4317 1000));
4364 break; 4318 break;
4365 case 3: 4319 case 3:
4366 NOTREACHED(); 4320 NOTREACHED();
4367 break; 4321 break;
4368 } 4322 }
4369 } 4323 }
4370 4324
4371 virtual void AfterTest() OVERRIDE {} 4325 virtual void AfterTest() OVERRIDE {}
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
4450 virtual void SetupTree() OVERRIDE { 4404 virtual void SetupTree() OVERRIDE {
4451 LayerTreeHostTest::SetupTree(); 4405 LayerTreeHostTest::SetupTree();
4452 root_layer_ = FakeContentLayer::Create(&client_); 4406 root_layer_ = FakeContentLayer::Create(&client_);
4453 root_layer_->SetBounds(gfx::Size(10, 10)); 4407 root_layer_->SetBounds(gfx::Size(10, 10));
4454 root_layer_->SetIsDrawable(false); 4408 root_layer_->SetIsDrawable(false);
4455 root_layer_->SetHaveWheelEventHandlers(true); 4409 root_layer_->SetHaveWheelEventHandlers(true);
4456 layer_tree_host()->SetRootLayer(root_layer_); 4410 layer_tree_host()->SetRootLayer(root_layer_);
4457 LayerTreeHostTest::SetupTree(); 4411 LayerTreeHostTest::SetupTree();
4458 } 4412 }
4459 4413
4460 virtual void BeginTest() OVERRIDE { 4414 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4461 PostSetNeedsCommitToMainThread();
4462 }
4463 4415
4464 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4416 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4465 FakeContentLayerImpl* layer_impl = 4417 FakeContentLayerImpl* layer_impl =
4466 static_cast<FakeContentLayerImpl*>(impl->RootLayer()); 4418 static_cast<FakeContentLayerImpl*>(impl->RootLayer());
4467 EXPECT_FALSE(layer_impl->DrawsContent()); 4419 EXPECT_FALSE(layer_impl->DrawsContent());
4468 EXPECT_EQ(0u, layer_impl->append_quads_count()); 4420 EXPECT_EQ(0u, layer_impl->append_quads_count());
4469 } 4421 }
4470 4422
4471 virtual void DidCommit() OVERRIDE { 4423 virtual void DidCommit() OVERRIDE {
4472 // The layer is not drawable, so it should not be updated. 4424 // The layer is not drawable, so it should not be updated.
4473 EXPECT_EQ(0u, root_layer_->update_count()); 4425 EXPECT_EQ(0u, root_layer_->update_count());
4474 EndTest(); 4426 EndTest();
4475 } 4427 }
4476 virtual void AfterTest() OVERRIDE {} 4428 virtual void AfterTest() OVERRIDE {}
4477 4429
4478 private: 4430 private:
4479 FakeContentLayerClient client_; 4431 FakeContentLayerClient client_;
4480 scoped_refptr<FakeContentLayer> root_layer_; 4432 scoped_refptr<FakeContentLayer> root_layer_;
4481 }; 4433 };
4482 4434
4483 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoQuadsForEmptyLayer); 4435 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoQuadsForEmptyLayer);
4484 4436
4485
4486 } // namespace 4437 } // namespace
4487 4438
4488 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface 4439 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
4489 : public LayerTreeHostTest { 4440 : public LayerTreeHostTest {
4490 protected: 4441 protected:
4491 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface() 4442 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface()
4492 : first_output_surface_memory_limit_(4321234), 4443 : first_output_surface_memory_limit_(4321234),
4493 second_output_surface_memory_limit_(1234321) {} 4444 second_output_surface_memory_limit_(1234321) {}
4494 4445
4495 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 4446 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
4496 OVERRIDE { 4447 OVERRIDE {
4497 if (!first_context_provider_) { 4448 if (!first_context_provider_) {
4498 first_context_provider_ = TestContextProvider::Create(); 4449 first_context_provider_ = TestContextProvider::Create();
4499 } else { 4450 } else {
4500 EXPECT_FALSE(second_context_provider_); 4451 EXPECT_FALSE(second_context_provider_);
4501 second_context_provider_ = TestContextProvider::Create(); 4452 second_context_provider_ = TestContextProvider::Create();
4502 } 4453 }
4503 4454
4504 scoped_ptr<FakeOutputSurface> output_surface( 4455 scoped_ptr<FakeOutputSurface> output_surface(FakeOutputSurface::Create3d(
4505 FakeOutputSurface::Create3d( 4456 second_context_provider_ ? second_context_provider_
4506 second_context_provider_ ? 4457 : first_context_provider_));
4507 second_context_provider_ : 4458 output_surface->SetMemoryPolicyToSetAtBind(
4508 first_context_provider_)); 4459 make_scoped_ptr(new ManagedMemoryPolicy(
4509 output_surface->SetMemoryPolicyToSetAtBind(make_scoped_ptr( 4460 second_context_provider_ ? second_output_surface_memory_limit_
4510 new ManagedMemoryPolicy( 4461 : first_output_surface_memory_limit_,
4511 second_context_provider_ ?
4512 second_output_surface_memory_limit_ :
4513 first_output_surface_memory_limit_,
4514 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4462 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4515 ManagedMemoryPolicy::kDefaultNumResourcesLimit))); 4463 ManagedMemoryPolicy::kDefaultNumResourcesLimit)));
4516 return output_surface.PassAs<OutputSurface>(); 4464 return output_surface.PassAs<OutputSurface>();
4517 } 4465 }
4518 4466
4519 virtual void SetupTree() OVERRIDE { 4467 virtual void SetupTree() OVERRIDE {
4520 root_ = FakeContentLayer::Create(&client_); 4468 root_ = FakeContentLayer::Create(&client_);
4521 root_->SetBounds(gfx::Size(20, 20)); 4469 root_->SetBounds(gfx::Size(20, 20));
4522 layer_tree_host()->SetRootLayer(root_); 4470 layer_tree_host()->SetRootLayer(root_);
4523 LayerTreeHostTest::SetupTree(); 4471 LayerTreeHostTest::SetupTree();
4524 } 4472 }
4525 4473
4526 virtual void BeginTest() OVERRIDE { 4474 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4527 PostSetNeedsCommitToMainThread();
4528 }
4529 4475
4530 virtual void DidCommitAndDrawFrame() OVERRIDE { 4476 virtual void DidCommitAndDrawFrame() OVERRIDE {
4531 // Lost context sometimes takes two frames to recreate. The third frame 4477 // Lost context sometimes takes two frames to recreate. The third frame
4532 // is sometimes aborted, so wait until the fourth frame to verify that 4478 // is sometimes aborted, so wait until the fourth frame to verify that
4533 // the memory has been set, and the fifth frame to end the test. 4479 // the memory has been set, and the fifth frame to end the test.
4534 if (layer_tree_host()->source_frame_number() < 5) { 4480 if (layer_tree_host()->source_frame_number() < 5) {
4535 layer_tree_host()->SetNeedsCommit(); 4481 layer_tree_host()->SetNeedsCommit();
4536 } else if (layer_tree_host()->source_frame_number() == 5) { 4482 } else if (layer_tree_host()->source_frame_number() == 5) {
4537 EndTest(); 4483 EndTest();
4538 } 4484 }
4539 } 4485 }
4540 4486
4541 virtual void SwapBuffersOnThread(LayerTreeHostImpl *impl, bool result) 4487 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl,
4542 OVERRIDE { 4488 bool result) OVERRIDE {
4543 switch (impl->active_tree()->source_frame_number()) { 4489 switch (impl->active_tree()->source_frame_number()) {
4544 case 1: 4490 case 1:
4545 EXPECT_EQ(first_output_surface_memory_limit_, 4491 EXPECT_EQ(first_output_surface_memory_limit_,
4546 impl->memory_allocation_limit_bytes()); 4492 impl->memory_allocation_limit_bytes());
4547 // Lose the output surface. 4493 // Lose the output surface.
4548 first_context_provider_->TestContext3d()->loseContextCHROMIUM( 4494 first_context_provider_->TestContext3d()->loseContextCHROMIUM(
4549 GL_GUILTY_CONTEXT_RESET_ARB, 4495 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
4550 GL_INNOCENT_CONTEXT_RESET_ARB);
4551 break; 4496 break;
4552 case 4: 4497 case 4:
4553 EXPECT_EQ(second_output_surface_memory_limit_, 4498 EXPECT_EQ(second_output_surface_memory_limit_,
4554 impl->memory_allocation_limit_bytes()); 4499 impl->memory_allocation_limit_bytes());
4555 break; 4500 break;
4556 } 4501 }
4557 } 4502 }
4558 4503
4559 virtual void AfterTest() OVERRIDE {} 4504 virtual void AfterTest() OVERRIDE {}
4560 4505
4561 scoped_refptr<TestContextProvider> first_context_provider_; 4506 scoped_refptr<TestContextProvider> first_context_provider_;
4562 scoped_refptr<TestContextProvider> second_context_provider_; 4507 scoped_refptr<TestContextProvider> second_context_provider_;
4563 size_t first_output_surface_memory_limit_; 4508 size_t first_output_surface_memory_limit_;
4564 size_t second_output_surface_memory_limit_; 4509 size_t second_output_surface_memory_limit_;
4565 FakeContentLayerClient client_; 4510 FakeContentLayerClient client_;
4566 scoped_refptr<FakeContentLayer> root_; 4511 scoped_refptr<FakeContentLayer> root_;
4567 }; 4512 };
4568 4513
4569 // No output to copy for delegated renderers. 4514 // No output to copy for delegated renderers.
4570 SINGLE_AND_MULTI_THREAD_TEST_F( 4515 SINGLE_AND_MULTI_THREAD_TEST_F(
4571 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); 4516 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface);
4572 4517
4573 struct TestSwapPromiseResult { 4518 struct TestSwapPromiseResult {
4574 TestSwapPromiseResult() : did_swap_called(false), 4519 TestSwapPromiseResult()
4575 did_not_swap_called(false), 4520 : did_swap_called(false),
4576 dtor_called(false), 4521 did_not_swap_called(false),
4577 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) { 4522 dtor_called(false),
4578 } 4523 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) {}
4579 4524
4580 bool did_swap_called; 4525 bool did_swap_called;
4581 bool did_not_swap_called; 4526 bool did_not_swap_called;
4582 bool dtor_called; 4527 bool dtor_called;
4583 SwapPromise::DidNotSwapReason reason; 4528 SwapPromise::DidNotSwapReason reason;
4584 base::Lock lock; 4529 base::Lock lock;
4585 }; 4530 };
4586 4531
4587 class TestSwapPromise : public SwapPromise { 4532 class TestSwapPromise : public SwapPromise {
4588 public: 4533 public:
4589 explicit TestSwapPromise(TestSwapPromiseResult* result) 4534 explicit TestSwapPromise(TestSwapPromiseResult* result) : result_(result) {}
4590 : result_(result) {
4591 }
4592 4535
4593 virtual ~TestSwapPromise() { 4536 virtual ~TestSwapPromise() {
4594 base::AutoLock lock(result_->lock); 4537 base::AutoLock lock(result_->lock);
4595 result_->dtor_called = true; 4538 result_->dtor_called = true;
4596 } 4539 }
4597 4540
4598 virtual void DidSwap(CompositorFrameMetadata* metadata) OVERRIDE { 4541 virtual void DidSwap(CompositorFrameMetadata* metadata) OVERRIDE {
4599 base::AutoLock lock(result_->lock); 4542 base::AutoLock lock(result_->lock);
4600 EXPECT_FALSE(result_->did_swap_called); 4543 EXPECT_FALSE(result_->did_swap_called);
4601 EXPECT_FALSE(result_->did_not_swap_called); 4544 EXPECT_FALSE(result_->did_not_swap_called);
4602 result_->did_swap_called = true; 4545 result_->did_swap_called = true;
4603 } 4546 }
4604 4547
4605 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { 4548 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE {
4606 base::AutoLock lock(result_->lock); 4549 base::AutoLock lock(result_->lock);
4607 EXPECT_FALSE(result_->did_swap_called); 4550 EXPECT_FALSE(result_->did_swap_called);
4608 EXPECT_FALSE(result_->did_not_swap_called); 4551 EXPECT_FALSE(result_->did_not_swap_called);
4609 result_->did_not_swap_called = true; 4552 result_->did_not_swap_called = true;
4610 result_->reason = reason; 4553 result_->reason = reason;
4611 } 4554 }
4612 4555
4613 private: 4556 private:
4614 // Not owned. 4557 // Not owned.
4615 TestSwapPromiseResult* result_; 4558 TestSwapPromiseResult* result_;
4616 }; 4559 };
4617 4560
4618 class LayerTreeHostTestBreakSwapPromise 4561 class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest {
4619 : public LayerTreeHostTest {
4620 protected: 4562 protected:
4621 LayerTreeHostTestBreakSwapPromise() 4563 LayerTreeHostTestBreakSwapPromise()
4622 : commit_count_(0), commit_complete_count_(0) { 4564 : commit_count_(0), commit_complete_count_(0) {}
4623 }
4624 4565
4625 virtual void WillBeginMainFrame() OVERRIDE { 4566 virtual void WillBeginMainFrame() OVERRIDE {
4626 ASSERT_LE(commit_count_, 2); 4567 ASSERT_LE(commit_count_, 2);
4627 scoped_ptr<SwapPromise> swap_promise(new TestSwapPromise( 4568 scoped_ptr<SwapPromise> swap_promise(
4628 &swap_promise_result_[commit_count_])); 4569 new TestSwapPromise(&swap_promise_result_[commit_count_]));
4629 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4570 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4630 } 4571 }
4631 4572
4632 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4573 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4633 4574
4634 virtual void DidCommit() OVERRIDE { 4575 virtual void DidCommit() OVERRIDE {
4635 commit_count_++; 4576 commit_count_++;
4636 if (commit_count_ == 2) { 4577 if (commit_count_ == 2) {
4637 // This commit will finish. 4578 // This commit will finish.
4638 layer_tree_host()->SetNeedsCommit(); 4579 layer_tree_host()->SetNeedsCommit();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4683 } 4624 }
4684 } 4625 }
4685 4626
4686 int commit_count_; 4627 int commit_count_;
4687 int commit_complete_count_; 4628 int commit_complete_count_;
4688 TestSwapPromiseResult swap_promise_result_[3]; 4629 TestSwapPromiseResult swap_promise_result_[3];
4689 }; 4630 };
4690 4631
4691 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); 4632 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise);
4692 4633
4693
4694 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4634 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4695 public: 4635 public:
4696 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4636 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4697 LayerTreeHostImpl* layer_tree_host_impl, 4637 LayerTreeHostImpl* layer_tree_host_impl,
4698 int* set_needs_commit_count, 4638 int* set_needs_commit_count,
4699 int* set_needs_redraw_count) 4639 int* set_needs_redraw_count)
4700 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4640 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4701 set_needs_commit_count_(set_needs_commit_count), 4641 set_needs_commit_count_(set_needs_commit_count),
4702 set_needs_redraw_count_(set_needs_redraw_count) {} 4642 set_needs_redraw_count_(set_needs_redraw_count) {}
4703 4643
4704 virtual ~SimpleSwapPromiseMonitor() {} 4644 virtual ~SimpleSwapPromiseMonitor() {}
4705 4645
4706 virtual void OnSetNeedsCommitOnMain() OVERRIDE { 4646 virtual void OnSetNeedsCommitOnMain() OVERRIDE {
4707 (*set_needs_commit_count_)++; 4647 (*set_needs_commit_count_)++;
4708 } 4648 }
4709 4649
4710 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { 4650 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE {
4711 (*set_needs_redraw_count_)++; 4651 (*set_needs_redraw_count_)++;
4712 } 4652 }
4713 4653
4714 private: 4654 private:
4715 int* set_needs_commit_count_; 4655 int* set_needs_commit_count_;
4716 int* set_needs_redraw_count_; 4656 int* set_needs_redraw_count_;
4717 }; 4657 };
4718 4658
4719 class LayerTreeHostTestSimpleSwapPromiseMonitor 4659 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest {
4720 : public LayerTreeHostTest { 4660 public:
4721
4722 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4661 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4723 4662
4724 virtual void WillBeginMainFrame() OVERRIDE { 4663 virtual void WillBeginMainFrame() OVERRIDE {
4725 int set_needs_commit_count = 0; 4664 int set_needs_commit_count = 0;
4726 int set_needs_redraw_count = 0; 4665 int set_needs_redraw_count = 0;
4727 4666
4728 { 4667 {
4729 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( 4668 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor(
4730 new SimpleSwapPromiseMonitor(layer_tree_host(), 4669 new SimpleSwapPromiseMonitor(layer_tree_host(),
4731 NULL, 4670 NULL,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4766 4705
4767 EndTest(); 4706 EndTest();
4768 } 4707 }
4769 4708
4770 virtual void AfterTest() OVERRIDE {} 4709 virtual void AfterTest() OVERRIDE {}
4771 }; 4710 };
4772 4711
4773 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); 4712 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor);
4774 4713
4775 } // namespace cc 4714 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698