Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / output / delegating_renderer_unittest.cc
blobb32e9a369fc6a66b8f47bbe31200aa775f501fea
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_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace cc {
14 class DelegatingRendererTest : public LayerTreeTest {
15 public:
16 DelegatingRendererTest() : LayerTreeTest(), output_surface_(NULL) {}
17 ~DelegatingRendererTest() override {}
19 scoped_ptr<OutputSurface> CreateOutputSurface() override {
20 scoped_ptr<FakeOutputSurface> output_surface =
21 FakeOutputSurface::CreateDelegating3d();
22 output_surface_ = output_surface.get();
23 return output_surface.Pass();
26 protected:
27 TestWebGraphicsContext3D* context3d_;
28 FakeOutputSurface* output_surface_;
31 class DelegatingRendererTestDraw : public DelegatingRendererTest {
32 public:
33 void BeginTest() override {
34 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
35 PostSetNeedsCommitToMainThread();
38 void AfterTest() override {}
40 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
41 LayerTreeHostImpl::FrameData* frame,
42 DrawResult draw_result) override {
43 EXPECT_EQ(0u, output_surface_->num_sent_frames());
45 const CompositorFrame& last_frame = output_surface_->last_sent_frame();
46 EXPECT_FALSE(last_frame.delegated_frame_data);
47 EXPECT_FALSE(last_frame.gl_frame_data);
48 EXPECT_EQ(0.f, last_frame.metadata.min_page_scale_factor);
49 EXPECT_EQ(0.f, last_frame.metadata.max_page_scale_factor);
50 return DRAW_SUCCESS;
53 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
54 EXPECT_EQ(0u, output_surface_->num_sent_frames());
57 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override {
58 EXPECT_TRUE(result);
59 EXPECT_EQ(1u, output_surface_->num_sent_frames());
61 const CompositorFrame& last_frame = output_surface_->last_sent_frame();
62 DelegatedFrameData* last_frame_data = last_frame.delegated_frame_data.get();
63 ASSERT_TRUE(last_frame.delegated_frame_data);
64 EXPECT_FALSE(last_frame.gl_frame_data);
65 EXPECT_EQ(host_impl->DeviceViewport().ToString(),
66 last_frame_data->render_pass_list.back()->output_rect.ToString());
67 EXPECT_EQ(0.5f, last_frame.metadata.min_page_scale_factor);
68 EXPECT_EQ(4.f, last_frame.metadata.max_page_scale_factor);
70 EXPECT_EQ(
71 0u, last_frame.delegated_frame_data->resource_list.size());
72 EXPECT_EQ(1u, last_frame.delegated_frame_data->render_pass_list.size());
74 EndTest();
78 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(DelegatingRendererTestDraw);
80 class DelegatingRendererTestResources : public DelegatingRendererTest {
81 public:
82 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
84 void AfterTest() override {}
86 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
87 LayerTreeHostImpl::FrameData* frame,
88 DrawResult draw_result) override {
89 frame->render_passes.clear();
90 frame->render_passes_by_id.clear();
92 RenderPass* child_pass =
93 AddRenderPass(&frame->render_passes, RenderPassId(2, 1),
94 gfx::Rect(3, 3, 10, 10), gfx::Transform());
95 uint32_t mailbox_sync_point;
96 AddOneOfEveryQuadType(child_pass, host_impl->resource_provider(),
97 RenderPassId(0, 0), &mailbox_sync_point);
99 RenderPass* pass = AddRenderPass(&frame->render_passes, RenderPassId(1, 1),
100 gfx::Rect(3, 3, 10, 10), gfx::Transform());
101 AddOneOfEveryQuadType(pass, host_impl->resource_provider(), child_pass->id,
102 &mailbox_sync_point);
103 return draw_result;
106 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
107 EXPECT_EQ(0u, output_surface_->num_sent_frames());
110 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override {
111 EXPECT_TRUE(result);
112 EXPECT_EQ(1u, output_surface_->num_sent_frames());
114 const CompositorFrame& last_frame = output_surface_->last_sent_frame();
115 ASSERT_TRUE(last_frame.delegated_frame_data);
117 EXPECT_EQ(2u, last_frame.delegated_frame_data->render_pass_list.size());
118 // Each render pass has 11 resources in it. And the root render pass has a
119 // mask resource used when drawing the child render pass, as well as its
120 // replica (it's added twice). The number 11 may change if
121 // AppendOneOfEveryQuadType() is updated, and the value here should be
122 // updated accordingly.
123 EXPECT_EQ(24u, last_frame.delegated_frame_data->resource_list.size());
125 EndTest();
129 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
130 DelegatingRendererTestResources);
132 } // namespace cc