Move more string_util functions to base namespace.
[chromium-blink-merge.git] / content / common / cc_messages_unittest.cc
blob3737e585be9966116feb5eacdff3af0e74a79803
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"
7 #include <string.h>
9 #include <algorithm>
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"
18 #if defined(OS_POSIX)
19 #include "base/file_descriptor_posix.h"
20 #endif
22 using cc::CheckerboardDrawQuad;
23 using cc::DelegatedFrameData;
24 using cc::DebugBorderDrawQuad;
25 using cc::DrawQuad;
26 using cc::FilterOperation;
27 using cc::FilterOperations;
28 using cc::IOSurfaceDrawQuad;
29 using cc::PictureDrawQuad;
30 using cc::RenderPass;
31 using cc::RenderPassId;
32 using cc::RenderPassDrawQuad;
33 using cc::ResourceId;
34 using cc::ResourceProvider;
35 using cc::SharedQuadState;
36 using cc::SoftwareFrameData;
37 using cc::SolidColorDrawQuad;
38 using cc::SurfaceDrawQuad;
39 using cc::TextureDrawQuad;
40 using cc::TileDrawQuad;
41 using cc::TransferableResource;
42 using cc::StreamVideoDrawQuad;
43 using cc::YUVVideoDrawQuad;
44 using gfx::Transform;
46 namespace content {
47 namespace {
49 class CCMessagesTest : public testing::Test {
50 protected:
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->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::CHECKERBOARD:
82 Compare(CheckerboardDrawQuad::MaterialCast(a),
83 CheckerboardDrawQuad::MaterialCast(b));
84 break;
85 case DrawQuad::DEBUG_BORDER:
86 Compare(DebugBorderDrawQuad::MaterialCast(a),
87 DebugBorderDrawQuad::MaterialCast(b));
88 break;
89 case DrawQuad::IO_SURFACE_CONTENT:
90 Compare(IOSurfaceDrawQuad::MaterialCast(a),
91 IOSurfaceDrawQuad::MaterialCast(b));
92 break;
93 case DrawQuad::PICTURE_CONTENT:
94 Compare(PictureDrawQuad::MaterialCast(a),
95 PictureDrawQuad::MaterialCast(b));
96 break;
97 case DrawQuad::RENDER_PASS:
98 Compare(RenderPassDrawQuad::MaterialCast(a),
99 RenderPassDrawQuad::MaterialCast(b));
100 break;
101 case DrawQuad::TEXTURE_CONTENT:
102 Compare(TextureDrawQuad::MaterialCast(a),
103 TextureDrawQuad::MaterialCast(b));
104 break;
105 case DrawQuad::TILED_CONTENT:
106 Compare(TileDrawQuad::MaterialCast(a),
107 TileDrawQuad::MaterialCast(b));
108 break;
109 case DrawQuad::SOLID_COLOR:
110 Compare(SolidColorDrawQuad::MaterialCast(a),
111 SolidColorDrawQuad::MaterialCast(b));
112 break;
113 case DrawQuad::STREAM_VIDEO_CONTENT:
114 Compare(StreamVideoDrawQuad::MaterialCast(a),
115 StreamVideoDrawQuad::MaterialCast(b));
116 break;
117 case DrawQuad::SURFACE_CONTENT:
118 Compare(SurfaceDrawQuad::MaterialCast(a),
119 SurfaceDrawQuad::MaterialCast(b));
120 break;
121 case DrawQuad::YUV_VIDEO_CONTENT:
122 Compare(YUVVideoDrawQuad::MaterialCast(a),
123 YUVVideoDrawQuad::MaterialCast(b));
124 break;
125 case DrawQuad::INVALID:
126 break;
130 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) {
131 EXPECT_EQ(a->color, b->color);
132 EXPECT_EQ(a->scale, b->scale);
135 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
136 EXPECT_EQ(a->color, b->color);
137 EXPECT_EQ(a->width, b->width);
140 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
141 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
142 EXPECT_EQ(a->io_surface_resource_id(), b->io_surface_resource_id());
143 EXPECT_EQ(a->orientation, b->orientation);
146 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
147 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
148 EXPECT_EQ(a->mask_resource_id(), b->mask_resource_id());
149 EXPECT_EQ(a->mask_uv_scale.ToString(), b->mask_uv_scale.ToString());
150 EXPECT_EQ(a->mask_texture_size.ToString(), b->mask_texture_size.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));
155 } else {
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->filters_scale, b->filters_scale);
162 EXPECT_EQ(a->background_filters, b->background_filters);
165 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
166 EXPECT_EQ(a->color, b->color);
167 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
170 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
171 EXPECT_EQ(a->resource_id(), b->resource_id());
172 EXPECT_EQ(a->resource_size_in_pixels(), b->resource_size_in_pixels());
173 EXPECT_EQ(a->allow_overlay(), b->allow_overlay());
174 EXPECT_EQ(a->matrix, b->matrix);
177 void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
178 EXPECT_EQ(a->surface_id, b->surface_id);
181 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
182 EXPECT_EQ(a->resource_id(), b->resource_id());
183 EXPECT_EQ(a->resource_size_in_pixels(), b->resource_size_in_pixels());
184 EXPECT_EQ(a->allow_overlay(), b->allow_overlay());
185 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha);
186 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
187 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
188 EXPECT_EQ(a->background_color, b->background_color);
189 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]);
190 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]);
191 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]);
192 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]);
193 EXPECT_EQ(a->y_flipped, b->y_flipped);
194 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
197 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
198 EXPECT_EQ(a->resource_id(), b->resource_id());
199 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
200 EXPECT_EQ(a->texture_size, b->texture_size);
201 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
202 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
205 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
206 EXPECT_EQ(a->ya_tex_coord_rect, b->ya_tex_coord_rect);
207 EXPECT_EQ(a->uv_tex_coord_rect, b->uv_tex_coord_rect);
208 EXPECT_EQ(a->ya_tex_size, b->ya_tex_size);
209 EXPECT_EQ(a->uv_tex_size, b->uv_tex_size);
210 EXPECT_EQ(a->y_plane_resource_id(), b->y_plane_resource_id());
211 EXPECT_EQ(a->u_plane_resource_id(), b->u_plane_resource_id());
212 EXPECT_EQ(a->v_plane_resource_id(), b->v_plane_resource_id());
213 EXPECT_EQ(a->a_plane_resource_id(), b->a_plane_resource_id());
214 EXPECT_EQ(a->color_space, b->color_space);
217 void Compare(const TransferableResource& a, const TransferableResource& b) {
218 EXPECT_EQ(a.id, b.id);
219 EXPECT_EQ(a.format, b.format);
220 EXPECT_EQ(a.filter, b.filter);
221 EXPECT_EQ(a.size.ToString(), b.size.ToString());
222 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
223 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
224 b.mailbox_holder.mailbox.name[i]);
226 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
227 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
228 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
232 TEST_F(CCMessagesTest, AllQuads) {
233 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
235 Transform arbitrary_matrix1;
236 arbitrary_matrix1.Scale(3, 3);
237 arbitrary_matrix1.Translate(-5, 20);
238 arbitrary_matrix1.Rotate(15);
239 Transform arbitrary_matrix2;
240 arbitrary_matrix2.Scale(10, -1);
241 arbitrary_matrix2.Translate(20, 3);
242 arbitrary_matrix2.Rotate(24);
243 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
244 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
245 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
246 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
247 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
248 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
249 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
250 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
251 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
252 gfx::Size arbitrary_size1(15, 19);
253 gfx::Size arbitrary_size2(3, 99);
254 gfx::Size arbitrary_size3(75, 1281);
255 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
256 gfx::RectF arbitrary_rectf2(2.1f, -411.05f, 7.8f, 14.75f);
257 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
258 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
259 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
260 gfx::Vector2dF arbitrary_vector2df1(16.2f, -85.1f);
261 gfx::Vector2dF arbitrary_vector2df2(-8.3f, 0.47f);
262 float arbitrary_float1 = 0.7f;
263 float arbitrary_float2 = 0.3f;
264 float arbitrary_float3 = 0.9f;
265 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
266 bool arbitrary_bool1 = true;
267 bool arbitrary_bool2 = false;
268 bool arbitrary_bool3 = true;
269 bool arbitrary_bool4 = true;
270 bool arbitrary_bool5 = false;
271 int arbitrary_context_id1 = 12;
272 int arbitrary_context_id2 = 57;
273 int arbitrary_context_id3 = -503;
274 int arbitrary_int = 5;
275 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
276 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
277 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
278 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
279 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
280 IOSurfaceDrawQuad::UNFLIPPED;
281 ResourceId arbitrary_resourceid1 = 55;
282 ResourceId arbitrary_resourceid2 = 47;
283 ResourceId arbitrary_resourceid3 = 23;
284 ResourceId arbitrary_resourceid4 = 16;
285 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
286 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
287 YUVVideoDrawQuad::REC_601;
289 RenderPassId child_id(30, 5);
290 RenderPassId root_id(10, 14);
292 FilterOperations arbitrary_filters1;
293 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
294 arbitrary_float1));
295 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
296 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
297 arbitrary_filters1.Append(
298 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
300 FilterOperations arbitrary_filters2;
301 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
302 arbitrary_float2));
304 scoped_ptr<RenderPass> child_pass_in = RenderPass::Create();
305 child_pass_in->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
306 arbitrary_matrix2, arbitrary_bool2);
308 scoped_ptr<RenderPass> child_pass_cmp = RenderPass::Create();
309 child_pass_cmp->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
310 arbitrary_matrix2, arbitrary_bool2);
312 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
313 pass_in->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
314 arbitrary_bool1);
316 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
317 shared_state1_in->SetAll(arbitrary_matrix1, arbitrary_size1, arbitrary_rect1,
318 arbitrary_rect2, arbitrary_bool1, arbitrary_float1,
319 arbitrary_blend_mode1, arbitrary_context_id1);
321 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
322 pass_cmp->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
323 arbitrary_bool1);
325 SharedQuadState* shared_state1_cmp =
326 pass_cmp->CreateAndAppendSharedQuadState();
327 shared_state1_cmp->CopyFrom(shared_state1_in);
329 CheckerboardDrawQuad* checkerboard_in =
330 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
331 checkerboard_in->SetAll(shared_state1_in, arbitrary_rect1,
332 arbitrary_rect2_inside_rect1,
333 arbitrary_rect1_inside_rect1, arbitrary_bool1,
334 arbitrary_color, arbitrary_float1);
335 pass_cmp->CopyFromAndAppendDrawQuad(checkerboard_in,
336 checkerboard_in->shared_quad_state);
338 DebugBorderDrawQuad* debugborder_in =
339 pass_in->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
340 debugborder_in->SetAll(shared_state1_in,
341 arbitrary_rect3,
342 arbitrary_rect1_inside_rect3,
343 arbitrary_rect2_inside_rect3,
344 arbitrary_bool1,
345 arbitrary_color,
346 arbitrary_int);
347 pass_cmp->CopyFromAndAppendDrawQuad(debugborder_in,
348 debugborder_in->shared_quad_state);
350 IOSurfaceDrawQuad* iosurface_in =
351 pass_in->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
352 iosurface_in->SetAll(shared_state1_in,
353 arbitrary_rect2,
354 arbitrary_rect2_inside_rect2,
355 arbitrary_rect1_inside_rect2,
356 arbitrary_bool1,
357 arbitrary_size1,
358 arbitrary_resourceid3,
359 arbitrary_orientation);
360 pass_cmp->CopyFromAndAppendDrawQuad(iosurface_in,
361 iosurface_in->shared_quad_state);
363 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
364 shared_state2_in->SetAll(arbitrary_matrix2, arbitrary_size2, arbitrary_rect2,
365 arbitrary_rect3, arbitrary_bool1, arbitrary_float2,
366 arbitrary_blend_mode2, arbitrary_context_id2);
367 SharedQuadState* shared_state2_cmp =
368 pass_cmp->CreateAndAppendSharedQuadState();
369 shared_state2_cmp->CopyFrom(shared_state2_in);
371 RenderPassDrawQuad* renderpass_in =
372 pass_in->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
373 renderpass_in->SetAll(
374 shared_state2_in, arbitrary_rect1, arbitrary_rect2_inside_rect1,
375 arbitrary_rect1_inside_rect1, arbitrary_bool1, child_id,
376 arbitrary_resourceid2, arbitrary_vector2df1, arbitrary_size1,
377 arbitrary_filters1, arbitrary_vector2df2, arbitrary_filters2);
378 pass_cmp->CopyFromAndAppendRenderPassDrawQuad(
379 renderpass_in,
380 renderpass_in->shared_quad_state,
381 renderpass_in->render_pass_id);
383 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
384 shared_state3_in->SetAll(arbitrary_matrix1, arbitrary_size3, arbitrary_rect3,
385 arbitrary_rect1, arbitrary_bool1, arbitrary_float3,
386 arbitrary_blend_mode3, 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,
394 arbitrary_rect3,
395 arbitrary_rect1_inside_rect3,
396 arbitrary_rect2_inside_rect3,
397 arbitrary_bool1,
398 arbitrary_color,
399 arbitrary_bool2);
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(
406 shared_state3_in, arbitrary_rect2, arbitrary_rect2_inside_rect2,
407 arbitrary_rect1_inside_rect2, arbitrary_bool1, arbitrary_resourceid2,
408 arbitrary_size1, arbitrary_bool2, arbitrary_matrix1);
409 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
410 streamvideo_in->shared_quad_state);
412 cc::SurfaceId arbitrary_surface_id(3);
413 SurfaceDrawQuad* surface_in =
414 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
415 surface_in->SetAll(shared_state3_in,
416 arbitrary_rect2,
417 arbitrary_rect2_inside_rect2,
418 arbitrary_rect1_inside_rect2,
419 arbitrary_bool1,
420 arbitrary_surface_id);
421 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
422 surface_in->shared_quad_state);
424 TextureDrawQuad* texture_in =
425 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
426 texture_in->SetAll(shared_state3_in, arbitrary_rect2,
427 arbitrary_rect2_inside_rect2, arbitrary_rect1_inside_rect2,
428 arbitrary_bool1, arbitrary_resourceid1, arbitrary_size1,
429 arbitrary_bool2, arbitrary_bool3, arbitrary_pointf1,
430 arbitrary_pointf2, arbitrary_color, arbitrary_float_array,
431 arbitrary_bool4, arbitrary_bool5);
432 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
433 texture_in->shared_quad_state);
435 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
436 tile_in->SetAll(shared_state3_in,
437 arbitrary_rect2,
438 arbitrary_rect2_inside_rect2,
439 arbitrary_rect1_inside_rect2,
440 arbitrary_bool1,
441 arbitrary_resourceid3,
442 arbitrary_rectf1,
443 arbitrary_size1,
444 arbitrary_bool2,
445 arbitrary_bool3);
446 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
448 YUVVideoDrawQuad* yuvvideo_in =
449 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
450 yuvvideo_in->SetAll(
451 shared_state3_in, arbitrary_rect1, arbitrary_rect2_inside_rect1,
452 arbitrary_rect1_inside_rect1, arbitrary_bool1, arbitrary_rectf1,
453 arbitrary_rectf2, arbitrary_size1, arbitrary_size2, arbitrary_resourceid1,
454 arbitrary_resourceid2, arbitrary_resourceid3, arbitrary_resourceid4,
455 arbitrary_color_space);
456 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
457 yuvvideo_in->shared_quad_state);
459 // Make sure the in and cmp RenderPasses match.
460 Compare(child_pass_cmp.get(), child_pass_in.get());
461 ASSERT_EQ(0u, child_pass_in->shared_quad_state_list.size());
462 ASSERT_EQ(0u, child_pass_in->quad_list.size());
463 Compare(pass_cmp.get(), pass_in.get());
464 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
465 ASSERT_EQ(10u, pass_in->quad_list.size());
466 for (cc::SharedQuadStateList::ConstIterator
467 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
468 in_iterator = pass_in->shared_quad_state_list.begin();
469 in_iterator != pass_in->shared_quad_state_list.end();
470 ++cmp_iterator, ++in_iterator) {
471 Compare(*cmp_iterator, *in_iterator);
473 for (auto in_iter = pass_in->quad_list.cbegin(),
474 cmp_iter = pass_cmp->quad_list.cbegin();
475 in_iter != pass_in->quad_list.cend();
476 ++in_iter, ++cmp_iter)
477 Compare(*cmp_iter, *in_iter);
479 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
480 bool same_shared_quad_state_cmp =
481 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
482 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
483 bool same_shared_quad_state_in =
484 pass_in->quad_list.ElementAt(i)->shared_quad_state ==
485 pass_in->quad_list.ElementAt(i - 1)->shared_quad_state;
486 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
489 DelegatedFrameData frame_in;
490 frame_in.render_pass_list.push_back(child_pass_in.Pass());
491 frame_in.render_pass_list.push_back(pass_in.Pass());
493 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
495 DelegatedFrameData frame_out;
496 base::PickleIterator iter(msg);
497 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
498 &iter, &frame_out));
500 // Make sure the out and cmp RenderPasses match.
501 scoped_ptr<RenderPass> child_pass_out =
502 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
503 Compare(child_pass_cmp.get(), child_pass_out.get());
504 ASSERT_EQ(0u, child_pass_out->shared_quad_state_list.size());
505 ASSERT_EQ(0u, child_pass_out->quad_list.size());
506 scoped_ptr<RenderPass> pass_out =
507 frame_out.render_pass_list.take(frame_out.render_pass_list.begin() + 1);
508 Compare(pass_cmp.get(), pass_out.get());
509 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
510 ASSERT_EQ(10u, pass_out->quad_list.size());
511 for (cc::SharedQuadStateList::ConstIterator
512 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
513 out_iterator = pass_out->shared_quad_state_list.begin();
514 out_iterator != pass_out->shared_quad_state_list.end();
515 ++cmp_iterator, ++out_iterator) {
516 Compare(*cmp_iterator, *out_iterator);
518 for (auto out_iter = pass_out->quad_list.cbegin(),
519 cmp_iter = pass_cmp->quad_list.cbegin();
520 out_iter != pass_out->quad_list.cend();
521 ++out_iter, ++cmp_iter)
522 Compare(*cmp_iter, *out_iter);
524 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
525 bool same_shared_quad_state_cmp =
526 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
527 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
528 bool same_shared_quad_state_out =
529 pass_out->quad_list.ElementAt(i)->shared_quad_state ==
530 pass_out->quad_list.ElementAt(i - 1)->shared_quad_state;
531 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
535 TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
536 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
537 pass_in->SetAll(RenderPassId(1, 1),
538 gfx::Rect(100, 100),
539 gfx::Rect(),
540 gfx::Transform(),
541 false);
543 // The first SharedQuadState is used.
544 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
545 shared_state1_in->SetAll(gfx::Transform(),
546 gfx::Size(1, 1),
547 gfx::Rect(),
548 gfx::Rect(),
549 false,
550 1.f,
551 SkXfermode::kSrcOver_Mode,
554 CheckerboardDrawQuad* quad1 =
555 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
556 quad1->SetAll(shared_state1_in, gfx::Rect(10, 10), gfx::Rect(10, 10),
557 gfx::Rect(10, 10), false, SK_ColorRED, 1.f);
559 // The second and third SharedQuadStates are not used.
560 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
561 shared_state2_in->SetAll(gfx::Transform(),
562 gfx::Size(2, 2),
563 gfx::Rect(),
564 gfx::Rect(),
565 false,
566 1.f,
567 SkXfermode::kSrcOver_Mode,
570 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
571 shared_state3_in->SetAll(gfx::Transform(),
572 gfx::Size(3, 3),
573 gfx::Rect(),
574 gfx::Rect(),
575 false,
576 1.f,
577 SkXfermode::kSrcOver_Mode,
580 // The fourth SharedQuadState is used.
581 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
582 shared_state4_in->SetAll(gfx::Transform(),
583 gfx::Size(4, 4),
584 gfx::Rect(),
585 gfx::Rect(),
586 false,
587 1.f,
588 SkXfermode::kSrcOver_Mode,
591 CheckerboardDrawQuad* quad2 =
592 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
593 quad2->SetAll(shared_state4_in, gfx::Rect(10, 10), gfx::Rect(10, 10),
594 gfx::Rect(10, 10), false, SK_ColorRED, 1.f);
596 // The fifth is not used again.
597 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
598 shared_state5_in->SetAll(gfx::Transform(),
599 gfx::Size(5, 5),
600 gfx::Rect(),
601 gfx::Rect(),
602 false,
603 1.f,
604 SkXfermode::kSrcOver_Mode,
607 // 5 SharedQuadStates go in.
608 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
609 ASSERT_EQ(2u, pass_in->quad_list.size());
611 DelegatedFrameData frame_in;
612 frame_in.render_pass_list.push_back(pass_in.Pass());
614 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
615 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
617 DelegatedFrameData frame_out;
618 base::PickleIterator iter(msg);
619 EXPECT_TRUE(
620 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
622 scoped_ptr<RenderPass> pass_out =
623 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
625 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
626 // used by quads, and so serialized. Others were not.
627 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
628 ASSERT_EQ(2u, pass_out->quad_list.size());
630 EXPECT_EQ(gfx::Size(1, 1).ToString(),
631 pass_out->shared_quad_state_list.ElementAt(0)
632 ->quad_layer_bounds.ToString());
633 EXPECT_EQ(gfx::Size(4, 4).ToString(),
634 pass_out->shared_quad_state_list.ElementAt(1)
635 ->quad_layer_bounds.ToString());
638 TEST_F(CCMessagesTest, Resources) {
639 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
640 gfx::Size arbitrary_size(757, 1281);
641 unsigned int arbitrary_uint1 = 71234838;
642 unsigned int arbitrary_uint2 = 53589793;
644 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
645 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
646 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
647 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
649 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
650 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
651 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
652 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
654 TransferableResource arbitrary_resource1;
655 arbitrary_resource1.id = 2178312;
656 arbitrary_resource1.format = cc::RGBA_8888;
657 arbitrary_resource1.filter = 53;
658 arbitrary_resource1.size = gfx::Size(37189, 123123);
659 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
660 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
661 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
662 arbitrary_resource1.allow_overlay = true;
664 TransferableResource arbitrary_resource2;
665 arbitrary_resource2.id = 789132;
666 arbitrary_resource2.format = cc::RGBA_4444;
667 arbitrary_resource2.filter = 47;
668 arbitrary_resource2.size = gfx::Size(89123, 23789);
669 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
670 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
671 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
672 arbitrary_resource2.allow_overlay = false;
674 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
675 renderpass_in->SetNew(
676 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
678 DelegatedFrameData frame_in;
679 frame_in.resource_list.push_back(arbitrary_resource1);
680 frame_in.resource_list.push_back(arbitrary_resource2);
681 frame_in.render_pass_list.push_back(renderpass_in.Pass());
683 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
685 DelegatedFrameData frame_out;
686 base::PickleIterator iter(msg);
687 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
688 &iter, &frame_out));
690 ASSERT_EQ(2u, frame_out.resource_list.size());
691 Compare(arbitrary_resource1, frame_out.resource_list[0]);
692 Compare(arbitrary_resource2, frame_out.resource_list[1]);
695 TEST_F(CCMessagesTest, SoftwareFrameData) {
696 cc::SoftwareFrameData frame_in;
697 frame_in.id = 3;
698 frame_in.size = gfx::Size(40, 20);
699 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
700 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
702 // Write the frame.
703 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
704 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
706 // Read the frame.
707 cc::SoftwareFrameData frame_out;
708 base::PickleIterator iter(msg);
709 EXPECT_TRUE(
710 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
711 EXPECT_EQ(frame_in.id, frame_out.id);
712 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
713 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
714 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
717 TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
718 SoftwareFrameData frame_in;
719 frame_in.id = 3;
720 frame_in.size = gfx::Size(40, 20);
721 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
722 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
724 // Write the SoftwareFrameData by hand, make sure it works.
726 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
727 IPC::WriteParam(&msg, frame_in.id);
728 IPC::WriteParam(&msg, frame_in.size);
729 IPC::WriteParam(&msg, frame_in.damage_rect);
730 IPC::WriteParam(&msg, frame_in.bitmap_id);
731 SoftwareFrameData frame_out;
732 base::PickleIterator iter(msg);
733 EXPECT_TRUE(
734 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
737 // The size of the frame may overflow when multiplied together.
738 int max = std::numeric_limits<int>::max();
739 frame_in.size = gfx::Size(max, max);
741 // If size_t is larger than int, then int*int*4 can always fit in size_t.
742 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
744 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
745 // should fail.
747 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
748 IPC::WriteParam(&msg, frame_in.id);
749 IPC::WriteParam(&msg, frame_in.size);
750 IPC::WriteParam(&msg, frame_in.damage_rect);
751 IPC::WriteParam(&msg, frame_in.bitmap_id);
752 SoftwareFrameData frame_out;
753 base::PickleIterator iter(msg);
754 EXPECT_EQ(
755 expect_read,
756 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
760 } // namespace
761 } // namespace content