1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/cc_messages.h"
11 #include "cc/output/compositor_frame.h"
12 #include "content/public/common/common_param_traits.h"
13 #include "ipc/ipc_message.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/khronos/GLES2/gl2ext.h"
16 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
19 #include "base/file_descriptor_posix.h"
22 using cc::DelegatedFrameData
;
23 using cc::DebugBorderDrawQuad
;
25 using cc::FilterOperation
;
26 using cc::FilterOperations
;
27 using cc::IOSurfaceDrawQuad
;
28 using cc::PictureDrawQuad
;
30 using cc::RenderPassId
;
31 using cc::RenderPassDrawQuad
;
33 using cc::ResourceProvider
;
34 using cc::SharedQuadState
;
35 using cc::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
);
56 EXPECT_EQ(a
->referenced_surfaces
, b
->referenced_surfaces
);
59 void Compare(const SharedQuadState
* a
, const SharedQuadState
* b
) {
60 EXPECT_EQ(a
->quad_to_target_transform
, b
->quad_to_target_transform
);
61 EXPECT_EQ(a
->quad_layer_bounds
, b
->quad_layer_bounds
);
62 EXPECT_EQ(a
->visible_quad_layer_rect
, b
->visible_quad_layer_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::DEBUG_BORDER
:
82 Compare(DebugBorderDrawQuad::MaterialCast(a
),
83 DebugBorderDrawQuad::MaterialCast(b
));
85 case DrawQuad::IO_SURFACE_CONTENT
:
86 Compare(IOSurfaceDrawQuad::MaterialCast(a
),
87 IOSurfaceDrawQuad::MaterialCast(b
));
89 case DrawQuad::PICTURE_CONTENT
:
90 Compare(PictureDrawQuad::MaterialCast(a
),
91 PictureDrawQuad::MaterialCast(b
));
93 case DrawQuad::RENDER_PASS
:
94 Compare(RenderPassDrawQuad::MaterialCast(a
),
95 RenderPassDrawQuad::MaterialCast(b
));
97 case DrawQuad::TEXTURE_CONTENT
:
98 Compare(TextureDrawQuad::MaterialCast(a
),
99 TextureDrawQuad::MaterialCast(b
));
101 case DrawQuad::TILED_CONTENT
:
102 Compare(TileDrawQuad::MaterialCast(a
),
103 TileDrawQuad::MaterialCast(b
));
105 case DrawQuad::SOLID_COLOR
:
106 Compare(SolidColorDrawQuad::MaterialCast(a
),
107 SolidColorDrawQuad::MaterialCast(b
));
109 case DrawQuad::STREAM_VIDEO_CONTENT
:
110 Compare(StreamVideoDrawQuad::MaterialCast(a
),
111 StreamVideoDrawQuad::MaterialCast(b
));
113 case DrawQuad::SURFACE_CONTENT
:
114 Compare(SurfaceDrawQuad::MaterialCast(a
),
115 SurfaceDrawQuad::MaterialCast(b
));
117 case DrawQuad::YUV_VIDEO_CONTENT
:
118 Compare(YUVVideoDrawQuad::MaterialCast(a
),
119 YUVVideoDrawQuad::MaterialCast(b
));
121 case DrawQuad::INVALID
:
126 void Compare(const DebugBorderDrawQuad
* a
, const DebugBorderDrawQuad
* b
) {
127 EXPECT_EQ(a
->color
, b
->color
);
128 EXPECT_EQ(a
->width
, b
->width
);
131 void Compare(const IOSurfaceDrawQuad
* a
, const IOSurfaceDrawQuad
* b
) {
132 EXPECT_EQ(a
->io_surface_size
.ToString(), b
->io_surface_size
.ToString());
133 EXPECT_EQ(a
->io_surface_resource_id(), b
->io_surface_resource_id());
134 EXPECT_EQ(a
->orientation
, b
->orientation
);
137 void Compare(const RenderPassDrawQuad
* a
, const RenderPassDrawQuad
* b
) {
138 EXPECT_EQ(a
->render_pass_id
, b
->render_pass_id
);
139 EXPECT_EQ(a
->mask_resource_id(), b
->mask_resource_id());
140 EXPECT_EQ(a
->mask_uv_scale
.ToString(), b
->mask_uv_scale
.ToString());
141 EXPECT_EQ(a
->mask_texture_size
.ToString(), b
->mask_texture_size
.ToString());
142 EXPECT_EQ(a
->filters
.size(), b
->filters
.size());
143 for (size_t i
= 0; i
< a
->filters
.size(); ++i
) {
144 if (a
->filters
.at(i
).type() != cc::FilterOperation::REFERENCE
) {
145 EXPECT_EQ(a
->filters
.at(i
), b
->filters
.at(i
));
147 EXPECT_EQ(b
->filters
.at(i
).type(), cc::FilterOperation::REFERENCE
);
148 EXPECT_EQ(a
->filters
.at(i
).image_filter()->countInputs(),
149 b
->filters
.at(i
).image_filter()->countInputs());
152 EXPECT_EQ(a
->filters_scale
, b
->filters_scale
);
153 EXPECT_EQ(a
->background_filters
, b
->background_filters
);
156 void Compare(const SolidColorDrawQuad
* a
, const SolidColorDrawQuad
* b
) {
157 EXPECT_EQ(a
->color
, b
->color
);
158 EXPECT_EQ(a
->force_anti_aliasing_off
, b
->force_anti_aliasing_off
);
161 void Compare(const StreamVideoDrawQuad
* a
, const StreamVideoDrawQuad
* b
) {
162 EXPECT_EQ(a
->resource_id(), b
->resource_id());
163 EXPECT_EQ(a
->resource_size_in_pixels(), b
->resource_size_in_pixels());
164 EXPECT_EQ(a
->allow_overlay(), b
->allow_overlay());
165 EXPECT_EQ(a
->matrix
, b
->matrix
);
168 void Compare(const SurfaceDrawQuad
* a
, const SurfaceDrawQuad
* b
) {
169 EXPECT_EQ(a
->surface_id
, b
->surface_id
);
172 void Compare(const TextureDrawQuad
* a
, const TextureDrawQuad
* b
) {
173 EXPECT_EQ(a
->resource_id(), b
->resource_id());
174 EXPECT_EQ(a
->resource_size_in_pixels(), b
->resource_size_in_pixels());
175 EXPECT_EQ(a
->allow_overlay(), b
->allow_overlay());
176 EXPECT_EQ(a
->premultiplied_alpha
, b
->premultiplied_alpha
);
177 EXPECT_EQ(a
->uv_top_left
, b
->uv_top_left
);
178 EXPECT_EQ(a
->uv_bottom_right
, b
->uv_bottom_right
);
179 EXPECT_EQ(a
->background_color
, b
->background_color
);
180 EXPECT_EQ(a
->vertex_opacity
[0], b
->vertex_opacity
[0]);
181 EXPECT_EQ(a
->vertex_opacity
[1], b
->vertex_opacity
[1]);
182 EXPECT_EQ(a
->vertex_opacity
[2], b
->vertex_opacity
[2]);
183 EXPECT_EQ(a
->vertex_opacity
[3], b
->vertex_opacity
[3]);
184 EXPECT_EQ(a
->y_flipped
, b
->y_flipped
);
185 EXPECT_EQ(a
->nearest_neighbor
, b
->nearest_neighbor
);
188 void Compare(const TileDrawQuad
* a
, const TileDrawQuad
* b
) {
189 EXPECT_EQ(a
->resource_id(), b
->resource_id());
190 EXPECT_EQ(a
->tex_coord_rect
, b
->tex_coord_rect
);
191 EXPECT_EQ(a
->texture_size
, b
->texture_size
);
192 EXPECT_EQ(a
->swizzle_contents
, b
->swizzle_contents
);
193 EXPECT_EQ(a
->nearest_neighbor
, b
->nearest_neighbor
);
196 void Compare(const YUVVideoDrawQuad
* a
, const YUVVideoDrawQuad
* b
) {
197 EXPECT_EQ(a
->ya_tex_coord_rect
, b
->ya_tex_coord_rect
);
198 EXPECT_EQ(a
->uv_tex_coord_rect
, b
->uv_tex_coord_rect
);
199 EXPECT_EQ(a
->ya_tex_size
, b
->ya_tex_size
);
200 EXPECT_EQ(a
->uv_tex_size
, b
->uv_tex_size
);
201 EXPECT_EQ(a
->y_plane_resource_id(), b
->y_plane_resource_id());
202 EXPECT_EQ(a
->u_plane_resource_id(), b
->u_plane_resource_id());
203 EXPECT_EQ(a
->v_plane_resource_id(), b
->v_plane_resource_id());
204 EXPECT_EQ(a
->a_plane_resource_id(), b
->a_plane_resource_id());
205 EXPECT_EQ(a
->color_space
, b
->color_space
);
208 void Compare(const TransferableResource
& a
, const TransferableResource
& b
) {
209 EXPECT_EQ(a
.id
, b
.id
);
210 EXPECT_EQ(a
.format
, b
.format
);
211 EXPECT_EQ(a
.filter
, b
.filter
);
212 EXPECT_EQ(a
.size
.ToString(), b
.size
.ToString());
213 for (size_t i
= 0; i
< arraysize(a
.mailbox_holder
.mailbox
.name
); ++i
) {
214 EXPECT_EQ(a
.mailbox_holder
.mailbox
.name
[i
],
215 b
.mailbox_holder
.mailbox
.name
[i
]);
217 EXPECT_EQ(a
.mailbox_holder
.texture_target
, b
.mailbox_holder
.texture_target
);
218 EXPECT_EQ(a
.mailbox_holder
.sync_point
, b
.mailbox_holder
.sync_point
);
219 EXPECT_EQ(a
.allow_overlay
, b
.allow_overlay
);
223 TEST_F(CCMessagesTest
, AllQuads
) {
224 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
226 Transform arbitrary_matrix1
;
227 arbitrary_matrix1
.Scale(3, 3);
228 arbitrary_matrix1
.Translate(-5, 20);
229 arbitrary_matrix1
.Rotate(15);
230 Transform arbitrary_matrix2
;
231 arbitrary_matrix2
.Scale(10, -1);
232 arbitrary_matrix2
.Translate(20, 3);
233 arbitrary_matrix2
.Rotate(24);
234 gfx::Rect
arbitrary_rect1(-5, 9, 3, 15);
235 gfx::Rect
arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
236 gfx::Rect
arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
237 gfx::Rect
arbitrary_rect2(40, 23, 11, 7);
238 gfx::Rect
arbitrary_rect1_inside_rect2(44, 23, 4, 2);
239 gfx::Rect
arbitrary_rect2_inside_rect2(41, 25, 3, 5);
240 gfx::Rect
arbitrary_rect3(7, -53, 22, 19);
241 gfx::Rect
arbitrary_rect1_inside_rect3(10, -40, 6, 3);
242 gfx::Rect
arbitrary_rect2_inside_rect3(12, -51, 5, 12);
243 gfx::Size
arbitrary_size1(15, 19);
244 gfx::Size
arbitrary_size2(3, 99);
245 gfx::Size
arbitrary_size3(75, 1281);
246 gfx::RectF
arbitrary_rectf1(4.2f
, -922.1f
, 15.6f
, 29.5f
);
247 gfx::RectF
arbitrary_rectf2(2.1f
, -411.05f
, 7.8f
, 14.75f
);
248 gfx::SizeF
arbitrary_sizef1(15.2f
, 104.6f
);
249 gfx::PointF
arbitrary_pointf1(31.4f
, 15.9f
);
250 gfx::PointF
arbitrary_pointf2(26.5f
, -35.8f
);
251 gfx::Vector2dF
arbitrary_vector2df1(16.2f
, -85.1f
);
252 gfx::Vector2dF
arbitrary_vector2df2(-8.3f
, 0.47f
);
253 float arbitrary_float1
= 0.7f
;
254 float arbitrary_float2
= 0.3f
;
255 float arbitrary_float3
= 0.9f
;
256 float arbitrary_float_array
[4] = {3.5f
, 6.2f
, 9.3f
, 12.3f
};
257 bool arbitrary_bool1
= true;
258 bool arbitrary_bool2
= false;
259 bool arbitrary_bool3
= true;
260 bool arbitrary_bool4
= true;
261 bool arbitrary_bool5
= false;
262 int arbitrary_context_id1
= 12;
263 int arbitrary_context_id2
= 57;
264 int arbitrary_context_id3
= -503;
265 int arbitrary_int
= 5;
266 SkColor arbitrary_color
= SkColorSetARGB(25, 36, 47, 58);
267 SkXfermode::Mode arbitrary_blend_mode1
= SkXfermode::kScreen_Mode
;
268 SkXfermode::Mode arbitrary_blend_mode2
= SkXfermode::kLighten_Mode
;
269 SkXfermode::Mode arbitrary_blend_mode3
= SkXfermode::kOverlay_Mode
;
270 IOSurfaceDrawQuad::Orientation arbitrary_orientation
=
271 IOSurfaceDrawQuad::UNFLIPPED
;
272 ResourceId arbitrary_resourceid1
= 55;
273 ResourceId arbitrary_resourceid2
= 47;
274 ResourceId arbitrary_resourceid3
= 23;
275 ResourceId arbitrary_resourceid4
= 16;
276 SkScalar arbitrary_sigma
= SkFloatToScalar(2.0f
);
277 YUVVideoDrawQuad::ColorSpace arbitrary_color_space
=
278 YUVVideoDrawQuad::REC_601
;
280 RenderPassId
child_id(30, 5);
281 RenderPassId
root_id(10, 14);
283 FilterOperations arbitrary_filters1
;
284 arbitrary_filters1
.Append(FilterOperation::CreateGrayscaleFilter(
286 skia::RefPtr
<SkImageFilter
> arbitrary_filter
= skia::AdoptRef(
287 SkBlurImageFilter::Create(arbitrary_sigma
, arbitrary_sigma
));
288 arbitrary_filters1
.Append(
289 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter
));
291 FilterOperations arbitrary_filters2
;
292 arbitrary_filters2
.Append(FilterOperation::CreateBrightnessFilter(
295 scoped_ptr
<RenderPass
> child_pass_in
= RenderPass::Create();
296 child_pass_in
->SetAll(child_id
, arbitrary_rect2
, arbitrary_rect3
,
297 arbitrary_matrix2
, arbitrary_bool2
);
299 scoped_ptr
<RenderPass
> child_pass_cmp
= RenderPass::Create();
300 child_pass_cmp
->SetAll(child_id
, arbitrary_rect2
, arbitrary_rect3
,
301 arbitrary_matrix2
, arbitrary_bool2
);
303 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
304 pass_in
->SetAll(root_id
, arbitrary_rect1
, arbitrary_rect2
, arbitrary_matrix1
,
307 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
308 shared_state1_in
->SetAll(arbitrary_matrix1
, arbitrary_size1
, arbitrary_rect1
,
309 arbitrary_rect2
, arbitrary_bool1
, arbitrary_float1
,
310 arbitrary_blend_mode1
, arbitrary_context_id1
);
312 scoped_ptr
<RenderPass
> pass_cmp
= RenderPass::Create();
313 pass_cmp
->SetAll(root_id
, arbitrary_rect1
, arbitrary_rect2
, arbitrary_matrix1
,
316 SharedQuadState
* shared_state1_cmp
=
317 pass_cmp
->CreateAndAppendSharedQuadState();
318 shared_state1_cmp
->CopyFrom(shared_state1_in
);
320 DebugBorderDrawQuad
* debugborder_in
=
321 pass_in
->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
322 debugborder_in
->SetAll(shared_state1_in
,
324 arbitrary_rect1_inside_rect3
,
325 arbitrary_rect2_inside_rect3
,
329 pass_cmp
->CopyFromAndAppendDrawQuad(debugborder_in
,
330 debugborder_in
->shared_quad_state
);
332 IOSurfaceDrawQuad
* iosurface_in
=
333 pass_in
->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
334 iosurface_in
->SetAll(shared_state1_in
,
336 arbitrary_rect2_inside_rect2
,
337 arbitrary_rect1_inside_rect2
,
340 arbitrary_resourceid3
,
341 arbitrary_orientation
);
342 pass_cmp
->CopyFromAndAppendDrawQuad(iosurface_in
,
343 iosurface_in
->shared_quad_state
);
345 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
346 shared_state2_in
->SetAll(arbitrary_matrix2
, arbitrary_size2
, arbitrary_rect2
,
347 arbitrary_rect3
, arbitrary_bool1
, arbitrary_float2
,
348 arbitrary_blend_mode2
, arbitrary_context_id2
);
349 SharedQuadState
* shared_state2_cmp
=
350 pass_cmp
->CreateAndAppendSharedQuadState();
351 shared_state2_cmp
->CopyFrom(shared_state2_in
);
353 RenderPassDrawQuad
* renderpass_in
=
354 pass_in
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
355 renderpass_in
->SetAll(
356 shared_state2_in
, arbitrary_rect1
, arbitrary_rect2_inside_rect1
,
357 arbitrary_rect1_inside_rect1
, arbitrary_bool1
, child_id
,
358 arbitrary_resourceid2
, arbitrary_vector2df1
, arbitrary_size1
,
359 arbitrary_filters1
, arbitrary_vector2df2
, arbitrary_filters2
);
360 pass_cmp
->CopyFromAndAppendRenderPassDrawQuad(
362 renderpass_in
->shared_quad_state
,
363 renderpass_in
->render_pass_id
);
365 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
366 shared_state3_in
->SetAll(arbitrary_matrix1
, arbitrary_size3
, arbitrary_rect3
,
367 arbitrary_rect1
, arbitrary_bool1
, arbitrary_float3
,
368 arbitrary_blend_mode3
, arbitrary_context_id3
);
369 SharedQuadState
* shared_state3_cmp
=
370 pass_cmp
->CreateAndAppendSharedQuadState();
371 shared_state3_cmp
->CopyFrom(shared_state3_in
);
373 SolidColorDrawQuad
* solidcolor_in
=
374 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
375 solidcolor_in
->SetAll(shared_state3_in
,
377 arbitrary_rect1_inside_rect3
,
378 arbitrary_rect2_inside_rect3
,
382 pass_cmp
->CopyFromAndAppendDrawQuad(solidcolor_in
,
383 solidcolor_in
->shared_quad_state
);
385 StreamVideoDrawQuad
* streamvideo_in
=
386 pass_in
->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
387 streamvideo_in
->SetAll(
388 shared_state3_in
, arbitrary_rect2
, arbitrary_rect2_inside_rect2
,
389 arbitrary_rect1_inside_rect2
, arbitrary_bool1
, arbitrary_resourceid2
,
390 arbitrary_size1
, arbitrary_bool2
, arbitrary_matrix1
);
391 pass_cmp
->CopyFromAndAppendDrawQuad(streamvideo_in
,
392 streamvideo_in
->shared_quad_state
);
394 cc::SurfaceId
arbitrary_surface_id(3);
395 SurfaceDrawQuad
* surface_in
=
396 pass_in
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
397 surface_in
->SetAll(shared_state3_in
,
399 arbitrary_rect2_inside_rect2
,
400 arbitrary_rect1_inside_rect2
,
402 arbitrary_surface_id
);
403 pass_cmp
->CopyFromAndAppendDrawQuad(surface_in
,
404 surface_in
->shared_quad_state
);
405 pass_in
->referenced_surfaces
.push_back(arbitrary_surface_id
);
406 pass_cmp
->referenced_surfaces
.push_back(arbitrary_surface_id
);
408 TextureDrawQuad
* texture_in
=
409 pass_in
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
410 texture_in
->SetAll(shared_state3_in
, arbitrary_rect2
,
411 arbitrary_rect2_inside_rect2
, arbitrary_rect1_inside_rect2
,
412 arbitrary_bool1
, arbitrary_resourceid1
, arbitrary_size1
,
413 arbitrary_bool2
, arbitrary_bool3
, arbitrary_pointf1
,
414 arbitrary_pointf2
, arbitrary_color
, arbitrary_float_array
,
415 arbitrary_bool4
, arbitrary_bool5
);
416 pass_cmp
->CopyFromAndAppendDrawQuad(texture_in
,
417 texture_in
->shared_quad_state
);
419 TileDrawQuad
* tile_in
= pass_in
->CreateAndAppendDrawQuad
<TileDrawQuad
>();
420 tile_in
->SetAll(shared_state3_in
,
422 arbitrary_rect2_inside_rect2
,
423 arbitrary_rect1_inside_rect2
,
425 arbitrary_resourceid3
,
430 pass_cmp
->CopyFromAndAppendDrawQuad(tile_in
, tile_in
->shared_quad_state
);
432 YUVVideoDrawQuad
* yuvvideo_in
=
433 pass_in
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
435 shared_state3_in
, arbitrary_rect1
, arbitrary_rect2_inside_rect1
,
436 arbitrary_rect1_inside_rect1
, arbitrary_bool1
, arbitrary_rectf1
,
437 arbitrary_rectf2
, arbitrary_size1
, arbitrary_size2
, arbitrary_resourceid1
,
438 arbitrary_resourceid2
, arbitrary_resourceid3
, arbitrary_resourceid4
,
439 arbitrary_color_space
);
440 pass_cmp
->CopyFromAndAppendDrawQuad(yuvvideo_in
,
441 yuvvideo_in
->shared_quad_state
);
443 // Make sure the in and cmp RenderPasses match.
444 Compare(child_pass_cmp
.get(), child_pass_in
.get());
445 ASSERT_EQ(0u, child_pass_in
->shared_quad_state_list
.size());
446 ASSERT_EQ(0u, child_pass_in
->quad_list
.size());
447 Compare(pass_cmp
.get(), pass_in
.get());
448 ASSERT_EQ(3u, pass_in
->shared_quad_state_list
.size());
449 ASSERT_EQ(9u, pass_in
->quad_list
.size());
450 for (cc::SharedQuadStateList::ConstIterator
451 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
452 in_iterator
= pass_in
->shared_quad_state_list
.begin();
453 in_iterator
!= pass_in
->shared_quad_state_list
.end();
454 ++cmp_iterator
, ++in_iterator
) {
455 Compare(*cmp_iterator
, *in_iterator
);
457 for (auto in_iter
= pass_in
->quad_list
.cbegin(),
458 cmp_iter
= pass_cmp
->quad_list
.cbegin();
459 in_iter
!= pass_in
->quad_list
.cend();
460 ++in_iter
, ++cmp_iter
)
461 Compare(*cmp_iter
, *in_iter
);
463 for (size_t i
= 1; i
< pass_in
->quad_list
.size(); ++i
) {
464 bool same_shared_quad_state_cmp
=
465 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
466 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
467 bool same_shared_quad_state_in
=
468 pass_in
->quad_list
.ElementAt(i
)->shared_quad_state
==
469 pass_in
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
470 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_in
);
473 DelegatedFrameData frame_in
;
474 frame_in
.render_pass_list
.push_back(child_pass_in
.Pass());
475 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
477 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
479 DelegatedFrameData frame_out
;
480 base::PickleIterator
iter(msg
);
481 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
484 // Make sure the out and cmp RenderPasses match.
485 scoped_ptr
<RenderPass
> child_pass_out
=
486 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
487 Compare(child_pass_cmp
.get(), child_pass_out
.get());
488 ASSERT_EQ(0u, child_pass_out
->shared_quad_state_list
.size());
489 ASSERT_EQ(0u, child_pass_out
->quad_list
.size());
490 scoped_ptr
<RenderPass
> pass_out
=
491 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin() + 1);
492 Compare(pass_cmp
.get(), pass_out
.get());
493 ASSERT_EQ(3u, pass_out
->shared_quad_state_list
.size());
494 ASSERT_EQ(9u, pass_out
->quad_list
.size());
495 for (cc::SharedQuadStateList::ConstIterator
496 cmp_iterator
= pass_cmp
->shared_quad_state_list
.begin(),
497 out_iterator
= pass_out
->shared_quad_state_list
.begin();
498 out_iterator
!= pass_out
->shared_quad_state_list
.end();
499 ++cmp_iterator
, ++out_iterator
) {
500 Compare(*cmp_iterator
, *out_iterator
);
502 for (auto out_iter
= pass_out
->quad_list
.cbegin(),
503 cmp_iter
= pass_cmp
->quad_list
.cbegin();
504 out_iter
!= pass_out
->quad_list
.cend();
505 ++out_iter
, ++cmp_iter
)
506 Compare(*cmp_iter
, *out_iter
);
508 for (size_t i
= 1; i
< pass_out
->quad_list
.size(); ++i
) {
509 bool same_shared_quad_state_cmp
=
510 pass_cmp
->quad_list
.ElementAt(i
)->shared_quad_state
==
511 pass_cmp
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
512 bool same_shared_quad_state_out
=
513 pass_out
->quad_list
.ElementAt(i
)->shared_quad_state
==
514 pass_out
->quad_list
.ElementAt(i
- 1)->shared_quad_state
;
515 EXPECT_EQ(same_shared_quad_state_cmp
, same_shared_quad_state_out
);
519 TEST_F(CCMessagesTest
, UnusedSharedQuadStates
) {
520 scoped_ptr
<RenderPass
> pass_in
= RenderPass::Create();
521 pass_in
->SetAll(RenderPassId(1, 1),
527 // The first SharedQuadState is used.
528 SharedQuadState
* shared_state1_in
= pass_in
->CreateAndAppendSharedQuadState();
529 shared_state1_in
->SetAll(gfx::Transform(),
535 SkXfermode::kSrcOver_Mode
,
538 SolidColorDrawQuad
* quad1
=
539 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
540 quad1
->SetAll(shared_state1_in
, gfx::Rect(10, 10), gfx::Rect(10, 10),
541 gfx::Rect(10, 10), false, SK_ColorRED
, false);
543 // The second and third SharedQuadStates are not used.
544 SharedQuadState
* shared_state2_in
= pass_in
->CreateAndAppendSharedQuadState();
545 shared_state2_in
->SetAll(gfx::Transform(),
551 SkXfermode::kSrcOver_Mode
,
554 SharedQuadState
* shared_state3_in
= pass_in
->CreateAndAppendSharedQuadState();
555 shared_state3_in
->SetAll(gfx::Transform(),
561 SkXfermode::kSrcOver_Mode
,
564 // The fourth SharedQuadState is used.
565 SharedQuadState
* shared_state4_in
= pass_in
->CreateAndAppendSharedQuadState();
566 shared_state4_in
->SetAll(gfx::Transform(),
572 SkXfermode::kSrcOver_Mode
,
575 SolidColorDrawQuad
* quad2
=
576 pass_in
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
577 quad2
->SetAll(shared_state4_in
, gfx::Rect(10, 10), gfx::Rect(10, 10),
578 gfx::Rect(10, 10), false, SK_ColorRED
, false);
580 // The fifth is not used again.
581 SharedQuadState
* shared_state5_in
= pass_in
->CreateAndAppendSharedQuadState();
582 shared_state5_in
->SetAll(gfx::Transform(),
588 SkXfermode::kSrcOver_Mode
,
591 // 5 SharedQuadStates go in.
592 ASSERT_EQ(5u, pass_in
->shared_quad_state_list
.size());
593 ASSERT_EQ(2u, pass_in
->quad_list
.size());
595 DelegatedFrameData frame_in
;
596 frame_in
.render_pass_list
.push_back(pass_in
.Pass());
598 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
599 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
601 DelegatedFrameData frame_out
;
602 base::PickleIterator
iter(msg
);
604 IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
, &iter
, &frame_out
));
606 scoped_ptr
<RenderPass
> pass_out
=
607 frame_out
.render_pass_list
.take(frame_out
.render_pass_list
.begin());
609 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
610 // used by quads, and so serialized. Others were not.
611 ASSERT_EQ(2u, pass_out
->shared_quad_state_list
.size());
612 ASSERT_EQ(2u, pass_out
->quad_list
.size());
614 EXPECT_EQ(gfx::Size(1, 1).ToString(),
615 pass_out
->shared_quad_state_list
.ElementAt(0)
616 ->quad_layer_bounds
.ToString());
617 EXPECT_EQ(gfx::Size(4, 4).ToString(),
618 pass_out
->shared_quad_state_list
.ElementAt(1)
619 ->quad_layer_bounds
.ToString());
622 TEST_F(CCMessagesTest
, Resources
) {
623 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
624 gfx::Size
arbitrary_size(757, 1281);
625 unsigned int arbitrary_uint1
= 71234838;
626 unsigned int arbitrary_uint2
= 53589793;
628 GLbyte arbitrary_mailbox1
[GL_MAILBOX_SIZE_CHROMIUM
] = {
629 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
630 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
631 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
633 GLbyte arbitrary_mailbox2
[GL_MAILBOX_SIZE_CHROMIUM
] = {
634 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
635 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
636 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
638 TransferableResource arbitrary_resource1
;
639 arbitrary_resource1
.id
= 2178312;
640 arbitrary_resource1
.format
= cc::RGBA_8888
;
641 arbitrary_resource1
.filter
= 53;
642 arbitrary_resource1
.size
= gfx::Size(37189, 123123);
643 arbitrary_resource1
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox1
);
644 arbitrary_resource1
.mailbox_holder
.texture_target
= GL_TEXTURE_2D
;
645 arbitrary_resource1
.mailbox_holder
.sync_point
= arbitrary_uint1
;
646 arbitrary_resource1
.allow_overlay
= true;
648 TransferableResource arbitrary_resource2
;
649 arbitrary_resource2
.id
= 789132;
650 arbitrary_resource2
.format
= cc::RGBA_4444
;
651 arbitrary_resource2
.filter
= 47;
652 arbitrary_resource2
.size
= gfx::Size(89123, 23789);
653 arbitrary_resource2
.mailbox_holder
.mailbox
.SetName(arbitrary_mailbox2
);
654 arbitrary_resource2
.mailbox_holder
.texture_target
= GL_TEXTURE_EXTERNAL_OES
;
655 arbitrary_resource2
.mailbox_holder
.sync_point
= arbitrary_uint2
;
656 arbitrary_resource2
.allow_overlay
= false;
658 scoped_ptr
<RenderPass
> renderpass_in
= RenderPass::Create();
659 renderpass_in
->SetNew(
660 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
662 DelegatedFrameData frame_in
;
663 frame_in
.resource_list
.push_back(arbitrary_resource1
);
664 frame_in
.resource_list
.push_back(arbitrary_resource2
);
665 frame_in
.render_pass_list
.push_back(renderpass_in
.Pass());
667 IPC::ParamTraits
<DelegatedFrameData
>::Write(&msg
, frame_in
);
669 DelegatedFrameData frame_out
;
670 base::PickleIterator
iter(msg
);
671 EXPECT_TRUE(IPC::ParamTraits
<DelegatedFrameData
>::Read(&msg
,
674 ASSERT_EQ(2u, frame_out
.resource_list
.size());
675 Compare(arbitrary_resource1
, frame_out
.resource_list
[0]);
676 Compare(arbitrary_resource2
, frame_out
.resource_list
[1]);
679 TEST_F(CCMessagesTest
, SoftwareFrameData
) {
680 cc::SoftwareFrameData frame_in
;
682 frame_in
.size
= gfx::Size(40, 20);
683 frame_in
.damage_rect
= gfx::Rect(5, 18, 31, 44);
684 frame_in
.bitmap_id
= cc::SharedBitmap::GenerateId();
687 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
688 IPC::ParamTraits
<cc::SoftwareFrameData
>::Write(&msg
, frame_in
);
691 cc::SoftwareFrameData frame_out
;
692 base::PickleIterator
iter(msg
);
694 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
695 EXPECT_EQ(frame_in
.id
, frame_out
.id
);
696 EXPECT_EQ(frame_in
.size
.ToString(), frame_out
.size
.ToString());
697 EXPECT_EQ(frame_in
.damage_rect
.ToString(), frame_out
.damage_rect
.ToString());
698 EXPECT_EQ(frame_in
.bitmap_id
, frame_out
.bitmap_id
);
701 TEST_F(CCMessagesTest
, SoftwareFrameDataMaxInt
) {
702 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();
708 // Write the SoftwareFrameData by hand, make sure it works.
710 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
711 IPC::WriteParam(&msg
, frame_in
.id
);
712 IPC::WriteParam(&msg
, frame_in
.size
);
713 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
714 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
715 SoftwareFrameData frame_out
;
716 base::PickleIterator
iter(msg
);
718 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
721 // The size of the frame may overflow when multiplied together.
722 int max
= std::numeric_limits
<int>::max();
723 frame_in
.size
= gfx::Size(max
, max
);
725 // If size_t is larger than int, then int*int*4 can always fit in size_t.
726 bool expect_read
= sizeof(size_t) >= sizeof(int) * 2;
728 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
731 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
732 IPC::WriteParam(&msg
, frame_in
.id
);
733 IPC::WriteParam(&msg
, frame_in
.size
);
734 IPC::WriteParam(&msg
, frame_in
.damage_rect
);
735 IPC::WriteParam(&msg
, frame_in
.bitmap_id
);
736 SoftwareFrameData frame_out
;
737 base::PickleIterator
iter(msg
);
740 IPC::ParamTraits
<SoftwareFrameData
>::Read(&msg
, &iter
, &frame_out
));
745 } // namespace content