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

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

Issue 458153002: cc: Use impl-side painting code in LTH scroll layer test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated more tests. Created 6 years, 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "cc/layers/content_layer.h"
9 #include "cc/layers/layer.h" 8 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h" 9 #include "cc/layers/layer_impl.h"
10 #include "cc/layers/picture_layer.h"
11 #include "cc/test/fake_content_layer_client.h" 11 #include "cc/test/fake_content_layer_client.h"
12 #include "cc/test/fake_layer_tree_host_client.h" 12 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_picture_layer.h"
14 #include "cc/test/fake_picture_layer_impl.h"
13 #include "cc/test/geometry_test_utils.h" 15 #include "cc/test/geometry_test_utils.h"
14 #include "cc/test/layer_tree_test.h" 16 #include "cc/test/layer_tree_test.h"
15 #include "cc/test/test_shared_bitmap_manager.h" 17 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/layer_tree_impl.h" 18 #include "cc/trees/layer_tree_impl.h"
17 #include "ui/gfx/point_conversions.h" 19 #include "ui/gfx/point_conversions.h"
18 #include "ui/gfx/size_conversions.h" 20 #include "ui/gfx/size_conversions.h"
19 #include "ui/gfx/vector2d_conversions.h" 21 #include "ui/gfx/vector2d_conversions.h"
20 22
21 namespace cc { 23 namespace cc {
22 namespace { 24 namespace {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 javascript_scroll_(40, 5), 444 javascript_scroll_(40, 5),
443 scroll_amount_(2, -1), 445 scroll_amount_(2, -1),
444 num_scrolls_(0) {} 446 num_scrolls_(0) {}
445 447
446 virtual void SetupTree() OVERRIDE { 448 virtual void SetupTree() OVERRIDE {
447 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); 449 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
448 450
449 scoped_refptr<Layer> root_layer = Layer::Create(); 451 scoped_refptr<Layer> root_layer = Layer::Create();
450 root_layer->SetBounds(gfx::Size(10, 10)); 452 root_layer->SetBounds(gfx::Size(10, 10));
451 453
452 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); 454 root_scroll_layer_ = FakePictureLayer::Create(&fake_content_layer_client_);
453 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); 455 root_scroll_layer_->SetBounds(gfx::Size(110, 110));
454 456
455 root_scroll_layer_->SetPosition(gfx::Point()); 457 root_scroll_layer_->SetPosition(gfx::Point());
456 458
457 root_scroll_layer_->SetIsDrawable(true); 459 root_scroll_layer_->SetIsDrawable(true);
458 root_scroll_layer_->SetScrollClipLayerId(root_layer->id()); 460 root_scroll_layer_->SetScrollClipLayerId(root_layer->id());
459 root_scroll_layer_->SetIsContainerForFixedPositionLayers(true); 461 root_scroll_layer_->SetIsContainerForFixedPositionLayers(true);
460 root_layer->AddChild(root_scroll_layer_); 462 root_layer->AddChild(root_scroll_layer_);
461 463
462 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); 464 child_layer_ = FakePictureLayer::Create(&fake_content_layer_client_);
463 child_layer_->set_did_scroll_callback( 465 child_layer_->set_did_scroll_callback(
464 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, 466 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll,
465 base::Unretained(this))); 467 base::Unretained(this)));
466 child_layer_->SetBounds(gfx::Size(110, 110)); 468 child_layer_->SetBounds(gfx::Size(110, 110));
467 469
468 if (scroll_child_layer_) { 470 if (scroll_child_layer_) {
469 // Scrolls on the child layer will happen at 5, 5. If they are treated 471 // Scrolls on the child layer will happen at 5, 5. If they are treated
470 // like device pixels, and device scale factor is 2, then they will 472 // like device pixels, and device scale factor is 2, then they will
471 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. 473 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer.
472 child_layer_->SetPosition(gfx::Point(5, 5)); 474 child_layer_->SetPosition(gfx::Point(5, 5));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 break; 535 break;
534 case 2: 536 case 2:
535 EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, 537 EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_,
536 expected_scroll_layer_->scroll_offset()); 538 expected_scroll_layer_->scroll_offset());
537 break; 539 break;
538 } 540 }
539 } 541 }
540 542
541 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 543 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
542 LayerImpl* root_impl = impl->active_tree()->root_layer(); 544 LayerImpl* root_impl = impl->active_tree()->root_layer();
543 LayerImpl* root_scroll_layer_impl = root_impl->children()[0]; 545 FakePictureLayerImpl* root_scroll_layer_impl =
544 LayerImpl* child_layer_impl = root_scroll_layer_impl->children()[0]; 546 static_cast<FakePictureLayerImpl*>(root_impl->children()[0]);
547 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>(
548 root_scroll_layer_impl->children()[0]);
545 549
546 LayerImpl* expected_scroll_layer_impl = NULL; 550 LayerImpl* expected_scroll_layer_impl = NULL;
547 LayerImpl* expected_no_scroll_layer_impl = NULL; 551 LayerImpl* expected_no_scroll_layer_impl = NULL;
548 if (scroll_child_layer_) { 552 if (scroll_child_layer_) {
549 expected_scroll_layer_impl = child_layer_impl; 553 expected_scroll_layer_impl = child_layer_impl;
550 expected_no_scroll_layer_impl = root_scroll_layer_impl; 554 expected_no_scroll_layer_impl = root_scroll_layer_impl;
551 } else { 555 } else {
552 expected_scroll_layer_impl = root_scroll_layer_impl; 556 expected_scroll_layer_impl = root_scroll_layer_impl;
553 expected_no_scroll_layer_impl = child_layer_impl; 557 expected_no_scroll_layer_impl = child_layer_impl;
554 } 558 }
555 559
556 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->ScrollDelta()); 560 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->ScrollDelta());
557 EXPECT_VECTOR_EQ(gfx::Vector2d(), 561 EXPECT_VECTOR_EQ(gfx::Vector2d(),
558 expected_no_scroll_layer_impl->ScrollDelta()); 562 expected_no_scroll_layer_impl->ScrollDelta());
559 563
560 // Ensure device scale factor is affecting the layers. 564 // Ensure device scale factor is affecting the contents scale.
danakj 2014/08/12 13:26:46 I think the comment was fine as is.
sohanjg 2014/08/12 13:38:24 Done.
561 gfx::Size expected_content_bounds = gfx::ToCeiledSize( 565 EXPECT_FLOAT_EQ(device_scale_factor_,
562 gfx::ScaleSize(root_scroll_layer_impl->bounds(), device_scale_factor_)); 566 root_scroll_layer_impl->HighResTiling()->contents_scale());
563 EXPECT_SIZE_EQ(expected_content_bounds,
564 root_scroll_layer_->content_bounds());
565 567
566 expected_content_bounds = gfx::ToCeiledSize( 568 EXPECT_FLOAT_EQ(device_scale_factor_,
567 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_)); 569 child_layer_impl->HighResTiling()->contents_scale());
568 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->content_bounds());
569 570
570 switch (impl->active_tree()->source_frame_number()) { 571 switch (impl->active_tree()->source_frame_number()) {
571 case 0: { 572 case 0: {
572 // Gesture scroll on impl thread. 573 // Gesture scroll on impl thread.
573 InputHandler::ScrollStatus status = impl->ScrollBegin( 574 InputHandler::ScrollStatus status = impl->ScrollBegin(
574 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() - 575 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() -
575 gfx::Vector2dF(0.5f, 0.5f)), 576 gfx::Vector2dF(0.5f, 0.5f)),
576 InputHandler::Gesture); 577 InputHandler::Gesture);
577 EXPECT_EQ(InputHandler::ScrollStarted, status); 578 EXPECT_EQ(InputHandler::ScrollStarted, status);
578 impl->ScrollBy(gfx::Point(), scroll_amount_); 579 impl->ScrollBy(gfx::Point(), scroll_amount_);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 scoped_refptr<Layer> root_scroll_layer_; 641 scoped_refptr<Layer> root_scroll_layer_;
641 scoped_refptr<Layer> child_layer_; 642 scoped_refptr<Layer> child_layer_;
642 scoped_refptr<Layer> expected_scroll_layer_; 643 scoped_refptr<Layer> expected_scroll_layer_;
643 scoped_refptr<Layer> expected_no_scroll_layer_; 644 scoped_refptr<Layer> expected_no_scroll_layer_;
644 }; 645 };
645 646
646 TEST_F(LayerTreeHostScrollTestCaseWithChild, 647 TEST_F(LayerTreeHostScrollTestCaseWithChild,
647 DeviceScaleFactor1_ScrollChild_DirectRenderer_MainThreadPaint) { 648 DeviceScaleFactor1_ScrollChild_DirectRenderer_MainThreadPaint) {
648 device_scale_factor_ = 1.f; 649 device_scale_factor_ = 1.f;
649 scroll_child_layer_ = true; 650 scroll_child_layer_ = true;
650 RunTest(true, false, false); 651 RunTest(true, false, true);
danakj 2014/08/12 13:26:46 This test case is the same as the _ImplSidePaint b
sohanjg 2014/08/12 13:38:23 Done.
651 } 652 }
652 653
653 TEST_F(LayerTreeHostScrollTestCaseWithChild, 654 TEST_F(LayerTreeHostScrollTestCaseWithChild,
654 DeviceScaleFactor1_ScrollChild_DirectRenderer_ImplSidePaint) { 655 DeviceScaleFactor1_ScrollChild_DirectRenderer_ImplSidePaint) {
655 device_scale_factor_ = 1.f; 656 device_scale_factor_ = 1.f;
656 scroll_child_layer_ = true; 657 scroll_child_layer_ = true;
657 RunTest(true, false, true); 658 RunTest(true, false, true);
658 } 659 }
659 660
660 TEST_F(LayerTreeHostScrollTestCaseWithChild, 661 TEST_F(LayerTreeHostScrollTestCaseWithChild,
661 DeviceScaleFactor1_ScrollChild_DelegatingRenderer_MainThreadPaint) { 662 DeviceScaleFactor1_ScrollChild_DelegatingRenderer_MainThreadPaint) {
662 device_scale_factor_ = 1.f; 663 device_scale_factor_ = 1.f;
663 scroll_child_layer_ = true; 664 scroll_child_layer_ = true;
664 RunTest(true, true, false); 665 RunTest(true, true, true);
danakj 2014/08/12 13:26:46 same
sohanjg 2014/08/12 13:38:23 Done.
665 } 666 }
666 667
667 TEST_F(LayerTreeHostScrollTestCaseWithChild, 668 TEST_F(LayerTreeHostScrollTestCaseWithChild,
668 DeviceScaleFactor1_ScrollChild_DelegatingRenderer_ImplSidePaint) { 669 DeviceScaleFactor1_ScrollChild_DelegatingRenderer_ImplSidePaint) {
669 device_scale_factor_ = 1.f; 670 device_scale_factor_ = 1.f;
670 scroll_child_layer_ = true; 671 scroll_child_layer_ = true;
671 RunTest(true, true, true); 672 RunTest(true, true, true);
672 } 673 }
673 674
674 TEST_F(LayerTreeHostScrollTestCaseWithChild, 675 TEST_F(LayerTreeHostScrollTestCaseWithChild,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 DeviceScaleFactor15_ScrollRootScrollLayer_DelegatingRenderer) { 725 DeviceScaleFactor15_ScrollRootScrollLayer_DelegatingRenderer) {
725 device_scale_factor_ = 1.5f; 726 device_scale_factor_ = 1.5f;
726 scroll_child_layer_ = false; 727 scroll_child_layer_ = false;
727 RunTest(true, true, true); 728 RunTest(true, true, true);
728 } 729 }
729 730
730 TEST_F(LayerTreeHostScrollTestCaseWithChild, 731 TEST_F(LayerTreeHostScrollTestCaseWithChild,
731 DeviceScaleFactor2_ScrollRootScrollLayer_DirectRenderer_MainSidePaint) { 732 DeviceScaleFactor2_ScrollRootScrollLayer_DirectRenderer_MainSidePaint) {
732 device_scale_factor_ = 2.f; 733 device_scale_factor_ = 2.f;
733 scroll_child_layer_ = false; 734 scroll_child_layer_ = false;
734 RunTest(true, false, false); 735 RunTest(true, false, true);
danakj 2014/08/12 13:26:46 same
sohanjg 2014/08/12 13:38:24 Done.
735 } 736 }
736 737
737 TEST_F(LayerTreeHostScrollTestCaseWithChild, 738 TEST_F(LayerTreeHostScrollTestCaseWithChild,
738 DeviceScaleFactor2_ScrollRootScrollLayer_DirectRenderer_ImplSidePaint) { 739 DeviceScaleFactor2_ScrollRootScrollLayer_DirectRenderer_ImplSidePaint) {
739 device_scale_factor_ = 2.f; 740 device_scale_factor_ = 2.f;
740 scroll_child_layer_ = false; 741 scroll_child_layer_ = false;
741 RunTest(true, false, true); 742 RunTest(true, false, true);
742 } 743 }
743 744
744 TEST_F(LayerTreeHostScrollTestCaseWithChild, 745 TEST_F(LayerTreeHostScrollTestCaseWithChild,
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 class FakeLayerScrollClient { 1198 class FakeLayerScrollClient {
1198 public: 1199 public:
1199 void DidScroll() { 1200 void DidScroll() {
1200 owner_->DidScroll(layer_); 1201 owner_->DidScroll(layer_);
1201 } 1202 }
1202 LayerTreeHostScrollTestLayerStructureChange* owner_; 1203 LayerTreeHostScrollTestLayerStructureChange* owner_;
1203 Layer* layer_; 1204 Layer* layer_;
1204 }; 1205 };
1205 1206
1206 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) { 1207 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) {
1207 scoped_refptr<Layer> scroll_layer = 1208 scoped_refptr<PictureLayer> scroll_layer =
1208 ContentLayer::Create(&fake_content_layer_client_); 1209 PictureLayer::Create(&fake_content_layer_client_);
1209 scroll_layer->SetBounds(gfx::Size(110, 110)); 1210 scroll_layer->SetBounds(gfx::Size(110, 110));
1210 scroll_layer->SetPosition(gfx::Point(0, 0)); 1211 scroll_layer->SetPosition(gfx::Point(0, 0));
1211 scroll_layer->SetIsDrawable(true); 1212 scroll_layer->SetIsDrawable(true);
1212 scroll_layer->SetScrollClipLayerId(parent->id()); 1213 scroll_layer->SetScrollClipLayerId(parent->id());
1213 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100, 1214 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100,
1214 parent->bounds().height() + 100)); 1215 parent->bounds().height() + 100));
1215 scroll_layer->set_did_scroll_callback(base::Bind( 1216 scroll_layer->set_did_scroll_callback(base::Bind(
1216 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); 1217 &FakeLayerScrollClient::DidScroll, base::Unretained(client)));
1217 client->owner_ = this; 1218 client->owner_ = this;
1218 client->layer_ = scroll_layer.get(); 1219 client->layer_ = scroll_layer.get();
1219 parent->AddChild(scroll_layer); 1220 parent->AddChild(scroll_layer);
1220 return scroll_layer.get(); 1221 return scroll_layer.get();
1221 } 1222 }
1222 1223
1223 FakeLayerScrollClient root_scroll_layer_client_; 1224 FakeLayerScrollClient root_scroll_layer_client_;
1224 FakeLayerScrollClient sibling_scroll_layer_client_; 1225 FakeLayerScrollClient sibling_scroll_layer_client_;
1225 FakeLayerScrollClient child_scroll_layer_client_; 1226 FakeLayerScrollClient child_scroll_layer_client_;
1226 1227
1227 FakeContentLayerClient fake_content_layer_client_; 1228 FakeContentLayerClient fake_content_layer_client_;
1228 1229
1229 bool scroll_destroy_whole_tree_; 1230 bool scroll_destroy_whole_tree_;
1230 }; 1231 };
1231 1232
1232 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { 1233 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) {
1233 RunTest(true, false, false); 1234 RunTest(true, false, true);
1234 } 1235 }
1235 1236
1236 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1237 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1237 scroll_destroy_whole_tree_ = true; 1238 scroll_destroy_whole_tree_ = true;
danakj 2014/08/12 13:26:46 This should be a 2space indent.. mind fixing it wh
sohanjg 2014/08/12 13:38:24 Done. strange why the cl format, didnt take care o
1238 RunTest(true, false, false); 1239 RunTest(true, false, true);
1239 } 1240 }
1240 1241
1241 } // namespace 1242 } // namespace
1242 } // namespace cc 1243 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698