/work/obj-fuzz/dist/include/mozilla/layers/WebRenderBridgeParent.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 mozilla_layers_WebRenderBridgeParent_h |
8 | | #define mozilla_layers_WebRenderBridgeParent_h |
9 | | |
10 | | #include <unordered_map> |
11 | | #include <unordered_set> |
12 | | |
13 | | #include "CompositableHost.h" // for CompositableHost, ImageCompositeNotificationInfo |
14 | | #include "GLContextProvider.h" |
15 | | #include "mozilla/layers/CompositableTransactionParent.h" |
16 | | #include "mozilla/layers/CompositorVsyncSchedulerOwner.h" |
17 | | #include "mozilla/layers/PWebRenderBridgeParent.h" |
18 | | #include "mozilla/Maybe.h" |
19 | | #include "mozilla/webrender/WebRenderTypes.h" |
20 | | #include "mozilla/webrender/WebRenderAPI.h" |
21 | | #include "nsTArrayForwardDeclare.h" |
22 | | |
23 | | namespace mozilla { |
24 | | |
25 | | namespace gl { |
26 | | class GLContext; |
27 | | } |
28 | | |
29 | | namespace widget { |
30 | | class CompositorWidget; |
31 | | } |
32 | | |
33 | | namespace wr { |
34 | | class WebRenderAPI; |
35 | | } |
36 | | |
37 | | namespace layers { |
38 | | |
39 | | class Compositor; |
40 | | class CompositorAnimationStorage; |
41 | | class CompositorBridgeParentBase; |
42 | | class CompositorVsyncScheduler; |
43 | | class AsyncImagePipelineManager; |
44 | | class WebRenderImageHost; |
45 | | |
46 | | class WebRenderBridgeParent final : public PWebRenderBridgeParent |
47 | | , public CompositorVsyncSchedulerOwner |
48 | | , public CompositableParentManager |
49 | | , public layers::FrameRecorder |
50 | | { |
51 | | public: |
52 | | WebRenderBridgeParent(CompositorBridgeParentBase* aCompositorBridge, |
53 | | const wr::PipelineId& aPipelineId, |
54 | | widget::CompositorWidget* aWidget, |
55 | | CompositorVsyncScheduler* aScheduler, |
56 | | RefPtr<wr::WebRenderAPI>&& aApi, |
57 | | RefPtr<AsyncImagePipelineManager>&& aImageMgr, |
58 | | RefPtr<CompositorAnimationStorage>&& aAnimStorage, |
59 | | TimeDuration aVsyncRate); |
60 | | |
61 | | static WebRenderBridgeParent* CreateDestroyed(const wr::PipelineId& aPipelineId); |
62 | | |
63 | 0 | wr::PipelineId PipelineId() { return mPipelineId; } |
64 | 0 | already_AddRefed<wr::WebRenderAPI> GetWebRenderAPI() { return do_AddRef(mApi); } |
65 | 0 | AsyncImagePipelineManager* AsyncImageManager() { return mAsyncImageManager; } |
66 | 0 | CompositorVsyncScheduler* CompositorScheduler() { return mCompositorScheduler.get(); } |
67 | | |
68 | | mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle, |
69 | | const TextureInfo& aInfo) override; |
70 | | mozilla::ipc::IPCResult RecvReleaseCompositable(const CompositableHandle& aHandle) override; |
71 | | |
72 | | mozilla::ipc::IPCResult RecvCreate(const gfx::IntSize& aSize) override; |
73 | | mozilla::ipc::IPCResult RecvShutdown() override; |
74 | | mozilla::ipc::IPCResult RecvShutdownSync() override; |
75 | | mozilla::ipc::IPCResult RecvDeleteCompositorAnimations(InfallibleTArray<uint64_t>&& aIds) override; |
76 | | mozilla::ipc::IPCResult RecvUpdateResources(nsTArray<OpUpdateResource>&& aUpdates, |
77 | | nsTArray<RefCountedShmem>&& aSmallShmems, |
78 | | nsTArray<ipc::Shmem>&& aLargeShmems) override; |
79 | | mozilla::ipc::IPCResult RecvSetDisplayList(const gfx::IntSize& aSize, |
80 | | InfallibleTArray<WebRenderParentCommand>&& aCommands, |
81 | | InfallibleTArray<OpDestroy>&& aToDestroy, |
82 | | const uint64_t& aFwdTransactionId, |
83 | | const TransactionId& aTransactionId, |
84 | | const wr::LayoutSize& aContentSize, |
85 | | ipc::ByteBuf&& dl, |
86 | | const wr::BuiltDisplayListDescriptor& dlDesc, |
87 | | const WebRenderScrollData& aScrollData, |
88 | | nsTArray<OpUpdateResource>&& aResourceUpdates, |
89 | | nsTArray<RefCountedShmem>&& aSmallShmems, |
90 | | nsTArray<ipc::Shmem>&& aLargeShmems, |
91 | | const wr::IdNamespace& aIdNamespace, |
92 | | const bool& aContainsSVGGroup, |
93 | | const TimeStamp& aRefreshStartTime, |
94 | | const TimeStamp& aTxnStartTime, |
95 | | const TimeStamp& aFwdTime) override; |
96 | | mozilla::ipc::IPCResult RecvEmptyTransaction(const FocusTarget& aFocusTarget, |
97 | | const ScrollUpdatesMap& aUpdates, |
98 | | const uint32_t& aPaintSequenceNumber, |
99 | | InfallibleTArray<WebRenderParentCommand>&& aCommands, |
100 | | InfallibleTArray<OpDestroy>&& aToDestroy, |
101 | | const uint64_t& aFwdTransactionId, |
102 | | const TransactionId& aTransactionId, |
103 | | const wr::IdNamespace& aIdNamespace, |
104 | | const TimeStamp& aRefreshStartTime, |
105 | | const TimeStamp& aTxnStartTime, |
106 | | const TimeStamp& aFwdTime) override; |
107 | | mozilla::ipc::IPCResult RecvSetFocusTarget(const FocusTarget& aFocusTarget) override; |
108 | | mozilla::ipc::IPCResult RecvParentCommands(nsTArray<WebRenderParentCommand>&& commands) override; |
109 | | mozilla::ipc::IPCResult RecvGetSnapshot(PTextureParent* aTexture) override; |
110 | | |
111 | | mozilla::ipc::IPCResult RecvSetLayersObserverEpoch(const LayersObserverEpoch& aChildEpoch) override; |
112 | | |
113 | | mozilla::ipc::IPCResult RecvClearCachedResources() override; |
114 | | mozilla::ipc::IPCResult RecvScheduleComposite() override; |
115 | | mozilla::ipc::IPCResult RecvCapture() override; |
116 | | mozilla::ipc::IPCResult RecvSyncWithCompositor() override; |
117 | | |
118 | | mozilla::ipc::IPCResult RecvSetConfirmedTargetAPZC(const uint64_t& aBlockId, |
119 | | nsTArray<ScrollableLayerGuid>&& aTargets) override; |
120 | | |
121 | | mozilla::ipc::IPCResult RecvSetTestSampleTime(const TimeStamp& aTime) override; |
122 | | mozilla::ipc::IPCResult RecvLeaveTestMode() override; |
123 | | mozilla::ipc::IPCResult RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId, |
124 | | OMTAValue* aValue) override; |
125 | | mozilla::ipc::IPCResult RecvSetAsyncScrollOffset(const FrameMetrics::ViewID& aScrollId, |
126 | | const float& aX, |
127 | | const float& aY) override; |
128 | | mozilla::ipc::IPCResult RecvSetAsyncZoom(const FrameMetrics::ViewID& aScrollId, |
129 | | const float& aZoom) override; |
130 | | mozilla::ipc::IPCResult RecvFlushApzRepaints() override; |
131 | | mozilla::ipc::IPCResult RecvGetAPZTestData(APZTestData* data) override; |
132 | | |
133 | | void ActorDestroy(ActorDestroyReason aWhy) override; |
134 | | |
135 | | void Pause(); |
136 | | bool Resume(); |
137 | | |
138 | | void Destroy(); |
139 | | |
140 | | // CompositorVsyncSchedulerOwner |
141 | 0 | bool IsPendingComposite() override { return false; } |
142 | 0 | void FinishPendingComposite() override { } |
143 | | void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override; |
144 | | |
145 | | // CompositableParentManager |
146 | | bool IsSameProcess() const override; |
147 | | base::ProcessId GetChildProcessId() override; |
148 | | void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override; |
149 | | void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override; |
150 | | void SendPendingAsyncMessages() override; |
151 | | void SetAboutToSendAsyncMessages() override; |
152 | | |
153 | | void HoldPendingTransactionId(const wr::Epoch& aWrEpoch, |
154 | | TransactionId aTransactionId, |
155 | | bool aContainsSVGGroup, |
156 | | const TimeStamp& aRefreshStartTime, |
157 | | const TimeStamp& aTxnStartTime, |
158 | | const TimeStamp& aFwdTime, |
159 | | const bool aUseForTelemetry = true); |
160 | | TransactionId LastPendingTransactionId(); |
161 | | TransactionId FlushTransactionIdsForEpoch(const wr::Epoch& aEpoch, const TimeStamp& aEndTime); |
162 | | |
163 | | TextureFactoryIdentifier GetTextureFactoryIdentifier(); |
164 | | |
165 | | void ExtractImageCompositeNotifications(nsTArray<ImageCompositeNotificationInfo>* aNotifications); |
166 | | |
167 | | wr::IdNamespace GetIdNamespace() |
168 | 0 | { |
169 | 0 | return mIdNamespace; |
170 | 0 | } |
171 | | |
172 | | void FlushRendering(bool aWaitForPresent = true); |
173 | | |
174 | | /** |
175 | | * Schedule generating WebRender frame definitely at next composite timing. |
176 | | * |
177 | | * WebRenderBridgeParent uses composite timing to check if there is an update |
178 | | * to AsyncImagePipelines. If there is no update, WebRenderBridgeParent skips |
179 | | * to generate frame. If we need to generate new frame at next composite timing, |
180 | | * call this method. |
181 | | * |
182 | | * Call CompositorVsyncScheduler::ScheduleComposition() directly, if we just |
183 | | * want to trigger AsyncImagePipelines update checks. |
184 | | */ |
185 | | void ScheduleGenerateFrame(); |
186 | | |
187 | | wr::Epoch UpdateWebRender(CompositorVsyncScheduler* aScheduler, |
188 | | wr::WebRenderAPI* aApi, |
189 | | AsyncImagePipelineManager* aImageMgr, |
190 | | CompositorAnimationStorage* aAnimStorage, |
191 | | const TextureFactoryIdentifier& aTextureFactoryIdentifier); |
192 | | |
193 | | void RemoveEpochDataPriorTo(const wr::Epoch& aRenderedEpoch); |
194 | | |
195 | | private: |
196 | | explicit WebRenderBridgeParent(const wr::PipelineId& aPipelineId); |
197 | | virtual ~WebRenderBridgeParent(); |
198 | | |
199 | | void UpdateAPZFocusState(const FocusTarget& aFocus); |
200 | | void UpdateAPZScrollData(const wr::Epoch& aEpoch, WebRenderScrollData&& aData); |
201 | | void UpdateAPZScrollOffsets(ScrollUpdatesMap&& aUpdates, |
202 | | uint32_t aPaintSequenceNumber); |
203 | | |
204 | | bool UpdateResources(const nsTArray<OpUpdateResource>& aResourceUpdates, |
205 | | const nsTArray<RefCountedShmem>& aSmallShmems, |
206 | | const nsTArray<ipc::Shmem>& aLargeShmems, |
207 | | wr::TransactionBuilder& aUpdates); |
208 | | bool AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey, |
209 | | wr::TransactionBuilder& aResources); |
210 | | bool UpdateExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey, |
211 | | const ImageIntRect& aDirtyRect, |
212 | | wr::TransactionBuilder& aResources); |
213 | | |
214 | | bool PushExternalImageForTexture(wr::ExternalImageId aExtId, |
215 | | wr::ImageKey aKey, |
216 | | TextureHost* aTexture, |
217 | | bool aIsUpdate, |
218 | | wr::TransactionBuilder& aResources); |
219 | | |
220 | | void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineIds, |
221 | | const CompositableHandle& aHandle, |
222 | | const bool& aAsync, |
223 | | wr::TransactionBuilder& aTxn); |
224 | | void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId, |
225 | | wr::TransactionBuilder& aTxn); |
226 | | |
227 | | void RemoveExternalImageId(const ExternalImageId& aImageId); |
228 | | void ReleaseTextureOfImage(const wr::ImageKey& aKey); |
229 | | |
230 | | LayersId GetLayersId() const; |
231 | | bool ProcessWebRenderParentCommands(const InfallibleTArray<WebRenderParentCommand>& aCommands, |
232 | | wr::TransactionBuilder& aTxn); |
233 | | |
234 | | void ClearResources(); |
235 | | bool ShouldParentObserveEpoch(); |
236 | | mozilla::ipc::IPCResult HandleShutdown(); |
237 | | |
238 | | // Returns true if there is any animation (including animations in delay |
239 | | // phase). |
240 | | bool AdvanceAnimations(); |
241 | | bool SampleAnimations(nsTArray<wr::WrOpacityProperty>& aOpacityArray, |
242 | | nsTArray<wr::WrTransformProperty>& aTransformArray); |
243 | | |
244 | | bool IsRootWebRenderBridgeParent() const; |
245 | | |
246 | | CompositorBridgeParent* GetRootCompositorBridgeParent() const; |
247 | | |
248 | | RefPtr<WebRenderBridgeParent> GetRootWebRenderBridgeParent() const; |
249 | | |
250 | | // Tell APZ what the subsequent sampling's timestamp should be. |
251 | | void SetAPZSampleTime(); |
252 | | |
253 | | wr::Epoch GetNextWrEpoch(); |
254 | | |
255 | | void FlushSceneBuilds(); |
256 | | void FlushFrameGeneration(); |
257 | | void FlushFramePresentation(); |
258 | | |
259 | | void MaybeGenerateFrame(bool aForceGenerateFrame); |
260 | | |
261 | | private: |
262 | | struct PendingTransactionId { |
263 | | PendingTransactionId(const wr::Epoch& aEpoch, |
264 | | TransactionId aId, |
265 | | bool aContainsSVGGroup, |
266 | | const TimeStamp& aRefreshStartTime, |
267 | | const TimeStamp& aTxnStartTime, |
268 | | const TimeStamp& aFwdTime, |
269 | | const bool aUseForTelemetry) |
270 | | : mEpoch(aEpoch) |
271 | | , mId(aId) |
272 | | , mRefreshStartTime(aRefreshStartTime) |
273 | | , mTxnStartTime(aTxnStartTime) |
274 | | , mFwdTime(aFwdTime) |
275 | | , mContainsSVGGroup(aContainsSVGGroup) |
276 | | , mUseForTelemetry(aUseForTelemetry) |
277 | 0 | {} |
278 | | wr::Epoch mEpoch; |
279 | | TransactionId mId; |
280 | | TimeStamp mRefreshStartTime; |
281 | | TimeStamp mTxnStartTime; |
282 | | TimeStamp mFwdTime; |
283 | | bool mContainsSVGGroup; |
284 | | bool mUseForTelemetry; |
285 | | }; |
286 | | |
287 | | struct CompositorAnimationIdsForEpoch { |
288 | | CompositorAnimationIdsForEpoch(const wr::Epoch& aEpoch, InfallibleTArray<uint64_t>&& aIds) |
289 | | : mEpoch(aEpoch) |
290 | | , mIds(std::move(aIds)) |
291 | 0 | { |
292 | 0 | } |
293 | | |
294 | | wr::Epoch mEpoch; |
295 | | InfallibleTArray<uint64_t> mIds; |
296 | | }; |
297 | | |
298 | | CompositorBridgeParentBase* MOZ_NON_OWNING_REF mCompositorBridge; |
299 | | wr::PipelineId mPipelineId; |
300 | | RefPtr<widget::CompositorWidget> mWidget; |
301 | | RefPtr<wr::WebRenderAPI> mApi; |
302 | | RefPtr<AsyncImagePipelineManager> mAsyncImageManager; |
303 | | RefPtr<CompositorVsyncScheduler> mCompositorScheduler; |
304 | | RefPtr<CompositorAnimationStorage> mAnimStorage; |
305 | | // mActiveAnimations is used to avoid leaking animations when WebRenderBridgeParent is |
306 | | // destroyed abnormally and Tab move between different windows. |
307 | | std::unordered_set<uint64_t> mActiveAnimations; |
308 | | std::unordered_map<uint64_t, RefPtr<WebRenderImageHost>> mAsyncCompositables; |
309 | | std::unordered_map<uint64_t, CompositableTextureHostRef> mTextureHosts; |
310 | | std::unordered_set<uint64_t> mSharedSurfaceIds; |
311 | | |
312 | | TimeDuration mVsyncRate; |
313 | | TimeStamp mPreviousFrameTimeStamp; |
314 | | // These fields keep track of the latest layer observer epoch values in the child and the |
315 | | // parent. mChildLayersObserverEpoch is the latest epoch value received from the child. |
316 | | // mParentLayersObserverEpoch is the latest epoch value that we have told TabParent about |
317 | | // (via ObserveLayerUpdate). |
318 | | LayersObserverEpoch mChildLayersObserverEpoch; |
319 | | LayersObserverEpoch mParentLayersObserverEpoch; |
320 | | |
321 | | std::queue<PendingTransactionId> mPendingTransactionIds; |
322 | | std::queue<CompositorAnimationIdsForEpoch> mCompositorAnimationsToDelete; |
323 | | wr::Epoch mWrEpoch; |
324 | | wr::IdNamespace mIdNamespace; |
325 | | |
326 | | bool mPaused; |
327 | | bool mDestroyed; |
328 | | bool mReceivedDisplayList; |
329 | | }; |
330 | | |
331 | | } // namespace layers |
332 | | } // namespace mozilla |
333 | | |
334 | | #endif // mozilla_layers_WebRenderBridgeParent_h |