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

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

Issue 645853008: Standardize usage of virtual/override/final in cc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 namespace { 68 namespace {
69 69
70 class LayerTreeHostTest : public LayerTreeTest {}; 70 class LayerTreeHostTest : public LayerTreeTest {};
71 71
72 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 72 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
73 // draw with frame 0. 73 // draw with frame 0.
74 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { 74 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest {
75 public: 75 public:
76 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {} 76 LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
77 77
78 virtual void BeginTest() override { 78 void BeginTest() override {
79 PostSetNeedsCommitToMainThread(); 79 PostSetNeedsCommitToMainThread();
80 PostSetNeedsCommitToMainThread(); 80 PostSetNeedsCommitToMainThread();
81 } 81 }
82 82
83 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 83 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
84 num_draws_++; 84 num_draws_++;
85 if (!impl->active_tree()->source_frame_number()) 85 if (!impl->active_tree()->source_frame_number())
86 EndTest(); 86 EndTest();
87 } 87 }
88 88
89 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 89 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
90 num_commits_++; 90 num_commits_++;
91 } 91 }
92 92
93 virtual void AfterTest() override { 93 void AfterTest() override {
94 EXPECT_LE(1, num_commits_); 94 EXPECT_LE(1, num_commits_);
95 EXPECT_LE(1, num_draws_); 95 EXPECT_LE(1, num_draws_);
96 } 96 }
97 97
98 private: 98 private:
99 int num_commits_; 99 int num_commits_;
100 int num_draws_; 100 int num_draws_;
101 }; 101 };
102 102
103 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1); 103 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1);
104 104
105 // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that 105 // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that
106 // first committed frame draws should lead to another commit. 106 // first committed frame draws should lead to another commit.
107 class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { 107 class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest {
108 public: 108 public:
109 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {} 109 LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {}
110 110
111 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 111 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
112 112
113 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 113 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { ++num_draws_; }
114 ++num_draws_;
115 }
116 114
117 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 115 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
118 ++num_commits_; 116 ++num_commits_;
119 switch (num_commits_) { 117 switch (num_commits_) {
120 case 1: 118 case 1:
121 PostSetNeedsCommitToMainThread(); 119 PostSetNeedsCommitToMainThread();
122 break; 120 break;
123 case 2: 121 case 2:
124 EndTest(); 122 EndTest();
125 break; 123 break;
126 default: 124 default:
127 NOTREACHED(); 125 NOTREACHED();
128 } 126 }
129 } 127 }
130 128
131 virtual void AfterTest() override { 129 void AfterTest() override {
132 EXPECT_EQ(2, num_commits_); 130 EXPECT_EQ(2, num_commits_);
133 EXPECT_LE(1, num_draws_); 131 EXPECT_LE(1, num_draws_);
134 } 132 }
135 133
136 private: 134 private:
137 int num_commits_; 135 int num_commits_;
138 int num_draws_; 136 int num_draws_;
139 }; 137 };
140 138
141 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); 139 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2);
142 140
143 // Verify that we pass property values in PushPropertiesTo. 141 // Verify that we pass property values in PushPropertiesTo.
144 class LayerTreeHostTestPushPropertiesTo : public LayerTreeHostTest { 142 class LayerTreeHostTestPushPropertiesTo : public LayerTreeHostTest {
145 protected: 143 protected:
146 virtual void SetupTree() override { 144 void SetupTree() override {
147 scoped_refptr<Layer> root = Layer::Create(); 145 scoped_refptr<Layer> root = Layer::Create();
148 root->SetBounds(gfx::Size(10, 10)); 146 root->SetBounds(gfx::Size(10, 10));
149 layer_tree_host()->SetRootLayer(root); 147 layer_tree_host()->SetRootLayer(root);
150 LayerTreeHostTest::SetupTree(); 148 LayerTreeHostTest::SetupTree();
151 } 149 }
152 150
153 enum Properties { 151 enum Properties {
154 STARTUP, 152 STARTUP,
155 BOUNDS, 153 BOUNDS,
156 HIDE_LAYER_AND_SUBTREE, 154 HIDE_LAYER_AND_SUBTREE,
157 DRAWS_CONTENT, 155 DRAWS_CONTENT,
158 DONE, 156 DONE,
159 }; 157 };
160 158
161 virtual void BeginTest() override { 159 void BeginTest() override {
162 index_ = STARTUP; 160 index_ = STARTUP;
163 PostSetNeedsCommitToMainThread(); 161 PostSetNeedsCommitToMainThread();
164 } 162 }
165 163
166 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 164 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
167 VerifyAfterValues(impl->active_tree()->root_layer()); 165 VerifyAfterValues(impl->active_tree()->root_layer());
168 } 166 }
169 167
170 virtual void DidCommitAndDrawFrame() override { 168 void DidCommitAndDrawFrame() override {
171 SetBeforeValues(layer_tree_host()->root_layer()); 169 SetBeforeValues(layer_tree_host()->root_layer());
172 VerifyBeforeValues(layer_tree_host()->root_layer()); 170 VerifyBeforeValues(layer_tree_host()->root_layer());
173 171
174 ++index_; 172 ++index_;
175 if (index_ == DONE) { 173 if (index_ == DONE) {
176 EndTest(); 174 EndTest();
177 return; 175 return;
178 } 176 }
179 177
180 SetAfterValues(layer_tree_host()->root_layer()); 178 SetAfterValues(layer_tree_host()->root_layer());
181 } 179 }
182 180
183 virtual void AfterTest() override {} 181 void AfterTest() override {}
184 182
185 void VerifyBeforeValues(Layer* layer) { 183 void VerifyBeforeValues(Layer* layer) {
186 EXPECT_EQ(gfx::Size(10, 10).ToString(), layer->bounds().ToString()); 184 EXPECT_EQ(gfx::Size(10, 10).ToString(), layer->bounds().ToString());
187 EXPECT_FALSE(layer->hide_layer_and_subtree()); 185 EXPECT_FALSE(layer->hide_layer_and_subtree());
188 EXPECT_FALSE(layer->DrawsContent()); 186 EXPECT_FALSE(layer->DrawsContent());
189 } 187 }
190 188
191 void SetBeforeValues(Layer* layer) { 189 void SetBeforeValues(Layer* layer) {
192 layer->SetBounds(gfx::Size(10, 10)); 190 layer->SetBounds(gfx::Size(10, 10));
193 layer->SetHideLayerAndSubtree(false); 191 layer->SetHideLayerAndSubtree(false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 }; 230 };
233 231
234 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo); 232 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo);
235 233
236 // 1 setNeedsRedraw after the first commit has completed should lead to 1 234 // 1 setNeedsRedraw after the first commit has completed should lead to 1
237 // additional draw. 235 // additional draw.
238 class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest { 236 class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest {
239 public: 237 public:
240 LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {} 238 LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {}
241 239
242 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 240 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
243 241
244 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 242 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
245 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); 243 EXPECT_EQ(0, impl->active_tree()->source_frame_number());
246 if (!num_draws_) { 244 if (!num_draws_) {
247 // Redraw again to verify that the second redraw doesn't commit. 245 // Redraw again to verify that the second redraw doesn't commit.
248 PostSetNeedsRedrawToMainThread(); 246 PostSetNeedsRedrawToMainThread();
249 } else { 247 } else {
250 EndTest(); 248 EndTest();
251 } 249 }
252 num_draws_++; 250 num_draws_++;
253 } 251 }
254 252
255 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 253 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
256 EXPECT_EQ(0, num_draws_); 254 EXPECT_EQ(0, num_draws_);
257 num_commits_++; 255 num_commits_++;
258 } 256 }
259 257
260 virtual void AfterTest() override { 258 void AfterTest() override {
261 EXPECT_GE(2, num_draws_); 259 EXPECT_GE(2, num_draws_);
262 EXPECT_EQ(1, num_commits_); 260 EXPECT_EQ(1, num_commits_);
263 } 261 }
264 262
265 private: 263 private:
266 int num_commits_; 264 int num_commits_;
267 int num_draws_; 265 int num_draws_;
268 }; 266 };
269 267
270 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); 268 MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw);
271 269
272 // After setNeedsRedrawRect(invalid_rect) the final damage_rect 270 // After setNeedsRedrawRect(invalid_rect) the final damage_rect
273 // must contain invalid_rect. 271 // must contain invalid_rect.
274 class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { 272 class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest {
275 public: 273 public:
276 LayerTreeHostTestSetNeedsRedrawRect() 274 LayerTreeHostTestSetNeedsRedrawRect()
277 : num_draws_(0), 275 : num_draws_(0),
278 bounds_(50, 50), 276 bounds_(50, 50),
279 invalid_rect_(10, 10, 20, 20), 277 invalid_rect_(10, 10, 20, 20),
280 root_layer_(ContentLayer::Create(&client_)) {} 278 root_layer_(ContentLayer::Create(&client_)) {}
281 279
282 virtual void BeginTest() override { 280 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 DrawResult PrepareToDrawOnThread( 288 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
291 LayerTreeHostImpl* host_impl, 289 LayerTreeHostImpl::FrameData* frame_data,
292 LayerTreeHostImpl::FrameData* frame_data, 290 DrawResult draw_result) override {
293 DrawResult draw_result) override {
294 EXPECT_EQ(DRAW_SUCCESS, draw_result); 291 EXPECT_EQ(DRAW_SUCCESS, draw_result);
295 292
296 gfx::RectF root_damage_rect; 293 gfx::RectF root_damage_rect;
297 if (!frame_data->render_passes.empty()) 294 if (!frame_data->render_passes.empty())
298 root_damage_rect = frame_data->render_passes.back()->damage_rect; 295 root_damage_rect = frame_data->render_passes.back()->damage_rect;
299 296
300 if (!num_draws_) { 297 if (!num_draws_) {
301 // If this is the first frame, expect full frame damage. 298 // If this is the first frame, expect full frame damage.
302 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_)); 299 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_));
303 } else { 300 } else {
304 // Check that invalid_rect_ is indeed repainted. 301 // Check that invalid_rect_ is indeed repainted.
305 EXPECT_TRUE(root_damage_rect.Contains(invalid_rect_)); 302 EXPECT_TRUE(root_damage_rect.Contains(invalid_rect_));
306 } 303 }
307 304
308 return draw_result; 305 return draw_result;
309 } 306 }
310 307
311 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 308 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
312 if (!num_draws_) { 309 if (!num_draws_) {
313 PostSetNeedsRedrawRectToMainThread(invalid_rect_); 310 PostSetNeedsRedrawRectToMainThread(invalid_rect_);
314 } else { 311 } else {
315 EndTest(); 312 EndTest();
316 } 313 }
317 num_draws_++; 314 num_draws_++;
318 } 315 }
319 316
320 virtual void AfterTest() override { EXPECT_EQ(2, num_draws_); } 317 void AfterTest() override { EXPECT_EQ(2, num_draws_); }
321 318
322 private: 319 private:
323 int num_draws_; 320 int num_draws_;
324 const gfx::Size bounds_; 321 const gfx::Size bounds_;
325 const gfx::Rect invalid_rect_; 322 const gfx::Rect invalid_rect_;
326 FakeContentLayerClient client_; 323 FakeContentLayerClient client_;
327 scoped_refptr<ContentLayer> root_layer_; 324 scoped_refptr<ContentLayer> root_layer_;
328 }; 325 };
329 326
330 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); 327 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect);
331 328
332 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { 329 class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest {
333 public: 330 public:
334 virtual void InitializeSettings(LayerTreeSettings* settings) override { 331 void InitializeSettings(LayerTreeSettings* settings) override {
335 settings->layer_transforms_should_scale_layer_contents = true; 332 settings->layer_transforms_should_scale_layer_contents = true;
336 } 333 }
337 334
338 virtual void SetupTree() override { 335 void SetupTree() override {
339 root_layer_ = Layer::Create(); 336 root_layer_ = Layer::Create();
340 root_layer_->SetBounds(gfx::Size(10, 20)); 337 root_layer_->SetBounds(gfx::Size(10, 20));
341 338
342 scaled_layer_ = FakeContentLayer::Create(&client_); 339 scaled_layer_ = FakeContentLayer::Create(&client_);
343 scaled_layer_->SetBounds(gfx::Size(1, 1)); 340 scaled_layer_->SetBounds(gfx::Size(1, 1));
344 root_layer_->AddChild(scaled_layer_); 341 root_layer_->AddChild(scaled_layer_);
345 342
346 layer_tree_host()->SetRootLayer(root_layer_); 343 layer_tree_host()->SetRootLayer(root_layer_);
347 LayerTreeHostTest::SetupTree(); 344 LayerTreeHostTest::SetupTree();
348 } 345 }
349 346
350 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 347 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
351 348
352 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 349 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
353 if (host_impl->active_tree()->source_frame_number() == 1) 350 if (host_impl->active_tree()->source_frame_number() == 1)
354 EndTest(); 351 EndTest();
355 } 352 }
356 353
357 virtual void DidCommit() override { 354 void DidCommit() override {
358 switch (layer_tree_host()->source_frame_number()) { 355 switch (layer_tree_host()->source_frame_number()) {
359 case 1: 356 case 1:
360 // Changing the device scale factor causes a commit. It also changes 357 // Changing the device scale factor causes a commit. It also changes
361 // the content bounds of |scaled_layer_|, which should not generate 358 // the content bounds of |scaled_layer_|, which should not generate
362 // a second commit as a result. 359 // a second commit as a result.
363 layer_tree_host()->SetDeviceScaleFactor(4.f); 360 layer_tree_host()->SetDeviceScaleFactor(4.f);
364 break; 361 break;
365 default: 362 default:
366 // No extra commits. 363 // No extra commits.
367 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); 364 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
368 } 365 }
369 } 366 }
370 367
371 virtual void AfterTest() override { 368 void AfterTest() override {
372 EXPECT_EQ(gfx::Size(4, 4).ToString(), 369 EXPECT_EQ(gfx::Size(4, 4).ToString(),
373 scaled_layer_->content_bounds().ToString()); 370 scaled_layer_->content_bounds().ToString());
374 } 371 }
375 372
376 private: 373 private:
377 FakeContentLayerClient client_; 374 FakeContentLayerClient client_;
378 scoped_refptr<Layer> root_layer_; 375 scoped_refptr<Layer> root_layer_;
379 scoped_refptr<FakeContentLayer> scaled_layer_; 376 scoped_refptr<FakeContentLayer> scaled_layer_;
380 }; 377 };
381 378
382 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); 379 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate);
383 380
384 class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate 381 class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate
385 : public LayerTreeHostTest { 382 : public LayerTreeHostTest {
386 public: 383 public:
387 virtual void InitializeSettings(LayerTreeSettings* settings) override { 384 void InitializeSettings(LayerTreeSettings* settings) override {
388 settings->layer_transforms_should_scale_layer_contents = true; 385 settings->layer_transforms_should_scale_layer_contents = true;
389 } 386 }
390 387
391 virtual void SetupTree() override { 388 void SetupTree() override {
392 root_layer_ = Layer::Create(); 389 root_layer_ = Layer::Create();
393 root_layer_->SetBounds(gfx::Size(10, 20)); 390 root_layer_->SetBounds(gfx::Size(10, 20));
394 391
395 bool paint_scrollbar = true; 392 bool paint_scrollbar = true;
396 bool has_thumb = false; 393 bool has_thumb = false;
397 scrollbar_ = FakePaintedScrollbarLayer::Create( 394 scrollbar_ = FakePaintedScrollbarLayer::Create(
398 paint_scrollbar, has_thumb, root_layer_->id()); 395 paint_scrollbar, has_thumb, root_layer_->id());
399 scrollbar_->SetPosition(gfx::Point(0, 10)); 396 scrollbar_->SetPosition(gfx::Point(0, 10));
400 scrollbar_->SetBounds(gfx::Size(10, 10)); 397 scrollbar_->SetBounds(gfx::Size(10, 10));
401 398
402 root_layer_->AddChild(scrollbar_); 399 root_layer_->AddChild(scrollbar_);
403 400
404 layer_tree_host()->SetRootLayer(root_layer_); 401 layer_tree_host()->SetRootLayer(root_layer_);
405 LayerTreeHostTest::SetupTree(); 402 LayerTreeHostTest::SetupTree();
406 } 403 }
407 404
408 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 405 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
409 406
410 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 407 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
411 if (host_impl->active_tree()->source_frame_number() == 1) 408 if (host_impl->active_tree()->source_frame_number() == 1)
412 EndTest(); 409 EndTest();
413 } 410 }
414 411
415 virtual void DidCommit() override { 412 void DidCommit() override {
416 switch (layer_tree_host()->source_frame_number()) { 413 switch (layer_tree_host()->source_frame_number()) {
417 case 1: 414 case 1:
418 // Changing the device scale factor causes a commit. It also changes 415 // Changing the device scale factor causes a commit. It also changes
419 // the content bounds of |scrollbar_|, which should not generate 416 // the content bounds of |scrollbar_|, which should not generate
420 // a second commit as a result. 417 // a second commit as a result.
421 layer_tree_host()->SetDeviceScaleFactor(4.f); 418 layer_tree_host()->SetDeviceScaleFactor(4.f);
422 break; 419 break;
423 default: 420 default:
424 // No extra commits. 421 // No extra commits.
425 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); 422 EXPECT_EQ(2, layer_tree_host()->source_frame_number());
426 } 423 }
427 } 424 }
428 425
429 virtual void AfterTest() override { 426 void AfterTest() override {
430 EXPECT_EQ(gfx::Size(40, 40).ToString(), 427 EXPECT_EQ(gfx::Size(40, 40).ToString(),
431 scrollbar_->content_bounds().ToString()); 428 scrollbar_->content_bounds().ToString());
432 } 429 }
433 430
434 private: 431 private:
435 FakeContentLayerClient client_; 432 FakeContentLayerClient client_;
436 scoped_refptr<Layer> root_layer_; 433 scoped_refptr<Layer> root_layer_;
437 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; 434 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_;
438 }; 435 };
439 436
440 SINGLE_AND_MULTI_THREAD_TEST_F( 437 SINGLE_AND_MULTI_THREAD_TEST_F(
441 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); 438 LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate);
442 439
443 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { 440 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest {
444 public: 441 public:
445 LayerTreeHostTestSetNextCommitForcesRedraw() 442 LayerTreeHostTestSetNextCommitForcesRedraw()
446 : num_draws_(0), 443 : num_draws_(0),
447 bounds_(50, 50), 444 bounds_(50, 50),
448 invalid_rect_(10, 10, 20, 20), 445 invalid_rect_(10, 10, 20, 20),
449 root_layer_(ContentLayer::Create(&client_)) {} 446 root_layer_(ContentLayer::Create(&client_)) {}
450 447
451 virtual void BeginTest() override { 448 void BeginTest() override {
452 root_layer_->SetIsDrawable(true); 449 root_layer_->SetIsDrawable(true);
453 root_layer_->SetBounds(bounds_); 450 root_layer_->SetBounds(bounds_);
454 layer_tree_host()->SetRootLayer(root_layer_); 451 layer_tree_host()->SetRootLayer(root_layer_);
455 layer_tree_host()->SetViewportSize(bounds_); 452 layer_tree_host()->SetViewportSize(bounds_);
456 PostSetNeedsCommitToMainThread(); 453 PostSetNeedsCommitToMainThread();
457 } 454 }
458 455
459 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 456 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
460 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) 457 if (num_draws_ == 3 && host_impl->settings().impl_side_painting)
461 host_impl->SetNeedsRedrawRect(invalid_rect_); 458 host_impl->SetNeedsRedrawRect(invalid_rect_);
462 } 459 }
463 460
464 virtual DrawResult PrepareToDrawOnThread( 461 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
465 LayerTreeHostImpl* host_impl, 462 LayerTreeHostImpl::FrameData* frame_data,
466 LayerTreeHostImpl::FrameData* frame_data, 463 DrawResult draw_result) override {
467 DrawResult draw_result) override {
468 EXPECT_EQ(DRAW_SUCCESS, draw_result); 464 EXPECT_EQ(DRAW_SUCCESS, draw_result);
469 465
470 gfx::RectF root_damage_rect; 466 gfx::RectF root_damage_rect;
471 if (!frame_data->render_passes.empty()) 467 if (!frame_data->render_passes.empty())
472 root_damage_rect = frame_data->render_passes.back()->damage_rect; 468 root_damage_rect = frame_data->render_passes.back()->damage_rect;
473 469
474 switch (num_draws_) { 470 switch (num_draws_) {
475 case 0: 471 case 0:
476 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); 472 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect);
477 break; 473 break;
478 case 1: 474 case 1:
479 case 2: 475 case 2:
480 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect); 476 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect);
481 break; 477 break;
482 case 3: 478 case 3:
483 EXPECT_RECT_EQ(invalid_rect_, root_damage_rect); 479 EXPECT_RECT_EQ(invalid_rect_, root_damage_rect);
484 break; 480 break;
485 case 4: 481 case 4:
486 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); 482 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect);
487 break; 483 break;
488 default: 484 default:
489 NOTREACHED(); 485 NOTREACHED();
490 } 486 }
491 487
492 return draw_result; 488 return draw_result;
493 } 489 }
494 490
495 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 491 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
496 switch (num_draws_) { 492 switch (num_draws_) {
497 case 0: 493 case 0:
498 case 1: 494 case 1:
499 // Cycle through a couple of empty commits to ensure we're observing the 495 // Cycle through a couple of empty commits to ensure we're observing the
500 // right behavior 496 // right behavior
501 PostSetNeedsCommitToMainThread(); 497 PostSetNeedsCommitToMainThread();
502 break; 498 break;
503 case 2: 499 case 2:
504 // Should force full frame damage on the next commit 500 // Should force full frame damage on the next commit
505 PostSetNextCommitForcesRedrawToMainThread(); 501 PostSetNextCommitForcesRedrawToMainThread();
506 PostSetNeedsCommitToMainThread(); 502 PostSetNeedsCommitToMainThread();
507 if (host_impl->settings().impl_side_painting) 503 if (host_impl->settings().impl_side_painting)
508 host_impl->BlockNotifyReadyToActivateForTesting(true); 504 host_impl->BlockNotifyReadyToActivateForTesting(true);
509 else 505 else
510 num_draws_++; 506 num_draws_++;
511 break; 507 break;
512 case 3: 508 case 3:
513 host_impl->BlockNotifyReadyToActivateForTesting(false); 509 host_impl->BlockNotifyReadyToActivateForTesting(false);
514 break; 510 break;
515 default: 511 default:
516 EndTest(); 512 EndTest();
517 break; 513 break;
518 } 514 }
519 num_draws_++; 515 num_draws_++;
520 } 516 }
521 517
522 virtual void AfterTest() override { EXPECT_EQ(5, num_draws_); } 518 void AfterTest() override { EXPECT_EQ(5, num_draws_); }
523 519
524 private: 520 private:
525 int num_draws_; 521 int num_draws_;
526 const gfx::Size bounds_; 522 const gfx::Size bounds_;
527 const gfx::Rect invalid_rect_; 523 const gfx::Rect invalid_rect_;
528 FakeContentLayerClient client_; 524 FakeContentLayerClient client_;
529 scoped_refptr<ContentLayer> root_layer_; 525 scoped_refptr<ContentLayer> root_layer_;
530 }; 526 };
531 527
532 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( 528 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F(
533 LayerTreeHostTestSetNextCommitForcesRedraw); 529 LayerTreeHostTestSetNextCommitForcesRedraw);
534 530
535 // Tests that if a layer is not drawn because of some reason in the parent then 531 // Tests that if a layer is not drawn because of some reason in the parent then
536 // its damage is preserved until the next time it is drawn. 532 // its damage is preserved until the next time it is drawn.
537 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { 533 class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest {
538 public: 534 public:
539 LayerTreeHostTestUndrawnLayersDamageLater() 535 LayerTreeHostTestUndrawnLayersDamageLater()
540 : root_layer_(ContentLayer::Create(&client_)) {} 536 : root_layer_(ContentLayer::Create(&client_)) {}
541 537
542 virtual void SetupTree() override { 538 void SetupTree() override {
543 root_layer_->SetIsDrawable(true); 539 root_layer_->SetIsDrawable(true);
544 root_layer_->SetBounds(gfx::Size(50, 50)); 540 root_layer_->SetBounds(gfx::Size(50, 50));
545 layer_tree_host()->SetRootLayer(root_layer_); 541 layer_tree_host()->SetRootLayer(root_layer_);
546 542
547 // The initially transparent layer has a larger child layer, which is 543 // The initially transparent layer has a larger child layer, which is
548 // not initially drawn because of the this (parent) layer. 544 // not initially drawn because of the this (parent) layer.
549 parent_layer_ = FakeContentLayer::Create(&client_); 545 parent_layer_ = FakeContentLayer::Create(&client_);
550 parent_layer_->SetBounds(gfx::Size(15, 15)); 546 parent_layer_->SetBounds(gfx::Size(15, 15));
551 parent_layer_->SetOpacity(0.0f); 547 parent_layer_->SetOpacity(0.0f);
552 root_layer_->AddChild(parent_layer_); 548 root_layer_->AddChild(parent_layer_);
553 549
554 child_layer_ = FakeContentLayer::Create(&client_); 550 child_layer_ = FakeContentLayer::Create(&client_);
555 child_layer_->SetBounds(gfx::Size(25, 25)); 551 child_layer_->SetBounds(gfx::Size(25, 25));
556 parent_layer_->AddChild(child_layer_); 552 parent_layer_->AddChild(child_layer_);
557 553
558 LayerTreeHostTest::SetupTree(); 554 LayerTreeHostTest::SetupTree();
559 } 555 }
560 556
561 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 557 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
562 558
563 virtual DrawResult PrepareToDrawOnThread( 559 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
564 LayerTreeHostImpl* host_impl, 560 LayerTreeHostImpl::FrameData* frame_data,
565 LayerTreeHostImpl::FrameData* frame_data, 561 DrawResult draw_result) override {
566 DrawResult draw_result) override {
567 EXPECT_EQ(DRAW_SUCCESS, draw_result); 562 EXPECT_EQ(DRAW_SUCCESS, draw_result);
568 563
569 gfx::RectF root_damage_rect; 564 gfx::RectF root_damage_rect;
570 if (!frame_data->render_passes.empty()) 565 if (!frame_data->render_passes.empty())
571 root_damage_rect = frame_data->render_passes.back()->damage_rect; 566 root_damage_rect = frame_data->render_passes.back()->damage_rect;
572 567
573 // The first time, the whole view needs be drawn. 568 // The first time, the whole view needs be drawn.
574 // Afterwards, just the opacity of surface_layer1 is changed a few times, 569 // Afterwards, just the opacity of surface_layer1 is changed a few times,
575 // and each damage should be the bounding box of it and its child. If this 570 // and each damage should be the bounding box of it and its child. If this
576 // was working improperly, the damage might not include its childs bounding 571 // was working improperly, the damage might not include its childs bounding
577 // box. 572 // box.
578 switch (host_impl->active_tree()->source_frame_number()) { 573 switch (host_impl->active_tree()->source_frame_number()) {
579 case 0: 574 case 0:
580 EXPECT_RECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); 575 EXPECT_RECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect);
581 break; 576 break;
582 case 1: 577 case 1:
583 case 2: 578 case 2:
584 case 3: 579 case 3:
585 EXPECT_RECT_EQ(gfx::Rect(child_layer_->bounds()), root_damage_rect); 580 EXPECT_RECT_EQ(gfx::Rect(child_layer_->bounds()), root_damage_rect);
586 break; 581 break;
587 default: 582 default:
588 NOTREACHED(); 583 NOTREACHED();
589 } 584 }
590 585
591 return draw_result; 586 return draw_result;
592 } 587 }
593 588
594 virtual void DidCommitAndDrawFrame() override { 589 void DidCommitAndDrawFrame() override {
595 switch (layer_tree_host()->source_frame_number()) { 590 switch (layer_tree_host()->source_frame_number()) {
596 case 1: 591 case 1:
597 // Test not owning the surface. 592 // Test not owning the surface.
598 parent_layer_->SetOpacity(1.0f); 593 parent_layer_->SetOpacity(1.0f);
599 break; 594 break;
600 case 2: 595 case 2:
601 parent_layer_->SetOpacity(0.0f); 596 parent_layer_->SetOpacity(0.0f);
602 break; 597 break;
603 case 3: 598 case 3:
604 // Test owning the surface. 599 // Test owning the surface.
605 parent_layer_->SetOpacity(0.5f); 600 parent_layer_->SetOpacity(0.5f);
606 parent_layer_->SetForceRenderSurface(true); 601 parent_layer_->SetForceRenderSurface(true);
607 break; 602 break;
608 case 4: 603 case 4:
609 EndTest(); 604 EndTest();
610 break; 605 break;
611 default: 606 default:
612 NOTREACHED(); 607 NOTREACHED();
613 } 608 }
614 } 609 }
615 610
616 virtual void AfterTest() override {} 611 void AfterTest() override {}
617 612
618 private: 613 private:
619 FakeContentLayerClient client_; 614 FakeContentLayerClient client_;
620 scoped_refptr<ContentLayer> root_layer_; 615 scoped_refptr<ContentLayer> root_layer_;
621 scoped_refptr<FakeContentLayer> parent_layer_; 616 scoped_refptr<FakeContentLayer> parent_layer_;
622 scoped_refptr<FakeContentLayer> child_layer_; 617 scoped_refptr<FakeContentLayer> child_layer_;
623 }; 618 };
624 619
625 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); 620 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater);
626 621
627 // Tests that if a layer is not drawn because of some reason in the parent, 622 // Tests that if a layer is not drawn because of some reason in the parent,
628 // causing its content bounds to not be computed, then when it is later drawn, 623 // causing its content bounds to not be computed, then when it is later drawn,
629 // its content bounds get pushed. 624 // its content bounds get pushed.
630 class LayerTreeHostTestUndrawnLayersPushContentBoundsLater 625 class LayerTreeHostTestUndrawnLayersPushContentBoundsLater
631 : public LayerTreeHostTest { 626 : public LayerTreeHostTest {
632 public: 627 public:
633 LayerTreeHostTestUndrawnLayersPushContentBoundsLater() 628 LayerTreeHostTestUndrawnLayersPushContentBoundsLater()
634 : root_layer_(Layer::Create()) {} 629 : root_layer_(Layer::Create()) {}
635 630
636 virtual void SetupTree() override { 631 void SetupTree() override {
637 root_layer_->SetIsDrawable(true); 632 root_layer_->SetIsDrawable(true);
638 root_layer_->SetBounds(gfx::Size(20, 20)); 633 root_layer_->SetBounds(gfx::Size(20, 20));
639 layer_tree_host()->SetRootLayer(root_layer_); 634 layer_tree_host()->SetRootLayer(root_layer_);
640 635
641 parent_layer_ = Layer::Create(); 636 parent_layer_ = Layer::Create();
642 parent_layer_->SetBounds(gfx::Size(20, 20)); 637 parent_layer_->SetBounds(gfx::Size(20, 20));
643 parent_layer_->SetOpacity(0.0f); 638 parent_layer_->SetOpacity(0.0f);
644 root_layer_->AddChild(parent_layer_); 639 root_layer_->AddChild(parent_layer_);
645 640
646 child_layer_ = Layer::Create(); 641 child_layer_ = Layer::Create();
647 child_layer_->SetBounds(gfx::Size(15, 15)); 642 child_layer_->SetBounds(gfx::Size(15, 15));
648 parent_layer_->AddChild(child_layer_); 643 parent_layer_->AddChild(child_layer_);
649 644
650 LayerTreeHostTest::SetupTree(); 645 LayerTreeHostTest::SetupTree();
651 } 646 }
652 647
653 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 648 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
654 649
655 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 650 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
656 LayerImpl* root = host_impl->active_tree()->root_layer(); 651 LayerImpl* root = host_impl->active_tree()->root_layer();
657 LayerImpl* parent = root->children()[0]; 652 LayerImpl* parent = root->children()[0];
658 LayerImpl* child = parent->children()[0]; 653 LayerImpl* child = parent->children()[0];
659 654
660 switch (host_impl->active_tree()->source_frame_number()) { 655 switch (host_impl->active_tree()->source_frame_number()) {
661 case 0: 656 case 0:
662 EXPECT_EQ(0.f, parent->opacity()); 657 EXPECT_EQ(0.f, parent->opacity());
663 EXPECT_EQ(gfx::SizeF(), child->content_bounds()); 658 EXPECT_EQ(gfx::SizeF(), child->content_bounds());
664 break; 659 break;
665 case 1: 660 case 1:
666 EXPECT_EQ(1.f, parent->opacity()); 661 EXPECT_EQ(1.f, parent->opacity());
667 EXPECT_EQ(gfx::SizeF(15.f, 15.f), child->content_bounds()); 662 EXPECT_EQ(gfx::SizeF(15.f, 15.f), child->content_bounds());
668 EndTest(); 663 EndTest();
669 break; 664 break;
670 default: 665 default:
671 NOTREACHED(); 666 NOTREACHED();
672 } 667 }
673 } 668 }
674 669
675 virtual void DidCommit() override { 670 void DidCommit() override {
676 switch (layer_tree_host()->source_frame_number()) { 671 switch (layer_tree_host()->source_frame_number()) {
677 case 1: 672 case 1:
678 parent_layer_->SetOpacity(1.0f); 673 parent_layer_->SetOpacity(1.0f);
679 break; 674 break;
680 case 2: 675 case 2:
681 break; 676 break;
682 default: 677 default:
683 NOTREACHED(); 678 NOTREACHED();
684 } 679 }
685 } 680 }
686 681
687 virtual void AfterTest() override {} 682 void AfterTest() override {}
688 683
689 private: 684 private:
690 scoped_refptr<Layer> root_layer_; 685 scoped_refptr<Layer> root_layer_;
691 scoped_refptr<Layer> parent_layer_; 686 scoped_refptr<Layer> parent_layer_;
692 scoped_refptr<Layer> child_layer_; 687 scoped_refptr<Layer> child_layer_;
693 }; 688 };
694 689
695 SINGLE_AND_MULTI_THREAD_TEST_F( 690 SINGLE_AND_MULTI_THREAD_TEST_F(
696 LayerTreeHostTestUndrawnLayersPushContentBoundsLater); 691 LayerTreeHostTestUndrawnLayersPushContentBoundsLater);
697 692
698 // This test verifies that properties on the layer tree host are commited 693 // This test verifies that properties on the layer tree host are commited
699 // to the impl side. 694 // to the impl side.
700 class LayerTreeHostTestCommit : public LayerTreeHostTest { 695 class LayerTreeHostTestCommit : public LayerTreeHostTest {
701 public: 696 public:
702 LayerTreeHostTestCommit() {} 697 LayerTreeHostTestCommit() {}
703 698
704 virtual void BeginTest() override { 699 void BeginTest() override {
705 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); 700 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
706 layer_tree_host()->set_background_color(SK_ColorGRAY); 701 layer_tree_host()->set_background_color(SK_ColorGRAY);
707 702
708 PostSetNeedsCommitToMainThread(); 703 PostSetNeedsCommitToMainThread();
709 } 704 }
710 705
711 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 706 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
712 EXPECT_EQ(gfx::Size(20, 20), impl->DrawViewportSize()); 707 EXPECT_EQ(gfx::Size(20, 20), impl->DrawViewportSize());
713 EXPECT_EQ(SK_ColorGRAY, impl->active_tree()->background_color()); 708 EXPECT_EQ(SK_ColorGRAY, impl->active_tree()->background_color());
714 709
715 EndTest(); 710 EndTest();
716 } 711 }
717 712
718 virtual void AfterTest() override {} 713 void AfterTest() override {}
719 }; 714 };
720 715
721 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); 716 MULTI_THREAD_TEST_F(LayerTreeHostTestCommit);
722 717
723 // This test verifies that LayerTreeHostImpl's current frame time gets 718 // This test verifies that LayerTreeHostImpl's current frame time gets
724 // updated in consecutive frames when it doesn't draw due to tree 719 // updated in consecutive frames when it doesn't draw due to tree
725 // activation failure. 720 // activation failure.
726 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails 721 class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails
727 : public LayerTreeHostTest { 722 : public LayerTreeHostTest {
728 public: 723 public:
729 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() 724 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails()
730 : frame_count_with_pending_tree_(0) {} 725 : frame_count_with_pending_tree_(0) {}
731 726
732 virtual void BeginTest() override { 727 void BeginTest() override {
733 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); 728 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
734 layer_tree_host()->set_background_color(SK_ColorGRAY); 729 layer_tree_host()->set_background_color(SK_ColorGRAY);
735 730
736 PostSetNeedsCommitToMainThread(); 731 PostSetNeedsCommitToMainThread();
737 } 732 }
738 733
739 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override { 734 void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
740 EXPECT_EQ(frame_count_with_pending_tree_, 0); 735 EXPECT_EQ(frame_count_with_pending_tree_, 0);
741 if (impl->settings().impl_side_painting) 736 if (impl->settings().impl_side_painting)
742 impl->BlockNotifyReadyToActivateForTesting(true); 737 impl->BlockNotifyReadyToActivateForTesting(true);
743 } 738 }
744 739
745 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl, 740 void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
746 const BeginFrameArgs& args) override { 741 const BeginFrameArgs& args) override {
747 if (impl->pending_tree()) 742 if (impl->pending_tree())
748 frame_count_with_pending_tree_++; 743 frame_count_with_pending_tree_++;
749 744
750 if (frame_count_with_pending_tree_ == 1) { 745 if (frame_count_with_pending_tree_ == 1) {
751 EXPECT_EQ(first_frame_time_.ToInternalValue(), 0); 746 EXPECT_EQ(first_frame_time_.ToInternalValue(), 0);
752 first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time; 747 first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time;
753 } else if (frame_count_with_pending_tree_ == 2 && 748 } else if (frame_count_with_pending_tree_ == 2 &&
754 impl->settings().impl_side_painting) { 749 impl->settings().impl_side_painting) {
755 impl->BlockNotifyReadyToActivateForTesting(false); 750 impl->BlockNotifyReadyToActivateForTesting(false);
756 } 751 }
757 } 752 }
758 753
759 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 754 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
760 if (frame_count_with_pending_tree_ > 1) { 755 if (frame_count_with_pending_tree_ > 1) {
761 EXPECT_NE(first_frame_time_.ToInternalValue(), 0); 756 EXPECT_NE(first_frame_time_.ToInternalValue(), 0);
762 EXPECT_NE(first_frame_time_.ToInternalValue(), 757 EXPECT_NE(first_frame_time_.ToInternalValue(),
763 impl->CurrentBeginFrameArgs().frame_time.ToInternalValue()); 758 impl->CurrentBeginFrameArgs().frame_time.ToInternalValue());
764 EndTest(); 759 EndTest();
765 return; 760 return;
766 } 761 }
767 762
768 EXPECT_FALSE(impl->settings().impl_side_painting); 763 EXPECT_FALSE(impl->settings().impl_side_painting);
769 EndTest(); 764 EndTest();
770 } 765 }
771 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 766 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
772 if (impl->settings().impl_side_painting) 767 if (impl->settings().impl_side_painting)
773 EXPECT_NE(frame_count_with_pending_tree_, 1); 768 EXPECT_NE(frame_count_with_pending_tree_, 1);
774 } 769 }
775 770
776 virtual void AfterTest() override {} 771 void AfterTest() override {}
777 772
778 private: 773 private:
779 int frame_count_with_pending_tree_; 774 int frame_count_with_pending_tree_;
780 base::TimeTicks first_frame_time_; 775 base::TimeTicks first_frame_time_;
781 }; 776 };
782 777
783 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( 778 SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F(
784 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); 779 LayerTreeHostTestFrameTimeUpdatesAfterActivationFails);
785 780
786 // This test verifies that LayerTreeHostImpl's current frame time gets 781 // This test verifies that LayerTreeHostImpl's current frame time gets
787 // updated in consecutive frames when it draws in each frame. 782 // updated in consecutive frames when it draws in each frame.
788 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { 783 class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest {
789 public: 784 public:
790 LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {} 785 LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {}
791 786
792 virtual void BeginTest() override { 787 void BeginTest() override {
793 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); 788 layer_tree_host()->SetViewportSize(gfx::Size(20, 20));
794 layer_tree_host()->set_background_color(SK_ColorGRAY); 789 layer_tree_host()->set_background_color(SK_ColorGRAY);
795 790
796 PostSetNeedsCommitToMainThread(); 791 PostSetNeedsCommitToMainThread();
797 } 792 }
798 793
799 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 794 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
800 frame_++; 795 frame_++;
801 if (frame_ == 1) { 796 if (frame_ == 1) {
802 first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time; 797 first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time;
803 impl->SetNeedsRedraw(); 798 impl->SetNeedsRedraw();
804 799
805 // Since we might use a low-resolution clock on Windows, we need to 800 // Since we might use a low-resolution clock on Windows, we need to
806 // make sure that the clock has incremented past first_frame_time_. 801 // make sure that the clock has incremented past first_frame_time_.
807 while (first_frame_time_ == gfx::FrameTime::Now()) { 802 while (first_frame_time_ == gfx::FrameTime::Now()) {
808 } 803 }
809 804
810 return; 805 return;
811 } 806 }
812 807
813 EXPECT_NE(first_frame_time_, impl->CurrentBeginFrameArgs().frame_time); 808 EXPECT_NE(first_frame_time_, impl->CurrentBeginFrameArgs().frame_time);
814 EndTest(); 809 EndTest();
815 } 810 }
816 811
817 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 812 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
818 // Ensure there isn't a commit between the two draws, to ensure that a 813 // Ensure there isn't a commit between the two draws, to ensure that a
819 // commit isn't required for updating the current frame time. We can 814 // commit isn't required for updating the current frame time. We can
820 // only check for this in the multi-threaded case, since in the single- 815 // only check for this in the multi-threaded case, since in the single-
821 // threaded case there will always be a commit between consecutive draws. 816 // threaded case there will always be a commit between consecutive draws.
822 if (HasImplThread()) 817 if (HasImplThread())
823 EXPECT_EQ(0, frame_); 818 EXPECT_EQ(0, frame_);
824 } 819 }
825 820
826 virtual void AfterTest() override {} 821 void AfterTest() override {}
827 822
828 private: 823 private:
829 int frame_; 824 int frame_;
830 base::TimeTicks first_frame_time_; 825 base::TimeTicks first_frame_time_;
831 }; 826 };
832 827
833 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw); 828 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw);
834 829
835 // Verifies that StartPageScaleAnimation events propagate correctly 830 // Verifies that StartPageScaleAnimation events propagate correctly
836 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor. 831 // from LayerTreeHost to LayerTreeHostImpl in the MT compositor.
837 class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { 832 class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest {
838 public: 833 public:
839 LayerTreeHostTestStartPageScaleAnimation() {} 834 LayerTreeHostTestStartPageScaleAnimation() {}
840 835
841 virtual void SetupTree() override { 836 void SetupTree() override {
842 LayerTreeHostTest::SetupTree(); 837 LayerTreeHostTest::SetupTree();
843 838
844 if (layer_tree_host()->settings().impl_side_painting) { 839 if (layer_tree_host()->settings().impl_side_painting) {
845 scoped_refptr<FakePictureLayer> layer = 840 scoped_refptr<FakePictureLayer> layer =
846 FakePictureLayer::Create(&client_); 841 FakePictureLayer::Create(&client_);
847 layer->set_always_update_resources(true); 842 layer->set_always_update_resources(true);
848 scroll_layer_ = layer; 843 scroll_layer_ = layer;
849 } else { 844 } else {
850 scroll_layer_ = FakeContentLayer::Create(&client_); 845 scroll_layer_ = FakeContentLayer::Create(&client_);
851 } 846 }
852 847
853 Layer* root_layer = layer_tree_host()->root_layer(); 848 Layer* root_layer = layer_tree_host()->root_layer();
854 scroll_layer_->SetScrollClipLayerId(root_layer->id()); 849 scroll_layer_->SetScrollClipLayerId(root_layer->id());
855 scroll_layer_->SetIsContainerForFixedPositionLayers(true); 850 scroll_layer_->SetIsContainerForFixedPositionLayers(true);
856 scroll_layer_->SetBounds(gfx::Size(2 * root_layer->bounds().width(), 851 scroll_layer_->SetBounds(gfx::Size(2 * root_layer->bounds().width(),
857 2 * root_layer->bounds().height())); 852 2 * root_layer->bounds().height()));
858 scroll_layer_->SetScrollOffset(gfx::ScrollOffset()); 853 scroll_layer_->SetScrollOffset(gfx::ScrollOffset());
859 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 854 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
860 // This test requires the page_scale and inner viewport layers to be 855 // This test requires the page_scale and inner viewport layers to be
861 // identified. 856 // identified.
862 layer_tree_host()->RegisterViewportLayers( 857 layer_tree_host()->RegisterViewportLayers(
863 root_layer, scroll_layer_.get(), NULL); 858 root_layer, scroll_layer_.get(), NULL);
864 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 2.f); 859 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 2.f);
865 } 860 }
866 861
867 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 862 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
868 863
869 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, 864 void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta,
870 float scale, 865 float scale,
871 float) override { 866 float) override {
872 gfx::ScrollOffset offset = scroll_layer_->scroll_offset(); 867 gfx::ScrollOffset offset = scroll_layer_->scroll_offset();
873 scroll_layer_->SetScrollOffset(ScrollOffsetWithDelta(offset, 868 scroll_layer_->SetScrollOffset(ScrollOffsetWithDelta(offset,
874 scroll_delta)); 869 scroll_delta));
875 layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f); 870 layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f);
876 } 871 }
877 872
878 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 873 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
879 // We get one commit before the first draw, and the animation doesn't happen 874 // We get one commit before the first draw, and the animation doesn't happen
880 // until the second draw. 875 // until the second draw.
881 switch (impl->active_tree()->source_frame_number()) { 876 switch (impl->active_tree()->source_frame_number()) {
882 case 0: 877 case 0:
883 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); 878 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor());
884 // We'll start an animation when we get back to the main thread. 879 // We'll start an animation when we get back to the main thread.
885 break; 880 break;
886 case 1: 881 case 1:
887 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor()); 882 EXPECT_EQ(1.f, impl->active_tree()->page_scale_factor());
888 break; 883 break;
889 case 2: 884 case 2:
890 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor()); 885 EXPECT_EQ(1.25f, impl->active_tree()->page_scale_factor());
891 EndTest(); 886 EndTest();
892 break; 887 break;
893 default: 888 default:
894 NOTREACHED(); 889 NOTREACHED();
895 } 890 }
896 } 891 }
897 892
898 virtual void DidCommitAndDrawFrame() override { 893 void DidCommitAndDrawFrame() override {
899 switch (layer_tree_host()->source_frame_number()) { 894 switch (layer_tree_host()->source_frame_number()) {
900 case 1: 895 case 1:
901 layer_tree_host()->StartPageScaleAnimation( 896 layer_tree_host()->StartPageScaleAnimation(
902 gfx::Vector2d(), false, 1.25f, base::TimeDelta()); 897 gfx::Vector2d(), false, 1.25f, base::TimeDelta());
903 break; 898 break;
904 } 899 }
905 } 900 }
906 901
907 virtual void AfterTest() override {} 902 void AfterTest() override {}
908 903
909 FakeContentLayerClient client_; 904 FakeContentLayerClient client_;
910 scoped_refptr<Layer> scroll_layer_; 905 scoped_refptr<Layer> scroll_layer_;
911 }; 906 };
912 907
913 MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation); 908 MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation);
914 909
915 class LayerTreeHostTestSetVisible : public LayerTreeHostTest { 910 class LayerTreeHostTestSetVisible : public LayerTreeHostTest {
916 public: 911 public:
917 LayerTreeHostTestSetVisible() : num_draws_(0) {} 912 LayerTreeHostTestSetVisible() : num_draws_(0) {}
918 913
919 virtual void BeginTest() override { 914 void BeginTest() override {
920 PostSetNeedsCommitToMainThread(); 915 PostSetNeedsCommitToMainThread();
921 PostSetVisibleToMainThread(false); 916 PostSetVisibleToMainThread(false);
922 // This is suppressed while we're invisible. 917 // This is suppressed while we're invisible.
923 PostSetNeedsRedrawToMainThread(); 918 PostSetNeedsRedrawToMainThread();
924 // Triggers the redraw. 919 // Triggers the redraw.
925 PostSetVisibleToMainThread(true); 920 PostSetVisibleToMainThread(true);
926 } 921 }
927 922
928 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 923 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
929 EXPECT_TRUE(impl->visible()); 924 EXPECT_TRUE(impl->visible());
930 ++num_draws_; 925 ++num_draws_;
931 EndTest(); 926 EndTest();
932 } 927 }
933 928
934 virtual void AfterTest() override { EXPECT_EQ(1, num_draws_); } 929 void AfterTest() override { EXPECT_EQ(1, num_draws_); }
935 930
936 private: 931 private:
937 int num_draws_; 932 int num_draws_;
938 }; 933 };
939 934
940 MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible); 935 MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible);
941 936
942 class TestOpacityChangeLayerDelegate : public ContentLayerClient { 937 class TestOpacityChangeLayerDelegate : public ContentLayerClient {
943 public: 938 public:
944 TestOpacityChangeLayerDelegate() : test_layer_(0) {} 939 TestOpacityChangeLayerDelegate() : test_layer_(0) {}
945 940
946 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } 941 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; }
947 942
948 virtual void PaintContents( 943 void PaintContents(
949 SkCanvas* canvas, 944 SkCanvas* canvas,
950 const gfx::Rect& clip, 945 const gfx::Rect& clip,
951 ContentLayerClient::GraphicsContextStatus gc_status) override { 946 ContentLayerClient::GraphicsContextStatus gc_status) override {
952 // Set layer opacity to 0. 947 // Set layer opacity to 0.
953 if (test_layer_) 948 if (test_layer_)
954 test_layer_->SetOpacity(0.f); 949 test_layer_->SetOpacity(0.f);
955 } 950 }
956 virtual void DidChangeLayerCanUseLCDText() override {} 951 void DidChangeLayerCanUseLCDText() override {}
957 virtual bool FillsBoundsCompletely() const override { return false; } 952 bool FillsBoundsCompletely() const override { return false; }
958 953
959 private: 954 private:
960 Layer* test_layer_; 955 Layer* test_layer_;
961 }; 956 };
962 957
963 class ContentLayerWithUpdateTracking : public ContentLayer { 958 class ContentLayerWithUpdateTracking : public ContentLayer {
964 public: 959 public:
965 static scoped_refptr<ContentLayerWithUpdateTracking> Create( 960 static scoped_refptr<ContentLayerWithUpdateTracking> Create(
966 ContentLayerClient* client) { 961 ContentLayerClient* client) {
967 return make_scoped_refptr(new ContentLayerWithUpdateTracking(client)); 962 return make_scoped_refptr(new ContentLayerWithUpdateTracking(client));
968 } 963 }
969 964
970 int PaintContentsCount() { return paint_contents_count_; } 965 int PaintContentsCount() { return paint_contents_count_; }
971 void ResetPaintContentsCount() { paint_contents_count_ = 0; } 966 void ResetPaintContentsCount() { paint_contents_count_ = 0; }
972 967
973 virtual bool Update(ResourceUpdateQueue* queue, 968 bool Update(ResourceUpdateQueue* queue,
974 const OcclusionTracker<Layer>* occlusion) override { 969 const OcclusionTracker<Layer>* occlusion) override {
975 bool updated = ContentLayer::Update(queue, occlusion); 970 bool updated = ContentLayer::Update(queue, occlusion);
976 paint_contents_count_++; 971 paint_contents_count_++;
977 return updated; 972 return updated;
978 } 973 }
979 974
980 private: 975 private:
981 explicit ContentLayerWithUpdateTracking(ContentLayerClient* client) 976 explicit ContentLayerWithUpdateTracking(ContentLayerClient* client)
982 : ContentLayer(client), paint_contents_count_(0) { 977 : ContentLayer(client), paint_contents_count_(0) {
983 SetBounds(gfx::Size(10, 10)); 978 SetBounds(gfx::Size(10, 10));
984 SetIsDrawable(true); 979 SetIsDrawable(true);
985 } 980 }
986 virtual ~ContentLayerWithUpdateTracking() {} 981 ~ContentLayerWithUpdateTracking() override {}
987 982
988 int paint_contents_count_; 983 int paint_contents_count_;
989 }; 984 };
990 985
991 // Layer opacity change during paint should not prevent compositor resources 986 // Layer opacity change during paint should not prevent compositor resources
992 // from being updated during commit. 987 // from being updated during commit.
993 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { 988 class LayerTreeHostTestOpacityChange : public LayerTreeHostTest {
994 public: 989 public:
995 LayerTreeHostTestOpacityChange() 990 LayerTreeHostTestOpacityChange()
996 : test_opacity_change_delegate_(), 991 : test_opacity_change_delegate_(),
997 update_check_layer_(ContentLayerWithUpdateTracking::Create( 992 update_check_layer_(ContentLayerWithUpdateTracking::Create(
998 &test_opacity_change_delegate_)) { 993 &test_opacity_change_delegate_)) {
999 test_opacity_change_delegate_.SetTestLayer(update_check_layer_.get()); 994 test_opacity_change_delegate_.SetTestLayer(update_check_layer_.get());
1000 } 995 }
1001 996
1002 virtual void BeginTest() override { 997 void BeginTest() override {
1003 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); 998 layer_tree_host()->SetViewportSize(gfx::Size(10, 10));
1004 layer_tree_host()->root_layer()->AddChild(update_check_layer_); 999 layer_tree_host()->root_layer()->AddChild(update_check_layer_);
1005 1000
1006 PostSetNeedsCommitToMainThread(); 1001 PostSetNeedsCommitToMainThread();
1007 } 1002 }
1008 1003
1009 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1004 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { EndTest(); }
1010 EndTest();
1011 }
1012 1005
1013 virtual void AfterTest() override { 1006 void AfterTest() override {
1014 // Update() should have been called once. 1007 // Update() should have been called once.
1015 EXPECT_EQ(1, update_check_layer_->PaintContentsCount()); 1008 EXPECT_EQ(1, update_check_layer_->PaintContentsCount());
1016 } 1009 }
1017 1010
1018 private: 1011 private:
1019 TestOpacityChangeLayerDelegate test_opacity_change_delegate_; 1012 TestOpacityChangeLayerDelegate test_opacity_change_delegate_;
1020 scoped_refptr<ContentLayerWithUpdateTracking> update_check_layer_; 1013 scoped_refptr<ContentLayerWithUpdateTracking> update_check_layer_;
1021 }; 1014 };
1022 1015
1023 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange); 1016 MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange);
1024 1017
1025 class NoScaleContentLayer : public ContentLayer { 1018 class NoScaleContentLayer : public ContentLayer {
1026 public: 1019 public:
1027 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { 1020 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
1028 return make_scoped_refptr(new NoScaleContentLayer(client)); 1021 return make_scoped_refptr(new NoScaleContentLayer(client));
1029 } 1022 }
1030 1023
1031 virtual void CalculateContentsScale(float ideal_contents_scale, 1024 void CalculateContentsScale(float ideal_contents_scale,
1032 float* contents_scale_x, 1025 float* contents_scale_x,
1033 float* contents_scale_y, 1026 float* contents_scale_y,
1034 gfx::Size* contentBounds) override { 1027 gfx::Size* contentBounds) override {
1035 // Skip over the ContentLayer's method to the base Layer class. 1028 // Skip over the ContentLayer's method to the base Layer class.
1036 Layer::CalculateContentsScale(ideal_contents_scale, 1029 Layer::CalculateContentsScale(ideal_contents_scale,
1037 contents_scale_x, 1030 contents_scale_x,
1038 contents_scale_y, 1031 contents_scale_y,
1039 contentBounds); 1032 contentBounds);
1040 } 1033 }
1041 1034
1042 private: 1035 private:
1043 explicit NoScaleContentLayer(ContentLayerClient* client) 1036 explicit NoScaleContentLayer(ContentLayerClient* client)
1044 : ContentLayer(client) {} 1037 : ContentLayer(client) {}
1045 virtual ~NoScaleContentLayer() {} 1038 ~NoScaleContentLayer() override {}
1046 }; 1039 };
1047 1040
1048 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers 1041 class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers
1049 : public LayerTreeHostTest { 1042 : public LayerTreeHostTest {
1050 public: 1043 public:
1051 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() 1044 LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers()
1052 : root_layer_(NoScaleContentLayer::Create(&client_)), 1045 : root_layer_(NoScaleContentLayer::Create(&client_)),
1053 child_layer_(ContentLayer::Create(&client_)) {} 1046 child_layer_(ContentLayer::Create(&client_)) {}
1054 1047
1055 virtual void BeginTest() override { 1048 void BeginTest() override {
1056 layer_tree_host()->SetViewportSize(gfx::Size(60, 60)); 1049 layer_tree_host()->SetViewportSize(gfx::Size(60, 60));
1057 layer_tree_host()->SetDeviceScaleFactor(1.5); 1050 layer_tree_host()->SetDeviceScaleFactor(1.5);
1058 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size()); 1051 EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size());
1059 1052
1060 root_layer_->AddChild(child_layer_); 1053 root_layer_->AddChild(child_layer_);
1061 1054
1062 root_layer_->SetIsDrawable(true); 1055 root_layer_->SetIsDrawable(true);
1063 root_layer_->SetBounds(gfx::Size(30, 30)); 1056 root_layer_->SetBounds(gfx::Size(30, 30));
1064 1057
1065 child_layer_->SetIsDrawable(true); 1058 child_layer_->SetIsDrawable(true);
1066 child_layer_->SetPosition(gfx::Point(2, 2)); 1059 child_layer_->SetPosition(gfx::Point(2, 2));
1067 child_layer_->SetBounds(gfx::Size(10, 10)); 1060 child_layer_->SetBounds(gfx::Size(10, 10));
1068 1061
1069 layer_tree_host()->SetRootLayer(root_layer_); 1062 layer_tree_host()->SetRootLayer(root_layer_);
1070 1063
1071 PostSetNeedsCommitToMainThread(); 1064 PostSetNeedsCommitToMainThread();
1072 } 1065 }
1073 1066
1074 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1067 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1075 // Should only do one commit. 1068 // Should only do one commit.
1076 EXPECT_EQ(0, impl->active_tree()->source_frame_number()); 1069 EXPECT_EQ(0, impl->active_tree()->source_frame_number());
1077 // Device scale factor should come over to impl. 1070 // Device scale factor should come over to impl.
1078 EXPECT_NEAR(impl->device_scale_factor(), 1.5f, 0.00001f); 1071 EXPECT_NEAR(impl->device_scale_factor(), 1.5f, 0.00001f);
1079 1072
1080 // Both layers are on impl. 1073 // Both layers are on impl.
1081 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); 1074 ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size());
1082 1075
1083 // Device viewport is scaled. 1076 // Device viewport is scaled.
1084 EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); 1077 EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 gfx::Transform child_draw_transform = child_screen_space_transform; 1123 gfx::Transform child_draw_transform = child_screen_space_transform;
1131 1124
1132 EXPECT_TRANSFORMATION_MATRIX_EQ(child_draw_transform, 1125 EXPECT_TRANSFORMATION_MATRIX_EQ(child_draw_transform,
1133 child->draw_transform()); 1126 child->draw_transform());
1134 EXPECT_TRANSFORMATION_MATRIX_EQ(child_screen_space_transform, 1127 EXPECT_TRANSFORMATION_MATRIX_EQ(child_screen_space_transform,
1135 child->screen_space_transform()); 1128 child->screen_space_transform());
1136 1129
1137 EndTest(); 1130 EndTest();
1138 } 1131 }
1139 1132
1140 virtual void AfterTest() override {} 1133 void AfterTest() override {}
1141 1134
1142 private: 1135 private:
1143 FakeContentLayerClient client_; 1136 FakeContentLayerClient client_;
1144 scoped_refptr<NoScaleContentLayer> root_layer_; 1137 scoped_refptr<NoScaleContentLayer> root_layer_;
1145 scoped_refptr<ContentLayer> child_layer_; 1138 scoped_refptr<ContentLayer> child_layer_;
1146 }; 1139 };
1147 1140
1148 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); 1141 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers);
1149 1142
1150 // Verify atomicity of commits and reuse of textures. 1143 // Verify atomicity of commits and reuse of textures.
1151 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { 1144 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest {
1152 public: 1145 public:
1153 virtual void InitializeSettings(LayerTreeSettings* settings) override { 1146 void InitializeSettings(LayerTreeSettings* settings) override {
1154 settings->texture_id_allocation_chunk_size = 1; 1147 settings->texture_id_allocation_chunk_size = 1;
1155 // Make sure partial texture updates are turned off. 1148 // Make sure partial texture updates are turned off.
1156 settings->max_partial_texture_updates = 0; 1149 settings->max_partial_texture_updates = 0;
1157 // Linear fade animator prevents scrollbars from drawing immediately. 1150 // Linear fade animator prevents scrollbars from drawing immediately.
1158 settings->scrollbar_animator = LayerTreeSettings::NoAnimator; 1151 settings->scrollbar_animator = LayerTreeSettings::NoAnimator;
1159 } 1152 }
1160 1153
1161 virtual void SetupTree() override { 1154 void SetupTree() override {
1162 layer_ = FakeContentLayer::Create(&client_); 1155 layer_ = FakeContentLayer::Create(&client_);
1163 layer_->SetBounds(gfx::Size(10, 20)); 1156 layer_->SetBounds(gfx::Size(10, 20));
1164 1157
1165 bool paint_scrollbar = true; 1158 bool paint_scrollbar = true;
1166 bool has_thumb = false; 1159 bool has_thumb = false;
1167 scrollbar_ = FakePaintedScrollbarLayer::Create( 1160 scrollbar_ = FakePaintedScrollbarLayer::Create(
1168 paint_scrollbar, has_thumb, layer_->id()); 1161 paint_scrollbar, has_thumb, layer_->id());
1169 scrollbar_->SetPosition(gfx::Point(0, 10)); 1162 scrollbar_->SetPosition(gfx::Point(0, 10));
1170 scrollbar_->SetBounds(gfx::Size(10, 10)); 1163 scrollbar_->SetBounds(gfx::Size(10, 10));
1171 1164
1172 layer_->AddChild(scrollbar_); 1165 layer_->AddChild(scrollbar_);
1173 1166
1174 layer_tree_host()->SetRootLayer(layer_); 1167 layer_tree_host()->SetRootLayer(layer_);
1175 LayerTreeHostTest::SetupTree(); 1168 LayerTreeHostTest::SetupTree();
1176 } 1169 }
1177 1170
1178 virtual void BeginTest() override { 1171 void BeginTest() override {
1179 drew_frame_ = -1; 1172 drew_frame_ = -1;
1180 PostSetNeedsCommitToMainThread(); 1173 PostSetNeedsCommitToMainThread();
1181 } 1174 }
1182 1175
1183 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1176 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1184 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1177 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1185 1178
1186 TestWebGraphicsContext3D* context = TestContext(); 1179 TestWebGraphicsContext3D* context = TestContext();
1187 1180
1188 switch (impl->active_tree()->source_frame_number()) { 1181 switch (impl->active_tree()->source_frame_number()) {
1189 case 0: 1182 case 0:
1190 // Number of textures should be one for each layer 1183 // Number of textures should be one for each layer
1191 ASSERT_EQ(2u, context->NumTextures()); 1184 ASSERT_EQ(2u, context->NumTextures());
1192 // Number of textures used for commit should be one for each layer. 1185 // Number of textures used for commit should be one for each layer.
1193 EXPECT_EQ(2u, context->NumUsedTextures()); 1186 EXPECT_EQ(2u, context->NumUsedTextures());
(...skipping 20 matching lines...) Expand all
1214 break; 1207 break;
1215 case 2: 1208 case 2:
1216 EndTest(); 1209 EndTest();
1217 break; 1210 break;
1218 default: 1211 default:
1219 NOTREACHED(); 1212 NOTREACHED();
1220 break; 1213 break;
1221 } 1214 }
1222 } 1215 }
1223 1216
1224 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 1217 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
1225 TestWebGraphicsContext3D* context = TestContext(); 1218 TestWebGraphicsContext3D* context = TestContext();
1226 1219
1227 if (drew_frame_ == impl->active_tree()->source_frame_number()) { 1220 if (drew_frame_ == impl->active_tree()->source_frame_number()) {
1228 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_; 1221 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_;
1229 return; 1222 return;
1230 } 1223 }
1231 drew_frame_ = impl->active_tree()->source_frame_number(); 1224 drew_frame_ = impl->active_tree()->source_frame_number();
1232 1225
1233 // We draw/ship one texture each frame for each layer. 1226 // We draw/ship one texture each frame for each layer.
1234 EXPECT_EQ(2u, context->NumUsedTextures()); 1227 EXPECT_EQ(2u, context->NumUsedTextures());
1235 context->ResetUsedTextures(); 1228 context->ResetUsedTextures();
1236 1229
1237 if (!TestEnded()) 1230 if (!TestEnded())
1238 PostSetNeedsCommitToMainThread(); 1231 PostSetNeedsCommitToMainThread();
1239 } 1232 }
1240 1233
1241 virtual void Layout() override { 1234 void Layout() override {
1242 layer_->SetNeedsDisplay(); 1235 layer_->SetNeedsDisplay();
1243 scrollbar_->SetNeedsDisplay(); 1236 scrollbar_->SetNeedsDisplay();
1244 } 1237 }
1245 1238
1246 virtual void AfterTest() override {} 1239 void AfterTest() override {}
1247 1240
1248 protected: 1241 protected:
1249 FakeContentLayerClient client_; 1242 FakeContentLayerClient client_;
1250 scoped_refptr<FakeContentLayer> layer_; 1243 scoped_refptr<FakeContentLayer> layer_;
1251 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; 1244 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_;
1252 int drew_frame_; 1245 int drew_frame_;
1253 }; 1246 };
1254 1247
1255 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1248 MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1256 LayerTreeHostTestDirectRendererAtomicCommit); 1249 LayerTreeHostTestDirectRendererAtomicCommit);
1257 1250
1258 class LayerTreeHostTestDelegatingRendererAtomicCommit 1251 class LayerTreeHostTestDelegatingRendererAtomicCommit
1259 : public LayerTreeHostTestDirectRendererAtomicCommit { 1252 : public LayerTreeHostTestDirectRendererAtomicCommit {
1260 public: 1253 public:
1261 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 1254 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
1262 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1255 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1263 1256
1264 TestWebGraphicsContext3D* context = TestContext(); 1257 TestWebGraphicsContext3D* context = TestContext();
1265 1258
1266 switch (impl->active_tree()->source_frame_number()) { 1259 switch (impl->active_tree()->source_frame_number()) {
1267 case 0: 1260 case 0:
1268 // Number of textures should be one for each layer 1261 // Number of textures should be one for each layer
1269 ASSERT_EQ(2u, context->NumTextures()); 1262 ASSERT_EQ(2u, context->NumTextures());
1270 // Number of textures used for commit should be one for each layer. 1263 // Number of textures used for commit should be one for each layer.
1271 EXPECT_EQ(2u, context->NumUsedTextures()); 1264 EXPECT_EQ(2u, context->NumUsedTextures());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 layer->SetTransform(transform); 1311 layer->SetTransform(transform);
1319 layer->SetTransformOrigin(transform_origin); 1312 layer->SetTransformOrigin(transform_origin);
1320 layer->SetPosition(position); 1313 layer->SetPosition(position);
1321 layer->SetBounds(bounds); 1314 layer->SetBounds(bounds);
1322 layer->SetContentsOpaque(opaque); 1315 layer->SetContentsOpaque(opaque);
1323 } 1316 }
1324 1317
1325 class LayerTreeHostTestAtomicCommitWithPartialUpdate 1318 class LayerTreeHostTestAtomicCommitWithPartialUpdate
1326 : public LayerTreeHostTest { 1319 : public LayerTreeHostTest {
1327 public: 1320 public:
1328 virtual void InitializeSettings(LayerTreeSettings* settings) override { 1321 void InitializeSettings(LayerTreeSettings* settings) override {
1329 settings->texture_id_allocation_chunk_size = 1; 1322 settings->texture_id_allocation_chunk_size = 1;
1330 // Allow one partial texture update. 1323 // Allow one partial texture update.
1331 settings->max_partial_texture_updates = 1; 1324 settings->max_partial_texture_updates = 1;
1332 // No partial updates when impl side painting is enabled. 1325 // No partial updates when impl side painting is enabled.
1333 settings->impl_side_painting = false; 1326 settings->impl_side_painting = false;
1334 } 1327 }
1335 1328
1336 virtual void SetupTree() override { 1329 void SetupTree() override {
1337 parent_ = FakeContentLayer::Create(&client_); 1330 parent_ = FakeContentLayer::Create(&client_);
1338 parent_->SetBounds(gfx::Size(10, 20)); 1331 parent_->SetBounds(gfx::Size(10, 20));
1339 1332
1340 child_ = FakeContentLayer::Create(&client_); 1333 child_ = FakeContentLayer::Create(&client_);
1341 child_->SetPosition(gfx::Point(0, 10)); 1334 child_->SetPosition(gfx::Point(0, 10));
1342 child_->SetBounds(gfx::Size(3, 10)); 1335 child_->SetBounds(gfx::Size(3, 10));
1343 1336
1344 parent_->AddChild(child_); 1337 parent_->AddChild(child_);
1345 1338
1346 layer_tree_host()->SetRootLayer(parent_); 1339 layer_tree_host()->SetRootLayer(parent_);
1347 LayerTreeHostTest::SetupTree(); 1340 LayerTreeHostTest::SetupTree();
1348 } 1341 }
1349 1342
1350 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1343 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1351 1344
1352 virtual void DidCommitAndDrawFrame() override { 1345 void DidCommitAndDrawFrame() override {
1353 switch (layer_tree_host()->source_frame_number()) { 1346 switch (layer_tree_host()->source_frame_number()) {
1354 case 1: 1347 case 1:
1355 parent_->SetNeedsDisplay(); 1348 parent_->SetNeedsDisplay();
1356 child_->SetNeedsDisplay(); 1349 child_->SetNeedsDisplay();
1357 break; 1350 break;
1358 case 2: 1351 case 2:
1359 // Damage part of layers. 1352 // Damage part of layers.
1360 parent_->SetNeedsDisplayRect(gfx::Rect(5, 5)); 1353 parent_->SetNeedsDisplayRect(gfx::Rect(5, 5));
1361 child_->SetNeedsDisplayRect(gfx::Rect(5, 5)); 1354 child_->SetNeedsDisplayRect(gfx::Rect(5, 5));
1362 break; 1355 break;
1363 case 3: 1356 case 3:
1364 child_->SetNeedsDisplay(); 1357 child_->SetNeedsDisplay();
1365 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); 1358 layer_tree_host()->SetViewportSize(gfx::Size(10, 10));
1366 break; 1359 break;
1367 case 4: 1360 case 4:
1368 layer_tree_host()->SetViewportSize(gfx::Size(10, 20)); 1361 layer_tree_host()->SetViewportSize(gfx::Size(10, 20));
1369 break; 1362 break;
1370 case 5: 1363 case 5:
1371 EndTest(); 1364 EndTest();
1372 break; 1365 break;
1373 default: 1366 default:
1374 NOTREACHED() << layer_tree_host()->source_frame_number(); 1367 NOTREACHED() << layer_tree_host()->source_frame_number();
1375 break; 1368 break;
1376 } 1369 }
1377 } 1370 }
1378 1371
1379 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1372 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1380 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); 1373 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates);
1381 1374
1382 TestWebGraphicsContext3D* context = TestContext(); 1375 TestWebGraphicsContext3D* context = TestContext();
1383 1376
1384 switch (impl->active_tree()->source_frame_number()) { 1377 switch (impl->active_tree()->source_frame_number()) {
1385 case 0: 1378 case 0:
1386 // Number of textures should be one for each layer. 1379 // Number of textures should be one for each layer.
1387 ASSERT_EQ(2u, context->NumTextures()); 1380 ASSERT_EQ(2u, context->NumTextures());
1388 // Number of textures used for commit should be one for each layer. 1381 // Number of textures used for commit should be one for each layer.
1389 EXPECT_EQ(2u, context->NumUsedTextures()); 1382 EXPECT_EQ(2u, context->NumUsedTextures());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 EXPECT_EQ(1u, context->NumUsedTextures()); 1452 EXPECT_EQ(1u, context->NumUsedTextures());
1460 1453
1461 context->ResetUsedTextures(); 1454 context->ResetUsedTextures();
1462 break; 1455 break;
1463 default: 1456 default:
1464 NOTREACHED(); 1457 NOTREACHED();
1465 break; 1458 break;
1466 } 1459 }
1467 } 1460 }
1468 1461
1469 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 1462 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
1470 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); 1463 EXPECT_LT(impl->active_tree()->source_frame_number(), 5);
1471 1464
1472 TestWebGraphicsContext3D* context = TestContext(); 1465 TestWebGraphicsContext3D* context = TestContext();
1473 1466
1474 // Number of textures used for drawing should one per layer except for 1467 // Number of textures used for drawing should one per layer except for
1475 // frame 3 where the viewport only contains one layer. 1468 // frame 3 where the viewport only contains one layer.
1476 if (impl->active_tree()->source_frame_number() == 3) { 1469 if (impl->active_tree()->source_frame_number() == 3) {
1477 EXPECT_EQ(1u, context->NumUsedTextures()); 1470 EXPECT_EQ(1u, context->NumUsedTextures());
1478 } else { 1471 } else {
1479 EXPECT_EQ(2u, context->NumUsedTextures()) 1472 EXPECT_EQ(2u, context->NumUsedTextures())
1480 << "For frame " << impl->active_tree()->source_frame_number(); 1473 << "For frame " << impl->active_tree()->source_frame_number();
1481 } 1474 }
1482 1475
1483 context->ResetUsedTextures(); 1476 context->ResetUsedTextures();
1484 } 1477 }
1485 1478
1486 virtual void AfterTest() override {} 1479 void AfterTest() override {}
1487 1480
1488 private: 1481 private:
1489 FakeContentLayerClient client_; 1482 FakeContentLayerClient client_;
1490 scoped_refptr<FakeContentLayer> parent_; 1483 scoped_refptr<FakeContentLayer> parent_;
1491 scoped_refptr<FakeContentLayer> child_; 1484 scoped_refptr<FakeContentLayer> child_;
1492 }; 1485 };
1493 1486
1494 // Partial updates are not possible with a delegating renderer. 1487 // Partial updates are not possible with a delegating renderer.
1495 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 1488 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1496 LayerTreeHostTestAtomicCommitWithPartialUpdate); 1489 LayerTreeHostTestAtomicCommitWithPartialUpdate);
1497 1490
1498 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit 1491 class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit
1499 : public LayerTreeHostTest { 1492 : public LayerTreeHostTest {
1500 protected: 1493 protected:
1501 virtual void SetupTree() override { 1494 void SetupTree() override {
1502 root_layer_ = FakeContentLayer::Create(&client_); 1495 root_layer_ = FakeContentLayer::Create(&client_);
1503 root_layer_->SetBounds(gfx::Size(100, 100)); 1496 root_layer_->SetBounds(gfx::Size(100, 100));
1504 1497
1505 surface_layer1_ = FakeContentLayer::Create(&client_); 1498 surface_layer1_ = FakeContentLayer::Create(&client_);
1506 surface_layer1_->SetBounds(gfx::Size(100, 100)); 1499 surface_layer1_->SetBounds(gfx::Size(100, 100));
1507 surface_layer1_->SetForceRenderSurface(true); 1500 surface_layer1_->SetForceRenderSurface(true);
1508 surface_layer1_->SetOpacity(0.5f); 1501 surface_layer1_->SetOpacity(0.5f);
1509 root_layer_->AddChild(surface_layer1_); 1502 root_layer_->AddChild(surface_layer1_);
1510 1503
1511 surface_layer2_ = FakeContentLayer::Create(&client_); 1504 surface_layer2_ = FakeContentLayer::Create(&client_);
1512 surface_layer2_->SetBounds(gfx::Size(100, 100)); 1505 surface_layer2_->SetBounds(gfx::Size(100, 100));
1513 surface_layer2_->SetForceRenderSurface(true); 1506 surface_layer2_->SetForceRenderSurface(true);
1514 surface_layer2_->SetOpacity(0.5f); 1507 surface_layer2_->SetOpacity(0.5f);
1515 surface_layer1_->AddChild(surface_layer2_); 1508 surface_layer1_->AddChild(surface_layer2_);
1516 1509
1517 replica_layer1_ = FakeContentLayer::Create(&client_); 1510 replica_layer1_ = FakeContentLayer::Create(&client_);
1518 surface_layer1_->SetReplicaLayer(replica_layer1_.get()); 1511 surface_layer1_->SetReplicaLayer(replica_layer1_.get());
1519 1512
1520 replica_layer2_ = FakeContentLayer::Create(&client_); 1513 replica_layer2_ = FakeContentLayer::Create(&client_);
1521 surface_layer2_->SetReplicaLayer(replica_layer2_.get()); 1514 surface_layer2_->SetReplicaLayer(replica_layer2_.get());
1522 1515
1523 layer_tree_host()->SetRootLayer(root_layer_); 1516 layer_tree_host()->SetRootLayer(root_layer_);
1524 LayerTreeHostTest::SetupTree(); 1517 LayerTreeHostTest::SetupTree();
1525 } 1518 }
1526 1519
1527 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1520 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1528 1521
1529 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 1522 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
1530 Renderer* renderer = host_impl->renderer(); 1523 Renderer* renderer = host_impl->renderer();
1531 RenderPassId surface1_render_pass_id = host_impl->active_tree() 1524 RenderPassId surface1_render_pass_id = host_impl->active_tree()
1532 ->root_layer() 1525 ->root_layer()
1533 ->children()[0] 1526 ->children()[0]
1534 ->render_surface() 1527 ->render_surface()
1535 ->GetRenderPassId(); 1528 ->GetRenderPassId();
1536 RenderPassId surface2_render_pass_id = host_impl->active_tree() 1529 RenderPassId surface2_render_pass_id = host_impl->active_tree()
1537 ->root_layer() 1530 ->root_layer()
1538 ->children()[0] 1531 ->children()[0]
1539 ->children()[0] 1532 ->children()[0]
(...skipping 16 matching lines...) Expand all
1556 EXPECT_FALSE( 1549 EXPECT_FALSE(
1557 renderer->HasAllocatedResourcesForTesting(surface1_render_pass_id)); 1550 renderer->HasAllocatedResourcesForTesting(surface1_render_pass_id));
1558 EXPECT_FALSE( 1551 EXPECT_FALSE(
1559 renderer->HasAllocatedResourcesForTesting(surface2_render_pass_id)); 1552 renderer->HasAllocatedResourcesForTesting(surface2_render_pass_id));
1560 1553
1561 EndTest(); 1554 EndTest();
1562 break; 1555 break;
1563 } 1556 }
1564 } 1557 }
1565 1558
1566 virtual void DidCommitAndDrawFrame() override { 1559 void DidCommitAndDrawFrame() override {
1567 if (layer_tree_host()->source_frame_number() < 2) 1560 if (layer_tree_host()->source_frame_number() < 2)
1568 root_layer_->SetNeedsDisplay(); 1561 root_layer_->SetNeedsDisplay();
1569 } 1562 }
1570 1563
1571 virtual void AfterTest() override { 1564 void AfterTest() override {
1572 EXPECT_LE(2u, root_layer_->update_count()); 1565 EXPECT_LE(2u, root_layer_->update_count());
1573 EXPECT_LE(2u, surface_layer1_->update_count()); 1566 EXPECT_LE(2u, surface_layer1_->update_count());
1574 EXPECT_LE(2u, surface_layer2_->update_count()); 1567 EXPECT_LE(2u, surface_layer2_->update_count());
1575 } 1568 }
1576 1569
1577 FakeContentLayerClient client_; 1570 FakeContentLayerClient client_;
1578 scoped_refptr<FakeContentLayer> root_layer_; 1571 scoped_refptr<FakeContentLayer> root_layer_;
1579 scoped_refptr<FakeContentLayer> surface_layer1_; 1572 scoped_refptr<FakeContentLayer> surface_layer1_;
1580 scoped_refptr<FakeContentLayer> replica_layer1_; 1573 scoped_refptr<FakeContentLayer> replica_layer1_;
1581 scoped_refptr<FakeContentLayer> surface_layer2_; 1574 scoped_refptr<FakeContentLayer> surface_layer2_;
1582 scoped_refptr<FakeContentLayer> replica_layer2_; 1575 scoped_refptr<FakeContentLayer> replica_layer2_;
1583 }; 1576 };
1584 1577
1585 // Surfaces don't exist with a delegated renderer. 1578 // Surfaces don't exist with a delegated renderer.
1586 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( 1579 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F(
1587 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit); 1580 LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit);
1588 1581
1589 class EvictionTestLayer : public Layer { 1582 class EvictionTestLayer : public Layer {
1590 public: 1583 public:
1591 static scoped_refptr<EvictionTestLayer> Create() { 1584 static scoped_refptr<EvictionTestLayer> Create() {
1592 return make_scoped_refptr(new EvictionTestLayer()); 1585 return make_scoped_refptr(new EvictionTestLayer());
1593 } 1586 }
1594 1587
1595 virtual bool Update(ResourceUpdateQueue*, 1588 bool Update(ResourceUpdateQueue*, const OcclusionTracker<Layer>*) override;
1596 const OcclusionTracker<Layer>*) override; 1589 bool DrawsContent() const override { return true; }
1597 virtual bool DrawsContent() const override { return true; }
1598 1590
1599 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 1591 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
1600 override; 1592 void PushPropertiesTo(LayerImpl* impl) override;
1601 virtual void PushPropertiesTo(LayerImpl* impl) override; 1593 void SetTexturePriorities(const PriorityCalculator&) override;
1602 virtual void SetTexturePriorities(const PriorityCalculator&) override;
1603 1594
1604 bool HaveBackingTexture() const { 1595 bool HaveBackingTexture() const {
1605 return texture_.get() ? texture_->have_backing_texture() : false; 1596 return texture_.get() ? texture_->have_backing_texture() : false;
1606 } 1597 }
1607 1598
1608 private: 1599 private:
1609 EvictionTestLayer() : Layer() {} 1600 EvictionTestLayer() : Layer() {}
1610 virtual ~EvictionTestLayer() {} 1601 ~EvictionTestLayer() override {}
1611 1602
1612 void CreateTextureIfNeeded() { 1603 void CreateTextureIfNeeded() {
1613 if (texture_) 1604 if (texture_)
1614 return; 1605 return;
1615 texture_ = PrioritizedResource::Create( 1606 texture_ = PrioritizedResource::Create(
1616 layer_tree_host()->contents_texture_manager()); 1607 layer_tree_host()->contents_texture_manager());
1617 texture_->SetDimensions(gfx::Size(10, 10), RGBA_8888); 1608 texture_->SetDimensions(gfx::Size(10, 10), RGBA_8888);
1618 bitmap_.allocN32Pixels(10, 10); 1609 bitmap_.allocN32Pixels(10, 10);
1619 } 1610 }
1620 1611
1621 scoped_ptr<PrioritizedResource> texture_; 1612 scoped_ptr<PrioritizedResource> texture_;
1622 SkBitmap bitmap_; 1613 SkBitmap bitmap_;
1623 }; 1614 };
1624 1615
1625 class EvictionTestLayerImpl : public LayerImpl { 1616 class EvictionTestLayerImpl : public LayerImpl {
1626 public: 1617 public:
1627 static scoped_ptr<EvictionTestLayerImpl> Create(LayerTreeImpl* tree_impl, 1618 static scoped_ptr<EvictionTestLayerImpl> Create(LayerTreeImpl* tree_impl,
1628 int id) { 1619 int id) {
1629 return make_scoped_ptr(new EvictionTestLayerImpl(tree_impl, id)); 1620 return make_scoped_ptr(new EvictionTestLayerImpl(tree_impl, id));
1630 } 1621 }
1631 virtual ~EvictionTestLayerImpl() {} 1622 ~EvictionTestLayerImpl() override {}
1632 1623
1633 virtual void AppendQuads(RenderPass* render_pass, 1624 void AppendQuads(RenderPass* render_pass,
1634 const Occlusion& occlusion_in_content_space, 1625 const Occlusion& occlusion_in_content_space,
1635 AppendQuadsData* append_quads_data) override { 1626 AppendQuadsData* append_quads_data) override {
1636 ASSERT_TRUE(has_texture_); 1627 ASSERT_TRUE(has_texture_);
1637 ASSERT_NE(0u, layer_tree_impl()->resource_provider()->num_resources()); 1628 ASSERT_NE(0u, layer_tree_impl()->resource_provider()->num_resources());
1638 } 1629 }
1639 1630
1640 void SetHasTexture(bool has_texture) { has_texture_ = has_texture; } 1631 void SetHasTexture(bool has_texture) { has_texture_ = has_texture; }
1641 1632
1642 private: 1633 private:
1643 EvictionTestLayerImpl(LayerTreeImpl* tree_impl, int id) 1634 EvictionTestLayerImpl(LayerTreeImpl* tree_impl, int id)
1644 : LayerImpl(tree_impl, id), has_texture_(false) {} 1635 : LayerImpl(tree_impl, id), has_texture_(false) {}
1645 1636
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 test_layer_impl->SetHasTexture(texture_->have_backing_texture()); 1670 test_layer_impl->SetHasTexture(texture_->have_backing_texture());
1680 } 1671 }
1681 1672
1682 class LayerTreeHostTestEvictTextures : public LayerTreeHostTest { 1673 class LayerTreeHostTestEvictTextures : public LayerTreeHostTest {
1683 public: 1674 public:
1684 LayerTreeHostTestEvictTextures() 1675 LayerTreeHostTestEvictTextures()
1685 : layer_(EvictionTestLayer::Create()), 1676 : layer_(EvictionTestLayer::Create()),
1686 impl_for_evict_textures_(0), 1677 impl_for_evict_textures_(0),
1687 num_commits_(0) {} 1678 num_commits_(0) {}
1688 1679
1689 virtual void BeginTest() override { 1680 void BeginTest() override {
1690 layer_tree_host()->SetRootLayer(layer_); 1681 layer_tree_host()->SetRootLayer(layer_);
1691 layer_tree_host()->SetViewportSize(gfx::Size(10, 20)); 1682 layer_tree_host()->SetViewportSize(gfx::Size(10, 20));
1692 1683
1693 gfx::Transform identity_matrix; 1684 gfx::Transform identity_matrix;
1694 SetLayerPropertiesForTesting(layer_.get(), 1685 SetLayerPropertiesForTesting(layer_.get(),
1695 0, 1686 0,
1696 identity_matrix, 1687 identity_matrix,
1697 gfx::Point3F(0.f, 0.f, 0.f), 1688 gfx::Point3F(0.f, 0.f, 0.f),
1698 gfx::PointF(0.f, 0.f), 1689 gfx::PointF(0.f, 0.f),
1699 gfx::Size(10, 20), 1690 gfx::Size(10, 20),
(...skipping 29 matching lines...) Expand all
1729 // Commit 6: Triggered by the eviction, post an eviction task in 1720 // Commit 6: Triggered by the eviction, post an eviction task in
1730 // Layout(), which will be a noop, letting the commit (which recreates the 1721 // Layout(), which will be a noop, letting the commit (which recreates the
1731 // textures) go through and draw a frame, then end the test. 1722 // textures) go through and draw a frame, then end the test.
1732 // 1723 //
1733 // Commits 1+2 test the eviction recovery path where eviction happens outside 1724 // Commits 1+2 test the eviction recovery path where eviction happens outside
1734 // of the beginFrame/commit pair. 1725 // of the beginFrame/commit pair.
1735 // Commits 3+4 test the eviction recovery path where eviction happens inside 1726 // Commits 3+4 test the eviction recovery path where eviction happens inside
1736 // the beginFrame/commit pair. 1727 // the beginFrame/commit pair.
1737 // Commits 5+6 test the path where an eviction happens during the eviction 1728 // Commits 5+6 test the path where an eviction happens during the eviction
1738 // recovery path. 1729 // recovery path.
1739 virtual void DidCommit() override { 1730 void DidCommit() override {
1740 switch (num_commits_) { 1731 switch (num_commits_) {
1741 case 1: 1732 case 1:
1742 EXPECT_TRUE(layer_->HaveBackingTexture()); 1733 EXPECT_TRUE(layer_->HaveBackingTexture());
1743 PostEvictTextures(); 1734 PostEvictTextures();
1744 break; 1735 break;
1745 case 2: 1736 case 2:
1746 EXPECT_TRUE(layer_->HaveBackingTexture()); 1737 EXPECT_TRUE(layer_->HaveBackingTexture());
1747 layer_tree_host()->SetNeedsCommit(); 1738 layer_tree_host()->SetNeedsCommit();
1748 break; 1739 break;
1749 case 3: 1740 case 3:
1750 break; 1741 break;
1751 case 4: 1742 case 4:
1752 EXPECT_TRUE(layer_->HaveBackingTexture()); 1743 EXPECT_TRUE(layer_->HaveBackingTexture());
1753 layer_tree_host()->SetNeedsCommit(); 1744 layer_tree_host()->SetNeedsCommit();
1754 break; 1745 break;
1755 case 5: 1746 case 5:
1756 break; 1747 break;
1757 case 6: 1748 case 6:
1758 EXPECT_TRUE(layer_->HaveBackingTexture()); 1749 EXPECT_TRUE(layer_->HaveBackingTexture());
1759 EndTest(); 1750 EndTest();
1760 break; 1751 break;
1761 default: 1752 default:
1762 NOTREACHED(); 1753 NOTREACHED();
1763 break; 1754 break;
1764 } 1755 }
1765 } 1756 }
1766 1757
1767 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1758 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1768 impl_for_evict_textures_ = impl; 1759 impl_for_evict_textures_ = impl;
1769 } 1760 }
1770 1761
1771 virtual void Layout() override { 1762 void Layout() override {
1772 ++num_commits_; 1763 ++num_commits_;
1773 switch (num_commits_) { 1764 switch (num_commits_) {
1774 case 1: 1765 case 1:
1775 case 2: 1766 case 2:
1776 break; 1767 break;
1777 case 3: 1768 case 3:
1778 PostEvictTextures(); 1769 PostEvictTextures();
1779 break; 1770 break;
1780 case 4: 1771 case 4:
1781 // We couldn't check in didCommitAndDrawFrame on commit 3, 1772 // We couldn't check in didCommitAndDrawFrame on commit 3,
1782 // so check here. 1773 // so check here.
1783 EXPECT_FALSE(layer_->HaveBackingTexture()); 1774 EXPECT_FALSE(layer_->HaveBackingTexture());
1784 break; 1775 break;
1785 case 5: 1776 case 5:
1786 PostEvictTextures(); 1777 PostEvictTextures();
1787 break; 1778 break;
1788 case 6: 1779 case 6:
1789 // We couldn't check in didCommitAndDrawFrame on commit 5, 1780 // We couldn't check in didCommitAndDrawFrame on commit 5,
1790 // so check here. 1781 // so check here.
1791 EXPECT_FALSE(layer_->HaveBackingTexture()); 1782 EXPECT_FALSE(layer_->HaveBackingTexture());
1792 PostEvictTextures(); 1783 PostEvictTextures();
1793 break; 1784 break;
1794 default: 1785 default:
1795 NOTREACHED(); 1786 NOTREACHED();
1796 break; 1787 break;
1797 } 1788 }
1798 } 1789 }
1799 1790
1800 virtual void AfterTest() override {} 1791 void AfterTest() override {}
1801 1792
1802 private: 1793 private:
1803 FakeContentLayerClient client_; 1794 FakeContentLayerClient client_;
1804 scoped_refptr<EvictionTestLayer> layer_; 1795 scoped_refptr<EvictionTestLayer> layer_;
1805 LayerTreeHostImpl* impl_for_evict_textures_; 1796 LayerTreeHostImpl* impl_for_evict_textures_;
1806 int num_commits_; 1797 int num_commits_;
1807 }; 1798 };
1808 1799
1809 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestEvictTextures); 1800 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestEvictTextures);
1810 1801
1811 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { 1802 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest {
1812 public: 1803 public:
1813 LayerTreeHostTestContinuousInvalidate() 1804 LayerTreeHostTestContinuousInvalidate()
1814 : num_commit_complete_(0), num_draw_layers_(0) {} 1805 : num_commit_complete_(0), num_draw_layers_(0) {}
1815 1806
1816 virtual void BeginTest() override { 1807 void BeginTest() override {
1817 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); 1808 layer_tree_host()->SetViewportSize(gfx::Size(10, 10));
1818 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); 1809 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
1819 1810
1820 content_layer_ = ContentLayer::Create(&client_); 1811 content_layer_ = ContentLayer::Create(&client_);
1821 content_layer_->SetBounds(gfx::Size(10, 10)); 1812 content_layer_->SetBounds(gfx::Size(10, 10));
1822 content_layer_->SetPosition(gfx::PointF(0.f, 0.f)); 1813 content_layer_->SetPosition(gfx::PointF(0.f, 0.f));
1823 content_layer_->SetIsDrawable(true); 1814 content_layer_->SetIsDrawable(true);
1824 layer_tree_host()->root_layer()->AddChild(content_layer_); 1815 layer_tree_host()->root_layer()->AddChild(content_layer_);
1825 1816
1826 PostSetNeedsCommitToMainThread(); 1817 PostSetNeedsCommitToMainThread();
1827 } 1818 }
1828 1819
1829 virtual void DidCommitAndDrawFrame() override { 1820 void DidCommitAndDrawFrame() override {
1830 if (num_draw_layers_ == 2) 1821 if (num_draw_layers_ == 2)
1831 return; 1822 return;
1832 content_layer_->SetNeedsDisplay(); 1823 content_layer_->SetNeedsDisplay();
1833 } 1824 }
1834 1825
1835 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 1826 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
1836 if (num_draw_layers_ == 1) 1827 if (num_draw_layers_ == 1)
1837 num_commit_complete_++; 1828 num_commit_complete_++;
1838 } 1829 }
1839 1830
1840 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 1831 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
1841 num_draw_layers_++; 1832 num_draw_layers_++;
1842 if (num_draw_layers_ == 2) 1833 if (num_draw_layers_ == 2)
1843 EndTest(); 1834 EndTest();
1844 } 1835 }
1845 1836
1846 virtual void AfterTest() override { 1837 void AfterTest() override {
1847 // Check that we didn't commit twice between first and second draw. 1838 // Check that we didn't commit twice between first and second draw.
1848 EXPECT_EQ(1, num_commit_complete_); 1839 EXPECT_EQ(1, num_commit_complete_);
1849 } 1840 }
1850 1841
1851 private: 1842 private:
1852 FakeContentLayerClient client_; 1843 FakeContentLayerClient client_;
1853 scoped_refptr<Layer> content_layer_; 1844 scoped_refptr<Layer> content_layer_;
1854 int num_commit_complete_; 1845 int num_commit_complete_;
1855 int num_draw_layers_; 1846 int num_draw_layers_;
1856 }; 1847 };
1857 1848
1858 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestContinuousInvalidate); 1849 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestContinuousInvalidate);
1859 1850
1860 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { 1851 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
1861 public: 1852 public:
1862 LayerTreeHostTestDeferCommits() 1853 LayerTreeHostTestDeferCommits()
1863 : num_commits_deferred_(0), num_complete_commits_(0) {} 1854 : num_commits_deferred_(0), num_complete_commits_(0) {}
1864 1855
1865 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1856 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1866 1857
1867 virtual void DidDeferCommit() override { 1858 void DidDeferCommit() override {
1868 num_commits_deferred_++; 1859 num_commits_deferred_++;
1869 layer_tree_host()->SetDeferCommits(false); 1860 layer_tree_host()->SetDeferCommits(false);
1870 } 1861 }
1871 1862
1872 virtual void DidCommit() override { 1863 void DidCommit() override {
1873 num_complete_commits_++; 1864 num_complete_commits_++;
1874 switch (num_complete_commits_) { 1865 switch (num_complete_commits_) {
1875 case 1: 1866 case 1:
1876 EXPECT_EQ(0, num_commits_deferred_); 1867 EXPECT_EQ(0, num_commits_deferred_);
1877 layer_tree_host()->SetDeferCommits(true); 1868 layer_tree_host()->SetDeferCommits(true);
1878 PostSetNeedsCommitToMainThread(); 1869 PostSetNeedsCommitToMainThread();
1879 break; 1870 break;
1880 case 2: 1871 case 2:
1881 EndTest(); 1872 EndTest();
1882 break; 1873 break;
1883 default: 1874 default:
1884 NOTREACHED(); 1875 NOTREACHED();
1885 break; 1876 break;
1886 } 1877 }
1887 } 1878 }
1888 1879
1889 virtual void AfterTest() override { 1880 void AfterTest() override {
1890 EXPECT_EQ(1, num_commits_deferred_); 1881 EXPECT_EQ(1, num_commits_deferred_);
1891 EXPECT_EQ(2, num_complete_commits_); 1882 EXPECT_EQ(2, num_complete_commits_);
1892 } 1883 }
1893 1884
1894 private: 1885 private:
1895 int num_commits_deferred_; 1886 int num_commits_deferred_;
1896 int num_complete_commits_; 1887 int num_complete_commits_;
1897 }; 1888 };
1898 1889
1899 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 1890 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 2047
2057 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted 2048 class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted
2058 : public LayerTreeHostTest { 2049 : public LayerTreeHostTest {
2059 public: 2050 public:
2060 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted() 2051 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted()
2061 : root_layer_(FakeContentLayer::Create(&client_)), 2052 : root_layer_(FakeContentLayer::Create(&client_)),
2062 child_layer1_(FakeContentLayer::Create(&client_)), 2053 child_layer1_(FakeContentLayer::Create(&client_)),
2063 child_layer2_(FakeContentLayer::Create(&client_)), 2054 child_layer2_(FakeContentLayer::Create(&client_)),
2064 num_commits_(0) {} 2055 num_commits_(0) {}
2065 2056
2066 virtual void BeginTest() override { 2057 void BeginTest() override {
2067 layer_tree_host()->SetViewportSize(gfx::Size(100, 100)); 2058 layer_tree_host()->SetViewportSize(gfx::Size(100, 100));
2068 root_layer_->SetBounds(gfx::Size(100, 100)); 2059 root_layer_->SetBounds(gfx::Size(100, 100));
2069 child_layer1_->SetBounds(gfx::Size(100, 100)); 2060 child_layer1_->SetBounds(gfx::Size(100, 100));
2070 child_layer2_->SetBounds(gfx::Size(100, 100)); 2061 child_layer2_->SetBounds(gfx::Size(100, 100));
2071 root_layer_->AddChild(child_layer1_); 2062 root_layer_->AddChild(child_layer1_);
2072 root_layer_->AddChild(child_layer2_); 2063 root_layer_->AddChild(child_layer2_);
2073 layer_tree_host()->SetRootLayer(root_layer_); 2064 layer_tree_host()->SetRootLayer(root_layer_);
2074 PostSetNeedsCommitToMainThread(); 2065 PostSetNeedsCommitToMainThread();
2075 } 2066 }
2076 2067
2077 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, 2068 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
2078 bool visible) override { 2069 bool visible) override {
2079 if (visible) { 2070 if (visible) {
2080 // One backing should remain unevicted. 2071 // One backing should remain unevicted.
2081 EXPECT_EQ( 2072 EXPECT_EQ(
2082 100u * 100u * 4u * 1u, 2073 100u * 100u * 4u * 1u,
2083 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2074 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2084 } else { 2075 } else {
2085 EXPECT_EQ( 2076 EXPECT_EQ(
2086 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2077 0u, layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2087 } 2078 }
2088 2079
2089 // Make sure that contents textures are marked as having been 2080 // Make sure that contents textures are marked as having been
2090 // purged. 2081 // purged.
2091 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged()); 2082 EXPECT_TRUE(host_impl->active_tree()->ContentsTexturesPurged());
2092 // End the test in this state. 2083 // End the test in this state.
2093 EndTest(); 2084 EndTest();
2094 } 2085 }
2095 2086
2096 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 2087 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2097 ++num_commits_; 2088 ++num_commits_;
2098 switch (num_commits_) { 2089 switch (num_commits_) {
2099 case 1: 2090 case 1:
2100 // All three backings should have memory. 2091 // All three backings should have memory.
2101 EXPECT_EQ( 2092 EXPECT_EQ(
2102 100u * 100u * 4u * 3u, 2093 100u * 100u * 4u * 3u,
2103 layer_tree_host()->contents_texture_manager()->MemoryUseBytes()); 2094 layer_tree_host()->contents_texture_manager()->MemoryUseBytes());
2104 // Set a new policy that will kick out 1 of the 3 resources. 2095 // Set a new policy that will kick out 1 of the 3 resources.
2105 // Because a resource was evicted, a commit will be kicked off. 2096 // Because a resource was evicted, a commit will be kicked off.
2106 host_impl->SetMemoryPolicy( 2097 host_impl->SetMemoryPolicy(
(...skipping 11 matching lines...) Expand all
2118 PostSetVisibleToMainThread(false); 2109 PostSetVisibleToMainThread(false);
2119 break; 2110 break;
2120 default: 2111 default:
2121 // No further commits should happen because this is not visible 2112 // No further commits should happen because this is not visible
2122 // anymore. 2113 // anymore.
2123 NOTREACHED(); 2114 NOTREACHED();
2124 break; 2115 break;
2125 } 2116 }
2126 } 2117 }
2127 2118
2128 virtual void AfterTest() override {} 2119 void AfterTest() override {}
2129 2120
2130 private: 2121 private:
2131 FakeContentLayerClient client_; 2122 FakeContentLayerClient client_;
2132 scoped_refptr<FakeContentLayer> root_layer_; 2123 scoped_refptr<FakeContentLayer> root_layer_;
2133 scoped_refptr<FakeContentLayer> child_layer1_; 2124 scoped_refptr<FakeContentLayer> child_layer1_;
2134 scoped_refptr<FakeContentLayer> child_layer2_; 2125 scoped_refptr<FakeContentLayer> child_layer2_;
2135 int num_commits_; 2126 int num_commits_;
2136 }; 2127 };
2137 2128
2138 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( 2129 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
2139 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); 2130 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted);
2140 2131
2141 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { 2132 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
2142 public: 2133 public:
2143 class NotificationClient : public ContentLayerClient { 2134 class NotificationClient : public ContentLayerClient {
2144 public: 2135 public:
2145 NotificationClient() 2136 NotificationClient()
2146 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} 2137 : layer_(0), paint_count_(0), lcd_notification_count_(0) {}
2147 2138
2148 void set_layer(Layer* layer) { layer_ = layer; } 2139 void set_layer(Layer* layer) { layer_ = layer; }
2149 int paint_count() const { return paint_count_; } 2140 int paint_count() const { return paint_count_; }
2150 int lcd_notification_count() const { return lcd_notification_count_; } 2141 int lcd_notification_count() const { return lcd_notification_count_; }
2151 2142
2152 virtual void PaintContents( 2143 void PaintContents(
2153 SkCanvas* canvas, 2144 SkCanvas* canvas,
2154 const gfx::Rect& clip, 2145 const gfx::Rect& clip,
2155 ContentLayerClient::GraphicsContextStatus gc_status) override { 2146 ContentLayerClient::GraphicsContextStatus gc_status) override {
2156 ++paint_count_; 2147 ++paint_count_;
2157 } 2148 }
2158 virtual void DidChangeLayerCanUseLCDText() override { 2149 void DidChangeLayerCanUseLCDText() override {
2159 ++lcd_notification_count_; 2150 ++lcd_notification_count_;
2160 layer_->SetNeedsDisplay(); 2151 layer_->SetNeedsDisplay();
2161 } 2152 }
2162 virtual bool FillsBoundsCompletely() const override { return false; } 2153 bool FillsBoundsCompletely() const override { return false; }
2163 2154
2164 private: 2155 private:
2165 Layer* layer_; 2156 Layer* layer_;
2166 int paint_count_; 2157 int paint_count_;
2167 int lcd_notification_count_; 2158 int lcd_notification_count_;
2168 }; 2159 };
2169 2160
2170 virtual void SetupTree() override { 2161 void SetupTree() override {
2171 scoped_refptr<Layer> root_layer; 2162 scoped_refptr<Layer> root_layer;
2172 if (layer_tree_host()->settings().impl_side_painting) 2163 if (layer_tree_host()->settings().impl_side_painting)
2173 root_layer = PictureLayer::Create(&client_); 2164 root_layer = PictureLayer::Create(&client_);
2174 else 2165 else
2175 root_layer = ContentLayer::Create(&client_); 2166 root_layer = ContentLayer::Create(&client_);
2176 root_layer->SetIsDrawable(true); 2167 root_layer->SetIsDrawable(true);
2177 root_layer->SetBounds(gfx::Size(1, 1)); 2168 root_layer->SetBounds(gfx::Size(1, 1));
2178 2169
2179 layer_tree_host()->SetRootLayer(root_layer); 2170 layer_tree_host()->SetRootLayer(root_layer);
2180 client_.set_layer(root_layer.get()); 2171 client_.set_layer(root_layer.get());
2181 2172
2182 // The expecations are based on the assumption that the default 2173 // The expecations are based on the assumption that the default
2183 // LCD settings are: 2174 // LCD settings are:
2184 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); 2175 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
2185 EXPECT_FALSE(root_layer->can_use_lcd_text()); 2176 EXPECT_FALSE(root_layer->can_use_lcd_text());
2186 2177
2187 LayerTreeHostTest::SetupTree(); 2178 LayerTreeHostTest::SetupTree();
2188 } 2179 }
2189 2180
2190 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2181 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2191 virtual void AfterTest() override {} 2182 void AfterTest() override {}
2192 2183
2193 virtual void DidCommit() override { 2184 void DidCommit() override {
2194 switch (layer_tree_host()->source_frame_number()) { 2185 switch (layer_tree_host()->source_frame_number()) {
2195 case 1: 2186 case 1:
2196 // The first update consists of one LCD notification and one paint. 2187 // The first update consists of one LCD notification and one paint.
2197 EXPECT_EQ(1, client_.lcd_notification_count()); 2188 EXPECT_EQ(1, client_.lcd_notification_count());
2198 EXPECT_EQ(1, client_.paint_count()); 2189 EXPECT_EQ(1, client_.paint_count());
2199 // LCD text must have been enabled on the layer. 2190 // LCD text must have been enabled on the layer.
2200 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2191 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2201 PostSetNeedsCommitToMainThread(); 2192 PostSetNeedsCommitToMainThread();
2202 break; 2193 break;
2203 case 2: 2194 case 2:
(...skipping 24 matching lines...) Expand all
2228 2219
2229 private: 2220 private:
2230 NotificationClient client_; 2221 NotificationClient client_;
2231 }; 2222 };
2232 2223
2233 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification); 2224 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification);
2234 2225
2235 // Verify that the BeginFrame notification is used to initiate rendering. 2226 // Verify that the BeginFrame notification is used to initiate rendering.
2236 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { 2227 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest {
2237 public: 2228 public:
2238 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2229 void InitializeSettings(LayerTreeSettings* settings) override {
2239 settings->begin_frame_scheduling_enabled = true; 2230 settings->begin_frame_scheduling_enabled = true;
2240 } 2231 }
2241 2232
2242 virtual void BeginTest() override { 2233 void BeginTest() override {
2243 // This will trigger a SetNeedsBeginFrame which will trigger a 2234 // This will trigger a SetNeedsBeginFrame which will trigger a
2244 // BeginFrame. 2235 // BeginFrame.
2245 PostSetNeedsCommitToMainThread(); 2236 PostSetNeedsCommitToMainThread();
2246 } 2237 }
2247 2238
2248 virtual DrawResult PrepareToDrawOnThread( 2239 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2249 LayerTreeHostImpl* host_impl, 2240 LayerTreeHostImpl::FrameData* frame,
2250 LayerTreeHostImpl::FrameData* frame, 2241 DrawResult draw_result) override {
2251 DrawResult draw_result) override {
2252 EndTest(); 2242 EndTest();
2253 return DRAW_SUCCESS; 2243 return DRAW_SUCCESS;
2254 } 2244 }
2255 2245
2256 virtual void AfterTest() override {} 2246 void AfterTest() override {}
2257 2247
2258 private: 2248 private:
2259 base::TimeTicks frame_time_; 2249 base::TimeTicks frame_time_;
2260 }; 2250 };
2261 2251
2262 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); 2252 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification);
2263 2253
2264 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled 2254 class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled
2265 : public LayerTreeHostTest { 2255 : public LayerTreeHostTest {
2266 public: 2256 public:
2267 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2257 void InitializeSettings(LayerTreeSettings* settings) override {
2268 settings->begin_frame_scheduling_enabled = true; 2258 settings->begin_frame_scheduling_enabled = true;
2269 settings->using_synchronous_renderer_compositor = true; 2259 settings->using_synchronous_renderer_compositor = true;
2270 } 2260 }
2271 2261
2272 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2262 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2273 2263
2274 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 2264 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
2275 // The BeginFrame notification is turned off now but will get enabled 2265 // The BeginFrame notification is turned off now but will get enabled
2276 // once we return. End test while it's enabled. 2266 // once we return. End test while it's enabled.
2277 ImplThreadTaskRunner()->PostTask( 2267 ImplThreadTaskRunner()->PostTask(
2278 FROM_HERE, 2268 FROM_HERE,
2279 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest, 2269 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest,
2280 base::Unretained(this))); 2270 base::Unretained(this)));
2281 } 2271 }
2282 2272
2283 virtual void AfterTest() override {} 2273 void AfterTest() override {}
2284 }; 2274 };
2285 2275
2286 MULTI_THREAD_TEST_F( 2276 MULTI_THREAD_TEST_F(
2287 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); 2277 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled);
2288 2278
2289 class LayerTreeHostTestAbortedCommitDoesntStall : public LayerTreeHostTest { 2279 class LayerTreeHostTestAbortedCommitDoesntStall : public LayerTreeHostTest {
2290 protected: 2280 protected:
2291 LayerTreeHostTestAbortedCommitDoesntStall() 2281 LayerTreeHostTestAbortedCommitDoesntStall()
2292 : commit_count_(0), commit_abort_count_(0), commit_complete_count_(0) {} 2282 : commit_count_(0), commit_abort_count_(0), commit_complete_count_(0) {}
2293 2283
2294 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2284 void InitializeSettings(LayerTreeSettings* settings) override {
2295 settings->begin_frame_scheduling_enabled = true; 2285 settings->begin_frame_scheduling_enabled = true;
2296 } 2286 }
2297 2287
2298 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2288 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2299 2289
2300 virtual void DidCommit() override { 2290 void DidCommit() override {
2301 commit_count_++; 2291 commit_count_++;
2302 if (commit_count_ == 4) { 2292 if (commit_count_ == 4) {
2303 // After two aborted commits, request a real commit now to make sure a 2293 // After two aborted commits, request a real commit now to make sure a
2304 // real commit following an aborted commit will still complete and 2294 // real commit following an aborted commit will still complete and
2305 // end the test even when the Impl thread is idle. 2295 // end the test even when the Impl thread is idle.
2306 layer_tree_host()->SetNeedsCommit(); 2296 layer_tree_host()->SetNeedsCommit();
2307 } 2297 }
2308 } 2298 }
2309 2299
2310 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 2300 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
2311 bool did_handle) override { 2301 bool did_handle) override {
2312 commit_abort_count_++; 2302 commit_abort_count_++;
2313 // Initiate another abortable commit. 2303 // Initiate another abortable commit.
2314 host_impl->SetNeedsCommit(); 2304 host_impl->SetNeedsCommit();
2315 } 2305 }
2316 2306
2317 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 2307 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
2318 commit_complete_count_++; 2308 commit_complete_count_++;
2319 if (commit_complete_count_ == 1) { 2309 if (commit_complete_count_ == 1) {
2320 // Initiate an abortable commit after the first commit. 2310 // Initiate an abortable commit after the first commit.
2321 host_impl->SetNeedsCommit(); 2311 host_impl->SetNeedsCommit();
2322 } else { 2312 } else {
2323 EndTest(); 2313 EndTest();
2324 } 2314 }
2325 } 2315 }
2326 2316
2327 virtual void AfterTest() override { 2317 void AfterTest() override {
2328 EXPECT_EQ(commit_count_, 5); 2318 EXPECT_EQ(commit_count_, 5);
2329 EXPECT_EQ(commit_abort_count_, 3); 2319 EXPECT_EQ(commit_abort_count_, 3);
2330 EXPECT_EQ(commit_complete_count_, 2); 2320 EXPECT_EQ(commit_complete_count_, 2);
2331 } 2321 }
2332 2322
2333 int commit_count_; 2323 int commit_count_;
2334 int commit_abort_count_; 2324 int commit_abort_count_;
2335 int commit_complete_count_; 2325 int commit_complete_count_;
2336 }; 2326 };
2337 2327
2338 class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor 2328 class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
2339 : public LayerTreeHostTestAbortedCommitDoesntStall { 2329 : public LayerTreeHostTestAbortedCommitDoesntStall {
2340 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2330 void InitializeSettings(LayerTreeSettings* settings) override {
2341 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings); 2331 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings);
2342 settings->using_synchronous_renderer_compositor = true; 2332 settings->using_synchronous_renderer_compositor = true;
2343 } 2333 }
2344 }; 2334 };
2345 2335
2346 MULTI_THREAD_TEST_F( 2336 MULTI_THREAD_TEST_F(
2347 LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor); 2337 LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor);
2348 2338
2349 class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync 2339 class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync
2350 : public LayerTreeHostTestAbortedCommitDoesntStall { 2340 : public LayerTreeHostTestAbortedCommitDoesntStall {
2351 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2341 void InitializeSettings(LayerTreeSettings* settings) override {
2352 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings); 2342 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings);
2353 settings->throttle_frame_production = false; 2343 settings->throttle_frame_production = false;
2354 } 2344 }
2355 }; 2345 };
2356 2346
2357 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync); 2347 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync);
2358 2348
2359 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation 2349 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation
2360 : public LayerTreeHostTest { 2350 : public LayerTreeHostTest {
2361 protected: 2351 protected:
2362 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2352 void InitializeSettings(LayerTreeSettings* settings) override {
2363 settings->impl_side_painting = true; 2353 settings->impl_side_painting = true;
2364 } 2354 }
2365 2355
2366 virtual void SetupTree() override { 2356 void SetupTree() override {
2367 LayerTreeHostTest::SetupTree(); 2357 LayerTreeHostTest::SetupTree();
2368 2358
2369 scoped_refptr<Layer> layer = PictureLayer::Create(&client_); 2359 scoped_refptr<Layer> layer = PictureLayer::Create(&client_);
2370 layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); 2360 layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2371 layer->SetBounds(gfx::Size(10, 10)); 2361 layer->SetBounds(gfx::Size(10, 10));
2372 layer_tree_host()->root_layer()->AddChild(layer); 2362 layer_tree_host()->root_layer()->AddChild(layer);
2373 } 2363 }
2374 2364
2375 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2365 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2376 2366
2377 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 2367 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2378 EndTest(); 2368 EndTest();
2379 } 2369 }
2380 2370
2381 virtual void AfterTest() override {} 2371 void AfterTest() override {}
2382 2372
2383 FakeContentLayerClient client_; 2373 FakeContentLayerClient client_;
2384 }; 2374 };
2385 2375
2386 MULTI_THREAD_TEST_F( 2376 MULTI_THREAD_TEST_F(
2387 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); 2377 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation);
2388 2378
2389 class LayerTreeHostTestChangeLayerPropertiesInPaintContents 2379 class LayerTreeHostTestChangeLayerPropertiesInPaintContents
2390 : public LayerTreeHostTest { 2380 : public LayerTreeHostTest {
2391 public: 2381 public:
2392 class SetBoundsClient : public ContentLayerClient { 2382 class SetBoundsClient : public ContentLayerClient {
2393 public: 2383 public:
2394 SetBoundsClient() : layer_(0) {} 2384 SetBoundsClient() : layer_(0) {}
2395 2385
2396 void set_layer(Layer* layer) { layer_ = layer; } 2386 void set_layer(Layer* layer) { layer_ = layer; }
2397 2387
2398 virtual void PaintContents( 2388 void PaintContents(
2399 SkCanvas* canvas, 2389 SkCanvas* canvas,
2400 const gfx::Rect& clip, 2390 const gfx::Rect& clip,
2401 ContentLayerClient::GraphicsContextStatus gc_status) override { 2391 ContentLayerClient::GraphicsContextStatus gc_status) override {
2402 layer_->SetBounds(gfx::Size(2, 2)); 2392 layer_->SetBounds(gfx::Size(2, 2));
2403 } 2393 }
2404 2394
2405 virtual void DidChangeLayerCanUseLCDText() override {} 2395 void DidChangeLayerCanUseLCDText() override {}
2406 2396
2407 virtual bool FillsBoundsCompletely() const override { return false; } 2397 bool FillsBoundsCompletely() const override { return false; }
2408 2398
2409 private: 2399 private:
2410 Layer* layer_; 2400 Layer* layer_;
2411 }; 2401 };
2412 2402
2413 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} 2403 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
2414 2404
2415 virtual void SetupTree() override { 2405 void SetupTree() override {
2416 if (layer_tree_host()->settings().impl_side_painting) { 2406 if (layer_tree_host()->settings().impl_side_painting) {
2417 scoped_refptr<PictureLayer> root_layer = PictureLayer::Create(&client_); 2407 scoped_refptr<PictureLayer> root_layer = PictureLayer::Create(&client_);
2418 layer_tree_host()->SetRootLayer(root_layer); 2408 layer_tree_host()->SetRootLayer(root_layer);
2419 } else { 2409 } else {
2420 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_); 2410 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_);
2421 layer_tree_host()->SetRootLayer(root_layer); 2411 layer_tree_host()->SetRootLayer(root_layer);
2422 } 2412 }
2423 Layer* root_layer = layer_tree_host()->root_layer(); 2413 Layer* root_layer = layer_tree_host()->root_layer();
2424 root_layer->SetIsDrawable(true); 2414 root_layer->SetIsDrawable(true);
2425 root_layer->SetBounds(gfx::Size(1, 1)); 2415 root_layer->SetBounds(gfx::Size(1, 1));
2426 2416
2427 client_.set_layer(root_layer); 2417 client_.set_layer(root_layer);
2428 2418
2429 LayerTreeHostTest::SetupTree(); 2419 LayerTreeHostTest::SetupTree();
2430 } 2420 }
2431 2421
2432 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2422 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2433 virtual void AfterTest() override {} 2423 void AfterTest() override {}
2434 2424
2435 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 2425 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2436 num_commits_++; 2426 num_commits_++;
2437 if (num_commits_ == 1) { 2427 if (num_commits_ == 1) {
2438 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); 2428 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
2439 EXPECT_SIZE_EQ(gfx::Size(1, 1), root_layer->bounds()); 2429 EXPECT_SIZE_EQ(gfx::Size(1, 1), root_layer->bounds());
2440 } else { 2430 } else {
2441 LayerImpl* root_layer = host_impl->active_tree()->root_layer(); 2431 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
2442 EXPECT_SIZE_EQ(gfx::Size(2, 2), root_layer->bounds()); 2432 EXPECT_SIZE_EQ(gfx::Size(2, 2), root_layer->bounds());
2443 EndTest(); 2433 EndTest();
2444 } 2434 }
2445 } 2435 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 GLsizei count, 2467 GLsizei count,
2478 GLenum type, 2468 GLenum type,
2479 GLintptr offset)); 2469 GLintptr offset));
2480 MOCK_METHOD1(deleteTexture, void(GLenum texture)); 2470 MOCK_METHOD1(deleteTexture, void(GLenum texture));
2481 MOCK_METHOD2(produceTextureCHROMIUM, 2471 MOCK_METHOD2(produceTextureCHROMIUM,
2482 void(GLenum target, const GLbyte* mailbox)); 2472 void(GLenum target, const GLbyte* mailbox));
2483 }; 2473 };
2484 2474
2485 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { 2475 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
2486 protected: 2476 protected:
2487 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 2477 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
2488 override { 2478 bool fallback) override {
2489 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned( 2479 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned(
2490 new MockIOSurfaceWebGraphicsContext3D); 2480 new MockIOSurfaceWebGraphicsContext3D);
2491 mock_context_ = mock_context_owned.get(); 2481 mock_context_ = mock_context_owned.get();
2492 2482
2493 if (delegating_renderer()) 2483 if (delegating_renderer())
2494 return FakeOutputSurface::CreateDelegating3d(mock_context_owned.Pass()); 2484 return FakeOutputSurface::CreateDelegating3d(mock_context_owned.Pass());
2495 else 2485 else
2496 return FakeOutputSurface::Create3d(mock_context_owned.Pass()); 2486 return FakeOutputSurface::Create3d(mock_context_owned.Pass());
2497 } 2487 }
2498 2488
2499 virtual void SetupTree() override { 2489 void SetupTree() override {
2500 LayerTreeHostTest::SetupTree(); 2490 LayerTreeHostTest::SetupTree();
2501 2491
2502 layer_tree_host()->root_layer()->SetIsDrawable(false); 2492 layer_tree_host()->root_layer()->SetIsDrawable(false);
2503 2493
2504 io_surface_id_ = 9; 2494 io_surface_id_ = 9;
2505 io_surface_size_ = gfx::Size(6, 7); 2495 io_surface_size_ = gfx::Size(6, 7);
2506 2496
2507 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create(); 2497 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create();
2508 io_surface_layer->SetBounds(gfx::Size(10, 10)); 2498 io_surface_layer->SetBounds(gfx::Size(10, 10));
2509 io_surface_layer->SetIsDrawable(true); 2499 io_surface_layer->SetIsDrawable(true);
2510 io_surface_layer->SetContentsOpaque(true); 2500 io_surface_layer->SetContentsOpaque(true);
2511 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); 2501 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_);
2512 layer_tree_host()->root_layer()->AddChild(io_surface_layer); 2502 layer_tree_host()->root_layer()->AddChild(io_surface_layer);
2513 } 2503 }
2514 2504
2515 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2505 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2516 2506
2517 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 2507 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
2518 EXPECT_EQ(0u, host_impl->resource_provider()->num_resources()); 2508 EXPECT_EQ(0u, host_impl->resource_provider()->num_resources());
2519 // In WillDraw, the IOSurfaceLayer sets up the io surface texture. 2509 // In WillDraw, the IOSurfaceLayer sets up the io surface texture.
2520 2510
2521 EXPECT_CALL(*mock_context_, activeTexture(_)).Times(0); 2511 EXPECT_CALL(*mock_context_, activeTexture(_)).Times(0);
2522 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) 2512 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2523 .Times(AtLeast(1)); 2513 .Times(AtLeast(1));
2524 EXPECT_CALL(*mock_context_, 2514 EXPECT_CALL(*mock_context_,
2525 texParameteri( 2515 texParameteri(
2526 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR)) 2516 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR))
2527 .Times(1); 2517 .Times(1);
(...skipping 17 matching lines...) Expand all
2545 EXPECT_CALL(*mock_context_, 2535 EXPECT_CALL(*mock_context_,
2546 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, 2536 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB,
2547 io_surface_size_.width(), 2537 io_surface_size_.width(),
2548 io_surface_size_.height(), 2538 io_surface_size_.height(),
2549 io_surface_id_, 2539 io_surface_id_,
2550 0)).Times(1); 2540 0)).Times(1);
2551 2541
2552 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); 2542 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber());
2553 } 2543 }
2554 2544
2555 virtual DrawResult PrepareToDrawOnThread( 2545 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2556 LayerTreeHostImpl* host_impl, 2546 LayerTreeHostImpl::FrameData* frame,
2557 LayerTreeHostImpl::FrameData* frame, 2547 DrawResult draw_result) override {
2558 DrawResult draw_result) override {
2559 Mock::VerifyAndClearExpectations(&mock_context_); 2548 Mock::VerifyAndClearExpectations(&mock_context_);
2560 ResourceProvider* resource_provider = host_impl->resource_provider(); 2549 ResourceProvider* resource_provider = host_impl->resource_provider();
2561 EXPECT_EQ(1u, resource_provider->num_resources()); 2550 EXPECT_EQ(1u, resource_provider->num_resources());
2562 CHECK_EQ(1u, frame->render_passes.size()); 2551 CHECK_EQ(1u, frame->render_passes.size());
2563 CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); 2552 CHECK_LE(1u, frame->render_passes[0]->quad_list.size());
2564 const DrawQuad* quad = frame->render_passes[0]->quad_list.front(); 2553 const DrawQuad* quad = frame->render_passes[0]->quad_list.front();
2565 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); 2554 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material);
2566 const IOSurfaceDrawQuad* io_surface_draw_quad = 2555 const IOSurfaceDrawQuad* io_surface_draw_quad =
2567 IOSurfaceDrawQuad::MaterialCast(quad); 2556 IOSurfaceDrawQuad::MaterialCast(quad);
2568 EXPECT_SIZE_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); 2557 EXPECT_SIZE_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size);
(...skipping 11 matching lines...) Expand all
2580 } else { 2569 } else {
2581 // The io surface layer's texture is drawn. 2570 // The io surface layer's texture is drawn.
2582 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1)); 2571 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1));
2583 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) 2572 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _))
2584 .Times(AtLeast(1)); 2573 .Times(AtLeast(1));
2585 } 2574 }
2586 2575
2587 return draw_result; 2576 return draw_result;
2588 } 2577 }
2589 2578
2590 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 2579 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
2591 Mock::VerifyAndClearExpectations(&mock_context_); 2580 Mock::VerifyAndClearExpectations(&mock_context_);
2592 2581
2593 EXPECT_CALL(*mock_context_, deleteTexture(1)).Times(AtLeast(1)); 2582 EXPECT_CALL(*mock_context_, deleteTexture(1)).Times(AtLeast(1));
2594 EndTest(); 2583 EndTest();
2595 } 2584 }
2596 2585
2597 virtual void AfterTest() override {} 2586 void AfterTest() override {}
2598 2587
2599 int io_surface_id_; 2588 int io_surface_id_;
2600 MockIOSurfaceWebGraphicsContext3D* mock_context_; 2589 MockIOSurfaceWebGraphicsContext3D* mock_context_;
2601 gfx::Size io_surface_size_; 2590 gfx::Size io_surface_size_;
2602 }; 2591 };
2603 2592
2604 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing); 2593 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing);
2605 2594
2606 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { 2595 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest {
2607 public: 2596 public:
2608 virtual void BeginTest() override { 2597 void BeginTest() override {
2609 frame_ = 0; 2598 frame_ = 0;
2610 PostSetNeedsCommitToMainThread(); 2599 PostSetNeedsCommitToMainThread();
2611 } 2600 }
2612 2601
2613 // Round 1: commit + draw 2602 // Round 1: commit + draw
2614 // Round 2: commit only (no draw/swap) 2603 // Round 2: commit only (no draw/swap)
2615 // Round 3: draw only (no commit) 2604 // Round 3: draw only (no commit)
2616 2605
2617 virtual void DidCommit() override { 2606 void DidCommit() override {
2618 int commit = layer_tree_host()->source_frame_number(); 2607 int commit = layer_tree_host()->source_frame_number();
2619 switch (commit) { 2608 switch (commit) {
2620 case 2: 2609 case 2:
2621 // Round 2 done. 2610 // Round 2 done.
2622 EXPECT_EQ(1, frame_); 2611 EXPECT_EQ(1, frame_);
2623 layer_tree_host()->SetNeedsRedraw(); 2612 layer_tree_host()->SetNeedsRedraw();
2624 break; 2613 break;
2625 } 2614 }
2626 } 2615 }
2627 2616
2628 virtual void DidCompleteSwapBuffers() override { 2617 void DidCompleteSwapBuffers() override {
2629 int commit = layer_tree_host()->source_frame_number(); 2618 int commit = layer_tree_host()->source_frame_number();
2630 ++frame_; 2619 ++frame_;
2631 switch (frame_) { 2620 switch (frame_) {
2632 case 1: 2621 case 1:
2633 // Round 1 done. 2622 // Round 1 done.
2634 EXPECT_EQ(1, commit); 2623 EXPECT_EQ(1, commit);
2635 layer_tree_host()->SetNeedsCommit(); 2624 layer_tree_host()->SetNeedsCommit();
2636 break; 2625 break;
2637 case 2: 2626 case 2:
2638 // Round 3 done. 2627 // Round 3 done.
2639 EXPECT_EQ(2, commit); 2628 EXPECT_EQ(2, commit);
2640 EndTest(); 2629 EndTest();
2641 break; 2630 break;
2642 } 2631 }
2643 } 2632 }
2644 2633
2645 virtual void AfterTest() override {} 2634 void AfterTest() override {}
2646 2635
2647 protected: 2636 protected:
2648 int frame_; 2637 int frame_;
2649 }; 2638 };
2650 2639
2651 // Flaky on all platforms: http://crbug.com/327498 2640 // Flaky on all platforms: http://crbug.com/327498
2652 TEST_F(LayerTreeHostTestNumFramesPending, DISABLED_DelegatingRenderer) { 2641 TEST_F(LayerTreeHostTestNumFramesPending, DISABLED_DelegatingRenderer) {
2653 RunTest(true, true, true); 2642 RunTest(true, true, true);
2654 } 2643 }
2655 2644
2656 TEST_F(LayerTreeHostTestNumFramesPending, DISABLED_GLRenderer) { 2645 TEST_F(LayerTreeHostTestNumFramesPending, DISABLED_GLRenderer) {
2657 RunTest(true, false, true); 2646 RunTest(true, false, true);
2658 } 2647 }
2659 2648
2660 class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest { 2649 class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest {
2661 public: 2650 public:
2662 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2651 void InitializeSettings(LayerTreeSettings* settings) override {
2663 // PictureLayer can only be used with impl side painting enabled. 2652 // PictureLayer can only be used with impl side painting enabled.
2664 settings->impl_side_painting = true; 2653 settings->impl_side_painting = true;
2665 } 2654 }
2666 2655
2667 virtual void SetupTree() override { 2656 void SetupTree() override {
2668 layer_ = FakePictureLayer::Create(&client_); 2657 layer_ = FakePictureLayer::Create(&client_);
2669 // Force commits to not be aborted so new frames get drawn, otherwise 2658 // Force commits to not be aborted so new frames get drawn, otherwise
2670 // the renderer gets deferred initialized but nothing new needs drawing. 2659 // the renderer gets deferred initialized but nothing new needs drawing.
2671 layer_->set_always_update_resources(true); 2660 layer_->set_always_update_resources(true);
2672 layer_tree_host()->SetRootLayer(layer_); 2661 layer_tree_host()->SetRootLayer(layer_);
2673 LayerTreeHostTest::SetupTree(); 2662 LayerTreeHostTest::SetupTree();
2674 } 2663 }
2675 2664
2676 virtual void BeginTest() override { 2665 void BeginTest() override {
2677 did_initialize_gl_ = false; 2666 did_initialize_gl_ = false;
2678 did_release_gl_ = false; 2667 did_release_gl_ = false;
2679 last_source_frame_number_drawn_ = -1; // Never drawn. 2668 last_source_frame_number_drawn_ = -1; // Never drawn.
2680 PostSetNeedsCommitToMainThread(); 2669 PostSetNeedsCommitToMainThread();
2681 } 2670 }
2682 2671
2683 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 2672 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
2684 override { 2673 bool fallback) override {
2685 scoped_ptr<TestWebGraphicsContext3D> context3d( 2674 scoped_ptr<TestWebGraphicsContext3D> context3d(
2686 TestWebGraphicsContext3D::Create()); 2675 TestWebGraphicsContext3D::Create());
2687 2676
2688 return FakeOutputSurface::CreateDeferredGL( 2677 return FakeOutputSurface::CreateDeferredGL(
2689 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), 2678 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice),
2690 delegating_renderer()); 2679 delegating_renderer());
2691 } 2680 }
2692 2681
2693 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 2682 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
2694 ASSERT_TRUE(host_impl->RootLayer()); 2683 ASSERT_TRUE(host_impl->RootLayer());
2695 FakePictureLayerImpl* layer_impl = 2684 FakePictureLayerImpl* layer_impl =
2696 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); 2685 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer());
2697 2686
2698 // The same frame can be draw multiple times if new visible tiles are 2687 // The same frame can be draw multiple times if new visible tiles are
2699 // rasterized. But we want to make sure we only post DeferredInitialize 2688 // rasterized. But we want to make sure we only post DeferredInitialize
2700 // and ReleaseGL once, so early out if the same frame is drawn again. 2689 // and ReleaseGL once, so early out if the same frame is drawn again.
2701 if (last_source_frame_number_drawn_ == 2690 if (last_source_frame_number_drawn_ ==
2702 host_impl->active_tree()->source_frame_number()) 2691 host_impl->active_tree()->source_frame_number())
2703 return; 2692 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2739 } 2728 }
2740 2729
2741 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { 2730 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) {
2742 EXPECT_TRUE(did_initialize_gl_); 2731 EXPECT_TRUE(did_initialize_gl_);
2743 EXPECT_FALSE(did_release_gl_); 2732 EXPECT_FALSE(did_release_gl_);
2744 // ReleaseGL calls SetNeedsCommit. 2733 // ReleaseGL calls SetNeedsCommit.
2745 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); 2734 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL();
2746 did_release_gl_ = true; 2735 did_release_gl_ = true;
2747 } 2736 }
2748 2737
2749 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 2738 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override {
2750 bool result) override {
2751 ASSERT_TRUE(result); 2739 ASSERT_TRUE(result);
2752 DelegatedFrameData* delegated_frame_data = 2740 DelegatedFrameData* delegated_frame_data =
2753 output_surface()->last_sent_frame().delegated_frame_data.get(); 2741 output_surface()->last_sent_frame().delegated_frame_data.get();
2754 if (!delegated_frame_data) 2742 if (!delegated_frame_data)
2755 return; 2743 return;
2756 2744
2757 // Return all resources immediately. 2745 // Return all resources immediately.
2758 TransferableResourceArray resources_to_return = 2746 TransferableResourceArray resources_to_return =
2759 output_surface()->resources_held_by_parent(); 2747 output_surface()->resources_held_by_parent();
2760 2748
2761 CompositorFrameAck ack; 2749 CompositorFrameAck ack;
2762 for (size_t i = 0; i < resources_to_return.size(); ++i) 2750 for (size_t i = 0; i < resources_to_return.size(); ++i)
2763 output_surface()->ReturnResource(resources_to_return[i].id, &ack); 2751 output_surface()->ReturnResource(resources_to_return[i].id, &ack);
2764 host_impl->ReclaimResources(&ack); 2752 host_impl->ReclaimResources(&ack);
2765 } 2753 }
2766 2754
2767 virtual void AfterTest() override { 2755 void AfterTest() override {
2768 EXPECT_TRUE(did_initialize_gl_); 2756 EXPECT_TRUE(did_initialize_gl_);
2769 EXPECT_TRUE(did_release_gl_); 2757 EXPECT_TRUE(did_release_gl_);
2770 } 2758 }
2771 2759
2772 private: 2760 private:
2773 FakeContentLayerClient client_; 2761 FakeContentLayerClient client_;
2774 scoped_refptr<FakePictureLayer> layer_; 2762 scoped_refptr<FakePictureLayer> layer_;
2775 bool did_initialize_gl_; 2763 bool did_initialize_gl_;
2776 bool did_release_gl_; 2764 bool did_release_gl_;
2777 int last_source_frame_number_drawn_; 2765 int last_source_frame_number_drawn_;
2778 }; 2766 };
2779 2767
2780 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); 2768 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize);
2781 2769
2782 class LayerTreeHostTestDeferredInitializeWithGpuRasterization 2770 class LayerTreeHostTestDeferredInitializeWithGpuRasterization
2783 : public LayerTreeHostTestDeferredInitialize { 2771 : public LayerTreeHostTestDeferredInitialize {
2784 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2772 void InitializeSettings(LayerTreeSettings* settings) override {
2785 // PictureLayer can only be used with impl side painting enabled. 2773 // PictureLayer can only be used with impl side painting enabled.
2786 settings->impl_side_painting = true; 2774 settings->impl_side_painting = true;
2787 settings->gpu_rasterization_enabled = true; 2775 settings->gpu_rasterization_enabled = true;
2788 settings->gpu_rasterization_forced = true; 2776 settings->gpu_rasterization_forced = true;
2789 } 2777 }
2790 }; 2778 };
2791 2779
2792 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitializeWithGpuRasterization); 2780 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitializeWithGpuRasterization);
2793 2781
2794 // Test for UI Resource management. 2782 // Test for UI Resource management.
2795 class LayerTreeHostTestUIResource : public LayerTreeHostTest { 2783 class LayerTreeHostTestUIResource : public LayerTreeHostTest {
2796 public: 2784 public:
2797 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} 2785 LayerTreeHostTestUIResource() : num_ui_resources_(0) {}
2798 2786
2799 virtual void InitializeSettings(LayerTreeSettings* settings) override { 2787 void InitializeSettings(LayerTreeSettings* settings) override {
2800 settings->texture_id_allocation_chunk_size = 1; 2788 settings->texture_id_allocation_chunk_size = 1;
2801 } 2789 }
2802 2790
2803 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2791 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2804 2792
2805 virtual void DidCommit() override { 2793 void DidCommit() override {
2806 int frame = layer_tree_host()->source_frame_number(); 2794 int frame = layer_tree_host()->source_frame_number();
2807 switch (frame) { 2795 switch (frame) {
2808 case 1: 2796 case 1:
2809 CreateResource(); 2797 CreateResource();
2810 CreateResource(); 2798 CreateResource();
2811 PostSetNeedsCommitToMainThread(); 2799 PostSetNeedsCommitToMainThread();
2812 break; 2800 break;
2813 case 2: 2801 case 2:
2814 // Usually ScopedUIResource are deleted from the manager in their 2802 // Usually ScopedUIResource are deleted from the manager in their
2815 // destructor. Here we just want to test that a direct call to 2803 // destructor. Here we just want to test that a direct call to
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2856 ASSERT_EQ(1u, context->NumTextures()); 2844 ASSERT_EQ(1u, context->NumTextures());
2857 break; 2845 break;
2858 case 4: 2846 case 4:
2859 // Creation after deletion: two more creates should total up to 2847 // Creation after deletion: two more creates should total up to
2860 // three textures. 2848 // three textures.
2861 ASSERT_EQ(3u, context->NumTextures()); 2849 ASSERT_EQ(3u, context->NumTextures());
2862 break; 2850 break;
2863 } 2851 }
2864 } 2852 }
2865 2853
2866 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 2854 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
2867 if (!layer_tree_host()->settings().impl_side_painting) 2855 if (!layer_tree_host()->settings().impl_side_painting)
2868 PerformTest(impl); 2856 PerformTest(impl);
2869 } 2857 }
2870 2858
2871 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 2859 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
2872 if (layer_tree_host()->settings().impl_side_painting) 2860 if (layer_tree_host()->settings().impl_side_painting)
2873 PerformTest(impl); 2861 PerformTest(impl);
2874 } 2862 }
2875 2863
2876 virtual void AfterTest() override {} 2864 void AfterTest() override {}
2877 2865
2878 private: 2866 private:
2879 // Must clear all resources before exiting. 2867 // Must clear all resources before exiting.
2880 void ClearResources() { 2868 void ClearResources() {
2881 for (int i = 0; i < num_ui_resources_; i++) 2869 for (int i = 0; i < num_ui_resources_; i++)
2882 ui_resources_[i] = nullptr; 2870 ui_resources_[i] = nullptr;
2883 } 2871 }
2884 2872
2885 void CreateResource() { 2873 void CreateResource() {
2886 ui_resources_[num_ui_resources_++] = 2874 ui_resources_[num_ui_resources_++] =
2887 FakeScopedUIResource::Create(layer_tree_host()); 2875 FakeScopedUIResource::Create(layer_tree_host());
2888 } 2876 }
2889 2877
2890 scoped_ptr<FakeScopedUIResource> ui_resources_[5]; 2878 scoped_ptr<FakeScopedUIResource> ui_resources_[5];
2891 int num_ui_resources_; 2879 int num_ui_resources_;
2892 }; 2880 };
2893 2881
2894 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource); 2882 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource);
2895 2883
2896 class PushPropertiesCountingLayerImpl : public LayerImpl { 2884 class PushPropertiesCountingLayerImpl : public LayerImpl {
2897 public: 2885 public:
2898 static scoped_ptr<PushPropertiesCountingLayerImpl> Create( 2886 static scoped_ptr<PushPropertiesCountingLayerImpl> Create(
2899 LayerTreeImpl* tree_impl, int id) { 2887 LayerTreeImpl* tree_impl, int id) {
2900 return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl, id)); 2888 return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl, id));
2901 } 2889 }
2902 2890
2903 virtual ~PushPropertiesCountingLayerImpl() {} 2891 ~PushPropertiesCountingLayerImpl() override {}
2904 2892
2905 virtual void PushPropertiesTo(LayerImpl* layer) override { 2893 void PushPropertiesTo(LayerImpl* layer) override {
2906 LayerImpl::PushPropertiesTo(layer); 2894 LayerImpl::PushPropertiesTo(layer);
2907 push_properties_count_++; 2895 push_properties_count_++;
2908 // Push state to the active tree because we can only access it from there. 2896 // Push state to the active tree because we can only access it from there.
2909 static_cast<PushPropertiesCountingLayerImpl*>( 2897 static_cast<PushPropertiesCountingLayerImpl*>(
2910 layer)->push_properties_count_ = push_properties_count_; 2898 layer)->push_properties_count_ = push_properties_count_;
2911 } 2899 }
2912 2900
2913 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 2901 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override {
2914 override {
2915 return PushPropertiesCountingLayerImpl::Create(tree_impl, id()); 2902 return PushPropertiesCountingLayerImpl::Create(tree_impl, id());
2916 } 2903 }
2917 2904
2918 size_t push_properties_count() const { return push_properties_count_; } 2905 size_t push_properties_count() const { return push_properties_count_; }
2919 void reset_push_properties_count() { push_properties_count_ = 0; } 2906 void reset_push_properties_count() { push_properties_count_ = 0; }
2920 2907
2921 private: 2908 private:
2922 size_t push_properties_count_; 2909 size_t push_properties_count_;
2923 2910
2924 PushPropertiesCountingLayerImpl(LayerTreeImpl* tree_impl, int id) 2911 PushPropertiesCountingLayerImpl(LayerTreeImpl* tree_impl, int id)
2925 : LayerImpl(tree_impl, id), 2912 : LayerImpl(tree_impl, id),
2926 push_properties_count_(0) { 2913 push_properties_count_(0) {
2927 SetBounds(gfx::Size(1, 1)); 2914 SetBounds(gfx::Size(1, 1));
2928 } 2915 }
2929 }; 2916 };
2930 2917
2931 class PushPropertiesCountingLayer : public Layer { 2918 class PushPropertiesCountingLayer : public Layer {
2932 public: 2919 public:
2933 static scoped_refptr<PushPropertiesCountingLayer> Create() { 2920 static scoped_refptr<PushPropertiesCountingLayer> Create() {
2934 return new PushPropertiesCountingLayer(); 2921 return new PushPropertiesCountingLayer();
2935 } 2922 }
2936 2923
2937 virtual void PushPropertiesTo(LayerImpl* layer) override { 2924 void PushPropertiesTo(LayerImpl* layer) override {
2938 Layer::PushPropertiesTo(layer); 2925 Layer::PushPropertiesTo(layer);
2939 push_properties_count_++; 2926 push_properties_count_++;
2940 if (persist_needs_push_properties_) 2927 if (persist_needs_push_properties_)
2941 needs_push_properties_ = true; 2928 needs_push_properties_ = true;
2942 } 2929 }
2943 2930
2944 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 2931 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override {
2945 override {
2946 return PushPropertiesCountingLayerImpl::Create(tree_impl, id()); 2932 return PushPropertiesCountingLayerImpl::Create(tree_impl, id());
2947 } 2933 }
2948 2934
2949 void SetDrawsContent(bool draws_content) { SetIsDrawable(draws_content); } 2935 void SetDrawsContent(bool draws_content) { SetIsDrawable(draws_content); }
2950 2936
2951 size_t push_properties_count() const { return push_properties_count_; } 2937 size_t push_properties_count() const { return push_properties_count_; }
2952 void reset_push_properties_count() { push_properties_count_ = 0; } 2938 void reset_push_properties_count() { push_properties_count_ = 0; }
2953 2939
2954 void set_persist_needs_push_properties(bool persist) { 2940 void set_persist_needs_push_properties(bool persist) {
2955 persist_needs_push_properties_ = persist; 2941 persist_needs_push_properties_ = persist;
2956 } 2942 }
2957 2943
2958 private: 2944 private:
2959 PushPropertiesCountingLayer() 2945 PushPropertiesCountingLayer()
2960 : push_properties_count_(0), persist_needs_push_properties_(false) { 2946 : push_properties_count_(0), persist_needs_push_properties_(false) {
2961 SetBounds(gfx::Size(1, 1)); 2947 SetBounds(gfx::Size(1, 1));
2962 } 2948 }
2963 virtual ~PushPropertiesCountingLayer() {} 2949 ~PushPropertiesCountingLayer() override {}
2964 2950
2965 size_t push_properties_count_; 2951 size_t push_properties_count_;
2966 bool persist_needs_push_properties_; 2952 bool persist_needs_push_properties_;
2967 }; 2953 };
2968 2954
2969 class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest { 2955 class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest {
2970 protected: 2956 protected:
2971 virtual void BeginTest() override { 2957 void BeginTest() override {
2972 num_commits_ = 0; 2958 num_commits_ = 0;
2973 expected_push_properties_root_ = 0; 2959 expected_push_properties_root_ = 0;
2974 expected_push_properties_child_ = 0; 2960 expected_push_properties_child_ = 0;
2975 expected_push_properties_grandchild_ = 0; 2961 expected_push_properties_grandchild_ = 0;
2976 expected_push_properties_child2_ = 0; 2962 expected_push_properties_child2_ = 0;
2977 expected_push_properties_other_root_ = 0; 2963 expected_push_properties_other_root_ = 0;
2978 expected_push_properties_leaf_layer_ = 0; 2964 expected_push_properties_leaf_layer_ = 0;
2979 PostSetNeedsCommitToMainThread(); 2965 PostSetNeedsCommitToMainThread();
2980 } 2966 }
2981 2967
2982 virtual void SetupTree() override { 2968 void SetupTree() override {
2983 root_ = PushPropertiesCountingLayer::Create(); 2969 root_ = PushPropertiesCountingLayer::Create();
2984 child_ = PushPropertiesCountingLayer::Create(); 2970 child_ = PushPropertiesCountingLayer::Create();
2985 child2_ = PushPropertiesCountingLayer::Create(); 2971 child2_ = PushPropertiesCountingLayer::Create();
2986 grandchild_ = PushPropertiesCountingLayer::Create(); 2972 grandchild_ = PushPropertiesCountingLayer::Create();
2987 leaf_always_pushing_layer_ = PushPropertiesCountingLayer::Create(); 2973 leaf_always_pushing_layer_ = PushPropertiesCountingLayer::Create();
2988 leaf_always_pushing_layer_->set_persist_needs_push_properties(true); 2974 leaf_always_pushing_layer_->set_persist_needs_push_properties(true);
2989 2975
2990 root_->AddChild(child_); 2976 root_->AddChild(child_);
2991 root_->AddChild(child2_); 2977 root_->AddChild(child2_);
2992 child_->AddChild(grandchild_); 2978 child_->AddChild(grandchild_);
2993 child2_->AddChild(leaf_always_pushing_layer_); 2979 child2_->AddChild(leaf_always_pushing_layer_);
2994 2980
2995 other_root_ = PushPropertiesCountingLayer::Create(); 2981 other_root_ = PushPropertiesCountingLayer::Create();
2996 2982
2997 // Don't set the root layer here. 2983 // Don't set the root layer here.
2998 LayerTreeHostTest::SetupTree(); 2984 LayerTreeHostTest::SetupTree();
2999 } 2985 }
3000 2986
3001 virtual void DidCommitAndDrawFrame() override { 2987 void DidCommitAndDrawFrame() override {
3002 ++num_commits_; 2988 ++num_commits_;
3003 2989
3004 EXPECT_EQ(expected_push_properties_root_, root_->push_properties_count()); 2990 EXPECT_EQ(expected_push_properties_root_, root_->push_properties_count());
3005 EXPECT_EQ(expected_push_properties_child_, child_->push_properties_count()); 2991 EXPECT_EQ(expected_push_properties_child_, child_->push_properties_count());
3006 EXPECT_EQ(expected_push_properties_grandchild_, 2992 EXPECT_EQ(expected_push_properties_grandchild_,
3007 grandchild_->push_properties_count()); 2993 grandchild_->push_properties_count());
3008 EXPECT_EQ(expected_push_properties_child2_, 2994 EXPECT_EQ(expected_push_properties_child2_,
3009 child2_->push_properties_count()); 2995 child2_->push_properties_count());
3010 EXPECT_EQ(expected_push_properties_other_root_, 2996 EXPECT_EQ(expected_push_properties_other_root_,
3011 other_root_->push_properties_count()); 2997 other_root_->push_properties_count());
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3131 case 17: 3117 case 17:
3132 EndTest(); 3118 EndTest();
3133 break; 3119 break;
3134 } 3120 }
3135 3121
3136 // The leaf layer always pushes. 3122 // The leaf layer always pushes.
3137 if (leaf_always_pushing_layer_->layer_tree_host()) 3123 if (leaf_always_pushing_layer_->layer_tree_host())
3138 ++expected_push_properties_leaf_layer_; 3124 ++expected_push_properties_leaf_layer_;
3139 } 3125 }
3140 3126
3141 virtual void AfterTest() override {} 3127 void AfterTest() override {}
3142 3128
3143 int num_commits_; 3129 int num_commits_;
3144 FakeContentLayerClient client_; 3130 FakeContentLayerClient client_;
3145 scoped_refptr<PushPropertiesCountingLayer> root_; 3131 scoped_refptr<PushPropertiesCountingLayer> root_;
3146 scoped_refptr<PushPropertiesCountingLayer> child_; 3132 scoped_refptr<PushPropertiesCountingLayer> child_;
3147 scoped_refptr<PushPropertiesCountingLayer> child2_; 3133 scoped_refptr<PushPropertiesCountingLayer> child2_;
3148 scoped_refptr<PushPropertiesCountingLayer> grandchild_; 3134 scoped_refptr<PushPropertiesCountingLayer> grandchild_;
3149 scoped_refptr<PushPropertiesCountingLayer> other_root_; 3135 scoped_refptr<PushPropertiesCountingLayer> other_root_;
3150 scoped_refptr<PushPropertiesCountingLayer> leaf_always_pushing_layer_; 3136 scoped_refptr<PushPropertiesCountingLayer> leaf_always_pushing_layer_;
3151 size_t expected_push_properties_root_; 3137 size_t expected_push_properties_root_;
3152 size_t expected_push_properties_child_; 3138 size_t expected_push_properties_child_;
3153 size_t expected_push_properties_child2_; 3139 size_t expected_push_properties_child2_;
3154 size_t expected_push_properties_grandchild_; 3140 size_t expected_push_properties_grandchild_;
3155 size_t expected_push_properties_other_root_; 3141 size_t expected_push_properties_other_root_;
3156 size_t expected_push_properties_leaf_layer_; 3142 size_t expected_push_properties_leaf_layer_;
3157 }; 3143 };
3158 3144
3159 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties); 3145 MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties);
3160 3146
3161 class LayerTreeHostTestImplLayersPushProperties 3147 class LayerTreeHostTestImplLayersPushProperties
3162 : public LayerTreeHostTestLayersPushProperties { 3148 : public LayerTreeHostTestLayersPushProperties {
3163 protected: 3149 protected:
3164 virtual void BeginTest() override { 3150 void BeginTest() override {
3165 expected_push_properties_root_impl_ = 0; 3151 expected_push_properties_root_impl_ = 0;
3166 expected_push_properties_child_impl_ = 0; 3152 expected_push_properties_child_impl_ = 0;
3167 expected_push_properties_grandchild_impl_ = 0; 3153 expected_push_properties_grandchild_impl_ = 0;
3168 expected_push_properties_child2_impl_ = 0; 3154 expected_push_properties_child2_impl_ = 0;
3169 expected_push_properties_grandchild2_impl_ = 0; 3155 expected_push_properties_grandchild2_impl_ = 0;
3170 LayerTreeHostTestLayersPushProperties::BeginTest(); 3156 LayerTreeHostTestLayersPushProperties::BeginTest();
3171 } 3157 }
3172 3158
3173 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 3159 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
3174 // These commits are in response to the changes made in 3160 // These commits are in response to the changes made in
3175 // LayerTreeHostTestLayersPushProperties::DidCommitAndDrawFrame() 3161 // LayerTreeHostTestLayersPushProperties::DidCommitAndDrawFrame()
3176 switch (num_commits_) { 3162 switch (num_commits_) {
3177 case 0: 3163 case 0:
3178 // Tree hasn't been setup yet don't bother to check anything. 3164 // Tree hasn't been setup yet don't bother to check anything.
3179 return; 3165 return;
3180 case 1: 3166 case 1:
3181 // Root gets set up, Everyone is initialized. 3167 // Root gets set up, Everyone is initialized.
3182 ++expected_push_properties_root_impl_; 3168 ++expected_push_properties_root_impl_;
3183 ++expected_push_properties_child_impl_; 3169 ++expected_push_properties_child_impl_;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 size_t expected_push_properties_grandchild2_impl_; 3340 size_t expected_push_properties_grandchild2_impl_;
3355 }; 3341 };
3356 3342
3357 TEST_F(LayerTreeHostTestImplLayersPushProperties, DelegatingRenderer) { 3343 TEST_F(LayerTreeHostTestImplLayersPushProperties, DelegatingRenderer) {
3358 RunTestWithImplSidePainting(); 3344 RunTestWithImplSidePainting();
3359 } 3345 }
3360 3346
3361 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed 3347 class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
3362 : public LayerTreeHostTest { 3348 : public LayerTreeHostTest {
3363 protected: 3349 protected:
3364 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 3350 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
3365 3351
3366 virtual void SetupTree() override { 3352 void SetupTree() override {
3367 root_ = Layer::Create(); 3353 root_ = Layer::Create();
3368 root_->SetBounds(gfx::Size(1, 1)); 3354 root_->SetBounds(gfx::Size(1, 1));
3369 3355
3370 bool paint_scrollbar = true; 3356 bool paint_scrollbar = true;
3371 bool has_thumb = false; 3357 bool has_thumb = false;
3372 scrollbar_layer_ = FakePaintedScrollbarLayer::Create( 3358 scrollbar_layer_ = FakePaintedScrollbarLayer::Create(
3373 paint_scrollbar, has_thumb, root_->id()); 3359 paint_scrollbar, has_thumb, root_->id());
3374 3360
3375 root_->AddChild(scrollbar_layer_); 3361 root_->AddChild(scrollbar_layer_);
3376 3362
3377 layer_tree_host()->SetRootLayer(root_); 3363 layer_tree_host()->SetRootLayer(root_);
3378 LayerTreeHostTest::SetupTree(); 3364 LayerTreeHostTest::SetupTree();
3379 } 3365 }
3380 3366
3381 virtual void DidCommitAndDrawFrame() override { 3367 void DidCommitAndDrawFrame() override {
3382 switch (layer_tree_host()->source_frame_number()) { 3368 switch (layer_tree_host()->source_frame_number()) {
3383 case 0: 3369 case 0:
3384 break; 3370 break;
3385 case 1: { 3371 case 1: {
3386 // During update, the ignore_set_needs_commit_ bit is set to true to 3372 // During update, the ignore_set_needs_commit_ bit is set to true to
3387 // avoid causing a second commit to be scheduled. If a property change 3373 // avoid causing a second commit to be scheduled. If a property change
3388 // is made during this, however, it needs to be pushed in the upcoming 3374 // is made during this, however, it needs to be pushed in the upcoming
3389 // commit. 3375 // commit.
3390 scoped_ptr<base::AutoReset<bool>> ignore = 3376 scoped_ptr<base::AutoReset<bool>> ignore =
3391 scrollbar_layer_->IgnoreSetNeedsCommit(); 3377 scrollbar_layer_->IgnoreSetNeedsCommit();
3392 3378
3393 scrollbar_layer_->SetBounds(gfx::Size(30, 30)); 3379 scrollbar_layer_->SetBounds(gfx::Size(30, 30));
3394 3380
3395 EXPECT_TRUE(scrollbar_layer_->needs_push_properties()); 3381 EXPECT_TRUE(scrollbar_layer_->needs_push_properties());
3396 EXPECT_TRUE(root_->descendant_needs_push_properties()); 3382 EXPECT_TRUE(root_->descendant_needs_push_properties());
3397 layer_tree_host()->SetNeedsCommit(); 3383 layer_tree_host()->SetNeedsCommit();
3398 3384
3399 scrollbar_layer_->reset_push_properties_count(); 3385 scrollbar_layer_->reset_push_properties_count();
3400 EXPECT_EQ(0u, scrollbar_layer_->push_properties_count()); 3386 EXPECT_EQ(0u, scrollbar_layer_->push_properties_count());
3401 break; 3387 break;
3402 } 3388 }
3403 case 2: 3389 case 2:
3404 EXPECT_EQ(1u, scrollbar_layer_->push_properties_count()); 3390 EXPECT_EQ(1u, scrollbar_layer_->push_properties_count());
3405 EndTest(); 3391 EndTest();
3406 break; 3392 break;
3407 } 3393 }
3408 } 3394 }
3409 3395
3410 virtual void AfterTest() override {} 3396 void AfterTest() override {}
3411 3397
3412 scoped_refptr<Layer> root_; 3398 scoped_refptr<Layer> root_;
3413 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; 3399 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
3414 }; 3400 };
3415 3401
3416 MULTI_THREAD_TEST_F(LayerTreeHostTestPropertyChangesDuringUpdateArePushed); 3402 MULTI_THREAD_TEST_F(LayerTreeHostTestPropertyChangesDuringUpdateArePushed);
3417 3403
3418 class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest { 3404 class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest {
3419 protected: 3405 protected:
3420 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 3406 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
3421 3407
3422 virtual void SetupTree() override { 3408 void SetupTree() override {
3423 root_ = PushPropertiesCountingLayer::Create(); 3409 root_ = PushPropertiesCountingLayer::Create();
3424 child_ = PushPropertiesCountingLayer::Create(); 3410 child_ = PushPropertiesCountingLayer::Create();
3425 root_->AddChild(child_); 3411 root_->AddChild(child_);
3426 3412
3427 layer_tree_host()->SetRootLayer(root_); 3413 layer_tree_host()->SetRootLayer(root_);
3428 LayerTreeHostTest::SetupTree(); 3414 LayerTreeHostTest::SetupTree();
3429 } 3415 }
3430 3416
3431 virtual void DidCommitAndDrawFrame() override { 3417 void DidCommitAndDrawFrame() override {
3432 switch (layer_tree_host()->source_frame_number()) { 3418 switch (layer_tree_host()->source_frame_number()) {
3433 case 0: 3419 case 0:
3434 break; 3420 break;
3435 case 1: { 3421 case 1: {
3436 // During update, the ignore_set_needs_commit_ bit is set to true to 3422 // During update, the ignore_set_needs_commit_ bit is set to true to
3437 // avoid causing a second commit to be scheduled. If a property change 3423 // avoid causing a second commit to be scheduled. If a property change
3438 // is made during this, however, it needs to be pushed in the upcoming 3424 // is made during this, however, it needs to be pushed in the upcoming
3439 // commit. 3425 // commit.
3440 EXPECT_FALSE(root_->needs_push_properties()); 3426 EXPECT_FALSE(root_->needs_push_properties());
3441 EXPECT_FALSE(child_->needs_push_properties()); 3427 EXPECT_FALSE(child_->needs_push_properties());
(...skipping 11 matching lines...) Expand all
3453 case 2: 3439 case 2:
3454 EXPECT_EQ(1u, root_->push_properties_count()); 3440 EXPECT_EQ(1u, root_->push_properties_count());
3455 EXPECT_EQ(1u, child_->push_properties_count()); 3441 EXPECT_EQ(1u, child_->push_properties_count());
3456 EXPECT_FALSE(root_->needs_push_properties()); 3442 EXPECT_FALSE(root_->needs_push_properties());
3457 EXPECT_FALSE(child_->needs_push_properties()); 3443 EXPECT_FALSE(child_->needs_push_properties());
3458 EndTest(); 3444 EndTest();
3459 break; 3445 break;
3460 } 3446 }
3461 } 3447 }
3462 3448
3463 virtual void AfterTest() override {} 3449 void AfterTest() override {}
3464 3450
3465 scoped_refptr<PushPropertiesCountingLayer> root_; 3451 scoped_refptr<PushPropertiesCountingLayer> root_;
3466 scoped_refptr<PushPropertiesCountingLayer> child_; 3452 scoped_refptr<PushPropertiesCountingLayer> child_;
3467 }; 3453 };
3468 3454
3469 MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit); 3455 MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit);
3470 3456
3471 class LayerTreeHostTestCasePushPropertiesThreeGrandChildren 3457 class LayerTreeHostTestCasePushPropertiesThreeGrandChildren
3472 : public LayerTreeHostTest { 3458 : public LayerTreeHostTest {
3473 protected: 3459 protected:
3474 virtual void BeginTest() override { 3460 void BeginTest() override {
3475 expected_push_properties_root_ = 0; 3461 expected_push_properties_root_ = 0;
3476 expected_push_properties_child_ = 0; 3462 expected_push_properties_child_ = 0;
3477 expected_push_properties_grandchild1_ = 0; 3463 expected_push_properties_grandchild1_ = 0;
3478 expected_push_properties_grandchild2_ = 0; 3464 expected_push_properties_grandchild2_ = 0;
3479 expected_push_properties_grandchild3_ = 0; 3465 expected_push_properties_grandchild3_ = 0;
3480 PostSetNeedsCommitToMainThread(); 3466 PostSetNeedsCommitToMainThread();
3481 } 3467 }
3482 3468
3483 virtual void SetupTree() override { 3469 void SetupTree() override {
3484 root_ = PushPropertiesCountingLayer::Create(); 3470 root_ = PushPropertiesCountingLayer::Create();
3485 child_ = PushPropertiesCountingLayer::Create(); 3471 child_ = PushPropertiesCountingLayer::Create();
3486 grandchild1_ = PushPropertiesCountingLayer::Create(); 3472 grandchild1_ = PushPropertiesCountingLayer::Create();
3487 grandchild2_ = PushPropertiesCountingLayer::Create(); 3473 grandchild2_ = PushPropertiesCountingLayer::Create();
3488 grandchild3_ = PushPropertiesCountingLayer::Create(); 3474 grandchild3_ = PushPropertiesCountingLayer::Create();
3489 3475
3490 root_->AddChild(child_); 3476 root_->AddChild(child_);
3491 child_->AddChild(grandchild1_); 3477 child_->AddChild(grandchild1_);
3492 child_->AddChild(grandchild2_); 3478 child_->AddChild(grandchild2_);
3493 child_->AddChild(grandchild3_); 3479 child_->AddChild(grandchild3_);
3494 3480
3495 // Don't set the root layer here. 3481 // Don't set the root layer here.
3496 LayerTreeHostTest::SetupTree(); 3482 LayerTreeHostTest::SetupTree();
3497 } 3483 }
3498 3484
3499 virtual void AfterTest() override {} 3485 void AfterTest() override {}
3500 3486
3501 FakeContentLayerClient client_; 3487 FakeContentLayerClient client_;
3502 scoped_refptr<PushPropertiesCountingLayer> root_; 3488 scoped_refptr<PushPropertiesCountingLayer> root_;
3503 scoped_refptr<PushPropertiesCountingLayer> child_; 3489 scoped_refptr<PushPropertiesCountingLayer> child_;
3504 scoped_refptr<PushPropertiesCountingLayer> grandchild1_; 3490 scoped_refptr<PushPropertiesCountingLayer> grandchild1_;
3505 scoped_refptr<PushPropertiesCountingLayer> grandchild2_; 3491 scoped_refptr<PushPropertiesCountingLayer> grandchild2_;
3506 scoped_refptr<PushPropertiesCountingLayer> grandchild3_; 3492 scoped_refptr<PushPropertiesCountingLayer> grandchild3_;
3507 size_t expected_push_properties_root_; 3493 size_t expected_push_properties_root_;
3508 size_t expected_push_properties_child_; 3494 size_t expected_push_properties_child_;
3509 size_t expected_push_properties_grandchild1_; 3495 size_t expected_push_properties_grandchild1_;
3510 size_t expected_push_properties_grandchild2_; 3496 size_t expected_push_properties_grandchild2_;
3511 size_t expected_push_properties_grandchild3_; 3497 size_t expected_push_properties_grandchild3_;
3512 }; 3498 };
3513 3499
3514 class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush 3500 class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush
3515 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { 3501 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
3516 protected: 3502 protected:
3517 virtual void DidCommitAndDrawFrame() override { 3503 void DidCommitAndDrawFrame() override {
3518 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; 3504 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1;
3519 switch (last_source_frame_number) { 3505 switch (last_source_frame_number) {
3520 case 0: 3506 case 0:
3521 EXPECT_FALSE(root_->needs_push_properties()); 3507 EXPECT_FALSE(root_->needs_push_properties());
3522 EXPECT_FALSE(root_->descendant_needs_push_properties()); 3508 EXPECT_FALSE(root_->descendant_needs_push_properties());
3523 EXPECT_FALSE(child_->needs_push_properties()); 3509 EXPECT_FALSE(child_->needs_push_properties());
3524 EXPECT_FALSE(child_->descendant_needs_push_properties()); 3510 EXPECT_FALSE(child_->descendant_needs_push_properties());
3525 EXPECT_FALSE(grandchild1_->needs_push_properties()); 3511 EXPECT_FALSE(grandchild1_->needs_push_properties());
3526 EXPECT_FALSE(grandchild1_->descendant_needs_push_properties()); 3512 EXPECT_FALSE(grandchild1_->descendant_needs_push_properties());
3527 EXPECT_FALSE(grandchild2_->needs_push_properties()); 3513 EXPECT_FALSE(grandchild2_->needs_push_properties());
(...skipping 19 matching lines...) Expand all
3547 break; 3533 break;
3548 } 3534 }
3549 } 3535 }
3550 }; 3536 };
3551 3537
3552 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush); 3538 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush);
3553 3539
3554 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion 3540 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion
3555 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { 3541 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
3556 protected: 3542 protected:
3557 virtual void DidCommitAndDrawFrame() override { 3543 void DidCommitAndDrawFrame() override {
3558 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; 3544 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1;
3559 switch (last_source_frame_number) { 3545 switch (last_source_frame_number) {
3560 case 0: 3546 case 0:
3561 layer_tree_host()->SetRootLayer(root_); 3547 layer_tree_host()->SetRootLayer(root_);
3562 break; 3548 break;
3563 case 1: 3549 case 1:
3564 EXPECT_FALSE(root_->needs_push_properties()); 3550 EXPECT_FALSE(root_->needs_push_properties());
3565 EXPECT_FALSE(root_->descendant_needs_push_properties()); 3551 EXPECT_FALSE(root_->descendant_needs_push_properties());
3566 EXPECT_FALSE(child_->needs_push_properties()); 3552 EXPECT_FALSE(child_->needs_push_properties());
3567 EXPECT_FALSE(child_->descendant_needs_push_properties()); 3553 EXPECT_FALSE(child_->descendant_needs_push_properties());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3630 break; 3616 break;
3631 } 3617 }
3632 } 3618 }
3633 }; 3619 };
3634 3620
3635 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion); 3621 MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion);
3636 3622
3637 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence 3623 class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence
3638 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { 3624 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
3639 protected: 3625 protected:
3640 virtual void DidCommitAndDrawFrame() override { 3626 void DidCommitAndDrawFrame() override {
3641 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; 3627 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1;
3642 switch (last_source_frame_number) { 3628 switch (last_source_frame_number) {
3643 case 0: 3629 case 0:
3644 layer_tree_host()->SetRootLayer(root_); 3630 layer_tree_host()->SetRootLayer(root_);
3645 grandchild1_->set_persist_needs_push_properties(true); 3631 grandchild1_->set_persist_needs_push_properties(true);
3646 grandchild2_->set_persist_needs_push_properties(true); 3632 grandchild2_->set_persist_needs_push_properties(true);
3647 break; 3633 break;
3648 case 1: 3634 case 1:
3649 EXPECT_FALSE(root_->needs_push_properties()); 3635 EXPECT_FALSE(root_->needs_push_properties());
3650 EXPECT_TRUE(root_->descendant_needs_push_properties()); 3636 EXPECT_TRUE(root_->descendant_needs_push_properties());
(...skipping 27 matching lines...) Expand all
3678 } 3664 }
3679 } 3665 }
3680 }; 3666 };
3681 3667
3682 MULTI_THREAD_TEST_F( 3668 MULTI_THREAD_TEST_F(
3683 LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence); 3669 LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence);
3684 3670
3685 class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree 3671 class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree
3686 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { 3672 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
3687 protected: 3673 protected:
3688 virtual void DidCommitAndDrawFrame() override { 3674 void DidCommitAndDrawFrame() override {
3689 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; 3675 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1;
3690 switch (last_source_frame_number) { 3676 switch (last_source_frame_number) {
3691 case 0: 3677 case 0:
3692 layer_tree_host()->SetRootLayer(root_); 3678 layer_tree_host()->SetRootLayer(root_);
3693 break; 3679 break;
3694 case 1: 3680 case 1:
3695 EXPECT_FALSE(root_->needs_push_properties()); 3681 EXPECT_FALSE(root_->needs_push_properties());
3696 EXPECT_FALSE(root_->descendant_needs_push_properties()); 3682 EXPECT_FALSE(root_->descendant_needs_push_properties());
3697 EXPECT_FALSE(child_->needs_push_properties()); 3683 EXPECT_FALSE(child_->needs_push_properties());
3698 EXPECT_FALSE(child_->descendant_needs_push_properties()); 3684 EXPECT_FALSE(child_->descendant_needs_push_properties());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3746 } 3732 }
3747 } 3733 }
3748 }; 3734 };
3749 3735
3750 MULTI_THREAD_TEST_F( 3736 MULTI_THREAD_TEST_F(
3751 LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree); 3737 LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree);
3752 3738
3753 class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild 3739 class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild
3754 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { 3740 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
3755 protected: 3741 protected:
3756 virtual void DidCommitAndDrawFrame() override { 3742 void DidCommitAndDrawFrame() override {
3757 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; 3743 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1;
3758 switch (last_source_frame_number) { 3744 switch (last_source_frame_number) {
3759 case 0: 3745 case 0:
3760 layer_tree_host()->SetRootLayer(root_); 3746 layer_tree_host()->SetRootLayer(root_);
3761 break; 3747 break;
3762 case 1: 3748 case 1:
3763 EXPECT_FALSE(root_->needs_push_properties()); 3749 EXPECT_FALSE(root_->needs_push_properties());
3764 EXPECT_FALSE(root_->descendant_needs_push_properties()); 3750 EXPECT_FALSE(root_->descendant_needs_push_properties());
3765 EXPECT_FALSE(child_->needs_push_properties()); 3751 EXPECT_FALSE(child_->needs_push_properties());
3766 EXPECT_FALSE(child_->descendant_needs_push_properties()); 3752 EXPECT_FALSE(child_->descendant_needs_push_properties());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3810 } 3796 }
3811 } 3797 }
3812 }; 3798 };
3813 3799
3814 MULTI_THREAD_TEST_F( 3800 MULTI_THREAD_TEST_F(
3815 LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild); 3801 LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild);
3816 3802
3817 class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent 3803 class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
3818 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { 3804 : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
3819 protected: 3805 protected:
3820 virtual void DidCommitAndDrawFrame() override { 3806 void DidCommitAndDrawFrame() override {
3821 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1; 3807 int last_source_frame_number = layer_tree_host()->source_frame_number() - 1;
3822 switch (last_source_frame_number) { 3808 switch (last_source_frame_number) {
3823 case 0: 3809 case 0:
3824 layer_tree_host()->SetRootLayer(root_); 3810 layer_tree_host()->SetRootLayer(root_);
3825 break; 3811 break;
3826 case 1: 3812 case 1:
3827 EXPECT_FALSE(root_->needs_push_properties()); 3813 EXPECT_FALSE(root_->needs_push_properties());
3828 EXPECT_FALSE(root_->descendant_needs_push_properties()); 3814 EXPECT_FALSE(root_->descendant_needs_push_properties());
3829 EXPECT_FALSE(child_->needs_push_properties()); 3815 EXPECT_FALSE(child_->needs_push_properties());
3830 EXPECT_FALSE(child_->descendant_needs_push_properties()); 3816 EXPECT_FALSE(child_->descendant_needs_push_properties());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 3863
3878 MULTI_THREAD_TEST_F( 3864 MULTI_THREAD_TEST_F(
3879 LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent); 3865 LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent);
3880 3866
3881 // This test verifies that the tree activation callback is invoked correctly. 3867 // This test verifies that the tree activation callback is invoked correctly.
3882 class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest { 3868 class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest {
3883 public: 3869 public:
3884 LayerTreeHostTestTreeActivationCallback() 3870 LayerTreeHostTestTreeActivationCallback()
3885 : num_commits_(0), callback_count_(0) {} 3871 : num_commits_(0), callback_count_(0) {}
3886 3872
3887 virtual void BeginTest() override { 3873 void BeginTest() override {
3888 EXPECT_TRUE(HasImplThread()); 3874 EXPECT_TRUE(HasImplThread());
3889 PostSetNeedsCommitToMainThread(); 3875 PostSetNeedsCommitToMainThread();
3890 } 3876 }
3891 3877
3892 virtual DrawResult PrepareToDrawOnThread( 3878 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
3893 LayerTreeHostImpl* host_impl, 3879 LayerTreeHostImpl::FrameData* frame_data,
3894 LayerTreeHostImpl::FrameData* frame_data, 3880 DrawResult draw_result) override {
3895 DrawResult draw_result) override {
3896 ++num_commits_; 3881 ++num_commits_;
3897 switch (num_commits_) { 3882 switch (num_commits_) {
3898 case 1: 3883 case 1:
3899 EXPECT_EQ(0, callback_count_); 3884 EXPECT_EQ(0, callback_count_);
3900 callback_count_ = 0; 3885 callback_count_ = 0;
3901 SetCallback(true); 3886 SetCallback(true);
3902 PostSetNeedsCommitToMainThread(); 3887 PostSetNeedsCommitToMainThread();
3903 break; 3888 break;
3904 case 2: 3889 case 2:
3905 EXPECT_EQ(1, callback_count_); 3890 EXPECT_EQ(1, callback_count_);
3906 callback_count_ = 0; 3891 callback_count_ = 0;
3907 SetCallback(false); 3892 SetCallback(false);
3908 PostSetNeedsCommitToMainThread(); 3893 PostSetNeedsCommitToMainThread();
3909 break; 3894 break;
3910 case 3: 3895 case 3:
3911 EXPECT_EQ(0, callback_count_); 3896 EXPECT_EQ(0, callback_count_);
3912 callback_count_ = 0; 3897 callback_count_ = 0;
3913 EndTest(); 3898 EndTest();
3914 break; 3899 break;
3915 default: 3900 default:
3916 ADD_FAILURE() << num_commits_; 3901 ADD_FAILURE() << num_commits_;
3917 EndTest(); 3902 EndTest();
3918 break; 3903 break;
3919 } 3904 }
3920 return LayerTreeHostTest::PrepareToDrawOnThread( 3905 return LayerTreeHostTest::PrepareToDrawOnThread(
3921 host_impl, frame_data, draw_result); 3906 host_impl, frame_data, draw_result);
3922 } 3907 }
3923 3908
3924 virtual void AfterTest() override { EXPECT_EQ(3, num_commits_); } 3909 void AfterTest() override { EXPECT_EQ(3, num_commits_); }
3925 3910
3926 void SetCallback(bool enable) { 3911 void SetCallback(bool enable) {
3927 output_surface()->SetTreeActivationCallback( 3912 output_surface()->SetTreeActivationCallback(
3928 enable 3913 enable
3929 ? base::Bind( 3914 ? base::Bind(
3930 &LayerTreeHostTestTreeActivationCallback::ActivationCallback, 3915 &LayerTreeHostTestTreeActivationCallback::ActivationCallback,
3931 base::Unretained(this)) 3916 base::Unretained(this))
3932 : base::Closure()); 3917 : base::Closure());
3933 } 3918 }
3934 3919
3935 void ActivationCallback() { ++callback_count_; } 3920 void ActivationCallback() { ++callback_count_; }
3936 3921
3937 int num_commits_; 3922 int num_commits_;
3938 int callback_count_; 3923 int callback_count_;
3939 }; 3924 };
3940 3925
3941 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) { 3926 TEST_F(LayerTreeHostTestTreeActivationCallback, DirectRenderer) {
3942 RunTest(true, false, true); 3927 RunTest(true, false, true);
3943 } 3928 }
3944 3929
3945 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) { 3930 TEST_F(LayerTreeHostTestTreeActivationCallback, DelegatingRenderer) {
3946 RunTest(true, true, true); 3931 RunTest(true, true, true);
3947 } 3932 }
3948 3933
3949 class LayerInvalidateCausesDraw : public LayerTreeHostTest { 3934 class LayerInvalidateCausesDraw : public LayerTreeHostTest {
3950 public: 3935 public:
3951 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {} 3936 LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {}
3952 3937
3953 virtual void BeginTest() override { 3938 void BeginTest() override {
3954 ASSERT_TRUE(!!invalidate_layer_.get()) 3939 ASSERT_TRUE(!!invalidate_layer_.get())
3955 << "Derived tests must set this in SetupTree"; 3940 << "Derived tests must set this in SetupTree";
3956 3941
3957 // One initial commit. 3942 // One initial commit.
3958 PostSetNeedsCommitToMainThread(); 3943 PostSetNeedsCommitToMainThread();
3959 } 3944 }
3960 3945
3961 virtual void DidCommitAndDrawFrame() override { 3946 void DidCommitAndDrawFrame() override {
3962 // After commit, invalidate the layer. This should cause a commit. 3947 // After commit, invalidate the layer. This should cause a commit.
3963 if (layer_tree_host()->source_frame_number() == 1) 3948 if (layer_tree_host()->source_frame_number() == 1)
3964 invalidate_layer_->SetNeedsDisplay(); 3949 invalidate_layer_->SetNeedsDisplay();
3965 } 3950 }
3966 3951
3967 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 3952 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
3968 num_draws_++; 3953 num_draws_++;
3969 if (impl->active_tree()->source_frame_number() == 1) 3954 if (impl->active_tree()->source_frame_number() == 1)
3970 EndTest(); 3955 EndTest();
3971 } 3956 }
3972 3957
3973 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 3958 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
3974 num_commits_++; 3959 num_commits_++;
3975 } 3960 }
3976 3961
3977 virtual void AfterTest() override { 3962 void AfterTest() override {
3978 EXPECT_GE(2, num_commits_); 3963 EXPECT_GE(2, num_commits_);
3979 EXPECT_GE(2, num_draws_); 3964 EXPECT_GE(2, num_draws_);
3980 } 3965 }
3981 3966
3982 protected: 3967 protected:
3983 scoped_refptr<Layer> invalidate_layer_; 3968 scoped_refptr<Layer> invalidate_layer_;
3984 3969
3985 private: 3970 private:
3986 int num_commits_; 3971 int num_commits_;
3987 int num_draws_; 3972 int num_draws_;
3988 }; 3973 };
3989 3974
3990 // VideoLayer must support being invalidated and then passing that along 3975 // VideoLayer must support being invalidated and then passing that along
3991 // to the compositor thread, even though no resources are updated in 3976 // to the compositor thread, even though no resources are updated in
3992 // response to that invalidation. 3977 // response to that invalidation.
3993 class LayerTreeHostTestVideoLayerInvalidate : public LayerInvalidateCausesDraw { 3978 class LayerTreeHostTestVideoLayerInvalidate : public LayerInvalidateCausesDraw {
3994 public: 3979 public:
3995 virtual void SetupTree() override { 3980 void SetupTree() override {
3996 LayerTreeHostTest::SetupTree(); 3981 LayerTreeHostTest::SetupTree();
3997 scoped_refptr<VideoLayer> video_layer = 3982 scoped_refptr<VideoLayer> video_layer =
3998 VideoLayer::Create(&provider_, media::VIDEO_ROTATION_0); 3983 VideoLayer::Create(&provider_, media::VIDEO_ROTATION_0);
3999 video_layer->SetBounds(gfx::Size(10, 10)); 3984 video_layer->SetBounds(gfx::Size(10, 10));
4000 video_layer->SetIsDrawable(true); 3985 video_layer->SetIsDrawable(true);
4001 layer_tree_host()->root_layer()->AddChild(video_layer); 3986 layer_tree_host()->root_layer()->AddChild(video_layer);
4002 3987
4003 invalidate_layer_ = video_layer; 3988 invalidate_layer_ = video_layer;
4004 } 3989 }
4005 3990
4006 private: 3991 private:
4007 FakeVideoFrameProvider provider_; 3992 FakeVideoFrameProvider provider_;
4008 }; 3993 };
4009 3994
4010 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate); 3995 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate);
4011 3996
4012 // IOSurfaceLayer must support being invalidated and then passing that along 3997 // IOSurfaceLayer must support being invalidated and then passing that along
4013 // to the compositor thread, even though no resources are updated in 3998 // to the compositor thread, even though no resources are updated in
4014 // response to that invalidation. 3999 // response to that invalidation.
4015 class LayerTreeHostTestIOSurfaceLayerInvalidate 4000 class LayerTreeHostTestIOSurfaceLayerInvalidate
4016 : public LayerInvalidateCausesDraw { 4001 : public LayerInvalidateCausesDraw {
4017 public: 4002 public:
4018 virtual void SetupTree() override { 4003 void SetupTree() override {
4019 LayerTreeHostTest::SetupTree(); 4004 LayerTreeHostTest::SetupTree();
4020 scoped_refptr<IOSurfaceLayer> layer = IOSurfaceLayer::Create(); 4005 scoped_refptr<IOSurfaceLayer> layer = IOSurfaceLayer::Create();
4021 layer->SetBounds(gfx::Size(10, 10)); 4006 layer->SetBounds(gfx::Size(10, 10));
4022 uint32_t fake_io_surface_id = 7; 4007 uint32_t fake_io_surface_id = 7;
4023 layer->SetIOSurfaceProperties(fake_io_surface_id, layer->bounds()); 4008 layer->SetIOSurfaceProperties(fake_io_surface_id, layer->bounds());
4024 layer->SetIsDrawable(true); 4009 layer->SetIsDrawable(true);
4025 layer_tree_host()->root_layer()->AddChild(layer); 4010 layer_tree_host()->root_layer()->AddChild(layer);
4026 4011
4027 invalidate_layer_ = layer; 4012 invalidate_layer_ = layer;
4028 } 4013 }
4029 }; 4014 };
4030 4015
4031 // TODO(danakj): IOSurface layer can not be transported. crbug.com/239335 4016 // TODO(danakj): IOSurface layer can not be transported. crbug.com/239335
4032 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 4017 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
4033 LayerTreeHostTestIOSurfaceLayerInvalidate); 4018 LayerTreeHostTestIOSurfaceLayerInvalidate);
4034 4019
4035 class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { 4020 class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest {
4036 protected: 4021 protected:
4037 virtual void SetupTree() override { 4022 void SetupTree() override {
4038 root_layer_ = Layer::Create(); 4023 root_layer_ = Layer::Create();
4039 root_layer_->SetPosition(gfx::Point()); 4024 root_layer_->SetPosition(gfx::Point());
4040 root_layer_->SetBounds(gfx::Size(10, 10)); 4025 root_layer_->SetBounds(gfx::Size(10, 10));
4041 4026
4042 parent_layer_ = SolidColorLayer::Create(); 4027 parent_layer_ = SolidColorLayer::Create();
4043 parent_layer_->SetPosition(gfx::Point()); 4028 parent_layer_->SetPosition(gfx::Point());
4044 parent_layer_->SetBounds(gfx::Size(10, 10)); 4029 parent_layer_->SetBounds(gfx::Size(10, 10));
4045 parent_layer_->SetIsDrawable(true); 4030 parent_layer_->SetIsDrawable(true);
4046 root_layer_->AddChild(parent_layer_); 4031 root_layer_->AddChild(parent_layer_);
4047 4032
4048 child_layer_ = SolidColorLayer::Create(); 4033 child_layer_ = SolidColorLayer::Create();
4049 child_layer_->SetPosition(gfx::Point()); 4034 child_layer_->SetPosition(gfx::Point());
4050 child_layer_->SetBounds(gfx::Size(10, 10)); 4035 child_layer_->SetBounds(gfx::Size(10, 10));
4051 child_layer_->SetIsDrawable(true); 4036 child_layer_->SetIsDrawable(true);
4052 parent_layer_->AddChild(child_layer_); 4037 parent_layer_->AddChild(child_layer_);
4053 4038
4054 layer_tree_host()->SetRootLayer(root_layer_); 4039 layer_tree_host()->SetRootLayer(root_layer_);
4055 LayerTreeHostTest::SetupTree(); 4040 LayerTreeHostTest::SetupTree();
4056 } 4041 }
4057 4042
4058 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4043 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4059 4044
4060 virtual void DidCommitAndDrawFrame() override { 4045 void DidCommitAndDrawFrame() override {
4061 switch (layer_tree_host()->source_frame_number()) { 4046 switch (layer_tree_host()->source_frame_number()) {
4062 case 1: 4047 case 1:
4063 // The layer type used does not need to push properties every frame. 4048 // The layer type used does not need to push properties every frame.
4064 EXPECT_FALSE(child_layer_->needs_push_properties()); 4049 EXPECT_FALSE(child_layer_->needs_push_properties());
4065 4050
4066 // Change the bounds of the child layer, but make it skipped 4051 // Change the bounds of the child layer, but make it skipped
4067 // by CalculateDrawProperties. 4052 // by CalculateDrawProperties.
4068 parent_layer_->SetOpacity(0.f); 4053 parent_layer_->SetOpacity(0.f);
4069 child_layer_->SetBounds(gfx::Size(5, 5)); 4054 child_layer_->SetBounds(gfx::Size(5, 5));
4070 break; 4055 break;
4071 case 2: 4056 case 2:
4072 // The bounds of the child layer were pushed to the impl side. 4057 // The bounds of the child layer were pushed to the impl side.
4073 EXPECT_FALSE(child_layer_->needs_push_properties()); 4058 EXPECT_FALSE(child_layer_->needs_push_properties());
4074 4059
4075 EndTest(); 4060 EndTest();
4076 break; 4061 break;
4077 } 4062 }
4078 } 4063 }
4079 4064
4080 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 4065 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
4081 LayerImpl* root = impl->active_tree()->root_layer(); 4066 LayerImpl* root = impl->active_tree()->root_layer();
4082 LayerImpl* parent = root->children()[0]; 4067 LayerImpl* parent = root->children()[0];
4083 LayerImpl* child = parent->children()[0]; 4068 LayerImpl* child = parent->children()[0];
4084 4069
4085 switch (impl->active_tree()->source_frame_number()) { 4070 switch (impl->active_tree()->source_frame_number()) {
4086 case 1: 4071 case 1:
4087 EXPECT_EQ(gfx::Size(5, 5).ToString(), child->bounds().ToString()); 4072 EXPECT_EQ(gfx::Size(5, 5).ToString(), child->bounds().ToString());
4088 break; 4073 break;
4089 } 4074 }
4090 } 4075 }
4091 4076
4092 virtual void AfterTest() override {} 4077 void AfterTest() override {}
4093 4078
4094 scoped_refptr<Layer> root_layer_; 4079 scoped_refptr<Layer> root_layer_;
4095 scoped_refptr<SolidColorLayer> parent_layer_; 4080 scoped_refptr<SolidColorLayer> parent_layer_;
4096 scoped_refptr<SolidColorLayer> child_layer_; 4081 scoped_refptr<SolidColorLayer> child_layer_;
4097 }; 4082 };
4098 4083
4099 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushHiddenLayer); 4084 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushHiddenLayer);
4100 4085
4101 class LayerTreeHostTestUpdateLayerInEmptyViewport : public LayerTreeHostTest { 4086 class LayerTreeHostTestUpdateLayerInEmptyViewport : public LayerTreeHostTest {
4102 protected: 4087 protected:
4103 virtual void InitializeSettings(LayerTreeSettings* settings) override { 4088 void InitializeSettings(LayerTreeSettings* settings) override {
4104 settings->impl_side_painting = true; 4089 settings->impl_side_painting = true;
4105 } 4090 }
4106 4091
4107 virtual void SetupTree() override { 4092 void SetupTree() override {
4108 root_layer_ = FakePictureLayer::Create(&client_); 4093 root_layer_ = FakePictureLayer::Create(&client_);
4109 root_layer_->SetBounds(gfx::Size(10, 10)); 4094 root_layer_->SetBounds(gfx::Size(10, 10));
4110 4095
4111 layer_tree_host()->SetRootLayer(root_layer_); 4096 layer_tree_host()->SetRootLayer(root_layer_);
4112 LayerTreeHostTest::SetupTree(); 4097 LayerTreeHostTest::SetupTree();
4113 } 4098 }
4114 4099
4115 virtual void BeginTest() override { 4100 void BeginTest() override {
4116 // The viewport is empty, but we still need to update layers on the main 4101 // The viewport is empty, but we still need to update layers on the main
4117 // thread. 4102 // thread.
4118 layer_tree_host()->SetViewportSize(gfx::Size(0, 0)); 4103 layer_tree_host()->SetViewportSize(gfx::Size(0, 0));
4119 PostSetNeedsCommitToMainThread(); 4104 PostSetNeedsCommitToMainThread();
4120 } 4105 }
4121 4106
4122 virtual void DidCommit() override { 4107 void DidCommit() override {
4123 // The layer should be updated even though the viewport is empty, so we 4108 // The layer should be updated even though the viewport is empty, so we
4124 // are capable of drawing it on the impl tree. 4109 // are capable of drawing it on the impl tree.
4125 EXPECT_GT(root_layer_->update_count(), 0u); 4110 EXPECT_GT(root_layer_->update_count(), 0u);
4126 EndTest(); 4111 EndTest();
4127 } 4112 }
4128 4113
4129 virtual void AfterTest() override {} 4114 void AfterTest() override {}
4130 4115
4131 FakeContentLayerClient client_; 4116 FakeContentLayerClient client_;
4132 scoped_refptr<FakePictureLayer> root_layer_; 4117 scoped_refptr<FakePictureLayer> root_layer_;
4133 }; 4118 };
4134 4119
4135 MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport); 4120 MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport);
4136 4121
4137 class LayerTreeHostTestAbortEvictedTextures : public LayerTreeHostTest { 4122 class LayerTreeHostTestAbortEvictedTextures : public LayerTreeHostTest {
4138 public: 4123 public:
4139 LayerTreeHostTestAbortEvictedTextures() 4124 LayerTreeHostTestAbortEvictedTextures()
4140 : num_will_begin_main_frames_(0), num_impl_commits_(0) {} 4125 : num_will_begin_main_frames_(0), num_impl_commits_(0) {}
4141 4126
4142 protected: 4127 protected:
4143 virtual void SetupTree() override { 4128 void SetupTree() override {
4144 scoped_refptr<SolidColorLayer> root_layer = SolidColorLayer::Create(); 4129 scoped_refptr<SolidColorLayer> root_layer = SolidColorLayer::Create();
4145 root_layer->SetBounds(gfx::Size(200, 200)); 4130 root_layer->SetBounds(gfx::Size(200, 200));
4146 root_layer->SetIsDrawable(true); 4131 root_layer->SetIsDrawable(true);
4147 4132
4148 layer_tree_host()->SetRootLayer(root_layer); 4133 layer_tree_host()->SetRootLayer(root_layer);
4149 LayerTreeHostTest::SetupTree(); 4134 LayerTreeHostTest::SetupTree();
4150 } 4135 }
4151 4136
4152 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4137 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4153 4138
4154 virtual void WillBeginMainFrame() override { 4139 void WillBeginMainFrame() override {
4155 num_will_begin_main_frames_++; 4140 num_will_begin_main_frames_++;
4156 switch (num_will_begin_main_frames_) { 4141 switch (num_will_begin_main_frames_) {
4157 case 2: 4142 case 2:
4158 // Send a redraw to the compositor thread. This will (wrongly) be 4143 // Send a redraw to the compositor thread. This will (wrongly) be
4159 // ignored unless aborting resets the texture state. 4144 // ignored unless aborting resets the texture state.
4160 layer_tree_host()->SetNeedsRedraw(); 4145 layer_tree_host()->SetNeedsRedraw();
4161 break; 4146 break;
4162 } 4147 }
4163 } 4148 }
4164 4149
4165 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) override { 4150 void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
4166 num_impl_commits_++; 4151 num_impl_commits_++;
4167 } 4152 }
4168 4153
4169 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 4154 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
4170 switch (impl->SourceAnimationFrameNumber()) { 4155 switch (impl->SourceAnimationFrameNumber()) {
4171 case 1: 4156 case 1:
4172 // Prevent draws until commit. 4157 // Prevent draws until commit.
4173 impl->active_tree()->SetContentsTexturesPurged(); 4158 impl->active_tree()->SetContentsTexturesPurged();
4174 EXPECT_FALSE(impl->CanDraw()); 4159 EXPECT_FALSE(impl->CanDraw());
4175 // Trigger an abortable commit. 4160 // Trigger an abortable commit.
4176 impl->SetNeedsCommit(); 4161 impl->SetNeedsCommit();
4177 break; 4162 break;
4178 case 2: 4163 case 2:
4179 EndTest(); 4164 EndTest();
4180 break; 4165 break;
4181 } 4166 }
4182 } 4167 }
4183 4168
4184 virtual void AfterTest() override { 4169 void AfterTest() override {
4185 // Ensure that the commit was truly aborted. 4170 // Ensure that the commit was truly aborted.
4186 EXPECT_EQ(2, num_will_begin_main_frames_); 4171 EXPECT_EQ(2, num_will_begin_main_frames_);
4187 EXPECT_EQ(1, num_impl_commits_); 4172 EXPECT_EQ(1, num_impl_commits_);
4188 } 4173 }
4189 4174
4190 private: 4175 private:
4191 int num_will_begin_main_frames_; 4176 int num_will_begin_main_frames_;
4192 int num_impl_commits_; 4177 int num_impl_commits_;
4193 }; 4178 };
4194 4179
4195 // Commits can only be aborted when using the thread proxy. 4180 // Commits can only be aborted when using the thread proxy.
4196 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); 4181 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures);
4197 4182
4198 class LayerTreeHostTestMaxTransferBufferUsageBytes : public LayerTreeHostTest { 4183 class LayerTreeHostTestMaxTransferBufferUsageBytes : public LayerTreeHostTest {
4199 protected: 4184 protected:
4200 virtual void InitializeSettings(LayerTreeSettings* settings) override { 4185 void InitializeSettings(LayerTreeSettings* settings) override {
4201 settings->impl_side_painting = true; 4186 settings->impl_side_painting = true;
4202 } 4187 }
4203 4188
4204 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 4189 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
4205 override { 4190 bool fallback) override {
4206 scoped_refptr<TestContextProvider> context_provider = 4191 scoped_refptr<TestContextProvider> context_provider =
4207 TestContextProvider::Create(); 4192 TestContextProvider::Create();
4208 context_provider->SetMaxTransferBufferUsageBytes(1024 * 1024); 4193 context_provider->SetMaxTransferBufferUsageBytes(1024 * 1024);
4209 if (delegating_renderer()) 4194 if (delegating_renderer())
4210 return FakeOutputSurface::CreateDelegating3d(context_provider); 4195 return FakeOutputSurface::CreateDelegating3d(context_provider);
4211 else 4196 else
4212 return FakeOutputSurface::Create3d(context_provider); 4197 return FakeOutputSurface::Create3d(context_provider);
4213 } 4198 }
4214 4199
4215 virtual void SetupTree() override { 4200 void SetupTree() override {
4216 client_.set_fill_with_nonsolid_color(true); 4201 client_.set_fill_with_nonsolid_color(true);
4217 scoped_refptr<FakePictureLayer> root_layer = 4202 scoped_refptr<FakePictureLayer> root_layer =
4218 FakePictureLayer::Create(&client_); 4203 FakePictureLayer::Create(&client_);
4219 root_layer->SetBounds(gfx::Size(6000, 6000)); 4204 root_layer->SetBounds(gfx::Size(6000, 6000));
4220 root_layer->SetIsDrawable(true); 4205 root_layer->SetIsDrawable(true);
4221 4206
4222 layer_tree_host()->SetRootLayer(root_layer); 4207 layer_tree_host()->SetRootLayer(root_layer);
4223 LayerTreeHostTest::SetupTree(); 4208 LayerTreeHostTest::SetupTree();
4224 } 4209 }
4225 4210
4226 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4211 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4227 4212
4228 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { 4213 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
4229 TestWebGraphicsContext3D* context = TestContext(); 4214 TestWebGraphicsContext3D* context = TestContext();
4230 4215
4231 // Expect that the transfer buffer memory used is equal to the 4216 // Expect that the transfer buffer memory used is equal to the
4232 // MaxTransferBufferUsageBytes value set in CreateOutputSurface. 4217 // MaxTransferBufferUsageBytes value set in CreateOutputSurface.
4233 EXPECT_EQ(1024 * 1024u, context->max_used_transfer_buffer_usage_bytes()); 4218 EXPECT_EQ(1024 * 1024u, context->max_used_transfer_buffer_usage_bytes());
4234 EndTest(); 4219 EndTest();
4235 } 4220 }
4236 4221
4237 virtual void AfterTest() override {} 4222 void AfterTest() override {}
4238 4223
4239 private: 4224 private:
4240 FakeContentLayerClient client_; 4225 FakeContentLayerClient client_;
4241 }; 4226 };
4242 4227
4243 // Impl-side painting is a multi-threaded compositor feature. 4228 // Impl-side painting is a multi-threaded compositor feature.
4244 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes); 4229 MULTI_THREAD_TEST_F(LayerTreeHostTestMaxTransferBufferUsageBytes);
4245 4230
4246 // Test ensuring that memory limits are sent to the prioritized resource 4231 // Test ensuring that memory limits are sent to the prioritized resource
4247 // manager. 4232 // manager.
4248 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest { 4233 class LayerTreeHostTestMemoryLimits : public LayerTreeHostTest {
4249 public: 4234 public:
4250 LayerTreeHostTestMemoryLimits() : num_commits_(0) {} 4235 LayerTreeHostTestMemoryLimits() : num_commits_(0) {}
4251 4236
4252 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4237 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4253 4238
4254 virtual void WillCommit() override { 4239 void WillCommit() override {
4255 // Some commits are aborted, so increment number of attempted commits here. 4240 // Some commits are aborted, so increment number of attempted commits here.
4256 num_commits_++; 4241 num_commits_++;
4257 } 4242 }
4258 4243
4259 virtual void DidCommit() override { 4244 void DidCommit() override {
4260 switch (num_commits_) { 4245 switch (num_commits_) {
4261 case 1: 4246 case 1:
4262 // Verify default values. 4247 // Verify default values.
4263 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 4248 EXPECT_EQ(PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
4264 layer_tree_host() 4249 layer_tree_host()
4265 ->contents_texture_manager() 4250 ->contents_texture_manager()
4266 ->MaxMemoryLimitBytes()); 4251 ->MaxMemoryLimitBytes());
4267 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(), 4252 EXPECT_EQ(PriorityCalculator::AllowEverythingCutoff(),
4268 layer_tree_host() 4253 layer_tree_host()
4269 ->contents_texture_manager() 4254 ->contents_texture_manager()
(...skipping 24 matching lines...) Expand all
4294 ->ExternalPriorityCutoff()); 4279 ->ExternalPriorityCutoff());
4295 EndTest(); 4280 EndTest();
4296 break; 4281 break;
4297 case 4: 4282 case 4:
4298 // Make sure no extra commits happen. 4283 // Make sure no extra commits happen.
4299 NOTREACHED(); 4284 NOTREACHED();
4300 break; 4285 break;
4301 } 4286 }
4302 } 4287 }
4303 4288
4304 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 4289 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
4305 switch (num_commits_) { 4290 switch (num_commits_) {
4306 case 1: 4291 case 1:
4307 break; 4292 break;
4308 case 2: 4293 case 2:
4309 // This will trigger a commit because the priority cutoff has changed. 4294 // This will trigger a commit because the priority cutoff has changed.
4310 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4295 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4311 16u * 1024u * 1024u, 4296 16u * 1024u * 1024u,
4312 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4297 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4313 1000)); 4298 1000));
4314 break; 4299 break;
4315 case 3: 4300 case 3:
4316 // This will not trigger a commit because the priority cutoff has not 4301 // This will not trigger a commit because the priority cutoff has not
4317 // changed, and there is already enough memory for all allocations. 4302 // changed, and there is already enough memory for all allocations.
4318 impl->SetMemoryPolicy(ManagedMemoryPolicy( 4303 impl->SetMemoryPolicy(ManagedMemoryPolicy(
4319 32u * 1024u * 1024u, 4304 32u * 1024u * 1024u,
4320 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4305 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4321 1000)); 4306 1000));
4322 break; 4307 break;
4323 case 4: 4308 case 4:
4324 NOTREACHED(); 4309 NOTREACHED();
4325 break; 4310 break;
4326 } 4311 }
4327 } 4312 }
4328 4313
4329 virtual void AfterTest() override {} 4314 void AfterTest() override {}
4330 4315
4331 private: 4316 private:
4332 int num_commits_; 4317 int num_commits_;
4333 }; 4318 };
4334 4319
4335 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestMemoryLimits); 4320 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestMemoryLimits);
4336 4321
4337 } // namespace 4322 } // namespace
4338 4323
4339 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface 4324 class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface
4340 : public LayerTreeHostTest { 4325 : public LayerTreeHostTest {
4341 protected: 4326 protected:
4342 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface() 4327 LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface()
4343 : first_output_surface_memory_limit_(4321234), 4328 : first_output_surface_memory_limit_(4321234),
4344 second_output_surface_memory_limit_(1234321) {} 4329 second_output_surface_memory_limit_(1234321) {}
4345 4330
4346 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 4331 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
4347 override { 4332 bool fallback) override {
4348 if (!first_context_provider_.get()) { 4333 if (!first_context_provider_.get()) {
4349 first_context_provider_ = TestContextProvider::Create(); 4334 first_context_provider_ = TestContextProvider::Create();
4350 } else { 4335 } else {
4351 EXPECT_FALSE(second_context_provider_.get()); 4336 EXPECT_FALSE(second_context_provider_.get());
4352 second_context_provider_ = TestContextProvider::Create(); 4337 second_context_provider_ = TestContextProvider::Create();
4353 } 4338 }
4354 4339
4355 scoped_refptr<TestContextProvider> provider(second_context_provider_.get() 4340 scoped_refptr<TestContextProvider> provider(second_context_provider_.get()
4356 ? second_context_provider_ 4341 ? second_context_provider_
4357 : first_context_provider_); 4342 : first_context_provider_);
4358 scoped_ptr<FakeOutputSurface> output_surface; 4343 scoped_ptr<FakeOutputSurface> output_surface;
4359 if (delegating_renderer()) 4344 if (delegating_renderer())
4360 output_surface = FakeOutputSurface::CreateDelegating3d(provider); 4345 output_surface = FakeOutputSurface::CreateDelegating3d(provider);
4361 else 4346 else
4362 output_surface = FakeOutputSurface::Create3d(provider); 4347 output_surface = FakeOutputSurface::Create3d(provider);
4363 output_surface->SetMemoryPolicyToSetAtBind( 4348 output_surface->SetMemoryPolicyToSetAtBind(
4364 make_scoped_ptr(new ManagedMemoryPolicy( 4349 make_scoped_ptr(new ManagedMemoryPolicy(
4365 second_context_provider_.get() ? second_output_surface_memory_limit_ 4350 second_context_provider_.get() ? second_output_surface_memory_limit_
4366 : first_output_surface_memory_limit_, 4351 : first_output_surface_memory_limit_,
4367 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE, 4352 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
4368 ManagedMemoryPolicy::kDefaultNumResourcesLimit))); 4353 ManagedMemoryPolicy::kDefaultNumResourcesLimit)));
4369 return output_surface.Pass(); 4354 return output_surface.Pass();
4370 } 4355 }
4371 4356
4372 virtual void SetupTree() override { 4357 void SetupTree() override {
4373 root_ = FakeContentLayer::Create(&client_); 4358 root_ = FakeContentLayer::Create(&client_);
4374 root_->SetBounds(gfx::Size(20, 20)); 4359 root_->SetBounds(gfx::Size(20, 20));
4375 layer_tree_host()->SetRootLayer(root_); 4360 layer_tree_host()->SetRootLayer(root_);
4376 LayerTreeHostTest::SetupTree(); 4361 LayerTreeHostTest::SetupTree();
4377 } 4362 }
4378 4363
4379 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4364 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4380 4365
4381 virtual void DidCommitAndDrawFrame() override { 4366 void DidCommitAndDrawFrame() override {
4382 // Lost context sometimes takes two frames to recreate. The third frame 4367 // Lost context sometimes takes two frames to recreate. The third frame
4383 // is sometimes aborted, so wait until the fourth frame to verify that 4368 // is sometimes aborted, so wait until the fourth frame to verify that
4384 // the memory has been set, and the fifth frame to end the test. 4369 // the memory has been set, and the fifth frame to end the test.
4385 if (layer_tree_host()->source_frame_number() < 5) { 4370 if (layer_tree_host()->source_frame_number() < 5) {
4386 layer_tree_host()->SetNeedsCommit(); 4371 layer_tree_host()->SetNeedsCommit();
4387 } else if (layer_tree_host()->source_frame_number() == 5) { 4372 } else if (layer_tree_host()->source_frame_number() == 5) {
4388 EndTest(); 4373 EndTest();
4389 } 4374 }
4390 } 4375 }
4391 4376
4392 virtual void SwapBuffersOnThread(LayerTreeHostImpl* impl, 4377 void SwapBuffersOnThread(LayerTreeHostImpl* impl, bool result) override {
4393 bool result) override {
4394 switch (impl->active_tree()->source_frame_number()) { 4378 switch (impl->active_tree()->source_frame_number()) {
4395 case 1: 4379 case 1:
4396 EXPECT_EQ(first_output_surface_memory_limit_, 4380 EXPECT_EQ(first_output_surface_memory_limit_,
4397 impl->memory_allocation_limit_bytes()); 4381 impl->memory_allocation_limit_bytes());
4398 // Lose the output surface. 4382 // Lose the output surface.
4399 first_context_provider_->TestContext3d()->loseContextCHROMIUM( 4383 first_context_provider_->TestContext3d()->loseContextCHROMIUM(
4400 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 4384 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
4401 break; 4385 break;
4402 case 4: 4386 case 4:
4403 EXPECT_EQ(second_output_surface_memory_limit_, 4387 EXPECT_EQ(second_output_surface_memory_limit_,
4404 impl->memory_allocation_limit_bytes()); 4388 impl->memory_allocation_limit_bytes());
4405 break; 4389 break;
4406 } 4390 }
4407 } 4391 }
4408 4392
4409 virtual void AfterTest() override {} 4393 void AfterTest() override {}
4410 4394
4411 scoped_refptr<TestContextProvider> first_context_provider_; 4395 scoped_refptr<TestContextProvider> first_context_provider_;
4412 scoped_refptr<TestContextProvider> second_context_provider_; 4396 scoped_refptr<TestContextProvider> second_context_provider_;
4413 size_t first_output_surface_memory_limit_; 4397 size_t first_output_surface_memory_limit_;
4414 size_t second_output_surface_memory_limit_; 4398 size_t second_output_surface_memory_limit_;
4415 FakeContentLayerClient client_; 4399 FakeContentLayerClient client_;
4416 scoped_refptr<FakeContentLayer> root_; 4400 scoped_refptr<FakeContentLayer> root_;
4417 }; 4401 };
4418 4402
4419 // No output to copy for delegated renderers. 4403 // No output to copy for delegated renderers.
(...skipping 11 matching lines...) Expand all
4431 bool did_not_swap_called; 4415 bool did_not_swap_called;
4432 bool dtor_called; 4416 bool dtor_called;
4433 SwapPromise::DidNotSwapReason reason; 4417 SwapPromise::DidNotSwapReason reason;
4434 base::Lock lock; 4418 base::Lock lock;
4435 }; 4419 };
4436 4420
4437 class TestSwapPromise : public SwapPromise { 4421 class TestSwapPromise : public SwapPromise {
4438 public: 4422 public:
4439 explicit TestSwapPromise(TestSwapPromiseResult* result) : result_(result) {} 4423 explicit TestSwapPromise(TestSwapPromiseResult* result) : result_(result) {}
4440 4424
4441 virtual ~TestSwapPromise() { 4425 ~TestSwapPromise() override {
4442 base::AutoLock lock(result_->lock); 4426 base::AutoLock lock(result_->lock);
4443 result_->dtor_called = true; 4427 result_->dtor_called = true;
4444 } 4428 }
4445 4429
4446 virtual void DidSwap(CompositorFrameMetadata* metadata) override { 4430 void DidSwap(CompositorFrameMetadata* metadata) override {
4447 base::AutoLock lock(result_->lock); 4431 base::AutoLock lock(result_->lock);
4448 EXPECT_FALSE(result_->did_swap_called); 4432 EXPECT_FALSE(result_->did_swap_called);
4449 EXPECT_FALSE(result_->did_not_swap_called); 4433 EXPECT_FALSE(result_->did_not_swap_called);
4450 result_->did_swap_called = true; 4434 result_->did_swap_called = true;
4451 } 4435 }
4452 4436
4453 virtual void DidNotSwap(DidNotSwapReason reason) override { 4437 void DidNotSwap(DidNotSwapReason reason) override {
4454 base::AutoLock lock(result_->lock); 4438 base::AutoLock lock(result_->lock);
4455 EXPECT_FALSE(result_->did_swap_called); 4439 EXPECT_FALSE(result_->did_swap_called);
4456 EXPECT_FALSE(result_->did_not_swap_called); 4440 EXPECT_FALSE(result_->did_not_swap_called);
4457 result_->did_not_swap_called = true; 4441 result_->did_not_swap_called = true;
4458 result_->reason = reason; 4442 result_->reason = reason;
4459 } 4443 }
4460 4444
4461 virtual int64 TraceId() const override { return 0; } 4445 int64 TraceId() const override { return 0; }
4462 4446
4463 private: 4447 private:
4464 // Not owned. 4448 // Not owned.
4465 TestSwapPromiseResult* result_; 4449 TestSwapPromiseResult* result_;
4466 }; 4450 };
4467 4451
4468 class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest { 4452 class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest {
4469 protected: 4453 protected:
4470 LayerTreeHostTestBreakSwapPromise() 4454 LayerTreeHostTestBreakSwapPromise()
4471 : commit_count_(0), commit_complete_count_(0) {} 4455 : commit_count_(0), commit_complete_count_(0) {}
4472 4456
4473 virtual void WillBeginMainFrame() override { 4457 void WillBeginMainFrame() override {
4474 ASSERT_LE(commit_count_, 2); 4458 ASSERT_LE(commit_count_, 2);
4475 scoped_ptr<SwapPromise> swap_promise( 4459 scoped_ptr<SwapPromise> swap_promise(
4476 new TestSwapPromise(&swap_promise_result_[commit_count_])); 4460 new TestSwapPromise(&swap_promise_result_[commit_count_]));
4477 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4461 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4478 } 4462 }
4479 4463
4480 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4464 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4481 4465
4482 virtual void DidCommit() override { 4466 void DidCommit() override {
4483 commit_count_++; 4467 commit_count_++;
4484 if (commit_count_ == 2) { 4468 if (commit_count_ == 2) {
4485 // This commit will finish. 4469 // This commit will finish.
4486 layer_tree_host()->SetNeedsCommit(); 4470 layer_tree_host()->SetNeedsCommit();
4487 } 4471 }
4488 } 4472 }
4489 4473
4490 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 4474 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
4491 commit_complete_count_++; 4475 commit_complete_count_++;
4492 if (commit_complete_count_ == 1) { 4476 if (commit_complete_count_ == 1) {
4493 // This commit will be aborted because no actual update. 4477 // This commit will be aborted because no actual update.
4494 PostSetNeedsUpdateLayersToMainThread(); 4478 PostSetNeedsUpdateLayersToMainThread();
4495 } else { 4479 } else {
4496 EndTest(); 4480 EndTest();
4497 } 4481 }
4498 } 4482 }
4499 4483
4500 virtual void AfterTest() override { 4484 void AfterTest() override {
4501 // 3 commits are scheduled. 2 completes. 1 is aborted. 4485 // 3 commits are scheduled. 2 completes. 1 is aborted.
4502 EXPECT_EQ(commit_count_, 3); 4486 EXPECT_EQ(commit_count_, 3);
4503 EXPECT_EQ(commit_complete_count_, 2); 4487 EXPECT_EQ(commit_complete_count_, 2);
4504 4488
4505 { 4489 {
4506 // The first commit completes and causes swap buffer which finishes 4490 // The first commit completes and causes swap buffer which finishes
4507 // the promise. 4491 // the promise.
4508 base::AutoLock lock(swap_promise_result_[0].lock); 4492 base::AutoLock lock(swap_promise_result_[0].lock);
4509 EXPECT_TRUE(swap_promise_result_[0].did_swap_called); 4493 EXPECT_TRUE(swap_promise_result_[0].did_swap_called);
4510 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called); 4494 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called);
(...skipping 23 matching lines...) Expand all
4534 int commit_count_; 4518 int commit_count_;
4535 int commit_complete_count_; 4519 int commit_complete_count_;
4536 TestSwapPromiseResult swap_promise_result_[3]; 4520 TestSwapPromiseResult swap_promise_result_[3];
4537 }; 4521 };
4538 4522
4539 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); 4523 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise);
4540 4524
4541 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit 4525 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit
4542 : public LayerTreeHostTest { 4526 : public LayerTreeHostTest {
4543 protected: 4527 protected:
4544 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4528 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4545 4529
4546 virtual void DidCommit() override { 4530 void DidCommit() override {
4547 layer_tree_host()->SetDeferCommits(true); 4531 layer_tree_host()->SetDeferCommits(true);
4548 layer_tree_host()->SetNeedsCommit(); 4532 layer_tree_host()->SetNeedsCommit();
4549 } 4533 }
4550 4534
4551 virtual void DidDeferCommit() override { 4535 void DidDeferCommit() override {
4552 layer_tree_host()->SetVisible(false); 4536 layer_tree_host()->SetVisible(false);
4553 scoped_ptr<SwapPromise> swap_promise( 4537 scoped_ptr<SwapPromise> swap_promise(
4554 new TestSwapPromise(&swap_promise_result_)); 4538 new TestSwapPromise(&swap_promise_result_));
4555 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4539 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4556 layer_tree_host()->SetDeferCommits(false); 4540 layer_tree_host()->SetDeferCommits(false);
4557 } 4541 }
4558 4542
4559 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4543 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4560 bool did_handle) override { 4544 bool did_handle) override {
4561 EndTest(); 4545 EndTest();
4562 } 4546 }
4563 4547
4564 virtual void AfterTest() override { 4548 void AfterTest() override {
4565 { 4549 {
4566 base::AutoLock lock(swap_promise_result_.lock); 4550 base::AutoLock lock(swap_promise_result_.lock);
4567 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4551 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4568 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4552 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4569 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4553 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4570 EXPECT_TRUE(swap_promise_result_.dtor_called); 4554 EXPECT_TRUE(swap_promise_result_.dtor_called);
4571 } 4555 }
4572 } 4556 }
4573 4557
4574 TestSwapPromiseResult swap_promise_result_; 4558 TestSwapPromiseResult swap_promise_result_;
4575 }; 4559 };
4576 4560
4577 SINGLE_AND_MULTI_THREAD_TEST_F( 4561 SINGLE_AND_MULTI_THREAD_TEST_F(
4578 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit); 4562 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4579 4563
4580 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit 4564 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit
4581 : public LayerTreeHostTest { 4565 : public LayerTreeHostTest {
4582 protected: 4566 protected:
4583 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4567 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4584 4568
4585 virtual void DidCommit() override { 4569 void DidCommit() override {
4586 if (TestEnded()) 4570 if (TestEnded())
4587 return; 4571 return;
4588 layer_tree_host()->SetDeferCommits(true); 4572 layer_tree_host()->SetDeferCommits(true);
4589 layer_tree_host()->SetNeedsCommit(); 4573 layer_tree_host()->SetNeedsCommit();
4590 } 4574 }
4591 4575
4592 virtual void DidDeferCommit() override { 4576 void DidDeferCommit() override {
4593 layer_tree_host()->DidLoseOutputSurface(); 4577 layer_tree_host()->DidLoseOutputSurface();
4594 scoped_ptr<SwapPromise> swap_promise( 4578 scoped_ptr<SwapPromise> swap_promise(
4595 new TestSwapPromise(&swap_promise_result_)); 4579 new TestSwapPromise(&swap_promise_result_));
4596 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4580 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4597 layer_tree_host()->SetDeferCommits(false); 4581 layer_tree_host()->SetDeferCommits(false);
4598 } 4582 }
4599 4583
4600 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4584 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4601 bool did_handle) override { 4585 bool did_handle) override {
4602 EndTest(); 4586 EndTest();
4603 // This lets the test finally commit and exit. 4587 // This lets the test finally commit and exit.
4604 MainThreadTaskRunner()->PostTask( 4588 MainThreadTaskRunner()->PostTask(
4605 FROM_HERE, 4589 FROM_HERE,
4606 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit:: 4590 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit::
4607 FindOutputSurface, 4591 FindOutputSurface,
4608 base::Unretained(this))); 4592 base::Unretained(this)));
4609 } 4593 }
4610 4594
4611 void FindOutputSurface() { 4595 void FindOutputSurface() {
4612 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(true); 4596 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(true);
4613 } 4597 }
4614 4598
4615 virtual void AfterTest() override { 4599 void AfterTest() override {
4616 { 4600 {
4617 base::AutoLock lock(swap_promise_result_.lock); 4601 base::AutoLock lock(swap_promise_result_.lock);
4618 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4602 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4619 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4603 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4620 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4604 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4621 EXPECT_TRUE(swap_promise_result_.dtor_called); 4605 EXPECT_TRUE(swap_promise_result_.dtor_called);
4622 } 4606 }
4623 } 4607 }
4624 4608
4625 TestSwapPromiseResult swap_promise_result_; 4609 TestSwapPromiseResult swap_promise_result_;
4626 }; 4610 };
4627 4611
4628 SINGLE_AND_MULTI_THREAD_TEST_F( 4612 SINGLE_AND_MULTI_THREAD_TEST_F(
4629 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); 4613 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit);
4630 4614
4631 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4615 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4632 public: 4616 public:
4633 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4617 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4634 LayerTreeHostImpl* layer_tree_host_impl, 4618 LayerTreeHostImpl* layer_tree_host_impl,
4635 int* set_needs_commit_count, 4619 int* set_needs_commit_count,
4636 int* set_needs_redraw_count) 4620 int* set_needs_redraw_count)
4637 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4621 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4638 set_needs_commit_count_(set_needs_commit_count) {} 4622 set_needs_commit_count_(set_needs_commit_count) {}
4639 4623
4640 virtual ~SimpleSwapPromiseMonitor() {} 4624 ~SimpleSwapPromiseMonitor() override {}
4641 4625
4642 virtual void OnSetNeedsCommitOnMain() override { 4626 void OnSetNeedsCommitOnMain() override { (*set_needs_commit_count_)++; }
4643 (*set_needs_commit_count_)++;
4644 }
4645 4627
4646 virtual void OnSetNeedsRedrawOnImpl() override { 4628 void OnSetNeedsRedrawOnImpl() override {
4647 ADD_FAILURE() << "Should not get called on main thread."; 4629 ADD_FAILURE() << "Should not get called on main thread.";
4648 } 4630 }
4649 4631
4650 virtual void OnForwardScrollUpdateToMainThreadOnImpl() override { 4632 void OnForwardScrollUpdateToMainThreadOnImpl() override {
4651 ADD_FAILURE() << "Should not get called on main thread."; 4633 ADD_FAILURE() << "Should not get called on main thread.";
4652 } 4634 }
4653 4635
4654 private: 4636 private:
4655 int* set_needs_commit_count_; 4637 int* set_needs_commit_count_;
4656 }; 4638 };
4657 4639
4658 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest { 4640 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest {
4659 public: 4641 public:
4660 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4642 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4661 4643
4662 virtual void WillBeginMainFrame() override { 4644 void WillBeginMainFrame() override {
4663 if (TestEnded()) 4645 if (TestEnded())
4664 return; 4646 return;
4665 4647
4666 int set_needs_commit_count = 0; 4648 int set_needs_commit_count = 0;
4667 int set_needs_redraw_count = 0; 4649 int set_needs_redraw_count = 0;
4668 4650
4669 { 4651 {
4670 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( 4652 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor(
4671 new SimpleSwapPromiseMonitor(layer_tree_host(), 4653 new SimpleSwapPromiseMonitor(layer_tree_host(),
4672 NULL, 4654 NULL,
(...skipping 28 matching lines...) Expand all
4701 &set_needs_commit_count, 4683 &set_needs_commit_count,
4702 &set_needs_redraw_count)); 4684 &set_needs_redraw_count));
4703 layer_tree_host()->SetNeedsAnimate(); 4685 layer_tree_host()->SetNeedsAnimate();
4704 EXPECT_EQ(3, set_needs_commit_count); 4686 EXPECT_EQ(3, set_needs_commit_count);
4705 EXPECT_EQ(0, set_needs_redraw_count); 4687 EXPECT_EQ(0, set_needs_redraw_count);
4706 } 4688 }
4707 4689
4708 EndTest(); 4690 EndTest();
4709 } 4691 }
4710 4692
4711 virtual void AfterTest() override {} 4693 void AfterTest() override {}
4712 }; 4694 };
4713 4695
4714 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); 4696 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor);
4715 4697
4716 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources 4698 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources
4717 : public LayerTreeHostTest { 4699 : public LayerTreeHostTest {
4718 protected: 4700 protected:
4719 virtual void InitializeSettings(LayerTreeSettings* settings) override { 4701 void InitializeSettings(LayerTreeSettings* settings) override {
4720 settings->impl_side_painting = true; 4702 settings->impl_side_painting = true;
4721 } 4703 }
4722 4704
4723 virtual void SetupTree() override { 4705 void SetupTree() override {
4724 LayerTreeHostTest::SetupTree(); 4706 LayerTreeHostTest::SetupTree();
4725 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); 4707 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
4726 } 4708 }
4727 4709
4728 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4710 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4729 4711
4730 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 4712 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
4731 host_impl->EvictAllUIResources(); 4713 host_impl->EvictAllUIResources();
4732 // Existence of evicted UI resources will trigger NEW_CONTENT_TAKES_PRIORITY 4714 // Existence of evicted UI resources will trigger NEW_CONTENT_TAKES_PRIORITY
4733 // mode. Active tree should require high-res to draw after entering this 4715 // mode. Active tree should require high-res to draw after entering this
4734 // mode to ensure that high-res tiles are also required for a pending tree 4716 // mode to ensure that high-res tiles are also required for a pending tree
4735 // to be activated. 4717 // to be activated.
4736 EXPECT_TRUE(host_impl->RequiresHighResToDraw()); 4718 EXPECT_TRUE(host_impl->RequiresHighResToDraw());
4737 } 4719 }
4738 4720
4739 virtual void DidCommit() override { 4721 void DidCommit() override {
4740 int frame = layer_tree_host()->source_frame_number(); 4722 int frame = layer_tree_host()->source_frame_number();
4741 switch (frame) { 4723 switch (frame) {
4742 case 1: 4724 case 1:
4743 PostSetNeedsCommitToMainThread(); 4725 PostSetNeedsCommitToMainThread();
4744 break; 4726 break;
4745 case 2: 4727 case 2:
4746 ui_resource_ = nullptr; 4728 ui_resource_ = nullptr;
4747 EndTest(); 4729 EndTest();
4748 break; 4730 break;
4749 } 4731 }
4750 } 4732 }
4751 4733
4752 virtual void AfterTest() override {} 4734 void AfterTest() override {}
4753 4735
4754 FakeContentLayerClient client_; 4736 FakeContentLayerClient client_;
4755 scoped_ptr<FakeScopedUIResource> ui_resource_; 4737 scoped_ptr<FakeScopedUIResource> ui_resource_;
4756 }; 4738 };
4757 4739
4758 // This test is flaky, see http://crbug.com/386199 4740 // This test is flaky, see http://crbug.com/386199
4759 // MULTI_THREAD_TEST_F(LayerTreeHostTestHighResRequiredAfterEvictingUIResources) 4741 // MULTI_THREAD_TEST_F(LayerTreeHostTestHighResRequiredAfterEvictingUIResources)
4760 4742
4761 class LayerTreeHostTestGpuRasterizationDefault : public LayerTreeHostTest { 4743 class LayerTreeHostTestGpuRasterizationDefault : public LayerTreeHostTest {
4762 protected: 4744 protected:
4763 virtual void InitializeSettings(LayerTreeSettings* settings) override { 4745 void InitializeSettings(LayerTreeSettings* settings) override {
4764 settings->impl_side_painting = true; 4746 settings->impl_side_painting = true;
4765 4747
4766 EXPECT_FALSE(settings->gpu_rasterization_enabled); 4748 EXPECT_FALSE(settings->gpu_rasterization_enabled);
4767 EXPECT_FALSE(settings->gpu_rasterization_forced); 4749 EXPECT_FALSE(settings->gpu_rasterization_forced);
4768 } 4750 }
4769 4751
4770 virtual void SetupTree() override { 4752 void SetupTree() override {
4771 LayerTreeHostTest::SetupTree(); 4753 LayerTreeHostTest::SetupTree();
4772 4754
4773 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_); 4755 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_);
4774 layer->SetBounds(gfx::Size(10, 10)); 4756 layer->SetBounds(gfx::Size(10, 10));
4775 layer->SetIsDrawable(true); 4757 layer->SetIsDrawable(true);
4776 layer_tree_host()->root_layer()->AddChild(layer); 4758 layer_tree_host()->root_layer()->AddChild(layer);
4777 } 4759 }
4778 4760
4779 virtual void BeginTest() override { 4761 void BeginTest() override {
4780 Layer* root = layer_tree_host()->root_layer(); 4762 Layer* root = layer_tree_host()->root_layer();
4781 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); 4763 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0));
4782 PicturePile* pile = layer->GetPicturePileForTesting(); 4764 PicturePile* pile = layer->GetPicturePileForTesting();
4783 4765
4784 // Verify default values. 4766 // Verify default values.
4785 EXPECT_TRUE(root->IsSuitableForGpuRasterization()); 4767 EXPECT_TRUE(root->IsSuitableForGpuRasterization());
4786 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); 4768 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
4787 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization()); 4769 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization());
4788 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); 4770 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4789 EXPECT_FALSE(layer_tree_host()->UseGpuRasterization()); 4771 EXPECT_FALSE(layer_tree_host()->UseGpuRasterization());
4790 4772
4791 // Setting gpu rasterization trigger does not enable gpu rasterization. 4773 // Setting gpu rasterization trigger does not enable gpu rasterization.
4792 layer_tree_host()->SetHasGpuRasterizationTrigger(true); 4774 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4793 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); 4775 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4794 EXPECT_FALSE(layer_tree_host()->UseGpuRasterization()); 4776 EXPECT_FALSE(layer_tree_host()->UseGpuRasterization());
4795 4777
4796 PostSetNeedsCommitToMainThread(); 4778 PostSetNeedsCommitToMainThread();
4797 } 4779 }
4798 4780
4799 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 4781 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
4800 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization()); 4782 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization());
4801 EXPECT_FALSE(host_impl->use_gpu_rasterization()); 4783 EXPECT_FALSE(host_impl->use_gpu_rasterization());
4802 } 4784 }
4803 4785
4804 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 4786 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
4805 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization()); 4787 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization());
4806 EXPECT_FALSE(host_impl->use_gpu_rasterization()); 4788 EXPECT_FALSE(host_impl->use_gpu_rasterization());
4807 EndTest(); 4789 EndTest();
4808 } 4790 }
4809 4791
4810 virtual void AfterTest() override {} 4792 void AfterTest() override {}
4811 4793
4812 FakeContentLayerClient layer_client_; 4794 FakeContentLayerClient layer_client_;
4813 }; 4795 };
4814 4796
4815 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDefault); 4797 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDefault);
4816 4798
4817 class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest { 4799 class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest {
4818 protected: 4800 protected:
4819 virtual void InitializeSettings(LayerTreeSettings* settings) override { 4801 void InitializeSettings(LayerTreeSettings* settings) override {
4820 settings->impl_side_painting = true; 4802 settings->impl_side_painting = true;
4821 4803
4822 EXPECT_FALSE(settings->gpu_rasterization_enabled); 4804 EXPECT_FALSE(settings->gpu_rasterization_enabled);
4823 settings->gpu_rasterization_enabled = true; 4805 settings->gpu_rasterization_enabled = true;
4824 } 4806 }
4825 4807
4826 virtual void SetupTree() override { 4808 void SetupTree() override {
4827 LayerTreeHostTest::SetupTree(); 4809 LayerTreeHostTest::SetupTree();
4828 4810
4829 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_); 4811 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_);
4830 layer->SetBounds(gfx::Size(10, 10)); 4812 layer->SetBounds(gfx::Size(10, 10));
4831 layer->SetIsDrawable(true); 4813 layer->SetIsDrawable(true);
4832 layer_tree_host()->root_layer()->AddChild(layer); 4814 layer_tree_host()->root_layer()->AddChild(layer);
4833 } 4815 }
4834 4816
4835 virtual void BeginTest() override { 4817 void BeginTest() override {
4836 Layer* root = layer_tree_host()->root_layer(); 4818 Layer* root = layer_tree_host()->root_layer();
4837 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); 4819 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0));
4838 PicturePile* pile = layer->GetPicturePileForTesting(); 4820 PicturePile* pile = layer->GetPicturePileForTesting();
4839 4821
4840 // Verify default values. 4822 // Verify default values.
4841 EXPECT_TRUE(root->IsSuitableForGpuRasterization()); 4823 EXPECT_TRUE(root->IsSuitableForGpuRasterization());
4842 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); 4824 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
4843 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization()); 4825 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization());
4844 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); 4826 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4845 EXPECT_FALSE(layer_tree_host()->UseGpuRasterization()); 4827 EXPECT_FALSE(layer_tree_host()->UseGpuRasterization());
4846 4828
4847 // Gpu rasterization trigger is relevant. 4829 // Gpu rasterization trigger is relevant.
4848 layer_tree_host()->SetHasGpuRasterizationTrigger(true); 4830 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4849 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); 4831 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4850 EXPECT_TRUE(layer_tree_host()->UseGpuRasterization()); 4832 EXPECT_TRUE(layer_tree_host()->UseGpuRasterization());
4851 4833
4852 // Content-based veto is relevant as well. 4834 // Content-based veto is relevant as well.
4853 pile->SetUnsuitableForGpuRasterizationForTesting(); 4835 pile->SetUnsuitableForGpuRasterizationForTesting();
4854 EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization()); 4836 EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization());
4855 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); 4837 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
4856 // Veto will take effect when layers are updated. 4838 // Veto will take effect when layers are updated.
4857 // The results will be verified after commit is completed below. 4839 // The results will be verified after commit is completed below.
4858 // Since we are manually marking picture pile as unsuitable, 4840 // Since we are manually marking picture pile as unsuitable,
4859 // make sure that the layer gets a chance to update. 4841 // make sure that the layer gets a chance to update.
4860 layer->SetNeedsDisplay(); 4842 layer->SetNeedsDisplay();
4861 PostSetNeedsCommitToMainThread(); 4843 PostSetNeedsCommitToMainThread();
4862 } 4844 }
4863 4845
4864 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 4846 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
4865 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization()); 4847 EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization());
4866 EXPECT_FALSE(host_impl->use_gpu_rasterization()); 4848 EXPECT_FALSE(host_impl->use_gpu_rasterization());
4867 } 4849 }
4868 4850
4869 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 4851 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
4870 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization()); 4852 EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization());
4871 EXPECT_FALSE(host_impl->use_gpu_rasterization()); 4853 EXPECT_FALSE(host_impl->use_gpu_rasterization());
4872 EndTest(); 4854 EndTest();
4873 } 4855 }
4874 4856
4875 virtual void AfterTest() override {} 4857 void AfterTest() override {}
4876 4858
4877 FakeContentLayerClient layer_client_; 4859 FakeContentLayerClient layer_client_;
4878 }; 4860 };
4879 4861
4880 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled); 4862 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled);
4881 4863
4882 class LayerTreeHostTestGpuRasterizationForced : public LayerTreeHostTest { 4864 class LayerTreeHostTestGpuRasterizationForced : public LayerTreeHostTest {
4883 protected: 4865 protected:
4884 virtual void InitializeSettings(LayerTreeSettings* settings) override { 4866 void InitializeSettings(LayerTreeSettings* settings) override {
4885 settings->impl_side_painting = true; 4867 settings->impl_side_painting = true;
4886 4868
4887 EXPECT_FALSE(settings->gpu_rasterization_forced); 4869 EXPECT_FALSE(settings->gpu_rasterization_forced);
4888 settings->gpu_rasterization_forced = true; 4870 settings->gpu_rasterization_forced = true;
4889 } 4871 }
4890 4872
4891 virtual void SetupTree() override { 4873 void SetupTree() override {
4892 LayerTreeHostTest::SetupTree(); 4874 LayerTreeHostTest::SetupTree();
4893 4875
4894 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_); 4876 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_);
4895 layer->SetBounds(gfx::Size(10, 10)); 4877 layer->SetBounds(gfx::Size(10, 10));
4896 layer->SetIsDrawable(true); 4878 layer->SetIsDrawable(true);
4897 layer_tree_host()->root_layer()->AddChild(layer); 4879 layer_tree_host()->root_layer()->AddChild(layer);
4898 } 4880 }
4899 4881
4900 virtual void BeginTest() override { 4882 void BeginTest() override {
4901 Layer* root = layer_tree_host()->root_layer(); 4883 Layer* root = layer_tree_host()->root_layer();
4902 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); 4884 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0));
4903 PicturePile* pile = layer->GetPicturePileForTesting(); 4885 PicturePile* pile = layer->GetPicturePileForTesting();
4904 4886
4905 // Verify default values. 4887 // Verify default values.
4906 EXPECT_TRUE(root->IsSuitableForGpuRasterization()); 4888 EXPECT_TRUE(root->IsSuitableForGpuRasterization());
4907 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); 4889 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
4908 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization()); 4890 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization());
4909 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger()); 4891 EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
4910 4892
4911 // With gpu rasterization forced, gpu rasterization trigger is irrelevant. 4893 // With gpu rasterization forced, gpu rasterization trigger is irrelevant.
4912 EXPECT_TRUE(layer_tree_host()->UseGpuRasterization()); 4894 EXPECT_TRUE(layer_tree_host()->UseGpuRasterization());
4913 layer_tree_host()->SetHasGpuRasterizationTrigger(true); 4895 layer_tree_host()->SetHasGpuRasterizationTrigger(true);
4914 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger()); 4896 EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
4915 EXPECT_TRUE(layer_tree_host()->UseGpuRasterization()); 4897 EXPECT_TRUE(layer_tree_host()->UseGpuRasterization());
4916 4898
4917 // Content-based veto is irrelevant as well. 4899 // Content-based veto is irrelevant as well.
4918 pile->SetUnsuitableForGpuRasterizationForTesting(); 4900 pile->SetUnsuitableForGpuRasterizationForTesting();
4919 EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization()); 4901 EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization());
4920 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); 4902 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
4921 // Veto will take effect when layers are updated. 4903 // Veto will take effect when layers are updated.
4922 // The results will be verified after commit is completed below. 4904 // The results will be verified after commit is completed below.
4923 // Since we are manually marking picture pile as unsuitable, 4905 // Since we are manually marking picture pile as unsuitable,
4924 // make sure that the layer gets a chance to update. 4906 // make sure that the layer gets a chance to update.
4925 layer->SetNeedsDisplay(); 4907 layer->SetNeedsDisplay();
4926 PostSetNeedsCommitToMainThread(); 4908 PostSetNeedsCommitToMainThread();
4927 } 4909 }
4928 4910
4929 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 4911 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
4930 EXPECT_TRUE(host_impl->pending_tree()->use_gpu_rasterization()); 4912 EXPECT_TRUE(host_impl->pending_tree()->use_gpu_rasterization());
4931 EXPECT_TRUE(host_impl->use_gpu_rasterization()); 4913 EXPECT_TRUE(host_impl->use_gpu_rasterization());
4932 } 4914 }
4933 4915
4934 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 4916 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
4935 EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization()); 4917 EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization());
4936 EXPECT_TRUE(host_impl->use_gpu_rasterization()); 4918 EXPECT_TRUE(host_impl->use_gpu_rasterization());
4937 EndTest(); 4919 EndTest();
4938 } 4920 }
4939 4921
4940 virtual void AfterTest() override {} 4922 void AfterTest() override {}
4941 4923
4942 FakeContentLayerClient layer_client_; 4924 FakeContentLayerClient layer_client_;
4943 }; 4925 };
4944 4926
4945 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationForced); 4927 MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationForced);
4946 4928
4947 class LayerTreeHostTestContinuousPainting : public LayerTreeHostTest { 4929 class LayerTreeHostTestContinuousPainting : public LayerTreeHostTest {
4948 public: 4930 public:
4949 LayerTreeHostTestContinuousPainting() 4931 LayerTreeHostTestContinuousPainting()
4950 : num_commits_(0), num_draws_(0), bounds_(20, 20), child_layer_(NULL) {} 4932 : num_commits_(0), num_draws_(0), bounds_(20, 20), child_layer_(NULL) {}
4951 4933
4952 protected: 4934 protected:
4953 enum { kExpectedNumCommits = 10 }; 4935 enum { kExpectedNumCommits = 10 };
4954 4936
4955 virtual void SetupTree() override { 4937 void SetupTree() override {
4956 scoped_refptr<Layer> root_layer = Layer::Create(); 4938 scoped_refptr<Layer> root_layer = Layer::Create();
4957 root_layer->SetBounds(bounds_); 4939 root_layer->SetBounds(bounds_);
4958 4940
4959 if (layer_tree_host()->settings().impl_side_painting) { 4941 if (layer_tree_host()->settings().impl_side_painting) {
4960 picture_layer_ = FakePictureLayer::Create(&client_); 4942 picture_layer_ = FakePictureLayer::Create(&client_);
4961 child_layer_ = picture_layer_.get(); 4943 child_layer_ = picture_layer_.get();
4962 } else { 4944 } else {
4963 content_layer_ = ContentLayerWithUpdateTracking::Create(&client_); 4945 content_layer_ = ContentLayerWithUpdateTracking::Create(&client_);
4964 child_layer_ = content_layer_.get(); 4946 child_layer_ = content_layer_.get();
4965 } 4947 }
4966 child_layer_->SetBounds(bounds_); 4948 child_layer_->SetBounds(bounds_);
4967 child_layer_->SetIsDrawable(true); 4949 child_layer_->SetIsDrawable(true);
4968 root_layer->AddChild(child_layer_); 4950 root_layer->AddChild(child_layer_);
4969 4951
4970 layer_tree_host()->SetRootLayer(root_layer); 4952 layer_tree_host()->SetRootLayer(root_layer);
4971 layer_tree_host()->SetViewportSize(bounds_); 4953 layer_tree_host()->SetViewportSize(bounds_);
4972 LayerTreeHostTest::SetupTree(); 4954 LayerTreeHostTest::SetupTree();
4973 } 4955 }
4974 4956
4975 virtual void BeginTest() override { 4957 void BeginTest() override {
4976 MainThreadTaskRunner()->PostTask( 4958 MainThreadTaskRunner()->PostTask(
4977 FROM_HERE, 4959 FROM_HERE,
4978 base::Bind( 4960 base::Bind(
4979 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting, 4961 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting,
4980 base::Unretained(this))); 4962 base::Unretained(this)));
4981 // Wait 50x longer than expected. 4963 // Wait 50x longer than expected.
4982 double milliseconds_per_frame = 4964 double milliseconds_per_frame =
4983 1000.0 / layer_tree_host()->settings().refresh_rate; 4965 1000.0 / layer_tree_host()->settings().refresh_rate;
4984 MainThreadTaskRunner()->PostDelayedTask( 4966 MainThreadTaskRunner()->PostDelayedTask(
4985 FROM_HERE, 4967 FROM_HERE,
4986 base::Bind( 4968 base::Bind(
4987 &LayerTreeHostTestContinuousPainting::DisableContinuousPainting, 4969 &LayerTreeHostTestContinuousPainting::DisableContinuousPainting,
4988 base::Unretained(this)), 4970 base::Unretained(this)),
4989 base::TimeDelta::FromMilliseconds(50 * kExpectedNumCommits * 4971 base::TimeDelta::FromMilliseconds(50 * kExpectedNumCommits *
4990 milliseconds_per_frame)); 4972 milliseconds_per_frame));
4991 } 4973 }
4992 4974
4993 virtual void BeginMainFrame(const BeginFrameArgs& args) override { 4975 void BeginMainFrame(const BeginFrameArgs& args) override {
4994 child_layer_->SetNeedsDisplay(); 4976 child_layer_->SetNeedsDisplay();
4995 } 4977 }
4996 4978
4997 virtual void AfterTest() override { 4979 void AfterTest() override {
4998 EXPECT_LE(kExpectedNumCommits, num_commits_); 4980 EXPECT_LE(kExpectedNumCommits, num_commits_);
4999 EXPECT_LE(kExpectedNumCommits, num_draws_); 4981 EXPECT_LE(kExpectedNumCommits, num_draws_);
5000 int update_count = content_layer_.get() 4982 int update_count = content_layer_.get()
5001 ? content_layer_->PaintContentsCount() 4983 ? content_layer_->PaintContentsCount()
5002 : picture_layer_->update_count(); 4984 : picture_layer_->update_count();
5003 EXPECT_LE(kExpectedNumCommits, update_count); 4985 EXPECT_LE(kExpectedNumCommits, update_count);
5004 } 4986 }
5005 4987
5006 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 4988 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
5007 if (++num_draws_ == kExpectedNumCommits) 4989 if (++num_draws_ == kExpectedNumCommits)
5008 EndTest(); 4990 EndTest();
5009 } 4991 }
5010 4992
5011 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 4993 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
5012 ++num_commits_; 4994 ++num_commits_;
5013 } 4995 }
5014 4996
5015 private: 4997 private:
5016 void EnableContinuousPainting() { 4998 void EnableContinuousPainting() {
5017 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); 4999 LayerTreeDebugState debug_state = layer_tree_host()->debug_state();
5018 debug_state.continuous_painting = true; 5000 debug_state.continuous_painting = true;
5019 layer_tree_host()->SetDebugState(debug_state); 5001 layer_tree_host()->SetDebugState(debug_state);
5020 } 5002 }
5021 5003
(...skipping 13 matching lines...) Expand all
5035 Layer* child_layer_; 5017 Layer* child_layer_;
5036 }; 5018 };
5037 5019
5038 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); 5020 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting);
5039 5021
5040 class LayerTreeHostTestActivateOnInvisible : public LayerTreeHostTest { 5022 class LayerTreeHostTestActivateOnInvisible : public LayerTreeHostTest {
5041 public: 5023 public:
5042 LayerTreeHostTestActivateOnInvisible() 5024 LayerTreeHostTestActivateOnInvisible()
5043 : activation_count_(0), visible_(true) {} 5025 : activation_count_(0), visible_(true) {}
5044 5026
5045 virtual void InitializeSettings(LayerTreeSettings* settings) override { 5027 void InitializeSettings(LayerTreeSettings* settings) override {
5046 settings->impl_side_painting = true; 5028 settings->impl_side_painting = true;
5047 } 5029 }
5048 5030
5049 virtual void BeginTest() override { 5031 void BeginTest() override {
5050 // Kick off the test with a commit. 5032 // Kick off the test with a commit.
5051 PostSetNeedsCommitToMainThread(); 5033 PostSetNeedsCommitToMainThread();
5052 } 5034 }
5053 5035
5054 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { 5036 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
5055 // Make sure we don't activate using the notify signal from tile manager. 5037 // Make sure we don't activate using the notify signal from tile manager.
5056 host_impl->BlockNotifyReadyToActivateForTesting(true); 5038 host_impl->BlockNotifyReadyToActivateForTesting(true);
5057 } 5039 }
5058 5040
5059 virtual void DidCommit() override { layer_tree_host()->SetVisible(false); } 5041 void DidCommit() override { layer_tree_host()->SetVisible(false); }
5060 5042
5061 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, 5043 void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
5062 bool visible) override { 5044 bool visible) override {
5063 visible_ = visible; 5045 visible_ = visible;
5064 5046
5065 // Once invisible, we can go visible again. 5047 // Once invisible, we can go visible again.
5066 if (!visible) { 5048 if (!visible) {
5067 PostSetVisibleToMainThread(true); 5049 PostSetVisibleToMainThread(true);
5068 } else { 5050 } else {
5069 EXPECT_TRUE(host_impl->RequiresHighResToDraw()); 5051 EXPECT_TRUE(host_impl->RequiresHighResToDraw());
5070 EndTest(); 5052 EndTest();
5071 } 5053 }
5072 } 5054 }
5073 5055
5074 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 5056 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
5075 ++activation_count_; 5057 ++activation_count_;
5076 EXPECT_FALSE(visible_); 5058 EXPECT_FALSE(visible_);
5077 } 5059 }
5078 5060
5079 virtual void AfterTest() override { 5061 void AfterTest() override {
5080 // Ensure we activated even though the signal was blocked. 5062 // Ensure we activated even though the signal was blocked.
5081 EXPECT_EQ(1, activation_count_); 5063 EXPECT_EQ(1, activation_count_);
5082 EXPECT_TRUE(visible_); 5064 EXPECT_TRUE(visible_);
5083 } 5065 }
5084 5066
5085 private: 5067 private:
5086 int activation_count_; 5068 int activation_count_;
5087 bool visible_; 5069 bool visible_;
5088 5070
5089 FakeContentLayerClient client_; 5071 FakeContentLayerClient client_;
5090 scoped_refptr<FakePictureLayer> picture_layer_; 5072 scoped_refptr<FakePictureLayer> picture_layer_;
5091 }; 5073 };
5092 5074
5093 // TODO(vmpstr): Enable with single thread impl-side painting. 5075 // TODO(vmpstr): Enable with single thread impl-side painting.
5094 MULTI_THREAD_TEST_F(LayerTreeHostTestActivateOnInvisible); 5076 MULTI_THREAD_TEST_F(LayerTreeHostTestActivateOnInvisible);
5095 5077
5096 // Do a synchronous composite and assert that the swap promise succeeds. 5078 // Do a synchronous composite and assert that the swap promise succeeds.
5097 class LayerTreeHostTestSynchronousCompositeSwapPromise 5079 class LayerTreeHostTestSynchronousCompositeSwapPromise
5098 : public LayerTreeHostTest { 5080 : public LayerTreeHostTest {
5099 public: 5081 public:
5100 LayerTreeHostTestSynchronousCompositeSwapPromise() : commit_count_(0) {} 5082 LayerTreeHostTestSynchronousCompositeSwapPromise() : commit_count_(0) {}
5101 5083
5102 virtual void InitializeSettings(LayerTreeSettings* settings) override { 5084 void InitializeSettings(LayerTreeSettings* settings) override {
5103 settings->single_thread_proxy_scheduler = false; 5085 settings->single_thread_proxy_scheduler = false;
5104 } 5086 }
5105 5087
5106 virtual void BeginTest() override { 5088 void BeginTest() override {
5107 // Successful composite. 5089 // Successful composite.
5108 scoped_ptr<SwapPromise> swap_promise0( 5090 scoped_ptr<SwapPromise> swap_promise0(
5109 new TestSwapPromise(&swap_promise_result_[0])); 5091 new TestSwapPromise(&swap_promise_result_[0]));
5110 layer_tree_host()->QueueSwapPromise(swap_promise0.Pass()); 5092 layer_tree_host()->QueueSwapPromise(swap_promise0.Pass());
5111 layer_tree_host()->Composite(gfx::FrameTime::Now()); 5093 layer_tree_host()->Composite(gfx::FrameTime::Now());
5112 5094
5113 // Fail to swap (no damage). 5095 // Fail to swap (no damage).
5114 scoped_ptr<SwapPromise> swap_promise1( 5096 scoped_ptr<SwapPromise> swap_promise1(
5115 new TestSwapPromise(&swap_promise_result_[1])); 5097 new TestSwapPromise(&swap_promise_result_[1]));
5116 layer_tree_host()->QueueSwapPromise(swap_promise1.Pass()); 5098 layer_tree_host()->QueueSwapPromise(swap_promise1.Pass());
5117 layer_tree_host()->SetNeedsCommit(); 5099 layer_tree_host()->SetNeedsCommit();
5118 layer_tree_host()->Composite(gfx::FrameTime::Now()); 5100 layer_tree_host()->Composite(gfx::FrameTime::Now());
5119 5101
5120 // Fail to draw (not visible). 5102 // Fail to draw (not visible).
5121 scoped_ptr<SwapPromise> swap_promise2( 5103 scoped_ptr<SwapPromise> swap_promise2(
5122 new TestSwapPromise(&swap_promise_result_[2])); 5104 new TestSwapPromise(&swap_promise_result_[2]));
5123 layer_tree_host()->QueueSwapPromise(swap_promise2.Pass()); 5105 layer_tree_host()->QueueSwapPromise(swap_promise2.Pass());
5124 layer_tree_host()->SetNeedsDisplayOnAllLayers(); 5106 layer_tree_host()->SetNeedsDisplayOnAllLayers();
5125 layer_tree_host()->SetVisible(false); 5107 layer_tree_host()->SetVisible(false);
5126 layer_tree_host()->Composite(gfx::FrameTime::Now()); 5108 layer_tree_host()->Composite(gfx::FrameTime::Now());
5127 5109
5128 EndTest(); 5110 EndTest();
5129 } 5111 }
5130 5112
5131 virtual void DidCommit() override { 5113 void DidCommit() override {
5132 commit_count_++; 5114 commit_count_++;
5133 ASSERT_LE(commit_count_, 3); 5115 ASSERT_LE(commit_count_, 3);
5134 } 5116 }
5135 5117
5136 virtual void AfterTest() override { 5118 void AfterTest() override {
5137 EXPECT_EQ(3, commit_count_); 5119 EXPECT_EQ(3, commit_count_);
5138 5120
5139 // Initial swap promise should have succeded. 5121 // Initial swap promise should have succeded.
5140 { 5122 {
5141 base::AutoLock lock(swap_promise_result_[0].lock); 5123 base::AutoLock lock(swap_promise_result_[0].lock);
5142 EXPECT_TRUE(swap_promise_result_[0].did_swap_called); 5124 EXPECT_TRUE(swap_promise_result_[0].did_swap_called);
5143 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called); 5125 EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called);
5144 EXPECT_TRUE(swap_promise_result_[0].dtor_called); 5126 EXPECT_TRUE(swap_promise_result_[0].dtor_called);
5145 } 5127 }
5146 5128
(...skipping 17 matching lines...) Expand all
5164 } 5146 }
5165 5147
5166 int commit_count_; 5148 int commit_count_;
5167 TestSwapPromiseResult swap_promise_result_[3]; 5149 TestSwapPromiseResult swap_promise_result_[3];
5168 }; 5150 };
5169 5151
5170 // Impl-side painting is not supported for synchronous compositing. 5152 // Impl-side painting is not supported for synchronous compositing.
5171 SINGLE_THREAD_NOIMPL_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise); 5153 SINGLE_THREAD_NOIMPL_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise);
5172 5154
5173 } // namespace cc 5155 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_pixeltest_readback.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698