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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "cc/test/fake_content_layer.h" | 7 #include "cc/test/fake_content_layer.h" |
| 8 #include "cc/test/fake_content_layer_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
| 9 #include "cc/test/fake_scrollbar_layer.h" | |
| 9 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
| 10 #include "cc/trees/damage_tracker.h" | 11 #include "cc/trees/damage_tracker.h" |
| 11 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // These tests deal with damage tracking. | 17 // These tests deal with damage tracking. |
| 17 class LayerTreeHostDamageTest : public LayerTreeTest {}; | 18 class LayerTreeHostDamageTest : public LayerTreeTest {}; |
| 18 | 19 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 virtual void AfterTest() OVERRIDE {} | 279 virtual void AfterTest() OVERRIDE {} |
| 279 | 280 |
| 280 FakeContentLayerClient client_; | 281 FakeContentLayerClient client_; |
| 281 scoped_refptr<FakeContentLayer> root_; | 282 scoped_refptr<FakeContentLayer> root_; |
| 282 scoped_refptr<FakeContentLayer> child_; | 283 scoped_refptr<FakeContentLayer> child_; |
| 283 gfx::RectF child_damage_rect_; | 284 gfx::RectF child_damage_rect_; |
| 284 }; | 285 }; |
| 285 | 286 |
| 286 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage); | 287 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage); |
| 287 | 288 |
| 289 class LayerTreeHostDamageTestScrollbarDoesDamage | |
| 290 : public LayerTreeHostDamageTest { | |
| 291 virtual void BeginTest() OVERRIDE { | |
| 292 did_swaps_ = 0; | |
| 293 PostSetNeedsCommitToMainThread(); | |
| 294 } | |
| 295 | |
| 296 virtual void SetupTree() OVERRIDE { | |
| 297 layer_tree_root_ = Layer::Create(); | |
|
danakj
2013/08/14 21:29:14
does this need to be a member variable? usually th
| |
| 298 scoped_refptr<Layer> content_layer = FakeContentLayer::Create(&client_); | |
| 299 scoped_refptr<Layer> scrollbar_layer = | |
| 300 FakeScrollbarLayer::Create(false, true, content_layer->id()); | |
| 301 layer_tree_root_->AddChild(content_layer); | |
|
danakj
2013/08/14 21:29:14
nit: some whitespace in between blocks of calls fo
| |
| 302 layer_tree_root_->AddChild(scrollbar_layer); | |
| 303 layer_tree_host()->SetRootLayer(layer_tree_root_); | |
| 304 content_layer->SetScrollable(true); | |
| 305 content_layer->SetScrollOffset(gfx::Vector2d(10, 20)); | |
| 306 content_layer->SetMaxScrollOffset(gfx::Vector2d(30, 50)); | |
| 307 content_layer->SetBounds(gfx::Size(100, 200)); | |
| 308 scrollbar_layer->SetPosition(gfx::Point(300, 300)); | |
| 309 scrollbar_layer->SetBounds(gfx::Size(10, 100)); | |
| 310 layer_tree_root_->SetBounds(gfx::Size(400,400)); | |
| 311 LayerTreeHostDamageTest::SetupTree(); | |
|
danakj
2013/08/14 21:29:14
can you EXPECT here that the content_layer does no
| |
| 312 } | |
| 313 | |
| 314 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 315 LayerTreeHostImpl::FrameData* frame_data, | |
| 316 bool result) OVERRIDE { | |
| 317 EXPECT_TRUE(result); | |
| 318 RenderSurfaceImpl* root_surface = | |
| 319 host_impl->active_tree()->root_layer()->render_surface(); | |
| 320 gfx::RectF root_damage = | |
| 321 root_surface->damage_tracker()->current_damage_rect(); | |
| 322 root_damage.Intersect(root_surface->content_rect()); | |
| 323 switch (did_swaps_) { | |
| 324 case 0: | |
| 325 // The first frame has damage, so we should draw and swap. | |
| 326 break; | |
| 327 case 1: | |
| 328 // The second frame should damage the scrollbars. | |
| 329 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); | |
| 330 break; | |
| 331 case 2: | |
| 332 // The third frame should not damage the scrollbars. | |
| 333 EXPECT_FALSE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); | |
|
enne (OOO)
2013/08/14 21:33:41
Can Contains be changed to Intersects here to be m
| |
| 334 EndTest(); | |
| 335 break; | |
| 336 } | |
| 337 return result; | |
| 338 } | |
| 339 | |
| 340 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | |
| 341 bool result) OVERRIDE { | |
| 342 ++did_swaps_; | |
| 343 EXPECT_TRUE(result); | |
| 344 switch (did_swaps_) { | |
| 345 case 1: | |
| 346 host_impl->ScrollBegin(gfx::Point(1,1), InputHandler::Wheel); | |
| 347 EXPECT_TRUE(host_impl->ScrollBy(gfx::Point(), | |
| 348 gfx::Vector2dF(10.0, 10.0))); | |
| 349 break; | |
| 350 case 2: | |
|
danakj
2013/08/14 21:29:14
Can you add a case that changes the max scroll (th
| |
| 351 host_impl->ScheduleAnimation(); | |
|
danakj
2013/08/14 21:29:14
nit: SetNeedsRedraw() instead?
| |
| 352 LayerImpl* root = host_impl->active_tree()->root_layer(); | |
| 353 | |
| 354 root->children()[0]->SetPosition(gfx::Point(1,1)); | |
|
danakj
2013/08/14 21:29:14
Add a comment explaining what this case is doing a
| |
| 355 break; | |
| 356 } | |
| 357 | |
| 358 } | |
| 359 | |
| 360 virtual void AfterTest() OVERRIDE { | |
| 361 EXPECT_EQ(3, did_swaps_); | |
| 362 } | |
| 363 | |
| 364 FakeContentLayerClient client_; | |
| 365 scoped_refptr<Layer> layer_tree_root_; | |
| 366 int did_swaps_; | |
| 367 }; | |
| 368 | |
| 369 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); | |
| 370 | |
| 288 } // namespace | 371 } // namespace |
| 289 } // namespace cc | 372 } // namespace cc |
| OLD | NEW |