| 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/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
| 10 #include "cc/layers/picture_layer.h" | 10 #include "cc/layers/picture_layer.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); | 47 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer, NULL); |
| 48 PostSetNeedsCommitToMainThread(); | 48 PostSetNeedsCommitToMainThread(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 virtual void Layout() OVERRIDE { | 51 virtual void Layout() OVERRIDE { |
| 52 Layer* root = layer_tree_host()->root_layer(); | 52 Layer* root = layer_tree_host()->root_layer(); |
| 53 Layer* scroll_layer = root->children()[0].get(); | 53 Layer* scroll_layer = root->children()[0].get(); |
| 54 if (!layer_tree_host()->source_frame_number()) { | 54 if (!layer_tree_host()->source_frame_number()) { |
| 55 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); | 55 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); |
| 56 } else { | 56 } else { |
| 57 EXPECT_VECTOR_EQ(initial_scroll_ + scroll_amount_, | 57 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(initial_scroll_, |
| 58 scroll_amount_), |
| 58 scroll_layer->scroll_offset()); | 59 scroll_layer->scroll_offset()); |
| 59 | 60 |
| 60 // Pretend like Javascript updated the scroll position itself. | 61 // Pretend like Javascript updated the scroll position itself. |
| 61 scroll_layer->SetScrollOffset(second_scroll_); | 62 scroll_layer->SetScrollOffset(second_scroll_); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 66 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 66 LayerImpl* root = impl->active_tree()->root_layer(); | 67 LayerImpl* root = impl->active_tree()->root_layer(); |
| 67 LayerImpl* scroll_layer = root->children()[0]; | 68 LayerImpl* scroll_layer = root->children()[0]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 88 | 89 |
| 89 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, | 90 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, |
| 90 float scale, | 91 float scale, |
| 91 float top_controls_delta) OVERRIDE { | 92 float top_controls_delta) OVERRIDE { |
| 92 num_scrolls_++; | 93 num_scrolls_++; |
| 93 } | 94 } |
| 94 | 95 |
| 95 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 96 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 gfx::Vector2d initial_scroll_; | 99 gfx::ScrollOffset initial_scroll_; |
| 99 gfx::Vector2d second_scroll_; | 100 gfx::ScrollOffset second_scroll_; |
| 100 gfx::Vector2d scroll_amount_; | 101 gfx::Vector2dF scroll_amount_; |
| 101 int num_scrolls_; | 102 int num_scrolls_; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); | 105 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); |
| 105 | 106 |
| 106 class LayerTreeHostScrollTestScrollMultipleRedraw | 107 class LayerTreeHostScrollTestScrollMultipleRedraw |
| 107 : public LayerTreeHostScrollTest { | 108 : public LayerTreeHostScrollTest { |
| 108 public: | 109 public: |
| 109 LayerTreeHostScrollTestScrollMultipleRedraw() | 110 LayerTreeHostScrollTestScrollMultipleRedraw() |
| 110 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} | 111 : initial_scroll_(40, 10), scroll_amount_(-3, 17), num_scrolls_(0) {} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, NULL); | 124 layer_tree_host()->RegisterViewportLayers(root_layer, scroll_layer_, NULL); |
| 124 PostSetNeedsCommitToMainThread(); | 125 PostSetNeedsCommitToMainThread(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 128 virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 128 switch (layer_tree_host()->source_frame_number()) { | 129 switch (layer_tree_host()->source_frame_number()) { |
| 129 case 0: | 130 case 0: |
| 130 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); | 131 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); |
| 131 break; | 132 break; |
| 132 case 1: | 133 case 1: |
| 133 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), | 134 EXPECT_VECTOR_EQ( |
| 134 initial_scroll_ + scroll_amount_ + scroll_amount_); | 135 scroll_layer_->scroll_offset(), |
| 136 gfx::ScrollOffsetWithDelta(initial_scroll_, |
| 137 scroll_amount_ + scroll_amount_)); |
| 135 case 2: | 138 case 2: |
| 136 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), | 139 EXPECT_VECTOR_EQ( |
| 137 initial_scroll_ + scroll_amount_ + scroll_amount_); | 140 scroll_layer_->scroll_offset(), |
| 141 gfx::ScrollOffsetWithDelta(initial_scroll_, |
| 142 scroll_amount_ + scroll_amount_)); |
| 138 break; | 143 break; |
| 139 } | 144 } |
| 140 } | 145 } |
| 141 | 146 |
| 142 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 147 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 143 LayerImpl* scroll_layer = | 148 LayerImpl* scroll_layer = |
| 144 impl->active_tree()->LayerById(scroll_layer_->id()); | 149 impl->active_tree()->LayerById(scroll_layer_->id()); |
| 145 if (impl->active_tree()->source_frame_number() == 0 && | 150 if (impl->active_tree()->source_frame_number() == 0 && |
| 146 impl->SourceAnimationFrameNumber() == 1) { | 151 impl->SourceAnimationFrameNumber() == 1) { |
| 147 // First draw after first commit. | 152 // First draw after first commit. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 158 scroll_layer->ScrollBy(scroll_amount_); | 163 scroll_layer->ScrollBy(scroll_amount_); |
| 159 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), | 164 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), |
| 160 scroll_amount_ + scroll_amount_); | 165 scroll_amount_ + scroll_amount_); |
| 161 | 166 |
| 162 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); | 167 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), initial_scroll_); |
| 163 PostSetNeedsCommitToMainThread(); | 168 PostSetNeedsCommitToMainThread(); |
| 164 } else if (impl->active_tree()->source_frame_number() == 1) { | 169 } else if (impl->active_tree()->source_frame_number() == 1) { |
| 165 // Third or later draw after second commit. | 170 // Third or later draw after second commit. |
| 166 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); | 171 EXPECT_GE(impl->SourceAnimationFrameNumber(), 3); |
| 167 EXPECT_VECTOR_EQ(scroll_layer_->ScrollDelta(), gfx::Vector2d()); | 172 EXPECT_VECTOR_EQ(scroll_layer_->ScrollDelta(), gfx::Vector2d()); |
| 168 EXPECT_VECTOR_EQ(scroll_layer_->scroll_offset(), | 173 EXPECT_VECTOR_EQ( |
| 169 initial_scroll_ + scroll_amount_ + scroll_amount_); | 174 scroll_layer_->scroll_offset(), |
| 175 gfx::ScrollOffsetWithDelta(initial_scroll_, |
| 176 scroll_amount_ + scroll_amount_)); |
| 170 EndTest(); | 177 EndTest(); |
| 171 } | 178 } |
| 172 } | 179 } |
| 173 | 180 |
| 174 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, | 181 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, |
| 175 float scale, | 182 float scale, |
| 176 float top_controls_delta) OVERRIDE { | 183 float top_controls_delta) OVERRIDE { |
| 177 num_scrolls_++; | 184 num_scrolls_++; |
| 178 } | 185 } |
| 179 | 186 |
| 180 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 187 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 181 | 188 |
| 182 private: | 189 private: |
| 183 gfx::Vector2d initial_scroll_; | 190 gfx::ScrollOffset initial_scroll_; |
| 184 gfx::Vector2d scroll_amount_; | 191 gfx::Vector2dF scroll_amount_; |
| 185 int num_scrolls_; | 192 int num_scrolls_; |
| 186 scoped_refptr<Layer> scroll_layer_; | 193 scoped_refptr<Layer> scroll_layer_; |
| 187 }; | 194 }; |
| 188 | 195 |
| 189 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); | 196 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw); |
| 190 | 197 |
| 191 class LayerTreeHostScrollTestScrollAbortedCommit | 198 class LayerTreeHostScrollTestScrollAbortedCommit |
| 192 : public LayerTreeHostScrollTest { | 199 : public LayerTreeHostScrollTest { |
| 193 public: | 200 public: |
| 194 LayerTreeHostScrollTestScrollAbortedCommit() | 201 LayerTreeHostScrollTestScrollAbortedCommit() |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 EXPECT_EQ(0, num_impl_scrolls_); | 238 EXPECT_EQ(0, num_impl_scrolls_); |
| 232 EXPECT_EQ(0, layer_tree_host()->source_frame_number()); | 239 EXPECT_EQ(0, layer_tree_host()->source_frame_number()); |
| 233 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_); | 240 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), initial_scroll_); |
| 234 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor()); | 241 EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor()); |
| 235 break; | 242 break; |
| 236 case 2: | 243 case 2: |
| 237 // This commit will be aborted, and another commit will be | 244 // This commit will be aborted, and another commit will be |
| 238 // initiated from the redraw. | 245 // initiated from the redraw. |
| 239 EXPECT_EQ(1, num_impl_scrolls_); | 246 EXPECT_EQ(1, num_impl_scrolls_); |
| 240 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | 247 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); |
| 241 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), | 248 EXPECT_VECTOR_EQ( |
| 242 initial_scroll_ + impl_scroll_); | 249 root_scroll_layer->scroll_offset(), |
| 250 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_)); |
| 243 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor()); | 251 EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor()); |
| 244 PostSetNeedsRedrawToMainThread(); | 252 PostSetNeedsRedrawToMainThread(); |
| 245 break; | 253 break; |
| 246 case 3: | 254 case 3: |
| 247 // This commit will not be aborted because of the scroll change. | 255 // This commit will not be aborted because of the scroll change. |
| 248 EXPECT_EQ(2, num_impl_scrolls_); | 256 EXPECT_EQ(2, num_impl_scrolls_); |
| 249 // The source frame number still increases even with the abort. | 257 // The source frame number still increases even with the abort. |
| 250 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | 258 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
| 251 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), | 259 EXPECT_VECTOR_EQ( |
| 252 initial_scroll_ + impl_scroll_ + impl_scroll_); | 260 root_scroll_layer->scroll_offset(), |
| 261 gfx::ScrollOffsetWithDelta(initial_scroll_, |
| 262 impl_scroll_ + impl_scroll_)); |
| 253 EXPECT_EQ(impl_scale_ * impl_scale_, | 263 EXPECT_EQ(impl_scale_ * impl_scale_, |
| 254 layer_tree_host()->page_scale_factor()); | 264 layer_tree_host()->page_scale_factor()); |
| 255 root_scroll_layer->SetScrollOffset(root_scroll_layer->scroll_offset() + | 265 root_scroll_layer->SetScrollOffset(gfx::ScrollOffsetWithDelta( |
| 256 second_main_scroll_); | 266 root_scroll_layer->scroll_offset(), second_main_scroll_)); |
| 257 break; | 267 break; |
| 258 case 4: | 268 case 4: |
| 259 // This commit will also be aborted. | 269 // This commit will also be aborted. |
| 260 EXPECT_EQ(3, num_impl_scrolls_); | 270 EXPECT_EQ(3, num_impl_scrolls_); |
| 261 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); | 271 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); |
| 272 gfx::Vector2dF delta = |
| 273 impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_; |
| 262 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), | 274 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), |
| 263 initial_scroll_ + impl_scroll_ + impl_scroll_ + | 275 gfx::ScrollOffsetWithDelta(initial_scroll_, delta)); |
| 264 impl_scroll_ + second_main_scroll_); | 276 |
| 265 // End the test by drawing to verify this commit is also aborted. | 277 // End the test by drawing to verify this commit is also aborted. |
| 266 PostSetNeedsRedrawToMainThread(); | 278 PostSetNeedsRedrawToMainThread(); |
| 267 break; | 279 break; |
| 268 } | 280 } |
| 269 } | 281 } |
| 270 | 282 |
| 271 virtual void DidBeginMainFrame() OVERRIDE { num_did_begin_main_frames_++; } | 283 virtual void DidBeginMainFrame() OVERRIDE { num_did_begin_main_frames_++; } |
| 272 | 284 |
| 273 virtual void WillCommit() OVERRIDE { num_will_commits_++; } | 285 virtual void WillCommit() OVERRIDE { num_will_commits_++; } |
| 274 | 286 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 299 // To simplify the testing flow, don't redraw here, just commit. | 311 // To simplify the testing flow, don't redraw here, just commit. |
| 300 impl->SetNeedsCommit(); | 312 impl->SetNeedsCommit(); |
| 301 } else if (impl->active_tree()->source_frame_number() == 0 && | 313 } else if (impl->active_tree()->source_frame_number() == 0 && |
| 302 impl->SourceAnimationFrameNumber() == 2) { | 314 impl->SourceAnimationFrameNumber() == 2) { |
| 303 // Test a second draw after an aborted commit. | 315 // Test a second draw after an aborted commit. |
| 304 // The scroll/scale values should be baked into the offset/scale factor | 316 // The scroll/scale values should be baked into the offset/scale factor |
| 305 // since the main thread consumed but aborted the begin frame. | 317 // since the main thread consumed but aborted the begin frame. |
| 306 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); | 318 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 307 root_scroll_layer->ScrollBy(impl_scroll_); | 319 root_scroll_layer->ScrollBy(impl_scroll_); |
| 308 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); | 320 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); |
| 309 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), | 321 EXPECT_VECTOR_EQ( |
| 310 initial_scroll_ + impl_scroll_); | 322 root_scroll_layer->scroll_offset(), |
| 323 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_scroll_)); |
| 311 | 324 |
| 312 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); | 325 EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta()); |
| 313 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); | 326 EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor()); |
| 314 impl->active_tree()->SetPageScaleDelta(impl_scale_); | 327 impl->active_tree()->SetPageScaleDelta(impl_scale_); |
| 315 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); | 328 EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta()); |
| 316 EXPECT_EQ(impl_scale_ * impl_scale_, | 329 EXPECT_EQ(impl_scale_ * impl_scale_, |
| 317 impl->active_tree()->total_page_scale_factor()); | 330 impl->active_tree()->total_page_scale_factor()); |
| 318 | 331 |
| 319 impl->SetNeedsCommit(); | 332 impl->SetNeedsCommit(); |
| 320 } else if (impl->active_tree()->source_frame_number() == 1) { | 333 } else if (impl->active_tree()->source_frame_number() == 1) { |
| 321 // Commit for source frame 1 is aborted. | 334 // Commit for source frame 1 is aborted. |
| 322 NOTREACHED(); | 335 NOTREACHED(); |
| 323 } else if (impl->active_tree()->source_frame_number() == 2 && | 336 } else if (impl->active_tree()->source_frame_number() == 2 && |
| 324 impl->SourceAnimationFrameNumber() == 3) { | 337 impl->SourceAnimationFrameNumber() == 3) { |
| 325 // Third draw after the second full commit. | 338 // Third draw after the second full commit. |
| 326 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); | 339 EXPECT_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 327 root_scroll_layer->ScrollBy(impl_scroll_); | 340 root_scroll_layer->ScrollBy(impl_scroll_); |
| 328 impl->SetNeedsCommit(); | 341 impl->SetNeedsCommit(); |
| 329 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); | 342 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), impl_scroll_); |
| 330 EXPECT_VECTOR_EQ( | 343 gfx::Vector2dF delta = impl_scroll_ + impl_scroll_ + second_main_scroll_; |
| 331 root_scroll_layer->scroll_offset(), | 344 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), |
| 332 initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_); | 345 gfx::ScrollOffsetWithDelta(initial_scroll_, delta)); |
| 333 } else if (impl->active_tree()->source_frame_number() == 2 && | 346 } else if (impl->active_tree()->source_frame_number() == 2 && |
| 334 impl->SourceAnimationFrameNumber() == 4) { | 347 impl->SourceAnimationFrameNumber() == 4) { |
| 335 // Final draw after the second aborted commit. | 348 // Final draw after the second aborted commit. |
| 336 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); | 349 EXPECT_VECTOR_EQ(root_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 350 gfx::Vector2dF delta = |
| 351 impl_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_; |
| 337 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), | 352 EXPECT_VECTOR_EQ(root_scroll_layer->scroll_offset(), |
| 338 initial_scroll_ + impl_scroll_ + impl_scroll_ + | 353 gfx::ScrollOffsetWithDelta(initial_scroll_, delta)); |
| 339 impl_scroll_ + second_main_scroll_); | |
| 340 EndTest(); | 354 EndTest(); |
| 341 } else { | 355 } else { |
| 342 // Commit for source frame 3 is aborted. | 356 // Commit for source frame 3 is aborted. |
| 343 NOTREACHED(); | 357 NOTREACHED(); |
| 344 } | 358 } |
| 345 } | 359 } |
| 346 | 360 |
| 347 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, | 361 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, |
| 348 float scale, | 362 float scale, |
| 349 float top_controls_delta) OVERRIDE { | 363 float top_controls_delta) OVERRIDE { |
| 350 num_impl_scrolls_++; | 364 num_impl_scrolls_++; |
| 351 } | 365 } |
| 352 | 366 |
| 353 virtual void AfterTest() OVERRIDE { | 367 virtual void AfterTest() OVERRIDE { |
| 354 EXPECT_EQ(3, num_impl_scrolls_); | 368 EXPECT_EQ(3, num_impl_scrolls_); |
| 355 // Verify that the embedder sees aborted commits as real commits. | 369 // Verify that the embedder sees aborted commits as real commits. |
| 356 EXPECT_EQ(4, num_will_begin_main_frames_); | 370 EXPECT_EQ(4, num_will_begin_main_frames_); |
| 357 EXPECT_EQ(4, num_did_begin_main_frames_); | 371 EXPECT_EQ(4, num_did_begin_main_frames_); |
| 358 EXPECT_EQ(4, num_will_commits_); | 372 EXPECT_EQ(4, num_will_commits_); |
| 359 EXPECT_EQ(4, num_did_commits_); | 373 EXPECT_EQ(4, num_did_commits_); |
| 360 // ...but the compositor thread only sees two real ones. | 374 // ...but the compositor thread only sees two real ones. |
| 361 EXPECT_EQ(2, num_impl_commits_); | 375 EXPECT_EQ(2, num_impl_commits_); |
| 362 } | 376 } |
| 363 | 377 |
| 364 private: | 378 private: |
| 365 gfx::Vector2d initial_scroll_; | 379 gfx::ScrollOffset initial_scroll_; |
| 366 gfx::Vector2d impl_scroll_; | 380 gfx::Vector2dF impl_scroll_; |
| 367 gfx::Vector2d second_main_scroll_; | 381 gfx::Vector2dF second_main_scroll_; |
| 368 float impl_scale_; | 382 float impl_scale_; |
| 369 int num_will_begin_main_frames_; | 383 int num_will_begin_main_frames_; |
| 370 int num_did_begin_main_frames_; | 384 int num_did_begin_main_frames_; |
| 371 int num_will_commits_; | 385 int num_will_commits_; |
| 372 int num_did_commits_; | 386 int num_did_commits_; |
| 373 int num_impl_commits_; | 387 int num_impl_commits_; |
| 374 int num_impl_scrolls_; | 388 int num_impl_scrolls_; |
| 375 }; | 389 }; |
| 376 | 390 |
| 377 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); | 391 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 virtual void Layout() OVERRIDE { | 539 virtual void Layout() OVERRIDE { |
| 526 EXPECT_VECTOR_EQ(gfx::Vector2d(), | 540 EXPECT_VECTOR_EQ(gfx::Vector2d(), |
| 527 expected_no_scroll_layer_->scroll_offset()); | 541 expected_no_scroll_layer_->scroll_offset()); |
| 528 | 542 |
| 529 switch (layer_tree_host()->source_frame_number()) { | 543 switch (layer_tree_host()->source_frame_number()) { |
| 530 case 0: | 544 case 0: |
| 531 EXPECT_VECTOR_EQ(initial_offset_, | 545 EXPECT_VECTOR_EQ(initial_offset_, |
| 532 expected_scroll_layer_->scroll_offset()); | 546 expected_scroll_layer_->scroll_offset()); |
| 533 break; | 547 break; |
| 534 case 1: | 548 case 1: |
| 535 EXPECT_VECTOR_EQ(initial_offset_ + scroll_amount_, | 549 EXPECT_VECTOR_EQ( |
| 536 expected_scroll_layer_->scroll_offset()); | 550 gfx::ScrollOffsetWithDelta(initial_offset_, scroll_amount_), |
| 551 expected_scroll_layer_->scroll_offset()); |
| 537 | 552 |
| 538 // Pretend like Javascript updated the scroll position itself. | 553 // Pretend like Javascript updated the scroll position itself. |
| 539 expected_scroll_layer_->SetScrollOffset(javascript_scroll_); | 554 expected_scroll_layer_->SetScrollOffset(javascript_scroll_); |
| 540 break; | 555 break; |
| 541 case 2: | 556 case 2: |
| 542 EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, | 557 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(javascript_scroll_, |
| 558 scroll_amount_), |
| 543 expected_scroll_layer_->scroll_offset()); | 559 expected_scroll_layer_->scroll_offset()); |
| 544 break; | 560 break; |
| 545 } | 561 } |
| 546 } | 562 } |
| 547 | 563 |
| 548 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 564 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 549 LayerImpl* root_impl = impl->active_tree()->root_layer(); | 565 LayerImpl* root_impl = impl->active_tree()->root_layer(); |
| 550 FakePictureLayerImpl* root_scroll_layer_impl = | 566 FakePictureLayerImpl* root_scroll_layer_impl = |
| 551 static_cast<FakePictureLayerImpl*>(root_impl->children()[0]); | 567 static_cast<FakePictureLayerImpl*>(root_impl->children()[0]); |
| 552 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( | 568 FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 614 |
| 599 // Check the scroll is applied as a delta. | 615 // Check the scroll is applied as a delta. |
| 600 EXPECT_VECTOR_EQ(javascript_scroll_, | 616 EXPECT_VECTOR_EQ(javascript_scroll_, |
| 601 expected_scroll_layer_impl->scroll_offset()); | 617 expected_scroll_layer_impl->scroll_offset()); |
| 602 EXPECT_VECTOR_EQ(scroll_amount_, | 618 EXPECT_VECTOR_EQ(scroll_amount_, |
| 603 expected_scroll_layer_impl->ScrollDelta()); | 619 expected_scroll_layer_impl->ScrollDelta()); |
| 604 break; | 620 break; |
| 605 } | 621 } |
| 606 case 2: | 622 case 2: |
| 607 | 623 |
| 608 EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, | 624 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(javascript_scroll_, |
| 625 scroll_amount_), |
| 609 expected_scroll_layer_impl->scroll_offset()); | 626 expected_scroll_layer_impl->scroll_offset()); |
| 610 EXPECT_VECTOR_EQ(gfx::Vector2d(), | 627 EXPECT_VECTOR_EQ(gfx::Vector2d(), |
| 611 expected_scroll_layer_impl->ScrollDelta()); | 628 expected_scroll_layer_impl->ScrollDelta()); |
| 612 | 629 |
| 613 EndTest(); | 630 EndTest(); |
| 614 break; | 631 break; |
| 615 } | 632 } |
| 616 } | 633 } |
| 617 | 634 |
| 618 virtual void AfterTest() OVERRIDE { | 635 virtual void AfterTest() OVERRIDE { |
| 619 if (scroll_child_layer_) { | 636 if (scroll_child_layer_) { |
| 620 EXPECT_EQ(0, num_scrolls_); | 637 EXPECT_EQ(0, num_scrolls_); |
| 621 EXPECT_VECTOR_EQ(javascript_scroll_ + scroll_amount_, | 638 EXPECT_VECTOR_EQ(gfx::ScrollOffsetWithDelta(javascript_scroll_, |
| 639 scroll_amount_), |
| 622 final_scroll_offset_); | 640 final_scroll_offset_); |
| 623 } else { | 641 } else { |
| 624 EXPECT_EQ(2, num_scrolls_); | 642 EXPECT_EQ(2, num_scrolls_); |
| 625 EXPECT_VECTOR_EQ(gfx::Vector2d(), final_scroll_offset_); | 643 EXPECT_VECTOR_EQ(gfx::ScrollOffset(), final_scroll_offset_); |
| 626 } | 644 } |
| 627 } | 645 } |
| 628 | 646 |
| 629 protected: | 647 protected: |
| 630 float device_scale_factor_; | 648 float device_scale_factor_; |
| 631 bool scroll_child_layer_; | 649 bool scroll_child_layer_; |
| 632 | 650 |
| 633 gfx::Vector2d initial_offset_; | 651 gfx::ScrollOffset initial_offset_; |
| 634 gfx::Vector2d javascript_scroll_; | 652 gfx::ScrollOffset javascript_scroll_; |
| 635 gfx::Vector2d scroll_amount_; | 653 gfx::Vector2d scroll_amount_; |
| 636 int num_scrolls_; | 654 int num_scrolls_; |
| 637 gfx::Vector2d final_scroll_offset_; | 655 gfx::ScrollOffset final_scroll_offset_; |
| 638 | 656 |
| 639 FakeContentLayerClient fake_content_layer_client_; | 657 FakeContentLayerClient fake_content_layer_client_; |
| 640 | 658 |
| 641 scoped_refptr<Layer> root_scroll_layer_; | 659 scoped_refptr<Layer> root_scroll_layer_; |
| 642 scoped_refptr<Layer> child_layer_; | 660 scoped_refptr<Layer> child_layer_; |
| 643 scoped_refptr<Layer> expected_scroll_layer_; | 661 scoped_refptr<Layer> expected_scroll_layer_; |
| 644 scoped_refptr<Layer> expected_no_scroll_layer_; | 662 scoped_refptr<Layer> expected_no_scroll_layer_; |
| 645 }; | 663 }; |
| 646 | 664 |
| 647 TEST_F(LayerTreeHostScrollTestCaseWithChild, | 665 TEST_F(LayerTreeHostScrollTestCaseWithChild, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 virtual void BeginTest() OVERRIDE { | 788 virtual void BeginTest() OVERRIDE { |
| 771 PostSetNeedsCommitToMainThread(); | 789 PostSetNeedsCommitToMainThread(); |
| 772 } | 790 } |
| 773 | 791 |
| 774 virtual void Layout() OVERRIDE { | 792 virtual void Layout() OVERRIDE { |
| 775 Layer* root = layer_tree_host()->root_layer(); | 793 Layer* root = layer_tree_host()->root_layer(); |
| 776 Layer* scroll_layer = root->children()[0].get(); | 794 Layer* scroll_layer = root->children()[0].get(); |
| 777 if (!layer_tree_host()->source_frame_number()) { | 795 if (!layer_tree_host()->source_frame_number()) { |
| 778 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); | 796 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 779 } else { | 797 } else { |
| 780 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), | 798 EXPECT_VECTOR_EQ( |
| 781 initial_scroll_ + impl_thread_scroll1_); | 799 scroll_layer->scroll_offset(), |
| 800 gfx::ScrollOffsetWithDelta(initial_scroll_, impl_thread_scroll1_)); |
| 782 | 801 |
| 783 // Pretend like Javascript updated the scroll position itself with a | 802 // Pretend like Javascript updated the scroll position itself with a |
| 784 // change of main_thread_scroll. | 803 // change of main_thread_scroll. |
| 785 scroll_layer->SetScrollOffset(initial_scroll_ + main_thread_scroll_ + | 804 scroll_layer->SetScrollOffset( |
| 786 impl_thread_scroll1_); | 805 gfx::ScrollOffsetWithDelta( |
| 806 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_)); |
| 787 } | 807 } |
| 788 } | 808 } |
| 789 | 809 |
| 790 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 810 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 791 // We force a second draw here of the first commit before activating | 811 // We force a second draw here of the first commit before activating |
| 792 // the second commit. | 812 // the second commit. |
| 793 if (impl->active_tree()->source_frame_number() == 0) | 813 if (impl->active_tree()->source_frame_number() == 0) |
| 794 impl->SetNeedsRedraw(); | 814 impl->SetNeedsRedraw(); |
| 795 } | 815 } |
| 796 | 816 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 824 scroll_layer->ScrollBy(impl_thread_scroll2_); | 844 scroll_layer->ScrollBy(impl_thread_scroll2_); |
| 825 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); | 845 EXPECT_VECTOR_EQ(scroll_layer->scroll_offset(), initial_scroll_); |
| 826 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), | 846 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), |
| 827 impl_thread_scroll1_ + impl_thread_scroll2_); | 847 impl_thread_scroll1_ + impl_thread_scroll2_); |
| 828 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), | 848 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), |
| 829 impl_thread_scroll1_); | 849 impl_thread_scroll1_); |
| 830 | 850 |
| 831 LayerImpl* pending_scroll_layer = pending_root->children()[0]; | 851 LayerImpl* pending_scroll_layer = pending_root->children()[0]; |
| 832 EXPECT_VECTOR_EQ( | 852 EXPECT_VECTOR_EQ( |
| 833 pending_scroll_layer->scroll_offset(), | 853 pending_scroll_layer->scroll_offset(), |
| 834 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); | 854 gfx::ScrollOffsetWithDelta( |
| 855 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_)); |
| 835 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), | 856 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), |
| 836 impl_thread_scroll2_); | 857 impl_thread_scroll2_); |
| 837 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), | 858 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), |
| 838 gfx::Vector2d()); | 859 gfx::Vector2d()); |
| 839 } | 860 } |
| 840 break; | 861 break; |
| 841 case 1: | 862 case 1: |
| 842 EXPECT_FALSE(impl->pending_tree()); | 863 EXPECT_FALSE(impl->pending_tree()); |
| 843 EXPECT_VECTOR_EQ( | 864 EXPECT_VECTOR_EQ( |
| 844 scroll_layer->scroll_offset(), | 865 scroll_layer->scroll_offset(), |
| 845 initial_scroll_ + main_thread_scroll_ + impl_thread_scroll1_); | 866 gfx::ScrollOffsetWithDelta( |
| 867 initial_scroll_, main_thread_scroll_ + impl_thread_scroll1_)); |
| 846 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_); | 868 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll2_); |
| 847 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); | 869 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); |
| 848 EndTest(); | 870 EndTest(); |
| 849 break; | 871 break; |
| 850 } | 872 } |
| 851 } | 873 } |
| 852 | 874 |
| 853 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, | 875 virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, |
| 854 float scale, | 876 float scale, |
| 855 float top_controls_delta) OVERRIDE { | 877 float top_controls_delta) OVERRIDE { |
| 856 num_scrolls_++; | 878 num_scrolls_++; |
| 857 } | 879 } |
| 858 | 880 |
| 859 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } | 881 virtual void AfterTest() OVERRIDE { EXPECT_EQ(1, num_scrolls_); } |
| 860 | 882 |
| 861 private: | 883 private: |
| 862 gfx::Vector2d initial_scroll_; | 884 gfx::ScrollOffset initial_scroll_; |
| 863 gfx::Vector2d main_thread_scroll_; | 885 gfx::Vector2dF main_thread_scroll_; |
| 864 gfx::Vector2d impl_thread_scroll1_; | 886 gfx::Vector2dF impl_thread_scroll1_; |
| 865 gfx::Vector2d impl_thread_scroll2_; | 887 gfx::Vector2dF impl_thread_scroll2_; |
| 866 int num_scrolls_; | 888 int num_scrolls_; |
| 867 }; | 889 }; |
| 868 | 890 |
| 869 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple); | 891 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestSimple); |
| 870 | 892 |
| 871 // This test makes sure that layers pick up scrolls that occur between | 893 // This test makes sure that layers pick up scrolls that occur between |
| 872 // beginning a commit and finishing a commit (aka scroll deltas not | 894 // beginning a commit and finishing a commit (aka scroll deltas not |
| 873 // included in sent scroll delta) still apply to layers that don't | 895 // included in sent scroll delta) still apply to layers that don't |
| 874 // push properties. | 896 // push properties. |
| 875 class ImplSidePaintingScrollTestImplOnlyScroll | 897 class ImplSidePaintingScrollTestImplOnlyScroll |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 ASSERT_TRUE(active_root); | 981 ASSERT_TRUE(active_root); |
| 960 EXPECT_VECTOR_EQ(active_scroll_layer->scroll_offset(), initial_scroll_); | 982 EXPECT_VECTOR_EQ(active_scroll_layer->scroll_offset(), initial_scroll_); |
| 961 EXPECT_VECTOR_EQ(active_scroll_layer->ScrollDelta(), | 983 EXPECT_VECTOR_EQ(active_scroll_layer->ScrollDelta(), |
| 962 impl_thread_scroll_); | 984 impl_thread_scroll_); |
| 963 EXPECT_VECTOR_EQ(active_scroll_layer->sent_scroll_delta(), | 985 EXPECT_VECTOR_EQ(active_scroll_layer->sent_scroll_delta(), |
| 964 gfx::Vector2d()); | 986 gfx::Vector2d()); |
| 965 break; | 987 break; |
| 966 case 2: | 988 case 2: |
| 967 // On the next commit, this delta should have been sent and applied. | 989 // On the next commit, this delta should have been sent and applied. |
| 968 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), | 990 EXPECT_VECTOR_EQ(pending_scroll_layer->scroll_offset(), |
| 969 initial_scroll_ + impl_thread_scroll_); | 991 gfx::ScrollOffsetWithDelta(initial_scroll_, |
| 992 impl_thread_scroll_)); |
| 970 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); | 993 EXPECT_VECTOR_EQ(pending_scroll_layer->ScrollDelta(), gfx::Vector2d()); |
| 971 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), | 994 EXPECT_VECTOR_EQ(pending_scroll_layer->sent_scroll_delta(), |
| 972 gfx::Vector2d()); | 995 gfx::Vector2d()); |
| 973 EndTest(); | 996 EndTest(); |
| 974 break; | 997 break; |
| 975 } | 998 } |
| 976 } | 999 } |
| 977 | 1000 |
| 978 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1001 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 979 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); | 1002 ImplSidePaintingScrollTest::DrawLayersOnThread(impl); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 993 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_); | 1016 EXPECT_VECTOR_EQ(scroll_layer->ScrollDelta(), impl_thread_scroll_); |
| 994 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); | 1017 EXPECT_VECTOR_EQ(scroll_layer->sent_scroll_delta(), gfx::Vector2d()); |
| 995 PostSetNeedsCommitToMainThread(); | 1018 PostSetNeedsCommitToMainThread(); |
| 996 break; | 1019 break; |
| 997 } | 1020 } |
| 998 } | 1021 } |
| 999 | 1022 |
| 1000 virtual void AfterTest() OVERRIDE {} | 1023 virtual void AfterTest() OVERRIDE {} |
| 1001 | 1024 |
| 1002 private: | 1025 private: |
| 1003 gfx::Vector2d initial_scroll_; | 1026 gfx::ScrollOffset initial_scroll_; |
| 1004 gfx::Vector2d impl_thread_scroll_; | 1027 gfx::Vector2dF impl_thread_scroll_; |
| 1005 }; | 1028 }; |
| 1006 | 1029 |
| 1007 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); | 1030 MULTI_THREAD_TEST_F(ImplSidePaintingScrollTestImplOnlyScroll); |
| 1008 | 1031 |
| 1009 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset | 1032 class LayerTreeHostScrollTestScrollZeroMaxScrollOffset |
| 1010 : public LayerTreeHostScrollTest { | 1033 : public LayerTreeHostScrollTest { |
| 1011 public: | 1034 public: |
| 1012 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} | 1035 LayerTreeHostScrollTestScrollZeroMaxScrollOffset() {} |
| 1013 | 1036 |
| 1014 virtual void SetupTree() OVERRIDE { | 1037 virtual void SetupTree() OVERRIDE { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 RunTest(true, false, true); | 1238 RunTest(true, false, true); |
| 1216 } | 1239 } |
| 1217 | 1240 |
| 1218 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { | 1241 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { |
| 1219 scroll_destroy_whole_tree_ = true; | 1242 scroll_destroy_whole_tree_ = true; |
| 1220 RunTest(true, false, true); | 1243 RunTest(true, false, true); |
| 1221 } | 1244 } |
| 1222 | 1245 |
| 1223 } // namespace | 1246 } // namespace |
| 1224 } // namespace cc | 1247 } // namespace cc |
| OLD | NEW |