1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "cc/output/delegating_renderer.h" 6 7 #include "cc/test/fake_output_surface.h" 8 #include "cc/test/layer_tree_test.h" 9 #include "cc/test/render_pass_test_common.h" 10 #include "cc/test/render_pass_test_utils.h" 11 #include "testing/gtest/include/gtest/gtest.h" 12 13 namespace cc { 14 15 class DelegatingRendererTest : public LayerTreeTest { 16 public: DelegatingRendererTest()17 DelegatingRendererTest() : LayerTreeTest(), output_surface_(NULL) {} ~DelegatingRendererTest()18 virtual ~DelegatingRendererTest() {} 19 CreateOutputSurface(bool fallback)20 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 21 OVERRIDE { 22 scoped_ptr<FakeOutputSurface> output_surface = 23 FakeOutputSurface::CreateDelegating3d(); 24 output_surface_ = output_surface.get(); 25 return output_surface.PassAs<OutputSurface>(); 26 } 27 28 protected: 29 TestWebGraphicsContext3D* context3d_; 30 FakeOutputSurface* output_surface_; 31 }; 32 33 class DelegatingRendererTestDraw : public DelegatingRendererTest { 34 public: BeginTest()35 virtual void BeginTest() OVERRIDE { 36 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); 37 PostSetNeedsCommitToMainThread(); 38 } 39 AfterTest()40 virtual void AfterTest() OVERRIDE {} 41 PrepareToDrawOnThread(LayerTreeHostImpl * host_impl,LayerTreeHostImpl::FrameData * frame,DrawResult draw_result)42 virtual DrawResult PrepareToDrawOnThread( 43 LayerTreeHostImpl* host_impl, 44 LayerTreeHostImpl::FrameData* frame, 45 DrawResult draw_result) OVERRIDE { 46 EXPECT_EQ(0u, output_surface_->num_sent_frames()); 47 48 const CompositorFrame& last_frame = output_surface_->last_sent_frame(); 49 EXPECT_FALSE(last_frame.delegated_frame_data); 50 EXPECT_FALSE(last_frame.gl_frame_data); 51 EXPECT_EQ(0.f, last_frame.metadata.min_page_scale_factor); 52 EXPECT_EQ(0.f, last_frame.metadata.max_page_scale_factor); 53 return DRAW_SUCCESS; 54 } 55 DrawLayersOnThread(LayerTreeHostImpl * host_impl)56 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 57 EXPECT_EQ(0u, output_surface_->num_sent_frames()); 58 } 59 SwapBuffersOnThread(LayerTreeHostImpl * host_impl,bool result)60 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 61 bool result) OVERRIDE { 62 EXPECT_TRUE(result); 63 EXPECT_EQ(1u, output_surface_->num_sent_frames()); 64 65 const CompositorFrame& last_frame = output_surface_->last_sent_frame(); 66 DelegatedFrameData* last_frame_data = last_frame.delegated_frame_data.get(); 67 ASSERT_TRUE(last_frame.delegated_frame_data); 68 EXPECT_FALSE(last_frame.gl_frame_data); 69 EXPECT_EQ(host_impl->DeviceViewport().ToString(), 70 last_frame_data->render_pass_list.back()->output_rect.ToString()); 71 EXPECT_EQ(0.5f, last_frame.metadata.min_page_scale_factor); 72 EXPECT_EQ(4.f, last_frame.metadata.max_page_scale_factor); 73 74 EXPECT_EQ( 75 0u, last_frame.delegated_frame_data->resource_list.size()); 76 EXPECT_EQ(1u, last_frame.delegated_frame_data->render_pass_list.size()); 77 78 EndTest(); 79 } 80 }; 81 82 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(DelegatingRendererTestDraw); 83 84 class DelegatingRendererTestResources : public DelegatingRendererTest { 85 public: BeginTest()86 virtual void BeginTest() OVERRIDE { 87 PostSetNeedsCommitToMainThread(); 88 } 89 AfterTest()90 virtual void AfterTest() OVERRIDE {} 91 PrepareToDrawOnThread(LayerTreeHostImpl * host_impl,LayerTreeHostImpl::FrameData * frame,DrawResult draw_result)92 virtual DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 93 LayerTreeHostImpl::FrameData* frame, 94 DrawResult draw_result) OVERRIDE { 95 frame->render_passes.clear(); 96 frame->render_passes_by_id.clear(); 97 98 TestRenderPass* child_pass = AddRenderPass( 99 &frame->render_passes, 100 RenderPass::Id(2, 1), 101 gfx::Rect(3, 3, 10, 10), 102 gfx::Transform()); 103 child_pass->AppendOneOfEveryQuadType( 104 host_impl->resource_provider(), RenderPass::Id(0, 0)); 105 106 TestRenderPass* pass = AddRenderPass( 107 &frame->render_passes, 108 RenderPass::Id(1, 1), 109 gfx::Rect(3, 3, 10, 10), 110 gfx::Transform()); 111 pass->AppendOneOfEveryQuadType( 112 host_impl->resource_provider(), child_pass->id); 113 return draw_result; 114 } 115 DrawLayersOnThread(LayerTreeHostImpl * host_impl)116 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 117 EXPECT_EQ(0u, output_surface_->num_sent_frames()); 118 } 119 SwapBuffersOnThread(LayerTreeHostImpl * host_impl,bool result)120 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 121 bool result) OVERRIDE { 122 EXPECT_TRUE(result); 123 EXPECT_EQ(1u, output_surface_->num_sent_frames()); 124 125 const CompositorFrame& last_frame = output_surface_->last_sent_frame(); 126 ASSERT_TRUE(last_frame.delegated_frame_data); 127 128 EXPECT_EQ(2u, last_frame.delegated_frame_data->render_pass_list.size()); 129 // Each render pass has 10 resources in it. And the root render pass has a 130 // mask resource used when drawing the child render pass, as well as its 131 // replica (it's added twice). The number 10 may change if 132 // AppendOneOfEveryQuadType() is updated, and the value here should be 133 // updated accordingly. 134 EXPECT_EQ( 135 22u, last_frame.delegated_frame_data->resource_list.size()); 136 137 EndTest(); 138 } 139 }; 140 141 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F( 142 DelegatingRendererTestResources); 143 144 } // namespace cc 145