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"
19 void ParamTraits
<cc::FilterOperation
>::Write(
20 Message
* m
, const param_type
& p
) {
21 WriteParam(m
, 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());
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());
40 case cc::FilterOperation::COLOR_MATRIX
:
41 for (int i
= 0; i
< 20; ++i
)
42 WriteParam(m
, p
.matrix()[i
]);
44 case cc::FilterOperation::ZOOM
:
45 WriteParam(m
, p
.amount());
46 WriteParam(m
, p
.zoom_inset());
48 case cc::FilterOperation::REFERENCE
:
49 WriteParam(m
, p
.image_filter());
51 case cc::FilterOperation::ALPHA_THRESHOLD
:
57 bool ParamTraits
<cc::FilterOperation
>::Read(const Message
* m
,
58 base::PickleIterator
* iter
,
60 cc::FilterOperation::FilterType type
;
62 gfx::Point drop_shadow_offset
;
63 SkColor drop_shadow_color
;
67 if (!ReadParam(m
, iter
, &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
);
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
);
98 case cc::FilterOperation::COLOR_MATRIX
: {
100 for (i
= 0; i
< 20; ++i
) {
101 if (!ReadParam(m
, iter
, &matrix
[i
]))
105 r
->set_matrix(matrix
);
110 case cc::FilterOperation::ZOOM
:
111 if (ReadParam(m
, iter
, &amount
) &&
112 ReadParam(m
, iter
, &zoom_inset
) &&
115 r
->set_amount(amount
);
116 r
->set_zoom_inset(zoom_inset
);
120 case cc::FilterOperation::REFERENCE
: {
121 skia::RefPtr
<SkImageFilter
> filter
;
122 if (!ReadParam(m
, iter
, &filter
)) {
126 r
->set_image_filter(filter
);
130 case cc::FilterOperation::ALPHA_THRESHOLD
:
136 void ParamTraits
<cc::FilterOperation
>::Log(
137 const param_type
& p
, std::string
* l
) {
139 LogParam(static_cast<unsigned>(p
.type()), l
);
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
);
155 case cc::FilterOperation::DROP_SHADOW
:
156 LogParam(p
.drop_shadow_offset(), l
);
158 LogParam(p
.amount(), l
);
160 LogParam(p
.drop_shadow_color(), l
);
162 case cc::FilterOperation::COLOR_MATRIX
:
163 for (int i
= 0; i
< 20; ++i
) {
166 LogParam(p
.matrix()[i
], l
);
169 case cc::FilterOperation::ZOOM
:
170 LogParam(p
.amount(), l
);
172 LogParam(p
.zoom_inset(), l
);
174 case cc::FilterOperation::REFERENCE
:
175 LogParam(p
.image_filter(), l
);
177 case cc::FilterOperation::ALPHA_THRESHOLD
:
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
,
196 if (!ReadParam(m
, iter
, &count
))
199 for (std::size_t i
= 0; i
< count
; ++i
) {
200 cc::FilterOperation op
= cc::FilterOperation::CreateEmptyFilter();
201 if (!ReadParam(m
, iter
, &op
))
208 void ParamTraits
<cc::FilterOperations
>::Log(
209 const param_type
& p
, std::string
* l
) {
211 for (std::size_t i
= 0; i
< p
.size(); ++i
) {
214 LogParam(p
.at(i
), l
);
219 void ParamTraits
<skia::RefPtr
<SkImageFilter
> >::Write(
220 Message
* m
, const param_type
& p
) {
221 SkImageFilter
* filter
= p
.get();
223 skia::RefPtr
<SkData
> data
=
224 skia::AdoptRef(SkValidatingSerializeFlattenable(filter
));
225 m
->WriteData(static_cast<const char*>(data
->data()), data
->size());
231 bool ParamTraits
<skia::RefPtr
<SkImageFilter
>>::Read(const Message
* m
,
232 base::PickleIterator
* iter
,
234 const char* data
= 0;
236 if (!iter
->ReadData(&data
, &length
))
239 SkFlattenable
* flattenable
= SkValidatingDeserializeFlattenable(
240 data
, length
, SkImageFilter::GetFlattenableType());
241 *r
= skia::AdoptRef(static_cast<SkImageFilter
*>(flattenable
));
248 void ParamTraits
<skia::RefPtr
<SkImageFilter
> >::Log(
249 const param_type
& p
, std::string
* l
) {
251 LogParam(p
.get() ? p
->countInputs() : 0, l
);
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
);
261 double column_major_data
[16];
262 p
.matrix().asColMajord(column_major_data
);
264 m
->WriteBytes(&column_major_data
, sizeof(SkMScalar
) * 16);
267 bool ParamTraits
<gfx::Transform
>::Read(const Message
* m
,
268 base::PickleIterator
* iter
,
270 const char* column_major_data
;
271 if (!iter
->ReadBytes(&column_major_data
, sizeof(SkMScalar
) * 16))
273 r
->matrix().setColMajor(
274 reinterpret_cast<const SkMScalar
*>(column_major_data
));
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
);
284 double row_major_data
[16];
285 p
.matrix().asRowMajord(row_major_data
);
288 for (int i
= 0; i
< 16; ++i
) {
291 LogParam(row_major_data
[i
], l
);
296 void ParamTraits
<cc::RenderPass
>::Write(
297 Message
* m
, const param_type
& p
) {
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
));
322 case cc::DrawQuad::DEBUG_BORDER
:
323 WriteParam(m
, *cc::DebugBorderDrawQuad::MaterialCast(quad
));
325 case cc::DrawQuad::IO_SURFACE_CONTENT
:
326 WriteParam(m
, *cc::IOSurfaceDrawQuad::MaterialCast(quad
));
328 case cc::DrawQuad::PICTURE_CONTENT
:
331 case cc::DrawQuad::TEXTURE_CONTENT
:
332 WriteParam(m
, *cc::TextureDrawQuad::MaterialCast(quad
));
334 case cc::DrawQuad::RENDER_PASS
:
335 WriteParam(m
, *cc::RenderPassDrawQuad::MaterialCast(quad
));
337 case cc::DrawQuad::SOLID_COLOR
:
338 WriteParam(m
, *cc::SolidColorDrawQuad::MaterialCast(quad
));
340 case cc::DrawQuad::SURFACE_CONTENT
:
341 WriteParam(m
, *cc::SurfaceDrawQuad::MaterialCast(quad
));
343 case cc::DrawQuad::TILED_CONTENT
:
344 WriteParam(m
, *cc::TileDrawQuad::MaterialCast(quad
));
346 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
347 WriteParam(m
, *cc::StreamVideoDrawQuad::MaterialCast(quad
));
349 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
350 WriteParam(m
, *cc::YUVVideoDrawQuad::MaterialCast(quad
));
352 case cc::DrawQuad::INVALID
:
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
) {
369 WriteParam(m
, **shared_quad_state_iter
);
370 last_shared_quad_state_iter
= shared_quad_state_iter
;
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();
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
))
402 bool ParamTraits
<cc::RenderPass
>::Read(const Message
* m
,
403 base::PickleIterator
* iter
,
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
))
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
))
432 cc::DrawQuad
* draw_quad
= NULL
;
434 case cc::DrawQuad::CHECKERBOARD
:
435 draw_quad
= ReadDrawQuad
<cc::CheckerboardDrawQuad
>(m
, iter
, p
);
437 case cc::DrawQuad::DEBUG_BORDER
:
438 draw_quad
= ReadDrawQuad
<cc::DebugBorderDrawQuad
>(m
, iter
, p
);
440 case cc::DrawQuad::IO_SURFACE_CONTENT
:
441 draw_quad
= ReadDrawQuad
<cc::IOSurfaceDrawQuad
>(m
, iter
, p
);
443 case cc::DrawQuad::PICTURE_CONTENT
:
446 case cc::DrawQuad::SURFACE_CONTENT
:
447 draw_quad
= ReadDrawQuad
<cc::SurfaceDrawQuad
>(m
, iter
, p
);
449 case cc::DrawQuad::TEXTURE_CONTENT
:
450 draw_quad
= ReadDrawQuad
<cc::TextureDrawQuad
>(m
, iter
, p
);
452 case cc::DrawQuad::RENDER_PASS
:
453 draw_quad
= ReadDrawQuad
<cc::RenderPassDrawQuad
>(m
, iter
, p
);
455 case cc::DrawQuad::SOLID_COLOR
:
456 draw_quad
= ReadDrawQuad
<cc::SolidColorDrawQuad
>(m
, iter
, p
);
458 case cc::DrawQuad::TILED_CONTENT
:
459 draw_quad
= ReadDrawQuad
<cc::TileDrawQuad
>(m
, iter
, p
);
461 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
462 draw_quad
= ReadDrawQuad
<cc::StreamVideoDrawQuad
>(m
, iter
, p
);
464 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
465 draw_quad
= ReadDrawQuad
<cc::YUVVideoDrawQuad
>(m
, iter
, p
);
467 case cc::DrawQuad::INVALID
:
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();
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();
486 bool has_new_shared_quad_state
;
487 if (!ReadParam(m
, iter
, &has_new_shared_quad_state
))
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
))
497 draw_quad
->shared_quad_state
= p
->shared_quad_state_list
.back();
503 void ParamTraits
<cc::RenderPass
>::Log(
504 const param_type
& p
, std::string
* l
) {
505 l
->append("RenderPass((");
508 LogParam(p
.output_rect
, l
);
510 LogParam(p
.damage_rect
, l
);
512 LogParam(p
.transform_to_root_target
, l
);
514 LogParam(p
.has_transparent_background
, l
);
518 for (const auto& shared_quad_state
: p
.shared_quad_state_list
) {
519 if (shared_quad_state
!= p
.shared_quad_state_list
.front())
521 LogParam(*shared_quad_state
, l
);
524 for (const auto& quad
: p
.quad_list
) {
525 if (quad
!= p
.quad_list
.front())
527 switch (quad
->material
) {
528 case cc::DrawQuad::CHECKERBOARD
:
529 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(quad
), l
);
531 case cc::DrawQuad::DEBUG_BORDER
:
532 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad
), l
);
534 case cc::DrawQuad::IO_SURFACE_CONTENT
:
535 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad
), l
);
537 case cc::DrawQuad::PICTURE_CONTENT
:
540 case cc::DrawQuad::TEXTURE_CONTENT
:
541 LogParam(*cc::TextureDrawQuad::MaterialCast(quad
), l
);
543 case cc::DrawQuad::RENDER_PASS
:
544 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad
), l
);
546 case cc::DrawQuad::SOLID_COLOR
:
547 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad
), l
);
549 case cc::DrawQuad::SURFACE_CONTENT
:
550 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad
), l
);
552 case cc::DrawQuad::TILED_CONTENT
:
553 LogParam(*cc::TileDrawQuad::MaterialCast(quad
), l
);
555 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
556 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad
), l
);
558 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
559 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad
), l
);
561 case cc::DrawQuad::INVALID
:
569 enum CompositorFrameType
{
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
);
593 WriteParam(m
, static_cast<int>(NO_FRAME
));
597 bool ParamTraits
<cc::CompositorFrame
>::Read(const Message
* m
,
598 base::PickleIterator
* iter
,
600 if (!ReadParam(m
, iter
, &p
->metadata
))
603 int compositor_frame_type
;
604 if (!ReadParam(m
, iter
, &compositor_frame_type
))
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()))
614 p
->gl_frame_data
.reset(new cc::GLFrameData());
615 if (!ReadParam(m
, iter
, p
->gl_frame_data
.get()))
619 p
->software_frame_data
.reset(new cc::SoftwareFrameData());
620 if (!ReadParam(m
, iter
, p
->software_frame_data
.get()))
631 void ParamTraits
<cc::CompositorFrame
>::Log(const param_type
& p
,
633 l
->append("CompositorFrame(");
634 LogParam(p
.metadata
, l
);
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
);
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
);
653 WriteParam(m
, static_cast<int>(NO_FRAME
));
657 bool ParamTraits
<cc::CompositorFrameAck
>::Read(const Message
* m
,
658 base::PickleIterator
* iter
,
660 if (!ReadParam(m
, iter
, &p
->resources
))
663 if (!ReadParam(m
, iter
, &p
->last_software_frame_id
))
666 int compositor_frame_type
;
667 if (!ReadParam(m
, iter
, &compositor_frame_type
))
670 switch (compositor_frame_type
) {
674 p
->gl_frame_data
.reset(new cc::GLFrameData());
675 if (!ReadParam(m
, iter
, p
->gl_frame_data
.get()))
684 void ParamTraits
<cc::CompositorFrameAck
>::Log(const param_type
& p
,
686 l
->append("CompositorFrameAck(");
687 LogParam(p
.resources
, l
);
689 LogParam(p
.last_software_frame_id
, l
);
692 LogParam(*p
.gl_frame_data
, l
);
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
,
722 if (!ReadParam(m
, iter
, &p
->device_scale_factor
))
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)
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
)
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()))
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
)
753 const cc::RenderPassDrawQuad
* rpdq
=
754 cc::RenderPassDrawQuad::MaterialCast(quad
);
755 if (!pass_set
.count(rpdq
->render_pass_id
))
758 pass_set
.insert(render_pass
->id
);
759 p
->render_pass_list
.push_back(render_pass
.Pass());
764 void ParamTraits
<cc::DelegatedFrameData
>::Log(const param_type
& p
,
766 l
->append("DelegatedFrameData(");
767 LogParam(p
.device_scale_factor
, l
);
768 LogParam(p
.resource_list
, l
);
770 for (size_t i
= 0; i
< p
.render_pass_list
.size(); ++i
) {
773 LogParam(*p
.render_pass_list
[i
], l
);
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
));
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
,
792 if (!ReadParam(m
, iter
, &p
->id
))
794 if (!ReadParam(m
, iter
, &p
->size
) ||
795 !cc::SharedBitmap::VerifySizeInBytes(p
->size
))
797 if (!ReadParam(m
, iter
, &p
->damage_rect
))
799 if (!ReadParam(m
, iter
, &p
->bitmap_id
))
804 void ParamTraits
<cc::SoftwareFrameData
>::Log(const param_type
& p
,
806 l
->append("SoftwareFrameData(");
811 LogParam(p
.damage_rect
, l
);
813 LogParam(p
.bitmap_id
, l
);
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
,
828 if (!ReadParam(m
, iter
, &p
->count
))
830 if (p
->count
> cc::DrawQuad::Resources::kMaxResourceIdCount
)
832 for (size_t i
= 0; i
< p
->count
; ++i
) {
833 if (!ReadParam(m
, iter
, &p
->ids
[i
]))
839 void ParamTraits
<cc::DrawQuad::Resources
>::Log(const param_type
& p
,
841 l
->append("DrawQuad::Resources(");
842 LogParam(p
.count
, l
);
844 if (p
.count
> cc::DrawQuad::Resources::kMaxResourceIdCount
) {
849 for (size_t i
= 0; i
< p
.count
; ++i
) {
850 LogParam(p
.ids
[i
], l
);
851 if (i
< (p
.count
- 1))
857 void ParamTraits
<cc::StreamVideoDrawQuad::OverlayResources
>::Write(
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(
868 base::PickleIterator
* iter
,
870 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
871 if (!ReadParam(m
, iter
, &p
->size_in_pixels
[i
]))
873 if (!ReadParam(m
, iter
, &p
->allow_overlay
[i
]))
879 void ParamTraits
<cc::StreamVideoDrawQuad::OverlayResources
>::Log(
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
);
886 LogParam(p
.allow_overlay
[i
], l
);
887 if (i
< (cc::DrawQuad::Resources::kMaxResourceIdCount
- 1))
893 void ParamTraits
<cc::TextureDrawQuad::OverlayResources
>::Write(
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(
904 base::PickleIterator
* iter
,
906 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
907 if (!ReadParam(m
, iter
, &p
->size_in_pixels
[i
]))
909 if (!ReadParam(m
, iter
, &p
->allow_overlay
[i
]))
915 void ParamTraits
<cc::TextureDrawQuad::OverlayResources
>::Log(
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
);
922 LogParam(p
.allow_overlay
[i
], l
);
923 if (i
< (cc::DrawQuad::Resources::kMaxResourceIdCount
- 1))