Update optimize_png_files.sh to work on msysgit bash.
[chromium-blink-merge.git] / content / common / cc_messages_unittest.cc
blobe8405965345aadf0456f747dc7b4399db6e55fce
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::RenderPassDrawQuad;
32 using cc::ResourceProvider;
33 using cc::SharedQuadState;
34 using cc::SoftwareFrameData;
35 using cc::SolidColorDrawQuad;
36 using cc::SurfaceDrawQuad;
37 using cc::TextureDrawQuad;
38 using cc::TileDrawQuad;
39 using cc::TransferableResource;
40 using cc::StreamVideoDrawQuad;
41 using cc::VideoLayerImpl;
42 using cc::YUVVideoDrawQuad;
43 using gfx::Transform;
45 namespace content {
46 namespace {
48 class CCMessagesTest : public testing::Test {
49 protected:
50 void Compare(const RenderPass* a, const RenderPass* b) {
51 EXPECT_EQ(a->id, b->id);
52 EXPECT_EQ(a->output_rect.ToString(), b->output_rect.ToString());
53 EXPECT_EQ(a->damage_rect.ToString(), b->damage_rect.ToString());
54 EXPECT_EQ(a->transform_to_root_target, b->transform_to_root_target);
55 EXPECT_EQ(a->has_transparent_background, b->has_transparent_background);
58 void Compare(const SharedQuadState* a, const SharedQuadState* b) {
59 EXPECT_EQ(a->content_to_target_transform, b->content_to_target_transform);
60 EXPECT_EQ(a->content_bounds, b->content_bounds);
61 EXPECT_EQ(a->visible_content_rect, b->visible_content_rect);
62 EXPECT_EQ(a->clip_rect, b->clip_rect);
63 EXPECT_EQ(a->is_clipped, b->is_clipped);
64 EXPECT_EQ(a->opacity, b->opacity);
65 EXPECT_EQ(a->blend_mode, b->blend_mode);
68 void Compare(const DrawQuad* a, const DrawQuad* b) {
69 ASSERT_NE(DrawQuad::INVALID, a->material);
70 ASSERT_EQ(a->material, b->material);
71 EXPECT_EQ(a->rect.ToString(), b->rect.ToString());
72 EXPECT_EQ(a->opaque_rect.ToString(), b->opaque_rect.ToString());
73 EXPECT_EQ(a->visible_rect.ToString(), b->visible_rect.ToString());
74 EXPECT_EQ(a->needs_blending, b->needs_blending);
76 Compare(a->shared_quad_state, b->shared_quad_state);
78 switch (a->material) {
79 case DrawQuad::CHECKERBOARD:
80 Compare(CheckerboardDrawQuad::MaterialCast(a),
81 CheckerboardDrawQuad::MaterialCast(b));
82 break;
83 case DrawQuad::DEBUG_BORDER:
84 Compare(DebugBorderDrawQuad::MaterialCast(a),
85 DebugBorderDrawQuad::MaterialCast(b));
86 break;
87 case DrawQuad::IO_SURFACE_CONTENT:
88 Compare(IOSurfaceDrawQuad::MaterialCast(a),
89 IOSurfaceDrawQuad::MaterialCast(b));
90 break;
91 case DrawQuad::PICTURE_CONTENT:
92 Compare(PictureDrawQuad::MaterialCast(a),
93 PictureDrawQuad::MaterialCast(b));
94 break;
95 case DrawQuad::RENDER_PASS:
96 Compare(RenderPassDrawQuad::MaterialCast(a),
97 RenderPassDrawQuad::MaterialCast(b));
98 break;
99 case DrawQuad::TEXTURE_CONTENT:
100 Compare(TextureDrawQuad::MaterialCast(a),
101 TextureDrawQuad::MaterialCast(b));
102 break;
103 case DrawQuad::TILED_CONTENT:
104 Compare(TileDrawQuad::MaterialCast(a),
105 TileDrawQuad::MaterialCast(b));
106 break;
107 case DrawQuad::SOLID_COLOR:
108 Compare(SolidColorDrawQuad::MaterialCast(a),
109 SolidColorDrawQuad::MaterialCast(b));
110 break;
111 case DrawQuad::STREAM_VIDEO_CONTENT:
112 Compare(StreamVideoDrawQuad::MaterialCast(a),
113 StreamVideoDrawQuad::MaterialCast(b));
114 break;
115 case DrawQuad::SURFACE_CONTENT:
116 Compare(SurfaceDrawQuad::MaterialCast(a),
117 SurfaceDrawQuad::MaterialCast(b));
118 break;
119 case DrawQuad::YUV_VIDEO_CONTENT:
120 Compare(YUVVideoDrawQuad::MaterialCast(a),
121 YUVVideoDrawQuad::MaterialCast(b));
122 break;
123 case DrawQuad::INVALID:
124 break;
128 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) {
129 EXPECT_EQ(a->color, b->color);
132 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
133 EXPECT_EQ(a->color, b->color);
134 EXPECT_EQ(a->width, b->width);
137 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
138 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
139 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
140 EXPECT_EQ(a->orientation, b->orientation);
143 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
144 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
145 EXPECT_EQ(a->is_replica, b->is_replica);
146 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id);
147 EXPECT_EQ(a->contents_changed_since_last_frame,
148 b->contents_changed_since_last_frame);
149 EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.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->background_filters, b->background_filters);
163 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
164 EXPECT_EQ(a->color, b->color);
165 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
168 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
169 EXPECT_EQ(a->resource_id, b->resource_id);
170 EXPECT_EQ(a->matrix, b->matrix);
173 void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
174 EXPECT_EQ(a->surface_id, b->surface_id);
177 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
178 EXPECT_EQ(a->resource_id, b->resource_id);
179 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha);
180 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
181 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
182 EXPECT_EQ(a->background_color, b->background_color);
183 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]);
184 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]);
185 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]);
186 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]);
187 EXPECT_EQ(a->flipped, b->flipped);
190 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
191 EXPECT_EQ(a->resource_id, b->resource_id);
192 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
193 EXPECT_EQ(a->texture_size, b->texture_size);
194 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
197 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
198 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
199 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id);
200 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id);
201 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id);
202 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
203 EXPECT_EQ(a->color_space, b->color_space);
206 void Compare(const TransferableResource& a, const TransferableResource& b) {
207 EXPECT_EQ(a.id, b.id);
208 EXPECT_EQ(a.format, b.format);
209 EXPECT_EQ(a.filter, b.filter);
210 EXPECT_EQ(a.size.ToString(), b.size.ToString());
211 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
212 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
213 b.mailbox_holder.mailbox.name[i]);
215 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
216 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
220 TEST_F(CCMessagesTest, AllQuads) {
221 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
223 Transform arbitrary_matrix;
224 arbitrary_matrix.Scale(3, 3);
225 arbitrary_matrix.Translate(-5, 20);
226 arbitrary_matrix.Rotate(15);
227 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
228 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
229 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
230 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
231 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
232 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
233 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
234 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
235 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
236 gfx::Size arbitrary_size1(15, 19);
237 gfx::Size arbitrary_size2(3, 99);
238 gfx::Size arbitrary_size3(75, 1281);
239 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
240 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
241 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
242 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
243 float arbitrary_float1 = 0.7f;
244 float arbitrary_float2 = 0.3f;
245 float arbitrary_float3 = 0.9f;
246 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
247 bool arbitrary_bool1 = true;
248 bool arbitrary_bool2 = false;
249 bool arbitrary_bool3 = true;
250 int arbitrary_int = 5;
251 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
252 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
253 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
254 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
255 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
256 IOSurfaceDrawQuad::UNFLIPPED;
257 RenderPass::Id arbitrary_id(10, 14);
258 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
259 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
260 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
261 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
262 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
263 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
264 YUVVideoDrawQuad::REC_601;
266 FilterOperations arbitrary_filters1;
267 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
268 arbitrary_float1));
269 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
270 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
271 arbitrary_filters1.Append(
272 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
274 FilterOperations arbitrary_filters2;
275 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
276 arbitrary_float2));
278 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
279 pass_in->SetAll(arbitrary_id,
280 arbitrary_rect1,
281 arbitrary_rect2,
282 arbitrary_matrix,
283 arbitrary_bool1);
285 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
286 shared_state1_in->SetAll(arbitrary_matrix,
287 arbitrary_size1,
288 arbitrary_rect1,
289 arbitrary_rect2,
290 arbitrary_bool1,
291 arbitrary_float1,
292 arbitrary_blend_mode1);
294 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
295 pass_cmp->SetAll(arbitrary_id,
296 arbitrary_rect1,
297 arbitrary_rect2,
298 arbitrary_matrix,
299 arbitrary_bool1);
301 SharedQuadState* shared_state1_cmp =
302 pass_cmp->CreateAndAppendSharedQuadState();
303 shared_state1_cmp->CopyFrom(shared_state1_in);
305 scoped_ptr<CheckerboardDrawQuad> checkerboard_in =
306 CheckerboardDrawQuad::Create();
307 checkerboard_in->SetAll(shared_state1_in,
308 arbitrary_rect1,
309 arbitrary_rect2_inside_rect1,
310 arbitrary_rect1_inside_rect1,
311 arbitrary_bool1,
312 arbitrary_color);
313 scoped_ptr<DrawQuad> checkerboard_cmp = checkerboard_in->Copy(
314 checkerboard_in->shared_quad_state);
316 scoped_ptr<DebugBorderDrawQuad> debugborder_in =
317 DebugBorderDrawQuad::Create();
318 debugborder_in->SetAll(shared_state1_in,
319 arbitrary_rect3,
320 arbitrary_rect1_inside_rect3,
321 arbitrary_rect2_inside_rect3,
322 arbitrary_bool1,
323 arbitrary_color,
324 arbitrary_int);
325 scoped_ptr<DrawQuad> debugborder_cmp = debugborder_in->Copy(
326 debugborder_in->shared_quad_state);
328 scoped_ptr<IOSurfaceDrawQuad> iosurface_in =
329 IOSurfaceDrawQuad::Create();
330 iosurface_in->SetAll(shared_state1_in,
331 arbitrary_rect2,
332 arbitrary_rect2_inside_rect2,
333 arbitrary_rect1_inside_rect2,
334 arbitrary_bool1,
335 arbitrary_size1,
336 arbitrary_resourceid3,
337 arbitrary_orientation);
338 scoped_ptr<DrawQuad> iosurface_cmp = iosurface_in->Copy(
339 iosurface_in->shared_quad_state);
341 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
342 shared_state2_in->SetAll(arbitrary_matrix,
343 arbitrary_size2,
344 arbitrary_rect2,
345 arbitrary_rect3,
346 arbitrary_bool1,
347 arbitrary_float2,
348 arbitrary_blend_mode2);
349 SharedQuadState* shared_state2_cmp =
350 pass_cmp->CreateAndAppendSharedQuadState();
351 shared_state2_cmp->CopyFrom(shared_state2_in);
353 scoped_ptr<RenderPassDrawQuad> renderpass_in =
354 RenderPassDrawQuad::Create();
355 renderpass_in->SetAll(shared_state2_in,
356 arbitrary_rect1,
357 arbitrary_rect2_inside_rect1,
358 arbitrary_rect1_inside_rect1,
359 arbitrary_bool1,
360 arbitrary_id,
361 arbitrary_bool2,
362 arbitrary_resourceid2,
363 arbitrary_rect1,
364 arbitrary_rectf1,
365 arbitrary_filters1,
366 arbitrary_filters2);
367 scoped_ptr<RenderPassDrawQuad> renderpass_cmp = renderpass_in->Copy(
368 renderpass_in->shared_quad_state, renderpass_in->render_pass_id);
370 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
371 shared_state3_in->SetAll(arbitrary_matrix,
372 arbitrary_size3,
373 arbitrary_rect3,
374 arbitrary_rect1,
375 arbitrary_bool1,
376 arbitrary_float3,
377 arbitrary_blend_mode3);
378 SharedQuadState* shared_state3_cmp =
379 pass_cmp->CreateAndAppendSharedQuadState();
380 shared_state3_cmp->CopyFrom(shared_state3_in);
382 scoped_ptr<SolidColorDrawQuad> solidcolor_in =
383 SolidColorDrawQuad::Create();
384 solidcolor_in->SetAll(shared_state3_in,
385 arbitrary_rect3,
386 arbitrary_rect1_inside_rect3,
387 arbitrary_rect2_inside_rect3,
388 arbitrary_bool1,
389 arbitrary_color,
390 arbitrary_bool2);
391 scoped_ptr<DrawQuad> solidcolor_cmp = solidcolor_in->Copy(
392 solidcolor_in->shared_quad_state);
394 scoped_ptr<StreamVideoDrawQuad> streamvideo_in =
395 StreamVideoDrawQuad::Create();
396 streamvideo_in->SetAll(shared_state3_in,
397 arbitrary_rect2,
398 arbitrary_rect2_inside_rect2,
399 arbitrary_rect1_inside_rect2,
400 arbitrary_bool1,
401 arbitrary_resourceid2,
402 arbitrary_matrix);
403 scoped_ptr<DrawQuad> streamvideo_cmp = streamvideo_in->Copy(
404 streamvideo_in->shared_quad_state);
406 int arbitrary_surface_id = 3;
407 scoped_ptr<SurfaceDrawQuad> surface_in = SurfaceDrawQuad::Create();
408 surface_in->SetAll(shared_state3_in,
409 arbitrary_rect2,
410 arbitrary_rect2_inside_rect2,
411 arbitrary_rect1_inside_rect2,
412 arbitrary_bool1,
413 arbitrary_surface_id);
414 scoped_ptr<DrawQuad> surface_cmp = surface_in->Copy(
415 surface_in->shared_quad_state);
417 scoped_ptr<TextureDrawQuad> texture_in = TextureDrawQuad::Create();
418 texture_in->SetAll(shared_state3_in,
419 arbitrary_rect2,
420 arbitrary_rect2_inside_rect2,
421 arbitrary_rect1_inside_rect2,
422 arbitrary_bool1,
423 arbitrary_resourceid1,
424 arbitrary_bool2,
425 arbitrary_pointf1,
426 arbitrary_pointf2,
427 arbitrary_color,
428 arbitrary_float_array,
429 arbitrary_bool3);
430 scoped_ptr<DrawQuad> texture_cmp = texture_in->Copy(
431 texture_in->shared_quad_state);
433 scoped_ptr<TileDrawQuad> tile_in = TileDrawQuad::Create();
434 tile_in->SetAll(shared_state3_in,
435 arbitrary_rect2,
436 arbitrary_rect2_inside_rect2,
437 arbitrary_rect1_inside_rect2,
438 arbitrary_bool1,
439 arbitrary_resourceid3,
440 arbitrary_rectf1,
441 arbitrary_size1,
442 arbitrary_bool2);
443 scoped_ptr<DrawQuad> tile_cmp = tile_in->Copy(
444 tile_in->shared_quad_state);
446 scoped_ptr<YUVVideoDrawQuad> yuvvideo_in =
447 YUVVideoDrawQuad::Create();
448 yuvvideo_in->SetAll(shared_state3_in,
449 arbitrary_rect1,
450 arbitrary_rect2_inside_rect1,
451 arbitrary_rect1_inside_rect1,
452 arbitrary_bool1,
453 arbitrary_rectf1,
454 arbitrary_resourceid1,
455 arbitrary_resourceid2,
456 arbitrary_resourceid3,
457 arbitrary_resourceid4,
458 arbitrary_color_space);
459 scoped_ptr<DrawQuad> yuvvideo_cmp = yuvvideo_in->Copy(
460 yuvvideo_in->shared_quad_state);
462 pass_in->quad_list.push_back(checkerboard_in.PassAs<DrawQuad>());
463 pass_in->quad_list.push_back(debugborder_in.PassAs<DrawQuad>());
464 pass_in->quad_list.push_back(iosurface_in.PassAs<DrawQuad>());
465 pass_in->quad_list.push_back(renderpass_in.PassAs<DrawQuad>());
466 pass_in->quad_list.push_back(solidcolor_in.PassAs<DrawQuad>());
467 pass_in->quad_list.push_back(streamvideo_in.PassAs<DrawQuad>());
468 pass_in->quad_list.push_back(surface_in.PassAs<DrawQuad>());
469 pass_in->quad_list.push_back(texture_in.PassAs<DrawQuad>());
470 pass_in->quad_list.push_back(tile_in.PassAs<DrawQuad>());
471 pass_in->quad_list.push_back(yuvvideo_in.PassAs<DrawQuad>());
474 pass_cmp->quad_list.push_back(checkerboard_cmp.PassAs<DrawQuad>());
475 pass_cmp->quad_list.push_back(debugborder_cmp.PassAs<DrawQuad>());
476 pass_cmp->quad_list.push_back(iosurface_cmp.PassAs<DrawQuad>());
477 pass_cmp->quad_list.push_back(renderpass_cmp.PassAs<DrawQuad>());
478 pass_cmp->quad_list.push_back(solidcolor_cmp.PassAs<DrawQuad>());
479 pass_cmp->quad_list.push_back(streamvideo_cmp.PassAs<DrawQuad>());
480 pass_cmp->quad_list.push_back(surface_cmp.PassAs<DrawQuad>());
481 pass_cmp->quad_list.push_back(texture_cmp.PassAs<DrawQuad>());
482 pass_cmp->quad_list.push_back(tile_cmp.PassAs<DrawQuad>());
483 pass_cmp->quad_list.push_back(yuvvideo_cmp.PassAs<DrawQuad>());
485 // Make sure the in and cmp RenderPasses match.
486 Compare(pass_cmp.get(), pass_in.get());
487 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
488 ASSERT_EQ(10u, pass_in->quad_list.size());
489 for (size_t i = 0; i < 3; ++i) {
490 Compare(pass_cmp->shared_quad_state_list[i],
491 pass_in->shared_quad_state_list[i]);
493 for (size_t i = 0; i < pass_in->quad_list.size(); ++i)
494 Compare(pass_cmp->quad_list[i], pass_in->quad_list[i]);
495 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
496 bool same_shared_quad_state_cmp =
497 pass_cmp->quad_list[i]->shared_quad_state ==
498 pass_cmp->quad_list[i - 1]->shared_quad_state;
499 bool same_shared_quad_state_in =
500 pass_in->quad_list[i]->shared_quad_state ==
501 pass_in->quad_list[i - 1]->shared_quad_state;
502 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
505 DelegatedFrameData frame_in;
506 frame_in.render_pass_list.push_back(pass_in.Pass());
508 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
510 DelegatedFrameData frame_out;
511 PickleIterator iter(msg);
512 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
513 &iter, &frame_out));
515 // Make sure the out and cmp RenderPasses match.
516 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
517 frame_out.render_pass_list.begin());
518 Compare(pass_cmp.get(), pass_out.get());
519 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
520 ASSERT_EQ(10u, pass_out->quad_list.size());
521 for (size_t i = 0; i < 3; ++i) {
522 Compare(pass_cmp->shared_quad_state_list[i],
523 pass_out->shared_quad_state_list[i]);
525 for (size_t i = 0; i < pass_out->quad_list.size(); ++i)
526 Compare(pass_cmp->quad_list[i], pass_out->quad_list[i]);
527 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
528 bool same_shared_quad_state_cmp =
529 pass_cmp->quad_list[i]->shared_quad_state ==
530 pass_cmp->quad_list[i - 1]->shared_quad_state;
531 bool same_shared_quad_state_out =
532 pass_out->quad_list[i]->shared_quad_state ==
533 pass_out->quad_list[i - 1]->shared_quad_state;
534 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
538 TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
539 scoped_ptr<CheckerboardDrawQuad> quad;
541 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
542 pass_in->SetAll(RenderPass::Id(1, 1),
543 gfx::Rect(100, 100),
544 gfx::Rect(),
545 gfx::Transform(),
546 false);
548 // The first SharedQuadState is used.
549 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
550 shared_state1_in->SetAll(gfx::Transform(),
551 gfx::Size(1, 1),
552 gfx::Rect(),
553 gfx::Rect(),
554 false,
555 1.f,
556 SkXfermode::kSrcOver_Mode);
558 quad = CheckerboardDrawQuad::Create();
559 quad->SetAll(shared_state1_in,
560 gfx::Rect(10, 10),
561 gfx::Rect(10, 10),
562 gfx::Rect(10, 10),
563 false,
564 SK_ColorRED);
565 pass_in->quad_list.push_back(quad.PassAs<DrawQuad>());
567 // The second and third SharedQuadStates are not used.
568 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
569 shared_state2_in->SetAll(gfx::Transform(),
570 gfx::Size(2, 2),
571 gfx::Rect(),
572 gfx::Rect(),
573 false,
574 1.f,
575 SkXfermode::kSrcOver_Mode);
577 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
578 shared_state3_in->SetAll(gfx::Transform(),
579 gfx::Size(3, 3),
580 gfx::Rect(),
581 gfx::Rect(),
582 false,
583 1.f,
584 SkXfermode::kSrcOver_Mode);
586 // The fourth SharedQuadState is used.
587 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
588 shared_state4_in->SetAll(gfx::Transform(),
589 gfx::Size(4, 4),
590 gfx::Rect(),
591 gfx::Rect(),
592 false,
593 1.f,
594 SkXfermode::kSrcOver_Mode);
596 quad = CheckerboardDrawQuad::Create();
597 quad->SetAll(shared_state4_in,
598 gfx::Rect(10, 10),
599 gfx::Rect(10, 10),
600 gfx::Rect(10, 10),
601 false,
602 SK_ColorRED);
603 pass_in->quad_list.push_back(quad.PassAs<DrawQuad>());
605 // The fifth is not used again.
606 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
607 shared_state5_in->SetAll(gfx::Transform(),
608 gfx::Size(5, 5),
609 gfx::Rect(),
610 gfx::Rect(),
611 false,
612 1.f,
613 SkXfermode::kSrcOver_Mode);
615 // 5 SharedQuadStates go in.
616 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
617 ASSERT_EQ(2u, pass_in->quad_list.size());
619 DelegatedFrameData frame_in;
620 frame_in.render_pass_list.push_back(pass_in.Pass());
622 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
623 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
625 DelegatedFrameData frame_out;
626 PickleIterator iter(msg);
627 EXPECT_TRUE(
628 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
630 scoped_ptr<RenderPass> pass_out =
631 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
633 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
634 // used by quads, and so serialized. Others were not.
635 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
636 ASSERT_EQ(2u, pass_out->quad_list.size());
638 EXPECT_EQ(gfx::Size(1, 1).ToString(),
639 pass_out->shared_quad_state_list[0]->content_bounds.ToString());
640 EXPECT_EQ(gfx::Size(4, 4).ToString(),
641 pass_out->shared_quad_state_list[1]->content_bounds.ToString());
644 TEST_F(CCMessagesTest, Resources) {
645 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
646 gfx::Size arbitrary_size(757, 1281);
647 unsigned int arbitrary_uint1 = 71234838;
648 unsigned int arbitrary_uint2 = 53589793;
650 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
651 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
652 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
653 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
655 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
656 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
657 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
658 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
660 TransferableResource arbitrary_resource1;
661 arbitrary_resource1.id = 2178312;
662 arbitrary_resource1.format = cc::RGBA_8888;
663 arbitrary_resource1.filter = 53;
664 arbitrary_resource1.size = gfx::Size(37189, 123123);
665 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
666 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
667 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
669 TransferableResource arbitrary_resource2;
670 arbitrary_resource2.id = 789132;
671 arbitrary_resource2.format = cc::RGBA_4444;
672 arbitrary_resource2.filter = 47;
673 arbitrary_resource2.size = gfx::Size(89123, 23789);
674 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
675 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
676 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
678 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
679 renderpass_in->SetNew(
680 RenderPass::Id(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
682 DelegatedFrameData frame_in;
683 frame_in.resource_list.push_back(arbitrary_resource1);
684 frame_in.resource_list.push_back(arbitrary_resource2);
685 frame_in.render_pass_list.push_back(renderpass_in.Pass());
687 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
689 DelegatedFrameData frame_out;
690 PickleIterator iter(msg);
691 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
692 &iter, &frame_out));
694 ASSERT_EQ(2u, frame_out.resource_list.size());
695 Compare(arbitrary_resource1, frame_out.resource_list[0]);
696 Compare(arbitrary_resource2, frame_out.resource_list[1]);
699 TEST_F(CCMessagesTest, LargestQuadType) {
700 size_t largest = 0;
702 bool done = false;
703 for (int i = 0; !done; ++i) {
704 switch (static_cast<DrawQuad::Material>(i)) {
705 case cc::DrawQuad::CHECKERBOARD:
706 largest = std::max(largest, sizeof(cc::CheckerboardDrawQuad));
707 break;
708 case cc::DrawQuad::DEBUG_BORDER:
709 largest = std::max(largest, sizeof(cc::DebugBorderDrawQuad));
710 break;
711 case cc::DrawQuad::IO_SURFACE_CONTENT:
712 largest = std::max(largest, sizeof(cc::IOSurfaceDrawQuad));
713 break;
714 case cc::DrawQuad::PICTURE_CONTENT:
715 largest = std::max(largest, sizeof(cc::PictureDrawQuad));
716 break;
717 case cc::DrawQuad::TEXTURE_CONTENT:
718 largest = std::max(largest, sizeof(cc::TextureDrawQuad));
719 break;
720 case cc::DrawQuad::RENDER_PASS:
721 largest = std::max(largest, sizeof(cc::RenderPassDrawQuad));
722 break;
723 case cc::DrawQuad::SOLID_COLOR:
724 largest = std::max(largest, sizeof(cc::SolidColorDrawQuad));
725 break;
726 case cc::DrawQuad::SURFACE_CONTENT:
727 largest = std::max(largest, sizeof(cc::SurfaceDrawQuad));
728 break;
729 case cc::DrawQuad::TILED_CONTENT:
730 largest = std::max(largest, sizeof(cc::TileDrawQuad));
731 break;
732 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
733 largest = std::max(largest, sizeof(cc::StreamVideoDrawQuad));
734 break;
735 case cc::DrawQuad::YUV_VIDEO_CONTENT:
736 largest = std::max(largest, sizeof(cc::YUVVideoDrawQuad));
737 break;
738 case cc::DrawQuad::INVALID:
739 break;
740 default:
741 done = true;
745 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever
746 // changes, then the ReserveSizeForRenderPassWrite() method needs to be
747 // updated as well to use the new largest quad.
748 EXPECT_EQ(sizeof(RenderPassDrawQuad), largest);
751 TEST_F(CCMessagesTest, SoftwareFrameData) {
752 cc::SoftwareFrameData frame_in;
753 frame_in.id = 3;
754 frame_in.size = gfx::Size(40, 20);
755 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
756 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
758 // Write the frame.
759 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
760 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
762 // Read the frame.
763 cc::SoftwareFrameData frame_out;
764 PickleIterator iter(msg);
765 EXPECT_TRUE(
766 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
767 EXPECT_EQ(frame_in.id, frame_out.id);
768 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
769 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
770 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
773 TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
774 SoftwareFrameData frame_in;
775 frame_in.id = 3;
776 frame_in.size = gfx::Size(40, 20);
777 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
778 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
780 // Write the SoftwareFrameData by hand, make sure it works.
782 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
783 IPC::WriteParam(&msg, frame_in.id);
784 IPC::WriteParam(&msg, frame_in.size);
785 IPC::WriteParam(&msg, frame_in.damage_rect);
786 IPC::WriteParam(&msg, frame_in.bitmap_id);
787 SoftwareFrameData frame_out;
788 PickleIterator iter(msg);
789 EXPECT_TRUE(
790 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
793 // The size of the frame may overflow when multiplied together.
794 int max = std::numeric_limits<int>::max();
795 frame_in.size = gfx::Size(max, max);
797 // If size_t is larger than int, then int*int*4 can always fit in size_t.
798 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
800 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
801 // should fail.
803 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
804 IPC::WriteParam(&msg, frame_in.id);
805 IPC::WriteParam(&msg, frame_in.size);
806 IPC::WriteParam(&msg, frame_in.damage_rect);
807 IPC::WriteParam(&msg, frame_in.bitmap_id);
808 SoftwareFrameData frame_out;
809 PickleIterator iter(msg);
810 EXPECT_EQ(
811 expect_read,
812 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
816 } // namespace
817 } // namespace content