Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / common / cc_messages.cc
blobcc8dd5ff2a6fdb589c30f6125535bbf3d8604431
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/draw_quad.h"
10 #include "cc/quads/largest_draw_quad.h"
11 #include "cc/quads/render_pass_id.h"
12 #include "content/public/common/common_param_traits.h"
13 #include "third_party/skia/include/core/SkData.h"
14 #include "third_party/skia/include/core/SkFlattenableSerialization.h"
15 #include "ui/gfx/transform.h"
17 namespace IPC {
19 void ParamTraits<cc::FilterOperation>::Write(
20 Message* m, const param_type& p) {
21 WriteParam(m, p.type());
22 switch (p.type()) {
23 case cc::FilterOperation::GRAYSCALE:
24 case cc::FilterOperation::SEPIA:
25 case cc::FilterOperation::SATURATE:
26 case cc::FilterOperation::HUE_ROTATE:
27 case cc::FilterOperation::INVERT:
28 case cc::FilterOperation::BRIGHTNESS:
29 case cc::FilterOperation::SATURATING_BRIGHTNESS:
30 case cc::FilterOperation::CONTRAST:
31 case cc::FilterOperation::OPACITY:
32 case cc::FilterOperation::BLUR:
33 WriteParam(m, p.amount());
34 break;
35 case cc::FilterOperation::DROP_SHADOW:
36 WriteParam(m, p.drop_shadow_offset());
37 WriteParam(m, p.amount());
38 WriteParam(m, p.drop_shadow_color());
39 break;
40 case cc::FilterOperation::COLOR_MATRIX:
41 for (int i = 0; i < 20; ++i)
42 WriteParam(m, p.matrix()[i]);
43 break;
44 case cc::FilterOperation::ZOOM:
45 WriteParam(m, p.amount());
46 WriteParam(m, p.zoom_inset());
47 break;
48 case cc::FilterOperation::REFERENCE:
49 WriteParam(m, p.image_filter());
50 break;
51 case cc::FilterOperation::ALPHA_THRESHOLD:
52 NOTREACHED();
53 break;
57 bool ParamTraits<cc::FilterOperation>::Read(const Message* m,
58 base::PickleIterator* iter,
59 param_type* r) {
60 cc::FilterOperation::FilterType type;
61 float amount;
62 gfx::Point drop_shadow_offset;
63 SkColor drop_shadow_color;
64 SkScalar matrix[20];
65 int zoom_inset;
67 if (!ReadParam(m, iter, &type))
68 return false;
69 r->set_type(type);
71 bool success = false;
72 switch (type) {
73 case cc::FilterOperation::GRAYSCALE:
74 case cc::FilterOperation::SEPIA:
75 case cc::FilterOperation::SATURATE:
76 case cc::FilterOperation::HUE_ROTATE:
77 case cc::FilterOperation::INVERT:
78 case cc::FilterOperation::BRIGHTNESS:
79 case cc::FilterOperation::SATURATING_BRIGHTNESS:
80 case cc::FilterOperation::CONTRAST:
81 case cc::FilterOperation::OPACITY:
82 case cc::FilterOperation::BLUR:
83 if (ReadParam(m, iter, &amount)) {
84 r->set_amount(amount);
85 success = true;
87 break;
88 case cc::FilterOperation::DROP_SHADOW:
89 if (ReadParam(m, iter, &drop_shadow_offset) &&
90 ReadParam(m, iter, &amount) &&
91 ReadParam(m, iter, &drop_shadow_color)) {
92 r->set_drop_shadow_offset(drop_shadow_offset);
93 r->set_amount(amount);
94 r->set_drop_shadow_color(drop_shadow_color);
95 success = true;
97 break;
98 case cc::FilterOperation::COLOR_MATRIX: {
99 int i;
100 for (i = 0; i < 20; ++i) {
101 if (!ReadParam(m, iter, &matrix[i]))
102 break;
104 if (i == 20) {
105 r->set_matrix(matrix);
106 success = true;
108 break;
110 case cc::FilterOperation::ZOOM:
111 if (ReadParam(m, iter, &amount) &&
112 ReadParam(m, iter, &zoom_inset) &&
113 amount >= 0.f &&
114 zoom_inset >= 0) {
115 r->set_amount(amount);
116 r->set_zoom_inset(zoom_inset);
117 success = true;
119 break;
120 case cc::FilterOperation::REFERENCE: {
121 skia::RefPtr<SkImageFilter> filter;
122 if (!ReadParam(m, iter, &filter)) {
123 success = false;
124 break;
126 r->set_image_filter(filter);
127 success = true;
128 break;
130 case cc::FilterOperation::ALPHA_THRESHOLD:
131 break;
133 return success;
136 void ParamTraits<cc::FilterOperation>::Log(
137 const param_type& p, std::string* l) {
138 l->append("(");
139 LogParam(static_cast<unsigned>(p.type()), l);
140 l->append(", ");
142 switch (p.type()) {
143 case cc::FilterOperation::GRAYSCALE:
144 case cc::FilterOperation::SEPIA:
145 case cc::FilterOperation::SATURATE:
146 case cc::FilterOperation::HUE_ROTATE:
147 case cc::FilterOperation::INVERT:
148 case cc::FilterOperation::BRIGHTNESS:
149 case cc::FilterOperation::SATURATING_BRIGHTNESS:
150 case cc::FilterOperation::CONTRAST:
151 case cc::FilterOperation::OPACITY:
152 case cc::FilterOperation::BLUR:
153 LogParam(p.amount(), l);
154 break;
155 case cc::FilterOperation::DROP_SHADOW:
156 LogParam(p.drop_shadow_offset(), l);
157 l->append(", ");
158 LogParam(p.amount(), l);
159 l->append(", ");
160 LogParam(p.drop_shadow_color(), l);
161 break;
162 case cc::FilterOperation::COLOR_MATRIX:
163 for (int i = 0; i < 20; ++i) {
164 if (i)
165 l->append(", ");
166 LogParam(p.matrix()[i], l);
168 break;
169 case cc::FilterOperation::ZOOM:
170 LogParam(p.amount(), l);
171 l->append(", ");
172 LogParam(p.zoom_inset(), l);
173 break;
174 case cc::FilterOperation::REFERENCE:
175 LogParam(p.image_filter(), l);
176 break;
177 case cc::FilterOperation::ALPHA_THRESHOLD:
178 NOTREACHED();
179 break;
181 l->append(")");
184 void ParamTraits<cc::FilterOperations>::Write(
185 Message* m, const param_type& p) {
186 WriteParam(m, p.size());
187 for (std::size_t i = 0; i < p.size(); ++i) {
188 WriteParam(m, p.at(i));
192 bool ParamTraits<cc::FilterOperations>::Read(const Message* m,
193 base::PickleIterator* iter,
194 param_type* r) {
195 size_t count;
196 if (!ReadParam(m, iter, &count))
197 return false;
199 for (std::size_t i = 0; i < count; ++i) {
200 cc::FilterOperation op = cc::FilterOperation::CreateEmptyFilter();
201 if (!ReadParam(m, iter, &op))
202 return false;
203 r->Append(op);
205 return true;
208 void ParamTraits<cc::FilterOperations>::Log(
209 const param_type& p, std::string* l) {
210 l->append("(");
211 for (std::size_t i = 0; i < p.size(); ++i) {
212 if (i)
213 l->append(", ");
214 LogParam(p.at(i), l);
216 l->append(")");
219 void ParamTraits<skia::RefPtr<SkImageFilter> >::Write(
220 Message* m, const param_type& p) {
221 SkImageFilter* filter = p.get();
222 if (filter) {
223 skia::RefPtr<SkData> data =
224 skia::AdoptRef(SkValidatingSerializeFlattenable(filter));
225 m->WriteData(static_cast<const char*>(data->data()), data->size());
226 } else {
227 m->WriteData(0, 0);
231 bool ParamTraits<skia::RefPtr<SkImageFilter>>::Read(const Message* m,
232 base::PickleIterator* iter,
233 param_type* r) {
234 const char* data = 0;
235 int length = 0;
236 if (!iter->ReadData(&data, &length))
237 return false;
238 if (length > 0) {
239 SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
240 data, length, SkImageFilter::GetFlattenableType());
241 *r = skia::AdoptRef(static_cast<SkImageFilter*>(flattenable));
242 } else {
243 r->clear();
245 return true;
248 void ParamTraits<skia::RefPtr<SkImageFilter> >::Log(
249 const param_type& p, std::string* l) {
250 l->append("(");
251 LogParam(p.get() ? p->countInputs() : 0, l);
252 l->append(")");
255 void ParamTraits<gfx::Transform>::Write(
256 Message* m, const param_type& p) {
257 #ifdef SK_MSCALAR_IS_FLOAT
258 float column_major_data[16];
259 p.matrix().asColMajorf(column_major_data);
260 #else
261 double column_major_data[16];
262 p.matrix().asColMajord(column_major_data);
263 #endif
264 m->WriteBytes(&column_major_data, sizeof(SkMScalar) * 16);
267 bool ParamTraits<gfx::Transform>::Read(const Message* m,
268 base::PickleIterator* iter,
269 param_type* r) {
270 const char* column_major_data;
271 if (!iter->ReadBytes(&column_major_data, sizeof(SkMScalar) * 16))
272 return false;
273 r->matrix().setColMajor(
274 reinterpret_cast<const SkMScalar*>(column_major_data));
275 return true;
278 void ParamTraits<gfx::Transform>::Log(
279 const param_type& p, std::string* l) {
280 #ifdef SK_MSCALAR_IS_FLOAT
281 float row_major_data[16];
282 p.matrix().asRowMajorf(row_major_data);
283 #else
284 double row_major_data[16];
285 p.matrix().asRowMajord(row_major_data);
286 #endif
287 l->append("(");
288 for (int i = 0; i < 16; ++i) {
289 if (i > 0)
290 l->append(", ");
291 LogParam(row_major_data[i], l);
293 l->append(") ");
296 void ParamTraits<cc::RenderPass>::Write(
297 Message* m, const param_type& p) {
298 WriteParam(m, p.id);
299 WriteParam(m, p.output_rect);
300 WriteParam(m, p.damage_rect);
301 WriteParam(m, p.transform_to_root_target);
302 WriteParam(m, p.has_transparent_background);
303 WriteParam(m, p.quad_list.size());
305 cc::SharedQuadStateList::ConstIterator shared_quad_state_iter =
306 p.shared_quad_state_list.begin();
307 cc::SharedQuadStateList::ConstIterator last_shared_quad_state_iter =
308 p.shared_quad_state_list.end();
309 for (const auto& quad : p.quad_list) {
310 DCHECK(quad->rect.Contains(quad->visible_rect))
311 << quad->material << " rect: " << quad->rect.ToString()
312 << " visible_rect: " << quad->visible_rect.ToString();
313 DCHECK(quad->opaque_rect.IsEmpty() ||
314 quad->rect.Contains(quad->opaque_rect))
315 << quad->material << " rect: " << quad->rect.ToString()
316 << " opaque_rect: " << quad->opaque_rect.ToString();
318 switch (quad->material) {
319 case cc::DrawQuad::CHECKERBOARD:
320 WriteParam(m, *cc::CheckerboardDrawQuad::MaterialCast(quad));
321 break;
322 case cc::DrawQuad::DEBUG_BORDER:
323 WriteParam(m, *cc::DebugBorderDrawQuad::MaterialCast(quad));
324 break;
325 case cc::DrawQuad::IO_SURFACE_CONTENT:
326 WriteParam(m, *cc::IOSurfaceDrawQuad::MaterialCast(quad));
327 break;
328 case cc::DrawQuad::PICTURE_CONTENT:
329 NOTREACHED();
330 break;
331 case cc::DrawQuad::TEXTURE_CONTENT:
332 WriteParam(m, *cc::TextureDrawQuad::MaterialCast(quad));
333 break;
334 case cc::DrawQuad::RENDER_PASS:
335 WriteParam(m, *cc::RenderPassDrawQuad::MaterialCast(quad));
336 break;
337 case cc::DrawQuad::SOLID_COLOR:
338 WriteParam(m, *cc::SolidColorDrawQuad::MaterialCast(quad));
339 break;
340 case cc::DrawQuad::SURFACE_CONTENT:
341 WriteParam(m, *cc::SurfaceDrawQuad::MaterialCast(quad));
342 break;
343 case cc::DrawQuad::TILED_CONTENT:
344 WriteParam(m, *cc::TileDrawQuad::MaterialCast(quad));
345 break;
346 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
347 WriteParam(m, *cc::StreamVideoDrawQuad::MaterialCast(quad));
348 break;
349 case cc::DrawQuad::YUV_VIDEO_CONTENT:
350 WriteParam(m, *cc::YUVVideoDrawQuad::MaterialCast(quad));
351 break;
352 case cc::DrawQuad::INVALID:
353 break;
356 // Null shared quad states should not occur.
357 DCHECK(quad->shared_quad_state);
359 // SharedQuadStates should appear in the order they are used by DrawQuads.
360 // Find the SharedQuadState for this DrawQuad.
361 while (shared_quad_state_iter != p.shared_quad_state_list.end() &&
362 quad->shared_quad_state != *shared_quad_state_iter)
363 ++shared_quad_state_iter;
365 DCHECK(shared_quad_state_iter != p.shared_quad_state_list.end());
367 if (shared_quad_state_iter != last_shared_quad_state_iter) {
368 WriteParam(m, true);
369 WriteParam(m, **shared_quad_state_iter);
370 last_shared_quad_state_iter = shared_quad_state_iter;
371 } else {
372 WriteParam(m, false);
377 static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
378 size_t to_reserve = sizeof(cc::RenderPass);
380 // Whether the quad points to a new shared quad state for each quad.
381 to_reserve += p.quad_list.size() * sizeof(bool);
383 // Shared quad state is only written when a quad contains a shared quad state
384 // that has not been written.
385 to_reserve += p.shared_quad_state_list.size() * sizeof(cc::SharedQuadState);
387 // The largest quad type, verified by a unit test.
388 to_reserve += p.quad_list.size() * cc::LargestDrawQuadSize();
389 return to_reserve;
392 template <typename QuadType>
393 static cc::DrawQuad* ReadDrawQuad(const Message* m,
394 base::PickleIterator* iter,
395 cc::RenderPass* render_pass) {
396 QuadType* quad = render_pass->CreateAndAppendDrawQuad<QuadType>();
397 if (!ReadParam(m, iter, quad))
398 return NULL;
399 return quad;
402 bool ParamTraits<cc::RenderPass>::Read(const Message* m,
403 base::PickleIterator* iter,
404 param_type* p) {
405 cc::RenderPassId id;
406 gfx::Rect output_rect;
407 gfx::Rect damage_rect;
408 gfx::Transform transform_to_root_target;
409 bool has_transparent_background;
410 size_t quad_list_size;
412 if (!ReadParam(m, iter, &id) ||
413 !ReadParam(m, iter, &output_rect) ||
414 !ReadParam(m, iter, &damage_rect) ||
415 !ReadParam(m, iter, &transform_to_root_target) ||
416 !ReadParam(m, iter, &has_transparent_background) ||
417 !ReadParam(m, iter, &quad_list_size))
418 return false;
420 p->SetAll(id,
421 output_rect,
422 damage_rect,
423 transform_to_root_target,
424 has_transparent_background);
426 for (size_t i = 0; i < quad_list_size; ++i) {
427 cc::DrawQuad::Material material;
428 base::PickleIterator temp_iter = *iter;
429 if (!ReadParam(m, &temp_iter, &material))
430 return false;
432 cc::DrawQuad* draw_quad = NULL;
433 switch (material) {
434 case cc::DrawQuad::CHECKERBOARD:
435 draw_quad = ReadDrawQuad<cc::CheckerboardDrawQuad>(m, iter, p);
436 break;
437 case cc::DrawQuad::DEBUG_BORDER:
438 draw_quad = ReadDrawQuad<cc::DebugBorderDrawQuad>(m, iter, p);
439 break;
440 case cc::DrawQuad::IO_SURFACE_CONTENT:
441 draw_quad = ReadDrawQuad<cc::IOSurfaceDrawQuad>(m, iter, p);
442 break;
443 case cc::DrawQuad::PICTURE_CONTENT:
444 NOTREACHED();
445 return false;
446 case cc::DrawQuad::SURFACE_CONTENT:
447 draw_quad = ReadDrawQuad<cc::SurfaceDrawQuad>(m, iter, p);
448 break;
449 case cc::DrawQuad::TEXTURE_CONTENT:
450 draw_quad = ReadDrawQuad<cc::TextureDrawQuad>(m, iter, p);
451 break;
452 case cc::DrawQuad::RENDER_PASS:
453 draw_quad = ReadDrawQuad<cc::RenderPassDrawQuad>(m, iter, p);
454 break;
455 case cc::DrawQuad::SOLID_COLOR:
456 draw_quad = ReadDrawQuad<cc::SolidColorDrawQuad>(m, iter, p);
457 break;
458 case cc::DrawQuad::TILED_CONTENT:
459 draw_quad = ReadDrawQuad<cc::TileDrawQuad>(m, iter, p);
460 break;
461 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
462 draw_quad = ReadDrawQuad<cc::StreamVideoDrawQuad>(m, iter, p);
463 break;
464 case cc::DrawQuad::YUV_VIDEO_CONTENT:
465 draw_quad = ReadDrawQuad<cc::YUVVideoDrawQuad>(m, iter, p);
466 break;
467 case cc::DrawQuad::INVALID:
468 break;
470 if (!draw_quad)
471 return false;
472 if (!draw_quad->rect.Contains(draw_quad->visible_rect)) {
473 LOG(ERROR) << "Quad with invalid visible rect " << draw_quad->material
474 << " rect: " << draw_quad->rect.ToString()
475 << " visible_rect: " << draw_quad->visible_rect.ToString();
476 return false;
478 if (!draw_quad->opaque_rect.IsEmpty() &&
479 !draw_quad->rect.Contains(draw_quad->opaque_rect)) {
480 LOG(ERROR) << "Quad with invalid opaque rect " << draw_quad->material
481 << " rect: " << draw_quad->rect.ToString()
482 << " opaque_rect: " << draw_quad->opaque_rect.ToString();
483 return false;
486 bool has_new_shared_quad_state;
487 if (!ReadParam(m, iter, &has_new_shared_quad_state))
488 return false;
490 // If the quad has a new shared quad state, read it in.
491 if (has_new_shared_quad_state) {
492 cc::SharedQuadState* state = p->CreateAndAppendSharedQuadState();
493 if (!ReadParam(m, iter, state))
494 return false;
497 draw_quad->shared_quad_state = p->shared_quad_state_list.back();
500 return true;
503 void ParamTraits<cc::RenderPass>::Log(
504 const param_type& p, std::string* l) {
505 l->append("RenderPass((");
506 LogParam(p.id, l);
507 l->append("), ");
508 LogParam(p.output_rect, l);
509 l->append(", ");
510 LogParam(p.damage_rect, l);
511 l->append(", ");
512 LogParam(p.transform_to_root_target, l);
513 l->append(", ");
514 LogParam(p.has_transparent_background, l);
515 l->append(", ");
517 l->append("[");
518 for (const auto& shared_quad_state : p.shared_quad_state_list) {
519 if (shared_quad_state != p.shared_quad_state_list.front())
520 l->append(", ");
521 LogParam(*shared_quad_state, l);
523 l->append("], [");
524 for (const auto& quad : p.quad_list) {
525 if (quad != p.quad_list.front())
526 l->append(", ");
527 switch (quad->material) {
528 case cc::DrawQuad::CHECKERBOARD:
529 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(quad), l);
530 break;
531 case cc::DrawQuad::DEBUG_BORDER:
532 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad), l);
533 break;
534 case cc::DrawQuad::IO_SURFACE_CONTENT:
535 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad), l);
536 break;
537 case cc::DrawQuad::PICTURE_CONTENT:
538 NOTREACHED();
539 break;
540 case cc::DrawQuad::TEXTURE_CONTENT:
541 LogParam(*cc::TextureDrawQuad::MaterialCast(quad), l);
542 break;
543 case cc::DrawQuad::RENDER_PASS:
544 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad), l);
545 break;
546 case cc::DrawQuad::SOLID_COLOR:
547 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad), l);
548 break;
549 case cc::DrawQuad::SURFACE_CONTENT:
550 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad), l);
551 break;
552 case cc::DrawQuad::TILED_CONTENT:
553 LogParam(*cc::TileDrawQuad::MaterialCast(quad), l);
554 break;
555 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
556 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad), l);
557 break;
558 case cc::DrawQuad::YUV_VIDEO_CONTENT:
559 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad), l);
560 break;
561 case cc::DrawQuad::INVALID:
562 break;
565 l->append("])");
568 namespace {
569 enum CompositorFrameType {
570 NO_FRAME,
571 DELEGATED_FRAME,
572 GL_FRAME,
573 SOFTWARE_FRAME,
577 void ParamTraits<cc::CompositorFrame>::Write(Message* m,
578 const param_type& p) {
579 WriteParam(m, p.metadata);
580 if (p.delegated_frame_data) {
581 DCHECK(!p.gl_frame_data);
582 DCHECK(!p.software_frame_data);
583 WriteParam(m, static_cast<int>(DELEGATED_FRAME));
584 WriteParam(m, *p.delegated_frame_data);
585 } else if (p.gl_frame_data) {
586 DCHECK(!p.software_frame_data);
587 WriteParam(m, static_cast<int>(GL_FRAME));
588 WriteParam(m, *p.gl_frame_data);
589 } else if (p.software_frame_data) {
590 WriteParam(m, static_cast<int>(SOFTWARE_FRAME));
591 WriteParam(m, *p.software_frame_data);
592 } else {
593 WriteParam(m, static_cast<int>(NO_FRAME));
597 bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
598 base::PickleIterator* iter,
599 param_type* p) {
600 if (!ReadParam(m, iter, &p->metadata))
601 return false;
603 int compositor_frame_type;
604 if (!ReadParam(m, iter, &compositor_frame_type))
605 return false;
607 switch (compositor_frame_type) {
608 case DELEGATED_FRAME:
609 p->delegated_frame_data.reset(new cc::DelegatedFrameData());
610 if (!ReadParam(m, iter, p->delegated_frame_data.get()))
611 return false;
612 break;
613 case GL_FRAME:
614 p->gl_frame_data.reset(new cc::GLFrameData());
615 if (!ReadParam(m, iter, p->gl_frame_data.get()))
616 return false;
617 break;
618 case SOFTWARE_FRAME:
619 p->software_frame_data.reset(new cc::SoftwareFrameData());
620 if (!ReadParam(m, iter, p->software_frame_data.get()))
621 return false;
622 break;
623 case NO_FRAME:
624 break;
625 default:
626 return false;
628 return true;
631 void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
632 std::string* l) {
633 l->append("CompositorFrame(");
634 LogParam(p.metadata, l);
635 l->append(", ");
636 if (p.delegated_frame_data)
637 LogParam(*p.delegated_frame_data, l);
638 else if (p.gl_frame_data)
639 LogParam(*p.gl_frame_data, l);
640 else if (p.software_frame_data)
641 LogParam(*p.software_frame_data, l);
642 l->append(")");
645 void ParamTraits<cc::CompositorFrameAck>::Write(Message* m,
646 const param_type& p) {
647 WriteParam(m, p.resources);
648 WriteParam(m, p.last_software_frame_id);
649 if (p.gl_frame_data) {
650 WriteParam(m, static_cast<int>(GL_FRAME));
651 WriteParam(m, *p.gl_frame_data);
652 } else {
653 WriteParam(m, static_cast<int>(NO_FRAME));
657 bool ParamTraits<cc::CompositorFrameAck>::Read(const Message* m,
658 base::PickleIterator* iter,
659 param_type* p) {
660 if (!ReadParam(m, iter, &p->resources))
661 return false;
663 if (!ReadParam(m, iter, &p->last_software_frame_id))
664 return false;
666 int compositor_frame_type;
667 if (!ReadParam(m, iter, &compositor_frame_type))
668 return false;
670 switch (compositor_frame_type) {
671 case NO_FRAME:
672 break;
673 case GL_FRAME:
674 p->gl_frame_data.reset(new cc::GLFrameData());
675 if (!ReadParam(m, iter, p->gl_frame_data.get()))
676 return false;
677 break;
678 default:
679 return false;
681 return true;
684 void ParamTraits<cc::CompositorFrameAck>::Log(const param_type& p,
685 std::string* l) {
686 l->append("CompositorFrameAck(");
687 LogParam(p.resources, l);
688 l->append(", ");
689 LogParam(p.last_software_frame_id, l);
690 l->append(", ");
691 if (p.gl_frame_data)
692 LogParam(*p.gl_frame_data, l);
693 l->append(")");
696 void ParamTraits<cc::DelegatedFrameData>::Write(Message* m,
697 const param_type& p) {
698 DCHECK_NE(0u, p.render_pass_list.size());
700 size_t to_reserve = sizeof(p.device_scale_factor);
701 to_reserve += p.resource_list.size() * sizeof(cc::TransferableResource);
702 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
703 const cc::RenderPass* pass = p.render_pass_list[i];
704 to_reserve += sizeof(size_t) * 2;
705 to_reserve += ReserveSizeForRenderPassWrite(*pass);
707 m->Reserve(to_reserve);
709 WriteParam(m, p.device_scale_factor);
710 WriteParam(m, p.resource_list);
711 WriteParam(m, p.render_pass_list.size());
712 for (const auto* pass : p.render_pass_list) {
713 WriteParam(m, pass->quad_list.size());
714 WriteParam(m, pass->shared_quad_state_list.size());
715 WriteParam(m, *pass);
719 bool ParamTraits<cc::DelegatedFrameData>::Read(const Message* m,
720 base::PickleIterator* iter,
721 param_type* p) {
722 if (!ReadParam(m, iter, &p->device_scale_factor))
723 return false;
725 const static size_t kMaxRenderPasses = 10000;
726 const static size_t kMaxSharedQuadStateListSize = 100000;
727 const static size_t kMaxQuadListSize = 1000000;
729 std::set<cc::RenderPassId> pass_set;
731 size_t num_render_passes;
732 if (!ReadParam(m, iter, &p->resource_list) ||
733 !ReadParam(m, iter, &num_render_passes) ||
734 num_render_passes > kMaxRenderPasses || num_render_passes == 0)
735 return false;
736 for (size_t i = 0; i < num_render_passes; ++i) {
737 size_t quad_list_size;
738 size_t shared_quad_state_list_size;
739 if (!ReadParam(m, iter, &quad_list_size) ||
740 !ReadParam(m, iter, &shared_quad_state_list_size) ||
741 quad_list_size > kMaxQuadListSize ||
742 shared_quad_state_list_size > kMaxSharedQuadStateListSize)
743 return false;
744 scoped_ptr<cc::RenderPass> render_pass =
745 cc::RenderPass::Create(shared_quad_state_list_size, quad_list_size);
746 if (!ReadParam(m, iter, render_pass.get()))
747 return false;
748 // Validate that each RenderPassDrawQuad points at a valid RenderPass
749 // earlier in the frame.
750 for (const auto* quad : render_pass->quad_list) {
751 if (quad->material != cc::DrawQuad::RENDER_PASS)
752 continue;
753 const cc::RenderPassDrawQuad* rpdq =
754 cc::RenderPassDrawQuad::MaterialCast(quad);
755 if (!pass_set.count(rpdq->render_pass_id))
756 return false;
758 pass_set.insert(render_pass->id);
759 p->render_pass_list.push_back(render_pass.Pass());
761 return true;
764 void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
765 std::string* l) {
766 l->append("DelegatedFrameData(");
767 LogParam(p.device_scale_factor, l);
768 LogParam(p.resource_list, l);
769 l->append(", [");
770 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
771 if (i)
772 l->append(", ");
773 LogParam(*p.render_pass_list[i], l);
775 l->append("])");
778 void ParamTraits<cc::SoftwareFrameData>::Write(Message* m,
779 const param_type& p) {
780 DCHECK(cc::SharedBitmap::VerifySizeInBytes(p.size));
782 m->Reserve(sizeof(cc::SoftwareFrameData));
783 WriteParam(m, p.id);
784 WriteParam(m, p.size);
785 WriteParam(m, p.damage_rect);
786 WriteParam(m, p.bitmap_id);
789 bool ParamTraits<cc::SoftwareFrameData>::Read(const Message* m,
790 base::PickleIterator* iter,
791 param_type* p) {
792 if (!ReadParam(m, iter, &p->id))
793 return false;
794 if (!ReadParam(m, iter, &p->size) ||
795 !cc::SharedBitmap::VerifySizeInBytes(p->size))
796 return false;
797 if (!ReadParam(m, iter, &p->damage_rect))
798 return false;
799 if (!ReadParam(m, iter, &p->bitmap_id))
800 return false;
801 return true;
804 void ParamTraits<cc::SoftwareFrameData>::Log(const param_type& p,
805 std::string* l) {
806 l->append("SoftwareFrameData(");
807 LogParam(p.id, l);
808 l->append(", ");
809 LogParam(p.size, l);
810 l->append(", ");
811 LogParam(p.damage_rect, l);
812 l->append(", ");
813 LogParam(p.bitmap_id, l);
814 l->append(")");
817 void ParamTraits<cc::DrawQuad::Resources>::Write(Message* m,
818 const param_type& p) {
819 DCHECK_LE(p.count, cc::DrawQuad::Resources::kMaxResourceIdCount);
820 WriteParam(m, p.count);
821 for (size_t i = 0; i < p.count; ++i)
822 WriteParam(m, p.ids[i]);
825 bool ParamTraits<cc::DrawQuad::Resources>::Read(const Message* m,
826 base::PickleIterator* iter,
827 param_type* p) {
828 if (!ReadParam(m, iter, &p->count))
829 return false;
830 if (p->count > cc::DrawQuad::Resources::kMaxResourceIdCount)
831 return false;
832 for (size_t i = 0; i < p->count; ++i) {
833 if (!ReadParam(m, iter, &p->ids[i]))
834 return false;
836 return true;
839 void ParamTraits<cc::DrawQuad::Resources>::Log(const param_type& p,
840 std::string* l) {
841 l->append("DrawQuad::Resources(");
842 LogParam(p.count, l);
843 l->append(", [");
844 if (p.count > cc::DrawQuad::Resources::kMaxResourceIdCount) {
845 l->append("])");
846 return;
849 for (size_t i = 0; i < p.count; ++i) {
850 LogParam(p.ids[i], l);
851 if (i < (p.count - 1))
852 l->append(", ");
854 l->append("])");
857 void ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Write(
858 Message* m,
859 const param_type& p) {
860 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
861 WriteParam(m, p.size_in_pixels[i]);
862 WriteParam(m, p.allow_overlay[i]);
866 bool ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Read(
867 const Message* m,
868 base::PickleIterator* iter,
869 param_type* p) {
870 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
871 if (!ReadParam(m, iter, &p->size_in_pixels[i]))
872 return false;
873 if (!ReadParam(m, iter, &p->allow_overlay[i]))
874 return false;
876 return true;
879 void ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Log(
880 const param_type& p,
881 std::string* l) {
882 l->append("StreamVideoDrawQuad::OverlayResources([");
883 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
884 LogParam(p.size_in_pixels[i], l);
885 l->append(", ");
886 LogParam(p.allow_overlay[i], l);
887 if (i < (cc::DrawQuad::Resources::kMaxResourceIdCount - 1))
888 l->append(", ");
890 l->append("])");
893 void ParamTraits<cc::TextureDrawQuad::OverlayResources>::Write(
894 Message* m,
895 const param_type& p) {
896 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
897 WriteParam(m, p.size_in_pixels[i]);
898 WriteParam(m, p.allow_overlay[i]);
902 bool ParamTraits<cc::TextureDrawQuad::OverlayResources>::Read(
903 const Message* m,
904 base::PickleIterator* iter,
905 param_type* p) {
906 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
907 if (!ReadParam(m, iter, &p->size_in_pixels[i]))
908 return false;
909 if (!ReadParam(m, iter, &p->allow_overlay[i]))
910 return false;
912 return true;
915 void ParamTraits<cc::TextureDrawQuad::OverlayResources>::Log(
916 const param_type& p,
917 std::string* l) {
918 l->append("TextureDrawQuad::OverlayResources([");
919 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
920 LogParam(p.size_in_pixels[i], l);
921 l->append(", ");
922 LogParam(p.allow_overlay[i], l);
923 if (i < (cc::DrawQuad::Resources::kMaxResourceIdCount - 1))
924 l->append(", ");
926 l->append("])");
929 } // namespace IPC