blob: b81bb7094da88531ca5c4d646e9706715cdf49dd [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;
42using cc::VideoLayerImpl;
43using 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);
132 }
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);
[email protected]458af1e2012-12-13 05:12:18148 EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.ToString());
[email protected]1dc7943e2013-09-26 04:41:48149 EXPECT_EQ(a->filters.size(), b->filters.size());
150 for (size_t i = 0; i < a->filters.size(); ++i) {
151 if (a->filters.at(i).type() != cc::FilterOperation::REFERENCE) {
152 EXPECT_EQ(a->filters.at(i), b->filters.at(i));
153 } else {
154 EXPECT_EQ(b->filters.at(i).type(), cc::FilterOperation::REFERENCE);
155 EXPECT_EQ(a->filters.at(i).image_filter()->countInputs(),
156 b->filters.at(i).image_filter()->countInputs());
157 }
158 }
[email protected]7ac3d492014-08-08 21:25:32159 EXPECT_EQ(a->filters_scale, b->filters_scale);
[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) {
[email protected]95052aa2014-03-27 11:43:50198 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
[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]82faf5e2014-05-03 02:25:58203 EXPECT_EQ(a->color_space, b->color_space);
[email protected]4934d362012-11-22 22:04:53204 }
[email protected]bca159072012-12-04 00:52:44205
206 void Compare(const TransferableResource& a, const TransferableResource& b) {
207 EXPECT_EQ(a.id, b.id);
208 EXPECT_EQ(a.format, b.format);
[email protected]80189292013-02-28 01:59:36209 EXPECT_EQ(a.filter, b.filter);
[email protected]bca159072012-12-04 00:52:44210 EXPECT_EQ(a.size.ToString(), b.size.ToString());
[email protected]df41e252014-02-03 23:39:50211 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
212 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
213 b.mailbox_holder.mailbox.name[i]);
214 }
215 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
216 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
[email protected]a8c63be22014-08-07 02:39:49217 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
[email protected]bca159072012-12-04 00:52:44218 }
[email protected]4934d362012-11-22 22:04:53219};
220
221TEST_F(CCMessagesTest, AllQuads) {
[email protected]753bb252013-11-04 22:28:12222 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]4934d362012-11-22 22:04:53223
[email protected]c8686a02012-11-27 08:29:00224 Transform arbitrary_matrix;
225 arbitrary_matrix.Scale(3, 3);
226 arbitrary_matrix.Translate(-5, 20);
227 arbitrary_matrix.Rotate(15);
[email protected]4934d362012-11-22 22:04:53228 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
[email protected]8e1da692013-10-12 17:11:30229 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
230 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
[email protected]4934d362012-11-22 22:04:53231 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
[email protected]8e1da692013-10-12 17:11:30232 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
233 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
[email protected]4934d362012-11-22 22:04:53234 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
[email protected]8e1da692013-10-12 17:11:30235 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
236 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
[email protected]4934d362012-11-22 22:04:53237 gfx::Size arbitrary_size1(15, 19);
238 gfx::Size arbitrary_size2(3, 99);
239 gfx::Size arbitrary_size3(75, 1281);
240 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
241 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
[email protected]61df9d82013-01-30 02:32:42242 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
243 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
[email protected]7ac3d492014-08-08 21:25:32244 gfx::Vector2dF arbitrary_vector2df1(16.2f, -85.1f);
[email protected]4934d362012-11-22 22:04:53245 float arbitrary_float1 = 0.7f;
246 float arbitrary_float2 = 0.3f;
247 float arbitrary_float3 = 0.9f;
[email protected]61df9d82013-01-30 02:32:42248 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
[email protected]4934d362012-11-22 22:04:53249 bool arbitrary_bool1 = true;
250 bool arbitrary_bool2 = false;
[email protected]61df9d82013-01-30 02:32:42251 bool arbitrary_bool3 = true;
[email protected]a9d4d4f2014-06-19 06:49:28252 int arbitrary_context_id1 = 12;
253 int arbitrary_context_id2 = 57;
254 int arbitrary_context_id3 = -503;
[email protected]4934d362012-11-22 22:04:53255 int arbitrary_int = 5;
256 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
[email protected]7bbeaf4e2013-11-26 10:27:22257 SkXfermode::Mode arbitrary_blend_mode1 = SkXfermode::kScreen_Mode;
258 SkXfermode::Mode arbitrary_blend_mode2 = SkXfermode::kLighten_Mode;
259 SkXfermode::Mode arbitrary_blend_mode3 = SkXfermode::kOverlay_Mode;
[email protected]4934d362012-11-22 22:04:53260 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
261 IOSurfaceDrawQuad::UNFLIPPED;
[email protected]0cd7d6f72014-08-22 14:50:51262 RenderPassId arbitrary_id(10, 14);
[email protected]b7cfc632013-04-10 04:44:49263 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
264 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
265 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
[email protected]0402b2382013-06-07 21:50:54266 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
[email protected]a1765672013-08-12 23:45:02267 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
[email protected]82faf5e2014-05-03 02:25:58268 YUVVideoDrawQuad::ColorSpace arbitrary_color_space =
269 YUVVideoDrawQuad::REC_601;
[email protected]4934d362012-11-22 22:04:53270
[email protected]ae6b1a72013-06-25 18:49:29271 FilterOperations arbitrary_filters1;
272 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
[email protected]4934d362012-11-22 22:04:53273 arbitrary_float1));
[email protected]1dc7943e2013-09-26 04:41:48274 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
[email protected]bb209bf2014-05-11 00:37:11275 SkBlurImageFilter::Create(arbitrary_sigma, arbitrary_sigma));
[email protected]1dc7943e2013-09-26 04:41:48276 arbitrary_filters1.Append(
277 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
[email protected]4934d362012-11-22 22:04:53278
[email protected]ae6b1a72013-06-25 18:49:29279 FilterOperations arbitrary_filters2;
280 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
[email protected]4934d362012-11-22 22:04:53281 arbitrary_float2));
282
[email protected]2b7f3892014-05-08 01:45:18283 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
284 pass_in->SetAll(arbitrary_id,
285 arbitrary_rect1,
286 arbitrary_rect2,
287 arbitrary_matrix,
288 arbitrary_bool1);
289
290 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]4934d362012-11-22 22:04:53291 shared_state1_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27292 arbitrary_size1,
[email protected]4934d362012-11-22 22:04:53293 arbitrary_rect1,
294 arbitrary_rect2,
[email protected]4934d362012-11-22 22:04:53295 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22296 arbitrary_float1,
[email protected]a9d4d4f2014-06-19 06:49:28297 arbitrary_blend_mode1,
298 arbitrary_context_id1);
[email protected]2b7f3892014-05-08 01:45:18299
300 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
301 pass_cmp->SetAll(arbitrary_id,
302 arbitrary_rect1,
303 arbitrary_rect2,
304 arbitrary_matrix,
305 arbitrary_bool1);
306
307 SharedQuadState* shared_state1_cmp =
308 pass_cmp->CreateAndAppendSharedQuadState();
309 shared_state1_cmp->CopyFrom(shared_state1_in);
[email protected]4934d362012-11-22 22:04:53310
[email protected]3b85fd92014-07-10 00:00:02311 CheckerboardDrawQuad* checkerboard_in =
312 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18313 checkerboard_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53314 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30315 arbitrary_rect2_inside_rect1,
316 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53317 arbitrary_bool1,
318 arbitrary_color);
[email protected]3b85fd92014-07-10 00:00:02319 pass_cmp->CopyFromAndAppendDrawQuad(checkerboard_in,
320 checkerboard_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53321
[email protected]3b85fd92014-07-10 00:00:02322 DebugBorderDrawQuad* debugborder_in =
323 pass_in->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18324 debugborder_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53325 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30326 arbitrary_rect1_inside_rect3,
327 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53328 arbitrary_bool1,
329 arbitrary_color,
330 arbitrary_int);
[email protected]3b85fd92014-07-10 00:00:02331 pass_cmp->CopyFromAndAppendDrawQuad(debugborder_in,
332 debugborder_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53333
[email protected]3b85fd92014-07-10 00:00:02334 IOSurfaceDrawQuad* iosurface_in =
335 pass_in->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18336 iosurface_in->SetAll(shared_state1_in,
[email protected]4934d362012-11-22 22:04:53337 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30338 arbitrary_rect2_inside_rect2,
339 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53340 arbitrary_bool1,
341 arbitrary_size1,
[email protected]b7cfc632013-04-10 04:44:49342 arbitrary_resourceid3,
[email protected]4934d362012-11-22 22:04:53343 arbitrary_orientation);
[email protected]3b85fd92014-07-10 00:00:02344 pass_cmp->CopyFromAndAppendDrawQuad(iosurface_in,
345 iosurface_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53346
[email protected]2b7f3892014-05-08 01:45:18347 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]cbe94b7a2013-11-13 11:03:37348 shared_state2_in->SetAll(arbitrary_matrix,
349 arbitrary_size2,
350 arbitrary_rect2,
351 arbitrary_rect3,
352 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22353 arbitrary_float2,
[email protected]a9d4d4f2014-06-19 06:49:28354 arbitrary_blend_mode2,
355 arbitrary_context_id2);
[email protected]2b7f3892014-05-08 01:45:18356 SharedQuadState* shared_state2_cmp =
357 pass_cmp->CreateAndAppendSharedQuadState();
358 shared_state2_cmp->CopyFrom(shared_state2_in);
[email protected]cbe94b7a2013-11-13 11:03:37359
[email protected]3b85fd92014-07-10 00:00:02360 RenderPassDrawQuad* renderpass_in =
361 pass_in->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18362 renderpass_in->SetAll(shared_state2_in,
[email protected]4934d362012-11-22 22:04:53363 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30364 arbitrary_rect2_inside_rect1,
365 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53366 arbitrary_bool1,
367 arbitrary_id,
[email protected]b7cfc632013-04-10 04:44:49368 arbitrary_resourceid2,
[email protected]20062042012-12-21 22:16:36369 arbitrary_rectf1,
370 arbitrary_filters1,
[email protected]7ac3d492014-08-08 21:25:32371 arbitrary_vector2df1,
[email protected]20062042012-12-21 22:16:36372 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();
[email protected]4934d362012-11-22 22:04:53379 shared_state3_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27380 arbitrary_size3,
[email protected]4934d362012-11-22 22:04:53381 arbitrary_rect3,
382 arbitrary_rect1,
[email protected]4934d362012-11-22 22:04:53383 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22384 arbitrary_float3,
[email protected]a9d4d4f2014-06-19 06:49:28385 arbitrary_blend_mode3,
386 arbitrary_context_id3);
[email protected]2b7f3892014-05-08 01:45:18387 SharedQuadState* shared_state3_cmp =
388 pass_cmp->CreateAndAppendSharedQuadState();
389 shared_state3_cmp->CopyFrom(shared_state3_in);
[email protected]4934d362012-11-22 22:04:53390
[email protected]3b85fd92014-07-10 00:00:02391 SolidColorDrawQuad* solidcolor_in =
392 pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18393 solidcolor_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53394 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30395 arbitrary_rect1_inside_rect3,
396 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53397 arbitrary_bool1,
[email protected]10a30b12013-05-02 16:42:11398 arbitrary_color,
399 arbitrary_bool2);
[email protected]3b85fd92014-07-10 00:00:02400 pass_cmp->CopyFromAndAppendDrawQuad(solidcolor_in,
401 solidcolor_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53402
[email protected]3b85fd92014-07-10 00:00:02403 StreamVideoDrawQuad* streamvideo_in =
404 pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18405 streamvideo_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53406 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30407 arbitrary_rect2_inside_rect2,
408 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53409 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49410 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53411 arbitrary_matrix);
[email protected]3b85fd92014-07-10 00:00:02412 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
413 streamvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53414
[email protected]16a6af152014-06-13 04:20:16415 cc::SurfaceId arbitrary_surface_id(3);
[email protected]3b85fd92014-07-10 00:00:02416 SurfaceDrawQuad* surface_in =
417 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18418 surface_in->SetAll(shared_state3_in,
419 arbitrary_rect2,
420 arbitrary_rect2_inside_rect2,
421 arbitrary_rect1_inside_rect2,
422 arbitrary_bool1,
423 arbitrary_surface_id);
[email protected]3b85fd92014-07-10 00:00:02424 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
425 surface_in->shared_quad_state);
[email protected]78d30122014-01-17 06:32:36426
[email protected]3b85fd92014-07-10 00:00:02427 TextureDrawQuad* texture_in =
428 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18429 texture_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42430 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30431 arbitrary_rect2_inside_rect2,
432 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42433 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49434 arbitrary_resourceid1,
[email protected]61df9d82013-01-30 02:32:42435 arbitrary_bool2,
436 arbitrary_pointf1,
437 arbitrary_pointf2,
[email protected]d18b4d62013-07-12 05:33:49438 arbitrary_color,
[email protected]61df9d82013-01-30 02:32:42439 arbitrary_float_array,
440 arbitrary_bool3);
[email protected]3b85fd92014-07-10 00:00:02441 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
442 texture_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42443
[email protected]3b85fd92014-07-10 00:00:02444 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18445 tile_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42446 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30447 arbitrary_rect2_inside_rect2,
448 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42449 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49450 arbitrary_resourceid3,
[email protected]61df9d82013-01-30 02:32:42451 arbitrary_rectf1,
452 arbitrary_size1,
[email protected]f902bf92013-03-04 18:33:27453 arbitrary_bool2);
[email protected]3b85fd92014-07-10 00:00:02454 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42455
[email protected]3b85fd92014-07-10 00:00:02456 YUVVideoDrawQuad* yuvvideo_in =
457 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18458 yuvvideo_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53459 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30460 arbitrary_rect2_inside_rect1,
461 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53462 arbitrary_bool1,
[email protected]95052aa2014-03-27 11:43:50463 arbitrary_rectf1,
[email protected]b7cfc632013-04-10 04:44:49464 arbitrary_resourceid1,
465 arbitrary_resourceid2,
[email protected]0402b2382013-06-07 21:50:54466 arbitrary_resourceid3,
[email protected]82faf5e2014-05-03 02:25:58467 arbitrary_resourceid4,
468 arbitrary_color_space);
[email protected]3b85fd92014-07-10 00:00:02469 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
470 yuvvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53471
472 // Make sure the in and cmp RenderPasses match.
473 Compare(pass_cmp.get(), pass_in.get());
474 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36475 ASSERT_EQ(10u, pass_in->quad_list.size());
weiliangc808f70f2014-10-03 22:53:15476 for (cc::SharedQuadStateList::ConstIterator
477 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
478 in_iterator = pass_in->shared_quad_state_list.begin();
479 in_iterator != pass_in->shared_quad_state_list.end();
480 ++cmp_iterator, ++in_iterator) {
481 Compare(&*cmp_iterator, &*in_iterator);
[email protected]4934d362012-11-22 22:04:53482 }
weiliangc7eb7ee62014-10-07 00:04:40483 for (auto in_iter = pass_in->quad_list.cbegin(),
484 cmp_iter = pass_cmp->quad_list.cbegin();
485 in_iter != pass_in->quad_list.cend();
weiliangc032e929d2014-09-26 01:55:01486 ++in_iter, ++cmp_iter)
487 Compare(&*cmp_iter, &*in_iter);
488
[email protected]61df9d82013-01-30 02:32:42489 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53490 bool same_shared_quad_state_cmp =
weiliangc032e929d2014-09-26 01:55:01491 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
492 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53493 bool same_shared_quad_state_in =
weiliangc032e929d2014-09-26 01:55:01494 pass_in->quad_list.ElementAt(i)->shared_quad_state ==
495 pass_in->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53496 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
497 }
498
[email protected]bf189f62012-12-18 03:42:11499 DelegatedFrameData frame_in;
[email protected]ead39c52013-01-09 07:22:45500 frame_in.render_pass_list.push_back(pass_in.Pass());
[email protected]4934d362012-11-22 22:04:53501
[email protected]bf189f62012-12-18 03:42:11502 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44503
[email protected]bf189f62012-12-18 03:42:11504 DelegatedFrameData frame_out;
[email protected]4934d362012-11-22 22:04:53505 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11506 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
507 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44508
[email protected]4934d362012-11-22 22:04:53509 // Make sure the out and cmp RenderPasses match.
[email protected]ead39c52013-01-09 07:22:45510 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
511 frame_out.render_pass_list.begin());
[email protected]4934d362012-11-22 22:04:53512 Compare(pass_cmp.get(), pass_out.get());
513 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36514 ASSERT_EQ(10u, pass_out->quad_list.size());
weiliangc808f70f2014-10-03 22:53:15515 for (cc::SharedQuadStateList::ConstIterator
516 cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
517 out_iterator = pass_out->shared_quad_state_list.begin();
518 out_iterator != pass_out->shared_quad_state_list.end();
519 ++cmp_iterator, ++out_iterator) {
520 Compare(&*cmp_iterator, &*out_iterator);
[email protected]4934d362012-11-22 22:04:53521 }
weiliangc7eb7ee62014-10-07 00:04:40522 for (auto out_iter = pass_out->quad_list.cbegin(),
523 cmp_iter = pass_cmp->quad_list.cbegin();
524 out_iter != pass_out->quad_list.cend();
weiliangc032e929d2014-09-26 01:55:01525 ++out_iter, ++cmp_iter)
526 Compare(&*cmp_iter, &*out_iter);
527
[email protected]61df9d82013-01-30 02:32:42528 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53529 bool same_shared_quad_state_cmp =
weiliangc032e929d2014-09-26 01:55:01530 pass_cmp->quad_list.ElementAt(i)->shared_quad_state ==
531 pass_cmp->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53532 bool same_shared_quad_state_out =
weiliangc032e929d2014-09-26 01:55:01533 pass_out->quad_list.ElementAt(i)->shared_quad_state ==
534 pass_out->quad_list.ElementAt(i - 1)->shared_quad_state;
[email protected]4934d362012-11-22 22:04:53535 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
536 }
537}
[email protected]bca159072012-12-04 00:52:44538
[email protected]cbe94b7a2013-11-13 11:03:37539TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
[email protected]cbe94b7a2013-11-13 11:03:37540 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
[email protected]0cd7d6f72014-08-22 14:50:51541 pass_in->SetAll(RenderPassId(1, 1),
[email protected]cbe94b7a2013-11-13 11:03:37542 gfx::Rect(100, 100),
[email protected]b4ead7b2014-04-07 18:12:18543 gfx::Rect(),
[email protected]cbe94b7a2013-11-13 11:03:37544 gfx::Transform(),
[email protected]8590da32014-03-28 20:49:07545 false);
[email protected]cbe94b7a2013-11-13 11:03:37546
547 // The first SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18548 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22549 shared_state1_in->SetAll(gfx::Transform(),
550 gfx::Size(1, 1),
551 gfx::Rect(),
552 gfx::Rect(),
553 false,
554 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28555 SkXfermode::kSrcOver_Mode,
556 0);
[email protected]cbe94b7a2013-11-13 11:03:37557
[email protected]3b85fd92014-07-10 00:00:02558 CheckerboardDrawQuad* quad1 =
559 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
560 quad1->SetAll(shared_state1_in,
561 gfx::Rect(10, 10),
562 gfx::Rect(10, 10),
563 gfx::Rect(10, 10),
564 false,
565 SK_ColorRED);
[email protected]cbe94b7a2013-11-13 11:03:37566
567 // The second and third SharedQuadStates are not used.
[email protected]2b7f3892014-05-08 01:45:18568 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22569 shared_state2_in->SetAll(gfx::Transform(),
570 gfx::Size(2, 2),
571 gfx::Rect(),
572 gfx::Rect(),
573 false,
574 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28575 SkXfermode::kSrcOver_Mode,
576 0);
[email protected]cbe94b7a2013-11-13 11:03:37577
[email protected]2b7f3892014-05-08 01:45:18578 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22579 shared_state3_in->SetAll(gfx::Transform(),
580 gfx::Size(3, 3),
581 gfx::Rect(),
582 gfx::Rect(),
583 false,
584 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28585 SkXfermode::kSrcOver_Mode,
586 0);
[email protected]cbe94b7a2013-11-13 11:03:37587
588 // The fourth SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18589 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22590 shared_state4_in->SetAll(gfx::Transform(),
591 gfx::Size(4, 4),
592 gfx::Rect(),
593 gfx::Rect(),
594 false,
595 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28596 SkXfermode::kSrcOver_Mode,
597 0);
[email protected]cbe94b7a2013-11-13 11:03:37598
[email protected]3b85fd92014-07-10 00:00:02599 CheckerboardDrawQuad* quad2 =
600 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
601 quad2->SetAll(shared_state4_in,
602 gfx::Rect(10, 10),
603 gfx::Rect(10, 10),
604 gfx::Rect(10, 10),
605 false,
606 SK_ColorRED);
[email protected]cbe94b7a2013-11-13 11:03:37607
608 // The fifth is not used again.
[email protected]2b7f3892014-05-08 01:45:18609 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22610 shared_state5_in->SetAll(gfx::Transform(),
611 gfx::Size(5, 5),
612 gfx::Rect(),
613 gfx::Rect(),
614 false,
615 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28616 SkXfermode::kSrcOver_Mode,
617 0);
[email protected]cbe94b7a2013-11-13 11:03:37618
[email protected]cbe94b7a2013-11-13 11:03:37619 // 5 SharedQuadStates go in.
620 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
621 ASSERT_EQ(2u, pass_in->quad_list.size());
622
623 DelegatedFrameData frame_in;
624 frame_in.render_pass_list.push_back(pass_in.Pass());
625
626 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
627 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
628
629 DelegatedFrameData frame_out;
630 PickleIterator iter(msg);
631 EXPECT_TRUE(
632 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
633
634 scoped_ptr<RenderPass> pass_out =
635 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
636
637 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
638 // used by quads, and so serialized. Others were not.
639 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
640 ASSERT_EQ(2u, pass_out->quad_list.size());
641
weiliangc808f70f2014-10-03 22:53:15642 EXPECT_EQ(
643 gfx::Size(1, 1).ToString(),
644 pass_out->shared_quad_state_list.ElementAt(0)->content_bounds.ToString());
645 EXPECT_EQ(
646 gfx::Size(4, 4).ToString(),
647 pass_out->shared_quad_state_list.ElementAt(1)->content_bounds.ToString());
[email protected]cbe94b7a2013-11-13 11:03:37648}
649
[email protected]bca159072012-12-04 00:52:44650TEST_F(CCMessagesTest, Resources) {
[email protected]753bb252013-11-04 22:28:12651 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]bca159072012-12-04 00:52:44652 gfx::Size arbitrary_size(757, 1281);
[email protected]09831f7f2013-02-27 03:32:15653 unsigned int arbitrary_uint1 = 71234838;
654 unsigned int arbitrary_uint2 = 53589793;
[email protected]bca159072012-12-04 00:52:44655
[email protected]e0a4d732014-02-15 00:23:26656 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
657 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
658 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
659 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:44660
[email protected]e0a4d732014-02-15 00:23:26661 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
662 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
663 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
664 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:44665
666 TransferableResource arbitrary_resource1;
667 arbitrary_resource1.id = 2178312;
[email protected]27a41fe2013-09-19 05:05:14668 arbitrary_resource1.format = cc::RGBA_8888;
[email protected]80189292013-02-28 01:59:36669 arbitrary_resource1.filter = 53;
[email protected]bca159072012-12-04 00:52:44670 arbitrary_resource1.size = gfx::Size(37189, 123123);
[email protected]df41e252014-02-03 23:39:50671 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
672 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
673 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
[email protected]a8c63be22014-08-07 02:39:49674 arbitrary_resource1.allow_overlay = true;
[email protected]bca159072012-12-04 00:52:44675
676 TransferableResource arbitrary_resource2;
677 arbitrary_resource2.id = 789132;
[email protected]27a41fe2013-09-19 05:05:14678 arbitrary_resource2.format = cc::RGBA_4444;
[email protected]645a47f22013-09-26 05:42:32679 arbitrary_resource2.filter = 47;
[email protected]bca159072012-12-04 00:52:44680 arbitrary_resource2.size = gfx::Size(89123, 23789);
[email protected]df41e252014-02-03 23:39:50681 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
682 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
683 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
[email protected]a8c63be22014-08-07 02:39:49684 arbitrary_resource2.allow_overlay = false;
[email protected]bca159072012-12-04 00:52:44685
[email protected]cb7d6492013-10-03 02:40:04686 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
687 renderpass_in->SetNew(
[email protected]0cd7d6f72014-08-22 14:50:51688 RenderPassId(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
[email protected]cb7d6492013-10-03 02:40:04689
[email protected]bf189f62012-12-18 03:42:11690 DelegatedFrameData frame_in;
[email protected]09831f7f2013-02-27 03:32:15691 frame_in.resource_list.push_back(arbitrary_resource1);
692 frame_in.resource_list.push_back(arbitrary_resource2);
[email protected]cb7d6492013-10-03 02:40:04693 frame_in.render_pass_list.push_back(renderpass_in.Pass());
[email protected]bca159072012-12-04 00:52:44694
[email protected]bf189f62012-12-18 03:42:11695 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44696
[email protected]bf189f62012-12-18 03:42:11697 DelegatedFrameData frame_out;
[email protected]bca159072012-12-04 00:52:44698 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11699 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
700 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44701
[email protected]09831f7f2013-02-27 03:32:15702 ASSERT_EQ(2u, frame_out.resource_list.size());
703 Compare(arbitrary_resource1, frame_out.resource_list[0]);
704 Compare(arbitrary_resource2, frame_out.resource_list[1]);
[email protected]bca159072012-12-04 00:52:44705}
706
[email protected]cecc8342014-03-20 21:43:39707TEST_F(CCMessagesTest, SoftwareFrameData) {
708 cc::SoftwareFrameData frame_in;
709 frame_in.id = 3;
710 frame_in.size = gfx::Size(40, 20);
711 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56712 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39713
714 // Write the frame.
715 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
716 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
717
718 // Read the frame.
719 cc::SoftwareFrameData frame_out;
720 PickleIterator iter(msg);
721 EXPECT_TRUE(
722 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
723 EXPECT_EQ(frame_in.id, frame_out.id);
724 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
725 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
[email protected]f1970082014-04-09 04:29:56726 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39727}
728
729TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
730 SoftwareFrameData frame_in;
731 frame_in.id = 3;
732 frame_in.size = gfx::Size(40, 20);
733 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56734 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39735
736 // Write the SoftwareFrameData by hand, make sure it works.
737 {
738 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
739 IPC::WriteParam(&msg, frame_in.id);
740 IPC::WriteParam(&msg, frame_in.size);
741 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56742 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39743 SoftwareFrameData frame_out;
744 PickleIterator iter(msg);
745 EXPECT_TRUE(
746 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
747 }
748
749 // The size of the frame may overflow when multiplied together.
750 int max = std::numeric_limits<int>::max();
751 frame_in.size = gfx::Size(max, max);
752
753 // If size_t is larger than int, then int*int*4 can always fit in size_t.
754 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
755
756 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
757 // should fail.
758 {
759 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
760 IPC::WriteParam(&msg, frame_in.id);
761 IPC::WriteParam(&msg, frame_in.size);
762 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56763 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39764 SoftwareFrameData frame_out;
765 PickleIterator iter(msg);
766 EXPECT_EQ(
767 expect_read,
768 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
769 }
770}
771
[email protected]bca159072012-12-04 00:52:44772} // namespace
773} // namespace content