Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / wr / WebRenderBridgeChild.h
blobd4b5e8516781ad0c93e6645c60dad00effba948d
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/. */
7 #ifndef mozilla_layers_WebRenderBridgeChild_h
8 #define mozilla_layers_WebRenderBridgeChild_h
10 #include "mozilla/layers/CompositableForwarder.h"
11 #include "mozilla/layers/PWebRenderBridgeChild.h"
13 namespace mozilla {
15 namespace widget {
16 class CompositorWidget;
19 namespace wr {
20 class DisplayListBuilder;
21 class ResourceUpdateQueue;
22 class IpcResourceUpdateQueue;
23 } // namespace wr
25 namespace layers {
27 class CompositableClient;
28 class CompositorBridgeChild;
29 class StackingContextHelper;
30 class TextureForwarder;
31 class WebRenderLayerManager;
33 template <class T>
34 class ThreadSafeWeakPtrHashKey : public PLDHashEntryHdr {
35 public:
36 typedef RefPtr<T> KeyType;
37 typedef const T* KeyTypePointer;
39 explicit ThreadSafeWeakPtrHashKey(KeyTypePointer aKey)
40 : mKey(do_AddRef(const_cast<T*>(aKey))) {}
42 KeyType GetKey() const { return do_AddRef(mKey); }
43 bool KeyEquals(KeyTypePointer aKey) const { return mKey == aKey; }
45 static KeyTypePointer KeyToPointer(const KeyType& aKey) { return aKey.get(); }
46 static PLDHashNumber HashKey(KeyTypePointer aKey) {
47 return NS_PTR_TO_UINT32(aKey) >> 2;
49 enum { ALLOW_MEMMOVE = true };
51 private:
52 ThreadSafeWeakPtr<T> mKey;
55 typedef ThreadSafeWeakPtrHashKey<gfx::UnscaledFont> UnscaledFontHashKey;
56 typedef ThreadSafeWeakPtrHashKey<gfx::ScaledFont> ScaledFontHashKey;
58 class WebRenderBridgeChild final : public PWebRenderBridgeChild,
59 public CompositableForwarder {
60 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderBridgeChild, override)
62 friend class PWebRenderBridgeChild;
64 public:
65 explicit WebRenderBridgeChild(const wr::PipelineId& aPipelineId);
67 void AddWebRenderParentCommand(const WebRenderParentCommand& aCmd,
68 wr::RenderRoot aRenderRoot);
69 bool HasWebRenderParentCommands(wr::RenderRoot aRenderRoot) {
70 return !mParentCommands.IsEmpty();
73 void UpdateResources(wr::IpcResourceUpdateQueue& aResources,
74 wr::RenderRoot aRenderRoot);
75 void BeginTransaction();
76 bool EndTransaction(nsTArray<RenderRootDisplayListData>& aRenderRoots,
77 TransactionId aTransactionId, bool aContainsSVGroup,
78 const mozilla::VsyncId& aVsyncId,
79 const mozilla::TimeStamp& aVsyncStartTime,
80 const mozilla::TimeStamp& aRefreshStartTime,
81 const mozilla::TimeStamp& aTxnStartTime,
82 const nsCString& aTxtURL);
83 void EndEmptyTransaction(const FocusTarget& aFocusTarget,
84 nsTArray<RenderRootUpdates>& aRenderRootUpdates,
85 TransactionId aTransactionId,
86 const mozilla::VsyncId& aVsyncId,
87 const mozilla::TimeStamp& aVsyncStartTime,
88 const mozilla::TimeStamp& aRefreshStartTime,
89 const mozilla::TimeStamp& aTxnStartTime,
90 const nsCString& aTxtURL);
91 void ProcessWebRenderParentCommands();
93 CompositorBridgeChild* GetCompositorBridgeChild();
95 wr::PipelineId GetPipeline() { return mPipelineId; }
97 // KnowsCompositor
98 TextureForwarder* GetTextureForwarder() override;
99 LayersIPCActor* GetLayersIPCActor() override;
100 void SyncWithCompositor() override;
101 ActiveResourceTracker* GetActiveResourceTracker() override {
102 return mActiveResourceTracker.get();
105 void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
106 const CompositableHandle& aHandlee,
107 wr::RenderRoot aRenderRoot);
108 void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
109 const CompositableHandle& aHandlee,
110 wr::RenderRoot aRenderRoot);
111 void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId,
112 wr::RenderRoot aRenderRoot);
114 /// Release TextureClient that is bounded to ImageKey.
115 /// It is used for recycling TextureClient.
116 void ReleaseTextureOfImage(const wr::ImageKey& aKey,
117 wr::RenderRoot aRenderRoot);
120 * Clean this up, finishing with SendShutDown() which will cause __delete__
121 * to be sent from the parent side.
123 void Destroy(bool aIsSync);
124 bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
125 bool GetSentDisplayList() const { return mSentDisplayList; }
126 bool IsDestroyed() const { return mDestroyed; }
128 uint32_t GetNextResourceId() { return ++mResourceId; }
129 wr::IdNamespace GetNamespace() { return mIdNamespace; }
130 void SetNamespace(wr::IdNamespace aIdNamespace) {
131 mIdNamespace = aIdNamespace;
134 wr::FontKey GetNextFontKey() {
135 return wr::FontKey{GetNamespace(), GetNextResourceId()};
138 wr::FontInstanceKey GetNextFontInstanceKey() {
139 return wr::FontInstanceKey{GetNamespace(), GetNextResourceId()};
142 wr::WrImageKey GetNextImageKey() {
143 return wr::WrImageKey{GetNamespace(), GetNextResourceId()};
146 void PushGlyphs(wr::DisplayListBuilder& aBuilder,
147 Range<const wr::GlyphInstance> aGlyphs,
148 gfx::ScaledFont* aFont, const wr::ColorF& aColor,
149 const StackingContextHelper& aSc,
150 const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
151 bool aBackfaceVisible,
152 const wr::GlyphOptions* aGlyphOptions = nullptr);
154 Maybe<wr::FontInstanceKey> GetFontKeyForScaledFont(
155 gfx::ScaledFont* aScaledFont, wr::RenderRoot aRenderRoot,
156 wr::IpcResourceUpdateQueue* aResources = nullptr);
157 Maybe<wr::FontKey> GetFontKeyForUnscaledFont(
158 gfx::UnscaledFont* aUnscaledFont, wr::RenderRoot aRenderRoot,
159 wr::IpcResourceUpdateQueue* aResources = nullptr);
160 void RemoveExpiredFontKeys(wr::IpcResourceUpdateQueue& aResources);
162 void BeginClearCachedResources();
163 void EndClearCachedResources();
165 void SetWebRenderLayerManager(WebRenderLayerManager* aManager);
167 mozilla::ipc::IShmemAllocator* GetShmemAllocator();
169 bool IsThreadSafe() const override { return false; }
171 RefPtr<KnowsCompositor> GetForMedia() override;
173 /// Alloc a specific type of shmem that is intended for use in
174 /// IpcResourceUpdateQueue only, and cache at most one of them,
175 /// when called multiple times.
177 /// Do not use this for anything else.
178 bool AllocResourceShmem(size_t aSize, RefCountedShmem& aShm);
179 /// Dealloc shared memory that was allocated with AllocResourceShmem.
181 /// Do not use this for anything else.
182 void DeallocResourceShmem(RefCountedShmem& aShm);
184 void Capture();
185 void ToggleCaptureSequence();
186 void SetTransactionLogging(bool aValue);
188 private:
189 friend class CompositorBridgeChild;
191 ~WebRenderBridgeChild();
193 wr::ExternalImageId GetNextExternalImageId();
195 // CompositableForwarder
196 void Connect(CompositableClient* aCompositable,
197 ImageContainer* aImageContainer = nullptr) override;
198 void UseTiledLayerBuffer(
199 CompositableClient* aCompositable,
200 const SurfaceDescriptorTiles& aTiledDescriptor) override;
201 void UpdateTextureRegion(CompositableClient* aCompositable,
202 const ThebesBufferData& aThebesBufferData,
203 const nsIntRegion& aUpdatedRegion) override;
204 void ReleaseCompositable(const CompositableHandle& aHandle) override;
205 bool DestroyInTransaction(PTextureChild* aTexture) override;
206 bool DestroyInTransaction(const CompositableHandle& aHandle);
207 void RemoveTextureFromCompositable(
208 CompositableClient* aCompositable, TextureClient* aTexture,
209 const Maybe<wr::RenderRoot>& aRenderRoot) override;
210 void UseTextures(CompositableClient* aCompositable,
211 const nsTArray<TimedTextureClient>& aTextures,
212 const Maybe<wr::RenderRoot>& aRenderRoot) override;
213 void UseComponentAlphaTextures(CompositableClient* aCompositable,
214 TextureClient* aClientOnBlack,
215 TextureClient* aClientOnWhite) override;
216 void UpdateFwdTransactionId() override;
217 uint64_t GetFwdTransactionId() override;
218 bool InForwarderThread() override;
220 void ActorDestroy(ActorDestroyReason why) override;
222 void DoDestroy();
224 mozilla::ipc::IPCResult RecvWrUpdated(
225 const wr::IdNamespace& aNewIdNamespace,
226 const TextureFactoryIdentifier& textureFactoryIdentifier);
227 mozilla::ipc::IPCResult RecvWrReleasedImages(
228 nsTArray<wr::ExternalImageKeyPair>&& aPairs);
230 void AddIPDLReference() {
231 MOZ_ASSERT(mIPCOpen == false);
232 mIPCOpen = true;
233 AddRef();
235 void ReleaseIPDLReference() {
236 MOZ_ASSERT(mIPCOpen == true);
237 mIPCOpen = false;
238 Release();
241 bool AddOpDestroy(const OpDestroy& aOp);
243 nsTArray<OpDestroy> mDestroyedActors;
244 nsTArray<WebRenderParentCommand> mParentCommands;
245 nsDataHashtable<nsUint64HashKey, CompositableClient*> mCompositables;
246 bool mIsInTransaction;
247 bool mIsInClearCachedResources;
248 wr::IdNamespace mIdNamespace;
249 uint32_t mResourceId;
250 wr::PipelineId mPipelineId;
251 WebRenderLayerManager* mManager;
253 bool mIPCOpen;
254 bool mDestroyed;
255 // True iff we have called SendSetDisplayList and haven't called
256 // SendClearCachedResources since that call.
257 bool mSentDisplayList;
259 uint32_t mFontKeysDeleted;
260 nsDataHashtable<UnscaledFontHashKey, wr::FontKey> mFontKeys;
262 uint32_t mFontInstanceKeysDeleted;
263 nsDataHashtable<ScaledFontHashKey, wr::FontInstanceKey> mFontInstanceKeys;
265 UniquePtr<ActiveResourceTracker> mActiveResourceTracker;
267 RefCountedShmem mResourceShm;
270 } // namespace layers
271 } // namespace mozilla
273 #endif // mozilla_layers_WebRenderBridgeChild_h