blob: fa4d7fb0de485dfc146208eb669e8b7b4fdb9c5a [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;
33using cc::ResourceProvider;
34using cc::SharedQuadState;
[email protected]cecc8342014-03-20 21:43:3935using cc::SoftwareFrameData;
[email protected]4934d362012-11-22 22:04:5336using cc::SolidColorDrawQuad;
[email protected]78d30122014-01-17 06:32:3637using cc::SurfaceDrawQuad;
[email protected]4934d362012-11-22 22:04:5338using cc::TextureDrawQuad;
39using cc::TileDrawQuad;
[email protected]bca159072012-12-04 00:52:4440using cc::TransferableResource;
[email protected]4934d362012-11-22 22:04:5341using cc::StreamVideoDrawQuad;
[email protected]4934d362012-11-22 22:04:5342using 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]a9d4d4f2014-06-19 06:49:2866 EXPECT_EQ(a->sorting_context_id, b->sorting_context_id);
[email protected]4934d362012-11-22 22:04:5367 }
68
69 void Compare(const DrawQuad* a, const DrawQuad* b) {
70 ASSERT_NE(DrawQuad::INVALID, a->material);
71 ASSERT_EQ(a->material, b->material);
72 EXPECT_EQ(a->rect.ToString(), b->rect.ToString());
73 EXPECT_EQ(a->opaque_rect.ToString(), b->opaque_rect.ToString());
74 EXPECT_EQ(a->visible_rect.ToString(), b->visible_rect.ToString());
75 EXPECT_EQ(a->needs_blending, b->needs_blending);
76
77 Compare(a->shared_quad_state, b->shared_quad_state);
78
79 switch (a->material) {
80 case DrawQuad::CHECKERBOARD:
81 Compare(CheckerboardDrawQuad::MaterialCast(a),
82 CheckerboardDrawQuad::MaterialCast(b));
83 break;
84 case DrawQuad::DEBUG_BORDER:
85 Compare(DebugBorderDrawQuad::MaterialCast(a),
86 DebugBorderDrawQuad::MaterialCast(b));
87 break;
88 case DrawQuad::IO_SURFACE_CONTENT:
89 Compare(IOSurfaceDrawQuad::MaterialCast(a),
90 IOSurfaceDrawQuad::MaterialCast(b));
91 break;
[email protected]9ee4d3a2013-03-27 17:43:1692 case DrawQuad::PICTURE_CONTENT:
93 Compare(PictureDrawQuad::MaterialCast(a),
94 PictureDrawQuad::MaterialCast(b));
95 break;
[email protected]4934d362012-11-22 22:04:5396 case DrawQuad::RENDER_PASS:
97 Compare(RenderPassDrawQuad::MaterialCast(a),
98 RenderPassDrawQuad::MaterialCast(b));
99 break;
100 case DrawQuad::TEXTURE_CONTENT:
101 Compare(TextureDrawQuad::MaterialCast(a),
102 TextureDrawQuad::MaterialCast(b));
103 break;
104 case DrawQuad::TILED_CONTENT:
105 Compare(TileDrawQuad::MaterialCast(a),
106 TileDrawQuad::MaterialCast(b));
107 break;
108 case DrawQuad::SOLID_COLOR:
109 Compare(SolidColorDrawQuad::MaterialCast(a),
110 SolidColorDrawQuad::MaterialCast(b));
111 break;
112 case DrawQuad::STREAM_VIDEO_CONTENT:
113 Compare(StreamVideoDrawQuad::MaterialCast(a),
114 StreamVideoDrawQuad::MaterialCast(b));
115 break;
[email protected]78d30122014-01-17 06:32:36116 case DrawQuad::SURFACE_CONTENT:
117 Compare(SurfaceDrawQuad::MaterialCast(a),
118 SurfaceDrawQuad::MaterialCast(b));
119 break;
[email protected]4934d362012-11-22 22:04:53120 case DrawQuad::YUV_VIDEO_CONTENT:
121 Compare(YUVVideoDrawQuad::MaterialCast(a),
122 YUVVideoDrawQuad::MaterialCast(b));
123 break;
124 case DrawQuad::INVALID:
125 break;
126 }
127 }
128
129 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) {
130 EXPECT_EQ(a->color, b->color);
danakje1419ce2015-03-04 21:26:27131 EXPECT_EQ(a->scale, b->scale);
[email protected]4934d362012-11-22 22:04:53132 }
133
134 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
135 EXPECT_EQ(a->color, b->color);
136 EXPECT_EQ(a->width, b->width);
137 }
138
139 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
140 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
[email protected]b7cfc632013-04-10 04:44:49141 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
[email protected]4934d362012-11-22 22:04:53142 EXPECT_EQ(a->orientation, b->orientation);
143 }
144
145 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
[email protected]82f93fb2013-04-17 21:42:06146 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
[email protected]4934d362012-11-22 22:04:53147 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id);
ennef6f3fbba42014-10-16 18:16:49148 EXPECT_EQ(a->mask_uv_scale.ToString(), b->mask_uv_scale.ToString());
149 EXPECT_EQ(a->mask_texture_size.ToString(), b->mask_texture_size.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]7ac3d492014-08-08 21:25:32160 EXPECT_EQ(a->filters_scale, b->filters_scale);
[email protected]20062042012-12-21 22:16:36161 EXPECT_EQ(a->background_filters, b->background_filters);
[email protected]4934d362012-11-22 22:04:53162 }
163
164 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
165 EXPECT_EQ(a->color, b->color);
[email protected]10a30b12013-05-02 16:42:11166 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
[email protected]4934d362012-11-22 22:04:53167 }
168
169 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
[email protected]b7cfc632013-04-10 04:44:49170 EXPECT_EQ(a->resource_id, b->resource_id);
[email protected]4934d362012-11-22 22:04:53171 EXPECT_EQ(a->matrix, b->matrix);
172 }
173
[email protected]78d30122014-01-17 06:32:36174 void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
175 EXPECT_EQ(a->surface_id, b->surface_id);
176 }
177
[email protected]4934d362012-11-22 22:04:53178 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
179 EXPECT_EQ(a->resource_id, b->resource_id);
180 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha);
[email protected]1fd555b2013-01-18 00:13:21181 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
182 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
[email protected]d18b4d62013-07-12 05:33:49183 EXPECT_EQ(a->background_color, b->background_color);
[email protected]61df9d82013-01-30 02:32:42184 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]);
185 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]);
186 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]);
187 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]);
[email protected]4934d362012-11-22 22:04:53188 EXPECT_EQ(a->flipped, b->flipped);
jackhou10c9af42014-12-04 05:24:44189 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
[email protected]4934d362012-11-22 22:04:53190 }
191
192 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
193 EXPECT_EQ(a->resource_id, b->resource_id);
194 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
195 EXPECT_EQ(a->texture_size, b->texture_size);
196 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
jackhou24229612014-12-13 23:41:00197 EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
[email protected]4934d362012-11-22 22:04:53198 }
199
200 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
[email protected]95052aa2014-03-27 11:43:50201 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
magjed7364ff92015-03-27 09:11:08202 EXPECT_EQ(a->ya_tex_size, b->ya_tex_size);
203 EXPECT_EQ(a->uv_tex_size, b->uv_tex_size);
[email protected]b7cfc632013-04-10 04:44:49204 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id);
205 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id);
206 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id);
[email protected]0402b2382013-06-07 21:50:54207 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
[email protected]82faf5e2014-05-03 02:25:58208 EXPECT_EQ(a->color_space, b->color_space);
[email protected]4934d362012-11-22 22:04:53209 }
[email protected]bca159072012-12-04 00:52:44210
211 void Compare(const TransferableResource& a, const TransferableResource& b) {
212 EXPECT_EQ(a.id, b.id);
213 EXPECT_EQ(a.format, b.format);
[email protected]80189292013-02-28 01:59:36214 EXPECT_EQ(a.filter, b.filter);
[email protected]bca159072012-12-04 00:52:44215 EXPECT_EQ(a.size.ToString(), b.size.ToString());
[email protected]df41e252014-02-03 23:39:50216 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
217 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
218 b.mailbox_holder.mailbox.name[i]);
219 }
220 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
221 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
[email protected]a8c63be22014-08-07 02:39:49222 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
[email protected]bca159072012-12-04 00:52:44223 }
[email protected]4934d362012-11-22 22:04:53224};
225
226TEST_F(CCMessagesTest, AllQuads) {
[email protected]753bb252013-11-04 22:28:12227 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]4934d362012-11-22 22:04:53228
danakj112d3a102015-04-14 18:24:49229 Transform arbitrary_matrix1;
230 arbitrary_matrix1.Scale(3, 3);
231 arbitrary_matrix1.Translate(-5, 20);
232 arbitrary_matrix1.Rotate(15);
233 Transform arbitrary_matrix2;
234 arbitrary_matrix2.Scale(10, -1);
235 arbitrary_matrix2.Translate(20, 3);
236 arbitrary_matrix2.Rotate(24);
[email protected]4934d362012-11-22 22:04:53237 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
[email protected]8e1da692013-10-12 17:11:30238 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
239 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
[email protected]4934d362012-11-22 22:04:53240 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
[email protected]8e1da692013-10-12 17:11:30241 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
242 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
[email protected]4934d362012-11-22 22:04:53243 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
[email protected]8e1da692013-10-12 17:11:30244 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
245 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
[email protected]4934d362012-11-22 22:04:53246 gfx::Size arbitrary_size1(15, 19);
247 gfx::Size arbitrary_size2(3, 99);
248 gfx::Size arbitrary_size3(75, 1281);
249 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
250 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
[email protected]61df9d82013-01-30 02:32:42251 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
252 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
[email protected]7ac3d492014-08-08 21:25:32253 gfx::Vector2dF arbitrary_vector2df1(16.2f, -85.1f);
ennef6f3fbba42014-10-16 18:16:49254 gfx::Vector2dF arbitrary_vector2df2(-8.3f, 0.47f);
[email protected]4934d362012-11-22 22:04:53255 float arbitrary_float1 = 0.7f;
256 float arbitrary_float2 = 0.3f;
257 float arbitrary_float3 = 0.9f;
[email protected]61df9d82013-01-30 02:32:42258 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
[email protected]4934d362012-11-22 22:04:53259 bool arbitrary_bool1 = true;
260 bool arbitrary_bool2 = false;
[email protected]61df9d82013-01-30 02:32:42261 bool arbitrary_bool3 = true;
jackhou10c9af42014-12-04 05:24:44262 bool arbitrary_bool4 = true;
[email protected]a9d4d4f2014-06-19 06:49:28263 int arbitrary_context_id1 = 12;
264 int arbitrary_context_id2 = 57;
265 int arbitrary_context_id3 = -503;
[email protected]4934d362012-11-22 22:04:53266 int arbitrary_int = 5;
267 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
[email protected]7bbeaf4e2013-11-26 10:27:22268 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
269 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
270 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
[email protected]4934d362012-11-22 22:04:53271 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
272 IOSurfaceDrawQuad::UNFLIPPED;
[email protected]b7cfc632013-04-10 04:44:49273 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
274 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
275 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
[email protected]0402b2382013-06-07 21:50:54276 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
[email protected]a1765672013-08-12 23:45:02277 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
[email protected]82faf5e2014-05-03 02:25:58278 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
279 YUVVideoDrawQuad::REC_601;
[email protected]4934d362012-11-22 22:04:53280
danakj112d3a102015-04-14 18:24:49281 RenderPassId child_id(30, 5);
282 RenderPassId root_id(10, 14);
283
[email protected]ae6b1a72013-06-25 18:49:29284 FilterOperations arbitrary_filters1;
285 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
[email protected]4934d362012-11-22 22:04:53286 arbitrary_float1));
[email protected]1dc7943e2013-09-26 04:41:48287 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
[email protected]bb209bf2014-05-11 00:37:11288 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
[email protected]1dc7943e2013-09-26 04:41:48289 arbitrary_filters1.Append(
290 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
[email protected]4934d362012-11-22 22:04:53291
[email protected]ae6b1a72013-06-25 18:49:29292 FilterOperations arbitrary_filters2;
293 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
[email protected]4934d362012-11-22 22:04:53294 arbitrary_float2));
295
danakj112d3a102015-04-14 18:24:49296 scoped_ptr<RenderPass> child_pass_in = RenderPass::Create();
297 child_pass_in->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
298 arbitrary_matrix2, arbitrary_bool2);
299
300 scoped_ptr<RenderPass> child_pass_cmp = RenderPass::Create();
301 child_pass_cmp->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
302 arbitrary_matrix2, arbitrary_bool2);
303
[email protected]2b7f3892014-05-08 01:45:18304 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
danakj112d3a102015-04-14 18:24:49305 pass_in->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
[email protected]2b7f3892014-05-08 01:45:18306 arbitrary_bool1);
307
308 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
danakj112d3a102015-04-14 18:24:49309 shared_state1_in->SetAll(arbitrary_matrix1, arbitrary_size1, arbitrary_rect1,
310 arbitrary_rect2, arbitrary_bool1, arbitrary_float1,
311 arbitrary_blend_mode1, arbitrary_context_id1);
[email protected]2b7f3892014-05-08 01:45:18312
313 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
danakj112d3a102015-04-14 18:24:49314 pass_cmp->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
[email protected]2b7f3892014-05-08 01:45:18315 arbitrary_bool1);
316
317 SharedQuadState* shared_state1_cmp =
318 pass_cmp->CreateAndAppendSharedQuadState();
319 shared_state1_cmp->CopyFrom(shared_state1_in);
[email protected]4934d362012-11-22 22:04:53320
[email protected]3b85fd92014-07-10 00:00:02321 CheckerboardDrawQuad* checkerboard_in =
322 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
danakje1419ce2015-03-04 21:26:27323 checkerboard_in->SetAll(shared_state1_in, arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30324 arbitrary_rect2_inside_rect1,
danakje1419ce2015-03-04 21:26:27325 arbitrary_rect1_inside_rect1, arbitrary_bool1,
326 arbitrary_color, arbitrary_float1);
[email protected]3b85fd92014-07-10 00:00:02327 pass_cmp->CopyFromAndAppendDrawQuad(checkerboard_in,
328 checkerboard_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53329
[email protected]3b85fd92014-07-10 00:00:02330 DebugBorderDrawQuad* debugborder_in =
331 pass_in->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18332 debugborder_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53333 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30334 arbitrary_rect1_inside_rect3,
335 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53336 arbitrary_bool1,
337 arbitrary_color,
338 arbitrary_int);
[email protected]3b85fd92014-07-10 00:00:02339 pass_cmp->CopyFromAndAppendDrawQuad(debugborder_in,
340 debugborder_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53341
[email protected]3b85fd92014-07-10 00:00:02342 IOSurfaceDrawQuad* iosurface_in =
343 pass_in->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18344 iosurface_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53345 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30346 arbitrary_rect2_inside_rect2,
347 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53348 arbitrary_bool1,
349 arbitrary_size1,
[email protected]b7cfc632013-04-10 04:44:49350 arbitrary_resourceid3,
[email protected]4934d362012-11-22 22:04:53351 arbitrary_orientation);
[email protected]3b85fd92014-07-10 00:00:02352 pass_cmp->CopyFromAndAppendDrawQuad(iosurface_in,
353 iosurface_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53354
[email protected]2b7f3892014-05-08 01:45:18355 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
danakj112d3a102015-04-14 18:24:49356 shared_state2_in->SetAll(arbitrary_matrix2, arbitrary_size2, arbitrary_rect2,
357 arbitrary_rect3, arbitrary_bool1, arbitrary_float2,
358 arbitrary_blend_mode2, arbitrary_context_id2);
[email protected]2b7f3892014-05-08 01:45:18359 SharedQuadState* shared_state2_cmp =
360 pass_cmp->CreateAndAppendSharedQuadState();
361 shared_state2_cmp->CopyFrom(shared_state2_in);
[email protected]cbe94b7a2013-11-13 11:03:37362
[email protected]3b85fd92014-07-10 00:00:02363 RenderPassDrawQuad* renderpass_in =
364 pass_in->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
danakj112d3a102015-04-14 18:24:49365 renderpass_in->SetAll(
366 shared_state2_in, arbitrary_rect1, arbitrary_rect2_inside_rect1,
367 arbitrary_rect1_inside_rect1, arbitrary_bool1, child_id,
368 arbitrary_resourceid2, arbitrary_vector2df1, arbitrary_size1,
369 arbitrary_filters1, arbitrary_vector2df2, arbitrary_filters2);
[email protected]3b85fd92014-07-10 00:00:02370 pass_cmp->CopyFromAndAppendRenderPassDrawQuad(
371 renderpass_in,
372 renderpass_in->shared_quad_state,
373 renderpass_in->render_pass_id);
[email protected]4934d362012-11-22 22:04:53374
[email protected]2b7f3892014-05-08 01:45:18375 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
danakj112d3a102015-04-14 18:24:49376 shared_state3_in->SetAll(arbitrary_matrix1, arbitrary_size3, arbitrary_rect3,
377 arbitrary_rect1, arbitrary_bool1, arbitrary_float3,
378 arbitrary_blend_mode3, arbitrary_context_id3);
[email protected]2b7f3892014-05-08 01:45:18379 SharedQuadState* shared_state3_cmp =
380 pass_cmp->CreateAndAppendSharedQuadState();
381 shared_state3_cmp->CopyFrom(shared_state3_in);
[email protected]4934d362012-11-22 22:04:53382
[email protected]3b85fd92014-07-10 00:00:02383 SolidColorDrawQuad* solidcolor_in =
384 pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18385 solidcolor_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53386 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30387 arbitrary_rect1_inside_rect3,
388 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53389 arbitrary_bool1,
[email protected]10a30b12013-05-02 16:42:11390 arbitrary_color,
391 arbitrary_bool2);
[email protected]3b85fd92014-07-10 00:00:02392 pass_cmp->CopyFromAndAppendDrawQuad(solidcolor_in,
393 solidcolor_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53394
[email protected]3b85fd92014-07-10 00:00:02395 StreamVideoDrawQuad* streamvideo_in =
396 pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
danakj112d3a102015-04-14 18:24:49397 streamvideo_in->SetAll(shared_state3_in, arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30398 arbitrary_rect2_inside_rect2,
danakj112d3a102015-04-14 18:24:49399 arbitrary_rect1_inside_rect2, arbitrary_bool1,
400 arbitrary_resourceid2, arbitrary_matrix1);
[email protected]3b85fd92014-07-10 00:00:02401 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
402 streamvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53403
[email protected]16a6af152014-06-13 04:20:16404 cc::SurfaceId arbitrary_surface_id(3);
[email protected]3b85fd92014-07-10 00:00:02405 SurfaceDrawQuad* surface_in =
406 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18407 surface_in->SetAll(shared_state3_in,
408 arbitrary_rect2,
409 arbitrary_rect2_inside_rect2,
410 arbitrary_rect1_inside_rect2,
411 arbitrary_bool1,
412 arbitrary_surface_id);
[email protected]3b85fd92014-07-10 00:00:02413 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
414 surface_in->shared_quad_state);
[email protected]78d30122014-01-17 06:32:36415
[email protected]3b85fd92014-07-10 00:00:02416 TextureDrawQuad* texture_in =
417 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18418 texture_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42419 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30420 arbitrary_rect2_inside_rect2,
421 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42422 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49423 arbitrary_resourceid1,
[email protected]61df9d82013-01-30 02:32:42424 arbitrary_bool2,
425 arbitrary_pointf1,
426 arbitrary_pointf2,
[email protected]d18b4d62013-07-12 05:33:49427 arbitrary_color,
[email protected]61df9d82013-01-30 02:32:42428 arbitrary_float_array,
jackhou10c9af42014-12-04 05:24:44429 arbitrary_bool3,
430 arbitrary_bool4);
[email protected]3b85fd92014-07-10 00:00:02431 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
432 texture_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42433
[email protected]3b85fd92014-07-10 00:00:02434 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18435 tile_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42436 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30437 arbitrary_rect2_inside_rect2,
438 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42439 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49440 arbitrary_resourceid3,
[email protected]61df9d82013-01-30 02:32:42441 arbitrary_rectf1,
442 arbitrary_size1,
jackhou24229612014-12-13 23:41:00443 arbitrary_bool2,
444 arbitrary_bool3);
[email protected]3b85fd92014-07-10 00:00:02445 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42446
[email protected]3b85fd92014-07-10 00:00:02447 YUVVideoDrawQuad* yuvvideo_in =
448 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18449 yuvvideo_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53450 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30451 arbitrary_rect2_inside_rect1,
452 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53453 arbitrary_bool1,
[email protected]95052aa2014-03-27 11:43:50454 arbitrary_rectf1,
ennea2a29702015-02-02 22:21:21455 arbitrary_size1,
magjed7364ff92015-03-27 09:11:08456 arbitrary_size2,
[email protected]b7cfc632013-04-10 04:44:49457 arbitrary_resourceid1,
458 arbitrary_resourceid2,
[email protected]0402b2382013-06-07 21:50:54459 arbitrary_resourceid3,
[email protected]82faf5e2014-05-03 02:25:58460 arbitrary_resourceid4,
461 arbitrary_color_space);
[email protected]3b85fd92014-07-10 00:00:02462 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
463 yuvvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53464
465 // Make sure the in and cmp RenderPasses match.
danakj112d3a102015-04-14 18:24:49466 Compare(child_pass_cmp.get(), child_pass_in.get());
467 ASSERT_EQ(0u, child_pass_in->shared_quad_state_list.size());
468 ASSERT_EQ(0u, child_pass_in->quad_list.size());
[email protected]4934d362012-11-22 22:04:53469 Compare(pass_cmp.get(), pass_in.get());
470 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36471 ASSERT_EQ(10u, pass_in->quad_list.size());
weiliangc808f70f2014-10-03 22:53:15472 for (cc::SharedQuadStateList::ConstIterator
473 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
474 in_iterator = pass_in->shared_quad_state_list.begin();
475 in_iterator != pass_in->shared_quad_state_list.end();
476 ++cmp_iterator, ++in_iterator) {
weiliangc48805fce2014-10-29 20:30:12477 Compare(*cmp_iterator, *in_iterator);
[email protected]4934d362012-11-22 22:04:53478 }
weiliangc7eb7ee62014-10-07 00:04:40479 for (auto in_iter = pass_in->quad_list.cbegin(),
480 cmp_iter = pass_cmp->quad_list.cbegin();
481 in_iter != pass_in->quad_list.cend();
weiliangc032e929d2014-09-26 01:55:01482 ++in_iter, ++cmp_iter)
weiliangc48805fce2014-10-29 20:30:12483 Compare(*cmp_iter, *in_iter);
weiliangc032e929d2014-09-26 01:55:01484
[email protected]61df9d82013-01-30 02:32:42485 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53486 bool same_shared_quad_state_cmp =
weiliangc032e929d2014-09-26 01:55:01487 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
488 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53489 bool same_shared_quad_state_in =
weiliangc032e929d2014-09-26 01:55:01490 pass_in->quad_list.ElementAt(i)->shared_quad_state ==
491 pass_in->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53492 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
493 }
494
[email protected]bf189f62012-12-18 03:42:11495 DelegatedFrameData frame_in;
danakj112d3a102015-04-14 18:24:49496 frame_in.render_pass_list.push_back(child_pass_in.Pass());
[email protected]ead39c52013-01-09 07:22:45497 frame_in.render_pass_list.push_back(pass_in.Pass());
[email protected]4934d362012-11-22 22:04:53498
[email protected]bf189f62012-12-18 03:42:11499 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44500
[email protected]bf189f62012-12-18 03:42:11501 DelegatedFrameData frame_out;
[email protected]4934d362012-11-22 22:04:53502 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11503 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
504 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44505
[email protected]4934d362012-11-22 22:04:53506 // Make sure the out and cmp RenderPasses match.
danakj112d3a102015-04-14 18:24:49507 scoped_ptr<RenderPass> child_pass_out =
508 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
509 Compare(child_pass_cmp.get(), child_pass_out.get());
510 ASSERT_EQ(0u, child_pass_out->shared_quad_state_list.size());
511 ASSERT_EQ(0u, child_pass_out->quad_list.size());
512 scoped_ptr<RenderPass> pass_out =
513 frame_out.render_pass_list.take(frame_out.render_pass_list.begin() + 1);
[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());
weiliangc808f70f2014-10-03 22:53:15517 for (cc::SharedQuadStateList::ConstIterator
518 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
519 out_iterator = pass_out->shared_quad_state_list.begin();
520 out_iterator != pass_out->shared_quad_state_list.end();
521 ++cmp_iterator, ++out_iterator) {
weiliangc48805fce2014-10-29 20:30:12522 Compare(*cmp_iterator, *out_iterator);
[email protected]4934d362012-11-22 22:04:53523 }
weiliangc7eb7ee62014-10-07 00:04:40524 for (auto out_iter = pass_out->quad_list.cbegin(),
525 cmp_iter = pass_cmp->quad_list.cbegin();
526 out_iter != pass_out->quad_list.cend();
weiliangc032e929d2014-09-26 01:55:01527 ++out_iter, ++cmp_iter)
weiliangc48805fce2014-10-29 20:30:12528 Compare(*cmp_iter, *out_iter);
weiliangc032e929d2014-09-26 01:55:01529
[email protected]61df9d82013-01-30 02:32:42530 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53531 bool same_shared_quad_state_cmp =
weiliangc032e929d2014-09-26 01:55:01532 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
533 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53534 bool same_shared_quad_state_out =
weiliangc032e929d2014-09-26 01:55:01535 pass_out->quad_list.ElementAt(i)->shared_quad_state ==
536 pass_out->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53537 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
538 }
539}
[email protected]bca159072012-12-04 00:52:44540
[email protected]cbe94b7a2013-11-13 11:03:37541TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
[email protected]cbe94b7a2013-11-13 11:03:37542 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
[email protected]0cd7d6f72014-08-22 14:50:51543 pass_in->SetAll(RenderPassId(1, 1),
[email protected]cbe94b7a2013-11-13 11:03:37544 gfx::Rect(100, 100),
[email protected]b4ead7b2014-04-07 18:12:18545 gfx::Rect(),
[email protected]cbe94b7a2013-11-13 11:03:37546 gfx::Transform(),
[email protected]8590da32014-03-28 20:49:07547 false);
[email protected]cbe94b7a2013-11-13 11:03:37548
549 // The first SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18550 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22551 shared_state1_in->SetAll(gfx::Transform(),
552 gfx::Size(1, 1),
553 gfx::Rect(),
554 gfx::Rect(),
555 false,
556 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28557 SkXfermode::kSrcOver_Mode,
558 0);
[email protected]cbe94b7a2013-11-13 11:03:37559
[email protected]3b85fd92014-07-10 00:00:02560 CheckerboardDrawQuad* quad1 =
561 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
danakje1419ce2015-03-04 21:26:27562 quad1->SetAll(shared_state1_in, gfx::Rect(10, 10), gfx::Rect(10, 10),
563 gfx::Rect(10, 10), false, SK_ColorRED, 1.f);
[email protected]cbe94b7a2013-11-13 11:03:37564
565 // The second and third SharedQuadStates are not used.
[email protected]2b7f3892014-05-08 01:45:18566 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22567 shared_state2_in->SetAll(gfx::Transform(),
568 gfx::Size(2, 2),
569 gfx::Rect(),
570 gfx::Rect(),
571 false,
572 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28573 SkXfermode::kSrcOver_Mode,
574 0);
[email protected]cbe94b7a2013-11-13 11:03:37575
[email protected]2b7f3892014-05-08 01:45:18576 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22577 shared_state3_in->SetAll(gfx::Transform(),
578 gfx::Size(3, 3),
579 gfx::Rect(),
580 gfx::Rect(),
581 false,
582 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28583 SkXfermode::kSrcOver_Mode,
584 0);
[email protected]cbe94b7a2013-11-13 11:03:37585
586 // The fourth SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18587 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22588 shared_state4_in->SetAll(gfx::Transform(),
589 gfx::Size(4, 4),
590 gfx::Rect(),
591 gfx::Rect(),
592 false,
593 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28594 SkXfermode::kSrcOver_Mode,
595 0);
[email protected]cbe94b7a2013-11-13 11:03:37596
[email protected]3b85fd92014-07-10 00:00:02597 CheckerboardDrawQuad* quad2 =
598 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
danakje1419ce2015-03-04 21:26:27599 quad2->SetAll(shared_state4_in, gfx::Rect(10, 10), gfx::Rect(10, 10),
600 gfx::Rect(10, 10), false, SK_ColorRED, 1.f);
[email protected]cbe94b7a2013-11-13 11:03:37601
602 // The fifth is not used again.
[email protected]2b7f3892014-05-08 01:45:18603 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
[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,
[email protected]a9d4d4f2014-06-19 06:49:28610 SkXfermode::kSrcOver_Mode,
611 0);
[email protected]cbe94b7a2013-11-13 11:03:37612
[email protected]cbe94b7a2013-11-13 11:03:37613 // 5 SharedQuadStates go in.
614 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
615 ASSERT_EQ(2u, pass_in->quad_list.size());
616
617 DelegatedFrameData frame_in;
618 frame_in.render_pass_list.push_back(pass_in.Pass());
619
620 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
621 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
622
623 DelegatedFrameData frame_out;
624 PickleIterator iter(msg);
625 EXPECT_TRUE(
626 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
627
628 scoped_ptr<RenderPass> pass_out =
629 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
630
631 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
632 // used by quads, and so serialized. Others were not.
633 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
634 ASSERT_EQ(2u, pass_out->quad_list.size());
635
weiliangc808f70f2014-10-03 22:53:15636 EXPECT_EQ(
637 gfx::Size(1, 1).ToString(),
638 pass_out->shared_quad_state_list.ElementAt(0)->content_bounds.ToString());
639 EXPECT_EQ(
640 gfx::Size(4, 4).ToString(),
641 pass_out->shared_quad_state_list.ElementAt(1)->content_bounds.ToString());
[email protected]cbe94b7a2013-11-13 11:03:37642}
643
[email protected]bca159072012-12-04 00:52:44644TEST_F(CCMessagesTest, Resources) {
[email protected]753bb252013-11-04 22:28:12645 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]bca159072012-12-04 00:52:44646 gfx::Size arbitrary_size(757, 1281);
[email protected]09831f7f2013-02-27 03:32:15647 unsigned int arbitrary_uint1 = 71234838;
648 unsigned int arbitrary_uint2 = 53589793;
[email protected]bca159072012-12-04 00:52:44649
[email protected]e0a4d732014-02-15 00:23:26650 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
651 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
652 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
653 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4};
[email protected]bca159072012-12-04 00:52:44654
[email protected]e0a4d732014-02-15 00:23:26655 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
656 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
657 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
658 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7};
[email protected]bca159072012-12-04 00:52:44659
660 TransferableResource arbitrary_resource1;
661 arbitrary_resource1.id = 2178312;
[email protected]27a41fe2013-09-19 05:05:14662 arbitrary_resource1.format = cc::RGBA_8888;
[email protected]80189292013-02-28 01:59:36663 arbitrary_resource1.filter = 53;
[email protected]bca159072012-12-04 00:52:44664 arbitrary_resource1.size = gfx::Size(37189, 123123);
[email protected]df41e252014-02-03 23:39:50665 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
666 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
667 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
[email protected]a8c63be22014-08-07 02:39:49668 arbitrary_resource1.allow_overlay = true;
[email protected]bca159072012-12-04 00:52:44669
670 TransferableResource arbitrary_resource2;
671 arbitrary_resource2.id = 789132;
[email protected]27a41fe2013-09-19 05:05:14672 arbitrary_resource2.format = cc::RGBA_4444;
[email protected]645a47f22013-09-26 05:42:32673 arbitrary_resource2.filter = 47;
[email protected]bca159072012-12-04 00:52:44674 arbitrary_resource2.size = gfx::Size(89123, 23789);
[email protected]df41e252014-02-03 23:39:50675 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
676 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
677 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
[email protected]a8c63be22014-08-07 02:39:49678 arbitrary_resource2.allow_overlay = false;
[email protected]bca159072012-12-04 00:52:44679
[email protected]cb7d6492013-10-03 02:40:04680 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
681 renderpass_in->SetNew(
[email protected]0cd7d6f72014-08-22 14:50:51682 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
[email protected]cb7d6492013-10-03 02:40:04683
[email protected]bf189f62012-12-18 03:42:11684 DelegatedFrameData frame_in;
[email protected]09831f7f2013-02-27 03:32:15685 frame_in.resource_list.push_back(arbitrary_resource1);
686 frame_in.resource_list.push_back(arbitrary_resource2);
[email protected]cb7d6492013-10-03 02:40:04687 frame_in.render_pass_list.push_back(renderpass_in.Pass());
[email protected]bca159072012-12-04 00:52:44688
[email protected]bf189f62012-12-18 03:42:11689 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44690
[email protected]bf189f62012-12-18 03:42:11691 DelegatedFrameData frame_out;
[email protected]bca159072012-12-04 00:52:44692 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11693 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
694 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44695
[email protected]09831f7f2013-02-27 03:32:15696 ASSERT_EQ(2u, frame_out.resource_list.size());
697 Compare(arbitrary_resource1, frame_out.resource_list[0]);
698 Compare(arbitrary_resource2, frame_out.resource_list[1]);
[email protected]bca159072012-12-04 00:52:44699}
700
[email protected]cecc8342014-03-20 21:43:39701TEST_F(CCMessagesTest, SoftwareFrameData) {
702 cc::SoftwareFrameData frame_in;
703 frame_in.id = 3;
704 frame_in.size = gfx::Size(40, 20);
705 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56706 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39707
708 // Write the frame.
709 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
710 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
711
712 // Read the frame.
713 cc::SoftwareFrameData frame_out;
714 PickleIterator iter(msg);
715 EXPECT_TRUE(
716 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
717 EXPECT_EQ(frame_in.id, frame_out.id);
718 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
719 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
[email protected]f1970082014-04-09 04:29:56720 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39721}
722
723TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
724 SoftwareFrameData frame_in;
725 frame_in.id = 3;
726 frame_in.size = gfx::Size(40, 20);
727 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56728 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39729
730 // Write the SoftwareFrameData by hand, make sure it works.
731 {
732 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
733 IPC::WriteParam(&msg, frame_in.id);
734 IPC::WriteParam(&msg, frame_in.size);
735 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56736 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39737 SoftwareFrameData frame_out;
738 PickleIterator iter(msg);
739 EXPECT_TRUE(
740 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
741 }
742
743 // The size of the frame may overflow when multiplied together.
744 int max = std::numeric_limits<int>::max();
745 frame_in.size = gfx::Size(max, max);
746
747 // If size_t is larger than int, then int*int*4 can always fit in size_t.
748 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
749
750 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
751 // should fail.
752 {
753 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
754 IPC::WriteParam(&msg, frame_in.id);
755 IPC::WriteParam(&msg, frame_in.size);
756 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56757 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39758 SoftwareFrameData frame_out;
759 PickleIterator iter(msg);
760 EXPECT_EQ(
761 expect_read,
762 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
763 }
764}
765
[email protected]bca159072012-12-04 00:52:44766} // namespace
767} // namespace content