blob: 73b1a0836344b152e09d179258776bcf54089cd6 [file] [log] [blame]
[email protected]4934d362012-11-22 22:04:531// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/common/cc_messages.h"
6
7#include <string.h>
8
[email protected]032bfc42013-10-29 22:23:529#include <algorithm>
10
[email protected]7f0d825f2013-03-18 07:24:3011#include "cc/output/compositor_frame.h"
[email protected]cecc8342014-03-20 21:43:3912#include "content/public/common/common_param_traits.h"
[email protected]4934d362012-11-22 22:04:5313#include "ipc/ipc_message.h"
14#include "testing/gtest/include/gtest/gtest.h"
[email protected]645a47f22013-09-26 05:42:3215#include "third_party/khronos/GLES2/gl2ext.h"
[email protected]a1765672013-08-12 23:45:0216#include "third_party/skia/include/effects/SkBlurImageFilter.h"
[email protected]4934d362012-11-22 22:04:5317
[email protected]cecc8342014-03-20 21:43:3918#if defined(OS_POSIX)
19#include "base/file_descriptor_posix.h"
20#endif
21
[email protected]4934d362012-11-22 22:04:5322using cc::CheckerboardDrawQuad;
[email protected]bf189f62012-12-18 03:42:1123using cc::DelegatedFrameData;
[email protected]4934d362012-11-22 22:04:5324using cc::DebugBorderDrawQuad;
25using cc::DrawQuad;
[email protected]ae6b1a72013-06-25 18:49:2926using cc::FilterOperation;
27using cc::FilterOperations;
[email protected]4934d362012-11-22 22:04:5328using cc::IOSurfaceDrawQuad;
[email protected]9ee4d3a2013-03-27 17:43:1629using cc::PictureDrawQuad;
[email protected]4934d362012-11-22 22:04:5330using cc::RenderPass;
31using cc::RenderPassDrawQuad;
32using cc::ResourceProvider;
33using cc::SharedQuadState;
[email protected]cecc8342014-03-20 21:43:3934using cc::SoftwareFrameData;
[email protected]4934d362012-11-22 22:04:5335using cc::SolidColorDrawQuad;
[email protected]78d30122014-01-17 06:32:3636using cc::SurfaceDrawQuad;
[email protected]4934d362012-11-22 22:04:5337using cc::TextureDrawQuad;
38using cc::TileDrawQuad;
[email protected]bca159072012-12-04 00:52:4439using cc::TransferableResource;
[email protected]4934d362012-11-22 22:04:5340using cc::StreamVideoDrawQuad;
41using cc::VideoLayerImpl;
42using cc::YUVVideoDrawQuad;
[email protected]c8686a02012-11-27 08:29:0043using gfx::Transform;
[email protected]4934d362012-11-22 22:04:5344
[email protected]bca159072012-12-04 00:52:4445namespace content {
46namespace {
47
[email protected]4934d362012-11-22 22:04:5348class CCMessagesTest : public testing::Test {
49 protected:
50 void Compare(const RenderPass* a, const RenderPass* b) {
51 EXPECT_EQ(a->id, b->id);
52 EXPECT_EQ(a->output_rect.ToString(), b->output_rect.ToString());
53 EXPECT_EQ(a->damage_rect.ToString(), b->damage_rect.ToString());
54 EXPECT_EQ(a->transform_to_root_target, b->transform_to_root_target);
55 EXPECT_EQ(a->has_transparent_background, b->has_transparent_background);
[email protected]4934d362012-11-22 22:04:5356 }
57
58 void Compare(const SharedQuadState* a, const SharedQuadState* b) {
59 EXPECT_EQ(a->content_to_target_transform, b->content_to_target_transform);
[email protected]f902bf92013-03-04 18:33:2760 EXPECT_EQ(a->content_bounds, b->content_bounds);
[email protected]4934d362012-11-22 22:04:5361 EXPECT_EQ(a->visible_content_rect, b->visible_content_rect);
[email protected]4934d362012-11-22 22:04:5362 EXPECT_EQ(a->clip_rect, b->clip_rect);
63 EXPECT_EQ(a->is_clipped, b->is_clipped);
64 EXPECT_EQ(a->opacity, b->opacity);
[email protected]7bbeaf4e2013-11-26 10:27:2265 EXPECT_EQ(a->blend_mode, b->blend_mode);
[email protected]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);
131 }
132
133 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
134 EXPECT_EQ(a->color, b->color);
135 EXPECT_EQ(a->width, b->width);
136 }
137
138 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
139 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
[email protected]b7cfc632013-04-10 04:44:49140 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
[email protected]4934d362012-11-22 22:04:53141 EXPECT_EQ(a->orientation, b->orientation);
142 }
143
144 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
[email protected]82f93fb2013-04-17 21:42:06145 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
[email protected]4934d362012-11-22 22:04:53146 EXPECT_EQ(a->is_replica, b->is_replica);
147 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id);
148 EXPECT_EQ(a->contents_changed_since_last_frame,
149 b->contents_changed_since_last_frame);
[email protected]458af1e2012-12-13 05:12:18150 EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.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]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);
189 }
190
191 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
192 EXPECT_EQ(a->resource_id, b->resource_id);
193 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
194 EXPECT_EQ(a->texture_size, b->texture_size);
195 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
[email protected]4934d362012-11-22 22:04:53196 }
197
198 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
[email protected]95052aa2014-03-27 11:43:50199 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
[email protected]b7cfc632013-04-10 04:44:49200 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id);
201 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id);
202 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id);
[email protected]0402b2382013-06-07 21:50:54203 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
[email protected]82faf5e2014-05-03 02:25:58204 EXPECT_EQ(a->color_space, b->color_space);
[email protected]4934d362012-11-22 22:04:53205 }
[email protected]bca159072012-12-04 00:52:44206
207 void Compare(const TransferableResource& a, const TransferableResource& b) {
208 EXPECT_EQ(a.id, b.id);
209 EXPECT_EQ(a.format, b.format);
[email protected]80189292013-02-28 01:59:36210 EXPECT_EQ(a.filter, b.filter);
[email protected]bca159072012-12-04 00:52:44211 EXPECT_EQ(a.size.ToString(), b.size.ToString());
[email protected]df41e252014-02-03 23:39:50212 for (size_t i = 0; i < arraysize(a.mailbox_holder.mailbox.name); ++i) {
213 EXPECT_EQ(a.mailbox_holder.mailbox.name[i],
214 b.mailbox_holder.mailbox.name[i]);
215 }
216 EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
217 EXPECT_EQ(a.mailbox_holder.sync_point, b.mailbox_holder.sync_point);
[email protected]a8c63be22014-08-07 02:39:49218 EXPECT_EQ(a.allow_overlay, b.allow_overlay);
[email protected]bca159072012-12-04 00:52:44219 }
[email protected]4934d362012-11-22 22:04:53220};
221
222TEST_F(CCMessagesTest, AllQuads) {
[email protected]753bb252013-11-04 22:28:12223 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]4934d362012-11-22 22:04:53224
[email protected]c8686a02012-11-27 08:29:00225 Transform arbitrary_matrix;
226 arbitrary_matrix.Scale(3, 3);
227 arbitrary_matrix.Translate(-5, 20);
228 arbitrary_matrix.Rotate(15);
[email protected]4934d362012-11-22 22:04:53229 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
[email protected]8e1da692013-10-12 17:11:30230 gfx::Rect arbitrary_rect1_inside_rect1(-4, 12, 2, 8);
231 gfx::Rect arbitrary_rect2_inside_rect1(-5, 11, 1, 2);
[email protected]4934d362012-11-22 22:04:53232 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
[email protected]8e1da692013-10-12 17:11:30233 gfx::Rect arbitrary_rect1_inside_rect2(44, 23, 4, 2);
234 gfx::Rect arbitrary_rect2_inside_rect2(41, 25, 3, 5);
[email protected]4934d362012-11-22 22:04:53235 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
[email protected]8e1da692013-10-12 17:11:30236 gfx::Rect arbitrary_rect1_inside_rect3(10, -40, 6, 3);
237 gfx::Rect arbitrary_rect2_inside_rect3(12, -51, 5, 12);
[email protected]4934d362012-11-22 22:04:53238 gfx::Size arbitrary_size1(15, 19);
239 gfx::Size arbitrary_size2(3, 99);
240 gfx::Size arbitrary_size3(75, 1281);
241 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
242 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
[email protected]61df9d82013-01-30 02:32:42243 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
244 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
[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;
262 RenderPass::Id 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,
368 arbitrary_bool2,
[email protected]b7cfc632013-04-10 04:44:49369 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53370 arbitrary_rect1,
[email protected]20062042012-12-21 22:16:36371 arbitrary_rectf1,
372 arbitrary_filters1,
[email protected]20062042012-12-21 22:16:36373 arbitrary_filters2);
[email protected]3b85fd92014-07-10 00:00:02374 pass_cmp->CopyFromAndAppendRenderPassDrawQuad(
375 renderpass_in,
376 renderpass_in->shared_quad_state,
377 renderpass_in->render_pass_id);
[email protected]4934d362012-11-22 22:04:53378
[email protected]2b7f3892014-05-08 01:45:18379 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]4934d362012-11-22 22:04:53380 shared_state3_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27381 arbitrary_size3,
[email protected]4934d362012-11-22 22:04:53382 arbitrary_rect3,
383 arbitrary_rect1,
[email protected]4934d362012-11-22 22:04:53384 arbitrary_bool1,
[email protected]7bbeaf4e2013-11-26 10:27:22385 arbitrary_float3,
[email protected]a9d4d4f2014-06-19 06:49:28386 arbitrary_blend_mode3,
387 arbitrary_context_id3);
[email protected]2b7f3892014-05-08 01:45:18388 SharedQuadState* shared_state3_cmp =
389 pass_cmp->CreateAndAppendSharedQuadState();
390 shared_state3_cmp->CopyFrom(shared_state3_in);
[email protected]4934d362012-11-22 22:04:53391
[email protected]3b85fd92014-07-10 00:00:02392 SolidColorDrawQuad* solidcolor_in =
393 pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18394 solidcolor_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53395 arbitrary_rect3,
[email protected]8e1da692013-10-12 17:11:30396 arbitrary_rect1_inside_rect3,
397 arbitrary_rect2_inside_rect3,
[email protected]4934d362012-11-22 22:04:53398 arbitrary_bool1,
[email protected]10a30b12013-05-02 16:42:11399 arbitrary_color,
400 arbitrary_bool2);
[email protected]3b85fd92014-07-10 00:00:02401 pass_cmp->CopyFromAndAppendDrawQuad(solidcolor_in,
402 solidcolor_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53403
[email protected]3b85fd92014-07-10 00:00:02404 StreamVideoDrawQuad* streamvideo_in =
405 pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18406 streamvideo_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53407 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30408 arbitrary_rect2_inside_rect2,
409 arbitrary_rect1_inside_rect2,
[email protected]4934d362012-11-22 22:04:53410 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49411 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53412 arbitrary_matrix);
[email protected]3b85fd92014-07-10 00:00:02413 pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in,
414 streamvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53415
[email protected]16a6af152014-06-13 04:20:16416 cc::SurfaceId arbitrary_surface_id(3);
[email protected]3b85fd92014-07-10 00:00:02417 SurfaceDrawQuad* surface_in =
418 pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18419 surface_in->SetAll(shared_state3_in,
420 arbitrary_rect2,
421 arbitrary_rect2_inside_rect2,
422 arbitrary_rect1_inside_rect2,
423 arbitrary_bool1,
424 arbitrary_surface_id);
[email protected]3b85fd92014-07-10 00:00:02425 pass_cmp->CopyFromAndAppendDrawQuad(surface_in,
426 surface_in->shared_quad_state);
[email protected]78d30122014-01-17 06:32:36427
[email protected]3b85fd92014-07-10 00:00:02428 TextureDrawQuad* texture_in =
429 pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18430 texture_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42431 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30432 arbitrary_rect2_inside_rect2,
433 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42434 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49435 arbitrary_resourceid1,
[email protected]61df9d82013-01-30 02:32:42436 arbitrary_bool2,
437 arbitrary_pointf1,
438 arbitrary_pointf2,
[email protected]d18b4d62013-07-12 05:33:49439 arbitrary_color,
[email protected]61df9d82013-01-30 02:32:42440 arbitrary_float_array,
441 arbitrary_bool3);
[email protected]3b85fd92014-07-10 00:00:02442 pass_cmp->CopyFromAndAppendDrawQuad(texture_in,
443 texture_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42444
[email protected]3b85fd92014-07-10 00:00:02445 TileDrawQuad* tile_in = pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18446 tile_in->SetAll(shared_state3_in,
[email protected]61df9d82013-01-30 02:32:42447 arbitrary_rect2,
[email protected]8e1da692013-10-12 17:11:30448 arbitrary_rect2_inside_rect2,
449 arbitrary_rect1_inside_rect2,
[email protected]61df9d82013-01-30 02:32:42450 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49451 arbitrary_resourceid3,
[email protected]61df9d82013-01-30 02:32:42452 arbitrary_rectf1,
453 arbitrary_size1,
[email protected]f902bf92013-03-04 18:33:27454 arbitrary_bool2);
[email protected]3b85fd92014-07-10 00:00:02455 pass_cmp->CopyFromAndAppendDrawQuad(tile_in, tile_in->shared_quad_state);
[email protected]61df9d82013-01-30 02:32:42456
[email protected]3b85fd92014-07-10 00:00:02457 YUVVideoDrawQuad* yuvvideo_in =
458 pass_in->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
[email protected]2b7f3892014-05-08 01:45:18459 yuvvideo_in->SetAll(shared_state3_in,
[email protected]4934d362012-11-22 22:04:53460 arbitrary_rect1,
[email protected]8e1da692013-10-12 17:11:30461 arbitrary_rect2_inside_rect1,
462 arbitrary_rect1_inside_rect1,
[email protected]4934d362012-11-22 22:04:53463 arbitrary_bool1,
[email protected]95052aa2014-03-27 11:43:50464 arbitrary_rectf1,
[email protected]b7cfc632013-04-10 04:44:49465 arbitrary_resourceid1,
466 arbitrary_resourceid2,
[email protected]0402b2382013-06-07 21:50:54467 arbitrary_resourceid3,
[email protected]82faf5e2014-05-03 02:25:58468 arbitrary_resourceid4,
469 arbitrary_color_space);
[email protected]3b85fd92014-07-10 00:00:02470 pass_cmp->CopyFromAndAppendDrawQuad(yuvvideo_in,
471 yuvvideo_in->shared_quad_state);
[email protected]4934d362012-11-22 22:04:53472
473 // Make sure the in and cmp RenderPasses match.
474 Compare(pass_cmp.get(), pass_in.get());
475 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36476 ASSERT_EQ(10u, pass_in->quad_list.size());
[email protected]4934d362012-11-22 22:04:53477 for (size_t i = 0; i < 3; ++i) {
478 Compare(pass_cmp->shared_quad_state_list[i],
479 pass_in->shared_quad_state_list[i]);
480 }
[email protected]61df9d82013-01-30 02:32:42481 for (size_t i = 0; i < pass_in->quad_list.size(); ++i)
[email protected]4934d362012-11-22 22:04:53482 Compare(pass_cmp->quad_list[i], pass_in->quad_list[i]);
[email protected]61df9d82013-01-30 02:32:42483 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53484 bool same_shared_quad_state_cmp =
485 pass_cmp->quad_list[i]->shared_quad_state ==
486 pass_cmp->quad_list[i - 1]->shared_quad_state;
487 bool same_shared_quad_state_in =
488 pass_in->quad_list[i]->shared_quad_state ==
489 pass_in->quad_list[i - 1]->shared_quad_state;
490 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
491 }
492
[email protected]bf189f62012-12-18 03:42:11493 DelegatedFrameData frame_in;
[email protected]ead39c52013-01-09 07:22:45494 frame_in.render_pass_list.push_back(pass_in.Pass());
[email protected]4934d362012-11-22 22:04:53495
[email protected]bf189f62012-12-18 03:42:11496 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44497
[email protected]bf189f62012-12-18 03:42:11498 DelegatedFrameData frame_out;
[email protected]4934d362012-11-22 22:04:53499 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11500 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
501 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44502
[email protected]4934d362012-11-22 22:04:53503 // Make sure the out and cmp RenderPasses match.
[email protected]ead39c52013-01-09 07:22:45504 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
505 frame_out.render_pass_list.begin());
[email protected]4934d362012-11-22 22:04:53506 Compare(pass_cmp.get(), pass_out.get());
507 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
[email protected]78d30122014-01-17 06:32:36508 ASSERT_EQ(10u, pass_out->quad_list.size());
[email protected]4934d362012-11-22 22:04:53509 for (size_t i = 0; i < 3; ++i) {
510 Compare(pass_cmp->shared_quad_state_list[i],
511 pass_out->shared_quad_state_list[i]);
512 }
[email protected]61df9d82013-01-30 02:32:42513 for (size_t i = 0; i < pass_out->quad_list.size(); ++i)
[email protected]4934d362012-11-22 22:04:53514 Compare(pass_cmp->quad_list[i], pass_out->quad_list[i]);
[email protected]61df9d82013-01-30 02:32:42515 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53516 bool same_shared_quad_state_cmp =
517 pass_cmp->quad_list[i]->shared_quad_state ==
518 pass_cmp->quad_list[i - 1]->shared_quad_state;
519 bool same_shared_quad_state_out =
520 pass_out->quad_list[i]->shared_quad_state ==
521 pass_out->quad_list[i - 1]->shared_quad_state;
522 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
523 }
524}
[email protected]bca159072012-12-04 00:52:44525
[email protected]cbe94b7a2013-11-13 11:03:37526TEST_F(CCMessagesTest, UnusedSharedQuadStates) {
[email protected]cbe94b7a2013-11-13 11:03:37527 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
528 pass_in->SetAll(RenderPass::Id(1, 1),
529 gfx::Rect(100, 100),
[email protected]b4ead7b2014-04-07 18:12:18530 gfx::Rect(),
[email protected]cbe94b7a2013-11-13 11:03:37531 gfx::Transform(),
[email protected]8590da32014-03-28 20:49:07532 false);
[email protected]cbe94b7a2013-11-13 11:03:37533
534 // The first SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18535 SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22536 shared_state1_in->SetAll(gfx::Transform(),
537 gfx::Size(1, 1),
538 gfx::Rect(),
539 gfx::Rect(),
540 false,
541 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28542 SkXfermode::kSrcOver_Mode,
543 0);
[email protected]cbe94b7a2013-11-13 11:03:37544
[email protected]3b85fd92014-07-10 00:00:02545 CheckerboardDrawQuad* quad1 =
546 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
547 quad1->SetAll(shared_state1_in,
548 gfx::Rect(10, 10),
549 gfx::Rect(10, 10),
550 gfx::Rect(10, 10),
551 false,
552 SK_ColorRED);
[email protected]cbe94b7a2013-11-13 11:03:37553
554 // The second and third SharedQuadStates are not used.
[email protected]2b7f3892014-05-08 01:45:18555 SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22556 shared_state2_in->SetAll(gfx::Transform(),
557 gfx::Size(2, 2),
558 gfx::Rect(),
559 gfx::Rect(),
560 false,
561 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28562 SkXfermode::kSrcOver_Mode,
563 0);
[email protected]cbe94b7a2013-11-13 11:03:37564
[email protected]2b7f3892014-05-08 01:45:18565 SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22566 shared_state3_in->SetAll(gfx::Transform(),
567 gfx::Size(3, 3),
568 gfx::Rect(),
569 gfx::Rect(),
570 false,
571 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28572 SkXfermode::kSrcOver_Mode,
573 0);
[email protected]cbe94b7a2013-11-13 11:03:37574
575 // The fourth SharedQuadState is used.
[email protected]2b7f3892014-05-08 01:45:18576 SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22577 shared_state4_in->SetAll(gfx::Transform(),
578 gfx::Size(4, 4),
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
[email protected]3b85fd92014-07-10 00:00:02586 CheckerboardDrawQuad* quad2 =
587 pass_in->CreateAndAppendDrawQuad<CheckerboardDrawQuad>();
588 quad2->SetAll(shared_state4_in,
589 gfx::Rect(10, 10),
590 gfx::Rect(10, 10),
591 gfx::Rect(10, 10),
592 false,
593 SK_ColorRED);
[email protected]cbe94b7a2013-11-13 11:03:37594
595 // The fifth is not used again.
[email protected]2b7f3892014-05-08 01:45:18596 SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
[email protected]7bbeaf4e2013-11-26 10:27:22597 shared_state5_in->SetAll(gfx::Transform(),
598 gfx::Size(5, 5),
599 gfx::Rect(),
600 gfx::Rect(),
601 false,
602 1.f,
[email protected]a9d4d4f2014-06-19 06:49:28603 SkXfermode::kSrcOver_Mode,
604 0);
[email protected]cbe94b7a2013-11-13 11:03:37605
[email protected]cbe94b7a2013-11-13 11:03:37606 // 5 SharedQuadStates go in.
607 ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
608 ASSERT_EQ(2u, pass_in->quad_list.size());
609
610 DelegatedFrameData frame_in;
611 frame_in.render_pass_list.push_back(pass_in.Pass());
612
613 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
614 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
615
616 DelegatedFrameData frame_out;
617 PickleIterator iter(msg);
618 EXPECT_TRUE(
619 IPC::ParamTraits<DelegatedFrameData>::Read(&msg, &iter, &frame_out));
620
621 scoped_ptr<RenderPass> pass_out =
622 frame_out.render_pass_list.take(frame_out.render_pass_list.begin());
623
624 // 2 SharedQuadStates come out. The first and fourth SharedQuadStates were
625 // used by quads, and so serialized. Others were not.
626 ASSERT_EQ(2u, pass_out->shared_quad_state_list.size());
627 ASSERT_EQ(2u, pass_out->quad_list.size());
628
629 EXPECT_EQ(gfx::Size(1, 1).ToString(),
630 pass_out->shared_quad_state_list[0]->content_bounds.ToString());
631 EXPECT_EQ(gfx::Size(4, 4).ToString(),
632 pass_out->shared_quad_state_list[1]->content_bounds.ToString());
633}
634
[email protected]bca159072012-12-04 00:52:44635TEST_F(CCMessagesTest, Resources) {
[email protected]753bb252013-11-04 22:28:12636 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
[email protected]bca159072012-12-04 00:52:44637 gfx::Size arbitrary_size(757, 1281);
[email protected]09831f7f2013-02-27 03:32:15638 unsigned int arbitrary_uint1 = 71234838;
639 unsigned int arbitrary_uint2 = 53589793;
[email protected]bca159072012-12-04 00:52:44640
[email protected]e0a4d732014-02-15 00:23:26641 GLbyte arbitrary_mailbox1[GL_MAILBOX_SIZE_CHROMIUM] = {
642 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
643 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4,
644 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:44645
[email protected]e0a4d732014-02-15 00:23:26646 GLbyte arbitrary_mailbox2[GL_MAILBOX_SIZE_CHROMIUM] = {
647 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9,
648 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7,
649 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:44650
651 TransferableResource arbitrary_resource1;
652 arbitrary_resource1.id = 2178312;
[email protected]27a41fe2013-09-19 05:05:14653 arbitrary_resource1.format = cc::RGBA_8888;
[email protected]80189292013-02-28 01:59:36654 arbitrary_resource1.filter = 53;
[email protected]bca159072012-12-04 00:52:44655 arbitrary_resource1.size = gfx::Size(37189, 123123);
[email protected]df41e252014-02-03 23:39:50656 arbitrary_resource1.mailbox_holder.mailbox.SetName(arbitrary_mailbox1);
657 arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
658 arbitrary_resource1.mailbox_holder.sync_point = arbitrary_uint1;
[email protected]a8c63be22014-08-07 02:39:49659 arbitrary_resource1.allow_overlay = true;
[email protected]bca159072012-12-04 00:52:44660
661 TransferableResource arbitrary_resource2;
662 arbitrary_resource2.id = 789132;
[email protected]27a41fe2013-09-19 05:05:14663 arbitrary_resource2.format = cc::RGBA_4444;
[email protected]645a47f22013-09-26 05:42:32664 arbitrary_resource2.filter = 47;
[email protected]bca159072012-12-04 00:52:44665 arbitrary_resource2.size = gfx::Size(89123, 23789);
[email protected]df41e252014-02-03 23:39:50666 arbitrary_resource2.mailbox_holder.mailbox.SetName(arbitrary_mailbox2);
667 arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
668 arbitrary_resource2.mailbox_holder.sync_point = arbitrary_uint2;
[email protected]a8c63be22014-08-07 02:39:49669 arbitrary_resource2.allow_overlay = false;
[email protected]bca159072012-12-04 00:52:44670
[email protected]cb7d6492013-10-03 02:40:04671 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
672 renderpass_in->SetNew(
673 RenderPass::Id(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
674
[email protected]bf189f62012-12-18 03:42:11675 DelegatedFrameData frame_in;
[email protected]09831f7f2013-02-27 03:32:15676 frame_in.resource_list.push_back(arbitrary_resource1);
677 frame_in.resource_list.push_back(arbitrary_resource2);
[email protected]cb7d6492013-10-03 02:40:04678 frame_in.render_pass_list.push_back(renderpass_in.Pass());
[email protected]bca159072012-12-04 00:52:44679
[email protected]bf189f62012-12-18 03:42:11680 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44681
[email protected]bf189f62012-12-18 03:42:11682 DelegatedFrameData frame_out;
[email protected]bca159072012-12-04 00:52:44683 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11684 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
685 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44686
[email protected]09831f7f2013-02-27 03:32:15687 ASSERT_EQ(2u, frame_out.resource_list.size());
688 Compare(arbitrary_resource1, frame_out.resource_list[0]);
689 Compare(arbitrary_resource2, frame_out.resource_list[1]);
[email protected]bca159072012-12-04 00:52:44690}
691
[email protected]032bfc42013-10-29 22:23:52692TEST_F(CCMessagesTest, LargestQuadType) {
693 size_t largest = 0;
694
695 bool done = false;
696 for (int i = 0; !done; ++i) {
697 switch (static_cast<DrawQuad::Material>(i)) {
698 case cc::DrawQuad::CHECKERBOARD:
699 largest = std::max(largest, sizeof(cc::CheckerboardDrawQuad));
700 break;
701 case cc::DrawQuad::DEBUG_BORDER:
702 largest = std::max(largest, sizeof(cc::DebugBorderDrawQuad));
703 break;
704 case cc::DrawQuad::IO_SURFACE_CONTENT:
705 largest = std::max(largest, sizeof(cc::IOSurfaceDrawQuad));
706 break;
707 case cc::DrawQuad::PICTURE_CONTENT:
708 largest = std::max(largest, sizeof(cc::PictureDrawQuad));
709 break;
710 case cc::DrawQuad::TEXTURE_CONTENT:
711 largest = std::max(largest, sizeof(cc::TextureDrawQuad));
712 break;
713 case cc::DrawQuad::RENDER_PASS:
714 largest = std::max(largest, sizeof(cc::RenderPassDrawQuad));
715 break;
716 case cc::DrawQuad::SOLID_COLOR:
717 largest = std::max(largest, sizeof(cc::SolidColorDrawQuad));
718 break;
[email protected]78d30122014-01-17 06:32:36719 case cc::DrawQuad::SURFACE_CONTENT:
720 largest = std::max(largest, sizeof(cc::SurfaceDrawQuad));
721 break;
[email protected]032bfc42013-10-29 22:23:52722 case cc::DrawQuad::TILED_CONTENT:
723 largest = std::max(largest, sizeof(cc::TileDrawQuad));
724 break;
725 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
726 largest = std::max(largest, sizeof(cc::StreamVideoDrawQuad));
727 break;
728 case cc::DrawQuad::YUV_VIDEO_CONTENT:
729 largest = std::max(largest, sizeof(cc::YUVVideoDrawQuad));
730 break;
731 case cc::DrawQuad::INVALID:
732 break;
733 default:
734 done = true;
735 }
736 }
737
738 // Verify the largest DrawQuad type is RenderPassDrawQuad. If this ever
739 // changes, then the ReserveSizeForRenderPassWrite() method needs to be
740 // updated as well to use the new largest quad.
741 EXPECT_EQ(sizeof(RenderPassDrawQuad), largest);
742}
743
[email protected]cecc8342014-03-20 21:43:39744TEST_F(CCMessagesTest, SoftwareFrameData) {
745 cc::SoftwareFrameData frame_in;
746 frame_in.id = 3;
747 frame_in.size = gfx::Size(40, 20);
748 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56749 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39750
751 // Write the frame.
752 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
753 IPC::ParamTraits<cc::SoftwareFrameData>::Write(&msg, frame_in);
754
755 // Read the frame.
756 cc::SoftwareFrameData frame_out;
757 PickleIterator iter(msg);
758 EXPECT_TRUE(
759 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
760 EXPECT_EQ(frame_in.id, frame_out.id);
761 EXPECT_EQ(frame_in.size.ToString(), frame_out.size.ToString());
762 EXPECT_EQ(frame_in.damage_rect.ToString(), frame_out.damage_rect.ToString());
[email protected]f1970082014-04-09 04:29:56763 EXPECT_EQ(frame_in.bitmap_id, frame_out.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39764}
765
766TEST_F(CCMessagesTest, SoftwareFrameDataMaxInt) {
767 SoftwareFrameData frame_in;
768 frame_in.id = 3;
769 frame_in.size = gfx::Size(40, 20);
770 frame_in.damage_rect = gfx::Rect(5, 18, 31, 44);
[email protected]f1970082014-04-09 04:29:56771 frame_in.bitmap_id = cc::SharedBitmap::GenerateId();
[email protected]cecc8342014-03-20 21:43:39772
773 // Write the SoftwareFrameData by hand, make sure it works.
774 {
775 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
776 IPC::WriteParam(&msg, frame_in.id);
777 IPC::WriteParam(&msg, frame_in.size);
778 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56779 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39780 SoftwareFrameData frame_out;
781 PickleIterator iter(msg);
782 EXPECT_TRUE(
783 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
784 }
785
786 // The size of the frame may overflow when multiplied together.
787 int max = std::numeric_limits<int>::max();
788 frame_in.size = gfx::Size(max, max);
789
790 // If size_t is larger than int, then int*int*4 can always fit in size_t.
791 bool expect_read = sizeof(size_t) >= sizeof(int) * 2;
792
793 // Write the SoftwareFrameData with the MaxInt size, if it causes overflow it
794 // should fail.
795 {
796 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
797 IPC::WriteParam(&msg, frame_in.id);
798 IPC::WriteParam(&msg, frame_in.size);
799 IPC::WriteParam(&msg, frame_in.damage_rect);
[email protected]f1970082014-04-09 04:29:56800 IPC::WriteParam(&msg, frame_in.bitmap_id);
[email protected]cecc8342014-03-20 21:43:39801 SoftwareFrameData frame_out;
802 PickleIterator iter(msg);
803 EXPECT_EQ(
804 expect_read,
805 IPC::ParamTraits<SoftwareFrameData>::Read(&msg, &iter, &frame_out));
806 }
807}
808
[email protected]bca159072012-12-04 00:52:44809} // namespace
810} // namespace content