| 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 "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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { | 25 class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { |
| 26 public: | 26 public: |
| 27 LayerTreeHostScrollTestScrollSimple() | 27 LayerTreeHostScrollTestScrollSimple() |
| 28 : initial_scroll_(10, 20), | 28 : initial_scroll_(10, 20), |
| 29 second_scroll_(40, 5), | 29 second_scroll_(40, 5), |
| 30 scroll_amount_(2, -1), | 30 scroll_amount_(2, -1), |
| 31 num_scrolls_(0) {} | 31 num_scrolls_(0) {} |
| 32 | 32 |
| 33 virtual void BeginTest() OVERRIDE { | 33 virtual void BeginTest() OVERRIDE { |
| 34 layer_tree_host()->root_layer()->SetScrollable(true); | 34 Layer* root_layer = layer_tree_host()->root_layer(); |
| 35 layer_tree_host()->root_layer() | 35 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 36 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 36 root_layer->AddChild(scroll_layer); |
| 37 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | 37 // Create an effective max_scroll_offset of (100, 100). |
| 38 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100, |
| 39 root_layer->bounds().height() + 100)); |
| 40 scroll_layer->SetIsDrawable(true); |
| 41 scroll_layer->SetScrollClipLayer(root_layer); |
| 42 scroll_layer->SetScrollOffset(initial_scroll_); |
| 43 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); |
| 38 PostSetNeedsCommitToMainThread(); | 44 PostSetNeedsCommitToMainThread(); |
| 39 } | 45 } |
| 40 | 46 |
| 41 virtual void Layout() OVERRIDE { | 47 virtual void Layout() OVERRIDE { |
| 42 Layer* root = layer_tree_host()->root_layer(); | 48 Layer* root = layer_tree_host()->root_layer(); |
| 49 Layer* scroll_layer = root->children()[0]; |
| 43 if (!layer_tree_host()->source_frame_number()) { | 50 if (!layer_tree_host()->source_frame_number()) { |
| 44 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset()); | 51 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); |
| 45 } else { | 52 } else { |
| 46 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, root->scroll_offset()); | 53 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, |
| 54 scroll_layer->scroll_offset()); |
| 47 | 55 |
| 48 // Pretend like Javascript updated the scroll position itself. | 56 // Pretend like Javascript updated the scroll position itself. |
| 49 root->SetScrollOffset(second_scroll_); | 57 scroll_layer->SetScrollOffset(second_scroll_); |
| 50 } | 58 } |
| 51 } | 59 } |
| 52 | 60 |
| 53 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 61 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 54 LayerImpl* root = impl->active_tree()->root_layer(); | 62 LayerImpl* root = impl->active_tree()->root_layer(); |
| 55 EXPECT_VECTOR_EQ(gfx::Vector2d(), root->ScrollDelta()); | 63 LayerImpl* scroll_layer = root->children()[0]; |
| 64 EXPECT_VECTOR_EQ(gfx::Vector2d(), scroll_layer->ScrollDelta()); |
| 56 | 65 |
| 57 root->SetScrollable(true); | 66 scroll_layer->SetScrollClipLayer(root->id()); |
| 58 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 67 scroll_layer->SetBounds( |
| 59 root->ScrollBy(scroll_amount_); | 68 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); |
| 69 scroll_layer->ScrollBy(scroll_amount_); |
| 60 | 70 |
| 61 switch (impl->active_tree()->source_frame_number()) { | 71 switch (impl->active_tree()->source_frame_number()) { |
| 62 case 0: | 72 case 0: |
| 63 EXPECT_VECTOR_EQ(initial_scroll_, root->scroll_offset()); | 73 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); |
| 64 EXPECT_VECTOR_EQ(scroll_amount_, root->ScrollDelta()); | 74 EXPECT_VECTOR_EQ(scroll_amount_, scroll_layer->ScrollDelta()); |
| 65 PostSetNeedsCommitToMainThread(); | 75 PostSetNeedsCommitToMainThread(); |
| 66 break; | 76 break; |
| 67 case 1: | 77 case 1: |
| 68 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_); | 78 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), second_scroll_); |
| 69 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); | 79 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_); |
| 70 EndTest(); | 80 EndTest(); |
| 71 break; | 81 break; |
| 72 } | 82 } |
| 73 } | 83 } |
| 74 | 84 |
| 75 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, | 85 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, |
| 76 float scale) OVERRIDE { | 86 float scale) OVERRIDE { |
| 77 num_scrolls_++; | 87 num_scrolls_++; |
| 78 } | 88 } |
| 79 | 89 |
| 80 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 90 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 81 | 91 |
| 82 private: | 92 private: |
| 83 gfx::Vector2d initial_scroll_; | 93 gfx::Vector2d initial_scroll_; |
| 84 gfx::Vector2d second_scroll_; | 94 gfx::Vector2d second_scroll_; |
| 85 gfx::Vector2d scroll_amount_; | 95 gfx::Vector2d scroll_amount_; |
| 86 int num_scrolls_; | 96 int num_scrolls_; |
| 87 }; | 97 }; |
| 88 | 98 |
| 89 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); | 99 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); |
| 90 | 100 |
| 91 class LayerTreeHostScrollTestScrollMultipleRedraw | 101 class LayerTreeHostScrollTestScrollMultipleRedraw |
| 92 : public LayerTreeHostScrollTest { | 102 : public LayerTreeHostScrollTest { |
| 93 public: | 103 public: |
| 94 LayerTreeHostScrollTestScrollMultipleRedraw() | 104 LayerTreeHostScrollTestScrollMultipleRedraw() |
| 95 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} | 105 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} |
| 96 | 106 |
| 97 virtual void BeginTest() OVERRIDE { | 107 virtual void BeginTest() OVERRIDE { |
| 98 layer_tree_host()->root_layer()->SetScrollable(true); | 108 Layer* root_layer = layer_tree_host()->root_layer(); |
| 99 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | 109 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 100 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); | 110 root_layer->AddChild(scroll_layer); |
| 101 layer_tree_host()->root_layer() | 111 // Create an effective max_scroll_offset of (100, 100). |
| 102 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 112 scroll_layer->SetBounds(gfx::Size(root_layer->bounds().width() + 100, |
| 113 root_layer->bounds().height() + 100)); |
| 114 scroll_layer->SetIsDrawable(true); |
| 115 scroll_layer->SetScrollClipLayer(root_layer); |
| 116 scroll_layer->SetScrollOffset(initial_scroll_); |
| 117 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); |
| 103 PostSetNeedsCommitToMainThread(); | 118 PostSetNeedsCommitToMainThread(); |
| 104 } | 119 } |
| 105 | 120 |
| 106 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 121 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 107 Layer* root = layer_tree_host()->root_layer(); | 122 Layer* root = layer_tree_host()->root_layer(); |
| 123 Layer* scroll_layer = root->children()[0]; |
| 108 switch (layer_tree_host()->source_frame_number()) { | 124 switch (layer_tree_host()->source_frame_number()) { |
| 109 case 0: | 125 case 0: |
| 110 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 126 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 111 break; | 127 break; |
| 112 case 1: | 128 case 1: |
| 113 EXPECT_VECTOR_EQ(root->scroll_offset(), | 129 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), |
| 114 initial_scroll_ + scroll_amount_ + scroll_amount_); | 130 initial_scroll_ + scroll_amount_ + scroll_amount_); |
| 115 case 2: | 131 case 2: |
| 116 EXPECT_VECTOR_EQ(root->scroll_offset(), | 132 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), |
| 117 initial_scroll_ + scroll_amount_ + scroll_amount_); | 133 initial_scroll_ + scroll_amount_ + scroll_amount_); |
| 118 break; | 134 break; |
| 119 } | 135 } |
| 120 } | 136 } |
| 121 | 137 |
| 122 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 138 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 123 LayerImpl* root = impl->active_tree()->root_layer(); | 139 LayerImpl* root = impl->active_tree()->root_layer(); |
| 140 LayerImpl* scroll_layer = root->children()[0]; |
| 124 if (impl->active_tree()->source_frame_number() == 0 && | 141 if (impl->active_tree()->source_frame_number() == 0 && |
| 125 impl->SourceAnimationFrameNumber() == 1) { | 142 impl->SourceAnimationFrameNumber() == 1) { |
| 126 // First draw after first commit. | 143 // First draw after first commit. |
| 127 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | 144 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 128 root->ScrollBy(scroll_amount_); | 145 scroll_layer->ScrollBy(scroll_amount_); |
| 129 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); | 146 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), scroll_amount_); |
| 130 | 147 |
| 131 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 148 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 132 PostSetNeedsRedrawToMainThread(); | 149 PostSetNeedsRedrawToMainThread(); |
| 133 } else if (impl->active_tree()->source_frame_number() == 0 && | 150 } else if (impl->active_tree()->source_frame_number() == 0 && |
| 134 impl->SourceAnimationFrameNumber() == 2) { | 151 impl->SourceAnimationFrameNumber() == 2) { |
| 135 // Second draw after first commit. | 152 // Second draw after first commit. |
| 136 EXPECT_EQ(root->ScrollDelta(), scroll_amount_); | 153 EXPECT_EQ(scroll_layer->ScrollDelta(), scroll_amount_); |
| 137 root->ScrollBy(scroll_amount_); | 154 scroll_layer->ScrollBy(scroll_amount_); |
| 138 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_ + scroll_amount_); | 155 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), |
| 156 scroll_amount_ + scroll_amount_); |
| 139 | 157 |
| 140 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 158 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 141 PostSetNeedsCommitToMainThread(); | 159 PostSetNeedsCommitToMainThread(); |
| 142 } else if (impl->active_tree()->source_frame_number() == 1) { | 160 } else if (impl->active_tree()->source_frame_number() == 1) { |
| 143 // Third or later draw after second commit. | 161 // Third or later draw after second commit. |
| 144 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); | 162 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); |
| 145 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | 163 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 146 EXPECT_VECTOR_EQ(root->scroll_offset(), | 164 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), |
| 147 initial_scroll_ + scroll_amount_ + scroll_amount_); | 165 initial_scroll_ + scroll_amount_ + scroll_amount_); |
| 148 EndTest(); | 166 EndTest(); |
| 149 } | 167 } |
| 150 } | 168 } |
| 151 | 169 |
| 152 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, | 170 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, |
| 153 float scale) OVERRIDE { | 171 float scale) OVERRIDE { |
| 154 num_scrolls_++; | 172 num_scrolls_++; |
| 155 } | 173 } |
| 156 | 174 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 176 num_did_begin_main_frames_(0), | 194 num_did_begin_main_frames_(0), |
| 177 num_will_commits_(0), | 195 num_will_commits_(0), |
| 178 num_did_commits_(0), | 196 num_did_commits_(0), |
| 179 num_impl_commits_(0), | 197 num_impl_commits_(0), |
| 180 num_impl_scrolls_(0) {} | 198 num_impl_scrolls_(0) {} |
| 181 | 199 |
| 182 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 200 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 183 | 201 |
| 184 virtual void SetupTree() OVERRIDE { | 202 virtual void SetupTree() OVERRIDE { |
| 185 LayerTreeHostScrollTest::SetupTree(); | 203 LayerTreeHostScrollTest::SetupTree(); |
| 204 Layer* root_layer = layer_tree_host()->root_layer(); |
| 186 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); | 205 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 187 root_scroll_layer->SetScrollable(true); | 206 root_scroll_layer->SetScrollClipLayer(root_layer); |
| 188 root_scroll_layer->SetScrollOffset(initial_scroll_); | 207 root_scroll_layer->SetScrollOffset(initial_scroll_); |
| 189 root_scroll_layer->SetBounds(gfx::Size(200, 200)); | 208 root_scroll_layer->SetBounds(gfx::Size(200, 200)); |
| 190 root_scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | |
| 191 root_scroll_layer->SetIsDrawable(true); | 209 root_scroll_layer->SetIsDrawable(true); |
| 192 layer_tree_host()->root_layer()->AddChild(root_scroll_layer); | 210 root_layer->AddChild(root_scroll_layer); |
| 193 | 211 |
| 212 layer_tree_host()->RegisterViewportLayers( |
| 213 root_layer, root_scroll_layer, NULL); |
| 194 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); | 214 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 195 } | 215 } |
| 196 | 216 |
| 197 virtual void WillBeginMainFrame() OVERRIDE { | 217 virtual void WillBeginMainFrame() OVERRIDE { |
| 198 num_will_begin_main_frames_++; | 218 num_will_begin_main_frames_++; |
| 199 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0]; | 219 Layer* root_scroll_layer = layer_tree_host()->root_layer()->children()[0]; |
| 200 switch (num_will_begin_main_frames_) { | 220 switch (num_will_begin_main_frames_) { |
| 201 case 1: | 221 case 1: |
| 202 // This will not be aborted because of the initial prop changes. | 222 // This will not be aborted because of the initial prop changes. |
| 203 EXPECT_EQ(0, num_impl_scrolls_); | 223 EXPECT_EQ(0, num_impl_scrolls_); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 int num_impl_commits_; | 357 int num_impl_commits_; |
| 338 int num_impl_scrolls_; | 358 int num_impl_scrolls_; |
| 339 }; | 359 }; |
| 340 | 360 |
| 341 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); | 361 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); |
| 342 | 362 |
| 343 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { | 363 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { |
| 344 public: | 364 public: |
| 345 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} | 365 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} |
| 346 | 366 |
| 367 virtual void SetupTree() OVERRIDE { |
| 368 LayerTreeHostScrollTest::SetupTree(); |
| 369 Layer* root_layer = layer_tree_host()->root_layer(); |
| 370 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 371 root_scroll_layer->SetScrollClipLayer(root_layer); |
| 372 root_scroll_layer->SetBounds( |
| 373 gfx::Size(root_layer->bounds().width() + 100, |
| 374 root_layer->bounds().height() + 100)); |
| 375 root_scroll_layer->SetIsDrawable(true); |
| 376 root_layer->AddChild(root_scroll_layer); |
| 377 |
| 378 layer_tree_host()->RegisterViewportLayers( |
| 379 root_layer, root_scroll_layer, NULL); |
| 380 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 381 } |
| 382 |
| 347 virtual void BeginTest() OVERRIDE { | 383 virtual void BeginTest() OVERRIDE { |
| 348 layer_tree_host()->root_layer()->SetScrollable(true); | |
| 349 layer_tree_host()->root_layer() | |
| 350 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | |
| 351 PostSetNeedsCommitToMainThread(); | 384 PostSetNeedsCommitToMainThread(); |
| 352 } | 385 } |
| 353 | 386 |
| 354 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 387 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 355 LayerImpl* root = impl->active_tree()->root_layer(); | 388 LayerImpl* root = impl->active_tree()->root_layer(); |
| 389 LayerImpl* scroll_layer = root->children()[0]; |
| 356 | 390 |
| 357 // Check that a fractional scroll delta is correctly accumulated over | 391 // Check that a fractional scroll delta is correctly accumulated over |
| 358 // multiple commits. | 392 // multiple commits. |
| 359 switch (impl->active_tree()->source_frame_number()) { | 393 switch (impl->active_tree()->source_frame_number()) { |
| 360 case 0: | 394 case 0: |
| 361 EXPECT_VECTOR_EQ(root->scroll_offset(), gfx::Vector2d(0, 0)); | 395 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), gfx::Vector2d(0, 0)); |
| 362 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d(0, 0)); | 396 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d(0, 0)); |
| 363 PostSetNeedsCommitToMainThread(); | 397 PostSetNeedsCommitToMainThread(); |
| 364 break; | 398 break; |
| 365 case 1: | 399 case 1: |
| 366 EXPECT_VECTOR_EQ(root->scroll_offset(), | 400 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), |
| 367 gfx::ToFlooredVector2d(scroll_amount_)); | 401 gfx::ToFlooredVector2d(scroll_amount_)); |
| 368 EXPECT_VECTOR_EQ(root->ScrollDelta(), | 402 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), |
| 369 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f)); | 403 gfx::Vector2dF(fmod(scroll_amount_.x(), 1.0f), 0.0f)); |
| 370 PostSetNeedsCommitToMainThread(); | 404 PostSetNeedsCommitToMainThread(); |
| 371 break; | 405 break; |
| 372 case 2: | 406 case 2: |
| 373 EXPECT_VECTOR_EQ( | 407 EXPECT_VECTOR_EQ( |
| 374 root->scroll_offset(), | 408 scroll_layer->scroll_offset(), |
| 375 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); | 409 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); |
| 376 EXPECT_VECTOR_EQ( | 410 EXPECT_VECTOR_EQ( |
| 377 root->ScrollDelta(), | 411 scroll_layer->ScrollDelta(), |
| 378 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); | 412 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); |
| 379 EndTest(); | 413 EndTest(); |
| 380 break; | 414 break; |
| 381 } | 415 } |
| 382 root->ScrollBy(scroll_amount_); | 416 scroll_layer->ScrollBy(scroll_amount_); |
| 383 } | 417 } |
| 384 | 418 |
| 385 virtual void AfterTest() OVERRIDE {} | 419 virtual void AfterTest() OVERRIDE {} |
| 386 | 420 |
| 387 private: | 421 private: |
| 388 gfx::Vector2dF scroll_amount_; | 422 gfx::Vector2dF scroll_amount_; |
| 389 }; | 423 }; |
| 390 | 424 |
| 391 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); | 425 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); |
| 392 | 426 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 404 scoped_refptr<Layer> root_layer = Layer::Create(); | 438 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 405 root_layer->SetBounds(gfx::Size(10, 10)); | 439 root_layer->SetBounds(gfx::Size(10, 10)); |
| 406 | 440 |
| 407 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); | 441 root_scroll_layer_ = ContentLayer::Create(&fake_content_layer_client_); |
| 408 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); | 442 root_scroll_layer_->SetBounds(gfx::Size(110, 110)); |
| 409 | 443 |
| 410 root_scroll_layer_->SetPosition(gfx::Point()); | 444 root_scroll_layer_->SetPosition(gfx::Point()); |
| 411 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); | 445 root_scroll_layer_->SetAnchorPoint(gfx::PointF()); |
| 412 | 446 |
| 413 root_scroll_layer_->SetIsDrawable(true); | 447 root_scroll_layer_->SetIsDrawable(true); |
| 414 root_scroll_layer_->SetScrollable(true); | 448 root_scroll_layer_->SetScrollClipLayer(root_layer); |
| 415 root_scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | |
| 416 root_layer->AddChild(root_scroll_layer_); | 449 root_layer->AddChild(root_scroll_layer_); |
| 417 | 450 |
| 418 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); | 451 child_layer_ = ContentLayer::Create(&fake_content_layer_client_); |
| 419 child_layer_->set_did_scroll_callback( | 452 child_layer_->set_did_scroll_callback( |
| 420 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, | 453 base::Bind(&LayerTreeHostScrollTestCaseWithChild::DidScroll, |
| 421 base::Unretained(this))); | 454 base::Unretained(this))); |
| 422 child_layer_->SetBounds(gfx::Size(110, 110)); | 455 child_layer_->SetBounds(gfx::Size(110, 110)); |
| 423 | 456 |
| 424 if (scroll_child_layer_) { | 457 if (scroll_child_layer_) { |
| 425 // Scrolls on the child layer will happen at 5, 5. If they are treated | 458 // Scrolls on the child layer will happen at 5, 5. If they are treated |
| 426 // like device pixels, and device scale factor is 2, then they will | 459 // like device pixels, and device scale factor is 2, then they will |
| 427 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. | 460 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. |
| 428 child_layer_->SetPosition(gfx::Point(5, 5)); | 461 child_layer_->SetPosition(gfx::Point(5, 5)); |
| 429 } else { | 462 } else { |
| 430 // Adjust the child layer horizontally so that scrolls will never hit it. | 463 // Adjust the child layer horizontally so that scrolls will never hit it. |
| 431 child_layer_->SetPosition(gfx::Point(60, 5)); | 464 child_layer_->SetPosition(gfx::Point(60, 5)); |
| 432 } | 465 } |
| 433 child_layer_->SetAnchorPoint(gfx::PointF()); | 466 child_layer_->SetAnchorPoint(gfx::PointF()); |
| 434 | 467 |
| 435 child_layer_->SetIsDrawable(true); | 468 child_layer_->SetIsDrawable(true); |
| 436 child_layer_->SetScrollable(true); | 469 child_layer_->SetScrollClipLayer(root_layer); |
| 437 child_layer_->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 470 child_layer_->SetBounds(root_scroll_layer_->bounds()); |
| 438 root_scroll_layer_->AddChild(child_layer_); | 471 root_scroll_layer_->AddChild(child_layer_); |
| 439 | 472 |
| 440 if (scroll_child_layer_) { | 473 if (scroll_child_layer_) { |
| 441 expected_scroll_layer_ = child_layer_; | 474 expected_scroll_layer_ = child_layer_; |
| 442 expected_no_scroll_layer_ = root_scroll_layer_; | 475 expected_no_scroll_layer_ = root_scroll_layer_; |
| 443 } else { | 476 } else { |
| 444 expected_scroll_layer_ = root_scroll_layer_; | 477 expected_scroll_layer_ = root_scroll_layer_; |
| 445 expected_no_scroll_layer_ = child_layer_; | 478 expected_no_scroll_layer_ = child_layer_; |
| 446 } | 479 } |
| 447 | 480 |
| 448 expected_scroll_layer_->SetScrollOffset(initial_offset_); | 481 expected_scroll_layer_->SetScrollOffset(initial_offset_); |
| 449 | 482 |
| 450 layer_tree_host()->SetRootLayer(root_layer); | 483 layer_tree_host()->SetRootLayer(root_layer); |
| 484 layer_tree_host()->RegisterViewportLayers( |
| 485 root_layer, root_scroll_layer_, NULL); |
| 451 LayerTreeHostScrollTest::SetupTree(); | 486 LayerTreeHostScrollTest::SetupTree(); |
| 452 } | 487 } |
| 453 | 488 |
| 454 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 489 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 455 | 490 |
| 456 virtual void WillCommit() OVERRIDE { | 491 virtual void WillCommit() OVERRIDE { |
| 457 // Keep the test committing (otherwise the early out for no update | 492 // Keep the test committing (otherwise the early out for no update |
| 458 // will stall the test). | 493 // will stall the test). |
| 459 if (layer_tree_host()->source_frame_number() < 2) { | 494 if (layer_tree_host()->source_frame_number() < 2) { |
| 460 layer_tree_host()->SetNeedsCommit(); | 495 layer_tree_host()->SetNeedsCommit(); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 | 752 |
| 718 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { | 753 class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest { |
| 719 public: | 754 public: |
| 720 ImplSidePaintingScrollTestSimple() | 755 ImplSidePaintingScrollTestSimple() |
| 721 : initial_scroll_(10, 20), | 756 : initial_scroll_(10, 20), |
| 722 main_thread_scroll_(40, 5), | 757 main_thread_scroll_(40, 5), |
| 723 impl_thread_scroll1_(2, -1), | 758 impl_thread_scroll1_(2, -1), |
| 724 impl_thread_scroll2_(-3, 10), | 759 impl_thread_scroll2_(-3, 10), |
| 725 num_scrolls_(0) {} | 760 num_scrolls_(0) {} |
| 726 | 761 |
| 762 virtual void SetupTree() OVERRIDE { |
| 763 LayerTreeHostScrollTest::SetupTree(); |
| 764 Layer* root_layer = layer_tree_host()->root_layer(); |
| 765 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 766 root_scroll_layer->SetScrollClipLayer(root_layer); |
| 767 root_scroll_layer->SetScrollOffset(initial_scroll_); |
| 768 root_scroll_layer->SetBounds( |
| 769 gfx::Size(root_layer->bounds().width() + 100, |
| 770 root_layer->bounds().height() + 100)); |
| 771 root_scroll_layer->SetIsDrawable(true); |
| 772 root_layer->AddChild(root_scroll_layer); |
| 773 |
| 774 layer_tree_host()->RegisterViewportLayers( |
| 775 root_layer, root_scroll_layer, NULL); |
| 776 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 777 } |
| 778 |
| 727 virtual void BeginTest() OVERRIDE { | 779 virtual void BeginTest() OVERRIDE { |
| 728 layer_tree_host()->root_layer()->SetScrollable(true); | |
| 729 layer_tree_host()->root_layer() | |
| 730 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | |
| 731 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | |
| 732 PostSetNeedsCommitToMainThread(); | 780 PostSetNeedsCommitToMainThread(); |
| 733 } | 781 } |
| 734 | 782 |
| 735 virtual void Layout() OVERRIDE { | 783 virtual void Layout() OVERRIDE { |
| 736 Layer* root = layer_tree_host()->root_layer(); | 784 Layer* root = layer_tree_host()->root_layer(); |
| 785 Layer* scroll_layer = root->children()[0]; |
| 737 if (!layer_tree_host()->source_frame_number()) { | 786 if (!layer_tree_host()->source_frame_number()) { |
| 738 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 787 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 739 } else { | 788 } else { |
| 740 EXPECT_VECTOR_EQ(root->scroll_offset(), | 789 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), |
| 741 initial_scroll_ + impl_thread_scroll1_); | 790 initial_scroll_ + impl_thread_scroll1_); |
| 742 | 791 |
| 743 // Pretend like Javascript updated the scroll position itself with a | 792 // Pretend like Javascript updated the scroll position itself with a |
| 744 // change of main_thread_scroll. | 793 // change of main_thread_scroll. |
| 745 root->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + | 794 scroll_layer->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + |
| 746 impl_thread_scroll1_); | 795 impl_thread_scroll1_); |
| 747 } | 796 } |
| 748 } | 797 } |
| 749 | 798 |
| 750 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 799 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 751 // We force a second draw here of the first commit before activating | 800 // We force a second draw here of the first commit before activating |
| 752 // the second commit. | 801 // the second commit. |
| 753 if (impl->active_tree()->source_frame_number() == 0) | 802 if (impl->active_tree()->source_frame_number() == 0) |
| 754 impl->SetNeedsRedraw(); | 803 impl->SetNeedsRedraw(); |
| 755 } | 804 } |
| 756 | 805 |
| 757 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 806 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 758 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); | 807 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); |
| 759 | 808 |
| 760 LayerImpl* root = impl->active_tree()->root_layer(); | 809 LayerImpl* root = impl->active_tree()->root_layer(); |
| 810 LayerImpl* scroll_layer = root->children()[0]; |
| 761 LayerImpl* pending_root = | 811 LayerImpl* pending_root = |
| 762 impl->active_tree()->FindPendingTreeLayerById(root->id()); | 812 impl->active_tree()->FindPendingTreeLayerById(root->id()); |
| 763 | 813 |
| 764 switch (impl->active_tree()->source_frame_number()) { | 814 switch (impl->active_tree()->source_frame_number()) { |
| 765 case 0: | 815 case 0: |
| 766 if (!impl->pending_tree()) { | 816 if (!impl->pending_tree()) { |
| 767 impl->BlockNotifyReadyToActivateForTesting(true); | 817 impl->BlockNotifyReadyToActivateForTesting(true); |
| 768 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | 818 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 769 root->ScrollBy(impl_thread_scroll1_); | 819 scroll_layer->ScrollBy(impl_thread_scroll1_); |
| 770 | 820 |
| 771 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 821 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 772 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll1_); | 822 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll1_); |
| 773 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 823 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); |
| 774 PostSetNeedsCommitToMainThread(); | 824 PostSetNeedsCommitToMainThread(); |
| 775 | 825 |
| 776 // CommitCompleteOnThread will trigger this function again | 826 // CommitCompleteOnThread will trigger this function again |
| 777 // and cause us to take the else clause. | 827 // and cause us to take the else clause. |
| 778 } else { | 828 } else { |
| 779 impl->BlockNotifyReadyToActivateForTesting(false); | 829 impl->BlockNotifyReadyToActivateForTesting(false); |
| 780 ASSERT_TRUE(pending_root); | 830 ASSERT_TRUE(pending_root); |
| 781 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); | 831 EXPECT_EQ(impl->pending_tree()->source_frame_number(), 1); |
| 782 | 832 |
| 783 root->ScrollBy(impl_thread_scroll2_); | 833 scroll_layer->ScrollBy(impl_thread_scroll2_); |
| 784 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 834 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 785 EXPECT_VECTOR_EQ(root->ScrollDelta(), | 835 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), |
| 786 impl_thread_scroll1_ + impl_thread_scroll2_); | 836 impl_thread_scroll1_ + impl_thread_scroll2_); |
| 787 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), impl_thread_scroll1_); | 837 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), |
| 838 impl_thread_scroll1_); |
| 788 | 839 |
| 840 LayerImpl* pending_scroll_layer = pending_root->children()[0]; |
| 789 EXPECT_VECTOR_EQ( | 841 EXPECT_VECTOR_EQ( |
| 790 pending_root->scroll_offset(), | 842 pending_scroll_layer->scroll_offset(), |
| 791 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); | 843 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); |
| 792 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll2_); | 844 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), |
| 793 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); | 845 impl_thread_scroll2_); |
| 846 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), |
| 847 gfx::Vector2d()); |
| 794 } | 848 } |
| 795 break; | 849 break; |
| 796 case 1: | 850 case 1: |
| 797 EXPECT_FALSE(impl->pending_tree()); | 851 EXPECT_FALSE(impl->pending_tree()); |
| 798 EXPECT_VECTOR_EQ( | 852 EXPECT_VECTOR_EQ( |
| 799 root->scroll_offset(), | 853 scroll_layer->scroll_offset(), |
| 800 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); | 854 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); |
| 801 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); | 855 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_); |
| 802 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 856 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); |
| 803 EndTest(); | 857 EndTest(); |
| 804 break; | 858 break; |
| 805 } | 859 } |
| 806 } | 860 } |
| 807 | 861 |
| 808 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, | 862 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, |
| 809 float scale) OVERRIDE { | 863 float scale) OVERRIDE { |
| 810 num_scrolls_++; | 864 num_scrolls_++; |
| 811 } | 865 } |
| 812 | 866 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 825 // This test makes sure that layers pick up scrolls that occur between | 879 // This test makes sure that layers pick up scrolls that occur between |
| 826 // beginning a commit and finishing a commit (aka scroll deltas not | 880 // beginning a commit and finishing a commit (aka scroll deltas not |
| 827 // included in sent scroll delta) still apply to layers that don't | 881 // included in sent scroll delta) still apply to layers that don't |
| 828 // push properties. | 882 // push properties. |
| 829 class ImplSidePaintingScrollTestImplOnlyScroll | 883 class ImplSidePaintingScrollTestImplOnlyScroll |
| 830 : public ImplSidePaintingScrollTest { | 884 : public ImplSidePaintingScrollTest { |
| 831 public: | 885 public: |
| 832 ImplSidePaintingScrollTestImplOnlyScroll() | 886 ImplSidePaintingScrollTestImplOnlyScroll() |
| 833 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {} | 887 : initial_scroll_(20, 10), impl_thread_scroll_(-2, 3) {} |
| 834 | 888 |
| 889 virtual void SetupTree() OVERRIDE { |
| 890 LayerTreeHostScrollTest::SetupTree(); |
| 891 Layer* root_layer = layer_tree_host()->root_layer(); |
| 892 scoped_refptr<Layer> root_scroll_layer = Layer::Create(); |
| 893 root_scroll_layer->SetScrollClipLayer(root_layer); |
| 894 root_scroll_layer->SetScrollOffset(initial_scroll_); |
| 895 root_scroll_layer->SetBounds( |
| 896 gfx::Size(root_layer->bounds().width() + 100, |
| 897 root_layer->bounds().height() + 100)); |
| 898 root_scroll_layer->SetIsDrawable(true); |
| 899 root_layer->AddChild(root_scroll_layer); |
| 900 |
| 901 layer_tree_host()->RegisterViewportLayers( |
| 902 root_layer, root_scroll_layer, NULL); |
| 903 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 904 } |
| 905 |
| 835 virtual void BeginTest() OVERRIDE { | 906 virtual void BeginTest() OVERRIDE { |
| 836 layer_tree_host()->root_layer()->SetScrollable(true); | |
| 837 layer_tree_host()->root_layer()->SetMaxScrollOffset( | |
| 838 gfx::Vector2d(100, 100)); | |
| 839 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); | |
| 840 PostSetNeedsCommitToMainThread(); | 907 PostSetNeedsCommitToMainThread(); |
| 841 } | 908 } |
| 842 | 909 |
| 843 virtual void WillCommit() OVERRIDE { | 910 virtual void WillCommit() OVERRIDE { |
| 844 Layer* root = layer_tree_host()->root_layer(); | 911 Layer* root = layer_tree_host()->root_layer(); |
| 912 Layer* scroll_layer = root->children()[0]; |
| 845 switch (layer_tree_host()->source_frame_number()) { | 913 switch (layer_tree_host()->source_frame_number()) { |
| 846 case 0: | 914 case 0: |
| 847 EXPECT_TRUE(root->needs_push_properties()); | 915 EXPECT_TRUE(scroll_layer->needs_push_properties()); |
| 848 break; | 916 break; |
| 849 case 1: | 917 case 1: |
| 850 // Even if this layer doesn't need push properties, it should | 918 // Even if this layer doesn't need push properties, it should |
| 851 // still pick up scrolls that happen on the active layer during | 919 // still pick up scrolls that happen on the active layer during |
| 852 // commit. | 920 // commit. |
| 853 EXPECT_FALSE(root->needs_push_properties()); | 921 EXPECT_FALSE(scroll_layer->needs_push_properties()); |
| 854 break; | 922 break; |
| 855 } | 923 } |
| 856 } | 924 } |
| 857 | 925 |
| 858 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 926 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 859 // Scroll after the 2nd commit has started. | 927 // Scroll after the 2nd commit has started. |
| 860 if (impl->active_tree()->source_frame_number() == 0) { | 928 if (impl->active_tree()->source_frame_number() == 0) { |
| 861 LayerImpl* active_root = impl->active_tree()->root_layer(); | 929 LayerImpl* active_root = impl->active_tree()->root_layer(); |
| 930 LayerImpl* active_scroll_layer = active_root->children()[0]; |
| 862 ASSERT_TRUE(active_root); | 931 ASSERT_TRUE(active_root); |
| 863 active_root->ScrollBy(impl_thread_scroll_); | 932 ASSERT_TRUE(active_scroll_layer); |
| 933 active_scroll_layer->ScrollBy(impl_thread_scroll_); |
| 864 } | 934 } |
| 865 } | 935 } |
| 866 | 936 |
| 867 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 937 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 868 // We force a second draw here of the first commit before activating | 938 // We force a second draw here of the first commit before activating |
| 869 // the second commit. | 939 // the second commit. |
| 870 LayerImpl* active_root = impl->active_tree()->root_layer(); | 940 LayerImpl* active_root = impl->active_tree()->root_layer(); |
| 941 LayerImpl* active_scroll_layer = |
| 942 active_root ? active_root->children()[0] : NULL; |
| 871 LayerImpl* pending_root = impl->pending_tree()->root_layer(); | 943 LayerImpl* pending_root = impl->pending_tree()->root_layer(); |
| 944 LayerImpl* pending_scroll_layer = pending_root->children()[0]; |
| 872 | 945 |
| 873 ASSERT_TRUE(pending_root); | 946 ASSERT_TRUE(pending_root); |
| 947 ASSERT_TRUE(pending_scroll_layer); |
| 874 switch (impl->pending_tree()->source_frame_number()) { | 948 switch (impl->pending_tree()->source_frame_number()) { |
| 875 case 0: | 949 case 0: |
| 876 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_); | 950 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), |
| 877 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d()); | 951 initial_scroll_); |
| 878 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); | 952 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 953 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), |
| 954 gfx::Vector2d()); |
| 879 EXPECT_FALSE(active_root); | 955 EXPECT_FALSE(active_root); |
| 880 break; | 956 break; |
| 881 case 1: | 957 case 1: |
| 882 // Even though the scroll happened during the commit, both layers | 958 // Even though the scroll happened during the commit, both layers |
| 883 // should have the appropriate scroll delta. | 959 // should have the appropriate scroll delta. |
| 884 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), initial_scroll_); | 960 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), |
| 885 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), impl_thread_scroll_); | 961 initial_scroll_); |
| 886 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); | 962 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), |
| 963 impl_thread_scroll_); |
| 964 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), |
| 965 gfx::Vector2d()); |
| 887 ASSERT_TRUE(active_root); | 966 ASSERT_TRUE(active_root); |
| 888 EXPECT_VECTOR_EQ(active_root->scroll_offset(), initial_scroll_); | 967 EXPECT_VECTOR_EQ(active_scroll_layer->scroll_offset(), initial_scroll_); |
| 889 EXPECT_VECTOR_EQ(active_root->ScrollDelta(), impl_thread_scroll_); | 968 EXPECT_VECTOR_EQ(active_scroll_layer->ScrollDelta(), |
| 890 EXPECT_VECTOR_EQ(active_root->sent_scroll_delta(), gfx::Vector2d()); | 969 impl_thread_scroll_); |
| 970 EXPECT_VECTOR_EQ(active_scroll_layer->sent_scroll_delta(), |
| 971 gfx::Vector2d()); |
| 891 break; | 972 break; |
| 892 case 2: | 973 case 2: |
| 893 // On the next commit, this delta should have been sent and applied. | 974 // On the next commit, this delta should have been sent and applied. |
| 894 EXPECT_VECTOR_EQ(pending_root->scroll_offset(), | 975 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), |
| 895 initial_scroll_ + impl_thread_scroll_); | 976 initial_scroll_ + impl_thread_scroll_); |
| 896 EXPECT_VECTOR_EQ(pending_root->ScrollDelta(), gfx::Vector2d()); | 977 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 897 EXPECT_VECTOR_EQ(pending_root->sent_scroll_delta(), gfx::Vector2d()); | 978 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), |
| 979 gfx::Vector2d()); |
| 898 EndTest(); | 980 EndTest(); |
| 899 break; | 981 break; |
| 900 } | 982 } |
| 901 } | 983 } |
| 902 | 984 |
| 903 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 985 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 904 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); | 986 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); |
| 905 | 987 |
| 906 LayerImpl* root = impl->active_tree()->root_layer(); | 988 LayerImpl* root = impl->active_tree()->root_layer(); |
| 989 LayerImpl* scroll_layer = root->children()[0]; |
| 907 | 990 |
| 908 switch (impl->active_tree()->source_frame_number()) { | 991 switch (impl->active_tree()->source_frame_number()) { |
| 909 case 0: | 992 case 0: |
| 910 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 993 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 911 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | 994 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 912 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 995 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); |
| 913 PostSetNeedsCommitToMainThread(); | 996 PostSetNeedsCommitToMainThread(); |
| 914 break; | 997 break; |
| 915 case 1: | 998 case 1: |
| 916 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); | 999 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 917 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll_); | 1000 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_); |
| 918 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 1001 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); |
| 919 PostSetNeedsCommitToMainThread(); | 1002 PostSetNeedsCommitToMainThread(); |
| 920 break; | 1003 break; |
| 921 } | 1004 } |
| 922 } | 1005 } |
| 923 | 1006 |
| 924 virtual void AfterTest() OVERRIDE {} | 1007 virtual void AfterTest() OVERRIDE {} |
| 925 | 1008 |
| 926 private: | 1009 private: |
| 927 gfx::Vector2d initial_scroll_; | 1010 gfx::Vector2d initial_scroll_; |
| 928 gfx::Vector2d impl_thread_scroll_; | 1011 gfx::Vector2d impl_thread_scroll_; |
| 929 }; | 1012 }; |
| 930 | 1013 |
| 931 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); | 1014 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); |
| 932 | 1015 |
| 933 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset | 1016 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset |
| 934 : public LayerTreeHostScrollTest { | 1017 : public LayerTreeHostScrollTest { |
| 935 public: | 1018 public: |
| 936 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} | 1019 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} |
| 937 | 1020 |
| 1021 virtual void SetupTree() OVERRIDE { |
| 1022 LayerTreeTest::SetupTree(); |
| 1023 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 1024 layer_tree_host()->root_layer()->AddChild(scroll_layer); |
| 1025 } |
| 1026 |
| 938 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1027 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 939 | 1028 |
| 940 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1029 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 941 LayerImpl* root = impl->active_tree()->root_layer(); | 1030 LayerImpl* root = impl->active_tree()->root_layer(); |
| 942 root->SetScrollable(true); | 1031 LayerImpl* scroll_layer = root->children()[0]; |
| 1032 scroll_layer->SetScrollClipLayer(root->id()); |
| 943 | 1033 |
| 944 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 1034 // Set max_scroll_offset = (100, 100). |
| 1035 scroll_layer->SetBounds( |
| 1036 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100)); |
| 945 EXPECT_EQ(InputHandler::ScrollStarted, | 1037 EXPECT_EQ(InputHandler::ScrollStarted, |
| 946 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); | 1038 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), |
| 1039 InputHandler::Gesture)); |
| 947 | 1040 |
| 948 root->SetMaxScrollOffset(gfx::Vector2d(0, 0)); | 1041 // Set max_scroll_offset = (0, 0). |
| 1042 scroll_layer->SetBounds(root->bounds()); |
| 949 EXPECT_EQ(InputHandler::ScrollIgnored, | 1043 EXPECT_EQ(InputHandler::ScrollIgnored, |
| 950 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); | 1044 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), |
| 1045 InputHandler::Gesture)); |
| 951 | 1046 |
| 952 root->SetMaxScrollOffset(gfx::Vector2d(-100, -100)); | 1047 // Set max_scroll_offset = (-100, -100). |
| 1048 scroll_layer->SetBounds(gfx::Size()); |
| 953 EXPECT_EQ(InputHandler::ScrollIgnored, | 1049 EXPECT_EQ(InputHandler::ScrollIgnored, |
| 954 root->TryScroll(gfx::PointF(0.0f, 1.0f), InputHandler::Gesture)); | 1050 scroll_layer->TryScroll(gfx::PointF(0.0f, 1.0f), |
| 1051 InputHandler::Gesture)); |
| 955 | 1052 |
| 956 EndTest(); | 1053 EndTest(); |
| 957 } | 1054 } |
| 958 | 1055 |
| 959 virtual void AfterTest() OVERRIDE {} | 1056 virtual void AfterTest() OVERRIDE {} |
| 960 }; | 1057 }; |
| 961 | 1058 |
| 962 SINGLE_AND_MULTI_THREAD_TEST_F( | 1059 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 963 LayerTreeHostScrollTestScrollZeroMaxScrollOffset); | 1060 LayerTreeHostScrollTestScrollZeroMaxScrollOffset); |
| 964 | 1061 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 Layer* layer_; | 1183 Layer* layer_; |
| 1087 }; | 1184 }; |
| 1088 | 1185 |
| 1089 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) { | 1186 Layer* CreateScrollLayer(Layer* parent, FakeLayerScrollClient* client) { |
| 1090 scoped_refptr<Layer> scroll_layer = | 1187 scoped_refptr<Layer> scroll_layer = |
| 1091 ContentLayer::Create(&fake_content_layer_client_); | 1188 ContentLayer::Create(&fake_content_layer_client_); |
| 1092 scroll_layer->SetBounds(gfx::Size(110, 110)); | 1189 scroll_layer->SetBounds(gfx::Size(110, 110)); |
| 1093 scroll_layer->SetPosition(gfx::Point(0, 0)); | 1190 scroll_layer->SetPosition(gfx::Point(0, 0)); |
| 1094 scroll_layer->SetAnchorPoint(gfx::PointF()); | 1191 scroll_layer->SetAnchorPoint(gfx::PointF()); |
| 1095 scroll_layer->SetIsDrawable(true); | 1192 scroll_layer->SetIsDrawable(true); |
| 1096 scroll_layer->SetScrollable(true); | 1193 scroll_layer->SetScrollClipLayer(parent); |
| 1097 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 1194 scroll_layer->SetBounds(gfx::Size(parent->bounds().width() + 100, |
| 1195 parent->bounds().height() + 100)); |
| 1098 scroll_layer->set_did_scroll_callback(base::Bind( | 1196 scroll_layer->set_did_scroll_callback(base::Bind( |
| 1099 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); | 1197 &FakeLayerScrollClient::DidScroll, base::Unretained(client))); |
| 1100 client->owner_ = this; | 1198 client->owner_ = this; |
| 1101 client->layer_ = scroll_layer.get(); | 1199 client->layer_ = scroll_layer.get(); |
| 1102 parent->AddChild(scroll_layer); | 1200 parent->AddChild(scroll_layer); |
| 1103 return scroll_layer.get(); | 1201 return scroll_layer.get(); |
| 1104 } | 1202 } |
| 1105 | 1203 |
| 1106 FakeLayerScrollClient root_scroll_layer_client_; | 1204 FakeLayerScrollClient root_scroll_layer_client_; |
| 1107 FakeLayerScrollClient sibling_scroll_layer_client_; | 1205 FakeLayerScrollClient sibling_scroll_layer_client_; |
| 1108 FakeLayerScrollClient child_scroll_layer_client_; | 1206 FakeLayerScrollClient child_scroll_layer_client_; |
| 1109 | 1207 |
| 1110 FakeContentLayerClient fake_content_layer_client_; | 1208 FakeContentLayerClient fake_content_layer_client_; |
| 1111 | 1209 |
| 1112 bool scroll_destroy_whole_tree_; | 1210 bool scroll_destroy_whole_tree_; |
| 1113 }; | 1211 }; |
| 1114 | 1212 |
| 1115 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { | 1213 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { |
| 1116 RunTest(true, false, false); | 1214 RunTest(true, false, false); |
| 1117 } | 1215 } |
| 1118 | 1216 |
| 1119 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1217 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
| 1120 scroll_destroy_whole_tree_ = true; | 1218 scroll_destroy_whole_tree_ = true; |
| 1121 RunTest(true, false, false); | 1219 RunTest(true, false, false); |
| 1122 } | 1220 } |
| 1123 | 1221 |
| 1124 } // namespace | 1222 } // namespace |
| 1125 } // namespace cc | 1223 } // namespace cc |
| OLD | NEW |