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