Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/layers/WebRenderBridgeChild.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_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
class ResourceUpdateQueue;
22
class IpcResourceUpdateQueue;
23
}
24
25
namespace layers {
26
27
class CompositableClient;
28
class CompositorBridgeChild;
29
class StackingContextHelper;
30
class TextureForwarder;
31
class WebRenderLayerManager;
32
33
template<class T>
34
class ThreadSafeWeakPtrHashKey : public PLDHashEntryHdr
35
{
36
public:
37
  typedef RefPtr<T> KeyType;
38
  typedef const T* KeyTypePointer;
39
40
  explicit ThreadSafeWeakPtrHashKey(KeyTypePointer aKey) : mKey(do_AddRef(const_cast<T*>(aKey))) {}
41
42
  KeyType GetKey() const { return do_AddRef(mKey); }
43
  bool KeyEquals(KeyTypePointer aKey) const { return mKey == aKey; }
44
45
  static KeyTypePointer KeyToPointer(const KeyType& aKey) { return aKey.get(); }
46
  static PLDHashNumber HashKey(KeyTypePointer aKey)
47
  {
48
    return NS_PTR_TO_UINT32(aKey) >> 2;
49
  }
50
  enum { ALLOW_MEMMOVE = true };
51
52
private:
53
  ThreadSafeWeakPtr<T> mKey;
54
};
55
56
typedef ThreadSafeWeakPtrHashKey<gfx::UnscaledFont> UnscaledFontHashKey;
57
typedef ThreadSafeWeakPtrHashKey<gfx::ScaledFont> ScaledFontHashKey;
58
59
class WebRenderBridgeChild final : public PWebRenderBridgeChild
60
                                 , public CompositableForwarder
61
{
62
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderBridgeChild, override)
63
64
public:
65
  explicit WebRenderBridgeChild(const wr::PipelineId& aPipelineId);
66
67
  void AddWebRenderParentCommand(const WebRenderParentCommand& aCmd);
68
69
  void UpdateResources(wr::IpcResourceUpdateQueue& aResources);
70
  void BeginTransaction();
71
  void EndTransaction(const wr::LayoutSize& aContentSize,
72
                      wr::BuiltDisplayList& dl,
73
                      wr::IpcResourceUpdateQueue& aResources,
74
                      const gfx::IntSize& aSize,
75
                      TransactionId aTransactionId,
76
                      const WebRenderScrollData& aScrollData,
77
                      bool aContainsSVGroup,
78
                      const mozilla::TimeStamp& aRefreshStartTime,
79
                      const mozilla::TimeStamp& aTxnStartTime);
80
  void EndEmptyTransaction(const FocusTarget& aFocusTarget,
81
                           const ScrollUpdatesMap& aUpdates,
82
                           uint32_t aPaintSequenceNumber,
83
                           TransactionId aTransactionId,
84
                           const mozilla::TimeStamp& aRefreshStartTime,
85
                           const mozilla::TimeStamp& aTxnStartTime);
86
  void ProcessWebRenderParentCommands();
87
88
  CompositorBridgeChild* GetCompositorBridgeChild();
89
90
  wr::PipelineId GetPipeline() { return mPipelineId; }
91
92
  // KnowsCompositor
93
  TextureForwarder* GetTextureForwarder() override;
94
  LayersIPCActor* GetLayersIPCActor() override;
95
  void SyncWithCompositor() override;
96
  ActiveResourceTracker* GetActiveResourceTracker() override { return mActiveResourceTracker.get(); }
97
98
  void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
99
                                         const CompositableHandle& aHandlee);
100
  void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
101
                                    const CompositableHandle& aHandlee);
102
  void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId);
103
104
  void DeallocExternalImageId(const wr::ExternalImageId& aImageId);
105
106
  /// Release TextureClient that is bounded to ImageKey.
107
  /// It is used for recycling TextureClient.
108
  void ReleaseTextureOfImage(const wr::ImageKey& aKey);
109
110
  /**
111
   * Clean this up, finishing with SendShutDown() which will cause __delete__
112
   * to be sent from the parent side.
113
   */
114
  void Destroy(bool aIsSync);
115
  bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
116
  bool IsDestroyed() const { return mDestroyed; }
117
118
  uint32_t GetNextResourceId() { return ++mResourceId; }
119
  wr::IdNamespace GetNamespace() { return mIdNamespace; }
120
  void SetNamespace(wr::IdNamespace aIdNamespace)
121
  {
122
    mIdNamespace = aIdNamespace;
123
  }
124
125
  wr::FontKey GetNextFontKey()
126
  {
127
    return wr::FontKey { GetNamespace(), GetNextResourceId() };
128
  }
129
130
  wr::FontInstanceKey GetNextFontInstanceKey()
131
  {
132
    return wr::FontInstanceKey { GetNamespace(), GetNextResourceId() };
133
  }
134
135
  wr::WrImageKey GetNextImageKey()
136
  {
137
    return wr::WrImageKey{ GetNamespace(), GetNextResourceId() };
138
  }
