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_will_begin_frames_(0), |
| 175 num_did_begin_frames_(0), |
| 176 num_will_commits_(0), |
| 177 num_did_commits_(0), |
| 178 num_impl_commits_(0), |
| 179 num_impl_scrolls_(0) {} |
| 180 |
| 181 virtual void BeginTest() OVERRIDE { |
| 182 layer_tree_host()->root_layer()->SetScrollable(true); |
| 183 layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_); |
| 184 layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200)); |
| 185 layer_tree_host()->root_layer() |
| 186 ->SetMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 187 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f); |
| 188 PostSetNeedsCommitToMainThread(); |
| 189 } |
| 190 |
| 191 virtual void WillBeginFrame() OVERRIDE { |
| 192 num_will_begin_frames_++; |
| 193 Layer* root = layer_tree_host()->root_layer(); |
| 194 switch (num_will_begin_frames_) { |
| 195 case 1: |
| 196 // This will not be aborted because of the initial prop changes. |
| 197 EXPECT_EQ(0, num_impl_scrolls_); |
| 198 EXPECT_EQ(0, layer_tree_host()->commit_number()); |
| 199 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 200 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor()); |
| 201 break; |
| 202 case 2: |
| 203 // This commit will be aborted, and another commit will be |
| 204 // initiated from the redraw. |
| 205 EXPECT_EQ(1, num_impl_scrolls_); |
| 206 EXPECT_EQ(1, layer_tree_host()->commit_number()); |
| 207 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 208 initial_scroll_ + impl_scroll_); |
| 209 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor()); |
| 210 PostSetNeedsRedrawToMainThread(); |
| 211 break; |
| 212 case 3: |
| 213 // This commit will not be aborted because of the scroll change. |
| 214 EXPECT_EQ(2, num_impl_scrolls_); |
| 215 EXPECT_EQ(1, layer_tree_host()->commit_number()); |
| 216 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 217 initial_scroll_ + impl_scroll_ + impl_scroll_); |
| 218 EXPECT_EQ(impl_scale_ * impl_scale_, |
| 219 layer_tree_host()->page_scale_factor()); |
| 220 root->SetScrollOffset(root->scroll_offset() + second_main_scroll_); |
| 221 break; |
| 222 case 4: |
| 223 // This commit will also be aborted. |
| 224 EXPECT_EQ(3, num_impl_scrolls_); |
| 225 EXPECT_EQ(2, layer_tree_host()->commit_number()); |
| 226 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 227 initial_scroll_ + impl_scroll_ + impl_scroll_ + |
| 228 impl_scroll_ + second_main_scroll_); |
| 229 // End the test by drawing to verify this commit is also aborted. |
| 230 PostSetNeedsRedrawToMainThread(); |
| 231 break; |
| 232 } |
| 233 } |
| 234 |
| 235 virtual void DidBeginFrame() OVERRIDE { |
| 236 num_did_begin_frames_++; |
| 237 } |
| 238 |
| 239 virtual void WillCommit() OVERRIDE { |
| 240 num_will_commits_++; |
| 241 } |
| 242 |
| 243 virtual void DidCommit() OVERRIDE { |
| 244 num_did_commits_++; |
| 245 } |
| 246 |
| 247 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 248 num_impl_commits_++; |
| 249 } |
| 250 |
| 251 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 252 LayerImpl* root = impl->active_tree()->root_layer(); |
| 253 |
| 254 if (impl->active_tree()->source_frame_number() == 0 && |
| 255 impl->SourceAnimationFrameNumber() == 1) { |
| 256 // First draw |
| 257 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 258 root->ScrollBy(impl_scroll_); |
| 259 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); |
| 260 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_); |
| 261 |
| 262 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
| 263 EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor()); |
| 264 impl->active_tree()->SetPageScaleDelta(impl_scale_); |
| 265 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
| 266 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); |
| 267 |
| 268 // To simplify the testing flow, don't redraw here, just commit. |
| 269 impl->SetNeedsCommit(); |
| 270 } else if (impl->active_tree()->source_frame_number() == 0 && |
| 271 impl->SourceAnimationFrameNumber() == 2) { |
| 272 // Test a second draw after an aborted commit. |
| 273 // The scroll/scale values should be baked into the offset/scale factor |
| 274 // since the main thread consumed but aborted the begin frame. |
| 275 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 276 root->ScrollBy(impl_scroll_); |
| 277 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); |
| 278 EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_ + impl_scroll_); |
| 279 |
| 280 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
| 281 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); |
| 282 impl->active_tree()->SetPageScaleDelta(impl_scale_); |
| 283 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
| 284 EXPECT_EQ(impl_scale_ * impl_scale_, |
| 285 impl->active_tree()->total_page_scale_factor()); |
| 286 |
| 287 impl->SetNeedsCommit(); |
| 288 } else if (impl->active_tree()->source_frame_number() == 1 && |
| 289 impl->SourceAnimationFrameNumber() == 3) { |
| 290 // Third draw after the second full commit. |
| 291 EXPECT_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 292 root->ScrollBy(impl_scroll_); |
| 293 impl->SetNeedsCommit(); |
| 294 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_); |
| 295 EXPECT_VECTOR_EQ( |
| 296 root->scroll_offset(), |
| 297 initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); |
| 298 } else if (impl->active_tree()->source_frame_number() == 1 && |
| 299 impl->SourceAnimationFrameNumber() == 4) { |
| 300 // Final draw after the second aborted commit. |
| 301 EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d()); |
| 302 EXPECT_VECTOR_EQ(root->scroll_offset(), |
| 303 initial_scroll_ + impl_scroll_ + impl_scroll_ + |
| 304 impl_scroll_ + second_main_scroll_); |
| 305 EndTest(); |
| 306 } |
| 307 } |
| 308 |
| 309 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
| 310 OVERRIDE { |
| 311 num_impl_scrolls_++; |
| 312 } |
| 313 |
| 314 virtual void AfterTest() OVERRIDE { |
| 315 EXPECT_EQ(3, num_impl_scrolls_); |
| 316 // Verify that the embedder sees aborted commits as real commits. |
| 317 EXPECT_EQ(4, num_will_begin_frames_); |
| 318 EXPECT_EQ(4, num_did_begin_frames_); |
| 319 EXPECT_EQ(4, num_will_commits_); |
| 320 EXPECT_EQ(4, num_did_commits_); |
| 321 // ...but the compositor thread only sees two real ones. |
| 322 EXPECT_EQ(2, num_impl_commits_); |
| 323 } |
| 324 |
| 325 private: |
| 326 gfx::Vector2d initial_scroll_; |
| 327 gfx::Vector2d impl_scroll_; |
| 328 gfx::Vector2d second_main_scroll_; |
| 329 float impl_scale_; |
| 330 int num_will_begin_frames_; |
| 331 int num_did_begin_frames_; |
| 332 int num_will_commits_; |
| 333 int num_did_commits_; |
| 334 int num_impl_commits_; |
| 335 int num_impl_scrolls_; |
| 336 }; |
| 337 |
| 338 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); |
| 339 |
170 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { | 340 class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest { |
171 public: | 341 public: |
172 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} | 342 LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {} |
173 | 343 |
174 virtual void BeginTest() OVERRIDE { | 344 virtual void BeginTest() OVERRIDE { |
175 layer_tree_host()->root_layer()->SetScrollable(true); | 345 layer_tree_host()->root_layer()->SetScrollable(true); |
176 PostSetNeedsCommitToMainThread(); | 346 PostSetNeedsCommitToMainThread(); |
177 } | 347 } |
178 | 348 |
179 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 349 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
(...skipping 21 matching lines...) Expand all Loading... |
201 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); | 371 gfx::ToFlooredVector2d(scroll_amount_ + scroll_amount_)); |
202 EXPECT_VECTOR_EQ( | 372 EXPECT_VECTOR_EQ( |
203 root->ScrollDelta(), | 373 root->ScrollDelta(), |
204 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); | 374 gfx::Vector2dF(fmod(2.0f * scroll_amount_.x(), 1.0f), 0.0f)); |
205 EndTest(); | 375 EndTest(); |
206 break; | 376 break; |
207 } | 377 } |
208 root->ScrollBy(scroll_amount_); | 378 root->ScrollBy(scroll_amount_); |
209 } | 379 } |
210 | 380 |
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 {} | 381 virtual void AfterTest() OVERRIDE {} |
218 | 382 |
219 private: | 383 private: |
220 gfx::Vector2dF scroll_amount_; | 384 gfx::Vector2dF scroll_amount_; |
221 }; | 385 }; |
222 | 386 |
223 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); | 387 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestFractionalScroll); |
224 | 388 |
225 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { | 389 class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest { |
226 public: | 390 public: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 442 } |
279 | 443 |
280 expected_scroll_layer_->SetScrollOffset(initial_offset_); | 444 expected_scroll_layer_->SetScrollOffset(initial_offset_); |
281 | 445 |
282 layer_tree_host()->SetRootLayer(root_layer); | 446 layer_tree_host()->SetRootLayer(root_layer); |
283 LayerTreeHostScrollTest::SetupTree(); | 447 LayerTreeHostScrollTest::SetupTree(); |
284 } | 448 } |
285 | 449 |
286 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 450 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
287 | 451 |
| 452 virtual void WillCommit() OVERRIDE { |
| 453 // Keep the test committing (otherwise the early out for no update |
| 454 // will stall the test). |
| 455 layer_tree_host()->SetNeedsCommit(); |
| 456 } |
| 457 |
288 void DidScroll() { | 458 void DidScroll() { |
289 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); | 459 final_scroll_offset_ = expected_scroll_layer_->scroll_offset(); |
290 } | 460 } |
291 | 461 |
292 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 462 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
293 OVERRIDE { | 463 OVERRIDE { |
294 gfx::Vector2d offset = root_scroll_layer_->scroll_offset(); | |
295 root_scroll_layer_->SetScrollOffset(offset + scroll_delta); | |
296 num_scrolls_++; | 464 num_scrolls_++; |
297 } | 465 } |
298 | 466 |
299 virtual void Layout() OVERRIDE { | 467 virtual void Layout() OVERRIDE { |
300 EXPECT_VECTOR_EQ(gfx::Vector2d(), | 468 EXPECT_VECTOR_EQ(gfx::Vector2d(), |
301 expected_no_scroll_layer_->scroll_offset()); | 469 expected_no_scroll_layer_->scroll_offset()); |
302 | 470 |
303 switch (layer_tree_host()->commit_number()) { | 471 switch (layer_tree_host()->commit_number()) { |
304 case 0: | 472 case 0: |
305 EXPECT_VECTOR_EQ(initial_offset_, | 473 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_); | 805 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); |
638 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); | 806 EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_thread_scroll2_); |
639 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); | 807 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), gfx::Vector2d()); |
640 EndTest(); | 808 EndTest(); |
641 break; | 809 break; |
642 } | 810 } |
643 } | 811 } |
644 | 812 |
645 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) | 813 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale) |
646 OVERRIDE { | 814 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_++; | 815 num_scrolls_++; |
650 } | 816 } |
651 | 817 |
652 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 818 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
653 | 819 |
654 private: | 820 private: |
655 gfx::Vector2d initial_scroll_; | 821 gfx::Vector2d initial_scroll_; |
656 gfx::Vector2d main_thread_scroll_; | 822 gfx::Vector2d main_thread_scroll_; |
657 gfx::Vector2d impl_thread_scroll1_; | 823 gfx::Vector2d impl_thread_scroll1_; |
658 gfx::Vector2d impl_thread_scroll2_; | 824 gfx::Vector2d impl_thread_scroll2_; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 RunTest(true, false, false); | 1015 RunTest(true, false, false); |
850 } | 1016 } |
851 | 1017 |
852 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1018 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
853 scroll_destroy_whole_tree_ = true; | 1019 scroll_destroy_whole_tree_ = true; |
854 RunTest(true, false, false); | 1020 RunTest(true, false, false); |
855 } | 1021 } |
856 | 1022 |
857 } // namespace | 1023 } // namespace |
858 } // namespace cc | 1024 } // namespace cc |
OLD | NEW |