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

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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 } 1456 }
1474 1457
1475 virtual void BeginTest() OVERRIDE { 1458 virtual void BeginTest() OVERRIDE {
1476 drew_frame_ = -1; 1459 drew_frame_ = -1;
1477 PostSetNeedsCommitToMainThread(); 1460 PostSetNeedsCommitToMainThread();
1478 } 1461 }
1479 1462
1480 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1463 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1481 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1464 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1482 1465
1483 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 1466 TestWebGraphicsContext3D* context = TestContext();
1484 impl->output_surface()->context_provider().get())->TestContext3d();
1485 1467
1486 switch (impl->active_tree()->source_frame_number()) { 1468 switch (impl->active_tree()->source_frame_number()) {
1487 case 0: 1469 case 0:
1488 // Number of textures should be one for each layer 1470 // Number of textures should be one for each layer
1489 ASSERT_EQ(2u, context->NumTextures()); 1471 ASSERT_EQ(2u, context->NumTextures());
1490 // Number of textures used for commit should be one for each layer. 1472 // Number of textures used for commit should be one for each layer.
1491 EXPECT_EQ(2u, context->NumUsedTextures()); 1473 EXPECT_EQ(2u, context->NumUsedTextures());
1492 // Verify that used texture is correct. 1474 // Verify that used texture is correct.
1493 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1475 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1494 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1476 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 20 matching lines...) Expand all
1515 case 2: 1497 case 2:
1516 EndTest(); 1498 EndTest();
1517 break; 1499 break;
1518 default: 1500 default:
1519 NOTREACHED(); 1501 NOTREACHED();
1520 break; 1502 break;
1521 } 1503 }
1522 } 1504 }
1523 1505
1524 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1506 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1525 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 1507 TestWebGraphicsContext3D* context = TestContext();
1526 impl->output_surface()->context_provider().get())->TestContext3d();
1527 1508
1528 if (drew_frame_ == impl->active_tree()->source_frame_number()) { 1509 if (drew_frame_ == impl->active_tree()->source_frame_number()) {
1529 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_; 1510 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_;
1530 return; 1511 return;
1531 } 1512 }
1532 drew_frame_ = impl->active_tree()->source_frame_number(); 1513 drew_frame_ = impl->active_tree()->source_frame_number();
1533 1514
1534 // We draw/ship one texture each frame for each layer. 1515 // We draw/ship one texture each frame for each layer.
1535 EXPECT_EQ(2u, context->NumUsedTextures()); 1516 EXPECT_EQ(2u, context->NumUsedTextures());
1536 context->ResetUsedTextures(); 1517 context->ResetUsedTextures();
(...skipping 15 matching lines...) Expand all
1552 1533
1553 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1534 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1554 LayerTreeHostTestDirectRendererAtomicCommit); 1535 LayerTreeHostTestDirectRendererAtomicCommit);
1555 1536
1556 class LayerTreeHostTestDelegatingRendererAtomicCommit 1537 class LayerTreeHostTestDelegatingRendererAtomicCommit
1557 : public LayerTreeHostTestDirectRendererAtomicCommit { 1538 : public LayerTreeHostTestDirectRendererAtomicCommit {
1558 public: 1539 public:
1559 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1540 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1560 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1541 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1561 1542
1562 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 1543 TestWebGraphicsContext3D* context = TestContext();
1563 impl->output_surface()->context_provider().get())->TestContext3d();
1564 1544
1565 switch (impl->active_tree()->source_frame_number()) { 1545 switch (impl->active_tree()->source_frame_number()) {
1566 case 0: 1546 case 0:
1567 // Number of textures should be one for each layer 1547 // Number of textures should be one for each layer
1568 ASSERT_EQ(2u, context->NumTextures()); 1548 ASSERT_EQ(2u, context->NumTextures());
1569 // Number of textures used for commit should be one for each layer. 1549 // Number of textures used for commit should be one for each layer.
1570 EXPECT_EQ(2u, context->NumUsedTextures()); 1550 EXPECT_EQ(2u, context->NumUsedTextures());
1571 // Verify that used texture is correct. 1551 // Verify that used texture is correct.
1572 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1552 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1573 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1553 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 child_ = FakeContentLayer::Create(&client_); 1621 child_ = FakeContentLayer::Create(&client_);
1642 child_->SetPosition(gfx::Point(0, 10)); 1622 child_->SetPosition(gfx::Point(0, 10));
1643 child_->SetBounds(gfx::Size(3, 10)); 1623 child_->SetBounds(gfx::Size(3, 10));
1644 1624
1645 parent_->AddChild(child_); 1625 parent_->AddChild(child_);
1646 1626
1647 layer_tree_host()->SetRootLayer(parent_); 1627 layer_tree_host()->SetRootLayer(parent_);
1648 LayerTreeHostTest::SetupTree(); 1628 LayerTreeHostTest::SetupTree();
1649 } 1629 }
1650 1630
1651 virtual void BeginTest() OVERRIDE { 1631 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1652 PostSetNeedsCommitToMainThread();
1653 }
1654 1632
1655 virtual void DidCommitAndDrawFrame() OVERRIDE { 1633 virtual void DidCommitAndDrawFrame() OVERRIDE {
1656 switch (layer_tree_host()->source_frame_number()) { 1634 switch (layer_tree_host()->source_frame_number()) {
1657 case 1: 1635 case 1:
1658 parent_->SetNeedsDisplay(); 1636 parent_->SetNeedsDisplay();
1659 child_->SetNeedsDisplay(); 1637 child_->SetNeedsDisplay();
1660 break; 1638 break;
1661 case 2: 1639 case 2:
1662 // Damage part of layers. 1640 // Damage part of layers.
1663 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f)); 1641 parent_->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f));
(...skipping 11 matching lines...) Expand all
1675 break; 1653 break;
1676 default: 1654 default:
1677 NOTREACHED() << layer_tree_host()->source_frame_number(); 1655 NOTREACHED() << layer_tree_host()->source_frame_number();
1678 break; 1656 break;
1679 } 1657 }
1680 } 1658 }
1681 1659
1682 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1660 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1683 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); 1661 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates);
1684 1662
1685 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 1663 TestWebGraphicsContext3D* context = TestContext();
1686 impl->output_surface()->context_provider().get())->TestContext3d();
1687 1664
1688 switch (impl->active_tree()->source_frame_number()) { 1665 switch (impl->active_tree()->source_frame_number()) {
1689 case 0: 1666 case 0:
1690 // Number of textures should be one for each layer. 1667 // Number of textures should be one for each layer.
1691 ASSERT_EQ(2u, context->NumTextures()); 1668 ASSERT_EQ(2u, context->NumTextures());
1692 // Number of textures used for commit should be one for each layer. 1669 // Number of textures used for commit should be one for each layer.
1693 EXPECT_EQ(2u, context->NumUsedTextures()); 1670 EXPECT_EQ(2u, context->NumUsedTextures());
1694 // Verify that used textures are correct. 1671 // Verify that used textures are correct.
1695 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1672 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1696 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1673 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 break; 1743 break;
1767 default: 1744 default:
1768 NOTREACHED(); 1745 NOTREACHED();
1769 break; 1746 break;
1770 } 1747 }
1771 } 1748 }
1772 1749
1773 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1750 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1774 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); 1751 EXPECT_LT(impl->active_tree()->source_frame_number(), 5);
1775 1752
1776 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 1753 TestWebGraphicsContext3D* context = TestContext();
1777 impl->output_surface()->context_provider().get())->TestContext3d();
1778 1754
1779 // Number of textures used for drawing should one per layer except for 1755 // Number of textures used for drawing should one per layer except for
1780 // frame 3 where the viewport only contains one layer. 1756 // frame 3 where the viewport only contains one layer.
1781 if (impl->active_tree()->source_frame_number() == 3) { 1757 if (impl->active_tree()->source_frame_number() == 3) {
1782 EXPECT_EQ(1u, context->NumUsedTextures()); 1758 EXPECT_EQ(1u, context->NumUsedTextures());
1783 } else { 1759 } else {
1784 EXPECT_EQ(2u, context->NumUsedTextures()) << 1760 EXPECT_EQ(2u, context->NumUsedTextures())
1785 "For frame " << impl->active_tree()->source_frame_number(); 1761 << "For frame " << impl->active_tree()->source_frame_number();
1786 } 1762 }
1787 1763
1788 context->ResetUsedTextures(); 1764 context->ResetUsedTextures();
1789 } 1765 }
1790 1766
1791 virtual void AfterTest() OVERRIDE {} 1767 virtual void AfterTest() OVERRIDE {}
1792 1768
1793 private: 1769 private:
1794 FakeContentLayerClient client_; 1770 FakeContentLayerClient client_;
1795 scoped_refptr<FakeContentLayer> parent_; 1771 scoped_refptr<FakeContentLayer> parent_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 replica_layer1_ = FakeContentLayer::Create(&client_); 1858 replica_layer1_ = FakeContentLayer::Create(&client_);
1883 surface_layer1_->SetReplicaLayer(replica_layer1_.get()); 1859 surface_layer1_->SetReplicaLayer(replica_layer1_.get());
1884 1860
1885 replica_layer2_ = FakeContentLayer::Create(&client_); 1861 replica_layer2_ = FakeContentLayer::Create(&client_);
1886 surface_layer2_->SetReplicaLayer(replica_layer2_.get()); 1862 surface_layer2_->SetReplicaLayer(replica_layer2_.get());
1887 1863
1888 layer_tree_host()->SetRootLayer(root_layer_); 1864 layer_tree_host()->SetRootLayer(root_layer_);
1889 LayerTreeHostTest::SetupTree(); 1865 LayerTreeHostTest::SetupTree();
1890 } 1866 }
1891 1867
1892 virtual void BeginTest() OVERRIDE { 1868 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1893 PostSetNeedsCommitToMainThread();
1894 }
1895 1869
1896 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1870 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1897 Renderer* renderer = host_impl->renderer(); 1871 Renderer* renderer = host_impl->renderer();
1898 RenderPass::Id surface1_render_pass_id = host_impl->active_tree() 1872 RenderPass::Id surface1_render_pass_id = host_impl->active_tree()
1899 ->root_layer()->children()[0]->render_surface()->RenderPassId(); 1873 ->root_layer()
1900 RenderPass::Id surface2_render_pass_id = 1874 ->children()[0]
1901 host_impl->active_tree()->root_layer()->children()[0]->children()[0] 1875 ->render_surface()
1902 ->render_surface()->RenderPassId(); 1876 ->RenderPassId();
1877 RenderPass::Id surface2_render_pass_id = host_impl->active_tree()
1878 ->root_layer()
1879 ->children()[0]
1880 ->children()[0]
1881 ->render_surface()
1882 ->RenderPassId();
1903 1883
1904 switch (host_impl->active_tree()->source_frame_number()) { 1884 switch (host_impl->active_tree()->source_frame_number()) {
1905 case 0: 1885 case 0:
1906 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( 1886 EXPECT_TRUE(
1907 surface1_render_pass_id)); 1887 renderer->HasAllocatedResourcesForTesting(surface1_render_pass_id));
1908 EXPECT_TRUE(renderer->HasAllocatedResourcesForTesting( 1888 EXPECT_TRUE(
1909 surface2_render_pass_id)); 1889 renderer->HasAllocatedResourcesForTesting(surface2_render_pass_id));
1910 1890
1911 // Reduce the memory limit to only fit the root layer and one render 1891 // Reduce the memory limit to only fit the root layer and one render
1912 // surface. This prevents any contents drawing into surfaces 1892 // surface. This prevents any contents drawing into surfaces
1913 // from being allocated. 1893 // from being allocated.
1914 host_impl->SetMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 * 2)); 1894 host_impl->SetMemoryPolicy(ManagedMemoryPolicy(100 * 100 * 4 * 2));
1915 break; 1895 break;
1916 case 1: 1896 case 1:
1917 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( 1897 EXPECT_FALSE(
1918 surface1_render_pass_id)); 1898 renderer->HasAllocatedResourcesForTesting(surface1_render_pass_id));
1919 EXPECT_FALSE(renderer->HasAllocatedResourcesForTesting( 1899 EXPECT_FALSE(
1920 surface2_render_pass_id)); 1900 renderer->HasAllocatedResourcesForTesting(surface2_render_pass_id));
1921 1901
1922 EndTest(); 1902 EndTest();
1923 break; 1903 break;
1924 } 1904 }
1925 } 1905 }
1926 1906
1927 virtual void DidCommitAndDrawFrame() OVERRIDE { 1907 virtual void DidCommitAndDrawFrame() OVERRIDE {
1928 if (layer_tree_host()->source_frame_number() < 2) 1908 if (layer_tree_host()->source_frame_number() < 2)
1929 root_layer_->SetNeedsDisplay(); 1909 root_layer_->SetNeedsDisplay();
1930 } 1910 }
(...skipping 15 matching lines...) Expand all
1946 // Surfaces don't exist with a delegated renderer. 1926 // Surfaces don't exist with a delegated renderer.
1947 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1927 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1948 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit); 1928 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit);
1949 1929
1950 class EvictionTestLayer : public Layer { 1930 class EvictionTestLayer : public Layer {
1951 public: 1931 public:
1952 static scoped_refptr<EvictionTestLayer> Create() { 1932 static scoped_refptr<EvictionTestLayer> Create() {
1953 return make_scoped_refptr(new EvictionTestLayer()); 1933 return make_scoped_refptr(new EvictionTestLayer());
1954 } 1934 }
1955 1935
1956 virtual bool Update(ResourceUpdateQueue*, 1936 virtual bool Update(ResourceUpdateQueue*, const OcclusionTracker*) OVERRIDE;
1957 const OcclusionTracker*) OVERRIDE;
1958 virtual bool DrawsContent() const OVERRIDE { return true; } 1937 virtual bool DrawsContent() const OVERRIDE { return true; }
1959 1938
1960 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 1939 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
1961 OVERRIDE; 1940 OVERRIDE;
1962 virtual void PushPropertiesTo(LayerImpl* impl) OVERRIDE; 1941 virtual void PushPropertiesTo(LayerImpl* impl) OVERRIDE;
1963 virtual void SetTexturePriorities(const PriorityCalculator&) OVERRIDE; 1942 virtual void SetTexturePriorities(const PriorityCalculator&) OVERRIDE;
1964 1943
1965 bool HaveBackingTexture() const { 1944 bool HaveBackingTexture() const {
1966 return texture_.get() ? texture_->have_backing_texture() : false; 1945 return texture_.get() ? texture_->have_backing_texture() : false;
1967 } 1946 }
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 2418
2440 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, 2419 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
2441 bool visible) OVERRIDE { 2420 bool visible) OVERRIDE {
2442 if (visible) { 2421 if (visible) {
2443 // One backing should remain unevicted. 2422 // One backing should remain unevicted.
2444 EXPECT_EQ( 2423 EXPECT_EQ(
2445 100u * 100u * 4u * 1u, 2424 100u * 100u * 4u * 1u,
2446 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2425 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2447 } else { 2426 } else {
2448 EXPECT_EQ( 2427 EXPECT_EQ(
2449 0u, 2428 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2450 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2451 } 2429 }
2452 2430
2453 // Make sure that contents textures are marked as having been 2431 // Make sure that contents textures are marked as having been
2454 // purged. 2432 // purged.
2455 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); 2433 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged());
2456 // End the test in this state. 2434 // End the test in this state.
2457 EndTest(); 2435 EndTest();
2458 } 2436 }
2459 2437
2460 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2438 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 2574 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
2597 settings->begin_impl_frame_scheduling_enabled = true; 2575 settings->begin_impl_frame_scheduling_enabled = true;
2598 } 2576 }
2599 2577
2600 virtual void BeginTest() OVERRIDE { 2578 virtual void BeginTest() OVERRIDE {
2601 // This will trigger a SetNeedsBeginImplFrame which will trigger a 2579 // This will trigger a SetNeedsBeginImplFrame which will trigger a
2602 // BeginImplFrame. 2580 // BeginImplFrame.
2603 PostSetNeedsCommitToMainThread(); 2581 PostSetNeedsCommitToMainThread();
2604 } 2582 }
2605 2583
2606 virtual bool PrepareToDrawOnThread( 2584 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2607 LayerTreeHostImpl* host_impl, 2585 LayerTreeHostImpl::FrameData* frame,
2608 LayerTreeHostImpl::FrameData* frame, 2586 bool result) OVERRIDE {
2609 bool result) OVERRIDE {
2610 EndTest(); 2587 EndTest();
2611 return true; 2588 return true;
2612 } 2589 }
2613 2590
2614 virtual void AfterTest() OVERRIDE {} 2591 virtual void AfterTest() OVERRIDE {}
2615 2592
2616 private: 2593 private:
2617 base::TimeTicks frame_time_; 2594 base::TimeTicks frame_time_;
2618 }; 2595 };
2619 2596
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 virtual void DidCommit() OVERRIDE { 2635 virtual void DidCommit() OVERRIDE {
2659 commit_count_++; 2636 commit_count_++;
2660 if (commit_count_ == 4) { 2637 if (commit_count_ == 4) {
2661 // After two aborted commits, request a real commit now to make sure a 2638 // After two aborted commits, request a real commit now to make sure a
2662 // real commit following an aborted commit will still complete and 2639 // real commit following an aborted commit will still complete and
2663 // end the test even when the Impl thread is idle. 2640 // end the test even when the Impl thread is idle.
2664 layer_tree_host()->SetNeedsCommit(); 2641 layer_tree_host()->SetNeedsCommit();
2665 } 2642 }
2666 } 2643 }
2667 2644
2668 virtual void BeginMainFrameAbortedOnThread( 2645 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
2669 LayerTreeHostImpl *host_impl, bool did_handle) OVERRIDE { 2646 bool did_handle) OVERRIDE {
2670 commit_abort_count_++; 2647 commit_abort_count_++;
2671 // Initiate another abortable commit. 2648 // Initiate another abortable commit.
2672 host_impl->SetNeedsCommit(); 2649 host_impl->SetNeedsCommit();
2673 } 2650 }
2674 2651
2675 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2652 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2676 commit_complete_count_++; 2653 commit_complete_count_++;
2677 if (commit_complete_count_ == 1) { 2654 if (commit_complete_count_ == 1) {
2678 // Initiate an abortable commit after the first commit. 2655 // Initiate an abortable commit after the first commit.
2679 host_impl->SetNeedsCommit(); 2656 host_impl->SetNeedsCommit();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2723 2700
2724 virtual void SetupTree() OVERRIDE { 2701 virtual void SetupTree() OVERRIDE {
2725 LayerTreeHostTest::SetupTree(); 2702 LayerTreeHostTest::SetupTree();
2726 2703
2727 scoped_refptr<Layer> layer = PictureLayer::Create(&client_); 2704 scoped_refptr<Layer> layer = PictureLayer::Create(&client_);
2728 layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); 2705 layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2729 layer->SetBounds(gfx::Size(10, 10)); 2706 layer->SetBounds(gfx::Size(10, 10));
2730 layer_tree_host()->root_layer()->AddChild(layer); 2707 layer_tree_host()->root_layer()->AddChild(layer);
2731 } 2708 }
2732 2709
2733 virtual void BeginTest() OVERRIDE { 2710 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
2734 PostSetNeedsCommitToMainThread();
2735 }
2736 2711
2737 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2712 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2738 EndTest(); 2713 EndTest();
2739 } 2714 }
2740 2715
2741 virtual void AfterTest() OVERRIDE { 2716 virtual void AfterTest() OVERRIDE {}
2742 }
2743 2717
2744 FakeContentLayerClient client_; 2718 FakeContentLayerClient client_;
2745 }; 2719 };
2746 2720
2747 MULTI_THREAD_TEST_F( 2721 MULTI_THREAD_TEST_F(
2748 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); 2722 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation);
2749 2723
2750 class LayerTreeHostTestChangeLayerPropertiesInPaintContents 2724 class LayerTreeHostTestChangeLayerPropertiesInPaintContents
2751 : public LayerTreeHostTest { 2725 : public LayerTreeHostTest {
2752 public: 2726 public:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2806 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { 2780 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D {
2807 public: 2781 public:
2808 MockIOSurfaceWebGraphicsContext3D() { 2782 MockIOSurfaceWebGraphicsContext3D() {
2809 test_capabilities_.gpu.iosurface = true; 2783 test_capabilities_.gpu.iosurface = true;
2810 test_capabilities_.gpu.texture_rectangle = true; 2784 test_capabilities_.gpu.texture_rectangle = true;
2811 } 2785 }
2812 2786
2813 virtual GLuint createTexture() OVERRIDE { 2787 virtual GLuint createTexture() OVERRIDE {
2814 return 1; 2788 return 1;
2815 } 2789 }
2816
2817 MOCK_METHOD1(activeTexture, void(GLenum texture)); 2790 MOCK_METHOD1(activeTexture, void(GLenum texture));
2818 MOCK_METHOD2(bindTexture, void(GLenum target, 2791 MOCK_METHOD2(bindTexture, void(GLenum target,
2819 GLuint texture_id)); 2792 GLuint texture_id));
2820 MOCK_METHOD3(texParameteri, void(GLenum target, 2793 MOCK_METHOD3(texParameteri, void(GLenum target,
2821 GLenum pname, 2794 GLenum pname,
2822 GLint param)); 2795 GLint param));
2823 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(GLenum target, 2796 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(GLenum target,
2824 GLint width, 2797 GLint width,
2825 GLint height, 2798 GLint height,
2826 GLuint ioSurfaceId, 2799 GLuint ioSurfaceId,
2827 GLuint plane)); 2800 GLuint plane));
2828 MOCK_METHOD4(drawElements, void(GLenum mode, 2801 MOCK_METHOD4(drawElements, void(GLenum mode,
2829 GLsizei count, 2802 GLsizei count,
2830 GLenum type, 2803 GLenum type,
2831 GLintptr offset)); 2804 GLintptr offset));
2832 MOCK_METHOD1(deleteTexture, void(GLenum texture)); 2805 MOCK_METHOD1(deleteTexture, void(GLenum texture));
2833 }; 2806 };
2834 2807
2835
2836 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { 2808 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
2837 protected: 2809 protected:
2838 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 2810 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurfaceForTest(
2839 OVERRIDE { 2811 bool fallback) OVERRIDE {
2840 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned( 2812 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned(
2841 new MockIOSurfaceWebGraphicsContext3D); 2813 new MockIOSurfaceWebGraphicsContext3D);
2842 mock_context_ = mock_context_owned.get(); 2814 mock_context_ = mock_context_owned.get();
2843 2815
2844 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 2816 return FakeOutputSurface::Create3d(
2845 mock_context_owned.PassAs<TestWebGraphicsContext3D>())); 2817 mock_context_owned.PassAs<TestWebGraphicsContext3D>());
2846 return output_surface.Pass();
2847 } 2818 }
2848 2819
2849 virtual void SetupTree() OVERRIDE { 2820 virtual void SetupTree() OVERRIDE {
2850 LayerTreeHostTest::SetupTree(); 2821 LayerTreeHostTest::SetupTree();
2851 2822
2852 layer_tree_host()->root_layer()->SetIsDrawable(false); 2823 layer_tree_host()->root_layer()->SetIsDrawable(false);
2853 2824
2854 io_surface_id_ = 9; 2825 io_surface_id_ = 9;
2855 io_surface_size_ = gfx::Size(6, 7); 2826 io_surface_size_ = gfx::Size(6, 7);
2856 2827
2857 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create(); 2828 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create();
2858 io_surface_layer->SetBounds(gfx::Size(10, 10)); 2829 io_surface_layer->SetBounds(gfx::Size(10, 10));
2859 io_surface_layer->SetAnchorPoint(gfx::PointF()); 2830 io_surface_layer->SetAnchorPoint(gfx::PointF());
2860 io_surface_layer->SetIsDrawable(true); 2831 io_surface_layer->SetIsDrawable(true);
2861 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); 2832 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_);
2862 layer_tree_host()->root_layer()->AddChild(io_surface_layer); 2833 layer_tree_host()->root_layer()->AddChild(io_surface_layer);
2863 } 2834 }
2864 2835
2865 virtual void BeginTest() OVERRIDE { 2836 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
2866 PostSetNeedsCommitToMainThread();
2867 }
2868 2837
2869 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2838 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2870 // In WillDraw, the IOSurfaceLayer sets up the io surface texture. 2839 // In WillDraw, the IOSurfaceLayer sets up the io surface texture.
2871 2840
2872 EXPECT_CALL(*mock_context_, activeTexture(_)) 2841 EXPECT_CALL(*mock_context_, activeTexture(_)).Times(0);
2873 .Times(0);
2874 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) 2842 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2875 .Times(AtLeast(1)); 2843 .Times(AtLeast(1));
2876 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2844 EXPECT_CALL(*mock_context_,
2877 GL_TEXTURE_MIN_FILTER, 2845 texParameteri(
2878 GL_LINEAR)) 2846 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR))
2879 .Times(1); 2847 .Times(1);
2880 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2848 EXPECT_CALL(*mock_context_,
2881 GL_TEXTURE_MAG_FILTER, 2849 texParameteri(
2882 GL_LINEAR)) 2850 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR))
2883 .Times(1); 2851 .Times(1);
2884 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2852 EXPECT_CALL(*mock_context_,
2885 GL_TEXTURE_WRAP_S, 2853 texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2886 GL_CLAMP_TO_EDGE)) 2854 GL_TEXTURE_WRAP_S,
2887 .Times(1); 2855 GL_CLAMP_TO_EDGE)).Times(1);
2888 EXPECT_CALL(*mock_context_, texParameteri(GL_TEXTURE_RECTANGLE_ARB, 2856 EXPECT_CALL(*mock_context_,
2889 GL_TEXTURE_WRAP_T, 2857 texParameteri(GL_TEXTURE_RECTANGLE_ARB,
2890 GL_CLAMP_TO_EDGE)) 2858 GL_TEXTURE_WRAP_T,
2891 .Times(1); 2859 GL_CLAMP_TO_EDGE)).Times(1);
2892 2860
2893 EXPECT_CALL(*mock_context_, texImageIOSurface2DCHROMIUM( 2861 EXPECT_CALL(*mock_context_,
2894 GL_TEXTURE_RECTANGLE_ARB, 2862 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB,
2895 io_surface_size_.width(), 2863 io_surface_size_.width(),
2896 io_surface_size_.height(), 2864 io_surface_size_.height(),
2897 io_surface_id_, 2865 io_surface_id_,
2898 0)) 2866 0)).Times(1);
2899 .Times(1);
2900 2867
2901 EXPECT_CALL(*mock_context_, bindTexture(_, 0)) 2868 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber());
2902 .Times(AnyNumber());
2903 } 2869 }
2904 2870
2905 virtual bool PrepareToDrawOnThread( 2871 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2906 LayerTreeHostImpl* host_impl, 2872 LayerTreeHostImpl::FrameData* frame,
2907 LayerTreeHostImpl::FrameData* frame, 2873 bool result) OVERRIDE {
2908 bool result) OVERRIDE {
2909 Mock::VerifyAndClearExpectations(&mock_context_); 2874 Mock::VerifyAndClearExpectations(&mock_context_);
2910 2875
2911 // The io surface layer's texture is drawn. 2876 // The io surface layer's texture is drawn.
2912 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)) 2877 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1));
2913 .Times(AtLeast(1));
2914 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) 2878 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2915 .Times(1); 2879 .Times(1);
2916 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) 2880 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _))
2917 .Times(AtLeast(1)); 2881 .Times(AtLeast(1));
2918 2882
2919 return result; 2883 return result;
2920 } 2884 }
2921 2885
2922 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2886 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2923 Mock::VerifyAndClearExpectations(&mock_context_); 2887 Mock::VerifyAndClearExpectations(&mock_context_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
3061 ImplThreadTaskRunner()->PostTask( 3025 ImplThreadTaskRunner()->PostTask(
3062 FROM_HERE, 3026 FROM_HERE,
3063 base::Bind( 3027 base::Bind(
3064 &LayerTreeHostTestDeferredInitialize::DeferredInitializeAndRedraw, 3028 &LayerTreeHostTestDeferredInitialize::DeferredInitializeAndRedraw,
3065 base::Unretained(this), 3029 base::Unretained(this),
3066 base::Unretained(host_impl))); 3030 base::Unretained(host_impl)));
3067 } else if (did_initialize_gl_ && !did_release_gl_) { 3031 } else if (did_initialize_gl_ && !did_release_gl_) {
3068 EXPECT_LE(2u, layer_impl->append_quads_count()); 3032 EXPECT_LE(2u, layer_impl->append_quads_count());
3069 ImplThreadTaskRunner()->PostTask( 3033 ImplThreadTaskRunner()->PostTask(
3070 FROM_HERE, 3034 FROM_HERE,
3071 base::Bind( 3035 base::Bind(&LayerTreeHostTestDeferredInitialize::ReleaseGLAndRedraw,
3072 &LayerTreeHostTestDeferredInitialize::ReleaseGLAndRedraw, 3036 base::Unretained(this),
3073 base::Unretained(this), 3037 base::Unretained(host_impl)));
3074 base::Unretained(host_impl)));
3075 } else if (did_initialize_gl_ && did_release_gl_) { 3038 } else if (did_initialize_gl_ && did_release_gl_) {
3076 EXPECT_LE(3u, layer_impl->append_quads_count()); 3039 EXPECT_LE(3u, layer_impl->append_quads_count());
3077 EndTest(); 3040 EndTest();
3078 } 3041 }
3079 } 3042 }
3080 3043
3081 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { 3044 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) {
3082 EXPECT_FALSE(did_initialize_gl_); 3045 EXPECT_FALSE(did_initialize_gl_);
3083 // SetAndInitializeContext3D calls SetNeedsCommit. 3046 // SetAndInitializeContext3D calls SetNeedsCommit.
3084 FakeOutputSurface* fake_output_surface = 3047 FakeOutputSurface* fake_output_surface =
3085 static_cast<FakeOutputSurface*>(host_impl->output_surface()); 3048 static_cast<FakeOutputSurface*>(host_impl->output_surface());
3086 scoped_refptr<TestContextProvider> context_provider = 3049 scoped_refptr<TestContextProvider> context_provider =
3087 TestContextProvider::Create(); // Not bound to thread. 3050 TestContextProvider::Create(); // Not bound to thread.
3088 EXPECT_TRUE(fake_output_surface->InitializeAndSetContext3d( 3051 EXPECT_TRUE(
3089 context_provider, NULL)); 3052 fake_output_surface->InitializeAndSetContext3d(context_provider, NULL));
3090 did_initialize_gl_ = true; 3053 did_initialize_gl_ = true;
3091 } 3054 }
3092 3055
3093 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { 3056 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) {
3094 EXPECT_TRUE(did_initialize_gl_); 3057 EXPECT_TRUE(did_initialize_gl_);
3095 EXPECT_FALSE(did_release_gl_); 3058 EXPECT_FALSE(did_release_gl_);
3096 // ReleaseGL calls SetNeedsCommit. 3059 // ReleaseGL calls SetNeedsCommit.
3097 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); 3060 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL();
3098 did_release_gl_ = true; 3061 did_release_gl_ = true;
3099 } 3062 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3150 PostSetNeedsCommitToMainThread(); 3113 PostSetNeedsCommitToMainThread();
3151 break; 3114 break;
3152 case 5: 3115 case 5:
3153 ClearResources(); 3116 ClearResources();
3154 EndTest(); 3117 EndTest();
3155 break; 3118 break;
3156 } 3119 }
3157 } 3120 }
3158 3121
3159 void PerformTest(LayerTreeHostImpl* impl) { 3122 void PerformTest(LayerTreeHostImpl* impl) {
3160 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 3123 TestWebGraphicsContext3D* context = TestContext();
3161 impl->output_surface()->context_provider().get())->TestContext3d();
3162 3124
3163 int frame = num_commits_; 3125 int frame = num_commits_;
3164 switch (frame) { 3126 switch (frame) {
3165 case 1: 3127 case 1:
3166 ASSERT_EQ(0u, context->NumTextures()); 3128 ASSERT_EQ(0u, context->NumTextures());
3167 break; 3129 break;
3168 case 2: 3130 case 2:
3169 // Created two textures. 3131 // Created two textures.
3170 ASSERT_EQ(2u, context->NumTextures()); 3132 ASSERT_EQ(2u, context->NumTextures());
3171 break; 3133 break;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3233 3195
3234 size_t push_properties_count() const { return push_properties_count_; } 3196 size_t push_properties_count() const { return push_properties_count_; }
3235 void reset_push_properties_count() { push_properties_count_ = 0; } 3197 void reset_push_properties_count() { push_properties_count_ = 0; }
3236 3198
3237 void set_persist_needs_push_properties(bool persist) { 3199 void set_persist_needs_push_properties(bool persist) {
3238 persist_needs_push_properties_ = persist; 3200 persist_needs_push_properties_ = persist;
3239 } 3201 }
3240 3202
3241 private: 3203 private:
3242 PushPropertiesCountingLayer() 3204 PushPropertiesCountingLayer()
3243 : push_properties_count_(0), 3205 : push_properties_count_(0), persist_needs_push_properties_(false) {
3244 persist_needs_push_properties_(false) {
3245 SetAnchorPoint(gfx::PointF()); 3206 SetAnchorPoint(gfx::PointF());
3246 SetBounds(gfx::Size(1, 1)); 3207 SetBounds(gfx::Size(1, 1));
3247 SetIsDrawable(true); 3208 SetIsDrawable(true);
3248 } 3209 }
3249 virtual ~PushPropertiesCountingLayer() {} 3210 virtual ~PushPropertiesCountingLayer() {}
3250 3211
3251 size_t push_properties_count_; 3212 size_t push_properties_count_;
3252 bool persist_needs_push_properties_; 3213 bool persist_needs_push_properties_;
3253 }; 3214 };
3254 3215
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
3440 size_t expected_push_properties_grandchild_; 3401 size_t expected_push_properties_grandchild_;
3441 size_t expected_push_properties_other_root_; 3402 size_t expected_push_properties_other_root_;
3442 size_t expected_push_properties_leaf_layer_; 3403 size_t expected_push_properties_leaf_layer_;
3443 }; 3404 };
3444 3405
3445 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties); 3406 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties);
3446 3407
3447 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed 3408 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
3448 : public LayerTreeHostTest { 3409 : public LayerTreeHostTest {
3449 protected: 3410 protected:
3450 virtual void BeginTest() OVERRIDE { 3411 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
3451 PostSetNeedsCommitToMainThread();
3452 }
3453 3412
3454 virtual void SetupTree() OVERRIDE { 3413 virtual void SetupTree() OVERRIDE {
3455 root_ = Layer::Create(); 3414 root_ = Layer::Create();
3456 root_->SetBounds(gfx::Size(1, 1)); 3415 root_->SetBounds(gfx::Size(1, 1));
3457 3416
3458 bool paint_scrollbar = true; 3417 bool paint_scrollbar = true;
3459 bool has_thumb = false; 3418 bool has_thumb = false;
3460 scrollbar_layer_ = FakePaintedScrollbarLayer::Create( 3419 scrollbar_layer_ = FakePaintedScrollbarLayer::Create(
3461 paint_scrollbar, has_thumb, root_->id()); 3420 paint_scrollbar, has_thumb, root_->id());
3462 3421
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
3944 case 3: 3903 case 3:
3945 EXPECT_EQ(0, callback_count_); 3904 EXPECT_EQ(0, callback_count_);
3946 callback_count_ = 0; 3905 callback_count_ = 0;
3947 EndTest(); 3906 EndTest();
3948 break; 3907 break;
3949 default: 3908 default:
3950 ADD_FAILURE() << num_commits_; 3909 ADD_FAILURE() << num_commits_;
3951 EndTest(); 3910 EndTest();
3952 break; 3911 break;
3953 } 3912 }
3954 return LayerTreeHostTest::PrepareToDrawOnThread(host_impl, frame_data, 3913 return LayerTreeHostTest::PrepareToDrawOnThread(
3955 result); 3914 host_impl, frame_data, result);
3956 } 3915 }
3957 3916
3958 virtual void AfterTest() OVERRIDE { 3917 virtual void AfterTest() OVERRIDE { EXPECT_EQ(3, num_commits_); }
3959 EXPECT_EQ(3, num_commits_); 3918
3919 void SetCallback(bool enable) {
3920 output_surface()->SetTreeActivationCallback(
3921 enable
3922 ? base::Bind(
3923 &LayerTreeHostTestTreeActivationCallback::ActivationCallback,
3924 base::Unretained(this))
3925 : base::Closure());
3960 } 3926 }
3961 3927
3962 void SetCallback(bool enable) { 3928 void ActivationCallback() { ++callback_count_; }
3963 output_surface()->SetTreeActivationCallback(enable ?
3964 base::Bind(&LayerTreeHostTestTreeActivationCallback::ActivationCallback,
3965 base::Unretained(this)) :
3966 base::Closure());
3967 }
3968
3969 void ActivationCallback() {
3970 ++callback_count_;
3971 }
3972 3929
3973 int num_commits_; 3930 int num_commits_;
3974 int callback_count_; 3931 int callback_count_;
3975 }; 3932 };
3976 3933
3977 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { 3934 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) {
3978 RunTest(true, false, true); 3935 RunTest(true, false, true);
3979 } 3936 }
3980 3937
3981 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { 3938 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) {
3982 RunTest(true, true, true); 3939 RunTest(true, true, true);
3983 } 3940 }
3984 3941
3985 class LayerInvalidateCausesDraw : public LayerTreeHostTest { 3942 class LayerInvalidateCausesDraw : public LayerTreeHostTest {
3986 public: 3943 public:
3987 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {} 3944 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {}
3988 3945
3989 virtual void BeginTest() OVERRIDE { 3946 virtual void BeginTest() OVERRIDE {
3990 ASSERT_TRUE(!!invalidate_layer_) 3947 ASSERT_TRUE(!!invalidate_layer_)
3991 << "Derived tests must set this in SetupTree"; 3948 << "Derived tests must set this in SetupTree";
3992 3949
3993 // One initial commit. 3950 // One initial commit.
3994 PostSetNeedsCommitToMainThread(); 3951 PostSetNeedsCommitToMainThread();
3995 } 3952 }
3996 3953
3997 virtual void DidCommitAndDrawFrame() OVERRIDE { 3954 virtual void DidCommitAndDrawFrame() OVERRIDE {
3998 // After commit, invalidate the layer. This should cause a commit. 3955 // After commit, invalidate the layer. This should cause a commit.
3999 if (layer_tree_host()->source_frame_number() == 1) 3956 if (layer_tree_host()->source_frame_number() == 1)
4000 invalidate_layer_->SetNeedsDisplay(); 3957 invalidate_layer_->SetNeedsDisplay();
4001 } 3958 }
4002 3959
4003 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 3960 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4004 num_draws_++; 3961 num_draws_++;
4005 if (impl->active_tree()->source_frame_number() == 1) 3962 if (impl->active_tree()->source_frame_number() == 1)
4006 EndTest(); 3963 EndTest();
4007 } 3964 }
4008 3965
4009 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 3966 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4010 num_commits_++; 3967 num_commits_++;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4234 // Commits can only be aborted when using the thread proxy. 4191 // Commits can only be aborted when using the thread proxy.
4235 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); 4192 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures);
4236 4193
4237 class LayerTreeHostTestMaxTransferBufferUsageBytes : public LayerTreeHostTest { 4194 class LayerTreeHostTestMaxTransferBufferUsageBytes : public LayerTreeHostTest {
4238 protected: 4195 protected:
4239 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 4196 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
4240 settings->impl_side_painting = true; 4197 settings->impl_side_painting = true;
4241 settings->default_tile_size = gfx::Size(128, 128); 4198 settings->default_tile_size = gfx::Size(128, 128);
4242 } 4199 }
4243 4200
4244 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 4201 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurfaceForTest(
4245 OVERRIDE { 4202 bool fallback) OVERRIDE {
4246 scoped_refptr<TestContextProvider> context_provider = 4203 scoped_refptr<TestContextProvider> context_provider =
4247 TestContextProvider::Create(); 4204 TestContextProvider::Create();
4248 context_provider->SetMaxTransferBufferUsageBytes(1024 * 1024); 4205 context_provider->SetMaxTransferBufferUsageBytes(1024 * 1024);
4249 return FakeOutputSurface::Create3d(context_provider) 4206 return FakeOutputSurface::Create3d(context_provider);
4250 .PassAs<OutputSurface>();
4251 } 4207 }
4252 4208
4253 virtual void SetupTree() OVERRIDE { 4209 virtual void SetupTree() OVERRIDE {
4254 scoped_refptr<FakePictureLayer> root_layer = 4210 scoped_refptr<FakePictureLayer> root_layer =
4255 FakePictureLayer::Create(&client_); 4211 FakePictureLayer::Create(&client_);
4256 root_layer->SetBounds(gfx::Size(6000, 6000)); 4212 root_layer->SetBounds(gfx::Size(6000, 6000));
4257 root_layer->SetIsDrawable(true); 4213 root_layer->SetIsDrawable(true);
4258 4214
4259 layer_tree_host()->SetRootLayer(root_layer); 4215 layer_tree_host()->SetRootLayer(root_layer);
4260 LayerTreeHostTest::SetupTree(); 4216 LayerTreeHostTest::SetupTree();
4261 } 4217 }
4262 4218
4263 virtual void BeginTest() OVERRIDE { 4219 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4264 PostSetNeedsCommitToMainThread();
4265 }
4266 4220
4267 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4221 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4268 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( 4222 TestWebGraphicsContext3D* context = TestContext();
4269 impl->output_surface()->context_provider().get())->TestContext3d();
4270 4223
4271 // Expect that the transfer buffer memory used is equal to the 4224 // Expect that the transfer buffer memory used is equal to the
4272 // MaxTransferBufferUsageBytes value set in CreateOutputSurface. 4225 // MaxTransferBufferUsageBytes value set in CreateOutputSurface.
4273 // NOTE: This is now 1/2 due to raster memory limit in TileManager. 4226 // NOTE: This is now 1/2 due to raster memory limit in TileManager.
4274 // Only half the limit will be reached unless the task set 4227 // Only half the limit will be reached unless the task set
4275 // thrashes to a completly new set of tiles. 4228 // thrashes to a completly new set of tiles.
4276 EXPECT_EQ(512 * 1024u, 4229 EXPECT_EQ(512 * 1024u, context->GetPeakTransferBufferMemoryUsedBytes());
4277 context->GetPeakTransferBufferMemoryUsedBytes());
4278 EndTest(); 4230 EndTest();
4279 } 4231 }
4280 4232
4281 virtual void AfterTest() OVERRIDE {} 4233 virtual void AfterTest() OVERRIDE {}
4282 4234
4283 private: 4235 private:
4284 FakeContentLayerClient client_; 4236 FakeContentLayerClient client_;
4285 }; 4237 };
4286 4238
4287 // Impl-side painting is a multi-threaded compositor feature. 4239 // Impl-side painting is a multi-threaded compositor feature.
4288 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes); 4240 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes);
4289 4241
4290 // Test ensuring that memory limits are sent to the prioritized resource 4242 // Test ensuring that memory limits are sent to the prioritized resource
4291 // manager. 4243 // manager.
4292 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest { 4244 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest {
4293 public: 4245 public:
4294 LayerTreeHostTestMemoryLimits() : num_commits_(0) {} 4246 LayerTreeHostTestMemoryLimits() : num_commits_(0) {}
4295 4247
4296 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4248 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4297 4249
4298 virtual void DidCommit() OVERRIDE { 4250 virtual void DidCommit() OVERRIDE {
4299 int frame = num_commits_; 4251 int frame = num_commits_;
4300 switch (frame) { 4252 switch (frame) {
4301 case 0: 4253 case 0:
4302 // Verify default values. 4254 // Verify default values.
4303 EXPECT_EQ( 4255 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4304 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4256 layer_tree_host()
4305 layer_tree_host()->contents_texture_manager()-> 4257 ->contents_texture_manager()
4306 MaxMemoryLimitBytes()); 4258 ->MaxMemoryLimitBytes());
4307 EXPECT_EQ( 4259 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4308 PriorityCalculator::AllowEverythingCutoff(), 4260 layer_tree_host()
4309 layer_tree_host()->contents_texture_manager()-> 4261 ->contents_texture_manager()
4310 ExternalPriorityCutoff()); 4262 ->ExternalPriorityCutoff());
4311 PostSetNeedsCommitToMainThread(); 4263 PostSetNeedsCommitToMainThread();
4312 break; 4264 break;
4313 case 1: 4265 case 1:
4314 // The values should remain the same until the commit after the policy 4266 // The values should remain the same until the commit after the policy
4315 // is changed. 4267 // is changed.
4316 EXPECT_EQ( 4268 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4317 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4269 layer_tree_host()
4318 layer_tree_host()->contents_texture_manager()-> 4270 ->contents_texture_manager()
4319 MaxMemoryLimitBytes()); 4271 ->MaxMemoryLimitBytes());
4320 EXPECT_EQ( 4272 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4321 PriorityCalculator::AllowEverythingCutoff(), 4273 layer_tree_host()
4322 layer_tree_host()->contents_texture_manager()-> 4274 ->contents_texture_manager()
4323 ExternalPriorityCutoff()); 4275 ->ExternalPriorityCutoff());
4324 break; 4276 break;
4325 case 2: 4277 case 2:
4326 // Verify values were correctly passed. 4278 // Verify values were correctly passed.
4327 EXPECT_EQ( 4279 EXPECT_EQ(16u * 1024u * 1024u,
4328 16u*1024u*1024u, 4280 layer_tree_host()
4329 layer_tree_host()->contents_texture_manager()-> 4281 ->contents_texture_manager()
4330 MaxMemoryLimitBytes()); 4282 ->MaxMemoryLimitBytes());
4331 EXPECT_EQ( 4283 EXPECT_EQ(PriorityCalculator::AllowVisibleAndNearbyCutoff(),
4332 PriorityCalculator::AllowVisibleAndNearbyCutoff(), 4284 layer_tree_host()
4333 layer_tree_host()->contents_texture_manager()-> 4285 ->contents_texture_manager()
4334 ExternalPriorityCutoff()); 4286 ->ExternalPriorityCutoff());
4335 EndTest(); 4287 EndTest();
4336 break; 4288 break;
4337 case 3: 4289 case 3:
4338 // Make sure no extra commits happen. 4290 // Make sure no extra commits happen.
4339 NOTREACHED(); 4291 NOTREACHED();
4340 break; 4292 break;
4341 } 4293 }
4342 4294
4343 ++num_commits_; 4295 ++num_commits_;
4344 } 4296 }
4345 4297
4346 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4298 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4347 int frame = num_commits_; 4299 int frame = num_commits_;
4348 switch (frame) { 4300 switch (frame) {
4349 case 0: 4301 case 0:
4350 break; 4302 break;
4351 case 1: 4303 case 1:
4352 // This will trigger a commit because the priority cutoff has changed. 4304 // This will trigger a commit because the priority cutoff has changed.
4353 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4305 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4354 16u*1024u*1024u, 4306 16u * 1024u * 1024u,
4355 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4307 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4356 1000)); 4308 1000));
4357 break; 4309 break;
4358 case 2: 4310 case 2:
4359 // This will not trigger a commit because the priority cutoff has not 4311 // This will not trigger a commit because the priority cutoff has not
4360 // changed, and there is already enough memory for all allocations. 4312 // changed, and there is already enough memory for all allocations.
4361 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4313 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4362 32u*1024u*1024u, 4314 32u * 1024u * 1024u,
4363 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4315 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4364 1000)); 4316 1000));
4365 break; 4317 break;
4366 case 3: 4318 case 3:
4367 NOTREACHED(); 4319 NOTREACHED();
4368 break; 4320 break;
4369 } 4321 }
4370 } 4322 }
4371 4323
4372 virtual void AfterTest() OVERRIDE {} 4324 virtual void AfterTest() OVERRIDE {}
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
4451 virtual void SetupTree() OVERRIDE { 4403 virtual void SetupTree() OVERRIDE {
4452 LayerTreeHostTest::SetupTree(); 4404 LayerTreeHostTest::SetupTree();
4453 root_layer_ = FakeContentLayer::Create(&client_); 4405 root_layer_ = FakeContentLayer::Create(&client_);
4454 root_layer_->SetBounds(gfx::Size(10, 10)); 4406 root_layer_->SetBounds(gfx::Size(10, 10));
4455 root_layer_->SetIsDrawable(false); 4407 root_layer_->SetIsDrawable(false);
4456 root_layer_->SetHaveWheelEventHandlers(true); 4408 root_layer_->SetHaveWheelEventHandlers(true);
4457 layer_tree_host()->SetRootLayer(root_layer_); 4409 layer_tree_host()->SetRootLayer(root_layer_);
4458 LayerTreeHostTest::SetupTree(); 4410 LayerTreeHostTest::SetupTree();
4459 } 4411 }
4460 4412
4461 virtual void BeginTest() OVERRIDE { 4413 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4462 PostSetNeedsCommitToMainThread();
4463 }
4464 4414
4465 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 4415 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
4466 FakeContentLayerImpl* layer_impl = 4416 FakeContentLayerImpl* layer_impl =
4467 static_cast<FakeContentLayerImpl*>(impl->RootLayer()); 4417 static_cast<FakeContentLayerImpl*>(impl->RootLayer());
4468 EXPECT_FALSE(layer_impl->DrawsContent()); 4418 EXPECT_FALSE(layer_impl->DrawsContent());
4469 EXPECT_EQ(0u, layer_impl->append_quads_count()); 4419 EXPECT_EQ(0u, layer_impl->append_quads_count());
4470 } 4420 }
4471 4421
4472 virtual void DidCommit() OVERRIDE { 4422 virtual void DidCommit() OVERRIDE {
4473 // The layer is not drawable, so it should not be updated. 4423 // The layer is not drawable, so it should not be updated.
4474 EXPECT_EQ(0u, root_layer_->update_count()); 4424 EXPECT_EQ(0u, root_layer_->update_count());
4475 EndTest(); 4425 EndTest();
4476 } 4426 }
4477 virtual void AfterTest() OVERRIDE {} 4427 virtual void AfterTest() OVERRIDE {}
4478 4428
4479 private: 4429 private:
4480 FakeContentLayerClient client_; 4430 FakeContentLayerClient client_;
4481 scoped_refptr<FakeContentLayer> root_layer_; 4431 scoped_refptr<FakeContentLayer> root_layer_;
4482 }; 4432 };
4483 4433
4484 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoQuadsForEmptyLayer); 4434 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoQuadsForEmptyLayer);
4485 4435
4486
4487 } // namespace 4436 } // namespace
4488 4437
4489 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface 4438 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
4490 : public LayerTreeHostTest { 4439 : public LayerTreeHostTest {
4491 protected: 4440 protected:
4492 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface() 4441 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface()
4493 : first_output_surface_memory_limit_(4321234), 4442 : first_output_surface_memory_limit_(4321234),
4494 second_output_surface_memory_limit_(1234321) {} 4443 second_output_surface_memory_limit_(1234321) {}
4495 4444
4496 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 4445 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
4497 OVERRIDE { 4446 OVERRIDE {
4498 if (!first_context_provider_) { 4447 if (!first_context_provider_) {
4499 first_context_provider_ = TestContextProvider::Create(); 4448 first_context_provider_ = TestContextProvider::Create();
4500 } else { 4449 } else {
4501 EXPECT_FALSE(second_context_provider_); 4450 EXPECT_FALSE(second_context_provider_);
4502 second_context_provider_ = TestContextProvider::Create(); 4451 second_context_provider_ = TestContextProvider::Create();
4503 } 4452 }
4504 4453
4505 scoped_ptr<FakeOutputSurface> output_surface( 4454 scoped_ptr<FakeOutputSurface> output_surface(FakeOutputSurface::Create3d(
4506 FakeOutputSurface::Create3d( 4455 second_context_provider_ ? second_context_provider_
4507 second_context_provider_ ? 4456 : first_context_provider_));
4508 second_context_provider_ : 4457 output_surface->SetMemoryPolicyToSetAtBind(
4509 first_context_provider_)); 4458 make_scoped_ptr(new ManagedMemoryPolicy(
4510 output_surface->SetMemoryPolicyToSetAtBind(make_scoped_ptr( 4459 second_context_provider_ ? second_output_surface_memory_limit_
4511 new ManagedMemoryPolicy( 4460 : first_output_surface_memory_limit_,
4512 second_context_provider_ ?
4513 second_output_surface_memory_limit_ :
4514 first_output_surface_memory_limit_,
4515 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4461 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4516 ManagedMemoryPolicy::kDefaultNumResourcesLimit))); 4462 ManagedMemoryPolicy::kDefaultNumResourcesLimit)));
4517 return output_surface.PassAs<OutputSurface>(); 4463 return output_surface.PassAs<OutputSurface>();
4518 } 4464 }
4519 4465
4520 virtual void SetupTree() OVERRIDE { 4466 virtual void SetupTree() OVERRIDE {
4521 root_ = FakeContentLayer::Create(&client_); 4467 root_ = FakeContentLayer::Create(&client_);
4522 root_->SetBounds(gfx::Size(20, 20)); 4468 root_->SetBounds(gfx::Size(20, 20));
4523 layer_tree_host()->SetRootLayer(root_); 4469 layer_tree_host()->SetRootLayer(root_);
4524 LayerTreeHostTest::SetupTree(); 4470 LayerTreeHostTest::SetupTree();
4525 } 4471 }
4526 4472
4527 virtual void BeginTest() OVERRIDE { 4473 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4528 PostSetNeedsCommitToMainThread();
4529 }
4530 4474
4531 virtual void DidCommitAndDrawFrame() OVERRIDE { 4475 virtual void DidCommitAndDrawFrame() OVERRIDE {
4532 // Lost context sometimes takes two frames to recreate. The third frame 4476 // Lost context sometimes takes two frames to recreate. The third frame
4533 // is sometimes aborted, so wait until the fourth frame to verify that 4477 // is sometimes aborted, so wait until the fourth frame to verify that
4534 // the memory has been set, and the fifth frame to end the test. 4478 // the memory has been set, and the fifth frame to end the test.
4535 if (layer_tree_host()->source_frame_number() < 5) { 4479 if (layer_tree_host()->source_frame_number() < 5) {
4536 layer_tree_host()->SetNeedsCommit(); 4480 layer_tree_host()->SetNeedsCommit();
4537 } else if (layer_tree_host()->source_frame_number() == 5) { 4481 } else if (layer_tree_host()->source_frame_number() == 5) {
4538 EndTest(); 4482 EndTest();
4539 } 4483 }
4540 } 4484 }
4541 4485
4542 virtual void SwapBuffersOnThread(LayerTreeHostImpl *impl, bool result) 4486 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl,
4543 OVERRIDE { 4487 bool result) OVERRIDE {
4544 switch (impl->active_tree()->source_frame_number()) { 4488 switch (impl->active_tree()->source_frame_number()) {
4545 case 1: 4489 case 1:
4546 EXPECT_EQ(first_output_surface_memory_limit_, 4490 EXPECT_EQ(first_output_surface_memory_limit_,
4547 impl->memory_allocation_limit_bytes()); 4491 impl->memory_allocation_limit_bytes());
4548 // Lose the output surface. 4492 // Lose the output surface.
4549 first_context_provider_->TestContext3d()->loseContextCHROMIUM( 4493 first_context_provider_->TestContext3d()->loseContextCHROMIUM(
4550 GL_GUILTY_CONTEXT_RESET_ARB, 4494 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
4551 GL_INNOCENT_CONTEXT_RESET_ARB);
4552 break; 4495 break;
4553 case 4: 4496 case 4:
4554 EXPECT_EQ(second_output_surface_memory_limit_, 4497 EXPECT_EQ(second_output_surface_memory_limit_,
4555 impl->memory_allocation_limit_bytes()); 4498 impl->memory_allocation_limit_bytes());
4556 break; 4499 break;
4557 } 4500 }
4558 } 4501 }
4559 4502
4560 virtual void AfterTest() OVERRIDE {} 4503 virtual void AfterTest() OVERRIDE {}
4561 4504
4562 scoped_refptr<TestContextProvider> first_context_provider_; 4505 scoped_refptr<TestContextProvider> first_context_provider_;
4563 scoped_refptr<TestContextProvider> second_context_provider_; 4506 scoped_refptr<TestContextProvider> second_context_provider_;
4564 size_t first_output_surface_memory_limit_; 4507 size_t first_output_surface_memory_limit_;
4565 size_t second_output_surface_memory_limit_; 4508 size_t second_output_surface_memory_limit_;
4566 FakeContentLayerClient client_; 4509 FakeContentLayerClient client_;
4567 scoped_refptr<FakeContentLayer> root_; 4510 scoped_refptr<FakeContentLayer> root_;
4568 }; 4511 };
4569 4512
4570 // No output to copy for delegated renderers. 4513 // No output to copy for delegated renderers.
4571 SINGLE_AND_MULTI_THREAD_TEST_F( 4514 SINGLE_AND_MULTI_THREAD_TEST_F(
4572 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); 4515 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface);
4573 4516
4574 struct TestSwapPromiseResult { 4517 struct TestSwapPromiseResult {
4575 TestSwapPromiseResult() : did_swap_called(false), 4518 TestSwapPromiseResult()
4576 did_not_swap_called(false), 4519 : did_swap_called(false),
4577 dtor_called(false), 4520 did_not_swap_called(false),
4578 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) { 4521 dtor_called(false),
4579 } 4522 reason(SwapPromise::DID_NOT_SWAP_UNKNOWN) {}
4580 4523
4581 bool did_swap_called; 4524 bool did_swap_called;
4582 bool did_not_swap_called; 4525 bool did_not_swap_called;
4583 bool dtor_called; 4526 bool dtor_called;
4584 SwapPromise::DidNotSwapReason reason; 4527 SwapPromise::DidNotSwapReason reason;
4585 base::Lock lock; 4528 base::Lock lock;
4586 }; 4529 };
4587 4530
4588 class TestSwapPromise : public SwapPromise { 4531 class TestSwapPromise : public SwapPromise {
4589 public: 4532 public:
4590 explicit TestSwapPromise(TestSwapPromiseResult* result) 4533 explicit TestSwapPromise(TestSwapPromiseResult* result) : result_(result) {}
4591 : result_(result) {
4592 }
4593 4534
4594 virtual ~TestSwapPromise() { 4535 virtual ~TestSwapPromise() {
4595 base::AutoLock lock(result_->lock); 4536 base::AutoLock lock(result_->lock);
4596 result_->dtor_called = true; 4537 result_->dtor_called = true;
4597 } 4538 }
4598 4539
4599 virtual void DidSwap(CompositorFrameMetadata* metadata) OVERRIDE { 4540 virtual void DidSwap(CompositorFrameMetadata* metadata) OVERRIDE {
4600 base::AutoLock lock(result_->lock); 4541 base::AutoLock lock(result_->lock);
4601 EXPECT_FALSE(result_->did_swap_called); 4542 EXPECT_FALSE(result_->did_swap_called);
4602 EXPECT_FALSE(result_->did_not_swap_called); 4543 EXPECT_FALSE(result_->did_not_swap_called);
4603 result_->did_swap_called = true; 4544 result_->did_swap_called = true;
4604 } 4545 }
4605 4546
4606 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { 4547 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE {
4607 base::AutoLock lock(result_->lock); 4548 base::AutoLock lock(result_->lock);
4608 EXPECT_FALSE(result_->did_swap_called); 4549 EXPECT_FALSE(result_->did_swap_called);
4609 EXPECT_FALSE(result_->did_not_swap_called); 4550 EXPECT_FALSE(result_->did_not_swap_called);
4610 result_->did_not_swap_called = true; 4551 result_->did_not_swap_called = true;
4611 result_->reason = reason; 4552 result_->reason = reason;
4612 } 4553 }
4613 4554
4614 private: 4555 private:
4615 // Not owned. 4556 // Not owned.
4616 TestSwapPromiseResult* result_; 4557 TestSwapPromiseResult* result_;
4617 }; 4558 };
4618 4559
4619 class LayerTreeHostTestBreakSwapPromise 4560 class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest {
4620 : public LayerTreeHostTest {
4621 protected: 4561 protected:
4622 LayerTreeHostTestBreakSwapPromise() 4562 LayerTreeHostTestBreakSwapPromise()
4623 : commit_count_(0), commit_complete_count_(0) { 4563 : commit_count_(0), commit_complete_count_(0) {}
4624 }
4625 4564
4626 virtual void WillBeginMainFrame() OVERRIDE { 4565 virtual void WillBeginMainFrame() OVERRIDE {
4627 ASSERT_LE(commit_count_, 2); 4566 ASSERT_LE(commit_count_, 2);
4628 scoped_ptr<SwapPromise> swap_promise(new TestSwapPromise( 4567 scoped_ptr<SwapPromise> swap_promise(
4629 &swap_promise_result_[commit_count_])); 4568 new TestSwapPromise(&swap_promise_result_[commit_count_]));
4630 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4569 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4631 } 4570 }
4632 4571
4633 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4572 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4634 4573
4635 virtual void DidCommit() OVERRIDE { 4574 virtual void DidCommit() OVERRIDE {
4636 commit_count_++; 4575 commit_count_++;
4637 if (commit_count_ == 2) { 4576 if (commit_count_ == 2) {
4638 // This commit will finish. 4577 // This commit will finish.
4639 layer_tree_host()->SetNeedsCommit(); 4578 layer_tree_host()->SetNeedsCommit();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4684 } 4623 }
4685 } 4624 }
4686 4625
4687 int commit_count_; 4626 int commit_count_;
4688 int commit_complete_count_; 4627 int commit_complete_count_;
4689 TestSwapPromiseResult swap_promise_result_[3]; 4628 TestSwapPromiseResult swap_promise_result_[3];
4690 }; 4629 };
4691 4630
4692 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); 4631 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise);
4693 4632
4694
4695 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4633 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4696 public: 4634 public:
4697 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4635 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4698 LayerTreeHostImpl* layer_tree_host_impl, 4636 LayerTreeHostImpl* layer_tree_host_impl,
4699 int* set_needs_commit_count, 4637 int* set_needs_commit_count,
4700 int* set_needs_redraw_count) 4638 int* set_needs_redraw_count)
4701 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4639 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4702 set_needs_commit_count_(set_needs_commit_count), 4640 set_needs_commit_count_(set_needs_commit_count),
4703 set_needs_redraw_count_(set_needs_redraw_count) {} 4641 set_needs_redraw_count_(set_needs_redraw_count) {}
4704 4642
4705 virtual ~SimpleSwapPromiseMonitor() {} 4643 virtual ~SimpleSwapPromiseMonitor() {}
4706 4644
4707 virtual void OnSetNeedsCommitOnMain() OVERRIDE { 4645 virtual void OnSetNeedsCommitOnMain() OVERRIDE {
4708 (*set_needs_commit_count_)++; 4646 (*set_needs_commit_count_)++;
4709 } 4647 }
4710 4648
4711 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE { 4649 virtual void OnSetNeedsRedrawOnImpl() OVERRIDE {
4712 (*set_needs_redraw_count_)++; 4650 (*set_needs_redraw_count_)++;
4713 } 4651 }
4714 4652
4715 private: 4653 private:
4716 int* set_needs_commit_count_; 4654 int* set_needs_commit_count_;
4717 int* set_needs_redraw_count_; 4655 int* set_needs_redraw_count_;
4718 }; 4656 };
4719 4657
4720 class LayerTreeHostTestSimpleSwapPromiseMonitor 4658 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest {
4721 : public LayerTreeHostTest { 4659 public:
4722
4723 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4660 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4724 4661
4725 virtual void WillBeginMainFrame() OVERRIDE { 4662 virtual void WillBeginMainFrame() OVERRIDE {
4726 int set_needs_commit_count = 0; 4663 int set_needs_commit_count = 0;
4727 int set_needs_redraw_count = 0; 4664 int set_needs_redraw_count = 0;
4728 4665
4729 { 4666 {
4730 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( 4667 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor(
4731 new SimpleSwapPromiseMonitor(layer_tree_host(), 4668 new SimpleSwapPromiseMonitor(layer_tree_host(),
4732 NULL, 4669 NULL,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4767 4704
4768 EndTest(); 4705 EndTest();
4769 } 4706 }
4770 4707
4771 virtual void AfterTest() OVERRIDE {} 4708 virtual void AfterTest() OVERRIDE {}
4772 }; 4709 };
4773 4710
4774 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); 4711 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor);
4775 4712
4776 } // namespace cc 4713 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_in_process_context_provider.cc ('k') | cc/trees/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698