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. 4 5 #include "content/common/cc_messages.h" 6 7 #include <string.h> 8 9 #include <algorithm> 10 11 #include "cc/output/compositor_frame.h" 12 #include "ipc/ipc_message.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "third_party/khronos/GLES2/gl2ext.h" 15 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 16 17 using cc::CheckerboardDrawQuad; 18 using cc::DelegatedFrameData; 19 using cc::DebugBorderDrawQuad; 20 using cc::DrawQuad; 21 using cc::FilterOperation; 22 using cc::FilterOperations; 23 using cc::IOSurfaceDrawQuad; 24 using cc::PictureDrawQuad; 25 using cc::RenderPass; 26 using cc::RenderPassDrawQuad; 27 using cc::ResourceProvider; 28 using cc::SharedQuadState; 29 using cc::SolidColorDrawQuad; 30 using cc::TextureDrawQuad; 31 using cc::TileDrawQuad; 32 using cc::TransferableResource; 33 using cc::StreamVideoDrawQuad; 34 using cc::VideoLayerImpl; 35 using cc::YUVVideoDrawQuad; 36 using gfx::Transform; 37 38 namespace content { 39 namespace { 40 41 class CCMessagesTest : public testing::Test { 42 protected: 43 void Compare(const RenderPass* a, const RenderPass* b) { 44 EXPECT_EQ(a->id, b->id); 45 EXPECT_EQ(a->output_rect.ToString(), b->output_rect.ToString()); 46 EXPECT_EQ(a->damage_rect.ToString(), b->damage_rect.ToString()); 47 EXPECT_EQ(a->transform_to_root_target, b->transform_to_root_target); 48 EXPECT_EQ(a->has_transparent_background, b->has_transparent_background); 49 } 50 51 void Compare(const SharedQuadState* a, const SharedQuadState* b) { 52 EXPECT_EQ(a->content_to_target_transform, b->content_to_target_transform); 53 EXPECT_EQ(a->content_bounds, b->content_bounds); 54 EXPECT_EQ(a->visible_content_rect, b->visible_content_rect); 55 EXPECT_EQ(a->clip_rect, b->clip_rect); 56 EXPECT_EQ(a->is_clipped, b->is_clipped); 57 EXPECT_EQ(a->opacity, b->opacity); 58 EXPECT_EQ(a->blend_mode, b->blend_mode); 59 } 60 61 void Compare(const DrawQuad* a, const DrawQuad* b) { 62 ASSERT_NE(DrawQuad::INVALID, a->material); 63 ASSERT_EQ(a->material, b->material); 64 EXPECT_EQ(a->rect.ToString(), b->rect.ToString()); 65 EXPECT_EQ(a->opaque_rect.ToString(), b->opaque_rect.ToString()); 66 EXPECT_EQ(a->visible_rect.ToString(), b->visible_rect.ToString()); 67 EXPECT_EQ(a->needs_blending, b->needs_blending); 68 69 Compare(a->shared_quad_state, b->shared_quad_state); 70 71 switch (a->material) { 72 case DrawQuad::CHECKERBOARD: 73 Compare(CheckerboardDrawQuad::MaterialCast(a), 74 CheckerboardDrawQuad::MaterialCast(b)); 75 break; 76 case DrawQuad::DEBUG_BORDER: 77 Compare(DebugBorderDrawQuad::MaterialCast(a), 78 DebugBorderDrawQuad::MaterialCast(b)); 79 break; 80 case DrawQuad::IO_SURFACE_CONTENT: 81 Compare(IOSurfaceDrawQuad::MaterialCast(a), 82 IOSurfaceDrawQuad::MaterialCast(b)); 83 break; 84 case DrawQuad::PICTURE_CONTENT: 85 Compare(PictureDrawQuad::MaterialCast(a), 86 PictureDrawQuad::MaterialCast(b)); 87 break; 88 case DrawQuad::RENDER_PASS: 89 Compare(RenderPassDrawQuad::MaterialCast(a), 90 RenderPassDrawQuad::MaterialCast(b)); 91 break; 92 case DrawQuad::TEXTURE_CONTENT: 93 Compare(TextureDrawQuad::MaterialCast(a), 94 TextureDrawQuad::MaterialCast(b)); 95 break; 96 case DrawQuad::TILED_CONTENT: 97 Compare(TileDrawQuad::MaterialCast(a), 98 TileDrawQuad::MaterialCast(b)); 99 break; 100 case DrawQuad::SOLID_COLOR: 101 Compare(SolidColorDrawQuad::MaterialCast(a), 102 SolidColorDrawQuad::MaterialCast(b)); 103 break; 104 case DrawQuad::STREAM_VIDEO_CONTENT: 105 Compare(StreamVideoDrawQuad::MaterialCast(a), 106 StreamVideoDrawQuad::MaterialCast(b)); 107 break; 108 case DrawQuad::YUV_VIDEO_CONTENT: 109 Compare(YUVVideoDrawQuad::MaterialCast(a), 110 YUVVideoDrawQuad::MaterialCast(b)); 111 break; 112 case DrawQuad::INVALID: 113 break; 114 } 115 } 116 117 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) { 118 EXPECT_EQ(a->color, b->color); 119 } 120 121 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) { 122 EXPECT_EQ(a->color, b->color); 123 EXPECT_EQ(a->width, b->width); 124 } 125 126 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) { 127 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString()); 128 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id); 129 EXPECT_EQ(a->orientation, b->orientation); 130 } 131 132 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) { 133 EXPECT_EQ(a->render_pass_id, b->render_pass_id); 134 EXPECT_EQ(a->is_replica, b->is_replica); 135 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id); 136 EXPECT_EQ(a->contents_changed_since_last_frame, 137 b->contents_changed_since_last_frame); 138 EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.ToString()); 139 EXPECT_EQ(a->filters.size(), b->filters.size()); 140 for (size_t i = 0; i < a->filters.size(); ++i) { 141 if (a->filters.at(i).type() != cc::FilterOperation::REFERENCE) { 142 EXPECT_EQ(a->filters.at(i), b->filters.at(i)); 143 } else { 144 EXPECT_EQ(b->filters.at(i).type(), cc::FilterOperation::REFERENCE); 145 EXPECT_EQ(a->filters.at(i).image_filter()->countInputs(), 146 b->filters.at(i).image_filter()->countInputs()); 147 } 148 } 149 EXPECT_EQ(a->background_filters, b->background_filters); 150 } 151 152 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) { 153 EXPECT_EQ(a->color, b->color); 154 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off); 155 } 156 157 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) { 158 EXPECT_EQ(a->resource_id, b->resource_id); 159 EXPECT_EQ(a->matrix, b->matrix); 160 } 161 162 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) { 163 EXPECT_EQ(a->resource_id, b->resource_id); 164 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha); 165 EXPECT_EQ(a->uv_top_left, b->uv_top_left); 166 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right); 167 EXPECT_EQ(a->background_color, b->background_color); 168 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]); 169 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]); 170 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]); 171 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]); 172 EXPECT_EQ(a->flipped, b->flipped); 173 } 174 175 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) { 176 EXPECT_EQ(a->resource_id, b->resource_id); 177 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect); 178 EXPECT_EQ(a->texture_size, b->texture_size); 179 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents); 180 } 181 182 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) { 183 EXPECT_EQ(a->tex_scale, b->tex_scale); 184 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id); 185 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id); 186 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id); 187 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id); 188 } 189 190 void Compare(const TransferableResource& a, const TransferableResource& b) { 191 EXPECT_EQ(a.id, b.id); 192 EXPECT_EQ(a.sync_point, b.sync_point); 193 EXPECT_EQ(a.format, b.format); 194 EXPECT_EQ(a.target, b.target); 195 EXPECT_EQ(a.filter, b.filter); 196 EXPECT_EQ(a.size.ToString(), b.size.ToString()); 197 for (size_t i = 0; i < arraysize(a.mailbox.name); ++i) 198 EXPECT_EQ(a.mailbox.name[i], b.mailbox.name[i]); 199 } 200 }; 201 202 TEST_F(CCMessagesTest, AllQuads) { 203 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 204 205 Transform arbitrary_matrix; 206 arbitrary_matrix.Scale(3, 3); 207 arbitrary_matrix.Translate(-5, 20); 208 arbitrary_matrix.Rotate(15); 209 gfx::Rect arbitrary_rect1(-5, 9, 3, 15); 210 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8); 211 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2); 212 gfx::Rect arbitrary_rect2(40, 23, 11, 7); 213 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2); 214 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5); 215 gfx::Rect arbitrary_rect3(7, -53, 22, 19); 216 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3); 217 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12); 218 gfx::Size arbitrary_size1(15, 19); 219 gfx::Size arbitrary_size2(3, 99); 220 gfx::Size arbitrary_size3(75, 1281); 221 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f); 222 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f); 223 gfx::PointF arbitrary_pointf1(31.4f, 15.9f); 224 gfx::PointF arbitrary_pointf2(26.5f, -35.8f); 225 float arbitrary_float1 = 0.7f; 226 float arbitrary_float2 = 0.3f; 227 float arbitrary_float3 = 0.9f; 228 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f}; 229 bool arbitrary_bool1 = true; 230 bool arbitrary_bool2 = false; 231 bool arbitrary_bool3 = true; 232 int arbitrary_int = 5; 233 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58); 234 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode; 235 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode; 236 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode; 237 IOSurfaceDrawQuad::Orientation arbitrary_orientation = 238 IOSurfaceDrawQuad::UNFLIPPED; 239 RenderPass::Id arbitrary_id(10, 14); 240 ResourceProvider::ResourceId arbitrary_resourceid1 = 55; 241 ResourceProvider::ResourceId arbitrary_resourceid2 = 47; 242 ResourceProvider::ResourceId arbitrary_resourceid3 = 23; 243 ResourceProvider::ResourceId arbitrary_resourceid4 = 16; 244 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f); 245 246 FilterOperations arbitrary_filters1; 247 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter( 248 arbitrary_float1)); 249 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef( 250 new SkBlurImageFilter(arbitrary_sigma, arbitrary_sigma)); 251 arbitrary_filters1.Append( 252 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter)); 253 254 FilterOperations arbitrary_filters2; 255 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter( 256 arbitrary_float2)); 257 258 scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create(); 259 shared_state1_in->SetAll(arbitrary_matrix, 260 arbitrary_size1, 261 arbitrary_rect1, 262 arbitrary_rect2, 263 arbitrary_bool1, 264 arbitrary_float1, 265 arbitrary_blend_mode1); 266 scoped_ptr<SharedQuadState> shared_state1_cmp = shared_state1_in->Copy(); 267 268 scoped_ptr<CheckerboardDrawQuad> checkerboard_in = 269 CheckerboardDrawQuad::Create(); 270 checkerboard_in->SetAll(shared_state1_in.get(), 271 arbitrary_rect1, 272 arbitrary_rect2_inside_rect1, 273 arbitrary_rect1_inside_rect1, 274 arbitrary_bool1, 275 arbitrary_color); 276 scoped_ptr<DrawQuad> checkerboard_cmp = checkerboard_in->Copy( 277 checkerboard_in->shared_quad_state); 278 279 scoped_ptr<DebugBorderDrawQuad> debugborder_in = 280 DebugBorderDrawQuad::Create(); 281 debugborder_in->SetAll(shared_state1_in.get(), 282 arbitrary_rect3, 283 arbitrary_rect1_inside_rect3, 284 arbitrary_rect2_inside_rect3, 285 arbitrary_bool1, 286 arbitrary_color, 287 arbitrary_int); 288 scoped_ptr<DrawQuad> debugborder_cmp = debugborder_in->Copy( 289 debugborder_in->shared_quad_state); 290 291 scoped_ptr<IOSurfaceDrawQuad> iosurface_in = 292 IOSurfaceDrawQuad::Create(); 293 iosurface_in->SetAll(shared_state1_in.get(), 294 arbitrary_rect2, 295 arbitrary_rect2_inside_rect2, 296 arbitrary_rect1_inside_rect2, 297 arbitrary_bool1, 298 arbitrary_size1, 299 arbitrary_resourceid3, 300 arbitrary_orientation); 301 scoped_ptr<DrawQuad> iosurface_cmp = iosurface_in->Copy( 302 iosurface_in->shared_quad_state); 303 304 scoped_ptr<SharedQuadState> shared_state2_in = SharedQuadState::Create(); 305 shared_state2_in->SetAll(arbitrary_matrix, 306 arbitrary_size2, 307 arbitrary_rect2, 308 arbitrary_rect3, 309 arbitrary_bool1, 310 arbitrary_float2, 311 arbitrary_blend_mode2); 312 scoped_ptr<SharedQuadState> shared_state2_cmp = shared_state2_in->Copy(); 313 314 scoped_ptr<RenderPassDrawQuad> renderpass_in = 315 RenderPassDrawQuad::Create(); 316 renderpass_in->SetAll(shared_state2_in.get(), 317 arbitrary_rect1, 318 arbitrary_rect2_inside_rect1, 319 arbitrary_rect1_inside_rect1, 320 arbitrary_bool1, 321 arbitrary_id, 322 arbitrary_bool2, 323 arbitrary_resourceid2, 324 arbitrary_rect1, 325 arbitrary_rectf1, 326 arbitrary_filters1, 327 arbitrary_filters2); 328 scoped_ptr<RenderPassDrawQuad> renderpass_cmp = renderpass_in->Copy( 329 renderpass_in->shared_quad_state, renderpass_in->render_pass_id); 330 331 scoped_ptr<SharedQuadState> shared_state3_in = SharedQuadState::Create(); 332 shared_state3_in->SetAll(arbitrary_matrix, 333 arbitrary_size3, 334 arbitrary_rect3, 335 arbitrary_rect1, 336 arbitrary_bool1, 337 arbitrary_float3, 338 arbitrary_blend_mode3); 339 scoped_ptr<SharedQuadState> shared_state3_cmp = shared_state3_in->Copy(); 340 341 scoped_ptr<SolidColorDrawQuad> solidcolor_in = 342 SolidColorDrawQuad::Create(); 343 solidcolor_in->SetAll(shared_state3_in.get(), 344 arbitrary_rect3, 345 arbitrary_rect1_inside_rect3, 346 arbitrary_rect2_inside_rect3, 347 arbitrary_bool1, 348 arbitrary_color, 349 arbitrary_bool2); 350 scoped_ptr<DrawQuad> solidcolor_cmp = solidcolor_in->Copy( 351 solidcolor_in->shared_quad_state); 352 353 scoped_ptr<StreamVideoDrawQuad> streamvideo_in = 354 StreamVideoDrawQuad::Create(); 355 streamvideo_in->SetAll(shared_state3_in.get(), 356 arbitrary_rect2, 357 arbitrary_rect2_inside_rect2, 358 arbitrary_rect1_inside_rect2, 359 arbitrary_bool1, 360 arbitrary_resourceid2, 361 arbitrary_matrix); 362 scoped_ptr<DrawQuad> streamvideo_cmp = streamvideo_in->Copy( 363 streamvideo_in->shared_quad_state); 364 365 scoped_ptr<TextureDrawQuad> texture_in = TextureDrawQuad::Create(); 366 texture_in->SetAll(shared_state3_in.get(), 367 arbitrary_rect2, 368 arbitrary_rect2_inside_rect2, 369 arbitrary_rect1_inside_rect2, 370 arbitrary_bool1, 371 arbitrary_resourceid1, 372 arbitrary_bool2, 373 arbitrary_pointf1, 374 arbitrary_pointf2, 375 arbitrary_color, 376 arbitrary_float_array, 377 arbitrary_bool3); 378 scoped_ptr<DrawQuad> texture_cmp = texture_in->Copy( 379 texture_in->shared_quad_state); 380 381 scoped_ptr<TileDrawQuad> tile_in = TileDrawQuad::Create(); 382 tile_in->SetAll(shared_state3_in.get(), 383 arbitrary_rect2, 384 arbitrary_rect2_inside_rect2, 385 arbitrary_rect1_inside_rect2, 386 arbitrary_bool1, 387 arbitrary_resourceid3, 388 arbitrary_rectf1, 389 arbitrary_size1, 390 arbitrary_bool2); 391 scoped_ptr<DrawQuad> tile_cmp = tile_in->Copy( 392 tile_in->shared_quad_state); 393 394 scoped_ptr<YUVVideoDrawQuad> yuvvideo_in = 395 YUVVideoDrawQuad::Create(); 396 yuvvideo_in->SetAll(shared_state3_in.get(), 397 arbitrary_rect1, 398 arbitrary_rect2_inside_rect1, 399 arbitrary_rect1_inside_rect1, 400 arbitrary_bool1, 401 arbitrary_sizef1, 402 arbitrary_resourceid1, 403 arbitrary_resourceid2, 404 arbitrary_resourceid3, 405 arbitrary_resourceid4); 406 scoped_ptr<DrawQuad> yuvvideo_cmp = yuvvideo_in->Copy( 407 yuvvideo_in->shared_quad_state); 408 409 scoped_ptr<RenderPass> pass_in = RenderPass::Create(); 410 pass_in->SetAll(arbitrary_id, 411 arbitrary_rect1, 412 arbitrary_rectf1, 413 arbitrary_matrix, 414 arbitrary_bool1); 415 416 pass_in->shared_quad_state_list.push_back(shared_state1_in.Pass()); 417 pass_in->quad_list.push_back(checkerboard_in.PassAs<DrawQuad>()); 418 pass_in->quad_list.push_back(debugborder_in.PassAs<DrawQuad>()); 419 pass_in->quad_list.push_back(iosurface_in.PassAs<DrawQuad>()); 420 pass_in->quad_list.push_back(renderpass_in.PassAs<DrawQuad>()); 421 pass_in->shared_quad_state_list.push_back(shared_state2_in.Pass()); 422 pass_in->shared_quad_state_list.push_back(shared_state3_in.Pass()); 423 pass_in->quad_list.push_back(solidcolor_in.PassAs<DrawQuad>()); 424 pass_in->quad_list.push_back(streamvideo_in.PassAs<DrawQuad>()); 425 pass_in->quad_list.push_back(texture_in.PassAs<DrawQuad>()); 426 pass_in->quad_list.push_back(tile_in.PassAs<DrawQuad>()); 427 pass_in->quad_list.push_back(yuvvideo_in.PassAs<DrawQuad>()); 428 429 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create(); 430 pass_cmp->SetAll(arbitrary_id, 431 arbitrary_rect1, 432 arbitrary_rectf1, 433 arbitrary_matrix, 434 arbitrary_bool1); 435 436 pass_cmp->shared_quad_state_list.push_back(shared_state1_cmp.Pass()); 437 pass_cmp->quad_list.push_back(checkerboard_cmp.PassAs<DrawQuad>()); 438 pass_cmp->quad_list.push_back(debugborder_cmp.PassAs<DrawQuad>()); 439 pass_cmp->quad_list.push_back(iosurface_cmp.PassAs<DrawQuad>()); 440 pass_cmp->quad_list.push_back(renderpass_cmp.PassAs<DrawQuad>()); 441 pass_cmp->shared_quad_state_list.push_back(shared_state2_cmp.Pass()); 442 pass_cmp->shared_quad_state_list.push_back(shared_state3_cmp.Pass()); 443 pass_cmp->quad_list.push_back(solidcolor_cmp.PassAs<DrawQuad>()); 444 pass_cmp->quad_list.push_back(streamvideo_cmp.PassAs<DrawQuad>()); 445 pass_cmp->quad_list.push_back(texture_cmp.PassAs<DrawQuad>()); 446 pass_cmp->quad_list.push_back(tile_cmp.PassAs<DrawQuad>()); 447 pass_cmp->quad_list.push_back(yuvvideo_cmp.PassAs<DrawQuad>()); 448 449 // Make sure the in and cmp RenderPasses match. 450 Compare(pass_cmp.get(), pass_in.get()); 451 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size()); 452 ASSERT_EQ(9u, pass_in->quad_list.size()); 453 for (size_t i = 0; i < 3; ++i) { 454 Compare(pass_cmp->shared_quad_state_list[i], 455 pass_in->shared_quad_state_list[i]); 456 } 457 for (size_t i = 0; i < pass_in->quad_list.size(); ++i) 458 Compare(pass_cmp->quad_list[i], pass_in->quad_list[i]); 459 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) { 460 bool same_shared_quad_state_cmp = 461 pass_cmp->quad_list[i]->shared_quad_state == 462 pass_cmp->quad_list[i - 1]->shared_quad_state; 463 bool same_shared_quad_state_in = 464 pass_in->quad_list[i]->shared_quad_state == 465 pass_in->quad_list[i - 1]->shared_quad_state; 466 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in); 467 } 468 469 DelegatedFrameData frame_in; 470 frame_in.render_pass_list.push_back(pass_in.Pass()); 471 472 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in); 473 474 DelegatedFrameData frame_out; 475 PickleIterator iter(msg); 476 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg, 477 &iter, &frame_out)); 478 479 // Make sure the out and cmp RenderPasses match. 480 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take( 481 frame_out.render_pass_list.begin()); 482 Compare(pass_cmp.get(), pass_out.get()); 483 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size()); 484 ASSERT_EQ(9u, pass_out->quad_list.size()); 485 for (size_t i = 0; i < 3; ++i) { 486 Compare(pass_cmp->shared_quad_state_list[i], 487 pass_out->shared_quad_state_list[i]); 488 } 489 for (size_t i = 0; i < pass_out->quad_list.size(); ++i) 490 Compare(pass_cmp->quad_list[i], pass_out->quad_list[i]); 491 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) { 492 bool same_shared_quad_state_cmp = 493 pass_cmp->quad_list[i]->shared_quad_state == 494 pass_cmp->quad_list[i - 1]->shared_quad_state; 495 bool same_shared_quad_state_out = 496 pass_out->quad_list[i]->shared_quad_state == 497 pass_out->quad_list[i - 1]->shared_quad_state; 498 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out); 499 } 500 } 501 502 TEST_F(CCMessagesTest, UnusedSharedQuadStates) { 503 scoped_ptr<CheckerboardDrawQuad> quad; 504 505 scoped_ptr<RenderPass> pass_in = RenderPass::Create(); 506 pass_in->SetAll(RenderPass::Id(1, 1), 507 gfx::Rect(100, 100), 508 gfx::RectF(), 509 gfx::Transform(), 510 false); 511 512 // The first SharedQuadState is used. 513 scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create(); 514 shared_state1_in->SetAll(gfx::Transform(), 515 gfx::Size(1, 1), 516 gfx::Rect(), 517 gfx::Rect(), 518 false, 519 1.f, 520 SkXfermode::kSrcOver_Mode); 521 522 quad = CheckerboardDrawQuad::Create(); 523 quad->SetAll(shared_state1_in.get(), 524 gfx::Rect(10, 10), 525 gfx::Rect(10, 10), 526 gfx::Rect(10, 10), 527 false, 528 SK_ColorRED); 529 pass_in->quad_list.push_back(quad.PassAs<DrawQuad>()); 530 531 // The second and third SharedQuadStates are not used. 532 scoped_ptr<SharedQuadState> shared_state2_in = SharedQuadState::Create(); 533 shared_state2_in->SetAll(gfx::Transform(), 534 gfx::Size(2, 2), 535 gfx::Rect(), 536 gfx::Rect(), 537 false, 538 1.f, 539 SkXfermode::kSrcOver_Mode); 540 541 scoped_ptr<SharedQuadState> shared_state3_in = SharedQuadState::Create(); 542 shared_state3_in->SetAll(gfx::Transform(), 543 gfx::Size(3, 3), 544 gfx::Rect(), 545 gfx::Rect(), 546 false, 547 1.f, 548 SkXfermode::kSrcOver_Mode); 549 550 // The fourth SharedQuadState is used. 551 scoped_ptr<SharedQuadState> shared_state4_in = SharedQuadState::Create(); 552 shared_state4_in->SetAll(gfx::Transform(), 553 gfx::Size(4, 4), 554 gfx::Rect(), 555 gfx::Rect(), 556 false, 557 1.f, 558 SkXfermode::kSrcOver_Mode); 559 560 quad = CheckerboardDrawQuad::Create(); 561 quad->SetAll(shared_state4_in.get(), 562 gfx::Rect(10, 10), 563 gfx::Rect(10, 10), 564 gfx::Rect(10, 10), 565 false, 566 SK_ColorRED); 567 pass_in->quad_list.push_back(quad.PassAs<DrawQuad>()); 568 569 // The fifth is not used again. 570 scoped_ptr<SharedQuadState> shared_state5_in = SharedQuadState::Create(); 571 shared_state5_in->SetAll(gfx::Transform(), 572 gfx::Size(5, 5), 573 gfx::Rect(), 574 gfx::Rect(), 575 false, 576 1.f, 577 SkXfermode::kSrcOver_Mode); 578 579 pass_in->shared_quad_state_list.push_back(shared_state1_in.Pass()); 580 pass_in->shared_quad_state_list.push_back(shared_state2_in.Pass()); 581 pass_in->shared_quad_state_list.push_back(shared_state3_in.Pass()); 582 pass_in->shared_quad_state_list.push_back(shared_state4_in.Pass()); 583 pass_in->shared_quad_state_list.push_back(shared_state5_in.Pass()); 584 585 // 5 SharedQuadStates go in. 586 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size()); 587 ASSERT_EQ(2u, pass_in->quad_list.size()); 588 589 DelegatedFrameData frame_in; 590 frame_in.render_pass_list.push_back(pass_in.Pass()); 591 592 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 593 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in); 594 595 DelegatedFrameData frame_out; 596 PickleIterator iter(msg); 597 EXPECT_TRUE( 598 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out)); 599 600 scoped_ptr<RenderPass> pass_out = 601 frame_out.render_pass_list.take(frame_out.render_pass_list.begin()); 602 603 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were 604 // used by quads, and so serialized. Others were not. 605 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size()); 606 ASSERT_EQ(2u, pass_out->quad_list.size()); 607 608 EXPECT_EQ(gfx::Size(1, 1).ToString(), 609 pass_out->shared_quad_state_list[0]->content_bounds.ToString()); 610 EXPECT_EQ(gfx::Size(4, 4).ToString(), 611 pass_out->shared_quad_state_list[1]->content_bounds.ToString()); 612 } 613 614 TEST_F(CCMessagesTest, Resources) { 615 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 616 gfx::Size arbitrary_size(757, 1281); 617 unsigned int arbitrary_uint1 = 71234838; 618 unsigned int arbitrary_uint2 = 53589793; 619 620 GLbyte arbitrary_mailbox1[64] = { 621 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 622 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 623 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 624 1, 2, 3, 4 625 }; 626 627 GLbyte arbitrary_mailbox2[64] = { 628 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 629 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 630 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 631 0, 9, 8, 7 632 }; 633 634 TransferableResource arbitrary_resource1; 635 arbitrary_resource1.id = 2178312; 636 arbitrary_resource1.sync_point = arbitrary_uint1; 637 arbitrary_resource1.format = cc::RGBA_8888; 638 arbitrary_resource1.target = GL_TEXTURE_2D; 639 arbitrary_resource1.filter = 53; 640 arbitrary_resource1.size = gfx::Size(37189, 123123); 641 arbitrary_resource1.mailbox.SetName(arbitrary_mailbox1); 642 643 TransferableResource arbitrary_resource2; 644 arbitrary_resource2.id = 789132; 645 arbitrary_resource2.sync_point = arbitrary_uint2; 646 arbitrary_resource2.format = cc::RGBA_4444; 647 arbitrary_resource2.target = GL_TEXTURE_EXTERNAL_OES; 648 arbitrary_resource2.filter = 47; 649 arbitrary_resource2.size = gfx::Size(89123, 23789); 650 arbitrary_resource2.mailbox.SetName(arbitrary_mailbox2); 651 652 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create(); 653 renderpass_in->SetNew( 654 RenderPass::Id(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform()); 655 656 DelegatedFrameData frame_in; 657 frame_in.resource_list.push_back(arbitrary_resource1); 658 frame_in.resource_list.push_back(arbitrary_resource2); 659 frame_in.render_pass_list.push_back(renderpass_in.Pass()); 660 661 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in); 662 663 DelegatedFrameData frame_out; 664 PickleIterator iter(msg); 665 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg, 666 &iter, &frame_out)); 667 668 ASSERT_EQ(2u, frame_out.resource_list.size()); 669 Compare(arbitrary_resource1, frame_out.resource_list[0]); 670 Compare(arbitrary_resource2, frame_out.resource_list[1]); 671 } 672 673 TEST_F(CCMessagesTest, LargestQuadType) { 674 size_t largest = 0; 675 676 bool done = false; 677 for (int i = 0; !done; ++i) { 678 switch (static_cast<DrawQuad::Material>(i)) { 679 case cc::DrawQuad::CHECKERBOARD: 680 largest = std::max(largest, sizeof(cc::CheckerboardDrawQuad)); 681 break; 682 case cc::DrawQuad::DEBUG_BORDER: 683 largest = std::max(largest, sizeof(cc::DebugBorderDrawQuad)); 684 break; 685 case cc::DrawQuad::IO_SURFACE_CONTENT: 686 largest = std::max(largest, sizeof(cc::IOSurfaceDrawQuad)); 687 break; 688 case cc::DrawQuad::PICTURE_CONTENT: 689 largest = std::max(largest, sizeof(cc::PictureDrawQuad)); 690 break; 691 case cc::DrawQuad::TEXTURE_CONTENT: 692 largest = std::max(largest, sizeof(cc::TextureDrawQuad)); 693 break; 694 case cc::DrawQuad::RENDER_PASS: 695 largest = std::max(largest, sizeof(cc::RenderPassDrawQuad)); 696 break; 697 case cc::DrawQuad::SOLID_COLOR: 698 largest = std::max(largest, sizeof(cc::SolidColorDrawQuad)); 699 break; 700 case cc::DrawQuad::TILED_CONTENT: 701 largest = std::max(largest, sizeof(cc::TileDrawQuad)); 702 break; 703 case cc::DrawQuad::STREAM_VIDEO_CONTENT: 704 largest = std::max(largest, sizeof(cc::StreamVideoDrawQuad)); 705 break; 706 case cc::DrawQuad::YUV_VIDEO_CONTENT: 707 largest = std::max(largest, sizeof(cc::YUVVideoDrawQuad)); 708 break; 709 case cc::DrawQuad::INVALID: 710 break; 711 default: 712 done = true; 713 } 714 } 715 716 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever 717 // changes, then the ReserveSizeForRenderPassWrite() method needs to be 718 // updated as well to use the new largest quad. 719 EXPECT_EQ(sizeof(RenderPassDrawQuad), largest); 720 } 721 722 } // namespace 723 } // namespace content 724