1 // Copyright (c) 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 "content/common/cc_messages.h"
11 #include "cc/output/compositor_frame.h"
12 #include "content/public/common/common_param_traits.h"
13 #include "ipc/ipc_message.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/khronos/GLES2/gl2ext.h"
16 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
19 #include "base/file_descriptor_posix.h"
22 using cc::DelegatedFrameData
;
23 using cc::DebugBorderDrawQuad
;
25 using cc::FilterOperation
;
26 using cc::FilterOperations
;
27 using cc::IOSurfaceDrawQuad
;
28 using cc::PictureDrawQuad
;
30 using cc::RenderPassId
;
31 using cc::RenderPassDrawQuad
;
33 using cc::ResourceProvider
;
34 using cc::SharedQuadState
;
35 using cc::SolidColorDrawQuad
;
36 using cc::SurfaceDrawQuad
;
37 using cc::TextureDrawQuad
;
38 using cc::TileDrawQuad
;
39 using cc::TransferableResource
;
40 using cc::StreamVideoDrawQuad
;
41 using cc::YUVVideoDrawQuad
;
47 class CCMessagesTest
: public testing::Test
{
49 void Compare(const RenderPass
* a
, const RenderPass
* b
) {
50 EXPECT_EQ(a
->id
, b
->id
);
51 EXPECT_EQ(a
->output_rect
.ToString(), b
->output_rect
.ToString());
52 EXPECT_EQ(a
->damage_rect
.ToString(), b
->damage_rect
.ToString());
53 EXPECT_EQ(a
->transform_to_root_target
, b
->transform_to_root_target
);
54 EXPECT_EQ(a
->has_transparent_background
, b
->has_transparent_background
);
55 EXPECT_EQ(a
->referenced_surfaces
, b
->referenced_surfaces
);
58 void Compare(const SharedQuadState
* a
, const SharedQuadState
* b
) {
59 EXPECT_EQ(a
->quad_to_target_transform
, b
->quad_to_target_transform
);
60 EXPECT_EQ(a
->quad_layer_bounds
, b
->quad_layer_bounds
);
61 EXPECT_EQ(a
->visible_quad_layer_rect
, b
->visible_quad_layer_rect
);
62 EXPECT_EQ(a
->clip_rect
, b
->clip_rect
);
63 EXPECT_EQ(a
->is_clipped
, b
->is_clipped
);
64 EXPECT_EQ(a
->opacity
, b
->opacity
);
65 EXPECT_EQ(a
->blend_mode
, b
->blend_mode
);
66 EXPECT_EQ(a
->sorting_context_id
, b
->sorting_context_id
);
69 void Compare(const DrawQuad
* a
, const DrawQuad
* b
) {
70 ASSERT_NE(DrawQuad::INVALID
, a
->material
);
71 ASSERT_EQ(a
->material
, b
->material
);
72 EXPECT_EQ(a
->rect
.ToString(), b
->rect
.ToString());
73 EXPECT_EQ(a
->opaque_rect
.ToString(), b
->opaque_rect
.ToString());
74 EXPECT_EQ(a
->visible_rect
.ToString(), b
->visible_rect
.ToString());
75 EXPECT_EQ(a
->needs_blending
, b
->needs_blending
);
77 Compare(a
->shared_quad_state
, b
->shared_quad_state
);
79 switch (a
->material
) {
80 case DrawQuad::DEBUG_BORDER
:
81 Compare(DebugBorderDrawQuad::MaterialCast(a
),
82 DebugBorderDrawQuad::MaterialCast(b
));
84 case DrawQuad::IO_SURFACE_CONTENT
:
85 Compare(IOSurfaceDrawQuad::MaterialCast(a
),
86 IOSurfaceDrawQuad::MaterialCast(b
));
88 case DrawQuad::PICTURE_CONTENT
:
89 Compare(PictureDrawQuad::MaterialCast(a
),
90 PictureDrawQuad::MaterialCast(b
));
92 case DrawQuad::RENDER_PASS
:
93 Compare(RenderPassDrawQuad::MaterialCast(a
),
94 RenderPassDrawQuad::MaterialCast(b
));
96 case DrawQuad::TEXTURE_CONTENT
:
97 Compare(TextureDrawQuad::MaterialCast(a
),
98 TextureDrawQuad::MaterialCast(b
));
100 case DrawQuad::TILED_CONTENT
:
101 Compare(TileDrawQuad::MaterialCast(a
),
102 TileDrawQuad::MaterialCast(b
));
104 case DrawQuad::SOLID_COLOR
:
105 Compare(SolidColorDrawQuad::MaterialCast(a
),
106 SolidColorDrawQuad::MaterialCast(b
));
108 case DrawQuad::STREAM_VIDEO_CONTENT
:
109 Compare(StreamVideoDrawQuad::MaterialCast(a
),
110 StreamVideoDrawQuad::MaterialCast(b
));
112 case DrawQuad::SURFACE_CONTENT
:
113 Compare(SurfaceDrawQuad::MaterialCast(a
),
114 SurfaceDrawQuad::MaterialCast(b
));
116 case DrawQuad::YUV_VIDEO_CONTENT
:
117 Compare(YUVVideoDrawQuad::MaterialCast(a
),
118 YUVVideoDrawQuad::MaterialCast(b
));
120 case DrawQuad::INVALID
:
125 void Compare(const DebugBorderDrawQuad
* a
, const DebugBorderDrawQuad
* b
) {
126 EXPECT_EQ(a
->color
, b
->color
);
127 EXPECT_EQ(a
->width
, b
->width
);
130 void Compare(const IOSurfaceDrawQuad
* a
, const IOSurfaceDrawQuad
* b
) {
131 EXPECT_EQ(a
->io_surface_size
.ToString(), b
->io_surface_size
.ToString());
132 EXPECT_EQ(a
->io_surface_resource_id(), b
->io_surface_resource_id());
133 EXPECT_EQ(a
->orientation
, b
->orientation
);
136 void Compare(const RenderPassDrawQuad
* a
, const RenderPassDrawQuad
* b
) {
137 EXPECT_EQ(a
->render_pass_id
, b
->render_pass_id
);
138 EXPECT_EQ(a
->mask_resource_id(), b
->mask_resource_id());
139 EXPECT_EQ(a
->mask_uv_scale
.ToString(), b
->mask_uv_scale
.ToString());
140 EXPECT_EQ(a
->mask_texture_size
.ToString(), b
->mask_texture_size
.ToString());
141 EXPECT_EQ(a
->filters
.size(), b
->filters
.size());
142 for (size_t i
= 0; i
< a
->filters
.size(); ++i
) {
143 if (a
->filters
.at(i
).type() != cc::FilterOperation::REFERENCE
) {
144 EXPECT_EQ(a
->filters
.at(i
), b
->filters
.at(i
));
146 EXPECT_EQ(b
->filters
.at(i
).type(), cc::FilterOperation::REFERENCE
);
147 EXPECT_EQ(a
->filters
.at(i
).image_filter()->countInputs(),
148 b
->filters
.at(i
).image_filter()->countInputs());
151 EXPECT_EQ(a
->filters_scale
, b
->filters_scale
);
152 EXPECT_EQ(a
->background_filters
, b
->background_filters
);
155 void Compare(const SolidColorDrawQuad
* a
, const SolidColorDrawQuad
* b
) {
156 EXPECT_EQ(a
->color
, b
->color
);
157 EXPECT_EQ(a
->force_anti_aliasing_off
, b
->force_anti_aliasing_off
);
160 void Compare(const StreamVideoDrawQuad
* a
, const StreamVideoDrawQuad
* b
) {
161 EXPECT_EQ(a
->resource_id(), b
->resource_id());
162 EXPECT_EQ(a
->resource_size_in_pixels(), b
->resource_size_in_pixels());
163 EXPECT_EQ(a
->allow_overlay(), b
->allow_overlay());
164 EXPECT_EQ(a
->matrix
, b
->matrix
);
167 void Compare(const SurfaceDrawQuad
* a
, const SurfaceDrawQuad
* b
) {
168 EXPECT_EQ(a
->surface_id
, b
->surface_id
);
171 void Compare(const TextureDrawQuad
* a
, const TextureDrawQuad
* b
) {
172 EXPECT_EQ(a
->resource_id(), b
->resource_id());
173 EXPECT_EQ(a
->resource_size_in_pixels(), b
->resource_size_in_pixels());
174 EXPECT_EQ(a
->allow_overlay(), b
->allow_overlay());
175 EXPECT_EQ(a
->premultiplied_alpha
, b
->premultiplied_alpha
);
176 EXPECT_EQ(a
->uv_top_left
, b
->uv_top_left
);
177 EXPECT_EQ(a
->uv_bottom_right
, b
->uv_bottom_right
);
178 EXPECT_EQ(a
->background_color
, b
->background_color
);
179 EXPECT_EQ(a
->vertex_opacity
[0], b
->vertex_opacity
[0]);
180 EXPECT_EQ(a
->vertex_opacity
[1], b
->vertex_opacity
[1]);
181 EXPECT_EQ(a
->vertex_opacity
[2], b
->vertex_opacity
[2]);
182 EXPECT_EQ(a
->vertex_opacity
[3], b
->vertex_opacity
[3]);
183 EXPECT_EQ(a
->y_flipped
, b
->y_flipped
);
184 EXPECT_EQ(a
->nearest_neighbor
, b
->nearest_neighbor
);
187 void Compare(const TileDrawQuad
* a
, const TileDrawQuad
* b
) {
188 EXPECT_EQ(a
->resource_id(), b
->resource_id());
189 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
190 EXPECT_EQ(a
->texture_size
, b
->texture_size
);
191 EXPECT_EQ(a
->swizzle_contents
, b
->swizzle_contents
);
192 EXPECT_EQ(a
->nearest_neighbor
, b
->nearest_neighbor
);
195 void Compare(const YUVVideoDrawQuad
* a
, const YUVVideoDrawQuad
* b
) {
196 EXPECT_EQ(a
->ya_tex_coord_rect
, b
->ya_tex_coord_rect
);
197 EXPECT_EQ(a
->uv_tex_coord_rect
, b
->uv_tex_coord_rect
);
198 EXPECT_EQ(a
->ya_tex_size
, b
->ya_tex_size
);
199 EXPECT_EQ(a
->uv_tex_size
, b
->uv_tex_size
);
200 EXPECT_EQ(a
->y_plane_resource_id(), b
->y_plane_resource_id());
201 EXPECT_EQ(a
->u_plane_resource_id(), b
->u_plane_resource_id());
202 EXPECT_EQ(a
->v_plane_resource_id(), b
->v_plane_resource_id());
203 EXPECT_EQ(a
->a_plane_resource_id(), b
->a_plane_resource_id());
204 EXPECT_EQ(a
->color_space
, b
->color_space
);
207 void Compare(const TransferableResource
& a
, const TransferableResource
& b
) {
208 EXPECT_EQ(a
.id
, b
.id
);
209 EXPECT_EQ(a
.format
, b
.format
);
210 EXPECT_EQ(a
.filter
, b
.filter
);
211 EXPECT_EQ(a
.size
.ToString(), b
.size
.ToString());
212 for (size_t i
= 0; i
< arraysize(a
.mailbox_holder
.mailbox
.name
); ++i
) {
213 EXPECT_EQ(a
.mailbox_holder
.mailbox
.name
[i
],
214 b
.mailbox_holder
.mailbox
.name
[i
]);
216 EXPECT_EQ(a
.mailbox_holder
.texture_target
, b
.mailbox_holder
.texture_target
);
217 EXPECT_EQ(a
.mailbox_holder
.sync_point
, b
.mailbox_holder
.sync_point
);
218 EXPECT_EQ(a
.allow_overlay
, b
.allow_overlay
);
222 TEST_F(CCMessagesTest
, AllQuads
) {
223 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
225 Transform arbitrary_matrix1
;
226 arbitrary_matrix1
.Scale(3, 3);
227 arbitrary_matrix1
.Translate(-5, 20);
228 arbitrary_matrix1
.Rotate(15);
229 Transform arbitrary_matrix2
;
230 arbitrary_matrix2
.Scale(10, -1);
231 arbitrary_matrix2
.Translate(20, 3);
232 arbitrary_matrix2
.Rotate(24);
233 gfx::Rect
arbitrary_rect1(-5, 9, 3, 15);
234 gfx::Rect
arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
235 gfx::Rect
arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
236 gfx::Rect
arbitrary_rect2(40, 23, 11, 7);
237 gfx::Rect
arbitrary_rect1_inside_rect2(44, 23, 4, 2);
238 gfx::Rect
arbitrary_rect2_inside_rect2(41, 25, 3, 5);
239 gfx::Rect
arbitrary_rect3(7, -53, 22, 19);
240 gfx::Rect
arbitrary_rect1_inside_rect3(10, -40, 6, 3);
241 gfx::Rect
arbitrary_rect2_inside_rect3(12, -51, 5, 12);
242 gfx::Size
arbitrary_size1(15, 19);
243 gfx::Size
arbitrary_size2(3, 99);
244 gfx::Size
arbitrary_size3(75, 1281);
245 gfx::RectF
arbitrary_rectf1(4.2f
, -922.1f
, 15.6f
, 29.5f
);
246 gfx::RectF
arbitrary_rectf2(2.1f
, -411.05f
, 7.8f
, 14.75f
);
247 gfx::SizeF
arbitrary_sizef1(15.2f
, 104.6f
);
248 gfx::PointF
arbitrary_pointf1(31.4f
, 15.9f
);
249 gfx::PointF
arbitrary_pointf2(26.5f
, -35.8f
);
250 gfx::Vector2dF
arbitrary_vector2df1(16.2f
, -85.1f
);
251 gfx::Vector2dF
arbitrary_vector2df2(-8.3f
, 0.47f
);
252 float arbitrary_float1
= 0.7f
;
253 float arbitrary_float2
= 0.3f
;
254 float arbitrary_float3
= 0.9f
;
255 float arbitrary_float_array
[4] = {3.5f
, 6.2f
, 9.3f
, 12.3f
};
256 bool arbitrary_bool1
= true;
257 bool arbitrary_bool2
= false;
258 bool arbitrary_bool3
= true;
259 bool arbitrary_bool4
= true;
260 bool arbitrary_bool5
= false;
261 int arbitrary_context_id1
= 12;
262 int arbitrary_context_id2
= 57;
263 int arbitrary_context_id3
= -503;
264 int arbitrary_int
= 5;
265 SkColor arbitrary_color
= SkColorSetARGB(25, 36, 47, 58);
266 SkXfermode::Mode arbitrary_blend_mode1
= SkXfermode::kScreen_Mode
;
267 SkXfermode::Mode arbitrary_blend_mode2
= SkXfermode::kLighten_Mode
;
268 SkXfermode::Mode arbitrary_blend_mode3
= SkXfermode::kOverlay_Mode
;
269 IOSurfaceDrawQuad::Orientation arbitrary_orientation
=
270 IOSurfaceDrawQuad::UNFLIPPED
;
271 ResourceId arbitrary_resourceid1
= 55;
272 ResourceId arbitrary_resourceid2
= 47;
273 ResourceId arbitrary_resourceid3
= 23;
274 ResourceId arbitrary_resourceid4
= 16;
275 SkScalar arbitrary_sigma
= SkFloatToScalar(2.0f
);
276 YUVVideoDrawQuad::ColorSpace arbitrary_color_space
=
277 YUVVideoDrawQuad::REC_601
;
279 RenderPassId
child_id(30, 5);
280 RenderPassId
root_id(10, 14);
282 FilterOperations arbitrary_filters1
;
283 arbitrary_filters1
.Append(FilterOperation::CreateGrayscaleFilter(
285 skia::RefPtr
<SkImageFilter
> arbitrary_filter
= skia::AdoptRef(
286 SkBlurImageFilter::Create(arbitrary_sigma
, arbitrary_sigma
));
287 arbitrary_filters1
.Append(
288 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter
));
290 FilterOperations arbitrary_filters2
;
291 arbitrary_filters2
.Append(FilterOperation::CreateBrightnessFilter(
294 scoped_ptr
<RenderPass
> child_pass_in
= RenderPass::Create();
295 child_pass_in
->SetAll(child_id
, arbitrary_rect2
, arbitrary_rect3
,
296 arbitrary_matrix2
, arbitrary_bool2
);
298 scoped_ptr
<RenderPass
> child_pass_cmp
= RenderPass::Create();
299 child_pass_cmp
->SetAll(child_id
, arbitrary_rect2
, arbitrary_rect3
,
300 arbitrary_matrix2
, arbitrary_bool2
);
302 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
303 pass_in
->SetAll(root_id
, arbitrary_rect1
, arbitrary_rect2
, arbitrary_matrix1
,
306 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
307 shared_state1_in
->SetAll(arbitrary_matrix1
, arbitrary_size1
, arbitrary_rect1
,
308 arbitrary_rect2
, arbitrary_bool1
, arbitrary_float1
,
309 arbitrary_blend_mode1
, arbitrary_context_id1
);
311 scoped_ptr
<RenderPass
> pass_cmp
= RenderPass::Create();
312 pass_cmp
->SetAll(root_id
, arbitrary_rect1
, arbitrary_rect2
, arbitrary_matrix1
,
315 SharedQuadState
* shared_state1_cmp
=
316 pass_cmp
->CreateAndAppendSharedQuadState();
317 shared_state1_cmp
->CopyFrom(shared_state1_in
);
319 DebugBorderDrawQuad
* debugborder_in
=
320 pass_in
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
321 debugborder_in
->SetAll(shared_state1_in
,
323 arbitrary_rect1_inside_rect3
,
324 arbitrary_rect2_inside_rect3
,
328 pass_cmp
->CopyFromAndAppendDrawQuad(debugborder_in
,
329 debugborder_in
->shared_quad_state
);
331 IOSurfaceDrawQuad
* iosurface_in
=
332 pass_in
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
333 iosurface_in
->SetAll(shared_state1_in
,
335 arbitrary_rect2_inside_rect2
,
336 arbitrary_rect1_inside_rect2
,
339 arbitrary_resourceid3
,
340 arbitrary_orientation
);
341 pass_cmp
->CopyFromAndAppendDrawQuad(iosurface_in
,
342 iosurface_in
->shared_quad_state
);
344 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
345 shared_state2_in
->SetAll(arbitrary_matrix2
, arbitrary_size2
, arbitrary_rect2
,
346 arbitrary_rect3
, arbitrary_bool1
, arbitrary_float2
,
347 arbitrary_blend_mode2
, arbitrary_context_id2
);
348 SharedQuadState
* shared_state2_cmp
=
349 pass_cmp
->CreateAndAppendSharedQuadState();
350 shared_state2_cmp
->CopyFrom(shared_state2_in
);
352 RenderPassDrawQuad
* renderpass_in
=
353 pass_in
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
354 renderpass_in
->SetAll(
355 shared_state2_in
, arbitrary_rect1
, arbitrary_rect2_inside_rect1
,
356 arbitrary_rect1_inside_rect1
, arbitrary_bool1
, child_id
,
357 arbitrary_resourceid2
, arbitrary_vector2df1
, arbitrary_size1
,
358 arbitrary_filters1
, arbitrary_vector2df2
, arbitrary_filters2
);
359 pass_cmp
->CopyFromAndAppendRenderPassDrawQuad(
361 renderpass_in
->shared_quad_state
,
362 renderpass_in
->render_pass_id
);
364 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
365 shared_state3_in
->SetAll(arbitrary_matrix1
, arbitrary_size3
, arbitrary_rect3
,
366 arbitrary_rect1
, arbitrary_bool1
, arbitrary_float3
,
367 arbitrary_blend_mode3
, arbitrary_context_id3
);
368 SharedQuadState
* shared_state3_cmp
=
369 pass_cmp
->CreateAndAppendSharedQuadState();
370 shared_state3_cmp
->CopyFrom(shared_state3_in
);
372 SolidColorDrawQuad
* solidcolor_in
=
373 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
374 solidcolor_in
->SetAll(shared_state3_in
,
376 arbitrary_rect1_inside_rect3
,
377 arbitrary_rect2_inside_rect3
,
381 pass_cmp
->CopyFromAndAppendDrawQuad(solidcolor_in
,
382 solidcolor_in
->shared_quad_state
);
384 StreamVideoDrawQuad
* streamvideo_in
=
385 pass_in
->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
386 streamvideo_in
->SetAll(
387 shared_state3_in
, arbitrary_rect2
, arbitrary_rect2_inside_rect2
,
388 arbitrary_rect1_inside_rect2
, arbitrary_bool1
, arbitrary_resourceid2
,
389 arbitrary_size1
, arbitrary_bool2
, arbitrary_matrix1
);
390 pass_cmp
->CopyFromAndAppendDrawQuad(streamvideo_in
,
391 streamvideo_in
->shared_quad_state
);
393 cc::SurfaceId
arbitrary_surface_id(3);
394 SurfaceDrawQuad
* surface_in
=
395 pass_in
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
396 surface_in
->SetAll(shared_state3_in
,
398 arbitrary_rect2_inside_rect2
,
399 arbitrary_rect1_inside_rect2
,
401 arbitrary_surface_id
);
402 pass_cmp
->CopyFromAndAppendDrawQuad(surface_in
,
403 surface_in
->shared_quad_state
);
404 pass_in
->referenced_surfaces
.push_back(arbitrary_surface_id
);
405 pass_cmp
->referenced_surfaces
.push_back(arbitrary_surface_id
);
407 TextureDrawQuad
* texture_in
=
408 pass_in
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
409 texture_in
->SetAll(shared_state3_in
, arbitrary_rect2
,
410 arbitrary_rect2_inside_rect2
, arbitrary_rect1_inside_rect2
,
411 arbitrary_bool1
, arbitrary_resourceid1
, arbitrary_size1
,
412 arbitrary_bool2
, arbitrary_bool3
, arbitrary_pointf1
,
413 arbitrary_pointf2
, arbitrary_color
, arbitrary_float_array
,
414 arbitrary_bool4
, arbitrary_bool5
);
415 pass_cmp
->CopyFromAndAppendDrawQuad(texture_in
,
416 texture_in
->shared_quad_state
);
418 TileDrawQuad
* tile_in
= pass_in
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
419 tile_in
->SetAll(shared_state3_in
,
421 arbitrary_rect2_inside_rect2
,
422 arbitrary_rect1_inside_rect2
,
424 arbitrary_resourceid3
,
429 pass_cmp
->CopyFromAndAppendDrawQuad(tile_in
, tile_in
->shared_quad_state
);
431 YUVVideoDrawQuad
* yuvvideo_in
=
432 pass_in
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
434 shared_state3_in
, arbitrary_rect1
, arbitrary_rect2_inside_rect1
,
435 arbitrary_rect1_inside_rect1
, arbitrary_bool1
, arbitrary_rectf1
,
436 arbitrary_rectf2
, arbitrary_size1
, arbitrary_size2
, arbitrary_resourceid1
,
437 arbitrary_resourceid2
, arbitrary_resourceid3
, arbitrary_resourceid4
,
438 arbitrary_color_space
);
439 pass_cmp
->CopyFromAndAppendDrawQuad(yuvvideo_in
,
440 yuvvideo_in
->shared_quad_state
);
442 // Make sure the in and cmp RenderPasses match.
443 Compare(child_pass_cmp
.get(), child_pass_in
.get());
444 ASSERT_EQ(0u, child_pass_in
->shared_quad_state_list
.size());
445 ASSERT_EQ(0u, child_pass_in
->quad_list
.size());
446 Compare(pass_cmp
.get(), pass_in
.get());
447 ASSERT_EQ(3u, pass_in
->shared_quad_state_list
.size());
448 ASSERT_EQ(9u, pass_in
->quad_list
.size());
449 for (cc::SharedQuadStateList::ConstIterator
450 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
451 in_iterator
= pass_in
->shared_quad_state_list
.begin();
452 in_iterator
!= pass_in
->shared_quad_state_list
.end();
453 ++cmp_iterator
, ++in_iterator
) {
454 Compare(*cmp_iterator
, *in_iterator
);
456 for (auto in_iter
= pass_in
->quad_list
.cbegin(),
457 cmp_iter
= pass_cmp
->quad_list
.cbegin();
458 in_iter
!= pass_in
->quad_list
.cend();
459 ++in_iter
, ++cmp_iter
)
460 Compare(*cmp_iter
, *in_iter
);
462 for (size_t i
= 1; i
< pass_in
->quad_list
.size(); ++i
) {
463 bool same_shared_quad_state_cmp
=
464 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
465 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
466 bool same_shared_quad_state_in
=
467 pass_in
->quad_list
.ElementAt(i
)->shared_quad_state
==
468 pass_in
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
469 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_in
);
472 DelegatedFrameData frame_in
;
473 frame_in
.render_pass_list
.push_back(child_pass_in
.Pass());
474 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
476 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
478 DelegatedFrameData frame_out
;
479 base::PickleIterator
iter(msg
);
480 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
483 // Make sure the out and cmp RenderPasses match.
484 scoped_ptr
<RenderPass
> child_pass_out
=
485 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
486 Compare(child_pass_cmp
.get(), child_pass_out
.get());
487 ASSERT_EQ(0u, child_pass_out
->shared_quad_state_list
.size());
488 ASSERT_EQ(0u, child_pass_out
->quad_list
.size());
489 scoped_ptr
<RenderPass
> pass_out
=
490 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin() + 1);
491 Compare(pass_cmp
.get(), pass_out
.get());
492 ASSERT_EQ(3u, pass_out
->shared_quad_state_list
.size());
493 ASSERT_EQ(9u, pass_out
->quad_list
.size());
494 for (cc::SharedQuadStateList::ConstIterator
495 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
496 out_iterator
= pass_out
->shared_quad_state_list
.begin();
497 out_iterator
!= pass_out
->shared_quad_state_list
.end();
498 ++cmp_iterator
, ++out_iterator
) {
499 Compare(*cmp_iterator
, *out_iterator
);
501 for (auto out_iter
= pass_out
->quad_list
.cbegin(),
502 cmp_iter
= pass_cmp
->quad_list
.cbegin();
503 out_iter
!= pass_out
->quad_list
.cend();
504 ++out_iter
, ++cmp_iter
)
505 Compare(*cmp_iter
, *out_iter
);
507 for (size_t i
= 1; i
< pass_out
->quad_list
.size(); ++i
) {
508 bool same_shared_quad_state_cmp
=
509 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
510 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
511 bool same_shared_quad_state_out
=
512 pass_out
->quad_list
.ElementAt(i
)->shared_quad_state
==
513 pass_out
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
514 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_out
);
518 TEST_F(CCMessagesTest
, UnusedSharedQuadStates
) {
519 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
520 pass_in
->SetAll(RenderPassId(1, 1),
526 // The first SharedQuadState is used.
527 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
528 shared_state1_in
->SetAll(gfx::Transform(),
534 SkXfermode::kSrcOver_Mode
,
537 SolidColorDrawQuad
* quad1
=
538 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
539 quad1
->SetAll(shared_state1_in
, gfx::Rect(10, 10), gfx::Rect(10, 10),
540 gfx::Rect(10, 10), false, SK_ColorRED
, false);
542 // The second and third SharedQuadStates are not used.
543 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
544 shared_state2_in
->SetAll(gfx::Transform(),
550 SkXfermode::kSrcOver_Mode
,
553 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
554 shared_state3_in
->SetAll(gfx::Transform(),
560 SkXfermode::kSrcOver_Mode
,
563 // The fourth SharedQuadState is used.
564 SharedQuadState
* shared_state4_in
= pass_in
->CreateAndAppendSharedQuadState();
565 shared_state4_in
->SetAll(gfx::Transform(),
571 SkXfermode::kSrcOver_Mode
,
574 SolidColorDrawQuad
* quad2
=
575 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
576 quad2
->SetAll(shared_state4_in
, gfx::Rect(10, 10), gfx::Rect(10, 10),
577 gfx::Rect(10, 10), false, SK_ColorRED
, false);
579 // The fifth is not used again.
580 SharedQuadState
* shared_state5_in
= pass_in
->CreateAndAppendSharedQuadState();
581 shared_state5_in
->SetAll(gfx::Transform(),
587 SkXfermode::kSrcOver_Mode
,
590 // 5 SharedQuadStates go in.
591 ASSERT_EQ(5u, pass_in
->shared_quad_state_list
.size());
592 ASSERT_EQ(2u, pass_in
->quad_list
.size());
594 DelegatedFrameData frame_in
;
595 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
597 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
598 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
600 DelegatedFrameData frame_out
;
601 base::PickleIterator
iter(msg
);
603 IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
, &iter
, &frame_out
));
605 scoped_ptr
<RenderPass
> pass_out
=
606 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
608 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
609 // used by quads, and so serialized. Others were not.
610 ASSERT_EQ(2u, pass_out
->shared_quad_state_list
.size());
611 ASSERT_EQ(2u, pass_out
->quad_list
.size());
613 EXPECT_EQ(gfx::Size(1, 1).ToString(),
614 pass_out
->shared_quad_state_list
.ElementAt(0)
615 ->quad_layer_bounds
.ToString());
616 EXPECT_EQ(gfx::Size(4, 4).ToString(),
617 pass_out
->shared_quad_state_list
.ElementAt(1)
618 ->quad_layer_bounds
.ToString());
621 TEST_F(CCMessagesTest
, Resources
) {
622 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
623 gfx::Size
arbitrary_size(757, 1281);
624 unsigned int arbitrary_uint1
= 71234838;
625 unsigned int arbitrary_uint2
= 53589793;
627 GLbyte arbitrary_mailbox1
[GL_MAILBOX_SIZE_CHROMIUM
] = {
628 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
629 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
630 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
632 GLbyte arbitrary_mailbox2
[GL_MAILBOX_SIZE_CHROMIUM
] = {
633 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
634 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
635 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
637 TransferableResource arbitrary_resource1
;
638 arbitrary_resource1
.id
= 2178312;
639 arbitrary_resource1
.format
= cc::RGBA_8888
;
640 arbitrary_resource1
.filter
= 53;
641 arbitrary_resource1
.size
= gfx::Size(37189, 123123);
642 arbitrary_resource1
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox1
);
643 arbitrary_resource1
.mailbox_holder
.texture_target
= GL_TEXTURE_2D
;
644 arbitrary_resource1
.mailbox_holder
.sync_point
= arbitrary_uint1
;
645 arbitrary_resource1
.allow_overlay
= true;
647 TransferableResource arbitrary_resource2
;
648 arbitrary_resource2
.id
= 789132;
649 arbitrary_resource2
.format
= cc::RGBA_4444
;
650 arbitrary_resource2
.filter
= 47;
651 arbitrary_resource2
.size
= gfx::Size(89123, 23789);
652 arbitrary_resource2
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox2
);
653 arbitrary_resource2
.mailbox_holder
.texture_target
= GL_TEXTURE_EXTERNAL_OES
;
654 arbitrary_resource2
.mailbox_holder
.sync_point
= arbitrary_uint2
;
655 arbitrary_resource2
.allow_overlay
= false;
657 scoped_ptr
<RenderPass
> renderpass_in
= RenderPass::Create();
658 renderpass_in
->SetNew(
659 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
661 DelegatedFrameData frame_in
;
662 frame_in
.resource_list
.push_back(arbitrary_resource1
);
663 frame_in
.resource_list
.push_back(arbitrary_resource2
);
664 frame_in
.render_pass_list
.push_back(renderpass_in
.Pass());
666 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
668 DelegatedFrameData frame_out
;
669 base::PickleIterator
iter(msg
);
670 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
673 ASSERT_EQ(2u, frame_out
.resource_list
.size());
674 Compare(arbitrary_resource1
, frame_out
.resource_list
[0]);
675 Compare(arbitrary_resource2
, frame_out
.resource_list
[1]);
679 } // namespace content