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::RenderPassDrawQuad
;
32 using cc::ResourceProvider
;
33 using cc::SharedQuadState
;
34 using cc::SoftwareFrameData
;
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::VideoLayerImpl
;
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
);
133 void Compare(const DebugBorderDrawQuad
* a
, const DebugBorderDrawQuad
* b
) {
134 EXPECT_EQ(a
->color
, b
->color
);
135 EXPECT_EQ(a
->width
, b
->width
);
138 void Compare(const IOSurfaceDrawQuad
* a
, const IOSurfaceDrawQuad
* b
) {
139 EXPECT_EQ(a
->io_surface_size
.ToString(), b
->io_surface_size
.ToString());
140 EXPECT_EQ(a
->io_surface_resource_id
, b
->io_surface_resource_id
);
141 EXPECT_EQ(a
->orientation
, b
->orientation
);
144 void Compare(const RenderPassDrawQuad
* a
, const RenderPassDrawQuad
* b
) {
145 EXPECT_EQ(a
->render_pass_id
, b
->render_pass_id
);
146 EXPECT_EQ(a
->is_replica
, b
->is_replica
);
147 EXPECT_EQ(a
->mask_resource_id
, b
->mask_resource_id
);
148 EXPECT_EQ(a
->contents_changed_since_last_frame
,
149 b
->contents_changed_since_last_frame
);
150 EXPECT_EQ(a
->mask_uv_rect
.ToString(), b
->mask_uv_rect
.ToString());
151 EXPECT_EQ(a
->filters
.size(), b
->filters
.size());
152 for (size_t i
= 0; i
< a
->filters
.size(); ++i
) {
153 if (a
->filters
.at(i
).type() != cc::FilterOperation::REFERENCE
) {
154 EXPECT_EQ(a
->filters
.at(i
), b
->filters
.at(i
));
156 EXPECT_EQ(b
->filters
.at(i
).type(), cc::FilterOperation::REFERENCE
);
157 EXPECT_EQ(a
->filters
.at(i
).image_filter()->countInputs(),
158 b
->filters
.at(i
).image_filter()->countInputs());
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
);
191 void Compare(const TileDrawQuad
* a
, const TileDrawQuad
* b
) {
192 EXPECT_EQ(a
->resource_id
, b
->resource_id
);
193 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
194 EXPECT_EQ(a
->texture_size
, b
->texture_size
);
195 EXPECT_EQ(a
->swizzle_contents
, b
->swizzle_contents
);
198 void Compare(const YUVVideoDrawQuad
* a
, const YUVVideoDrawQuad
* b
) {
199 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
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
);
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 float arbitrary_float1
= 0.7f
;
245 float arbitrary_float2
= 0.3f
;
246 float arbitrary_float3
= 0.9f
;
247 float arbitrary_float_array
[4] = {3.5f
, 6.2f
, 9.3f
, 12.3f
};
248 bool arbitrary_bool1
= true;
249 bool arbitrary_bool2
= false;
250 bool arbitrary_bool3
= true;
251 int arbitrary_context_id1
= 12;
252 int arbitrary_context_id2
= 57;
253 int arbitrary_context_id3
= -503;
254 int arbitrary_int
= 5;
255 SkColor arbitrary_color
= SkColorSetARGB(25, 36, 47, 58);
256 SkXfermode::Mode arbitrary_blend_mode1
= SkXfermode::kScreen_Mode
;
257 SkXfermode::Mode arbitrary_blend_mode2
= SkXfermode::kLighten_Mode
;
258 SkXfermode::Mode arbitrary_blend_mode3
= SkXfermode::kOverlay_Mode
;
259 IOSurfaceDrawQuad::Orientation arbitrary_orientation
=
260 IOSurfaceDrawQuad::UNFLIPPED
;
261 RenderPass::Id
arbitrary_id(10, 14);
262 ResourceProvider::ResourceId arbitrary_resourceid1
= 55;
263 ResourceProvider::ResourceId arbitrary_resourceid2
= 47;
264 ResourceProvider::ResourceId arbitrary_resourceid3
= 23;
265 ResourceProvider::ResourceId arbitrary_resourceid4
= 16;
266 SkScalar arbitrary_sigma
= SkFloatToScalar(2.0f
);
267 YUVVideoDrawQuad::ColorSpace arbitrary_color_space
=
268 YUVVideoDrawQuad::REC_601
;
270 FilterOperations arbitrary_filters1
;
271 arbitrary_filters1
.Append(FilterOperation::CreateGrayscaleFilter(
273 skia::RefPtr
<SkImageFilter
> arbitrary_filter
= skia::AdoptRef(
274 SkBlurImageFilter::Create(arbitrary_sigma
, arbitrary_sigma
));
275 arbitrary_filters1
.Append(
276 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter
));
278 FilterOperations arbitrary_filters2
;
279 arbitrary_filters2
.Append(FilterOperation::CreateBrightnessFilter(
282 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
283 pass_in
->SetAll(arbitrary_id
,
289 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
290 shared_state1_in
->SetAll(arbitrary_matrix
,
296 arbitrary_blend_mode1
,
297 arbitrary_context_id1
);
299 scoped_ptr
<RenderPass
> pass_cmp
= RenderPass::Create();
300 pass_cmp
->SetAll(arbitrary_id
,
306 SharedQuadState
* shared_state1_cmp
=
307 pass_cmp
->CreateAndAppendSharedQuadState();
308 shared_state1_cmp
->CopyFrom(shared_state1_in
);
310 CheckerboardDrawQuad
* checkerboard_in
=
311 pass_in
->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
312 checkerboard_in
->SetAll(shared_state1_in
,
314 arbitrary_rect2_inside_rect1
,
315 arbitrary_rect1_inside_rect1
,
318 pass_cmp
->CopyFromAndAppendDrawQuad(checkerboard_in
,
319 checkerboard_in
->shared_quad_state
);
321 DebugBorderDrawQuad
* debugborder_in
=
322 pass_in
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
323 debugborder_in
->SetAll(shared_state1_in
,
325 arbitrary_rect1_inside_rect3
,
326 arbitrary_rect2_inside_rect3
,
330 pass_cmp
->CopyFromAndAppendDrawQuad(debugborder_in
,
331 debugborder_in
->shared_quad_state
);
333 IOSurfaceDrawQuad
* iosurface_in
=
334 pass_in
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
335 iosurface_in
->SetAll(shared_state1_in
,
337 arbitrary_rect2_inside_rect2
,
338 arbitrary_rect1_inside_rect2
,
341 arbitrary_resourceid3
,
342 arbitrary_orientation
);
343 pass_cmp
->CopyFromAndAppendDrawQuad(iosurface_in
,
344 iosurface_in
->shared_quad_state
);
346 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
347 shared_state2_in
->SetAll(arbitrary_matrix
,
353 arbitrary_blend_mode2
,
354 arbitrary_context_id2
);
355 SharedQuadState
* shared_state2_cmp
=
356 pass_cmp
->CreateAndAppendSharedQuadState();
357 shared_state2_cmp
->CopyFrom(shared_state2_in
);
359 RenderPassDrawQuad
* renderpass_in
=
360 pass_in
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
361 renderpass_in
->SetAll(shared_state2_in
,
363 arbitrary_rect2_inside_rect1
,
364 arbitrary_rect1_inside_rect1
,
368 arbitrary_resourceid2
,
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(RenderPass::Id(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
;
659 TransferableResource arbitrary_resource2
;
660 arbitrary_resource2
.id
= 789132;
661 arbitrary_resource2
.format
= cc::RGBA_4444
;
662 arbitrary_resource2
.filter
= 47;
663 arbitrary_resource2
.size
= gfx::Size(89123, 23789);
664 arbitrary_resource2
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox2
);
665 arbitrary_resource2
.mailbox_holder
.texture_target
= GL_TEXTURE_EXTERNAL_OES
;
666 arbitrary_resource2
.mailbox_holder
.sync_point
= arbitrary_uint2
;
668 scoped_ptr
<RenderPass
> renderpass_in
= RenderPass::Create();
669 renderpass_in
->SetNew(
670 RenderPass::Id(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
672 DelegatedFrameData frame_in
;
673 frame_in
.resource_list
.push_back(arbitrary_resource1
);
674 frame_in
.resource_list
.push_back(arbitrary_resource2
);
675 frame_in
.render_pass_list
.push_back(renderpass_in
.Pass());
677 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
679 DelegatedFrameData frame_out
;
680 PickleIterator
iter(msg
);
681 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
684 ASSERT_EQ(2u, frame_out
.resource_list
.size());
685 Compare(arbitrary_resource1
, frame_out
.resource_list
[0]);
686 Compare(arbitrary_resource2
, frame_out
.resource_list
[1]);
689 TEST_F(CCMessagesTest
, LargestQuadType
) {
693 for (int i
= 0; !done
; ++i
) {
694 switch (static_cast<DrawQuad::Material
>(i
)) {
695 case cc::DrawQuad::CHECKERBOARD
:
696 largest
= std::max(largest
, sizeof(cc::CheckerboardDrawQuad
));
698 case cc::DrawQuad::DEBUG_BORDER
:
699 largest
= std::max(largest
, sizeof(cc::DebugBorderDrawQuad
));
701 case cc::DrawQuad::IO_SURFACE_CONTENT
:
702 largest
= std::max(largest
, sizeof(cc::IOSurfaceDrawQuad
));
704 case cc::DrawQuad::PICTURE_CONTENT
:
705 largest
= std::max(largest
, sizeof(cc::PictureDrawQuad
));
707 case cc::DrawQuad::TEXTURE_CONTENT
:
708 largest
= std::max(largest
, sizeof(cc::TextureDrawQuad
));
710 case cc::DrawQuad::RENDER_PASS
:
711 largest
= std::max(largest
, sizeof(cc::RenderPassDrawQuad
));
713 case cc::DrawQuad::SOLID_COLOR
:
714 largest
= std::max(largest
, sizeof(cc::SolidColorDrawQuad
));
716 case cc::DrawQuad::SURFACE_CONTENT
:
717 largest
= std::max(largest
, sizeof(cc::SurfaceDrawQuad
));
719 case cc::DrawQuad::TILED_CONTENT
:
720 largest
= std::max(largest
, sizeof(cc::TileDrawQuad
));
722 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
723 largest
= std::max(largest
, sizeof(cc::StreamVideoDrawQuad
));
725 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
726 largest
= std::max(largest
, sizeof(cc::YUVVideoDrawQuad
));
728 case cc::DrawQuad::INVALID
:
735 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever
736 // changes, then the ReserveSizeForRenderPassWrite() method needs to be
737 // updated as well to use the new largest quad.
738 EXPECT_EQ(sizeof(RenderPassDrawQuad
), largest
);
741 TEST_F(CCMessagesTest
, SoftwareFrameData
) {
742 cc::SoftwareFrameData frame_in
;
744 frame_in
.size
= gfx::Size(40, 20);
745 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
746 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
749 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
750 IPC::ParamTraits
<cc::SoftwareFrameData
>::Write(&msg
, frame_in
);
753 cc::SoftwareFrameData frame_out
;
754 PickleIterator
iter(msg
);
756 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
757 EXPECT_EQ(frame_in
.id
, frame_out
.id
);
758 EXPECT_EQ(frame_in
.size
.ToString(), frame_out
.size
.ToString());
759 EXPECT_EQ(frame_in
.damage_rect
.ToString(), frame_out
.damage_rect
.ToString());
760 EXPECT_EQ(frame_in
.bitmap_id
, frame_out
.bitmap_id
);
763 TEST_F(CCMessagesTest
, SoftwareFrameDataMaxInt
) {
764 SoftwareFrameData frame_in
;
766 frame_in
.size
= gfx::Size(40, 20);
767 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
768 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
770 // Write the SoftwareFrameData by hand, make sure it works.
772 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
773 IPC::WriteParam(&msg
, frame_in
.id
);
774 IPC::WriteParam(&msg
, frame_in
.size
);
775 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
776 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
777 SoftwareFrameData frame_out
;
778 PickleIterator
iter(msg
);
780 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
783 // The size of the frame may overflow when multiplied together.
784 int max
= std::numeric_limits
<int>::max();
785 frame_in
.size
= gfx::Size(max
, max
);
787 // If size_t is larger than int, then int*int*4 can always fit in size_t.
788 bool expect_read
= sizeof(size_t) >= sizeof(int) * 2;
790 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
793 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
794 IPC::WriteParam(&msg
, frame_in
.id
);
795 IPC::WriteParam(&msg
, frame_in
.size
);
796 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
797 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
798 SoftwareFrameData frame_out
;
799 PickleIterator
iter(msg
);
802 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
807 } // namespace content