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