Non-SFI mode: Clean up libevent_nacl_nonsfi.gyp.
[chromium-blink-merge.git] / content / common / cc_messages.cc
blob8ecdf0c4cea1b95fc5bf773af522bedd696cdfd6
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() || 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 // Null shared quad states should not occur.
350 DCHECK(quad.shared_quad_state);
352 // SharedQuadStates should appear in the order they are used by DrawQuads.
353 // Find the SharedQuadState for this DrawQuad.
354 while (shared_quad_state_iter != p.shared_quad_state_list.end() &&
355 quad.shared_quad_state != &*shared_quad_state_iter)
356 ++shared_quad_state_iter;
358 DCHECK(shared_quad_state_iter != p.shared_quad_state_list.end());
360 if (shared_quad_state_iter != last_shared_quad_state_iter) {
361 WriteParam(m, true);
362 WriteParam(m, *shared_quad_state_iter);
363 last_shared_quad_state_iter = shared_quad_state_iter;
364 } else {
365 WriteParam(m, false);
370 static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
371 size_t to_reserve = sizeof(cc::RenderPass);
373 // Whether the quad points to a new shared quad state for each quad.
374 to_reserve += p.quad_list.size() * sizeof(bool);
376 // Shared quad state is only written when a quad contains a shared quad state
377 // that has not been written.
378 to_reserve += p.shared_quad_state_list.size() * sizeof(cc::SharedQuadState);
380 // The largest quad type, verified by a unit test.
381 to_reserve += p.quad_list.size() * sizeof(cc::kLargestDrawQuad);
382 return to_reserve;
385 template <typename QuadType>
386 static cc::DrawQuad* ReadDrawQuad(const Message* m,
387 PickleIterator* iter,
388 cc::RenderPass* render_pass) {
389 QuadType* quad = render_pass->CreateAndAppendDrawQuad<QuadType>();
390 if (!ReadParam(m, iter, quad))
391 return NULL;
392 return quad;
395 bool ParamTraits<cc::RenderPass>::Read(
396 const Message* m, PickleIterator* iter, param_type* p) {
397 cc::RenderPassId id(-1, -1);
398 gfx::Rect output_rect;
399 gfx::Rect damage_rect;
400 gfx::Transform transform_to_root_target;
401 bool has_transparent_background;
402 size_t quad_list_size;
404 if (!ReadParam(m, iter, &id) ||
405 !ReadParam(m, iter, &output_rect) ||
406 !ReadParam(m, iter, &damage_rect) ||
407 !ReadParam(m, iter, &transform_to_root_target) ||
408 !ReadParam(m, iter, &has_transparent_background) ||
409 !ReadParam(m, iter, &quad_list_size))
410 return false;
412 p->SetAll(id,
413 output_rect,
414 damage_rect,
415 transform_to_root_target,
416 has_transparent_background);
418 for (size_t i = 0; i < quad_list_size; ++i) {
419 cc::DrawQuad::Material material;
420 PickleIterator temp_iter = *iter;
421 if (!ReadParam(m, &temp_iter, &material))
422 return false;
424 cc::DrawQuad* draw_quad = NULL;
425 switch (material) {
426 case cc::DrawQuad::CHECKERBOARD:
427 draw_quad = ReadDrawQuad<cc::CheckerboardDrawQuad>(m, iter, p);
428 break;
429 case cc::DrawQuad::DEBUG_BORDER:
430 draw_quad = ReadDrawQuad<cc::DebugBorderDrawQuad>(m, iter, p);
431 break;
432 case cc::DrawQuad::IO_SURFACE_CONTENT:
433 draw_quad = ReadDrawQuad<cc::IOSurfaceDrawQuad>(m, iter, p);
434 break;
435 case cc::DrawQuad::PICTURE_CONTENT:
436 NOTREACHED();
437 return false;
438 case cc::DrawQuad::SURFACE_CONTENT:
439 draw_quad = ReadDrawQuad<cc::SurfaceDrawQuad>(m, iter, p);
440 break;
441 case cc::DrawQuad::TEXTURE_CONTENT:
442 draw_quad = ReadDrawQuad<cc::TextureDrawQuad>(m, iter, p);
443 break;
444 case cc::DrawQuad::RENDER_PASS:
445 draw_quad = ReadDrawQuad<cc::RenderPassDrawQuad>(m, iter, p);
446 break;
447 case cc::DrawQuad::SOLID_COLOR:
448 draw_quad = ReadDrawQuad<cc::SolidColorDrawQuad>(m, iter, p);
449 break;
450 case cc::DrawQuad::TILED_CONTENT:
451 draw_quad = ReadDrawQuad<cc::TileDrawQuad>(m, iter, p);
452 break;
453 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
454 draw_quad = ReadDrawQuad<cc::StreamVideoDrawQuad>(m, iter, p);
455 break;
456 case cc::DrawQuad::YUV_VIDEO_CONTENT:
457 draw_quad = ReadDrawQuad<cc::YUVVideoDrawQuad>(m, iter, p);
458 break;
459 case cc::DrawQuad::INVALID:
460 break;
462 if (!draw_quad)
463 return false;
464 if (!draw_quad->rect.Contains(draw_quad->visible_rect)) {
465 LOG(ERROR) << "Quad with invalid visible rect " << draw_quad->material
466 << " rect: " << draw_quad->rect.ToString()
467 << " visible_rect: " << draw_quad->visible_rect.ToString();
468 return false;
470 if (!draw_quad->opaque_rect.IsEmpty() &&
471 !draw_quad->rect.Contains(draw_quad->opaque_rect)) {
472 LOG(ERROR) << "Quad with invalid opaque rect " << draw_quad->material
473 << " rect: " << draw_quad->rect.ToString()
474 << " opaque_rect: " << draw_quad->opaque_rect.ToString();
475 return false;
478 bool has_new_shared_quad_state;
479 if (!ReadParam(m, iter, &has_new_shared_quad_state))
480 return false;
482 // If the quad has a new shared quad state, read it in.
483 if (has_new_shared_quad_state) {
484 cc::SharedQuadState* state = p->CreateAndAppendSharedQuadState();
485 if (!ReadParam(m, iter, state))
486 return false;
489 draw_quad->shared_quad_state = p->shared_quad_state_list.back();
492 return true;
495 void ParamTraits<cc::RenderPass>::Log(
496 const param_type& p, std::string* l) {
497 l->append("RenderPass((");
498 LogParam(p.id, l);
499 l->append("), ");
500 LogParam(p.output_rect, l);
501 l->append(", ");
502 LogParam(p.damage_rect, l);
503 l->append(", ");
504 LogParam(p.transform_to_root_target, l);
505 l->append(", ");
506 LogParam(p.has_transparent_background, l);
507 l->append(", ");
509 l->append("[");
510 for (const auto& shared_quad_state : p.shared_quad_state_list) {
511 if (&shared_quad_state != p.shared_quad_state_list.front())
512 l->append(", ");
513 LogParam(shared_quad_state, l);
515 l->append("], [");
516 for (const auto& quad : p.quad_list) {
517 if (&quad != p.quad_list.front())
518 l->append(", ");
519 switch (quad.material) {
520 case cc::DrawQuad::CHECKERBOARD:
521 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(&quad), l);
522 break;
523 case cc::DrawQuad::DEBUG_BORDER:
524 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(&quad), l);
525 break;
526 case cc::DrawQuad::IO_SURFACE_CONTENT:
527 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(&quad), l);
528 break;
529 case cc::DrawQuad::PICTURE_CONTENT:
530 NOTREACHED();
531 break;
532 case cc::DrawQuad::TEXTURE_CONTENT:
533 LogParam(*cc::TextureDrawQuad::MaterialCast(&quad), l);
534 break;
535 case cc::DrawQuad::RENDER_PASS:
536 LogParam(*cc::RenderPassDrawQuad::MaterialCast(&quad), l);
537 break;
538 case cc::DrawQuad::SOLID_COLOR:
539 LogParam(*cc::SolidColorDrawQuad::MaterialCast(&quad), l);
540 break;
541 case cc::DrawQuad::SURFACE_CONTENT:
542 LogParam(*cc::SurfaceDrawQuad::MaterialCast(&quad), l);
543 break;
544 case cc::DrawQuad::TILED_CONTENT:
545 LogParam(*cc::TileDrawQuad::MaterialCast(&quad), l);
546 break;
547 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
548 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(&quad), l);
549 break;
550 case cc::DrawQuad::YUV_VIDEO_CONTENT:
551 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(&quad), l);
552 break;
553 case cc::DrawQuad::INVALID:
554 break;
557 l->append("])");
560 namespace {
561 enum CompositorFrameType {
562 NO_FRAME,
563 DELEGATED_FRAME,
564 GL_FRAME,
565 SOFTWARE_FRAME,
569 void ParamTraits<cc::CompositorFrame>::Write(Message* m,
570 const param_type& p) {
571 WriteParam(m, p.metadata);
572 if (p.delegated_frame_data) {
573 DCHECK(!p.gl_frame_data);
574 DCHECK(!p.software_frame_data);
575 WriteParam(m, static_cast<int>(DELEGATED_FRAME));
576 WriteParam(m, *p.delegated_frame_data);
577 } else if (p.gl_frame_data) {
578 DCHECK(!p.software_frame_data);
579 WriteParam(m, static_cast<int>(GL_FRAME));
580 WriteParam(m, *p.gl_frame_data);
581 } else if (p.software_frame_data) {
582 WriteParam(m, static_cast<int>(SOFTWARE_FRAME));
583 WriteParam(m, *p.software_frame_data);
584 } else {
585 WriteParam(m, static_cast<int>(NO_FRAME));
589 bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
590 PickleIterator* iter,
591 param_type* p) {
592 if (!ReadParam(m, iter, &p->metadata))
593 return false;
595 int compositor_frame_type;
596 if (!ReadParam(m, iter, &compositor_frame_type))
597 return false;
599 switch (compositor_frame_type) {
600 case DELEGATED_FRAME:
601 p->delegated_frame_data.reset(new cc::DelegatedFrameData());
602 if (!ReadParam(m, iter, p->delegated_frame_data.get()))
603 return false;
604 break;
605 case GL_FRAME:
606 p->gl_frame_data.reset(new cc::GLFrameData());
607 if (!ReadParam(m, iter, p->gl_frame_data.get()))
608 return false;
609 break;
610 case SOFTWARE_FRAME:
611 p->software_frame_data.reset(new cc::SoftwareFrameData());
612 if (!ReadParam(m, iter, p->software_frame_data.get()))
613 return false;
614 break;
615 case NO_FRAME:
616 break;
617 default:
618 return false;
620 return true;
623 void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
624 std::string* l) {
625 l->append("CompositorFrame(");
626 LogParam(p.metadata, l);
627 l->append(", ");
628 if (p.delegated_frame_data)
629 LogParam(*p.delegated_frame_data, l);
630 else if (p.gl_frame_data)
631 LogParam(*p.gl_frame_data, l);
632 else if (p.software_frame_data)
633 LogParam(*p.software_frame_data, l);
634 l->append(")");
637 void ParamTraits<cc::CompositorFrameAck>::Write(Message* m,
638 const param_type& p) {
639 WriteParam(m, p.resources);
640 WriteParam(m, p.last_software_frame_id);
641 if (p.gl_frame_data) {
642 WriteParam(m, static_cast<int>(GL_FRAME));
643 WriteParam(m, *p.gl_frame_data);
644 } else {
645 WriteParam(m, static_cast<int>(NO_FRAME));
649 bool ParamTraits<cc::CompositorFrameAck>::Read(const Message* m,
650 PickleIterator* iter,
651 param_type* p) {
652 if (!ReadParam(m, iter, &p->resources))
653 return false;
655 if (!ReadParam(m, iter, &p->last_software_frame_id))
656 return false;
658 int compositor_frame_type;
659 if (!ReadParam(m, iter, &compositor_frame_type))
660 return false;
662 switch (compositor_frame_type) {
663 case NO_FRAME:
664 break;
665 case GL_FRAME:
666 p->gl_frame_data.reset(new cc::GLFrameData());
667 if (!ReadParam(m, iter, p->gl_frame_data.get()))
668 return false;
669 break;
670 default:
671 return false;
673 return true;
676 void ParamTraits<cc::CompositorFrameAck>::Log(const param_type& p,
677 std::string* l) {
678 l->append("CompositorFrameAck(");
679 LogParam(p.resources, l);
680 l->append(", ");
681 LogParam(p.last_software_frame_id, l);
682 l->append(", ");
683 if (p.gl_frame_data)
684 LogParam(*p.gl_frame_data, l);
685 l->append(")");
688 void ParamTraits<cc::DelegatedFrameData>::Write(Message* m,
689 const param_type& p) {
690 DCHECK_NE(0u, p.render_pass_list.size());
692 size_t to_reserve = sizeof(p.device_scale_factor);
693 to_reserve += p.resource_list.size() * sizeof(cc::TransferableResource);
694 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
695 const cc::RenderPass* pass = p.render_pass_list[i];
696 to_reserve += sizeof(size_t) * 2;
697 to_reserve += ReserveSizeForRenderPassWrite(*pass);
699 m->Reserve(to_reserve);
701 WriteParam(m, p.device_scale_factor);
702 WriteParam(m, p.resource_list);
703 WriteParam(m, p.render_pass_list.size());
704 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
705 WriteParam(m, p.render_pass_list[i]->quad_list.size());
706 WriteParam(m, p.render_pass_list[i]->shared_quad_state_list.size());
707 WriteParam(m, *p.render_pass_list[i]);
711 bool ParamTraits<cc::DelegatedFrameData>::Read(const Message* m,
712 PickleIterator* iter,
713 param_type* p) {
714 if (!ReadParam(m, iter, &p->device_scale_factor))
715 return false;
717 const static size_t kMaxRenderPasses = 10000;
718 const static size_t kMaxSharedQuadStateListSize = 100000;
719 const static size_t kMaxQuadListSize = 1000000;
721 size_t num_render_passes;
722 if (!ReadParam(m, iter, &p->resource_list) ||
723 !ReadParam(m, iter, &num_render_passes) ||
724 num_render_passes > kMaxRenderPasses || num_render_passes == 0)
725 return false;
726 for (size_t i = 0; i < num_render_passes; ++i) {
727 size_t quad_list_size;
728 size_t shared_quad_state_list_size;
729 if (!ReadParam(m, iter, &quad_list_size) ||
730 !ReadParam(m, iter, &shared_quad_state_list_size) ||
731 quad_list_size > kMaxQuadListSize ||
732 shared_quad_state_list_size > kMaxSharedQuadStateListSize)
733 return false;
734 scoped_ptr<cc::RenderPass> render_pass =
735 cc::RenderPass::Create(shared_quad_state_list_size, quad_list_size);
736 if (!ReadParam(m, iter, render_pass.get()))
737 return false;
738 p->render_pass_list.push_back(render_pass.Pass());
740 return true;
743 void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
744 std::string* l) {
745 l->append("DelegatedFrameData(");
746 LogParam(p.device_scale_factor, l);
747 LogParam(p.resource_list, l);
748 l->append(", [");
749 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
750 if (i)
751 l->append(", ");
752 LogParam(*p.render_pass_list[i], l);
754 l->append("])");
757 void ParamTraits<cc::SoftwareFrameData>::Write(Message* m,
758 const param_type& p) {
759 DCHECK(cc::SharedBitmap::VerifySizeInBytes(p.size));
761 m->Reserve(sizeof(cc::SoftwareFrameData));
762 WriteParam(m, p.id);
763 WriteParam(m, p.size);
764 WriteParam(m, p.damage_rect);
765 WriteParam(m, p.bitmap_id);
768 bool ParamTraits<cc::SoftwareFrameData>::Read(const Message* m,
769 PickleIterator* iter,
770 param_type* p) {
771 if (!ReadParam(m, iter, &p->id))
772 return false;
773 if (!ReadParam(m, iter, &p->size) ||
774 !cc::SharedBitmap::VerifySizeInBytes(p->size))
775 return false;
776 if (!ReadParam(m, iter, &p->damage_rect))
777 return false;
778 if (!ReadParam(m, iter, &p->bitmap_id))
779 return false;
780 return true;
783 void ParamTraits<cc::SoftwareFrameData>::Log(const param_type& p,
784 std::string* l) {
785 l->append("SoftwareFrameData(");
786 LogParam(p.id, l);
787 l->append(", ");
788 LogParam(p.size, l);
789 l->append(", ");
790 LogParam(p.damage_rect, l);
791 l->append(", ");
792 LogParam(p.bitmap_id, l);
793 l->append(")");
796 } // namespace IPC