139
140
  void PushGlyphs(wr::DisplayListBuilder& aBuilder, Range<const wr::GlyphInstance> aGlyphs,
141
                  gfx::ScaledFont* aFont, const wr::ColorF& aColor,
142
                  const StackingContextHelper& aSc,
143
                  const wr::LayoutRect& aBounds, const wr::LayoutRect& aClip,
144
                  bool aBackfaceVisible,
145
                  const wr::GlyphOptions* aGlyphOptions = nullptr);
146
147
  wr::FontInstanceKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont,
148
                                              wr::IpcResourceUpdateQueue* aResources = nullptr);
149
  wr::FontKey GetFontKeyForUnscaledFont(gfx::UnscaledFont* aUnscaledFont,
150
                                        wr::IpcResourceUpdateQueue* aResources = nullptr);
151
  void RemoveExpiredFontKeys(wr::IpcResourceUpdateQueue& aResources);
152
153
  void BeginClearCachedResources();
154
  void EndClearCachedResources();
155
156
  void SetWebRenderLayerManager(WebRenderLayerManager* aManager);
157
158
  ipc::IShmemAllocator* GetShmemAllocator();
159
160
  virtual bool IsThreadSafe() const override { return false; }
161
162
  virtual RefPtr<KnowsCompositor> GetForMedia() override;
163
164
  /// Alloc a specific type of shmem that is intended for use in
165
  /// IpcResourceUpdateQueue only, and cache at most one of them,
166
  /// when called multiple times.
167
  ///
168
  /// Do not use this for anything else.
169
  bool AllocResourceShmem(size_t aSize, RefCountedShmem& aShm);
170
  /// Dealloc shared memory that was allocated with AllocResourceShmem.
171
  /// 
172
  /// Do not use this for anything else.
173
  void DeallocResourceShmem(RefCountedShmem& aShm);
174
175
  void Capture();
176
177
private:
178
  friend class CompositorBridgeChild;
179
180
  ~WebRenderBridgeChild();
181
182
  wr::ExternalImageId GetNextExternalImageId();
183
184
  // CompositableForwarder
185
  void Connect(CompositableClient* aCompositable,
186
               ImageContainer* aImageContainer = nullptr) override;
187
  void UseTiledLayerBuffer(CompositableClient* aCompositable,
188
                           const SurfaceDescriptorTiles& aTiledDescriptor) override;
189
  void UpdateTextureRegion(CompositableClient* aCompositable,
190
                           const ThebesBufferData& aThebesBufferData,
191
                           const nsIntRegion& aUpdatedRegion) override;
192
  void ReleaseCompositable(const CompositableHandle& aHandle) override;
193
  bool DestroyInTransaction(PTextureChild* aTexture) override;
194
  bool DestroyInTransaction(const CompositableHandle& aHandle);
195
  void RemoveTextureFromCompositable(CompositableClient* aCompositable,
196
                                     TextureClient* aTexture) override;
197
  void UseTextures(CompositableClient* aCompositable,
198
                   const nsTArray<TimedTextureClient>& aTextures) override;
199
  void UseComponentAlphaTextures(CompositableClient* aCompositable,
200
                                 TextureClient* aClientOnBlack,
201
                                 TextureClient* aClientOnWhite) override;
202
  void UpdateFwdTransactionId() override;
203
  uint64_t GetFwdTransactionId() override;
204
  bool InForwarderThread() override;
205
206
  void ActorDestroy(ActorDestroyReason why) override;
207
208
  void DoDestroy();
209
210
  mozilla::ipc::IPCResult RecvWrUpdated(const wr::IdNamespace& aNewIdNamespace,
211
                                        const TextureFactoryIdentifier& textureFactoryIdentifier) override;
212
213
0
  void AddIPDLReference() {
214
0
    MOZ_ASSERT(mIPCOpen == false);
215
0
    mIPCOpen = true;
216
0
    AddRef();
217
0
  }
218
0
  void ReleaseIPDLReference() {
219
0
    MOZ_ASSERT(mIPCOpen == true);
220
0
    mIPCOpen = false;
221
0
    Release();
222
0
  }
223
224
  bool AddOpDestroy(const OpDestroy& aOp);
225
226
  nsTArray<WebRenderParentCommand> mParentCommands;
227
  nsTArray<OpDestroy> mDestroyedActors;
228
  nsDataHashtable<nsUint64HashKey, CompositableClient*> mCompositables;
229
  bool mIsInTransaction;
230
  bool mIsInClearCachedResources;
231
  wr::IdNamespace mIdNamespace;
232
  uint32_t mResourceId;
233
  wr::PipelineId mPipelineId;
234
  WebRenderLayerManager* mManager;
235
236
  bool mIPCOpen;
237
  bool mDestroyed;
238
239
  uint32_t mFontKeysDeleted;
240
  nsDataHashtable<UnscaledFontHashKey, wr::FontKey> mFontKeys;
241
242
  uint32_t mFontInstanceKeysDeleted;
243
  nsDataHashtable<ScaledFontHashKey, wr::FontInstanceKey> mFontInstanceKeys;
244
245
  UniquePtr<ActiveResourceTracker> mActiveResourceTracker;
246
247
  RefCountedShmem mResourceShm;
248
};
249
250
} // namespace layers
251
} // namespace mozilla
252
253
#endif // mozilla_layers_WebRenderBridgeChild_h