OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 root_layer_(ContentLayer::Create(&client_)) {} | 279 root_layer_(ContentLayer::Create(&client_)) {} |
280 | 280 |
281 virtual void BeginTest() OVERRIDE { | 281 virtual void BeginTest() OVERRIDE { |
282 root_layer_->SetIsDrawable(true); | 282 root_layer_->SetIsDrawable(true); |
283 root_layer_->SetBounds(bounds_); | 283 root_layer_->SetBounds(bounds_); |
284 layer_tree_host()->SetRootLayer(root_layer_); | 284 layer_tree_host()->SetRootLayer(root_layer_); |
285 layer_tree_host()->SetViewportSize(bounds_); | 285 layer_tree_host()->SetViewportSize(bounds_); |
286 PostSetNeedsCommitToMainThread(); | 286 PostSetNeedsCommitToMainThread(); |
287 } | 287 } |
288 | 288 |
289 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 289 virtual DrawResult PrepareToDrawOnThread( |
290 LayerTreeHostImpl* host_impl, | 290 LayerTreeHostImpl* host_impl, |
291 LayerTreeHostImpl::FrameData* frame_data, | 291 LayerTreeHostImpl::FrameData* frame_data, |
292 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 292 DrawResult draw_result) OVERRIDE { |
293 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 293 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
294 | 294 |
295 gfx::RectF root_damage_rect; | 295 gfx::RectF root_damage_rect; |
296 if (!frame_data->render_passes.empty()) | 296 if (!frame_data->render_passes.empty()) |
297 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 297 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
298 | 298 |
299 if (!num_draws_) { | 299 if (!num_draws_) { |
300 // If this is the first frame, expect full frame damage. | 300 // If this is the first frame, expect full frame damage. |
301 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_)); | 301 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_)); |
302 } else { | 302 } else { |
303 // Check that invalid_rect_ is indeed repainted. | 303 // Check that invalid_rect_ is indeed repainted. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 : did_post_readback_(false) {} | 511 : did_post_readback_(false) {} |
512 | 512 |
513 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 513 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
514 // This enables forced draws after a single prepare to draw failure. | 514 // This enables forced draws after a single prepare to draw failure. |
515 settings->timeout_and_draw_when_animation_checkerboards = true; | 515 settings->timeout_and_draw_when_animation_checkerboards = true; |
516 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 516 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
517 } | 517 } |
518 | 518 |
519 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 519 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
520 | 520 |
521 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 521 virtual DrawResult PrepareToDrawOnThread( |
522 LayerTreeHostImpl* host_impl, | 522 LayerTreeHostImpl* host_impl, |
523 LayerTreeHostImpl::FrameData* frame_data, | 523 LayerTreeHostImpl::FrameData* frame_data, |
524 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 524 DrawResult draw_result) OVERRIDE { |
525 int sfn = host_impl->active_tree()->source_frame_number(); | 525 int sfn = host_impl->active_tree()->source_frame_number(); |
526 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || | 526 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || |
527 sfn == kReadbackSourceFrameNumber || | 527 sfn == kReadbackSourceFrameNumber || |
528 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) | 528 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) |
529 << sfn; | 529 << sfn; |
530 | 530 |
531 // Before we react to the failed draw by initiating the forced draw | 531 // Before we react to the failed draw by initiating the forced draw |
532 // sequence, start a readback on the main thread. | 532 // sequence, start a readback on the main thread. |
533 if (sfn == kFirstCommitSourceFrameNumber && !did_post_readback_) { | 533 if (sfn == kFirstCommitSourceFrameNumber && !did_post_readback_) { |
534 did_post_readback_ = true; | 534 did_post_readback_ = true; |
535 PostReadbackToMainThread(); | 535 PostReadbackToMainThread(); |
536 } | 536 } |
537 | 537 |
538 // Aborting for checkerboarding animations will result in a forced draw. | 538 // Aborting for checkerboarding animations will result in a forced draw. |
539 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 539 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
540 } | 540 } |
541 | 541 |
542 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 542 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
543 // We should only draw for the readback and the forced draw. | 543 // We should only draw for the readback and the forced draw. |
544 int sfn = host_impl->active_tree()->source_frame_number(); | 544 int sfn = host_impl->active_tree()->source_frame_number(); |
545 EXPECT_TRUE(sfn == kReadbackSourceFrameNumber || | 545 EXPECT_TRUE(sfn == kReadbackSourceFrameNumber || |
546 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) | 546 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) |
547 << sfn; | 547 << sfn; |
548 } | 548 } |
549 | 549 |
(...skipping 22 matching lines...) Expand all Loading... |
572 static const int kReadbackReplacementSourceFrameNumber = 3; | 572 static const int kReadbackReplacementSourceFrameNumber = 3; |
573 | 573 |
574 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 574 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
575 // This enables forced draws after a single prepare to draw failure. | 575 // This enables forced draws after a single prepare to draw failure. |
576 settings->timeout_and_draw_when_animation_checkerboards = true; | 576 settings->timeout_and_draw_when_animation_checkerboards = true; |
577 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 577 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
578 } | 578 } |
579 | 579 |
580 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 580 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
581 | 581 |
582 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 582 virtual DrawResult PrepareToDrawOnThread( |
583 LayerTreeHostImpl* host_impl, | 583 LayerTreeHostImpl* host_impl, |
584 LayerTreeHostImpl::FrameData* frame_data, | 584 LayerTreeHostImpl::FrameData* frame_data, |
585 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 585 DrawResult draw_result) OVERRIDE { |
586 int sfn = host_impl->active_tree()->source_frame_number(); | 586 int sfn = host_impl->active_tree()->source_frame_number(); |
587 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || | 587 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || |
588 sfn == kForcedDrawSourceFrameNumber || | 588 sfn == kForcedDrawSourceFrameNumber || |
589 sfn == kReadbackSourceFrameNumber || | 589 sfn == kReadbackSourceFrameNumber || |
590 sfn == kReadbackReplacementSourceFrameNumber) | 590 sfn == kReadbackReplacementSourceFrameNumber) |
591 << sfn; | 591 << sfn; |
592 | 592 |
593 // Aborting for checkerboarding animations will result in a forced draw. | 593 // Aborting for checkerboarding animations will result in a forced draw. |
594 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 594 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
595 } | 595 } |
596 | 596 |
597 virtual void DidCommit() OVERRIDE { | 597 virtual void DidCommit() OVERRIDE { |
598 if (layer_tree_host()->source_frame_number() == | 598 if (layer_tree_host()->source_frame_number() == |
599 kForcedDrawSourceFrameNumber) { | 599 kForcedDrawSourceFrameNumber) { |
600 // Avoid aborting the forced draw commit so source_frame_number | 600 // Avoid aborting the forced draw commit so source_frame_number |
601 // increments. | 601 // increments. |
602 layer_tree_host()->SetNeedsCommit(); | 602 layer_tree_host()->SetNeedsCommit(); |
603 } else if (layer_tree_host()->source_frame_number() == | 603 } else if (layer_tree_host()->source_frame_number() == |
604 kReadbackSourceFrameNumber) { | 604 kReadbackSourceFrameNumber) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 layer_tree_host()->SetRootLayer(root_layer_); | 649 layer_tree_host()->SetRootLayer(root_layer_); |
650 layer_tree_host()->SetViewportSize(bounds_); | 650 layer_tree_host()->SetViewportSize(bounds_); |
651 PostSetNeedsCommitToMainThread(); | 651 PostSetNeedsCommitToMainThread(); |
652 } | 652 } |
653 | 653 |
654 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 654 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
655 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) | 655 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) |
656 host_impl->SetNeedsRedrawRect(invalid_rect_); | 656 host_impl->SetNeedsRedrawRect(invalid_rect_); |
657 } | 657 } |
658 | 658 |
659 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 659 virtual DrawResult PrepareToDrawOnThread( |
660 LayerTreeHostImpl* host_impl, | 660 LayerTreeHostImpl* host_impl, |
661 LayerTreeHostImpl::FrameData* frame_data, | 661 LayerTreeHostImpl::FrameData* frame_data, |
662 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 662 DrawResult draw_result) OVERRIDE { |
663 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 663 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
664 | 664 |
665 gfx::RectF root_damage_rect; | 665 gfx::RectF root_damage_rect; |
666 if (!frame_data->render_passes.empty()) | 666 if (!frame_data->render_passes.empty()) |
667 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 667 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
668 | 668 |
669 switch (num_draws_) { | 669 switch (num_draws_) { |
670 case 0: | 670 case 0: |
671 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); | 671 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); |
672 break; | 672 break; |
673 case 1: | 673 case 1: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 | 747 |
748 child_layer_ = FakeContentLayer::Create(&client_); | 748 child_layer_ = FakeContentLayer::Create(&client_); |
749 child_layer_->SetBounds(gfx::Size(25, 25)); | 749 child_layer_->SetBounds(gfx::Size(25, 25)); |
750 parent_layer_->AddChild(child_layer_); | 750 parent_layer_->AddChild(child_layer_); |
751 | 751 |
752 LayerTreeHostTest::SetupTree(); | 752 LayerTreeHostTest::SetupTree(); |
753 } | 753 } |
754 | 754 |
755 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 755 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
756 | 756 |
757 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 757 virtual DrawResult PrepareToDrawOnThread( |
758 LayerTreeHostImpl* host_impl, | 758 LayerTreeHostImpl* host_impl, |
759 LayerTreeHostImpl::FrameData* frame_data, | 759 LayerTreeHostImpl::FrameData* frame_data, |
760 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 760 DrawResult draw_result) OVERRIDE { |
761 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 761 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
762 | 762 |
763 gfx::RectF root_damage_rect; | 763 gfx::RectF root_damage_rect; |
764 if (!frame_data->render_passes.empty()) | 764 if (!frame_data->render_passes.empty()) |
765 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 765 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
766 | 766 |
767 // The first time, the whole view needs be drawn. | 767 // The first time, the whole view needs be drawn. |
768 // Afterwards, just the opacity of surface_layer1 is changed a few times, | 768 // Afterwards, just the opacity of surface_layer1 is changed a few times, |
769 // and each damage should be the bounding box of it and its child. If this | 769 // and each damage should be the bounding box of it and its child. If this |
770 // was working improperly, the damage might not include its childs bounding | 770 // was working improperly, the damage might not include its childs bounding |
771 // box. | 771 // box. |
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2612 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2612 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
2613 settings->begin_frame_scheduling_enabled = true; | 2613 settings->begin_frame_scheduling_enabled = true; |
2614 } | 2614 } |
2615 | 2615 |
2616 virtual void BeginTest() OVERRIDE { | 2616 virtual void BeginTest() OVERRIDE { |
2617 // This will trigger a SetNeedsBeginFrame which will trigger a | 2617 // This will trigger a SetNeedsBeginFrame which will trigger a |
2618 // BeginFrame. | 2618 // BeginFrame. |
2619 PostSetNeedsCommitToMainThread(); | 2619 PostSetNeedsCommitToMainThread(); |
2620 } | 2620 } |
2621 | 2621 |
2622 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 2622 virtual DrawResult PrepareToDrawOnThread( |
2623 LayerTreeHostImpl* host_impl, | 2623 LayerTreeHostImpl* host_impl, |
2624 LayerTreeHostImpl::FrameData* frame, | 2624 LayerTreeHostImpl::FrameData* frame, |
2625 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 2625 DrawResult draw_result) OVERRIDE { |
2626 EndTest(); | 2626 EndTest(); |
2627 return DrawSwapReadbackResult::DRAW_SUCCESS; | 2627 return DRAW_SUCCESS; |
2628 } | 2628 } |
2629 | 2629 |
2630 virtual void AfterTest() OVERRIDE {} | 2630 virtual void AfterTest() OVERRIDE {} |
2631 | 2631 |
2632 private: | 2632 private: |
2633 base::TimeTicks frame_time_; | 2633 base::TimeTicks frame_time_; |
2634 }; | 2634 }; |
2635 | 2635 |
2636 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); | 2636 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); |
2637 | 2637 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2917 EXPECT_CALL(*mock_context_, | 2917 EXPECT_CALL(*mock_context_, |
2918 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, | 2918 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, |
2919 io_surface_size_.width(), | 2919 io_surface_size_.width(), |
2920 io_surface_size_.height(), | 2920 io_surface_size_.height(), |
2921 io_surface_id_, | 2921 io_surface_id_, |
2922 0)).Times(1); | 2922 0)).Times(1); |
2923 | 2923 |
2924 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); | 2924 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); |
2925 } | 2925 } |
2926 | 2926 |
2927 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 2927 virtual DrawResult PrepareToDrawOnThread( |
2928 LayerTreeHostImpl* host_impl, | 2928 LayerTreeHostImpl* host_impl, |
2929 LayerTreeHostImpl::FrameData* frame, | 2929 LayerTreeHostImpl::FrameData* frame, |
2930 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 2930 DrawResult draw_result) OVERRIDE { |
2931 Mock::VerifyAndClearExpectations(&mock_context_); | 2931 Mock::VerifyAndClearExpectations(&mock_context_); |
2932 ResourceProvider* resource_provider = host_impl->resource_provider(); | 2932 ResourceProvider* resource_provider = host_impl->resource_provider(); |
2933 EXPECT_EQ(1u, resource_provider->num_resources()); | 2933 EXPECT_EQ(1u, resource_provider->num_resources()); |
2934 CHECK_EQ(1u, frame->render_passes.size()); | 2934 CHECK_EQ(1u, frame->render_passes.size()); |
2935 CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); | 2935 CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); |
2936 const DrawQuad* quad = frame->render_passes[0]->quad_list[0]; | 2936 const DrawQuad* quad = frame->render_passes[0]->quad_list[0]; |
2937 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); | 2937 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); |
2938 const IOSurfaceDrawQuad* io_surface_draw_quad = | 2938 const IOSurfaceDrawQuad* io_surface_draw_quad = |
2939 IOSurfaceDrawQuad::MaterialCast(quad); | 2939 IOSurfaceDrawQuad::MaterialCast(quad); |
2940 EXPECT_SIZE_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); | 2940 EXPECT_SIZE_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4191 class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest { | 4191 class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest { |
4192 public: | 4192 public: |
4193 LayerTreeHostTestTreeActivationCallback() | 4193 LayerTreeHostTestTreeActivationCallback() |
4194 : num_commits_(0), callback_count_(0) {} | 4194 : num_commits_(0), callback_count_(0) {} |
4195 | 4195 |
4196 virtual void BeginTest() OVERRIDE { | 4196 virtual void BeginTest() OVERRIDE { |
4197 EXPECT_TRUE(HasImplThread()); | 4197 EXPECT_TRUE(HasImplThread()); |
4198 PostSetNeedsCommitToMainThread(); | 4198 PostSetNeedsCommitToMainThread(); |
4199 } | 4199 } |
4200 | 4200 |
4201 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 4201 virtual DrawResult PrepareToDrawOnThread( |
4202 LayerTreeHostImpl* host_impl, | 4202 LayerTreeHostImpl* host_impl, |
4203 LayerTreeHostImpl::FrameData* frame_data, | 4203 LayerTreeHostImpl::FrameData* frame_data, |
4204 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 4204 DrawResult draw_result) OVERRIDE { |
4205 ++num_commits_; | 4205 ++num_commits_; |
4206 switch (num_commits_) { | 4206 switch (num_commits_) { |
4207 case 1: | 4207 case 1: |
4208 EXPECT_EQ(0, callback_count_); | 4208 EXPECT_EQ(0, callback_count_); |
4209 callback_count_ = 0; | 4209 callback_count_ = 0; |
4210 SetCallback(true); | 4210 SetCallback(true); |
4211 PostSetNeedsCommitToMainThread(); | 4211 PostSetNeedsCommitToMainThread(); |
4212 break; | 4212 break; |
4213 case 2: | 4213 case 2: |
4214 EXPECT_EQ(1, callback_count_); | 4214 EXPECT_EQ(1, callback_count_); |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5283 const gfx::Size bounds_; | 5283 const gfx::Size bounds_; |
5284 FakeContentLayerClient client_; | 5284 FakeContentLayerClient client_; |
5285 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 5285 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
5286 scoped_refptr<FakePictureLayer> picture_layer_; | 5286 scoped_refptr<FakePictureLayer> picture_layer_; |
5287 Layer* child_layer_; | 5287 Layer* child_layer_; |
5288 }; | 5288 }; |
5289 | 5289 |
5290 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 5290 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
5291 | 5291 |
5292 } // namespace cc | 5292 } // namespace cc |
OLD | NEW |