Remove obsolete Channel ID expiration time from site data viewer.
[chromium-blink-merge.git] / content / common / cc_messages.cc
blobf8e0d7495b73b4b3162956178750abe4cb6e8d25
1 // 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.
5 #include "content/common/cc_messages.h"
7 #include "cc/output/compositor_frame.h"
8 #include "content/public/common/common_param_traits.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h"
11 #include "ui/gfx/transform.h"
13 namespace IPC {
15 void ParamTraits<WebKit::WebFilterOperation>::Write(
16 Message* m, const param_type& p) {
17 WriteParam(m, p.type());
18 switch (p.type()) {
19 case WebKit::WebFilterOperation::FilterTypeGrayscale:
20 case WebKit::WebFilterOperation::FilterTypeSepia:
21 case WebKit::WebFilterOperation::FilterTypeSaturate:
22 case WebKit::WebFilterOperation::FilterTypeHueRotate:
23 case WebKit::WebFilterOperation::FilterTypeInvert:
24 case WebKit::WebFilterOperation::FilterTypeBrightness:
25 case WebKit::WebFilterOperation::FilterTypeSaturatingBrightness:
26 case WebKit::WebFilterOperation::FilterTypeContrast:
27 case WebKit::WebFilterOperation::FilterTypeOpacity:
28 case WebKit::WebFilterOperation::FilterTypeBlur:
29 WriteParam(m, p.amount());
30 break;
31 case WebKit::WebFilterOperation::FilterTypeDropShadow:
32 WriteParam(m, p.dropShadowOffset());
33 WriteParam(m, p.amount());
34 WriteParam(m, p.dropShadowColor());
35 break;
36 case WebKit::WebFilterOperation::FilterTypeColorMatrix:
37 for (int i = 0; i < 20; ++i)
38 WriteParam(m, p.matrix()[i]);
39 break;
40 case WebKit::WebFilterOperation::FilterTypeZoom:
41 WriteParam(m, p.amount());
42 WriteParam(m, p.zoomInset());
43 break;
47 bool ParamTraits<WebKit::WebFilterOperation>::Read(
48 const Message* m, PickleIterator* iter, param_type* r) {
49 WebKit::WebFilterOperation::FilterType type;
50 float amount;
51 WebKit::WebPoint dropShadowOffset;
52 WebKit::WebColor dropShadowColor;
53 SkScalar matrix[20];
54 int zoom_inset;
56 if (!ReadParam(m, iter, &type))
57 return false;
58 r->setType(type);
60 bool success = false;
61 switch (type) {
62 case WebKit::WebFilterOperation::FilterTypeGrayscale:
63 case WebKit::WebFilterOperation::FilterTypeSepia:
64 case WebKit::WebFilterOperation::FilterTypeSaturate:
65 case WebKit::WebFilterOperation::FilterTypeHueRotate:
66 case WebKit::WebFilterOperation::FilterTypeInvert:
67 case WebKit::WebFilterOperation::FilterTypeBrightness:
68 case WebKit::WebFilterOperation::FilterTypeSaturatingBrightness:
69 case WebKit::WebFilterOperation::FilterTypeContrast:
70 case WebKit::WebFilterOperation::FilterTypeOpacity:
71 case WebKit::WebFilterOperation::FilterTypeBlur:
72 if (ReadParam(m, iter, &amount)) {
73 r->setAmount(amount);
74 success = true;
76 break;
77 case WebKit::WebFilterOperation::FilterTypeDropShadow:
78 if (ReadParam(m, iter, &dropShadowOffset) &&
79 ReadParam(m, iter, &amount) &&
80 ReadParam(m, iter, &dropShadowColor)) {
81 r->setDropShadowOffset(dropShadowOffset);
82 r->setAmount(amount);
83 r->setDropShadowColor(dropShadowColor);
84 success = true;
86 break;
87 case WebKit::WebFilterOperation::FilterTypeColorMatrix: {
88 int i;
89 for (i = 0; i < 20; ++i) {
90 if (!ReadParam(m, iter, &matrix[i]))
91 break;
93 if (i == 20) {
94 r->setMatrix(matrix);
95 success = true;
97 break;
99 case WebKit::WebFilterOperation::FilterTypeZoom:
100 if (ReadParam(m, iter, &amount) &&
101 ReadParam(m, iter, &zoom_inset) &&
102 amount >= 0.f &&
103 zoom_inset >= 0) {
104 r->setAmount(amount);
105 r->setZoomInset(zoom_inset);
106 success = true;
108 break;
110 return success;
113 void ParamTraits<WebKit::WebFilterOperation>::Log(
114 const param_type& p, std::string* l) {
115 l->append("(");
116 LogParam(static_cast<unsigned>(p.type()), l);
117 l->append(", ");
119 switch (p.type()) {
120 case WebKit::WebFilterOperation::FilterTypeGrayscale:
121 case WebKit::WebFilterOperation::FilterTypeSepia:
122 case WebKit::WebFilterOperation::FilterTypeSaturate:
123 case WebKit::WebFilterOperation::FilterTypeHueRotate:
124 case WebKit::WebFilterOperation::FilterTypeInvert:
125 case WebKit::WebFilterOperation::FilterTypeBrightness:
126 case WebKit::WebFilterOperation::FilterTypeSaturatingBrightness:
127 case WebKit::WebFilterOperation::FilterTypeContrast:
128 case WebKit::WebFilterOperation::FilterTypeOpacity:
129 case WebKit::WebFilterOperation::FilterTypeBlur:
130 LogParam(p.amount(), l);
131 break;
132 case WebKit::WebFilterOperation::FilterTypeDropShadow:
133 LogParam(p.dropShadowOffset(), l);
134 l->append(", ");
135 LogParam(p.amount(), l);
136 l->append(", ");
137 LogParam(p.dropShadowColor(), l);
138 break;
139 case WebKit::WebFilterOperation::FilterTypeColorMatrix:
140 for (int i = 0; i < 20; ++i) {
141 if (i)
142 l->append(", ");
143 LogParam(p.matrix()[i], l);
145 break;
146 case WebKit::WebFilterOperation::FilterTypeZoom:
147 LogParam(p.amount(), l);
148 l->append(", ");
149 LogParam(p.zoomInset(), l);
150 break;
152 l->append(")");
155 void ParamTraits<WebKit::WebFilterOperations>::Write(
156 Message* m, const param_type& p) {
157 WriteParam(m, p.size());
158 for (std::size_t i = 0; i < p.size(); ++i) {
159 WriteParam(m, p.at(i));
163 bool ParamTraits<WebKit::WebFilterOperations>::Read(
164 const Message* m, PickleIterator* iter, param_type* r) {
165 size_t count;
166 if (!ReadParam(m, iter, &count))
167 return false;
169 for (std::size_t i = 0; i < count; ++i) {
170 WebKit::WebFilterOperation op =
171 WebKit::WebFilterOperation::createEmptyFilter();
172 if (!ReadParam(m, iter, &op))
173 return false;
174 r->append(op);
176 return true;
179 void ParamTraits<WebKit::WebFilterOperations>::Log(
180 const param_type& p, std::string* l) {
181 l->append("(");
182 for (std::size_t i = 0; i < p.size(); ++i) {
183 if (i)
184 l->append(", ");
185 LogParam(p.at(i), l);
187 l->append(")");
190 void ParamTraits<gfx::Transform>::Write(
191 Message* m, const param_type& p) {
192 WriteParam(m, p.matrix().getDouble(0, 0));
193 WriteParam(m, p.matrix().getDouble(1, 0));
194 WriteParam(m, p.matrix().getDouble(2, 0));
195 WriteParam(m, p.matrix().getDouble(3, 0));
196 WriteParam(m, p.matrix().getDouble(0, 1));
197 WriteParam(m, p.matrix().getDouble(1, 1));
198 WriteParam(m, p.matrix().getDouble(2, 1));
199 WriteParam(m, p.matrix().getDouble(3, 1));
200 WriteParam(m, p.matrix().getDouble(0, 2));
201 WriteParam(m, p.matrix().getDouble(1, 2));
202 WriteParam(m, p.matrix().getDouble(2, 2));
203 WriteParam(m, p.matrix().getDouble(3, 2));
204 WriteParam(m, p.matrix().getDouble(0, 3));
205 WriteParam(m, p.matrix().getDouble(1, 3));
206 WriteParam(m, p.matrix().getDouble(2, 3));
207 WriteParam(m, p.matrix().getDouble(3, 3));
210 bool ParamTraits<gfx::Transform>::Read(
211 const Message* m, PickleIterator* iter, param_type* r) {
212 // Note: In this function, "m12" means 1st row, 2nd column of the matrix.
213 // This is consistent with Skia's row-column notation, but backwards from
214 // WebCore's column-row notation.
215 double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34,
216 m41, m42, m43, m44;
218 bool success =
219 ReadParam(m, iter, &m11) &&
220 ReadParam(m, iter, &m21) &&
221 ReadParam(m, iter, &m31) &&
222 ReadParam(m, iter, &m41) &&
223 ReadParam(m, iter, &m12) &&
224 ReadParam(m, iter, &m22) &&
225 ReadParam(m, iter, &m32) &&
226 ReadParam(m, iter, &m42) &&
227 ReadParam(m, iter, &m13) &&
228 ReadParam(m, iter, &m23) &&
229 ReadParam(m, iter, &m33) &&
230 ReadParam(m, iter, &m43) &&
231 ReadParam(m, iter, &m14) &&
232 ReadParam(m, iter, &m24) &&
233 ReadParam(m, iter, &m34) &&
234 ReadParam(m, iter, &m44);
236 if (success) {
237 r->matrix().setDouble(0, 0, m11);
238 r->matrix().setDouble(1, 0, m21);
239 r->matrix().setDouble(2, 0, m31);
240 r->matrix().setDouble(3, 0, m41);
241 r->matrix().setDouble(0, 1, m12);
242 r->matrix().setDouble(1, 1, m22);
243 r->matrix().setDouble(2, 1, m32);
244 r->matrix().setDouble(3, 1, m42);
245 r->matrix().setDouble(0, 2, m13);
246 r->matrix().setDouble(1, 2, m23);
247 r->matrix().setDouble(2, 2, m33);
248 r->matrix().setDouble(3, 2, m43);
249 r->matrix().setDouble(0, 3, m14);
250 r->matrix().setDouble(1, 3, m24);
251 r->matrix().setDouble(2, 3, m34);
252 r->matrix().setDouble(3, 3, m44);
255 return success;
258 void ParamTraits<gfx::Transform>::Log(
259 const param_type& p, std::string* l) {
260 l->append("(");
261 LogParam(p.matrix().getDouble(0, 0), l);
262 l->append(", ");
263 LogParam(p.matrix().getDouble(1, 0), l);
264 l->append(", ");
265 LogParam(p.matrix().getDouble(2, 0), l);
266 l->append(", ");
267 LogParam(p.matrix().getDouble(3, 0), l);
268 l->append(", ");
269 LogParam(p.matrix().getDouble(0, 1), l);
270 l->append(", ");
271 LogParam(p.matrix().getDouble(1, 1), l);
272 l->append(", ");
273 LogParam(p.matrix().getDouble(2, 1), l);
274 l->append(", ");
275 LogParam(p.matrix().getDouble(3, 1), l);
276 l->append(", ");
277 LogParam(p.matrix().getDouble(0, 2), l);
278 l->append(", ");
279 LogParam(p.matrix().getDouble(1, 2), l);
280 l->append(", ");
281 LogParam(p.matrix().getDouble(2, 2), l);
282 l->append(", ");
283 LogParam(p.matrix().getDouble(3, 2), l);
284 l->append(", ");
285 LogParam(p.matrix().getDouble(0, 3), l);
286 l->append(", ");
287 LogParam(p.matrix().getDouble(1, 3), l);
288 l->append(", ");
289 LogParam(p.matrix().getDouble(2, 3), l);
290 l->append(", ");
291 LogParam(p.matrix().getDouble(3, 3), l);
292 l->append(") ");
295 void ParamTraits<cc::RenderPass>::Write(
296 Message* m, const param_type& p) {
297 WriteParam(m, p.id);
298 WriteParam(m, p.output_rect);
299 WriteParam(m, p.damage_rect);
300 WriteParam(m, p.transform_to_root_target);
301 WriteParam(m, p.has_transparent_background);
302 WriteParam(m, p.has_occlusion_from_outside_target_surface);
303 WriteParam(m, p.shared_quad_state_list.size());
304 WriteParam(m, p.quad_list.size());
306 for (size_t i = 0; i < p.shared_quad_state_list.size(); ++i)
307 WriteParam(m, *p.shared_quad_state_list[i]);
309 size_t shared_quad_state_index = 0;
310 for (size_t i = 0; i < p.quad_list.size(); ++i) {
311 const cc::DrawQuad* quad = p.quad_list[i];
313 switch (quad->material) {
314 case cc::DrawQuad::CHECKERBOARD:
315 WriteParam(m, *cc::CheckerboardDrawQuad::MaterialCast(quad));
316 break;
317 case cc::DrawQuad::DEBUG_BORDER:
318 WriteParam(m, *cc::DebugBorderDrawQuad::MaterialCast(quad));
319 break;
320 case cc::DrawQuad::IO_SURFACE_CONTENT:
321 WriteParam(m, *cc::IOSurfaceDrawQuad::MaterialCast(quad));
322 break;
323 case cc::DrawQuad::PICTURE_CONTENT:
324 NOTREACHED();
325 break;
326 case cc::DrawQuad::TEXTURE_CONTENT:
327 WriteParam(m, *cc::TextureDrawQuad::MaterialCast(quad));
328 break;
329 case cc::DrawQuad::RENDER_PASS:
330 WriteParam(m, *cc::RenderPassDrawQuad::MaterialCast(quad));
331 break;
332 case cc::DrawQuad::SOLID_COLOR:
333 WriteParam(m, *cc::SolidColorDrawQuad::MaterialCast(quad));
334 break;
335 case cc::DrawQuad::TILED_CONTENT:
336 WriteParam(m, *cc::TileDrawQuad::MaterialCast(quad));
337 break;
338 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
339 WriteParam(m, *cc::StreamVideoDrawQuad::MaterialCast(quad));
340 break;
341 case cc::DrawQuad::YUV_VIDEO_CONTENT:
342 WriteParam(m, *cc::YUVVideoDrawQuad::MaterialCast(quad));
343 break;
344 case cc::DrawQuad::INVALID:
345 break;
348 const cc::ScopedPtrVector<cc::SharedQuadState>& sqs_list =
349 p.shared_quad_state_list;
351 // This is an invalid index.
352 size_t bad_index = sqs_list.size();
354 // Null shared quad states should not occur.
355 DCHECK(quad->shared_quad_state);
356 if (!quad->shared_quad_state) {
357 WriteParam(m, bad_index);
358 continue;
361 // SharedQuadStates should appear in the order they are used by DrawQuads.
362 // Find the SharedQuadState for this DrawQuad.
363 while (shared_quad_state_index < sqs_list.size() &&
364 quad->shared_quad_state != sqs_list[shared_quad_state_index])
365 ++shared_quad_state_index;
367 DCHECK_LT(shared_quad_state_index, sqs_list.size());
368 if (shared_quad_state_index >= sqs_list.size()) {
369 WriteParam(m, bad_index);
370 continue;
373 DCHECK_LT(shared_quad_state_index, p.shared_quad_state_list.size());
374 WriteParam(m, shared_quad_state_index);
378 template<typename QuadType>
379 static scoped_ptr<cc::DrawQuad> ReadDrawQuad(const Message* m,
380 PickleIterator* iter) {
381 scoped_ptr<QuadType> quad = QuadType::Create();
382 if (!ReadParam(m, iter, quad.get()))
383 return scoped_ptr<QuadType>(NULL).template PassAs<cc::DrawQuad>();
384 return quad.template PassAs<cc::DrawQuad>();
387 bool ParamTraits<cc::RenderPass>::Read(
388 const Message* m, PickleIterator* iter, param_type* p) {
389 cc::RenderPass::Id id(-1, -1);
390 gfx::Rect output_rect;
391 gfx::RectF damage_rect;
392 gfx::Transform transform_to_root_target;
393 bool has_transparent_background;
394 bool has_occlusion_from_outside_target_surface;
395 size_t shared_quad_state_list_size;
396 size_t quad_list_size;
398 if (!ReadParam(m, iter, &id) ||
399 !ReadParam(m, iter, &output_rect) ||
400 !ReadParam(m, iter, &damage_rect) ||
401 !ReadParam(m, iter, &transform_to_root_target) ||
402 !ReadParam(m, iter, &has_transparent_background) ||
403 !ReadParam(m, iter, &has_occlusion_from_outside_target_surface) ||
404 !ReadParam(m, iter, &shared_quad_state_list_size) ||
405 !ReadParam(m, iter, &quad_list_size))
406 return false;
408 p->SetAll(id,
409 output_rect,
410 damage_rect,
411 transform_to_root_target,
412 has_transparent_background,
413 has_occlusion_from_outside_target_surface);
415 for (size_t i = 0; i < shared_quad_state_list_size; ++i) {
416 scoped_ptr<cc::SharedQuadState> state(cc::SharedQuadState::Create());
417 if (!ReadParam(m, iter, state.get()))
418 return false;
419 p->shared_quad_state_list.push_back(state.Pass());
422 size_t last_shared_quad_state_index = 0;
423 for (size_t i = 0; i < quad_list_size; ++i) {
424 cc::DrawQuad::Material material;
425 PickleIterator temp_iter = *iter;
426 if (!ReadParam(m, &temp_iter, &material))
427 return false;
429 scoped_ptr<cc::DrawQuad> draw_quad;
430 switch (material) {
431 case cc::DrawQuad::CHECKERBOARD:
432 draw_quad = ReadDrawQuad<cc::CheckerboardDrawQuad>(m, iter);
433 break;
434 case cc::DrawQuad::DEBUG_BORDER:
435 draw_quad = ReadDrawQuad<cc::DebugBorderDrawQuad>(m, iter);
436 break;
437 case cc::DrawQuad::IO_SURFACE_CONTENT:
438 draw_quad = ReadDrawQuad<cc::IOSurfaceDrawQuad>(m, iter);
439 break;
440 case cc::DrawQuad::PICTURE_CONTENT:
441 NOTREACHED();
442 return false;
443 case cc::DrawQuad::TEXTURE_CONTENT:
444 draw_quad = ReadDrawQuad<cc::TextureDrawQuad>(m, iter);
445 break;
446 case cc::DrawQuad::RENDER_PASS:
447 draw_quad = ReadDrawQuad<cc::RenderPassDrawQuad>(m, iter);
448 break;
449 case cc::DrawQuad::SOLID_COLOR:
450 draw_quad = ReadDrawQuad<cc::SolidColorDrawQuad>(m, iter);
451 break;
452 case cc::DrawQuad::TILED_CONTENT:
453 draw_quad = ReadDrawQuad<cc::TileDrawQuad>(m, iter);
454 break;
455 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
456 draw_quad = ReadDrawQuad<cc::StreamVideoDrawQuad>(m, iter);
457 break;
458 case cc::DrawQuad::YUV_VIDEO_CONTENT:
459 draw_quad = ReadDrawQuad<cc::YUVVideoDrawQuad>(m, iter);
460 break;
461 case cc::DrawQuad::INVALID:
462 break;
464 if (!draw_quad)
465 return false;
467 size_t shared_quad_state_index;
468 if (!ReadParam(m, iter, &shared_quad_state_index) ||
469 shared_quad_state_index >= p->shared_quad_state_list.size())
470 return false;
471 // SharedQuadState indexes should be in ascending order.
472 if (shared_quad_state_index < last_shared_quad_state_index)
473 return false;
474 last_shared_quad_state_index = shared_quad_state_index;
476 draw_quad->shared_quad_state =
477 p->shared_quad_state_list[shared_quad_state_index];
479 p->quad_list.push_back(draw_quad.Pass());
482 return true;
485 void ParamTraits<cc::RenderPass>::Log(
486 const param_type& p, std::string* l) {
487 l->append("RenderPass((");
488 LogParam(p.id, l);
489 l->append("), ");
490 LogParam(p.output_rect, l);
491 l->append(", ");
492 LogParam(p.damage_rect, l);
493 l->append(", ");
494 LogParam(p.transform_to_root_target, l);
495 l->append(", ");
496 LogParam(p.has_transparent_background, l);
497 l->append(", ");
498 LogParam(p.has_occlusion_from_outside_target_surface, l);
499 l->append(", ");
501 l->append("[");
502 for (size_t i = 0; i < p.shared_quad_state_list.size(); ++i) {
503 if (i)
504 l->append(", ");
505 LogParam(*p.shared_quad_state_list[i], l);
507 l->append("], [");
508 for (size_t i = 0; i < p.quad_list.size(); ++i) {
509 if (i)
510 l->append(", ");
511 const cc::DrawQuad* quad = p.quad_list[i];
512 switch (quad->material) {
513 case cc::DrawQuad::CHECKERBOARD:
514 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(quad), l);
515 break;
516 case cc::DrawQuad::DEBUG_BORDER:
517 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad), l);
518 break;
519 case cc::DrawQuad::IO_SURFACE_CONTENT:
520 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad), l);
521 break;
522 case cc::DrawQuad::PICTURE_CONTENT:
523 NOTREACHED();
524 break;
525 case cc::DrawQuad::TEXTURE_CONTENT:
526 LogParam(*cc::TextureDrawQuad::MaterialCast(quad), l);
527 break;
528 case cc::DrawQuad::RENDER_PASS:
529 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad), l);
530 break;
531 case cc::DrawQuad::SOLID_COLOR:
532 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad), l);
533 break;
534 case cc::DrawQuad::TILED_CONTENT:
535 LogParam(*cc::TileDrawQuad::MaterialCast(quad), l);
536 break;
537 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
538 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad), l);
539 break;
540 case cc::DrawQuad::YUV_VIDEO_CONTENT:
541 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad), l);
542 break;
543 case cc::DrawQuad::INVALID:
544 break;
547 l->append("])");
550 namespace {
551 enum CompositorFrameType {
552 NO_FRAME,
553 DELEGATED_FRAME,
554 GL_FRAME,
555 SOFTWARE_FRAME,
559 void ParamTraits<cc::CompositorFrame>::Write(Message* m,
560 const param_type& p) {
561 WriteParam(m, p.metadata);
562 if (p.delegated_frame_data) {
563 DCHECK(!p.gl_frame_data);
564 DCHECK(!p.software_frame_data);
565 WriteParam(m, static_cast<int>(DELEGATED_FRAME));
566 WriteParam(m, *p.delegated_frame_data);
567 } else if (p.gl_frame_data) {
568 DCHECK(!p.software_frame_data);
569 WriteParam(m, static_cast<int>(GL_FRAME));
570 WriteParam(m, *p.gl_frame_data);
571 } else if (p.software_frame_data) {
572 WriteParam(m, static_cast<int>(SOFTWARE_FRAME));
573 WriteParam(m, *p.software_frame_data);
574 } else {
575 WriteParam(m, static_cast<int>(NO_FRAME));
579 bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
580 PickleIterator* iter,
581 param_type* p) {
582 if (!ReadParam(m, iter, &p->metadata))
583 return false;
585 int compositor_frame_type;
586 if (!ReadParam(m, iter, &compositor_frame_type))
587 return false;
589 switch (compositor_frame_type) {
590 case DELEGATED_FRAME:
591 p->delegated_frame_data.reset(new cc::DelegatedFrameData());
592 if (!ReadParam(m, iter, p->delegated_frame_data.get()))
593 return false;
594 break;
595 case GL_FRAME:
596 p->gl_frame_data.reset(new cc::GLFrameData());
597 if (!ReadParam(m, iter, p->gl_frame_data.get()))
598 return false;
599 break;
600 case SOFTWARE_FRAME:
601 p->software_frame_data.reset(new cc::SoftwareFrameData());
602 if (!ReadParam(m, iter, p->software_frame_data.get()))
603 return false;
604 break;
605 case NO_FRAME:
606 break;
607 default:
608 return false;
610 return true;
613 void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
614 std::string* l) {
615 l->append("CompositorFrame(");
616 LogParam(p.metadata, l);
617 l->append(", ");
618 if (p.delegated_frame_data)
619 LogParam(*p.delegated_frame_data, l);
620 else if (p.gl_frame_data)
621 LogParam(*p.gl_frame_data, l);
622 else if (p.software_frame_data)
623 LogParam(*p.software_frame_data, l);
624 l->append(")");
627 void ParamTraits<cc::CompositorFrameAck>::Write(Message* m,
628 const param_type& p) {
629 WriteParam(m, p.resources);
630 WriteParam(m, p.last_dib_id);
631 if (p.gl_frame_data) {
632 WriteParam(m, static_cast<int>(GL_FRAME));
633 WriteParam(m, *p.gl_frame_data);
634 } else {
635 WriteParam(m, static_cast<int>(NO_FRAME));
639 bool ParamTraits<cc::CompositorFrameAck>::Read(const Message* m,
640 PickleIterator* iter,
641 param_type* p) {
642 if (!ReadParam(m, iter, &p->resources))
643 return false;
645 if (!ReadParam(m, iter, &p->last_dib_id))
646 return false;
648 int compositor_frame_type;
649 if (!ReadParam(m, iter, &compositor_frame_type))
650 return false;
652 switch (compositor_frame_type) {
653 case NO_FRAME:
654 break;
655 case GL_FRAME:
656 p->gl_frame_data.reset(new cc::GLFrameData());
657 if (!ReadParam(m, iter, p->gl_frame_data.get()))
658 return false;
659 break;
660 default:
661 return false;
663 return true;
666 void ParamTraits<cc::CompositorFrameAck>::Log(const param_type& p,
667 std::string* l) {
668 l->append("CompositorFrameAck(");
669 LogParam(p.resources, l);
670 l->append(", ");
671 LogParam(p.last_dib_id, l);
672 l->append(", ");
673 if (p.gl_frame_data)
674 LogParam(*p.gl_frame_data, l);
675 l->append(")");
678 void ParamTraits<cc::DelegatedFrameData>::Write(Message* m,
679 const param_type& p) {
680 WriteParam(m, p.resource_list);
681 WriteParam(m, p.render_pass_list.size());
682 for (size_t i = 0; i < p.render_pass_list.size(); ++i)
683 WriteParam(m, *p.render_pass_list[i]);
686 bool ParamTraits<cc::DelegatedFrameData>::Read(const Message* m,
687 PickleIterator* iter,
688 param_type* p) {
689 const static size_t kMaxRenderPasses = 10000;
691 size_t num_render_passes;
692 if (!ReadParam(m, iter, &p->resource_list) ||
693 !ReadParam(m, iter, &num_render_passes) ||
694 num_render_passes > kMaxRenderPasses)
695 return false;
696 for (size_t i = 0; i < num_render_passes; ++i) {
697 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
698 if (!ReadParam(m, iter, render_pass.get()))
699 return false;
700 p->render_pass_list.push_back(render_pass.Pass());
702 return true;
705 void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
706 std::string* l) {
707 l->append("DelegatedFrameData(");
708 LogParam(p.resource_list, l);
709 l->append(", [");
710 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
711 if (i)
712 l->append(", ");
713 LogParam(*p.render_pass_list[i], l);
715 l->append("])");
718 } // namespace IPC