[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / common / cc_messages.cc
blob1e2d7419b3bb2b41708a6669b1f19d24ed37ac26
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 "cc/output/filter_operations.h"
9 #include "content/public/common/common_param_traits.h"
10 #include "third_party/skia/include/core/SkData.h"
11 #include "third_party/skia/include/core/SkFlattenableSerialization.h"
12 #include "ui/gfx/transform.h"
14 namespace IPC {
16 void ParamTraits<cc::FilterOperation>::Write(
17 Message* m, const param_type& p) {
18 WriteParam(m, p.type());
19 switch (p.type()) {
20 case cc::FilterOperation::GRAYSCALE:
21 case cc::FilterOperation::SEPIA:
22 case cc::FilterOperation::SATURATE:
23 case cc::FilterOperation::HUE_ROTATE:
24 case cc::FilterOperation::INVERT:
25 case cc::FilterOperation::BRIGHTNESS:
26 case cc::FilterOperation::SATURATING_BRIGHTNESS:
27 case cc::FilterOperation::CONTRAST:
28 case cc::FilterOperation::OPACITY:
29 case cc::FilterOperation::BLUR:
30 WriteParam(m, p.amount());
31 break;
32 case cc::FilterOperation::DROP_SHADOW:
33 WriteParam(m, p.drop_shadow_offset());
34 WriteParam(m, p.amount());
35 WriteParam(m, p.drop_shadow_color());
36 break;
37 case cc::FilterOperation::COLOR_MATRIX:
38 for (int i = 0; i < 20; ++i)
39 WriteParam(m, p.matrix()[i]);
40 break;
41 case cc::FilterOperation::ZOOM:
42 WriteParam(m, p.amount());
43 WriteParam(m, p.zoom_inset());
44 break;
45 case cc::FilterOperation::REFERENCE:
46 WriteParam(m, p.image_filter());
47 break;
48 case cc::FilterOperation::ALPHA_THRESHOLD:
49 NOTREACHED();
50 break;
54 bool ParamTraits<cc::FilterOperation>::Read(
55 const Message* m, PickleIterator* iter, param_type* r) {
56 cc::FilterOperation::FilterType type;
57 float amount;
58 gfx::Point drop_shadow_offset;
59 SkColor drop_shadow_color;
60 SkScalar matrix[20];
61 int zoom_inset;
63 if (!ReadParam(m, iter, &type))
64 return false;
65 r->set_type(type);
67 bool success = false;
68 switch (type) {
69 case cc::FilterOperation::GRAYSCALE:
70 case cc::FilterOperation::SEPIA:
71 case cc::FilterOperation::SATURATE:
72 case cc::FilterOperation::HUE_ROTATE:
73 case cc::FilterOperation::INVERT:
74 case cc::FilterOperation::BRIGHTNESS:
75 case cc::FilterOperation::SATURATING_BRIGHTNESS:
76 case cc::FilterOperation::CONTRAST:
77 case cc::FilterOperation::OPACITY:
78 case cc::FilterOperation::BLUR:
79 if (ReadParam(m, iter, &amount)) {
80 r->set_amount(amount);
81 success = true;
83 break;
84 case cc::FilterOperation::DROP_SHADOW:
85 if (ReadParam(m, iter, &drop_shadow_offset) &&
86 ReadParam(m, iter, &amount) &&
87 ReadParam(m, iter, &drop_shadow_color)) {
88 r->set_drop_shadow_offset(drop_shadow_offset);
89 r->set_amount(amount);
90 r->set_drop_shadow_color(drop_shadow_color);
91 success = true;
93 break;
94 case cc::FilterOperation::COLOR_MATRIX: {
95 int i;
96 for (i = 0; i < 20; ++i) {
97 if (!ReadParam(m, iter, &matrix[i]))
98 break;
100 if (i == 20) {
101 r->set_matrix(matrix);
102 success = true;
104 break;
106 case cc::FilterOperation::ZOOM:
107 if (ReadParam(m, iter, &amount) &&
108 ReadParam(m, iter, &zoom_inset) &&
109 amount >= 0.f &&
110 zoom_inset >= 0) {
111 r->set_amount(amount);
112 r->set_zoom_inset(zoom_inset);
113 success = true;
115 break;
116 case cc::FilterOperation::REFERENCE: {
117 skia::RefPtr<SkImageFilter> filter;
118 if (!ReadParam(m, iter, &filter)) {
119 success = false;
120 break;
122 r->set_image_filter(filter);
123 success = true;
124 break;
126 case cc::FilterOperation::ALPHA_THRESHOLD:
127 break;
129 return success;
132 void ParamTraits<cc::FilterOperation>::Log(
133 const param_type& p, std::string* l) {
134 l->append("(");
135 LogParam(static_cast<unsigned>(p.type()), l);
136 l->append(", ");
138 switch (p.type()) {
139 case cc::FilterOperation::GRAYSCALE:
140 case cc::FilterOperation::SEPIA:
141 case cc::FilterOperation::SATURATE:
142 case cc::FilterOperation::HUE_ROTATE:
143 case cc::FilterOperation::INVERT:
144 case cc::FilterOperation::BRIGHTNESS:
145 case cc::FilterOperation::SATURATING_BRIGHTNESS:
146 case cc::FilterOperation::CONTRAST:
147 case cc::FilterOperation::OPACITY:
148 case cc::FilterOperation::BLUR:
149 LogParam(p.amount(), l);
150 break;
151 case cc::FilterOperation::DROP_SHADOW:
152 LogParam(p.drop_shadow_offset(), l);
153 l->append(", ");
154 LogParam(p.amount(), l);
155 l->append(", ");
156 LogParam(p.drop_shadow_color(), l);
157 break;
158 case cc::FilterOperation::COLOR_MATRIX:
159 for (int i = 0; i < 20; ++i) {
160 if (i)
161 l->append(", ");
162 LogParam(p.matrix()[i], l);
164 break;
165 case cc::FilterOperation::ZOOM:
166 LogParam(p.amount(), l);
167 l->append(", ");
168 LogParam(p.zoom_inset(), l);
169 break;
170 case cc::FilterOperation::REFERENCE:
171 LogParam(p.image_filter(), l);
172 break;
173 case cc::FilterOperation::ALPHA_THRESHOLD:
174 NOTREACHED();
175 break;
177 l->append(")");
180 void ParamTraits<cc::FilterOperations>::Write(
181 Message* m, const param_type& p) {
182 WriteParam(m, p.size());
183 for (std::size_t i = 0; i < p.size(); ++i) {
184 WriteParam(m, p.at(i));
188 bool ParamTraits<cc::FilterOperations>::Read(
189 const Message* m, PickleIterator* iter, param_type* r) {
190 size_t count;
191 if (!ReadParam(m, iter, &count))
192 return false;
194 for (std::size_t i = 0; i < count; ++i) {
195 cc::FilterOperation op = cc::FilterOperation::CreateEmptyFilter();
196 if (!ReadParam(m, iter, &op))
197 return false;
198 r->Append(op);
200 return true;
203 void ParamTraits<cc::FilterOperations>::Log(
204 const param_type& p, std::string* l) {
205 l->append("(");
206 for (std::size_t i = 0; i < p.size(); ++i) {
207 if (i)
208 l->append(", ");
209 LogParam(p.at(i), l);
211 l->append(")");
214 void ParamTraits<skia::RefPtr<SkImageFilter> >::Write(
215 Message* m, const param_type& p) {
216 SkImageFilter* filter = p.get();
217 if (filter) {
218 skia::RefPtr<SkData> data =
219 skia::AdoptRef(SkValidatingSerializeFlattenable(filter));
220 m->WriteData(static_cast<const char*>(data->data()), data->size());
221 } else {
222 m->WriteData(0, 0);
226 bool ParamTraits<skia::RefPtr<SkImageFilter> >::Read(
227 const Message* m, PickleIterator* iter, param_type* r) {
228 const char* data = 0;
229 int length = 0;
230 if (!m->ReadData(iter, &data, &length))
231 return false;
232 if (length > 0) {
233 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
234 data, length, SkImageFilter::GetFlattenableType());
235 *r = skia::AdoptRef(static_cast<SkImageFilter*>(flattenable));
236 } else {
237 r->clear();
239 return true;
242 void ParamTraits<skia::RefPtr<SkImageFilter> >::Log(
243 const param_type& p, std::string* l) {
244 l->append("(");
245 LogParam(p.get() ? p->countInputs() : 0, l);
246 l->append(")");
249 void ParamTraits<gfx::Transform>::Write(
250 Message* m, const param_type& p) {
251 #ifdef SK_MSCALAR_IS_FLOAT
252 float column_major_data[16];
253 p.matrix().asColMajorf(column_major_data);
254 #else
255 double column_major_data[16];
256 p.matrix().asColMajord(column_major_data);
257 #endif
258 m->WriteBytes(&column_major_data, sizeof(SkMScalar) * 16);
261 bool ParamTraits<gfx::Transform>::Read(
262 const Message* m, PickleIterator* iter, param_type* r) {
263 const char* column_major_data;
264 if (!m->ReadBytes(iter, &column_major_data, sizeof(SkMScalar) * 16))
265 return false;
266 r->matrix().setColMajor(
267 reinterpret_cast<const SkMScalar*>(column_major_data));
268 return true;
271 void ParamTraits<gfx::Transform>::Log(
272 const param_type& p, std::string* l) {
273 #ifdef SK_MSCALAR_IS_FLOAT
274 float row_major_data[16];
275 p.matrix().asRowMajorf(row_major_data);
276 #else
277 double row_major_data[16];
278 p.matrix().asRowMajord(row_major_data);
279 #endif
280 l->append("(");
281 for (int i = 0; i < 16; ++i) {
282 if (i > 0)
283 l->append(", ");
284 LogParam(row_major_data[i], l);
286 l->append(") ");
289 void ParamTraits<cc::RenderPass>::Write(
290 Message* m, const param_type& p) {
291 WriteParam(m, p.id);
292 WriteParam(m, p.output_rect);
293 WriteParam(m, p.damage_rect);
294 WriteParam(m, p.transform_to_root_target);
295 WriteParam(m, p.has_transparent_background);
296 WriteParam(m, p.shared_quad_state_list.size());
297 WriteParam(m, p.quad_list.size());
299 size_t shared_quad_state_index = 0;
300 size_t last_shared_quad_state_index = kuint32max;
301 for (size_t i = 0; i < p.quad_list.size(); ++i) {
302 const cc::DrawQuad* quad = p.quad_list[i];
303 DCHECK(quad->rect.Contains(quad->visible_rect))
304 << quad->material << " rect: " << quad->rect.ToString()
305 << " visible_rect: " << quad->visible_rect.ToString();
306 DCHECK(quad->opaque_rect.IsEmpty() ||
307 quad->rect.Contains(quad->opaque_rect))
308 << quad->material << " rect: " << quad->rect.ToString()
309 << " opaque_rect: " << quad->opaque_rect.ToString();
311 switch (quad->material) {
312 case cc::DrawQuad::CHECKERBOARD:
313 WriteParam(m, *cc::CheckerboardDrawQuad::MaterialCast(quad));
314 break;
315 case cc::DrawQuad::DEBUG_BORDER:
316 WriteParam(m, *cc::DebugBorderDrawQuad::MaterialCast(quad));
317 break;
318 case cc::DrawQuad::IO_SURFACE_CONTENT:
319 WriteParam(m, *cc::IOSurfaceDrawQuad::MaterialCast(quad));
320 break;
321 case cc::DrawQuad::PICTURE_CONTENT:
322 NOTREACHED();
323 break;
324 case cc::DrawQuad::TEXTURE_CONTENT:
325 WriteParam(m, *cc::TextureDrawQuad::MaterialCast(quad));
326 break;
327 case cc::DrawQuad::RENDER_PASS:
328 WriteParam(m, *cc::RenderPassDrawQuad::MaterialCast(quad));
329 break;
330 case cc::DrawQuad::SOLID_COLOR:
331 WriteParam(m, *cc::SolidColorDrawQuad::MaterialCast(quad));
332 break;
333 case cc::DrawQuad::SURFACE_CONTENT:
334 WriteParam(m, *cc::SurfaceDrawQuad::MaterialCast(quad));
335 break;
336 case cc::DrawQuad::TILED_CONTENT:
337 WriteParam(m, *cc::TileDrawQuad::MaterialCast(quad));
338 break;
339 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
340 WriteParam(m, *cc::StreamVideoDrawQuad::MaterialCast(quad));
341 break;
342 case cc::DrawQuad::YUV_VIDEO_CONTENT:
343 WriteParam(m, *cc::YUVVideoDrawQuad::MaterialCast(quad));
344 break;
345 case cc::DrawQuad::INVALID:
346 break;
349 const cc::ScopedPtrVector<cc::SharedQuadState>& sqs_list =
350 p.shared_quad_state_list;
352 // This is an invalid index.
353 size_t bad_index = sqs_list.size();
355 // Null shared quad states should not occur.
356 DCHECK(quad->shared_quad_state);
357 if (!quad->shared_quad_state) {
358 WriteParam(m, bad_index);
359 continue;
362 // SharedQuadStates should appear in the order they are used by DrawQuads.
363 // Find the SharedQuadState for this DrawQuad.
364 while (shared_quad_state_index < sqs_list.size() &&
365 quad->shared_quad_state != sqs_list[shared_quad_state_index])
366 ++shared_quad_state_index;
368 DCHECK_LT(shared_quad_state_index, sqs_list.size());
369 if (shared_quad_state_index >= sqs_list.size()) {
370 WriteParam(m, bad_index);
371 continue;
374 WriteParam(m, shared_quad_state_index);
375 if (shared_quad_state_index != last_shared_quad_state_index) {
376 WriteParam(m, *sqs_list[shared_quad_state_index]);
377 last_shared_quad_state_index = shared_quad_state_index;
382 static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
383 size_t to_reserve = sizeof(cc::RenderPass);
385 to_reserve += p.shared_quad_state_list.size() * sizeof(cc::SharedQuadState);
387 // The shared_quad_state_index for each quad.
388 to_reserve += p.quad_list.size() * sizeof(size_t);
390 // The largest quad type, verified by a unit test.
391 to_reserve += p.quad_list.size() * sizeof(cc::RenderPassDrawQuad);
392 return to_reserve;
395 template<typename QuadType>
396 static scoped_ptr<cc::DrawQuad> ReadDrawQuad(const Message* m,
397 PickleIterator* iter) {
398 scoped_ptr<QuadType> quad(new QuadType);
399 if (!ReadParam(m, iter, quad.get()))
400 return scoped_ptr<QuadType>().template PassAs<cc::DrawQuad>();
401 return quad.template PassAs<cc::DrawQuad>();
404 bool ParamTraits<cc::RenderPass>::Read(
405 const Message* m, PickleIterator* iter, param_type* p) {
406 cc::RenderPass::Id id(-1, -1);
407 gfx::Rect output_rect;
408 gfx::Rect damage_rect;
409 gfx::Transform transform_to_root_target;
410 bool has_transparent_background;
411 size_t shared_quad_state_list_size;
412 size_t quad_list_size;
414 if (!ReadParam(m, iter, &id) ||
415 !ReadParam(m, iter, &output_rect) ||
416 !ReadParam(m, iter, &damage_rect) ||
417 !ReadParam(m, iter, &transform_to_root_target) ||
418 !ReadParam(m, iter, &has_transparent_background) ||
419 !ReadParam(m, iter, &shared_quad_state_list_size) ||
420 !ReadParam(m, iter, &quad_list_size))
421 return false;
423 p->SetAll(id,
424 output_rect,
425 damage_rect,
426 transform_to_root_target,
427 has_transparent_background);
429 size_t last_shared_quad_state_index = kuint32max;
430 for (size_t i = 0; i < quad_list_size; ++i) {
431 cc::DrawQuad::Material material;
432 PickleIterator temp_iter = *iter;
433 if (!ReadParam(m, &temp_iter, &material))
434 return false;
436 scoped_ptr<cc::DrawQuad> draw_quad;
437 switch (material) {
438 case cc::DrawQuad::CHECKERBOARD:
439 draw_quad = ReadDrawQuad<cc::CheckerboardDrawQuad>(m, iter);
440 break;
441 case cc::DrawQuad::DEBUG_BORDER:
442 draw_quad = ReadDrawQuad<cc::DebugBorderDrawQuad>(m, iter);
443 break;
444 case cc::DrawQuad::IO_SURFACE_CONTENT:
445 draw_quad = ReadDrawQuad<cc::IOSurfaceDrawQuad>(m, iter);
446 break;
447 case cc::DrawQuad::PICTURE_CONTENT:
448 NOTREACHED();
449 return false;
450 case cc::DrawQuad::SURFACE_CONTENT:
451 draw_quad = ReadDrawQuad<cc::SurfaceDrawQuad>(m, iter);
452 break;
453 case cc::DrawQuad::TEXTURE_CONTENT:
454 draw_quad = ReadDrawQuad<cc::TextureDrawQuad>(m, iter);
455 break;
456 case cc::DrawQuad::RENDER_PASS:
457 draw_quad = ReadDrawQuad<cc::RenderPassDrawQuad>(m, iter);
458 break;
459 case cc::DrawQuad::SOLID_COLOR:
460 draw_quad = ReadDrawQuad<cc::SolidColorDrawQuad>(m, iter);
461 break;
462 case cc::DrawQuad::TILED_CONTENT:
463 draw_quad = ReadDrawQuad<cc::TileDrawQuad>(m, iter);
464 break;
465 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
466 draw_quad = ReadDrawQuad<cc::StreamVideoDrawQuad>(m, iter);
467 break;
468 case cc::DrawQuad::YUV_VIDEO_CONTENT:
469 draw_quad = ReadDrawQuad<cc::YUVVideoDrawQuad>(m, iter);
470 break;
471 case cc::DrawQuad::INVALID:
472 break;
474 if (!draw_quad)
475 return false;
476 if (!draw_quad->rect.Contains(draw_quad->visible_rect)) {
477 LOG(ERROR) << "Quad with invalid visible rect " << draw_quad->material
478 << " rect: " << draw_quad->rect.ToString()
479 << " visible_rect: " << draw_quad->visible_rect.ToString();
480 return false;
482 if (!draw_quad->opaque_rect.IsEmpty() &&
483 !draw_quad->rect.Contains(draw_quad->opaque_rect)) {
484 LOG(ERROR) << "Quad with invalid opaque rect " << draw_quad->material
485 << " rect: " << draw_quad->rect.ToString()
486 << " opaque_rect: " << draw_quad->opaque_rect.ToString();
487 return false;
490 size_t shared_quad_state_index;
491 if (!ReadParam(m, iter, &shared_quad_state_index))
492 return false;
493 if (shared_quad_state_index >= shared_quad_state_list_size)
494 return false;
495 // SharedQuadState indexes should be in ascending order.
496 if (last_shared_quad_state_index != kuint32max &&
497 shared_quad_state_index < last_shared_quad_state_index)
498 return false;
500 // If the quad has a new shared quad state, read it in.
501 if (last_shared_quad_state_index != shared_quad_state_index) {
502 cc::SharedQuadState* state = p->CreateAndAppendSharedQuadState();
503 if (!ReadParam(m, iter, state))
504 return false;
505 last_shared_quad_state_index = shared_quad_state_index;
508 draw_quad->shared_quad_state = p->shared_quad_state_list.back();
509 p->quad_list.push_back(draw_quad.Pass());
512 return true;
515 void ParamTraits<cc::RenderPass>::Log(
516 const param_type& p, std::string* l) {
517 l->append("RenderPass((");
518 LogParam(p.id, l);
519 l->append("), ");
520 LogParam(p.output_rect, l);
521 l->append(", ");
522 LogParam(p.damage_rect, l);
523 l->append(", ");
524 LogParam(p.transform_to_root_target, l);
525 l->append(", ");
526 LogParam(p.has_transparent_background, l);
527 l->append(", ");
529 l->append("[");
530 for (size_t i = 0; i < p.shared_quad_state_list.size(); ++i) {
531 if (i)
532 l->append(", ");
533 LogParam(*p.shared_quad_state_list[i], l);
535 l->append("], [");
536 for (size_t i = 0; i < p.quad_list.size(); ++i) {
537 if (i)
538 l->append(", ");
539 const cc::DrawQuad* quad = p.quad_list[i];
540 switch (quad->material) {
541 case cc::DrawQuad::CHECKERBOARD:
542 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(quad), l);
543 break;
544 case cc::DrawQuad::DEBUG_BORDER:
545 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad), l);
546 break;
547 case cc::DrawQuad::IO_SURFACE_CONTENT:
548 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad), l);
549 break;
550 case cc::DrawQuad::PICTURE_CONTENT:
551 NOTREACHED();
552 break;
553 case cc::DrawQuad::TEXTURE_CONTENT:
554 LogParam(*cc::TextureDrawQuad::MaterialCast(quad), l);
555 break;
556 case cc::DrawQuad::RENDER_PASS:
557 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad), l);
558 break;
559 case cc::DrawQuad::SOLID_COLOR:
560 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad), l);
561 break;
562 case cc::DrawQuad::SURFACE_CONTENT:
563 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad), l);
564 break;
565 case cc::DrawQuad::TILED_CONTENT:
566 LogParam(*cc::TileDrawQuad::MaterialCast(quad), l);
567 break;
568 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
569 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad), l);
570 break;
571 case cc::DrawQuad::YUV_VIDEO_CONTENT:
572 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad), l);
573 break;
574 case cc::DrawQuad::INVALID:
575 break;
578 l->append("])");
581 namespace {
582 enum CompositorFrameType {
583 NO_FRAME,
584 DELEGATED_FRAME,
585 GL_FRAME,
586 SOFTWARE_FRAME,
590 void ParamTraits<cc::CompositorFrame>::Write(Message* m,
591 const param_type& p) {
592 WriteParam(m, p.metadata);
593 if (p.delegated_frame_data) {
594 DCHECK(!p.gl_frame_data);
595 DCHECK(!p.software_frame_data);
596 WriteParam(m, static_cast<int>(DELEGATED_FRAME));
597 WriteParam(m, *p.delegated_frame_data);
598 } else if (p.gl_frame_data) {
599 DCHECK(!p.software_frame_data);
600 WriteParam(m, static_cast<int>(GL_FRAME));
601 WriteParam(m, *p.gl_frame_data);
602 } else if (p.software_frame_data) {
603 WriteParam(m, static_cast<int>(SOFTWARE_FRAME));
604 WriteParam(m, *p.software_frame_data);
605 } else {
606 WriteParam(m, static_cast<int>(NO_FRAME));
610 bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
611 PickleIterator* iter,
612 param_type* p) {
613 if (!ReadParam(m, iter, &p->metadata))
614 return false;
616 int compositor_frame_type;
617 if (!ReadParam(m, iter, &compositor_frame_type))
618 return false;
620 switch (compositor_frame_type) {
621 case DELEGATED_FRAME:
622 p->delegated_frame_data.reset(new cc::DelegatedFrameData());
623 if (!ReadParam(m, iter, p->delegated_frame_data.get()))
624 return false;
625 break;
626 case GL_FRAME:
627 p->gl_frame_data.reset(new cc::GLFrameData());
628 if (!ReadParam(m, iter, p->gl_frame_data.get()))
629 return false;
630 break;
631 case SOFTWARE_FRAME:
632 p->software_frame_data.reset(new cc::SoftwareFrameData());
633 if (!ReadParam(m, iter, p->software_frame_data.get()))
634 return false;
635 break;
636 case NO_FRAME:
637 break;
638 default:
639 return false;
641 return true;
644 void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
645 std::string* l) {
646 l->append("CompositorFrame(");
647 LogParam(p.metadata, l);
648 l->append(", ");
649 if (p.delegated_frame_data)
650 LogParam(*p.delegated_frame_data, l);
651 else if (p.gl_frame_data)
652 LogParam(*p.gl_frame_data, l);
653 else if (p.software_frame_data)
654 LogParam(*p.software_frame_data, l);
655 l->append(")");
658 void ParamTraits<cc::CompositorFrameAck>::Write(Message* m,
659 const param_type& p) {
660 WriteParam(m, p.resources);
661 WriteParam(m, p.last_software_frame_id);
662 if (p.gl_frame_data) {
663 WriteParam(m, static_cast<int>(GL_FRAME));
664 WriteParam(m, *p.gl_frame_data);
665 } else {
666 WriteParam(m, static_cast<int>(NO_FRAME));
670 bool ParamTraits<cc::CompositorFrameAck>::Read(const Message* m,
671 PickleIterator* iter,
672 param_type* p) {
673 if (!ReadParam(m, iter, &p->resources))
674 return false;
676 if (!ReadParam(m, iter, &p->last_software_frame_id))
677 return false;
679 int compositor_frame_type;
680 if (!ReadParam(m, iter, &compositor_frame_type))
681 return false;
683 switch (compositor_frame_type) {
684 case NO_FRAME:
685 break;
686 case GL_FRAME:
687 p->gl_frame_data.reset(new cc::GLFrameData());
688 if (!ReadParam(m, iter, p->gl_frame_data.get()))
689 return false;
690 break;
691 default:
692 return false;
694 return true;
697 void ParamTraits<cc::CompositorFrameAck>::Log(const param_type& p,
698 std::string* l) {
699 l->append("CompositorFrameAck(");
700 LogParam(p.resources, l);
701 l->append(", ");
702 LogParam(p.last_software_frame_id, l);
703 l->append(", ");
704 if (p.gl_frame_data)
705 LogParam(*p.gl_frame_data, l);
706 l->append(")");
709 void ParamTraits<cc::DelegatedFrameData>::Write(Message* m,
710 const param_type& p) {
711 DCHECK_NE(0u, p.render_pass_list.size());
713 size_t to_reserve = sizeof(p.device_scale_factor);
714 to_reserve += p.resource_list.size() * sizeof(cc::TransferableResource);
715 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
716 const cc::RenderPass* pass = p.render_pass_list[i];
717 to_reserve += ReserveSizeForRenderPassWrite(*pass);
719 m->Reserve(to_reserve);
721 WriteParam(m, p.device_scale_factor);
722 WriteParam(m, p.resource_list);
723 WriteParam(m, p.render_pass_list.size());
724 for (size_t i = 0; i < p.render_pass_list.size(); ++i)
725 WriteParam(m, *p.render_pass_list[i]);
728 bool ParamTraits<cc::DelegatedFrameData>::Read(const Message* m,
729 PickleIterator* iter,
730 param_type* p) {
731 if (!ReadParam(m, iter, &p->device_scale_factor))
732 return false;
734 const static size_t kMaxRenderPasses = 10000;
736 size_t num_render_passes;
737 if (!ReadParam(m, iter, &p->resource_list) ||
738 !ReadParam(m, iter, &num_render_passes) ||
739 num_render_passes > kMaxRenderPasses || num_render_passes == 0)
740 return false;
741 for (size_t i = 0; i < num_render_passes; ++i) {
742 scoped_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
743 if (!ReadParam(m, iter, render_pass.get()))
744 return false;
745 p->render_pass_list.push_back(render_pass.Pass());
747 return true;
750 void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
751 std::string* l) {
752 l->append("DelegatedFrameData(");
753 LogParam(p.device_scale_factor, l);
754 LogParam(p.resource_list, l);
755 l->append(", [");
756 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
757 if (i)
758 l->append(", ");
759 LogParam(*p.render_pass_list[i], l);
761 l->append("])");
764 void ParamTraits<cc::SoftwareFrameData>::Write(Message* m,
765 const param_type& p) {
766 DCHECK(cc::SharedBitmap::VerifySizeInBytes(p.size));
768 m->Reserve(sizeof(cc::SoftwareFrameData));
769 WriteParam(m, p.id);
770 WriteParam(m, p.size);
771 WriteParam(m, p.damage_rect);
772 WriteParam(m, p.bitmap_id);
775 bool ParamTraits<cc::SoftwareFrameData>::Read(const Message* m,
776 PickleIterator* iter,
777 param_type* p) {
778 if (!ReadParam(m, iter, &p->id))
779 return false;
780 if (!ReadParam(m, iter, &p->size) ||
781 !cc::SharedBitmap::VerifySizeInBytes(p->size))
782 return false;
783 if (!ReadParam(m, iter, &p->damage_rect))
784 return false;
785 if (!ReadParam(m, iter, &p->bitmap_id))
786 return false;
787 return true;
790 void ParamTraits<cc::SoftwareFrameData>::Log(const param_type& p,
791 std::string* l) {
792 l->append("SoftwareFrameData(");
793 LogParam(p.id, l);
794 l->append(", ");
795 LogParam(p.size, l);
796 l->append(", ");
797 LogParam(p.damage_rect, l);
798 l->append(", ");
799 LogParam(p.bitmap_id, l);
800 l->append(")");
803 } // namespace IPC