blob: 1e801d5e3f65254ab1d6dea24fba5a4777349ed8 [file] [log] [blame]
[email protected]4934d362012-11-22 22:04:531// 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
[email protected]032bfc42013-10-29 22:23:529#include <algorithm>
10
[email protected]7f0d825f2013-03-18 07:24:3011#include "cc/output/compositor_frame.h"
[email protected]cecc8342014-03-20 21:43:3912#include "content/public/common/common_param_traits.h"
[email protected]4934d362012-11-22 22:04:5313#include "ipc/ipc_message.h"
14#include "testing/gtest/include/gtest/gtest.h"
[email protected]645a47f22013-09-26 05:42:3215#include "third_party/khronos/GLES2/gl2ext.h"
[email protected]a1765672013-08-12 23:45:0216#include "third_party/skia/include/effects/SkBlurImageFilter.h"
[email protected]4934d362012-11-22 22:04:5317
[email protected]cecc8342014-03-20 21:43:3918#if defined(OS_POSIX)
19#include "base/file_descriptor_posix.h"
20#endif
21
[email protected]4934d362012-11-22 22:04:5322using cc::CheckerboardDrawQuad;
[email protected]bf189f62012-12-18 03:42:1123using cc::DelegatedFrameData;
[email protected]4934d362012-11-22 22:04:5324using cc::DebugBorderDrawQuad;
25using cc::DrawQuad;
[email protected]ae6b1a72013-06-25 18:49:2926using cc::FilterOperation;
27using cc::FilterOperations;
[email protected]4934d362012-11-22 22:04:5328using cc::IOSurfaceDrawQuad;
[email protected]9ee4d3a2013-03-27 17:43:1629using cc::PictureDrawQuad;
[email protected]4934d362012-11-22 22:04:5330using cc::RenderPass;
31using cc::RenderPassDrawQuad;
32using cc::ResourceProvider;
33using cc::SharedQuadState;
[email protected]cecc8342014-03-20 21:43:3934using cc::SoftwareFrameData;
[email protected]4934d362012-11-22 22:04:5335using cc::SolidColorDrawQuad;
[email protected]78d30122014-01-17 06:32:3636using cc::SurfaceDrawQuad;
[email protected]4934d362012-11-22 22:04:5337using cc::TextureDrawQuad;
38using cc::TileDrawQuad;
[email protected]bca159072012-12-04 00:52:4439using cc::TransferableResource;
[email protected]4934d362012-11-22 22:04:5340using cc::StreamVideoDrawQuad;
41using cc::VideoLayerImpl;
42using cc::YUVVideoDrawQuad;
[email protected]c8686a02012-11-27 08:29:0043using gfx::Transform;
[email protected]4934d362012-11-22 22:04:5344
[email protected]bca159072012-12-04 00:52:4445namespace content {
46namespace {
47
[email protected]4934d362012-11-22 22:04:5348class 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);
[email protected]4934d362012-11-22 22:04:5356 }
57
58 void Compare(const SharedQuadState* a, const SharedQuadState* b) {
59 EXPECT_EQ(a->content_to_target_transform, b->content_to_target_transform);
[email protected]f902bf92013-03-04 18:33:2760 EXPECT_EQ(a->content_bounds, b->content_bounds);
[email protected]4934d362012-11-22 22:04:5361 EXPECT_EQ(a->visible_content_rect, b->visible_content_rect);
[email protected]4934d362012-11-22 22:04:5362 EXPECT_EQ(a->clip_rect, b->clip_rect);
63 EXPECT_EQ(a->is_clipped, b->is_clipped);
64 EXPECT_EQ(a->opacity, b->opacity);
[email protected]7bbeaf4e2013-11-26 10:27:2265 EXPECT_EQ(a->blend_mode, b->blend_mode);
[email protected]4934d362012-11-22 22:04:5366 }
67
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);
75
76 Compare(a->shared_quad_state, b->shared_quad_state);
77
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;
[email protected]9ee4d3a2013-03-27 17:43:1691 case DrawQuad::PICTURE_CONTENT:
92 Compare(PictureDrawQuad::MaterialCast(a),
93 PictureDrawQuad::MaterialCast(b));
94 break;
[email protected]4934d362012-11-22 22:04:5395 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;
[email protected]78d30122014-01-17 06:32:36115 case DrawQuad::SURFACE_CONTENT:
116 Compare(SurfaceDrawQuad::MaterialCast(a),
117 SurfaceDrawQuad::MaterialCast(b));
118 break;
[email protected]4934d362012-11-22 22:04:53119 case DrawQuad::YUV_VIDEO_CONTENT:
120 Compare(YUVVideoDrawQuad::MaterialCast(a),
121 YUVVideoDrawQuad::MaterialCast(b));
122 break;
123 case DrawQuad::INVALID:
124 break;
125 }
126 }
127
128 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) {
129 EXPECT_EQ(a->color, b->color);
130 }
131
132 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
133 EXPECT_EQ(a->color, b->color);
134 EXPECT_EQ(a->width, b->width);
135 }
136
137 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
138 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
[email protected]b7cfc632013-04-10 04:44:49139 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
[email protected]4934d362012-11-22 22:04:53140 EXPECT_EQ(a->orientation, b->orientation);
141 }
142
143 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
[email protected]82f93fb2013-04-17 21:42:06144 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
[email protected]4934d362012-11-22 22:04:53145 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);
[email protected]458af1e2012-12-13 05:12:18149 EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.ToString());
[email protected]1dc7943e2013-09-26 04:41:48150 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());
158 }
159 }
[email protected]20062042012-12-21 22:16:36160 EXPECT_EQ(a->background_filters, b->background_filters);
[email protected]4934d362012-11-22 22:04:53161 }
162
163 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
164 EXPECT_EQ(a->color, b->color);
[email protected]10a30b12013-05-02 16:42:11165 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
[email protected]4934d362012-11-22 22:04:53166 }
167
168 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
[email protected]b7cfc632013-04-10 04:44:49169 EXPECT_EQ(a->resource_id, b->resource_id);
[email protected]4934d362012-11-22 22:04:53170 EXPECT_EQ(a->matrix, b->matrix);
171 }
172
[email protected]78d30122014-01-17 06:32:36173 void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
174 EXPECT_EQ(a->surface_id, b->surface_id);
175 }
176
[email protected]4934d362012-11-22 22:04:53177 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);
[email protected]1fd555b2013-01-18 00:13:21180 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
181 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
[email protected]d18b4d62013-07-12 05:33:49182 EXPECT_EQ(a->background_color, b->background_color);
[email protected]61df9d82013-01-30 02:32:42183 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]);
[email protected]4934d362012-11-22 22:04:53187 EXPECT_EQ(a->flipped, b->flipped);
188 }
189
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);
[email protected]4934d362012-11-22 22:04:53195 }
196
197 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
198 EXPECT_EQ(a->tex_scale, b->tex_scale);
[email protected]b7cfc632013-04-10 04:44:49199 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);
[email protected]0402b2382013-06-07 21:50:54202 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
[email protected]4934d362012-11-22 22:04:53203 }
[email protected]bca159072012-12-04 00:52:44204
205 void Compare(const TransferableResource& a, const TransferableResource& b) {
206 EXPECT_EQ(a.id, b.id);
207 EXPECT_EQ(a.format, b.format);
[email protected]80189292013-02-28 01:59:36208 EXPECT_EQ(a.filter, b.filter);
[email protected]bca159072012-12-04 00:52:44209 EXPECT_EQ(a.size.ToString(), b.size.ToString());
[email protected]df41e252014-02-03 23:39:50210 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
211 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
212 b.mailbox_holder.mailbox.name[i]);
213 }
214 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
215 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
[email protected]bca159072012-12-04 00:52:44216 }
[email protected]4934d362012-11-22 22:04:53217};
218
219TEST_F(CCMessagesTest, AllQuads) {
[email protected]753bb252013-11-04 22:28:12220 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]4934d362012-11-22 22:04:53221
[email protected]c8686a02012-11-27 08:29:00222 Transform arbitrary_matrix;
223 arbitrary_matrix.Scale(3, 3);
224 arbitrary_matrix.Translate(-5, 20);
225 arbitrary_matrix.Rotate(15);
[email protected]4934d362012-11-22 22:04:53226 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
[email protected]8e1da692013-10-12 17:11:30227 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
228 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
[email protected]4934d362012-11-22 22:04:53229 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
[email protected]8e1da692013-10-12 17:11:30230 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
231 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
[email protected]4934d362012-11-22 22:04:53232 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
[email protected]8e1da692013-10-12 17:11:30233 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
234 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
[email protected]4934d362012-11-22 22:04:53235 gfx::Size arbitrary_size1(15, 19);
236 gfx::Size arbitrary_size2(3, 99);
237 gfx::Size arbitrary_size3(75, 1281);
238 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
239 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
[email protected]61df9d82013-01-30 02:32:42240 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
241 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
[email protected]4934d362012-11-22 22:04:53242 float arbitrary_float1 = 0.7f;
243 float arbitrary_float2 = 0.3f;
244 float arbitrary_float3 = 0.9f;
[email protected]61df9d82013-01-30 02:32:42245 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
[email protected]4934d362012-11-22 22:04:53246 bool arbitrary_bool1 = true;
247 bool arbitrary_bool2 = false;
[email protected]61df9d82013-01-30 02:32:42248 bool arbitrary_bool3 = true;
[email protected]4934d362012-11-22 22:04:53249 int arbitrary_int = 5;
250 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
[email protected]7bbeaf4e2013-11-26 10:27:22251 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
252 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
253 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
[email protected]4934d362012-11-22 22:04:53254 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
255 IOSurfaceDrawQuad::UNFLIPPED;
256 RenderPass::Id arbitrary_id(10, 14);
[email protected]b7cfc632013-04-10 04:44:49257 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
258 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
259 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
[email protected]0402b2382013-06-07 21:50:54260 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
[email protected]a1765672013-08-12 23:45:02261 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
[email protected]4934d362012-11-22 22:04:53262
[email protected]ae6b1a72013-06-25 18:49:29263 FilterOperations arbitrary_filters1;
264 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
[email protected]4934d362012-11-22 22:04:53265 arbitrary_float1));
[email protected]1dc7943e2013-09-26 04:41:48266 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
267 new SkBlurImageFilter(arbitrary_sigma, arbitrary_sigma));
268 arbitrary_filters1.Append(
269 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
[email protected]4934d362012-11-22 22:04:53270
[email protected]ae6b1a72013-06-25 18:49:29271 FilterOperations arbitrary_filters2;
272 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
[email protected]4934d362012-11-22 22:04:53273 arbitrary_float2));
274
275 scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create();
276 shared_state1_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27277 arbitrary_size1,
[email protected]4934d362012-11-22 22:04:53278 arbitrary_rect1,
279 arbitrary_rect2,
[email protected]4934d362012-11-22 22:04:53280 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22281 arbitrary_float1,
282 arbitrary_blend_mode1);
[email protected]4934d362012-11-22 22:04:53283 scoped_ptr<SharedQuadState> shared_state1_cmp = shared_state1_in->Copy();
284
285 scoped_ptr<CheckerboardDrawQuad> checkerboard_in =
286 CheckerboardDrawQuad::Create();
287 checkerboard_in->SetAll(shared_state1_in.get(),
288 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30289 arbitrary_rect2_inside_rect1,
290 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53291 arbitrary_bool1,
292 arbitrary_color);
293 scoped_ptr<DrawQuad> checkerboard_cmp = checkerboard_in->Copy(
294 checkerboard_in->shared_quad_state);
295
296 scoped_ptr<DebugBorderDrawQuad> debugborder_in =
297 DebugBorderDrawQuad::Create();
298 debugborder_in->SetAll(shared_state1_in.get(),
299 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30300 arbitrary_rect1_inside_rect3,
301 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53302 arbitrary_bool1,
303 arbitrary_color,
304 arbitrary_int);
305 scoped_ptr<DrawQuad> debugborder_cmp = debugborder_in->Copy(
306 debugborder_in->shared_quad_state);
307
308 scoped_ptr<IOSurfaceDrawQuad> iosurface_in =
309 IOSurfaceDrawQuad::Create();
310 iosurface_in->SetAll(shared_state1_in.get(),
311 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30312 arbitrary_rect2_inside_rect2,
313 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53314 arbitrary_bool1,
315 arbitrary_size1,
[email protected]b7cfc632013-04-10 04:44:49316 arbitrary_resourceid3,
[email protected]4934d362012-11-22 22:04:53317 arbitrary_orientation);
318 scoped_ptr<DrawQuad> iosurface_cmp = iosurface_in->Copy(
319 iosurface_in->shared_quad_state);
320
[email protected]cbe94b7a2013-11-13 11:03:37321 scoped_ptr<SharedQuadState> shared_state2_in = SharedQuadState::Create();
322 shared_state2_in->SetAll(arbitrary_matrix,
323 arbitrary_size2,
324 arbitrary_rect2,
325 arbitrary_rect3,
326 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22327 arbitrary_float2,
328 arbitrary_blend_mode2);
[email protected]cbe94b7a2013-11-13 11:03:37329 scoped_ptr<SharedQuadState> shared_state2_cmp = shared_state2_in->Copy();
330
[email protected]4934d362012-11-22 22:04:53331 scoped_ptr<RenderPassDrawQuad> renderpass_in =
332 RenderPassDrawQuad::Create();
[email protected]cbe94b7a2013-11-13 11:03:37333 renderpass_in->SetAll(shared_state2_in.get(),
[email protected]4934d362012-11-22 22:04:53334 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30335 arbitrary_rect2_inside_rect1,
336 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53337 arbitrary_bool1,
338 arbitrary_id,
339 arbitrary_bool2,
[email protected]b7cfc632013-04-10 04:44:49340 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53341 arbitrary_rect1,
[email protected]20062042012-12-21 22:16:36342 arbitrary_rectf1,
343 arbitrary_filters1,
[email protected]20062042012-12-21 22:16:36344 arbitrary_filters2);
[email protected]4934d362012-11-22 22:04:53345 scoped_ptr<RenderPassDrawQuad> renderpass_cmp = renderpass_in->Copy(
346 renderpass_in->shared_quad_state, renderpass_in->render_pass_id);
347
[email protected]4934d362012-11-22 22:04:53348 scoped_ptr<SharedQuadState> shared_state3_in = SharedQuadState::Create();
349 shared_state3_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27350 arbitrary_size3,
[email protected]4934d362012-11-22 22:04:53351 arbitrary_rect3,
352 arbitrary_rect1,
[email protected]4934d362012-11-22 22:04:53353 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22354 arbitrary_float3,
355 arbitrary_blend_mode3);
[email protected]4934d362012-11-22 22:04:53356 scoped_ptr<SharedQuadState> shared_state3_cmp = shared_state3_in->Copy();
357
358 scoped_ptr<SolidColorDrawQuad> solidcolor_in =
359 SolidColorDrawQuad::Create();
[email protected]cbe94b7a2013-11-13 11:03:37360 solidcolor_in->SetAll(shared_state3_in.get(),
[email protected]4934d362012-11-22 22:04:53361 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30362 arbitrary_rect1_inside_rect3,
363 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53364 arbitrary_bool1,
[email protected]10a30b12013-05-02 16:42:11365 arbitrary_color,
366 arbitrary_bool2);
[email protected]4934d362012-11-22 22:04:53367 scoped_ptr<DrawQuad> solidcolor_cmp = solidcolor_in->Copy(
368 solidcolor_in->shared_quad_state);
369
370 scoped_ptr<StreamVideoDrawQuad> streamvideo_in =
371 StreamVideoDrawQuad::Create();
[email protected]cbe94b7a2013-11-13 11:03:37372 streamvideo_in->SetAll(shared_state3_in.get(),
[email protected]4934d362012-11-22 22:04:53373 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30374 arbitrary_rect2_inside_rect2,
375 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53376 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49377 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53378 arbitrary_matrix);
379 scoped_ptr<DrawQuad> streamvideo_cmp = streamvideo_in->Copy(
380 streamvideo_in->shared_quad_state);
381
[email protected]78d30122014-01-17 06:32:36382 int arbitrary_surface_id = 3;
383 scoped_ptr<SurfaceDrawQuad> surface_in = SurfaceDrawQuad::Create();
384 surface_in->SetAll(shared_state3_in.get(),
385 arbitrary_rect2,
386 arbitrary_rect2_inside_rect2,
387 arbitrary_rect1_inside_rect2,
388 arbitrary_bool1,
389 arbitrary_surface_id);
390 scoped_ptr<DrawQuad> surface_cmp = surface_in->Copy(
391 surface_in->shared_quad_state);
392
[email protected]61df9d82013-01-30 02:32:42393 scoped_ptr<TextureDrawQuad> texture_in = TextureDrawQuad::Create();
[email protected]cbe94b7a2013-11-13 11:03:37394 texture_in->SetAll(shared_state3_in.get(),
[email protected]61df9d82013-01-30 02:32:42395 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30396 arbitrary_rect2_inside_rect2,
397 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42398 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49399 arbitrary_resourceid1,
[email protected]61df9d82013-01-30 02:32:42400 arbitrary_bool2,
401 arbitrary_pointf1,
402 arbitrary_pointf2,
[email protected]d18b4d62013-07-12 05:33:49403 arbitrary_color,
[email protected]61df9d82013-01-30 02:32:42404 arbitrary_float_array,
405 arbitrary_bool3);
406 scoped_ptr<DrawQuad> texture_cmp = texture_in->Copy(
407 texture_in->shared_quad_state);
408
409 scoped_ptr<TileDrawQuad> tile_in = TileDrawQuad::Create();
[email protected]cbe94b7a2013-11-13 11:03:37410 tile_in->SetAll(shared_state3_in.get(),
[email protected]61df9d82013-01-30 02:32:42411 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30412 arbitrary_rect2_inside_rect2,
413 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42414 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49415 arbitrary_resourceid3,
[email protected]61df9d82013-01-30 02:32:42416 arbitrary_rectf1,
417 arbitrary_size1,
[email protected]f902bf92013-03-04 18:33:27418 arbitrary_bool2);
[email protected]61df9d82013-01-30 02:32:42419 scoped_ptr<DrawQuad> tile_cmp = tile_in->Copy(
420 tile_in->shared_quad_state);
421
[email protected]4934d362012-11-22 22:04:53422 scoped_ptr<YUVVideoDrawQuad> yuvvideo_in =
423 YUVVideoDrawQuad::Create();
[email protected]cbe94b7a2013-11-13 11:03:37424 yuvvideo_in->SetAll(shared_state3_in.get(),
[email protected]4934d362012-11-22 22:04:53425 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30426 arbitrary_rect2_inside_rect1,
427 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53428 arbitrary_bool1,
429 arbitrary_sizef1,
[email protected]b7cfc632013-04-10 04:44:49430 arbitrary_resourceid1,
431 arbitrary_resourceid2,
[email protected]0402b2382013-06-07 21:50:54432 arbitrary_resourceid3,
433 arbitrary_resourceid4);
[email protected]4934d362012-11-22 22:04:53434 scoped_ptr<DrawQuad> yuvvideo_cmp = yuvvideo_in->Copy(
435 yuvvideo_in->shared_quad_state);
436
437 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
438 pass_in->SetAll(arbitrary_id,
439 arbitrary_rect1,
440 arbitrary_rectf1,
441 arbitrary_matrix,
[email protected]63880f8d2014-03-20 05:56:39442 arbitrary_bool1,
443 cc::RenderPass::NO_OVERLAY);
[email protected]4934d362012-11-22 22:04:53444
[email protected]ead39c52013-01-09 07:22:45445 pass_in->shared_quad_state_list.push_back(shared_state1_in.Pass());
446 pass_in->quad_list.push_back(checkerboard_in.PassAs<DrawQuad>());
447 pass_in->quad_list.push_back(debugborder_in.PassAs<DrawQuad>());
448 pass_in->quad_list.push_back(iosurface_in.PassAs<DrawQuad>());
449 pass_in->quad_list.push_back(renderpass_in.PassAs<DrawQuad>());
450 pass_in->shared_quad_state_list.push_back(shared_state2_in.Pass());
451 pass_in->shared_quad_state_list.push_back(shared_state3_in.Pass());
452 pass_in->quad_list.push_back(solidcolor_in.PassAs<DrawQuad>());
453 pass_in->quad_list.push_back(streamvideo_in.PassAs<DrawQuad>());
[email protected]78d30122014-01-17 06:32:36454 pass_in->quad_list.push_back(surface_in.PassAs<DrawQuad>());
[email protected]61df9d82013-01-30 02:32:42455 pass_in->quad_list.push_back(texture_in.PassAs<DrawQuad>());
456 pass_in->quad_list.push_back(tile_in.PassAs<DrawQuad>());
[email protected]ead39c52013-01-09 07:22:45457 pass_in->quad_list.push_back(yuvvideo_in.PassAs<DrawQuad>());
[email protected]4934d362012-11-22 22:04:53458
459 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
460 pass_cmp->SetAll(arbitrary_id,
461 arbitrary_rect1,
462 arbitrary_rectf1,
463 arbitrary_matrix,
[email protected]63880f8d2014-03-20 05:56:39464 arbitrary_bool1,
465 cc::RenderPass::NO_OVERLAY);
[email protected]4934d362012-11-22 22:04:53466
[email protected]ead39c52013-01-09 07:22:45467 pass_cmp->shared_quad_state_list.push_back(shared_state1_cmp.Pass());
468 pass_cmp->quad_list.push_back(checkerboard_cmp.PassAs<DrawQuad>());
469 pass_cmp->quad_list.push_back(debugborder_cmp.PassAs<DrawQuad>());
470 pass_cmp->quad_list.push_back(iosurface_cmp.PassAs<DrawQuad>());
471 pass_cmp->quad_list.push_back(renderpass_cmp.PassAs<DrawQuad>());
472 pass_cmp->shared_quad_state_list.push_back(shared_state2_cmp.Pass());
473 pass_cmp->shared_quad_state_list.push_back(shared_state3_cmp.Pass());
474 pass_cmp->quad_list.push_back(solidcolor_cmp.PassAs<DrawQuad>());
475 pass_cmp->quad_list.push_back(streamvideo_cmp.PassAs<DrawQuad>());
[email protected]78d30122014-01-17 06:32:36476 pass_cmp->quad_list.push_back(surface_cmp.PassAs<DrawQuad>());
[email protected]61df9d82013-01-30 02:32:42477 pass_cmp->quad_list.push_back(texture_cmp.PassAs<DrawQuad>());
478 pass_cmp->quad_list.push_back(tile_cmp.PassAs<DrawQuad>());
[email protected]ead39c52013-01-09 07:22:45479 pass_cmp->quad_list.push_back(yuvvideo_cmp.PassAs<DrawQuad>());
[email protected]4934d362012-11-22 22:04:53480
481 // Make sure the in and cmp RenderPasses match.
482 Compare(pass_cmp.get(), pass_in.get());
483 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36484 ASSERT_EQ(10u, pass_in->quad_list.size());
[email protected]4934d362012-11-22 22:04:53485 for (size_t i = 0; i < 3; ++i) {
486 Compare(pass_cmp->shared_quad_state_list[i],
487 pass_in->shared_quad_state_list[i]);
488 }
[email protected]61df9d82013-01-30 02:32:42489 for (size_t i = 0; i < pass_in->quad_list.size(); ++i)
[email protected]4934d362012-11-22 22:04:53490 Compare(pass_cmp->quad_list[i], pass_in->quad_list[i]);
[email protected]61df9d82013-01-30 02:32:42491 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53492 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_in =
496 pass_in->quad_list[i]->shared_quad_state ==
497 pass_in->quad_list[i - 1]->shared_quad_state;
498 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
499 }
500
[email protected]bf189f62012-12-18 03:42:11501 DelegatedFrameData frame_in;
[email protected]ead39c52013-01-09 07:22:45502 frame_in.render_pass_list.push_back(pass_in.Pass());
[email protected]4934d362012-11-22 22:04:53503
[email protected]bf189f62012-12-18 03:42:11504 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44505
[email protected]bf189f62012-12-18 03:42:11506 DelegatedFrameData frame_out;
[email protected]4934d362012-11-22 22:04:53507 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11508 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
509 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44510
[email protected]4934d362012-11-22 22:04:53511 // Make sure the out and cmp RenderPasses match.
[email protected]ead39c52013-01-09 07:22:45512 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
513 frame_out.render_pass_list.begin());
[email protected]4934d362012-11-22 22:04:53514 Compare(pass_cmp.get(), pass_out.get());
515 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36516 ASSERT_EQ(10u, pass_out->quad_list.size());
[email protected]4934d362012-11-22 22:04:53517 for (size_t i = 0; i < 3; ++i) {
518 Compare(pass_cmp->shared_quad_state_list[i],
519 pass_out->shared_quad_state_list[i]);
520 }
[email protected]61df9d82013-01-30 02:32:42521 for (size_t i = 0; i < pass_out->quad_list.size(); ++i)
[email protected]4934d362012-11-22 22:04:53522 Compare(pass_cmp->quad_list[i], pass_out->quad_list[i]);
[email protected]61df9d82013-01-30 02:32:42523 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53524 bool same_shared_quad_state_cmp =
525 pass_cmp->quad_list[i]->shared_quad_state ==
526 pass_cmp->quad_list[i - 1]->shared_quad_state;
527 bool same_shared_quad_state_out =
528 pass_out->quad_list[i]->shared_quad_state ==
529 pass_out->quad_list[i - 1]->shared_quad_state;
530 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
531 }
532}
[email protected]bca159072012-12-04 00:52:44533
[email protected]cbe94b7a2013-11-13 11:03:37534TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
535 scoped_ptr<CheckerboardDrawQuad> quad;
536
537 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
538 pass_in->SetAll(RenderPass::Id(1, 1),
539 gfx::Rect(100, 100),
540 gfx::RectF(),
541 gfx::Transform(),
[email protected]63880f8d2014-03-20 05:56:39542 false,
543 cc::RenderPass::NO_OVERLAY);
[email protected]cbe94b7a2013-11-13 11:03:37544
545 // The first SharedQuadState is used.
546 scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create();
[email protected]7bbeaf4e2013-11-26 10:27:22547 shared_state1_in->SetAll(gfx::Transform(),
548 gfx::Size(1, 1),
549 gfx::Rect(),
550 gfx::Rect(),
551 false,
552 1.f,
553 SkXfermode::kSrcOver_Mode);
[email protected]cbe94b7a2013-11-13 11:03:37554
555 quad = CheckerboardDrawQuad::Create();
556 quad->SetAll(shared_state1_in.get(),
557 gfx::Rect(10, 10),
558 gfx::Rect(10, 10),
559 gfx::Rect(10, 10),
560 false,
561 SK_ColorRED);
562 pass_in->quad_list.push_back(quad.PassAs<DrawQuad>());
563
564 // The second and third SharedQuadStates are not used.
565 scoped_ptr<SharedQuadState> shared_state2_in = SharedQuadState::Create();
[email protected]7bbeaf4e2013-11-26 10:27:22566 shared_state2_in->SetAll(gfx::Transform(),
567 gfx::Size(2, 2),
568 gfx::Rect(),
569 gfx::Rect(),
570 false,
571 1.f,
572 SkXfermode::kSrcOver_Mode);
[email protected]cbe94b7a2013-11-13 11:03:37573
574 scoped_ptr<SharedQuadState> shared_state3_in = SharedQuadState::Create();
[email protected]7bbeaf4e2013-11-26 10:27:22575 shared_state3_in->SetAll(gfx::Transform(),
576 gfx::Size(3, 3),
577 gfx::Rect(),
578 gfx::Rect(),
579 false,
580 1.f,
581 SkXfermode::kSrcOver_Mode);
[email protected]cbe94b7a2013-11-13 11:03:37582
583 // The fourth SharedQuadState is used.
584 scoped_ptr<SharedQuadState> shared_state4_in = SharedQuadState::Create();
[email protected]7bbeaf4e2013-11-26 10:27:22585 shared_state4_in->SetAll(gfx::Transform(),
586 gfx::Size(4, 4),
587 gfx::Rect(),
588 gfx::Rect(),
589 false,
590 1.f,
591 SkXfermode::kSrcOver_Mode);
[email protected]cbe94b7a2013-11-13 11:03:37592
593 quad = CheckerboardDrawQuad::Create();
594 quad->SetAll(shared_state4_in.get(),
595 gfx::Rect(10, 10),
596 gfx::Rect(10, 10),
597 gfx::Rect(10, 10),
598 false,
599 SK_ColorRED);
600 pass_in->quad_list.push_back(quad.PassAs<DrawQuad>());
601
602 // The fifth is not used again.
603 scoped_ptr<SharedQuadState> shared_state5_in = SharedQuadState::Create();
[email protected]7bbeaf4e2013-11-26 10:27:22604 shared_state5_in->SetAll(gfx::Transform(),
605 gfx::Size(5, 5),
606 gfx::Rect(),
607 gfx::Rect(),
608 false,
609 1.f,
610 SkXfermode::kSrcOver_Mode);
[email protected]cbe94b7a2013-11-13 11:03:37611
612 pass_in->shared_quad_state_list.push_back(shared_state1_in.Pass());
613 pass_in->shared_quad_state_list.push_back(shared_state2_in.Pass());
614 pass_in->shared_quad_state_list.push_back(shared_state3_in.Pass());
615 pass_in->shared_quad_state_list.push_back(shared_state4_in.Pass());
616 pass_in->shared_quad_state_list.push_back(shared_state5_in.Pass());
617
618 // 5 SharedQuadStates go in.
619 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
620 ASSERT_EQ(2u, pass_in->quad_list.size());
621
622 DelegatedFrameData frame_in;
623 frame_in.render_pass_list.push_back(pass_in.Pass());
624
625 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
626 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
627
628 DelegatedFrameData frame_out;
629 PickleIterator iter(msg);
630 EXPECT_TRUE(
631 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
632
633 scoped_ptr<RenderPass> pass_out =
634 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
635
636 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
637 // used by quads, and so serialized. Others were not.
638 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
639 ASSERT_EQ(2u, pass_out->quad_list.size());
640
641 EXPECT_EQ(gfx::Size(1, 1).ToString(),
642 pass_out->shared_quad_state_list[0]->content_bounds.ToString());
643 EXPECT_EQ(gfx::Size(4, 4).ToString(),
644 pass_out->shared_quad_state_list[1]->content_bounds.ToString());
645}
646
[email protected]bca159072012-12-04 00:52:44647TEST_F(CCMessagesTest, Resources) {
[email protected]753bb252013-11-04 22:28:12648 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]bca159072012-12-04 00:52:44649 gfx::Size arbitrary_size(757, 1281);
[email protected]09831f7f2013-02-27 03:32:15650 unsigned int arbitrary_uint1 = 71234838;
651 unsigned int arbitrary_uint2 = 53589793;
[email protected]bca159072012-12-04 00:52:44652
[email protected]e0a4d732014-02-15 00:23:26653 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
654 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
655 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
656 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
[email protected]bca159072012-12-04 00:52:44657
[email protected]e0a4d732014-02-15 00:23:26658 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
659 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
660 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
661 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
[email protected]bca159072012-12-04 00:52:44662
663 TransferableResource arbitrary_resource1;
664 arbitrary_resource1.id = 2178312;
[email protected]27a41fe2013-09-19 05:05:14665 arbitrary_resource1.format = cc::RGBA_8888;
[email protected]80189292013-02-28 01:59:36666 arbitrary_resource1.filter = 53;
[email protected]bca159072012-12-04 00:52:44667 arbitrary_resource1.size = gfx::Size(37189, 123123);
[email protected]df41e252014-02-03 23:39:50668 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
669 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
670 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
[email protected]bca159072012-12-04 00:52:44671
672 TransferableResource arbitrary_resource2;
673 arbitrary_resource2.id = 789132;
[email protected]27a41fe2013-09-19 05:05:14674 arbitrary_resource2.format = cc::RGBA_4444;
[email protected]645a47f22013-09-26 05:42:32675 arbitrary_resource2.filter = 47;
[email protected]bca159072012-12-04 00:52:44676 arbitrary_resource2.size = gfx::Size(89123, 23789);
[email protected]df41e252014-02-03 23:39:50677 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
678 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
679 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
[email protected]bca159072012-12-04 00:52:44680
[email protected]cb7d6492013-10-03 02:40:04681 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
682 renderpass_in->SetNew(
683 RenderPass::Id(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
684
[email protected]bf189f62012-12-18 03:42:11685 DelegatedFrameData frame_in;
[email protected]09831f7f2013-02-27 03:32:15686 frame_in.resource_list.push_back(arbitrary_resource1);
687 frame_in.resource_list.push_back(arbitrary_resource2);
[email protected]cb7d6492013-10-03 02:40:04688 frame_in.render_pass_list.push_back(renderpass_in.Pass());
[email protected]bca159072012-12-04 00:52:44689
[email protected]bf189f62012-12-18 03:42:11690 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44691
[email protected]bf189f62012-12-18 03:42:11692 DelegatedFrameData frame_out;
[email protected]bca159072012-12-04 00:52:44693 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11694 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
695 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44696
[email protected]09831f7f2013-02-27 03:32:15697 ASSERT_EQ(2u, frame_out.resource_list.size());
698 Compare(arbitrary_resource1, frame_out.resource_list[0]);
699 Compare(arbitrary_resource2, frame_out.resource_list[1]);
[email protected]bca159072012-12-04 00:52:44700}
701
[email protected]032bfc42013-10-29 22:23:52702TEST_F(CCMessagesTest, LargestQuadType) {
703 size_t largest = 0;
704
705 bool done = false;
706 for (int i = 0; !done; ++i) {
707 switch (static_cast<DrawQuad::Material>(i)) {
708 case cc::DrawQuad::CHECKERBOARD:
709 largest = std::max(largest, sizeof(cc::CheckerboardDrawQuad));
710 break;
711 case cc::DrawQuad::DEBUG_BORDER:
712 largest = std::max(largest, sizeof(cc::DebugBorderDrawQuad));
713 break;
714 case cc::DrawQuad::IO_SURFACE_CONTENT:
715 largest = std::max(largest, sizeof(cc::IOSurfaceDrawQuad));
716 break;
717 case cc::DrawQuad::PICTURE_CONTENT:
718 largest = std::max(largest, sizeof(cc::PictureDrawQuad));
719 break;
720 case cc::DrawQuad::TEXTURE_CONTENT:
721 largest = std::max(largest, sizeof(cc::TextureDrawQuad));
722 break;
723 case cc::DrawQuad::RENDER_PASS:
724 largest = std::max(largest, sizeof(cc::RenderPassDrawQuad));
725 break;
726 case cc::DrawQuad::SOLID_COLOR:
727 largest = std::max(largest, sizeof(cc::SolidColorDrawQuad));
728 break;
[email protected]78d30122014-01-17 06:32:36729 case cc::DrawQuad::SURFACE_CONTENT:
730 largest = std::max(largest, sizeof(cc::SurfaceDrawQuad));
731 break;
[email protected]032bfc42013-10-29 22:23:52732 case cc::DrawQuad::TILED_CONTENT:
733 largest = std::max(largest, sizeof(cc::TileDrawQuad));
734 break;
735 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
736 largest = std::max(largest, sizeof(cc::StreamVideoDrawQuad));
737 break;
738 case cc::DrawQuad::YUV_VIDEO_CONTENT:
739 largest = std::max(largest, sizeof(cc::YUVVideoDrawQuad));
740 break;
741 case cc::DrawQuad::INVALID:
742 break;
743 default:
744 done = true;
745 }
746 }
747
748 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever
749 // changes, then the ReserveSizeForRenderPassWrite() method needs to be
750 // updated as well to use the new largest quad.
751 EXPECT_EQ(sizeof(RenderPassDrawQuad), largest);
752}
753
[email protected]cecc8342014-03-20 21:43:39754TEST_F(CCMessagesTest, SoftwareFrameData) {
755 cc::SoftwareFrameData frame_in;
756 frame_in.id = 3;
757 frame_in.size = gfx::Size(40, 20);
758 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
759#if defined(OS_WIN)
760 frame_in.handle = reinterpret_cast<base::SharedMemoryHandle>(23);
761#elif defined(OS_POSIX)
762 frame_in.handle = base::FileDescriptor(23, true);
763#endif
764
765 // Write the frame.
766 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
767 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
768
769 // Read the frame.
770 cc::SoftwareFrameData frame_out;
771 PickleIterator iter(msg);
772 EXPECT_TRUE(
773 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
774 EXPECT_EQ(frame_in.id, frame_out.id);
775 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
776 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
777 EXPECT_EQ(frame_in.handle, frame_out.handle);
778}
779
780TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
781 SoftwareFrameData frame_in;
782 frame_in.id = 3;
783 frame_in.size = gfx::Size(40, 20);
784 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
785#if defined(OS_WIN)
786 frame_in.handle = reinterpret_cast<base::SharedMemoryHandle>(23);
787#elif defined(OS_POSIX)
788 frame_in.handle = base::FileDescriptor(23, true);
789#endif
790
791 // Write the SoftwareFrameData by hand, make sure it works.
792 {
793 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
794 IPC::WriteParam(&msg, frame_in.id);
795 IPC::WriteParam(&msg, frame_in.size);
796 IPC::WriteParam(&msg, frame_in.damage_rect);
797 IPC::WriteParam(&msg, frame_in.handle);
798 SoftwareFrameData frame_out;
799 PickleIterator iter(msg);
800 EXPECT_TRUE(
801 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
802 }
803
804 // The size of the frame may overflow when multiplied together.
805 int max = std::numeric_limits<int>::max();
806 frame_in.size = gfx::Size(max, max);
807
808 // If size_t is larger than int, then int*int*4 can always fit in size_t.
809 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
810
811 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
812 // should fail.
813 {
814 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
815 IPC::WriteParam(&msg, frame_in.id);
816 IPC::WriteParam(&msg, frame_in.size);
817 IPC::WriteParam(&msg, frame_in.damage_rect);
818 IPC::WriteParam(&msg, frame_in.handle);
819 SoftwareFrameData frame_out;
820 PickleIterator iter(msg);
821 EXPECT_EQ(
822 expect_read,
823 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
824 }
825}
826
[email protected]bca159072012-12-04 00:52:44827} // namespace
828} // namespace content