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

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

Issue 2158973002: cc: Clean up LayerTreeTest and TestHooks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: proxy-impls: test Created 4 years, 5 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "cc/test/fake_recording_source.h" 43 #include "cc/test/fake_recording_source.h"
44 #include "cc/test/fake_scoped_ui_resource.h" 44 #include "cc/test/fake_scoped_ui_resource.h"
45 #include "cc/test/fake_video_frame_provider.h" 45 #include "cc/test/fake_video_frame_provider.h"
46 #include "cc/test/geometry_test_utils.h" 46 #include "cc/test/geometry_test_utils.h"
47 #include "cc/test/layer_internals_for_test.h" 47 #include "cc/test/layer_internals_for_test.h"
48 #include "cc/test/layer_tree_test.h" 48 #include "cc/test/layer_tree_test.h"
49 #include "cc/test/skia_common.h" 49 #include "cc/test/skia_common.h"
50 #include "cc/test/test_shared_bitmap_manager.h" 50 #include "cc/test/test_shared_bitmap_manager.h"
51 #include "cc/test/test_web_graphics_context_3d.h" 51 #include "cc/test/test_web_graphics_context_3d.h"
52 #include "cc/trees/effect_node.h" 52 #include "cc/trees/effect_node.h"
53 #include "cc/trees/layer_tree_host_common.h"
53 #include "cc/trees/layer_tree_host_impl.h" 54 #include "cc/trees/layer_tree_host_impl.h"
54 #include "cc/trees/layer_tree_impl.h" 55 #include "cc/trees/layer_tree_impl.h"
55 #include "cc/trees/single_thread_proxy.h" 56 #include "cc/trees/single_thread_proxy.h"
56 #include "cc/trees/transform_node.h" 57 #include "cc/trees/transform_node.h"
57 #include "gpu/GLES2/gl2extchromium.h" 58 #include "gpu/GLES2/gl2extchromium.h"
58 #include "testing/gmock/include/gmock/gmock.h" 59 #include "testing/gmock/include/gmock/gmock.h"
59 #include "third_party/khronos/GLES2/gl2.h" 60 #include "third_party/khronos/GLES2/gl2.h"
60 #include "third_party/khronos/GLES2/gl2ext.h" 61 #include "third_party/khronos/GLES2/gl2ext.h"
61 #include "third_party/skia/include/core/SkPicture.h" 62 #include "third_party/skia/include/core/SkPicture.h"
62 #include "third_party/skia/include/gpu/GrContext.h" 63 #include "third_party/skia/include/gpu/GrContext.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 enum MainOrder : int { 141 enum MainOrder : int {
141 MAIN_START = 1, 142 MAIN_START = 1,
142 MAIN_LAYOUT, 143 MAIN_LAYOUT,
143 MAIN_COMMIT_COMPLETE, 144 MAIN_COMMIT_COMPLETE,
144 MAIN_DID_BEGIN_FRAME, 145 MAIN_DID_BEGIN_FRAME,
145 MAIN_END, 146 MAIN_END,
146 }; 147 };
147 148
148 enum ImplOrder : int { 149 enum ImplOrder : int {
149 IMPL_START = 1, 150 IMPL_START = 1,
151 IMPL_READY_TO_COMMIT,
150 IMPL_COMMIT, 152 IMPL_COMMIT,
151 IMPL_COMMIT_COMPLETE, 153 IMPL_COMMIT_COMPLETE,
152 IMPL_ACTIVATE, 154 IMPL_ACTIVATE,
153 IMPL_DRAW, 155 IMPL_DRAW,
154 IMPL_END, 156 IMPL_END,
155 }; 157 };
156 158
157 template <typename T> 159 template <typename T>
158 bool CheckStep(T next, T* var) { 160 bool CheckStep(T next, T* var) {
159 int expected = next - 1; 161 int expected = next - 1;
(...skipping 10 matching lines...) Expand all
170 } 172 }
171 173
172 void DidCommit() override { 174 void DidCommit() override {
173 EXPECT_TRUE(CheckStep(MAIN_COMMIT_COMPLETE, &main_)); 175 EXPECT_TRUE(CheckStep(MAIN_COMMIT_COMPLETE, &main_));
174 } 176 }
175 177
176 void DidBeginMainFrame() override { 178 void DidBeginMainFrame() override {
177 EXPECT_TRUE(CheckStep(MAIN_DID_BEGIN_FRAME, &main_)); 179 EXPECT_TRUE(CheckStep(MAIN_DID_BEGIN_FRAME, &main_));
178 } 180 }
179 181
182 void ReadyToCommitOnThread(LayerTreeHostImpl* impl) override {
183 EXPECT_TRUE(CheckStep(IMPL_READY_TO_COMMIT, &impl_));
184 }
185
180 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { 186 void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
181 EXPECT_TRUE(CheckStep(IMPL_COMMIT, &impl_)); 187 EXPECT_TRUE(CheckStep(IMPL_COMMIT, &impl_));
182 } 188 }
183 189
184 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { 190 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
185 EXPECT_TRUE(CheckStep(IMPL_COMMIT_COMPLETE, &impl_)); 191 EXPECT_TRUE(CheckStep(IMPL_COMMIT_COMPLETE, &impl_));
186 } 192 }
187 193
188 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 194 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
189 EXPECT_TRUE(CheckStep(IMPL_ACTIVATE, &impl_)); 195 EXPECT_TRUE(CheckStep(IMPL_ACTIVATE, &impl_));
(...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 case 5: 2328 case 5:
2323 PostSetDeferCommitsToMainThread(false); 2329 PostSetDeferCommitsToMainThread(false);
2324 break; 2330 break;
2325 default: 2331 default:
2326 // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the 2332 // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the
2327 // main thread is slow to respond. 2333 // main thread is slow to respond.
2328 break; 2334 break;
2329 } 2335 }
2330 } 2336 }
2331 2337
2332 void ScheduledActionSendBeginMainFrame() override { 2338 void WillBeginMainFrame() override {
2333 num_send_begin_main_frame_++; 2339 num_send_begin_main_frame_++;
2334 switch (num_send_begin_main_frame_) { 2340 switch (num_send_begin_main_frame_) {
2335 case 1: 2341 case 1:
2336 PostSetDeferCommitsToMainThread(true); 2342 layer_tree_host()->SetDeferCommits(true);
2337 break; 2343 break;
2338 case 2: 2344 case 2:
2339 EndTest(); 2345 EndTest();
2340 break; 2346 break;
2341 default: 2347 default:
2342 NOTREACHED(); 2348 NOTREACHED();
2343 break; 2349 break;
2344 } 2350 }
2345 } 2351 }
2346 2352
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 EXPECT_EQ(commit_count_, 5); 2616 EXPECT_EQ(commit_count_, 5);
2611 EXPECT_EQ(commit_abort_count_, 3); 2617 EXPECT_EQ(commit_abort_count_, 3);
2612 EXPECT_EQ(commit_complete_count_, 2); 2618 EXPECT_EQ(commit_complete_count_, 2);
2613 } 2619 }
2614 2620
2615 int commit_count_; 2621 int commit_count_;
2616 int commit_abort_count_; 2622 int commit_abort_count_;
2617 int commit_complete_count_; 2623 int commit_complete_count_;
2618 }; 2624 };
2619 2625
2626 class OnDrawOutputSurface : public OutputSurface {
2627 public:
2628 explicit OnDrawOutputSurface(base::Closure invalidate_callback)
2629 : OutputSurface(TestContextProvider::Create(),
2630 TestContextProvider::CreateWorker(),
2631 nullptr),
2632 invalidate_callback_(std::move(invalidate_callback)) {
2633 capabilities_.delegated_rendering = true;
2634 }
2635
2636 // OutputSurface implementation.
2637 void SwapBuffers(CompositorFrame frame) override { did_swap_ = true; }
2638 uint32_t GetFramebufferCopyTextureFormat() override { return 0; }
2639 void Invalidate() override { invalidate_callback_.Run(); }
2640
2641 void OnDraw(bool resourceless_software_draw) {
2642 gfx::Transform identity;
2643 gfx::Rect empty_rect;
2644 // SwapBuffers happens inside of OnDraw.
2645 client_->OnDraw(identity, empty_rect, empty_rect,
2646 resourceless_software_draw);
2647 if (did_swap_) {
2648 did_swap_ = false;
2649 client_->DidSwapBuffersComplete();
2650 }
2651 }
2652
2653 private:
2654 bool did_swap_ = false;
2655 base::Closure invalidate_callback_;
2656 };
2657
2620 class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor 2658 class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
2621 : public LayerTreeHostTestAbortedCommitDoesntStall { 2659 : public LayerTreeHostTestAbortedCommitDoesntStall {
2622 protected: 2660 protected:
2623 void InitializeSettings(LayerTreeSettings* settings) override { 2661 void InitializeSettings(LayerTreeSettings* settings) override {
2624 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings); 2662 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings);
2625 settings->using_synchronous_renderer_compositor = true; 2663 settings->using_synchronous_renderer_compositor = true;
2626 } 2664 }
2627 2665
2628 void ScheduledActionInvalidateOutputSurface() override { 2666 std::unique_ptr<OutputSurface> CreateOutputSurface() override {
2629 // Do not call ImplThreadTaskRunner after the test ended because of the 2667 auto output_surface = base::MakeUnique<OnDrawOutputSurface>(base::Bind(
2630 // possibility of use-after-free due to a race. 2668 &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
2631 if (TestEnded()) 2669 CallOnDraw,
2632 return; 2670 base::Unretained(this)));
2633 ImplThreadTaskRunner()->PostTask( 2671 output_surface_ = output_surface.get();
2634 FROM_HERE, 2672 return std::move(output_surface);
2635 base::Bind(
2636 &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
2637 CallOnDraw,
2638 base::Unretained(this)));
2639 } 2673 }
2640 2674
2641 void CallOnDraw() { 2675 void CallOnDraw() {
2642 // Synchronous compositor does not draw unless told to do so by the output 2676 if (!TestEnded()) {
2643 // surface. 2677 // Synchronous compositor does not draw unless told to do so by the output
2644 gfx::Transform identity; 2678 // surface. But it needs to be done on a new stack frame.
2645 gfx::Rect empty_rect; 2679 bool resourceless_software_draw = false;
2646 bool resourceless_software_draw = false; 2680 ImplThreadTaskRunner()->PostTask(
2647 fake_output_surface()->client()->OnDraw(identity, empty_rect, empty_rect, 2681 FROM_HERE, base::Bind(&OnDrawOutputSurface::OnDraw,
2648 resourceless_software_draw); 2682 base::Unretained(output_surface_),
2683 resourceless_software_draw));
2684 }
2649 } 2685 }
2686
2687 OnDrawOutputSurface* output_surface_ = nullptr;
2650 }; 2688 };
2651 2689
2652 MULTI_THREAD_TEST_F( 2690 MULTI_THREAD_TEST_F(
2653 LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor); 2691 LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor);
2654 2692
2655 class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync 2693 class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync
2656 : public LayerTreeHostTestAbortedCommitDoesntStall { 2694 : public LayerTreeHostTestAbortedCommitDoesntStall {
2657 void InitializeSettings(LayerTreeSettings* settings) override { 2695 void InitializeSettings(LayerTreeSettings* settings) override {
2658 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings); 2696 LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings);
2659 settings->wait_for_beginframe_interval = false; 2697 settings->wait_for_beginframe_interval = false;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 2769
2732 void AfterTest() override {} 2770 void AfterTest() override {}
2733 2771
2734 protected: 2772 protected:
2735 int frame_; 2773 int frame_;
2736 }; 2774 };
2737 2775
2738 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending); 2776 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending);
2739 2777
2740 class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { 2778 class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest {
2741 public: 2779 protected:
2742 void InitializeSettings(LayerTreeSettings* settings) override { 2780 void InitializeSettings(LayerTreeSettings* settings) override {
2743 settings->using_synchronous_renderer_compositor = true; 2781 settings->using_synchronous_renderer_compositor = true;
2744 } 2782 }
2745 2783
2746 void SetupTree() override { 2784 void SetupTree() override {
2747 root_layer_ = FakePictureLayer::Create(&client_); 2785 root_layer_ = FakePictureLayer::Create(&client_);
2748 root_layer_->SetIsDrawable(true); 2786 root_layer_->SetIsDrawable(true);
2749 root_layer_->SetBounds(gfx::Size(50, 50)); 2787 root_layer_->SetBounds(gfx::Size(50, 50));
2750 2788
2751 parent_layer_ = FakePictureLayer::Create(&client_); 2789 parent_layer_ = FakePictureLayer::Create(&client_);
2752 parent_layer_->SetIsDrawable(true); 2790 parent_layer_->SetIsDrawable(true);
2753 parent_layer_->SetBounds(gfx::Size(50, 50)); 2791 parent_layer_->SetBounds(gfx::Size(50, 50));
2754 parent_layer_->SetForceRenderSurfaceForTesting(true); 2792 parent_layer_->SetForceRenderSurfaceForTesting(true);
2755 2793
2756 child_layer_ = FakePictureLayer::Create(&client_); 2794 child_layer_ = FakePictureLayer::Create(&client_);
2757 child_layer_->SetIsDrawable(true); 2795 child_layer_->SetIsDrawable(true);
2758 child_layer_->SetBounds(gfx::Size(50, 50)); 2796 child_layer_->SetBounds(gfx::Size(50, 50));
2759 2797
2760 root_layer_->AddChild(parent_layer_); 2798 root_layer_->AddChild(parent_layer_);
2761 parent_layer_->AddChild(child_layer_); 2799 parent_layer_->AddChild(child_layer_);
2762 layer_tree_host()->SetRootLayer(root_layer_); 2800 layer_tree_host()->SetRootLayer(root_layer_);
2763 2801
2764 LayerTreeHostTest::SetupTree(); 2802 LayerTreeHostTest::SetupTree();
2765 client_.set_bounds(root_layer_->bounds()); 2803 client_.set_bounds(root_layer_->bounds());
2766 } 2804 }
2767 2805
2768 std::unique_ptr<OutputSurface> CreateOutputSurface() override { 2806 std::unique_ptr<OutputSurface> CreateOutputSurface() override {
2769 auto output_surface = delegating_renderer() 2807 auto output_surface = base::MakeUnique<OnDrawOutputSurface>(
2770 ? FakeOutputSurface::CreateDelegatingSoftware( 2808 base::Bind(&LayerTreeHostTestResourcelessSoftwareDraw::CallOnDraw,
2771 base::WrapUnique(new SoftwareOutputDevice)) 2809 base::Unretained(this)));
2772 : FakeOutputSurface::CreateSoftware( 2810 output_surface_ = output_surface.get();
2773 base::WrapUnique(new SoftwareOutputDevice));
2774 software_output_surface_ = output_surface.get();
2775 return std::move(output_surface); 2811 return std::move(output_surface);
2776 } 2812 }
2777 2813
2778 void BeginTest() override { 2814 void BeginTest() override {
2779 PostSetNeedsCommitToMainThread(); 2815 PostSetNeedsCommitToMainThread();
2780 swap_count_ = 0;
2781 }
2782
2783 void ScheduledActionInvalidateOutputSurface() override {
2784 if (TestEnded())
2785 return;
2786
2787 ImplThreadTaskRunner()->PostTask(
2788 FROM_HERE,
2789 base::Bind(&LayerTreeHostTestResourcelessSoftwareDraw::CallOnDraw,
2790 base::Unretained(this)));
2791 } 2816 }
2792 2817
2793 void CallOnDraw() { 2818 void CallOnDraw() {
2794 gfx::Transform identity; 2819 if (!TestEnded()) {
2795 gfx::Rect empty_rect; 2820 // Synchronous compositor does not draw unless told to do so by the output
2796 bool resourceless_software_draw = true; 2821 // surface. But it needs to be done on a new stack frame.
2797 software_output_surface_->client()->OnDraw(identity, empty_rect, empty_rect, 2822 bool resourceless_software_draw = true;
2798 resourceless_software_draw); 2823 ImplThreadTaskRunner()->PostTask(
2824 FROM_HERE, base::Bind(&OnDrawOutputSurface::OnDraw,
2825 base::Unretained(output_surface_),
2826 resourceless_software_draw));
2827 }
2799 } 2828 }
2800 2829
2801 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 2830 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
2802 LayerTreeHostImpl::FrameData* frame_data, 2831 LayerTreeHostImpl::FrameData* frame_data,
2803 DrawResult draw_result) override { 2832 DrawResult draw_result) override {
2804 if (host_impl->GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE) { 2833 if (host_impl->GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE) {
2805 EXPECT_EQ(1u, frame_data->render_passes.size()); 2834 EXPECT_EQ(1u, frame_data->render_passes.size());
2806 // Has at least 3 quads for each layer. 2835 // Has at least 3 quads for each layer.
2807 RenderPass* render_pass = frame_data->render_passes[0].get(); 2836 RenderPass* render_pass = frame_data->render_passes[0].get();
2808 EXPECT_GE(render_pass->quad_list.size(), 3u); 2837 EXPECT_GE(render_pass->quad_list.size(), 3u);
2809 } else { 2838 } else {
2810 EXPECT_EQ(2u, frame_data->render_passes.size()); 2839 EXPECT_EQ(2u, frame_data->render_passes.size());
2811 2840
2812 // At least root layer quad in root render pass. 2841 // At least root layer quad in root render pass.
2813 EXPECT_GE(frame_data->render_passes[0]->quad_list.size(), 1u); 2842 EXPECT_GE(frame_data->render_passes[0]->quad_list.size(), 1u);
2814 // At least parent and child layer quads in parent render pass. 2843 // At least parent and child layer quads in parent render pass.
2815 EXPECT_GE(frame_data->render_passes[1]->quad_list.size(), 2u); 2844 EXPECT_GE(frame_data->render_passes[1]->quad_list.size(), 2u);
2816 } 2845 }
2817 return draw_result; 2846 return draw_result;
2818 } 2847 }
2819 2848
2820 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 2849 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
2821 swap_count_++; 2850 draw_count_++;
2822 switch (swap_count_) { 2851 switch (draw_count_) {
2823 case 1: 2852 case 1:
2824 host_impl->SetNeedsRedraw(); 2853 host_impl->SetNeedsRedraw();
2825 break; 2854 break;
2826 case 2: 2855 case 2:
2827 EndTest(); 2856 EndTest();
2828 break; 2857 break;
2829 default: 2858 default:
2830 NOTREACHED(); 2859 NOTREACHED();
2831 } 2860 }
2832 } 2861 }
2833 2862
2834 void AfterTest() override {} 2863 void AfterTest() override {}
2835 2864
2836 private: 2865 private:
2837 FakeOutputSurface* software_output_surface_ = nullptr; 2866 OnDrawOutputSurface* output_surface_ = nullptr;
2838 FakeContentLayerClient client_; 2867 FakeContentLayerClient client_;
2839 scoped_refptr<Layer> root_layer_; 2868 scoped_refptr<Layer> root_layer_;
2840 scoped_refptr<Layer> parent_layer_; 2869 scoped_refptr<Layer> parent_layer_;
2841 scoped_refptr<Layer> child_layer_; 2870 scoped_refptr<Layer> child_layer_;
2842 int swap_count_; 2871 int draw_count_ = 0;
2843 }; 2872 };
2844 2873
2845 // Resourceless is not used for SingleThreadProxy, so it is unimplemented. 2874 // Resourceless is not used for SingleThreadProxy, so it is unimplemented.
2846 MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw); 2875 MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw);
2847 2876
2848 // Test for UI Resource management. 2877 // Test for UI Resource management.
2849 class LayerTreeHostTestUIResource : public LayerTreeHostTest { 2878 class LayerTreeHostTestUIResource : public LayerTreeHostTest {
2850 public: 2879 public:
2851 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} 2880 LayerTreeHostTestUIResource() : num_ui_resources_(0) {}
2852 2881
(...skipping 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after
4625 protected: 4654 protected:
4626 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4655 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4627 4656
4628 void SetVisibleFalseAndQueueSwapPromise() { 4657 void SetVisibleFalseAndQueueSwapPromise() {
4629 layer_tree_host()->SetVisible(false); 4658 layer_tree_host()->SetVisible(false);
4630 std::unique_ptr<SwapPromise> swap_promise( 4659 std::unique_ptr<SwapPromise> swap_promise(
4631 new TestSwapPromise(&swap_promise_result_)); 4660 new TestSwapPromise(&swap_promise_result_));
4632 layer_tree_host()->QueueSwapPromise(std::move(swap_promise)); 4661 layer_tree_host()->QueueSwapPromise(std::move(swap_promise));
4633 } 4662 }
4634 4663
4635 void ScheduledActionWillSendBeginMainFrame() override { 4664 void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
4665 const BeginFrameArgs& args) override {
4636 MainThreadTaskRunner()->PostTask( 4666 MainThreadTaskRunner()->PostTask(
4637 FROM_HERE, 4667 FROM_HERE,
4638 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility 4668 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
4639 ::SetVisibleFalseAndQueueSwapPromise, 4669 ::SetVisibleFalseAndQueueSwapPromise,
4640 base::Unretained(this))); 4670 base::Unretained(this)));
4641 } 4671 }
4642 4672
4643 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4673 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4644 CommitEarlyOutReason reason) override { 4674 CommitEarlyOutReason reason) override {
4645 EndTest(); 4675 EndTest();
(...skipping 23 matching lines...) Expand all
4669 4699
4670 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4700 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4671 4701
4672 void LoseOutputSurfaceAndQueueSwapPromise() { 4702 void LoseOutputSurfaceAndQueueSwapPromise() {
4673 layer_tree_host()->DidLoseOutputSurface(); 4703 layer_tree_host()->DidLoseOutputSurface();
4674 std::unique_ptr<SwapPromise> swap_promise( 4704 std::unique_ptr<SwapPromise> swap_promise(
4675 new TestSwapPromise(&swap_promise_result_)); 4705 new TestSwapPromise(&swap_promise_result_));
4676 layer_tree_host()->QueueSwapPromise(std::move(swap_promise)); 4706 layer_tree_host()->QueueSwapPromise(std::move(swap_promise));
4677 } 4707 }
4678 4708
4679 void ScheduledActionWillSendBeginMainFrame() override { 4709 void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
4710 const BeginFrameArgs& args) override {
4680 if (output_surface_lost_triggered_) 4711 if (output_surface_lost_triggered_)
4681 return; 4712 return;
4682 output_surface_lost_triggered_ = true; 4713 output_surface_lost_triggered_ = true;
4683 4714
4684 MainThreadTaskRunner()->PostTask( 4715 MainThreadTaskRunner()->PostTask(
4685 FROM_HERE, 4716 FROM_HERE,
4686 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext 4717 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext
4687 ::LoseOutputSurfaceAndQueueSwapPromise, 4718 ::LoseOutputSurfaceAndQueueSwapPromise,
4688 base::Unretained(this))); 4719 base::Unretained(this)));
4689 } 4720 }
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
5197 did_finish_impl_frame_count_++; 5228 did_finish_impl_frame_count_++;
5198 EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_); 5229 EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_);
5199 5230
5200 // Request a number of commits to cause multiple impl frames. We expect to 5231 // Request a number of commits to cause multiple impl frames. We expect to
5201 // get one more impl frames than the number of commits requested because 5232 // get one more impl frames than the number of commits requested because
5202 // after a commit it takes one frame to become idle. 5233 // after a commit it takes one frame to become idle.
5203 if (did_finish_impl_frame_count_ < kExpectedNumImplFrames - 1) 5234 if (did_finish_impl_frame_count_ < kExpectedNumImplFrames - 1)
5204 PostSetNeedsCommitToMainThread(); 5235 PostSetNeedsCommitToMainThread();
5205 } 5236 }
5206 5237
5207 void SendBeginMainFrameNotExpectedSoon() override { EndTest(); } 5238 void BeginMainFrameNotExpectedSoon() override { EndTest(); }
5208 5239
5209 void AfterTest() override { 5240 void AfterTest() override {
5210 EXPECT_GT(will_begin_impl_frame_count_, 0); 5241 EXPECT_GT(will_begin_impl_frame_count_, 0);
5211 EXPECT_GT(did_finish_impl_frame_count_, 0); 5242 EXPECT_GT(did_finish_impl_frame_count_, 0);
5212 EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_); 5243 EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_);
5213 5244
5214 // TODO(mithro): Figure out why the multithread version of this test 5245 // TODO(mithro): Figure out why the multithread version of this test
5215 // sometimes has one more frame then expected. Possibly related to 5246 // sometimes has one more frame then expected. Possibly related to
5216 // http://crbug.com/443185 5247 // http://crbug.com/443185
5217 if (!HasImplThread()) { 5248 if (!HasImplThread()) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5270 if (will_begin_impl_frame_count_ < 10) 5301 if (will_begin_impl_frame_count_ < 10)
5271 PostSetNeedsCommitToMainThread(); 5302 PostSetNeedsCommitToMainThread();
5272 } 5303 }
5273 5304
5274 void BeginMainFrame(const BeginFrameArgs& args) override { 5305 void BeginMainFrame(const BeginFrameArgs& args) override {
5275 ASSERT_GT(impl_frame_args_.size(), 0U) 5306 ASSERT_GT(impl_frame_args_.size(), 0U)
5276 << "BeginMainFrame called before BeginImplFrame called!"; 5307 << "BeginMainFrame called before BeginImplFrame called!";
5277 EXPECT_PRED_FORMAT2(AssertFrameTimeContained, impl_frame_args_, args); 5308 EXPECT_PRED_FORMAT2(AssertFrameTimeContained, impl_frame_args_, args);
5278 } 5309 }
5279 5310
5280 void SendBeginMainFrameNotExpectedSoon() override { EndTest(); } 5311 void BeginMainFrameNotExpectedSoon() override { EndTest(); }
5281 5312
5282 void AfterTest() override { 5313 void AfterTest() override {
5283 EXPECT_GT(impl_frame_args_.size(), 0U); 5314 EXPECT_GT(impl_frame_args_.size(), 0U);
5284 EXPECT_GE(will_begin_impl_frame_count_, 10); 5315 EXPECT_GE(will_begin_impl_frame_count_, 10);
5285 } 5316 }
5286 5317
5287 private: 5318 private:
5288 std::vector<BeginFrameArgs> impl_frame_args_; 5319 std::vector<BeginFrameArgs> impl_frame_args_;
5289 int will_begin_impl_frame_count_; 5320 int will_begin_impl_frame_count_;
5290 }; 5321 };
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
5975 bool success) override { 6006 bool success) override {
5976 ASSERT_TRUE(success); 6007 ASSERT_TRUE(success);
5977 host_impl->tile_manager()->SetScheduledRasterTaskLimitForTesting(1); 6008 host_impl->tile_manager()->SetScheduledRasterTaskLimitForTesting(1);
5978 } 6009 }
5979 6010
5980 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { 6011 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
5981 ++notify_ready_to_activate_count_; 6012 ++notify_ready_to_activate_count_;
5982 EndTestAfterDelayMs(100); 6013 EndTestAfterDelayMs(100);
5983 } 6014 }
5984 6015
5985 void ScheduledActionPrepareTiles() override { 6016 void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
5986 ++scheduled_prepare_tiles_count_; 6017 ++scheduled_prepare_tiles_count_;
5987 } 6018 }
5988 6019
5989 void AfterTest() override { 6020 void AfterTest() override {
5990 // Expect at most a notification for each scheduled prepare tiles, plus one 6021 // Expect at most a notification for each scheduled prepare tiles, plus one
5991 // for the initial commit (which doesn't go through scheduled actions). 6022 // for the initial commit (which doesn't go through scheduled actions).
5992 // The reason this is not an equality is because depending on timing, we 6023 // The reason this is not an equality is because depending on timing, we
5993 // might get a prepare tiles but not yet get a notification that we're 6024 // might get a prepare tiles but not yet get a notification that we're
5994 // ready to activate. The intent of a test is to ensure that we don't 6025 // ready to activate. The intent of a test is to ensure that we don't
5995 // get more than one notification per prepare tiles, so this is OK. 6026 // get more than one notification per prepare tiles, so this is OK.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6030 6061
6031 // After activating, we either need to prepare tiles, or we've already 6062 // After activating, we either need to prepare tiles, or we've already
6032 // called a scheduled prepare tiles. This is done because activation might 6063 // called a scheduled prepare tiles. This is done because activation might
6033 // cause us to have to memory available (old active tree is gone), so we 6064 // cause us to have to memory available (old active tree is gone), so we
6034 // need to ensure we will get a PrepareTiles call. 6065 // need to ensure we will get a PrepareTiles call.
6035 if (!impl->prepare_tiles_needed()) 6066 if (!impl->prepare_tiles_needed())
6036 EXPECT_GE(scheduled_prepare_tiles_count_, 1); 6067 EXPECT_GE(scheduled_prepare_tiles_count_, 1);
6037 EndTest(); 6068 EndTest();
6038 } 6069 }
6039 6070
6040 void ScheduledActionPrepareTiles() override { 6071 void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
6041 ++scheduled_prepare_tiles_count_; 6072 ++scheduled_prepare_tiles_count_;
6042 } 6073 }
6043 6074
6044 void AfterTest() override {} 6075 void AfterTest() override {}
6045 6076
6046 protected: 6077 protected:
6047 FakeContentLayerClient client_; 6078 FakeContentLayerClient client_;
6048 int scheduled_prepare_tiles_count_; 6079 int scheduled_prepare_tiles_count_;
6049 }; 6080 };
6050 6081
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
6685 } 6716 }
6686 6717
6687 void AfterTest() override {} 6718 void AfterTest() override {}
6688 6719
6689 std::vector<int> affected_by_page_scale_; 6720 std::vector<int> affected_by_page_scale_;
6690 std::vector<int> not_affected_by_page_scale_; 6721 std::vector<int> not_affected_by_page_scale_;
6691 }; 6722 };
6692 6723
6693 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags); 6724 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags);
6694 6725
6695 class LayerTreeHostScrollingAndScalingUpdatesLayers : public LayerTreeHostTest {
6696 public:
6697 LayerTreeHostScrollingAndScalingUpdatesLayers()
6698 : requested_update_layers_(false), commit_count_(0) {}
6699
6700 void SetupTree() override {
6701 LayerTreeHostTest::SetupTree();
6702 Layer* root_layer = layer_tree_host()->root_layer();
6703 scoped_refptr<Layer> scroll_layer = Layer::Create();
6704 CreateVirtualViewportLayers(root_layer, scroll_layer, root_layer->bounds(),
6705 root_layer->bounds(), layer_tree_host());
6706 }
6707
6708 void BeginTest() override {
6709 LayerTreeHostCommon::ScrollUpdateInfo scroll;
6710 scroll.layer_id = layer_tree_host()->root_layer()->id();
6711 scroll.scroll_delta = gfx::Vector2d(0, 33);
6712 scroll_info_.scrolls.push_back(scroll);
6713
6714 scale_info_.page_scale_delta = 2.71f;
6715
6716 PostSetNeedsCommitToMainThread();
6717 }
6718
6719 void BeginMainFrame(const BeginFrameArgs& args) override {
6720 switch (commit_count_) {
6721 case 0:
6722 requested_update_layers_ = false;
6723 layer_tree_host()->ApplyScrollAndScale(&no_op_info_);
6724 EXPECT_FALSE(requested_update_layers_);
6725 break;
6726 case 1:
6727 requested_update_layers_ = false;
6728 layer_tree_host()->ApplyScrollAndScale(&scale_info_);
6729 EXPECT_TRUE(requested_update_layers_);
6730 break;
6731 case 2:
6732 requested_update_layers_ = false;
6733 layer_tree_host()->ApplyScrollAndScale(&scroll_info_);
6734 EXPECT_TRUE(requested_update_layers_);
6735 EndTest();
6736 break;
6737 default:
6738 NOTREACHED();
6739 }
6740 }
6741
6742 void DidSetNeedsUpdateLayers() override { requested_update_layers_ = true; }
6743
6744 void DidCommit() override {
6745 if (++commit_count_ < 3)
6746 PostSetNeedsCommitToMainThread();
6747 }
6748
6749 void AfterTest() override {}
6750
6751 ScrollAndScaleSet scroll_info_;
6752 ScrollAndScaleSet scale_info_;
6753 ScrollAndScaleSet no_op_info_;
6754 bool requested_update_layers_;
6755 int commit_count_;
6756 };
6757
6758 MULTI_THREAD_TEST_F(LayerTreeHostScrollingAndScalingUpdatesLayers);
6759
6760 class LayerTreeHostTestDestroyWhileInitializingOutputSurface 6726 class LayerTreeHostTestDestroyWhileInitializingOutputSurface
6761 : public LayerTreeHostTest { 6727 : public LayerTreeHostTest {
6762 protected: 6728 protected:
6763 void BeginTest() override { 6729 void BeginTest() override {
6764 // By ending the test immediately we start initialization of an output 6730 // By ending the test immediately we start initialization of an output
6765 // surface but destroy the LTH before it completes. This test verifies 6731 // surface but destroy the LTH before it completes. This test verifies
6766 // that this works correctly and the output surface is destroyed on 6732 // that this works correctly and the output surface is destroyed on
6767 // the correct thread. 6733 // the correct thread.
6768 EndTest(); 6734 EndTest();
6769 } 6735 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
6873 private: 6839 private:
6874 FakeContentLayerClient client_; 6840 FakeContentLayerClient client_;
6875 const gfx::Size viewport_size_; 6841 const gfx::Size viewport_size_;
6876 const gfx::Size large_image_size_; 6842 const gfx::Size large_image_size_;
6877 }; 6843 };
6878 6844
6879 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage); 6845 SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage);
6880 6846
6881 } // namespace 6847 } // namespace
6882 } // namespace cc 6848 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698