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