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.
5 #include "cc/output/delegating_renderer.h"
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"
15 class DelegatingRendererTest
: public LayerTreeTest
{
17 DelegatingRendererTest() : LayerTreeTest(), output_surface_(NULL
) {}
18 virtual ~DelegatingRendererTest() {}
20 virtual scoped_ptr
<OutputSurface
> CreateOutputSurface(bool fallback
)
22 scoped_ptr
<FakeOutputSurface
> output_surface
=
23 FakeOutputSurface::CreateDelegating3d();
24 output_surface_
= output_surface
.get();
25 return output_surface
.PassAs
<OutputSurface
>();
29 TestWebGraphicsContext3D
* context3d_
;
30 FakeOutputSurface
* output_surface_
;
33 class DelegatingRendererTestDraw
: public DelegatingRendererTest
{
35 virtual void BeginTest() OVERRIDE
{
36 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.5f
, 4.f
);
37 PostSetNeedsCommitToMainThread();
40 virtual void AfterTest() OVERRIDE
{}
42 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
43 LayerTreeHostImpl::FrameData
* frame
,
46 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
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
);
56 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
57 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
60 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
61 bool result
) OVERRIDE
{
63 EXPECT_EQ(1u, output_surface_
->num_sent_frames());
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
);
70 gfx::Rect(host_impl
->device_viewport_size()).ToString(),
71 last_frame_data
->render_pass_list
.back()->output_rect
.ToString());
72 EXPECT_EQ(0.5f
, last_frame
.metadata
.min_page_scale_factor
);
73 EXPECT_EQ(4.f
, last_frame
.metadata
.max_page_scale_factor
);
76 0u, last_frame
.delegated_frame_data
->resource_list
.size());
77 EXPECT_EQ(1u, last_frame
.delegated_frame_data
->render_pass_list
.size());
83 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(DelegatingRendererTestDraw
);
85 class DelegatingRendererTestResources
: public DelegatingRendererTest
{
87 virtual void BeginTest() OVERRIDE
{
88 PostSetNeedsCommitToMainThread();
91 virtual void AfterTest() OVERRIDE
{}
93 virtual bool PrepareToDrawOnThread(
94 LayerTreeHostImpl
* host_impl
,
95 LayerTreeHostImpl::FrameData
* frame
,
96 bool result
) OVERRIDE
{
97 frame
->render_passes
.clear();
98 frame
->render_passes_by_id
.clear();
100 TestRenderPass
* child_pass
= AddRenderPass(
101 &frame
->render_passes
,
102 RenderPass::Id(2, 1),
103 gfx::Rect(3, 3, 10, 10),
105 child_pass
->AppendOneOfEveryQuadType(
106 host_impl
->resource_provider(), RenderPass::Id(0, 0));
108 TestRenderPass
* pass
= AddRenderPass(
109 &frame
->render_passes
,
110 RenderPass::Id(1, 1),
111 gfx::Rect(3, 3, 10, 10),
113 pass
->AppendOneOfEveryQuadType(
114 host_impl
->resource_provider(), child_pass
->id
);
118 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
119 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
122 virtual void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
,
123 bool result
) OVERRIDE
{
125 EXPECT_EQ(1u, output_surface_
->num_sent_frames());
127 const CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
128 ASSERT_TRUE(last_frame
.delegated_frame_data
);
130 EXPECT_EQ(2u, last_frame
.delegated_frame_data
->render_pass_list
.size());
131 // Each render pass has 10 resources in it. And the root render pass has a
132 // mask resource used when drawing the child render pass, as well as its
133 // replica (it's added twice). The number 10 may change if
134 // AppendOneOfEveryQuadType() is updated, and the value here should be
135 // updated accordingly.
137 22u, last_frame
.delegated_frame_data
->resource_list
.size());
143 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
144 DelegatingRendererTestResources
);