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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « cc/trees/layer_tree_host_unittest_occlusion.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/test/fake_content_layer_client.h" 7 #include "cc/test/fake_content_layer_client.h"
8 #include "cc/test/fake_picture_layer.h" 8 #include "cc/test/fake_picture_layer.h"
9 #include "cc/test/fake_picture_layer_impl.h" 9 #include "cc/test/fake_picture_layer_impl.h"
10 #include "cc/test/layer_tree_test.h" 10 #include "cc/test/layer_tree_test.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 ++activates_; 130 ++activates_;
131 } 131 }
132 132
133 void AfterTest() override { EXPECT_EQ(5, activates_); } 133 void AfterTest() override { EXPECT_EQ(5, activates_); }
134 134
135 int activates_; 135 int activates_;
136 }; 136 };
137 137
138 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer); 138 // There is no pending layers in single thread mode.
139 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer);
139 140
140 class LayerTreeHostPictureTestResizeViewportWithGpuRaster 141 class LayerTreeHostPictureTestResizeViewportWithGpuRaster
141 : public LayerTreeHostPictureTest { 142 : public LayerTreeHostPictureTest {
142 void InitializeSettings(LayerTreeSettings* settings) override { 143 void InitializeSettings(LayerTreeSettings* settings) override {
143 settings->gpu_rasterization_forced = true; 144 settings->gpu_rasterization_forced = true;
144 } 145 }
145 146
146 void SetupTree() override { 147 void SetupTree() override {
147 scoped_refptr<Layer> root = Layer::Create(); 148 scoped_refptr<Layer> root = Layer::Create();
148 root->SetBounds(gfx::Size(768, 960)); 149 root->SetBounds(gfx::Size(768, 960));
149 150
150 client_.set_fill_with_nonsolid_color(true); 151 client_.set_fill_with_nonsolid_color(true);
151 picture_ = FakePictureLayer::Create(&client_); 152 picture_ = FakePictureLayer::Create(&client_);
152 picture_->SetBounds(gfx::Size(768, 960)); 153 picture_->SetBounds(gfx::Size(768, 960));
153 root->AddChild(picture_); 154 root->AddChild(picture_);
154 155
155 layer_tree_host()->SetRootLayer(root); 156 layer_tree_host()->SetRootLayer(root);
156 LayerTreeHostPictureTest::SetupTree(); 157 LayerTreeHostPictureTest::SetupTree();
157 } 158 }
158 159
159 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 160 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
160 161
161 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 162 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
162 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0]; 163 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
163 FakePictureLayerImpl* picture_impl = 164 FakePictureLayerImpl* picture_impl =
164 static_cast<FakePictureLayerImpl*>(child); 165 static_cast<FakePictureLayerImpl*>(child);
165 gfx::Size tile_size = 166 gfx::Size tile_size =
166 picture_impl->HighResTiling()->TileAt(0, 0)->content_rect().size(); 167 picture_impl->HighResTiling()->TileAt(0, 0)->content_rect().size();
167 168
168 switch (impl->sync_tree()->source_frame_number()) { 169 switch (impl->sync_tree()->source_frame_number()) {
169 case 0: 170 case 0:
170 tile_size_ = tile_size; 171 tile_size_ = tile_size;
171 // GPU Raster picks a tile size based on the viewport size. 172 // GPU Raster picks a tile size based on the viewport size.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 318 }
318 319
319 void AfterTest() override {} 320 void AfterTest() override {}
320 321
321 int frame_; 322 int frame_;
322 bool did_post_commit_; 323 bool did_post_commit_;
323 FakeContentLayerClient client_; 324 FakeContentLayerClient client_;
324 scoped_refptr<FakePictureLayer> picture_; 325 scoped_refptr<FakePictureLayer> picture_;
325 }; 326 };
326 327
327 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( 328 // Multi-thread only since there is no recycle tree in single thread.
329 MULTI_THREAD_IMPL_TEST_F(
328 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree); 330 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree);
329 331
332 class LayerTreeHostPictureTestRSLLMembership : public LayerTreeHostPictureTest {
333 void SetupTree() override {
334 scoped_refptr<Layer> root = Layer::Create();
335 root->SetBounds(gfx::Size(100, 100));
336
337 child_ = Layer::Create();
338 root->AddChild(child_);
339
340 // Don't be solid color so the layer has tilings/tiles.
341 client_.set_fill_with_nonsolid_color(true);
342 picture_ = FakePictureLayer::Create(&client_);
343 picture_->SetBounds(gfx::Size(100, 100));
344 child_->AddChild(picture_);
345
346 layer_tree_host()->SetRootLayer(root);
347 LayerTreeHostPictureTest::SetupTree();
348 }
349
350 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
351
352 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
353 LayerImpl* root = impl->sync_tree()->root_layer();
354 LayerImpl* child = root->children()[0];
355 LayerImpl* gchild = child->children()[0];
356 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
357
358 switch (impl->sync_tree()->source_frame_number()) {
359 case 0:
360 // On 1st commit the layer has tilings.
361 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
362 break;
363 case 1:
364 // On 2nd commit, the layer is transparent, but its tilings are left
365 // there.
366 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
367 break;
368 case 2:
369 // On 3rd commit, the layer is visible again, so has tilings.
370 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
371 }
372 }
373
374 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
375 LayerImpl* root = impl->active_tree()->root_layer();
376 LayerImpl* child = root->children()[0];
377 LayerImpl* gchild = child->children()[0];
378 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
379
380 switch (impl->active_tree()->source_frame_number()) {
381 case 0:
382 // On 1st commit the layer has tilings.
383 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
384 break;
385 case 1:
386 // On 2nd commit, the layer is transparent, but its tilings are left
387 // there.
388 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
389 break;
390 case 2:
391 // On 3rd commit, the layer is visible again, so has tilings.
392 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
393 EndTest();
394 }
395 }
396
397 void DidCommit() override {
398 switch (layer_tree_host()->source_frame_number()) {
399 case 1:
400 // For the 2nd commit, change opacity to 0 so that the layer will not be
401 // part of the visible frame.
402 child_->SetOpacity(0.f);
403 break;
404 case 2:
405 // For the 3rd commit, change opacity to 1 so that the layer will again
406 // be part of the visible frame.
407 child_->SetOpacity(1.f);
408 }
409 }
410
411 void AfterTest() override {}
412
413 FakeContentLayerClient client_;
414 scoped_refptr<Layer> child_;
415 scoped_refptr<FakePictureLayer> picture_;
416 };
417
418 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestRSLLMembership);
419
420 class LayerTreeHostPictureTestRSLLMembershipWithScale
421 : public LayerTreeHostPictureTest {
422 void SetupTree() override {
423 scoped_refptr<Layer> root = Layer::Create();
424 root->SetBounds(gfx::Size(100, 100));
425
426 pinch_ = Layer::Create();
427 pinch_->SetBounds(gfx::Size(500, 500));
428 pinch_->SetScrollClipLayerId(root->id());
429 pinch_->SetIsContainerForFixedPositionLayers(true);
430 root->AddChild(pinch_);
431
432 // Don't be solid color so the layer has tilings/tiles.
433 client_.set_fill_with_nonsolid_color(true);
434 picture_ = FakePictureLayer::Create(&client_);
435 picture_->SetBounds(gfx::Size(100, 100));
436 pinch_->AddChild(picture_);
437
438 layer_tree_host()->RegisterViewportLayers(NULL, root, pinch_, pinch_);
439 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
440 layer_tree_host()->SetRootLayer(root);
441 LayerTreeHostPictureTest::SetupTree();
442 }
443
444 void InitializeSettings(LayerTreeSettings* settings) override {
445 settings->layer_transforms_should_scale_layer_contents = true;
446 }
447
448 void BeginTest() override {
449 frame_ = 0;
450 draws_in_frame_ = 0;
451 last_frame_drawn_ = -1;
452 PostSetNeedsCommitToMainThread();
453 }
454
455 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
456 LayerImpl* root = impl->sync_tree()->root_layer();
457 LayerImpl* pinch = root->children()[0];
458 LayerImpl* gchild = pinch->children()[0];
459 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
460
461 switch (frame_) {
462 case 0:
463 // On 1st commit the layer has tilings.
464 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
465 break;
466 case 1:
467 // On 2nd commit, the layer is transparent, so does not have tilings.
468 EXPECT_EQ(0u, picture->tilings()->num_tilings());
469 break;
470 case 2:
471 // On 3rd commit, the layer is visible again, so has tilings.
472 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
473 }
474 }
475
476 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
477 LayerImpl* root = impl->active_tree()->root_layer();
478 LayerImpl* pinch = root->children()[0];
479 LayerImpl* gchild = pinch->children()[0];
480 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
481
482 if (frame_ != last_frame_drawn_)
483 draws_in_frame_ = 0;
484 ++draws_in_frame_;
485 last_frame_drawn_ = frame_;
486
487 switch (frame_) {
488 case 0:
489 if (draws_in_frame_ == 1) {
490 // On 1st commit the layer has tilings.
491 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
492 EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale());
493
494 // Pinch zoom in to change the scale on the active tree.
495 impl->PinchGestureBegin();
496 impl->PinchGestureUpdate(2.f, gfx::Point(1, 1));
497 impl->PinchGestureEnd();
498 } else if (picture->tilings()->num_tilings() == 1) {
499 // If the pinch gesture caused a commit we could get here with a
500 // pending tree.
501 EXPECT_FALSE(impl->pending_tree());
502 // The active layer now has only a 2.f scale tiling, which means the
503 // recycled layer's tiling is destroyed.
504 EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale());
505 EXPECT_EQ(0u, picture->GetRecycledTwinLayer()
506 ->picture_layer_tiling_set()
507 ->num_tilings());
508
509 ++frame_;
510 MainThreadTaskRunner()->PostTask(
511 FROM_HERE,
512 base::Bind(
513 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep,
514 base::Unretained(this)));
515 }
516 break;
517 case 1:
518 EXPECT_EQ(1, draws_in_frame_);
519 // On 2nd commit, the layer is transparent, so does not create
520 // tilings. Since the 1.f tiling was destroyed in the recycle tree, it
521 // has no tilings left. This is propogated to the active tree.
522 EXPECT_EQ(0u, picture->picture_layer_tiling_set()->num_tilings());
523 EXPECT_EQ(0u, picture->GetRecycledTwinLayer()
524 ->picture_layer_tiling_set()
525 ->num_tilings());
526 ++frame_;
527 MainThreadTaskRunner()->PostTask(
528 FROM_HERE,
529 base::Bind(
530 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep,
531 base::Unretained(this)));
532 break;
533 case 2:
534 EXPECT_EQ(1, draws_in_frame_);
535 // On 3rd commit, the layer is visible again, so has tilings.
536 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
537 EndTest();
538 }
539 }
540
541 void NextStep() {
542 switch (frame_) {
543 case 1:
544 // For the 2nd commit, change opacity to 0 so that the layer will not be
545 // part of the visible frame.
546 pinch_->SetOpacity(0.f);
547 break;
548 case 2:
549 // For the 3rd commit, change opacity to 1 so that the layer will again
550 // be part of the visible frame.
551 pinch_->SetOpacity(1.f);
552 break;
553 }
554 }
555
556 void AfterTest() override {}
557
558 FakeContentLayerClient client_;
559 scoped_refptr<Layer> pinch_;
560 scoped_refptr<FakePictureLayer> picture_;
561 int frame_;
562 int draws_in_frame_;
563 int last_frame_drawn_;
564 };
565
566 // Multi-thread only because in single thread you can't pinch zoom on the
567 // compositor thread.
568 MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestRSLLMembershipWithScale);
569
330 } // namespace 570 } // namespace
331 } // namespace cc 571 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest_occlusion.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698