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::CheckerboardDrawQuad
;
23 using cc::DelegatedFrameData
;
24 using cc::DebugBorderDrawQuad
;
26 using cc::FilterOperation
;
27 using cc::FilterOperations
;
28 using cc::IOSurfaceDrawQuad
;
29 using cc::PictureDrawQuad
;
31 using cc::RenderPassId
;
32 using cc::RenderPassDrawQuad
;
33 using cc::ResourceProvider
;
34 using cc::SharedQuadState
;
35 using cc::SoftwareFrameData
;
36 using cc::SolidColorDrawQuad
;
37 using cc::SurfaceDrawQuad
;
38 using cc::TextureDrawQuad
;
39 using cc::TileDrawQuad
;
40 using cc::TransferableResource
;
41 using cc::StreamVideoDrawQuad
;
42 using cc::VideoLayerImpl
;
43 using cc::YUVVideoDrawQuad
;
49 class CCMessagesTest
: public testing::Test
{
51 void Compare(const RenderPass
* a
, const RenderPass
* b
) {
52 EXPECT_EQ(a
->id
, b
->id
);
53 EXPECT_EQ(a
->output_rect
.ToString(), b
->output_rect
.ToString());
54 EXPECT_EQ(a
->damage_rect
.ToString(), b
->damage_rect
.ToString());
55 EXPECT_EQ(a
->transform_to_root_target
, b
->transform_to_root_target
);
56 EXPECT_EQ(a
->has_transparent_background
, b
->has_transparent_background
);
59 void Compare(const SharedQuadState
* a
, const SharedQuadState
* b
) {
60 EXPECT_EQ(a
->content_to_target_transform
, b
->content_to_target_transform
);
61 EXPECT_EQ(a
->content_bounds
, b
->content_bounds
);
62 EXPECT_EQ(a
->visible_content_rect
, b
->visible_content_rect
);
63 EXPECT_EQ(a
->clip_rect
, b
->clip_rect
);
64 EXPECT_EQ(a
->is_clipped
, b
->is_clipped
);
65 EXPECT_EQ(a
->opacity
, b
->opacity
);
66 EXPECT_EQ(a
->blend_mode
, b
->blend_mode
);
67 EXPECT_EQ(a
->sorting_context_id
, b
->sorting_context_id
);
70 void Compare(const DrawQuad
* a
, const DrawQuad
* b
) {
71 ASSERT_NE(DrawQuad::INVALID
, a
->material
);
72 ASSERT_EQ(a
->material
, b
->material
);
73 EXPECT_EQ(a
->rect
.ToString(), b
->rect
.ToString());
74 EXPECT_EQ(a
->opaque_rect
.ToString(), b
->opaque_rect
.ToString());
75 EXPECT_EQ(a
->visible_rect
.ToString(), b
->visible_rect
.ToString());
76 EXPECT_EQ(a
->needs_blending
, b
->needs_blending
);
78 Compare(a
->shared_quad_state
, b
->shared_quad_state
);
80 switch (a
->material
) {
81 case DrawQuad::CHECKERBOARD
:
82 Compare(CheckerboardDrawQuad::MaterialCast(a
),
83 CheckerboardDrawQuad::MaterialCast(b
));
85 case DrawQuad::DEBUG_BORDER
:
86 Compare(DebugBorderDrawQuad::MaterialCast(a
),
87 DebugBorderDrawQuad::MaterialCast(b
));
89 case DrawQuad::IO_SURFACE_CONTENT
:
90 Compare(IOSurfaceDrawQuad::MaterialCast(a
),
91 IOSurfaceDrawQuad::MaterialCast(b
));
93 case DrawQuad::PICTURE_CONTENT
:
94 Compare(PictureDrawQuad::MaterialCast(a
),
95 PictureDrawQuad::MaterialCast(b
));
97 case DrawQuad::RENDER_PASS
:
98 Compare(RenderPassDrawQuad::MaterialCast(a
),
99 RenderPassDrawQuad::MaterialCast(b
));
101 case DrawQuad::TEXTURE_CONTENT
:
102 Compare(TextureDrawQuad::MaterialCast(a
),
103 TextureDrawQuad::MaterialCast(b
));
105 case DrawQuad::TILED_CONTENT
:
106 Compare(TileDrawQuad::MaterialCast(a
),
107 TileDrawQuad::MaterialCast(b
));
109 case DrawQuad::SOLID_COLOR
:
110 Compare(SolidColorDrawQuad::MaterialCast(a
),
111 SolidColorDrawQuad::MaterialCast(b
));
113 case DrawQuad::STREAM_VIDEO_CONTENT
:
114 Compare(StreamVideoDrawQuad::MaterialCast(a
),
115 StreamVideoDrawQuad::MaterialCast(b
));
117 case DrawQuad::SURFACE_CONTENT
:
118 Compare(SurfaceDrawQuad::MaterialCast(a
),
119 SurfaceDrawQuad::MaterialCast(b
));
121 case DrawQuad::YUV_VIDEO_CONTENT
:
122 Compare(YUVVideoDrawQuad::MaterialCast(a
),
123 YUVVideoDrawQuad::MaterialCast(b
));
125 case DrawQuad::INVALID
:
130 void Compare(const CheckerboardDrawQuad
* a
, const CheckerboardDrawQuad
* b
) {
131 EXPECT_EQ(a
->color
, b
->color
);
134 void Compare(const DebugBorderDrawQuad
* a
, const DebugBorderDrawQuad
* b
) {
135 EXPECT_EQ(a
->color
, b
->color
);
136 EXPECT_EQ(a
->width
, b
->width
);
139 void Compare(const IOSurfaceDrawQuad
* a
, const IOSurfaceDrawQuad
* b
) {
140 EXPECT_EQ(a
->io_surface_size
.ToString(), b
->io_surface_size
.ToString());
141 EXPECT_EQ(a
->io_surface_resource_id
, b
->io_surface_resource_id
);
142 EXPECT_EQ(a
->orientation
, b
->orientation
);
145 void Compare(const RenderPassDrawQuad
* a
, const RenderPassDrawQuad
* b
) {
146 EXPECT_EQ(a
->render_pass_id
, b
->render_pass_id
);
147 EXPECT_EQ(a
->mask_resource_id
, b
->mask_resource_id
);
148 EXPECT_EQ(a
->mask_uv_scale
.ToString(), b
->mask_uv_scale
.ToString());
149 EXPECT_EQ(a
->mask_texture_size
.ToString(), b
->mask_texture_size
.ToString());
150 EXPECT_EQ(a
->filters
.size(), b
->filters
.size());
151 for (size_t i
= 0; i
< a
->filters
.size(); ++i
) {
152 if (a
->filters
.at(i
).type() != cc::FilterOperation::REFERENCE
) {
153 EXPECT_EQ(a
->filters
.at(i
), b
->filters
.at(i
));
155 EXPECT_EQ(b
->filters
.at(i
).type(), cc::FilterOperation::REFERENCE
);
156 EXPECT_EQ(a
->filters
.at(i
).image_filter()->countInputs(),
157 b
->filters
.at(i
).image_filter()->countInputs());
160 EXPECT_EQ(a
->filters_scale
, b
->filters_scale
);
161 EXPECT_EQ(a
->background_filters
, b
->background_filters
);
164 void Compare(const SolidColorDrawQuad
* a
, const SolidColorDrawQuad
* b
) {
165 EXPECT_EQ(a
->color
, b
->color
);
166 EXPECT_EQ(a
->force_anti_aliasing_off
, b
->force_anti_aliasing_off
);
169 void Compare(const StreamVideoDrawQuad
* a
, const StreamVideoDrawQuad
* b
) {
170 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
171 EXPECT_EQ(a
->matrix
, b
->matrix
);
174 void Compare(const SurfaceDrawQuad
* a
, const SurfaceDrawQuad
* b
) {
175 EXPECT_EQ(a
->surface_id
, b
->surface_id
);
178 void Compare(const TextureDrawQuad
* a
, const TextureDrawQuad
* b
) {
179 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
180 EXPECT_EQ(a
->premultiplied_alpha
, b
->premultiplied_alpha
);
181 EXPECT_EQ(a
->uv_top_left
, b
->uv_top_left
);
182 EXPECT_EQ(a
->uv_bottom_right
, b
->uv_bottom_right
);
183 EXPECT_EQ(a
->background_color
, b
->background_color
);
184 EXPECT_EQ(a
->vertex_opacity
[0], b
->vertex_opacity
[0]);
185 EXPECT_EQ(a
->vertex_opacity
[1], b
->vertex_opacity
[1]);
186 EXPECT_EQ(a
->vertex_opacity
[2], b
->vertex_opacity
[2]);
187 EXPECT_EQ(a
->vertex_opacity
[3], b
->vertex_opacity
[3]);
188 EXPECT_EQ(a
->flipped
, b
->flipped
);
189 EXPECT_EQ(a
->nearest_neighbor
, b
->nearest_neighbor
);
192 void Compare(const TileDrawQuad
* a
, const TileDrawQuad
* b
) {
193 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
194 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
195 EXPECT_EQ(a
->texture_size
, b
->texture_size
);
196 EXPECT_EQ(a
->swizzle_contents
, b
->swizzle_contents
);
197 EXPECT_EQ(a
->nearest_neighbor
, b
->nearest_neighbor
);
200 void Compare(const YUVVideoDrawQuad
* a
, const YUVVideoDrawQuad
* b
) {
201 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
202 EXPECT_EQ(a
->tex_size
, b
->tex_size
);
203 EXPECT_EQ(a
->y_plane_resource_id
, b
->y_plane_resource_id
);
204 EXPECT_EQ(a
->u_plane_resource_id
, b
->u_plane_resource_id
);
205 EXPECT_EQ(a
->v_plane_resource_id
, b
->v_plane_resource_id
);
206 EXPECT_EQ(a
->a_plane_resource_id
, b
->a_plane_resource_id
);
207 EXPECT_EQ(a
->color_space
, b
->color_space
);
210 void Compare(const TransferableResource
& a
, const TransferableResource
& b
) {
211 EXPECT_EQ(a
.id
, b
.id
);
212 EXPECT_EQ(a
.format
, b
.format
);
213 EXPECT_EQ(a
.filter
, b
.filter
);
214 EXPECT_EQ(a
.size
.ToString(), b
.size
.ToString());
215 for (size_t i
= 0; i
< arraysize(a
.mailbox_holder
.mailbox
.name
); ++i
) {
216 EXPECT_EQ(a
.mailbox_holder
.mailbox
.name
[i
],
217 b
.mailbox_holder
.mailbox
.name
[i
]);
219 EXPECT_EQ(a
.mailbox_holder
.texture_target
, b
.mailbox_holder
.texture_target
);
220 EXPECT_EQ(a
.mailbox_holder
.sync_point
, b
.mailbox_holder
.sync_point
);
221 EXPECT_EQ(a
.allow_overlay
, b
.allow_overlay
);
225 TEST_F(CCMessagesTest
, AllQuads
) {
226 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
228 Transform arbitrary_matrix
;
229 arbitrary_matrix
.Scale(3, 3);
230 arbitrary_matrix
.Translate(-5, 20);
231 arbitrary_matrix
.Rotate(15);
232 gfx::Rect
arbitrary_rect1(-5, 9, 3, 15);
233 gfx::Rect
arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
234 gfx::Rect
arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
235 gfx::Rect
arbitrary_rect2(40, 23, 11, 7);
236 gfx::Rect
arbitrary_rect1_inside_rect2(44, 23, 4, 2);
237 gfx::Rect
arbitrary_rect2_inside_rect2(41, 25, 3, 5);
238 gfx::Rect
arbitrary_rect3(7, -53, 22, 19);
239 gfx::Rect
arbitrary_rect1_inside_rect3(10, -40, 6, 3);
240 gfx::Rect
arbitrary_rect2_inside_rect3(12, -51, 5, 12);
241 gfx::Size
arbitrary_size1(15, 19);
242 gfx::Size
arbitrary_size2(3, 99);
243 gfx::Size
arbitrary_size3(75, 1281);
244 gfx::RectF
arbitrary_rectf1(4.2f
, -922.1f
, 15.6f
, 29.5f
);
245 gfx::SizeF
arbitrary_sizef1(15.2f
, 104.6f
);
246 gfx::PointF
arbitrary_pointf1(31.4f
, 15.9f
);
247 gfx::PointF
arbitrary_pointf2(26.5f
, -35.8f
);
248 gfx::Vector2dF
arbitrary_vector2df1(16.2f
, -85.1f
);
249 gfx::Vector2dF
arbitrary_vector2df2(-8.3f
, 0.47f
);
250 float arbitrary_float1
= 0.7f
;
251 float arbitrary_float2
= 0.3f
;
252 float arbitrary_float3
= 0.9f
;
253 float arbitrary_float_array
[4] = {3.5f
, 6.2f
, 9.3f
, 12.3f
};
254 bool arbitrary_bool1
= true;
255 bool arbitrary_bool2
= false;
256 bool arbitrary_bool3
= true;
257 bool arbitrary_bool4
= true;
258 int arbitrary_context_id1
= 12;
259 int arbitrary_context_id2
= 57;
260 int arbitrary_context_id3
= -503;
261 int arbitrary_int
= 5;
262 SkColor arbitrary_color
= SkColorSetARGB(25, 36, 47, 58);
263 SkXfermode::Mode arbitrary_blend_mode1
= SkXfermode::kScreen_Mode
;
264 SkXfermode::Mode arbitrary_blend_mode2
= SkXfermode::kLighten_Mode
;
265 SkXfermode::Mode arbitrary_blend_mode3
= SkXfermode::kOverlay_Mode
;
266 IOSurfaceDrawQuad::Orientation arbitrary_orientation
=
267 IOSurfaceDrawQuad::UNFLIPPED
;
268 RenderPassId
arbitrary_id(10, 14);
269 ResourceProvider::ResourceId arbitrary_resourceid1
= 55;
270 ResourceProvider::ResourceId arbitrary_resourceid2
= 47;
271 ResourceProvider::ResourceId arbitrary_resourceid3
= 23;
272 ResourceProvider::ResourceId arbitrary_resourceid4
= 16;
273 SkScalar arbitrary_sigma
= SkFloatToScalar(2.0f
);
274 YUVVideoDrawQuad::ColorSpace arbitrary_color_space
=
275 YUVVideoDrawQuad::REC_601
;
277 FilterOperations arbitrary_filters1
;
278 arbitrary_filters1
.Append(FilterOperation::CreateGrayscaleFilter(
280 skia::RefPtr
<SkImageFilter
> arbitrary_filter
= skia::AdoptRef(
281 SkBlurImageFilter::Create(arbitrary_sigma
, arbitrary_sigma
));
282 arbitrary_filters1
.Append(
283 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter
));
285 FilterOperations arbitrary_filters2
;
286 arbitrary_filters2
.Append(FilterOperation::CreateBrightnessFilter(
289 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
290 pass_in
->SetAll(arbitrary_id
,
296 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
297 shared_state1_in
->SetAll(arbitrary_matrix
,
303 arbitrary_blend_mode1
,
304 arbitrary_context_id1
);
306 scoped_ptr
<RenderPass
> pass_cmp
= RenderPass::Create();
307 pass_cmp
->SetAll(arbitrary_id
,
313 SharedQuadState
* shared_state1_cmp
=
314 pass_cmp
->CreateAndAppendSharedQuadState();
315 shared_state1_cmp
->CopyFrom(shared_state1_in
);
317 CheckerboardDrawQuad
* checkerboard_in
=
318 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
319 checkerboard_in
->SetAll(shared_state1_in
,
321 arbitrary_rect2_inside_rect1
,
322 arbitrary_rect1_inside_rect1
,
325 pass_cmp
->CopyFromAndAppendDrawQuad(checkerboard_in
,
326 checkerboard_in
->shared_quad_state
);
328 DebugBorderDrawQuad
* debugborder_in
=
329 pass_in
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
330 debugborder_in
->SetAll(shared_state1_in
,
332 arbitrary_rect1_inside_rect3
,
333 arbitrary_rect2_inside_rect3
,
337 pass_cmp
->CopyFromAndAppendDrawQuad(debugborder_in
,
338 debugborder_in
->shared_quad_state
);
340 IOSurfaceDrawQuad
* iosurface_in
=
341 pass_in
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
342 iosurface_in
->SetAll(shared_state1_in
,
344 arbitrary_rect2_inside_rect2
,
345 arbitrary_rect1_inside_rect2
,
348 arbitrary_resourceid3
,
349 arbitrary_orientation
);
350 pass_cmp
->CopyFromAndAppendDrawQuad(iosurface_in
,
351 iosurface_in
->shared_quad_state
);
353 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
354 shared_state2_in
->SetAll(arbitrary_matrix
,
360 arbitrary_blend_mode2
,
361 arbitrary_context_id2
);
362 SharedQuadState
* shared_state2_cmp
=
363 pass_cmp
->CreateAndAppendSharedQuadState();
364 shared_state2_cmp
->CopyFrom(shared_state2_in
);
366 RenderPassDrawQuad
* renderpass_in
=
367 pass_in
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
368 renderpass_in
->SetAll(shared_state2_in
,
370 arbitrary_rect2_inside_rect1
,
371 arbitrary_rect1_inside_rect1
,
374 arbitrary_resourceid2
,
375 arbitrary_vector2df1
,
378 arbitrary_vector2df2
,
380 pass_cmp
->CopyFromAndAppendRenderPassDrawQuad(
382 renderpass_in
->shared_quad_state
,
383 renderpass_in
->render_pass_id
);
385 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
386 shared_state3_in
->SetAll(arbitrary_matrix
,
392 arbitrary_blend_mode3
,
393 arbitrary_context_id3
);
394 SharedQuadState
* shared_state3_cmp
=
395 pass_cmp
->CreateAndAppendSharedQuadState();
396 shared_state3_cmp
->CopyFrom(shared_state3_in
);
398 SolidColorDrawQuad
* solidcolor_in
=
399 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
400 solidcolor_in
->SetAll(shared_state3_in
,
402 arbitrary_rect1_inside_rect3
,
403 arbitrary_rect2_inside_rect3
,
407 pass_cmp
->CopyFromAndAppendDrawQuad(solidcolor_in
,
408 solidcolor_in
->shared_quad_state
);
410 StreamVideoDrawQuad
* streamvideo_in
=
411 pass_in
->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
412 streamvideo_in
->SetAll(shared_state3_in
,
414 arbitrary_rect2_inside_rect2
,
415 arbitrary_rect1_inside_rect2
,
417 arbitrary_resourceid2
,
419 pass_cmp
->CopyFromAndAppendDrawQuad(streamvideo_in
,
420 streamvideo_in
->shared_quad_state
);
422 cc::SurfaceId
arbitrary_surface_id(3);
423 SurfaceDrawQuad
* surface_in
=
424 pass_in
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
425 surface_in
->SetAll(shared_state3_in
,
427 arbitrary_rect2_inside_rect2
,
428 arbitrary_rect1_inside_rect2
,
430 arbitrary_surface_id
);
431 pass_cmp
->CopyFromAndAppendDrawQuad(surface_in
,
432 surface_in
->shared_quad_state
);
434 TextureDrawQuad
* texture_in
=
435 pass_in
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
436 texture_in
->SetAll(shared_state3_in
,
438 arbitrary_rect2_inside_rect2
,
439 arbitrary_rect1_inside_rect2
,
441 arbitrary_resourceid1
,
446 arbitrary_float_array
,
449 pass_cmp
->CopyFromAndAppendDrawQuad(texture_in
,
450 texture_in
->shared_quad_state
);
452 TileDrawQuad
* tile_in
= pass_in
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
453 tile_in
->SetAll(shared_state3_in
,
455 arbitrary_rect2_inside_rect2
,
456 arbitrary_rect1_inside_rect2
,
458 arbitrary_resourceid3
,
463 pass_cmp
->CopyFromAndAppendDrawQuad(tile_in
, tile_in
->shared_quad_state
);
465 YUVVideoDrawQuad
* yuvvideo_in
=
466 pass_in
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
467 yuvvideo_in
->SetAll(shared_state3_in
,
469 arbitrary_rect2_inside_rect1
,
470 arbitrary_rect1_inside_rect1
,
474 arbitrary_resourceid1
,
475 arbitrary_resourceid2
,
476 arbitrary_resourceid3
,
477 arbitrary_resourceid4
,
478 arbitrary_color_space
);
479 pass_cmp
->CopyFromAndAppendDrawQuad(yuvvideo_in
,
480 yuvvideo_in
->shared_quad_state
);
482 // Make sure the in and cmp RenderPasses match.
483 Compare(pass_cmp
.get(), pass_in
.get());
484 ASSERT_EQ(3u, pass_in
->shared_quad_state_list
.size());
485 ASSERT_EQ(10u, pass_in
->quad_list
.size());
486 for (cc::SharedQuadStateList::ConstIterator
487 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
488 in_iterator
= pass_in
->shared_quad_state_list
.begin();
489 in_iterator
!= pass_in
->shared_quad_state_list
.end();
490 ++cmp_iterator
, ++in_iterator
) {
491 Compare(*cmp_iterator
, *in_iterator
);
493 for (auto in_iter
= pass_in
->quad_list
.cbegin(),
494 cmp_iter
= pass_cmp
->quad_list
.cbegin();
495 in_iter
!= pass_in
->quad_list
.cend();
496 ++in_iter
, ++cmp_iter
)
497 Compare(*cmp_iter
, *in_iter
);
499 for (size_t i
= 1; i
< pass_in
->quad_list
.size(); ++i
) {
500 bool same_shared_quad_state_cmp
=
501 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
502 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
503 bool same_shared_quad_state_in
=
504 pass_in
->quad_list
.ElementAt(i
)->shared_quad_state
==
505 pass_in
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
506 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_in
);
509 DelegatedFrameData frame_in
;
510 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
512 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
514 DelegatedFrameData frame_out
;
515 PickleIterator
iter(msg
);
516 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
519 // Make sure the out and cmp RenderPasses match.
520 scoped_ptr
<RenderPass
> pass_out
= frame_out
.render_pass_list
.take(
521 frame_out
.render_pass_list
.begin());
522 Compare(pass_cmp
.get(), pass_out
.get());
523 ASSERT_EQ(3u, pass_out
->shared_quad_state_list
.size());
524 ASSERT_EQ(10u, pass_out
->quad_list
.size());
525 for (cc::SharedQuadStateList::ConstIterator
526 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
527 out_iterator
= pass_out
->shared_quad_state_list
.begin();
528 out_iterator
!= pass_out
->shared_quad_state_list
.end();
529 ++cmp_iterator
, ++out_iterator
) {
530 Compare(*cmp_iterator
, *out_iterator
);
532 for (auto out_iter
= pass_out
->quad_list
.cbegin(),
533 cmp_iter
= pass_cmp
->quad_list
.cbegin();
534 out_iter
!= pass_out
->quad_list
.cend();
535 ++out_iter
, ++cmp_iter
)
536 Compare(*cmp_iter
, *out_iter
);
538 for (size_t i
= 1; i
< pass_out
->quad_list
.size(); ++i
) {
539 bool same_shared_quad_state_cmp
=
540 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
541 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
542 bool same_shared_quad_state_out
=
543 pass_out
->quad_list
.ElementAt(i
)->shared_quad_state
==
544 pass_out
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
545 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_out
);
549 TEST_F(CCMessagesTest
, UnusedSharedQuadStates
) {
550 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
551 pass_in
->SetAll(RenderPassId(1, 1),
557 // The first SharedQuadState is used.
558 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
559 shared_state1_in
->SetAll(gfx::Transform(),
565 SkXfermode::kSrcOver_Mode
,
568 CheckerboardDrawQuad
* quad1
=
569 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
570 quad1
->SetAll(shared_state1_in
,
577 // The second and third SharedQuadStates are not used.
578 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
579 shared_state2_in
->SetAll(gfx::Transform(),
585 SkXfermode::kSrcOver_Mode
,
588 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
589 shared_state3_in
->SetAll(gfx::Transform(),
595 SkXfermode::kSrcOver_Mode
,
598 // The fourth SharedQuadState is used.
599 SharedQuadState
* shared_state4_in
= pass_in
->CreateAndAppendSharedQuadState();
600 shared_state4_in
->SetAll(gfx::Transform(),
606 SkXfermode::kSrcOver_Mode
,
609 CheckerboardDrawQuad
* quad2
=
610 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
611 quad2
->SetAll(shared_state4_in
,
618 // The fifth is not used again.
619 SharedQuadState
* shared_state5_in
= pass_in
->CreateAndAppendSharedQuadState();
620 shared_state5_in
->SetAll(gfx::Transform(),
626 SkXfermode::kSrcOver_Mode
,
629 // 5 SharedQuadStates go in.
630 ASSERT_EQ(5u, pass_in
->shared_quad_state_list
.size());
631 ASSERT_EQ(2u, pass_in
->quad_list
.size());
633 DelegatedFrameData frame_in
;
634 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
636 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
637 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
639 DelegatedFrameData frame_out
;
640 PickleIterator
iter(msg
);
642 IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
, &iter
, &frame_out
));
644 scoped_ptr
<RenderPass
> pass_out
=
645 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
647 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
648 // used by quads, and so serialized. Others were not.
649 ASSERT_EQ(2u, pass_out
->shared_quad_state_list
.size());
650 ASSERT_EQ(2u, pass_out
->quad_list
.size());
653 gfx::Size(1, 1).ToString(),
654 pass_out
->shared_quad_state_list
.ElementAt(0)->content_bounds
.ToString());
656 gfx::Size(4, 4).ToString(),
657 pass_out
->shared_quad_state_list
.ElementAt(1)->content_bounds
.ToString());
660 TEST_F(CCMessagesTest
, Resources
) {
661 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
662 gfx::Size
arbitrary_size(757, 1281);
663 unsigned int arbitrary_uint1
= 71234838;
664 unsigned int arbitrary_uint2
= 53589793;
666 GLbyte arbitrary_mailbox1
[GL_MAILBOX_SIZE_CHROMIUM
] = {
667 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
668 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
669 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
671 GLbyte arbitrary_mailbox2
[GL_MAILBOX_SIZE_CHROMIUM
] = {
672 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
673 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
674 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
676 TransferableResource arbitrary_resource1
;
677 arbitrary_resource1
.id
= 2178312;
678 arbitrary_resource1
.format
= cc::RGBA_8888
;
679 arbitrary_resource1
.filter
= 53;
680 arbitrary_resource1
.size
= gfx::Size(37189, 123123);
681 arbitrary_resource1
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox1
);
682 arbitrary_resource1
.mailbox_holder
.texture_target
= GL_TEXTURE_2D
;
683 arbitrary_resource1
.mailbox_holder
.sync_point
= arbitrary_uint1
;
684 arbitrary_resource1
.allow_overlay
= true;
686 TransferableResource arbitrary_resource2
;
687 arbitrary_resource2
.id
= 789132;
688 arbitrary_resource2
.format
= cc::RGBA_4444
;
689 arbitrary_resource2
.filter
= 47;
690 arbitrary_resource2
.size
= gfx::Size(89123, 23789);
691 arbitrary_resource2
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox2
);
692 arbitrary_resource2
.mailbox_holder
.texture_target
= GL_TEXTURE_EXTERNAL_OES
;
693 arbitrary_resource2
.mailbox_holder
.sync_point
= arbitrary_uint2
;
694 arbitrary_resource2
.allow_overlay
= false;
696 scoped_ptr
<RenderPass
> renderpass_in
= RenderPass::Create();
697 renderpass_in
->SetNew(
698 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
700 DelegatedFrameData frame_in
;
701 frame_in
.resource_list
.push_back(arbitrary_resource1
);
702 frame_in
.resource_list
.push_back(arbitrary_resource2
);
703 frame_in
.render_pass_list
.push_back(renderpass_in
.Pass());
705 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
707 DelegatedFrameData frame_out
;
708 PickleIterator
iter(msg
);
709 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
712 ASSERT_EQ(2u, frame_out
.resource_list
.size());
713 Compare(arbitrary_resource1
, frame_out
.resource_list
[0]);
714 Compare(arbitrary_resource2
, frame_out
.resource_list
[1]);
717 TEST_F(CCMessagesTest
, SoftwareFrameData
) {
718 cc::SoftwareFrameData frame_in
;
720 frame_in
.size
= gfx::Size(40, 20);
721 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
722 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
725 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
726 IPC::ParamTraits
<cc::SoftwareFrameData
>::Write(&msg
, frame_in
);
729 cc::SoftwareFrameData frame_out
;
730 PickleIterator
iter(msg
);
732 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
733 EXPECT_EQ(frame_in
.id
, frame_out
.id
);
734 EXPECT_EQ(frame_in
.size
.ToString(), frame_out
.size
.ToString());
735 EXPECT_EQ(frame_in
.damage_rect
.ToString(), frame_out
.damage_rect
.ToString());
736 EXPECT_EQ(frame_in
.bitmap_id
, frame_out
.bitmap_id
);
739 TEST_F(CCMessagesTest
, SoftwareFrameDataMaxInt
) {
740 SoftwareFrameData frame_in
;
742 frame_in
.size
= gfx::Size(40, 20);
743 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
744 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
746 // Write the SoftwareFrameData by hand, make sure it works.
748 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
749 IPC::WriteParam(&msg
, frame_in
.id
);
750 IPC::WriteParam(&msg
, frame_in
.size
);
751 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
752 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
753 SoftwareFrameData frame_out
;
754 PickleIterator
iter(msg
);
756 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
759 // The size of the frame may overflow when multiplied together.
760 int max
= std::numeric_limits
<int>::max();
761 frame_in
.size
= gfx::Size(max
, max
);
763 // If size_t is larger than int, then int*int*4 can always fit in size_t.
764 bool expect_read
= sizeof(size_t) >= sizeof(int) * 2;
766 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
769 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
770 IPC::WriteParam(&msg
, frame_in
.id
);
771 IPC::WriteParam(&msg
, frame_in
.size
);
772 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
773 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
774 SoftwareFrameData frame_out
;
775 PickleIterator
iter(msg
);
778 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
783 } // namespace content