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::YUVVideoDrawQuad
;
48 class CCMessagesTest
: public testing::Test
{
50 void Compare(const RenderPass
* a
, const RenderPass
* b
) {
51 EXPECT_EQ(a
->id
, b
->id
);
52 EXPECT_EQ(a
->output_rect
.ToString(), b
->output_rect
.ToString());
53 EXPECT_EQ(a
->damage_rect
.ToString(), b
->damage_rect
.ToString());
54 EXPECT_EQ(a
->transform_to_root_target
, b
->transform_to_root_target
);
55 EXPECT_EQ(a
->has_transparent_background
, b
->has_transparent_background
);
58 void Compare(const SharedQuadState
* a
, const SharedQuadState
* b
) {
59 EXPECT_EQ(a
->content_to_target_transform
, b
->content_to_target_transform
);
60 EXPECT_EQ(a
->content_bounds
, b
->content_bounds
);
61 EXPECT_EQ(a
->visible_content_rect
, b
->visible_content_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::CHECKERBOARD
:
81 Compare(CheckerboardDrawQuad::MaterialCast(a
),
82 CheckerboardDrawQuad::MaterialCast(b
));
84 case DrawQuad::DEBUG_BORDER
:
85 Compare(DebugBorderDrawQuad::MaterialCast(a
),
86 DebugBorderDrawQuad::MaterialCast(b
));
88 case DrawQuad::IO_SURFACE_CONTENT
:
89 Compare(IOSurfaceDrawQuad::MaterialCast(a
),
90 IOSurfaceDrawQuad::MaterialCast(b
));
92 case DrawQuad::PICTURE_CONTENT
:
93 Compare(PictureDrawQuad::MaterialCast(a
),
94 PictureDrawQuad::MaterialCast(b
));
96 case DrawQuad::RENDER_PASS
:
97 Compare(RenderPassDrawQuad::MaterialCast(a
),
98 RenderPassDrawQuad::MaterialCast(b
));
100 case DrawQuad::TEXTURE_CONTENT
:
101 Compare(TextureDrawQuad::MaterialCast(a
),
102 TextureDrawQuad::MaterialCast(b
));
104 case DrawQuad::TILED_CONTENT
:
105 Compare(TileDrawQuad::MaterialCast(a
),
106 TileDrawQuad::MaterialCast(b
));
108 case DrawQuad::SOLID_COLOR
:
109 Compare(SolidColorDrawQuad::MaterialCast(a
),
110 SolidColorDrawQuad::MaterialCast(b
));
112 case DrawQuad::STREAM_VIDEO_CONTENT
:
113 Compare(StreamVideoDrawQuad::MaterialCast(a
),
114 StreamVideoDrawQuad::MaterialCast(b
));
116 case DrawQuad::SURFACE_CONTENT
:
117 Compare(SurfaceDrawQuad::MaterialCast(a
),
118 SurfaceDrawQuad::MaterialCast(b
));
120 case DrawQuad::YUV_VIDEO_CONTENT
:
121 Compare(YUVVideoDrawQuad::MaterialCast(a
),
122 YUVVideoDrawQuad::MaterialCast(b
));
124 case DrawQuad::INVALID
:
129 void Compare(const CheckerboardDrawQuad
* a
, const CheckerboardDrawQuad
* b
) {
130 EXPECT_EQ(a
->color
, b
->color
);
131 EXPECT_EQ(a
->scale
, b
->scale
);
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
->ya_tex_size
, b
->ya_tex_size
);
203 EXPECT_EQ(a
->uv_tex_size
, b
->uv_tex_size
);
204 EXPECT_EQ(a
->y_plane_resource_id
, b
->y_plane_resource_id
);
205 EXPECT_EQ(a
->u_plane_resource_id
, b
->u_plane_resource_id
);
206 EXPECT_EQ(a
->v_plane_resource_id
, b
->v_plane_resource_id
);
207 EXPECT_EQ(a
->a_plane_resource_id
, b
->a_plane_resource_id
);
208 EXPECT_EQ(a
->color_space
, b
->color_space
);
211 void Compare(const TransferableResource
& a
, const TransferableResource
& b
) {
212 EXPECT_EQ(a
.id
, b
.id
);
213 EXPECT_EQ(a
.format
, b
.format
);
214 EXPECT_EQ(a
.filter
, b
.filter
);
215 EXPECT_EQ(a
.size
.ToString(), b
.size
.ToString());
216 for (size_t i
= 0; i
< arraysize(a
.mailbox_holder
.mailbox
.name
); ++i
) {
217 EXPECT_EQ(a
.mailbox_holder
.mailbox
.name
[i
],
218 b
.mailbox_holder
.mailbox
.name
[i
]);
220 EXPECT_EQ(a
.mailbox_holder
.texture_target
, b
.mailbox_holder
.texture_target
);
221 EXPECT_EQ(a
.mailbox_holder
.sync_point
, b
.mailbox_holder
.sync_point
);
222 EXPECT_EQ(a
.allow_overlay
, b
.allow_overlay
);
226 TEST_F(CCMessagesTest
, AllQuads
) {
227 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
229 Transform arbitrary_matrix1
;
230 arbitrary_matrix1
.Scale(3, 3);
231 arbitrary_matrix1
.Translate(-5, 20);
232 arbitrary_matrix1
.Rotate(15);
233 Transform arbitrary_matrix2
;
234 arbitrary_matrix2
.Scale(10, -1);
235 arbitrary_matrix2
.Translate(20, 3);
236 arbitrary_matrix2
.Rotate(24);
237 gfx::Rect
arbitrary_rect1(-5, 9, 3, 15);
238 gfx::Rect
arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
239 gfx::Rect
arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
240 gfx::Rect
arbitrary_rect2(40, 23, 11, 7);
241 gfx::Rect
arbitrary_rect1_inside_rect2(44, 23, 4, 2);
242 gfx::Rect
arbitrary_rect2_inside_rect2(41, 25, 3, 5);
243 gfx::Rect
arbitrary_rect3(7, -53, 22, 19);
244 gfx::Rect
arbitrary_rect1_inside_rect3(10, -40, 6, 3);
245 gfx::Rect
arbitrary_rect2_inside_rect3(12, -51, 5, 12);
246 gfx::Size
arbitrary_size1(15, 19);
247 gfx::Size
arbitrary_size2(3, 99);
248 gfx::Size
arbitrary_size3(75, 1281);
249 gfx::RectF
arbitrary_rectf1(4.2f
, -922.1f
, 15.6f
, 29.5f
);
250 gfx::SizeF
arbitrary_sizef1(15.2f
, 104.6f
);
251 gfx::PointF
arbitrary_pointf1(31.4f
, 15.9f
);
252 gfx::PointF
arbitrary_pointf2(26.5f
, -35.8f
);
253 gfx::Vector2dF
arbitrary_vector2df1(16.2f
, -85.1f
);
254 gfx::Vector2dF
arbitrary_vector2df2(-8.3f
, 0.47f
);
255 float arbitrary_float1
= 0.7f
;
256 float arbitrary_float2
= 0.3f
;
257 float arbitrary_float3
= 0.9f
;
258 float arbitrary_float_array
[4] = {3.5f
, 6.2f
, 9.3f
, 12.3f
};
259 bool arbitrary_bool1
= true;
260 bool arbitrary_bool2
= false;
261 bool arbitrary_bool3
= true;
262 bool arbitrary_bool4
= true;
263 int arbitrary_context_id1
= 12;
264 int arbitrary_context_id2
= 57;
265 int arbitrary_context_id3
= -503;
266 int arbitrary_int
= 5;
267 SkColor arbitrary_color
= SkColorSetARGB(25, 36, 47, 58);
268 SkXfermode::Mode arbitrary_blend_mode1
= SkXfermode::kScreen_Mode
;
269 SkXfermode::Mode arbitrary_blend_mode2
= SkXfermode::kLighten_Mode
;
270 SkXfermode::Mode arbitrary_blend_mode3
= SkXfermode::kOverlay_Mode
;
271 IOSurfaceDrawQuad::Orientation arbitrary_orientation
=
272 IOSurfaceDrawQuad::UNFLIPPED
;
273 ResourceProvider::ResourceId arbitrary_resourceid1
= 55;
274 ResourceProvider::ResourceId arbitrary_resourceid2
= 47;
275 ResourceProvider::ResourceId arbitrary_resourceid3
= 23;
276 ResourceProvider::ResourceId arbitrary_resourceid4
= 16;
277 SkScalar arbitrary_sigma
= SkFloatToScalar(2.0f
);
278 YUVVideoDrawQuad::ColorSpace arbitrary_color_space
=
279 YUVVideoDrawQuad::REC_601
;
281 RenderPassId
child_id(30, 5);
282 RenderPassId
root_id(10, 14);
284 FilterOperations arbitrary_filters1
;
285 arbitrary_filters1
.Append(FilterOperation::CreateGrayscaleFilter(
287 skia::RefPtr
<SkImageFilter
> arbitrary_filter
= skia::AdoptRef(
288 SkBlurImageFilter::Create(arbitrary_sigma
, arbitrary_sigma
));
289 arbitrary_filters1
.Append(
290 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter
));
292 FilterOperations arbitrary_filters2
;
293 arbitrary_filters2
.Append(FilterOperation::CreateBrightnessFilter(
296 scoped_ptr
<RenderPass
> child_pass_in
= RenderPass::Create();
297 child_pass_in
->SetAll(child_id
, arbitrary_rect2
, arbitrary_rect3
,
298 arbitrary_matrix2
, arbitrary_bool2
);
300 scoped_ptr
<RenderPass
> child_pass_cmp
= RenderPass::Create();
301 child_pass_cmp
->SetAll(child_id
, arbitrary_rect2
, arbitrary_rect3
,
302 arbitrary_matrix2
, arbitrary_bool2
);
304 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
305 pass_in
->SetAll(root_id
, arbitrary_rect1
, arbitrary_rect2
, arbitrary_matrix1
,
308 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
309 shared_state1_in
->SetAll(arbitrary_matrix1
, arbitrary_size1
, arbitrary_rect1
,
310 arbitrary_rect2
, arbitrary_bool1
, arbitrary_float1
,
311 arbitrary_blend_mode1
, arbitrary_context_id1
);
313 scoped_ptr
<RenderPass
> pass_cmp
= RenderPass::Create();
314 pass_cmp
->SetAll(root_id
, arbitrary_rect1
, arbitrary_rect2
, arbitrary_matrix1
,
317 SharedQuadState
* shared_state1_cmp
=
318 pass_cmp
->CreateAndAppendSharedQuadState();
319 shared_state1_cmp
->CopyFrom(shared_state1_in
);
321 CheckerboardDrawQuad
* checkerboard_in
=
322 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
323 checkerboard_in
->SetAll(shared_state1_in
, arbitrary_rect1
,
324 arbitrary_rect2_inside_rect1
,
325 arbitrary_rect1_inside_rect1
, arbitrary_bool1
,
326 arbitrary_color
, arbitrary_float1
);
327 pass_cmp
->CopyFromAndAppendDrawQuad(checkerboard_in
,
328 checkerboard_in
->shared_quad_state
);
330 DebugBorderDrawQuad
* debugborder_in
=
331 pass_in
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
332 debugborder_in
->SetAll(shared_state1_in
,
334 arbitrary_rect1_inside_rect3
,
335 arbitrary_rect2_inside_rect3
,
339 pass_cmp
->CopyFromAndAppendDrawQuad(debugborder_in
,
340 debugborder_in
->shared_quad_state
);
342 IOSurfaceDrawQuad
* iosurface_in
=
343 pass_in
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
344 iosurface_in
->SetAll(shared_state1_in
,
346 arbitrary_rect2_inside_rect2
,
347 arbitrary_rect1_inside_rect2
,
350 arbitrary_resourceid3
,
351 arbitrary_orientation
);
352 pass_cmp
->CopyFromAndAppendDrawQuad(iosurface_in
,
353 iosurface_in
->shared_quad_state
);
355 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
356 shared_state2_in
->SetAll(arbitrary_matrix2
, arbitrary_size2
, arbitrary_rect2
,
357 arbitrary_rect3
, arbitrary_bool1
, arbitrary_float2
,
358 arbitrary_blend_mode2
, arbitrary_context_id2
);
359 SharedQuadState
* shared_state2_cmp
=
360 pass_cmp
->CreateAndAppendSharedQuadState();
361 shared_state2_cmp
->CopyFrom(shared_state2_in
);
363 RenderPassDrawQuad
* renderpass_in
=
364 pass_in
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
365 renderpass_in
->SetAll(
366 shared_state2_in
, arbitrary_rect1
, arbitrary_rect2_inside_rect1
,
367 arbitrary_rect1_inside_rect1
, arbitrary_bool1
, child_id
,
368 arbitrary_resourceid2
, arbitrary_vector2df1
, arbitrary_size1
,
369 arbitrary_filters1
, arbitrary_vector2df2
, arbitrary_filters2
);
370 pass_cmp
->CopyFromAndAppendRenderPassDrawQuad(
372 renderpass_in
->shared_quad_state
,
373 renderpass_in
->render_pass_id
);
375 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
376 shared_state3_in
->SetAll(arbitrary_matrix1
, arbitrary_size3
, arbitrary_rect3
,
377 arbitrary_rect1
, arbitrary_bool1
, arbitrary_float3
,
378 arbitrary_blend_mode3
, arbitrary_context_id3
);
379 SharedQuadState
* shared_state3_cmp
=
380 pass_cmp
->CreateAndAppendSharedQuadState();
381 shared_state3_cmp
->CopyFrom(shared_state3_in
);
383 SolidColorDrawQuad
* solidcolor_in
=
384 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
385 solidcolor_in
->SetAll(shared_state3_in
,
387 arbitrary_rect1_inside_rect3
,
388 arbitrary_rect2_inside_rect3
,
392 pass_cmp
->CopyFromAndAppendDrawQuad(solidcolor_in
,
393 solidcolor_in
->shared_quad_state
);
395 StreamVideoDrawQuad
* streamvideo_in
=
396 pass_in
->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
397 streamvideo_in
->SetAll(shared_state3_in
, arbitrary_rect2
,
398 arbitrary_rect2_inside_rect2
,
399 arbitrary_rect1_inside_rect2
, arbitrary_bool1
,
400 arbitrary_resourceid2
, arbitrary_matrix1
);
401 pass_cmp
->CopyFromAndAppendDrawQuad(streamvideo_in
,
402 streamvideo_in
->shared_quad_state
);
404 cc::SurfaceId
arbitrary_surface_id(3);
405 SurfaceDrawQuad
* surface_in
=
406 pass_in
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
407 surface_in
->SetAll(shared_state3_in
,
409 arbitrary_rect2_inside_rect2
,
410 arbitrary_rect1_inside_rect2
,
412 arbitrary_surface_id
);
413 pass_cmp
->CopyFromAndAppendDrawQuad(surface_in
,
414 surface_in
->shared_quad_state
);
416 TextureDrawQuad
* texture_in
=
417 pass_in
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
418 texture_in
->SetAll(shared_state3_in
,
420 arbitrary_rect2_inside_rect2
,
421 arbitrary_rect1_inside_rect2
,
423 arbitrary_resourceid1
,
428 arbitrary_float_array
,
431 pass_cmp
->CopyFromAndAppendDrawQuad(texture_in
,
432 texture_in
->shared_quad_state
);
434 TileDrawQuad
* tile_in
= pass_in
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
435 tile_in
->SetAll(shared_state3_in
,
437 arbitrary_rect2_inside_rect2
,
438 arbitrary_rect1_inside_rect2
,
440 arbitrary_resourceid3
,
445 pass_cmp
->CopyFromAndAppendDrawQuad(tile_in
, tile_in
->shared_quad_state
);
447 YUVVideoDrawQuad
* yuvvideo_in
=
448 pass_in
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
449 yuvvideo_in
->SetAll(shared_state3_in
,
451 arbitrary_rect2_inside_rect1
,
452 arbitrary_rect1_inside_rect1
,
457 arbitrary_resourceid1
,
458 arbitrary_resourceid2
,
459 arbitrary_resourceid3
,
460 arbitrary_resourceid4
,
461 arbitrary_color_space
);
462 pass_cmp
->CopyFromAndAppendDrawQuad(yuvvideo_in
,
463 yuvvideo_in
->shared_quad_state
);
465 // Make sure the in and cmp RenderPasses match.
466 Compare(child_pass_cmp
.get(), child_pass_in
.get());
467 ASSERT_EQ(0u, child_pass_in
->shared_quad_state_list
.size());
468 ASSERT_EQ(0u, child_pass_in
->quad_list
.size());
469 Compare(pass_cmp
.get(), pass_in
.get());
470 ASSERT_EQ(3u, pass_in
->shared_quad_state_list
.size());
471 ASSERT_EQ(10u, pass_in
->quad_list
.size());
472 for (cc::SharedQuadStateList::ConstIterator
473 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
474 in_iterator
= pass_in
->shared_quad_state_list
.begin();
475 in_iterator
!= pass_in
->shared_quad_state_list
.end();
476 ++cmp_iterator
, ++in_iterator
) {
477 Compare(*cmp_iterator
, *in_iterator
);
479 for (auto in_iter
= pass_in
->quad_list
.cbegin(),
480 cmp_iter
= pass_cmp
->quad_list
.cbegin();
481 in_iter
!= pass_in
->quad_list
.cend();
482 ++in_iter
, ++cmp_iter
)
483 Compare(*cmp_iter
, *in_iter
);
485 for (size_t i
= 1; i
< pass_in
->quad_list
.size(); ++i
) {
486 bool same_shared_quad_state_cmp
=
487 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
488 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
489 bool same_shared_quad_state_in
=
490 pass_in
->quad_list
.ElementAt(i
)->shared_quad_state
==
491 pass_in
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
492 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_in
);
495 DelegatedFrameData frame_in
;
496 frame_in
.render_pass_list
.push_back(child_pass_in
.Pass());
497 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
499 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
501 DelegatedFrameData frame_out
;
502 PickleIterator
iter(msg
);
503 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
506 // Make sure the out and cmp RenderPasses match.
507 scoped_ptr
<RenderPass
> child_pass_out
=
508 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
509 Compare(child_pass_cmp
.get(), child_pass_out
.get());
510 ASSERT_EQ(0u, child_pass_out
->shared_quad_state_list
.size());
511 ASSERT_EQ(0u, child_pass_out
->quad_list
.size());
512 scoped_ptr
<RenderPass
> pass_out
=
513 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin() + 1);
514 Compare(pass_cmp
.get(), pass_out
.get());
515 ASSERT_EQ(3u, pass_out
->shared_quad_state_list
.size());
516 ASSERT_EQ(10u, pass_out
->quad_list
.size());
517 for (cc::SharedQuadStateList::ConstIterator
518 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
519 out_iterator
= pass_out
->shared_quad_state_list
.begin();
520 out_iterator
!= pass_out
->shared_quad_state_list
.end();
521 ++cmp_iterator
, ++out_iterator
) {
522 Compare(*cmp_iterator
, *out_iterator
);
524 for (auto out_iter
= pass_out
->quad_list
.cbegin(),
525 cmp_iter
= pass_cmp
->quad_list
.cbegin();
526 out_iter
!= pass_out
->quad_list
.cend();
527 ++out_iter
, ++cmp_iter
)
528 Compare(*cmp_iter
, *out_iter
);
530 for (size_t i
= 1; i
< pass_out
->quad_list
.size(); ++i
) {
531 bool same_shared_quad_state_cmp
=
532 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
533 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
534 bool same_shared_quad_state_out
=
535 pass_out
->quad_list
.ElementAt(i
)->shared_quad_state
==
536 pass_out
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
537 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_out
);
541 TEST_F(CCMessagesTest
, UnusedSharedQuadStates
) {
542 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
543 pass_in
->SetAll(RenderPassId(1, 1),
549 // The first SharedQuadState is used.
550 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
551 shared_state1_in
->SetAll(gfx::Transform(),
557 SkXfermode::kSrcOver_Mode
,
560 CheckerboardDrawQuad
* quad1
=
561 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
562 quad1
->SetAll(shared_state1_in
, gfx::Rect(10, 10), gfx::Rect(10, 10),
563 gfx::Rect(10, 10), false, SK_ColorRED
, 1.f
);
565 // The second and third SharedQuadStates are not used.
566 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
567 shared_state2_in
->SetAll(gfx::Transform(),
573 SkXfermode::kSrcOver_Mode
,
576 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
577 shared_state3_in
->SetAll(gfx::Transform(),
583 SkXfermode::kSrcOver_Mode
,
586 // The fourth SharedQuadState is used.
587 SharedQuadState
* shared_state4_in
= pass_in
->CreateAndAppendSharedQuadState();
588 shared_state4_in
->SetAll(gfx::Transform(),
594 SkXfermode::kSrcOver_Mode
,
597 CheckerboardDrawQuad
* quad2
=
598 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
599 quad2
->SetAll(shared_state4_in
, gfx::Rect(10, 10), gfx::Rect(10, 10),
600 gfx::Rect(10, 10), false, SK_ColorRED
, 1.f
);
602 // The fifth is not used again.
603 SharedQuadState
* shared_state5_in
= pass_in
->CreateAndAppendSharedQuadState();
604 shared_state5_in
->SetAll(gfx::Transform(),
610 SkXfermode::kSrcOver_Mode
,
613 // 5 SharedQuadStates go in.
614 ASSERT_EQ(5u, pass_in
->shared_quad_state_list
.size());
615 ASSERT_EQ(2u, pass_in
->quad_list
.size());
617 DelegatedFrameData frame_in
;
618 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
620 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
621 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
623 DelegatedFrameData frame_out
;
624 PickleIterator
iter(msg
);
626 IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
, &iter
, &frame_out
));
628 scoped_ptr
<RenderPass
> pass_out
=
629 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
631 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
632 // used by quads, and so serialized. Others were not.
633 ASSERT_EQ(2u, pass_out
->shared_quad_state_list
.size());
634 ASSERT_EQ(2u, pass_out
->quad_list
.size());
637 gfx::Size(1, 1).ToString(),
638 pass_out
->shared_quad_state_list
.ElementAt(0)->content_bounds
.ToString());
640 gfx::Size(4, 4).ToString(),
641 pass_out
->shared_quad_state_list
.ElementAt(1)->content_bounds
.ToString());
644 TEST_F(CCMessagesTest
, Resources
) {
645 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
646 gfx::Size
arbitrary_size(757, 1281);
647 unsigned int arbitrary_uint1
= 71234838;
648 unsigned int arbitrary_uint2
= 53589793;
650 GLbyte arbitrary_mailbox1
[GL_MAILBOX_SIZE_CHROMIUM
] = {
651 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
652 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
653 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
655 GLbyte arbitrary_mailbox2
[GL_MAILBOX_SIZE_CHROMIUM
] = {
656 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
657 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
658 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
660 TransferableResource arbitrary_resource1
;
661 arbitrary_resource1
.id
= 2178312;
662 arbitrary_resource1
.format
= cc::RGBA_8888
;
663 arbitrary_resource1
.filter
= 53;
664 arbitrary_resource1
.size
= gfx::Size(37189, 123123);
665 arbitrary_resource1
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox1
);
666 arbitrary_resource1
.mailbox_holder
.texture_target
= GL_TEXTURE_2D
;
667 arbitrary_resource1
.mailbox_holder
.sync_point
= arbitrary_uint1
;
668 arbitrary_resource1
.allow_overlay
= true;
670 TransferableResource arbitrary_resource2
;
671 arbitrary_resource2
.id
= 789132;
672 arbitrary_resource2
.format
= cc::RGBA_4444
;
673 arbitrary_resource2
.filter
= 47;
674 arbitrary_resource2
.size
= gfx::Size(89123, 23789);
675 arbitrary_resource2
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox2
);
676 arbitrary_resource2
.mailbox_holder
.texture_target
= GL_TEXTURE_EXTERNAL_OES
;
677 arbitrary_resource2
.mailbox_holder
.sync_point
= arbitrary_uint2
;
678 arbitrary_resource2
.allow_overlay
= false;
680 scoped_ptr
<RenderPass
> renderpass_in
= RenderPass::Create();
681 renderpass_in
->SetNew(
682 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
684 DelegatedFrameData frame_in
;
685 frame_in
.resource_list
.push_back(arbitrary_resource1
);
686 frame_in
.resource_list
.push_back(arbitrary_resource2
);
687 frame_in
.render_pass_list
.push_back(renderpass_in
.Pass());
689 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
691 DelegatedFrameData frame_out
;
692 PickleIterator
iter(msg
);
693 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
696 ASSERT_EQ(2u, frame_out
.resource_list
.size());
697 Compare(arbitrary_resource1
, frame_out
.resource_list
[0]);
698 Compare(arbitrary_resource2
, frame_out
.resource_list
[1]);
701 TEST_F(CCMessagesTest
, SoftwareFrameData
) {
702 cc::SoftwareFrameData frame_in
;
704 frame_in
.size
= gfx::Size(40, 20);
705 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
706 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
709 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
710 IPC::ParamTraits
<cc::SoftwareFrameData
>::Write(&msg
, frame_in
);
713 cc::SoftwareFrameData frame_out
;
714 PickleIterator
iter(msg
);
716 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
717 EXPECT_EQ(frame_in
.id
, frame_out
.id
);
718 EXPECT_EQ(frame_in
.size
.ToString(), frame_out
.size
.ToString());
719 EXPECT_EQ(frame_in
.damage_rect
.ToString(), frame_out
.damage_rect
.ToString());
720 EXPECT_EQ(frame_in
.bitmap_id
, frame_out
.bitmap_id
);
723 TEST_F(CCMessagesTest
, SoftwareFrameDataMaxInt
) {
724 SoftwareFrameData frame_in
;
726 frame_in
.size
= gfx::Size(40, 20);
727 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
728 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
730 // Write the SoftwareFrameData by hand, make sure it works.
732 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
733 IPC::WriteParam(&msg
, frame_in
.id
);
734 IPC::WriteParam(&msg
, frame_in
.size
);
735 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
736 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
737 SoftwareFrameData frame_out
;
738 PickleIterator
iter(msg
);
740 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
743 // The size of the frame may overflow when multiplied together.
744 int max
= std::numeric_limits
<int>::max();
745 frame_in
.size
= gfx::Size(max
, max
);
747 // If size_t is larger than int, then int*int*4 can always fit in size_t.
748 bool expect_read
= sizeof(size_t) >= sizeof(int) * 2;
750 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
753 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
754 IPC::WriteParam(&msg
, frame_in
.id
);
755 IPC::WriteParam(&msg
, frame_in
.size
);
756 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
757 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
758 SoftwareFrameData frame_out
;
759 PickleIterator
iter(msg
);
762 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
767 } // namespace content