| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class LayerTreeHostDamageTest : public LayerTreeTest {}; | 23 class LayerTreeHostDamageTest : public LayerTreeTest {}; |
| 24 | 24 |
| 25 // LayerTreeHost::SetNeedsRedraw should damage the whole viewport. | 25 // LayerTreeHost::SetNeedsRedraw should damage the whole viewport. |
| 26 class LayerTreeHostDamageTestSetNeedsRedraw | 26 class LayerTreeHostDamageTestSetNeedsRedraw |
| 27 : public LayerTreeHostDamageTest { | 27 : public LayerTreeHostDamageTest { |
| 28 void SetupTree() override { | 28 void SetupTree() override { |
| 29 // Viewport is 10x10. | 29 // Viewport is 10x10. |
| 30 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); | 30 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); |
| 31 root->SetBounds(gfx::Size(10, 10)); | 31 root->SetBounds(gfx::Size(10, 10)); |
| 32 | 32 |
| 33 layer_tree()->SetRootLayer(root); | 33 layer_tree_host()->SetRootLayer(root); |
| 34 LayerTreeHostDamageTest::SetupTree(); | 34 LayerTreeHostDamageTest::SetupTree(); |
| 35 client_.set_bounds(root->bounds()); | 35 client_.set_bounds(root->bounds()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void BeginTest() override { | 38 void BeginTest() override { |
| 39 draw_count_ = 0; | 39 draw_count_ = 0; |
| 40 PostSetNeedsCommitToMainThread(); | 40 PostSetNeedsCommitToMainThread(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void DidCommitAndDrawFrame() override { | 43 void DidCommitAndDrawFrame() override { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestSetNeedsRedraw); | 85 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestSetNeedsRedraw); |
| 86 | 86 |
| 87 // LayerTreeHost::SetViewportSize should damage the whole viewport. | 87 // LayerTreeHost::SetViewportSize should damage the whole viewport. |
| 88 class LayerTreeHostDamageTestSetViewportSize | 88 class LayerTreeHostDamageTestSetViewportSize |
| 89 : public LayerTreeHostDamageTest { | 89 : public LayerTreeHostDamageTest { |
| 90 void SetupTree() override { | 90 void SetupTree() override { |
| 91 // Viewport is 10x10. | 91 // Viewport is 10x10. |
| 92 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); | 92 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); |
| 93 root->SetBounds(gfx::Size(10, 10)); | 93 root->SetBounds(gfx::Size(10, 10)); |
| 94 | 94 |
| 95 layer_tree()->SetRootLayer(root); | 95 layer_tree_host()->SetRootLayer(root); |
| 96 LayerTreeHostDamageTest::SetupTree(); | 96 LayerTreeHostDamageTest::SetupTree(); |
| 97 client_.set_bounds(root->bounds()); | 97 client_.set_bounds(root->bounds()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void BeginTest() override { | 100 void BeginTest() override { |
| 101 draw_count_ = 0; | 101 draw_count_ = 0; |
| 102 PostSetNeedsCommitToMainThread(); | 102 PostSetNeedsCommitToMainThread(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void DidCommitAndDrawFrame() override { | 105 void DidCommitAndDrawFrame() override { |
| 106 switch (layer_tree_host()->source_frame_number()) { | 106 switch (layer_tree_host()->source_frame_number()) { |
| 107 case 1: | 107 case 1: |
| 108 layer_tree()->SetViewportSize(gfx::Size(15, 15)); | 108 layer_tree_host()->SetViewportSize(gfx::Size(15, 15)); |
| 109 break; | 109 break; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, | 113 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, |
| 114 LayerTreeHostImpl::FrameData* frame_data, | 114 LayerTreeHostImpl::FrameData* frame_data, |
| 115 DrawResult draw_result) override { | 115 DrawResult draw_result) override { |
| 116 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 116 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 117 | 117 |
| 118 RenderSurfaceImpl* root_surface = | 118 RenderSurfaceImpl* root_surface = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 void SetupTree() override { | 155 void SetupTree() override { |
| 156 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); | 156 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); |
| 157 root->SetBounds(gfx::Size(10, 10)); | 157 root->SetBounds(gfx::Size(10, 10)); |
| 158 | 158 |
| 159 // Most of the layer isn't visible. | 159 // Most of the layer isn't visible. |
| 160 content_ = FakePictureLayer::Create(&client_); | 160 content_ = FakePictureLayer::Create(&client_); |
| 161 content_->SetBounds(gfx::Size(2000, 100)); | 161 content_->SetBounds(gfx::Size(2000, 100)); |
| 162 root->AddChild(content_); | 162 root->AddChild(content_); |
| 163 | 163 |
| 164 layer_tree()->SetRootLayer(root); | 164 layer_tree_host()->SetRootLayer(root); |
| 165 LayerTreeHostDamageTest::SetupTree(); | 165 LayerTreeHostDamageTest::SetupTree(); |
| 166 client_.set_bounds(root->bounds()); | 166 client_.set_bounds(root->bounds()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 169 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 170 LayerTreeHostImpl::FrameData* frame_data, | 170 LayerTreeHostImpl::FrameData* frame_data, |
| 171 DrawResult draw_result) override { | 171 DrawResult draw_result) override { |
| 172 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 172 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 173 | 173 |
| 174 int source_frame = host_impl->active_tree()->source_frame_number(); | 174 int source_frame = host_impl->active_tree()->source_frame_number(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 204 | 204 |
| 205 void DidCommit() override { | 205 void DidCommit() override { |
| 206 int next_frame = layer_tree_host()->source_frame_number(); | 206 int next_frame = layer_tree_host()->source_frame_number(); |
| 207 switch (next_frame) { | 207 switch (next_frame) { |
| 208 case 1: | 208 case 1: |
| 209 layer_tree_host()->SetNeedsCommit(); | 209 layer_tree_host()->SetNeedsCommit(); |
| 210 break; | 210 break; |
| 211 case 2: | 211 case 2: |
| 212 // Cause visible damage. | 212 // Cause visible damage. |
| 213 content_->SetNeedsDisplayRect( | 213 content_->SetNeedsDisplayRect( |
| 214 gfx::Rect(layer_tree()->device_viewport_size())); | 214 gfx::Rect(layer_tree_host()->device_viewport_size())); |
| 215 break; | 215 break; |
| 216 case 3: | 216 case 3: |
| 217 // Cause non-visible damage. | 217 // Cause non-visible damage. |
| 218 content_->SetNeedsDisplayRect(gfx::Rect(1990, 1990, 10, 10)); | 218 content_->SetNeedsDisplayRect(gfx::Rect(1990, 1990, 10, 10)); |
| 219 layer_tree_host()->SetNeedsCommit(); | 219 layer_tree_host()->SetNeedsCommit(); |
| 220 break; | 220 break; |
| 221 } | 221 } |
| 222 } | 222 } |
| 223 | 223 |
| 224 void AfterTest() override { | 224 void AfterTest() override { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 239 | 239 |
| 240 void SetupTree() override { | 240 void SetupTree() override { |
| 241 root_ = FakePictureLayer::Create(&client_); | 241 root_ = FakePictureLayer::Create(&client_); |
| 242 child_ = FakePictureLayer::Create(&client_); | 242 child_ = FakePictureLayer::Create(&client_); |
| 243 | 243 |
| 244 root_->SetBounds(gfx::Size(500, 500)); | 244 root_->SetBounds(gfx::Size(500, 500)); |
| 245 child_->SetPosition(gfx::PointF(100.f, 100.f)); | 245 child_->SetPosition(gfx::PointF(100.f, 100.f)); |
| 246 child_->SetBounds(gfx::Size(30, 30)); | 246 child_->SetBounds(gfx::Size(30, 30)); |
| 247 | 247 |
| 248 root_->AddChild(child_); | 248 root_->AddChild(child_); |
| 249 layer_tree()->SetRootLayer(root_); | 249 layer_tree_host()->SetRootLayer(root_); |
| 250 LayerTreeHostDamageTest::SetupTree(); | 250 LayerTreeHostDamageTest::SetupTree(); |
| 251 client_.set_bounds(root_->bounds()); | 251 client_.set_bounds(root_->bounds()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 254 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 255 LayerTreeHostImpl::FrameData* frame_data, | 255 LayerTreeHostImpl::FrameData* frame_data, |
| 256 DrawResult draw_result) override { | 256 DrawResult draw_result) override { |
| 257 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 257 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 258 | 258 |
| 259 RenderSurfaceImpl* root_surface = | 259 RenderSurfaceImpl* root_surface = |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 gfx::Rect child_damage_rect_; | 325 gfx::Rect child_damage_rect_; |
| 326 }; | 326 }; |
| 327 | 327 |
| 328 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage); | 328 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage); |
| 329 | 329 |
| 330 class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { | 330 class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { |
| 331 void SetupTree() override { | 331 void SetupTree() override { |
| 332 scoped_refptr<Layer> root_layer = Layer::Create(); | 332 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 333 root_layer->SetBounds(gfx::Size(400, 400)); | 333 root_layer->SetBounds(gfx::Size(400, 400)); |
| 334 root_layer->SetMasksToBounds(true); | 334 root_layer->SetMasksToBounds(true); |
| 335 layer_tree()->SetRootLayer(root_layer); | 335 layer_tree_host()->SetRootLayer(root_layer); |
| 336 | 336 |
| 337 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); | 337 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(); |
| 338 content_layer_ = FakePictureLayer::Create(&client_); | 338 content_layer_ = FakePictureLayer::Create(&client_); |
| 339 content_layer_->SetScrollClipLayerId(scroll_clip_layer->id()); | 339 content_layer_->SetScrollClipLayerId(scroll_clip_layer->id()); |
| 340 content_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 340 content_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 341 content_layer_->SetBounds(gfx::Size(100, 200)); | 341 content_layer_->SetBounds(gfx::Size(100, 200)); |
| 342 content_layer_->SetIsDrawable(true); | 342 content_layer_->SetIsDrawable(true); |
| 343 scroll_clip_layer->SetBounds( | 343 scroll_clip_layer->SetBounds( |
| 344 gfx::Size(content_layer_->bounds().width() - 30, | 344 gfx::Size(content_layer_->bounds().width() - 30, |
| 345 content_layer_->bounds().height() - 50)); | 345 content_layer_->bounds().height() - 50)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 | 437 |
| 438 void ModifyContentLayerPosition() { | 438 void ModifyContentLayerPosition() { |
| 439 EXPECT_EQ(1, num_draws_); | 439 EXPECT_EQ(1, num_draws_); |
| 440 content_layer_->SetPosition(gfx::PointF(10.f, 10.f)); | 440 content_layer_->SetPosition(gfx::PointF(10.f, 10.f)); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void ResizeScrollLayer() { | 443 void ResizeScrollLayer() { |
| 444 EXPECT_EQ(3, num_draws_); | 444 EXPECT_EQ(3, num_draws_); |
| 445 Layer* root = layer_tree()->root_layer(); | 445 Layer* root = layer_tree_host()->root_layer(); |
| 446 content_layer_->SetBounds( | 446 content_layer_->SetBounds( |
| 447 gfx::Size(root->bounds().width() + 60, root->bounds().height() + 100)); | 447 gfx::Size(root->bounds().width() + 60, root->bounds().height() + 100)); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void AfterTest() override { EXPECT_EQ(4, num_draws_); } | 450 void AfterTest() override { EXPECT_EQ(4, num_draws_); } |
| 451 | 451 |
| 452 int num_draws_; | 452 int num_draws_; |
| 453 }; | 453 }; |
| 454 | 454 |
| 455 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); | 455 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 520 |
| 521 void AfterTest() override { EXPECT_EQ(3, num_draws_); } | 521 void AfterTest() override { EXPECT_EQ(3, num_draws_); } |
| 522 | 522 |
| 523 int num_draws_; | 523 int num_draws_; |
| 524 }; | 524 }; |
| 525 | 525 |
| 526 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); | 526 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); |
| 527 | 527 |
| 528 } // namespace | 528 } // namespace |
| 529 } // namespace cc | 529 } // namespace cc |
| OLD | NEW |