Chromium Code Reviews| 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "cc/content_layer.h" | 7 #include "cc/content_layer.h" |
| 8 #include "cc/layer.h" | 8 #include "cc/layer.h" |
| 9 #include "cc/layer_impl.h" | 9 #include "cc/layer_impl.h" |
| 10 #include "cc/layer_tree_impl.h" | 10 #include "cc/layer_tree_impl.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 | 230 |
| 231 private: | 231 private: |
| 232 gfx::Vector2dF scroll_amount_; | 232 gfx::Vector2dF scroll_amount_; |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 TEST_F(LayerTreeHostScrollTestFractionalScroll, runMultiThread) | 235 TEST_F(LayerTreeHostScrollTestFractionalScroll, runMultiThread) |
| 236 { | 236 { |
| 237 runTest(true); | 237 runTest(true); |
| 238 } | 238 } |
| 239 | 239 |
| 240 template<int kDeviceScaleFactorTimesTen, bool kScrollChildLayer> | |
| 240 class LayerTreeHostScrollTestCaseWithChild : | 241 class LayerTreeHostScrollTestCaseWithChild : |
| 241 public LayerTreeHostScrollTest, | 242 public LayerTreeHostScrollTest, |
| 242 public WebKit::WebLayerScrollClient { | 243 public WebKit::WebLayerScrollClient { |
| 243 public: | 244 public: |
| 244 LayerTreeHostScrollTestCaseWithChild( | 245 LayerTreeHostScrollTestCaseWithChild() |
| 245 float device_scale_factor, bool scroll_child_layer) | 246 : initial_offset_(10, 20), |
| 246 : device_scale_factor_(device_scale_factor), | |
| 247 scroll_child_layer_(scroll_child_layer), | |
| 248 initial_offset_(10, 20), | |
| 249 javascript_scroll_(40, 5), | 247 javascript_scroll_(40, 5), |
| 250 scroll_amount_(2, -1), | 248 scroll_amount_(2, -1), |
| 251 num_scrolls_(0) { | 249 num_scrolls_(0) { |
| 252 } | 250 } |
| 253 | 251 |
| 254 virtual void setupTree() OVERRIDE { | 252 virtual void setupTree() OVERRIDE { |
| 255 m_layerTreeHost->setDeviceScaleFactor(device_scale_factor_); | 253 m_layerTreeHost->setDeviceScaleFactor(kDeviceScaleFactorTimesTen / 10.f); |
| 256 | 254 |
| 257 scoped_refptr<Layer> root_layer = Layer::create(); | 255 scoped_refptr<Layer> root_layer = Layer::create(); |
| 258 root_layer->setBounds(gfx::Size(10, 10)); | 256 root_layer->setBounds(gfx::Size(10, 10)); |
| 259 | 257 |
| 260 root_scroll_layer_ = ContentLayer::create(&fake_content_layer_client_); | 258 root_scroll_layer_ = ContentLayer::create(&fake_content_layer_client_); |
| 261 root_scroll_layer_->setBounds(gfx::Size(110, 110)); | 259 root_scroll_layer_->setBounds(gfx::Size(110, 110)); |
| 262 | 260 |
| 263 root_scroll_layer_->setPosition(gfx::Point(0, 0)); | 261 root_scroll_layer_->setPosition(gfx::Point(0, 0)); |
| 264 root_scroll_layer_->setAnchorPoint(gfx::PointF()); | 262 root_scroll_layer_->setAnchorPoint(gfx::PointF()); |
| 265 | 263 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 276 // like device pixels, and device scale factor is 2, then they will | 274 // like device pixels, and device scale factor is 2, then they will |
| 277 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. | 275 // be considered at 2.5, 2.5 in logical pixels, and will miss this layer. |
| 278 child_layer_->setPosition(gfx::Point(5, 5)); | 276 child_layer_->setPosition(gfx::Point(5, 5)); |
| 279 child_layer_->setAnchorPoint(gfx::PointF()); | 277 child_layer_->setAnchorPoint(gfx::PointF()); |
| 280 | 278 |
| 281 child_layer_->setIsDrawable(true); | 279 child_layer_->setIsDrawable(true); |
| 282 child_layer_->setScrollable(true); | 280 child_layer_->setScrollable(true); |
| 283 child_layer_->setMaxScrollOffset(gfx::Vector2d(100, 100)); | 281 child_layer_->setMaxScrollOffset(gfx::Vector2d(100, 100)); |
| 284 root_scroll_layer_->addChild(child_layer_); | 282 root_scroll_layer_->addChild(child_layer_); |
| 285 | 283 |
| 286 if (scroll_child_layer_) { | 284 if (kScrollChildLayer) { |
| 287 expected_scroll_layer_ = child_layer_; | 285 expected_scroll_layer_ = child_layer_; |
| 288 expected_no_scroll_layer_ = root_scroll_layer_; | 286 expected_no_scroll_layer_ = root_scroll_layer_; |
| 289 } else { | 287 } else { |
| 290 expected_scroll_layer_ = root_scroll_layer_; | 288 expected_scroll_layer_ = root_scroll_layer_; |
| 291 expected_no_scroll_layer_ = child_layer_; | 289 expected_no_scroll_layer_ = child_layer_; |
| 292 } | 290 } |
| 293 | 291 |
| 294 expected_scroll_layer_->setScrollOffset(initial_offset_); | 292 expected_scroll_layer_->setScrollOffset(initial_offset_); |
| 295 | 293 |
| 296 m_layerTreeHost->setRootLayer(root_layer); | 294 m_layerTreeHost->setRootLayer(root_layer); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 } | 336 } |
| 339 } | 337 } |
| 340 | 338 |
| 341 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 339 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 342 LayerImpl* root_impl = impl->rootLayer(); | 340 LayerImpl* root_impl = impl->rootLayer(); |
| 343 LayerImpl* root_scroll_layer_impl = root_impl->children()[0]; | 341 LayerImpl* root_scroll_layer_impl = root_impl->children()[0]; |
| 344 LayerImpl* child_layer_impl = root_scroll_layer_impl->children()[0]; | 342 LayerImpl* child_layer_impl = root_scroll_layer_impl->children()[0]; |
| 345 | 343 |
| 346 LayerImpl* expected_scroll_layer_impl = NULL; | 344 LayerImpl* expected_scroll_layer_impl = NULL; |
| 347 LayerImpl* expected_no_scroll_layer_impl = NULL; | 345 LayerImpl* expected_no_scroll_layer_impl = NULL; |
| 348 if (scroll_child_layer_) { | 346 if (kScrollChildLayer) { |
| 349 expected_scroll_layer_impl = child_layer_impl; | 347 expected_scroll_layer_impl = child_layer_impl; |
| 350 expected_no_scroll_layer_impl = root_scroll_layer_impl; | 348 expected_no_scroll_layer_impl = root_scroll_layer_impl; |
| 351 } else { | 349 } else { |
| 352 expected_scroll_layer_impl = root_scroll_layer_impl; | 350 expected_scroll_layer_impl = root_scroll_layer_impl; |
| 353 expected_no_scroll_layer_impl = child_layer_impl; | 351 expected_no_scroll_layer_impl = child_layer_impl; |
| 354 } | 352 } |
| 355 | 353 |
| 356 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->scrollDelta()); | 354 EXPECT_VECTOR_EQ(gfx::Vector2d(), root_impl->scrollDelta()); |
| 357 EXPECT_VECTOR_EQ( | 355 EXPECT_VECTOR_EQ( |
| 358 gfx::Vector2d(), | 356 gfx::Vector2d(), |
| 359 expected_no_scroll_layer_impl->scrollDelta()); | 357 expected_no_scroll_layer_impl->scrollDelta()); |
| 360 | 358 |
| 361 // Ensure device scale factor is affecting the layers. | 359 // Ensure device scale factor is affecting the layers. |
| 362 gfx::Size expected_content_bounds = gfx::ToCeiledSize( | 360 gfx::Size expected_content_bounds = gfx::ToCeiledSize( |
| 363 gfx::ScaleSize(root_scroll_layer_impl->bounds(), device_scale_factor_)); | 361 gfx::ScaleSize( |
| 362 root_scroll_layer_impl->bounds(), | |
| 363 kDeviceScaleFactorTimesTen / 10.f)); | |
| 364 EXPECT_SIZE_EQ( | 364 EXPECT_SIZE_EQ( |
| 365 expected_content_bounds, | 365 expected_content_bounds, |
| 366 root_scroll_layer_->contentBounds()); | 366 root_scroll_layer_->contentBounds()); |
| 367 | 367 |
| 368 expected_content_bounds = gfx::ToCeiledSize( | 368 expected_content_bounds = gfx::ToCeiledSize( |
| 369 gfx::ScaleSize(child_layer_impl->bounds(), device_scale_factor_)); | 369 gfx::ScaleSize( |
| 370 child_layer_impl->bounds(), kDeviceScaleFactorTimesTen / 10.f)); | |
| 370 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->contentBounds()); | 371 EXPECT_SIZE_EQ(expected_content_bounds, child_layer_->contentBounds()); |
| 371 | 372 |
| 372 switch (impl->activeTree()->source_frame_number()) { | 373 switch (impl->activeTree()->source_frame_number()) { |
| 373 case 0: { | 374 case 0: { |
| 374 // Gesture scroll on impl thread. | 375 // Gesture scroll on impl thread. |
| 375 InputHandlerClient::ScrollStatus status = impl->scrollBegin( | 376 InputHandlerClient::ScrollStatus status = impl->scrollBegin( |
| 376 gfx::ToCeiledPoint( | 377 gfx::ToCeiledPoint( |
| 377 expected_scroll_layer_impl->position() + | 378 expected_scroll_layer_impl->position() + |
| 378 gfx::Vector2dF(0.5f, 0.5f)), | 379 gfx::Vector2dF(0.5f, 0.5f)), |
| 379 InputHandlerClient::Gesture); | 380 InputHandlerClient::Gesture); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 EXPECT_VECTOR_EQ( | 419 EXPECT_VECTOR_EQ( |
| 419 gfx::Vector2d(), | 420 gfx::Vector2d(), |
| 420 expected_scroll_layer_impl->scrollDelta()); | 421 expected_scroll_layer_impl->scrollDelta()); |
| 421 | 422 |
| 422 endTest(); | 423 endTest(); |
| 423 break; | 424 break; |
| 424 } | 425 } |
| 425 } | 426 } |
| 426 | 427 |
| 427 virtual void afterTest() OVERRIDE { | 428 virtual void afterTest() OVERRIDE { |
| 428 if (scroll_child_layer_) { | 429 if (kScrollChildLayer) { |
| 429 EXPECT_EQ(0, num_scrolls_); | 430 EXPECT_EQ(0, num_scrolls_); |
| 430 EXPECT_VECTOR_EQ( | 431 EXPECT_VECTOR_EQ( |
| 431 javascript_scroll_ + scroll_amount_, | 432 javascript_scroll_ + scroll_amount_, |
| 432 final_scroll_offset_); | 433 final_scroll_offset_); |
| 433 } else { | 434 } else { |
| 434 EXPECT_EQ(2, num_scrolls_); | 435 EXPECT_EQ(2, num_scrolls_); |
| 435 EXPECT_VECTOR_EQ(gfx::Vector2d(), final_scroll_offset_); | 436 EXPECT_VECTOR_EQ(gfx::Vector2d(), final_scroll_offset_); |
| 436 } | 437 } |
| 437 } | 438 } |
| 438 | 439 |
| 439 private: | 440 private: |
| 440 float device_scale_factor_; | |
| 441 bool scroll_child_layer_; | |
| 442 gfx::Vector2d initial_offset_; | 441 gfx::Vector2d initial_offset_; |
| 443 gfx::Vector2d javascript_scroll_; | 442 gfx::Vector2d javascript_scroll_; |
| 444 gfx::Vector2d scroll_amount_; | 443 gfx::Vector2d scroll_amount_; |
| 445 int num_scrolls_; | 444 int num_scrolls_; |
| 446 gfx::Vector2d final_scroll_offset_; | 445 gfx::Vector2d final_scroll_offset_; |
| 447 | 446 |
| 448 FakeContentLayerClient fake_content_layer_client_; | 447 FakeContentLayerClient fake_content_layer_client_; |
| 449 | 448 |
| 450 scoped_refptr<Layer> root_scroll_layer_; | 449 scoped_refptr<Layer> root_scroll_layer_; |
| 451 scoped_refptr<Layer> child_layer_; | 450 scoped_refptr<Layer> child_layer_; |
| 452 scoped_refptr<Layer> expected_scroll_layer_; | 451 scoped_refptr<Layer> expected_scroll_layer_; |
| 453 scoped_refptr<Layer> expected_no_scroll_layer_; | 452 scoped_refptr<Layer> expected_no_scroll_layer_; |
| 454 }; | 453 }; |
| 455 | 454 |
| 456 MULTI_THREAD_TEST_P2(LayerTreeHostScrollTestCaseWithChild, | 455 class LayerTreeHostScrollTestScrollChild_DeviceScaleFactor1 |
| 457 DeviceScaleFactor1, 1.0f, | 456 : public LayerTreeHostScrollTestCaseWithChild<10, true> {}; |
| 458 ScrollChild, true) | 457 |
| 459 MULTI_THREAD_TEST_P2(LayerTreeHostScrollTestCaseWithChild, | 458 MULTI_THREAD_TEST_F( |
| 460 DeviceScaleFactor15, 1.5f, | 459 LayerTreeHostScrollTestScrollChild_DeviceScaleFactor1) |
|
jamesr
2013/01/03 22:59:07
this is 5 lines to set up and run a threaded test.
| |
| 461 ScrollChild, true) | 460 |
| 462 MULTI_THREAD_TEST_P2(LayerTreeHostScrollTestCaseWithChild, | 461 class LayerTreeHostScrollTestScrollChild_DeviceScaleFactor15 |
| 463 DeviceScaleFactor2, 2.0f, | 462 : public LayerTreeHostScrollTestCaseWithChild<15, true> {}; |
| 464 ScrollChild, true) | 463 |
| 465 MULTI_THREAD_TEST_P2(LayerTreeHostScrollTestCaseWithChild, | 464 MULTI_THREAD_TEST_F( |
| 466 DeviceScaleFactor1, 1.0f, | 465 LayerTreeHostScrollTestScrollChild_DeviceScaleFactor15) |
| 467 ScrollRootScrollLayer, false) | 466 |
| 468 MULTI_THREAD_TEST_P2(LayerTreeHostScrollTestCaseWithChild, | 467 class LayerTreeHostScrollTestScrollChild_DeviceScaleFactor2 |
| 469 DeviceScaleFactor15, 1.5f, | 468 : public LayerTreeHostScrollTestCaseWithChild<20, true> {}; |
| 470 ScrollRootScrollLayer, false) | 469 |
| 471 MULTI_THREAD_TEST_P2(LayerTreeHostScrollTestCaseWithChild, | 470 MULTI_THREAD_TEST_F( |
| 472 DeviceScaleFactor2, 2.0f, | 471 LayerTreeHostScrollTestScrollChild_DeviceScaleFactor2) |
| 473 ScrollRootScrollLayer, false) | 472 |
| 473 class LayerTreeHostScrollTestScrollRootScrollLayer_DeviceScaleFactor1 | |
| 474 : public LayerTreeHostScrollTestCaseWithChild<10, true> {}; | |
| 475 | |
| 476 MULTI_THREAD_TEST_F( | |
| 477 LayerTreeHostScrollTestScrollRootScrollLayer_DeviceScaleFactor1) | |
| 478 | |
| 479 class LayerTreeHostScrollTestScrollRootScrollLayer_DeviceScaleFactor15 | |
| 480 : public LayerTreeHostScrollTestCaseWithChild<15, true> {}; | |
| 481 | |
| 482 MULTI_THREAD_TEST_F( | |
| 483 LayerTreeHostScrollTestScrollRootScrollLayer_DeviceScaleFactor15) | |
| 484 | |
| 485 class LayerTreeHostScrollTestScrollRootScrollLayer_DeviceScaleFactor2 | |
| 486 : public LayerTreeHostScrollTestCaseWithChild<20, true> {}; | |
| 487 | |
| 488 MULTI_THREAD_TEST_F( | |
| 489 LayerTreeHostScrollTestScrollRootScrollLayer_DeviceScaleFactor2) | |
| 490 | |
| 474 | 491 |
| 475 } // namespace | 492 } // namespace |
| 476 } // namespace cc | 493 } // namespace cc |
| OLD | NEW |