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