| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "cc/layers/solid_color_layer.h" | 11 #include "cc/layers/solid_color_layer.h" |
| 12 #include "cc/test/fake_content_layer_client.h" | 12 #include "cc/test/fake_content_layer_client.h" |
| 13 #include "cc/test/fake_painted_scrollbar_layer.h" | 13 #include "cc/test/fake_painted_scrollbar_layer.h" |
| 14 #include "cc/test/fake_picture_layer.h" | 14 #include "cc/test/fake_picture_layer.h" |
| 15 #include "cc/test/layer_test_common.h" |
| 15 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
| 16 #include "cc/trees/damage_tracker.h" | 17 #include "cc/trees/damage_tracker.h" |
| 17 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // These tests deal with damage tracking. | 23 // These tests deal with damage tracking. |
| 23 class LayerTreeHostDamageTest : public LayerTreeTest {}; | 24 class LayerTreeHostDamageTest : public LayerTreeTest {}; |
| 24 | 25 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 48 break; | 49 break; |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, | 53 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, |
| 53 LayerTreeHostImpl::FrameData* frame_data, | 54 LayerTreeHostImpl::FrameData* frame_data, |
| 54 DrawResult draw_result) override { | 55 DrawResult draw_result) override { |
| 55 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 56 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 56 | 57 |
| 57 RenderSurfaceImpl* root_surface = | 58 RenderSurfaceImpl* root_surface = |
| 58 impl->active_tree()->root_layer_for_testing()->GetRenderSurface(); | 59 GetRenderSurface(impl->active_tree()->root_layer_for_testing()); |
| 59 gfx::Rect root_damage; | 60 gfx::Rect root_damage; |
| 60 EXPECT_TRUE( | 61 EXPECT_TRUE( |
| 61 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); | 62 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); |
| 62 | 63 |
| 63 switch (draw_count_) { | 64 switch (draw_count_) { |
| 64 case 0: | 65 case 0: |
| 65 // The first frame has full damage. | 66 // The first frame has full damage. |
| 66 EXPECT_EQ(gfx::Rect(10, 10), root_damage); | 67 EXPECT_EQ(gfx::Rect(10, 10), root_damage); |
| 67 break; | 68 break; |
| 68 case 1: | 69 case 1: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 break; | 112 break; |
| 112 } | 113 } |
| 113 } | 114 } |
| 114 | 115 |
| 115 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, | 116 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, |
| 116 LayerTreeHostImpl::FrameData* frame_data, | 117 LayerTreeHostImpl::FrameData* frame_data, |
| 117 DrawResult draw_result) override { | 118 DrawResult draw_result) override { |
| 118 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 119 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 119 | 120 |
| 120 RenderSurfaceImpl* root_surface = | 121 RenderSurfaceImpl* root_surface = |
| 121 impl->active_tree()->root_layer_for_testing()->GetRenderSurface(); | 122 GetRenderSurface(impl->active_tree()->root_layer_for_testing()); |
| 122 gfx::Rect root_damage; | 123 gfx::Rect root_damage; |
| 123 EXPECT_TRUE( | 124 EXPECT_TRUE( |
| 124 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); | 125 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); |
| 125 | 126 |
| 126 switch (draw_count_) { | 127 switch (draw_count_) { |
| 127 case 0: | 128 case 0: |
| 128 // The first frame has full damage. | 129 // The first frame has full damage. |
| 129 EXPECT_EQ(gfx::Rect(10, 10), root_damage); | 130 EXPECT_EQ(gfx::Rect(10, 10), root_damage); |
| 130 break; | 131 break; |
| 131 case 1: | 132 case 1: |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 LayerTreeHostDamageTest::SetupTree(); | 254 LayerTreeHostDamageTest::SetupTree(); |
| 254 client_.set_bounds(root_->bounds()); | 255 client_.set_bounds(root_->bounds()); |
| 255 } | 256 } |
| 256 | 257 |
| 257 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 258 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 258 LayerTreeHostImpl::FrameData* frame_data, | 259 LayerTreeHostImpl::FrameData* frame_data, |
| 259 DrawResult draw_result) override { | 260 DrawResult draw_result) override { |
| 260 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 261 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 261 | 262 |
| 262 RenderSurfaceImpl* root_surface = | 263 RenderSurfaceImpl* root_surface = |
| 263 host_impl->active_tree()->root_layer_for_testing()->GetRenderSurface(); | 264 GetRenderSurface(host_impl->active_tree()->root_layer_for_testing()); |
| 264 gfx::Rect root_damage; | 265 gfx::Rect root_damage; |
| 265 EXPECT_TRUE( | 266 EXPECT_TRUE( |
| 266 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); | 267 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); |
| 267 root_damage.Intersect(root_surface->content_rect()); | 268 root_damage.Intersect(root_surface->content_rect()); |
| 268 | 269 |
| 269 int source_frame = host_impl->active_tree()->source_frame_number(); | 270 int source_frame = host_impl->active_tree()->source_frame_number(); |
| 270 switch (source_frame) { | 271 switch (source_frame) { |
| 271 case 0: | 272 case 0: |
| 272 // The first frame draws and clears any damage. | 273 // The first frame draws and clears any damage. |
| 273 EXPECT_EQ(root_surface->content_rect(), root_damage); | 274 EXPECT_EQ(root_surface->content_rect(), root_damage); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 void BeginTest() override { | 381 void BeginTest() override { |
| 381 num_draws_ = 0; | 382 num_draws_ = 0; |
| 382 PostSetNeedsCommitToMainThread(); | 383 PostSetNeedsCommitToMainThread(); |
| 383 } | 384 } |
| 384 | 385 |
| 385 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 386 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 386 LayerTreeHostImpl::FrameData* frame_data, | 387 LayerTreeHostImpl::FrameData* frame_data, |
| 387 DrawResult draw_result) override { | 388 DrawResult draw_result) override { |
| 388 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 389 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 389 RenderSurfaceImpl* root_surface = | 390 RenderSurfaceImpl* root_surface = |
| 390 host_impl->active_tree()->root_layer_for_testing()->GetRenderSurface(); | 391 GetRenderSurface(host_impl->active_tree()->root_layer_for_testing()); |
| 391 gfx::Rect root_damage; | 392 gfx::Rect root_damage; |
| 392 EXPECT_TRUE( | 393 EXPECT_TRUE( |
| 393 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); | 394 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); |
| 394 root_damage.Intersect(root_surface->content_rect()); | 395 root_damage.Intersect(root_surface->content_rect()); |
| 395 switch (num_draws_) { | 396 switch (num_draws_) { |
| 396 case 0: | 397 case 0: |
| 397 // The first frame has damage, so we should draw and swap. | 398 // The first frame has damage, so we should draw and swap. |
| 398 break; | 399 break; |
| 399 case 1: | 400 case 1: |
| 400 // The second frame should not damage the scrollbars. | 401 // The second frame should not damage the scrollbars. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 void BeginTest() override { | 467 void BeginTest() override { |
| 467 num_draws_ = 0; | 468 num_draws_ = 0; |
| 468 PostSetNeedsCommitToMainThread(); | 469 PostSetNeedsCommitToMainThread(); |
| 469 } | 470 } |
| 470 | 471 |
| 471 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 472 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 472 LayerTreeHostImpl::FrameData* frame_data, | 473 LayerTreeHostImpl::FrameData* frame_data, |
| 473 DrawResult draw_result) override { | 474 DrawResult draw_result) override { |
| 474 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 475 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 475 RenderSurfaceImpl* root_surface = | 476 RenderSurfaceImpl* root_surface = |
| 476 host_impl->active_tree()->root_layer_for_testing()->GetRenderSurface(); | 477 GetRenderSurface(host_impl->active_tree()->root_layer_for_testing()); |
| 477 gfx::Rect root_damage; | 478 gfx::Rect root_damage; |
| 478 EXPECT_TRUE( | 479 EXPECT_TRUE( |
| 479 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); | 480 root_surface->damage_tracker()->GetDamageRectIfValid(&root_damage)); |
| 480 root_damage.Intersect(root_surface->content_rect()); | 481 root_damage.Intersect(root_surface->content_rect()); |
| 481 int frame = host_impl->active_tree()->source_frame_number(); | 482 int frame = host_impl->active_tree()->source_frame_number(); |
| 482 switch (num_draws_) { | 483 switch (num_draws_) { |
| 483 case 0: | 484 case 0: |
| 484 // The first frame has damage, so we should draw and swap. | 485 // The first frame has damage, so we should draw and swap. |
| 485 EXPECT_EQ(0, frame); | 486 EXPECT_EQ(0, frame); |
| 486 break; | 487 break; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 529 |
| 529 void AfterTest() override { EXPECT_EQ(3, num_draws_); } | 530 void AfterTest() override { EXPECT_EQ(3, num_draws_); } |
| 530 | 531 |
| 531 int num_draws_; | 532 int num_draws_; |
| 532 }; | 533 }; |
| 533 | 534 |
| 534 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); | 535 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); |
| 535 | 536 |
| 536 } // namespace | 537 } // namespace |
| 537 } // namespace cc | 538 } // namespace cc |
| OLD | NEW |