Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / common / cc_messages_unittest.cc
blobcc1fdf0c84c478b7bfd3b3c68b53038f4c160673
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::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;
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->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));
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);
134 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
135 EXPECT_EQ(a->color, b->color);
136 EXPECT_EQ(a->width, b->width);
139 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
140 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
141 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
142 EXPECT_EQ(a->orientation, b->orientation);
145 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
146 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
147 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id);
148 EXPECT_EQ(a->mask_uv_scale.ToString(), b->mask_uv_scale.ToString());
149 EXPECT_EQ(a->mask_texture_size.ToString(), b->mask_texture_size.ToString());
150 EXPECT_EQ(a->filters.size(), b->filters.size());
151 for (size_t i = 0; i < a->filters.size(); ++i) {
152 if (a->filters.at(i).type() != cc::FilterOperation::REFERENCE) {
153 EXPECT_EQ(a->filters.at(i), b->filters.at(i));
154 } else {
155 EXPECT_EQ(b->filters.at(i).type(), cc::FilterOperation::REFERENCE);
156 EXPECT_EQ(a->filters.at(i).image_filter()->countInputs(),
157 b->filters.at(i).image_filter()->countInputs());
160 EXPECT_EQ(a->filters_scale, b->filters_scale);
161 EXPECT_EQ(a->background_filters, b->background_filters);
164 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
165 EXPECT_EQ(a->color, b->color);
166 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
169 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
170 EXPECT_EQ(a->resource_id, b->resource_id);
171 EXPECT_EQ(a->matrix, b->matrix);
174 void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
175 EXPECT_EQ(a->surface_id, b->surface_id);
178 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
179 EXPECT_EQ(a->resource_id, b->resource_id);
180 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha);
181 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
182 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
183 EXPECT_EQ(a->background_color, b->background_color);
184 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]);
185 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]);
186 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]);
187 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]);
188 EXPECT_EQ(a->flipped, b->flipped);
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);
218 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
222 TEST_F(CCMessagesTest, AllQuads) {
223 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
225 Transform arbitrary_matrix;
226 arbitrary_matrix.Scale(3, 3);
227 arbitrary_matrix.Translate(-5, 20);
228 arbitrary_matrix.Rotate(15);
229 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
230 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
231 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
232 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
233 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
234 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
235 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
236 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
237 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
238 gfx::Size arbitrary_size1(15, 19);
239 gfx::Size arbitrary_size2(3, 99);
240 gfx::Size arbitrary_size3(75, 1281);
241 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
242 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
243 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
244 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
245 gfx::Vector2dF arbitrary_vector2df1(16.2f, -85.1f);
246 gfx::Vector2dF arbitrary_vector2df2(-8.3f, 0.47f);
247 float arbitrary_float1 = 0.7f;
248 float arbitrary_float2 = 0.3f;
249 float arbitrary_float3 = 0.9f;
250 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
251 bool arbitrary_bool1 = true;
252 bool arbitrary_bool2 = false;
253 bool arbitrary_bool3 = true;
254 int arbitrary_context_id1 = 12;
255 int arbitrary_context_id2 = 57;
256 int arbitrary_context_id3 = -503;
257 int arbitrary_int = 5;
258 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
259 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
260 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
261 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
262 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
263 IOSurfaceDrawQuad::UNFLIPPED;
264 RenderPassId arbitrary_id(10, 14);
265 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
266 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
267 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
268 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
269 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
270 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
271 YUVVideoDrawQuad::REC_601;
273 FilterOperations arbitrary_filters1;
274 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
275 arbitrary_float1));
276 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
277 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
278 arbitrary_filters1.Append(
279 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
281 FilterOperations arbitrary_filters2;
282 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
283 arbitrary_float2));
285 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
286 pass_in->SetAll(arbitrary_id,
287 arbitrary_rect1,
288 arbitrary_rect2,
289 arbitrary_matrix,
290 arbitrary_bool1);
292 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
293 shared_state1_in->SetAll(arbitrary_matrix,
294 arbitrary_size1,
295 arbitrary_rect1,
296 arbitrary_rect2,
297 arbitrary_bool1,
298 arbitrary_float1,
299 arbitrary_blend_mode1,
300 arbitrary_context_id1);
302 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
303 pass_cmp->SetAll(arbitrary_id,
304 arbitrary_rect1,
305 arbitrary_rect2,
306 arbitrary_matrix,
307 arbitrary_bool1);
309 SharedQuadState* shared_state1_cmp =
310 pass_cmp->CreateAndAppendSharedQuadState();
311 shared_state1_cmp->CopyFrom(shared_state1_in);
313 CheckerboardDrawQuad* checkerboard_in =
314 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
315 checkerboard_in->SetAll(shared_state1_in,
316 arbitrary_rect1,
317 arbitrary_rect2_inside_rect1,
318 arbitrary_rect1_inside_rect1,
319 arbitrary_bool1,
320 arbitrary_color);
321 pass_cmp->CopyFromAndAppendDrawQuad(checkerboard_in,
322 checkerboard_in->shared_quad_state);
324 DebugBorderDrawQuad* debugborder_in =
325 pass_in->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
326 debugborder_in->SetAll(shared_state1_in,
327 arbitrary_rect3,
328 arbitrary_rect1_inside_rect3,
329 arbitrary_rect2_inside_rect3,
330 arbitrary_bool1,
331 arbitrary_color,
332 arbitrary_int);
333 pass_cmp->CopyFromAndAppendDrawQuad(debugborder_in,
334 debugborder_in->shared_quad_state);
336 IOSurfaceDrawQuad* iosurface_in =
337 pass_in->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
338 iosurface_in->SetAll(shared_state1_in,
339 arbitrary_rect2,
340 arbitrary_rect2_inside_rect2,
341 arbitrary_rect1_inside_rect2,
342 arbitrary_bool1,
343 arbitrary_size1,
344 arbitrary_resourceid3,
345 arbitrary_orientation);
346 pass_cmp->CopyFromAndAppendDrawQuad(iosurface_in,
347 iosurface_in->shared_quad_state);
349 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
350 shared_state2_in->SetAll(arbitrary_matrix,
351 arbitrary_size2,
352 arbitrary_rect2,
353 arbitrary_rect3,
354 arbitrary_bool1,
355 arbitrary_float2,
356 arbitrary_blend_mode2,
357 arbitrary_context_id2);
358 SharedQuadState* shared_state2_cmp =
359 pass_cmp->CreateAndAppendSharedQuadState();
360 shared_state2_cmp->CopyFrom(shared_state2_in);
362 RenderPassDrawQuad* renderpass_in =
363 pass_in->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
364 renderpass_in->SetAll(shared_state2_in,
365 arbitrary_rect1,
366 arbitrary_rect2_inside_rect1,
367 arbitrary_rect1_inside_rect1,
368 arbitrary_bool1,
369 arbitrary_id,
370 arbitrary_resourceid2,
371 arbitrary_vector2df1,
372 arbitrary_size1,
373 arbitrary_filters1,
374 arbitrary_vector2df2,
375 arbitrary_filters2);
376 pass_cmp->CopyFromAndAppendRenderPassDrawQuad(
377 renderpass_in,
378 renderpass_in->shared_quad_state,
379 renderpass_in->render_pass_id);
381 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
382 shared_state3_in->SetAll(arbitrary_matrix,
383 arbitrary_size3,
384 arbitrary_rect3,
385 arbitrary_rect1,
386 arbitrary_bool1,
387 arbitrary_float3,
388 arbitrary_blend_mode3,
389 arbitrary_context_id3);
390 SharedQuadState* shared_state3_cmp =
391 pass_cmp->CreateAndAppendSharedQuadState();
392 shared_state3_cmp->CopyFrom(shared_state3_in);
394 SolidColorDrawQuad* solidcolor_in =
395 pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
396 solidcolor_in->SetAll(shared_state3_in,
397 arbitrary_rect3,
398 arbitrary_rect1_inside_rect3,
399 arbitrary_rect2_inside_rect3,
400 arbitrary_bool1,
401 arbitrary_color,
402 arbitrary_bool2);
403 pass_cmp->CopyFromAndAppendDrawQuad(solidcolor_in,
404 solidcolor_in->shared_quad_state);
406 StreamVideoDrawQuad* streamvideo_in =
407 pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
408 streamvideo_in->SetAll(shared_state3_in,
409 arbitrary_rect2,
410 arbitrary_rect2_inside_rect2,
411 arbitrary_rect1_inside_rect2,
412 arbitrary_bool1,
413 arbitrary_resourceid2,
414 arbitrary_matrix);
415 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
416 streamvideo_in->shared_quad_state);
418 cc::SurfaceId arbitrary_surface_id(3);
419 SurfaceDrawQuad* surface_in =
420 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
421 surface_in->SetAll(shared_state3_in,
422 arbitrary_rect2,
423 arbitrary_rect2_inside_rect2,
424 arbitrary_rect1_inside_rect2,
425 arbitrary_bool1,
426 arbitrary_surface_id);
427 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
428 surface_in->shared_quad_state);
430 TextureDrawQuad* texture_in =
431 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
432 texture_in->SetAll(shared_state3_in,
433 arbitrary_rect2,
434 arbitrary_rect2_inside_rect2,
435 arbitrary_rect1_inside_rect2,
436 arbitrary_bool1,
437 arbitrary_resourceid1,
438 arbitrary_bool2,
439 arbitrary_pointf1,
440 arbitrary_pointf2,
441 arbitrary_color,
442 arbitrary_float_array,
443 arbitrary_bool3);
444 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
445 texture_in->shared_quad_state);
447 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
448 tile_in->SetAll(shared_state3_in,
449 arbitrary_rect2,
450 arbitrary_rect2_inside_rect2,
451 arbitrary_rect1_inside_rect2,
452 arbitrary_bool1,
453 arbitrary_resourceid3,
454 arbitrary_rectf1,
455 arbitrary_size1,
456 arbitrary_bool2);
457 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
459 YUVVideoDrawQuad* yuvvideo_in =
460 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
461 yuvvideo_in->SetAll(shared_state3_in,
462 arbitrary_rect1,
463 arbitrary_rect2_inside_rect1,
464 arbitrary_rect1_inside_rect1,
465 arbitrary_bool1,
466 arbitrary_rectf1,
467 arbitrary_resourceid1,
468 arbitrary_resourceid2,
469 arbitrary_resourceid3,
470 arbitrary_resourceid4,
471 arbitrary_color_space);
472 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
473 yuvvideo_in->shared_quad_state);
475 // Make sure the in and cmp RenderPasses match.
476 Compare(pass_cmp.get(), pass_in.get());
477 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
478 ASSERT_EQ(10u, pass_in->quad_list.size());
479 for (cc::SharedQuadStateList::ConstIterator
480 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
481 in_iterator = pass_in->shared_quad_state_list.begin();
482 in_iterator != pass_in->shared_quad_state_list.end();
483 ++cmp_iterator, ++in_iterator) {
484 Compare(*cmp_iterator, *in_iterator);
486 for (auto in_iter = pass_in->quad_list.cbegin(),
487 cmp_iter = pass_cmp->quad_list.cbegin();
488 in_iter != pass_in->quad_list.cend();
489 ++in_iter, ++cmp_iter)
490 Compare(*cmp_iter, *in_iter);
492 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
493 bool same_shared_quad_state_cmp =
494 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
495 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
496 bool same_shared_quad_state_in =
497 pass_in->quad_list.ElementAt(i)->shared_quad_state ==
498 pass_in->quad_list.ElementAt(i - 1)->shared_quad_state;
499 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
502 DelegatedFrameData frame_in;
503 frame_in.render_pass_list.push_back(pass_in.Pass());
505 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
507 DelegatedFrameData frame_out;
508 PickleIterator iter(msg);
509 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
510 &iter, &frame_out));
512 // Make sure the out and cmp RenderPasses match.
513 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
514 frame_out.render_pass_list.begin());
515 Compare(pass_cmp.get(), pass_out.get());
516 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
517 ASSERT_EQ(10u, pass_out->quad_list.size());
518 for (cc::SharedQuadStateList::ConstIterator
519 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
520 out_iterator = pass_out->shared_quad_state_list.begin();
521 out_iterator != pass_out->shared_quad_state_list.end();
522 ++cmp_iterator, ++out_iterator) {
523 Compare(*cmp_iterator, *out_iterator);
525 for (auto out_iter = pass_out->quad_list.cbegin(),
526 cmp_iter = pass_cmp->quad_list.cbegin();
527 out_iter != pass_out->quad_list.cend();
528 ++out_iter, ++cmp_iter)
529 Compare(*cmp_iter, *out_iter);
531 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
532 bool same_shared_quad_state_cmp =
533 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
534 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
535 bool same_shared_quad_state_out =
536 pass_out->quad_list.ElementAt(i)->shared_quad_state ==
537 pass_out->quad_list.ElementAt(i - 1)->shared_quad_state;
538 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
542 TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
543 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
544 pass_in->SetAll(RenderPassId(1, 1),
545 gfx::Rect(100, 100),
546 gfx::Rect(),
547 gfx::Transform(),
548 false);
550 // The first SharedQuadState is used.
551 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
552 shared_state1_in->SetAll(gfx::Transform(),
553 gfx::Size(1, 1),
554 gfx::Rect(),
555 gfx::Rect(),
556 false,
557 1.f,
558 SkXfermode::kSrcOver_Mode,
561 CheckerboardDrawQuad* quad1 =
562 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
563 quad1->SetAll(shared_state1_in,
564 gfx::Rect(10, 10),
565 gfx::Rect(10, 10),
566 gfx::Rect(10, 10),
567 false,
568 SK_ColorRED);
570 // The second and third SharedQuadStates are not used.
571 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
572 shared_state2_in->SetAll(gfx::Transform(),
573 gfx::Size(2, 2),
574 gfx::Rect(),
575 gfx::Rect(),
576 false,
577 1.f,
578 SkXfermode::kSrcOver_Mode,
581 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
582 shared_state3_in->SetAll(gfx::Transform(),
583 gfx::Size(3, 3),
584 gfx::Rect(),
585 gfx::Rect(),
586 false,
587 1.f,
588 SkXfermode::kSrcOver_Mode,
591 // The fourth SharedQuadState is used.
592 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
593 shared_state4_in->SetAll(gfx::Transform(),
594 gfx::Size(4, 4),
595 gfx::Rect(),
596 gfx::Rect(),
597 false,
598 1.f,
599 SkXfermode::kSrcOver_Mode,
602 CheckerboardDrawQuad* quad2 =
603 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
604 quad2->SetAll(shared_state4_in,
605 gfx::Rect(10, 10),
606 gfx::Rect(10, 10),
607 gfx::Rect(10, 10),
608 false,
609 SK_ColorRED);
611 // The fifth is not used again.
612 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
613 shared_state5_in->SetAll(gfx::Transform(),
614 gfx::Size(5, 5),
615 gfx::Rect(),
616 gfx::Rect(),
617 false,
618 1.f,
619 SkXfermode::kSrcOver_Mode,
622 // 5 SharedQuadStates go in.
623 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
624 ASSERT_EQ(2u, pass_in->quad_list.size());
626 DelegatedFrameData frame_in;
627 frame_in.render_pass_list.push_back(pass_in.Pass());
629 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
630 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
632 DelegatedFrameData frame_out;
633 PickleIterator iter(msg);
634 EXPECT_TRUE(
635 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
637 scoped_ptr<RenderPass> pass_out =
638 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
640 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
641 // used by quads, and so serialized. Others were not.
642 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
643 ASSERT_EQ(2u, pass_out->quad_list.size());
645 EXPECT_EQ(
646 gfx::Size(1, 1).ToString(),
647 pass_out->shared_quad_state_list.ElementAt(0)->content_bounds.ToString());
648 EXPECT_EQ(
649 gfx::Size(4, 4).ToString(),
650 pass_out->shared_quad_state_list.ElementAt(1)->content_bounds.ToString());
653 TEST_F(CCMessagesTest, Resources) {
654 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
655 gfx::Size arbitrary_size(757, 1281);
656 unsigned int arbitrary_uint1 = 71234838;
657 unsigned int arbitrary_uint2 = 53589793;
659 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
660 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
661 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
662 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
664 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
665 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
666 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
667 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
669 TransferableResource arbitrary_resource1;
670 arbitrary_resource1.id = 2178312;
671 arbitrary_resource1.format = cc::RGBA_8888;
672 arbitrary_resource1.filter = 53;
673 arbitrary_resource1.size = gfx::Size(37189, 123123);
674 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
675 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
676 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
677 arbitrary_resource1.allow_overlay = true;
679 TransferableResource arbitrary_resource2;
680 arbitrary_resource2.id = 789132;
681 arbitrary_resource2.format = cc::RGBA_4444;
682 arbitrary_resource2.filter = 47;
683 arbitrary_resource2.size = gfx::Size(89123, 23789);
684 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
685 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
686 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
687 arbitrary_resource2.allow_overlay = false;
689 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
690 renderpass_in->SetNew(
691 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
693 DelegatedFrameData frame_in;
694 frame_in.resource_list.push_back(arbitrary_resource1);
695 frame_in.resource_list.push_back(arbitrary_resource2);
696 frame_in.render_pass_list.push_back(renderpass_in.Pass());
698 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
700 DelegatedFrameData frame_out;
701 PickleIterator iter(msg);
702 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
703 &iter, &frame_out));
705 ASSERT_EQ(2u, frame_out.resource_list.size());
706 Compare(arbitrary_resource1, frame_out.resource_list[0]);
707 Compare(arbitrary_resource2, frame_out.resource_list[1]);
710 TEST_F(CCMessagesTest, SoftwareFrameData) {
711 cc::SoftwareFrameData frame_in;
712 frame_in.id = 3;
713 frame_in.size = gfx::Size(40, 20);
714 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
715 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
717 // Write the frame.
718 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
719 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
721 // Read the frame.
722 cc::SoftwareFrameData frame_out;
723 PickleIterator iter(msg);
724 EXPECT_TRUE(
725 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
726 EXPECT_EQ(frame_in.id, frame_out.id);
727 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
728 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
729 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
732 TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
733 SoftwareFrameData frame_in;
734 frame_in.id = 3;
735 frame_in.size = gfx::Size(40, 20);
736 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
737 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
739 // Write the SoftwareFrameData by hand, make sure it works.
741 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
742 IPC::WriteParam(&msg, frame_in.id);
743 IPC::WriteParam(&msg, frame_in.size);
744 IPC::WriteParam(&msg, frame_in.damage_rect);
745 IPC::WriteParam(&msg, frame_in.bitmap_id);
746 SoftwareFrameData frame_out;
747 PickleIterator iter(msg);
748 EXPECT_TRUE(
749 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
752 // The size of the frame may overflow when multiplied together.
753 int max = std::numeric_limits<int>::max();
754 frame_in.size = gfx::Size(max, max);
756 // If size_t is larger than int, then int*int*4 can always fit in size_t.
757 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
759 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
760 // should fail.
762 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
763 IPC::WriteParam(&msg, frame_in.id);
764 IPC::WriteParam(&msg, frame_in.size);
765 IPC::WriteParam(&msg, frame_in.damage_rect);
766 IPC::WriteParam(&msg, frame_in.bitmap_id);
767 SoftwareFrameData frame_out;
768 PickleIterator iter(msg);
769 EXPECT_EQ(
770 expect_read,
771 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
775 } // namespace
776 } // namespace content