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