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

Side by Side Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 2251143002: cc: Reland Move data to LayerTree from LayerTreeHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better fix? Created 4 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
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 8
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "cc/animation/animation_host.h" 10 #include "cc/animation/animation_host.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 LayerTreeHost::InitParams params; 115 LayerTreeHost::InitParams params;
116 params.client = &fake_client_; 116 params.client = &fake_client_;
117 params.settings = &layer_tree_settings_; 117 params.settings = &layer_tree_settings_;
118 params.task_graph_runner = &task_graph_runner_; 118 params.task_graph_runner = &task_graph_runner_;
119 params.animation_host = 119 params.animation_host =
120 AnimationHost::CreateForTesting(ThreadInstance::MAIN); 120 AnimationHost::CreateForTesting(ThreadInstance::MAIN);
121 121
122 layer_tree_host_.reset( 122 layer_tree_host_.reset(
123 new FakeResourceTrackingLayerTreeHost(&fake_client_, &params)); 123 new FakeResourceTrackingLayerTreeHost(&fake_client_, &params));
124 layer_tree_ = layer_tree_host_->GetLayerTree();
124 layer_tree_host_->SetVisible(true); 125 layer_tree_host_->SetVisible(true);
125 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); 126 fake_client_.SetLayerTreeHost(layer_tree_host_.get());
126 // Force output surface creation for renderer capabilities. 127 // Force output surface creation for renderer capabilities.
127 layer_tree_host_->Composite(base::TimeTicks()); 128 layer_tree_host_->Composite(base::TimeTicks());
128 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); 129 EXPECT_FALSE(layer_tree_host_->output_surface_lost());
129 } 130 }
130 131
131 LayerImpl* LayerImplForScrollAreaAndScrollbar( 132 LayerImpl* LayerImplForScrollAreaAndScrollbar(
132 FakeLayerTreeHost* host, 133 FakeLayerTreeHost* host,
133 std::unique_ptr<Scrollbar> scrollbar, 134 std::unique_ptr<Scrollbar> scrollbar,
(...skipping 19 matching lines...) Expand all
153 host->SetRootLayer(layer_tree_root); 154 host->SetRootLayer(layer_tree_root);
154 host->BuildPropertyTreesForTesting(); 155 host->BuildPropertyTreesForTesting();
155 return host->CommitAndCreateLayerImplTree(); 156 return host->CommitAndCreateLayerImplTree();
156 } 157 }
157 158
158 protected: 159 protected:
159 FakeLayerTreeHostClient fake_client_; 160 FakeLayerTreeHostClient fake_client_;
160 TestTaskGraphRunner task_graph_runner_; 161 TestTaskGraphRunner task_graph_runner_;
161 LayerTreeSettings layer_tree_settings_; 162 LayerTreeSettings layer_tree_settings_;
162 std::unique_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; 163 std::unique_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_;
164 LayerTree* layer_tree_;
163 int scrollbar_layer_id_; 165 int scrollbar_layer_id_;
164 }; 166 };
165 167
166 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 168 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
167 // Create and attach a non-overlay scrollbar. 169 // Create and attach a non-overlay scrollbar.
168 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); 170 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar);
169 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 171 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
170 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); 172 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0);
171 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 173 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
172 static_cast<PaintedScrollbarLayerImpl*>( 174 static_cast<PaintedScrollbarLayerImpl*>(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( 216 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create(
215 std::move(scrollbar), layer_tree_root->id()); 217 std::move(scrollbar), layer_tree_root->id());
216 218
217 // Choose bounds to give max_scroll_offset = (30, 50). 219 // Choose bounds to give max_scroll_offset = (30, 50).
218 layer_tree_root->SetBounds(gfx::Size(70, 150)); 220 layer_tree_root->SetBounds(gfx::Size(70, 150));
219 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 221 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
220 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); 222 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20));
221 scroll_layer->SetBounds(gfx::Size(100, 200)); 223 scroll_layer->SetBounds(gfx::Size(100, 200));
222 content_layer->SetBounds(gfx::Size(100, 200)); 224 content_layer->SetBounds(gfx::Size(100, 200));
223 225
224 layer_tree_host_->SetRootLayer(layer_tree_root); 226 layer_tree_->SetRootLayer(layer_tree_root);
225 layer_tree_root->AddChild(scroll_layer); 227 layer_tree_root->AddChild(scroll_layer);
226 scroll_layer->AddChild(content_layer); 228 scroll_layer->AddChild(content_layer);
227 layer_tree_root->AddChild(scrollbar_layer); 229 layer_tree_root->AddChild(scrollbar_layer);
228 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 230 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
229 231
230 layer_tree_root->SavePaintProperties(); 232 layer_tree_root->SavePaintProperties();
231 content_layer->SavePaintProperties(); 233 content_layer->SavePaintProperties();
232
233 layer_tree_host_->UpdateLayers(); 234 layer_tree_host_->UpdateLayers();
234 LayerImpl* layer_impl_tree_root = 235 LayerImpl* layer_impl_tree_root =
235 layer_tree_host_->CommitAndCreateLayerImplTree(); 236 layer_tree_host_->CommitAndCreateLayerImplTree();
236 237
237 ScrollbarLayerImplBase* cc_scrollbar_layer = 238 ScrollbarLayerImplBase* cc_scrollbar_layer =
238 static_cast<PaintedScrollbarLayerImpl*>( 239 static_cast<PaintedScrollbarLayerImpl*>(
239 layer_impl_tree_root->layer_tree_impl()->LayerById( 240 layer_impl_tree_root->layer_tree_impl()->LayerById(
240 scrollbar_layer->id())); 241 scrollbar_layer->id()));
241 242
242 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 243 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 scoped_refptr<Layer> content_layer = Layer::Create(); 284 scoped_refptr<Layer> content_layer = Layer::Create();
284 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 285 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
285 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 286 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
286 287
287 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 288 root_layer->SetScrollClipLayerId(root_clip_layer->id());
288 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 289 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
289 root_clip_layer->SetBounds(gfx::Size(20, 50)); 290 root_clip_layer->SetBounds(gfx::Size(20, 50));
290 root_layer->SetBounds(gfx::Size(100, 50)); 291 root_layer->SetBounds(gfx::Size(100, 50));
291 content_layer->SetBounds(gfx::Size(100, 50)); 292 content_layer->SetBounds(gfx::Size(100, 50));
292 293
293 layer_tree_host_->SetRootLayer(root_clip_layer); 294 layer_tree_->SetRootLayer(root_clip_layer);
294 root_clip_layer->AddChild(root_layer); 295 root_clip_layer->AddChild(root_layer);
295 root_layer->AddChild(content_layer); 296 root_layer->AddChild(content_layer);
296 root_layer->AddChild(scrollbar_layer); 297 root_layer->AddChild(scrollbar_layer);
297 298
298 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 299 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
299 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 300 scrollbar_layer->SetBounds(gfx::Size(70, 10));
300 scrollbar_layer->SetScrollLayer(root_layer->id()); 301 scrollbar_layer->SetScrollLayer(root_layer->id());
301 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 302 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
302 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 303 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
303 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 304 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
(...skipping 18 matching lines...) Expand all
322 scoped_refptr<Layer> content_layer = Layer::Create(); 323 scoped_refptr<Layer> content_layer = Layer::Create();
323 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 324 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
324 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 325 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
325 326
326 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 327 root_layer->SetScrollClipLayerId(root_clip_layer->id());
327 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 328 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
328 root_clip_layer->SetBounds(gfx::Size(20, 50)); 329 root_clip_layer->SetBounds(gfx::Size(20, 50));
329 root_layer->SetBounds(gfx::Size(100, 50)); 330 root_layer->SetBounds(gfx::Size(100, 50));
330 content_layer->SetBounds(gfx::Size(100, 50)); 331 content_layer->SetBounds(gfx::Size(100, 50));
331 332
332 layer_tree_host_->SetRootLayer(root_clip_layer); 333 layer_tree_->SetRootLayer(root_clip_layer);
333 root_clip_layer->AddChild(root_layer); 334 root_clip_layer->AddChild(root_layer);
334 root_layer->AddChild(content_layer); 335 root_layer->AddChild(content_layer);
335 root_layer->AddChild(scrollbar_layer); 336 root_layer->AddChild(scrollbar_layer);
336 337
337 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 338 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
338 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 339 scrollbar_layer->SetBounds(gfx::Size(70, 10));
339 scrollbar_layer->SetScrollLayer(root_layer->id()); 340 scrollbar_layer->SetScrollLayer(root_layer->id());
340 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 341 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
341 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 342 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
342 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 343 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 scoped_refptr<Layer> child1 = Layer::Create(); 468 scoped_refptr<Layer> child1 = Layer::Create();
468 scoped_refptr<Layer> child2; 469 scoped_refptr<Layer> child2;
469 const bool kIsLeftSideVerticalScrollbar = false; 470 const bool kIsLeftSideVerticalScrollbar = false;
470 child2 = SolidColorScrollbarLayer::Create( 471 child2 = SolidColorScrollbarLayer::Create(
471 scrollbar->Orientation(), kThumbThickness, kTrackStart, 472 scrollbar->Orientation(), kThumbThickness, kTrackStart,
472 kIsLeftSideVerticalScrollbar, child1->id()); 473 kIsLeftSideVerticalScrollbar, child1->id());
473 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 474 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
474 scroll_layer->AddChild(child1); 475 scroll_layer->AddChild(child1);
475 scroll_layer->InsertChild(child2, 1); 476 scroll_layer->InsertChild(child2, 1);
476 layer_tree_root->AddChild(scroll_layer); 477 layer_tree_root->AddChild(scroll_layer);
477 layer_tree_host_->SetRootLayer(layer_tree_root); 478 layer_tree_->SetRootLayer(layer_tree_root);
478 479
479 // Choose layer bounds to give max_scroll_offset = (8, 8). 480 // Choose layer bounds to give max_scroll_offset = (8, 8).
480 layer_tree_root->SetBounds(gfx::Size(2, 2)); 481 layer_tree_root->SetBounds(gfx::Size(2, 2));
481 scroll_layer->SetBounds(gfx::Size(10, 10)); 482 scroll_layer->SetBounds(gfx::Size(10, 10));
482 483
483 layer_tree_host_->UpdateLayers(); 484 layer_tree_host_->UpdateLayers();
484 485
485 LayerImpl* layer_impl_tree_root = 486 LayerImpl* layer_impl_tree_root =
486 layer_tree_host_->CommitAndCreateLayerImplTree(); 487 layer_tree_host_->CommitAndCreateLayerImplTree();
487 LayerImpl* scroll_layer_impl = 488 LayerImpl* scroll_layer_impl =
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 scoped_refptr<Layer> child1 = Layer::Create(); 521 scoped_refptr<Layer> child1 = Layer::Create();
521 scoped_refptr<Layer> scrollbar_layer; 522 scoped_refptr<Layer> scrollbar_layer;
522 const bool kIsLeftSideVerticalScrollbar = false; 523 const bool kIsLeftSideVerticalScrollbar = false;
523 scrollbar_layer = SolidColorScrollbarLayer::Create( 524 scrollbar_layer = SolidColorScrollbarLayer::Create(
524 scrollbar->Orientation(), kThumbThickness, kTrackStart, 525 scrollbar->Orientation(), kThumbThickness, kTrackStart,
525 kIsLeftSideVerticalScrollbar, child1->id()); 526 kIsLeftSideVerticalScrollbar, child1->id());
526 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 527 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
527 scroll_layer->AddChild(child1); 528 scroll_layer->AddChild(child1);
528 scroll_layer->InsertChild(scrollbar_layer, 1); 529 scroll_layer->InsertChild(scrollbar_layer, 1);
529 layer_tree_root->AddChild(scroll_layer); 530 layer_tree_root->AddChild(scroll_layer);
530 layer_tree_host_->SetRootLayer(layer_tree_root); 531 layer_tree_->SetRootLayer(layer_tree_root);
531 532
532 // Choose layer bounds to give max_scroll_offset = (8, 8). 533 // Choose layer bounds to give max_scroll_offset = (8, 8).
533 layer_tree_root->SetBounds(gfx::Size(2, 2)); 534 layer_tree_root->SetBounds(gfx::Size(2, 2));
534 scroll_layer->SetBounds(gfx::Size(10, 10)); 535 scroll_layer->SetBounds(gfx::Size(10, 10));
535 536
536 // Building property trees twice shouldn't change the size of 537 // Building property trees twice shouldn't change the size of
537 // PropertyTrees::always_use_active_tree_opacity_effect_ids. 538 // PropertyTrees::always_use_active_tree_opacity_effect_ids.
538 layer_tree_host_->BuildPropertyTreesForTesting(); 539 layer_tree_host_->BuildPropertyTreesForTesting();
539 EXPECT_EQ(layer_tree_host_->property_trees() 540 EXPECT_EQ(layer_tree_->property_trees()
540 ->always_use_active_tree_opacity_effect_ids.size(), 541 ->always_use_active_tree_opacity_effect_ids.size(),
541 1u); 542 1u);
542 layer_tree_host_->property_trees()->needs_rebuild = true; 543 layer_tree_->property_trees()->needs_rebuild = true;
543 layer_tree_host_->BuildPropertyTreesForTesting(); 544 layer_tree_host_->BuildPropertyTreesForTesting();
544 EXPECT_EQ(layer_tree_host_->property_trees() 545 EXPECT_EQ(layer_tree_->property_trees()
545 ->always_use_active_tree_opacity_effect_ids.size(), 546 ->always_use_active_tree_opacity_effect_ids.size(),
546 1u); 547 1u);
547 548
548 // A solid color scrollbar layer's opacity is initialized to 0 on main thread 549 // A solid color scrollbar layer's opacity is initialized to 0 on main thread
549 layer_tree_host_->UpdateLayers(); 550 layer_tree_host_->UpdateLayers();
550 EffectNode* node = layer_tree_host_->property_trees()->effect_tree.Node( 551 EffectNode* node = layer_tree_->property_trees()->effect_tree.Node(
551 scrollbar_layer->effect_tree_index()); 552 scrollbar_layer->effect_tree_index());
552 EXPECT_EQ(node->opacity, 0.f); 553 EXPECT_EQ(node->opacity, 0.f);
553 554
554 // This tests that the initial opacity(0) of the scrollbar gets pushed onto 555 // This tests that the initial opacity(0) of the scrollbar gets pushed onto
555 // the pending tree and then onto the active tree. 556 // the pending tree and then onto the active tree.
556 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl(); 557 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl();
557 host_impl->CreatePendingTree(); 558 host_impl->CreatePendingTree();
558 LayerImpl* layer_impl_tree_root = 559 LayerImpl* layer_impl_tree_root =
559 layer_tree_host_->CommitAndCreatePendingTree(); 560 layer_tree_host_->CommitAndCreatePendingTree();
560 LayerTreeImpl* layer_tree_impl = layer_impl_tree_root->layer_tree_impl(); 561 LayerTreeImpl* layer_tree_impl = layer_impl_tree_root->layer_tree_impl();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 scoped_refptr<Layer> scrollbar_layer; 603 scoped_refptr<Layer> scrollbar_layer;
603 const bool kIsLeftSideVerticalScrollbar = false; 604 const bool kIsLeftSideVerticalScrollbar = false;
604 scrollbar_layer = SolidColorScrollbarLayer::Create( 605 scrollbar_layer = SolidColorScrollbarLayer::Create(
605 scrollbar->Orientation(), kThumbThickness, kTrackStart, 606 scrollbar->Orientation(), kThumbThickness, kTrackStart,
606 kIsLeftSideVerticalScrollbar, child1->id()); 607 kIsLeftSideVerticalScrollbar, child1->id());
607 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 608 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
608 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 609 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
609 scroll_layer->AddChild(child1); 610 scroll_layer->AddChild(child1);
610 scroll_layer->InsertChild(scrollbar_layer, 1); 611 scroll_layer->InsertChild(scrollbar_layer, 1);
611 layer_tree_root->AddChild(scroll_layer); 612 layer_tree_root->AddChild(scroll_layer);
612 layer_tree_host_->SetRootLayer(layer_tree_root); 613 layer_tree_->SetRootLayer(layer_tree_root);
613 614
614 layer_tree_root->SetBounds(gfx::Size(2, 2)); 615 layer_tree_root->SetBounds(gfx::Size(2, 2));
615 scroll_layer->SetBounds(gfx::Size(10, 10)); 616 scroll_layer->SetBounds(gfx::Size(10, 10));
616 layer_tree_host_->UpdateLayers(); 617 layer_tree_host_->UpdateLayers();
617 layer_tree_host_->CommitAndCreateLayerImplTree(); 618 layer_tree_host_->CommitAndCreateLayerImplTree();
618 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl(); 619 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl();
619 EXPECT_TRUE(host_impl->ScrollbarAnimationControllerForId(scroll_layer->id())); 620 EXPECT_TRUE(host_impl->ScrollbarAnimationControllerForId(scroll_layer->id()));
620 621
621 scroll_layer->SetBounds(gfx::Size(20, 20)); 622 scroll_layer->SetBounds(gfx::Size(20, 20));
622 scroll_layer->SetForceRenderSurfaceForTesting(true); 623 scroll_layer->SetForceRenderSurfaceForTesting(true);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 740 }
740 741
741 class ScrollbarLayerTestWithFixedScrollbarBounds : public LayerTreeTest { 742 class ScrollbarLayerTestWithFixedScrollbarBounds : public LayerTreeTest {
742 public: 743 public:
743 ScrollbarLayerTestWithFixedScrollbarBounds() {} 744 ScrollbarLayerTestWithFixedScrollbarBounds() {}
744 745
745 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } 746 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; }
746 747
747 void BeginTest() override { 748 void BeginTest() override {
748 scroll_layer_ = Layer::Create(); 749 scroll_layer_ = Layer::Create();
749 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 750 layer_tree()->root_layer()->AddChild(scroll_layer_);
750 751
751 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); 752 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar);
752 scrollbar_layer_ = PaintedScrollbarLayer::Create(std::move(scrollbar), 753 scrollbar_layer_ = PaintedScrollbarLayer::Create(std::move(scrollbar),
753 scroll_layer_->id()); 754 scroll_layer_->id());
754 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); 755 scrollbar_layer_->SetScrollLayer(scroll_layer_->id());
755 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 756 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
756 scrollbar_layer_->SetBounds(bounds_); 757 scrollbar_layer_->SetBounds(bounds_);
757 scrollbar_layer_->SetIsDrawable(true); 758 scrollbar_layer_->SetIsDrawable(true);
758 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 759 layer_tree()->root_layer()->AddChild(scrollbar_layer_);
759 760
760 PostSetNeedsCommitToMainThread(); 761 PostSetNeedsCommitToMainThread();
761 } 762 }
762 763
763 void DidCommitAndDrawFrame() override { 764 void DidCommitAndDrawFrame() override {
764 const int kMaxTextureSize = 765 const int kMaxTextureSize =
765 layer_tree_host()->GetRendererCapabilities().max_texture_size; 766 layer_tree_host()->GetRendererCapabilities().max_texture_size;
766 767
767 // Check first that we're actually testing something. 768 // Check first that we're actually testing something.
768 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); 769 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 scrollbar_layer = SolidColorScrollbarLayer::Create( 811 scrollbar_layer = SolidColorScrollbarLayer::Create(
811 scrollbar->Orientation(), kThumbThickness, kTrackStart, 812 scrollbar->Orientation(), kThumbThickness, kTrackStart,
812 kIsLeftSideVerticalScrollbar, layer_tree_root->id()); 813 kIsLeftSideVerticalScrollbar, layer_tree_root->id());
813 } else { 814 } else {
814 scrollbar_layer = PaintedScrollbarLayer::Create(std::move(scrollbar), 815 scrollbar_layer = PaintedScrollbarLayer::Create(std::move(scrollbar),
815 layer_tree_root->id()); 816 layer_tree_root->id());
816 } 817 }
817 layer_tree_root->AddChild(content_layer); 818 layer_tree_root->AddChild(content_layer);
818 layer_tree_root->AddChild(scrollbar_layer); 819 layer_tree_root->AddChild(scrollbar_layer);
819 820
820 layer_tree_host_->SetRootLayer(layer_tree_root); 821 layer_tree_->SetRootLayer(layer_tree_root);
821 822
822 scrollbar_layer->SetIsDrawable(true); 823 scrollbar_layer->SetIsDrawable(true);
823 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 824 scrollbar_layer->SetBounds(gfx::Size(100, 100));
824 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); 825 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20));
825 layer_tree_root->SetBounds(gfx::Size(100, 200)); 826 layer_tree_root->SetBounds(gfx::Size(100, 200));
826 content_layer->SetBounds(gfx::Size(100, 200)); 827 content_layer->SetBounds(gfx::Size(100, 200));
827 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200)); 828 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200));
828 829
829 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 830 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
830 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 831 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { 867 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) {
867 gfx::Point scrollbar_location(0, 185); 868 gfx::Point scrollbar_location(0, 185);
868 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 869 scoped_refptr<Layer> layer_tree_root = Layer::Create();
869 scoped_refptr<Layer> content_layer = Layer::Create(); 870 scoped_refptr<Layer> content_layer = Layer::Create();
870 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 871 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
871 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 872 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
872 873
873 layer_tree_root->AddChild(content_layer); 874 layer_tree_root->AddChild(content_layer);
874 layer_tree_root->AddChild(scrollbar_layer); 875 layer_tree_root->AddChild(scrollbar_layer);
875 876
876 layer_tree_host_->SetRootLayer(layer_tree_root); 877 layer_tree_->SetRootLayer(layer_tree_root);
877 878
878 scrollbar_layer->SetIsDrawable(true); 879 scrollbar_layer->SetIsDrawable(true);
879 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 880 scrollbar_layer->SetBounds(gfx::Size(100, 15));
880 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); 881 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location));
881 layer_tree_root->SetBounds(gfx::Size(100, 200)); 882 layer_tree_root->SetBounds(gfx::Size(100, 200));
882 content_layer->SetBounds(gfx::Size(100, 200)); 883 content_layer->SetBounds(gfx::Size(100, 200));
883 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200)); 884 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200));
884 885
885 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 886 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
886 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 887 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 void TestResourceUpload(const float test_scale) { 1009 void TestResourceUpload(const float test_scale) {
1009 gfx::Point scrollbar_location(0, 185); 1010 gfx::Point scrollbar_location(0, 185);
1010 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1011 scoped_refptr<Layer> layer_tree_root = Layer::Create();
1011 scoped_refptr<Layer> content_layer = Layer::Create(); 1012 scoped_refptr<Layer> content_layer = Layer::Create();
1012 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1013 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
1013 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 1014 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
1014 1015
1015 layer_tree_root->AddChild(content_layer); 1016 layer_tree_root->AddChild(content_layer);
1016 layer_tree_root->AddChild(scrollbar_layer); 1017 layer_tree_root->AddChild(scrollbar_layer);
1017 1018
1018 layer_tree_host_->SetRootLayer(layer_tree_root); 1019 layer_tree_->SetRootLayer(layer_tree_root);
1019 1020
1020 scrollbar_layer->SetIsDrawable(true); 1021 scrollbar_layer->SetIsDrawable(true);
1021 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 1022 scrollbar_layer->SetBounds(gfx::Size(100, 15));
1022 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); 1023 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location));
1023 layer_tree_root->SetBounds(gfx::Size(100, 200)); 1024 layer_tree_root->SetBounds(gfx::Size(100, 200));
1024 content_layer->SetBounds(gfx::Size(100, 200)); 1025 content_layer->SetBounds(gfx::Size(100, 200));
1025 scrollbar_layer->set_visible_layer_rect( 1026 scrollbar_layer->set_visible_layer_rect(
1026 gfx::Rect(scrollbar_location, scrollbar_layer->bounds())); 1027 gfx::Rect(scrollbar_location, scrollbar_layer->bounds()));
1027 1028
1028 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 1029 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
1029 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 1030 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
1030 1031
1031 layer_tree_host_->SetDeviceScaleFactor(test_scale); 1032 layer_tree_->SetDeviceScaleFactor(test_scale);
1032 1033
1033 scrollbar_layer->SavePaintProperties(); 1034 scrollbar_layer->SavePaintProperties();
1034 scrollbar_layer->Update(); 1035 scrollbar_layer->Update();
1035 1036
1036 // Verify that we have not generated any content uploads that are larger 1037 // Verify that we have not generated any content uploads that are larger
1037 // than their destination textures. 1038 // than their destination textures.
1038 1039
1039 gfx::Size track_size = layer_tree_host_->ui_resource_size( 1040 gfx::Size track_size = layer_tree_host_->ui_resource_size(
1040 scrollbar_layer->track_resource_id()); 1041 scrollbar_layer->track_resource_id());
1041 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( 1042 gfx::Size thumb_size = layer_tree_host_->ui_resource_size(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 1079 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
1079 bool paint_during_update = true; 1080 bool paint_during_update = true;
1080 bool has_thumb = false; 1081 bool has_thumb = false;
1081 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1082 scoped_refptr<Layer> layer_tree_root = Layer::Create();
1082 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1083 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
1083 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, 1084 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb,
1084 layer_tree_root->id()); 1085 layer_tree_root->id());
1085 1086
1086 layer_tree_root->AddChild(scrollbar_layer); 1087 layer_tree_root->AddChild(scrollbar_layer);
1087 1088
1088 layer_tree_host_->SetRootLayer(layer_tree_root); 1089 layer_tree_->SetRootLayer(layer_tree_root);
1089 1090
1090 scrollbar_layer->SetBounds(scrollbar_rect.size()); 1091 scrollbar_layer->SetBounds(scrollbar_rect.size());
1091 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); 1092 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin()));
1092 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); 1093 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin());
1093 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); 1094 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect);
1094 scrollbar_layer->set_visible_layer_rect(scrollbar_rect); 1095 scrollbar_layer->set_visible_layer_rect(scrollbar_rect);
1095 1096
1096 layer_tree_host_->SetDeviceScaleFactor(test_scale); 1097 layer_tree_->SetDeviceScaleFactor(test_scale);
1097 1098
1098 gfx::Rect screen_space_clip_rect; 1099 gfx::Rect screen_space_clip_rect;
1099 scrollbar_layer->SavePaintProperties(); 1100 scrollbar_layer->SavePaintProperties();
1100 1101
1101 scrollbar_layer->Update(); 1102 scrollbar_layer->Update();
1102 1103
1103 UIResourceBitmap* bitmap = layer_tree_host_->ui_resource_bitmap( 1104 UIResourceBitmap* bitmap = layer_tree_host_->ui_resource_bitmap(
1104 scrollbar_layer->track_resource_id()); 1105 scrollbar_layer->track_resource_id());
1105 1106
1106 DCHECK(bitmap); 1107 DCHECK(bitmap);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1146 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1146 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1147 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1147 1148
1148 // Horizontal Scrollbars. 1149 // Horizontal Scrollbars.
1149 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1150 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1150 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1151 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1151 } 1152 }
1152 1153
1153 } // namespace 1154 } // namespace
1154 } // namespace cc 1155 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698