blob: 039826636368e8b6fa5f7127164934ee3fd145d6 [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;
[email protected]0cd7d6f72014-08-22 14:50:5131using cc::RenderPassId;
[email protected]4934d362012-11-22 22:04:5332using cc::RenderPassDrawQuad;
jbaumanbbd425e2015-05-19 00:33:3533using cc::ResourceId;
[email protected]4934d362012-11-22 22:04:5334using cc::ResourceProvider;
35using cc::SharedQuadState;
[email protected]cecc8342014-03-20 21:43:3936using cc::SoftwareFrameData;
[email protected]4934d362012-11-22 22:04:5337using cc::SolidColorDrawQuad;
[email protected]78d30122014-01-17 06:32:3638using cc::SurfaceDrawQuad;
[email protected]4934d362012-11-22 22:04:5339using cc::TextureDrawQuad;
40using cc::TileDrawQuad;
[email protected]bca159072012-12-04 00:52:4441using cc::TransferableResource;
[email protected]4934d362012-11-22 22:04:5342using cc::StreamVideoDrawQuad;
[email protected]4934d362012-11-22 22:04:5343using cc::YUVVideoDrawQuad;
[email protected]c8686a02012-11-27 08:29:0044using gfx::Transform;
[email protected]4934d362012-11-22 22:04:5345
[email protected]bca159072012-12-04 00:52:4446namespace content {
47namespace {
48
[email protected]4934d362012-11-22 22:04:5349class CCMessagesTest : public testing::Test {
50 protected:
51 void Compare(const RenderPass* a, const RenderPass* b) {
52 EXPECT_EQ(a->id, b->id);
53 EXPECT_EQ(a->output_rect.ToString(), b->output_rect.ToString());
54 EXPECT_EQ(a->damage_rect.ToString(), b->damage_rect.ToString());
55 EXPECT_EQ(a->transform_to_root_target, b->transform_to_root_target);
56 EXPECT_EQ(a->has_transparent_background, b->has_transparent_background);
[email protected]4934d362012-11-22 22:04:5357 }
58
59 void Compare(const SharedQuadState* a, const SharedQuadState* b) {
60 EXPECT_EQ(a->content_to_target_transform, b->content_to_target_transform);
[email protected]f902bf92013-03-04 18:33:2761 EXPECT_EQ(a->content_bounds, b->content_bounds);
[email protected]4934d362012-11-22 22:04:5362 EXPECT_EQ(a->visible_content_rect, b->visible_content_rect);
[email protected]4934d362012-11-22 22:04:5363 EXPECT_EQ(a->clip_rect, b->clip_rect);
64 EXPECT_EQ(a->is_clipped, b->is_clipped);
65 EXPECT_EQ(a->opacity, b->opacity);
[email protected]7bbeaf4e2013-11-26 10:27:2266 EXPECT_EQ(a->blend_mode, b->blend_mode);
[email protected]a9d4d4f2014-06-19 06:49:2867 EXPECT_EQ(a->sorting_context_id, b->sorting_context_id);
[email protected]4934d362012-11-22 22:04:5368 }
69
70 void Compare(const DrawQuad* a, const DrawQuad* b) {
71 ASSERT_NE(DrawQuad::INVALID, a->material);
72 ASSERT_EQ(a->material, b->material);
73 EXPECT_EQ(a->rect.ToString(), b->rect.ToString());
74 EXPECT_EQ(a->opaque_rect.ToString(), b->opaque_rect.ToString());
75 EXPECT_EQ(a->visible_rect.ToString(), b->visible_rect.ToString());
76 EXPECT_EQ(a->needs_blending, b->needs_blending);
77
78 Compare(a->shared_quad_state, b->shared_quad_state);
79
80 switch (a->material) {
81 case DrawQuad::CHECKERBOARD:
82 Compare(CheckerboardDrawQuad::MaterialCast(a),
83 CheckerboardDrawQuad::MaterialCast(b));
84 break;
85 case DrawQuad::DEBUG_BORDER:
86 Compare(DebugBorderDrawQuad::MaterialCast(a),
87 DebugBorderDrawQuad::MaterialCast(b));
88 break;
89 case DrawQuad::IO_SURFACE_CONTENT:
90 Compare(IOSurfaceDrawQuad::MaterialCast(a),
91 IOSurfaceDrawQuad::MaterialCast(b));
92 break;
[email protected]9ee4d3a2013-03-27 17:43:1693 case DrawQuad::PICTURE_CONTENT:
94 Compare(PictureDrawQuad::MaterialCast(a),
95 PictureDrawQuad::MaterialCast(b));
96 break;
[email protected]4934d362012-11-22 22:04:5397 case DrawQuad::RENDER_PASS:
98 Compare(RenderPassDrawQuad::MaterialCast(a),
99 RenderPassDrawQuad::MaterialCast(b));
100 break;
101 case DrawQuad::TEXTURE_CONTENT:
102 Compare(TextureDrawQuad::MaterialCast(a),
103 TextureDrawQuad::MaterialCast(b));
104 break;
105 case DrawQuad::TILED_CONTENT:
106 Compare(TileDrawQuad::MaterialCast(a),
107 TileDrawQuad::MaterialCast(b));
108 break;
109 case DrawQuad::SOLID_COLOR:
110 Compare(SolidColorDrawQuad::MaterialCast(a),
111 SolidColorDrawQuad::MaterialCast(b));
112 break;
113 case DrawQuad::STREAM_VIDEO_CONTENT:
114 Compare(StreamVideoDrawQuad::MaterialCast(a),
115 StreamVideoDrawQuad::MaterialCast(b));
116 break;
[email protected]78d30122014-01-17 06:32:36117 case DrawQuad::SURFACE_CONTENT:
118 Compare(SurfaceDrawQuad::MaterialCast(a),
119 SurfaceDrawQuad::MaterialCast(b));
120 break;
[email protected]4934d362012-11-22 22:04:53121 case DrawQuad::YUV_VIDEO_CONTENT:
122 Compare(YUVVideoDrawQuad::MaterialCast(a),
123 YUVVideoDrawQuad::MaterialCast(b));
124 break;
125 case DrawQuad::INVALID:
126 break;
127 }
128 }
129
130 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) {
131 EXPECT_EQ(a->color, b->color);
danakje1419ce2015-03-04 21:26:27132 EXPECT_EQ(a->scale, b->scale);
[email protected]4934d362012-11-22 22:04:53133 }
134
135 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
136 EXPECT_EQ(a->color, b->color);
137 EXPECT_EQ(a->width, b->width);
138 }
139
140 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
141 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
[email protected]b7cfc632013-04-10 04:44:49142 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
[email protected]4934d362012-11-22 22:04:53143 EXPECT_EQ(a->orientation, b->orientation);
144 }
145
146 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
[email protected]82f93fb2013-04-17 21:42:06147 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
[email protected]4934d362012-11-22 22:04:53148 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id);
ennef6f3fbba42014-10-16 18:16:49149 EXPECT_EQ(a->mask_uv_scale.ToString(), b->mask_uv_scale.ToString());
150 EXPECT_EQ(a->mask_texture_size.ToString(), b->mask_texture_size.ToString());
[email protected]1dc7943e2013-09-26 04:41:48151 EXPECT_EQ(a->filters.size(), b->filters.size());
152 for (size_t i = 0; i < a->filters.size(); ++i) {
153 if (a->filters.at(i).type() != cc::FilterOperation::REFERENCE) {
154 EXPECT_EQ(a->filters.at(i), b->filters.at(i));
155 } else {
156 EXPECT_EQ(b->filters.at(i).type(), cc::FilterOperation::REFERENCE);
157 EXPECT_EQ(a->filters.at(i).image_filter()->countInputs(),
158 b->filters.at(i).image_filter()->countInputs());
159 }
160 }
[email protected]7ac3d492014-08-08 21:25:32161 EXPECT_EQ(a->filters_scale, b->filters_scale);
[email protected]20062042012-12-21 22:16:36162 EXPECT_EQ(a->background_filters, b->background_filters);
[email protected]4934d362012-11-22 22:04:53163 }
164
165 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
166 EXPECT_EQ(a->color, b->color);
[email protected]10a30b12013-05-02 16:42:11167 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
[email protected]4934d362012-11-22 22:04:53168 }
169
170 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
[email protected]b7cfc632013-04-10 04:44:49171 EXPECT_EQ(a->resource_id, b->resource_id);
[email protected]4934d362012-11-22 22:04:53172 EXPECT_EQ(a->matrix, b->matrix);
173 }
174
[email protected]78d30122014-01-17 06:32:36175 void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
176 EXPECT_EQ(a->surface_id, b->surface_id);
177 }
178
[email protected]4934d362012-11-22 22:04:53179 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
180 EXPECT_EQ(a->resource_id, b->resource_id);
181 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha);
[email protected]1fd555b2013-01-18 00:13:21182 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
183 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
[email protected]d18b4d62013-07-12 05:33:49184 EXPECT_EQ(a->background_color, b->background_color);
[email protected]61df9d82013-01-30 02:32:42185 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]);
186 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]);
187 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]);
188 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]);
halliwellaa111282015-05-13 21:58:43189 EXPECT_EQ(a->y_flipped, b->y_flipped);
jackhou10c9af42014-12-04 05:24:44190 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
[email protected]4934d362012-11-22 22:04:53191 }
192
193 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
194 EXPECT_EQ(a->resource_id, b->resource_id);
195 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
196 EXPECT_EQ(a->texture_size, b->texture_size);
197 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
jackhou24229612014-12-13 23:41:00198 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
[email protected]4934d362012-11-22 22:04:53199 }
200
201 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
revemanb71e3992015-05-12 23:01:51202 EXPECT_EQ(a->ya_tex_coord_rect, b->ya_tex_coord_rect);
203 EXPECT_EQ(a->uv_tex_coord_rect, b->uv_tex_coord_rect);
magjed7364ff92015-03-27 09:11:08204 EXPECT_EQ(a->ya_tex_size, b->ya_tex_size);
205 EXPECT_EQ(a->uv_tex_size, b->uv_tex_size);
[email protected]b7cfc632013-04-10 04:44:49206 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id);
207 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id);
208 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id);
[email protected]0402b2382013-06-07 21:50:54209 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
[email protected]82faf5e2014-05-03 02:25:58210 EXPECT_EQ(a->color_space, b->color_space);
[email protected]4934d362012-11-22 22:04:53211 }
[email protected]bca159072012-12-04 00:52:44212
213 void Compare(const TransferableResource& a, const TransferableResource& b) {
214 EXPECT_EQ(a.id, b.id);
215 EXPECT_EQ(a.format, b.format);
[email protected]80189292013-02-28 01:59:36216 EXPECT_EQ(a.filter, b.filter);
[email protected]bca159072012-12-04 00:52:44217 EXPECT_EQ(a.size.ToString(), b.size.ToString());
[email protected]df41e252014-02-03 23:39:50218 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
219 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
220 b.mailbox_holder.mailbox.name[i]);
221 }
222 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
223 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
[email protected]a8c63be22014-08-07 02:39:49224 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
[email protected]bca159072012-12-04 00:52:44225 }
[email protected]4934d362012-11-22 22:04:53226};
227
228TEST_F(CCMessagesTest, AllQuads) {
[email protected]753bb252013-11-04 22:28:12229 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]4934d362012-11-22 22:04:53230
danakj112d3a102015-04-14 18:24:49231 Transform arbitrary_matrix1;
232 arbitrary_matrix1.Scale(3, 3);
233 arbitrary_matrix1.Translate(-5, 20);
234 arbitrary_matrix1.Rotate(15);
235 Transform arbitrary_matrix2;
236 arbitrary_matrix2.Scale(10, -1);
237 arbitrary_matrix2.Translate(20, 3);
238 arbitrary_matrix2.Rotate(24);
[email protected]4934d362012-11-22 22:04:53239 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
[email protected]8e1da692013-10-12 17:11:30240 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
241 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
[email protected]4934d362012-11-22 22:04:53242 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
[email protected]8e1da692013-10-12 17:11:30243 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
244 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
[email protected]4934d362012-11-22 22:04:53245 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
[email protected]8e1da692013-10-12 17:11:30246 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
247 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
[email protected]4934d362012-11-22 22:04:53248 gfx::Size arbitrary_size1(15, 19);
249 gfx::Size arbitrary_size2(3, 99);
250 gfx::Size arbitrary_size3(75, 1281);
251 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
revemanb71e3992015-05-12 23:01:51252 gfx::RectF arbitrary_rectf2(2.1f, -411.05f, 7.8f, 14.75f);
[email protected]4934d362012-11-22 22:04:53253 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
[email protected]61df9d82013-01-30 02:32:42254 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
255 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
[email protected]7ac3d492014-08-08 21:25:32256 gfx::Vector2dF arbitrary_vector2df1(16.2f, -85.1f);
ennef6f3fbba42014-10-16 18:16:49257 gfx::Vector2dF arbitrary_vector2df2(-8.3f, 0.47f);
[email protected]4934d362012-11-22 22:04:53258 float arbitrary_float1 = 0.7f;
259 float arbitrary_float2 = 0.3f;
260 float arbitrary_float3 = 0.9f;
[email protected]61df9d82013-01-30 02:32:42261 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
[email protected]4934d362012-11-22 22:04:53262 bool arbitrary_bool1 = true;
263 bool arbitrary_bool2 = false;
[email protected]61df9d82013-01-30 02:32:42264 bool arbitrary_bool3 = true;
jackhou10c9af42014-12-04 05:24:44265 bool arbitrary_bool4 = true;
[email protected]a9d4d4f2014-06-19 06:49:28266 int arbitrary_context_id1 = 12;
267 int arbitrary_context_id2 = 57;
268 int arbitrary_context_id3 = -503;
[email protected]4934d362012-11-22 22:04:53269 int arbitrary_int = 5;
270 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
[email protected]7bbeaf4e2013-11-26 10:27:22271 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
272 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
273 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
[email protected]4934d362012-11-22 22:04:53274 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
275 IOSurfaceDrawQuad::UNFLIPPED;
jbaumanbbd425e2015-05-19 00:33:35276 ResourceId arbitrary_resourceid1 = 55;
277 ResourceId arbitrary_resourceid2 = 47;
278 ResourceId arbitrary_resourceid3 = 23;
279 ResourceId arbitrary_resourceid4 = 16;
[email protected]a1765672013-08-12 23:45:02280 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
[email protected]82faf5e2014-05-03 02:25:58281 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
282 YUVVideoDrawQuad::REC_601;
[email protected]4934d362012-11-22 22:04:53283
danakj112d3a102015-04-14 18:24:49284 RenderPassId child_id(30, 5);
285 RenderPassId root_id(10, 14);
286
[email protected]ae6b1a72013-06-25 18:49:29287 FilterOperations arbitrary_filters1;
288 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
[email protected]4934d362012-11-22 22:04:53289 arbitrary_float1));
[email protected]1dc7943e2013-09-26 04:41:48290 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
[email protected]bb209bf2014-05-11 00:37:11291 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
[email protected]1dc7943e2013-09-26 04:41:48292 arbitrary_filters1.Append(
293 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
[email protected]4934d362012-11-22 22:04:53294
[email protected]ae6b1a72013-06-25 18:49:29295 FilterOperations arbitrary_filters2;
296 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
[email protected]4934d362012-11-22 22:04:53297 arbitrary_float2));
298
danakj112d3a102015-04-14 18:24:49299 scoped_ptr<RenderPass> child_pass_in = RenderPass::Create();
300 child_pass_in->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
301 arbitrary_matrix2, arbitrary_bool2);
302
303 scoped_ptr<RenderPass> child_pass_cmp = RenderPass::Create();
304 child_pass_cmp->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
305 arbitrary_matrix2, arbitrary_bool2);
306
[email protected]2b7f3892014-05-08 01:45:18307 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
danakj112d3a102015-04-14 18:24:49308 pass_in->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
[email protected]2b7f3892014-05-08 01:45:18309 arbitrary_bool1);
310
311 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
danakj112d3a102015-04-14 18:24:49312 shared_state1_in->SetAll(arbitrary_matrix1, arbitrary_size1, arbitrary_rect1,
313 arbitrary_rect2, arbitrary_bool1, arbitrary_float1,
314 arbitrary_blend_mode1, arbitrary_context_id1);
[email protected]2b7f3892014-05-08 01:45:18315
316 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
danakj112d3a102015-04-14 18:24:49317 pass_cmp->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
[email protected]2b7f3892014-05-08 01:45:18318 arbitrary_bool1);
319
320 SharedQuadState* shared_state1_cmp =
321 pass_cmp->CreateAndAppendSharedQuadState();
322 shared_state1_cmp->CopyFrom(shared_state1_in);
[email protected]4934d362012-11-22 22:04:53323
[email protected]3b85fd92014-07-10 00:00:02324 CheckerboardDrawQuad* checkerboard_in =
325 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
danakje1419ce2015-03-04 21:26:27326 checkerboard_in->SetAll(shared_state1_in, arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30327 arbitrary_rect2_inside_rect1,
danakje1419ce2015-03-04 21:26:27328 arbitrary_rect1_inside_rect1, arbitrary_bool1,
329 arbitrary_color, arbitrary_float1);
[email protected]3b85fd92014-07-10 00:00:02330 pass_cmp->CopyFromAndAppendDrawQuad(checkerboard_in,
331 checkerboard_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53332
[email protected]3b85fd92014-07-10 00:00:02333 DebugBorderDrawQuad* debugborder_in =
334 pass_in->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18335 debugborder_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53336 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30337 arbitrary_rect1_inside_rect3,
338 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53339 arbitrary_bool1,
340 arbitrary_color,
341 arbitrary_int);
[email protected]3b85fd92014-07-10 00:00:02342 pass_cmp->CopyFromAndAppendDrawQuad(debugborder_in,
343 debugborder_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53344
[email protected]3b85fd92014-07-10 00:00:02345 IOSurfaceDrawQuad* iosurface_in =
346 pass_in->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18347 iosurface_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53348 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30349 arbitrary_rect2_inside_rect2,
350 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53351 arbitrary_bool1,
352 arbitrary_size1,
[email protected]b7cfc632013-04-10 04:44:49353 arbitrary_resourceid3,
[email protected]4934d362012-11-22 22:04:53354 arbitrary_orientation);
[email protected]3b85fd92014-07-10 00:00:02355 pass_cmp->CopyFromAndAppendDrawQuad(iosurface_in,
356 iosurface_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53357
[email protected]2b7f3892014-05-08 01:45:18358 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
danakj112d3a102015-04-14 18:24:49359 shared_state2_in->SetAll(arbitrary_matrix2, arbitrary_size2, arbitrary_rect2,
360 arbitrary_rect3, arbitrary_bool1, arbitrary_float2,
361 arbitrary_blend_mode2, arbitrary_context_id2);
[email protected]2b7f3892014-05-08 01:45:18362 SharedQuadState* shared_state2_cmp =
363 pass_cmp->CreateAndAppendSharedQuadState();
364 shared_state2_cmp->CopyFrom(shared_state2_in);
[email protected]cbe94b7a2013-11-13 11:03:37365
[email protected]3b85fd92014-07-10 00:00:02366 RenderPassDrawQuad* renderpass_in =
367 pass_in->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
danakj112d3a102015-04-14 18:24:49368 renderpass_in->SetAll(
369 shared_state2_in, arbitrary_rect1, arbitrary_rect2_inside_rect1,
370 arbitrary_rect1_inside_rect1, arbitrary_bool1, child_id,
371 arbitrary_resourceid2, arbitrary_vector2df1, arbitrary_size1,
372 arbitrary_filters1, arbitrary_vector2df2, arbitrary_filters2);
[email protected]3b85fd92014-07-10 00:00:02373 pass_cmp->CopyFromAndAppendRenderPassDrawQuad(
374 renderpass_in,
375 renderpass_in->shared_quad_state,
376 renderpass_in->render_pass_id);
[email protected]4934d362012-11-22 22:04:53377
[email protected]2b7f3892014-05-08 01:45:18378 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
danakj112d3a102015-04-14 18:24:49379 shared_state3_in->SetAll(arbitrary_matrix1, arbitrary_size3, arbitrary_rect3,
380 arbitrary_rect1, arbitrary_bool1, arbitrary_float3,
381 arbitrary_blend_mode3, arbitrary_context_id3);
[email protected]2b7f3892014-05-08 01:45:18382 SharedQuadState* shared_state3_cmp =
383 pass_cmp->CreateAndAppendSharedQuadState();
384 shared_state3_cmp->CopyFrom(shared_state3_in);
[email protected]4934d362012-11-22 22:04:53385
[email protected]3b85fd92014-07-10 00:00:02386 SolidColorDrawQuad* solidcolor_in =
387 pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18388 solidcolor_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53389 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30390 arbitrary_rect1_inside_rect3,
391 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53392 arbitrary_bool1,
[email protected]10a30b12013-05-02 16:42:11393 arbitrary_color,
394 arbitrary_bool2);
[email protected]3b85fd92014-07-10 00:00:02395 pass_cmp->CopyFromAndAppendDrawQuad(solidcolor_in,
396 solidcolor_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53397
[email protected]3b85fd92014-07-10 00:00:02398 StreamVideoDrawQuad* streamvideo_in =
399 pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
danakj112d3a102015-04-14 18:24:49400 streamvideo_in->SetAll(shared_state3_in, arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30401 arbitrary_rect2_inside_rect2,
danakj112d3a102015-04-14 18:24:49402 arbitrary_rect1_inside_rect2, arbitrary_bool1,
403 arbitrary_resourceid2, arbitrary_matrix1);
[email protected]3b85fd92014-07-10 00:00:02404 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
405 streamvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53406
[email protected]16a6af152014-06-13 04:20:16407 cc::SurfaceId arbitrary_surface_id(3);
[email protected]3b85fd92014-07-10 00:00:02408 SurfaceDrawQuad* surface_in =
409 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18410 surface_in->SetAll(shared_state3_in,
411 arbitrary_rect2,
412 arbitrary_rect2_inside_rect2,
413 arbitrary_rect1_inside_rect2,
414 arbitrary_bool1,
415 arbitrary_surface_id);
[email protected]3b85fd92014-07-10 00:00:02416 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
417 surface_in->shared_quad_state);
[email protected]78d30122014-01-17 06:32:36418
[email protected]3b85fd92014-07-10 00:00:02419 TextureDrawQuad* texture_in =
420 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18421 texture_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42422 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30423 arbitrary_rect2_inside_rect2,
424 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42425 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49426 arbitrary_resourceid1,
[email protected]61df9d82013-01-30 02:32:42427 arbitrary_bool2,
428 arbitrary_pointf1,
429 arbitrary_pointf2,
[email protected]d18b4d62013-07-12 05:33:49430 arbitrary_color,
[email protected]61df9d82013-01-30 02:32:42431 arbitrary_float_array,
jackhou10c9af42014-12-04 05:24:44432 arbitrary_bool3,
433 arbitrary_bool4);
[email protected]3b85fd92014-07-10 00:00:02434 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
435 texture_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42436
[email protected]3b85fd92014-07-10 00:00:02437 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18438 tile_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42439 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30440 arbitrary_rect2_inside_rect2,
441 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42442 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49443 arbitrary_resourceid3,
[email protected]61df9d82013-01-30 02:32:42444 arbitrary_rectf1,
445 arbitrary_size1,
jackhou24229612014-12-13 23:41:00446 arbitrary_bool2,
447 arbitrary_bool3);
[email protected]3b85fd92014-07-10 00:00:02448 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42449
[email protected]3b85fd92014-07-10 00:00:02450 YUVVideoDrawQuad* yuvvideo_in =
451 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
revemanb71e3992015-05-12 23:01:51452 yuvvideo_in->SetAll(
453 shared_state3_in, arbitrary_rect1, arbitrary_rect2_inside_rect1,
454 arbitrary_rect1_inside_rect1, arbitrary_bool1, arbitrary_rectf1,
455 arbitrary_rectf2, arbitrary_size1, arbitrary_size2, arbitrary_resourceid1,
456 arbitrary_resourceid2, arbitrary_resourceid3, arbitrary_resourceid4,
457 arbitrary_color_space);
[email protected]3b85fd92014-07-10 00:00:02458 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
459 yuvvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53460
461 // Make sure the in and cmp RenderPasses match.
danakj112d3a102015-04-14 18:24:49462 Compare(child_pass_cmp.get(), child_pass_in.get());
463 ASSERT_EQ(0u, child_pass_in->shared_quad_state_list.size());
464 ASSERT_EQ(0u, child_pass_in->quad_list.size());
[email protected]4934d362012-11-22 22:04:53465 Compare(pass_cmp.get(), pass_in.get());
466 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36467 ASSERT_EQ(10u, pass_in->quad_list.size());
weiliangc808f70f2014-10-03 22:53:15468 for (cc::SharedQuadStateList::ConstIterator
469 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
470 in_iterator = pass_in->shared_quad_state_list.begin();
471 in_iterator != pass_in->shared_quad_state_list.end();
472 ++cmp_iterator, ++in_iterator) {
weiliangc48805fce2014-10-29 20:30:12473 Compare(*cmp_iterator, *in_iterator);
[email protected]4934d362012-11-22 22:04:53474 }
weiliangc7eb7ee62014-10-07 00:04:40475 for (auto in_iter = pass_in->quad_list.cbegin(),
476 cmp_iter = pass_cmp->quad_list.cbegin();
477 in_iter != pass_in->quad_list.cend();
weiliangc032e929d2014-09-26 01:55:01478 ++in_iter, ++cmp_iter)
weiliangc48805fce2014-10-29 20:30:12479 Compare(*cmp_iter, *in_iter);
weiliangc032e929d2014-09-26 01:55:01480
[email protected]61df9d82013-01-30 02:32:42481 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53482 bool same_shared_quad_state_cmp =
weiliangc032e929d2014-09-26 01:55:01483 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
484 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53485 bool same_shared_quad_state_in =
weiliangc032e929d2014-09-26 01:55:01486 pass_in->quad_list.ElementAt(i)->shared_quad_state ==
487 pass_in->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53488 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
489 }
490
[email protected]bf189f62012-12-18 03:42:11491 DelegatedFrameData frame_in;
danakj112d3a102015-04-14 18:24:49492 frame_in.render_pass_list.push_back(child_pass_in.Pass());
[email protected]ead39c52013-01-09 07:22:45493 frame_in.render_pass_list.push_back(pass_in.Pass());
[email protected]4934d362012-11-22 22:04:53494
[email protected]bf189f62012-12-18 03:42:11495 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44496
[email protected]bf189f62012-12-18 03:42:11497 DelegatedFrameData frame_out;
[email protected]4934d362012-11-22 22:04:53498 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11499 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
500 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44501
[email protected]4934d362012-11-22 22:04:53502 // Make sure the out and cmp RenderPasses match.
danakj112d3a102015-04-14 18:24:49503 scoped_ptr<RenderPass> child_pass_out =
504 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
505 Compare(child_pass_cmp.get(), child_pass_out.get());
506 ASSERT_EQ(0u, child_pass_out->shared_quad_state_list.size());
507 ASSERT_EQ(0u, child_pass_out->quad_list.size());
508 scoped_ptr<RenderPass> pass_out =
509 frame_out.render_pass_list.take(frame_out.render_pass_list.begin() + 1);
[email protected]4934d362012-11-22 22:04:53510 Compare(pass_cmp.get(), pass_out.get());
511 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36512 ASSERT_EQ(10u, pass_out->quad_list.size());
weiliangc808f70f2014-10-03 22:53:15513 for (cc::SharedQuadStateList::ConstIterator
514 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
515 out_iterator = pass_out->shared_quad_state_list.begin();
516 out_iterator != pass_out->shared_quad_state_list.end();
517 ++cmp_iterator, ++out_iterator) {
weiliangc48805fce2014-10-29 20:30:12518 Compare(*cmp_iterator, *out_iterator);
[email protected]4934d362012-11-22 22:04:53519 }
weiliangc7eb7ee62014-10-07 00:04:40520 for (auto out_iter = pass_out->quad_list.cbegin(),
521 cmp_iter = pass_cmp->quad_list.cbegin();
522 out_iter != pass_out->quad_list.cend();
weiliangc032e929d2014-09-26 01:55:01523 ++out_iter, ++cmp_iter)
weiliangc48805fce2014-10-29 20:30:12524 Compare(*cmp_iter, *out_iter);
weiliangc032e929d2014-09-26 01:55:01525
[email protected]61df9d82013-01-30 02:32:42526 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53527 bool same_shared_quad_state_cmp =
weiliangc032e929d2014-09-26 01:55:01528 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
529 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53530 bool same_shared_quad_state_out =
weiliangc032e929d2014-09-26 01:55:01531 pass_out->quad_list.ElementAt(i)->shared_quad_state ==
532 pass_out->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53533 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
534 }
535}
[email protected]bca159072012-12-04 00:52:44536
[email protected]cbe94b7a2013-11-13 11:03:37537TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
[email protected]cbe94b7a2013-11-13 11:03:37538 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
[email protected]0cd7d6f72014-08-22 14:50:51539 pass_in->SetAll(RenderPassId(1, 1),
[email protected]cbe94b7a2013-11-13 11:03:37540 gfx::Rect(100, 100),
[email protected]b4ead7b2014-04-07 18:12:18541 gfx::Rect(),
[email protected]cbe94b7a2013-11-13 11:03:37542 gfx::Transform(),
[email protected]8590da32014-03-28 20:49:07543 false);
[email protected]cbe94b7a2013-11-13 11:03:37544
545 // The first SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18546 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
[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,
[email protected]a9d4d4f2014-06-19 06:49:28553 SkXfermode::kSrcOver_Mode,
554 0);
[email protected]cbe94b7a2013-11-13 11:03:37555
[email protected]3b85fd92014-07-10 00:00:02556 CheckerboardDrawQuad* quad1 =
557 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
danakje1419ce2015-03-04 21:26:27558 quad1->SetAll(shared_state1_in, gfx::Rect(10, 10), gfx::Rect(10, 10),
559 gfx::Rect(10, 10), false, SK_ColorRED, 1.f);
[email protected]cbe94b7a2013-11-13 11:03:37560
561 // The second and third SharedQuadStates are not used.
[email protected]2b7f3892014-05-08 01:45:18562 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22563 shared_state2_in->SetAll(gfx::Transform(),
564 gfx::Size(2, 2),
565 gfx::Rect(),
566 gfx::Rect(),
567 false,
568 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28569 SkXfermode::kSrcOver_Mode,
570 0);
[email protected]cbe94b7a2013-11-13 11:03:37571
[email protected]2b7f3892014-05-08 01:45:18572 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22573 shared_state3_in->SetAll(gfx::Transform(),
574 gfx::Size(3, 3),
575 gfx::Rect(),
576 gfx::Rect(),
577 false,
578 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28579 SkXfermode::kSrcOver_Mode,
580 0);
[email protected]cbe94b7a2013-11-13 11:03:37581
582 // The fourth SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18583 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22584 shared_state4_in->SetAll(gfx::Transform(),
585 gfx::Size(4, 4),
586 gfx::Rect(),
587 gfx::Rect(),
588 false,
589 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28590 SkXfermode::kSrcOver_Mode,
591 0);
[email protected]cbe94b7a2013-11-13 11:03:37592
[email protected]3b85fd92014-07-10 00:00:02593 CheckerboardDrawQuad* quad2 =
594 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
danakje1419ce2015-03-04 21:26:27595 quad2->SetAll(shared_state4_in, gfx::Rect(10, 10), gfx::Rect(10, 10),
596 gfx::Rect(10, 10), false, SK_ColorRED, 1.f);
[email protected]cbe94b7a2013-11-13 11:03:37597
598 // The fifth is not used again.
[email protected]2b7f3892014-05-08 01:45:18599 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22600 shared_state5_in->SetAll(gfx::Transform(),
601 gfx::Size(5, 5),
602 gfx::Rect(),
603 gfx::Rect(),
604 false,
605 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28606 SkXfermode::kSrcOver_Mode,
607 0);
[email protected]cbe94b7a2013-11-13 11:03:37608
[email protected]cbe94b7a2013-11-13 11:03:37609 // 5 SharedQuadStates go in.
610 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
611 ASSERT_EQ(2u, pass_in->quad_list.size());
612
613 DelegatedFrameData frame_in;
614 frame_in.render_pass_list.push_back(pass_in.Pass());
615
616 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
617 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
618
619 DelegatedFrameData frame_out;
620 PickleIterator iter(msg);
621 EXPECT_TRUE(
622 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
623
624 scoped_ptr<RenderPass> pass_out =
625 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
626
627 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
628 // used by quads, and so serialized. Others were not.
629 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
630 ASSERT_EQ(2u, pass_out->quad_list.size());
631
weiliangc808f70f2014-10-03 22:53:15632 EXPECT_EQ(
633 gfx::Size(1, 1).ToString(),
634 pass_out->shared_quad_state_list.ElementAt(0)->content_bounds.ToString());
635 EXPECT_EQ(
636 gfx::Size(4, 4).ToString(),
637 pass_out->shared_quad_state_list.ElementAt(1)->content_bounds.ToString());
[email protected]cbe94b7a2013-11-13 11:03:37638}
639
[email protected]bca159072012-12-04 00:52:44640TEST_F(CCMessagesTest, Resources) {
[email protected]753bb252013-11-04 22:28:12641 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]bca159072012-12-04 00:52:44642 gfx::Size arbitrary_size(757, 1281);
[email protected]09831f7f2013-02-27 03:32:15643 unsigned int arbitrary_uint1 = 71234838;
644 unsigned int arbitrary_uint2 = 53589793;
[email protected]bca159072012-12-04 00:52:44645
[email protected]e0a4d732014-02-15 00:23:26646 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
647 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
648 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
649 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:44650
[email protected]e0a4d732014-02-15 00:23:26651 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
652 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
653 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
654 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:44655
656 TransferableResource arbitrary_resource1;
657 arbitrary_resource1.id = 2178312;
[email protected]27a41fe2013-09-19 05:05:14658 arbitrary_resource1.format = cc::RGBA_8888;
[email protected]80189292013-02-28 01:59:36659 arbitrary_resource1.filter = 53;
[email protected]bca159072012-12-04 00:52:44660 arbitrary_resource1.size = gfx::Size(37189, 123123);
[email protected]df41e252014-02-03 23:39:50661 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
662 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
663 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
[email protected]a8c63be22014-08-07 02:39:49664 arbitrary_resource1.allow_overlay = true;
[email protected]bca159072012-12-04 00:52:44665
666 TransferableResource arbitrary_resource2;
667 arbitrary_resource2.id = 789132;
[email protected]27a41fe2013-09-19 05:05:14668 arbitrary_resource2.format = cc::RGBA_4444;
[email protected]645a47f22013-09-26 05:42:32669 arbitrary_resource2.filter = 47;
[email protected]bca159072012-12-04 00:52:44670 arbitrary_resource2.size = gfx::Size(89123, 23789);
[email protected]df41e252014-02-03 23:39:50671 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
672 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
673 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
[email protected]a8c63be22014-08-07 02:39:49674 arbitrary_resource2.allow_overlay = false;
[email protected]bca159072012-12-04 00:52:44675
[email protected]cb7d6492013-10-03 02:40:04676 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
677 renderpass_in->SetNew(
[email protected]0cd7d6f72014-08-22 14:50:51678 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
[email protected]cb7d6492013-10-03 02:40:04679
[email protected]bf189f62012-12-18 03:42:11680 DelegatedFrameData frame_in;
[email protected]09831f7f2013-02-27 03:32:15681 frame_in.resource_list.push_back(arbitrary_resource1);
682 frame_in.resource_list.push_back(arbitrary_resource2);
[email protected]cb7d6492013-10-03 02:40:04683 frame_in.render_pass_list.push_back(renderpass_in.Pass());
[email protected]bca159072012-12-04 00:52:44684
[email protected]bf189f62012-12-18 03:42:11685 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44686
[email protected]bf189f62012-12-18 03:42:11687 DelegatedFrameData frame_out;
[email protected]bca159072012-12-04 00:52:44688 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11689 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
690 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44691
[email protected]09831f7f2013-02-27 03:32:15692 ASSERT_EQ(2u, frame_out.resource_list.size());
693 Compare(arbitrary_resource1, frame_out.resource_list[0]);
694 Compare(arbitrary_resource2, frame_out.resource_list[1]);
[email protected]bca159072012-12-04 00:52:44695}
696
[email protected]cecc8342014-03-20 21:43:39697TEST_F(CCMessagesTest, SoftwareFrameData) {
698 cc::SoftwareFrameData frame_in;
699 frame_in.id = 3;
700 frame_in.size = gfx::Size(40, 20);
701 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56702 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39703
704 // Write the frame.
705 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
706 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
707
708 // Read the frame.
709 cc::SoftwareFrameData frame_out;
710 PickleIterator iter(msg);
711 EXPECT_TRUE(
712 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
713 EXPECT_EQ(frame_in.id, frame_out.id);
714 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
715 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
[email protected]f1970082014-04-09 04:29:56716 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39717}
718
719TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
720 SoftwareFrameData frame_in;
721 frame_in.id = 3;
722 frame_in.size = gfx::Size(40, 20);
723 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56724 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39725
726 // Write the SoftwareFrameData by hand, make sure it works.
727 {
728 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
729 IPC::WriteParam(&msg, frame_in.id);
730 IPC::WriteParam(&msg, frame_in.size);
731 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56732 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39733 SoftwareFrameData frame_out;
734 PickleIterator iter(msg);
735 EXPECT_TRUE(
736 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
737 }
738
739 // The size of the frame may overflow when multiplied together.
740 int max = std::numeric_limits<int>::max();
741 frame_in.size = gfx::Size(max, max);
742
743 // If size_t is larger than int, then int*int*4 can always fit in size_t.
744 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
745
746 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
747 // should fail.
748 {
749 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
750 IPC::WriteParam(&msg, frame_in.id);
751 IPC::WriteParam(&msg, frame_in.size);
752 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56753 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39754 SoftwareFrameData frame_out;
755 PickleIterator iter(msg);
756 EXPECT_EQ(
757 expect_read,
758 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
759 }
760}
761
[email protected]bca159072012-12-04 00:52:44762} // namespace
763} // namespace content