Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=4 ts=8 et 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_WebRenderBridgeChild_h
8 : #define mozilla_layers_WebRenderBridgeChild_h
9 :
10 : #include "mozilla/layers/CompositableForwarder.h"
11 : #include "mozilla/layers/PWebRenderBridgeChild.h"
12 :
13 : namespace mozilla {
14 :
15 : namespace widget {
16 : class CompositorWidget;
17 : }
18 :
19 : namespace wr {
20 : class DisplayListBuilder;
21 : }
22 :
23 : namespace layers {
24 :
25 : class CompositableClient;
26 : class CompositorBridgeChild;
27 : class StackingContextHelper;
28 : class TextureForwarder;
29 :
30 0 : class UnscaledFontHashKey : public PLDHashEntryHdr
31 : {
32 : public:
33 : typedef gfx::UnscaledFont* KeyType;
34 : typedef const gfx::UnscaledFont* KeyTypePointer;
35 :
36 0 : explicit UnscaledFontHashKey(KeyTypePointer aKey) : mKey(const_cast<KeyType>(aKey)) {}
37 :
38 0 : KeyType GetKey() const { return mKey; }
39 0 : bool KeyEquals(KeyTypePointer aKey) const { return aKey == mKey; }
40 :
41 0 : static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
42 0 : static PLDHashNumber HashKey(KeyTypePointer aKey)
43 : {
44 0 : return NS_PTR_TO_UINT32(aKey) >> 2;
45 : }
46 : enum { ALLOW_MEMMOVE = true };
47 :
48 : private:
49 : WeakPtr<gfx::UnscaledFont> mKey;
50 : };
51 :
52 : class WebRenderBridgeChild final : public PWebRenderBridgeChild
53 : , public CompositableForwarder
54 : {
55 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderBridgeChild, override)
56 :
57 : public:
58 : explicit WebRenderBridgeChild(const wr::PipelineId& aPipelineId);
59 :
60 : void AddWebRenderParentCommand(const WebRenderParentCommand& aCmd);
61 : void AddWebRenderParentCommands(const nsTArray<WebRenderParentCommand>& aCommands);
62 :
63 : bool DPBegin(const gfx::IntSize& aSize);
64 : void DPEnd(wr::DisplayListBuilder &aBuilder, const gfx::IntSize& aSize,
65 : bool aIsSync, uint64_t aTransactionId,
66 : const WebRenderScrollData& aScrollData);
67 : void ProcessWebRenderParentCommands();
68 :
69 : CompositorBridgeChild* GetCompositorBridgeChild();
70 :
71 0 : wr::PipelineId GetPipeline() { return mPipelineId; }
72 :
73 : // KnowsCompositor
74 : TextureForwarder* GetTextureForwarder() override;
75 : LayersIPCActor* GetLayersIPCActor() override;
76 :
77 : void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
78 : const CompositableHandle& aHandlee);
79 : void RemovePipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId);
80 :
81 : wr::ExternalImageId AllocExternalImageIdForCompositable(CompositableClient* aCompositable);
82 : void DeallocExternalImageId(wr::ExternalImageId& aImageId);
83 :
84 : /**
85 : * Clean this up, finishing with SendShutDown() which will cause __delete__
86 : * to be sent from the parent side.
87 : */
88 : void Destroy(bool aIsSync);
89 0 : bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
90 : bool IsDestroyed() const { return mDestroyed; }
91 :
92 0 : uint32_t GetNextResourceId() { return ++mResourceId; }
93 0 : uint32_t GetNamespace() { return mIdNamespace; }
94 0 : void SetNamespace(uint32_t aIdNamespace)
95 : {
96 0 : mIdNamespace = aIdNamespace;
97 0 : }
98 :
99 0 : WrImageKey GetNextImageKey()
100 : {
101 0 : return WrImageKey{ GetNamespace(), GetNextResourceId() };
102 : }
103 :
104 : void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
105 : gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
106 : const LayerRect& aBounds, const LayerRect& aClip);
107 :
108 : wr::FontKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont);
109 :
110 : void RemoveExpiredFontKeys();
111 : void ClearReadLocks();
112 :
113 : private:
114 : friend class CompositorBridgeChild;
115 :
116 0 : ~WebRenderBridgeChild() {}
117 :
118 : wr::ExternalImageId GetNextExternalImageId();
119 :
120 : // CompositableForwarder
121 : void Connect(CompositableClient* aCompositable,
122 : ImageContainer* aImageContainer = nullptr) override;
123 : void UseTiledLayerBuffer(CompositableClient* aCompositable,
124 : const SurfaceDescriptorTiles& aTiledDescriptor) override;
125 : void UpdateTextureRegion(CompositableClient* aCompositable,
126 : const ThebesBufferData& aThebesBufferData,
127 : const nsIntRegion& aUpdatedRegion) override;
128 : void ReleaseCompositable(const CompositableHandle& aHandle) override;
129 : bool DestroyInTransaction(PTextureChild* aTexture) override;
130 : bool DestroyInTransaction(const CompositableHandle& aHandle);
131 : void RemoveTextureFromCompositable(CompositableClient* aCompositable,
132 : TextureClient* aTexture) override;
133 : void UseTextures(CompositableClient* aCompositable,
134 : const nsTArray<TimedTextureClient>& aTextures) override;
135 : void UseComponentAlphaTextures(CompositableClient* aCompositable,
136 : TextureClient* aClientOnBlack,
137 : TextureClient* aClientOnWhite) override;
138 : void UpdateFwdTransactionId() override;
139 : uint64_t GetFwdTransactionId() override;
140 : bool InForwarderThread() override;
141 :
142 : void ActorDestroy(ActorDestroyReason why) override;
143 :
144 : virtual mozilla::ipc::IPCResult RecvWrUpdated(const uint32_t& aNewIdNameSpace) override;
145 :
146 0 : void AddIPDLReference() {
147 0 : MOZ_ASSERT(mIPCOpen == false);
148 0 : mIPCOpen = true;
149 0 : AddRef();
150 0 : }
151 0 : void ReleaseIPDLReference() {
152 0 : MOZ_ASSERT(mIPCOpen == true);
153 0 : mIPCOpen = false;
154 0 : Release();
155 0 : }
156 :
157 : bool AddOpDestroy(const OpDestroy& aOp);
158 :
159 : nsTArray<WebRenderParentCommand> mParentCommands;
160 : nsTArray<OpDestroy> mDestroyedActors;
161 : nsDataHashtable<nsUint64HashKey, CompositableClient*> mCompositables;
162 : nsTArray<nsTArray<ReadLockInit>> mReadLocks;
163 : uint64_t mReadLockSequenceNumber;
164 : bool mIsInTransaction;
165 : uint32_t mIdNamespace;
166 : uint32_t mResourceId;
167 : wr::PipelineId mPipelineId;
168 :
169 : bool mIPCOpen;
170 : bool mDestroyed;
171 :
172 : uint32_t mFontKeysDeleted;
173 : nsDataHashtable<UnscaledFontHashKey, wr::FontKey> mFontKeys;
174 : };
175 :
176 : } // namespace layers
177 : } // namespace mozilla
178 :
179 : #endif // mozilla_layers_WebRenderBridgeChild_h
|