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/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "cc/test/fake_content_layer.h" | 12 #include "cc/layers/solid_color_layer.h" |
13 #include "cc/test/fake_content_layer_client.h" | 13 #include "cc/test/fake_content_layer_client.h" |
14 #include "cc/test/fake_painted_scrollbar_layer.h" | 14 #include "cc/test/fake_painted_scrollbar_layer.h" |
15 #include "cc/test/fake_picture_layer.h" | 15 #include "cc/test/fake_picture_layer.h" |
16 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
17 #include "cc/trees/damage_tracker.h" | 17 #include "cc/trees/damage_tracker.h" |
18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 namespace { | 21 namespace { |
22 | 22 |
23 // These tests deal with damage tracking. | 23 // These tests deal with damage tracking. |
24 class LayerTreeHostDamageTest : public LayerTreeTest {}; | 24 class LayerTreeHostDamageTest : public LayerTreeTest {}; |
25 | 25 |
26 // LayerTreeHost::SetNeedsRedraw should damage the whole viewport. | 26 // LayerTreeHost::SetNeedsRedraw should damage the whole viewport. |
27 class LayerTreeHostDamageTestSetNeedsRedraw | 27 class LayerTreeHostDamageTestSetNeedsRedraw |
28 : public LayerTreeHostDamageTest { | 28 : public LayerTreeHostDamageTest { |
29 void SetupTree() override { | 29 void SetupTree() override { |
30 // Viewport is 10x10. | 30 // Viewport is 10x10. |
31 scoped_refptr<FakeContentLayer> root = | 31 scoped_refptr<FakePictureLayer> root = |
32 FakeContentLayer::Create(layer_settings(), &client_); | 32 FakePictureLayer::Create(layer_settings(), &client_); |
33 root->SetBounds(gfx::Size(10, 10)); | 33 root->SetBounds(gfx::Size(10, 10)); |
34 | 34 |
35 layer_tree_host()->SetRootLayer(root); | 35 layer_tree_host()->SetRootLayer(root); |
36 LayerTreeHostDamageTest::SetupTree(); | 36 LayerTreeHostDamageTest::SetupTree(); |
37 } | 37 } |
38 | 38 |
39 void BeginTest() override { | 39 void BeginTest() override { |
40 draw_count_ = 0; | 40 draw_count_ = 0; |
41 PostSetNeedsCommitToMainThread(); | 41 PostSetNeedsCommitToMainThread(); |
42 } | 42 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 FakeContentLayerClient client_; | 83 FakeContentLayerClient client_; |
84 }; | 84 }; |
85 | 85 |
86 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestSetNeedsRedraw); | 86 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestSetNeedsRedraw); |
87 | 87 |
88 // LayerTreeHost::SetViewportSize should damage the whole viewport. | 88 // LayerTreeHost::SetViewportSize should damage the whole viewport. |
89 class LayerTreeHostDamageTestSetViewportSize | 89 class LayerTreeHostDamageTestSetViewportSize |
90 : public LayerTreeHostDamageTest { | 90 : public LayerTreeHostDamageTest { |
91 void SetupTree() override { | 91 void SetupTree() override { |
92 // Viewport is 10x10. | 92 // Viewport is 10x10. |
93 scoped_refptr<FakeContentLayer> root = | 93 scoped_refptr<FakePictureLayer> root = |
94 FakeContentLayer::Create(layer_settings(), &client_); | 94 FakePictureLayer::Create(layer_settings(), &client_); |
95 root->SetBounds(gfx::Size(10, 10)); | 95 root->SetBounds(gfx::Size(10, 10)); |
96 | 96 |
97 layer_tree_host()->SetRootLayer(root); | 97 layer_tree_host()->SetRootLayer(root); |
98 LayerTreeHostDamageTest::SetupTree(); | 98 LayerTreeHostDamageTest::SetupTree(); |
99 } | 99 } |
100 | 100 |
101 void BeginTest() override { | 101 void BeginTest() override { |
102 draw_count_ = 0; | 102 draw_count_ = 0; |
103 PostSetNeedsCommitToMainThread(); | 103 PostSetNeedsCommitToMainThread(); |
104 } | 104 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 class LayerTreeHostDamageTestNoDamageDoesNotSwap | 150 class LayerTreeHostDamageTestNoDamageDoesNotSwap |
151 : public LayerTreeHostDamageTest { | 151 : public LayerTreeHostDamageTest { |
152 void BeginTest() override { | 152 void BeginTest() override { |
153 expect_swap_and_succeed_ = 0; | 153 expect_swap_and_succeed_ = 0; |
154 did_swaps_ = 0; | 154 did_swaps_ = 0; |
155 did_swap_and_succeed_ = 0; | 155 did_swap_and_succeed_ = 0; |
156 PostSetNeedsCommitToMainThread(); | 156 PostSetNeedsCommitToMainThread(); |
157 } | 157 } |
158 | 158 |
159 void SetupTree() override { | 159 void SetupTree() override { |
160 scoped_refptr<FakeContentLayer> root = | 160 scoped_refptr<FakePictureLayer> root = |
161 FakeContentLayer::Create(layer_settings(), &client_); | 161 FakePictureLayer::Create(layer_settings(), &client_); |
162 root->SetBounds(gfx::Size(10, 10)); | 162 root->SetBounds(gfx::Size(10, 10)); |
163 | 163 |
164 // Most of the layer isn't visible. | 164 // Most of the layer isn't visible. |
165 content_ = FakeContentLayer::Create(layer_settings(), &client_); | 165 content_ = FakePictureLayer::Create(layer_settings(), &client_); |
166 content_->SetBounds(gfx::Size(2000, 100)); | 166 content_->SetBounds(gfx::Size(2000, 100)); |
167 root->AddChild(content_); | 167 root->AddChild(content_); |
168 | 168 |
169 layer_tree_host()->SetRootLayer(root); | 169 layer_tree_host()->SetRootLayer(root); |
170 LayerTreeHostDamageTest::SetupTree(); | 170 LayerTreeHostDamageTest::SetupTree(); |
171 } | 171 } |
172 | 172 |
173 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 173 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
174 LayerTreeHostImpl::FrameData* frame_data, | 174 LayerTreeHostImpl::FrameData* frame_data, |
175 DrawResult draw_result) override { | 175 DrawResult draw_result) override { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 void AfterTest() override { | 226 void AfterTest() override { |
227 EXPECT_EQ(4, did_swaps_); | 227 EXPECT_EQ(4, did_swaps_); |
228 EXPECT_EQ(2, expect_swap_and_succeed_); | 228 EXPECT_EQ(2, expect_swap_and_succeed_); |
229 EXPECT_EQ(expect_swap_and_succeed_, did_swap_and_succeed_); | 229 EXPECT_EQ(expect_swap_and_succeed_, did_swap_and_succeed_); |
230 } | 230 } |
231 | 231 |
232 FakeContentLayerClient client_; | 232 FakeContentLayerClient client_; |
233 scoped_refptr<FakeContentLayer> content_; | 233 scoped_refptr<FakePictureLayer> content_; |
234 int expect_swap_and_succeed_; | 234 int expect_swap_and_succeed_; |
235 int did_swaps_; | 235 int did_swaps_; |
236 int did_swap_and_succeed_; | 236 int did_swap_and_succeed_; |
237 }; | 237 }; |
238 | 238 |
239 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 239 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostDamageTestNoDamageDoesNotSwap); |
240 LayerTreeHostDamageTestNoDamageDoesNotSwap); | |
241 | 240 |
242 class LayerTreeHostDamageTestForcedFullDamage : public LayerTreeHostDamageTest { | 241 class LayerTreeHostDamageTestForcedFullDamage : public LayerTreeHostDamageTest { |
243 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 242 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
244 | 243 |
245 void SetupTree() override { | 244 void SetupTree() override { |
246 root_ = FakeContentLayer::Create(layer_settings(), &client_); | 245 root_ = FakePictureLayer::Create(layer_settings(), &client_); |
247 child_ = FakeContentLayer::Create(layer_settings(), &client_); | 246 child_ = FakePictureLayer::Create(layer_settings(), &client_); |
248 | 247 |
249 root_->SetBounds(gfx::Size(500, 500)); | 248 root_->SetBounds(gfx::Size(500, 500)); |
250 child_->SetPosition(gfx::Point(100, 100)); | 249 child_->SetPosition(gfx::Point(100, 100)); |
251 child_->SetBounds(gfx::Size(30, 30)); | 250 child_->SetBounds(gfx::Size(30, 30)); |
252 | 251 |
253 root_->AddChild(child_); | 252 root_->AddChild(child_); |
254 layer_tree_host()->SetRootLayer(root_); | 253 layer_tree_host()->SetRootLayer(root_); |
255 LayerTreeHostDamageTest::SetupTree(); | 254 LayerTreeHostDamageTest::SetupTree(); |
256 } | 255 } |
257 | 256 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 EXPECT_FALSE(frame_data->has_no_damage); | 288 EXPECT_FALSE(frame_data->has_no_damage); |
290 | 289 |
291 // Just a part of the next frame should be damaged. | 290 // Just a part of the next frame should be damaged. |
292 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); | 291 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); |
293 break; | 292 break; |
294 case 3: | 293 case 3: |
295 // The update rect in the child should be damaged and the damaged area | 294 // The update rect in the child should be damaged and the damaged area |
296 // should match the invalidation. | 295 // should match the invalidation. |
297 EXPECT_EQ(gfx::RectF(100+10, 100+11, 12, 13).ToString(), | 296 EXPECT_EQ(gfx::RectF(100+10, 100+11, 12, 13).ToString(), |
298 root_damage.ToString()); | 297 root_damage.ToString()); |
299 | |
300 // TODO(danakj): Remove this when impl side painting is always on. | |
301 if (delegating_renderer() || | |
302 host_impl->settings().impl_side_painting) { | |
303 // When using a delegating renderer, or using impl side painting, the | |
304 // entire child is considered damaged as we need to replace its | |
305 // resources with newly created ones. The damaged area is kept as it | |
306 // is, but entire child is painted. | |
307 | |
308 // The paint rect should match the layer bounds. | |
309 gfx::RectF paint_rect = child_->LastPaintRect(); | |
enne (OOO)
2015/06/05 22:17:10
Why is this not needed anymore?
danakj
2015/06/05 23:09:08
This is testing a specific change to TiledLayer. h
| |
310 paint_rect.set_origin(child_->position()); | |
311 EXPECT_EQ(gfx::RectF(100, 100, 30, 30).ToString(), | |
312 paint_rect.ToString()); | |
313 } | |
314 EXPECT_FALSE(frame_data->has_no_damage); | 298 EXPECT_FALSE(frame_data->has_no_damage); |
315 | 299 |
316 // If we damage part of the frame, but also damage the full | 300 // If we damage part of the frame, but also damage the full |
317 // frame, then the whole frame should be damaged. | 301 // frame, then the whole frame should be damaged. |
318 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); | 302 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); |
319 host_impl->SetFullRootLayerDamage(); | 303 host_impl->SetFullRootLayerDamage(); |
320 break; | 304 break; |
321 case 4: | 305 case 4: |
322 // The whole frame is damaged. | 306 // The whole frame is damaged. |
323 EXPECT_EQ(gfx::RectF(root_surface->content_rect()).ToString(), | 307 EXPECT_EQ(gfx::RectF(root_surface->content_rect()).ToString(), |
(...skipping 12 matching lines...) Expand all Loading... | |
336 | 320 |
337 if (!child_damage_rect_.IsEmpty()) { | 321 if (!child_damage_rect_.IsEmpty()) { |
338 child_->SetNeedsDisplayRect(child_damage_rect_); | 322 child_->SetNeedsDisplayRect(child_damage_rect_); |
339 child_damage_rect_ = gfx::Rect(); | 323 child_damage_rect_ = gfx::Rect(); |
340 } | 324 } |
341 } | 325 } |
342 | 326 |
343 void AfterTest() override {} | 327 void AfterTest() override {} |
344 | 328 |
345 FakeContentLayerClient client_; | 329 FakeContentLayerClient client_; |
346 scoped_refptr<FakeContentLayer> root_; | 330 scoped_refptr<FakePictureLayer> root_; |
347 scoped_refptr<FakeContentLayer> child_; | 331 scoped_refptr<FakePictureLayer> child_; |
348 gfx::Rect child_damage_rect_; | 332 gfx::Rect child_damage_rect_; |
349 }; | 333 }; |
350 | 334 |
351 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostDamageTestForcedFullDamage); | 335 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostDamageTestForcedFullDamage); |
352 | 336 |
353 class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { | 337 class LayerTreeHostScrollbarDamageTest : public LayerTreeHostDamageTest { |
354 void SetupTree() override { | 338 void SetupTree() override { |
355 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); | 339 scoped_refptr<Layer> root_layer = Layer::Create(layer_settings()); |
356 root_layer->SetBounds(gfx::Size(400, 400)); | 340 root_layer->SetBounds(gfx::Size(400, 400)); |
357 root_layer->SetMasksToBounds(true); | 341 root_layer->SetMasksToBounds(true); |
358 layer_tree_host()->SetRootLayer(root_layer); | 342 layer_tree_host()->SetRootLayer(root_layer); |
359 | 343 |
360 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(layer_settings()); | 344 scoped_refptr<Layer> scroll_clip_layer = Layer::Create(layer_settings()); |
361 scoped_refptr<Layer> content_layer = | 345 scoped_refptr<Layer> content_layer = |
362 FakeContentLayer::Create(layer_settings(), &client_); | 346 FakePictureLayer::Create(layer_settings(), &client_); |
363 content_layer->SetScrollClipLayerId(scroll_clip_layer->id()); | 347 content_layer->SetScrollClipLayerId(scroll_clip_layer->id()); |
364 content_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 348 content_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
365 content_layer->SetBounds(gfx::Size(100, 200)); | 349 content_layer->SetBounds(gfx::Size(100, 200)); |
350 content_layer->SetIsDrawable(true); | |
366 scroll_clip_layer->SetBounds( | 351 scroll_clip_layer->SetBounds( |
367 gfx::Size(content_layer->bounds().width() - 30, | 352 gfx::Size(content_layer->bounds().width() - 30, |
368 content_layer->bounds().height() - 50)); | 353 content_layer->bounds().height() - 50)); |
369 scroll_clip_layer->AddChild(content_layer); | 354 scroll_clip_layer->AddChild(content_layer); |
370 root_layer->AddChild(scroll_clip_layer); | 355 root_layer->AddChild(scroll_clip_layer); |
371 | 356 |
372 scoped_refptr<Layer> scrollbar_layer = FakePaintedScrollbarLayer::Create( | 357 scoped_refptr<Layer> scrollbar_layer = FakePaintedScrollbarLayer::Create( |
373 layer_settings(), false, true, content_layer->id()); | 358 layer_settings(), false, true, content_layer->id()); |
374 scrollbar_layer->SetPosition(gfx::Point(300, 300)); | 359 scrollbar_layer->SetPosition(gfx::Point(300, 300)); |
375 scrollbar_layer->SetBounds(gfx::Size(10, 100)); | 360 scrollbar_layer->SetBounds(gfx::Size(10, 100)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 scroll_layer->SetPosition(gfx::Point(1, 1)); | 425 scroll_layer->SetPosition(gfx::Point(1, 1)); |
441 scroll_layer->PushScrollOffsetFromMainThread( | 426 scroll_layer->PushScrollOffsetFromMainThread( |
442 scroll_layer->BaseScrollOffset()); | 427 scroll_layer->BaseScrollOffset()); |
443 host_impl->SetNeedsRedraw(); | 428 host_impl->SetNeedsRedraw(); |
444 break; | 429 break; |
445 case 2: | 430 case 2: |
446 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); | 431 scroll_layer->ScrollBy(gfx::Vector2dF(10.f, 10.f)); |
447 host_impl->SetNeedsRedraw(); | 432 host_impl->SetNeedsRedraw(); |
448 break; | 433 break; |
449 case 3: | 434 case 3: |
450 scroll_layer->SetBounds(gfx::Size(root->bounds().width() + 60, | 435 // We will resize the content layer, on the main thread. |
451 root->bounds().height() + 100)); | 436 MainThreadTaskRunner()->PostTask( |
452 host_impl->SetNeedsRedraw(); | 437 FROM_HERE, |
438 base::Bind( | |
439 &LayerTreeHostDamageTestScrollbarDoesDamage::ResizeScrollLayer, | |
440 base::Unretained(this))); | |
453 break; | 441 break; |
454 } | 442 } |
455 } | 443 } |
456 | 444 |
445 void ResizeScrollLayer() { | |
446 EXPECT_EQ(3, did_swaps_); | |
447 Layer* root = layer_tree_host()->root_layer(); | |
448 Layer* scroll_clip_layer = root->child_at(0); | |
449 Layer* scroll_layer = scroll_clip_layer->child_at(0); | |
450 scroll_layer->SetBounds( | |
451 gfx::Size(root->bounds().width() + 60, root->bounds().height() + 100)); | |
452 } | |
453 | |
457 void AfterTest() override { EXPECT_EQ(4, did_swaps_); } | 454 void AfterTest() override { EXPECT_EQ(4, did_swaps_); } |
458 | 455 |
459 int did_swaps_; | 456 int did_swaps_; |
460 }; | 457 }; |
461 | 458 |
462 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); | 459 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
463 | 460 |
464 class LayerTreeHostDamageTestScrollbarCommitDoesNoDamage | 461 class LayerTreeHostDamageTestScrollbarCommitDoesNoDamage |
465 : public LayerTreeHostScrollbarDamageTest { | 462 : public LayerTreeHostScrollbarDamageTest { |
466 void BeginTest() override { | 463 void BeginTest() override { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 | 526 |
530 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } | 527 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } |
531 | 528 |
532 int did_swaps_; | 529 int did_swaps_; |
533 }; | 530 }; |
534 | 531 |
535 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); | 532 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); |
536 | 533 |
537 } // namespace | 534 } // namespace |
538 } // namespace cc | 535 } // namespace cc |
OLD | NEW |