blob: 2084c79c2b75281b4c53dd2be127681de85ef2f7 [file] [log] [blame]
[email protected]05469632013-01-16 03:41:001// 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.
4
5#include "cc/delegating_renderer.h"
6
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"
12
13namespace cc {
14
15class DelegatingRendererTest : public ThreadedTest {
16 public:
17 DelegatingRendererTest() : ThreadedTest(), output_surface_(NULL) {}
18 virtual ~DelegatingRendererTest() {}
19
20 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE {
[email protected]c8756fbe2013-02-12 01:53:4921 scoped_ptr<TestWebGraphicsContext3D> context3d =
22 TestWebGraphicsContext3D::Create(
[email protected]05469632013-01-16 03:41:0023 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>();
30 }
31
32 protected:
[email protected]c8756fbe2013-02-12 01:53:4933 TestWebGraphicsContext3D* context3d_;
[email protected]05469632013-01-16 03:41:0034 FakeOutputSurface* output_surface_;
35};
36
37class DelegatingRendererTestDraw : public DelegatingRendererTest {
38 public:
39 virtual void beginTest() OVERRIDE {
40 m_layerTreeHost->setPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
41 postSetNeedsCommitToMainThread();
42 }
43
44 virtual void afterTest() OVERRIDE {}
45
46 virtual bool prepareToDrawOnThread(
47 LayerTreeHostImpl*, LayerTreeHostImpl::FrameData& frame, bool result)
48 OVERRIDE {
49 EXPECT_EQ(0u, output_surface_->num_sent_frames());
50
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);
56 return true;
57 }
58
59 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
60 EXPECT_EQ(1u, output_surface_->num_sent_frames());
61
62 CompositorFrame& last_frame = output_surface_->last_sent_frame();
[email protected]86306a322013-02-23 01:20:3963 DelegatedFrameData* last_frame_data = last_frame.delegated_frame_data.get();
[email protected]05469632013-01-16 03:41:0064 ASSERT_TRUE(last_frame.delegated_frame_data);
65 EXPECT_FALSE(last_frame.gl_frame_data);
66 EXPECT_EQ(
[email protected]90ec9872013-03-08 02:28:1867 gfx::Rect(host_impl->DeviceViewportSize()).ToString(),
[email protected]86306a322013-02-23 01:20:3968 last_frame_data->render_pass_list.back()->output_rect.ToString());
[email protected]05469632013-01-16 03:41:0069 EXPECT_EQ(0.5f, last_frame.metadata.min_page_scale_factor);
70 EXPECT_EQ(4.f, last_frame.metadata.max_page_scale_factor);
71
72 EXPECT_EQ(
[email protected]09831f7f2013-02-27 03:32:1573 0u, last_frame.delegated_frame_data->resource_list.size());
[email protected]05469632013-01-16 03:41:0074 EXPECT_EQ(1u, last_frame.delegated_frame_data->render_pass_list.size());
75
76 endTest();
77 }
78};
79
80SINGLE_AND_MULTI_THREAD_TEST_F(DelegatingRendererTestDraw)
81
82class DelegatingRendererTestResources : public DelegatingRendererTest {
83 public:
84 virtual void beginTest() OVERRIDE {
85 postSetNeedsCommitToMainThread();
86 }
87
88 virtual void afterTest() OVERRIDE {}
89
90 virtual bool prepareToDrawOnThread(
91 LayerTreeHostImpl* host_impl,
92 LayerTreeHostImpl::FrameData& frame,
93 bool result) OVERRIDE {
94
95 frame.renderPasses.clear();
96 frame.renderPassesById.clear();
97
98 TestRenderPass* child_pass = addRenderPass(
99 frame.renderPasses,
100 RenderPass::Id(2, 1),
101 gfx::Rect(3, 3, 10, 10),
102 gfx::Transform());
103 child_pass->AppendOneOfEveryQuadType(
104 host_impl->resourceProvider(), RenderPass::Id(0, 0));
105
106 TestRenderPass* pass = addRenderPass(
107 frame.renderPasses,
108 RenderPass::Id(1, 1),
109 gfx::Rect(3, 3, 10, 10),
110 gfx::Transform());
111 pass->AppendOneOfEveryQuadType(
112 host_impl->resourceProvider(), child_pass->id);
113 return true;
114 }
115
116 virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
117 EXPECT_EQ(1u, output_surface_->num_sent_frames());
118
119 CompositorFrame& last_frame = output_surface_->last_sent_frame();
120 ASSERT_TRUE(last_frame.delegated_frame_data);
121
122 EXPECT_EQ(2u, last_frame.delegated_frame_data->render_pass_list.size());
123 // Each render pass has 7 resources in it. And the root render pass has a
124 // mask resource used when drawing the child render pass. The number 7 may
125 // change if AppendOneOfEveryQuadType is updated, and the value here should
126 // be updated accordingly.
127 EXPECT_EQ(
[email protected]09831f7f2013-02-27 03:32:15128 15u, last_frame.delegated_frame_data->resource_list.size());
[email protected]05469632013-01-16 03:41:00129
130 endTest();
131 }
132};
133
134SINGLE_AND_MULTI_THREAD_TEST_F(DelegatingRendererTestResources)
135
136} // namespace cc