1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/cc_messages.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/filter_operations.h"
9 #include "cc/quads/largest_draw_quad.h"
10 #include "content/public/common/common_param_traits.h"
11 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkFlattenableSerialization.h"
13 #include "ui/gfx/transform.h"
17 void ParamTraits
<cc::FilterOperation
>::Write(
18 Message
* m
, const param_type
& p
) {
19 WriteParam(m
, p
.type());
21 case cc::FilterOperation::GRAYSCALE
:
22 case cc::FilterOperation::SEPIA
:
23 case cc::FilterOperation::SATURATE
:
24 case cc::FilterOperation::HUE_ROTATE
:
25 case cc::FilterOperation::INVERT
:
26 case cc::FilterOperation::BRIGHTNESS
:
27 case cc::FilterOperation::SATURATING_BRIGHTNESS
:
28 case cc::FilterOperation::CONTRAST
:
29 case cc::FilterOperation::OPACITY
:
30 case cc::FilterOperation::BLUR
:
31 WriteParam(m
, p
.amount());
33 case cc::FilterOperation::DROP_SHADOW
:
34 WriteParam(m
, p
.drop_shadow_offset());
35 WriteParam(m
, p
.amount());
36 WriteParam(m
, p
.drop_shadow_color());
38 case cc::FilterOperation::COLOR_MATRIX
:
39 for (int i
= 0; i
< 20; ++i
)
40 WriteParam(m
, p
.matrix()[i
]);
42 case cc::FilterOperation::ZOOM
:
43 WriteParam(m
, p
.amount());
44 WriteParam(m
, p
.zoom_inset());
46 case cc::FilterOperation::REFERENCE
:
47 WriteParam(m
, p
.image_filter());
49 case cc::FilterOperation::ALPHA_THRESHOLD
:
55 bool ParamTraits
<cc::FilterOperation
>::Read(
56 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
57 cc::FilterOperation::FilterType type
;
59 gfx::Point drop_shadow_offset
;
60 SkColor drop_shadow_color
;
64 if (!ReadParam(m
, iter
, &type
))
70 case cc::FilterOperation::GRAYSCALE
:
71 case cc::FilterOperation::SEPIA
:
72 case cc::FilterOperation::SATURATE
:
73 case cc::FilterOperation::HUE_ROTATE
:
74 case cc::FilterOperation::INVERT
:
75 case cc::FilterOperation::BRIGHTNESS
:
76 case cc::FilterOperation::SATURATING_BRIGHTNESS
:
77 case cc::FilterOperation::CONTRAST
:
78 case cc::FilterOperation::OPACITY
:
79 case cc::FilterOperation::BLUR
:
80 if (ReadParam(m
, iter
, &amount
)) {
81 r
->set_amount(amount
);
85 case cc::FilterOperation::DROP_SHADOW
:
86 if (ReadParam(m
, iter
, &drop_shadow_offset
) &&
87 ReadParam(m
, iter
, &amount
) &&
88 ReadParam(m
, iter
, &drop_shadow_color
)) {
89 r
->set_drop_shadow_offset(drop_shadow_offset
);
90 r
->set_amount(amount
);
91 r
->set_drop_shadow_color(drop_shadow_color
);
95 case cc::FilterOperation::COLOR_MATRIX
: {
97 for (i
= 0; i
< 20; ++i
) {
98 if (!ReadParam(m
, iter
, &matrix
[i
]))
102 r
->set_matrix(matrix
);
107 case cc::FilterOperation::ZOOM
:
108 if (ReadParam(m
, iter
, &amount
) &&
109 ReadParam(m
, iter
, &zoom_inset
) &&
112 r
->set_amount(amount
);
113 r
->set_zoom_inset(zoom_inset
);
117 case cc::FilterOperation::REFERENCE
: {
118 skia::RefPtr
<SkImageFilter
> filter
;
119 if (!ReadParam(m
, iter
, &filter
)) {
123 r
->set_image_filter(filter
);
127 case cc::FilterOperation::ALPHA_THRESHOLD
:
133 void ParamTraits
<cc::FilterOperation
>::Log(
134 const param_type
& p
, std::string
* l
) {
136 LogParam(static_cast<unsigned>(p
.type()), l
);
140 case cc::FilterOperation::GRAYSCALE
:
141 case cc::FilterOperation::SEPIA
:
142 case cc::FilterOperation::SATURATE
:
143 case cc::FilterOperation::HUE_ROTATE
:
144 case cc::FilterOperation::INVERT
:
145 case cc::FilterOperation::BRIGHTNESS
:
146 case cc::FilterOperation::SATURATING_BRIGHTNESS
:
147 case cc::FilterOperation::CONTRAST
:
148 case cc::FilterOperation::OPACITY
:
149 case cc::FilterOperation::BLUR
:
150 LogParam(p
.amount(), l
);
152 case cc::FilterOperation::DROP_SHADOW
:
153 LogParam(p
.drop_shadow_offset(), l
);
155 LogParam(p
.amount(), l
);
157 LogParam(p
.drop_shadow_color(), l
);
159 case cc::FilterOperation::COLOR_MATRIX
:
160 for (int i
= 0; i
< 20; ++i
) {
163 LogParam(p
.matrix()[i
], l
);
166 case cc::FilterOperation::ZOOM
:
167 LogParam(p
.amount(), l
);
169 LogParam(p
.zoom_inset(), l
);
171 case cc::FilterOperation::REFERENCE
:
172 LogParam(p
.image_filter(), l
);
174 case cc::FilterOperation::ALPHA_THRESHOLD
:
181 void ParamTraits
<cc::FilterOperations
>::Write(
182 Message
* m
, const param_type
& p
) {
183 WriteParam(m
, p
.size());
184 for (std::size_t i
= 0; i
< p
.size(); ++i
) {
185 WriteParam(m
, p
.at(i
));
189 bool ParamTraits
<cc::FilterOperations
>::Read(
190 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
192 if (!ReadParam(m
, iter
, &count
))
195 for (std::size_t i
= 0; i
< count
; ++i
) {
196 cc::FilterOperation op
= cc::FilterOperation::CreateEmptyFilter();
197 if (!ReadParam(m
, iter
, &op
))
204 void ParamTraits
<cc::FilterOperations
>::Log(
205 const param_type
& p
, std::string
* l
) {
207 for (std::size_t i
= 0; i
< p
.size(); ++i
) {
210 LogParam(p
.at(i
), l
);
215 void ParamTraits
<skia::RefPtr
<SkImageFilter
> >::Write(
216 Message
* m
, const param_type
& p
) {
217 SkImageFilter
* filter
= p
.get();
219 skia::RefPtr
<SkData
> data
=
220 skia::AdoptRef(SkValidatingSerializeFlattenable(filter
));
221 m
->WriteData(static_cast<const char*>(data
->data()), data
->size());
227 bool ParamTraits
<skia::RefPtr
<SkImageFilter
> >::Read(
228 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
229 const char* data
= 0;
231 if (!iter
->ReadData(&data
, &length
))
234 SkFlattenable
* flattenable
= SkValidatingDeserializeFlattenable(
235 data
, length
, SkImageFilter::GetFlattenableType());
236 *r
= skia::AdoptRef(static_cast<SkImageFilter
*>(flattenable
));
243 void ParamTraits
<skia::RefPtr
<SkImageFilter
> >::Log(
244 const param_type
& p
, std::string
* l
) {
246 LogParam(p
.get() ? p
->countInputs() : 0, l
);
250 void ParamTraits
<gfx::Transform
>::Write(
251 Message
* m
, const param_type
& p
) {
252 #ifdef SK_MSCALAR_IS_FLOAT
253 float column_major_data
[16];
254 p
.matrix().asColMajorf(column_major_data
);
256 double column_major_data
[16];
257 p
.matrix().asColMajord(column_major_data
);
259 m
->WriteBytes(&column_major_data
, sizeof(SkMScalar
) * 16);
262 bool ParamTraits
<gfx::Transform
>::Read(
263 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
264 const char* column_major_data
;
265 if (!iter
->ReadBytes(&column_major_data
, sizeof(SkMScalar
) * 16))
267 r
->matrix().setColMajor(
268 reinterpret_cast<const SkMScalar
*>(column_major_data
));
272 void ParamTraits
<gfx::Transform
>::Log(
273 const param_type
& p
, std::string
* l
) {
274 #ifdef SK_MSCALAR_IS_FLOAT
275 float row_major_data
[16];
276 p
.matrix().asRowMajorf(row_major_data
);
278 double row_major_data
[16];
279 p
.matrix().asRowMajord(row_major_data
);
282 for (int i
= 0; i
< 16; ++i
) {
285 LogParam(row_major_data
[i
], l
);
290 void ParamTraits
<cc::RenderPass
>::Write(
291 Message
* m
, const param_type
& p
) {
293 WriteParam(m
, p
.output_rect
);
294 WriteParam(m
, p
.damage_rect
);
295 WriteParam(m
, p
.transform_to_root_target
);
296 WriteParam(m
, p
.has_transparent_background
);
297 WriteParam(m
, p
.quad_list
.size());
299 cc::SharedQuadStateList::ConstIterator shared_quad_state_iter
=
300 p
.shared_quad_state_list
.begin();
301 cc::SharedQuadStateList::ConstIterator last_shared_quad_state_iter
=
302 p
.shared_quad_state_list
.end();
303 for (const auto& quad
: p
.quad_list
) {
304 DCHECK(quad
->rect
.Contains(quad
->visible_rect
))
305 << quad
->material
<< " rect: " << quad
->rect
.ToString()
306 << " visible_rect: " << quad
->visible_rect
.ToString();
307 DCHECK(quad
->opaque_rect
.IsEmpty() ||
308 quad
->rect
.Contains(quad
->opaque_rect
))
309 << quad
->material
<< " rect: " << quad
->rect
.ToString()
310 << " opaque_rect: " << quad
->opaque_rect
.ToString();
312 switch (quad
->material
) {
313 case cc::DrawQuad::CHECKERBOARD
:
314 WriteParam(m
, *cc::CheckerboardDrawQuad::MaterialCast(quad
));
316 case cc::DrawQuad::DEBUG_BORDER
:
317 WriteParam(m
, *cc::DebugBorderDrawQuad::MaterialCast(quad
));
319 case cc::DrawQuad::IO_SURFACE_CONTENT
:
320 WriteParam(m
, *cc::IOSurfaceDrawQuad::MaterialCast(quad
));
322 case cc::DrawQuad::PICTURE_CONTENT
:
325 case cc::DrawQuad::TEXTURE_CONTENT
:
326 WriteParam(m
, *cc::TextureDrawQuad::MaterialCast(quad
));
328 case cc::DrawQuad::RENDER_PASS
:
329 WriteParam(m
, *cc::RenderPassDrawQuad::MaterialCast(quad
));
331 case cc::DrawQuad::SOLID_COLOR
:
332 WriteParam(m
, *cc::SolidColorDrawQuad::MaterialCast(quad
));
334 case cc::DrawQuad::SURFACE_CONTENT
:
335 WriteParam(m
, *cc::SurfaceDrawQuad::MaterialCast(quad
));
337 case cc::DrawQuad::TILED_CONTENT
:
338 WriteParam(m
, *cc::TileDrawQuad::MaterialCast(quad
));
340 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
341 WriteParam(m
, *cc::StreamVideoDrawQuad::MaterialCast(quad
));
343 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
344 WriteParam(m
, *cc::YUVVideoDrawQuad::MaterialCast(quad
));
346 case cc::DrawQuad::INVALID
:
350 // Null shared quad states should not occur.
351 DCHECK(quad
->shared_quad_state
);
353 // SharedQuadStates should appear in the order they are used by DrawQuads.
354 // Find the SharedQuadState for this DrawQuad.
355 while (shared_quad_state_iter
!= p
.shared_quad_state_list
.end() &&
356 quad
->shared_quad_state
!= *shared_quad_state_iter
)
357 ++shared_quad_state_iter
;
359 DCHECK(shared_quad_state_iter
!= p
.shared_quad_state_list
.end());
361 if (shared_quad_state_iter
!= last_shared_quad_state_iter
) {
363 WriteParam(m
, **shared_quad_state_iter
);
364 last_shared_quad_state_iter
= shared_quad_state_iter
;
366 WriteParam(m
, false);
371 static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass
& p
) {
372 size_t to_reserve
= sizeof(cc::RenderPass
);
374 // Whether the quad points to a new shared quad state for each quad.
375 to_reserve
+= p
.quad_list
.size() * sizeof(bool);
377 // Shared quad state is only written when a quad contains a shared quad state
378 // that has not been written.
379 to_reserve
+= p
.shared_quad_state_list
.size() * sizeof(cc::SharedQuadState
);
381 // The largest quad type, verified by a unit test.
382 to_reserve
+= p
.quad_list
.size() * cc::LargestDrawQuadSize();
386 template <typename QuadType
>
387 static cc::DrawQuad
* ReadDrawQuad(const Message
* m
,
388 PickleIterator
* iter
,
389 cc::RenderPass
* render_pass
) {
390 QuadType
* quad
= render_pass
->CreateAndAppendDrawQuad
<QuadType
>();
391 if (!ReadParam(m
, iter
, quad
))
396 bool ParamTraits
<cc::RenderPass
>::Read(
397 const Message
* m
, PickleIterator
* iter
, param_type
* p
) {
398 cc::RenderPassId
id(-1, -1);
399 gfx::Rect output_rect
;
400 gfx::Rect damage_rect
;
401 gfx::Transform transform_to_root_target
;
402 bool has_transparent_background
;
403 size_t quad_list_size
;
405 if (!ReadParam(m
, iter
, &id
) ||
406 !ReadParam(m
, iter
, &output_rect
) ||
407 !ReadParam(m
, iter
, &damage_rect
) ||
408 !ReadParam(m
, iter
, &transform_to_root_target
) ||
409 !ReadParam(m
, iter
, &has_transparent_background
) ||
410 !ReadParam(m
, iter
, &quad_list_size
))
416 transform_to_root_target
,
417 has_transparent_background
);
419 for (size_t i
= 0; i
< quad_list_size
; ++i
) {
420 cc::DrawQuad::Material material
;
421 PickleIterator temp_iter
= *iter
;
422 if (!ReadParam(m
, &temp_iter
, &material
))
425 cc::DrawQuad
* draw_quad
= NULL
;
427 case cc::DrawQuad::CHECKERBOARD
:
428 draw_quad
= ReadDrawQuad
<cc::CheckerboardDrawQuad
>(m
, iter
, p
);
430 case cc::DrawQuad::DEBUG_BORDER
:
431 draw_quad
= ReadDrawQuad
<cc::DebugBorderDrawQuad
>(m
, iter
, p
);
433 case cc::DrawQuad::IO_SURFACE_CONTENT
:
434 draw_quad
= ReadDrawQuad
<cc::IOSurfaceDrawQuad
>(m
, iter
, p
);
436 case cc::DrawQuad::PICTURE_CONTENT
:
439 case cc::DrawQuad::SURFACE_CONTENT
:
440 draw_quad
= ReadDrawQuad
<cc::SurfaceDrawQuad
>(m
, iter
, p
);
442 case cc::DrawQuad::TEXTURE_CONTENT
:
443 draw_quad
= ReadDrawQuad
<cc::TextureDrawQuad
>(m
, iter
, p
);
445 case cc::DrawQuad::RENDER_PASS
:
446 draw_quad
= ReadDrawQuad
<cc::RenderPassDrawQuad
>(m
, iter
, p
);
448 case cc::DrawQuad::SOLID_COLOR
:
449 draw_quad
= ReadDrawQuad
<cc::SolidColorDrawQuad
>(m
, iter
, p
);
451 case cc::DrawQuad::TILED_CONTENT
:
452 draw_quad
= ReadDrawQuad
<cc::TileDrawQuad
>(m
, iter
, p
);
454 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
455 draw_quad
= ReadDrawQuad
<cc::StreamVideoDrawQuad
>(m
, iter
, p
);
457 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
458 draw_quad
= ReadDrawQuad
<cc::YUVVideoDrawQuad
>(m
, iter
, p
);
460 case cc::DrawQuad::INVALID
:
465 if (!draw_quad
->rect
.Contains(draw_quad
->visible_rect
)) {
466 LOG(ERROR
) << "Quad with invalid visible rect " << draw_quad
->material
467 << " rect: " << draw_quad
->rect
.ToString()
468 << " visible_rect: " << draw_quad
->visible_rect
.ToString();
471 if (!draw_quad
->opaque_rect
.IsEmpty() &&
472 !draw_quad
->rect
.Contains(draw_quad
->opaque_rect
)) {
473 LOG(ERROR
) << "Quad with invalid opaque rect " << draw_quad
->material
474 << " rect: " << draw_quad
->rect
.ToString()
475 << " opaque_rect: " << draw_quad
->opaque_rect
.ToString();
479 bool has_new_shared_quad_state
;
480 if (!ReadParam(m
, iter
, &has_new_shared_quad_state
))
483 // If the quad has a new shared quad state, read it in.
484 if (has_new_shared_quad_state
) {
485 cc::SharedQuadState
* state
= p
->CreateAndAppendSharedQuadState();
486 if (!ReadParam(m
, iter
, state
))
490 draw_quad
->shared_quad_state
= p
->shared_quad_state_list
.back();
496 void ParamTraits
<cc::RenderPass
>::Log(
497 const param_type
& p
, std::string
* l
) {
498 l
->append("RenderPass((");
501 LogParam(p
.output_rect
, l
);
503 LogParam(p
.damage_rect
, l
);
505 LogParam(p
.transform_to_root_target
, l
);
507 LogParam(p
.has_transparent_background
, l
);
511 for (const auto& shared_quad_state
: p
.shared_quad_state_list
) {
512 if (shared_quad_state
!= p
.shared_quad_state_list
.front())
514 LogParam(*shared_quad_state
, l
);
517 for (const auto& quad
: p
.quad_list
) {
518 if (quad
!= p
.quad_list
.front())
520 switch (quad
->material
) {
521 case cc::DrawQuad::CHECKERBOARD
:
522 LogParam(*cc::CheckerboardDrawQuad::MaterialCast(quad
), l
);
524 case cc::DrawQuad::DEBUG_BORDER
:
525 LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad
), l
);
527 case cc::DrawQuad::IO_SURFACE_CONTENT
:
528 LogParam(*cc::IOSurfaceDrawQuad::MaterialCast(quad
), l
);
530 case cc::DrawQuad::PICTURE_CONTENT
:
533 case cc::DrawQuad::TEXTURE_CONTENT
:
534 LogParam(*cc::TextureDrawQuad::MaterialCast(quad
), l
);
536 case cc::DrawQuad::RENDER_PASS
:
537 LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad
), l
);
539 case cc::DrawQuad::SOLID_COLOR
:
540 LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad
), l
);
542 case cc::DrawQuad::SURFACE_CONTENT
:
543 LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad
), l
);
545 case cc::DrawQuad::TILED_CONTENT
:
546 LogParam(*cc::TileDrawQuad::MaterialCast(quad
), l
);
548 case cc::DrawQuad::STREAM_VIDEO_CONTENT
:
549 LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad
), l
);
551 case cc::DrawQuad::YUV_VIDEO_CONTENT
:
552 LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad
), l
);
554 case cc::DrawQuad::INVALID
:
562 enum CompositorFrameType
{
570 void ParamTraits
<cc::CompositorFrame
>::Write(Message
* m
,
571 const param_type
& p
) {
572 WriteParam(m
, p
.metadata
);
573 if (p
.delegated_frame_data
) {
574 DCHECK(!p
.gl_frame_data
);
575 DCHECK(!p
.software_frame_data
);
576 WriteParam(m
, static_cast<int>(DELEGATED_FRAME
));
577 WriteParam(m
, *p
.delegated_frame_data
);
578 } else if (p
.gl_frame_data
) {
579 DCHECK(!p
.software_frame_data
);
580 WriteParam(m
, static_cast<int>(GL_FRAME
));
581 WriteParam(m
, *p
.gl_frame_data
);
582 } else if (p
.software_frame_data
) {
583 WriteParam(m
, static_cast<int>(SOFTWARE_FRAME
));
584 WriteParam(m
, *p
.software_frame_data
);
586 WriteParam(m
, static_cast<int>(NO_FRAME
));
590 bool ParamTraits
<cc::CompositorFrame
>::Read(const Message
* m
,
591 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()))
612 p
->software_frame_data
.reset(new cc::SoftwareFrameData());
613 if (!ReadParam(m
, iter
, p
->software_frame_data
.get()))
624 void ParamTraits
<cc::CompositorFrame
>::Log(const param_type
& p
,
626 l
->append("CompositorFrame(");
627 LogParam(p
.metadata
, l
);
629 if (p
.delegated_frame_data
)
630 LogParam(*p
.delegated_frame_data
, l
);
631 else if (p
.gl_frame_data
)
632 LogParam(*p
.gl_frame_data
, l
);
633 else if (p
.software_frame_data
)
634 LogParam(*p
.software_frame_data
, l
);
638 void ParamTraits
<cc::CompositorFrameAck
>::Write(Message
* m
,
639 const param_type
& p
) {
640 WriteParam(m
, p
.resources
);
641 WriteParam(m
, p
.last_software_frame_id
);
642 if (p
.gl_frame_data
) {
643 WriteParam(m
, static_cast<int>(GL_FRAME
));
644 WriteParam(m
, *p
.gl_frame_data
);
646 WriteParam(m
, static_cast<int>(NO_FRAME
));
650 bool ParamTraits
<cc::CompositorFrameAck
>::Read(const Message
* m
,
651 PickleIterator
* iter
,
653 if (!ReadParam(m
, iter
, &p
->resources
))
656 if (!ReadParam(m
, iter
, &p
->last_software_frame_id
))
659 int compositor_frame_type
;
660 if (!ReadParam(m
, iter
, &compositor_frame_type
))
663 switch (compositor_frame_type
) {
667 p
->gl_frame_data
.reset(new cc::GLFrameData());
668 if (!ReadParam(m
, iter
, p
->gl_frame_data
.get()))
677 void ParamTraits
<cc::CompositorFrameAck
>::Log(const param_type
& p
,
679 l
->append("CompositorFrameAck(");
680 LogParam(p
.resources
, l
);
682 LogParam(p
.last_software_frame_id
, l
);
685 LogParam(*p
.gl_frame_data
, l
);
689 void ParamTraits
<cc::DelegatedFrameData
>::Write(Message
* m
,
690 const param_type
& p
) {
691 DCHECK_NE(0u, p
.render_pass_list
.size());
693 size_t to_reserve
= sizeof(p
.device_scale_factor
);
694 to_reserve
+= p
.resource_list
.size() * sizeof(cc::TransferableResource
);
695 for (size_t i
= 0; i
< p
.render_pass_list
.size(); ++i
) {
696 const cc::RenderPass
* pass
= p
.render_pass_list
[i
];
697 to_reserve
+= sizeof(size_t) * 2;
698 to_reserve
+= ReserveSizeForRenderPassWrite(*pass
);
700 m
->Reserve(to_reserve
);
702 WriteParam(m
, p
.device_scale_factor
);
703 WriteParam(m
, p
.resource_list
);
704 WriteParam(m
, p
.render_pass_list
.size());
705 for (size_t i
= 0; i
< p
.render_pass_list
.size(); ++i
) {
706 WriteParam(m
, p
.render_pass_list
[i
]->quad_list
.size());
707 WriteParam(m
, p
.render_pass_list
[i
]->shared_quad_state_list
.size());
708 WriteParam(m
, *p
.render_pass_list
[i
]);
712 bool ParamTraits
<cc::DelegatedFrameData
>::Read(const Message
* m
,
713 PickleIterator
* iter
,
715 if (!ReadParam(m
, iter
, &p
->device_scale_factor
))
718 const static size_t kMaxRenderPasses
= 10000;
719 const static size_t kMaxSharedQuadStateListSize
= 100000;
720 const static size_t kMaxQuadListSize
= 1000000;
722 size_t num_render_passes
;
723 if (!ReadParam(m
, iter
, &p
->resource_list
) ||
724 !ReadParam(m
, iter
, &num_render_passes
) ||
725 num_render_passes
> kMaxRenderPasses
|| num_render_passes
== 0)
727 for (size_t i
= 0; i
< num_render_passes
; ++i
) {
728 size_t quad_list_size
;
729 size_t shared_quad_state_list_size
;
730 if (!ReadParam(m
, iter
, &quad_list_size
) ||
731 !ReadParam(m
, iter
, &shared_quad_state_list_size
) ||
732 quad_list_size
> kMaxQuadListSize
||
733 shared_quad_state_list_size
> kMaxSharedQuadStateListSize
)
735 scoped_ptr
<cc::RenderPass
> render_pass
=
736 cc::RenderPass::Create(shared_quad_state_list_size
, quad_list_size
);
737 if (!ReadParam(m
, iter
, render_pass
.get()))
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::SoftwareFrameData
>::Write(Message
* m
,
759 const param_type
& p
) {
760 DCHECK(cc::SharedBitmap::VerifySizeInBytes(p
.size
));
762 m
->Reserve(sizeof(cc::SoftwareFrameData
));
764 WriteParam(m
, p
.size
);
765 WriteParam(m
, p
.damage_rect
);
766 WriteParam(m
, p
.bitmap_id
);
769 bool ParamTraits
<cc::SoftwareFrameData
>::Read(const Message
* m
,
770 PickleIterator
* iter
,
772 if (!ReadParam(m
, iter
, &p
->id
))
774 if (!ReadParam(m
, iter
, &p
->size
) ||
775 !cc::SharedBitmap::VerifySizeInBytes(p
->size
))
777 if (!ReadParam(m
, iter
, &p
->damage_rect
))
779 if (!ReadParam(m
, iter
, &p
->bitmap_id
))
784 void ParamTraits
<cc::SoftwareFrameData
>::Log(const param_type
& p
,
786 l
->append("SoftwareFrameData(");
791 LogParam(p
.damage_rect
, l
);
793 LogParam(p
.bitmap_id
, l
);