Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/wr/WebRenderLayerManager.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 GFX_WEBRENDERLAYERMANAGER_H
8
#define GFX_WEBRENDERLAYERMANAGER_H
9
10
#include <unordered_set>
11
#include <vector>
12
13
#include "gfxPrefs.h"
14
#include "Layers.h"
15
#include "mozilla/MozPromise.h"
16
#include "mozilla/layers/APZTestData.h"
17
#include "mozilla/layers/FocusTarget.h"
18
#include "mozilla/layers/StackingContextHelper.h"
19
#include "mozilla/layers/TransactionIdAllocator.h"
20
#include "mozilla/layers/WebRenderCommandBuilder.h"
21
#include "mozilla/layers/WebRenderScrollData.h"
22
#include "mozilla/layers/WebRenderUserData.h"
23
#include "mozilla/webrender/WebRenderAPI.h"
24
#include "mozilla/webrender/WebRenderTypes.h"
25
#include "nsDisplayList.h"
26
27
class nsIWidget;
28
29
namespace mozilla {
30
31
struct ActiveScrolledRoot;
32
33
namespace dom {
34
class TabGroup;
35
}
36
37
namespace layers {
38
39
class CompositorBridgeChild;
40
class KnowsCompositor;
41
class PCompositorBridgeChild;
42
class WebRenderBridgeChild;
43
class WebRenderParentCommand;
44
45
class WebRenderLayerManager final : public LayerManager
46
{
47
  typedef nsTArray<RefPtr<Layer> > LayerRefArray;
48
  typedef nsTHashtable<nsRefPtrHashKey<WebRenderUserData>> WebRenderUserDataRefTable;
49
50
public:
51
  explicit WebRenderLayerManager(nsIWidget* aWidget);
52
  bool Initialize(PCompositorBridgeChild* aCBChild, wr::PipelineId aLayersId, TextureFactoryIdentifier* aTextureFactoryIdentifier);
53
54
  virtual void Destroy() override;
55
56
  void DoDestroy(bool aIsSync);
57
58
protected:
59
  virtual ~WebRenderLayerManager();
60
61
public:
62
  virtual KnowsCompositor* AsKnowsCompositor() override;
63
0
  WebRenderLayerManager* AsWebRenderLayerManager() override { return this; }
64
  virtual CompositorBridgeChild* GetCompositorBridgeChild() override;
65
66
  // WebRender can handle images larger than the max texture size via tiling.
67
0
  virtual int32_t GetMaxTextureSize() const override { return INT32_MAX; }
68
69
  virtual bool BeginTransactionWithTarget(gfxContext* aTarget) override;
70
  virtual bool BeginTransaction() override;
71
  virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) override;
72
  void EndTransactionWithoutLayer(nsDisplayList* aDisplayList,
73
                                  nsDisplayListBuilder* aDisplayListBuilder,
74
                                  const nsTArray<wr::WrFilterOp>& aFilters = nsTArray<wr::WrFilterOp>(),
75
                                  WebRenderBackgroundData* aBackground = nullptr);
76
  virtual void EndTransaction(DrawPaintedLayerCallback aCallback,
77
                              void* aCallbackData,
78
                              EndTransactionFlags aFlags = END_DEFAULT) override;
79
80
0
  virtual LayersBackend GetBackendType() override { return LayersBackend::LAYERS_WR; }
81
0
  virtual void GetBackendName(nsAString& name) override { name.AssignLiteral("WebRender"); }
82
0
  virtual const char* Name() const override { return "WebRender"; }
83
84
  virtual void SetRoot(Layer* aLayer) override;
85
86
0
  already_AddRefed<PaintedLayer> CreatePaintedLayer() override { return nullptr; }
87
0
  already_AddRefed<ContainerLayer> CreateContainerLayer() override { return nullptr; }
88
0
  already_AddRefed<ImageLayer> CreateImageLayer() override { return nullptr; }
89
0
  already_AddRefed<ColorLayer> CreateColorLayer() override { return nullptr; }
90
0
  already_AddRefed<CanvasLayer> CreateCanvasLayer() override { return nullptr; }
91
92
0
  virtual bool NeedsWidgetInvalidation() override { return false; }
93
94
  virtual void SetLayersObserverEpoch(LayersObserverEpoch aEpoch) override;
95
96
  virtual void DidComposite(TransactionId aTransactionId,
97
                            const mozilla::TimeStamp& aCompositeStart,
98
                            const mozilla::TimeStamp& aCompositeEnd) override;
99
100
  virtual void ClearCachedResources(Layer* aSubtree = nullptr) override;
101
  virtual void UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier) override;
102
  virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override;
103
104
  virtual void SetTransactionIdAllocator(TransactionIdAllocator* aAllocator) override;
105
  virtual TransactionId GetLastTransactionId() override;
106
107
  virtual void AddDidCompositeObserver(DidCompositeObserver* aObserver) override;
108
  virtual void RemoveDidCompositeObserver(DidCompositeObserver* aObserver) override;
109
110
  virtual void FlushRendering() override;
111
  virtual void WaitOnTransactionProcessed() override;
112
113
  virtual void SendInvalidRegion(const nsIntRegion& aRegion) override;
114
115
  virtual void ScheduleComposite() override;
116
117
  virtual void SetNeedsComposite(bool aNeedsComposite) override
118
0
  {
119
0
    mNeedsComposite = aNeedsComposite;
120
0
  }
121
0
  virtual bool NeedsComposite() const override { return mNeedsComposite; }
122
0
  virtual void SetIsFirstPaint() override { mIsFirstPaint = true; }
123
  virtual void SetFocusTarget(const FocusTarget& aFocusTarget) override;
124
125
  virtual already_AddRefed<PersistentBufferProvider>
126
  CreatePersistentBufferProvider(const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat) override;
127
128
  bool AsyncPanZoomEnabled() const override;
129
130
  // adds an imagekey to a list of keys that will be discarded on the next
131
  // transaction or destruction
132
  void AddImageKeyForDiscard(wr::ImageKey);
133
  void DiscardImages();
134
  void DiscardLocalImages();
135
136
  // Methods to manage the compositor animation ids. Active animations are still
137
  // going, and when they end we discard them and remove them from the active
138
  // list.
139
  void AddActiveCompositorAnimationId(uint64_t aId);
140
  void AddCompositorAnimationsIdForDiscard(uint64_t aId);
141
  void DiscardCompositorAnimations();
142
143
0
  WebRenderBridgeChild* WrBridge() const { return mWrChild; }
144
145
  // See equivalent function in ClientLayerManager
146
  void LogTestDataForCurrentPaint(FrameMetrics::ViewID aScrollId,
147
                                  const std::string& aKey,
148
                                  const std::string& aValue) {
149
    MOZ_ASSERT(gfxPrefs::APZTestLoggingEnabled(), "don't call me");
150
    mApzTestData.LogTestDataForPaint(mPaintSequenceNumber, aScrollId, aKey, aValue);
151
  }
152
  // See equivalent function in ClientLayerManager
153
  const APZTestData& GetAPZTestData() const
154
  { return mApzTestData; }
155
156
  WebRenderCommandBuilder& CommandBuilder() { return mWebRenderCommandBuilder; }
157
0
  WebRenderUserDataRefTable* GetWebRenderUserDataTable() { return mWebRenderCommandBuilder.GetWebRenderUserDataTable(); }
158
0
  WebRenderScrollData& GetScrollData() { return mScrollData; }
159
160
  void WrUpdated();
161
  void WindowOverlayChanged() { mWindowOverlayChanged = true; }
162
0
  nsIWidget* GetWidget() { return mWidget; }
163
164
  dom::TabGroup* GetTabGroup();
165
166
  uint32_t StartFrameTimeRecording(int32_t aBufferSize) override;
167
  void StopFrameTimeRecording(uint32_t         aStartIndex,
168
                              nsTArray<float>& aFrameIntervals) override;
169
170
private:
171
  /**
172
   * Take a snapshot of the parent context, and copy
173
   * it into mTarget.
174
   */
175
  void MakeSnapshotIfRequired(LayoutDeviceIntSize aSize);
176
177
private:
178
  nsIWidget* MOZ_NON_OWNING_REF mWidget;
179
  nsTArray<wr::ImageKey> mImageKeysToDelete;
180
181
  // Set of compositor animation ids for which there are active animations (as
182
  // of the last transaction) on the compositor side.
183
  std::unordered_set<uint64_t> mActiveCompositorAnimationIds;
184
  // Compositor animation ids for animations that are done now and that we want
185
  // the compositor to discard information for.
186
  nsTArray<uint64_t> mDiscardedCompositorAnimationsIds;
187
188
  RefPtr<WebRenderBridgeChild> mWrChild;
189
190
  RefPtr<TransactionIdAllocator> mTransactionIdAllocator;
191
  TransactionId mLatestTransactionId;
192
193
  nsTArray<DidCompositeObserver*> mDidCompositeObservers;
194
195
  // This holds the scroll data that we need to send to the compositor for
196
  // APZ to do it's job
197
  WebRenderScrollData mScrollData;
198
199
  bool mWindowOverlayChanged;
200
  bool mNeedsComposite;
201
  bool mIsFirstPaint;
202
  FocusTarget mFocusTarget;
203
204
  // When we're doing a transaction in order to draw to a non-default
205
  // target, the layers transaction is only performed in order to send
206
  // a PLayers:Update.  We save the original non-default target to
207
  // mTarget, and then perform the transaction. After the transaction ends,
208
  // we send a message to our remote side to capture the actual pixels
209
  // being drawn to the default target, and then copy those pixels
210
  // back to mTarget.
211
  RefPtr<gfxContext> mTarget;
212
213
  // See equivalent field in ClientLayerManager
214
  uint32_t mPaintSequenceNumber;
215
  // See equivalent field in ClientLayerManager
216
  APZTestData mApzTestData;
217
218
  TimeStamp mTransactionStart;
219
  WebRenderCommandBuilder mWebRenderCommandBuilder;
220
221
  size_t mLastDisplayListSize;
222
};
223
224
} // namespace layers
225
} // namespace mozilla
226
227
#endif /* GFX_WEBRENDERLAYERMANAGER_H */