| 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/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "cc/input/scrollbar_animation_controller.h" | 10 #include "cc/input/scrollbar_animation_controller.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "cc/trees/layer_tree_impl.h" | 30 #include "cc/trees/layer_tree_impl.h" |
| 31 #include "cc/trees/occlusion_tracker.h" | 31 #include "cc/trees/occlusion_tracker.h" |
| 32 #include "cc/trees/single_thread_proxy.h" | 32 #include "cc/trees/single_thread_proxy.h" |
| 33 #include "cc/trees/tree_synchronizer.h" | 33 #include "cc/trees/tree_synchronizer.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 36 |
| 37 namespace cc { | 37 namespace cc { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 LayerImpl* LayerImplForScrollAreaAndScrollbar(const LayerSettings& settings, | 40 LayerImpl* LayerImplForScrollAreaAndScrollbar(FakeLayerTreeHost* host, |
| 41 FakeLayerTreeHost* host, | |
| 42 scoped_ptr<Scrollbar> scrollbar, | 41 scoped_ptr<Scrollbar> scrollbar, |
| 43 bool reverse_order, | 42 bool reverse_order, |
| 44 bool use_solid_color_scrollbar, | 43 bool use_solid_color_scrollbar, |
| 45 int thumb_thickness, | 44 int thumb_thickness, |
| 46 int track_start) { | 45 int track_start) { |
| 47 scoped_refptr<Layer> layer_tree_root = Layer::Create(settings); | 46 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 48 scoped_refptr<Layer> child1 = Layer::Create(settings); | 47 scoped_refptr<Layer> child1 = Layer::Create(); |
| 49 scoped_refptr<Layer> child2; | 48 scoped_refptr<Layer> child2; |
| 50 if (use_solid_color_scrollbar) { | 49 if (use_solid_color_scrollbar) { |
| 51 const bool kIsLeftSideVerticalScrollbar = false; | 50 const bool kIsLeftSideVerticalScrollbar = false; |
| 52 child2 = SolidColorScrollbarLayer::Create( | 51 child2 = SolidColorScrollbarLayer::Create( |
| 53 settings, scrollbar->Orientation(), thumb_thickness, track_start, | 52 scrollbar->Orientation(), thumb_thickness, track_start, |
| 54 kIsLeftSideVerticalScrollbar, child1->id()); | 53 kIsLeftSideVerticalScrollbar, child1->id()); |
| 55 } else { | 54 } else { |
| 56 child2 = PaintedScrollbarLayer::Create(settings, std::move(scrollbar), | 55 child2 = PaintedScrollbarLayer::Create(std::move(scrollbar), child1->id()); |
| 57 child1->id()); | |
| 58 } | 56 } |
| 59 layer_tree_root->AddChild(child1); | 57 layer_tree_root->AddChild(child1); |
| 60 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | 58 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
| 61 host->SetRootLayer(layer_tree_root); | 59 host->SetRootLayer(layer_tree_root); |
| 62 return host->CommitAndCreateLayerImplTree(); | 60 return host->CommitAndCreateLayerImplTree(); |
| 63 } | 61 } |
| 64 | 62 |
| 65 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { | 63 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { |
| 66 public: | 64 public: |
| 67 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, | 65 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 130 |
| 133 layer_tree_host_.reset( | 131 layer_tree_host_.reset( |
| 134 new FakeResourceTrackingLayerTreeHost(&fake_client_, ¶ms)); | 132 new FakeResourceTrackingLayerTreeHost(&fake_client_, ¶ms)); |
| 135 layer_tree_host_->SetVisible(true); | 133 layer_tree_host_->SetVisible(true); |
| 136 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); | 134 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); |
| 137 // Force output surface creation for renderer capabilities. | 135 // Force output surface creation for renderer capabilities. |
| 138 layer_tree_host_->Composite(base::TimeTicks()); | 136 layer_tree_host_->Composite(base::TimeTicks()); |
| 139 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); | 137 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); |
| 140 } | 138 } |
| 141 | 139 |
| 142 const LayerSettings& layer_settings() { return layer_settings_; } | |
| 143 | |
| 144 protected: | 140 protected: |
| 145 FakeLayerTreeHostClient fake_client_; | 141 FakeLayerTreeHostClient fake_client_; |
| 146 TestTaskGraphRunner task_graph_runner_; | 142 TestTaskGraphRunner task_graph_runner_; |
| 147 LayerTreeSettings layer_tree_settings_; | 143 LayerTreeSettings layer_tree_settings_; |
| 148 LayerSettings layer_settings_; | |
| 149 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; | 144 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; |
| 150 }; | 145 }; |
| 151 | 146 |
| 152 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 147 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
| 153 // Create and attach a non-overlay scrollbar. | 148 // Create and attach a non-overlay scrollbar. |
| 154 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 149 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 155 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 150 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 156 layer_settings(), layer_tree_host_.get(), std::move(scrollbar), false, | 151 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); |
| 157 false, 0, 0); | |
| 158 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 152 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
| 159 static_cast<PaintedScrollbarLayerImpl*>( | 153 static_cast<PaintedScrollbarLayerImpl*>( |
| 160 layer_impl_tree_root->children()[1].get()); | 154 layer_impl_tree_root->children()[1].get()); |
| 161 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); | 155 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 162 ScrollTree& scroll_tree = | 156 ScrollTree& scroll_tree = |
| 163 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; | 157 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; |
| 164 ScrollNode* scroll_node = | 158 ScrollNode* scroll_node = |
| 165 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); | 159 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); |
| 166 | 160 |
| 167 // When the scrollbar is not an overlay scrollbar, the scroll should be | 161 // When the scrollbar is not an overlay scrollbar, the scroll should be |
| 168 // responded to on the main thread as the compositor does not yet implement | 162 // responded to on the main thread as the compositor does not yet implement |
| 169 // scrollbar scrolling. | 163 // scrollbar scrolling. |
| 170 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll( | 164 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll( |
| 171 gfx::PointF(), InputHandler::GESTURE, scroll_tree, scroll_node); | 165 gfx::PointF(), InputHandler::GESTURE, scroll_tree, scroll_node); |
| 172 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); | 166 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
| 173 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling, | 167 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling, |
| 174 status.main_thread_scrolling_reasons); | 168 status.main_thread_scrolling_reasons); |
| 175 | 169 |
| 176 // Create and attach an overlay scrollbar. | 170 // Create and attach an overlay scrollbar. |
| 177 scrollbar.reset(new FakeScrollbar(false, false, true)); | 171 scrollbar.reset(new FakeScrollbar(false, false, true)); |
| 178 | 172 |
| 179 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 173 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 180 layer_settings(), layer_tree_host_.get(), std::move(scrollbar), false, | 174 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); |
| 181 false, 0, 0); | |
| 182 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | 175 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
| 183 layer_impl_tree_root->children()[1].get()); | 176 layer_impl_tree_root->children()[1].get()); |
| 184 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); | 177 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 185 scroll_tree = | 178 scroll_tree = |
| 186 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; | 179 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; |
| 187 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); | 180 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); |
| 188 | 181 |
| 189 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 182 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
| 190 // may be handled in the compositor. | 183 // may be handled in the compositor. |
| 191 status = layer_tree_host_->host_impl()->TryScroll( | 184 status = layer_tree_host_->host_impl()->TryScroll( |
| 192 gfx::PointF(), InputHandler::GESTURE, scroll_tree, scroll_node); | 185 gfx::PointF(), InputHandler::GESTURE, scroll_tree, scroll_node); |
| 193 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); | 186 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
| 194 EXPECT_EQ(MainThreadScrollingReason::kNotScrollable, | 187 EXPECT_EQ(MainThreadScrollingReason::kNotScrollable, |
| 195 status.main_thread_scrolling_reasons); | 188 status.main_thread_scrolling_reasons); |
| 196 } | 189 } |
| 197 | 190 |
| 198 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { | 191 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { |
| 199 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 192 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 200 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 193 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 201 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); | 194 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 202 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 195 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 203 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( | 196 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( |
| 204 layer_settings(), std::move(scrollbar), layer_tree_root->id()); | 197 std::move(scrollbar), layer_tree_root->id()); |
| 205 | 198 |
| 206 // Choose bounds to give max_scroll_offset = (30, 50). | 199 // Choose bounds to give max_scroll_offset = (30, 50). |
| 207 layer_tree_root->SetBounds(gfx::Size(70, 150)); | 200 layer_tree_root->SetBounds(gfx::Size(70, 150)); |
| 208 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 201 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 209 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 202 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 210 scroll_layer->SetBounds(gfx::Size(100, 200)); | 203 scroll_layer->SetBounds(gfx::Size(100, 200)); |
| 211 content_layer->SetBounds(gfx::Size(100, 200)); | 204 content_layer->SetBounds(gfx::Size(100, 200)); |
| 212 | 205 |
| 213 layer_tree_host_->SetRootLayer(layer_tree_root); | 206 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 214 layer_tree_root->AddChild(scroll_layer); | 207 layer_tree_root->AddChild(scroll_layer); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 do { \ | 251 do { \ |
| 259 scrollbar_layer->UpdateInternalContentScale(); \ | 252 scrollbar_layer->UpdateInternalContentScale(); \ |
| 260 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ | 253 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
| 261 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ | 254 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ |
| 262 root_layer_impl = root_clip_layer_impl->children()[0].get(); \ | 255 root_layer_impl = root_clip_layer_impl->children()[0].get(); \ |
| 263 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ | 256 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
| 264 root_layer_impl->children()[1].get()); \ | 257 root_layer_impl->children()[1].get()); \ |
| 265 } while (false) | 258 } while (false) |
| 266 | 259 |
| 267 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { | 260 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { |
| 268 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings()); | 261 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 269 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); | 262 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 270 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 263 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 271 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 264 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 272 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, | 265 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 273 root_layer->id()); | |
| 274 | 266 |
| 275 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 267 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 276 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 268 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 277 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 269 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
| 278 root_layer->SetBounds(gfx::Size(100, 50)); | 270 root_layer->SetBounds(gfx::Size(100, 50)); |
| 279 content_layer->SetBounds(gfx::Size(100, 50)); | 271 content_layer->SetBounds(gfx::Size(100, 50)); |
| 280 | 272 |
| 281 layer_tree_host_->SetRootLayer(root_clip_layer); | 273 layer_tree_host_->SetRootLayer(root_clip_layer); |
| 282 root_clip_layer->AddChild(root_layer); | 274 root_clip_layer->AddChild(root_layer); |
| 283 root_layer->AddChild(content_layer); | 275 root_layer->AddChild(content_layer); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 299 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 291 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 300 | 292 |
| 301 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); | 293 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); |
| 302 | 294 |
| 303 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 295 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
| 304 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), | 296 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), |
| 305 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 297 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 306 } | 298 } |
| 307 | 299 |
| 308 TEST_F(ScrollbarLayerTest, ThumbRect) { | 300 TEST_F(ScrollbarLayerTest, ThumbRect) { |
| 309 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings()); | 301 scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
| 310 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); | 302 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 311 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 303 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 312 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 304 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 313 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, | 305 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
| 314 root_layer->id()); | |
| 315 | 306 |
| 316 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 307 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
| 317 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 308 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
| 318 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 309 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
| 319 root_layer->SetBounds(gfx::Size(100, 50)); | 310 root_layer->SetBounds(gfx::Size(100, 50)); |
| 320 content_layer->SetBounds(gfx::Size(100, 50)); | 311 content_layer->SetBounds(gfx::Size(100, 50)); |
| 321 | 312 |
| 322 layer_tree_host_->SetRootLayer(root_clip_layer); | 313 layer_tree_host_->SetRootLayer(root_clip_layer); |
| 323 root_clip_layer->AddChild(root_layer); | 314 root_clip_layer->AddChild(root_layer); |
| 324 root_layer->AddChild(content_layer); | 315 root_layer->AddChild(content_layer); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 375 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
| 385 } | 376 } |
| 386 | 377 |
| 387 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { | 378 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 388 const int kThumbThickness = 3; | 379 const int kThumbThickness = 3; |
| 389 const int kTrackStart = 1; | 380 const int kTrackStart = 1; |
| 390 const int kTrackLength = 100; | 381 const int kTrackLength = 100; |
| 391 | 382 |
| 392 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 383 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 393 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 384 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 394 layer_settings(), layer_tree_host_.get(), std::move(scrollbar), false, | 385 layer_tree_host_.get(), std::move(scrollbar), false, true, |
| 395 true, kThumbThickness, kTrackStart); | 386 kThumbThickness, kTrackStart); |
| 396 ScrollbarLayerImplBase* scrollbar_layer_impl = | 387 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 397 static_cast<SolidColorScrollbarLayerImpl*>( | 388 static_cast<SolidColorScrollbarLayerImpl*>( |
| 398 layer_impl_tree_root->children()[1].get()); | 389 layer_impl_tree_root->children()[1].get()); |
| 399 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 390 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 400 scrollbar_layer_impl->SetCurrentPos(10.f); | 391 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 401 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); | 392 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); |
| 402 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); | 393 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); |
| 403 | 394 |
| 404 // Thickness should be overridden to 3. | 395 // Thickness should be overridden to 3. |
| 405 { | 396 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 436 } |
| 446 | 437 |
| 447 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 438 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 448 const int kThumbThickness = 3; | 439 const int kThumbThickness = 3; |
| 449 const int kTrackStart = 0; | 440 const int kTrackStart = 0; |
| 450 const int kTrackLength = 10; | 441 const int kTrackLength = 10; |
| 451 | 442 |
| 452 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 443 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 453 | 444 |
| 454 { | 445 { |
| 455 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 446 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 456 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); | 447 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 457 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 448 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 458 scoped_refptr<Layer> child1 = Layer::Create(layer_settings()); | 449 scoped_refptr<Layer> child1 = Layer::Create(); |
| 459 scoped_refptr<Layer> child2; | 450 scoped_refptr<Layer> child2; |
| 460 const bool kIsLeftSideVerticalScrollbar = false; | 451 const bool kIsLeftSideVerticalScrollbar = false; |
| 461 child2 = SolidColorScrollbarLayer::Create( | 452 child2 = SolidColorScrollbarLayer::Create( |
| 462 layer_settings(), scrollbar->Orientation(), kThumbThickness, | 453 scrollbar->Orientation(), kThumbThickness, kTrackStart, |
| 463 kTrackStart, kIsLeftSideVerticalScrollbar, child1->id()); | 454 kIsLeftSideVerticalScrollbar, child1->id()); |
| 464 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); | 455 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
| 465 scroll_layer->AddChild(child1); | 456 scroll_layer->AddChild(child1); |
| 466 scroll_layer->InsertChild(child2, 1); | 457 scroll_layer->InsertChild(child2, 1); |
| 467 layer_tree_root->AddChild(scroll_layer); | 458 layer_tree_root->AddChild(scroll_layer); |
| 468 layer_tree_host_->SetRootLayer(layer_tree_root); | 459 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 469 | 460 |
| 470 // Choose layer bounds to give max_scroll_offset = (8, 8). | 461 // Choose layer bounds to give max_scroll_offset = (8, 8). |
| 471 layer_tree_root->SetBounds(gfx::Size(2, 2)); | 462 layer_tree_root->SetBounds(gfx::Size(2, 2)); |
| 472 scroll_layer->SetBounds(gfx::Size(10, 10)); | 463 scroll_layer->SetBounds(gfx::Size(10, 10)); |
| 473 | 464 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 596 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 606 } | 597 } |
| 607 | 598 |
| 608 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { | 599 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { |
| 609 public: | 600 public: |
| 610 ScrollbarLayerTestMaxTextureSize() {} | 601 ScrollbarLayerTestMaxTextureSize() {} |
| 611 | 602 |
| 612 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } | 603 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } |
| 613 | 604 |
| 614 void BeginTest() override { | 605 void BeginTest() override { |
| 615 scroll_layer_ = Layer::Create(layer_settings()); | 606 scroll_layer_ = Layer::Create(); |
| 616 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 607 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 617 | 608 |
| 618 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 609 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 619 scrollbar_layer_ = PaintedScrollbarLayer::Create( | 610 scrollbar_layer_ = PaintedScrollbarLayer::Create(std::move(scrollbar), |
| 620 layer_settings(), std::move(scrollbar), scroll_layer_->id()); | 611 scroll_layer_->id()); |
| 621 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); | 612 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); |
| 622 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); | 613 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
| 623 scrollbar_layer_->SetBounds(bounds_); | 614 scrollbar_layer_->SetBounds(bounds_); |
| 624 scrollbar_layer_->SetIsDrawable(true); | 615 scrollbar_layer_->SetIsDrawable(true); |
| 625 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); | 616 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); |
| 626 | 617 |
| 627 PostSetNeedsCommitToMainThread(); | 618 PostSetNeedsCommitToMainThread(); |
| 628 } | 619 } |
| 629 | 620 |
| 630 void DidCommitAndDrawFrame() override { | 621 void DidCommitAndDrawFrame() override { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 } | 660 } |
| 670 | 661 |
| 671 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { | 662 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { |
| 672 public: | 663 public: |
| 673 void TestResourceUpload(int num_updates, | 664 void TestResourceUpload(int num_updates, |
| 674 size_t expected_resources, | 665 size_t expected_resources, |
| 675 int expected_created, | 666 int expected_created, |
| 676 int expected_deleted, | 667 int expected_deleted, |
| 677 bool use_solid_color_scrollbar) { | 668 bool use_solid_color_scrollbar) { |
| 678 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 669 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
| 679 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 670 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 680 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 671 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 681 scoped_refptr<Layer> scrollbar_layer; | 672 scoped_refptr<Layer> scrollbar_layer; |
| 682 if (use_solid_color_scrollbar) { | 673 if (use_solid_color_scrollbar) { |
| 683 const int kThumbThickness = 3; | 674 const int kThumbThickness = 3; |
| 684 const int kTrackStart = 0; | 675 const int kTrackStart = 0; |
| 685 const bool kIsLeftSideVerticalScrollbar = false; | 676 const bool kIsLeftSideVerticalScrollbar = false; |
| 686 scrollbar_layer = SolidColorScrollbarLayer::Create( | 677 scrollbar_layer = SolidColorScrollbarLayer::Create( |
| 687 layer_settings(), scrollbar->Orientation(), kThumbThickness, | 678 scrollbar->Orientation(), kThumbThickness, kTrackStart, |
| 688 kTrackStart, kIsLeftSideVerticalScrollbar, layer_tree_root->id()); | 679 kIsLeftSideVerticalScrollbar, layer_tree_root->id()); |
| 689 } else { | 680 } else { |
| 690 scrollbar_layer = PaintedScrollbarLayer::Create( | 681 scrollbar_layer = PaintedScrollbarLayer::Create(std::move(scrollbar), |
| 691 layer_settings(), std::move(scrollbar), layer_tree_root->id()); | 682 layer_tree_root->id()); |
| 692 } | 683 } |
| 693 layer_tree_root->AddChild(content_layer); | 684 layer_tree_root->AddChild(content_layer); |
| 694 layer_tree_root->AddChild(scrollbar_layer); | 685 layer_tree_root->AddChild(scrollbar_layer); |
| 695 | 686 |
| 696 layer_tree_host_->SetRootLayer(layer_tree_root); | 687 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 697 | 688 |
| 698 scrollbar_layer->SetIsDrawable(true); | 689 scrollbar_layer->SetIsDrawable(true); |
| 699 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 690 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| 700 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 691 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 701 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 692 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 725 |
| 735 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, | 726 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, |
| 736 SolidColorNoResourceUpload) { | 727 SolidColorNoResourceUpload) { |
| 737 bool use_solid_color_scrollbars = true; | 728 bool use_solid_color_scrollbars = true; |
| 738 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); | 729 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
| 739 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); | 730 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); |
| 740 } | 731 } |
| 741 | 732 |
| 742 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { | 733 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { |
| 743 gfx::Point scrollbar_location(0, 185); | 734 gfx::Point scrollbar_location(0, 185); |
| 744 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 735 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 745 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 736 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 746 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 737 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 747 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, | 738 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); |
| 748 layer_tree_root->id()); | |
| 749 | 739 |
| 750 layer_tree_root->AddChild(content_layer); | 740 layer_tree_root->AddChild(content_layer); |
| 751 layer_tree_root->AddChild(scrollbar_layer); | 741 layer_tree_root->AddChild(scrollbar_layer); |
| 752 | 742 |
| 753 layer_tree_host_->SetRootLayer(layer_tree_root); | 743 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 754 | 744 |
| 755 scrollbar_layer->SetIsDrawable(true); | 745 scrollbar_layer->SetIsDrawable(true); |
| 756 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 746 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
| 757 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); | 747 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); |
| 758 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 748 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); | 867 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); |
| 878 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); | 868 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); |
| 879 | 869 |
| 880 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 870 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 881 } | 871 } |
| 882 | 872 |
| 883 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { | 873 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { |
| 884 public: | 874 public: |
| 885 void TestResourceUpload(const float test_scale) { | 875 void TestResourceUpload(const float test_scale) { |
| 886 gfx::Point scrollbar_location(0, 185); | 876 gfx::Point scrollbar_location(0, 185); |
| 887 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 877 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 888 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); | 878 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 889 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 879 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 890 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, | 880 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); |
| 891 layer_tree_root->id()); | |
| 892 | 881 |
| 893 layer_tree_root->AddChild(content_layer); | 882 layer_tree_root->AddChild(content_layer); |
| 894 layer_tree_root->AddChild(scrollbar_layer); | 883 layer_tree_root->AddChild(scrollbar_layer); |
| 895 | 884 |
| 896 layer_tree_host_->SetRootLayer(layer_tree_root); | 885 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 897 | 886 |
| 898 scrollbar_layer->SetIsDrawable(true); | 887 scrollbar_layer->SetIsDrawable(true); |
| 899 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 888 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
| 900 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); | 889 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); |
| 901 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 890 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 | 938 |
| 950 // Try something extreme to make sure it gets clamped. | 939 // Try something extreme to make sure it gets clamped. |
| 951 TestResourceUpload(2147483647.0f); | 940 TestResourceUpload(2147483647.0f); |
| 952 } | 941 } |
| 953 | 942 |
| 954 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { | 943 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { |
| 955 public: | 944 public: |
| 956 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { | 945 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { |
| 957 bool paint_during_update = true; | 946 bool paint_during_update = true; |
| 958 bool has_thumb = false; | 947 bool has_thumb = false; |
| 959 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); | 948 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 960 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 949 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 961 FakePaintedScrollbarLayer::Create(layer_settings(), paint_during_update, | 950 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, |
| 962 has_thumb, layer_tree_root->id()); | 951 layer_tree_root->id()); |
| 963 | 952 |
| 964 layer_tree_root->AddChild(scrollbar_layer); | 953 layer_tree_root->AddChild(scrollbar_layer); |
| 965 | 954 |
| 966 layer_tree_host_->SetRootLayer(layer_tree_root); | 955 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 967 | 956 |
| 968 scrollbar_layer->SetBounds(scrollbar_rect.size()); | 957 scrollbar_layer->SetBounds(scrollbar_rect.size()); |
| 969 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); | 958 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); |
| 970 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); | 959 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); |
| 971 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); | 960 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); |
| 972 scrollbar_layer->set_visible_layer_rect(scrollbar_rect); | 961 scrollbar_layer->set_visible_layer_rect(scrollbar_rect); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1012 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1024 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1013 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1025 | 1014 |
| 1026 // Horizontal Scrollbars. | 1015 // Horizontal Scrollbars. |
| 1027 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1016 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1028 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1017 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1029 } | 1018 } |
| 1030 | 1019 |
| 1031 } // namespace | 1020 } // namespace |
| 1032 } // namespace cc | 1021 } // namespace cc |
| OLD | NEW |