Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/ClientLayerManager.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_CLIENTLAYERMANAGER_H
8
#define GFX_CLIENTLAYERMANAGER_H
9
10
#include <stdint.h>                     // for int32_t
11
#include "Layers.h"
12
#include "gfxContext.h"                 // for gfxContext
13
#include "gfxPrefs.h"
14
#include "mozilla/Attributes.h"         // for override
15
#include "mozilla/LinkedList.h"         // For LinkedList
16
#include "mozilla/WidgetUtils.h"        // for ScreenRotation
17
#include "mozilla/gfx/Rect.h"           // for Rect
18
#include "mozilla/layers/CompositorTypes.h"
19
#include "mozilla/layers/FocusTarget.h"  // for FocusTarget
20
#include "mozilla/layers/LayersTypes.h"  // for BufferMode, LayersBackend, etc
21
#include "mozilla/layers/PaintThread.h" // For PaintThread
22
#include "mozilla/layers/ShadowLayers.h"  // for ShadowLayerForwarder, etc
23
#include "mozilla/layers/APZTestData.h" // for APZTestData
24
#include "mozilla/layers/MemoryPressureObserver.h"
25
#include "nsCOMPtr.h"                   // for already_AddRefed
26
#include "nsIObserver.h"                // for nsIObserver
27
#include "nsISupportsImpl.h"            // for Layer::Release, etc
28
#include "nsRect.h"                     // for mozilla::gfx::IntRect
29
#include "nsTArray.h"                   // for nsTArray
30
#include "nscore.h"                     // for nsAString
31
#include "mozilla/layers/TransactionIdAllocator.h"
32
#include "nsIWidget.h"                  // For plugin window configuration information structs
33
34
class nsDisplayListBuilder;
35
36
namespace mozilla {
37
38
namespace dom {
39
class TabGroup;
40
}
41
namespace layers {
42
43
using dom::TabGroup;
44
45
class ClientPaintedLayer;
46
class CompositorBridgeChild;
47
class ImageLayer;
48
class FrameUniformityData;
49
50
class ClientLayerManager final : public LayerManager
51
                               , public MemoryPressureListener
52
{
53
  typedef nsTArray<RefPtr<Layer> > LayerRefArray;
54
55
public:
56
  explicit ClientLayerManager(nsIWidget* aWidget);
57
58
  virtual void Destroy() override;
59
60
protected:
61
  virtual ~ClientLayerManager();
62
63
public:
64
  virtual ShadowLayerForwarder* AsShadowForwarder() override
65
0
  {
66
0
    return mForwarder;
67
0
  }
68
69
  virtual KnowsCompositor* AsKnowsCompositor() override
70
0
  {
71
0
    return mForwarder;
72
0
  }
73
74
  virtual ClientLayerManager* AsClientLayerManager() override
75
0
  {
76
0
    return this;
77
0
  }
78
79
  TabGroup* GetTabGroup();
80
81
  virtual int32_t GetMaxTextureSize() const override;
82
83
  virtual void SetDefaultTargetConfiguration(BufferMode aDoubleBuffering, ScreenRotation aRotation);
84
  virtual bool BeginTransactionWithTarget(gfxContext* aTarget) override;
85
  virtual bool BeginTransaction() override;
86
  virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) override;
87
  virtual void EndTransaction(DrawPaintedLayerCallback aCallback,
88
                              void* aCallbackData,
89
                              EndTransactionFlags aFlags = END_DEFAULT) override;
90
91
0
  virtual LayersBackend GetBackendType() override { return LayersBackend::LAYERS_CLIENT; }
92
  virtual LayersBackend GetCompositorBackendType() override
93
0
  {
94
0
    return AsShadowForwarder()->GetCompositorBackendType();
95
0
  }
96
  virtual void GetBackendName(nsAString& name) override;
97
0
  virtual const char* Name() const override { return "Client"; }
98
99
  virtual void SetRoot(Layer* aLayer) override;
100
101
  virtual void Mutated(Layer* aLayer) override;
102
  virtual void MutatedSimple(Layer* aLayer) override;
103
104
  virtual already_AddRefed<PaintedLayer> CreatePaintedLayer() override;
105
  virtual already_AddRefed<PaintedLayer> CreatePaintedLayerWithHint(PaintedLayerCreationHint aHint) override;
106
  virtual already_AddRefed<ContainerLayer> CreateContainerLayer() override;
107
  virtual already_AddRefed<ImageLayer> CreateImageLayer() override;
108
  virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() override;
109
  virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override;
110
  virtual already_AddRefed<ColorLayer> CreateColorLayer() override;
111
  virtual already_AddRefed<RefLayer> CreateRefLayer() override;
112
113
  virtual void UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier) override;
114
  virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override
115
0
  {
116
0
    return AsShadowForwarder()->GetTextureFactoryIdentifier();
117
0
  }
118
119
  virtual void FlushRendering() override;
120
  virtual void WaitOnTransactionProcessed() override;
121
  virtual void SendInvalidRegion(const nsIntRegion& aRegion) override;
122
123
  virtual uint32_t StartFrameTimeRecording(int32_t aBufferSize) override;
124
125
  virtual void StopFrameTimeRecording(uint32_t         aStartIndex,
126
                                      nsTArray<float>& aFrameIntervals) override;
127
128
0
  virtual bool NeedsWidgetInvalidation() override { return false; }
129
130
  ShadowableLayer* Hold(Layer* aLayer);
131
132
0
  bool HasShadowManager() const { return mForwarder->HasShadowManager(); }
133
134
  virtual bool IsCompositingCheap() override;
135
0
  virtual bool HasShadowManagerInternal() const override { return HasShadowManager(); }
136
137
  virtual void SetIsFirstPaint() override;
138
139
  virtual void SetFocusTarget(const FocusTarget& aFocusTarget) override;
140
141
  /**
142
   * Pass through call to the forwarder for nsPresContext's
143
   * CollectPluginGeometryUpdates. Passes widget configuration information
144
   * to the compositor for transmission to the chrome process. This
145
   * configuration gets set when the window paints.
146
   */
147
  void StorePluginWidgetConfigurations(const nsTArray<nsIWidget::Configuration>&
148
                                       aConfigurations) override;
149
150
  // Drop cached resources and ask our shadow manager to do the same,
151
  // if we have one.
152
  virtual void ClearCachedResources(Layer* aSubtree = nullptr) override;
153
154
  virtual void OnMemoryPressure(MemoryPressureReason aWhy) override;
155
156
0
  void SetRepeatTransaction() { mRepeatTransaction = true; }
157
0
  bool GetRepeatTransaction() { return mRepeatTransaction; }
158
159
0
  bool IsRepeatTransaction() { return mIsRepeatTransaction; }
160
161
0
  void SetTransactionIncomplete() { mTransactionIncomplete = true; }
162
0
  void SetQueuedAsyncPaints() { mQueuedAsyncPaints = true; }
163
164
0
  bool HasShadowTarget() { return !!mShadowTarget; }
165
166
0
  void SetShadowTarget(gfxContext* aTarget) { mShadowTarget = aTarget; }
167
168
0
  bool CompositorMightResample() { return mCompositorMightResample; } 
169
  
170
  DrawPaintedLayerCallback GetPaintedLayerCallback() const
171
0
  { return mPaintedLayerCallback; }
172
173
  void* GetPaintedLayerCallbackData() const
174
0
  { return mPaintedLayerCallbackData; }
175
176
  CompositorBridgeChild* GetRemoteRenderer();
177
178
  virtual CompositorBridgeChild* GetCompositorBridgeChild() override;
179
180
0
  bool InConstruction() { return mPhase == PHASE_CONSTRUCTION; }
181
#ifdef DEBUG
182
  bool InDrawing() { return mPhase == PHASE_DRAWING; }
183
  bool InForward() { return mPhase == PHASE_FORWARD; }
184
#endif
185
0
  bool InTransaction() { return mPhase != PHASE_NONE; }
186
187
  virtual void SetNeedsComposite(bool aNeedsComposite) override
188
0
  {
189
0
    mNeedsComposite = aNeedsComposite;
190
0
  }
191
0
  virtual bool NeedsComposite() const override { return mNeedsComposite; }
192
193
  virtual void ScheduleComposite() override;
194
  virtual void GetFrameUniformity(FrameUniformityData* aFrameUniformityData) override;
195
196
  virtual void DidComposite(TransactionId aTransactionId,
197
                            const mozilla::TimeStamp& aCompositeStart,
198
                            const mozilla::TimeStamp& aCompositeEnd) override;
199
200
  virtual bool AreComponentAlphaLayersEnabled() override;
201
202
  // Log APZ test data for the current paint. We supply the paint sequence
203
  // number ourselves, and take care of calling APZTestData::StartNewPaint()
204
  // when a new paint is started.
205
  void LogTestDataForCurrentPaint(FrameMetrics::ViewID aScrollId,
206
                                  const std::string& aKey,
207
                                  const std::string& aValue)
208
0
  {
209
0
    MOZ_ASSERT(gfxPrefs::APZTestLoggingEnabled(), "don't call me");
210
0
    mApzTestData.LogTestDataForPaint(mPaintSequenceNumber, aScrollId, aKey, aValue);
211
0
  }
212
213
  // Log APZ test data for a repaint request. The sequence number must be
214
  // passed in from outside, and APZTestData::StartNewRepaintRequest() needs
215
  // to be called from the outside as well when a new repaint request is started.
216
  void StartNewRepaintRequest(SequenceNumber aSequenceNumber);
217
218
  // TODO(botond): When we start using this and write a wrapper similar to
219
  // nsLayoutUtils::LogTestDataForPaint(), make sure that wrapper checks
220
  // gfxPrefs::APZTestLoggingEnabled().
221
  void LogTestDataForRepaintRequest(SequenceNumber aSequenceNumber,
222
                                    FrameMetrics::ViewID aScrollId,
223
                                    const std::string& aKey,
224
                                    const std::string& aValue)
225
0
  {
226
0
    MOZ_ASSERT(gfxPrefs::APZTestLoggingEnabled(), "don't call me");
227
0
    mApzTestData.LogTestDataForRepaintRequest(aSequenceNumber, aScrollId, aKey, aValue);
228
0
  }
229
230
  // Get the content-side APZ test data for reading. For writing, use the
231
  // LogTestData...() functions.
232
0
  const APZTestData& GetAPZTestData() const {
233
0
    return mApzTestData;
234
0
  }
235
236
  // Get a copy of the compositor-side APZ test data for our layers ID.
237
  void GetCompositorSideAPZTestData(APZTestData* aData) const;
238
239
  virtual void SetTransactionIdAllocator(TransactionIdAllocator* aAllocator) override;
240
241
0
  virtual TransactionId GetLastTransactionId() override { return mLatestTransactionId; }
242
243
  float RequestProperty(const nsAString& aProperty) override;
244
245
  bool AsyncPanZoomEnabled() const override;
246
247
  virtual void SetLayersObserverEpoch(LayersObserverEpoch aEpoch) override;
248
249
  virtual void AddDidCompositeObserver(DidCompositeObserver* aObserver) override;
250
  virtual void RemoveDidCompositeObserver(DidCompositeObserver* aObserver) override;
251
252
  virtual already_AddRefed<PersistentBufferProvider>
253
  CreatePersistentBufferProvider(const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat) override;
254
255
0
  static PaintTiming* MaybeGetPaintTiming(LayerManager* aManager) {
256
0
    if (!aManager) {
257
0
      return nullptr;
258
0
    }
259
0
    if (ClientLayerManager* lm = aManager->AsClientLayerManager()) {
260
0
      return &lm->AsShadowForwarder()->GetPaintTiming();
261
0
    }
262
0
    return nullptr;
263
0
  }
264
265
protected:
266
  enum TransactionPhase {
267
    PHASE_NONE, PHASE_CONSTRUCTION, PHASE_DRAWING, PHASE_FORWARD
268
  };
269
  TransactionPhase mPhase;
270
271
private:
272
  /**
273
   * Forward transaction results to the parent context.
274
   */
275
  void ForwardTransaction(bool aScheduleComposite);
276
277
  /**
278
   * Take a snapshot of the parent context, and copy
279
   * it into mShadowTarget.
280
   */
281
  void MakeSnapshotIfRequired();
282
283
  void ClearLayer(Layer* aLayer);
284
285
  void HandleMemoryPressureLayer(Layer* aLayer);
286
287
  bool EndTransactionInternal(DrawPaintedLayerCallback aCallback,
288
                              void* aCallbackData,
289
                              EndTransactionFlags);
290
291
  void FlushAsyncPaints();
292
293
  LayerRefArray mKeepAlive;
294
295
  nsIWidget* mWidget;
296
297
  /* PaintedLayer callbacks; valid at the end of a transaciton,
298
   * while rendering */
299
  DrawPaintedLayerCallback mPaintedLayerCallback;
300
  void *mPaintedLayerCallbackData;
301
302
  // When we're doing a transaction in order to draw to a non-default
303
  // target, the layers transaction is only performed in order to send
304
  // a PLayers:Update.  We save the original non-default target to
305
  // mShadowTarget, and then perform the transaction using
306
  // mDummyTarget as the render target.  After the transaction ends,
307
  // we send a message to our remote side to capture the actual pixels
308
  // being drawn to the default target, and then copy those pixels
309
  // back to mShadowTarget.
310
  RefPtr<gfxContext> mShadowTarget;
311
312
  RefPtr<TransactionIdAllocator> mTransactionIdAllocator;
313
  TransactionId mLatestTransactionId;
314
  TimeDuration mLastPaintTime;
315
316
  // Sometimes we draw to targets that don't natively support
317
  // landscape/portrait orientation.  When we need to implement that
318
  // ourselves, |mTargetRotation| describes the induced transform we
319
  // need to apply when compositing content to our target.
320
  ScreenRotation mTargetRotation;
321
322
  // Used to repeat the transaction right away (to avoid rebuilding
323
  // a display list) to support progressive drawing.
324
  bool mRepeatTransaction;
325
  bool mIsRepeatTransaction;
326
  bool mTransactionIncomplete;
327
  bool mCompositorMightResample;
328
  bool mNeedsComposite;
329
  bool mQueuedAsyncPaints;
330
331
  // An incrementing sequence number for paints.
332
  // Incremented in BeginTransaction(), but not for repeat transactions.
333
  uint32_t mPaintSequenceNumber;
334
335
  APZTestData mApzTestData;
336
337
  RefPtr<ShadowLayerForwarder> mForwarder;
338
  mozilla::TimeStamp mTransactionStart;
339
340
  nsTArray<DidCompositeObserver*> mDidCompositeObservers;
341
342
  RefPtr<MemoryPressureObserver> mMemoryPressureObserver;
343
};
344
345
class ClientLayer : public ShadowableLayer
346
{
347
public:
348
  ClientLayer()
349
0
  {
350
0
    MOZ_COUNT_CTOR(ClientLayer);
351
0
  }
352
353
  ~ClientLayer();
354
355
  // Shrink memory usage.
356
  // Called when "memory-pressure" is observed.
357
0
  virtual void HandleMemoryPressure() { }
358
359
  virtual void RenderLayer() = 0;
360
0
  virtual void RenderLayerWithReadback(ReadbackProcessor *aReadback) { RenderLayer(); }
361
362
0
  virtual ClientPaintedLayer* AsThebes() { return nullptr; }
363
364
  static inline ClientLayer *
365
  ToClientLayer(Layer* aLayer)
366
0
  {
367
0
    return static_cast<ClientLayer*>(aLayer->ImplData());
368
0
  }
369
370
  template <typename LayerType>
371
0
  static inline void RenderMaskLayers(LayerType* aLayer) {
372
0
    if (aLayer->GetMaskLayer()) {
373
0
      ToClientLayer(aLayer->GetMaskLayer())->RenderLayer();
374
0
    }
375
0
    for (size_t i = 0; i < aLayer->GetAncestorMaskLayerCount(); i++) {
376
0
      ToClientLayer(aLayer->GetAncestorMaskLayerAt(i))->RenderLayer();
377
0
    }
378
0
  }
Unexecuted instantiation: void mozilla::layers::ClientLayer::RenderMaskLayers<mozilla::layers::ClientColorLayer>(mozilla::layers::ClientColorLayer*)
Unexecuted instantiation: void mozilla::layers::ClientLayer::RenderMaskLayers<mozilla::layers::ClientContainerLayer>(mozilla::layers::ClientContainerLayer*)
Unexecuted instantiation: void mozilla::layers::ClientLayer::RenderMaskLayers<mozilla::layers::ClientCanvasLayer>(mozilla::layers::ClientCanvasLayer*)
Unexecuted instantiation: void mozilla::layers::ClientLayer::RenderMaskLayers<mozilla::layers::ClientImageLayer>(mozilla::layers::ClientImageLayer*)
Unexecuted instantiation: void mozilla::layers::ClientLayer::RenderMaskLayers<mozilla::layers::ClientPaintedLayer>(mozilla::layers::ClientPaintedLayer*)
Unexecuted instantiation: void mozilla::layers::ClientLayer::RenderMaskLayers<mozilla::layers::ClientTiledPaintedLayer>(mozilla::layers::ClientTiledPaintedLayer*)
379
};
380
381
// Create a LayerHandle for aLayer, if we're forwarding our layer tree
382
// to a parent process.  Record the new layer creation in the current
383
// open transaction as a side effect.
384
template<typename CreatedMethod> void
385
CreateShadowFor(ClientLayer* aLayer,
386
                ClientLayerManager* aMgr,
387
                CreatedMethod aMethod)
388
0
{
389
0
  LayerHandle shadow = aMgr->AsShadowForwarder()->ConstructShadowFor(aLayer);
390
0
  if (!shadow) {
391
0
    return;
392
0
  }
393
0
394
0
  aLayer->SetShadow(aMgr->AsShadowForwarder(), shadow);
395
0
  (aMgr->AsShadowForwarder()->*aMethod)(aLayer);
396
0
  aMgr->Hold(aLayer->AsLayer());
397
0
}
398
399
#define CREATE_SHADOW(_type)                                       \
400
0
  CreateShadowFor(layer, this,                                     \
401
0
                  &ShadowLayerForwarder::Created ## _type ## Layer)
402
403
404
} // namespace layers
405
} // namespace mozilla
406
407
#endif /* GFX_CLIENTLAYERMANAGER_H */