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

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

Issue 1122393003: CC: Plumb LayerSettings parameter for cc::Layer construction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_unittest.cc ('k') | cc/layers/solid_color_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 params.settings = &layer_tree_settings_; 127 params.settings = &layer_tree_settings_;
128 128
129 layer_tree_host_.reset( 129 layer_tree_host_.reset(
130 new FakeResourceTrackingLayerTreeHost(&fake_client_, &params)); 130 new FakeResourceTrackingLayerTreeHost(&fake_client_, &params));
131 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); 131 fake_client_.SetLayerTreeHost(layer_tree_host_.get());
132 // Force output surface creation for renderer capabilities. 132 // Force output surface creation for renderer capabilities.
133 layer_tree_host_->Composite(base::TimeTicks()); 133 layer_tree_host_->Composite(base::TimeTicks());
134 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); 134 EXPECT_FALSE(layer_tree_host_->output_surface_lost());
135 } 135 }
136 136
137 const LayerSettings& layer_settings() { return layer_settings_; }
138
137 protected: 139 protected:
138 FakeLayerTreeHostClient fake_client_; 140 FakeLayerTreeHostClient fake_client_;
139 LayerTreeSettings layer_tree_settings_; 141 LayerTreeSettings layer_tree_settings_;
142 LayerSettings layer_settings_;
140 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; 143 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_;
141 }; 144 };
142 145
143 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer) { 146 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer) {
144 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 147 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
145 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 148 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
146 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); 149 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false,
150 0, 0);
147 151
148 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 152 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
149 PaintedScrollbarLayerImpl* cc_child2 = 153 PaintedScrollbarLayerImpl* cc_child2 =
150 static_cast<PaintedScrollbarLayerImpl*>( 154 static_cast<PaintedScrollbarLayerImpl*>(
151 layer_impl_tree_root->children()[1]); 155 layer_impl_tree_root->children()[1]);
152 156
153 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); 157 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL);
154 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); 158 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2);
155 } 159 }
156 160
157 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { 161 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
158 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 162 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
159 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 163 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
160 layer_tree_host_.get(), scrollbar.Pass(), true, false, 0, 0); 164 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), true, false,
165 0, 0);
161 166
162 PaintedScrollbarLayerImpl* cc_child1 = 167 PaintedScrollbarLayerImpl* cc_child1 =
163 static_cast<PaintedScrollbarLayerImpl*>( 168 static_cast<PaintedScrollbarLayerImpl*>(
164 layer_impl_tree_root->children()[0]); 169 layer_impl_tree_root->children()[0]);
165 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 170 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
166 171
167 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); 172 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL);
168 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); 173 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1);
169 } 174 }
170 175
171 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 176 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
172 // Create and attach a non-overlay scrollbar. 177 // Create and attach a non-overlay scrollbar.
173 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 178 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
174 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 179 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
175 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); 180 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false,
181 0, 0);
176 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 182 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
177 static_cast<PaintedScrollbarLayerImpl*>( 183 static_cast<PaintedScrollbarLayerImpl*>(
178 layer_impl_tree_root->children()[1]); 184 layer_impl_tree_root->children()[1]);
179 185
180 // When the scrollbar is not an overlay scrollbar, the scroll should be 186 // When the scrollbar is not an overlay scrollbar, the scroll should be
181 // responded to on the main thread as the compositor does not yet implement 187 // responded to on the main thread as the compositor does not yet implement
182 // scrollbar scrolling. 188 // scrollbar scrolling.
183 EXPECT_EQ( 189 EXPECT_EQ(
184 InputHandler::SCROLL_ON_MAIN_THREAD, 190 InputHandler::SCROLL_ON_MAIN_THREAD,
185 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, 191 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE,
186 SCROLL_BLOCKS_ON_NONE)); 192 SCROLL_BLOCKS_ON_NONE));
187 193
188 // Create and attach an overlay scrollbar. 194 // Create and attach an overlay scrollbar.
189 scrollbar.reset(new FakeScrollbar(false, false, true)); 195 scrollbar.reset(new FakeScrollbar(false, false, true));
190 196
191 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 197 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
192 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); 198 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, false,
199 0, 0);
193 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( 200 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
194 layer_impl_tree_root->children()[1]); 201 layer_impl_tree_root->children()[1]);
195 202
196 // The user shouldn't be able to drag an overlay scrollbar and the scroll 203 // The user shouldn't be able to drag an overlay scrollbar and the scroll
197 // may be handled in the compositor. 204 // may be handled in the compositor.
198 EXPECT_EQ( 205 EXPECT_EQ(
199 InputHandler::SCROLL_IGNORED, 206 InputHandler::SCROLL_IGNORED,
200 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE, 207 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), InputHandler::GESTURE,
201 SCROLL_BLOCKS_ON_NONE)); 208 SCROLL_BLOCKS_ON_NONE));
202 } 209 }
203 210
204 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { 211 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
205 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 212 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
206 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 213 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings());
207 scoped_refptr<Layer> scroll_layer = Layer::Create(); 214 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings());
208 scoped_refptr<Layer> content_layer = Layer::Create(); 215 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
209 scoped_refptr<Layer> scrollbar_layer = 216 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create(
210 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 217 layer_settings(), scrollbar.Pass(), layer_tree_root->id());
211 218
212 // Choose bounds to give max_scroll_offset = (30, 50). 219 // Choose bounds to give max_scroll_offset = (30, 50).
213 layer_tree_root->SetBounds(gfx::Size(70, 150)); 220 layer_tree_root->SetBounds(gfx::Size(70, 150));
214 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 221 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
215 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); 222 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20));
216 scroll_layer->SetBounds(gfx::Size(100, 200)); 223 scroll_layer->SetBounds(gfx::Size(100, 200));
217 content_layer->SetBounds(gfx::Size(100, 200)); 224 content_layer->SetBounds(gfx::Size(100, 200));
218 225
219 layer_tree_host_->SetRootLayer(layer_tree_root); 226 layer_tree_host_->SetRootLayer(layer_tree_root);
220 layer_tree_root->AddChild(scroll_layer); 227 layer_tree_root->AddChild(scroll_layer);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 scrollbar_layer->UpdateInternalContentScale(); \ 272 scrollbar_layer->UpdateInternalContentScale(); \
266 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ 273 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
267 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ 274 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \
268 root_layer_impl = root_clip_layer_impl->children()[0]; \ 275 root_layer_impl = root_clip_layer_impl->children()[0]; \
269 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 276 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
270 root_layer_impl->children()[1]); \ 277 root_layer_impl->children()[1]); \
271 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \ 278 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \
272 } while (false) 279 } while (false)
273 280
274 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 281 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
275 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 282 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings());
276 scoped_refptr<Layer> root_layer = Layer::Create(); 283 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings());
277 scoped_refptr<Layer> content_layer = Layer::Create(); 284 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
278 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 285 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
279 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 286 FakePaintedScrollbarLayer::Create(layer_settings(), false, true,
287 root_layer->id());
280 288
281 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 289 root_layer->SetScrollClipLayerId(root_clip_layer->id());
282 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 290 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
283 root_clip_layer->SetBounds(gfx::Size(20, 50)); 291 root_clip_layer->SetBounds(gfx::Size(20, 50));
284 root_layer->SetBounds(gfx::Size(100, 50)); 292 root_layer->SetBounds(gfx::Size(100, 50));
285 content_layer->SetBounds(gfx::Size(100, 50)); 293 content_layer->SetBounds(gfx::Size(100, 50));
286 294
287 layer_tree_host_->SetRootLayer(root_clip_layer); 295 layer_tree_host_->SetRootLayer(root_clip_layer);
288 root_clip_layer->AddChild(root_layer); 296 root_clip_layer->AddChild(root_layer);
289 root_layer->AddChild(content_layer); 297 root_layer->AddChild(content_layer);
(...skipping 16 matching lines...) Expand all
306 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 314 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
307 315
308 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); 316 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
309 317
310 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 318 UPDATE_AND_EXTRACT_LAYER_POINTERS();
311 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), 319 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(),
312 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 320 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
313 } 321 }
314 322
315 TEST_F(ScrollbarLayerTest, ThumbRect) { 323 TEST_F(ScrollbarLayerTest, ThumbRect) {
316 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 324 scoped_refptr<Layer> root_clip_layer = Layer::Create(layer_settings());
317 scoped_refptr<Layer> root_layer = Layer::Create(); 325 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings());
318 scoped_refptr<Layer> content_layer = Layer::Create(); 326 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
319 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 327 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
320 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 328 FakePaintedScrollbarLayer::Create(layer_settings(), false, true,
329 root_layer->id());
321 330
322 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 331 root_layer->SetScrollClipLayerId(root_clip_layer->id());
323 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 332 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
324 root_clip_layer->SetBounds(gfx::Size(20, 50)); 333 root_clip_layer->SetBounds(gfx::Size(20, 50));
325 root_layer->SetBounds(gfx::Size(100, 50)); 334 root_layer->SetBounds(gfx::Size(100, 50));
326 content_layer->SetBounds(gfx::Size(100, 50)); 335 content_layer->SetBounds(gfx::Size(100, 50));
327 336
328 layer_tree_host_->SetRootLayer(root_clip_layer); 337 layer_tree_host_->SetRootLayer(root_clip_layer);
329 root_clip_layer->AddChild(root_layer); 338 root_clip_layer->AddChild(root_layer);
330 root_layer->AddChild(content_layer); 339 root_layer->AddChild(content_layer);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 399 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
391 } 400 }
392 401
393 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { 402 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) {
394 const int kThumbThickness = 3; 403 const int kThumbThickness = 3;
395 const int kTrackStart = 1; 404 const int kTrackStart = 1;
396 const int kTrackLength = 100; 405 const int kTrackLength = 100;
397 406
398 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 407 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
399 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 408 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
400 layer_tree_host_.get(), scrollbar.Pass(), false, true, kThumbThickness, 409 layer_settings(), layer_tree_host_.get(), scrollbar.Pass(), false, true,
401 kTrackStart); 410 kThumbThickness, kTrackStart);
402 ScrollbarLayerImplBase* scrollbar_layer_impl = 411 ScrollbarLayerImplBase* scrollbar_layer_impl =
403 static_cast<SolidColorScrollbarLayerImpl*>( 412 static_cast<SolidColorScrollbarLayerImpl*>(
404 layer_impl_tree_root->children()[1]); 413 layer_impl_tree_root->children()[1]);
405 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 414 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
406 scrollbar_layer_impl->SetCurrentPos(10.f); 415 scrollbar_layer_impl->SetCurrentPos(10.f);
407 scrollbar_layer_impl->SetMaximum(100); 416 scrollbar_layer_impl->SetMaximum(100);
408 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); 417 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f);
409 418
410 // Thickness should be overridden to 3. 419 // Thickness should be overridden to 3.
411 { 420 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 474 }
466 475
467 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 476 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
468 const int kThumbThickness = 3; 477 const int kThumbThickness = 3;
469 const int kTrackStart = 0; 478 const int kTrackStart = 0;
470 const int kTrackLength = 10; 479 const int kTrackLength = 10;
471 480
472 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 481 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
473 482
474 { 483 {
475 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 484 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings());
476 scoped_refptr<Layer> scroll_layer = Layer::Create(); 485 scoped_refptr<Layer> scroll_layer = Layer::Create(layer_settings());
477 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 486 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
478 scoped_refptr<Layer> child1 = Layer::Create(); 487 scoped_refptr<Layer> child1 = Layer::Create(layer_settings());
479 scoped_refptr<Layer> child2; 488 scoped_refptr<Layer> child2;
480 const bool kIsLeftSideVerticalScrollbar = false; 489 const bool kIsLeftSideVerticalScrollbar = false;
481 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 490 child2 = SolidColorScrollbarLayer::Create(
482 kThumbThickness, 491 layer_settings(), scrollbar->Orientation(), kThumbThickness,
483 kTrackStart, 492 kTrackStart, kIsLeftSideVerticalScrollbar, child1->id());
484 kIsLeftSideVerticalScrollbar,
485 child1->id());
486 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 493 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
487 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 494 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
488 scroll_layer->AddChild(child1); 495 scroll_layer->AddChild(child1);
489 scroll_layer->InsertChild(child2, 1); 496 scroll_layer->InsertChild(child2, 1);
490 layer_tree_root->AddChild(scroll_layer); 497 layer_tree_root->AddChild(scroll_layer);
491 layer_tree_host_->SetRootLayer(layer_tree_root); 498 layer_tree_host_->SetRootLayer(layer_tree_root);
492 } 499 }
493 LayerImpl* layer_impl_tree_root = 500 LayerImpl* layer_impl_tree_root =
494 layer_tree_host_->CommitAndCreateLayerImplTree(); 501 layer_tree_host_->CommitAndCreateLayerImplTree();
495 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 502 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 631 vertical_scrollbar_layer_->ComputeThumbQuadRect());
625 } 632 }
626 633
627 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { 634 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
628 public: 635 public:
629 ScrollbarLayerTestMaxTextureSize() {} 636 ScrollbarLayerTestMaxTextureSize() {}
630 637
631 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; } 638 void SetScrollbarBounds(const gfx::Size& bounds) { bounds_ = bounds; }
632 639
633 void BeginTest() override { 640 void BeginTest() override {
634 scroll_layer_ = Layer::Create(); 641 scroll_layer_ = Layer::Create(layer_settings());
635 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 642 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
636 643
637 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 644 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
638 scrollbar_layer_ = 645 scrollbar_layer_ = PaintedScrollbarLayer::Create(
639 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); 646 layer_settings(), scrollbar.Pass(), scroll_layer_->id());
640 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); 647 scrollbar_layer_->SetScrollLayer(scroll_layer_->id());
641 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 648 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
642 scrollbar_layer_->SetBounds(bounds_); 649 scrollbar_layer_->SetBounds(bounds_);
643 scrollbar_layer_->SetIsDrawable(true); 650 scrollbar_layer_->SetIsDrawable(true);
644 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 651 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
645 652
646 PostSetNeedsCommitToMainThread(); 653 PostSetNeedsCommitToMainThread();
647 } 654 }
648 655
649 void DidCommitAndDrawFrame() override { 656 void DidCommitAndDrawFrame() override {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 695 }
689 696
690 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { 697 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
691 public: 698 public:
692 void TestResourceUpload(int num_updates, 699 void TestResourceUpload(int num_updates,
693 size_t expected_resources, 700 size_t expected_resources,
694 int expected_created, 701 int expected_created,
695 int expected_deleted, 702 int expected_deleted,
696 bool use_solid_color_scrollbar) { 703 bool use_solid_color_scrollbar) {
697 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 704 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
698 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 705 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings());
699 scoped_refptr<Layer> content_layer = Layer::Create(); 706 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
700 scoped_refptr<Layer> scrollbar_layer; 707 scoped_refptr<Layer> scrollbar_layer;
701 if (use_solid_color_scrollbar) { 708 if (use_solid_color_scrollbar) {
702 const int kThumbThickness = 3; 709 const int kThumbThickness = 3;
703 const int kTrackStart = 0; 710 const int kTrackStart = 0;
704 const bool kIsLeftSideVerticalScrollbar = false; 711 const bool kIsLeftSideVerticalScrollbar = false;
705 scrollbar_layer = 712 scrollbar_layer = SolidColorScrollbarLayer::Create(
706 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 713 layer_settings(), scrollbar->Orientation(), kThumbThickness,
707 kThumbThickness, 714 kTrackStart, kIsLeftSideVerticalScrollbar, layer_tree_root->id());
708 kTrackStart,
709 kIsLeftSideVerticalScrollbar,
710 layer_tree_root->id());
711 } else { 715 } else {
712 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), 716 scrollbar_layer = PaintedScrollbarLayer::Create(
713 layer_tree_root->id()); 717 layer_settings(), scrollbar.Pass(), layer_tree_root->id());
714 } 718 }
715 layer_tree_root->AddChild(content_layer); 719 layer_tree_root->AddChild(content_layer);
716 layer_tree_root->AddChild(scrollbar_layer); 720 layer_tree_root->AddChild(scrollbar_layer);
717 721
718 layer_tree_host_->SetRootLayer(layer_tree_root); 722 layer_tree_host_->SetRootLayer(layer_tree_root);
719 723
720 scrollbar_layer->SetIsDrawable(true); 724 scrollbar_layer->SetIsDrawable(true);
721 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 725 scrollbar_layer->SetBounds(gfx::Size(100, 100));
722 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); 726 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20));
723 layer_tree_root->SetBounds(gfx::Size(100, 200)); 727 layer_tree_root->SetBounds(gfx::Size(100, 200));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 770
767 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, 771 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
768 SolidColorNoResourceUpload) { 772 SolidColorNoResourceUpload) {
769 bool use_solid_color_scrollbars = true; 773 bool use_solid_color_scrollbars = true;
770 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 774 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
771 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 775 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
772 } 776 }
773 777
774 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { 778 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) {
775 gfx::Point scrollbar_location(0, 185); 779 gfx::Point scrollbar_location(0, 185);
776 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 780 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings());
777 scoped_refptr<Layer> content_layer = Layer::Create(); 781 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
778 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 782 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
779 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 783 FakePaintedScrollbarLayer::Create(layer_settings(), false, true,
784 layer_tree_root->id());
780 785
781 layer_tree_root->AddChild(content_layer); 786 layer_tree_root->AddChild(content_layer);
782 layer_tree_root->AddChild(scrollbar_layer); 787 layer_tree_root->AddChild(scrollbar_layer);
783 788
784 layer_tree_host_->SetRootLayer(layer_tree_root); 789 layer_tree_host_->SetRootLayer(layer_tree_root);
785 790
786 scrollbar_layer->SetIsDrawable(true); 791 scrollbar_layer->SetIsDrawable(true);
787 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 792 scrollbar_layer->SetBounds(gfx::Size(100, 15));
788 scrollbar_layer->SetPosition(scrollbar_location); 793 scrollbar_layer->SetPosition(scrollbar_location);
789 layer_tree_root->SetBounds(gfx::Size(100, 200)); 794 layer_tree_root->SetBounds(gfx::Size(100, 200));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 908 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
904 909
905 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 910 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
906 scrollbar_layer->ClearRenderSurface(); 911 scrollbar_layer->ClearRenderSurface();
907 } 912 }
908 913
909 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { 914 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest {
910 public: 915 public:
911 void TestResourceUpload(const float test_scale) { 916 void TestResourceUpload(const float test_scale) {
912 gfx::Point scrollbar_location(0, 185); 917 gfx::Point scrollbar_location(0, 185);
913 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 918 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings());
914 scoped_refptr<Layer> content_layer = Layer::Create(); 919 scoped_refptr<Layer> content_layer = Layer::Create(layer_settings());
915 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 920 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
916 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 921 FakePaintedScrollbarLayer::Create(layer_settings(), false, true,
922 layer_tree_root->id());
917 923
918 layer_tree_root->AddChild(content_layer); 924 layer_tree_root->AddChild(content_layer);
919 layer_tree_root->AddChild(scrollbar_layer); 925 layer_tree_root->AddChild(scrollbar_layer);
920 926
921 layer_tree_host_->SetRootLayer(layer_tree_root); 927 layer_tree_host_->SetRootLayer(layer_tree_root);
922 928
923 scrollbar_layer->SetIsDrawable(true); 929 scrollbar_layer->SetIsDrawable(true);
924 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 930 scrollbar_layer->SetBounds(gfx::Size(100, 15));
925 scrollbar_layer->SetPosition(scrollbar_location); 931 scrollbar_layer->SetPosition(scrollbar_location);
926 layer_tree_root->SetBounds(gfx::Size(100, 200)); 932 layer_tree_root->SetBounds(gfx::Size(100, 200));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 TestResourceUpload(.041f); 985 TestResourceUpload(.041f);
980 TestResourceUpload(1.41f); 986 TestResourceUpload(1.41f);
981 TestResourceUpload(4.1f); 987 TestResourceUpload(4.1f);
982 } 988 }
983 989
984 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { 990 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest {
985 public: 991 public:
986 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 992 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
987 bool paint_during_update = true; 993 bool paint_during_update = true;
988 bool has_thumb = false; 994 bool has_thumb = false;
989 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 995 scoped_refptr<Layer> layer_tree_root = Layer::Create(layer_settings());
990 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 996 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
991 FakePaintedScrollbarLayer::Create(paint_during_update, 997 FakePaintedScrollbarLayer::Create(layer_settings(), paint_during_update,
992 has_thumb, 998 has_thumb, layer_tree_root->id());
993 layer_tree_root->id());
994 999
995 layer_tree_root->AddChild(scrollbar_layer); 1000 layer_tree_root->AddChild(scrollbar_layer);
996 1001
997 layer_tree_host_->SetRootLayer(layer_tree_root); 1002 layer_tree_host_->SetRootLayer(layer_tree_root);
998 1003
999 scrollbar_layer->SetBounds(scrollbar_rect.size()); 1004 scrollbar_layer->SetBounds(scrollbar_rect.size());
1000 scrollbar_layer->SetPosition(scrollbar_rect.origin()); 1005 scrollbar_layer->SetPosition(scrollbar_rect.origin());
1001 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); 1006 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin());
1002 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); 1007 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect);
1003 gfx::SizeF scaled_size = 1008 gfx::SizeF scaled_size =
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1071 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1067 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1072 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1068 1073
1069 // Horizontal Scrollbars. 1074 // Horizontal Scrollbars.
1070 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1075 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1071 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1076 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1072 } 1077 }
1073 1078
1074 } // namespace 1079 } // namespace
1075 } // namespace cc 1080 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_unittest.cc ('k') | cc/layers/solid_color_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698