Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / common / cc_messages.cc
blobd2f4bd629188a90a790dc863e0fb96bf77afa555
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 "cc/quads/largest_draw_quad.h"
10 #include "content/public/common/common_param_traits.h"
11 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkFlattenableSerialization.h"
13 #include "ui/gfx/transform.h"
15 namespace IPC {
17 void ParamTraits<cc::FilterOperation>::Write(
18 Message* m, const param_type& p) {
19 WriteParam(m, p.type());
20 switch (p.type()) {
21 case cc::FilterOperation::GRAYSCALE:
22 case cc::FilterOperation::SEPIA:
23 case cc::FilterOperation::SATURATE:
24 case cc::FilterOperation::HUE_ROTATE:
25 case cc::FilterOperation::INVERT:
26 case cc::FilterOperation::BRIGHTNESS:
27 case cc::FilterOperation::SATURATING_BRIGHTNESS:
28 case cc::FilterOperation::CONTRAST:
29 case cc::FilterOperation::OPACITY:
30 case cc::FilterOperation::BLUR:
31 WriteParam(m, p.amount());
32 break;
33 case cc::FilterOperation::DROP_SHADOW:
34 WriteParam(m, p.drop_shadow_offset());
35 WriteParam(m, p.amount());
36 WriteParam(m, p.drop_shadow_color());
37 break;
38 case cc::FilterOperation::COLOR_MATRIX:
39 for (int i = 0; i < 20; ++i)
40 WriteParam(m, p.matrix()[i]);
41 break;
42 case cc::FilterOperation::ZOOM:
43 WriteParam(m, p.amount());
44 WriteParam(m, p.zoom_inset());
45 break;
46 case cc::FilterOperation::REFERENCE:
47 WriteParam(m, p.image_filter());
48 break;
49 case cc::FilterOperation::ALPHA_THRESHOLD:
50 NOTREACHED();
51 break;
55 bool ParamTraits<cc::FilterOperation>::Read(
56 const Message* m, PickleIterator* iter, param_type* r) {
57 cc::FilterOperation::FilterType type;
58 float amount;
59 gfx::Point drop_shadow_offset;
60 SkColor drop_shadow_color;
61 SkScalar matrix[20];
62 int zoom_inset;
64 if (!ReadParam(m, iter, &type))
65 return false;
66 r->set_type(type);
68 bool success = false;
69 switch (type) {
70 case cc::FilterOperation::GRAYSCALE:
71 case cc::FilterOperation::SEPIA:
72 case cc::FilterOperation::SATURATE:
73 case cc::FilterOperation::HUE_ROTATE:
74 case cc::FilterOperation::INVERT:
75 case cc::FilterOperation::BRIGHTNESS:
76 case cc::FilterOperation::SATURATING_BRIGHTNESS:
77 case cc::FilterOperation::CONTRAST:
78 case cc::FilterOperation::OPACITY:
79 case cc::FilterOperation::BLUR:
80 if (ReadParam(m, iter, &amount)) {
81 r->set_amount(amount);
82 success = true;
84 break;
85 case cc::FilterOperation::DROP_SHADOW:
86 if (ReadParam(m, iter, &drop_shadow_offset) &&
87 ReadParam(m, iter, &amount) &&
88 ReadParam(m, iter, &drop_shadow_color)) {
89 r->set_drop_shadow_offset(drop_shadow_offset);
90 r->set_amount(amount);
91 r->set_drop_shadow_color(drop_shadow_color);
92 success = true;
94 break;
95 case cc::FilterOperation::COLOR_MATRIX: {
96 int i;
97 for (i = 0; i < 20; ++i) {
98 if (!ReadParam(m, iter, &matrix[i]))
99 break;
101 if (i == 20) {
102 r->set_matrix(matrix);
103 success = true;
105 break;
107 case cc::FilterOperation::ZOOM:
108 if (ReadParam(m, iter, &amount) &&
109 ReadParam(m, iter, &zoom_inset) &&
110 amount >= 0.f &&
111 zoom_inset >= 0) {
112 r->set_amount(amount);
113 r->set_zoom_inset(zoom_inset);
114 success = true;
116 break;
117 case cc::FilterOperation::REFERENCE: {
118 skia::RefPtr<SkImageFilter> filter;
119 if (!ReadParam(m, iter, &filter)) {
120 success = false;
121 break;
123 r->set_image_filter(filter);
124 success = true;
125 break;
127 case cc::FilterOperation::ALPHA_THRESHOLD:
128 break;
130 return success;
133 void ParamTraits<cc::FilterOperation>::Log(
134 const param_type& p, std::string* l) {
135 l->append("(");
136 LogParam(static_cast<unsigned>(p.type()), l);
137 l->append(", ");
139 switch (p.type()) {
140 case cc::FilterOperation::GRAYSCALE:
141 case cc::FilterOperation::SEPIA:
142 case cc::FilterOperation::SATURATE:
143 case cc::FilterOperation::HUE_ROTATE:
144 case cc::FilterOperation::INVERT:
145 case cc::FilterOperation::BRIGHTNESS:
146 case cc::FilterOperation::SATURATING_BRIGHTNESS:
147 case cc::FilterOperation::CONTRAST:
148 case cc::FilterOperation::OPACITY:
149 case cc::FilterOperation::BLUR:
150 LogParam(p.amount(), l);
151 break;
152 case cc::FilterOperation::DROP_SHADOW:
153 LogParam(p.drop_shadow_offset(), l);
154 l->append(", ");
155 LogParam(p.amount(), l);
156 l->append(", ");
157 LogParam(p.drop_shadow_color(), l);
158 break;
159 case cc::FilterOperation::COLOR_MATRIX:
160 for (int i = 0; i < 20; ++i) {
161 if (i)
162 l->append(", ");
163 LogParam(p.matrix()[i], l);
165 break;
166 case cc::FilterOperation::ZOOM:
167 LogParam(p.amount(), l);
168 l->append(", ");
169 LogParam(p.zoom_inset(), l);
170 break;
171 case cc::FilterOperation::REFERENCE:
172 LogParam(p.image_filter(), l);
173 break;
174 case cc::FilterOperation::ALPHA_THRESHOLD:
175 NOTREACHED();
176 break;
178 l->append(")");
181 void ParamTraits<cc::FilterOperations>::Write(
182 Message* m, const param_type& p) {
183 WriteParam(m, p.size());
184 for (std::size_t i = 0; i < p.size(); ++i) {
185 WriteParam(m, p.at(i));
189 bool ParamTraits<cc::FilterOperations>::Read(
190 const Message* m, PickleIterator* iter, param_type* r) {
191 size_t count;
192 if (!ReadParam(m, iter, &count))
193 return false;
195 for (std::size_t i = 0; i < count; ++i) {
196 cc::FilterOperation op = cc::FilterOperation::CreateEmptyFilter();
197 if (!ReadParam(m, iter, &op))
198 return false;
199 r->Append(op);
201 return true;
204 void ParamTraits<cc::FilterOperations>::Log(
205 const param_type& p, std::string* l) {
206 l->append("(");
207 for (std::size_t i = 0; i < p.size(); ++i) {
208 if (i)
209 l->append(", ");
210 LogParam(p.at(i), l);
212 l->append(")");
215 void ParamTraits<skia::RefPtr<SkImageFilter> >::Write(
216 Message* m, const param_type& p) {
217 SkImageFilter* filter = p.get();
218 if (filter) {
219 skia::RefPtr<SkData> data =
220 skia::AdoptRef(SkValidatingSerializeFlattenable(filter));
221 m->WriteData(static_cast<const char*>(data->data()), data->size());
222 } else {
223 m->WriteData(0, 0);
227 bool ParamTraits<skia::RefPtr<SkImageFilter> >::Read(
228 const Message* m, PickleIterator* iter, param_type* r) {
229 const char* data = 0;
230 int length = 0;
231 if (!m->ReadData(iter, &data, &length))
232 return false;
233 if (length > 0) {
234 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
235 data, length, SkImageFilter::GetFlattenableType());
236 *r = skia::AdoptRef(static_cast<SkImageFilter*>(flattenable));
237 } else {
238 r->clear();
240 return true;
243 void ParamTraits<skia::RefPtr<SkImageFilter> >::Log(
244 const param_type& p, std::string* l) {
245 l->append("(");
246 LogParam(p.get() ? p->countInputs() : 0, l);
247 l->append(")");
250 void ParamTraits<gfx::Transform>::Write(
251 Message* m, const param_type& p) {
252 #ifdef SK_MSCALAR_IS_FLOAT
253 float column_major_data[16];
254 p.matrix().asColMajorf(column_major_data);
255 #else
256 double column_major_data[16];
257 p.matrix().asColMajord(column_major_data);
258 #endif
259 m->WriteBytes(&column_major_data, sizeof(SkMScalar) * 16);
262 bool ParamTraits<gfx::Transform>::Read(
263 const Message* m, PickleIterator* iter, param_type* r) {
264 const char* column_major_data;
265 if (!m->ReadBytes(iter, &column_major_data, sizeof(SkMScalar) * 16))
266 return false;
267 r->matrix().setColMajor(
268 reinterpret_cast<const SkMScalar*>(column_major_data));
269 return true;
272 void ParamTraits<gfx::Transform>::Log(
273 const param_type& p, std::string* l) {
274 #ifdef SK_MSCALAR_IS_FLOAT
275 float row_major_data[16];
276 p.matrix().asRowMajorf(row_major_data);
277 #else
278 double row_major_data[16];
279 p.matrix().asRowMajord(row_major_data);
280 #endif
281 l->append("(");
282 for (int i = 0; i < 16; ++i) {
283 if (i > 0)
284 l->append(", ");
285 LogParam(row_major_data[i], l);
287 l->append(") ");
290 void ParamTraits<cc::RenderPass>::Write(
291 Message* m, const param_type& p) {
292 WriteParam(m, p.id);
293 WriteParam(m, p.output_rect);
294 WriteParam(m, p.damage_rect);
295 WriteParam(m, p.transform_to_root_target);
296 WriteParam(m, p.has_transparent_background);
297 WriteParam(m, p.quad_list.size());
299 cc::SharedQuadStateList::ConstIterator shared_quad_state_iter =
300 p.shared_quad_state_list.begin();
301 cc::SharedQuadStateList::ConstIterator last_shared_quad_state_iter =
302 p.shared_quad_state_list.end();
303 for (const auto& quad : p.quad_list) {
304 DCHECK(quad->rect.Contains(quad->visible_rect))
305 << quad->material << " rect: " << quad->rect.ToString()
306 << " visible_rect: " << quad->visible_rect.ToString();
307 DCHECK(quad->opaque_rect.IsEmpty() ||
308 quad->rect.Contains(quad->opaque_rect))
309 << quad->material << " rect: " << quad->rect.ToString()
310 << " opaque_rect: " << quad->opaque_rect.ToString();
312 switch (quad->material) {
313 case cc::DrawQuad::CHECKERBOARD:
314 WriteParam(m, *cc::CheckerboardDrawQuad::MaterialCast(quad));
315 break;
316 case cc::DrawQuad::DEBUG_BORDER:
317 WriteParam(m, *cc::DebugBorderDrawQuad::MaterialCast(quad));
318 break;
319 case cc::DrawQuad::IO_SURFACE_CONTENT:
320 WriteParam(m, *cc::IOSurfaceDrawQuad::MaterialCast(quad));
321 break;
322 case cc::DrawQuad::PICTURE_CONTENT:
323 NOTREACHED();
324 break;
325 case cc::DrawQuad::TEXTURE_CONTENT:
326 WriteParam(m, *cc::TextureDrawQuad::MaterialCast(quad));
327 break;
328 case cc::DrawQuad::RENDER_PASS:
329 WriteParam(m, *cc::RenderPassDrawQuad::MaterialCast(quad));
330 break;
331 case cc::DrawQuad::SOLID_COLOR:
332 WriteParam(m, *cc::SolidColorDrawQuad::MaterialCast(quad));
333 break;
334 case cc::DrawQuad::SURFACE_CONTENT:
335 WriteParam(m, *cc::SurfaceDrawQuad::MaterialCast(quad));
336 break;
337 case cc::DrawQuad::TILED_CONTENT:
338 WriteParam(m, *cc::TileDrawQuad::MaterialCast(quad));
339 break;
340 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
341 WriteParam(m, *cc::StreamVideoDrawQuad::MaterialCast(quad));
342 break;
343 case cc::DrawQuad::YUV_VIDEO_CONTENT:
344 WriteParam(m, *cc::YUVVideoDrawQuad::MaterialCast(quad));
345 break;
346 case cc::DrawQuad::INVALID:
347 break;
350 // Null shared quad states should not occur.
351 DCHECK(quad->shared_quad_state);
353 // SharedQuadStates should appear in the order they are used by DrawQuads.
354 // Find the SharedQuadState for this DrawQuad.
355 while (shared_quad_state_iter != p.shared_quad_state_list.end() &&
356 quad->shared_quad_state != *shared_quad_state_iter)
357 ++shared_quad_state_iter;
359 DCHECK(shared_quad_state_iter != p.shared_quad_state_list.end());
361 if (shared_quad_state_iter != last_shared_quad_state_iter) {
362 WriteParam(m, true);
363 WriteParam(m, **shared_quad_state_iter);
364 last_shared_quad_state_iter = shared_quad_state_iter;
365 } else {
366 WriteParam(m, false);
371 static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
372 size_t to_reserve = sizeof(cc::RenderPass);
374 // Whether the quad points to a new shared quad state for each quad.
375 to_reserve += p.quad_list.size() * sizeof(bool);
377 // Shared quad state is only written when a quad contains a shared quad state
378 // that has not been written.
379 to_reserve += p.shared_quad_state_list.size() * sizeof(cc::SharedQuadState);
381 // The largest quad type, verified by a unit test.
382 to_reserve += p.quad_list.size() * sizeof(cc::kLargestDrawQuad);
383 return to_reserve;
386 template <typename QuadType>
387 static cc::DrawQuad* ReadDrawQuad(const Message* m,
388 PickleIterator* iter,
389 cc::RenderPass* render_pass) {
390 QuadType* quad = render_pass->CreateAndAppendDrawQuad<QuadType>();
391 if (!ReadParam(m, iter, quad))
392 return NULL;
393 return quad;
396 bool ParamTraits<cc::RenderPass>::Read(
397 const Message* m, PickleIterator* iter, param_type* p) {
398 cc::RenderPassId id(-1, -1);
399 gfx::Rect output_rect;
400 gfx::Rect damage_rect;
401 gfx::Transform transform_to_root_target;
402 bool has_transparent_background;
403 size_t quad_list_size;
405 if (!ReadParam(m, iter, &id) ||
406 !ReadParam(m, iter, &output_rect) ||
407 !ReadParam(m, iter, &damage_rect) ||
408 !ReadParam(m, iter, &transform_to_root_target) ||
409 !ReadParam(m, iter, &has_transparent_background) ||
410 !ReadParam(m, iter, &quad_list_size))
411 return false;
413 p->SetAll(id,
414 output_rect,
415 damage_rect,
416 transform_to_root_target,
417 has_transparent_background);
419 for (size_t i = 0; i < quad_list_size; ++i) {
420 cc::DrawQuad::Material material;
421 PickleIterator temp_iter = *iter;
422 if (!ReadParam(m, &temp_iter, &material))
423 return false;
425 cc::DrawQuad* draw_quad = NULL;
426 switch (material) {
427 case cc::DrawQuad::CHECKERBOARD:
428 draw_quad = ReadDrawQuad<cc::CheckerboardDrawQuad>(m, iter, p);
429 break;
430 case cc::DrawQuad::DEBUG_BORDER:
431 draw_quad = ReadDrawQuad<cc::DebugBorderDrawQuad>(m, iter, p);
432 break;
433 case cc::DrawQuad::IO_SURFACE_CONTENT:
434 draw_quad = ReadDrawQuad<cc::IOSurfaceDrawQuad>(m, iter, p);
435 break;
436 case cc::DrawQuad::PICTURE_CONTENT:
437 NOTREACHED();
438 return false;
439 case cc::DrawQuad::SURFACE_CONTENT:
440 draw_quad = ReadDrawQuad<cc::SurfaceDrawQuad>(m, iter, p);
441 break;
442 case cc::DrawQuad::TEXTURE_CONTENT:
443 draw_quad = ReadDrawQuad<cc::TextureDrawQuad>(m, iter, p);
444 break;
445 case cc::DrawQuad::RENDER_PASS:
446 draw_quad = ReadDrawQuad<cc::RenderPassDrawQuad>(m, iter, p);
447 break;
448 case cc::DrawQuad::SOLID_COLOR:
449 draw_quad = ReadDrawQuad<cc::SolidColorDrawQuad>(m, iter, p);
450 break;
451 case cc::DrawQuad::TILED_CONTENT:
452 draw_quad = ReadDrawQuad<cc::TileDrawQuad>(m, iter, p);
453 break;
454 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
455 draw_quad = ReadDrawQuad<cc::StreamVideoDrawQuad>(m, iter, p);
456 break;
457 case cc::DrawQuad::YUV_VIDEO_CONTENT:
458 draw_quad = ReadDrawQuad<cc::YUVVideoDrawQuad>(m, iter, p);
459 break;
460 case cc::DrawQuad::INVALID:
461 break;
463 if (!draw_quad)
464 return false;
465 if (!draw_quad->rect.Contains(draw_quad->visible_rect)) {
466 LOG(ERROR) << "Quad with invalid visible rect " << draw_quad->material
467 << " rect: " << draw_quad->rect.ToString()
468 << " visible_rect: " << draw_quad->visible_rect.ToString();
469 return false;
471 if (!draw_quad->opaque_rect.IsEmpty() &&
472 !draw_quad->rect.Contains(draw_quad->opaque_rect)) {
473 LOG(ERROR) << "Quad with invalid opaque rect " << draw_quad->material
474 << " rect: " << draw_quad->rect.ToString()
475 << " opaque_rect: " << draw_quad->opaque_rect.ToString();
476 return false;
479 bool has_new_shared_quad_state;
480 if (!ReadParam(m, iter, &has_new_shared_quad_state))
481 return false;
483 // If the quad has a new shared quad state, read it in.
484 if (has_new_shared_quad_state) {
485 cc::SharedQuadState* state = p->CreateAndAppendSharedQuadState();
486 if (!ReadParam(m, iter, state))
487 return false;
490 draw_quad->shared_quad_state = p->shared_quad_state_list.back();
493 return true;
496 void ParamTraits<cc::RenderPass>::Log(
497 const param_type& p, std::string* l) {
498 l->append("RenderPass((");
499 LogParam(p.id, l);
500 l->append("), ");
501 LogParam(p.output_rect, l);
502 l->append(", ");
503 LogParam(p.damage_rect, l);
504 l->append(", ");
505 LogParam(p.transform_to_root_target, l);
506 l->append(", ");
507 LogParam(p.has_transparent_background, l);
508 l->append(", ");
510 l->append("[");
511 for (const auto& shared_quad_state : p.shared_quad_state_list) {
512 if (shared_quad_state != p.shared_quad_state_list.front())
513 l->append(", ");
514 LogParam(*shared_quad_state, l);
516 l->append("], [");
517 for (const auto& quad : p.quad_list) {
518 if (quad != p.quad_list.front())
519 l->append(", ");
520 switch (quad->material) {
521 case cc::DrawQuad::CHECKERBOARD:
522 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(quad), l);
523 break;
524 case cc::DrawQuad::DEBUG_BORDER:
525 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad), l);
526 break;
527 case cc::DrawQuad::IO_SURFACE_CONTENT:
528 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad), l);
529 break;
530 case cc::DrawQuad::PICTURE_CONTENT:
531 NOTREACHED();
532 break;
533 case cc::DrawQuad::TEXTURE_CONTENT:
534 LogParam(*cc::TextureDrawQuad::MaterialCast(quad), l);
535 break;
536 case cc::DrawQuad::RENDER_PASS:
537 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad), l);
538 break;
539 case cc::DrawQuad::SOLID_COLOR:
540 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad), l);
541 break;
542 case cc::DrawQuad::SURFACE_CONTENT:
543 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad), l);
544 break;
545 case cc::DrawQuad::TILED_CONTENT:
546 LogParam(*cc::TileDrawQuad::MaterialCast(quad), l);
547 break;
548 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
549 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad), l);
550 break;
551 case cc::DrawQuad::YUV_VIDEO_CONTENT:
552 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad), l);
553 break;
554 case cc::DrawQuad::INVALID:
555 break;
558 l->append("])");
561 namespace {
562 enum CompositorFrameType {
563 NO_FRAME,
564 DELEGATED_FRAME,
565 GL_FRAME,
566 SOFTWARE_FRAME,
570 void ParamTraits<cc::CompositorFrame>::Write(Message* m,
571 const param_type& p) {
572 WriteParam(m, p.metadata);
573 if (p.delegated_frame_data) {
574 DCHECK(!p.gl_frame_data);
575 DCHECK(!p.software_frame_data);
576 WriteParam(m, static_cast<int>(DELEGATED_FRAME));
577 WriteParam(m, *p.delegated_frame_data);
578 } else if (p.gl_frame_data) {
579 DCHECK(!p.software_frame_data);
580 WriteParam(m, static_cast<int>(GL_FRAME));
581 WriteParam(m, *p.gl_frame_data);
582 } else if (p.software_frame_data) {
583 WriteParam(m, static_cast<int>(SOFTWARE_FRAME));
584 WriteParam(m, *p.software_frame_data);
585 } else {
586 WriteParam(m, static_cast<int>(NO_FRAME));
590 bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
591 PickleIterator* iter,
592 param_type* p) {
593 if (!ReadParam(m, iter, &p->metadata))
594 return false;
596 int compositor_frame_type;
597 if (!ReadParam(m, iter, &compositor_frame_type))
598 return false;
600 switch (compositor_frame_type) {
601 case DELEGATED_FRAME:
602 p->delegated_frame_data.reset(new cc::DelegatedFrameData());
603 if (!ReadParam(m, iter, p->delegated_frame_data.get()))
604 return false;
605 break;
606 case GL_FRAME:
607 p->gl_frame_data.reset(new cc::GLFrameData());
608 if (!ReadParam(m, iter, p->gl_frame_data.get()))
609 return false;
610 break;
611 case SOFTWARE_FRAME:
612 p->software_frame_data.reset(new cc::SoftwareFrameData());
613 if (!ReadParam(m, iter, p->software_frame_data.get()))
614 return false;
615 break;
616 case NO_FRAME:
617 break;
618 default:
619 return false;
621 return true;
624 void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
625 std::string* l) {
626 l->append("CompositorFrame(");
627 LogParam(p.metadata, l);
628 l->append(", ");
629 if (p.delegated_frame_data)
630 LogParam(*p.delegated_frame_data, l);
631 else if (p.gl_frame_data)
632 LogParam(*p.gl_frame_data, l);
633 else if (p.software_frame_data)
634 LogParam(*p.software_frame_data, l);
635 l->append(")");
638 void ParamTraits<cc::CompositorFrameAck>::Write(Message* m,
639 const param_type& p) {
640 WriteParam(m, p.resources);
641 WriteParam(m, p.last_software_frame_id);
642 if (p.gl_frame_data) {
643 WriteParam(m, static_cast<int>(GL_FRAME));
644 WriteParam(m, *p.gl_frame_data);
645 } else {
646 WriteParam(m, static_cast<int>(NO_FRAME));
650 bool ParamTraits<cc::CompositorFrameAck>::Read(const Message* m,
651 PickleIterator* iter,
652 param_type* p) {
653 if (!ReadParam(m, iter, &p->resources))
654 return false;
656 if (!ReadParam(m, iter, &p->last_software_frame_id))
657 return false;
659 int compositor_frame_type;
660 if (!ReadParam(m, iter, &compositor_frame_type))
661 return false;
663 switch (compositor_frame_type) {
664 case NO_FRAME:
665 break;
666 case GL_FRAME:
667 p->gl_frame_data.reset(new cc::GLFrameData());
668 if (!ReadParam(m, iter, p->gl_frame_data.get()))
669 return false;
670 break;
671 default:
672 return false;
674 return true;
677 void ParamTraits<cc::CompositorFrameAck>::Log(const param_type& p,
678 std::string* l) {
679 l->append("CompositorFrameAck(");
680 LogParam(p.resources, l);
681 l->append(", ");
682 LogParam(p.last_software_frame_id, l);
683 l->append(", ");
684 if (p.gl_frame_data)
685 LogParam(*p.gl_frame_data, l);
686 l->append(")");
689 void ParamTraits<cc::DelegatedFrameData>::Write(Message* m,
690 const param_type& p) {
691 DCHECK_NE(0u, p.render_pass_list.size());
693 size_t to_reserve = sizeof(p.device_scale_factor);
694 to_reserve += p.resource_list.size() * sizeof(cc::TransferableResource);
695 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
696 const cc::RenderPass* pass = p.render_pass_list[i];
697 to_reserve += sizeof(size_t) * 2;
698 to_reserve += ReserveSizeForRenderPassWrite(*pass);
700 m->Reserve(to_reserve);
702 WriteParam(m, p.device_scale_factor);
703 WriteParam(m, p.resource_list);
704 WriteParam(m, p.render_pass_list.size());
705 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
706 WriteParam(m, p.render_pass_list[i]->quad_list.size());
707 WriteParam(m, p.render_pass_list[i]->shared_quad_state_list.size());
708 WriteParam(m, *p.render_pass_list[i]);
712 bool ParamTraits<cc::DelegatedFrameData>::Read(const Message* m,
713 PickleIterator* iter,
714 param_type* p) {
715 if (!ReadParam(m, iter, &p->device_scale_factor))
716 return false;
718 const static size_t kMaxRenderPasses = 10000;
719 const static size_t kMaxSharedQuadStateListSize = 100000;
720 const static size_t kMaxQuadListSize = 1000000;
722 size_t num_render_passes;
723 if (!ReadParam(m, iter, &p->resource_list) ||
724 !ReadParam(m, iter, &num_render_passes) ||
725 num_render_passes > kMaxRenderPasses || num_render_passes == 0)
726 return false;
727 for (size_t i = 0; i < num_render_passes; ++i) {
728 size_t quad_list_size;
729 size_t shared_quad_state_list_size;
730 if (!ReadParam(m, iter, &quad_list_size) ||
731 !ReadParam(m, iter, &shared_quad_state_list_size) ||
732 quad_list_size > kMaxQuadListSize ||
733 shared_quad_state_list_size > kMaxSharedQuadStateListSize)
734 return false;
735 scoped_ptr<cc::RenderPass> render_pass =
736 cc::RenderPass::Create(shared_quad_state_list_size, quad_list_size);
737 if (!ReadParam(m, iter, render_pass.get()))
738 return false;
739 p->render_pass_list.push_back(render_pass.Pass());
741 return true;
744 void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
745 std::string* l) {
746 l->append("DelegatedFrameData(");
747 LogParam(p.device_scale_factor, l);
748 LogParam(p.resource_list, l);
749 l->append(", [");
750 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
751 if (i)
752 l->append(", ");
753 LogParam(*p.render_pass_list[i], l);
755 l->append("])");
758 void ParamTraits<cc::SoftwareFrameData>::Write(Message* m,
759 const param_type& p) {
760 DCHECK(cc::SharedBitmap::VerifySizeInBytes(p.size));
762 m->Reserve(sizeof(cc::SoftwareFrameData));
763 WriteParam(m, p.id);
764 WriteParam(m, p.size);
765 WriteParam(m, p.damage_rect);
766 WriteParam(m, p.bitmap_id);
769 bool ParamTraits<cc::SoftwareFrameData>::Read(const Message* m,
770 PickleIterator* iter,
771 param_type* p) {
772 if (!ReadParam(m, iter, &p->id))
773 return false;
774 if (!ReadParam(m, iter, &p->size) ||
775 !cc::SharedBitmap::VerifySizeInBytes(p->size))
776 return false;
777 if (!ReadParam(m, iter, &p->damage_rect))
778 return false;
779 if (!ReadParam(m, iter, &p->bitmap_id))
780 return false;
781 return true;
784 void ParamTraits<cc::SoftwareFrameData>::Log(const param_type& p,
785 std::string* l) {
786 l->append("SoftwareFrameData(");
787 LogParam(p.id, l);
788 l->append(", ");
789 LogParam(p.size, l);
790 l->append(", ");
791 LogParam(p.damage_rect, l);
792 l->append(", ");
793 LogParam(p.bitmap_id, l);
794 l->append(")");
797 } // namespace IPC