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

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

Issue 1801853002: Transfer LayerImpl ownership to LayerTreeImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more asan. Created 4 years, 9 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/render_surface_impl_unittest.cc ('k') | cc/test/fake_layer_tree_host.cc » ('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 <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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; 144 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_;
145 }; 145 };
146 146
147 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 147 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
148 // Create and attach a non-overlay scrollbar. 148 // Create and attach a non-overlay scrollbar.
149 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 149 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
150 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 150 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
151 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); 151 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0);
152 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 152 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
153 static_cast<PaintedScrollbarLayerImpl*>( 153 static_cast<PaintedScrollbarLayerImpl*>(
154 layer_impl_tree_root->children()[1].get()); 154 layer_impl_tree_root->children()[1]);
155 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); 155 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting();
156 ScrollTree& scroll_tree = 156 ScrollTree& scroll_tree =
157 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; 157 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree;
158 ScrollNode* scroll_node = 158 ScrollNode* scroll_node =
159 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); 159 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index());
160 160
161 // 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
162 // 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
163 // scrollbar scrolling. 163 // scrollbar scrolling.
164 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll( 164 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll(
165 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); 165 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node);
166 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); 166 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread);
167 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling, 167 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling,
168 status.main_thread_scrolling_reasons); 168 status.main_thread_scrolling_reasons);
169 169
170 // Create and attach an overlay scrollbar. 170 // Create and attach an overlay scrollbar.
171 scrollbar.reset(new FakeScrollbar(false, false, true)); 171 scrollbar.reset(new FakeScrollbar(false, false, true));
172 172
173 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 173 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
174 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); 174 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0);
175 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( 175 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
176 layer_impl_tree_root->children()[1].get()); 176 layer_impl_tree_root->children()[1]);
177 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); 177 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting();
178 scroll_tree = 178 scroll_tree =
179 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; 179 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree;
180 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); 180 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index());
181 181
182 // 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
183 // may be handled in the compositor. 183 // may be handled in the compositor.
184 status = layer_tree_host_->host_impl()->TryScroll( 184 status = layer_tree_host_->host_impl()->TryScroll(
185 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); 185 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node);
186 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); 186 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread);
(...skipping 24 matching lines...) Expand all
211 211
212 layer_tree_root->SavePaintProperties(); 212 layer_tree_root->SavePaintProperties();
213 content_layer->SavePaintProperties(); 213 content_layer->SavePaintProperties();
214 214
215 layer_tree_host_->UpdateLayers(); 215 layer_tree_host_->UpdateLayers();
216 LayerImpl* layer_impl_tree_root = 216 LayerImpl* layer_impl_tree_root =
217 layer_tree_host_->CommitAndCreateLayerImplTree(); 217 layer_tree_host_->CommitAndCreateLayerImplTree();
218 218
219 ScrollbarLayerImplBase* cc_scrollbar_layer = 219 ScrollbarLayerImplBase* cc_scrollbar_layer =
220 static_cast<PaintedScrollbarLayerImpl*>( 220 static_cast<PaintedScrollbarLayerImpl*>(
221 layer_impl_tree_root->children()[1].get()); 221 layer_impl_tree_root->children()[1]);
222 222
223 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 223 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
224 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() - 224 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() -
225 cc_scrollbar_layer->clip_layer_length()); 225 cc_scrollbar_layer->clip_layer_length());
226 226
227 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 227 layer_tree_root->SetBounds(gfx::Size(700, 1500));
228 layer_tree_root->SavePaintProperties(); 228 layer_tree_root->SavePaintProperties();
229 scroll_layer->SetBounds(gfx::Size(1000, 2000)); 229 scroll_layer->SetBounds(gfx::Size(1000, 2000));
230 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); 230 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200));
231 scroll_layer->SavePaintProperties(); 231 scroll_layer->SavePaintProperties();
232 content_layer->SetBounds(gfx::Size(1000, 2000)); 232 content_layer->SetBounds(gfx::Size(1000, 2000));
233 content_layer->SavePaintProperties(); 233 content_layer->SavePaintProperties();
234 234
235 layer_tree_host_->UpdateLayers(); 235 layer_tree_host_->UpdateLayers();
236 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); 236 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree();
237 237
238 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); 238 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
239 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - 239 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() -
240 cc_scrollbar_layer->clip_layer_length()); 240 cc_scrollbar_layer->clip_layer_length());
241 241
242 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0].get(); 242 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
243 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); 243 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
244 244
245 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); 245 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
246 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - 246 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() -
247 cc_scrollbar_layer->clip_layer_length()); 247 cc_scrollbar_layer->clip_layer_length());
248 } 248 }
249 249
250 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ 250 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \
251 do { \ 251 do { \
252 scrollbar_layer->UpdateInternalContentScale(); \ 252 scrollbar_layer->UpdateInternalContentScale(); \
253 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ 253 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
254 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ 254 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \
255 root_layer_impl = root_clip_layer_impl->children()[0].get(); \ 255 root_layer_impl = root_clip_layer_impl->children()[0]; \
256 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 256 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
257 root_layer_impl->children()[1].get()); \ 257 root_layer_impl->children()[1]); \
258 } while (false) 258 } while (false)
259 259
260 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 260 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
261 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 261 scoped_refptr<Layer> root_clip_layer = Layer::Create();
262 scoped_refptr<Layer> root_layer = Layer::Create(); 262 scoped_refptr<Layer> root_layer = Layer::Create();
263 scoped_refptr<Layer> content_layer = Layer::Create(); 263 scoped_refptr<Layer> content_layer = Layer::Create();
264 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 264 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
265 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 265 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
266 266
267 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 267 root_layer->SetScrollClipLayerId(root_clip_layer->id());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 const int kThumbThickness = 3; 379 const int kThumbThickness = 3;
380 const int kTrackStart = 1; 380 const int kTrackStart = 1;
381 const int kTrackLength = 100; 381 const int kTrackLength = 100;
382 382
383 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 383 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
384 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 384 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
385 layer_tree_host_.get(), std::move(scrollbar), false, true, 385 layer_tree_host_.get(), std::move(scrollbar), false, true,
386 kThumbThickness, kTrackStart); 386 kThumbThickness, kTrackStart);
387 ScrollbarLayerImplBase* scrollbar_layer_impl = 387 ScrollbarLayerImplBase* scrollbar_layer_impl =
388 static_cast<SolidColorScrollbarLayerImpl*>( 388 static_cast<SolidColorScrollbarLayerImpl*>(
389 layer_impl_tree_root->children()[1].get()); 389 layer_impl_tree_root->children()[1]);
390 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 390 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
391 scrollbar_layer_impl->SetCurrentPos(10.f); 391 scrollbar_layer_impl->SetCurrentPos(10.f);
392 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); 392 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f);
393 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); 393 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f);
394 394
395 // Thickness should be overridden to 3. 395 // Thickness should be overridden to 3.
396 { 396 {
397 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 397 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
398 AppendQuadsData data; 398 AppendQuadsData data;
399 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); 399 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 460
461 // Choose layer bounds to give max_scroll_offset = (8, 8). 461 // Choose layer bounds to give max_scroll_offset = (8, 8).
462 layer_tree_root->SetBounds(gfx::Size(2, 2)); 462 layer_tree_root->SetBounds(gfx::Size(2, 2));
463 scroll_layer->SetBounds(gfx::Size(10, 10)); 463 scroll_layer->SetBounds(gfx::Size(10, 10));
464 464
465 layer_tree_host_->UpdateLayers(); 465 layer_tree_host_->UpdateLayers();
466 } 466 }
467 467
468 LayerImpl* layer_impl_tree_root = 468 LayerImpl* layer_impl_tree_root =
469 layer_tree_host_->CommitAndCreateLayerImplTree(); 469 layer_tree_host_->CommitAndCreateLayerImplTree();
470 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0].get(); 470 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
471 471
472 auto* scrollbar_layer_impl = static_cast<ScrollbarLayerImplBase*>( 472 auto* scrollbar_layer_impl =
473 scroll_layer_impl->children()[1].get()); 473 static_cast<ScrollbarLayerImplBase*>(scroll_layer_impl->children()[1]);
474 474
475 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 475 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f));
476 476
477 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 477 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
478 scrollbar_layer_impl->SetCurrentPos(4.f); 478 scrollbar_layer_impl->SetCurrentPos(4.f);
479 479
480 { 480 {
481 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); 481 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
482 482
483 AppendQuadsData data; 483 AppendQuadsData data;
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1012 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1013 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1013 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1014 1014
1015 // Horizontal Scrollbars. 1015 // Horizontal Scrollbars.
1016 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1016 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1017 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1017 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1018 } 1018 }
1019 1019
1020 } // namespace 1020 } // namespace
1021 } // namespace cc 1021 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/render_surface_impl_unittest.cc ('k') | cc/test/fake_layer_tree_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698