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 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 298 root_layer->SetBounds(gfx::Size(400,400)); |
| 299 layer_tree_host()->SetRootLayer(root_layer); |
| 300 |
| 301 scoped_refptr<Layer> content_layer = FakeContentLayer::Create(&client_); |
| 302 content_layer->SetScrollable(true); |
| 303 content_layer->SetScrollOffset(gfx::Vector2d(10, 20)); |
| 304 content_layer->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
| 305 content_layer->SetBounds(gfx::Size(100, 200)); |
| 306 root_layer->AddChild(content_layer); |
| 307 |
| 308 scoped_refptr<Layer> scrollbar_layer = |
| 309 FakeScrollbarLayer::Create(false, true, content_layer->id()); |
| 310 scrollbar_layer->SetPosition(gfx::Point(300, 300)); |
| 311 scrollbar_layer->SetBounds(gfx::Size(10, 100)); |
| 312 root_layer->AddChild(scrollbar_layer); |
| 313 |
| 314 gfx::RectF content_rect(content_layer->position(), |
| 315 content_layer->bounds()); |
| 316 gfx::RectF scrollbar_rect(scrollbar_layer->position(), |
| 317 scrollbar_layer->bounds()); |
| 318 EXPECT_FALSE(content_rect.Intersects(scrollbar_rect)); |
| 319 |
| 320 LayerTreeHostDamageTest::SetupTree(); |
| 321 } |
| 322 |
| 323 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 324 LayerTreeHostImpl::FrameData* frame_data, |
| 325 bool result) OVERRIDE { |
| 326 EXPECT_TRUE(result); |
| 327 RenderSurfaceImpl* root_surface = |
| 328 host_impl->active_tree()->root_layer()->render_surface(); |
| 329 gfx::RectF root_damage = |
| 330 root_surface->damage_tracker()->current_damage_rect(); |
| 331 root_damage.Intersect(root_surface->content_rect()); |
| 332 switch (did_swaps_) { |
| 333 case 0: |
| 334 // The first frame has damage, so we should draw and swap. |
| 335 break; |
| 336 case 1: |
| 337 // The second frame should damage the scrollbars. |
| 338 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); |
| 339 break; |
| 340 case 2: |
| 341 // The third frame should damage the scrollbars. |
| 342 EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); |
| 343 break; |
| 344 case 3: |
| 345 // The fourth frame should not damage the scrollbars. |
| 346 EXPECT_FALSE(root_damage.Intersects(gfx::Rect(300, 300, 10, 100))); |
| 347 EndTest(); |
| 348 break; |
| 349 } |
| 350 return result; |
| 351 } |
| 352 |
| 353 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 354 bool result) OVERRIDE { |
| 355 ++did_swaps_; |
| 356 EXPECT_TRUE(result); |
| 357 LayerImpl* root = host_impl->active_tree()->root_layer(); |
| 358 LayerImpl* scroll_layer = root->children()[0]; |
| 359 switch (did_swaps_) { |
| 360 case 1: |
| 361 host_impl->ScrollBegin(gfx::Point(1,1), InputHandler::Wheel); |
| 362 EXPECT_TRUE(host_impl->ScrollBy(gfx::Point(), |
| 363 gfx::Vector2dF(10.0, 10.0))); |
| 364 break; |
| 365 case 2: |
| 366 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(60, 100)); |
| 367 host_impl->SetNeedsRedraw(); |
| 368 break; |
| 369 case 3: |
| 370 // Test that modifying the position of the content layer (not |
| 371 // scrolling) won't damage the scrollbar. |
| 372 scroll_layer->SetPosition(gfx::Point(1,1)); |
| 373 scroll_layer->SetScrollOffset(scroll_layer->scroll_offset()); |
| 374 host_impl->SetNeedsRedraw(); |
| 375 break; |
| 376 } |
| 377 |
| 378 } |
| 379 |
| 380 virtual void AfterTest() OVERRIDE { |
| 381 EXPECT_EQ(4, did_swaps_); |
| 382 } |
| 383 |
| 384 FakeContentLayerClient client_; |
| 385 int did_swaps_; |
| 386 }; |
| 387 |
| 388 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
| 389 |
288 } // namespace | 390 } // namespace |
289 } // namespace cc | 391 } // namespace cc |
OLD | NEW |