Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / output / delegating_renderer_unittest.cc
blob3238d2d90284888455a6d37c4ae6a419f0e13224
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"
13 namespace cc {
15 class DelegatingRendererTest : public LayerTreeTest {
16 public:
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();
27 protected:
28 TestWebGraphicsContext3D* context3d_;
29 FakeOutputSurface* output_surface_;
32 class DelegatingRendererTestDraw : public DelegatingRendererTest {
33 public:
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);
51 return DRAW_SUCCESS;
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 {
59 EXPECT_TRUE(result);
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);
71 EXPECT_EQ(
72 0u, last_frame.delegated_frame_data->resource_list.size());
73 EXPECT_EQ(1u, last_frame.delegated_frame_data->render_pass_list.size());
75 EndTest();
79 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(DelegatingRendererTestDraw);
81 class DelegatingRendererTestResources : public DelegatingRendererTest {
82 public:
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,
94 RenderPassId(2, 1),
95 gfx::Rect(3, 3, 10, 10),
96 gfx::Transform());
97 child_pass->AppendOneOfEveryQuadType(host_impl->resource_provider(),
98 RenderPassId(0, 0));
100 TestRenderPass* pass = AddRenderPass(&frame->render_passes,
101 RenderPassId(1, 1),
102 gfx::Rect(3, 3, 10, 10),
103 gfx::Transform());
104 pass->AppendOneOfEveryQuadType(
105 host_impl->resource_provider(), child_pass->id);
106 return draw_result;
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 {
114 EXPECT_TRUE(result);
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());
128 EndTest();
132 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
133 DelegatingRendererTestResources);
135 } // namespace cc