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
.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
));
323 case cc::DrawQuad::IO_SURFACE_CONTENT
:
324 WriteParam(m
, *cc::IOSurfaceDrawQuad::MaterialCast(quad
));
326 case cc::DrawQuad::PICTURE_CONTENT
:
329 case cc::DrawQuad::TEXTURE_CONTENT
:
330 WriteParam(m
, *cc::TextureDrawQuad::MaterialCast(quad
));
332 case cc::DrawQuad::RENDER_PASS
:
333 WriteParam(m
, *cc::RenderPassDrawQuad::MaterialCast(quad
));
335 case cc::DrawQuad::SOLID_COLOR
:
336 WriteParam(m
, *cc::SolidColorDrawQuad::MaterialCast(quad
));
338 case cc::DrawQuad::SURFACE_CONTENT
:
339 WriteParam(m
, *cc::SurfaceDrawQuad::MaterialCast(quad
));
341 case cc::DrawQuad::TILED_CONTENT
:
342 WriteParam(m
, *cc::TileDrawQuad::MaterialCast(quad
));
344 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
345 WriteParam(m
, *cc::StreamVideoDrawQuad::MaterialCast(quad
));
347 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
348 WriteParam(m
, *cc::YUVVideoDrawQuad::MaterialCast(quad
));
350 case cc::DrawQuad::INVALID
:
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
) {
367 WriteParam(m
, **shared_quad_state_iter
);
368 last_shared_quad_state_iter
= shared_quad_state_iter
;
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
);
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
))
403 bool ParamTraits
<cc::RenderPass
>::Read(const Message
* m
,
404 base::PickleIterator
* iter
,
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
))
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
))
435 cc::DrawQuad
* draw_quad
= NULL
;
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
);
516 LogParam(p
.referenced_surfaces
, l
);
520 for (const auto& shared_quad_state
: p
.shared_quad_state_list
) {
521 if (shared_quad_state
!= p
.shared_quad_state_list
.front())
523 LogParam(*shared_quad_state
, l
);
526 for (const auto& quad
: p
.quad_list
) {
527 if (quad
!= p
.quad_list
.front())
529 switch (quad
->material
) {
530 case cc::DrawQuad::DEBUG_BORDER
:
531 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad
), l
);
533 case cc::DrawQuad::IO_SURFACE_CONTENT
:
534 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad
), l
);
536 case cc::DrawQuad::PICTURE_CONTENT
:
539 case cc::DrawQuad::TEXTURE_CONTENT
:
540 LogParam(*cc::TextureDrawQuad::MaterialCast(quad
), l
);
542 case cc::DrawQuad::RENDER_PASS
:
543 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad
), l
);
545 case cc::DrawQuad::SOLID_COLOR
:
546 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad
), l
);
548 case cc::DrawQuad::SURFACE_CONTENT
:
549 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad
), l
);
551 case cc::DrawQuad::TILED_CONTENT
:
552 LogParam(*cc::TileDrawQuad::MaterialCast(quad
), l
);
554 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
555 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad
), l
);
557 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
558 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad
), l
);
560 case cc::DrawQuad::INVALID
:
568 enum CompositorFrameType
{
575 void ParamTraits
<cc::CompositorFrame
>::Write(Message
* m
,
576 const param_type
& p
) {
577 WriteParam(m
, p
.metadata
);
578 if (p
.delegated_frame_data
) {
579 DCHECK(!p
.gl_frame_data
);
580 WriteParam(m
, static_cast<int>(DELEGATED_FRAME
));
581 WriteParam(m
, *p
.delegated_frame_data
);
582 } else if (p
.gl_frame_data
) {
583 WriteParam(m
, static_cast<int>(GL_FRAME
));
584 WriteParam(m
, *p
.gl_frame_data
);
586 WriteParam(m
, static_cast<int>(NO_FRAME
));
590 bool ParamTraits
<cc::CompositorFrame
>::Read(const Message
* m
,
591 base::PickleIterator
* iter
,
593 if (!ReadParam(m
, iter
, &p
->metadata
))
596 int compositor_frame_type
;
597 if (!ReadParam(m
, iter
, &compositor_frame_type
))
600 switch (compositor_frame_type
) {
601 case DELEGATED_FRAME
:
602 p
->delegated_frame_data
.reset(new cc::DelegatedFrameData());
603 if (!ReadParam(m
, iter
, p
->delegated_frame_data
.get()))
607 p
->gl_frame_data
.reset(new cc::GLFrameData());
608 if (!ReadParam(m
, iter
, p
->gl_frame_data
.get()))
619 void ParamTraits
<cc::CompositorFrame
>::Log(const param_type
& p
,
621 l
->append("CompositorFrame(");
622 LogParam(p
.metadata
, l
);
624 if (p
.delegated_frame_data
)
625 LogParam(*p
.delegated_frame_data
, l
);
626 else if (p
.gl_frame_data
)
627 LogParam(*p
.gl_frame_data
, l
);
631 void ParamTraits
<cc::CompositorFrameAck
>::Write(Message
* m
,
632 const param_type
& p
) {
633 WriteParam(m
, p
.resources
);
634 if (p
.gl_frame_data
) {
635 WriteParam(m
, static_cast<int>(GL_FRAME
));
636 WriteParam(m
, *p
.gl_frame_data
);
638 WriteParam(m
, static_cast<int>(NO_FRAME
));
642 bool ParamTraits
<cc::CompositorFrameAck
>::Read(const Message
* m
,
643 base::PickleIterator
* iter
,
645 if (!ReadParam(m
, iter
, &p
->resources
))
648 int compositor_frame_type
;
649 if (!ReadParam(m
, iter
, &compositor_frame_type
))
652 switch (compositor_frame_type
) {
656 p
->gl_frame_data
.reset(new cc::GLFrameData());
657 if (!ReadParam(m
, iter
, p
->gl_frame_data
.get()))
666 void ParamTraits
<cc::CompositorFrameAck
>::Log(const param_type
& p
,
668 l
->append("CompositorFrameAck(");
669 LogParam(p
.resources
, l
);
672 LogParam(*p
.gl_frame_data
, l
);
676 void ParamTraits
<cc::DelegatedFrameData
>::Write(Message
* m
,
677 const param_type
& p
) {
678 DCHECK_NE(0u, p
.render_pass_list
.size());
680 size_t to_reserve
= sizeof(p
.device_scale_factor
);
681 to_reserve
+= p
.resource_list
.size() * sizeof(cc::TransferableResource
);
682 for (size_t i
= 0; i
< p
.render_pass_list
.size(); ++i
) {
683 const cc::RenderPass
* pass
= p
.render_pass_list
[i
];
684 to_reserve
+= sizeof(size_t) * 2;
685 to_reserve
+= ReserveSizeForRenderPassWrite(*pass
);
687 m
->Reserve(to_reserve
);
689 WriteParam(m
, p
.device_scale_factor
);
690 WriteParam(m
, p
.resource_list
);
691 WriteParam(m
, p
.render_pass_list
.size());
692 for (const auto* pass
: p
.render_pass_list
) {
693 WriteParam(m
, pass
->quad_list
.size());
694 WriteParam(m
, pass
->shared_quad_state_list
.size());
695 WriteParam(m
, *pass
);
699 bool ParamTraits
<cc::DelegatedFrameData
>::Read(const Message
* m
,
700 base::PickleIterator
* iter
,
702 if (!ReadParam(m
, iter
, &p
->device_scale_factor
))
705 const static size_t kMaxRenderPasses
= 10000;
706 const static size_t kMaxSharedQuadStateListSize
= 100000;
707 const static size_t kMaxQuadListSize
= 1000000;
709 std::set
<cc::RenderPassId
> pass_set
;
711 size_t num_render_passes
;
712 if (!ReadParam(m
, iter
, &p
->resource_list
) ||
713 !ReadParam(m
, iter
, &num_render_passes
) ||
714 num_render_passes
> kMaxRenderPasses
|| num_render_passes
== 0)
716 for (size_t i
= 0; i
< num_render_passes
; ++i
) {
717 size_t quad_list_size
;
718 size_t shared_quad_state_list_size
;
719 if (!ReadParam(m
, iter
, &quad_list_size
) ||
720 !ReadParam(m
, iter
, &shared_quad_state_list_size
) ||
721 quad_list_size
> kMaxQuadListSize
||
722 shared_quad_state_list_size
> kMaxSharedQuadStateListSize
)
724 scoped_ptr
<cc::RenderPass
> render_pass
=
725 cc::RenderPass::Create(shared_quad_state_list_size
, quad_list_size
);
726 if (!ReadParam(m
, iter
, render_pass
.get()))
728 // Validate that each RenderPassDrawQuad points at a valid RenderPass
729 // earlier in the frame.
730 for (const auto* quad
: render_pass
->quad_list
) {
731 if (quad
->material
!= cc::DrawQuad::RENDER_PASS
)
733 const cc::RenderPassDrawQuad
* rpdq
=
734 cc::RenderPassDrawQuad::MaterialCast(quad
);
735 if (!pass_set
.count(rpdq
->render_pass_id
))
738 pass_set
.insert(render_pass
->id
);
739 p
->render_pass_list
.push_back(render_pass
.Pass());
744 void ParamTraits
<cc::DelegatedFrameData
>::Log(const param_type
& p
,
746 l
->append("DelegatedFrameData(");
747 LogParam(p
.device_scale_factor
, l
);
748 LogParam(p
.resource_list
, l
);
750 for (size_t i
= 0; i
< p
.render_pass_list
.size(); ++i
) {
753 LogParam(*p
.render_pass_list
[i
], l
);
758 void ParamTraits
<cc::DrawQuad::Resources
>::Write(Message
* m
,
759 const param_type
& p
) {
760 DCHECK_LE(p
.count
, cc::DrawQuad::Resources::kMaxResourceIdCount
);
761 WriteParam(m
, p
.count
);
762 for (size_t i
= 0; i
< p
.count
; ++i
)
763 WriteParam(m
, p
.ids
[i
]);
766 bool ParamTraits
<cc::DrawQuad::Resources
>::Read(const Message
* m
,
767 base::PickleIterator
* iter
,
769 if (!ReadParam(m
, iter
, &p
->count
))
771 if (p
->count
> cc::DrawQuad::Resources::kMaxResourceIdCount
)
773 for (size_t i
= 0; i
< p
->count
; ++i
) {
774 if (!ReadParam(m
, iter
, &p
->ids
[i
]))
780 void ParamTraits
<cc::DrawQuad::Resources
>::Log(const param_type
& p
,
782 l
->append("DrawQuad::Resources(");
783 LogParam(p
.count
, l
);
785 if (p
.count
> cc::DrawQuad::Resources::kMaxResourceIdCount
) {
790 for (size_t i
= 0; i
< p
.count
; ++i
) {
791 LogParam(p
.ids
[i
], l
);
792 if (i
< (p
.count
- 1))
798 void ParamTraits
<cc::StreamVideoDrawQuad::OverlayResources
>::Write(
800 const param_type
& p
) {
801 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
802 WriteParam(m
, p
.size_in_pixels
[i
]);
803 WriteParam(m
, p
.allow_overlay
[i
]);
807 bool ParamTraits
<cc::StreamVideoDrawQuad::OverlayResources
>::Read(
809 base::PickleIterator
* iter
,
811 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
812 if (!ReadParam(m
, iter
, &p
->size_in_pixels
[i
]))
814 if (!ReadParam(m
, iter
, &p
->allow_overlay
[i
]))
820 void ParamTraits
<cc::StreamVideoDrawQuad::OverlayResources
>::Log(
823 l
->append("StreamVideoDrawQuad::OverlayResources([");
824 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
825 LogParam(p
.size_in_pixels
[i
], l
);
827 LogParam(p
.allow_overlay
[i
], l
);
828 if (i
< (cc::DrawQuad::Resources::kMaxResourceIdCount
- 1))
834 void ParamTraits
<cc::TextureDrawQuad::OverlayResources
>::Write(
836 const param_type
& p
) {
837 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
838 WriteParam(m
, p
.size_in_pixels
[i
]);
839 WriteParam(m
, p
.allow_overlay
[i
]);
843 bool ParamTraits
<cc::TextureDrawQuad::OverlayResources
>::Read(
845 base::PickleIterator
* iter
,
847 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
848 if (!ReadParam(m
, iter
, &p
->size_in_pixels
[i
]))
850 if (!ReadParam(m
, iter
, &p
->allow_overlay
[i
]))
856 void ParamTraits
<cc::TextureDrawQuad::OverlayResources
>::Log(
859 l
->append("TextureDrawQuad::OverlayResources([");
860 for (size_t i
= 0; i
< cc::DrawQuad::Resources::kMaxResourceIdCount
; ++i
) {
861 LogParam(p
.size_in_pixels
[i
], l
);
863 LogParam(p
.allow_overlay
[i
], l
);
864 if (i
< (cc::DrawQuad::Resources::kMaxResourceIdCount
- 1))