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

Side by Side Diff: cc/trees/layer_tree_host_unittest_scroll.cc

Issue 18400003: cc: Consider scroll offset in CalcDrawProperties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 5 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 | Annotate | Revision Log
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 "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "cc/layers/content_layer.h" 8 #include "cc/layers/content_layer.h"
9 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } else if (impl->active_tree()->source_frame_number() == 0 && 133 } else if (impl->active_tree()->source_frame_number() == 0 &&
134 impl->SourceAnimationFrameNumber() == 2) { 134 impl->SourceAnimationFrameNumber() == 2) {
135 // Second draw after first commit. 135 // Second draw after first commit.
136 EXPECT_EQ(root->ScrollDelta(), scroll_amount_); 136 EXPECT_EQ(root->ScrollDelta(), scroll_amount_);
137 root->ScrollBy(scroll_amount_); 137 root->ScrollBy(scroll_amount_);
138 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_ + scroll_amount_); 138 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_ + scroll_amount_);
139 139
140 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); 140 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
141 PostSetNeedsCommitToMainThread(); 141 PostSetNeedsCommitToMainThread();
142 } else if (impl->active_tree()->source_frame_number() == 1) { 142 } else if (impl->active_tree()->source_frame_number() == 1) {
143 // Third or later draw after second commit. 143 // Any draw after second commit. The animation frame may not update
144 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); 144 // if no damage occurs here and the draw is skipped.
145 EXPECT_GE(impl->SourceAnimationFrameNumber(), 2);
danakj 2013/07/08 21:53:42 Does this mean we do the above elseif{} block (sou
enne (OOO) 2013/07/08 22:03:46 All three blocks run in order on different "draws"
enne (OOO) 2013/07/09 00:49:45 I fixed this case by resizing the root. Now that
145 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); 146 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
146 EXPECT_VECTOR_EQ(root->scroll_offset(), 147 EXPECT_VECTOR_EQ(root->scroll_offset(),
147 initial_scroll_ + scroll_amount_ + scroll_amount_); 148 initial_scroll_ + scroll_amount_ + scroll_amount_);
148 EndTest(); 149 EndTest();
149 } 150 }
150 } 151 }
151 152
152 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) 153 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
153 OVERRIDE { 154 OVERRIDE {
154 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); 155 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 232
232 virtual void SetupTree() OVERRIDE { 233 virtual void SetupTree() OVERRIDE {
233 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); 234 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_);
234 235
235 scoped_refptr<Layer> root_layer = Layer::Create(); 236 scoped_refptr<Layer> root_layer = Layer::Create();
236 root_layer->SetBounds(gfx::Size(10, 10)); 237 root_layer->SetBounds(gfx::Size(10, 10));
237 238
238 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); 239 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_);
239 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); 240 root_scroll_layer_->SetBounds(gfx::Size(110, 110));
240 241
241 root_scroll_layer_->SetPosition(gfx::Point(0, 0)); 242 root_scroll_layer_->SetPosition(gfx::Point());
242 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); 243 root_scroll_layer_->SetAnchorPoint(gfx::PointF());
243 244
244 root_scroll_layer_->SetIsDrawable(true); 245 root_scroll_layer_->SetIsDrawable(true);
245 root_scroll_layer_->SetScrollable(true); 246 root_scroll_layer_->SetScrollable(true);
246 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 247 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100));
247 root_layer->AddChild(root_scroll_layer_); 248 root_layer->AddChild(root_scroll_layer_);
248 249
249 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); 250 child_layer_ = ContentLayer::Create(&fake_content_layer_client_);
250 child_layer_->set_did_scroll_callback( 251 child_layer_->set_did_scroll_callback(
251 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, 252 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll,
252 base::Unretained(this))); 253 base::Unretained(this)));
253 child_layer_->SetBounds(gfx::Size(110, 110)); 254 child_layer_->SetBounds(gfx::Size(110, 110));
254 255
255 // Scrolls on the child layer will happen at 5, 5. If they are treated 256 if (scroll_child_layer_) {
256 // like device pixels, and device scale factor is 2, then they will 257 child_layer_->SetPosition(gfx::Point());
257 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. 258 } else {
258 child_layer_->SetPosition(gfx::Point(5, 5)); 259 // Offset the child layer further than the sum of all scrolls so that
260 // scrolls beginning at the viewport origin will always hit the root.
261 child_layer_->SetPosition(gfx::Point(60, 60));
262 EXPECT_GT(child_layer_->position().x(),
263 (initial_offset_ + javascript_scroll_).x());
264 EXPECT_GT(child_layer_->position().y(),
265 (initial_offset_ + javascript_scroll_).y());
266 }
259 child_layer_->SetAnchorPoint(gfx::PointF()); 267 child_layer_->SetAnchorPoint(gfx::PointF());
260 268
261 child_layer_->SetIsDrawable(true); 269 child_layer_->SetIsDrawable(true);
262 child_layer_->SetScrollable(true); 270 child_layer_->SetScrollable(true);
263 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 271 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100));
264 root_scroll_layer_->AddChild(child_layer_); 272 root_scroll_layer_->AddChild(child_layer_);
265 273
266 if (scroll_child_layer_) { 274 if (scroll_child_layer_) {
267 expected_scroll_layer_ = child_layer_; 275 expected_scroll_layer_ = child_layer_;
268 expected_no_scroll_layer_ = root_scroll_layer_; 276 expected_no_scroll_layer_ = root_scroll_layer_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_SIZE_EQ(expected_content_bounds, 346 EXPECT_SIZE_EQ(expected_content_bounds,
339 root_scroll_layer_->content_bounds()); 347 root_scroll_layer_->content_bounds());
340 348
341 expected_content_bounds = gfx::ToCeiledSize( 349 expected_content_bounds = gfx::ToCeiledSize(
342 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_)); 350 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_));
343 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->content_bounds()); 351 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->content_bounds());
344 352
345 switch (impl->active_tree()->source_frame_number()) { 353 switch (impl->active_tree()->source_frame_number()) {
346 case 0: { 354 case 0: {
347 // Gesture scroll on impl thread. 355 // Gesture scroll on impl thread.
348 InputHandler::ScrollStatus status = impl->ScrollBegin( 356 InputHandler::ScrollStatus status =
349 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() + 357 impl->ScrollBegin(gfx::Point(), InputHandler::Gesture);
350 gfx::Vector2dF(0.5f, 0.5f)),
351 InputHandler::Gesture);
352 EXPECT_EQ(InputHandler::ScrollStarted, status); 358 EXPECT_EQ(InputHandler::ScrollStarted, status);
353 impl->ScrollBy(gfx::Point(), scroll_amount_); 359 impl->ScrollBy(gfx::Point(), scroll_amount_);
354 impl->ScrollEnd(); 360 impl->ScrollEnd();
355 361
356 // Check the scroll is applied as a delta. 362 // Check the scroll is applied as a delta.
357 EXPECT_VECTOR_EQ(initial_offset_, 363 EXPECT_VECTOR_EQ(initial_offset_,
358 expected_scroll_layer_impl->scroll_offset()); 364 expected_scroll_layer_impl->scroll_offset());
359 EXPECT_VECTOR_EQ(scroll_amount_, 365 EXPECT_VECTOR_EQ(scroll_amount_,
360 expected_scroll_layer_impl->ScrollDelta()); 366 expected_scroll_layer_impl->ScrollDelta());
361 break; 367 break;
362 } 368 }
363 case 1: { 369 case 1: {
364 // Wheel scroll on impl thread. 370 // Wheel scroll on impl thread.
365 InputHandler::ScrollStatus status = impl->ScrollBegin( 371 InputHandler::ScrollStatus status =
366 gfx::ToCeiledPoint(expected_scroll_layer_impl->position() + 372 impl->ScrollBegin(gfx::Point(), InputHandler::Wheel);
367 gfx::Vector2dF(0.5f, 0.5f)),
368 InputHandler::Wheel);
369 EXPECT_EQ(InputHandler::ScrollStarted, status); 373 EXPECT_EQ(InputHandler::ScrollStarted, status);
370 impl->ScrollBy(gfx::Point(), scroll_amount_); 374 impl->ScrollBy(gfx::Point(), scroll_amount_);
371 impl->ScrollEnd(); 375 impl->ScrollEnd();
372 376
373 // Check the scroll is applied as a delta. 377 // Check the scroll is applied as a delta.
374 EXPECT_VECTOR_EQ(javascript_scroll_, 378 EXPECT_VECTOR_EQ(javascript_scroll_,
375 expected_scroll_layer_impl->scroll_offset()); 379 expected_scroll_layer_impl->scroll_offset());
376 EXPECT_VECTOR_EQ(scroll_amount_, 380 EXPECT_VECTOR_EQ(scroll_amount_,
377 expected_scroll_layer_impl->ScrollDelta()); 381 expected_scroll_layer_impl->ScrollDelta());
378 break; 382 break;
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 RunTest(true, false, false); 847 RunTest(true, false, false);
844 } 848 }
845 849
846 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 850 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
847 scroll_destroy_whole_tree_ = true; 851 scroll_destroy_whole_tree_ = true;
848 RunTest(true, false, false); 852 RunTest(true, false, false);
849 } 853 }
850 854
851 } // namespace 855 } // namespace
852 } // namespace cc 856 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698