blob: ab3798cb8ba2a6dd4e541a11c57879dcbc8f31cf [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]a1765672013-08-12 23:45:029#include "base/command_line.h"
[email protected]7f0d825f2013-03-18 07:24:3010#include "cc/output/compositor_frame.h"
[email protected]a1765672013-08-12 23:45:0211#include "content/public/common/content_switches.h"
[email protected]4934d362012-11-22 22:04:5312#include "ipc/ipc_message.h"
13#include "testing/gtest/include/gtest/gtest.h"
[email protected]645a47f22013-09-26 05:42:3214#include "third_party/khronos/GLES2/gl2ext.h"
[email protected]a1765672013-08-12 23:45:0215#include "third_party/skia/include/effects/SkBlurImageFilter.h"
[email protected]4934d362012-11-22 22:04:5316
17using cc::CheckerboardDrawQuad;
[email protected]bf189f62012-12-18 03:42:1118using cc::DelegatedFrameData;
[email protected]4934d362012-11-22 22:04:5319using cc::DebugBorderDrawQuad;
20using cc::DrawQuad;
[email protected]ae6b1a72013-06-25 18:49:2921using cc::FilterOperation;
22using cc::FilterOperations;
[email protected]4934d362012-11-22 22:04:5323using cc::IOSurfaceDrawQuad;
[email protected]9ee4d3a2013-03-27 17:43:1624using cc::PictureDrawQuad;
[email protected]4934d362012-11-22 22:04:5325using cc::RenderPass;
26using cc::RenderPassDrawQuad;
27using cc::ResourceProvider;
28using cc::SharedQuadState;
29using cc::SolidColorDrawQuad;
30using cc::TextureDrawQuad;
31using cc::TileDrawQuad;
[email protected]bca159072012-12-04 00:52:4432using cc::TransferableResource;
[email protected]4934d362012-11-22 22:04:5333using cc::StreamVideoDrawQuad;
34using cc::VideoLayerImpl;
35using cc::YUVVideoDrawQuad;
[email protected]c8686a02012-11-27 08:29:0036using gfx::Transform;
[email protected]4934d362012-11-22 22:04:5337
[email protected]bca159072012-12-04 00:52:4438namespace content {
39namespace {
40
[email protected]4934d362012-11-22 22:04:5341class CCMessagesTest : public testing::Test {
42 protected:
43 void Compare(const RenderPass* a, const RenderPass* b) {
44 EXPECT_EQ(a->id, b->id);
45 EXPECT_EQ(a->output_rect.ToString(), b->output_rect.ToString());
46 EXPECT_EQ(a->damage_rect.ToString(), b->damage_rect.ToString());
47 EXPECT_EQ(a->transform_to_root_target, b->transform_to_root_target);
48 EXPECT_EQ(a->has_transparent_background, b->has_transparent_background);
[email protected]4934d362012-11-22 22:04:5349 }
50
51 void Compare(const SharedQuadState* a, const SharedQuadState* b) {
52 EXPECT_EQ(a->content_to_target_transform, b->content_to_target_transform);
[email protected]f902bf92013-03-04 18:33:2753 EXPECT_EQ(a->content_bounds, b->content_bounds);
[email protected]4934d362012-11-22 22:04:5354 EXPECT_EQ(a->visible_content_rect, b->visible_content_rect);
[email protected]4934d362012-11-22 22:04:5355 EXPECT_EQ(a->clip_rect, b->clip_rect);
56 EXPECT_EQ(a->is_clipped, b->is_clipped);
57 EXPECT_EQ(a->opacity, b->opacity);
58 }
59
60 void Compare(const DrawQuad* a, const DrawQuad* b) {
61 ASSERT_NE(DrawQuad::INVALID, a->material);
62 ASSERT_EQ(a->material, b->material);
63 EXPECT_EQ(a->rect.ToString(), b->rect.ToString());
64 EXPECT_EQ(a->opaque_rect.ToString(), b->opaque_rect.ToString());
65 EXPECT_EQ(a->visible_rect.ToString(), b->visible_rect.ToString());
66 EXPECT_EQ(a->needs_blending, b->needs_blending);
67
68 Compare(a->shared_quad_state, b->shared_quad_state);
69
70 switch (a->material) {
71 case DrawQuad::CHECKERBOARD:
72 Compare(CheckerboardDrawQuad::MaterialCast(a),
73 CheckerboardDrawQuad::MaterialCast(b));
74 break;
75 case DrawQuad::DEBUG_BORDER:
76 Compare(DebugBorderDrawQuad::MaterialCast(a),
77 DebugBorderDrawQuad::MaterialCast(b));
78 break;
79 case DrawQuad::IO_SURFACE_CONTENT:
80 Compare(IOSurfaceDrawQuad::MaterialCast(a),
81 IOSurfaceDrawQuad::MaterialCast(b));
82 break;
[email protected]9ee4d3a2013-03-27 17:43:1683 case DrawQuad::PICTURE_CONTENT:
84 Compare(PictureDrawQuad::MaterialCast(a),
85 PictureDrawQuad::MaterialCast(b));
86 break;
[email protected]4934d362012-11-22 22:04:5387 case DrawQuad::RENDER_PASS:
88 Compare(RenderPassDrawQuad::MaterialCast(a),
89 RenderPassDrawQuad::MaterialCast(b));
90 break;
91 case DrawQuad::TEXTURE_CONTENT:
92 Compare(TextureDrawQuad::MaterialCast(a),
93 TextureDrawQuad::MaterialCast(b));
94 break;
95 case DrawQuad::TILED_CONTENT:
96 Compare(TileDrawQuad::MaterialCast(a),
97 TileDrawQuad::MaterialCast(b));
98 break;
99 case DrawQuad::SOLID_COLOR:
100 Compare(SolidColorDrawQuad::MaterialCast(a),
101 SolidColorDrawQuad::MaterialCast(b));
102 break;
103 case DrawQuad::STREAM_VIDEO_CONTENT:
104 Compare(StreamVideoDrawQuad::MaterialCast(a),
105 StreamVideoDrawQuad::MaterialCast(b));
106 break;
107 case DrawQuad::YUV_VIDEO_CONTENT:
108 Compare(YUVVideoDrawQuad::MaterialCast(a),
109 YUVVideoDrawQuad::MaterialCast(b));
110 break;
111 case DrawQuad::INVALID:
112 break;
113 }
114 }
115
116 void Compare(const CheckerboardDrawQuad* a, const CheckerboardDrawQuad* b) {
117 EXPECT_EQ(a->color, b->color);
118 }
119
120 void Compare(const DebugBorderDrawQuad* a, const DebugBorderDrawQuad* b) {
121 EXPECT_EQ(a->color, b->color);
122 EXPECT_EQ(a->width, b->width);
123 }
124
125 void Compare(const IOSurfaceDrawQuad* a, const IOSurfaceDrawQuad* b) {
126 EXPECT_EQ(a->io_surface_size.ToString(), b->io_surface_size.ToString());
[email protected]b7cfc632013-04-10 04:44:49127 EXPECT_EQ(a->io_surface_resource_id, b->io_surface_resource_id);
[email protected]4934d362012-11-22 22:04:53128 EXPECT_EQ(a->orientation, b->orientation);
129 }
130
131 void Compare(const RenderPassDrawQuad* a, const RenderPassDrawQuad* b) {
[email protected]82f93fb2013-04-17 21:42:06132 EXPECT_EQ(a->render_pass_id, b->render_pass_id);
[email protected]4934d362012-11-22 22:04:53133 EXPECT_EQ(a->is_replica, b->is_replica);
134 EXPECT_EQ(a->mask_resource_id, b->mask_resource_id);
135 EXPECT_EQ(a->contents_changed_since_last_frame,
136 b->contents_changed_since_last_frame);
[email protected]458af1e2012-12-13 05:12:18137 EXPECT_EQ(a->mask_uv_rect.ToString(), b->mask_uv_rect.ToString());
[email protected]1dc7943e2013-09-26 04:41:48138 EXPECT_EQ(a->filters.size(), b->filters.size());
139 for (size_t i = 0; i < a->filters.size(); ++i) {
140 if (a->filters.at(i).type() != cc::FilterOperation::REFERENCE) {
141 EXPECT_EQ(a->filters.at(i), b->filters.at(i));
142 } else {
143 EXPECT_EQ(b->filters.at(i).type(), cc::FilterOperation::REFERENCE);
144 EXPECT_EQ(a->filters.at(i).image_filter()->countInputs(),
145 b->filters.at(i).image_filter()->countInputs());
146 }
147 }
[email protected]20062042012-12-21 22:16:36148 EXPECT_EQ(a->background_filters, b->background_filters);
[email protected]4934d362012-11-22 22:04:53149 }
150
151 void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
152 EXPECT_EQ(a->color, b->color);
[email protected]10a30b12013-05-02 16:42:11153 EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
[email protected]4934d362012-11-22 22:04:53154 }
155
156 void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) {
[email protected]b7cfc632013-04-10 04:44:49157 EXPECT_EQ(a->resource_id, b->resource_id);
[email protected]4934d362012-11-22 22:04:53158 EXPECT_EQ(a->matrix, b->matrix);
159 }
160
161 void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
162 EXPECT_EQ(a->resource_id, b->resource_id);
163 EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha);
[email protected]1fd555b2013-01-18 00:13:21164 EXPECT_EQ(a->uv_top_left, b->uv_top_left);
165 EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right);
[email protected]d18b4d62013-07-12 05:33:49166 EXPECT_EQ(a->background_color, b->background_color);
[email protected]61df9d82013-01-30 02:32:42167 EXPECT_EQ(a->vertex_opacity[0], b->vertex_opacity[0]);
168 EXPECT_EQ(a->vertex_opacity[1], b->vertex_opacity[1]);
169 EXPECT_EQ(a->vertex_opacity[2], b->vertex_opacity[2]);
170 EXPECT_EQ(a->vertex_opacity[3], b->vertex_opacity[3]);
[email protected]4934d362012-11-22 22:04:53171 EXPECT_EQ(a->flipped, b->flipped);
172 }
173
174 void Compare(const TileDrawQuad* a, const TileDrawQuad* b) {
175 EXPECT_EQ(a->resource_id, b->resource_id);
176 EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
177 EXPECT_EQ(a->texture_size, b->texture_size);
178 EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
[email protected]4934d362012-11-22 22:04:53179 }
180
181 void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
182 EXPECT_EQ(a->tex_scale, b->tex_scale);
[email protected]b7cfc632013-04-10 04:44:49183 EXPECT_EQ(a->y_plane_resource_id, b->y_plane_resource_id);
184 EXPECT_EQ(a->u_plane_resource_id, b->u_plane_resource_id);
185 EXPECT_EQ(a->v_plane_resource_id, b->v_plane_resource_id);
[email protected]0402b2382013-06-07 21:50:54186 EXPECT_EQ(a->a_plane_resource_id, b->a_plane_resource_id);
[email protected]4934d362012-11-22 22:04:53187 }
[email protected]bca159072012-12-04 00:52:44188
189 void Compare(const TransferableResource& a, const TransferableResource& b) {
190 EXPECT_EQ(a.id, b.id);
[email protected]09831f7f2013-02-27 03:32:15191 EXPECT_EQ(a.sync_point, b.sync_point);
[email protected]bca159072012-12-04 00:52:44192 EXPECT_EQ(a.format, b.format);
[email protected]645a47f22013-09-26 05:42:32193 EXPECT_EQ(a.target, b.target);
[email protected]80189292013-02-28 01:59:36194 EXPECT_EQ(a.filter, b.filter);
[email protected]bca159072012-12-04 00:52:44195 EXPECT_EQ(a.size.ToString(), b.size.ToString());
196 for (size_t i = 0; i < arraysize(a.mailbox.name); ++i)
197 EXPECT_EQ(a.mailbox.name[i], b.mailbox.name[i]);
198 }
[email protected]4934d362012-11-22 22:04:53199};
200
201TEST_F(CCMessagesTest, AllQuads) {
[email protected]a1765672013-08-12 23:45:02202 CommandLine& command_line = *CommandLine::ForCurrentProcess();
203 if (!command_line.HasSwitch(switches::kAllowFiltersOverIPC))
204 command_line.AppendSwitch(switches::kAllowFiltersOverIPC);
205
[email protected]4934d362012-11-22 22:04:53206 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
207
[email protected]c8686a02012-11-27 08:29:00208 Transform arbitrary_matrix;
209 arbitrary_matrix.Scale(3, 3);
210 arbitrary_matrix.Translate(-5, 20);
211 arbitrary_matrix.Rotate(15);
[email protected]4934d362012-11-22 22:04:53212 gfx::Rect arbitrary_rect1(-5, 9, 3, 15);
213 gfx::Rect arbitrary_rect2(40, 23, 11, 7);
214 gfx::Rect arbitrary_rect3(7, -53, 22, 19);
215 gfx::Size arbitrary_size1(15, 19);
216 gfx::Size arbitrary_size2(3, 99);
217 gfx::Size arbitrary_size3(75, 1281);
218 gfx::RectF arbitrary_rectf1(4.2f, -922.1f, 15.6f, 29.5f);
219 gfx::SizeF arbitrary_sizef1(15.2f, 104.6f);
[email protected]61df9d82013-01-30 02:32:42220 gfx::PointF arbitrary_pointf1(31.4f, 15.9f);
221 gfx::PointF arbitrary_pointf2(26.5f, -35.8f);
[email protected]4934d362012-11-22 22:04:53222 float arbitrary_float1 = 0.7f;
223 float arbitrary_float2 = 0.3f;
224 float arbitrary_float3 = 0.9f;
[email protected]61df9d82013-01-30 02:32:42225 float arbitrary_float_array[4] = {3.5f, 6.2f, 9.3f, 12.3f};
[email protected]4934d362012-11-22 22:04:53226 bool arbitrary_bool1 = true;
227 bool arbitrary_bool2 = false;
[email protected]61df9d82013-01-30 02:32:42228 bool arbitrary_bool3 = true;
[email protected]4934d362012-11-22 22:04:53229 int arbitrary_int = 5;
230 SkColor arbitrary_color = SkColorSetARGB(25, 36, 47, 58);
231 IOSurfaceDrawQuad::Orientation arbitrary_orientation =
232 IOSurfaceDrawQuad::UNFLIPPED;
233 RenderPass::Id arbitrary_id(10, 14);
[email protected]b7cfc632013-04-10 04:44:49234 ResourceProvider::ResourceId arbitrary_resourceid1 = 55;
235 ResourceProvider::ResourceId arbitrary_resourceid2 = 47;
236 ResourceProvider::ResourceId arbitrary_resourceid3 = 23;
[email protected]0402b2382013-06-07 21:50:54237 ResourceProvider::ResourceId arbitrary_resourceid4 = 16;
[email protected]a1765672013-08-12 23:45:02238 SkScalar arbitrary_sigma = SkFloatToScalar(2.0f);
[email protected]4934d362012-11-22 22:04:53239
[email protected]ae6b1a72013-06-25 18:49:29240 FilterOperations arbitrary_filters1;
241 arbitrary_filters1.Append(FilterOperation::CreateGrayscaleFilter(
[email protected]4934d362012-11-22 22:04:53242 arbitrary_float1));
[email protected]1dc7943e2013-09-26 04:41:48243 skia::RefPtr<SkImageFilter> arbitrary_filter = skia::AdoptRef(
244 new SkBlurImageFilter(arbitrary_sigma, arbitrary_sigma));
245 arbitrary_filters1.Append(
246 cc::FilterOperation::CreateReferenceFilter(arbitrary_filter));
[email protected]4934d362012-11-22 22:04:53247
[email protected]ae6b1a72013-06-25 18:49:29248 FilterOperations arbitrary_filters2;
249 arbitrary_filters2.Append(FilterOperation::CreateBrightnessFilter(
[email protected]4934d362012-11-22 22:04:53250 arbitrary_float2));
251
252 scoped_ptr<SharedQuadState> shared_state1_in = SharedQuadState::Create();
253 shared_state1_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27254 arbitrary_size1,
[email protected]4934d362012-11-22 22:04:53255 arbitrary_rect1,
256 arbitrary_rect2,
[email protected]4934d362012-11-22 22:04:53257 arbitrary_bool1,
258 arbitrary_float1);
259 scoped_ptr<SharedQuadState> shared_state1_cmp = shared_state1_in->Copy();
260
261 scoped_ptr<CheckerboardDrawQuad> checkerboard_in =
262 CheckerboardDrawQuad::Create();
263 checkerboard_in->SetAll(shared_state1_in.get(),
264 arbitrary_rect1,
265 arbitrary_rect2,
266 arbitrary_rect3,
267 arbitrary_bool1,
268 arbitrary_color);
269 scoped_ptr<DrawQuad> checkerboard_cmp = checkerboard_in->Copy(
270 checkerboard_in->shared_quad_state);
271
272 scoped_ptr<DebugBorderDrawQuad> debugborder_in =
273 DebugBorderDrawQuad::Create();
274 debugborder_in->SetAll(shared_state1_in.get(),
275 arbitrary_rect3,
276 arbitrary_rect1,
277 arbitrary_rect2,
278 arbitrary_bool1,
279 arbitrary_color,
280 arbitrary_int);
281 scoped_ptr<DrawQuad> debugborder_cmp = debugborder_in->Copy(
282 debugborder_in->shared_quad_state);
283
284 scoped_ptr<IOSurfaceDrawQuad> iosurface_in =
285 IOSurfaceDrawQuad::Create();
286 iosurface_in->SetAll(shared_state1_in.get(),
287 arbitrary_rect2,
288 arbitrary_rect3,
289 arbitrary_rect1,
290 arbitrary_bool1,
291 arbitrary_size1,
[email protected]b7cfc632013-04-10 04:44:49292 arbitrary_resourceid3,
[email protected]4934d362012-11-22 22:04:53293 arbitrary_orientation);
294 scoped_ptr<DrawQuad> iosurface_cmp = iosurface_in->Copy(
295 iosurface_in->shared_quad_state);
296
297 scoped_ptr<RenderPassDrawQuad> renderpass_in =
298 RenderPassDrawQuad::Create();
299 renderpass_in->SetAll(shared_state1_in.get(),
300 arbitrary_rect1,
301 arbitrary_rect2,
302 arbitrary_rect3,
303 arbitrary_bool1,
304 arbitrary_id,
305 arbitrary_bool2,
[email protected]b7cfc632013-04-10 04:44:49306 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53307 arbitrary_rect1,
[email protected]20062042012-12-21 22:16:36308 arbitrary_rectf1,
309 arbitrary_filters1,
[email protected]20062042012-12-21 22:16:36310 arbitrary_filters2);
[email protected]4934d362012-11-22 22:04:53311 scoped_ptr<RenderPassDrawQuad> renderpass_cmp = renderpass_in->Copy(
312 renderpass_in->shared_quad_state, renderpass_in->render_pass_id);
313
314 scoped_ptr<SharedQuadState> shared_state2_in = SharedQuadState::Create();
315 shared_state2_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27316 arbitrary_size2,
[email protected]4934d362012-11-22 22:04:53317 arbitrary_rect2,
318 arbitrary_rect3,
[email protected]4934d362012-11-22 22:04:53319 arbitrary_bool1,
320 arbitrary_float2);
321 scoped_ptr<SharedQuadState> shared_state2_cmp = shared_state2_in->Copy();
322
323 scoped_ptr<SharedQuadState> shared_state3_in = SharedQuadState::Create();
324 shared_state3_in->SetAll(arbitrary_matrix,
[email protected]f902bf92013-03-04 18:33:27325 arbitrary_size3,
[email protected]4934d362012-11-22 22:04:53326 arbitrary_rect3,
327 arbitrary_rect1,
[email protected]4934d362012-11-22 22:04:53328 arbitrary_bool1,
329 arbitrary_float3);
330 scoped_ptr<SharedQuadState> shared_state3_cmp = shared_state3_in->Copy();
331
332 scoped_ptr<SolidColorDrawQuad> solidcolor_in =
333 SolidColorDrawQuad::Create();
334 solidcolor_in->SetAll(shared_state1_in.get(),
335 arbitrary_rect3,
336 arbitrary_rect1,
337 arbitrary_rect2,
338 arbitrary_bool1,
[email protected]10a30b12013-05-02 16:42:11339 arbitrary_color,
340 arbitrary_bool2);
[email protected]4934d362012-11-22 22:04:53341 scoped_ptr<DrawQuad> solidcolor_cmp = solidcolor_in->Copy(
342 solidcolor_in->shared_quad_state);
343
344 scoped_ptr<StreamVideoDrawQuad> streamvideo_in =
345 StreamVideoDrawQuad::Create();
346 streamvideo_in->SetAll(shared_state1_in.get(),
347 arbitrary_rect2,
348 arbitrary_rect3,
349 arbitrary_rect1,
350 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49351 arbitrary_resourceid2,
[email protected]4934d362012-11-22 22:04:53352 arbitrary_matrix);
353 scoped_ptr<DrawQuad> streamvideo_cmp = streamvideo_in->Copy(
354 streamvideo_in->shared_quad_state);
355
[email protected]61df9d82013-01-30 02:32:42356 scoped_ptr<TextureDrawQuad> texture_in = TextureDrawQuad::Create();
357 texture_in->SetAll(shared_state1_in.get(),
358 arbitrary_rect2,
359 arbitrary_rect3,
360 arbitrary_rect1,
361 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49362 arbitrary_resourceid1,
[email protected]61df9d82013-01-30 02:32:42363 arbitrary_bool2,
364 arbitrary_pointf1,
365 arbitrary_pointf2,
[email protected]d18b4d62013-07-12 05:33:49366 arbitrary_color,
[email protected]61df9d82013-01-30 02:32:42367 arbitrary_float_array,
368 arbitrary_bool3);
369 scoped_ptr<DrawQuad> texture_cmp = texture_in->Copy(
370 texture_in->shared_quad_state);
371
372 scoped_ptr<TileDrawQuad> tile_in = TileDrawQuad::Create();
373 tile_in->SetAll(shared_state1_in.get(),
374 arbitrary_rect2,
375 arbitrary_rect3,
376 arbitrary_rect1,
377 arbitrary_bool1,
[email protected]b7cfc632013-04-10 04:44:49378 arbitrary_resourceid3,
[email protected]61df9d82013-01-30 02:32:42379 arbitrary_rectf1,
380 arbitrary_size1,
[email protected]f902bf92013-03-04 18:33:27381 arbitrary_bool2);
[email protected]61df9d82013-01-30 02:32:42382 scoped_ptr<DrawQuad> tile_cmp = tile_in->Copy(
383 tile_in->shared_quad_state);
384
[email protected]4934d362012-11-22 22:04:53385 scoped_ptr<YUVVideoDrawQuad> yuvvideo_in =
386 YUVVideoDrawQuad::Create();
387 yuvvideo_in->SetAll(shared_state1_in.get(),
388 arbitrary_rect1,
389 arbitrary_rect2,
390 arbitrary_rect3,
391 arbitrary_bool1,
392 arbitrary_sizef1,
[email protected]b7cfc632013-04-10 04:44:49393 arbitrary_resourceid1,
394 arbitrary_resourceid2,
[email protected]0402b2382013-06-07 21:50:54395 arbitrary_resourceid3,
396 arbitrary_resourceid4);
[email protected]4934d362012-11-22 22:04:53397 scoped_ptr<DrawQuad> yuvvideo_cmp = yuvvideo_in->Copy(
398 yuvvideo_in->shared_quad_state);
399
400 scoped_ptr<RenderPass> pass_in = RenderPass::Create();
401 pass_in->SetAll(arbitrary_id,
402 arbitrary_rect1,
403 arbitrary_rectf1,
404 arbitrary_matrix,
[email protected]fbc293322013-10-01 05:07:15405 arbitrary_bool1);
[email protected]4934d362012-11-22 22:04:53406
[email protected]ead39c52013-01-09 07:22:45407 pass_in->shared_quad_state_list.push_back(shared_state1_in.Pass());
408 pass_in->quad_list.push_back(checkerboard_in.PassAs<DrawQuad>());
409 pass_in->quad_list.push_back(debugborder_in.PassAs<DrawQuad>());
410 pass_in->quad_list.push_back(iosurface_in.PassAs<DrawQuad>());
411 pass_in->quad_list.push_back(renderpass_in.PassAs<DrawQuad>());
412 pass_in->shared_quad_state_list.push_back(shared_state2_in.Pass());
413 pass_in->shared_quad_state_list.push_back(shared_state3_in.Pass());
414 pass_in->quad_list.push_back(solidcolor_in.PassAs<DrawQuad>());
415 pass_in->quad_list.push_back(streamvideo_in.PassAs<DrawQuad>());
[email protected]61df9d82013-01-30 02:32:42416 pass_in->quad_list.push_back(texture_in.PassAs<DrawQuad>());
417 pass_in->quad_list.push_back(tile_in.PassAs<DrawQuad>());
[email protected]ead39c52013-01-09 07:22:45418 pass_in->quad_list.push_back(yuvvideo_in.PassAs<DrawQuad>());
[email protected]4934d362012-11-22 22:04:53419
420 scoped_ptr<RenderPass> pass_cmp = RenderPass::Create();
421 pass_cmp->SetAll(arbitrary_id,
422 arbitrary_rect1,
423 arbitrary_rectf1,
424 arbitrary_matrix,
[email protected]fbc293322013-10-01 05:07:15425 arbitrary_bool1);
[email protected]4934d362012-11-22 22:04:53426
[email protected]ead39c52013-01-09 07:22:45427 pass_cmp->shared_quad_state_list.push_back(shared_state1_cmp.Pass());
428 pass_cmp->quad_list.push_back(checkerboard_cmp.PassAs<DrawQuad>());
429 pass_cmp->quad_list.push_back(debugborder_cmp.PassAs<DrawQuad>());
430 pass_cmp->quad_list.push_back(iosurface_cmp.PassAs<DrawQuad>());
431 pass_cmp->quad_list.push_back(renderpass_cmp.PassAs<DrawQuad>());
432 pass_cmp->shared_quad_state_list.push_back(shared_state2_cmp.Pass());
433 pass_cmp->shared_quad_state_list.push_back(shared_state3_cmp.Pass());
434 pass_cmp->quad_list.push_back(solidcolor_cmp.PassAs<DrawQuad>());
435 pass_cmp->quad_list.push_back(streamvideo_cmp.PassAs<DrawQuad>());
[email protected]61df9d82013-01-30 02:32:42436 pass_cmp->quad_list.push_back(texture_cmp.PassAs<DrawQuad>());
437 pass_cmp->quad_list.push_back(tile_cmp.PassAs<DrawQuad>());
[email protected]ead39c52013-01-09 07:22:45438 pass_cmp->quad_list.push_back(yuvvideo_cmp.PassAs<DrawQuad>());
[email protected]4934d362012-11-22 22:04:53439
440 // Make sure the in and cmp RenderPasses match.
441 Compare(pass_cmp.get(), pass_in.get());
442 ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
[email protected]61df9d82013-01-30 02:32:42443 ASSERT_EQ(9u, pass_in->quad_list.size());
[email protected]4934d362012-11-22 22:04:53444 for (size_t i = 0; i < 3; ++i) {
445 Compare(pass_cmp->shared_quad_state_list[i],
446 pass_in->shared_quad_state_list[i]);
447 }
[email protected]61df9d82013-01-30 02:32:42448 for (size_t i = 0; i < pass_in->quad_list.size(); ++i)
[email protected]4934d362012-11-22 22:04:53449 Compare(pass_cmp->quad_list[i], pass_in->quad_list[i]);
[email protected]61df9d82013-01-30 02:32:42450 for (size_t i = 1; i < pass_in->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53451 bool same_shared_quad_state_cmp =
452 pass_cmp->quad_list[i]->shared_quad_state ==
453 pass_cmp->quad_list[i - 1]->shared_quad_state;
454 bool same_shared_quad_state_in =
455 pass_in->quad_list[i]->shared_quad_state ==
456 pass_in->quad_list[i - 1]->shared_quad_state;
457 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_in);
458 }
459
[email protected]bf189f62012-12-18 03:42:11460 DelegatedFrameData frame_in;
[email protected]ead39c52013-01-09 07:22:45461 frame_in.render_pass_list.push_back(pass_in.Pass());
[email protected]4934d362012-11-22 22:04:53462
[email protected]bf189f62012-12-18 03:42:11463 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44464
[email protected]bf189f62012-12-18 03:42:11465 DelegatedFrameData frame_out;
[email protected]4934d362012-11-22 22:04:53466 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11467 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
468 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44469
[email protected]4934d362012-11-22 22:04:53470 // Make sure the out and cmp RenderPasses match.
[email protected]ead39c52013-01-09 07:22:45471 scoped_ptr<RenderPass> pass_out = frame_out.render_pass_list.take(
472 frame_out.render_pass_list.begin());
[email protected]4934d362012-11-22 22:04:53473 Compare(pass_cmp.get(), pass_out.get());
474 ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
[email protected]61df9d82013-01-30 02:32:42475 ASSERT_EQ(9u, pass_out->quad_list.size());
[email protected]4934d362012-11-22 22:04:53476 for (size_t i = 0; i < 3; ++i) {
477 Compare(pass_cmp->shared_quad_state_list[i],
478 pass_out->shared_quad_state_list[i]);
479 }
[email protected]61df9d82013-01-30 02:32:42480 for (size_t i = 0; i < pass_out->quad_list.size(); ++i)
[email protected]4934d362012-11-22 22:04:53481 Compare(pass_cmp->quad_list[i], pass_out->quad_list[i]);
[email protected]61df9d82013-01-30 02:32:42482 for (size_t i = 1; i < pass_out->quad_list.size(); ++i) {
[email protected]4934d362012-11-22 22:04:53483 bool same_shared_quad_state_cmp =
484 pass_cmp->quad_list[i]->shared_quad_state ==
485 pass_cmp->quad_list[i - 1]->shared_quad_state;
486 bool same_shared_quad_state_out =
487 pass_out->quad_list[i]->shared_quad_state ==
488 pass_out->quad_list[i - 1]->shared_quad_state;
489 EXPECT_EQ(same_shared_quad_state_cmp, same_shared_quad_state_out);
490 }
491}
[email protected]bca159072012-12-04 00:52:44492
493TEST_F(CCMessagesTest, Resources) {
494 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
495 gfx::Size arbitrary_size(757, 1281);
[email protected]09831f7f2013-02-27 03:32:15496 unsigned int arbitrary_uint1 = 71234838;
497 unsigned int arbitrary_uint2 = 53589793;
[email protected]bca159072012-12-04 00:52:44498
499 GLbyte arbitrary_mailbox1[64] = {
500 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
501 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
502 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
503 1, 2, 3, 4
504 };
505
506 GLbyte arbitrary_mailbox2[64] = {
507 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0,
508 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0,
509 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0,
510 0, 9, 8, 7
511 };
512
513 TransferableResource arbitrary_resource1;
514 arbitrary_resource1.id = 2178312;
[email protected]09831f7f2013-02-27 03:32:15515 arbitrary_resource1.sync_point = arbitrary_uint1;
[email protected]27a41fe2013-09-19 05:05:14516 arbitrary_resource1.format = cc::RGBA_8888;
[email protected]645a47f22013-09-26 05:42:32517 arbitrary_resource1.target = GL_TEXTURE_2D;
[email protected]80189292013-02-28 01:59:36518 arbitrary_resource1.filter = 53;
[email protected]bca159072012-12-04 00:52:44519 arbitrary_resource1.size = gfx::Size(37189, 123123);
[email protected]1aca0092013-03-04 22:46:03520 arbitrary_resource1.mailbox.SetName(arbitrary_mailbox1);
[email protected]bca159072012-12-04 00:52:44521
522 TransferableResource arbitrary_resource2;
523 arbitrary_resource2.id = 789132;
[email protected]645a47f22013-09-26 05:42:32524 arbitrary_resource2.sync_point = arbitrary_uint2;
[email protected]27a41fe2013-09-19 05:05:14525 arbitrary_resource2.format = cc::RGBA_4444;
[email protected]645a47f22013-09-26 05:42:32526 arbitrary_resource2.target = GL_TEXTURE_EXTERNAL_OES;
527 arbitrary_resource2.filter = 47;
[email protected]bca159072012-12-04 00:52:44528 arbitrary_resource2.size = gfx::Size(89123, 23789);
[email protected]1aca0092013-03-04 22:46:03529 arbitrary_resource2.mailbox.SetName(arbitrary_mailbox2);
[email protected]bca159072012-12-04 00:52:44530
[email protected]cb7d6492013-10-03 02:40:04531 scoped_ptr<RenderPass> renderpass_in = RenderPass::Create();
532 renderpass_in->SetNew(
533 RenderPass::Id(1, 1), gfx::Rect(), gfx::Rect(), gfx::Transform());
534
[email protected]bf189f62012-12-18 03:42:11535 DelegatedFrameData frame_in;
[email protected]09831f7f2013-02-27 03:32:15536 frame_in.resource_list.push_back(arbitrary_resource1);
537 frame_in.resource_list.push_back(arbitrary_resource2);
[email protected]cb7d6492013-10-03 02:40:04538 frame_in.render_pass_list.push_back(renderpass_in.Pass());
[email protected]bca159072012-12-04 00:52:44539
[email protected]bf189f62012-12-18 03:42:11540 IPC::ParamTraits<DelegatedFrameData>::Write(&msg, frame_in);
[email protected]bca159072012-12-04 00:52:44541
[email protected]bf189f62012-12-18 03:42:11542 DelegatedFrameData frame_out;
[email protected]bca159072012-12-04 00:52:44543 PickleIterator iter(msg);
[email protected]bf189f62012-12-18 03:42:11544 EXPECT_TRUE(IPC::ParamTraits<DelegatedFrameData>::Read(&msg,
545 &iter, &frame_out));
[email protected]bca159072012-12-04 00:52:44546
[email protected]09831f7f2013-02-27 03:32:15547 ASSERT_EQ(2u, frame_out.resource_list.size());
548 Compare(arbitrary_resource1, frame_out.resource_list[0]);
549 Compare(arbitrary_resource2, frame_out.resource_list[1]);
[email protected]bca159072012-12-04 00:52:44550}
551
552} // namespace
553} // namespace content