/work/obj-fuzz/dist/include/mozilla/layers/LayerTransactionParent.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_LAYERTRANSACTIONPARENT_H |
8 | | #define MOZILLA_LAYERS_LAYERTRANSACTIONPARENT_H |
9 | | |
10 | | #include <stddef.h> // for size_t |
11 | | #include <stdint.h> // for uint64_t, uint32_t |
12 | | #include "CompositableTransactionParent.h" |
13 | | #include "mozilla/Attributes.h" // for override |
14 | | #include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc |
15 | | #include "mozilla/layers/PLayerTransactionParent.h" |
16 | | #include "nsRefPtrHashtable.h" |
17 | | #include "nsTArrayForwardDeclare.h" // for InfallibleTArray |
18 | | |
19 | | namespace mozilla { |
20 | | |
21 | | namespace ipc { |
22 | | class Shmem; |
23 | | } // namespace ipc |
24 | | |
25 | | namespace layout { |
26 | | class RenderFrameParent; |
27 | | } // namespace layout |
28 | | |
29 | | namespace layers { |
30 | | |
31 | | class Layer; |
32 | | class HostLayerManager; |
33 | | class ShadowLayerParent; |
34 | | class CompositableParent; |
35 | | class CompositorAnimationStorage; |
36 | | class CompositorBridgeParentBase; |
37 | | |
38 | | class LayerTransactionParent final : public PLayerTransactionParent, |
39 | | public CompositableParentManager, |
40 | | public ShmemAllocator |
41 | | { |
42 | | typedef mozilla::layout::RenderFrameParent RenderFrameParent; |
43 | | typedef InfallibleTArray<Edit> EditArray; |
44 | | typedef InfallibleTArray<OpDestroy> OpDestroyArray; |
45 | | typedef InfallibleTArray<PluginWindowData> PluginsArray; |
46 | | |
47 | | public: |
48 | | LayerTransactionParent(HostLayerManager* aManager, |
49 | | CompositorBridgeParentBase* aBridge, |
50 | | CompositorAnimationStorage* aAnimStorage, |
51 | | LayersId aId, |
52 | | TimeDuration aVsyncRate); |
53 | | |
54 | | protected: |
55 | | ~LayerTransactionParent(); |
56 | | |
57 | | public: |
58 | | void Destroy(); |
59 | | |
60 | | void SetLayerManager(HostLayerManager* aLayerManager, CompositorAnimationStorage* aAnimStorage); |
61 | | |
62 | | LayersId GetId() const { return mId; } |
63 | | Layer* GetRoot() const { return mRoot; } |
64 | | |
65 | | LayersObserverEpoch GetChildEpoch() const { return mChildEpoch; } |
66 | | bool ShouldParentObserveEpoch(); |
67 | | |
68 | | ShmemAllocator* AsShmemAllocator() override { return this; } |
69 | | |
70 | | bool AllocShmem(size_t aSize, |
71 | | ipc::SharedMemory::SharedMemoryType aType, |
72 | | ipc::Shmem* aShmem) override; |
73 | | |
74 | | bool AllocUnsafeShmem(size_t aSize, |
75 | | ipc::SharedMemory::SharedMemoryType aType, |
76 | | ipc::Shmem* aShmem) override; |
77 | | |
78 | | void DeallocShmem(ipc::Shmem& aShmem) override; |
79 | | |
80 | | bool IsSameProcess() const override; |
81 | | |
82 | 0 | const TransactionId& GetPendingTransactionId() { return mPendingTransaction; } |
83 | | void SetPendingTransactionId(TransactionId aId, |
84 | | const TimeStamp& aRefreshStartTime, |
85 | | const TimeStamp& aTxnStartTime, |
86 | | const TimeStamp& aFwdTime) |
87 | | { |
88 | | mPendingTransaction = aId; |
89 | | mRefreshStartTime = aRefreshStartTime; |
90 | | mTxnStartTime = aTxnStartTime; |
91 | | mFwdTime = aFwdTime; |
92 | | } |
93 | | TransactionId FlushTransactionId(TimeStamp& aCompositeEnd); |
94 | | |
95 | | // CompositableParentManager |
96 | | void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override; |
97 | | |
98 | | void SendPendingAsyncMessages() override; |
99 | | |
100 | | void SetAboutToSendAsyncMessages() override; |
101 | | |
102 | | void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override; |
103 | | |
104 | | base::ProcessId GetChildProcessId() override |
105 | | { |
106 | | return OtherPid(); |
107 | | } |
108 | | |
109 | | protected: |
110 | | mozilla::ipc::IPCResult RecvShutdown() override; |
111 | | mozilla::ipc::IPCResult RecvShutdownSync() override; |
112 | | |
113 | | mozilla::ipc::IPCResult RecvPaintTime(const TransactionId& aTransactionId, |
114 | | const TimeDuration& aPaintTime) override; |
115 | | |
116 | | mozilla::ipc::IPCResult RecvUpdate(const TransactionInfo& aInfo) override; |
117 | | |
118 | | mozilla::ipc::IPCResult RecvSetLayersObserverEpoch(const LayersObserverEpoch& aChildEpoch) override; |
119 | | mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle, |
120 | | const TextureInfo& aInfo) override; |
121 | | mozilla::ipc::IPCResult RecvReleaseLayer(const LayerHandle& aHandle) override; |
122 | | mozilla::ipc::IPCResult RecvReleaseCompositable(const CompositableHandle& aHandle) override; |
123 | | |
124 | | mozilla::ipc::IPCResult RecvClearCachedResources() override; |
125 | | mozilla::ipc::IPCResult RecvScheduleComposite() override; |
126 | | mozilla::ipc::IPCResult RecvSetTestSampleTime(const TimeStamp& aTime) override; |
127 | | mozilla::ipc::IPCResult RecvLeaveTestMode() override; |
128 | | mozilla::ipc::IPCResult RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId, |
129 | | OMTAValue* aValue) override; |
130 | | mozilla::ipc::IPCResult RecvGetTransform(const LayerHandle& aHandle, |
131 | | MaybeTransform* aTransform) override; |
132 | | mozilla::ipc::IPCResult RecvSetAsyncScrollOffset(const FrameMetrics::ViewID& aId, |
133 | | const float& aX, const float& aY) override; |
134 | | mozilla::ipc::IPCResult RecvSetAsyncZoom(const FrameMetrics::ViewID& aId, |
135 | | const float& aValue) override; |
136 | | mozilla::ipc::IPCResult RecvFlushApzRepaints() override; |
137 | | mozilla::ipc::IPCResult RecvGetAPZTestData(APZTestData* aOutData) override; |
138 | | mozilla::ipc::IPCResult RecvRequestProperty(const nsString& aProperty, float* aValue) override; |
139 | | mozilla::ipc::IPCResult RecvSetConfirmedTargetAPZC(const uint64_t& aBlockId, |
140 | | nsTArray<ScrollableLayerGuid>&& aTargets) override; |
141 | | mozilla::ipc::IPCResult RecvRecordPaintTimes(const PaintTiming& aTiming) override; |
142 | | mozilla::ipc::IPCResult RecvGetTextureFactoryIdentifier(TextureFactoryIdentifier* aIdentifier) override; |
143 | | |
144 | | bool SetLayerAttributes(const OpSetLayerAttributes& aOp); |
145 | | |
146 | | void ActorDestroy(ActorDestroyReason why) override; |
147 | | |
148 | | template <typename T> |
149 | | bool BindLayer(const RefPtr<Layer>& aLayer, const T& aCreateOp) { |
150 | | return BindLayerToHandle(aLayer, aCreateOp.layer()); |
151 | | } |
152 | | |
153 | | bool BindLayerToHandle(RefPtr<Layer> aLayer, const LayerHandle& aHandle); |
154 | | |
155 | | Layer* AsLayer(const LayerHandle& aLayer); |
156 | | |
157 | | bool Attach(Layer* aLayer, CompositableHost* aCompositable, bool aIsAsyncVideo); |
158 | | |
159 | | void AddIPDLReference() { |
160 | | MOZ_ASSERT(mIPCOpen == false); |
161 | | mIPCOpen = true; |
162 | | AddRef(); |
163 | | } |
164 | | void ReleaseIPDLReference() { |
165 | | MOZ_ASSERT(mIPCOpen == true); |
166 | | mIPCOpen = false; |
167 | | Release(); |
168 | | } |
169 | | friend class CompositorBridgeParent; |
170 | | friend class CrossProcessCompositorBridgeParent; |
171 | | friend class layout::RenderFrameParent; |
172 | | |
173 | | private: |
174 | | // This is a function so we can log or breakpoint on why hit |
175 | | // testing tree changes are made. |
176 | | void UpdateHitTestingTree(Layer* aLayer, const char* aWhy) { |
177 | | mUpdateHitTestingTree = true; |
178 | | } |
179 | | |
180 | | private: |
181 | | RefPtr<HostLayerManager> mLayerManager; |
182 | | CompositorBridgeParentBase* mCompositorBridge; |
183 | | RefPtr<CompositorAnimationStorage> mAnimStorage; |
184 | | |
185 | | // Hold the root because it might be grafted under various |
186 | | // containers in the "real" layer tree |
187 | | RefPtr<Layer> mRoot; |
188 | | |
189 | | // Mapping from LayerHandles to Layers. |
190 | | nsRefPtrHashtable<nsUint64HashKey, Layer> mLayerMap; |
191 | | |
192 | | LayersId mId; |
193 | | |
194 | | // These fields keep track of the latest epoch values in the child and the |
195 | | // parent. mChildEpoch is the latest epoch value received from the child. |
196 | | // mParentEpoch is the latest epoch value that we have told TabParent about |
197 | | // (via ObserveLayerUpdate). |
198 | | LayersObserverEpoch mChildEpoch; |
199 | | LayersObserverEpoch mParentEpoch; |
200 | | |
201 | | TimeDuration mVsyncRate; |
202 | | |
203 | | TransactionId mPendingTransaction; |
204 | | TimeStamp mRefreshStartTime; |
205 | | TimeStamp mTxnStartTime; |
206 | | TimeStamp mFwdTime; |
207 | | |
208 | | // When the widget/frame/browser stuff in this process begins its |
209 | | // destruction process, we need to Disconnect() all the currently |
210 | | // live shadow layers, because some of them might be orphaned from |
211 | | // the layer tree. This happens in Destroy() above. After we |
212 | | // Destroy() ourself, there's a window in which that information |
213 | | // hasn't yet propagated back to the child side and it might still |
214 | | // send us layer transactions. We want to ignore those transactions |
215 | | // because they refer to "zombie layers" on this side. So, we track |
216 | | // that state with |mDestroyed|. This is similar to, but separate |
217 | | // from, |mLayerManager->IsDestroyed()|; we might have had Destroy() |
218 | | // called on us but the mLayerManager might not be destroyed, or |
219 | | // vice versa. In both cases though, we want to ignore shadow-layer |
220 | | // transactions posted by the child. |
221 | | |
222 | | bool mDestroyed; |
223 | | bool mIPCOpen; |
224 | | |
225 | | // This is set during RecvUpdate to track whether we'll need to update |
226 | | // APZ's hit test regions. |
227 | | bool mUpdateHitTestingTree; |
228 | | }; |
229 | | |
230 | | } // namespace layers |
231 | | } // namespace mozilla |
232 | | |
233 | | #endif // MOZILLA_LAYERS_LAYERTRANSACTIONPARENT_H |