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_ContentCompositorBridgeParent_h
8 #define mozilla_layers_ContentCompositorBridgeParent_h
9 
10 #include "mozilla/layers/CanvasTranslator.h"
11 #include "mozilla/layers/CompositorBridgeParent.h"
12 #include "mozilla/layers/CompositorThread.h"
13 #include "mozilla/UniquePtr.h"
14 
15 namespace mozilla {
16 namespace webgpu {
17 class PWebGPUParent;
18 }  // namespace webgpu
19 
20 namespace layers {
21 
22 class CompositorOptions;
23 
24 /**
25  * This class handles layer updates pushed directly from child processes to
26  * the compositor thread. It's associated with a CompositorBridgeParent on the
27  * compositor thread. While it uses the PCompositorBridge protocol to manage
28  * these updates, it doesn't actually drive compositing itself. For that it
29  * hands off work to the CompositorBridgeParent it's associated with.
30  */
31 class ContentCompositorBridgeParent final : public CompositorBridgeParentBase {
32   friend class CompositorBridgeParent;
33 
34  public:
ContentCompositorBridgeParent(CompositorManagerParent * aManager)35   explicit ContentCompositorBridgeParent(CompositorManagerParent* aManager)
36       : CompositorBridgeParentBase(aManager),
37         mNotifyAfterRemotePaint(false),
38         mDestroyCalled(false) {}
39 
40   void ActorDestroy(ActorDestroyReason aWhy) override;
41 
42   // FIXME/bug 774388: work out what shutdown protocol we need.
RecvInitialize(const LayersId & aRootLayerTreeId)43   mozilla::ipc::IPCResult RecvInitialize(
44       const LayersId& aRootLayerTreeId) override {
45     return IPC_FAIL_NO_REASON(this);
46   }
RecvWillClose()47   mozilla::ipc::IPCResult RecvWillClose() override { return IPC_OK(); }
RecvPause()48   mozilla::ipc::IPCResult RecvPause() override { return IPC_OK(); }
RecvRequestFxrOutput()49   mozilla::ipc::IPCResult RecvRequestFxrOutput() override {
50     return IPC_FAIL_NO_REASON(this);
51   }
RecvResume()52   mozilla::ipc::IPCResult RecvResume() override { return IPC_OK(); }
RecvResumeAsync()53   mozilla::ipc::IPCResult RecvResumeAsync() override { return IPC_OK(); }
54   mozilla::ipc::IPCResult RecvNotifyChildCreated(
55       const LayersId& child, CompositorOptions* aOptions) override;
56   mozilla::ipc::IPCResult RecvMapAndNotifyChildCreated(
57       const LayersId& child, const base::ProcessId& pid,
58       CompositorOptions* aOptions) override;
RecvNotifyChildRecreated(const LayersId & child,CompositorOptions * aOptions)59   mozilla::ipc::IPCResult RecvNotifyChildRecreated(
60       const LayersId& child, CompositorOptions* aOptions) override {
61     return IPC_FAIL_NO_REASON(this);
62   }
RecvAdoptChild(const LayersId & child)63   mozilla::ipc::IPCResult RecvAdoptChild(const LayersId& child) override {
64     return IPC_FAIL_NO_REASON(this);
65   }
RecvMakeSnapshot(const SurfaceDescriptor & aInSnapshot,const gfx::IntRect & aRect)66   mozilla::ipc::IPCResult RecvMakeSnapshot(const SurfaceDescriptor& aInSnapshot,
67                                            const gfx::IntRect& aRect) override {
68     return IPC_OK();
69   }
RecvFlushRendering()70   mozilla::ipc::IPCResult RecvFlushRendering() override { return IPC_OK(); }
RecvFlushRenderingAsync()71   mozilla::ipc::IPCResult RecvFlushRenderingAsync() override {
72     return IPC_OK();
73   }
RecvForcePresent()74   mozilla::ipc::IPCResult RecvForcePresent() override { return IPC_OK(); }
RecvWaitOnTransactionProcessed()75   mozilla::ipc::IPCResult RecvWaitOnTransactionProcessed() override {
76     return IPC_OK();
77   }
RecvNotifyRegionInvalidated(const nsIntRegion & aRegion)78   mozilla::ipc::IPCResult RecvNotifyRegionInvalidated(
79       const nsIntRegion& aRegion) override {
80     return IPC_OK();
81   }
RecvStartFrameTimeRecording(const int32_t & aBufferSize,uint32_t * aOutStartIndex)82   mozilla::ipc::IPCResult RecvStartFrameTimeRecording(
83       const int32_t& aBufferSize, uint32_t* aOutStartIndex) override {
84     return IPC_OK();
85   }
RecvStopFrameTimeRecording(const uint32_t & aStartIndex,nsTArray<float> * intervals)86   mozilla::ipc::IPCResult RecvStopFrameTimeRecording(
87       const uint32_t& aStartIndex, nsTArray<float>* intervals) override {
88     return IPC_OK();
89   }
90 
91   mozilla::ipc::IPCResult RecvCheckContentOnlyTDR(
92       const uint32_t& sequenceNum, bool* isContentOnlyTDR) override;
93 
RecvBeginRecording(const TimeStamp & aRecordingStart,BeginRecordingResolver && aResolve)94   mozilla::ipc::IPCResult RecvBeginRecording(
95       const TimeStamp& aRecordingStart,
96       BeginRecordingResolver&& aResolve) override {
97     aResolve(false);
98     return IPC_OK();
99   }
100 
RecvEndRecordingToDisk(EndRecordingToDiskResolver && aResolve)101   mozilla::ipc::IPCResult RecvEndRecordingToDisk(
102       EndRecordingToDiskResolver&& aResolve) override {
103     aResolve(false);
104     return IPC_OK();
105   }
106 
RecvEndRecordingToMemory(EndRecordingToMemoryResolver && aResolve)107   mozilla::ipc::IPCResult RecvEndRecordingToMemory(
108       EndRecordingToMemoryResolver&& aResolve) override {
109     aResolve(Nothing());
110     return IPC_OK();
111   }
112 
113   /**
114    * Tells this CompositorBridgeParent to send a message when the compositor has
115    * received the transaction.
116    */
117   mozilla::ipc::IPCResult RecvRequestNotifyAfterRemotePaint() override;
118 
119   PLayerTransactionParent* AllocPLayerTransactionParent(
120       const nsTArray<LayersBackend>& aBackendHints,
121       const LayersId& aId) override;
122 
123   bool DeallocPLayerTransactionParent(
124       PLayerTransactionParent* aLayers) override;
125 
126   void ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
127                            const TransactionInfo& aInfo,
128                            bool aHitTestUpdate) override;
129   void ScheduleComposite(LayerTransactionParent* aLayerTree) override;
130   void NotifyClearCachedResources(LayerTransactionParent* aLayerTree) override;
131   bool SetTestSampleTime(const LayersId& aId, const TimeStamp& aTime) override;
132   void LeaveTestMode(const LayersId& aId) override;
133   void ApplyAsyncProperties(LayerTransactionParent* aLayerTree,
134                             TransformsToSkip aSkip) override;
135   void SetTestAsyncScrollOffset(const LayersId& aLayersId,
136                                 const ScrollableLayerGuid::ViewID& aScrollId,
137                                 const CSSPoint& aPoint) override;
138   void SetTestAsyncZoom(const LayersId& aLayersId,
139                         const ScrollableLayerGuid::ViewID& aScrollId,
140                         const LayerToParentLayerScale& aZoom) override;
141   void FlushApzRepaints(const LayersId& aLayersId) override;
142   void GetAPZTestData(const LayersId& aLayersId,
143                       APZTestData* aOutData) override;
144   void GetFrameUniformity(const LayersId& aLayersId,
145                           FrameUniformityData* aOutData) override;
146   void SetConfirmedTargetAPZC(
147       const LayersId& aLayersId, const uint64_t& aInputBlockId,
148       nsTArray<ScrollableLayerGuid>&& aTargets) override;
149 
150   AsyncCompositionManager* GetCompositionManager(
151       LayerTransactionParent* aParent) override;
152 
153   already_AddRefed<dom::PWebGLParent> AllocPWebGLParent() override;
154 
155   // Use DidCompositeLocked if you already hold a lock on
156   // sIndirectLayerTreesLock; Otherwise use DidComposite, which would request
157   // the lock automatically.
158   void DidCompositeLocked(LayersId aId, const VsyncId& aVsyncId,
159                           TimeStamp& aCompositeStart, TimeStamp& aCompositeEnd);
160 
161   PTextureParent* AllocPTextureParent(
162       const SurfaceDescriptor& aSharedData, const ReadLockDescriptor& aReadLock,
163       const LayersBackend& aLayersBackend, const TextureFlags& aFlags,
164       const LayersId& aId, const uint64_t& aSerial,
165       const wr::MaybeExternalImageId& aExternalImageId) override;
166 
167   bool DeallocPTextureParent(PTextureParent* actor) override;
168 
169   mozilla::ipc::IPCResult RecvInitPCanvasParent(
170       Endpoint<PCanvasParent>&& aEndpoint) final;
171 
172   mozilla::ipc::IPCResult RecvReleasePCanvasParent() final;
173 
174   bool IsSameProcess() const override;
175 
AllocPCompositorWidgetParent(const CompositorWidgetInitData & aInitData)176   PCompositorWidgetParent* AllocPCompositorWidgetParent(
177       const CompositorWidgetInitData& aInitData) override {
178     // Not allowed.
179     return nullptr;
180   }
DeallocPCompositorWidgetParent(PCompositorWidgetParent * aActor)181   bool DeallocPCompositorWidgetParent(
182       PCompositorWidgetParent* aActor) override {
183     // Not allowed.
184     return false;
185   }
186 
187   PAPZCTreeManagerParent* AllocPAPZCTreeManagerParent(
188       const LayersId& aLayersId) override;
189   bool DeallocPAPZCTreeManagerParent(PAPZCTreeManagerParent* aActor) override;
190 
191   PAPZParent* AllocPAPZParent(const LayersId& aLayersId) override;
192   bool DeallocPAPZParent(PAPZParent* aActor) override;
193 
194   void UpdatePaintTime(LayerTransactionParent* aLayerTree,
195                        const TimeDuration& aPaintTime) override;
196   void RegisterPayloads(LayerTransactionParent* aLayerTree,
197                         const nsTArray<CompositionPayload>& aPayload) override;
198 
199   PWebRenderBridgeParent* AllocPWebRenderBridgeParent(
200       const wr::PipelineId& aPipelineId, const LayoutDeviceIntSize& aSize,
201       const WindowKind& aWindowKind) override;
202   bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override;
203 
204   webgpu::PWebGPUParent* AllocPWebGPUParent() override;
205   bool DeallocPWebGPUParent(webgpu::PWebGPUParent* aActor) override;
206 
207   void ObserveLayersUpdate(LayersId aLayersId, LayersObserverEpoch aEpoch,
208                            bool aActive) override;
209 
IsRemote()210   bool IsRemote() const override { return true; }
211 
212   UniquePtr<SurfaceDescriptor> LookupSurfaceDescriptorForClientTexture(
213       const int64_t aTextureId) final;
214 
215  private:
216   // Private destructor, to discourage deletion outside of Release():
217   virtual ~ContentCompositorBridgeParent();
218 
219   void DeferredDestroy();
220 
221   // There can be many CPCPs, and IPDL-generated code doesn't hold a
222   // reference to top-level actors.  So we hold a reference to
223   // ourself.  This is released (deferred) in ActorDestroy().
224   RefPtr<ContentCompositorBridgeParent> mSelfRef;
225 
226   // If true, we should send a RemotePaintIsReady message when the layer
227   // transaction is received
228   bool mNotifyAfterRemotePaint;
229   bool mDestroyCalled;
230 
231   RefPtr<CanvasTranslator> mCanvasTranslator;
232 };
233 
234 }  // namespace layers
235 }  // namespace mozilla
236 
237 #endif  // mozilla_layers_ContentCompositorBridgeParent_h
238