| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, | 51 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl, |
| 52 LayerTreeHostImpl::FrameData* frame_data, | 52 LayerTreeHostImpl::FrameData* frame_data, |
| 53 DrawResult draw_result) override { | 53 DrawResult draw_result) override { |
| 54 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 54 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 55 | 55 |
| 56 RenderSurfaceImpl* root_surface = | 56 RenderSurfaceImpl* root_surface = |
| 57 impl->active_tree()->root_layer()->render_surface(); | 57 impl->active_tree()->root_layer()->render_surface(); |
| 58 gfx::RectF root_damage = | 58 gfx::Rect root_damage = |
| 59 root_surface->damage_tracker()->current_damage_rect(); | 59 root_surface->damage_tracker()->current_damage_rect(); |
| 60 | 60 |
| 61 switch (draw_count_) { | 61 switch (draw_count_) { |
| 62 case 0: | 62 case 0: |
| 63 // The first frame has full damage. | 63 // The first frame has full damage. |
| 64 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); | 64 EXPECT_EQ(gfx::Rect(10, 10), root_damage); |
| 65 break; | 65 break; |
| 66 case 1: | 66 case 1: |
| 67 // The second frame has full damage. | 67 // The second frame has full damage. |
| 68 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); | 68 EXPECT_EQ(gfx::Rect(10, 10), root_damage); |
| 69 EndTest(); | 69 EndTest(); |
| 70 break; | 70 break; |
| 71 case 2: | 71 case 2: |
| 72 NOTREACHED(); | 72 NOTREACHED(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 ++draw_count_; | 75 ++draw_count_; |
| 76 return draw_result; | 76 return draw_result; |
| 77 } | 77 } |
| 78 | 78 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = |
| 119 impl->active_tree()->root_layer()->render_surface(); | 119 impl->active_tree()->root_layer()->render_surface(); |
| 120 gfx::RectF root_damage = | 120 gfx::Rect root_damage = |
| 121 root_surface->damage_tracker()->current_damage_rect(); | 121 root_surface->damage_tracker()->current_damage_rect(); |
| 122 | 122 |
| 123 switch (draw_count_) { | 123 switch (draw_count_) { |
| 124 case 0: | 124 case 0: |
| 125 // The first frame has full damage. | 125 // The first frame has full damage. |
| 126 EXPECT_EQ(gfx::RectF(10.f, 10.f).ToString(), root_damage.ToString()); | 126 EXPECT_EQ(gfx::Rect(10, 10), root_damage); |
| 127 break; | 127 break; |
| 128 case 1: | 128 case 1: |
| 129 // The second frame has full damage. | 129 // The second frame has full damage. |
| 130 EXPECT_EQ(gfx::RectF(15.f, 15.f).ToString(), root_damage.ToString()); | 130 EXPECT_EQ(gfx::Rect(15, 15), root_damage); |
| 131 EndTest(); | 131 EndTest(); |
| 132 break; | 132 break; |
| 133 case 2: | 133 case 2: |
| 134 NOTREACHED(); | 134 NOTREACHED(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 ++draw_count_; | 137 ++draw_count_; |
| 138 return draw_result; | 138 return draw_result; |
| 139 } | 139 } |
| 140 | 140 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 LayerTreeHostDamageTest::SetupTree(); | 253 LayerTreeHostDamageTest::SetupTree(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 256 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 257 LayerTreeHostImpl::FrameData* frame_data, | 257 LayerTreeHostImpl::FrameData* frame_data, |
| 258 DrawResult draw_result) override { | 258 DrawResult draw_result) override { |
| 259 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 259 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 260 | 260 |
| 261 RenderSurfaceImpl* root_surface = | 261 RenderSurfaceImpl* root_surface = |
| 262 host_impl->active_tree()->root_layer()->render_surface(); | 262 host_impl->active_tree()->root_layer()->render_surface(); |
| 263 gfx::RectF root_damage = | 263 gfx::Rect root_damage = |
| 264 root_surface->damage_tracker()->current_damage_rect(); | 264 root_surface->damage_tracker()->current_damage_rect(); |
| 265 root_damage.Intersect(root_surface->content_rect()); | 265 root_damage.Intersect(root_surface->content_rect()); |
| 266 | 266 |
| 267 int source_frame = host_impl->active_tree()->source_frame_number(); | 267 int source_frame = host_impl->active_tree()->source_frame_number(); |
| 268 switch (source_frame) { | 268 switch (source_frame) { |
| 269 case 0: | 269 case 0: |
| 270 // The first frame draws and clears any damage. | 270 // The first frame draws and clears any damage. |
| 271 EXPECT_EQ(gfx::RectF(root_surface->content_rect()).ToString(), | 271 EXPECT_EQ(root_surface->content_rect(), root_damage); |
| 272 root_damage.ToString()); | |
| 273 EXPECT_FALSE(frame_data->has_no_damage); | 272 EXPECT_FALSE(frame_data->has_no_damage); |
| 274 break; | 273 break; |
| 275 case 1: | 274 case 1: |
| 276 // If we get a frame without damage then we don't draw. | 275 // If we get a frame without damage then we don't draw. |
| 277 EXPECT_EQ(gfx::RectF().ToString(), root_damage.ToString()); | 276 EXPECT_EQ(gfx::Rect(), root_damage); |
| 278 EXPECT_TRUE(frame_data->has_no_damage); | 277 EXPECT_TRUE(frame_data->has_no_damage); |
| 279 | 278 |
| 280 // Then we set full damage for the next frame. | 279 // Then we set full damage for the next frame. |
| 281 host_impl->SetFullRootLayerDamage(); | 280 host_impl->SetFullRootLayerDamage(); |
| 282 break; | 281 break; |
| 283 case 2: | 282 case 2: |
| 284 // The whole frame should be damaged as requested. | 283 // The whole frame should be damaged as requested. |
| 285 EXPECT_EQ(gfx::RectF(root_surface->content_rect()).ToString(), | 284 EXPECT_EQ(root_surface->content_rect(), root_damage); |
| 286 root_damage.ToString()); | |
| 287 EXPECT_FALSE(frame_data->has_no_damage); | 285 EXPECT_FALSE(frame_data->has_no_damage); |
| 288 | 286 |
| 289 // Just a part of the next frame should be damaged. | 287 // Just a part of the next frame should be damaged. |
| 290 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); | 288 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); |
| 291 break; | 289 break; |
| 292 case 3: | 290 case 3: |
| 293 // The update rect in the child should be damaged and the damaged area | 291 // The update rect in the child should be damaged and the damaged area |
| 294 // should match the invalidation. | 292 // should match the invalidation. |
| 295 EXPECT_EQ(gfx::RectF(100+10, 100+11, 12, 13).ToString(), | 293 EXPECT_EQ(gfx::Rect(100 + 10, 100 + 11, 12, 13), root_damage); |
| 296 root_damage.ToString()); | |
| 297 EXPECT_FALSE(frame_data->has_no_damage); | 294 EXPECT_FALSE(frame_data->has_no_damage); |
| 298 | 295 |
| 299 // If we damage part of the frame, but also damage the full | 296 // If we damage part of the frame, but also damage the full |
| 300 // frame, then the whole frame should be damaged. | 297 // frame, then the whole frame should be damaged. |
| 301 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); | 298 child_damage_rect_ = gfx::Rect(10, 11, 12, 13); |
| 302 host_impl->SetFullRootLayerDamage(); | 299 host_impl->SetFullRootLayerDamage(); |
| 303 break; | 300 break; |
| 304 case 4: | 301 case 4: |
| 305 // The whole frame is damaged. | 302 // The whole frame is damaged. |
| 306 EXPECT_EQ(gfx::RectF(root_surface->content_rect()).ToString(), | 303 EXPECT_EQ(root_surface->content_rect(), root_damage); |
| 307 root_damage.ToString()); | |
| 308 EXPECT_FALSE(frame_data->has_no_damage); | 304 EXPECT_FALSE(frame_data->has_no_damage); |
| 309 | 305 |
| 310 EndTest(); | 306 EndTest(); |
| 311 break; | 307 break; |
| 312 } | 308 } |
| 313 return draw_result; | 309 return draw_result; |
| 314 } | 310 } |
| 315 | 311 |
| 316 void DidCommitAndDrawFrame() override { | 312 void DidCommitAndDrawFrame() override { |
| 317 if (!TestEnded()) | 313 if (!TestEnded()) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 did_swaps_ = 0; | 376 did_swaps_ = 0; |
| 381 PostSetNeedsCommitToMainThread(); | 377 PostSetNeedsCommitToMainThread(); |
| 382 } | 378 } |
| 383 | 379 |
| 384 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 380 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 385 LayerTreeHostImpl::FrameData* frame_data, | 381 LayerTreeHostImpl::FrameData* frame_data, |
| 386 DrawResult draw_result) override { | 382 DrawResult draw_result) override { |
| 387 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 383 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 388 RenderSurfaceImpl* root_surface = | 384 RenderSurfaceImpl* root_surface = |
| 389 host_impl->active_tree()->root_layer()->render_surface(); | 385 host_impl->active_tree()->root_layer()->render_surface(); |
| 390 gfx::RectF root_damage = | 386 gfx::Rect root_damage = |
| 391 root_surface->damage_tracker()->current_damage_rect(); | 387 root_surface->damage_tracker()->current_damage_rect(); |
| 392 root_damage.Intersect(root_surface->content_rect()); | 388 root_damage.Intersect(root_surface->content_rect()); |
| 393 switch (did_swaps_) { | 389 switch (did_swaps_) { |
| 394 case 0: | 390 case 0: |
| 395 // The first frame has damage, so we should draw and swap. | 391 // The first frame has damage, so we should draw and swap. |
| 396 break; | 392 break; |
| 397 case 1: | 393 case 1: |
| 398 // The second frame should not damage the scrollbars. | 394 // The second frame should not damage the scrollbars. |
| 399 EXPECT_FALSE(root_damage.Intersects(gfx::Rect(300, 300, 10, 100))); | 395 EXPECT_FALSE(root_damage.Intersects(gfx::Rect(300, 300, 10, 100))); |
| 400 break; | 396 break; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 did_swaps_ = 0; | 459 did_swaps_ = 0; |
| 464 PostSetNeedsCommitToMainThread(); | 460 PostSetNeedsCommitToMainThread(); |
| 465 } | 461 } |
| 466 | 462 |
| 467 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 463 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 468 LayerTreeHostImpl::FrameData* frame_data, | 464 LayerTreeHostImpl::FrameData* frame_data, |
| 469 DrawResult draw_result) override { | 465 DrawResult draw_result) override { |
| 470 EXPECT_EQ(DRAW_SUCCESS, draw_result); | 466 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| 471 RenderSurfaceImpl* root_surface = | 467 RenderSurfaceImpl* root_surface = |
| 472 host_impl->active_tree()->root_layer()->render_surface(); | 468 host_impl->active_tree()->root_layer()->render_surface(); |
| 473 gfx::RectF root_damage = | 469 gfx::Rect root_damage = |
| 474 root_surface->damage_tracker()->current_damage_rect(); | 470 root_surface->damage_tracker()->current_damage_rect(); |
| 475 root_damage.Intersect(root_surface->content_rect()); | 471 root_damage.Intersect(root_surface->content_rect()); |
| 476 int frame = host_impl->active_tree()->source_frame_number(); | 472 int frame = host_impl->active_tree()->source_frame_number(); |
| 477 switch (did_swaps_) { | 473 switch (did_swaps_) { |
| 478 case 0: | 474 case 0: |
| 479 // The first frame has damage, so we should draw and swap. | 475 // The first frame has damage, so we should draw and swap. |
| 480 EXPECT_EQ(0, frame); | 476 EXPECT_EQ(0, frame); |
| 481 break; | 477 break; |
| 482 case 1: | 478 case 1: |
| 483 // The second frame has scrolled, so the scrollbar should be damaged. | 479 // The second frame has scrolled, so the scrollbar should be damaged. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 521 |
| 526 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } | 522 void AfterTest() override { EXPECT_EQ(3, did_swaps_); } |
| 527 | 523 |
| 528 int did_swaps_; | 524 int did_swaps_; |
| 529 }; | 525 }; |
| 530 | 526 |
| 531 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); | 527 MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarCommitDoesNoDamage); |
| 532 | 528 |
| 533 } // namespace | 529 } // namespace |
| 534 } // namespace cc | 530 } // namespace cc |
| OLD | NEW |