Bug 1803984 - Add tests for the interaction between speculative preloading and module...
[gecko.git] / gfx / layers / wr / WebRenderMessageUtils.h
blob40edf6676dff1006b3c953fb729883f234509464
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"
18 namespace IPC {
20 template <>
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) {
30 size_t length;
31 return ReadParam(aReader, &length) && aResult->Allocate(length) &&
32 aReader->ReadBytesInto(aResult->mData, length);
36 template <>
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);
57 template <>
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> {};
64 template <>
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);
70 switch (aParam.tag) {
71 case mozilla::wr::GeckoDisplayListType::Tag::None:
72 break;
73 case mozilla::wr::GeckoDisplayListType::Tag::Partial:
74 WriteParam(aWriter, aParam.partial._0);
75 break;
76 case mozilla::wr::GeckoDisplayListType::Tag::Full:
77 WriteParam(aWriter, aParam.full._0);
78 break;
79 default:
80 MOZ_RELEASE_ASSERT(false, "bad enum variant");
84 static bool Read(MessageReader* aReader, paramType* aResult) {
85 if (!ReadParam(aReader, &aResult->tag)) {
86 return false;
88 switch (aResult->tag) {
89 case mozilla::wr::GeckoDisplayListType::Tag::None:
90 return true;
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);
95 default:
96 MOZ_RELEASE_ASSERT(false, "bad enum variant");
101 template <>
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);
126 template <>
127 struct ParamTraits<mozilla::wr::IdNamespace>
128 : public PlainOldDataSerializer<mozilla::wr::IdNamespace> {};
130 template <>
131 struct ParamTraits<mozilla::wr::ImageKey>
132 : public PlainOldDataSerializer<mozilla::wr::ImageKey> {};
134 template <>
135 struct ParamTraits<mozilla::wr::BlobImageKey>
136 : public PlainOldDataSerializer<mozilla::wr::BlobImageKey> {};
138 template <>
139 struct ParamTraits<mozilla::wr::FontKey>
140 : public PlainOldDataSerializer<mozilla::wr::FontKey> {};
142 template <>
143 struct ParamTraits<mozilla::wr::FontInstanceKey>
144 : public PlainOldDataSerializer<mozilla::wr::FontInstanceKey> {};
146 template <>
147 struct ParamTraits<mozilla::wr::FontInstanceOptions>
148 : public PlainOldDataSerializer<mozilla::wr::FontInstanceOptions> {};
150 template <>
151 struct ParamTraits<mozilla::wr::FontInstancePlatformOptions>
152 : public PlainOldDataSerializer<mozilla::wr::FontInstancePlatformOptions> {
155 template <>
156 struct ParamTraits<mozilla::wr::ExternalImageId>
157 : public PlainOldDataSerializer<mozilla::wr::ExternalImageId> {};
159 template <>
160 struct ParamTraits<mozilla::wr::PipelineId>
161 : public PlainOldDataSerializer<mozilla::wr::PipelineId> {};
163 template <>
164 struct ParamTraits<mozilla::wr::ImageFormat>
165 : public ContiguousEnumSerializer<mozilla::wr::ImageFormat,
166 mozilla::wr::ImageFormat::R8,
167 mozilla::wr::ImageFormat::Sentinel> {};
169 template <>
170 struct ParamTraits<mozilla::wr::LayoutSize>
171 : public PlainOldDataSerializer<mozilla::wr::LayoutSize> {};
173 template <>
174 struct ParamTraits<mozilla::wr::LayoutRect>
175 : public PlainOldDataSerializer<mozilla::wr::LayoutRect> {};
177 template <>
178 struct ParamTraits<mozilla::wr::LayoutPoint>
179 : public PlainOldDataSerializer<mozilla::wr::LayoutPoint> {};
181 template <>
182 struct ParamTraits<mozilla::wr::ImageRendering>
183 : public ContiguousEnumSerializer<mozilla::wr::ImageRendering,
184 mozilla::wr::ImageRendering::Auto,
185 mozilla::wr::ImageRendering::Sentinel> {};
187 template <>
188 struct ParamTraits<mozilla::wr::MixBlendMode>
189 : public ContiguousEnumSerializer<mozilla::wr::MixBlendMode,
190 mozilla::wr::MixBlendMode::Normal,
191 mozilla::wr::MixBlendMode::Sentinel> {};
193 template <>
194 struct ParamTraits<mozilla::wr::WebRenderError>
195 : public ContiguousEnumSerializer<mozilla::wr::WebRenderError,
196 mozilla::wr::WebRenderError::INITIALIZE,
197 mozilla::wr::WebRenderError::Sentinel> {};
199 template <>
200 struct ParamTraits<mozilla::wr::MemoryReport>
201 : public PlainOldDataSerializer<mozilla::wr::MemoryReport> {};
203 template <>
204 struct ParamTraits<mozilla::wr::OpacityType>
205 : public PlainOldDataSerializer<mozilla::wr::OpacityType> {};
207 template <>
208 struct ParamTraits<mozilla::wr::ExternalImageKeyPair>
209 : public PlainOldDataSerializer<mozilla::wr::ExternalImageKeyPair> {};
211 template <>
212 struct ParamTraits<mozilla::wr::RenderReasons>
213 : public PlainOldDataSerializer<mozilla::wr::RenderReasons> {};
215 } // namespace IPC
217 #endif // GFX_WEBRENDERMESSAGEUTILS_H