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

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

Issue 672283003: cc: ReadyToDraw notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve tests. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 using testing::_; 62 using testing::_;
63 using testing::AnyNumber; 63 using testing::AnyNumber;
64 using testing::AtLeast; 64 using testing::AtLeast;
65 using testing::Mock; 65 using testing::Mock;
66 66
67 namespace cc { 67 namespace cc {
68 namespace { 68 namespace {
69 69
70 class LayerTreeHostTest : public LayerTreeTest {}; 70 class LayerTreeHostTest : public LayerTreeTest {};
71 71
72 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
73 // when no raster tasks get scheduled.
74 class LayerTreeHostTestReadyToActivate : public LayerTreeHostTest {
75 public:
76 LayerTreeHostTestReadyToActivate()
77 : did_notify_ready_to_activate_(false),
78 all_tiles_required_for_activation_are_ready_to_draw_(false) {}
79
80 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
81
82 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
83 did_notify_ready_to_activate_ = true;
84 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers();
85 all_tiles_required_for_activation_are_ready_to_draw_ = true;
86 for (const auto& layer : layers) {
87 if (!layer->AllTilesRequiredForActivationAreReadyToDraw())
88 all_tiles_required_for_activation_are_ready_to_draw_ = false;
89 }
90 EndTest();
91 }
92
93 void AfterTest() override {
94 EXPECT_TRUE(did_notify_ready_to_activate_);
95 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_);
96 }
97
98 private:
99 bool did_notify_ready_to_activate_;
100 bool all_tiles_required_for_activation_are_ready_to_draw_;
101 };
102
103 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivate);
104
105 // Test if the LTHI receives ReadyToActivate notifications from the TileManager
106 // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled.
107 class LayerTreeHostTestReadyToActivateNonEmpty
108 : public LayerTreeHostTestReadyToActivate {
109 public:
110 void SetupTree() override {
111 client_.set_fill_with_nonsolid_color(true);
112 scoped_refptr<FakePictureLayer> root_layer =
113 FakePictureLayer::Create(&client_);
114 root_layer->SetBounds(gfx::Size(1024, 1024));
115 root_layer->SetIsDrawable(true);
116
117 layer_tree_host()->SetRootLayer(root_layer);
118 LayerTreeHostTest::SetupTree();
119 }
120
121 private:
122 FakeContentLayerClient client_;
123 };
124
125 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty);
126
127 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
128 // no raster tasks get scheduled.
129 class LayerTreeHostTestReadyToDraw : public LayerTreeHostTest {
enne (OOO) 2014/11/10 20:02:12 Can you add some DCHECK that verifies that this is
ernstm 2014/11/11 01:36:39 Done.
130 public:
131 LayerTreeHostTestReadyToDraw()
132 : did_notify_ready_to_draw_(false),
133 all_tiles_required_for_draw_are_ready_to_draw_(false) {}
134
135 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
136
137 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override {
138 did_notify_ready_to_draw_ = true;
139 const std::vector<PictureLayerImpl*>& layers = impl->GetPictureLayers();
140 all_tiles_required_for_draw_are_ready_to_draw_ = true;
141 for (const auto& layer : layers) {
142 if (!layer->AllTilesRequiredForDrawAreReadyToDraw())
143 all_tiles_required_for_draw_are_ready_to_draw_ = false;
144 }
145 EndTest();
146 }
147
148 void AfterTest() override {
149 EXPECT_TRUE(did_notify_ready_to_draw_);
150 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_);
151 }
152
153 private:
154 bool did_notify_ready_to_draw_;
155 bool all_tiles_required_for_draw_are_ready_to_draw_;
156 };
157
158 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDraw);
159
160 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when
161 // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled.
162 class LayerTreeHostTestReadyToDrawNonEmpty
enne (OOO) 2014/11/10 20:02:12 Can you add some DCHECK that verifies that this is
ernstm 2014/11/11 01:36:39 Done.
163 : public LayerTreeHostTestReadyToDraw {
164 public:
165 void SetupTree() override {
166 client_.set_fill_with_nonsolid_color(true);
167 scoped_refptr<FakePictureLayer> root_layer =
168 FakePictureLayer::Create(&client_);
169 root_layer->SetBounds(gfx::Size(1024, 1024));
170 root_layer->SetIsDrawable(true);
171
172 layer_tree_host()->SetRootLayer(root_layer);
173 LayerTreeHostTest::SetupTree();
174 }
175
176 private:
177 FakeContentLayerClient client_;
178 };
179
180 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
181 // single threaded mode.
182 SINGLE_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty);
183
72 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 184 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
73 // draw with frame 0. 185 // draw with frame 0.
74 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { 186 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest {
75 public: 187 public:
76 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {} 188 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
77 189
78 void BeginTest() override { 190 void BeginTest() override {
79 PostSetNeedsCommitToMainThread(); 191 PostSetNeedsCommitToMainThread();
80 PostSetNeedsCommitToMainThread(); 192 PostSetNeedsCommitToMainThread();
81 } 193 }
(...skipping 5117 matching lines...) Expand 10 before | Expand all | Expand 10 after
5199 void AfterTest() override { 5311 void AfterTest() override {
5200 EXPECT_TRUE(deltas_sent_to_client_); 5312 EXPECT_TRUE(deltas_sent_to_client_);
5201 } 5313 }
5202 5314
5203 ScrollAndScaleSet info_; 5315 ScrollAndScaleSet info_;
5204 bool deltas_sent_to_client_; 5316 bool deltas_sent_to_client_;
5205 }; 5317 };
5206 5318
5207 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); 5319 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer);
5208 } // namespace cc 5320 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698