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 "base/containers/hash_tables.h" | 5 #include "base/containers/hash_tables.h" |
6 #include "base/thread_task_runner_handle.h" | 6 #include "base/thread_task_runner_handle.h" |
7 #include "cc/animation/scrollbar_animation_controller.h" | 7 #include "cc/animation/scrollbar_animation_controller.h" |
8 #include "cc/layers/append_quads_data.h" | 8 #include "cc/layers/append_quads_data.h" |
9 #include "cc/layers/painted_scrollbar_layer.h" | 9 #include "cc/layers/painted_scrollbar_layer.h" |
10 #include "cc/layers/painted_scrollbar_layer_impl.h" | 10 #include "cc/layers/painted_scrollbar_layer_impl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "cc/trees/layer_tree_impl.h" | 28 #include "cc/trees/layer_tree_impl.h" |
29 #include "cc/trees/occlusion_tracker.h" | 29 #include "cc/trees/occlusion_tracker.h" |
30 #include "cc/trees/single_thread_proxy.h" | 30 #include "cc/trees/single_thread_proxy.h" |
31 #include "cc/trees/tree_synchronizer.h" | 31 #include "cc/trees/tree_synchronizer.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 | 34 |
35 namespace cc { | 35 namespace cc { |
36 namespace { | 36 namespace { |
37 | 37 |
38 LayerImpl* LayerImplForScrollAreaAndScrollbar(FakeLayerTreeHost* host, | 38 LayerImpl* LayerImplForScrollAreaAndScrollbar(const LayerSettings& settings, |
| 39 FakeLayerTreeHost* host, |
39 scoped_ptr<Scrollbar> scrollbar, | 40 scoped_ptr<Scrollbar> scrollbar, |
40 bool reverse_order, | 41 bool reverse_order, |
41 bool use_solid_color_scrollbar, | 42 bool use_solid_color_scrollbar, |
42 int thumb_thickness, | 43 int thumb_thickness, |
43 int track_start) { | 44 int track_start) { |
44 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 45 scoped_refptr<Layer> layer_tree_root = Layer::Create(settings); |
45 scoped_refptr<Layer> child1 = Layer::Create(); | 46 scoped_refptr<Layer> child1 = Layer::Create(settings); |
46 scoped_refptr<Layer> child2; | 47 scoped_refptr<Layer> child2; |
47 if (use_solid_color_scrollbar) { | 48 if (use_solid_color_scrollbar) { |
48 const bool kIsLeftSideVerticalScrollbar = false; | 49 const bool kIsLeftSideVerticalScrollbar = false; |
49 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | 50 child2 = SolidColorScrollbarLayer::Create( |
50 thumb_thickness, | 51 settings, scrollbar->Orientation(), thumb_thickness, track_start, |
51 track_start, | 52 kIsLeftSideVerticalScrollbar, child1->id()); |
52 kIsLeftSideVerticalScrollbar, | |
53 child1->id()); | |
54 } else { | 53 } else { |
55 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); | 54 child2 = |
| 55 PaintedScrollbarLayer::Create(settings, scrollbar.Pass(), child1->id()); |
56 } | 56 } |
57 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); | 57 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
58 layer_tree_root->AddChild(child1); | 58 layer_tree_root->AddChild(child1); |
59 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | 59 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
60 host->SetRootLayer(layer_tree_root); | 60 host->SetRootLayer(layer_tree_root); |
61 return host->CommitAndCreateLayerImplTree(); | 61 return host->CommitAndCreateLayerImplTree(); |
62 } | 62 } |
63 | 63 |
64 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { | 64 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { |
65 public: | 65 public: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { | 122 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { |
123 layer_tree_settings_.single_thread_proxy_scheduler = false; | 123 layer_tree_settings_.single_thread_proxy_scheduler = false; |
124 layer_tree_host_.reset(new FakeResourceTrackingLayerTreeHost( | 124 layer_tree_host_.reset(new FakeResourceTrackingLayerTreeHost( |
125 &fake_client_, layer_tree_settings_)); | 125 &fake_client_, layer_tree_settings_)); |
126 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); | 126 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); |
127 // Force output surface creation for renderer capabilities. | 127 // Force output surface creation for renderer capabilities. |
128 layer_tree_host_->Composite(base::TimeTicks()); | 128 layer_tree_host_->Composite(base::TimeTicks()); |
129 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); | 129 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); |
130 } | 130 } |
131 | 131 |
| 132 const LayerSettings& layer_settings() { return layer_settings_; } |
| 133 |
132 protected: | 134 protected: |
133 FakeLayerTreeHostClient fake_client_; | 135 FakeLayerTreeHostClient fake_client_; |
134 LayerTreeSettings layer_tree_settings_; | 136 LayerTreeSettings layer_tree_settings_; |
| 137 LayerSettings layer_settings_; |
135 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; | 138 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; |
136 }; | 139 }; |
137 | 140 |
138 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer) { | 141 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
139 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 142 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
140 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 143 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
141 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); | 144 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, |
| 145 0, 0); |
142 | 146 |
143 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 147 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
144 PaintedScrollbarLayerImpl* cc_child2 = | 148 PaintedScrollbarLayerImpl* cc_child2 = |
145 static_cast<PaintedScrollbarLayerImpl*>( | 149 static_cast<PaintedScrollbarLayerImpl*>( |
146 layer_impl_tree_root->children()[1]); | 150 layer_impl_tree_root->children()[1]); |
147 | 151 |
148 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); | 152 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); |
149 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); | 153 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); |
150 } | 154 } |
151 | 155 |
152 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { | 156 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
153 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 157 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
154 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 158 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
155 layer_tree_host_.get(), scrollbar.Pass(), true, false, 0, 0); | 159 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), true, false, |
| 160 0, 0); |
156 | 161 |
157 PaintedScrollbarLayerImpl* cc_child1 = | 162 PaintedScrollbarLayerImpl* cc_child1 = |
158 static_cast<PaintedScrollbarLayerImpl*>( | 163 static_cast<PaintedScrollbarLayerImpl*>( |
159 layer_impl_tree_root->children()[0]); | 164 layer_impl_tree_root->children()[0]); |
160 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 165 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
161 | 166 |
162 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); | 167 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); |
163 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); | 168 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); |
164 } | 169 } |
165 | 170 |
166 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 171 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
167 // Create and attach a non-overlay scrollbar. | 172 // Create and attach a non-overlay scrollbar. |
168 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 173 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
169 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 174 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
170 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); | 175 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, |
| 176 0, 0); |
171 PaintedScrollbarLayerImpl* scrollbar_layer_impl = | 177 PaintedScrollbarLayerImpl* scrollbar_layer_impl = |
172 static_cast<PaintedScrollbarLayerImpl*>( | 178 static_cast<PaintedScrollbarLayerImpl*>( |
173 layer_impl_tree_root->children()[1]); | 179 layer_impl_tree_root->children()[1]); |
174 | 180 |
175 // When the scrollbar is not an overlay scrollbar, the scroll should be | 181 // When the scrollbar is not an overlay scrollbar, the scroll should be |
176 // responded to on the main thread as the compositor does not yet implement | 182 // responded to on the main thread as the compositor does not yet implement |
177 // scrollbar scrolling. | 183 // scrollbar scrolling. |
178 EXPECT_EQ( | 184 EXPECT_EQ( |
179 InputHandler::SCROLL_ON_MAIN_THREAD, | 185 InputHandler::SCROLL_ON_MAIN_THREAD, |
180 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, | 186 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, |
181 SCROLL_BLOCKS_ON_NONE)); | 187 SCROLL_BLOCKS_ON_NONE)); |
182 | 188 |
183 // Create and attach an overlay scrollbar. | 189 // Create and attach an overlay scrollbar. |
184 scrollbar.reset(new FakeScrollbar(false, false, true)); | 190 scrollbar.reset(new FakeScrollbar(false, false, true)); |
185 | 191 |
186 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 192 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
187 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); | 193 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false, |
| 194 0, 0); |
188 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( | 195 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
189 layer_impl_tree_root->children()[1]); | 196 layer_impl_tree_root->children()[1]); |
190 | 197 |
191 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 198 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
192 // may be handled in the compositor. | 199 // may be handled in the compositor. |
193 EXPECT_EQ( | 200 EXPECT_EQ( |
194 InputHandler::SCROLL_IGNORED, | 201 InputHandler::SCROLL_IGNORED, |
195 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, | 202 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, |
196 SCROLL_BLOCKS_ON_NONE)); | 203 SCROLL_BLOCKS_ON_NONE)); |
197 } | 204 } |
198 | 205 |
199 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { | 206 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { |
200 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 207 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
201 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 208 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
202 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 209 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); |
203 scoped_refptr<Layer> content_layer = Layer::Create(); | 210 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
204 scoped_refptr<Layer> scrollbar_layer = | 211 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( |
205 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 212 layer_settings(), scrollbar.Pass(), layer_tree_root->id()); |
206 | 213 |
207 // Choose bounds to give max_scroll_offset = (30, 50). | 214 // Choose bounds to give max_scroll_offset = (30, 50). |
208 layer_tree_root->SetBounds(gfx::Size(70, 150)); | 215 layer_tree_root->SetBounds(gfx::Size(70, 150)); |
209 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 216 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
210 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 217 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
211 scroll_layer->SetBounds(gfx::Size(100, 200)); | 218 scroll_layer->SetBounds(gfx::Size(100, 200)); |
212 content_layer->SetBounds(gfx::Size(100, 200)); | 219 content_layer->SetBounds(gfx::Size(100, 200)); |
213 | 220 |
214 layer_tree_host_->SetRootLayer(layer_tree_root); | 221 layer_tree_host_->SetRootLayer(layer_tree_root); |
215 layer_tree_root->AddChild(scroll_layer); | 222 layer_tree_root->AddChild(scroll_layer); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 scrollbar_layer->UpdateInternalContentScale(); \ | 267 scrollbar_layer->UpdateInternalContentScale(); \ |
261 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ | 268 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
262 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ | 269 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ |
263 root_layer_impl = root_clip_layer_impl->children()[0]; \ | 270 root_layer_impl = root_clip_layer_impl->children()[0]; \ |
264 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ | 271 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
265 root_layer_impl->children()[1]); \ | 272 root_layer_impl->children()[1]); \ |
266 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \ | 273 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \ |
267 } while (false) | 274 } while (false) |
268 | 275 |
269 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { | 276 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { |
270 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 277 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings()); |
271 scoped_refptr<Layer> root_layer = Layer::Create(); | 278 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); |
272 scoped_refptr<Layer> content_layer = Layer::Create(); | 279 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
273 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 280 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
274 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 281 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, |
| 282 root_layer->id()); |
275 | 283 |
276 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 284 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
277 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). | 285 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
278 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 286 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
279 root_layer->SetBounds(gfx::Size(100, 50)); | 287 root_layer->SetBounds(gfx::Size(100, 50)); |
280 content_layer->SetBounds(gfx::Size(100, 50)); | 288 content_layer->SetBounds(gfx::Size(100, 50)); |
281 | 289 |
282 layer_tree_host_->SetRootLayer(root_clip_layer); | 290 layer_tree_host_->SetRootLayer(root_clip_layer); |
283 root_clip_layer->AddChild(root_layer); | 291 root_clip_layer->AddChild(root_layer); |
284 root_layer->AddChild(content_layer); | 292 root_layer->AddChild(content_layer); |
(...skipping 16 matching lines...) Expand all Loading... |
301 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 309 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
302 | 310 |
303 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); | 311 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); |
304 | 312 |
305 UPDATE_AND_EXTRACT_LAYER_POINTERS(); | 313 UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
306 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), | 314 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), |
307 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 315 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
308 } | 316 } |
309 | 317 |
310 TEST_F(ScrollbarLayerTest, ThumbRect) { | 318 TEST_F(ScrollbarLayerTest, ThumbRect) { |
311 scoped_refptr<Layer> root_clip_layer = Layer::Create(); | 319 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings()); |
312 scoped_refptr<Layer> root_layer = Layer::Create(); | 320 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); |
313 scoped_refptr<Layer> content_layer = Layer::Create(); | 321 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
314 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 322 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
315 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); | 323 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, |
| 324 root_layer->id()); |
316 | 325 |
317 root_layer->SetScrollClipLayerId(root_clip_layer->id()); | 326 root_layer->SetScrollClipLayerId(root_clip_layer->id()); |
318 // 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). |
319 root_clip_layer->SetBounds(gfx::Size(20, 50)); | 328 root_clip_layer->SetBounds(gfx::Size(20, 50)); |
320 root_layer->SetBounds(gfx::Size(100, 50)); | 329 root_layer->SetBounds(gfx::Size(100, 50)); |
321 content_layer->SetBounds(gfx::Size(100, 50)); | 330 content_layer->SetBounds(gfx::Size(100, 50)); |
322 | 331 |
323 layer_tree_host_->SetRootLayer(root_clip_layer); | 332 layer_tree_host_->SetRootLayer(root_clip_layer); |
324 root_clip_layer->AddChild(root_layer); | 333 root_clip_layer->AddChild(root_layer); |
325 root_layer->AddChild(content_layer); | 334 root_layer->AddChild(content_layer); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); | 394 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
386 } | 395 } |
387 | 396 |
388 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { | 397 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { |
389 const int kThumbThickness = 3; | 398 const int kThumbThickness = 3; |
390 const int kTrackStart = 1; | 399 const int kTrackStart = 1; |
391 const int kTrackLength = 100; | 400 const int kTrackLength = 100; |
392 | 401 |
393 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 402 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
394 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 403 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
395 layer_tree_host_.get(), scrollbar.Pass(), false, true, kThumbThickness, | 404 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, true, |
396 kTrackStart); | 405 kThumbThickness, kTrackStart); |
397 ScrollbarLayerImplBase* scrollbar_layer_impl = | 406 ScrollbarLayerImplBase* scrollbar_layer_impl = |
398 static_cast<SolidColorScrollbarLayerImpl*>( | 407 static_cast<SolidColorScrollbarLayerImpl*>( |
399 layer_impl_tree_root->children()[1]); | 408 layer_impl_tree_root->children()[1]); |
400 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 409 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
401 scrollbar_layer_impl->SetCurrentPos(10.f); | 410 scrollbar_layer_impl->SetCurrentPos(10.f); |
402 scrollbar_layer_impl->SetMaximum(100); | 411 scrollbar_layer_impl->SetMaximum(100); |
403 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); | 412 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); |
404 | 413 |
405 // Thickness should be overridden to 3. | 414 // Thickness should be overridden to 3. |
406 { | 415 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 469 } |
461 | 470 |
462 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 471 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
463 const int kThumbThickness = 3; | 472 const int kThumbThickness = 3; |
464 const int kTrackStart = 0; | 473 const int kTrackStart = 0; |
465 const int kTrackLength = 10; | 474 const int kTrackLength = 10; |
466 | 475 |
467 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 476 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
468 | 477 |
469 { | 478 { |
470 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 479 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
471 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 480 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings()); |
472 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 481 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
473 scoped_refptr<Layer> child1 = Layer::Create(); | 482 scoped_refptr<Layer> child1 = Layer::Create(layer_settings()); |
474 scoped_refptr<Layer> child2; | 483 scoped_refptr<Layer> child2; |
475 const bool kIsLeftSideVerticalScrollbar = false; | 484 const bool kIsLeftSideVerticalScrollbar = false; |
476 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | 485 child2 = SolidColorScrollbarLayer::Create( |
477 kThumbThickness, | 486 layer_settings(), scrollbar->Orientation(), kThumbThickness, |
478 kTrackStart, | 487 kTrackStart, kIsLeftSideVerticalScrollbar, child1->id()); |
479 kIsLeftSideVerticalScrollbar, | |
480 child1->id()); | |
481 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); | 488 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
482 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); | 489 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
483 scroll_layer->AddChild(child1); | 490 scroll_layer->AddChild(child1); |
484 scroll_layer->InsertChild(child2, 1); | 491 scroll_layer->InsertChild(child2, 1); |
485 layer_tree_root->AddChild(scroll_layer); | 492 layer_tree_root->AddChild(scroll_layer); |
486 layer_tree_host_->SetRootLayer(layer_tree_root); | 493 layer_tree_host_->SetRootLayer(layer_tree_root); |
487 } | 494 } |
488 LayerImpl* layer_impl_tree_root = | 495 LayerImpl* layer_impl_tree_root = |
489 layer_tree_host_->CommitAndCreateLayerImplTree(); | 496 layer_tree_host_->CommitAndCreateLayerImplTree(); |
490 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; | 497 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 626 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
620 } | 627 } |
621 | 628 |
622 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { | 629 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { |
623 public: | 630 public: |
624 ScrollbarLayerTestMaxTextureSize() {} | 631 ScrollbarLayerTestMaxTextureSize() {} |
625 | 632 |
626 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } | 633 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } |
627 | 634 |
628 void BeginTest() override { | 635 void BeginTest() override { |
629 scroll_layer_ = Layer::Create(); | 636 scroll_layer_ = Layer::Create(layer_settings()); |
630 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 637 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
631 | 638 |
632 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 639 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
633 scrollbar_layer_ = | 640 scrollbar_layer_ = PaintedScrollbarLayer::Create( |
634 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); | 641 layer_settings(), scrollbar.Pass(), scroll_layer_->id()); |
635 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); | 642 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); |
636 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); | 643 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
637 scrollbar_layer_->SetBounds(bounds_); | 644 scrollbar_layer_->SetBounds(bounds_); |
638 scrollbar_layer_->SetIsDrawable(true); | 645 scrollbar_layer_->SetIsDrawable(true); |
639 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); | 646 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); |
640 | 647 |
641 PostSetNeedsCommitToMainThread(); | 648 PostSetNeedsCommitToMainThread(); |
642 } | 649 } |
643 | 650 |
644 void DidCommitAndDrawFrame() override { | 651 void DidCommitAndDrawFrame() override { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } | 690 } |
684 | 691 |
685 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { | 692 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { |
686 public: | 693 public: |
687 void TestResourceUpload(int num_updates, | 694 void TestResourceUpload(int num_updates, |
688 size_t expected_resources, | 695 size_t expected_resources, |
689 int expected_created, | 696 int expected_created, |
690 int expected_deleted, | 697 int expected_deleted, |
691 bool use_solid_color_scrollbar) { | 698 bool use_solid_color_scrollbar) { |
692 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 699 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
693 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 700 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
694 scoped_refptr<Layer> content_layer = Layer::Create(); | 701 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
695 scoped_refptr<Layer> scrollbar_layer; | 702 scoped_refptr<Layer> scrollbar_layer; |
696 if (use_solid_color_scrollbar) { | 703 if (use_solid_color_scrollbar) { |
697 const int kThumbThickness = 3; | 704 const int kThumbThickness = 3; |
698 const int kTrackStart = 0; | 705 const int kTrackStart = 0; |
699 const bool kIsLeftSideVerticalScrollbar = false; | 706 const bool kIsLeftSideVerticalScrollbar = false; |
700 scrollbar_layer = | 707 scrollbar_layer = SolidColorScrollbarLayer::Create( |
701 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | 708 layer_settings(), scrollbar->Orientation(), kThumbThickness, |
702 kThumbThickness, | 709 kTrackStart, kIsLeftSideVerticalScrollbar, layer_tree_root->id()); |
703 kTrackStart, | |
704 kIsLeftSideVerticalScrollbar, | |
705 layer_tree_root->id()); | |
706 } else { | 710 } else { |
707 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), | 711 scrollbar_layer = PaintedScrollbarLayer::Create( |
708 layer_tree_root->id()); | 712 layer_settings(), scrollbar.Pass(), layer_tree_root->id()); |
709 } | 713 } |
710 layer_tree_root->AddChild(content_layer); | 714 layer_tree_root->AddChild(content_layer); |
711 layer_tree_root->AddChild(scrollbar_layer); | 715 layer_tree_root->AddChild(scrollbar_layer); |
712 | 716 |
713 layer_tree_host_->SetRootLayer(layer_tree_root); | 717 layer_tree_host_->SetRootLayer(layer_tree_root); |
714 | 718 |
715 scrollbar_layer->SetIsDrawable(true); | 719 scrollbar_layer->SetIsDrawable(true); |
716 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 720 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
717 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 721 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
718 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 722 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 765 |
762 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, | 766 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, |
763 SolidColorNoResourceUpload) { | 767 SolidColorNoResourceUpload) { |
764 bool use_solid_color_scrollbars = true; | 768 bool use_solid_color_scrollbars = true; |
765 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); | 769 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
766 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); | 770 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); |
767 } | 771 } |
768 | 772 |
769 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { | 773 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { |
770 gfx::Point scrollbar_location(0, 185); | 774 gfx::Point scrollbar_location(0, 185); |
771 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 775 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
772 scoped_refptr<Layer> content_layer = Layer::Create(); | 776 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
773 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 777 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
774 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); | 778 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, |
| 779 layer_tree_root->id()); |
775 | 780 |
776 layer_tree_root->AddChild(content_layer); | 781 layer_tree_root->AddChild(content_layer); |
777 layer_tree_root->AddChild(scrollbar_layer); | 782 layer_tree_root->AddChild(scrollbar_layer); |
778 | 783 |
779 layer_tree_host_->SetRootLayer(layer_tree_root); | 784 layer_tree_host_->SetRootLayer(layer_tree_root); |
780 | 785 |
781 scrollbar_layer->SetIsDrawable(true); | 786 scrollbar_layer->SetIsDrawable(true); |
782 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 787 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
783 scrollbar_layer->SetPosition(scrollbar_location); | 788 scrollbar_layer->SetPosition(scrollbar_location); |
784 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 789 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); | 903 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); |
899 | 904 |
900 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 905 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
901 scrollbar_layer->ClearRenderSurface(); | 906 scrollbar_layer->ClearRenderSurface(); |
902 } | 907 } |
903 | 908 |
904 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { | 909 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { |
905 public: | 910 public: |
906 void TestResourceUpload(const float test_scale) { | 911 void TestResourceUpload(const float test_scale) { |
907 gfx::Point scrollbar_location(0, 185); | 912 gfx::Point scrollbar_location(0, 185); |
908 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 913 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
909 scoped_refptr<Layer> content_layer = Layer::Create(); | 914 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings()); |
910 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 915 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
911 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); | 916 FakePaintedScrollbarLayer::Create(layer_settings(), false, true, |
| 917 layer_tree_root->id()); |
912 | 918 |
913 layer_tree_root->AddChild(content_layer); | 919 layer_tree_root->AddChild(content_layer); |
914 layer_tree_root->AddChild(scrollbar_layer); | 920 layer_tree_root->AddChild(scrollbar_layer); |
915 | 921 |
916 layer_tree_host_->SetRootLayer(layer_tree_root); | 922 layer_tree_host_->SetRootLayer(layer_tree_root); |
917 | 923 |
918 scrollbar_layer->SetIsDrawable(true); | 924 scrollbar_layer->SetIsDrawable(true); |
919 scrollbar_layer->SetBounds(gfx::Size(100, 15)); | 925 scrollbar_layer->SetBounds(gfx::Size(100, 15)); |
920 scrollbar_layer->SetPosition(scrollbar_location); | 926 scrollbar_layer->SetPosition(scrollbar_location); |
921 layer_tree_root->SetBounds(gfx::Size(100, 200)); | 927 layer_tree_root->SetBounds(gfx::Size(100, 200)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 TestResourceUpload(.041f); | 980 TestResourceUpload(.041f); |
975 TestResourceUpload(1.41f); | 981 TestResourceUpload(1.41f); |
976 TestResourceUpload(4.1f); | 982 TestResourceUpload(4.1f); |
977 } | 983 } |
978 | 984 |
979 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { | 985 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { |
980 public: | 986 public: |
981 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { | 987 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { |
982 bool paint_during_update = true; | 988 bool paint_during_update = true; |
983 bool has_thumb = false; | 989 bool has_thumb = false; |
984 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 990 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings()); |
985 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 991 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
986 FakePaintedScrollbarLayer::Create(paint_during_update, | 992 FakePaintedScrollbarLayer::Create(layer_settings(), paint_during_update, |
987 has_thumb, | 993 has_thumb, layer_tree_root->id()); |
988 layer_tree_root->id()); | |
989 | 994 |
990 layer_tree_root->AddChild(scrollbar_layer); | 995 layer_tree_root->AddChild(scrollbar_layer); |
991 | 996 |
992 layer_tree_host_->SetRootLayer(layer_tree_root); | 997 layer_tree_host_->SetRootLayer(layer_tree_root); |
993 | 998 |
994 scrollbar_layer->SetBounds(scrollbar_rect.size()); | 999 scrollbar_layer->SetBounds(scrollbar_rect.size()); |
995 scrollbar_layer->SetPosition(scrollbar_rect.origin()); | 1000 scrollbar_layer->SetPosition(scrollbar_rect.origin()); |
996 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); | 1001 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); |
997 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); | 1002 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); |
998 gfx::SizeF scaled_size = | 1003 gfx::SizeF scaled_size = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1066 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
1062 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1067 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
1063 | 1068 |
1064 // Horizontal Scrollbars. | 1069 // Horizontal Scrollbars. |
1065 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1070 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
1066 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1071 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
1067 } | 1072 } |
1068 | 1073 |
1069 } // namespace | 1074 } // namespace |
1070 } // namespace cc | 1075 } // namespace cc |
OLD | NEW |