/work/obj-fuzz/dist/include/mozilla/layers/WebRenderScrollData.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef GFX_WEBRENDERSCROLLDATA_H |
8 | | #define GFX_WEBRENDERSCROLLDATA_H |
9 | | |
10 | | #include <map> |
11 | | |
12 | | #include "chrome/common/ipc_message_utils.h" |
13 | | #include "FrameMetrics.h" |
14 | | #include "ipc/IPCMessageUtils.h" |
15 | | #include "LayersTypes.h" |
16 | | #include "mozilla/Attributes.h" |
17 | | #include "mozilla/GfxMessageUtils.h" |
18 | | #include "mozilla/layers/LayerAttributes.h" |
19 | | #include "mozilla/layers/LayersMessageUtils.h" |
20 | | #include "mozilla/layers/FocusTarget.h" |
21 | | #include "mozilla/Maybe.h" |
22 | | #include "nsTArrayForwardDeclare.h" |
23 | | |
24 | | class nsDisplayItem; |
25 | | |
26 | | namespace mozilla { |
27 | | |
28 | | struct ActiveScrolledRoot; |
29 | | |
30 | | namespace layers { |
31 | | |
32 | | class Layer; |
33 | | class WebRenderLayerManager; |
34 | | class WebRenderScrollData; |
35 | | |
36 | | // Data needed by APZ, per layer. One instance of this class is created for |
37 | | // each layer in the layer tree and sent over PWebRenderBridge to the APZ code. |
38 | | // Each WebRenderLayerScrollData is conceptually associated with an "owning" |
39 | | // WebRenderScrollData. |
40 | | class WebRenderLayerScrollData |
41 | | { |
42 | | public: |
43 | | WebRenderLayerScrollData(); // needed for IPC purposes |
44 | | ~WebRenderLayerScrollData(); |
45 | | |
46 | | void InitializeRoot(int32_t aDescendantCount); |
47 | | void Initialize(WebRenderScrollData& aOwner, |
48 | | nsDisplayItem* aItem, |
49 | | int32_t aDescendantCount, |
50 | | const ActiveScrolledRoot* aStopAtAsr, |
51 | | const Maybe<gfx::Matrix4x4>& aAncestorTransform); |
52 | | |
53 | | int32_t GetDescendantCount() const; |
54 | | size_t GetScrollMetadataCount() const; |
55 | | |
56 | | void AppendScrollMetadata(WebRenderScrollData& aOwner, |
57 | | const ScrollMetadata& aData); |
58 | | // Return the ScrollMetadata object that used to be on the original Layer |
59 | | // at the given index. Since we deduplicate the ScrollMetadata objects into |
60 | | // the array in the owning WebRenderScrollData object, we need to be passed |
61 | | // in a reference to that owner as well. |
62 | | const ScrollMetadata& GetScrollMetadata(const WebRenderScrollData& aOwner, |
63 | | size_t aIndex) const; |
64 | | |
65 | 0 | gfx::Matrix4x4 GetAncestorTransform() const { return mAncestorTransform; } |
66 | 0 | void SetTransform(const gfx::Matrix4x4& aTransform) { mTransform = aTransform; } |
67 | 0 | gfx::Matrix4x4 GetTransform() const { return mTransform; } |
68 | | CSSTransformMatrix GetTransformTyped() const; |
69 | 0 | void SetTransformIsPerspective(bool aTransformIsPerspective) { mTransformIsPerspective = aTransformIsPerspective; } |
70 | 0 | bool GetTransformIsPerspective() const { return mTransformIsPerspective; } |
71 | | |
72 | 0 | void AddEventRegions(const EventRegions& aRegions) { mEventRegions.OrWith(aRegions); } |
73 | 0 | EventRegions GetEventRegions() const { return mEventRegions; } |
74 | 0 | void SetEventRegionsOverride(const EventRegionsOverride& aOverride) { mEventRegionsOverride = aOverride; } |
75 | 0 | EventRegionsOverride GetEventRegionsOverride() const { return mEventRegionsOverride; } |
76 | | |
77 | 0 | const LayerIntRegion& GetVisibleRegion() const { return mVisibleRegion; } |
78 | 0 | void SetReferentId(LayersId aReferentId) { mReferentId = Some(aReferentId); } |
79 | 0 | Maybe<LayersId> GetReferentId() const { return mReferentId; } |
80 | | |
81 | 0 | void SetScrollbarData(const ScrollbarData& aData) { mScrollbarData = aData; } |
82 | 0 | const ScrollbarData& GetScrollbarData() const { return mScrollbarData; } |
83 | 0 | void SetScrollbarAnimationId(const uint64_t& aId) { mScrollbarAnimationId = aId; } |
84 | 0 | const uint64_t& GetScrollbarAnimationId() const { return mScrollbarAnimationId; } |
85 | | |
86 | 0 | void SetFixedPositionScrollContainerId(FrameMetrics::ViewID aId) { mFixedPosScrollContainerId = aId; } |
87 | 0 | FrameMetrics::ViewID GetFixedPositionScrollContainerId() const { return mFixedPosScrollContainerId; } |
88 | | |
89 | | void Dump(const WebRenderScrollData& aOwner) const; |
90 | | |
91 | | friend struct IPC::ParamTraits<WebRenderLayerScrollData>; |
92 | | |
93 | | private: |
94 | | // The number of descendants this layer has (not including the layer itself). |
95 | | // This is needed to reconstruct the depth-first layer tree traversal |
96 | | // efficiently. Leaf layers should always have 0 descendants. |
97 | | int32_t mDescendantCount; |
98 | | |
99 | | // Handles to the ScrollMetadata objects that were on this layer. The values |
100 | | // stored in this array are indices into the owning WebRenderScrollData's |
101 | | // mScrollMetadatas array. This indirection is used to deduplicate the |
102 | | // ScrollMetadata objects, since there is usually heavy duplication of them |
103 | | // within a layer tree. |
104 | | nsTArray<size_t> mScrollIds; |
105 | | |
106 | | // Various data that we collect from the Layer in Initialize(), serialize |
107 | | // over IPC, and use on the parent side in APZ. |
108 | | |
109 | | gfx::Matrix4x4 mAncestorTransform; |
110 | | gfx::Matrix4x4 mTransform; |
111 | | bool mTransformIsPerspective; |
112 | | EventRegions mEventRegions; |
113 | | LayerIntRegion mVisibleRegion; |
114 | | Maybe<LayersId> mReferentId; |
115 | | EventRegionsOverride mEventRegionsOverride; |
116 | | ScrollbarData mScrollbarData; |
117 | | uint64_t mScrollbarAnimationId; |
118 | | FrameMetrics::ViewID mFixedPosScrollContainerId; |
119 | | }; |
120 | | |
121 | | // Data needed by APZ, for the whole layer tree. One instance of this class |
122 | | // is created for each transaction sent over PWebRenderBridge. It is populated |
123 | | // with information from the WebRender layer tree on the client side and the |
124 | | // information is used by APZ on the parent side. |
125 | | class WebRenderScrollData |
126 | | { |
127 | | public: |
128 | | WebRenderScrollData(); |
129 | | explicit WebRenderScrollData(WebRenderLayerManager* aManager); |
130 | | ~WebRenderScrollData(); |
131 | | |
132 | | WebRenderLayerManager* GetManager() const; |
133 | | |
134 | | // Add the given ScrollMetadata if it doesn't already exist. Return an index |
135 | | // that can be used to look up the metadata later. |
136 | | size_t AddMetadata(const ScrollMetadata& aMetadata); |
137 | | // Add the provided WebRenderLayerScrollData and return the index that can |
138 | | // be used to look it up via GetLayerData. |
139 | | size_t AddLayerData(const WebRenderLayerScrollData& aData); |
140 | | |
141 | | size_t GetLayerCount() const; |
142 | | |
143 | | // Return a pointer to the scroll data at the given index. Use with caution, |
144 | | // as the pointer may be invalidated if this WebRenderScrollData is mutated. |
145 | | const WebRenderLayerScrollData* GetLayerData(size_t aIndex) const; |
146 | | |
147 | | const ScrollMetadata& GetScrollMetadata(size_t aIndex) const; |
148 | | Maybe<size_t> HasMetadataFor(const FrameMetrics::ViewID& aScrollId) const; |
149 | | |
150 | 0 | const FocusTarget& GetFocusTarget() const { return mFocusTarget; } |
151 | | void SetFocusTarget(const FocusTarget& aFocusTarget); |
152 | | |
153 | | void SetIsFirstPaint(); |
154 | | bool IsFirstPaint() const; |
155 | | void SetPaintSequenceNumber(uint32_t aPaintSequenceNumber); |
156 | | uint32_t GetPaintSequenceNumber() const; |
157 | | |
158 | | void ApplyUpdates(const ScrollUpdatesMap& aUpdates, |
159 | | uint32_t aPaintSequenceNumber); |
160 | | |
161 | | friend struct IPC::ParamTraits<WebRenderScrollData>; |
162 | | |
163 | | void Dump() const; |
164 | | |
165 | | private: |
166 | | // This is called by the ParamTraits implementation to rebuild mScrollIdMap |
167 | | // based on mScrollMetadatas |
168 | | bool RepopulateMap(); |
169 | | |
170 | | private: |
171 | | // Pointer back to the layer manager; if this is non-null, it will always be |
172 | | // valid, because the WebRenderLayerManager that created |this| will |
173 | | // outlive |this|. |
174 | | WebRenderLayerManager* MOZ_NON_OWNING_REF mManager; |
175 | | |
176 | | // Internal data structure used to maintain uniqueness of mScrollMetadatas. |
177 | | // This is not serialized/deserialized over IPC, but it is rebuilt on the |
178 | | // parent side when mScrollMetadatas is deserialized. So it should always be |
179 | | // valid on both the child and parent. |
180 | | // The key into this map is the scrollId of a ScrollMetadata, and the value is |
181 | | // an index into the mScrollMetadatas array. |
182 | | std::map<FrameMetrics::ViewID, size_t> mScrollIdMap; |
183 | | |
184 | | // A list of all the unique ScrollMetadata objects from the layer tree. Each |
185 | | // ScrollMetadata in this list must have a unique scroll id. |
186 | | nsTArray<ScrollMetadata> mScrollMetadatas; |
187 | | |
188 | | // A list of per-layer scroll data objects, generated via a depth-first, |
189 | | // pre-order, last-to-first traversal of the layer tree (i.e. a recursive |
190 | | // traversal where a node N first pushes itself, followed by its children in |
191 | | // last-to-first order). Each layer's scroll data object knows how many |
192 | | // descendants that layer had, which allows reconstructing the traversal on the |
193 | | // other side. |
194 | | nsTArray<WebRenderLayerScrollData> mLayerScrollData; |
195 | | |
196 | | // The focus information for this layer tree |
197 | | FocusTarget mFocusTarget; |
198 | | |
199 | | bool mIsFirstPaint; |
200 | | uint32_t mPaintSequenceNumber; |
201 | | }; |
202 | | |
203 | | } // namespace layers |
204 | | } // namespace mozilla |
205 | | |
206 | | namespace IPC { |
207 | | |
208 | | // When ScrollbarData is stored on the layer tree, it's part of |
209 | | // SimpleAttributes which itself uses PlainOldDataSerializer, so |
210 | | // we don't need a ParamTraits specialization for ScrollbarData |
211 | | // separately. Here, however, ScrollbarData is stored as part |
212 | | // of WebRenderLayerScrollData whose fields are serialized |
213 | | // individually, so we do. |
214 | | template<> |
215 | | struct ParamTraits<mozilla::layers::ScrollbarData> |
216 | | : public PlainOldDataSerializer<mozilla::layers::ScrollbarData> |
217 | | { }; |
218 | | |
219 | | template<> |
220 | | struct ParamTraits<mozilla::layers::WebRenderLayerScrollData> |
221 | | { |
222 | | typedef mozilla::layers::WebRenderLayerScrollData paramType; |
223 | | |
224 | | static void |
225 | | Write(Message* aMsg, const paramType& aParam) |
226 | 0 | { |
227 | 0 | WriteParam(aMsg, aParam.mDescendantCount); |
228 | 0 | WriteParam(aMsg, aParam.mScrollIds); |
229 | 0 | WriteParam(aMsg, aParam.mAncestorTransform); |
230 | 0 | WriteParam(aMsg, aParam.mTransform); |
231 | 0 | WriteParam(aMsg, aParam.mTransformIsPerspective); |
232 | 0 | WriteParam(aMsg, aParam.mEventRegions); |
233 | 0 | WriteParam(aMsg, aParam.mVisibleRegion); |
234 | 0 | WriteParam(aMsg, aParam.mReferentId); |
235 | 0 | WriteParam(aMsg, aParam.mEventRegionsOverride); |
236 | 0 | WriteParam(aMsg, aParam.mScrollbarData); |
237 | 0 | WriteParam(aMsg, aParam.mScrollbarAnimationId); |
238 | 0 | WriteParam(aMsg, aParam.mFixedPosScrollContainerId); |
239 | 0 | } |
240 | | |
241 | | static bool |
242 | | Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
243 | 0 | { |
244 | 0 | return ReadParam(aMsg, aIter, &aResult->mDescendantCount) |
245 | 0 | && ReadParam(aMsg, aIter, &aResult->mScrollIds) |
246 | 0 | && ReadParam(aMsg, aIter, &aResult->mAncestorTransform) |
247 | 0 | && ReadParam(aMsg, aIter, &aResult->mTransform) |
248 | 0 | && ReadParam(aMsg, aIter, &aResult->mTransformIsPerspective) |
249 | 0 | && ReadParam(aMsg, aIter, &aResult->mEventRegions) |
250 | 0 | && ReadParam(aMsg, aIter, &aResult->mVisibleRegion) |
251 | 0 | && ReadParam(aMsg, aIter, &aResult->mReferentId) |
252 | 0 | && ReadParam(aMsg, aIter, &aResult->mEventRegionsOverride) |
253 | 0 | && ReadParam(aMsg, aIter, &aResult->mScrollbarData) |
254 | 0 | && ReadParam(aMsg, aIter, &aResult->mScrollbarAnimationId) |
255 | 0 | && ReadParam(aMsg, aIter, &aResult->mFixedPosScrollContainerId); |
256 | 0 | } |
257 | | }; |
258 | | |
259 | | template<> |
260 | | struct ParamTraits<mozilla::layers::WebRenderScrollData> |
261 | | { |
262 | | typedef mozilla::layers::WebRenderScrollData paramType; |
263 | | |
264 | | static void |
265 | | Write(Message* aMsg, const paramType& aParam) |
266 | 0 | { |
267 | 0 | WriteParam(aMsg, aParam.mScrollMetadatas); |
268 | 0 | WriteParam(aMsg, aParam.mLayerScrollData); |
269 | 0 | WriteParam(aMsg, aParam.mFocusTarget); |
270 | 0 | WriteParam(aMsg, aParam.mIsFirstPaint); |
271 | 0 | WriteParam(aMsg, aParam.mPaintSequenceNumber); |
272 | 0 | } |
273 | | |
274 | | static bool |
275 | | Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
276 | 0 | { |
277 | 0 | return ReadParam(aMsg, aIter, &aResult->mScrollMetadatas) |
278 | 0 | && ReadParam(aMsg, aIter, &aResult->mLayerScrollData) |
279 | 0 | && ReadParam(aMsg, aIter, &aResult->mFocusTarget) |
280 | 0 | && ReadParam(aMsg, aIter, &aResult->mIsFirstPaint) |
281 | 0 | && ReadParam(aMsg, aIter, &aResult->mPaintSequenceNumber) |
282 | 0 | && aResult->RepopulateMap(); |
283 | 0 | } |
284 | | }; |
285 | | |
286 | | } // namespace IPC |
287 | | |
288 | | #endif /* GFX_WEBRENDERSCROLLDATA_H */ |