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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 root_layer_(ContentLayer::Create(&client_)) {} | 277 root_layer_(ContentLayer::Create(&client_)) {} |
278 | 278 |
279 virtual void BeginTest() OVERRIDE { | 279 virtual void BeginTest() OVERRIDE { |
280 root_layer_->SetIsDrawable(true); | 280 root_layer_->SetIsDrawable(true); |
281 root_layer_->SetBounds(bounds_); | 281 root_layer_->SetBounds(bounds_); |
282 layer_tree_host()->SetRootLayer(root_layer_); | 282 layer_tree_host()->SetRootLayer(root_layer_); |
283 layer_tree_host()->SetViewportSize(bounds_); | 283 layer_tree_host()->SetViewportSize(bounds_); |
284 PostSetNeedsCommitToMainThread(); | 284 PostSetNeedsCommitToMainThread(); |
285 } | 285 } |
286 | 286 |
287 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 287 virtual DrawResult PrepareToDrawOnThread( |
288 LayerTreeHostImpl* host_impl, | 288 LayerTreeHostImpl* host_impl, |
289 LayerTreeHostImpl::FrameData* frame_data, | 289 LayerTreeHostImpl::FrameData* frame_data, |
290 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 290 DrawResult draw_result) OVERRIDE { |
291 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 291 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
292 | 292 |
293 gfx::RectF root_damage_rect; | 293 gfx::RectF root_damage_rect; |
294 if (!frame_data->render_passes.empty()) | 294 if (!frame_data->render_passes.empty()) |
295 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 295 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
296 | 296 |
297 if (!num_draws_) { | 297 if (!num_draws_) { |
298 // If this is the first frame, expect full frame damage. | 298 // If this is the first frame, expect full frame damage. |
299 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_)); | 299 EXPECT_RECT_EQ(root_damage_rect, gfx::Rect(bounds_)); |
300 } else { | 300 } else { |
301 // Check that invalid_rect_ is indeed repainted. | 301 // Check that invalid_rect_ is indeed repainted. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 : did_post_readback_(false) {} | 509 : did_post_readback_(false) {} |
510 | 510 |
511 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 511 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
512 // This enables forced draws after a single prepare to draw failure. | 512 // This enables forced draws after a single prepare to draw failure. |
513 settings->timeout_and_draw_when_animation_checkerboards = true; | 513 settings->timeout_and_draw_when_animation_checkerboards = true; |
514 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 514 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
515 } | 515 } |
516 | 516 |
517 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 517 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
518 | 518 |
519 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 519 virtual DrawResult PrepareToDrawOnThread( |
520 LayerTreeHostImpl* host_impl, | 520 LayerTreeHostImpl* host_impl, |
521 LayerTreeHostImpl::FrameData* frame_data, | 521 LayerTreeHostImpl::FrameData* frame_data, |
522 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 522 DrawResult draw_result) OVERRIDE { |
523 int sfn = host_impl->active_tree()->source_frame_number(); | 523 int sfn = host_impl->active_tree()->source_frame_number(); |
524 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || | 524 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || |
525 sfn == kReadbackSourceFrameNumber || | 525 sfn == kReadbackSourceFrameNumber || |
526 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) | 526 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) |
527 << sfn; | 527 << sfn; |
528 | 528 |
529 // Before we react to the failed draw by initiating the forced draw | 529 // Before we react to the failed draw by initiating the forced draw |
530 // sequence, start a readback on the main thread. | 530 // sequence, start a readback on the main thread. |
531 if (sfn == kFirstCommitSourceFrameNumber && !did_post_readback_) { | 531 if (sfn == kFirstCommitSourceFrameNumber && !did_post_readback_) { |
532 did_post_readback_ = true; | 532 did_post_readback_ = true; |
533 PostReadbackToMainThread(); | 533 PostReadbackToMainThread(); |
534 } | 534 } |
535 | 535 |
536 // Aborting for checkerboarding animations will result in a forced draw. | 536 // Aborting for checkerboarding animations will result in a forced draw. |
537 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 537 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
538 } | 538 } |
539 | 539 |
540 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 540 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
541 // We should only draw for the readback and the forced draw. | 541 // We should only draw for the readback and the forced draw. |
542 int sfn = host_impl->active_tree()->source_frame_number(); | 542 int sfn = host_impl->active_tree()->source_frame_number(); |
543 EXPECT_TRUE(sfn == kReadbackSourceFrameNumber || | 543 EXPECT_TRUE(sfn == kReadbackSourceFrameNumber || |
544 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) | 544 sfn == kReadbackReplacementAndForcedDrawSourceFrameNumber) |
545 << sfn; | 545 << sfn; |
546 } | 546 } |
547 | 547 |
(...skipping 22 matching lines...) Expand all Loading... |
570 static const int kReadbackReplacementSourceFrameNumber = 3; | 570 static const int kReadbackReplacementSourceFrameNumber = 3; |
571 | 571 |
572 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 572 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
573 // This enables forced draws after a single prepare to draw failure. | 573 // This enables forced draws after a single prepare to draw failure. |
574 settings->timeout_and_draw_when_animation_checkerboards = true; | 574 settings->timeout_and_draw_when_animation_checkerboards = true; |
575 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; | 575 settings->maximum_number_of_failed_draws_before_draw_is_forced_ = 1; |
576 } | 576 } |
577 | 577 |
578 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 578 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
579 | 579 |
580 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 580 virtual DrawResult PrepareToDrawOnThread( |
581 LayerTreeHostImpl* host_impl, | 581 LayerTreeHostImpl* host_impl, |
582 LayerTreeHostImpl::FrameData* frame_data, | 582 LayerTreeHostImpl::FrameData* frame_data, |
583 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 583 DrawResult draw_result) OVERRIDE { |
584 int sfn = host_impl->active_tree()->source_frame_number(); | 584 int sfn = host_impl->active_tree()->source_frame_number(); |
585 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || | 585 EXPECT_TRUE(sfn == kFirstCommitSourceFrameNumber || |
586 sfn == kForcedDrawSourceFrameNumber || | 586 sfn == kForcedDrawSourceFrameNumber || |
587 sfn == kReadbackSourceFrameNumber || | 587 sfn == kReadbackSourceFrameNumber || |
588 sfn == kReadbackReplacementSourceFrameNumber) | 588 sfn == kReadbackReplacementSourceFrameNumber) |
589 << sfn; | 589 << sfn; |
590 | 590 |
591 // Aborting for checkerboarding animations will result in a forced draw. | 591 // Aborting for checkerboarding animations will result in a forced draw. |
592 return DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 592 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
593 } | 593 } |
594 | 594 |
595 virtual void DidCommit() OVERRIDE { | 595 virtual void DidCommit() OVERRIDE { |
596 if (layer_tree_host()->source_frame_number() == | 596 if (layer_tree_host()->source_frame_number() == |
597 kForcedDrawSourceFrameNumber) { | 597 kForcedDrawSourceFrameNumber) { |
598 // Avoid aborting the forced draw commit so source_frame_number | 598 // Avoid aborting the forced draw commit so source_frame_number |
599 // increments. | 599 // increments. |
600 layer_tree_host()->SetNeedsCommit(); | 600 layer_tree_host()->SetNeedsCommit(); |
601 } else if (layer_tree_host()->source_frame_number() == | 601 } else if (layer_tree_host()->source_frame_number() == |
602 kReadbackSourceFrameNumber) { | 602 kReadbackSourceFrameNumber) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 layer_tree_host()->SetRootLayer(root_layer_); | 647 layer_tree_host()->SetRootLayer(root_layer_); |
648 layer_tree_host()->SetViewportSize(bounds_); | 648 layer_tree_host()->SetViewportSize(bounds_); |
649 PostSetNeedsCommitToMainThread(); | 649 PostSetNeedsCommitToMainThread(); |
650 } | 650 } |
651 | 651 |
652 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 652 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
653 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) | 653 if (num_draws_ == 3 && host_impl->settings().impl_side_painting) |
654 host_impl->SetNeedsRedrawRect(invalid_rect_); | 654 host_impl->SetNeedsRedrawRect(invalid_rect_); |
655 } | 655 } |
656 | 656 |
657 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 657 virtual DrawResult PrepareToDrawOnThread( |
658 LayerTreeHostImpl* host_impl, | 658 LayerTreeHostImpl* host_impl, |
659 LayerTreeHostImpl::FrameData* frame_data, | 659 LayerTreeHostImpl::FrameData* frame_data, |
660 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 660 DrawResult draw_result) OVERRIDE { |
661 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 661 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
662 | 662 |
663 gfx::RectF root_damage_rect; | 663 gfx::RectF root_damage_rect; |
664 if (!frame_data->render_passes.empty()) | 664 if (!frame_data->render_passes.empty()) |
665 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 665 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
666 | 666 |
667 switch (num_draws_) { | 667 switch (num_draws_) { |
668 case 0: | 668 case 0: |
669 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); | 669 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect); |
670 break; | 670 break; |
671 case 1: | 671 case 1: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 745 |
746 child_layer_ = FakeContentLayer::Create(&client_); | 746 child_layer_ = FakeContentLayer::Create(&client_); |
747 child_layer_->SetBounds(gfx::Size(25, 25)); | 747 child_layer_->SetBounds(gfx::Size(25, 25)); |
748 parent_layer_->AddChild(child_layer_); | 748 parent_layer_->AddChild(child_layer_); |
749 | 749 |
750 LayerTreeHostTest::SetupTree(); | 750 LayerTreeHostTest::SetupTree(); |
751 } | 751 } |
752 | 752 |
753 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 753 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
754 | 754 |
755 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 755 virtual DrawResult PrepareToDrawOnThread( |
756 LayerTreeHostImpl* host_impl, | 756 LayerTreeHostImpl* host_impl, |
757 LayerTreeHostImpl::FrameData* frame_data, | 757 LayerTreeHostImpl::FrameData* frame_data, |
758 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 758 DrawResult draw_result) OVERRIDE { |
759 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, draw_result); | 759 EXPECT_EQ(DRAW_SUCCESS, draw_result); |
760 | 760 |
761 gfx::RectF root_damage_rect; | 761 gfx::RectF root_damage_rect; |
762 if (!frame_data->render_passes.empty()) | 762 if (!frame_data->render_passes.empty()) |
763 root_damage_rect = frame_data->render_passes.back()->damage_rect; | 763 root_damage_rect = frame_data->render_passes.back()->damage_rect; |
764 | 764 |
765 // The first time, the whole view needs be drawn. | 765 // The first time, the whole view needs be drawn. |
766 // Afterwards, just the opacity of surface_layer1 is changed a few times, | 766 // Afterwards, just the opacity of surface_layer1 is changed a few times, |
767 // and each damage should be the bounding box of it and its child. If this | 767 // and each damage should be the bounding box of it and its child. If this |
768 // was working improperly, the damage might not include its childs bounding | 768 // was working improperly, the damage might not include its childs bounding |
769 // box. | 769 // box. |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2605 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2605 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
2606 settings->begin_frame_scheduling_enabled = true; | 2606 settings->begin_frame_scheduling_enabled = true; |
2607 } | 2607 } |
2608 | 2608 |
2609 virtual void BeginTest() OVERRIDE { | 2609 virtual void BeginTest() OVERRIDE { |
2610 // This will trigger a SetNeedsBeginFrame which will trigger a | 2610 // This will trigger a SetNeedsBeginFrame which will trigger a |
2611 // BeginFrame. | 2611 // BeginFrame. |
2612 PostSetNeedsCommitToMainThread(); | 2612 PostSetNeedsCommitToMainThread(); |
2613 } | 2613 } |
2614 | 2614 |
2615 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 2615 virtual DrawResult PrepareToDrawOnThread( |
2616 LayerTreeHostImpl* host_impl, | 2616 LayerTreeHostImpl* host_impl, |
2617 LayerTreeHostImpl::FrameData* frame, | 2617 LayerTreeHostImpl::FrameData* frame, |
2618 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 2618 DrawResult draw_result) OVERRIDE { |
2619 EndTest(); | 2619 EndTest(); |
2620 return DrawSwapReadbackResult::DRAW_SUCCESS; | 2620 return DRAW_SUCCESS; |
2621 } | 2621 } |
2622 | 2622 |
2623 virtual void AfterTest() OVERRIDE {} | 2623 virtual void AfterTest() OVERRIDE {} |
2624 | 2624 |
2625 private: | 2625 private: |
2626 base::TimeTicks frame_time_; | 2626 base::TimeTicks frame_time_; |
2627 }; | 2627 }; |
2628 | 2628 |
2629 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); | 2629 MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); |
2630 | 2630 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2895 EXPECT_CALL(*mock_context_, | 2895 EXPECT_CALL(*mock_context_, |
2896 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, | 2896 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, |
2897 io_surface_size_.width(), | 2897 io_surface_size_.width(), |
2898 io_surface_size_.height(), | 2898 io_surface_size_.height(), |
2899 io_surface_id_, | 2899 io_surface_id_, |
2900 0)).Times(1); | 2900 0)).Times(1); |
2901 | 2901 |
2902 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); | 2902 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); |
2903 } | 2903 } |
2904 | 2904 |
2905 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 2905 virtual DrawResult PrepareToDrawOnThread( |
2906 LayerTreeHostImpl* host_impl, | 2906 LayerTreeHostImpl* host_impl, |
2907 LayerTreeHostImpl::FrameData* frame, | 2907 LayerTreeHostImpl::FrameData* frame, |
2908 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 2908 DrawResult draw_result) OVERRIDE { |
2909 Mock::VerifyAndClearExpectations(&mock_context_); | 2909 Mock::VerifyAndClearExpectations(&mock_context_); |
2910 | 2910 |
2911 // The io surface layer's texture is drawn. | 2911 // The io surface layer's texture is drawn. |
2912 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1)); | 2912 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1)); |
2913 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) | 2913 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) |
2914 .Times(1); | 2914 .Times(1); |
2915 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) | 2915 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) |
2916 .Times(AtLeast(1)); | 2916 .Times(AtLeast(1)); |
2917 | 2917 |
2918 return draw_result; | 2918 return draw_result; |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4152 class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest { | 4152 class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest { |
4153 public: | 4153 public: |
4154 LayerTreeHostTestTreeActivationCallback() | 4154 LayerTreeHostTestTreeActivationCallback() |
4155 : num_commits_(0), callback_count_(0) {} | 4155 : num_commits_(0), callback_count_(0) {} |
4156 | 4156 |
4157 virtual void BeginTest() OVERRIDE { | 4157 virtual void BeginTest() OVERRIDE { |
4158 EXPECT_TRUE(HasImplThread()); | 4158 EXPECT_TRUE(HasImplThread()); |
4159 PostSetNeedsCommitToMainThread(); | 4159 PostSetNeedsCommitToMainThread(); |
4160 } | 4160 } |
4161 | 4161 |
4162 virtual DrawSwapReadbackResult::DrawResult PrepareToDrawOnThread( | 4162 virtual DrawResult PrepareToDrawOnThread( |
4163 LayerTreeHostImpl* host_impl, | 4163 LayerTreeHostImpl* host_impl, |
4164 LayerTreeHostImpl::FrameData* frame_data, | 4164 LayerTreeHostImpl::FrameData* frame_data, |
4165 DrawSwapReadbackResult::DrawResult draw_result) OVERRIDE { | 4165 DrawResult draw_result) OVERRIDE { |
4166 ++num_commits_; | 4166 ++num_commits_; |
4167 switch (num_commits_) { | 4167 switch (num_commits_) { |
4168 case 1: | 4168 case 1: |
4169 EXPECT_EQ(0, callback_count_); | 4169 EXPECT_EQ(0, callback_count_); |
4170 callback_count_ = 0; | 4170 callback_count_ = 0; |
4171 SetCallback(true); | 4171 SetCallback(true); |
4172 PostSetNeedsCommitToMainThread(); | 4172 PostSetNeedsCommitToMainThread(); |
4173 break; | 4173 break; |
4174 case 2: | 4174 case 2: |
4175 EXPECT_EQ(1, callback_count_); | 4175 EXPECT_EQ(1, callback_count_); |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5148 const gfx::Size bounds_; | 5148 const gfx::Size bounds_; |
5149 FakeContentLayerClient client_; | 5149 FakeContentLayerClient client_; |
5150 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 5150 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
5151 scoped_refptr<FakePictureLayer> picture_layer_; | 5151 scoped_refptr<FakePictureLayer> picture_layer_; |
5152 Layer* child_layer_; | 5152 Layer* child_layer_; |
5153 }; | 5153 }; |
5154 | 5154 |
5155 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 5155 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
5156 | 5156 |
5157 } // namespace cc | 5157 } // namespace cc |
OLD | NEW |