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/delegating_renderer.h"
7 #include "cc/test/fake_output_surface.h"
8 #include "cc/test/layer_tree_test_common.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 ThreadedTest
{
17 DelegatingRendererTest() : ThreadedTest(), output_surface_(NULL
) {}
18 virtual ~DelegatingRendererTest() {}
20 virtual scoped_ptr
<OutputSurface
> createOutputSurface() OVERRIDE
{
21 scoped_ptr
<FakeWebGraphicsContext3D
> context3d
=
22 FakeWebGraphicsContext3D::Create(
23 WebKit::WebGraphicsContext3D::Attributes());
24 context3d_
= context3d
.get();
25 scoped_ptr
<FakeOutputSurface
> output_surface
=
26 FakeOutputSurface::CreateDelegating3d(
27 context3d
.PassAs
<WebKit::WebGraphicsContext3D
>());
28 output_surface_
= output_surface
.get();
29 return output_surface
.PassAs
<OutputSurface
>();
33 FakeWebGraphicsContext3D
* context3d_
;
34 FakeOutputSurface
* output_surface_
;
37 class DelegatingRendererTestDraw
: public DelegatingRendererTest
{
39 virtual void beginTest() OVERRIDE
{
40 m_layerTreeHost
->setPageScaleFactorAndLimits(1.f
, 0.5f
, 4.f
);
41 postSetNeedsCommitToMainThread();
44 virtual void afterTest() OVERRIDE
{}
46 virtual bool prepareToDrawOnThread(
47 LayerTreeHostImpl
*, LayerTreeHostImpl::FrameData
& frame
, bool result
)
49 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
51 CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
52 EXPECT_FALSE(last_frame
.delegated_frame_data
);
53 EXPECT_FALSE(last_frame
.gl_frame_data
);
54 EXPECT_EQ(0.f
, last_frame
.metadata
.min_page_scale_factor
);
55 EXPECT_EQ(0.f
, last_frame
.metadata
.max_page_scale_factor
);
59 virtual void drawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
60 EXPECT_EQ(1u, output_surface_
->num_sent_frames());
62 CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
63 ASSERT_TRUE(last_frame
.delegated_frame_data
);
64 EXPECT_FALSE(last_frame
.gl_frame_data
);
66 host_impl
->deviceViewportSize().ToString(),
67 last_frame
.delegated_frame_data
->size
.ToString());
68 EXPECT_EQ(0.5f
, last_frame
.metadata
.min_page_scale_factor
);
69 EXPECT_EQ(4.f
, last_frame
.metadata
.max_page_scale_factor
);
72 0u, last_frame
.delegated_frame_data
->resource_list
.resources
.size());
73 EXPECT_EQ(1u, last_frame
.delegated_frame_data
->render_pass_list
.size());
79 SINGLE_AND_MULTI_THREAD_TEST_F(DelegatingRendererTestDraw
)
81 class DelegatingRendererTestResources
: public DelegatingRendererTest
{
83 virtual void beginTest() OVERRIDE
{
84 postSetNeedsCommitToMainThread();
87 virtual void afterTest() OVERRIDE
{}
89 virtual bool prepareToDrawOnThread(
90 LayerTreeHostImpl
* host_impl
,
91 LayerTreeHostImpl::FrameData
& frame
,
92 bool result
) OVERRIDE
{
94 frame
.renderPasses
.clear();
95 frame
.renderPassesById
.clear();
97 TestRenderPass
* child_pass
= addRenderPass(
100 gfx::Rect(3, 3, 10, 10),
102 child_pass
->AppendOneOfEveryQuadType(
103 host_impl
->resourceProvider(), RenderPass::Id(0, 0));
105 TestRenderPass
* pass
= addRenderPass(
107 RenderPass::Id(1, 1),
108 gfx::Rect(3, 3, 10, 10),
110 pass
->AppendOneOfEveryQuadType(
111 host_impl
->resourceProvider(), child_pass
->id
);
115 virtual void drawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
116 EXPECT_EQ(1u, output_surface_
->num_sent_frames());
118 CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
119 ASSERT_TRUE(last_frame
.delegated_frame_data
);
121 EXPECT_EQ(2u, last_frame
.delegated_frame_data
->render_pass_list
.size());
122 // Each render pass has 7 resources in it. And the root render pass has a
123 // mask resource used when drawing the child render pass. The number 7 may
124 // change if AppendOneOfEveryQuadType is updated, and the value here should
125 // be updated accordingly.
127 15u, last_frame
.delegated_frame_data
->resource_list
.resources
.size());
133 SINGLE_AND_MULTI_THREAD_TEST_F(DelegatingRendererTestResources
)