1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_WEBRENDERMESSAGEUTILS_H
8 #define GFX_WEBRENDERMESSAGEUTILS_H
10 #include "chrome/common/ipc_message_utils.h"
12 #include "ipc/EnumSerializer.h"
13 #include "ipc/IPCMessageUtils.h"
14 #include "mozilla/webrender/webrender_ffi.h"
15 #include "mozilla/webrender/WebRenderTypes.h"
16 #include "mozilla/dom/MediaIPCUtils.h"
21 struct ParamTraits
<mozilla::wr::ByteBuffer
> {
22 typedef mozilla::wr::ByteBuffer paramType
;
24 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
25 WriteParam(aWriter
, aParam
.mLength
);
26 aWriter
->WriteBytes(aParam
.mData
, aParam
.mLength
);
29 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
31 return ReadParam(aReader
, &length
) && aResult
->Allocate(length
) &&
32 aReader
->ReadBytesInto(aResult
->mData
, length
);
37 struct ParamTraits
<mozilla::wr::ImageDescriptor
> {
38 typedef mozilla::wr::ImageDescriptor paramType
;
40 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
41 WriteParam(aWriter
, aParam
.format
);
42 WriteParam(aWriter
, aParam
.width
);
43 WriteParam(aWriter
, aParam
.height
);
44 WriteParam(aWriter
, aParam
.stride
);
45 WriteParam(aWriter
, aParam
.opacity
);
48 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
49 return ReadParam(aReader
, &aResult
->format
) &&
50 ReadParam(aReader
, &aResult
->width
) &&
51 ReadParam(aReader
, &aResult
->height
) &&
52 ReadParam(aReader
, &aResult
->stride
) &&
53 ReadParam(aReader
, &aResult
->opacity
);
58 struct ParamTraits
<mozilla::wr::GeckoDisplayListType::Tag
>
59 : public ContiguousEnumSerializer
<
60 mozilla::wr::GeckoDisplayListType::Tag
,
61 mozilla::wr::GeckoDisplayListType::Tag::None
,
62 mozilla::wr::GeckoDisplayListType::Tag::Sentinel
> {};
65 struct ParamTraits
<mozilla::wr::GeckoDisplayListType
> {
66 typedef mozilla::wr::GeckoDisplayListType paramType
;
68 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
69 WriteParam(aWriter
, aParam
.tag
);
71 case mozilla::wr::GeckoDisplayListType::Tag::None
:
73 case mozilla::wr::GeckoDisplayListType::Tag::Partial
:
74 WriteParam(aWriter
, aParam
.partial
._0
);
76 case mozilla::wr::GeckoDisplayListType::Tag::Full
:
77 WriteParam(aWriter
, aParam
.full
._0
);
80 MOZ_RELEASE_ASSERT(false, "bad enum variant");
84 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
85 if (!ReadParam(aReader
, &aResult
->tag
)) {
88 switch (aResult
->tag
) {
89 case mozilla::wr::GeckoDisplayListType::Tag::None
:
91 case mozilla::wr::GeckoDisplayListType::Tag::Partial
:
92 return ReadParam(aReader
, &aResult
->partial
._0
);
93 case mozilla::wr::GeckoDisplayListType::Tag::Full
:
94 return ReadParam(aReader
, &aResult
->full
._0
);
96 MOZ_RELEASE_ASSERT(false, "bad enum variant");
102 struct ParamTraits
<mozilla::wr::BuiltDisplayListDescriptor
> {
103 typedef mozilla::wr::BuiltDisplayListDescriptor paramType
;
105 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
106 WriteParam(aWriter
, aParam
.gecko_display_list_type
);
107 WriteParam(aWriter
, aParam
.builder_start_time
);
108 WriteParam(aWriter
, aParam
.builder_finish_time
);
109 WriteParam(aWriter
, aParam
.send_start_time
);
110 WriteParam(aWriter
, aParam
.total_clip_nodes
);
111 WriteParam(aWriter
, aParam
.total_spatial_nodes
);
112 WriteParam(aWriter
, aParam
.cache_size
);
115 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
116 return ReadParam(aReader
, &aResult
->gecko_display_list_type
) &&
117 ReadParam(aReader
, &aResult
->builder_start_time
) &&
118 ReadParam(aReader
, &aResult
->builder_finish_time
) &&
119 ReadParam(aReader
, &aResult
->send_start_time
) &&
120 ReadParam(aReader
, &aResult
->total_clip_nodes
) &&
121 ReadParam(aReader
, &aResult
->total_spatial_nodes
) &&
122 ReadParam(aReader
, &aResult
->cache_size
);
127 struct ParamTraits
<mozilla::wr::IdNamespace
>
128 : public PlainOldDataSerializer
<mozilla::wr::IdNamespace
> {};
131 struct ParamTraits
<mozilla::wr::ImageKey
>
132 : public PlainOldDataSerializer
<mozilla::wr::ImageKey
> {};
135 struct ParamTraits
<mozilla::wr::BlobImageKey
>
136 : public PlainOldDataSerializer
<mozilla::wr::BlobImageKey
> {};
139 struct ParamTraits
<mozilla::wr::FontKey
>
140 : public PlainOldDataSerializer
<mozilla::wr::FontKey
> {};
143 struct ParamTraits
<mozilla::wr::FontInstanceKey
>
144 : public PlainOldDataSerializer
<mozilla::wr::FontInstanceKey
> {};
147 struct ParamTraits
<mozilla::wr::FontInstanceOptions
>
148 : public PlainOldDataSerializer
<mozilla::wr::FontInstanceOptions
> {};
151 struct ParamTraits
<mozilla::wr::FontInstancePlatformOptions
>
152 : public PlainOldDataSerializer
<mozilla::wr::FontInstancePlatformOptions
> {
156 struct ParamTraits
<mozilla::wr::ExternalImageId
>
157 : public PlainOldDataSerializer
<mozilla::wr::ExternalImageId
> {};
160 struct ParamTraits
<mozilla::wr::PipelineId
>
161 : public PlainOldDataSerializer
<mozilla::wr::PipelineId
> {};
164 struct ParamTraits
<mozilla::wr::ImageFormat
>
165 : public ContiguousEnumSerializer
<mozilla::wr::ImageFormat
,
166 mozilla::wr::ImageFormat::R8
,
167 mozilla::wr::ImageFormat::Sentinel
> {};
170 struct ParamTraits
<mozilla::wr::LayoutSize
>
171 : public PlainOldDataSerializer
<mozilla::wr::LayoutSize
> {};
174 struct ParamTraits
<mozilla::wr::LayoutRect
>
175 : public PlainOldDataSerializer
<mozilla::wr::LayoutRect
> {};
178 struct ParamTraits
<mozilla::wr::LayoutPoint
>
179 : public PlainOldDataSerializer
<mozilla::wr::LayoutPoint
> {};
182 struct ParamTraits
<mozilla::wr::ImageRendering
>
183 : public ContiguousEnumSerializer
<mozilla::wr::ImageRendering
,
184 mozilla::wr::ImageRendering::Auto
,
185 mozilla::wr::ImageRendering::Sentinel
> {};
188 struct ParamTraits
<mozilla::wr::MixBlendMode
>
189 : public ContiguousEnumSerializer
<mozilla::wr::MixBlendMode
,
190 mozilla::wr::MixBlendMode::Normal
,
191 mozilla::wr::MixBlendMode::Sentinel
> {};
194 struct ParamTraits
<mozilla::wr::WebRenderError
>
195 : public ContiguousEnumSerializer
<mozilla::wr::WebRenderError
,
196 mozilla::wr::WebRenderError::INITIALIZE
,
197 mozilla::wr::WebRenderError::Sentinel
> {};
200 struct ParamTraits
<mozilla::wr::MemoryReport
>
201 : public PlainOldDataSerializer
<mozilla::wr::MemoryReport
> {};
204 struct ParamTraits
<mozilla::wr::OpacityType
>
205 : public PlainOldDataSerializer
<mozilla::wr::OpacityType
> {};
208 struct ParamTraits
<mozilla::wr::ExternalImageKeyPair
>
209 : public PlainOldDataSerializer
<mozilla::wr::ExternalImageKeyPair
> {};
212 struct ParamTraits
<mozilla::wr::RenderReasons
>
213 : public PlainOldDataSerializer
<mozilla::wr::RenderReasons
> {};
217 #endif // GFX_WEBRENDERMESSAGEUTILS_H