| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 case 1: | 65 case 1: |
| 66 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_); | 66 EXPECT_VECTOR_EQ(root->scroll_offset(), second_scroll_); |
| 67 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); | 67 EXPECT_VECTOR_EQ(root->ScrollDelta(), scroll_amount_); |
| 68 EndTest(); | 68 EndTest(); |
| 69 break; | 69 break; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 73 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 74 OVERRIDE { | 74 OVERRIDE { |
| 75 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); | |
| 76 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta); | |
| 77 num_scrolls_++; | 75 num_scrolls_++; |
| 78 } | 76 } |
| 79 | 77 |
| 80 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 78 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 81 | 79 |
| 82 private: | 80 private: |
| 83 gfx::Vector2d initial_scroll_; | 81 gfx::Vector2d initial_scroll_; |
| 84 gfx::Vector2d second_scroll_; | 82 gfx::Vector2d second_scroll_; |
| 85 gfx::Vector2d scroll_amount_; | 83 gfx::Vector2d scroll_amount_; |
| 86 int num_scrolls_; | 84 int num_scrolls_; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); | 143 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); |
| 146 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); | 144 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 147 EXPECT_VECTOR_EQ(root->scroll_offset(), | 145 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 148 initial_scroll_ + scroll_amount_ + scroll_amount_); | 146 initial_scroll_ + scroll_amount_ + scroll_amount_); |
| 149 EndTest(); | 147 EndTest(); |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 | 150 |
| 153 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 151 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 154 OVERRIDE { | 152 OVERRIDE { |
| 155 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); | |
| 156 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta); | |
| 157 num_scrolls_++; | 153 num_scrolls_++; |
| 158 } | 154 } |
| 159 | 155 |
| 160 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 156 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 161 | 157 |
| 162 private: | 158 private: |
| 163 gfx::Vector2d initial_scroll_; | 159 gfx::Vector2d initial_scroll_; |
| 164 gfx::Vector2d scroll_amount_; | 160 gfx::Vector2d scroll_amount_; |
| 165 int num_scrolls_; | 161 int num_scrolls_; |
| 166 }; | 162 }; |
| 167 | 163 |
| 168 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); | 164 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); |
| 169 | 165 |
| 166 class LayerTreeHostScrollTestScrollAbortedCommit |
| 167 : public LayerTreeHostScrollTest { |
| 168 public: |
| 169 LayerTreeHostScrollTestScrollAbortedCommit() |
| 170 : initial_scroll_(50, 60), |
| 171 impl_scroll_(-3, 2), |
| 172 second_main_scroll_(14, -3), |
| 173 impl_scale_(2.f), |
| 174 num_begin_frames_(0), |
| 175 num_commits_(0), |
| 176 num_impl_scrolls_(0) {} |
| 177 |
| 178 virtual void BeginTest() OVERRIDE { |
| 179 layer_tree_host()->root_layer()->SetScrollable(true); |
| 180 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); |
| 181 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); |
| 182 layer_tree_host()->root_layer() |
| 183 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 184 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 185 PostSetNeedsCommitToMainThread(); |
| 186 } |
| 187 |
| 188 virtual void WillBeginFrame() OVERRIDE { |
| 189 num_begin_frames_++; |
| 190 Layer* root = layer_tree_host()->root_layer(); |
| 191 switch (num_begin_frames_) { |
| 192 case 1: |
| 193 // This will not be aborted because of the initial prop changes. |
| 194 EXPECT_EQ(0, num_impl_scrolls_); |
| 195 EXPECT_EQ(0, layer_tree_host()->commit_number()); |
| 196 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 197 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor()); |
| 198 break; |
| 199 case 2: |
| 200 // This commit will be aborted, and another commit will be |
| 201 // initiated from the redraw. |
| 202 EXPECT_EQ(1, num_impl_scrolls_); |
| 203 EXPECT_EQ(1, layer_tree_host()->commit_number()); |
| 204 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 205 initial_scroll_ + impl_scroll_); |
| 206 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor()); |
| 207 PostSetNeedsRedrawToMainThread(); |
| 208 break; |
| 209 case 3: |
| 210 // This commit will not be aborted because of the scroll change. |
| 211 EXPECT_EQ(2, num_impl_scrolls_); |
| 212 EXPECT_EQ(1, layer_tree_host()->commit_number()); |
| 213 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 214 initial_scroll_ + impl_scroll_ + impl_scroll_); |
| 215 EXPECT_EQ(impl_scale_ * impl_scale_, |
| 216 layer_tree_host()->page_scale_factor()); |
| 217 root->SetScrollOffset(root->scroll_offset() + second_main_scroll_); |
| 218 break; |
| 219 case 4: |
| 220 // This commit will also be aborted. |
| 221 EXPECT_EQ(3, num_impl_scrolls_); |
| 222 EXPECT_EQ(2, layer_tree_host()->commit_number()); |
| 223 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 224 initial_scroll_ + impl_scroll_ + impl_scroll_ + |
| 225 impl_scroll_ + second_main_scroll_); |
| 226 // End the test by drawing to verify this commit is also aborted. |
| 227 PostSetNeedsRedrawToMainThread(); |
| 228 break; |
| 229 } |
| 230 } |
| 231 |
| 232 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 233 num_commits_++; |
| 234 } |
| 235 |
| 236 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 237 LayerImpl* root = impl->active_tree()->root_layer(); |
| 238 |
| 239 if (impl->active_tree()->source_frame_number() == 0 && |
| 240 impl->SourceAnimationFrameNumber() == 1) { |
| 241 // First draw |
| 242 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 243 root->ScrollBy(impl_scroll_); |
| 244 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); |
| 245 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 246 |
| 247 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
| 248 EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor()); |
| 249 impl->active_tree()->SetPageScaleDelta(impl_scale_); |
| 250 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
| 251 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); |
| 252 |
| 253 // To simplify the testing flow, don't redraw here, just commit. |
| 254 impl->SetNeedsCommit(); |
| 255 } else if (impl->active_tree()->source_frame_number() == 0 && |
| 256 impl->SourceAnimationFrameNumber() == 2) { |
| 257 // Test a second draw after an aborted commit. |
| 258 // The scroll/scale values should be baked into the offset/scale factor |
| 259 // since the main thread consumed but aborted the begin frame. |
| 260 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 261 root->ScrollBy(impl_scroll_); |
| 262 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); |
| 263 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_ + impl_scroll_); |
| 264 |
| 265 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
| 266 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); |
| 267 impl->active_tree()->SetPageScaleDelta(impl_scale_); |
| 268 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
| 269 EXPECT_EQ(impl_scale_ * impl_scale_, |
| 270 impl->active_tree()->total_page_scale_factor()); |
| 271 |
| 272 impl->SetNeedsCommit(); |
| 273 } else if (impl->active_tree()->source_frame_number() == 1 && |
| 274 impl->SourceAnimationFrameNumber() == 3) { |
| 275 // Third draw after the second full commit. |
| 276 EXPECT_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 277 root->ScrollBy(impl_scroll_); |
| 278 impl->SetNeedsCommit(); |
| 279 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); |
| 280 EXPECT_VECTOR_EQ( |
| 281 root->scroll_offset(), |
| 282 initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); |
| 283 } else if (impl->active_tree()->source_frame_number() == 1 && |
| 284 impl->SourceAnimationFrameNumber() == 4) { |
| 285 // Final draw after the second aborted commit. |
| 286 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 287 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 288 initial_scroll_ + impl_scroll_ + impl_scroll_ + |
| 289 impl_scroll_ + second_main_scroll_); |
| 290 EndTest(); |
| 291 } |
| 292 } |
| 293 |
| 294 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 295 OVERRIDE { |
| 296 // Emulate Blink: |
| 297 layer_tree_host()->SetPageScaleFactorAndLimits( |
| 298 layer_tree_host()->page_scale_factor() * scale, 0.01f, 100.f); |
| 299 num_impl_scrolls_++; |
| 300 } |
| 301 |
| 302 virtual void AfterTest() OVERRIDE { |
| 303 EXPECT_EQ(3, num_impl_scrolls_); |
| 304 EXPECT_EQ(2, num_commits_); |
| 305 EXPECT_EQ(4, num_begin_frames_); |
| 306 } |
| 307 |
| 308 private: |
| 309 gfx::Vector2d initial_scroll_; |
| 310 gfx::Vector2d impl_scroll_; |
| 311 gfx::Vector2d second_main_scroll_; |
| 312 float impl_scale_; |
| 313 int num_begin_frames_; |
| 314 int num_commits_; |
| 315 int num_impl_scrolls_; |
| 316 }; |
| 317 |
| 318 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); |
| 319 |
| 170 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { | 320 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { |
| 171 public: | 321 public: |
| 172 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} | 322 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} |
| 173 | 323 |
| 174 virtual void BeginTest() OVERRIDE { | 324 virtual void BeginTest() OVERRIDE { |
| 175 layer_tree_host()->root_layer()->SetScrollable(true); | 325 layer_tree_host()->root_layer()->SetScrollable(true); |
| 176 PostSetNeedsCommitToMainThread(); | 326 PostSetNeedsCommitToMainThread(); |
| 177 } | 327 } |
| 178 | 328 |
| 179 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 329 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 201 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); | 351 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); |
| 202 EXPECT_VECTOR_EQ( | 352 EXPECT_VECTOR_EQ( |
| 203 root->ScrollDelta(), | 353 root->ScrollDelta(), |
| 204 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); | 354 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); |
| 205 EndTest(); | 355 EndTest(); |
| 206 break; | 356 break; |
| 207 } | 357 } |
| 208 root->ScrollBy(scroll_amount_); | 358 root->ScrollBy(scroll_amount_); |
| 209 } | 359 } |
| 210 | 360 |
| 211 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | |
| 212 OVERRIDE { | |
| 213 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); | |
| 214 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta); | |
| 215 } | |
| 216 | |
| 217 virtual void AfterTest() OVERRIDE {} | 361 virtual void AfterTest() OVERRIDE {} |
| 218 | 362 |
| 219 private: | 363 private: |
| 220 gfx::Vector2dF scroll_amount_; | 364 gfx::Vector2dF scroll_amount_; |
| 221 }; | 365 }; |
| 222 | 366 |
| 223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); | 367 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); |
| 224 | 368 |
| 225 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { | 369 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { |
| 226 public: | 370 public: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 422 } |
| 279 | 423 |
| 280 expected_scroll_layer_->SetScrollOffset(initial_offset_); | 424 expected_scroll_layer_->SetScrollOffset(initial_offset_); |
| 281 | 425 |
| 282 layer_tree_host()->SetRootLayer(root_layer); | 426 layer_tree_host()->SetRootLayer(root_layer); |
| 283 LayerTreeHostScrollTest::SetupTree(); | 427 LayerTreeHostScrollTest::SetupTree(); |
| 284 } | 428 } |
| 285 | 429 |
| 286 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 430 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 287 | 431 |
| 432 virtual void WillCommit() OVERRIDE { |
| 433 // Keep the test committing (otherwise the early out for no update |
| 434 // will stall the test). |
| 435 layer_tree_host()->SetNeedsCommit(); |
| 436 } |
| 437 |
| 288 void DidScroll() { | 438 void DidScroll() { |
| 289 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); | 439 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); |
| 290 } | 440 } |
| 291 | 441 |
| 292 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 442 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 293 OVERRIDE { | 443 OVERRIDE { |
| 294 gfx::Vector2d offset = root_scroll_layer_->scroll_offset(); | |
| 295 root_scroll_layer_->SetScrollOffset(offset + scroll_delta); | |
| 296 num_scrolls_++; | 444 num_scrolls_++; |
| 297 } | 445 } |
| 298 | 446 |
| 299 virtual void Layout() OVERRIDE { | 447 virtual void Layout() OVERRIDE { |
| 300 EXPECT_VECTOR_EQ(gfx::Vector2d(), | 448 EXPECT_VECTOR_EQ(gfx::Vector2d(), |
| 301 expected_no_scroll_layer_->scroll_offset()); | 449 expected_no_scroll_layer_->scroll_offset()); |
| 302 | 450 |
| 303 switch (layer_tree_host()->commit_number()) { | 451 switch (layer_tree_host()->commit_number()) { |
| 304 case 0: | 452 case 0: |
| 305 EXPECT_VECTOR_EQ(initial_offset_, | 453 EXPECT_VECTOR_EQ(initial_offset_, |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); | 785 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); |
| 638 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); | 786 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); |
| 639 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 787 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); |
| 640 EndTest(); | 788 EndTest(); |
| 641 break; | 789 break; |
| 642 } | 790 } |
| 643 } | 791 } |
| 644 | 792 |
| 645 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 793 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 646 OVERRIDE { | 794 OVERRIDE { |
| 647 gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset(); | |
| 648 layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta); | |
| 649 num_scrolls_++; | 795 num_scrolls_++; |
| 650 } | 796 } |
| 651 | 797 |
| 652 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 798 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 653 | 799 |
| 654 private: | 800 private: |
| 655 gfx::Vector2d initial_scroll_; | 801 gfx::Vector2d initial_scroll_; |
| 656 gfx::Vector2d main_thread_scroll_; | 802 gfx::Vector2d main_thread_scroll_; |
| 657 gfx::Vector2d impl_thread_scroll1_; | 803 gfx::Vector2d impl_thread_scroll1_; |
| 658 gfx::Vector2d impl_thread_scroll2_; | 804 gfx::Vector2d impl_thread_scroll2_; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 RunTest(true, false, false); | 995 RunTest(true, false, false); |
| 850 } | 996 } |
| 851 | 997 |
| 852 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 998 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
| 853 scroll_destroy_whole_tree_ = true; | 999 scroll_destroy_whole_tree_ = true; |
| 854 RunTest(true, false, false); | 1000 RunTest(true, false, false); |
| 855 } | 1001 } |
| 856 | 1002 |
| 857 } // namespace | 1003 } // namespace |
| 858 } // namespace cc | 1004 } // namespace cc |
| OLD | NEW |