base/threading: remove ScopedTracker placed for experiments
[chromium-blink-merge.git] / content / common / cc_messages.cc
blob1c1b5e003706c1e38ba39707003a2b852ecdaf4c
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.referenced_surfaces);
304 WriteParam(m, p.quad_list.size());
306 cc::SharedQuadStateList::ConstIterator shared_quad_state_iter =
307 p.shared_quad_state_list.begin();
308 cc::SharedQuadStateList::ConstIterator last_shared_quad_state_iter =
309 p.shared_quad_state_list.end();
310 for (const auto& quad : p.quad_list) {
311 DCHECK(quad->rect.Contains(quad->visible_rect))
312 << quad->material << " rect: " << quad->rect.ToString()
313 << " visible_rect: " << quad->visible_rect.ToString();
314 DCHECK(quad->opaque_rect.IsEmpty() ||
315 quad->rect.Contains(quad->opaque_rect))
316 << quad->material << " rect: " << quad->rect.ToString()
317 << " opaque_rect: " << quad->opaque_rect.ToString();
319 switch (quad->material) {
320 case cc::DrawQuad::DEBUG_BORDER:
321 WriteParam(m, *cc::DebugBorderDrawQuad::MaterialCast(quad));
322 break;
323 case cc::DrawQuad::IO_SURFACE_CONTENT:
324 WriteParam(m, *cc::IOSurfaceDrawQuad::MaterialCast(quad));
325 break;
326 case cc::DrawQuad::PICTURE_CONTENT:
327 NOTREACHED();
328 break;
329 case cc::DrawQuad::TEXTURE_CONTENT:
330 WriteParam(m, *cc::TextureDrawQuad::MaterialCast(quad));
331 break;
332 case cc::DrawQuad::RENDER_PASS:
333 WriteParam(m, *cc::RenderPassDrawQuad::MaterialCast(quad));
334 break;
335 case cc::DrawQuad::SOLID_COLOR:
336 WriteParam(m, *cc::SolidColorDrawQuad::MaterialCast(quad));
337 break;
338 case cc::DrawQuad::SURFACE_CONTENT:
339 WriteParam(m, *cc::SurfaceDrawQuad::MaterialCast(quad));
340 break;
341 case cc::DrawQuad::TILED_CONTENT:
342 WriteParam(m, *cc::TileDrawQuad::MaterialCast(quad));
343 break;
344 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
345 WriteParam(m, *cc::StreamVideoDrawQuad::MaterialCast(quad));
346 break;
347 case cc::DrawQuad::YUV_VIDEO_CONTENT:
348 WriteParam(m, *cc::YUVVideoDrawQuad::MaterialCast(quad));
349 break;
350 case cc::DrawQuad::INVALID:
351 break;
354 // Null shared quad states should not occur.
355 DCHECK(quad->shared_quad_state);
357 // SharedQuadStates should appear in the order they are used by DrawQuads.
358 // Find the SharedQuadState for this DrawQuad.
359 while (shared_quad_state_iter != p.shared_quad_state_list.end() &&
360 quad->shared_quad_state != *shared_quad_state_iter)
361 ++shared_quad_state_iter;
363 DCHECK(shared_quad_state_iter != p.shared_quad_state_list.end());
365 if (shared_quad_state_iter != last_shared_quad_state_iter) {
366 WriteParam(m, true);
367 WriteParam(m, **shared_quad_state_iter);
368 last_shared_quad_state_iter = shared_quad_state_iter;
369 } else {
370 WriteParam(m, false);
375 static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
376 size_t to_reserve = sizeof(cc::RenderPass);
378 // Whether the quad points to a new shared quad state for each quad.
379 to_reserve += p.quad_list.size() * sizeof(bool);
381 // Shared quad state is only written when a quad contains a shared quad state
382 // that has not been written.
383 to_reserve += p.shared_quad_state_list.size() * sizeof(cc::SharedQuadState);
385 // The largest quad type, verified by a unit test.
386 to_reserve += p.quad_list.size() * cc::LargestDrawQuadSize();
388 // The actual list of referenced surfaces.
389 to_reserve += p.referenced_surfaces.size() * sizeof(cc::SurfaceId);
390 return to_reserve;
393 template <typename QuadType>
394 static cc::DrawQuad* ReadDrawQuad(const Message* m,
395 base::PickleIterator* iter,
396 cc::RenderPass* render_pass) {
397 QuadType* quad = render_pass->CreateAndAppendDrawQuad<QuadType>();
398 if (!ReadParam(m, iter, quad))
399 return NULL;
400 return quad;
403 bool ParamTraits<cc::RenderPass>::Read(const Message* m,
404 base::PickleIterator* iter,
405 param_type* p) {
406 cc::RenderPassId id;
407 gfx::Rect output_rect;
408 gfx::Rect damage_rect;
409 gfx::Transform transform_to_root_target;
410 bool has_transparent_background;
411 std::vector<cc::SurfaceId> referenced_surfaces;
412 size_t quad_list_size;
414 if (!ReadParam(m, iter, &id) || !ReadParam(m, iter, &output_rect) ||
415 !ReadParam(m, iter, &damage_rect) ||
416 !ReadParam(m, iter, &transform_to_root_target) ||
417 !ReadParam(m, iter, &has_transparent_background) ||
418 !ReadParam(m, iter, &referenced_surfaces) ||
419 !ReadParam(m, iter, &quad_list_size))
420 return false;
422 p->SetAll(id,
423 output_rect,
424 damage_rect,
425 transform_to_root_target,
426 has_transparent_background);
427 p->referenced_surfaces.swap(referenced_surfaces);
429 for (size_t i = 0; i < quad_list_size; ++i) {
430 cc::DrawQuad::Material material;
431 base::PickleIterator temp_iter = *iter;
432 if (!ReadParam(m, &temp_iter, &material))
433 return false;
435 cc::DrawQuad* draw_quad = NULL;
436 switch (material) {
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(", ");
516 LogParam(p.referenced_surfaces, l);
517 l->append(", ");
519 l->append("[");
520 for (const auto& shared_quad_state : p.shared_quad_state_list) {
521 if (shared_quad_state != p.shared_quad_state_list.front())
522 l->append(", ");
523 LogParam(*shared_quad_state, l);
525 l->append("], [");
526 for (const auto& quad : p.quad_list) {
527 if (quad != p.quad_list.front())
528 l->append(", ");
529 switch (quad->material) {
530 case cc::DrawQuad::DEBUG_BORDER:
531 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad), l);
532 break;
533 case cc::DrawQuad::IO_SURFACE_CONTENT:
534 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad), l);
535 break;
536 case cc::DrawQuad::PICTURE_CONTENT:
537 NOTREACHED();
538 break;
539 case cc::DrawQuad::TEXTURE_CONTENT:
540 LogParam(*cc::TextureDrawQuad::MaterialCast(quad), l);
541 break;
542 case cc::DrawQuad::RENDER_PASS:
543 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad), l);
544 break;
545 case cc::DrawQuad::SOLID_COLOR:
546 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad), l);
547 break;
548 case cc::DrawQuad::SURFACE_CONTENT:
549 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad), l);
550 break;
551 case cc::DrawQuad::TILED_CONTENT:
552 LogParam(*cc::TileDrawQuad::MaterialCast(quad), l);
553 break;
554 case cc::DrawQuad::STREAM_VIDEO_CONTENT:
555 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad), l);
556 break;
557 case cc::DrawQuad::YUV_VIDEO_CONTENT:
558 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad), l);
559 break;
560 case cc::DrawQuad::INVALID:
561 break;
564 l->append("])");
567 namespace {
568 enum CompositorFrameType {
569 NO_FRAME,
570 DELEGATED_FRAME,
571 GL_FRAME,
572 SOFTWARE_FRAME,
576 void ParamTraits<cc::CompositorFrame>::Write(Message* m,
577 const param_type& p) {
578 WriteParam(m, p.metadata);
579 if (p.delegated_frame_data) {
580 DCHECK(!p.gl_frame_data);
581 DCHECK(!p.software_frame_data);
582 WriteParam(m, static_cast<int>(DELEGATED_FRAME));
583 WriteParam(m, *p.delegated_frame_data);
584 } else if (p.gl_frame_data) {
585 DCHECK(!p.software_frame_data);
586 WriteParam(m, static_cast<int>(GL_FRAME));
587 WriteParam(m, *p.gl_frame_data);
588 } else if (p.software_frame_data) {
589 WriteParam(m, static_cast<int>(SOFTWARE_FRAME));
590 WriteParam(m, *p.software_frame_data);
591 } else {
592 WriteParam(m, static_cast<int>(NO_FRAME));
596 bool ParamTraits<cc::CompositorFrame>::Read(const Message* m,
597 base::PickleIterator* iter,
598 param_type* p) {
599 if (!ReadParam(m, iter, &p->metadata))
600 return false;
602 int compositor_frame_type;
603 if (!ReadParam(m, iter, &compositor_frame_type))
604 return false;
606 switch (compositor_frame_type) {
607 case DELEGATED_FRAME:
608 p->delegated_frame_data.reset(new cc::DelegatedFrameData());
609 if (!ReadParam(m, iter, p->delegated_frame_data.get()))
610 return false;
611 break;
612 case GL_FRAME:
613 p->gl_frame_data.reset(new cc::GLFrameData());
614 if (!ReadParam(m, iter, p->gl_frame_data.get()))
615 return false;
616 break;
617 case SOFTWARE_FRAME:
618 p->software_frame_data.reset(new cc::SoftwareFrameData());
619 if (!ReadParam(m, iter, p->software_frame_data.get()))
620 return false;
621 break;
622 case NO_FRAME:
623 break;
624 default:
625 return false;
627 return true;
630 void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
631 std::string* l) {
632 l->append("CompositorFrame(");
633 LogParam(p.metadata, l);
634 l->append(", ");
635 if (p.delegated_frame_data)
636 LogParam(*p.delegated_frame_data, l);
637 else if (p.gl_frame_data)
638 LogParam(*p.gl_frame_data, l);
639 else if (p.software_frame_data)
640 LogParam(*p.software_frame_data, l);
641 l->append(")");
644 void ParamTraits<cc::CompositorFrameAck>::Write(Message* m,
645 const param_type& p) {
646 WriteParam(m, p.resources);
647 WriteParam(m, p.last_software_frame_id);
648 if (p.gl_frame_data) {
649 WriteParam(m, static_cast<int>(GL_FRAME));
650 WriteParam(m, *p.gl_frame_data);
651 } else {
652 WriteParam(m, static_cast<int>(NO_FRAME));
656 bool ParamTraits<cc::CompositorFrameAck>::Read(const Message* m,
657 base::PickleIterator* iter,
658 param_type* p) {
659 if (!ReadParam(m, iter, &p->resources))
660 return false;
662 if (!ReadParam(m, iter, &p->last_software_frame_id))
663 return false;
665 int compositor_frame_type;
666 if (!ReadParam(m, iter, &compositor_frame_type))
667 return false;
669 switch (compositor_frame_type) {
670 case NO_FRAME:
671 break;
672 case GL_FRAME:
673 p->gl_frame_data.reset(new cc::GLFrameData());
674 if (!ReadParam(m, iter, p->gl_frame_data.get()))
675 return false;
676 break;
677 default:
678 return false;
680 return true;
683 void ParamTraits<cc::CompositorFrameAck>::Log(const param_type& p,
684 std::string* l) {
685 l->append("CompositorFrameAck(");
686 LogParam(p.resources, l);
687 l->append(", ");
688 LogParam(p.last_software_frame_id, l);
689 l->append(", ");
690 if (p.gl_frame_data)
691 LogParam(*p.gl_frame_data, l);
692 l->append(")");
695 void ParamTraits<cc::DelegatedFrameData>::Write(Message* m,
696 const param_type& p) {
697 DCHECK_NE(0u, p.render_pass_list.size());
699 size_t to_reserve = sizeof(p.device_scale_factor);
700 to_reserve += p.resource_list.size() * sizeof(cc::TransferableResource);
701 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
702 const cc::RenderPass* pass = p.render_pass_list[i];
703 to_reserve += sizeof(size_t) * 2;
704 to_reserve += ReserveSizeForRenderPassWrite(*pass);
706 m->Reserve(to_reserve);
708 WriteParam(m, p.device_scale_factor);
709 WriteParam(m, p.resource_list);
710 WriteParam(m, p.render_pass_list.size());
711 for (const auto* pass : p.render_pass_list) {
712 WriteParam(m, pass->quad_list.size());
713 WriteParam(m, pass->shared_quad_state_list.size());
714 WriteParam(m, *pass);
718 bool ParamTraits<cc::DelegatedFrameData>::Read(const Message* m,
719 base::PickleIterator* iter,
720 param_type* p) {
721 if (!ReadParam(m, iter, &p->device_scale_factor))
722 return false;
724 const static size_t kMaxRenderPasses = 10000;
725 const static size_t kMaxSharedQuadStateListSize = 100000;
726 const static size_t kMaxQuadListSize = 1000000;
728 std::set<cc::RenderPassId> pass_set;
730 size_t num_render_passes;
731 if (!ReadParam(m, iter, &p->resource_list) ||
732 !ReadParam(m, iter, &num_render_passes) ||
733 num_render_passes > kMaxRenderPasses || num_render_passes == 0)
734 return false;
735 for (size_t i = 0; i < num_render_passes; ++i) {
736 size_t quad_list_size;
737 size_t shared_quad_state_list_size;
738 if (!ReadParam(m, iter, &quad_list_size) ||
739 !ReadParam(m, iter, &shared_quad_state_list_size) ||
740 quad_list_size > kMaxQuadListSize ||
741 shared_quad_state_list_size > kMaxSharedQuadStateListSize)
742 return false;
743 scoped_ptr<cc::RenderPass> render_pass =
744 cc::RenderPass::Create(shared_quad_state_list_size, quad_list_size);
745 if (!ReadParam(m, iter, render_pass.get()))
746 return false;
747 // Validate that each RenderPassDrawQuad points at a valid RenderPass
748 // earlier in the frame.
749 for (const auto* quad : render_pass->quad_list) {
750 if (quad->material != cc::DrawQuad::RENDER_PASS)
751 continue;
752 const cc::RenderPassDrawQuad* rpdq =
753 cc::RenderPassDrawQuad::MaterialCast(quad);
754 if (!pass_set.count(rpdq->render_pass_id))
755 return false;
757 pass_set.insert(render_pass->id);
758 p->render_pass_list.push_back(render_pass.Pass());
760 return true;
763 void ParamTraits<cc::DelegatedFrameData>::Log(const param_type& p,
764 std::string* l) {
765 l->append("DelegatedFrameData(");
766 LogParam(p.device_scale_factor, l);
767 LogParam(p.resource_list, l);
768 l->append(", [");
769 for (size_t i = 0; i < p.render_pass_list.size(); ++i) {
770 if (i)
771 l->append(", ");
772 LogParam(*p.render_pass_list[i], l);
774 l->append("])");
777 void ParamTraits<cc::SoftwareFrameData>::Write(Message* m,
778 const param_type& p) {
779 DCHECK(cc::SharedBitmap::VerifySizeInBytes(p.size));
781 m->Reserve(sizeof(cc::SoftwareFrameData));
782 WriteParam(m, p.id);
783 WriteParam(m, p.size);
784 WriteParam(m, p.damage_rect);
785 WriteParam(m, p.bitmap_id);
788 bool ParamTraits<cc::SoftwareFrameData>::Read(const Message* m,
789 base::PickleIterator* iter,
790 param_type* p) {
791 if (!ReadParam(m, iter, &p->id))
792 return false;
793 if (!ReadParam(m, iter, &p->size) ||
794 !cc::SharedBitmap::VerifySizeInBytes(p->size))
795 return false;
796 if (!ReadParam(m, iter, &p->damage_rect))
797 return false;
798 if (!ReadParam(m, iter, &p->bitmap_id))
799 return false;
800 return true;
803 void ParamTraits<cc::SoftwareFrameData>::Log(const param_type& p,
804 std::string* l) {
805 l->append("SoftwareFrameData(");
806 LogParam(p.id, l);
807 l->append(", ");
808 LogParam(p.size, l);
809 l->append(", ");
810 LogParam(p.damage_rect, l);
811 l->append(", ");
812 LogParam(p.bitmap_id, l);
813 l->append(")");
816 void ParamTraits<cc::DrawQuad::Resources>::Write(Message* m,
817 const param_type& p) {
818 DCHECK_LE(p.count, cc::DrawQuad::Resources::kMaxResourceIdCount);
819 WriteParam(m, p.count);
820 for (size_t i = 0; i < p.count; ++i)
821 WriteParam(m, p.ids[i]);
824 bool ParamTraits<cc::DrawQuad::Resources>::Read(const Message* m,
825 base::PickleIterator* iter,
826 param_type* p) {
827 if (!ReadParam(m, iter, &p->count))
828 return false;
829 if (p->count > cc::DrawQuad::Resources::kMaxResourceIdCount)
830 return false;
831 for (size_t i = 0; i < p->count; ++i) {
832 if (!ReadParam(m, iter, &p->ids[i]))
833 return false;
835 return true;
838 void ParamTraits<cc::DrawQuad::Resources>::Log(const param_type& p,
839 std::string* l) {
840 l->append("DrawQuad::Resources(");
841 LogParam(p.count, l);
842 l->append(", [");
843 if (p.count > cc::DrawQuad::Resources::kMaxResourceIdCount) {
844 l->append("])");
845 return;
848 for (size_t i = 0; i < p.count; ++i) {
849 LogParam(p.ids[i], l);
850 if (i < (p.count - 1))
851 l->append(", ");
853 l->append("])");
856 void ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Write(
857 Message* m,
858 const param_type& p) {
859 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
860 WriteParam(m, p.size_in_pixels[i]);
861 WriteParam(m, p.allow_overlay[i]);
865 bool ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Read(
866 const Message* m,
867 base::PickleIterator* iter,
868 param_type* p) {
869 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
870 if (!ReadParam(m, iter, &p->size_in_pixels[i]))
871 return false;
872 if (!ReadParam(m, iter, &p->allow_overlay[i]))
873 return false;
875 return true;
878 void ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Log(
879 const param_type& p,
880 std::string* l) {
881 l->append("StreamVideoDrawQuad::OverlayResources([");
882 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
883 LogParam(p.size_in_pixels[i], l);
884 l->append(", ");
885 LogParam(p.allow_overlay[i], l);
886 if (i < (cc::DrawQuad::Resources::kMaxResourceIdCount - 1))
887 l->append(", ");
889 l->append("])");
892 void ParamTraits<cc::TextureDrawQuad::OverlayResources>::Write(
893 Message* m,
894 const param_type& p) {
895 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
896 WriteParam(m, p.size_in_pixels[i]);
897 WriteParam(m, p.allow_overlay[i]);
901 bool ParamTraits<cc::TextureDrawQuad::OverlayResources>::Read(
902 const Message* m,
903 base::PickleIterator* iter,
904 param_type* p) {
905 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
906 if (!ReadParam(m, iter, &p->size_in_pixels[i]))
907 return false;
908 if (!ReadParam(m, iter, &p->allow_overlay[i]))
909 return false;
911 return true;
914 void ParamTraits<cc::TextureDrawQuad::OverlayResources>::Log(
915 const param_type& p,
916 std::string* l) {
917 l->append("TextureDrawQuad::OverlayResources([");
918 for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) {
919 LogParam(p.size_in_pixels[i], l);
920 l->append(", ");
921 LogParam(p.allow_overlay[i], l);
922 if (i < (cc::DrawQuad::Resources::kMaxResourceIdCount - 1))
923 l->append(", ");
925 l->append("])");
928 } // namespace IPC