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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 virtual void DidCommitAndDrawFrame() OVERRIDE { | 43 virtual void DidCommitAndDrawFrame() OVERRIDE { |
44 switch (layer_tree_host()->source_frame_number()) { | 44 switch (layer_tree_host()->source_frame_number()) { |
45 case 1: | 45 case 1: |
46 layer_tree_host()->SetNeedsRedraw(); | 46 layer_tree_host()->SetNeedsRedraw(); |
47 break; | 47 break; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 51 virtual DrawResult PrepareToDrawOnThread( |
52 LayerTreeHostImpl* impl, | 52 LayerTreeHostImpl* impl, |
53 LayerTreeHostImpl::FrameData* frame_data, | 53 LayerTreeHostImpl::FrameData* frame_data, |
54 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 54 DrawResult draw_result) OVERRIDE { |
55 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 55 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
56 | 56 |
57 RenderSurfaceImpl* root_surface = | 57 RenderSurfaceImpl* root_surface = |
58 impl->active_tree()->root_layer()->render_surface(); | 58 impl->active_tree()->root_layer()->render_surface(); |
59 gfx::RectF root_damage = | 59 gfx::RectF root_damage = |
60 root_surface->damage_tracker()->current_damage_rect(); | 60 root_surface->damage_tracker()->current_damage_rect(); |
61 | 61 |
62 switch (draw_count_) { | 62 switch (draw_count_) { |
63 case 0: | 63 case 0: |
64 // The first frame has full damage. | 64 // The first frame has full damage. |
65 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); | 65 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 virtual void DidCommitAndDrawFrame() OVERRIDE { | 105 virtual 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_host()->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 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 113 virtual DrawResult PrepareToDrawOnThread( |
114 LayerTreeHostImpl* impl, | 114 LayerTreeHostImpl* impl, |
115 LayerTreeHostImpl::FrameData* frame_data, | 115 LayerTreeHostImpl::FrameData* frame_data, |
116 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 116 DrawResult draw_result) OVERRIDE { |
117 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 117 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
118 | 118 |
119 RenderSurfaceImpl* root_surface = | 119 RenderSurfaceImpl* root_surface = |
120 impl->active_tree()->root_layer()->render_surface(); | 120 impl->active_tree()->root_layer()->render_surface(); |
121 gfx::RectF root_damage = | 121 gfx::RectF root_damage = |
122 root_surface->damage_tracker()->current_damage_rect(); | 122 root_surface->damage_tracker()->current_damage_rect(); |
123 | 123 |
124 switch (draw_count_) { | 124 switch (draw_count_) { |
125 case 0: | 125 case 0: |
126 // The first frame has full damage. | 126 // The first frame has full damage. |
127 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); | 127 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 // Most of the layer isn't visible. | 163 // Most of the layer isn't visible. |
164 content_ = FakeContentLayer::Create(&client_); | 164 content_ = FakeContentLayer::Create(&client_); |
165 content_->SetBounds(gfx::Size(2000, 100)); | 165 content_->SetBounds(gfx::Size(2000, 100)); |
166 root->AddChild(content_); | 166 root->AddChild(content_); |
167 | 167 |
168 layer_tree_host()->SetRootLayer(root); | 168 layer_tree_host()->SetRootLayer(root); |
169 LayerTreeHostDamageTest::SetupTree(); | 169 LayerTreeHostDamageTest::SetupTree(); |
170 } | 170 } |
171 | 171 |
172 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 172 virtual DrawResult PrepareToDrawOnThread( |
173 LayerTreeHostImpl* host_impl, | 173 LayerTreeHostImpl* host_impl, |
174 LayerTreeHostImpl::FrameData* frame_data, | 174 LayerTreeHostImpl::FrameData* frame_data, |
175 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 175 DrawResult draw_result) OVERRIDE { |
176 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 176 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
177 | 177 |
178 int source_frame = host_impl->active_tree()->source_frame_number(); | 178 int source_frame = host_impl->active_tree()->source_frame_number(); |
179 switch (source_frame) { | 179 switch (source_frame) { |
180 case 0: | 180 case 0: |
181 // The first frame has damage, so we should draw and swap. | 181 // The first frame has damage, so we should draw and swap. |
182 ++expect_swap_and_succeed_; | 182 ++expect_swap_and_succeed_; |
183 break; | 183 break; |
184 case 1: | 184 case 1: |
185 // The second frame has no damage, so we should not draw and swap. | 185 // The second frame has no damage, so we should not draw and swap. |
186 break; | 186 break; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 // Most of the layer isn't visible. | 253 // Most of the layer isn't visible. |
254 content_ = FakeContentLayer::Create(&client_); | 254 content_ = FakeContentLayer::Create(&client_); |
255 content_->SetBounds(gfx::Size(100, 100)); | 255 content_->SetBounds(gfx::Size(100, 100)); |
256 root->AddChild(content_); | 256 root->AddChild(content_); |
257 | 257 |
258 layer_tree_host()->SetRootLayer(root); | 258 layer_tree_host()->SetRootLayer(root); |
259 LayerTreeHostDamageTest::SetupTree(); | 259 LayerTreeHostDamageTest::SetupTree(); |
260 } | 260 } |
261 | 261 |
262 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 262 virtual DrawResult PrepareToDrawOnThread( |
263 LayerTreeHostImpl* host_impl, | 263 LayerTreeHostImpl* host_impl, |
264 LayerTreeHostImpl::FrameData* frame_data, | 264 LayerTreeHostImpl::FrameData* frame_data, |
265 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 265 DrawResult draw_result) OVERRIDE { |
266 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 266 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
267 | 267 |
268 int source_frame = host_impl->active_tree()->source_frame_number(); | 268 int source_frame = host_impl->active_tree()->source_frame_number(); |
269 switch (source_frame) { | 269 switch (source_frame) { |
270 case 0: | 270 case 0: |
271 // The first frame draws and clears any damage. | 271 // The first frame draws and clears any damage. |
272 break; | 272 break; |
273 case 1: { | 273 case 1: { |
274 // The second frame is a readback, we should have damage in the readback | 274 // The second frame is a readback, we should have damage in the readback |
275 // rect, but not swap. | 275 // rect, but not swap. |
276 RenderSurfaceImpl* root_surface = | 276 RenderSurfaceImpl* root_surface = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 323 |
324 root_->SetBounds(gfx::Size(500, 500)); | 324 root_->SetBounds(gfx::Size(500, 500)); |
325 child_->SetPosition(gfx::Point(100, 100)); | 325 child_->SetPosition(gfx::Point(100, 100)); |
326 child_->SetBounds(gfx::Size(30, 30)); | 326 child_->SetBounds(gfx::Size(30, 30)); |
327 | 327 |
328 root_->AddChild(child_); | 328 root_->AddChild(child_); |
329 layer_tree_host()->SetRootLayer(root_); | 329 layer_tree_host()->SetRootLayer(root_); |
330 LayerTreeHostDamageTest::SetupTree(); | 330 LayerTreeHostDamageTest::SetupTree(); |
331 } | 331 } |
332 | 332 |
333 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 333 virtual DrawResult PrepareToDrawOnThread( |
334 LayerTreeHostImpl* host_impl, | 334 LayerTreeHostImpl* host_impl, |
335 LayerTreeHostImpl::FrameData* frame_data, | 335 LayerTreeHostImpl::FrameData* frame_data, |
336 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 336 DrawResult draw_result) OVERRIDE { |
337 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 337 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
338 | 338 |
339 RenderSurfaceImpl* root_surface = | 339 RenderSurfaceImpl* root_surface = |
340 host_impl->active_tree()->root_layer()->render_surface(); | 340 host_impl->active_tree()->root_layer()->render_surface(); |
341 gfx::RectF root_damage = | 341 gfx::RectF root_damage = |
342 root_surface->damage_tracker()->current_damage_rect(); | 342 root_surface->damage_tracker()->current_damage_rect(); |
343 root_damage.Intersect(root_surface->content_rect()); | 343 root_damage.Intersect(root_surface->content_rect()); |
344 | 344 |
345 int source_frame = host_impl->active_tree()->source_frame_number(); | 345 int source_frame = host_impl->active_tree()->source_frame_number(); |
346 switch (source_frame) { | 346 switch (source_frame) { |
347 case 0: | 347 case 0: |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 FakeContentLayerClient client_; | 465 FakeContentLayerClient client_; |
466 }; | 466 }; |
467 | 467 |
468 class LayerTreeHostDamageTestScrollbarDoesDamage | 468 class LayerTreeHostDamageTestScrollbarDoesDamage |
469 : public LayerTreeHostScrollbarDamageTest { | 469 : public LayerTreeHostScrollbarDamageTest { |
470 virtual void BeginTest() OVERRIDE { | 470 virtual void BeginTest() OVERRIDE { |
471 did_swaps_ = 0; | 471 did_swaps_ = 0; |
472 PostSetNeedsCommitToMainThread(); | 472 PostSetNeedsCommitToMainThread(); |
473 } | 473 } |
474 | 474 |
475 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 475 virtual DrawResult PrepareToDrawOnThread( |
476 LayerTreeHostImpl* host_impl, | 476 LayerTreeHostImpl* host_impl, |
477 LayerTreeHostImpl::FrameData* frame_data, | 477 LayerTreeHostImpl::FrameData* frame_data, |
478 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 478 DrawResult draw_result) OVERRIDE { |
479 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 479 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
480 RenderSurfaceImpl* root_surface = | 480 RenderSurfaceImpl* root_surface = |
481 host_impl->active_tree()->root_layer()->render_surface(); | 481 host_impl->active_tree()->root_layer()->render_surface(); |
482 gfx::RectF root_damage = | 482 gfx::RectF root_damage = |
483 root_surface->damage_tracker()->current_damage_rect(); | 483 root_surface->damage_tracker()->current_damage_rect(); |
484 root_damage.Intersect(root_surface->content_rect()); | 484 root_damage.Intersect(root_surface->content_rect()); |
485 switch (did_swaps_) { | 485 switch (did_swaps_) { |
486 case 0: | 486 case 0: |
487 // The first frame has damage, so we should draw and swap. | 487 // The first frame has damage, so we should draw and swap. |
488 break; | 488 break; |
489 case 1: | 489 case 1: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 539 |
540 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); | 540 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
541 | 541 |
542 class LayerTreeHostDamageTestScrollbarCommitDoesNoDamage | 542 class LayerTreeHostDamageTestScrollbarCommitDoesNoDamage |
543 : public LayerTreeHostScrollbarDamageTest { | 543 : public LayerTreeHostScrollbarDamageTest { |
544 virtual void BeginTest() OVERRIDE { | 544 virtual void BeginTest() OVERRIDE { |
545 did_swaps_ = 0; | 545 did_swaps_ = 0; |
546 PostSetNeedsCommitToMainThread(); | 546 PostSetNeedsCommitToMainThread(); |
547 } | 547 } |
548 | 548 |
549 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 549 virtual DrawResult PrepareToDrawOnThread( |
550 LayerTreeHostImpl* host_impl, | 550 LayerTreeHostImpl* host_impl, |
551 LayerTreeHostImpl::FrameData* frame_data, | 551 LayerTreeHostImpl::FrameData* frame_data, |
552 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 552 DrawResult draw_result) OVERRIDE { |
553 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 553 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
554 RenderSurfaceImpl* root_surface = | 554 RenderSurfaceImpl* root_surface = |
555 host_impl->active_tree()->root_layer()->render_surface(); | 555 host_impl->active_tree()->root_layer()->render_surface(); |
556 gfx::RectF root_damage = | 556 gfx::RectF root_damage = |
557 root_surface->damage_tracker()->current_damage_rect(); | 557 root_surface->damage_tracker()->current_damage_rect(); |
558 root_damage.Intersect(root_surface->content_rect()); | 558 root_damage.Intersect(root_surface->content_rect()); |
559 int frame = host_impl->active_tree()->source_frame_number(); | 559 int frame = host_impl->active_tree()->source_frame_number(); |
560 switch (did_swaps_) { | 560 switch (did_swaps_) { |
561 case 0: | 561 case 0: |
562 // The first frame has damage, so we should draw and swap. | 562 // The first frame has damage, so we should draw and swap. |
563 EXPECT_EQ(0, frame); | 563 EXPECT_EQ(0, frame); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); | 631 scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_); |
632 root->SetBounds(gfx::Size(500, 500)); | 632 root->SetBounds(gfx::Size(500, 500)); |
633 layer_tree_host()->SetRootLayer(root); | 633 layer_tree_host()->SetRootLayer(root); |
634 LayerTreeHostDamageTest::SetupTree(); | 634 LayerTreeHostDamageTest::SetupTree(); |
635 | 635 |
636 swap_count_ = 0; | 636 swap_count_ = 0; |
637 prepare_to_draw_count_ = 0; | 637 prepare_to_draw_count_ = 0; |
638 update_visible_tile_count_ = 0; | 638 update_visible_tile_count_ = 0; |
639 } | 639 } |
640 | 640 |
641 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 641 virtual DrawResult PrepareToDrawOnThread( |
642 LayerTreeHostImpl* host_impl, | 642 LayerTreeHostImpl* host_impl, |
643 LayerTreeHostImpl::FrameData* frame_data, | 643 LayerTreeHostImpl::FrameData* frame_data, |
644 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 644 DrawResult draw_result) OVERRIDE { |
645 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 645 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
646 prepare_to_draw_count_++; | 646 prepare_to_draw_count_++; |
647 switch (prepare_to_draw_count_) { | 647 switch (prepare_to_draw_count_) { |
648 case 1: | 648 case 1: |
649 // Detect that we have an incomplete tile, during the first frame. | 649 // Detect that we have an incomplete tile, during the first frame. |
650 // The first frame should have damage. | 650 // The first frame should have damage. |
651 frame_data->contains_incomplete_tile = true; | 651 frame_data->contains_incomplete_tile = true; |
652 DCHECK(!frame_data->has_no_damage); | 652 DCHECK(!frame_data->has_no_damage); |
653 break; | 653 break; |
654 case 2: | 654 case 2: |
655 // Make a no-damage frame. We early out and can't detect | 655 // Make a no-damage frame. We early out and can't detect |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 FakeContentLayerClient client_; | 709 FakeContentLayerClient client_; |
710 int swap_count_; | 710 int swap_count_; |
711 int prepare_to_draw_count_; | 711 int prepare_to_draw_count_; |
712 int update_visible_tile_count_; | 712 int update_visible_tile_count_; |
713 }; | 713 }; |
714 | 714 |
715 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestVisibleTilesStillTriggerDraws); | 715 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestVisibleTilesStillTriggerDraws); |
716 | 716 |
717 } // namespace | 717 } // namespace |
718 } // namespace cc | 718 } // namespace cc |
OLD | NEW |