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_utils.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 "third_party/skia/include/core/SkColor.h"
19 #include "third_party/skia/include/core/SkImageFilter.h"
20 #include "ui/gfx/geometry/rect.h"
24 RenderPass
* AddRenderPass(RenderPassList
* pass_list
,
26 const gfx::Rect
& output_rect
,
27 const gfx::Transform
& root_transform
) {
28 scoped_ptr
<RenderPass
> pass(RenderPass::Create());
29 pass
->SetNew(id
, output_rect
, output_rect
, root_transform
);
30 RenderPass
* saved
= pass
.get();
31 pass_list
->push_back(pass
.Pass());
35 SolidColorDrawQuad
* AddQuad(RenderPass
* pass
,
36 const gfx::Rect
& rect
,
38 SharedQuadState
* shared_state
= pass
->CreateAndAppendSharedQuadState();
39 shared_state
->SetAll(gfx::Transform(),
45 SkXfermode::kSrcOver_Mode
,
47 SolidColorDrawQuad
* quad
=
48 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
49 quad
->SetNew(shared_state
, rect
, rect
, color
, false);
53 SolidColorDrawQuad
* AddClippedQuad(RenderPass
* pass
,
54 const gfx::Rect
& rect
,
56 SharedQuadState
* shared_state
= pass
->CreateAndAppendSharedQuadState();
57 shared_state
->SetAll(gfx::Transform(),
63 SkXfermode::kSrcOver_Mode
,
65 SolidColorDrawQuad
* quad
=
66 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
67 quad
->SetNew(shared_state
, rect
, rect
, color
, false);
71 SolidColorDrawQuad
* AddTransformedQuad(RenderPass
* pass
,
72 const gfx::Rect
& rect
,
74 const gfx::Transform
& transform
) {
75 SharedQuadState
* shared_state
= pass
->CreateAndAppendSharedQuadState();
76 shared_state
->SetAll(transform
,
82 SkXfermode::kSrcOver_Mode
,
84 SolidColorDrawQuad
* quad
=
85 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
86 quad
->SetNew(shared_state
, rect
, rect
, color
, false);
90 void AddRenderPassQuad(RenderPass
* to_pass
, RenderPass
* contributing_pass
) {
91 gfx::Rect output_rect
= contributing_pass
->output_rect
;
92 SharedQuadState
* shared_state
= to_pass
->CreateAndAppendSharedQuadState();
93 shared_state
->SetAll(gfx::Transform(),
99 SkXfermode::kSrcOver_Mode
,
101 RenderPassDrawQuad
* quad
=
102 to_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
103 quad
->SetNew(shared_state
,
106 contributing_pass
->id
,
115 void AddRenderPassQuad(RenderPass
* to_pass
,
116 RenderPass
* contributing_pass
,
117 ResourceId mask_resource_id
,
118 const FilterOperations
& filters
,
119 gfx::Transform transform
,
120 SkXfermode::Mode blend_mode
) {
121 gfx::Rect output_rect
= contributing_pass
->output_rect
;
122 SharedQuadState
* shared_state
= to_pass
->CreateAndAppendSharedQuadState();
123 shared_state
->SetAll(transform
,
131 RenderPassDrawQuad
* quad
=
132 to_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
133 gfx::Size
arbitrary_nonzero_size(1, 1);
134 quad
->SetNew(shared_state
,
137 contributing_pass
->id
,
139 gfx::Vector2dF(1.f
, 1.f
),
140 arbitrary_nonzero_size
,
146 static void EmptyReleaseCallback(uint32 sync_point
,
148 BlockingTaskRunner
* main_thread_task_runner
) {}
150 void AddOneOfEveryQuadType(RenderPass
* to_pass
,
151 ResourceProvider
* resource_provider
,
152 RenderPassId child_pass
,
153 uint32_t* sync_point_for_mailbox_texture_quad
) {
154 gfx::Rect
rect(0, 0, 100, 100);
155 gfx::Rect
opaque_rect(10, 10, 80, 80);
156 gfx::Rect
visible_rect(0, 0, 100, 100);
157 const float vertex_opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
159 static const uint32_t kSyncPointForMailboxTextureQuad
= 30;
160 *sync_point_for_mailbox_texture_quad
= kSyncPointForMailboxTextureQuad
;
162 ResourceId resource1
= resource_provider
->CreateResource(
163 gfx::Size(45, 5), GL_CLAMP_TO_EDGE
,
164 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
165 resource_provider
->best_texture_format());
166 resource_provider
->AllocateForTesting(resource1
);
167 ResourceId resource2
= resource_provider
->CreateResource(
168 gfx::Size(346, 61), GL_CLAMP_TO_EDGE
,
169 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
170 resource_provider
->best_texture_format());
171 resource_provider
->AllocateForTesting(resource2
);
172 ResourceId resource3
= resource_provider
->CreateResource(
173 gfx::Size(12, 134), GL_CLAMP_TO_EDGE
,
174 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
175 resource_provider
->best_texture_format());
176 resource_provider
->AllocateForTesting(resource3
);
177 ResourceId resource4
= resource_provider
->CreateResource(
178 gfx::Size(56, 12), GL_CLAMP_TO_EDGE
,
179 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
180 resource_provider
->best_texture_format());
181 resource_provider
->AllocateForTesting(resource4
);
182 gfx::Size
resource5_size(73, 26);
183 ResourceId resource5
= resource_provider
->CreateResource(
184 resource5_size
, GL_CLAMP_TO_EDGE
,
185 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
186 resource_provider
->best_texture_format());
187 resource_provider
->AllocateForTesting(resource5
);
188 ResourceId resource6
= resource_provider
->CreateResource(
189 gfx::Size(64, 92), GL_CLAMP_TO_EDGE
,
190 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
191 resource_provider
->best_texture_format());
192 resource_provider
->AllocateForTesting(resource6
);
193 ResourceId resource7
= resource_provider
->CreateResource(
194 gfx::Size(9, 14), GL_CLAMP_TO_EDGE
,
195 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
196 resource_provider
->best_texture_format());
197 resource_provider
->AllocateForTesting(resource7
);
199 unsigned target
= GL_TEXTURE_2D
;
200 gpu::Mailbox gpu_mailbox
;
201 memcpy(gpu_mailbox
.name
, "Hello world", strlen("Hello world") + 1);
202 scoped_ptr
<SingleReleaseCallbackImpl
> callback
=
203 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback
));
204 TextureMailbox
mailbox(gpu_mailbox
, target
,
205 *sync_point_for_mailbox_texture_quad
);
206 ResourceId resource8
= resource_provider
->CreateResourceFromTextureMailbox(
207 mailbox
, callback
.Pass());
208 resource_provider
->AllocateForTesting(resource8
);
210 SharedQuadState
* shared_state
= to_pass
->CreateAndAppendSharedQuadState();
211 shared_state
->SetAll(gfx::Transform(), rect
.size(), rect
, rect
, false, 1,
212 SkXfermode::kSrcOver_Mode
, 0);
214 DebugBorderDrawQuad
* debug_border_quad
=
215 to_pass
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
216 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
218 IOSurfaceDrawQuad
* io_surface_quad
=
219 to_pass
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
220 io_surface_quad
->SetNew(shared_state
, rect
, opaque_rect
, visible_rect
,
221 gfx::Size(50, 50), resource7
,
222 IOSurfaceDrawQuad::FLIPPED
, false);
224 if (child_pass
.layer_id
) {
225 RenderPassDrawQuad
* render_pass_quad
=
226 to_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
227 render_pass_quad
->SetNew(shared_state
, rect
, visible_rect
, child_pass
,
228 resource5
, gfx::Vector2dF(1.f
, 1.f
),
229 resource5_size
, FilterOperations(),
230 gfx::Vector2dF(), FilterOperations());
232 RenderPassDrawQuad
* render_pass_replica_quad
=
233 to_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
234 render_pass_replica_quad
->SetNew(
235 shared_state
, rect
, visible_rect
, child_pass
, resource5
,
236 gfx::Vector2dF(1.f
, 1.f
), resource5_size
, FilterOperations(),
237 gfx::Vector2dF(), FilterOperations());
240 SolidColorDrawQuad
* solid_color_quad
=
241 to_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
242 solid_color_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
,
245 StreamVideoDrawQuad
* stream_video_quad
=
246 to_pass
->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
247 stream_video_quad
->SetNew(shared_state
, rect
, opaque_rect
, visible_rect
,
248 resource6
, gfx::Size(), false, gfx::Transform());
250 TextureDrawQuad
* texture_quad
=
251 to_pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
252 texture_quad
->SetNew(shared_state
, rect
, opaque_rect
, visible_rect
, resource1
,
253 false, gfx::PointF(0.f
, 0.f
), gfx::PointF(1.f
, 1.f
),
254 SK_ColorTRANSPARENT
, vertex_opacity
, false, false);
256 TextureDrawQuad
* mailbox_texture_quad
=
257 to_pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
258 mailbox_texture_quad
->SetNew(shared_state
, rect
, opaque_rect
, visible_rect
,
259 resource8
, false, gfx::PointF(0.f
, 0.f
),
260 gfx::PointF(1.f
, 1.f
), SK_ColorTRANSPARENT
,
261 vertex_opacity
, false, false);
263 TileDrawQuad
* scaled_tile_quad
=
264 to_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
265 scaled_tile_quad
->SetNew(shared_state
, rect
, opaque_rect
, visible_rect
,
266 resource2
, gfx::RectF(0, 0, 50, 50),
267 gfx::Size(50, 50), false, false);
269 SharedQuadState
* transformed_state
=
270 to_pass
->CreateAndAppendSharedQuadState();
271 transformed_state
->CopyFrom(shared_state
);
272 gfx::Transform rotation
;
274 transformed_state
->quad_to_target_transform
=
275 transformed_state
->quad_to_target_transform
* rotation
;
276 TileDrawQuad
* transformed_tile_quad
=
277 to_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
278 transformed_tile_quad
->SetNew(
279 transformed_state
, rect
, opaque_rect
, visible_rect
, resource3
,
280 gfx::RectF(0, 0, 100, 100), gfx::Size(100, 100), false, false);
282 SharedQuadState
* shared_state2
= to_pass
->CreateAndAppendSharedQuadState();
283 shared_state
->SetAll(gfx::Transform(), rect
.size(), rect
, rect
, false, 1,
284 SkXfermode::kSrcOver_Mode
, 0);
286 TileDrawQuad
* tile_quad
= to_pass
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
287 tile_quad
->SetNew(shared_state2
, rect
, opaque_rect
, visible_rect
, resource4
,
288 gfx::RectF(0, 0, 100, 100), gfx::Size(100, 100), false,
291 ResourceId plane_resources
[4];
292 for (int i
= 0; i
< 4; ++i
) {
293 plane_resources
[i
] = resource_provider
->CreateResource(
294 gfx::Size(20, 12), GL_CLAMP_TO_EDGE
,
295 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
296 resource_provider
->best_texture_format());
297 resource_provider
->AllocateForTesting(plane_resources
[i
]);
299 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601
;
300 YUVVideoDrawQuad
* yuv_quad
=
301 to_pass
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
302 yuv_quad
->SetNew(shared_state2
, rect
, opaque_rect
, visible_rect
,
303 gfx::RectF(.0f
, .0f
, 100.0f
, 100.0f
),
304 gfx::RectF(.0f
, .0f
, 50.0f
, 50.0f
), gfx::Size(100, 100),
305 gfx::Size(50, 50), plane_resources
[0], plane_resources
[1],
306 plane_resources
[2], plane_resources
[3], color_space
);