Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 23694031: Fix race conditions in window snapshot code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated unittest again, attempted to address feedback from jamesr@ Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 629
630 if (sfn == kReadbackReplacementSourceFrameNumber) 630 if (sfn == kReadbackReplacementSourceFrameNumber)
631 EndTest(); 631 EndTest();
632 } 632 }
633 633
634 virtual void AfterTest() OVERRIDE {} 634 virtual void AfterTest() OVERRIDE {}
635 }; 635 };
636 636
637 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackAfterForcedDraw); 637 MULTI_THREAD_TEST_F(LayerTreeHostTestCompositeAndReadbackAfterForcedDraw);
638 638
639 class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest {
640 public:
641 LayerTreeHostTestSetNextCommitForcesRedraw()
642 : num_draws_(0),
643 bounds_(50, 50),
644 invalid_rect_(10, 10, 20, 20),
645 root_layer_(ContentLayer::Create(&client_)) {
646 }
647
648 virtual void BeginTest() OVERRIDE {
649 root_layer_->SetIsDrawable(true);
650 root_layer_->SetBounds(bounds_);
651 layer_tree_host()->SetRootLayer(root_layer_);
652 layer_tree_host()->SetViewportSize(bounds_);
653 PostSetNeedsCommitToMainThread();
654 }
655
656 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
657 if (num_draws_ == 3 && host_impl->settings().impl_side_painting)
658 host_impl->SetNeedsRedrawRect(invalid_rect_);
659 }
660
661 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
662 LayerTreeHostImpl::FrameData* frame_data,
663 bool result) OVERRIDE {
664 EXPECT_TRUE(result);
665
666 gfx::RectF root_damage_rect;
667 if (!frame_data->render_passes.empty())
668 root_damage_rect = frame_data->render_passes.back()->damage_rect;
669
670 switch (num_draws_) {
671 case 0:
672 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect);
673 break;
674 case 1:
675 case 2:
676 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect);
677 break;
678 case 3:
679 EXPECT_RECT_EQ(invalid_rect_, root_damage_rect);
680 break;
681 case 4:
682 EXPECT_RECT_EQ(gfx::Rect(bounds_), root_damage_rect);
683 break;
684 default:
685 NOTREACHED();
686 }
687
688 return result;
689 }
690
691 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
692 switch (num_draws_) {
693 case 0:
694 case 1:
695 // Cycle through a couple of empty commits to ensure we're observing the
696 // right behavior
697 PostSetNeedsCommitToMainThread();
698 break;
699 case 2:
700 // Should force full frame damage on the next commit
701 PostSetNextCommitForcesRedrawToMainThread();
702 PostSetNeedsCommitToMainThread();
703 if (host_impl->settings().impl_side_painting)
704 host_impl->BlockNotifyReadyToActivateForTesting(true);
705 else
706 num_draws_++;
707 break;
708 case 3:
709 host_impl->BlockNotifyReadyToActivateForTesting(false);
710 break;
711 default:
712 EndTest();
713 break;
714 }
715 num_draws_++;
716 }
717
718 virtual void AfterTest() OVERRIDE {
719 EXPECT_EQ(5, num_draws_);
720 }
721
722 private:
723 int num_draws_;
724 const gfx::Size bounds_;
725 const gfx::Rect invalid_rect_;
726 FakeContentLayerClient client_;
727 scoped_refptr<ContentLayer> root_layer_;
728 };
729
730 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw);
731
639 // If the layerTreeHost says it can't draw, Then we should not try to draw. 732 // If the layerTreeHost says it can't draw, Then we should not try to draw.
640 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest { 733 class LayerTreeHostTestCanDrawBlocksDrawing : public LayerTreeHostTest {
641 public: 734 public:
642 LayerTreeHostTestCanDrawBlocksDrawing() : num_commits_(0), done_(false) {} 735 LayerTreeHostTestCanDrawBlocksDrawing() : num_commits_(0), done_(false) {}
643 736
644 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 737 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
645 738
646 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 739 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
647 if (done_) 740 if (done_)
648 return; 741 return;
(...skipping 4187 matching lines...) Expand 10 before | Expand all | Expand 10 after
4836 : public LayerTreeHostTestOffscreenContext { 4929 : public LayerTreeHostTestOffscreenContext {
4837 protected: 4930 protected:
4838 LayerTreeHostTestOffscreenContext_WithContext() { with_context_ = true; } 4931 LayerTreeHostTestOffscreenContext_WithContext() { with_context_ = true; }
4839 }; 4932 };
4840 4933
4841 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestOffscreenContext_WithContext); 4934 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestOffscreenContext_WithContext);
4842 4935
4843 } // namespace 4936 } // namespace
4844 4937
4845 } // namespace cc 4938 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698