| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/animation/animation_host.h" | 11 #include "cc/animation/animation_host.h" |
| 12 #include "cc/input/scrollbar_animation_controller.h" | 12 #include "cc/input/scrollbar_animation_controller.h" |
| 13 #include "cc/layers/append_quads_data.h" | 13 #include "cc/layers/append_quads_data.h" |
| 14 #include "cc/layers/painted_overlay_scrollbar_layer.h" |
| 14 #include "cc/layers/painted_scrollbar_layer.h" | 15 #include "cc/layers/painted_scrollbar_layer.h" |
| 15 #include "cc/layers/painted_scrollbar_layer_impl.h" | 16 #include "cc/layers/painted_scrollbar_layer_impl.h" |
| 16 #include "cc/layers/scrollbar_layer_interface.h" | 17 #include "cc/layers/scrollbar_layer_interface.h" |
| 17 #include "cc/layers/solid_color_scrollbar_layer.h" | 18 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 18 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 19 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 19 #include "cc/quads/solid_color_draw_quad.h" | 20 #include "cc/quads/solid_color_draw_quad.h" |
| 20 #include "cc/resources/ui_resource_manager.h" | 21 #include "cc/resources/ui_resource_manager.h" |
| 21 #include "cc/test/fake_impl_task_runner_provider.h" | 22 #include "cc/test/fake_impl_task_runner_provider.h" |
| 22 #include "cc/test/fake_layer_tree_host.h" | 23 #include "cc/test/fake_layer_tree_host.h" |
| 23 #include "cc/test/fake_layer_tree_host_client.h" | 24 #include "cc/test/fake_layer_tree_host_client.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 FakeResourceTrackingUIResourceManager* fake_ui_resource_manager_; | 169 FakeResourceTrackingUIResourceManager* fake_ui_resource_manager_; |
| 169 FakeLayerTreeHostClient fake_client_; | 170 FakeLayerTreeHostClient fake_client_; |
| 170 StubLayerTreeHostSingleThreadClient single_thread_client_; | 171 StubLayerTreeHostSingleThreadClient single_thread_client_; |
| 171 TestTaskGraphRunner task_graph_runner_; | 172 TestTaskGraphRunner task_graph_runner_; |
| 172 LayerTreeSettings layer_tree_settings_; | 173 LayerTreeSettings layer_tree_settings_; |
| 173 std::unique_ptr<AnimationHost> animation_host_; | 174 std::unique_ptr<AnimationHost> animation_host_; |
| 174 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; | 175 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; |
| 175 int scrollbar_layer_id_; | 176 int scrollbar_layer_id_; |
| 176 }; | 177 }; |
| 177 | 178 |
| 179 class FakePaintedOverlayScrollbar : public FakeScrollbar { |
| 180 public: |
| 181 FakePaintedOverlayScrollbar() : FakeScrollbar(true, true, true) {} |
| 182 bool UsesNinePatchThumbResource() const override { return true; } |
| 183 gfx::Size NinePatchThumbCanvasSize() const override { |
| 184 return gfx::Size(3, 3); |
| 185 } |
| 186 gfx::Rect NinePatchThumbAperture() const override { |
| 187 return gfx::Rect(1, 1, 1, 1); |
| 188 } |
| 189 }; |
| 190 |
| 191 // Test that a painted overlay scrollbar will repaint and recrate its resource |
| 192 // after its been disposed, even if Blink doesn't think it requires a repaint. |
| 193 // crbug.com/704656. |
| 194 TEST_F(ScrollbarLayerTest, RepaintOverlayWhenResourceDisposed) { |
| 195 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 196 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 197 std::unique_ptr<FakePaintedOverlayScrollbar> scrollbar( |
| 198 new FakePaintedOverlayScrollbar); |
| 199 FakePaintedOverlayScrollbar* fake_scrollbar = scrollbar.get(); |
| 200 scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer = |
| 201 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar), |
| 202 layer_tree_root->id()); |
| 203 |
| 204 // Setup. |
| 205 { |
| 206 layer_tree_root->AddChild(content_layer); |
| 207 layer_tree_root->AddChild(scrollbar_layer); |
| 208 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 209 scrollbar_layer->SetIsDrawable(true); |
| 210 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| 211 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
| 212 content_layer->SetBounds(gfx::Size(100, 200)); |
| 213 scrollbar_layer->set_visible_layer_rect(gfx::Rect(0, 0, 100, 200)); |
| 214 scrollbar_layer->SavePaintProperties(); |
| 215 } |
| 216 |
| 217 // First call to update should create a resource. The scrollbar itself thinks |
| 218 // it needs a repaint. |
| 219 { |
| 220 fake_scrollbar->set_needs_paint_thumb(true); |
| 221 EXPECT_EQ(0u, fake_ui_resource_manager_->UIResourceCount()); |
| 222 EXPECT_TRUE(scrollbar_layer->Update()); |
| 223 EXPECT_EQ(1u, fake_ui_resource_manager_->UIResourceCount()); |
| 224 } |
| 225 |
| 226 // Now the scrollbar has been painted and nothing else has changed, calling |
| 227 // Update() shouldn't have an effect. |
| 228 { |
| 229 fake_scrollbar->set_needs_paint_thumb(false); |
| 230 EXPECT_FALSE(scrollbar_layer->Update()); |
| 231 EXPECT_EQ(1u, fake_ui_resource_manager_->UIResourceCount()); |
| 232 } |
| 233 |
| 234 // Detach and reattach the LayerTreeHost (this can happen during tree |
| 235 // reconstruction). This should cause the UIResource for the scrollbar to be |
| 236 // disposed but the scrollbar itself hasn't changed so it reports that no |
| 237 // repaint is needed. An Update should cause us to recreate the resource |
| 238 // though. |
| 239 { |
| 240 scrollbar_layer->SetLayerTreeHost(nullptr); |
| 241 scrollbar_layer->SetLayerTreeHost(layer_tree_host_.get()); |
| 242 EXPECT_EQ(0u, fake_ui_resource_manager_->UIResourceCount()); |
| 243 EXPECT_TRUE(scrollbar_layer->Update()); |
| 244 EXPECT_EQ(1u, fake_ui_resource_manager_->UIResourceCount()); |
| 245 } |
| 246 } |
| 247 |
| 178 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 248 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
| 179 // Create and attach a non-overlay scrollbar. | 249 // Create and attach a non-overlay scrollbar. |
| 180 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 250 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 181 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 251 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 182 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); | 252 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); |
| 183 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 253 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
| 184 static_cast<PaintedScrollbarLayerImpl*>( | 254 static_cast<PaintedScrollbarLayerImpl*>( |
| 185 layer_impl_tree_root->layer_tree_impl()->LayerById( | 255 layer_impl_tree_root->layer_tree_impl()->LayerById( |
| 186 scrollbar_layer_id_)); | 256 scrollbar_layer_id_)); |
| 187 ScrollTree& scroll_tree = | 257 ScrollTree& scroll_tree = |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1235 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1166 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1236 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1167 | 1237 |
| 1168 // Horizontal Scrollbars. | 1238 // Horizontal Scrollbars. |
| 1169 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1239 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1170 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1240 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1171 } | 1241 } |
| 1172 | 1242 |
| 1173 } // namespace | 1243 } // namespace |
| 1174 } // namespace cc | 1244 } // namespace cc |
| OLD | NEW |