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_rect
.ToString(), b
->mask_uv_rect
.ToString());
149 EXPECT_EQ(a
->filters
.size(), b
->filters
.size());
150 for (size_t i
= 0; i
< a
->filters
.size(); ++i
) {
151 if (a
->filters
.at(i
).type() != cc::FilterOperation::REFERENCE
) {
152 EXPECT_EQ(a
->filters
.at(i
), b
->filters
.at(i
));
154 EXPECT_EQ(b
->filters
.at(i
).type(), cc::FilterOperation::REFERENCE
);
155 EXPECT_EQ(a
->filters
.at(i
).image_filter()->countInputs(),
156 b
->filters
.at(i
).image_filter()->countInputs());
159 EXPECT_EQ(a
->filters_scale
, b
->filters_scale
);
160 EXPECT_EQ(a
->background_filters
, b
->background_filters
);
163 void Compare(const SolidColorDrawQuad
* a
, const SolidColorDrawQuad
* b
) {
164 EXPECT_EQ(a
->color
, b
->color
);
165 EXPECT_EQ(a
->force_anti_aliasing_off
, b
->force_anti_aliasing_off
);
168 void Compare(const StreamVideoDrawQuad
* a
, const StreamVideoDrawQuad
* b
) {
169 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
170 EXPECT_EQ(a
->matrix
, b
->matrix
);
173 void Compare(const SurfaceDrawQuad
* a
, const SurfaceDrawQuad
* b
) {
174 EXPECT_EQ(a
->surface_id
, b
->surface_id
);
177 void Compare(const TextureDrawQuad
* a
, const TextureDrawQuad
* b
) {
178 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
179 EXPECT_EQ(a
->premultiplied_alpha
, b
->premultiplied_alpha
);
180 EXPECT_EQ(a
->uv_top_left
, b
->uv_top_left
);
181 EXPECT_EQ(a
->uv_bottom_right
, b
->uv_bottom_right
);
182 EXPECT_EQ(a
->background_color
, b
->background_color
);
183 EXPECT_EQ(a
->vertex_opacity
[0], b
->vertex_opacity
[0]);
184 EXPECT_EQ(a
->vertex_opacity
[1], b
->vertex_opacity
[1]);
185 EXPECT_EQ(a
->vertex_opacity
[2], b
->vertex_opacity
[2]);
186 EXPECT_EQ(a
->vertex_opacity
[3], b
->vertex_opacity
[3]);
187 EXPECT_EQ(a
->flipped
, b
->flipped
);
190 void Compare(const TileDrawQuad
* a
, const TileDrawQuad
* b
) {
191 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
192 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
193 EXPECT_EQ(a
->texture_size
, b
->texture_size
);
194 EXPECT_EQ(a
->swizzle_contents
, b
->swizzle_contents
);
197 void Compare(const YUVVideoDrawQuad
* a
, const YUVVideoDrawQuad
* b
) {
198 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
199 EXPECT_EQ(a
->y_plane_resource_id
, b
->y_plane_resource_id
);
200 EXPECT_EQ(a
->u_plane_resource_id
, b
->u_plane_resource_id
);
201 EXPECT_EQ(a
->v_plane_resource_id
, b
->v_plane_resource_id
);
202 EXPECT_EQ(a
->a_plane_resource_id
, b
->a_plane_resource_id
);
203 EXPECT_EQ(a
->color_space
, b
->color_space
);
206 void Compare(const TransferableResource
& a
, const TransferableResource
& b
) {
207 EXPECT_EQ(a
.id
, b
.id
);
208 EXPECT_EQ(a
.format
, b
.format
);
209 EXPECT_EQ(a
.filter
, b
.filter
);
210 EXPECT_EQ(a
.size
.ToString(), b
.size
.ToString());
211 for (size_t i
= 0; i
< arraysize(a
.mailbox_holder
.mailbox
.name
); ++i
) {
212 EXPECT_EQ(a
.mailbox_holder
.mailbox
.name
[i
],
213 b
.mailbox_holder
.mailbox
.name
[i
]);
215 EXPECT_EQ(a
.mailbox_holder
.texture_target
, b
.mailbox_holder
.texture_target
);
216 EXPECT_EQ(a
.mailbox_holder
.sync_point
, b
.mailbox_holder
.sync_point
);
217 EXPECT_EQ(a
.allow_overlay
, b
.allow_overlay
);
221 TEST_F(CCMessagesTest
, AllQuads
) {
222 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
224 Transform arbitrary_matrix
;
225 arbitrary_matrix
.Scale(3, 3);
226 arbitrary_matrix
.Translate(-5, 20);
227 arbitrary_matrix
.Rotate(15);
228 gfx::Rect
arbitrary_rect1(-5, 9, 3, 15);
229 gfx::Rect
arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
230 gfx::Rect
arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
231 gfx::Rect
arbitrary_rect2(40, 23, 11, 7);
232 gfx::Rect
arbitrary_rect1_inside_rect2(44, 23, 4, 2);
233 gfx::Rect
arbitrary_rect2_inside_rect2(41, 25, 3, 5);
234 gfx::Rect
arbitrary_rect3(7, -53, 22, 19);
235 gfx::Rect
arbitrary_rect1_inside_rect3(10, -40, 6, 3);
236 gfx::Rect
arbitrary_rect2_inside_rect3(12, -51, 5, 12);
237 gfx::Size
arbitrary_size1(15, 19);
238 gfx::Size
arbitrary_size2(3, 99);
239 gfx::Size
arbitrary_size3(75, 1281);
240 gfx::RectF
arbitrary_rectf1(4.2f
, -922.1f
, 15.6f
, 29.5f
);
241 gfx::SizeF
arbitrary_sizef1(15.2f
, 104.6f
);
242 gfx::PointF
arbitrary_pointf1(31.4f
, 15.9f
);
243 gfx::PointF
arbitrary_pointf2(26.5f
, -35.8f
);
244 gfx::Vector2dF
arbitrary_vector2df1(16.2f
, -85.1f
);
245 float arbitrary_float1
= 0.7f
;
246 float arbitrary_float2
= 0.3f
;
247 float arbitrary_float3
= 0.9f
;
248 float arbitrary_float_array
[4] = {3.5f
, 6.2f
, 9.3f
, 12.3f
};
249 bool arbitrary_bool1
= true;
250 bool arbitrary_bool2
= false;
251 bool arbitrary_bool3
= true;
252 int arbitrary_context_id1
= 12;
253 int arbitrary_context_id2
= 57;
254 int arbitrary_context_id3
= -503;
255 int arbitrary_int
= 5;
256 SkColor arbitrary_color
= SkColorSetARGB(25, 36, 47, 58);
257 SkXfermode::Mode arbitrary_blend_mode1
= SkXfermode::kScreen_Mode
;
258 SkXfermode::Mode arbitrary_blend_mode2
= SkXfermode::kLighten_Mode
;
259 SkXfermode::Mode arbitrary_blend_mode3
= SkXfermode::kOverlay_Mode
;
260 IOSurfaceDrawQuad::Orientation arbitrary_orientation
=
261 IOSurfaceDrawQuad::UNFLIPPED
;
262 RenderPassId
arbitrary_id(10, 14);
263 ResourceProvider::ResourceId arbitrary_resourceid1
= 55;
264 ResourceProvider::ResourceId arbitrary_resourceid2
= 47;
265 ResourceProvider::ResourceId arbitrary_resourceid3
= 23;
266 ResourceProvider::ResourceId arbitrary_resourceid4
= 16;
267 SkScalar arbitrary_sigma
= SkFloatToScalar(2.0f
);
268 YUVVideoDrawQuad::ColorSpace arbitrary_color_space
=
269 YUVVideoDrawQuad::REC_601
;
271 FilterOperations arbitrary_filters1
;
272 arbitrary_filters1
.Append(FilterOperation::CreateGrayscaleFilter(
274 skia::RefPtr
<SkImageFilter
> arbitrary_filter
= skia::AdoptRef(
275 SkBlurImageFilter::Create(arbitrary_sigma
, arbitrary_sigma
));
276 arbitrary_filters1
.Append(
277 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter
));
279 FilterOperations arbitrary_filters2
;
280 arbitrary_filters2
.Append(FilterOperation::CreateBrightnessFilter(
283 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
284 pass_in
->SetAll(arbitrary_id
,
290 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
291 shared_state1_in
->SetAll(arbitrary_matrix
,
297 arbitrary_blend_mode1
,
298 arbitrary_context_id1
);
300 scoped_ptr
<RenderPass
> pass_cmp
= RenderPass::Create();
301 pass_cmp
->SetAll(arbitrary_id
,
307 SharedQuadState
* shared_state1_cmp
=
308 pass_cmp
->CreateAndAppendSharedQuadState();
309 shared_state1_cmp
->CopyFrom(shared_state1_in
);
311 CheckerboardDrawQuad
* checkerboard_in
=
312 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
313 checkerboard_in
->SetAll(shared_state1_in
,
315 arbitrary_rect2_inside_rect1
,
316 arbitrary_rect1_inside_rect1
,
319 pass_cmp
->CopyFromAndAppendDrawQuad(checkerboard_in
,
320 checkerboard_in
->shared_quad_state
);
322 DebugBorderDrawQuad
* debugborder_in
=
323 pass_in
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
324 debugborder_in
->SetAll(shared_state1_in
,
326 arbitrary_rect1_inside_rect3
,
327 arbitrary_rect2_inside_rect3
,
331 pass_cmp
->CopyFromAndAppendDrawQuad(debugborder_in
,
332 debugborder_in
->shared_quad_state
);
334 IOSurfaceDrawQuad
* iosurface_in
=
335 pass_in
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
336 iosurface_in
->SetAll(shared_state1_in
,
338 arbitrary_rect2_inside_rect2
,
339 arbitrary_rect1_inside_rect2
,
342 arbitrary_resourceid3
,
343 arbitrary_orientation
);
344 pass_cmp
->CopyFromAndAppendDrawQuad(iosurface_in
,
345 iosurface_in
->shared_quad_state
);
347 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
348 shared_state2_in
->SetAll(arbitrary_matrix
,
354 arbitrary_blend_mode2
,
355 arbitrary_context_id2
);
356 SharedQuadState
* shared_state2_cmp
=
357 pass_cmp
->CreateAndAppendSharedQuadState();
358 shared_state2_cmp
->CopyFrom(shared_state2_in
);
360 RenderPassDrawQuad
* renderpass_in
=
361 pass_in
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
362 renderpass_in
->SetAll(shared_state2_in
,
364 arbitrary_rect2_inside_rect1
,
365 arbitrary_rect1_inside_rect1
,
368 arbitrary_resourceid2
,
371 arbitrary_vector2df1
,
373 pass_cmp
->CopyFromAndAppendRenderPassDrawQuad(
375 renderpass_in
->shared_quad_state
,
376 renderpass_in
->render_pass_id
);
378 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
379 shared_state3_in
->SetAll(arbitrary_matrix
,
385 arbitrary_blend_mode3
,
386 arbitrary_context_id3
);
387 SharedQuadState
* shared_state3_cmp
=
388 pass_cmp
->CreateAndAppendSharedQuadState();
389 shared_state3_cmp
->CopyFrom(shared_state3_in
);
391 SolidColorDrawQuad
* solidcolor_in
=
392 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
393 solidcolor_in
->SetAll(shared_state3_in
,
395 arbitrary_rect1_inside_rect3
,
396 arbitrary_rect2_inside_rect3
,
400 pass_cmp
->CopyFromAndAppendDrawQuad(solidcolor_in
,
401 solidcolor_in
->shared_quad_state
);
403 StreamVideoDrawQuad
* streamvideo_in
=
404 pass_in
->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
405 streamvideo_in
->SetAll(shared_state3_in
,
407 arbitrary_rect2_inside_rect2
,
408 arbitrary_rect1_inside_rect2
,
410 arbitrary_resourceid2
,
412 pass_cmp
->CopyFromAndAppendDrawQuad(streamvideo_in
,
413 streamvideo_in
->shared_quad_state
);
415 cc::SurfaceId
arbitrary_surface_id(3);
416 SurfaceDrawQuad
* surface_in
=
417 pass_in
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
418 surface_in
->SetAll(shared_state3_in
,
420 arbitrary_rect2_inside_rect2
,
421 arbitrary_rect1_inside_rect2
,
423 arbitrary_surface_id
);
424 pass_cmp
->CopyFromAndAppendDrawQuad(surface_in
,
425 surface_in
->shared_quad_state
);
427 TextureDrawQuad
* texture_in
=
428 pass_in
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
429 texture_in
->SetAll(shared_state3_in
,
431 arbitrary_rect2_inside_rect2
,
432 arbitrary_rect1_inside_rect2
,
434 arbitrary_resourceid1
,
439 arbitrary_float_array
,
441 pass_cmp
->CopyFromAndAppendDrawQuad(texture_in
,
442 texture_in
->shared_quad_state
);
444 TileDrawQuad
* tile_in
= pass_in
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
445 tile_in
->SetAll(shared_state3_in
,
447 arbitrary_rect2_inside_rect2
,
448 arbitrary_rect1_inside_rect2
,
450 arbitrary_resourceid3
,
454 pass_cmp
->CopyFromAndAppendDrawQuad(tile_in
, tile_in
->shared_quad_state
);
456 YUVVideoDrawQuad
* yuvvideo_in
=
457 pass_in
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
458 yuvvideo_in
->SetAll(shared_state3_in
,
460 arbitrary_rect2_inside_rect1
,
461 arbitrary_rect1_inside_rect1
,
464 arbitrary_resourceid1
,
465 arbitrary_resourceid2
,
466 arbitrary_resourceid3
,
467 arbitrary_resourceid4
,
468 arbitrary_color_space
);
469 pass_cmp
->CopyFromAndAppendDrawQuad(yuvvideo_in
,
470 yuvvideo_in
->shared_quad_state
);
472 // Make sure the in and cmp RenderPasses match.
473 Compare(pass_cmp
.get(), pass_in
.get());
474 ASSERT_EQ(3u, pass_in
->shared_quad_state_list
.size());
475 ASSERT_EQ(10u, pass_in
->quad_list
.size());
476 for (size_t i
= 0; i
< 3; ++i
) {
477 Compare(pass_cmp
->shared_quad_state_list
[i
],
478 pass_in
->shared_quad_state_list
[i
]);
480 for (size_t i
= 0; i
< pass_in
->quad_list
.size(); ++i
)
481 Compare(pass_cmp
->quad_list
[i
], pass_in
->quad_list
[i
]);
482 for (size_t i
= 1; i
< pass_in
->quad_list
.size(); ++i
) {
483 bool same_shared_quad_state_cmp
=
484 pass_cmp
->quad_list
[i
]->shared_quad_state
==
485 pass_cmp
->quad_list
[i
- 1]->shared_quad_state
;
486 bool same_shared_quad_state_in
=
487 pass_in
->quad_list
[i
]->shared_quad_state
==
488 pass_in
->quad_list
[i
- 1]->shared_quad_state
;
489 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_in
);
492 DelegatedFrameData frame_in
;
493 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
495 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
497 DelegatedFrameData frame_out
;
498 PickleIterator
iter(msg
);
499 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
502 // Make sure the out and cmp RenderPasses match.
503 scoped_ptr
<RenderPass
> pass_out
= frame_out
.render_pass_list
.take(
504 frame_out
.render_pass_list
.begin());
505 Compare(pass_cmp
.get(), pass_out
.get());
506 ASSERT_EQ(3u, pass_out
->shared_quad_state_list
.size());
507 ASSERT_EQ(10u, pass_out
->quad_list
.size());
508 for (size_t i
= 0; i
< 3; ++i
) {
509 Compare(pass_cmp
->shared_quad_state_list
[i
],
510 pass_out
->shared_quad_state_list
[i
]);
512 for (size_t i
= 0; i
< pass_out
->quad_list
.size(); ++i
)
513 Compare(pass_cmp
->quad_list
[i
], pass_out
->quad_list
[i
]);
514 for (size_t i
= 1; i
< pass_out
->quad_list
.size(); ++i
) {
515 bool same_shared_quad_state_cmp
=
516 pass_cmp
->quad_list
[i
]->shared_quad_state
==
517 pass_cmp
->quad_list
[i
- 1]->shared_quad_state
;
518 bool same_shared_quad_state_out
=
519 pass_out
->quad_list
[i
]->shared_quad_state
==
520 pass_out
->quad_list
[i
- 1]->shared_quad_state
;
521 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_out
);
525 TEST_F(CCMessagesTest
, UnusedSharedQuadStates
) {
526 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
527 pass_in
->SetAll(RenderPassId(1, 1),
533 // The first SharedQuadState is used.
534 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
535 shared_state1_in
->SetAll(gfx::Transform(),
541 SkXfermode::kSrcOver_Mode
,
544 CheckerboardDrawQuad
* quad1
=
545 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
546 quad1
->SetAll(shared_state1_in
,
553 // The second and third SharedQuadStates are not used.
554 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
555 shared_state2_in
->SetAll(gfx::Transform(),
561 SkXfermode::kSrcOver_Mode
,
564 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
565 shared_state3_in
->SetAll(gfx::Transform(),
571 SkXfermode::kSrcOver_Mode
,
574 // The fourth SharedQuadState is used.
575 SharedQuadState
* shared_state4_in
= pass_in
->CreateAndAppendSharedQuadState();
576 shared_state4_in
->SetAll(gfx::Transform(),
582 SkXfermode::kSrcOver_Mode
,
585 CheckerboardDrawQuad
* quad2
=
586 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
587 quad2
->SetAll(shared_state4_in
,
594 // The fifth is not used again.
595 SharedQuadState
* shared_state5_in
= pass_in
->CreateAndAppendSharedQuadState();
596 shared_state5_in
->SetAll(gfx::Transform(),
602 SkXfermode::kSrcOver_Mode
,
605 // 5 SharedQuadStates go in.
606 ASSERT_EQ(5u, pass_in
->shared_quad_state_list
.size());
607 ASSERT_EQ(2u, pass_in
->quad_list
.size());
609 DelegatedFrameData frame_in
;
610 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
612 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
613 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
615 DelegatedFrameData frame_out
;
616 PickleIterator
iter(msg
);
618 IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
, &iter
, &frame_out
));
620 scoped_ptr
<RenderPass
> pass_out
=
621 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
623 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
624 // used by quads, and so serialized. Others were not.
625 ASSERT_EQ(2u, pass_out
->shared_quad_state_list
.size());
626 ASSERT_EQ(2u, pass_out
->quad_list
.size());
628 EXPECT_EQ(gfx::Size(1, 1).ToString(),
629 pass_out
->shared_quad_state_list
[0]->content_bounds
.ToString());
630 EXPECT_EQ(gfx::Size(4, 4).ToString(),
631 pass_out
->shared_quad_state_list
[1]->content_bounds
.ToString());
634 TEST_F(CCMessagesTest
, Resources
) {
635 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
636 gfx::Size
arbitrary_size(757, 1281);
637 unsigned int arbitrary_uint1
= 71234838;
638 unsigned int arbitrary_uint2
= 53589793;
640 GLbyte arbitrary_mailbox1
[GL_MAILBOX_SIZE_CHROMIUM
] = {
641 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
642 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
643 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
645 GLbyte arbitrary_mailbox2
[GL_MAILBOX_SIZE_CHROMIUM
] = {
646 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
647 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
648 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
650 TransferableResource arbitrary_resource1
;
651 arbitrary_resource1
.id
= 2178312;
652 arbitrary_resource1
.format
= cc::RGBA_8888
;
653 arbitrary_resource1
.filter
= 53;
654 arbitrary_resource1
.size
= gfx::Size(37189, 123123);
655 arbitrary_resource1
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox1
);
656 arbitrary_resource1
.mailbox_holder
.texture_target
= GL_TEXTURE_2D
;
657 arbitrary_resource1
.mailbox_holder
.sync_point
= arbitrary_uint1
;
658 arbitrary_resource1
.allow_overlay
= true;
660 TransferableResource arbitrary_resource2
;
661 arbitrary_resource2
.id
= 789132;
662 arbitrary_resource2
.format
= cc::RGBA_4444
;
663 arbitrary_resource2
.filter
= 47;
664 arbitrary_resource2
.size
= gfx::Size(89123, 23789);
665 arbitrary_resource2
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox2
);
666 arbitrary_resource2
.mailbox_holder
.texture_target
= GL_TEXTURE_EXTERNAL_OES
;
667 arbitrary_resource2
.mailbox_holder
.sync_point
= arbitrary_uint2
;
668 arbitrary_resource2
.allow_overlay
= false;
670 scoped_ptr
<RenderPass
> renderpass_in
= RenderPass::Create();
671 renderpass_in
->SetNew(
672 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
674 DelegatedFrameData frame_in
;
675 frame_in
.resource_list
.push_back(arbitrary_resource1
);
676 frame_in
.resource_list
.push_back(arbitrary_resource2
);
677 frame_in
.render_pass_list
.push_back(renderpass_in
.Pass());
679 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
681 DelegatedFrameData frame_out
;
682 PickleIterator
iter(msg
);
683 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
686 ASSERT_EQ(2u, frame_out
.resource_list
.size());
687 Compare(arbitrary_resource1
, frame_out
.resource_list
[0]);
688 Compare(arbitrary_resource2
, frame_out
.resource_list
[1]);
691 TEST_F(CCMessagesTest
, SoftwareFrameData
) {
692 cc::SoftwareFrameData frame_in
;
694 frame_in
.size
= gfx::Size(40, 20);
695 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
696 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
699 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
700 IPC::ParamTraits
<cc::SoftwareFrameData
>::Write(&msg
, frame_in
);
703 cc::SoftwareFrameData frame_out
;
704 PickleIterator
iter(msg
);
706 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
707 EXPECT_EQ(frame_in
.id
, frame_out
.id
);
708 EXPECT_EQ(frame_in
.size
.ToString(), frame_out
.size
.ToString());
709 EXPECT_EQ(frame_in
.damage_rect
.ToString(), frame_out
.damage_rect
.ToString());
710 EXPECT_EQ(frame_in
.bitmap_id
, frame_out
.bitmap_id
);
713 TEST_F(CCMessagesTest
, SoftwareFrameDataMaxInt
) {
714 SoftwareFrameData frame_in
;
716 frame_in
.size
= gfx::Size(40, 20);
717 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
718 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
720 // Write the SoftwareFrameData by hand, make sure it works.
722 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
723 IPC::WriteParam(&msg
, frame_in
.id
);
724 IPC::WriteParam(&msg
, frame_in
.size
);
725 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
726 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
727 SoftwareFrameData frame_out
;
728 PickleIterator
iter(msg
);
730 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
733 // The size of the frame may overflow when multiplied together.
734 int max
= std::numeric_limits
<int>::max();
735 frame_in
.size
= gfx::Size(max
, max
);
737 // If size_t is larger than int, then int*int*4 can always fit in size_t.
738 bool expect_read
= sizeof(size_t) >= sizeof(int) * 2;
740 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
743 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
744 IPC::WriteParam(&msg
, frame_in
.id
);
745 IPC::WriteParam(&msg
, frame_in
.size
);
746 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
747 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
748 SoftwareFrameData frame_out
;
749 PickleIterator
iter(msg
);
752 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
757 } // namespace content