Cleanup: Update the path to insets and point headers.
[chromium-blink-merge.git] / content / common / cc_messages_unittest.cc
blobd3ec0df50060336776cee4924c60681c26738ff0
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);
189 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
192 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
193 EXPECT_EQ(a->resource_id, b->resource_id);
194 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
195 EXPECT_EQ(a->texture_size, b->texture_size);
196 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
197 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
200 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
201 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
202 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id);
203 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id);
204 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id);
205 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
206 EXPECT_EQ(a->color_space, b->color_space);
209 void Compare(const TransferableResource& a, const TransferableResource& b) {
210 EXPECT_EQ(a.id, b.id);
211 EXPECT_EQ(a.format, b.format);
212 EXPECT_EQ(a.filter, b.filter);
213 EXPECT_EQ(a.size.ToString(), b.size.ToString());
214 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
215 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
216 b.mailbox_holder.mailbox.name[i]);
218 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
219 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
220 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
224 TEST_F(CCMessagesTest, AllQuads) {
225 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
227 Transform arbitrary_matrix;
228 arbitrary_matrix.Scale(3, 3);
229 arbitrary_matrix.Translate(-5, 20);
230 arbitrary_matrix.Rotate(15);
231 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
232 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
233 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
234 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
235 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
236 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
237 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
238 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
239 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
240 gfx::Size arbitrary_size1(15, 19);
241 gfx::Size arbitrary_size2(3, 99);
242 gfx::Size arbitrary_size3(75, 1281);
243 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
244 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
245 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
246 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
247 gfx::Vector2dF arbitrary_vector2df1(16.2f, -85.1f);
248 gfx::Vector2dF arbitrary_vector2df2(-8.3f, 0.47f);
249 float arbitrary_float1 = 0.7f;
250 float arbitrary_float2 = 0.3f;
251 float arbitrary_float3 = 0.9f;
252 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
253 bool arbitrary_bool1 = true;
254 bool arbitrary_bool2 = false;
255 bool arbitrary_bool3 = true;
256 bool arbitrary_bool4 = true;
257 int arbitrary_context_id1 = 12;
258 int arbitrary_context_id2 = 57;
259 int arbitrary_context_id3 = -503;
260 int arbitrary_int = 5;
261 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
262 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
263 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
264 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
265 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
266 IOSurfaceDrawQuad::UNFLIPPED;
267 RenderPassId arbitrary_id(10, 14);
268 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
269 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
270 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
271 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
272 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
273 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
274 YUVVideoDrawQuad::REC_601;
276 FilterOperations arbitrary_filters1;
277 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
278 arbitrary_float1));
279 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
280 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
281 arbitrary_filters1.Append(
282 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
284 FilterOperations arbitrary_filters2;
285 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
286 arbitrary_float2));
288 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
289 pass_in->SetAll(arbitrary_id,
290 arbitrary_rect1,
291 arbitrary_rect2,
292 arbitrary_matrix,
293 arbitrary_bool1);
295 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
296 shared_state1_in->SetAll(arbitrary_matrix,
297 arbitrary_size1,
298 arbitrary_rect1,
299 arbitrary_rect2,
300 arbitrary_bool1,
301 arbitrary_float1,
302 arbitrary_blend_mode1,
303 arbitrary_context_id1);
305 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
306 pass_cmp->SetAll(arbitrary_id,
307 arbitrary_rect1,
308 arbitrary_rect2,
309 arbitrary_matrix,
310 arbitrary_bool1);
312 SharedQuadState* shared_state1_cmp =
313 pass_cmp->CreateAndAppendSharedQuadState();
314 shared_state1_cmp->CopyFrom(shared_state1_in);
316 CheckerboardDrawQuad* checkerboard_in =
317 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
318 checkerboard_in->SetAll(shared_state1_in,
319 arbitrary_rect1,
320 arbitrary_rect2_inside_rect1,
321 arbitrary_rect1_inside_rect1,
322 arbitrary_bool1,
323 arbitrary_color);
324 pass_cmp->CopyFromAndAppendDrawQuad(checkerboard_in,
325 checkerboard_in->shared_quad_state);
327 DebugBorderDrawQuad* debugborder_in =
328 pass_in->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
329 debugborder_in->SetAll(shared_state1_in,
330 arbitrary_rect3,
331 arbitrary_rect1_inside_rect3,
332 arbitrary_rect2_inside_rect3,
333 arbitrary_bool1,
334 arbitrary_color,
335 arbitrary_int);
336 pass_cmp->CopyFromAndAppendDrawQuad(debugborder_in,
337 debugborder_in->shared_quad_state);
339 IOSurfaceDrawQuad* iosurface_in =
340 pass_in->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
341 iosurface_in->SetAll(shared_state1_in,
342 arbitrary_rect2,
343 arbitrary_rect2_inside_rect2,
344 arbitrary_rect1_inside_rect2,
345 arbitrary_bool1,
346 arbitrary_size1,
347 arbitrary_resourceid3,
348 arbitrary_orientation);
349 pass_cmp->CopyFromAndAppendDrawQuad(iosurface_in,
350 iosurface_in->shared_quad_state);
352 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
353 shared_state2_in->SetAll(arbitrary_matrix,
354 arbitrary_size2,
355 arbitrary_rect2,
356 arbitrary_rect3,
357 arbitrary_bool1,
358 arbitrary_float2,
359 arbitrary_blend_mode2,
360 arbitrary_context_id2);
361 SharedQuadState* shared_state2_cmp =
362 pass_cmp->CreateAndAppendSharedQuadState();
363 shared_state2_cmp->CopyFrom(shared_state2_in);
365 RenderPassDrawQuad* renderpass_in =
366 pass_in->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
367 renderpass_in->SetAll(shared_state2_in,
368 arbitrary_rect1,
369 arbitrary_rect2_inside_rect1,
370 arbitrary_rect1_inside_rect1,
371 arbitrary_bool1,
372 arbitrary_id,
373 arbitrary_resourceid2,
374 arbitrary_vector2df1,
375 arbitrary_size1,
376 arbitrary_filters1,
377 arbitrary_vector2df2,
378 arbitrary_filters2);
379 pass_cmp->CopyFromAndAppendRenderPassDrawQuad(
380 renderpass_in,
381 renderpass_in->shared_quad_state,
382 renderpass_in->render_pass_id);
384 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
385 shared_state3_in->SetAll(arbitrary_matrix,
386 arbitrary_size3,
387 arbitrary_rect3,
388 arbitrary_rect1,
389 arbitrary_bool1,
390 arbitrary_float3,
391 arbitrary_blend_mode3,
392 arbitrary_context_id3);
393 SharedQuadState* shared_state3_cmp =
394 pass_cmp->CreateAndAppendSharedQuadState();
395 shared_state3_cmp->CopyFrom(shared_state3_in);
397 SolidColorDrawQuad* solidcolor_in =
398 pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
399 solidcolor_in->SetAll(shared_state3_in,
400 arbitrary_rect3,
401 arbitrary_rect1_inside_rect3,
402 arbitrary_rect2_inside_rect3,
403 arbitrary_bool1,
404 arbitrary_color,
405 arbitrary_bool2);
406 pass_cmp->CopyFromAndAppendDrawQuad(solidcolor_in,
407 solidcolor_in->shared_quad_state);
409 StreamVideoDrawQuad* streamvideo_in =
410 pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
411 streamvideo_in->SetAll(shared_state3_in,
412 arbitrary_rect2,
413 arbitrary_rect2_inside_rect2,
414 arbitrary_rect1_inside_rect2,
415 arbitrary_bool1,
416 arbitrary_resourceid2,
417 arbitrary_matrix);
418 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
419 streamvideo_in->shared_quad_state);
421 cc::SurfaceId arbitrary_surface_id(3);
422 SurfaceDrawQuad* surface_in =
423 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
424 surface_in->SetAll(shared_state3_in,
425 arbitrary_rect2,
426 arbitrary_rect2_inside_rect2,
427 arbitrary_rect1_inside_rect2,
428 arbitrary_bool1,
429 arbitrary_surface_id);
430 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
431 surface_in->shared_quad_state);
433 TextureDrawQuad* texture_in =
434 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
435 texture_in->SetAll(shared_state3_in,
436 arbitrary_rect2,
437 arbitrary_rect2_inside_rect2,
438 arbitrary_rect1_inside_rect2,
439 arbitrary_bool1,
440 arbitrary_resourceid1,
441 arbitrary_bool2,
442 arbitrary_pointf1,
443 arbitrary_pointf2,
444 arbitrary_color,
445 arbitrary_float_array,
446 arbitrary_bool3,
447 arbitrary_bool4);
448 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
449 texture_in->shared_quad_state);
451 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
452 tile_in->SetAll(shared_state3_in,
453 arbitrary_rect2,
454 arbitrary_rect2_inside_rect2,
455 arbitrary_rect1_inside_rect2,
456 arbitrary_bool1,
457 arbitrary_resourceid3,
458 arbitrary_rectf1,
459 arbitrary_size1,
460 arbitrary_bool2,
461 arbitrary_bool3);
462 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
464 YUVVideoDrawQuad* yuvvideo_in =
465 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
466 yuvvideo_in->SetAll(shared_state3_in,
467 arbitrary_rect1,
468 arbitrary_rect2_inside_rect1,
469 arbitrary_rect1_inside_rect1,
470 arbitrary_bool1,
471 arbitrary_rectf1,
472 arbitrary_resourceid1,
473 arbitrary_resourceid2,
474 arbitrary_resourceid3,
475 arbitrary_resourceid4,
476 arbitrary_color_space);
477 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
478 yuvvideo_in->shared_quad_state);
480 // Make sure the in and cmp RenderPasses match.
481 Compare(pass_cmp.get(), pass_in.get());
482 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
483 ASSERT_EQ(10u, pass_in->quad_list.size());
484 for (cc::SharedQuadStateList::ConstIterator
485 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
486 in_iterator = pass_in->shared_quad_state_list.begin();
487 in_iterator != pass_in->shared_quad_state_list.end();
488 ++cmp_iterator, ++in_iterator) {
489 Compare(*cmp_iterator, *in_iterator);
491 for (auto in_iter = pass_in->quad_list.cbegin(),
492 cmp_iter = pass_cmp->quad_list.cbegin();
493 in_iter != pass_in->quad_list.cend();
494 ++in_iter, ++cmp_iter)
495 Compare(*cmp_iter, *in_iter);
497 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
498 bool same_shared_quad_state_cmp =
499 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
500 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
501 bool same_shared_quad_state_in =
502 pass_in->quad_list.ElementAt(i)->shared_quad_state ==
503 pass_in->quad_list.ElementAt(i - 1)->shared_quad_state;
504 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
507 DelegatedFrameData frame_in;
508 frame_in.render_pass_list.push_back(pass_in.Pass());
510 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
512 DelegatedFrameData frame_out;
513 PickleIterator iter(msg);
514 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
515 &iter, &frame_out));
517 // Make sure the out and cmp RenderPasses match.
518 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
519 frame_out.render_pass_list.begin());
520 Compare(pass_cmp.get(), pass_out.get());
521 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
522 ASSERT_EQ(10u, pass_out->quad_list.size());
523 for (cc::SharedQuadStateList::ConstIterator
524 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
525 out_iterator = pass_out->shared_quad_state_list.begin();
526 out_iterator != pass_out->shared_quad_state_list.end();
527 ++cmp_iterator, ++out_iterator) {
528 Compare(*cmp_iterator, *out_iterator);
530 for (auto out_iter = pass_out->quad_list.cbegin(),
531 cmp_iter = pass_cmp->quad_list.cbegin();
532 out_iter != pass_out->quad_list.cend();
533 ++out_iter, ++cmp_iter)
534 Compare(*cmp_iter, *out_iter);
536 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
537 bool same_shared_quad_state_cmp =
538 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
539 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
540 bool same_shared_quad_state_out =
541 pass_out->quad_list.ElementAt(i)->shared_quad_state ==
542 pass_out->quad_list.ElementAt(i - 1)->shared_quad_state;
543 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
547 TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
548 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
549 pass_in->SetAll(RenderPassId(1, 1),
550 gfx::Rect(100, 100),
551 gfx::Rect(),
552 gfx::Transform(),
553 false);
555 // The first SharedQuadState is used.
556 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
557 shared_state1_in->SetAll(gfx::Transform(),
558 gfx::Size(1, 1),
559 gfx::Rect(),
560 gfx::Rect(),
561 false,
562 1.f,
563 SkXfermode::kSrcOver_Mode,
566 CheckerboardDrawQuad* quad1 =
567 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
568 quad1->SetAll(shared_state1_in,
569 gfx::Rect(10, 10),
570 gfx::Rect(10, 10),
571 gfx::Rect(10, 10),
572 false,
573 SK_ColorRED);
575 // The second and third SharedQuadStates are not used.
576 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
577 shared_state2_in->SetAll(gfx::Transform(),
578 gfx::Size(2, 2),
579 gfx::Rect(),
580 gfx::Rect(),
581 false,
582 1.f,
583 SkXfermode::kSrcOver_Mode,
586 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
587 shared_state3_in->SetAll(gfx::Transform(),
588 gfx::Size(3, 3),
589 gfx::Rect(),
590 gfx::Rect(),
591 false,
592 1.f,
593 SkXfermode::kSrcOver_Mode,
596 // The fourth SharedQuadState is used.
597 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
598 shared_state4_in->SetAll(gfx::Transform(),
599 gfx::Size(4, 4),
600 gfx::Rect(),
601 gfx::Rect(),
602 false,
603 1.f,
604 SkXfermode::kSrcOver_Mode,
607 CheckerboardDrawQuad* quad2 =
608 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
609 quad2->SetAll(shared_state4_in,
610 gfx::Rect(10, 10),
611 gfx::Rect(10, 10),
612 gfx::Rect(10, 10),
613 false,
614 SK_ColorRED);
616 // The fifth is not used again.
617 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
618 shared_state5_in->SetAll(gfx::Transform(),
619 gfx::Size(5, 5),
620 gfx::Rect(),
621 gfx::Rect(),
622 false,
623 1.f,
624 SkXfermode::kSrcOver_Mode,
627 // 5 SharedQuadStates go in.
628 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
629 ASSERT_EQ(2u, pass_in->quad_list.size());
631 DelegatedFrameData frame_in;
632 frame_in.render_pass_list.push_back(pass_in.Pass());
634 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
635 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
637 DelegatedFrameData frame_out;
638 PickleIterator iter(msg);
639 EXPECT_TRUE(
640 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
642 scoped_ptr<RenderPass> pass_out =
643 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
645 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
646 // used by quads, and so serialized. Others were not.
647 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
648 ASSERT_EQ(2u, pass_out->quad_list.size());
650 EXPECT_EQ(
651 gfx::Size(1, 1).ToString(),
652 pass_out->shared_quad_state_list.ElementAt(0)->content_bounds.ToString());
653 EXPECT_EQ(
654 gfx::Size(4, 4).ToString(),
655 pass_out->shared_quad_state_list.ElementAt(1)->content_bounds.ToString());
658 TEST_F(CCMessagesTest, Resources) {
659 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
660 gfx::Size arbitrary_size(757, 1281);
661 unsigned int arbitrary_uint1 = 71234838;
662 unsigned int arbitrary_uint2 = 53589793;
664 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
665 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
666 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
667 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
669 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
670 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
671 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
672 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
674 TransferableResource arbitrary_resource1;
675 arbitrary_resource1.id = 2178312;
676 arbitrary_resource1.format = cc::RGBA_8888;
677 arbitrary_resource1.filter = 53;
678 arbitrary_resource1.size = gfx::Size(37189, 123123);
679 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
680 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
681 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
682 arbitrary_resource1.allow_overlay = true;
684 TransferableResource arbitrary_resource2;
685 arbitrary_resource2.id = 789132;
686 arbitrary_resource2.format = cc::RGBA_4444;
687 arbitrary_resource2.filter = 47;
688 arbitrary_resource2.size = gfx::Size(89123, 23789);
689 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
690 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
691 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
692 arbitrary_resource2.allow_overlay = false;
694 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
695 renderpass_in->SetNew(
696 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
698 DelegatedFrameData frame_in;
699 frame_in.resource_list.push_back(arbitrary_resource1);
700 frame_in.resource_list.push_back(arbitrary_resource2);
701 frame_in.render_pass_list.push_back(renderpass_in.Pass());
703 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
705 DelegatedFrameData frame_out;
706 PickleIterator iter(msg);
707 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
708 &iter, &frame_out));
710 ASSERT_EQ(2u, frame_out.resource_list.size());
711 Compare(arbitrary_resource1, frame_out.resource_list[0]);
712 Compare(arbitrary_resource2, frame_out.resource_list[1]);
715 TEST_F(CCMessagesTest, SoftwareFrameData) {
716 cc::SoftwareFrameData frame_in;
717 frame_in.id = 3;
718 frame_in.size = gfx::Size(40, 20);
719 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
720 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
722 // Write the frame.
723 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
724 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
726 // Read the frame.
727 cc::SoftwareFrameData frame_out;
728 PickleIterator iter(msg);
729 EXPECT_TRUE(
730 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
731 EXPECT_EQ(frame_in.id, frame_out.id);
732 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
733 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
734 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
737 TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
738 SoftwareFrameData frame_in;
739 frame_in.id = 3;
740 frame_in.size = gfx::Size(40, 20);
741 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
742 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
744 // Write the SoftwareFrameData by hand, make sure it works.
746 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
747 IPC::WriteParam(&msg, frame_in.id);
748 IPC::WriteParam(&msg, frame_in.size);
749 IPC::WriteParam(&msg, frame_in.damage_rect);
750 IPC::WriteParam(&msg, frame_in.bitmap_id);
751 SoftwareFrameData frame_out;
752 PickleIterator iter(msg);
753 EXPECT_TRUE(
754 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
757 // The size of the frame may overflow when multiplied together.
758 int max = std::numeric_limits<int>::max();
759 frame_in.size = gfx::Size(max, max);
761 // If size_t is larger than int, then int*int*4 can always fit in size_t.
762 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
764 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
765 // should fail.
767 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
768 IPC::WriteParam(&msg, frame_in.id);
769 IPC::WriteParam(&msg, frame_in.size);
770 IPC::WriteParam(&msg, frame_in.damage_rect);
771 IPC::WriteParam(&msg, frame_in.bitmap_id);
772 SoftwareFrameData frame_out;
773 PickleIterator iter(msg);
774 EXPECT_EQ(
775 expect_read,
776 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
780 } // namespace
781 } // namespace content