Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / test / render_pass_test_common.cc
blobc4f6310bcbfeb49a716e42831c9d547fcf5db410
1 // Copyright 2012 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/test/render_pass_test_common.h"
7 #include "cc/quads/checkerboard_draw_quad.h"
8 #include "cc/quads/debug_border_draw_quad.h"
9 #include "cc/quads/io_surface_draw_quad.h"
10 #include "cc/quads/render_pass_draw_quad.h"
11 #include "cc/quads/shared_quad_state.h"
12 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/quads/stream_video_draw_quad.h"
14 #include "cc/quads/texture_draw_quad.h"
15 #include "cc/quads/tile_draw_quad.h"
16 #include "cc/quads/yuv_video_draw_quad.h"
17 #include "cc/resources/resource_provider.h"
18 #include "ui/gfx/transform.h"
20 namespace cc {
22 void TestRenderPass::AppendQuad(scoped_ptr<cc::DrawQuad> quad) {
23 quad_list.push_back(quad.Pass());
26 void TestRenderPass::AppendSharedQuadState(
27 scoped_ptr<cc::SharedQuadState> state) {
28 shared_quad_state_list.push_back(state.Pass());
31 void TestRenderPass::AppendOneOfEveryQuadType(
32 cc::ResourceProvider* resource_provider, RenderPass::Id child_pass) {
33 gfx::Rect rect(0, 0, 100, 100);
34 gfx::Rect opaque_rect(10, 10, 80, 80);
35 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
36 cc::ResourceProvider::ResourceId resource1 =
37 resource_provider->CreateResource(
38 gfx::Size(45, 5),
39 resource_provider->best_texture_format(),
40 ResourceProvider::TextureUsageAny);
41 resource_provider->AllocateForTesting(resource1);
42 cc::ResourceProvider::ResourceId resource2 =
43 resource_provider->CreateResource(
44 gfx::Size(346, 61),
45 resource_provider->best_texture_format(),
46 ResourceProvider::TextureUsageAny);
47 resource_provider->AllocateForTesting(resource2);
48 cc::ResourceProvider::ResourceId resource3 =
49 resource_provider->CreateResource(
50 gfx::Size(12, 134),
51 resource_provider->best_texture_format(),
52 ResourceProvider::TextureUsageAny);
53 resource_provider->AllocateForTesting(resource3);
54 cc::ResourceProvider::ResourceId resource4 =
55 resource_provider->CreateResource(
56 gfx::Size(56, 12),
57 resource_provider->best_texture_format(),
58 ResourceProvider::TextureUsageAny);
59 resource_provider->AllocateForTesting(resource4);
60 cc::ResourceProvider::ResourceId resource5 =
61 resource_provider->CreateResource(
62 gfx::Size(73, 26),
63 resource_provider->best_texture_format(),
64 ResourceProvider::TextureUsageAny);
65 resource_provider->AllocateForTesting(resource5);
66 cc::ResourceProvider::ResourceId resource6 =
67 resource_provider->CreateResource(
68 gfx::Size(64, 92),
69 resource_provider->best_texture_format(),
70 ResourceProvider::TextureUsageAny);
71 resource_provider->AllocateForTesting(resource6);
72 cc::ResourceProvider::ResourceId resource7 =
73 resource_provider->CreateResource(
74 gfx::Size(9, 14),
75 resource_provider->best_texture_format(),
76 ResourceProvider::TextureUsageAny);
77 resource_provider->AllocateForTesting(resource7);
79 scoped_ptr<cc::SharedQuadState> shared_state = cc::SharedQuadState::Create();
80 shared_state->SetAll(gfx::Transform(),
81 rect.size(),
82 rect,
83 rect,
84 false,
85 1);
87 scoped_ptr<cc::CheckerboardDrawQuad> checkerboard_quad =
88 cc::CheckerboardDrawQuad::Create();
89 checkerboard_quad->SetNew(shared_state.get(),
90 rect,
91 SK_ColorRED);
92 AppendQuad(checkerboard_quad.PassAs<DrawQuad>());
94 scoped_ptr<cc::DebugBorderDrawQuad> debug_border_quad =
95 cc::DebugBorderDrawQuad::Create();
96 debug_border_quad->SetNew(shared_state.get(),
97 rect,
98 SK_ColorRED,
99 1);
100 AppendQuad(debug_border_quad.PassAs<DrawQuad>());
102 scoped_ptr<cc::IOSurfaceDrawQuad> io_surface_quad =
103 cc::IOSurfaceDrawQuad::Create();
104 io_surface_quad->SetNew(shared_state.get(),
105 rect,
106 opaque_rect,
107 gfx::Size(50, 50),
108 resource7,
109 cc::IOSurfaceDrawQuad::FLIPPED);
110 AppendQuad(io_surface_quad.PassAs<DrawQuad>());
112 if (child_pass.layer_id) {
113 scoped_ptr<cc::RenderPassDrawQuad> render_pass_quad =
114 cc::RenderPassDrawQuad::Create();
115 render_pass_quad->SetNew(shared_state.get(),
116 rect,
117 child_pass,
118 false,
119 resource5,
120 rect,
121 gfx::RectF(),
122 WebKit::WebFilterOperations(),
123 skia::RefPtr<SkImageFilter>(),
124 WebKit::WebFilterOperations());
125 AppendQuad(render_pass_quad.PassAs<DrawQuad>());
127 scoped_ptr<cc::RenderPassDrawQuad> render_pass_replica_quad =
128 cc::RenderPassDrawQuad::Create();
129 render_pass_replica_quad->SetNew(shared_state.get(),
130 rect,
131 child_pass,
132 true,
133 resource5,
134 rect,
135 gfx::RectF(),
136 WebKit::WebFilterOperations(),
137 skia::RefPtr<SkImageFilter>(),
138 WebKit::WebFilterOperations());
139 AppendQuad(render_pass_replica_quad.PassAs<DrawQuad>());
142 scoped_ptr<cc::SolidColorDrawQuad> solid_color_quad =
143 cc::SolidColorDrawQuad::Create();
144 solid_color_quad->SetNew(shared_state.get(),
145 rect,
146 SK_ColorRED);
147 AppendQuad(solid_color_quad.PassAs<DrawQuad>());
149 scoped_ptr<cc::StreamVideoDrawQuad> stream_video_quad =
150 cc::StreamVideoDrawQuad::Create();
151 stream_video_quad->SetNew(shared_state.get(),
152 rect,
153 opaque_rect,
154 resource6,
155 gfx::Transform());
156 AppendQuad(stream_video_quad.PassAs<DrawQuad>());
158 scoped_ptr<cc::TextureDrawQuad> texture_quad =
159 cc::TextureDrawQuad::Create();
160 texture_quad->SetNew(shared_state.get(),
161 rect,
162 opaque_rect,
163 resource1,
164 false,
165 gfx::PointF(0.f, 0.f),
166 gfx::PointF(1.f, 1.f),
167 vertex_opacity,
168 false);
169 AppendQuad(texture_quad.PassAs<DrawQuad>());
171 scoped_ptr<cc::TileDrawQuad> scaled_tile_quad =
172 cc::TileDrawQuad::Create();
173 scaled_tile_quad->SetNew(shared_state.get(),
174 rect,
175 opaque_rect,
176 resource2,
177 gfx::RectF(0, 0, 50, 50),
178 gfx::Size(50, 50),
179 false);
180 AppendQuad(scaled_tile_quad.PassAs<DrawQuad>());
182 scoped_ptr<cc::SharedQuadState> transformed_state = shared_state->Copy();
183 gfx::Transform rotation;
184 rotation.Rotate(45);
185 transformed_state->content_to_target_transform =
186 transformed_state->content_to_target_transform * rotation;
187 scoped_ptr<cc::TileDrawQuad> transformed_tile_quad =
188 cc::TileDrawQuad::Create();
189 transformed_tile_quad->SetNew(transformed_state.get(),
190 rect,
191 opaque_rect,
192 resource3,
193 gfx::RectF(0, 0, 100, 100),
194 gfx::Size(100, 100),
195 false);
196 AppendQuad(transformed_tile_quad.PassAs<DrawQuad>());
198 scoped_ptr<cc::TileDrawQuad> tile_quad =
199 cc::TileDrawQuad::Create();
200 tile_quad->SetNew(shared_state.get(),
201 rect,
202 opaque_rect,
203 resource4,
204 gfx::RectF(0, 0, 100, 100),
205 gfx::Size(100, 100),
206 false);
207 AppendQuad(tile_quad.PassAs<DrawQuad>());
209 ResourceProvider::ResourceId plane_resources[3];
210 for (int i = 0; i < 3; ++i) {
211 plane_resources[i] =
212 resource_provider->CreateResource(
213 gfx::Size(20, 12),
214 resource_provider->best_texture_format(),
215 ResourceProvider::TextureUsageAny);
216 resource_provider->AllocateForTesting(plane_resources[i]);
218 scoped_ptr<cc::YUVVideoDrawQuad> yuv_quad =
219 cc::YUVVideoDrawQuad::Create();
220 yuv_quad->SetNew(shared_state.get(),
221 rect,
222 opaque_rect,
223 gfx::Size(100, 100),
224 plane_resources[0],
225 plane_resources[1],
226 plane_resources[2]);
227 AppendQuad(yuv_quad.PassAs<DrawQuad>());
229 AppendSharedQuadState(transformed_state.Pass());
230 AppendSharedQuadState(shared_state.Pass());
233 } // namespace cc