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 ~DelegatingRendererTest() override
{}
20 scoped_ptr
<OutputSurface
> CreateOutputSurface() override
{
21 scoped_ptr
<FakeOutputSurface
> output_surface
=
22 FakeOutputSurface::CreateDelegating3d();
23 output_surface_
= output_surface
.get();
24 return output_surface
.Pass();
28 TestWebGraphicsContext3D
* context3d_
;
29 FakeOutputSurface
* output_surface_
;
32 class DelegatingRendererTestDraw
: public DelegatingRendererTest
{
34 void BeginTest() override
{
35 layer_tree_host()->SetPageScaleFactorAndLimits(1.f
, 0.5f
, 4.f
);
36 PostSetNeedsCommitToMainThread();
39 void AfterTest() override
{}
41 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
42 LayerTreeHostImpl::FrameData
* frame
,
43 DrawResult draw_result
) override
{
44 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
46 const CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
47 EXPECT_FALSE(last_frame
.delegated_frame_data
);
48 EXPECT_FALSE(last_frame
.gl_frame_data
);
49 EXPECT_EQ(0.f
, last_frame
.metadata
.min_page_scale_factor
);
50 EXPECT_EQ(0.f
, last_frame
.metadata
.max_page_scale_factor
);
54 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
55 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
58 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
60 EXPECT_EQ(1u, output_surface_
->num_sent_frames());
62 const CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
63 DelegatedFrameData
* last_frame_data
= last_frame
.delegated_frame_data
.get();
64 ASSERT_TRUE(last_frame
.delegated_frame_data
);
65 EXPECT_FALSE(last_frame
.gl_frame_data
);
66 EXPECT_EQ(host_impl
->DeviceViewport().ToString(),
67 last_frame_data
->render_pass_list
.back()->output_rect
.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
.size());
73 EXPECT_EQ(1u, last_frame
.delegated_frame_data
->render_pass_list
.size());
79 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(DelegatingRendererTestDraw
);
81 class DelegatingRendererTestResources
: public DelegatingRendererTest
{
83 void BeginTest() override
{ PostSetNeedsCommitToMainThread(); }
85 void AfterTest() override
{}
87 DrawResult
PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
88 LayerTreeHostImpl::FrameData
* frame
,
89 DrawResult draw_result
) override
{
90 frame
->render_passes
.clear();
91 frame
->render_passes_by_id
.clear();
93 TestRenderPass
* child_pass
= AddRenderPass(&frame
->render_passes
,
95 gfx::Rect(3, 3, 10, 10),
97 child_pass
->AppendOneOfEveryQuadType(host_impl
->resource_provider(),
100 TestRenderPass
* pass
= AddRenderPass(&frame
->render_passes
,
102 gfx::Rect(3, 3, 10, 10),
104 pass
->AppendOneOfEveryQuadType(
105 host_impl
->resource_provider(), child_pass
->id
);
109 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
110 EXPECT_EQ(0u, output_surface_
->num_sent_frames());
113 void SwapBuffersOnThread(LayerTreeHostImpl
* host_impl
, bool result
) override
{
115 EXPECT_EQ(1u, output_surface_
->num_sent_frames());
117 const CompositorFrame
& last_frame
= output_surface_
->last_sent_frame();
118 ASSERT_TRUE(last_frame
.delegated_frame_data
);
120 EXPECT_EQ(2u, last_frame
.delegated_frame_data
->render_pass_list
.size());
121 // Each render pass has 11 resources in it. And the root render pass has a
122 // mask resource used when drawing the child render pass, as well as its
123 // replica (it's added twice). The number 11 may change if
124 // AppendOneOfEveryQuadType() is updated, and the value here should be
125 // updated accordingly.
126 EXPECT_EQ(24u, last_frame
.delegated_frame_data
->resource_list
.size());
132 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
133 DelegatingRendererTestResources
);