Source code

Revision control

Other Tools

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_LAYERS_H
8
#define GFX_LAYERS_H
9
10
#include <map>
11
#include <unordered_set>
12
#include <stdint.h> // for uint32_t, uint64_t, uint8_t
13
#include <stdio.h> // for FILE
14
#include <sys/types.h> // for int32_t
15
#include "FrameMetrics.h" // for FrameMetrics
16
#include "Units.h" // for LayerMargin, LayerPoint, ParentLayerIntRect
17
#include "gfxContext.h"
18
#include "gfxTypes.h"
19
#include "gfxPoint.h" // for gfxPoint
20
#include "gfxRect.h" // for gfxRect
21
#include "gfx2DGlue.h"
22
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2, etc
23
#include "mozilla/Array.h"
24
#include "mozilla/DebugOnly.h" // for DebugOnly
25
#include "mozilla/EventForwards.h" // for nsPaintEvent
26
#include "mozilla/Maybe.h" // for Maybe
27
#include "mozilla/Poison.h"
28
#include "mozilla/RefPtr.h" // for already_AddRefed
29
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
30
#include "mozilla/UniquePtr.h" // for UniquePtr
31
#include "mozilla/gfx/BaseMargin.h" // for BaseMargin
32
#include "mozilla/gfx/BasePoint.h" // for BasePoint
33
#include "mozilla/gfx/Point.h" // for IntSize
34
#include "mozilla/gfx/TiledRegion.h" // for TiledIntRegion
35
#include "mozilla/gfx/Types.h" // for SurfaceFormat
36
#include "mozilla/gfx/UserData.h" // for UserData, etc
37
#include "mozilla/layers/AnimationInfo.h" // for AnimationInfo
38
#include "mozilla/layers/BSPTree.h" // for LayerPolygon
39
#include "mozilla/layers/CanvasRenderer.h"
40
#include "mozilla/layers/LayerAttributes.h"
41
#include "mozilla/layers/LayersTypes.h"
42
#include "mozilla/webrender/WebRenderTypes.h"
43
#include "mozilla/mozalloc.h" // for operator delete, etc
44
#include "nsCOMPtr.h" // for already_AddRefed
45
#include "nsCSSPropertyID.h" // for nsCSSPropertyID
46
#include "nsDebug.h" // for NS_ASSERTION
47
#include "nsISupportsImpl.h" // for Layer::Release, etc
48
#include "nsRect.h" // for mozilla::gfx::IntRect
49
#include "nsRegion.h" // for nsIntRegion
50
#include "nsString.h" // for nsCString
51
#include "nsTArray.h" // for nsTArray
52
#include "nsTArrayForwardDeclare.h" // for nsTArray
53
#include "nscore.h" // for nsACString, nsAString
54
#include "mozilla/Logging.h" // for PRLogModuleInfo
55
#include "nsIWidget.h" // For plugin window configuration information structs
56
#include "ImageContainer.h"
57
58
class gfxContext;
59
class nsDisplayListBuilder;
60
class nsDisplayItem;
61
62
extern uint8_t gLayerManagerLayerBuilder;
63
64
namespace mozilla {
65
66
class ComputedTimingFunction;
67
class FrameLayerBuilder;
68
69
namespace gl {
70
class GLContext;
71
} // namespace gl
72
73
namespace gfx {
74
class DrawTarget;
75
} // namespace gfx
76
77
namespace layers {
78
79
class Animation;
80
class AsyncCanvasRenderer;
81
class AsyncPanZoomController;
82
class BasicLayerManager;
83
class ClientLayerManager;
84
class HostLayerManager;
85
class Layer;
86
class LayerMetricsWrapper;
87
class PaintedLayer;
88
class ContainerLayer;
89
class ImageLayer;
90
class ColorLayer;
91
class CompositorAnimations;
92
class CompositorBridgeChild;
93
class CanvasLayer;
94
class ReadbackLayer;
95
class ReadbackProcessor;
96
class RefLayer;
97
class HostLayer;
98
class FocusTarget;
99
class KnowsCompositor;
100
class ShadowableLayer;
101
class ShadowLayerForwarder;
102
class LayerManagerComposite;
103
class SpecificLayerAttributes;
104
class TransactionIdAllocator;
105
class Compositor;
106
class FrameUniformityData;
107
class PersistentBufferProvider;
108
class GlyphArray;
109
class WebRenderLayerManager;
110
struct AnimData;
111
112
namespace layerscope {
113
class LayersPacket;
114
} // namespace layerscope
115
116
#define MOZ_LAYER_DECL_NAME(n, e) \
117
const char* Name() const override { return n; } \
118
LayerType GetType() const override { return e; } \
119
static LayerType Type() { return e; }
120
121
// Defined in LayerUserData.h; please include that file instead.
122
class LayerUserData;
123
124
class DidCompositeObserver {
125
public:
126
virtual void DidComposite() = 0;
127
};
128
129
class FrameRecorder {
130
public:
131
/**
132
* Record (and return) frame-intervals and paint-times for frames which were
133
* presented between calling StartFrameTimeRecording and
134
* StopFrameTimeRecording.
135
*
136
* - Uses a cyclic buffer and serves concurrent consumers, so if Stop is
137
* called too late
138
* (elements were overwritten since Start), result is considered invalid
139
* and hence empty.)
140
* - Buffer is capable of holding 10 seconds @ 60fps (or more if frames were
141
* less frequent).
142
* Can be changed (up to 1 hour) via pref:
143
* toolkit.framesRecording.bufferSize.
144
* - Note: the first frame-interval may be longer than expected because last
145
* frame
146
* might have been presented some time before calling
147
* StartFrameTimeRecording.
148
*/
149
150
/**
151
* Returns a handle which represents current recording start position.
152
*/
153
virtual uint32_t StartFrameTimeRecording(int32_t aBufferSize);
154
155
/**
156
* Clears, then populates aFrameIntervals with the recorded frame timing
157
* data. The array will be empty if data was overwritten since
158
* aStartIndex was obtained.
159
*/
160
virtual void StopFrameTimeRecording(uint32_t aStartIndex,
161
nsTArray<float>& aFrameIntervals);
162
163
void RecordFrame();
164
165
private:
166
struct FramesTimingRecording {
167
// Stores state and data for frame intervals and paint times recording.
168
// see LayerManager::StartFrameTimeRecording() at Layers.cpp for more
169
// details.
170
FramesTimingRecording()
171
: mNextIndex(0),
172
mLatestStartIndex(0),
173
mCurrentRunStartIndex(0),
174
mIsPaused(true) {}
175
nsTArray<float> mIntervals;
176
TimeStamp mLastFrameTime;
177
uint32_t mNextIndex;
178
uint32_t mLatestStartIndex;
179
uint32_t mCurrentRunStartIndex;
180
bool mIsPaused;
181
};
182
FramesTimingRecording mRecording;
183
};
184
185
/*
186
* Motivation: For truly smooth animation and video playback, we need to
187
* be able to compose frames and render them on a dedicated thread (i.e.
188
* off the main thread where DOM manipulation, script execution and layout
189
* induce difficult-to-bound latency). This requires Gecko to construct
190
* some kind of persistent scene structure (graph or tree) that can be
191
* safely transmitted across threads. We have other scenarios (e.g. mobile
192
* browsing) where retaining some rendered data between paints is desired
193
* for performance, so again we need a retained scene structure.
194
*
195
* Our retained scene structure is a layer tree. Each layer represents
196
* content which can be composited onto a destination surface; the root
197
* layer is usually composited into a window, and non-root layers are
198
* composited into their parent layers. Layers have attributes (e.g.
199
* opacity and clipping) that influence their compositing.
200
*
201
* We want to support a variety of layer implementations, including
202
* a simple "immediate mode" implementation that doesn't retain any
203
* rendered data between paints (i.e. uses cairo in just the way that
204
* Gecko used it before layers were introduced). But we also don't want
205
* to have bifurcated "layers"/"non-layers" rendering paths in Gecko.
206
* Therefore the layers API is carefully designed to permit maximally
207
* efficient implementation in an "immediate mode" style. See the
208
* BasicLayerManager for such an implementation.
209
*/
210
211
/**
212
* A LayerManager controls a tree of layers. All layers in the tree
213
* must use the same LayerManager.
214
*
215
* All modifications to a layer tree must happen inside a transaction.
216
* Only the state of the layer tree at the end of a transaction is
217
* rendered. Transactions cannot be nested
218
*
219
* Each transaction has two phases:
220
* 1) Construction: layers are created, inserted, removed and have
221
* properties set on them in this phase.
222
* BeginTransaction and BeginTransactionWithTarget start a transaction in
223
* the Construction phase.
224
* 2) Drawing: PaintedLayers are rendered into in this phase, in tree
225
* order. When the client has finished drawing into the PaintedLayers, it should
226
* call EndTransaction to complete the transaction.
227
*
228
* All layer API calls happen on the main thread.
229
*
230
* Layers are refcounted. The layer manager holds a reference to the
231
* root layer, and each container layer holds a reference to its children.
232
*/
233
class LayerManager : public FrameRecorder {
234
NS_INLINE_DECL_REFCOUNTING(LayerManager)
235
236
protected:
237
typedef mozilla::gfx::DrawTarget DrawTarget;
238
typedef mozilla::gfx::IntSize IntSize;
239
typedef mozilla::gfx::SurfaceFormat SurfaceFormat;
240
241
public:
242
LayerManager()
243
: mDestroyed(false),
244
mSnapEffectiveTransforms(true),
245
mId(0),
246
mInTransaction(false),
247
mContainsSVG(false),
248
mPaintedPixelCount(0) {}
249
250
/**
251
* Release layers and resources held by this layer manager, and mark
252
* it as destroyed. Should do any cleanup necessary in preparation
253
* for its widget going away. After this call, only user data calls
254
* are valid on the layer manager.
255
*/
256
virtual void Destroy() {
257
mDestroyed = true;
258
mUserData.Destroy();
259
mRoot = nullptr;
260
}
261
bool IsDestroyed() { return mDestroyed; }
262
263
virtual ShadowLayerForwarder* AsShadowForwarder() { return nullptr; }
264
265
virtual KnowsCompositor* AsKnowsCompositor() { return nullptr; }
266
267
virtual LayerManagerComposite* AsLayerManagerComposite() { return nullptr; }
268
269
virtual ClientLayerManager* AsClientLayerManager() { return nullptr; }
270
271
virtual BasicLayerManager* AsBasicLayerManager() { return nullptr; }
272
virtual HostLayerManager* AsHostLayerManager() { return nullptr; }
273
274
virtual WebRenderLayerManager* AsWebRenderLayerManager() { return nullptr; }
275
276
/**
277
* Returns true if this LayerManager is owned by an nsIWidget,
278
* and is used for drawing into the widget.
279
*/
280
virtual bool IsWidgetLayerManager() { return true; }
281
virtual bool IsInactiveLayerManager() { return false; }
282
283
/**
284
* Start a new transaction. Nested transactions are not allowed so
285
* there must be no transaction currently in progress.
286
* This transaction will update the state of the window from which
287
* this LayerManager was obtained.
288
*/
289
virtual bool BeginTransaction(const nsCString& aURL = nsCString()) = 0;
290
/**
291
* Start a new transaction. Nested transactions are not allowed so
292
* there must be no transaction currently in progress.
293
* This transaction will render the contents of the layer tree to
294
* the given target context. The rendering will be complete when
295
* EndTransaction returns.
296
*/
297
virtual bool BeginTransactionWithTarget(
298
gfxContext* aTarget, const nsCString& aURL = nsCString()) = 0;
299
300
enum EndTransactionFlags {
301
END_DEFAULT = 0,
302
END_NO_IMMEDIATE_REDRAW = 1 << 0, // Do not perform the drawing phase
303
END_NO_COMPOSITE =
304
1 << 1, // Do not composite after drawing painted layer contents.
305
END_NO_REMOTE_COMPOSITE = 1 << 2 // Do not schedule a composition with a
306
// remote Compositor, if one exists.
307
};
308
309
FrameLayerBuilder* GetLayerBuilder() {
310
return reinterpret_cast<FrameLayerBuilder*>(
311
GetUserData(&gLayerManagerLayerBuilder));
312
}
313
314
/**
315
* Attempts to end an "empty transaction". There must have been no
316
* changes to the layer tree since the BeginTransaction().
317
* It's possible for this to fail; PaintedLayers may need to be updated
318
* due to VRAM data being lost, for example. In such cases this method
319
* returns false, and the caller must proceed with a normal layer tree
320
* update and EndTransaction.
321
*/
322
virtual bool EndEmptyTransaction(
323
EndTransactionFlags aFlags = END_DEFAULT) = 0;
324
325
/**
326
* Function called to draw the contents of each PaintedLayer.
327
* aRegionToDraw contains the region that needs to be drawn.
328
* This would normally be a subregion of the visible region.
329
* The callee must draw all of aRegionToDraw. Drawing outside
330
* aRegionToDraw will be clipped out or ignored.
331
* The callee must draw all of aRegionToDraw.
332
* This region is relative to 0,0 in the PaintedLayer.
333
*
334
* aDirtyRegion should contain the total region that is be due to be painted
335
* during the transaction, even though only aRegionToDraw should be drawn
336
* during this call. aRegionToDraw must be entirely contained within
337
* aDirtyRegion. If the total dirty region is unknown it is okay to pass a
338
* subregion of the total dirty region, e.g. just aRegionToDraw, though it
339
* may not be as efficient.
340
*
341
* aRegionToInvalidate contains a region whose contents have been
342
* changed by the layer manager and which must therefore be invalidated.
343
* For example, this could be non-empty if a retained layer internally
344
* switches from RGBA to RGB or back ... we might want to repaint it to
345
* consistently use subpixel-AA or not.
346
* This region is relative to 0,0 in the PaintedLayer.
347
* aRegionToInvalidate may contain areas that are outside
348
* aRegionToDraw; the callee must ensure that these areas are repainted
349
* in the current layer manager transaction or in a later layer
350
* manager transaction.
351
*
352
* aContext must not be used after the call has returned.
353
* We guarantee that buffered contents in the visible
354
* region are valid once drawing is complete.
355
*
356
* The origin of aContext is 0,0 in the PaintedLayer.
357
*/
358
typedef void (*DrawPaintedLayerCallback)(
359
PaintedLayer* aLayer, gfxContext* aContext,
360
const nsIntRegion& aRegionToDraw, const nsIntRegion& aDirtyRegion,
361
DrawRegionClip aClip, const nsIntRegion& aRegionToInvalidate,
362
void* aCallbackData);
363
364
/**
365
* Finish the construction phase of the transaction, perform the
366
* drawing phase, and end the transaction.
367
* During the drawing phase, all PaintedLayers in the tree are
368
* drawn in tree order, exactly once each, except for those layers
369
* where it is known that the visible region is empty.
370
*/
371
virtual void EndTransaction(DrawPaintedLayerCallback aCallback,
372
void* aCallbackData,
373
EndTransactionFlags aFlags = END_DEFAULT) = 0;
374
375
/**
376
* Schedule a composition with the remote Compositor, if one exists
377
* for this LayerManager. Useful in conjunction with the
378
* END_NO_REMOTE_COMPOSITE flag to EndTransaction.
379
*/
380
virtual void ScheduleComposite() {}
381
382
virtual void SetNeedsComposite(bool aNeedsComposite) {}
383
virtual bool NeedsComposite() const { return false; }
384
385
virtual bool HasShadowManagerInternal() const { return false; }
386
bool HasShadowManager() const { return HasShadowManagerInternal(); }
387
virtual void StorePluginWidgetConfigurations(
388
const nsTArray<nsIWidget::Configuration>& aConfigurations) {}
389
bool IsSnappingEffectiveTransforms() { return mSnapEffectiveTransforms; }
390
391
/**
392
* Returns true if the underlying platform can properly support layers with
393
* SurfaceMode::SURFACE_COMPONENT_ALPHA.
394
*/
395
static bool LayersComponentAlphaEnabled();
396
397
/**
398
* Returns true if this LayerManager can properly support layers with
399
* SurfaceMode::SURFACE_COMPONENT_ALPHA. LayerManagers that can't will use
400
* transparent surfaces (and lose subpixel-AA for text).
401
*/
402
virtual bool AreComponentAlphaLayersEnabled();
403
404
/**
405
* Returns true if this LayerManager always requires an intermediate surface
406
* to render blend operations.
407
*/
408
virtual bool BlendingRequiresIntermediateSurface() { return false; }
409
410
/**
411
* CONSTRUCTION PHASE ONLY
412
* Set the root layer. The root layer is initially null. If there is
413
* no root layer, EndTransaction won't draw anything.
414
*/
415
virtual void SetRoot(Layer* aLayer) = 0;
416
/**
417
* Can be called anytime
418
*/
419
Layer* GetRoot() { return mRoot; }
420
421
/**
422
* Does a breadth-first search from the root layer to find the first
423
* scrollable layer, and returns its ViewID. Note that there may be
424
* other layers in the tree which share the same ViewID.
425
* Can be called any time.
426
*/
427
ScrollableLayerGuid::ViewID GetRootScrollableLayerId();
428
429
/**
430
* Returns a LayerMetricsWrapper containing the Root
431
* Content Documents layer.
432
*/
433
LayerMetricsWrapper GetRootContentLayer();
434
435
/**
436
* CONSTRUCTION PHASE ONLY
437
* Called when a managee has mutated.
438
* Subclasses overriding this method must first call their
439
* superclass's impl
440
*/
441
virtual void Mutated(Layer* aLayer) {}
442
virtual void MutatedSimple(Layer* aLayer) {}
443
444
/**
445
* Hints that can be used during PaintedLayer creation to influence the type
446
* or properties of the layer created.
447
*
448
* NONE: No hint.
449
* SCROLLABLE: This layer may represent scrollable content.
450
*/
451
enum PaintedLayerCreationHint { NONE, SCROLLABLE };
452
453
/**
454
* CONSTRUCTION PHASE ONLY
455
* Create a PaintedLayer for this manager's layer tree.
456
*/
457
virtual already_AddRefed<PaintedLayer> CreatePaintedLayer() = 0;
458
/**
459
* CONSTRUCTION PHASE ONLY
460
* Create a PaintedLayer for this manager's layer tree, with a creation hint
461
* parameter to help optimise the type of layer created.
462
*/
463
virtual already_AddRefed<PaintedLayer> CreatePaintedLayerWithHint(
464
PaintedLayerCreationHint) {
465
return CreatePaintedLayer();
466
}
467
/**
468
* CONSTRUCTION PHASE ONLY
469
* Create a ContainerLayer for this manager's layer tree.
470
*/
471
virtual already_AddRefed<ContainerLayer> CreateContainerLayer() = 0;
472
/**
473
* CONSTRUCTION PHASE ONLY
474
* Create an ImageLayer for this manager's layer tree.
475
*/
476
virtual already_AddRefed<ImageLayer> CreateImageLayer() = 0;
477
/**
478
* CONSTRUCTION PHASE ONLY
479
* Create a ColorLayer for this manager's layer tree.
480
*/
481
virtual already_AddRefed<ColorLayer> CreateColorLayer() = 0;
482
/**
483
* CONSTRUCTION PHASE ONLY
484
* Create a CanvasLayer for this manager's layer tree.
485
*/
486
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() = 0;
487
/**
488
* CONSTRUCTION PHASE ONLY
489
* Create a ReadbackLayer for this manager's layer tree.
490
*/
491
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() {
492
return nullptr;
493
}
494
/**
495
* CONSTRUCTION PHASE ONLY
496
* Create a RefLayer for this manager's layer tree.
497
*/
498
virtual already_AddRefed<RefLayer> CreateRefLayer() { return nullptr; }
499
/**
500
* Can be called anytime, from any thread.
501
*
502
* Creates an Image container which forwards its images to the compositor
503
* within layer transactions on the main thread or asynchronously using the
504
* ImageBridge IPDL protocol. In the case of asynchronous, If the protocol is
505
* not available, the returned ImageContainer will forward images within layer
506
* transactions.
507
*/
508
static already_AddRefed<ImageContainer> CreateImageContainer(
509
ImageContainer::Mode flag = ImageContainer::SYNCHRONOUS);
510
511
/**
512
* Type of layer manager his is. This is to be used sparsely in order to
513
* avoid a lot of Layers backend specific code. It should be used only when
514
* Layers backend specific functionality is necessary.
515
*/
516
virtual LayersBackend GetBackendType() = 0;
517
518
/**
519
* Type of layers backend that will be used to composite this layer tree.
520
* When compositing is done remotely, then this returns the layers type
521
* of the compositor.
522
*/
523
virtual LayersBackend GetCompositorBackendType() { return GetBackendType(); }
524
525
/**
526
* Creates a DrawTarget which is optimized for inter-operating with this
527
* layer manager.
528
*/
529
virtual already_AddRefed<DrawTarget> CreateOptimalDrawTarget(
530
const IntSize& aSize, SurfaceFormat imageFormat);
531
532
/**
533
* Creates a DrawTarget for alpha masks which is optimized for inter-
534
* operating with this layer manager. In contrast to CreateOptimalDrawTarget,
535
* this surface is optimised for drawing alpha only and we assume that
536
* drawing the mask is fairly simple.
537
*/
538
virtual already_AddRefed<DrawTarget> CreateOptimalMaskDrawTarget(
539
const IntSize& aSize);
540
541
/**
542
* Creates a DrawTarget for use with canvas which is optimized for
543
* inter-operating with this layermanager.
544
*/
545
virtual already_AddRefed<mozilla::gfx::DrawTarget> CreateDrawTarget(
546
const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
547
548
/**
549
* Creates a PersistentBufferProvider for use with canvas which is optimized
550
* for inter-operating with this layermanager.
551
*/
552
virtual already_AddRefed<PersistentBufferProvider>
553
CreatePersistentBufferProvider(const mozilla::gfx::IntSize& aSize,
554
mozilla::gfx::SurfaceFormat aFormat);
555
556
virtual bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) {
557
return true;
558
}
559
560
/**
561
* returns the maximum texture size on this layer backend, or INT32_MAX
562
* if there is no maximum
563
*/
564
virtual int32_t GetMaxTextureSize() const = 0;
565
566
/**
567
* Return the name of the layer manager's backend.
568
*/
569
virtual void GetBackendName(nsAString& aName) = 0;
570
571
/**
572
* This setter can be used anytime. The user data for all keys is
573
* initially null. Ownership pases to the layer manager.
574
*/
575
void SetUserData(void* aKey, LayerUserData* aData) {
576
mUserData.Add(static_cast<gfx::UserDataKey*>(aKey), aData,
577
LayerUserDataDestroy);
578
}
579
/**
580
* This can be used anytime. Ownership passes to the caller!
581
*/
582
UniquePtr<LayerUserData> RemoveUserData(void* aKey);
583
584
/**
585
* This getter can be used anytime.
586
*/
587
bool HasUserData(void* aKey) {
588
return mUserData.Has(static_cast<gfx::UserDataKey*>(aKey));
589
}
590
/**
591
* This getter can be used anytime. Ownership is retained by the layer
592
* manager.
593
*/
594
LayerUserData* GetUserData(void* aKey) const {
595
return static_cast<LayerUserData*>(
596
mUserData.Get(static_cast<gfx::UserDataKey*>(aKey)));
597
}
598
599
/**
600
* Must be called outside of a layers transaction.
601
*
602
* For the subtree rooted at |aSubtree|, this attempts to free up
603
* any free-able resources like retained buffers, but may do nothing
604
* at all. After this call, the layer tree is left in an undefined
605
* state; the layers in |aSubtree|'s subtree may no longer have
606
* buffers with valid content and may no longer be able to draw
607
* their visible and valid regions.
608
*
609
* In general, a painting or forwarding transaction on |this| must
610
* complete on the tree before it returns to a valid state.
611
*
612
* Resource freeing begins from |aSubtree| or |mRoot| if |aSubtree|
613
* is null. |aSubtree|'s manager must be this.
614
*/
615
virtual void ClearCachedResources(Layer* aSubtree = nullptr) {}
616
617
/**
618
* Flag the next paint as the first for a document.
619
*/
620
virtual void SetIsFirstPaint() {}
621
virtual bool GetIsFirstPaint() const { return false; }
622
623
/**
624
* Set the current focus target to be sent with the next paint.
625
*/
626
virtual void SetFocusTarget(const FocusTarget& aFocusTarget) {}
627
628
/**
629
* Make sure that the previous transaction has been entirely
630
* completed.
631
*
632
* Note: This may sychronously wait on a remote compositor
633
* to complete rendering.
634
*/
635
virtual void FlushRendering() {}
636
637
/**
638
* Make sure that the previous transaction has been
639
* received. This will synchronsly wait on a remote compositor. */
640
virtual void WaitOnTransactionProcessed() {}
641
642
virtual void SendInvalidRegion(const nsIntRegion& aRegion) {}
643
644
/**
645
* Checks if we need to invalidate the OS widget to trigger
646
* painting when updating this layer manager.
647
*/
648
virtual bool NeedsWidgetInvalidation() { return true; }
649
650
virtual const char* Name() const { return "???"; }
651
652
/**
653
* Dump information about this layer manager and its managed tree to
654
* aStream.
655
*/
656
void Dump(std::stringstream& aStream, const char* aPrefix = "",
657
bool aDumpHtml = false, bool aSorted = false);
658
/**
659
* Dump information about just this layer manager itself to aStream
660
*/
661
void DumpSelf(std::stringstream& aStream, const char* aPrefix = "",
662
bool aSorted = false);
663
void Dump(bool aSorted = false);
664
665
/**
666
* Dump information about this layer manager and its managed tree to
667
* layerscope packet.
668
*/
669
void Dump(layerscope::LayersPacket* aPacket);
670
671
/**
672
* Log information about this layer manager and its managed tree to
673
* the NSPR log (if enabled for "Layers").
674
*/
675
void Log(const char* aPrefix = "");
676
/**
677
* Log information about just this layer manager itself to the NSPR
678
* log (if enabled for "Layers").
679
*/
680
void LogSelf(const char* aPrefix = "");
681
682
static bool IsLogEnabled();
683
static mozilla::LogModule* GetLog();
684
685
bool IsCompositingCheap(LayersBackend aBackend) {
686
// LayersBackend::LAYERS_NONE is an error state, but in that case we should
687
// try to avoid loading the compositor!
688
return LayersBackend::LAYERS_BASIC != aBackend &&
689
LayersBackend::LAYERS_NONE != aBackend;
690
}
691
692
virtual bool IsCompositingCheap() { return true; }
693
694
bool IsInTransaction() const { return mInTransaction; }
695
virtual void GetFrameUniformity(FrameUniformityData* aOutData) {}
696
697
virtual void SetRegionToClear(const nsIntRegion& aRegion) {
698
mRegionToClear = aRegion;
699
}
700
701
virtual float RequestProperty(const nsAString& property) { return -1; }
702
703
const TimeStamp& GetAnimationReadyTime() const { return mAnimationReadyTime; }
704
705
virtual bool AsyncPanZoomEnabled() const { return false; }
706
707
static void LayerUserDataDestroy(void* data);
708
709
void AddPaintedPixelCount(int32_t aCount) { mPaintedPixelCount += aCount; }
710
711
uint32_t GetAndClearPaintedPixelCount() {
712
uint32_t count = mPaintedPixelCount;
713
mPaintedPixelCount = 0;
714
return count;
715
}
716
717
virtual void SetLayersObserverEpoch(LayersObserverEpoch aEpoch) {}
718
719
virtual void DidComposite(TransactionId aTransactionId,
720
const mozilla::TimeStamp& aCompositeStart,
721
const mozilla::TimeStamp& aCompositeEnd) {}
722
723
virtual void AddDidCompositeObserver(DidCompositeObserver* aObserver) {
724
MOZ_CRASH("GFX: LayerManager");
725
}
726
virtual void RemoveDidCompositeObserver(DidCompositeObserver* aObserver) {
727
MOZ_CRASH("GFX: LayerManager");
728
}
729
730
virtual void UpdateTextureFactoryIdentifier(
731
const TextureFactoryIdentifier& aNewIdentifier) {}
732
733
virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() {
734
return TextureFactoryIdentifier();
735
}
736
737
virtual void SetTransactionIdAllocator(TransactionIdAllocator* aAllocator) {}
738
739
virtual TransactionId GetLastTransactionId() { return TransactionId{0}; }
740
741
virtual CompositorBridgeChild* GetCompositorBridgeChild() { return nullptr; }
742
743
void RegisterPayload(const CompositionPayload& aPayload) {
744
mPayload.AppendElement(aPayload);
745
MOZ_ASSERT(mPayload.Length() < 10000);
746
}
747
748
void RegisterPayloads(const nsTArray<CompositionPayload>& aPayload) {
749
mPayload.AppendElements(aPayload);
750
MOZ_ASSERT(mPayload.Length() < 10000);
751
}
752
753
virtual void PayloadPresented();
754
755
void SetContainsSVG(bool aContainsSVG) { mContainsSVG = aContainsSVG; }
756
757
protected:
758
RefPtr<Layer> mRoot;
759
gfx::UserData mUserData;
760
bool mDestroyed;
761
bool mSnapEffectiveTransforms;
762
763
nsIntRegion mRegionToClear;
764
765
// Protected destructor, to discourage deletion outside of Release():
766
virtual ~LayerManager() = default;
767
768
// Print interesting information about this into aStreamo. Internally
769
// used to implement Dump*() and Log*().
770
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);
771
772
// Print interesting information about this into layerscope packet.
773
// Internally used to implement Dump().
774
virtual void DumpPacket(layerscope::LayersPacket* aPacket);
775
776
uint64_t mId;
777
bool mInTransaction;
778
779
// Used for tracking CONTENT_FRAME_TIME_WITH_SVG
780
bool mContainsSVG;
781
// The time when painting most recently finished. This is recorded so that
782
// we can time any play-pending animations from this point.
783
TimeStamp mAnimationReadyTime;
784
// The count of pixels that were painted in the current transaction.
785
uint32_t mPaintedPixelCount;
786
// The payload associated with currently pending painting work, for
787
// client layer managers that typically means payload that is part of the
788
// 'upcoming transaction', for HostLayerManagers this typically means
789
// what has been included in received transactions to be presented on the
790
// next composite.
791
// IMPORTANT: Clients should take care to clear this or risk it slowly
792
// growing out of control.
793
nsTArray<CompositionPayload> mPayload;
794
795
public:
796
/*
797
* Methods to store/get/clear a "pending scroll info update" object on a
798
* per-scrollid basis. This is used for empty transactions that push over
799
* scroll position updates to the APZ code.
800
*/
801
virtual bool SetPendingScrollUpdateForNextTransaction(
802
ScrollableLayerGuid::ViewID aScrollId,
803
const ScrollUpdateInfo& aUpdateInfo, wr::RenderRoot aRenderRoot);
804
Maybe<ScrollUpdateInfo> GetPendingScrollInfoUpdate(
805
ScrollableLayerGuid::ViewID aScrollId);
806
std::unordered_set<ScrollableLayerGuid::ViewID>
807
ClearPendingScrollInfoUpdate();
808
809
protected:
810
wr::RenderRootArray<ScrollUpdatesMap> mPendingScrollUpdates;
811
};
812
813
/**
814
* A Layer represents anything that can be rendered onto a destination
815
* surface.
816
*/
817
class Layer {
818
NS_INLINE_DECL_REFCOUNTING(Layer)
819
820
typedef nsTArray<Animation> AnimationArray;
821
822
public:
823
// Keep these in alphabetical order
824
enum LayerType {
825
TYPE_CANVAS,
826
TYPE_COLOR,
827
TYPE_CONTAINER,
828
TYPE_DISPLAYITEM,
829
TYPE_IMAGE,
830
TYPE_READBACK,
831
TYPE_REF,
832
TYPE_SHADOW,
833
TYPE_PAINTED
834
};
835
836
/**
837
* Returns the LayerManager this Layer belongs to. Note that the layer
838
* manager might be in a destroyed state, at which point it's only
839
* valid to set/get user data from it.
840
*/
841
LayerManager* Manager() { return mManager; }
842
843
/**
844
* This should only be called when changing layer managers from HostLayers.
845
*/
846
void SetManager(LayerManager* aManager, HostLayer* aSelf);
847
848
enum {
849
/**
850
* If this is set, the caller is promising that by the end of this
851
* transaction the entire visible region (as specified by
852
* SetVisibleRegion) will be filled with opaque content.
853
*/
854
CONTENT_OPAQUE = 0x01,
855
/**
856
* If this is set, the caller is notifying that the contents of this layer
857
* require per-component alpha for optimal fidelity. However, there is no
858
* guarantee that component alpha will be supported for this layer at
859
* paint time.
860
* This should never be set at the same time as CONTENT_OPAQUE.
861
*/
862
CONTENT_COMPONENT_ALPHA = 0x02,
863
864
/**
865
* If this is set then one of the descendant layers of this one has
866
* CONTENT_COMPONENT_ALPHA set.
867
*/
868
CONTENT_COMPONENT_ALPHA_DESCENDANT = 0x04,
869
870
/**
871
* If this is set then this layer is part of a preserve-3d group, and should
872
* be sorted with sibling layers that are also part of the same group.
873
*/
874
CONTENT_EXTEND_3D_CONTEXT = 0x08,
875
/**
876
* This indicates that the transform may be changed on during an empty
877
* transaction where there is no possibility of redrawing the content, so
878
* the implementation should be ready for that.
879
*/
880
CONTENT_MAY_CHANGE_TRANSFORM = 0x10,
881
882
/**
883
* Disable subpixel AA for this layer. This is used if the display isn't
884
* suited for subpixel AA like hidpi or rotated content.
885
*/
886
CONTENT_DISABLE_SUBPIXEL_AA = 0x20,
887
888
/**
889
* If this is set then the layer contains content that may look
890
* objectionable if not handled as an active layer (such as text with an
891
* animated transform). This is for internal layout/FrameLayerBuilder usage
892
* only until flattening code is obsoleted. See bug 633097
893
*/
894
CONTENT_DISABLE_FLATTENING = 0x40,
895
896
/**
897
* This layer is hidden if the backface of the layer is visible
898
* to user.
899
*/
900
CONTENT_BACKFACE_HIDDEN = 0x80
901
};
902
/**
903
* CONSTRUCTION PHASE ONLY
904
* This lets layout make some promises about what will be drawn into the
905
* visible region of the PaintedLayer. This enables internal quality
906
* and performance optimizations.
907
*/
908
void SetContentFlags(uint32_t aFlags) {
909
NS_ASSERTION((aFlags & (CONTENT_OPAQUE | CONTENT_COMPONENT_ALPHA)) !=
910
(CONTENT_OPAQUE | CONTENT_COMPONENT_ALPHA),
911
"Can't be opaque and require component alpha");
912
if (mSimpleAttrs.SetContentFlags(aFlags)) {
913
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
914
("Layer::Mutated(%p) ContentFlags", this));
915
MutatedSimple();
916
}
917
}
918
919
/**
920
* CONSTRUCTION PHASE ONLY
921
* Tell this layer which region will be visible. The visible region
922
* is a region which contains all the contents of the layer that can
923
* actually affect the rendering of the window. It can exclude areas
924
* that are covered by opaque contents of other layers, and it can
925
* exclude areas where this layer simply contains no content at all.
926
* (This can be an overapproximation to the "true" visible region.)
927
*
928
* There is no general guarantee that drawing outside the bounds of the
929
* visible region will be ignored. So if a layer draws outside the bounds
930
* of its visible region, it needs to ensure that what it draws is valid.
931
*/
932
virtual void SetVisibleRegion(const LayerIntRegion& aRegion) {
933
// IsEmpty is required otherwise we get invalidation glitches.
934
// See bug 1288464 for investigating why.
935
if (!mVisibleRegion.IsEqual(aRegion) || aRegion.IsEmpty()) {
936
MOZ_LAYERS_LOG_IF_SHADOWABLE(
937
this, ("Layer::Mutated(%p) VisibleRegion was %s is %s", this,
938
mVisibleRegion.ToString().get(), aRegion.ToString().get()));
939
mVisibleRegion = aRegion;
940
Mutated();
941
}
942
}
943
944
/**
945
* CONSTRUCTION PHASE ONLY
946
* Set the (sub)document metrics used to render the Layer subtree
947
* rooted at this. Note that a layer may have multiple FrameMetrics
948
* objects; calling this function will remove all of them and replace
949
* them with the provided FrameMetrics. See the documentation for
950
* SetFrameMetrics(const nsTArray<FrameMetrics>&) for more details.
951
*/
952
void SetScrollMetadata(const ScrollMetadata& aScrollMetadata) {
953
Manager()->ClearPendingScrollInfoUpdate();
954
if (mScrollMetadata.Length() != 1 ||
955
mScrollMetadata[0] != aScrollMetadata) {
956
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
957
("Layer::Mutated(%p) FrameMetrics", this));
958
mScrollMetadata.ReplaceElementsAt(0, mScrollMetadata.Length(),
959
aScrollMetadata);
960
ScrollMetadataChanged();
961
Mutated();
962
}
963
}
964
965
/**
966
* CONSTRUCTION PHASE ONLY
967
* Set the (sub)document metrics used to render the Layer subtree
968
* rooted at this. There might be multiple metrics on this layer
969
* because the layer may, for example, be contained inside multiple
970
* nested scrolling subdocuments. In general a Layer having multiple
971
* ScrollMetadata objects is conceptually equivalent to having a stack
972
* of ContainerLayers that have been flattened into this Layer.
973
* See the documentation in LayerMetricsWrapper.h for a more detailed
974
* explanation of this conceptual equivalence.
975
*
976
* Note also that there is actually a many-to-many relationship between
977
* Layers and ScrollMetadata, because multiple Layers may have identical
978
* ScrollMetadata objects. This happens when those layers belong to the
979
* same scrolling subdocument and therefore end up with the same async
980
* transform when they are scrolled by the APZ code.
981
*/
982
void SetScrollMetadata(const nsTArray<ScrollMetadata>& aMetadataArray) {
983
Manager()->ClearPendingScrollInfoUpdate();
984
if (mScrollMetadata != aMetadataArray) {
985
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
986
("Layer::Mutated(%p) FrameMetrics", this));
987
mScrollMetadata = aMetadataArray;
988
ScrollMetadataChanged();
989
Mutated();
990
}
991
}
992
993
/*
994
* Compositor event handling
995
* =========================
996
* When a touch-start event (or similar) is sent to the
997
* AsyncPanZoomController, it needs to decide whether the event should be sent
998
* to the main thread. Each layer has a list of event handling regions. When
999
* the compositor needs to determine how to handle a touch event, it scans the
1000
* layer tree from top to bottom in z-order (traversing children before their
1001
* parents). Points outside the clip region for a layer cause that layer (and
1002
* its subtree) to be ignored. If a layer has a mask layer, and that mask
1003
* layer's alpha value is zero at the event point, then the layer and its
1004
* subtree should be ignored. For each layer, if the point is outside its hit
1005
* region, we ignore the layer and move onto the next. If the point is inside
1006
* its hit region but outside the dispatch-to-content region, we can initiate
1007
* a gesture without consulting the content thread. Otherwise we must dispatch
1008
* the event to content. Note that if a layer or any ancestor layer has a
1009
* ForceEmptyHitRegion override in GetEventRegionsOverride() then the
1010
* hit-region must be treated as empty. Similarly, if there is a
1011
* ForceDispatchToContent override then the dispatch-to-content region must be
1012
* treated as encompassing the entire hit region, and therefore we must
1013
* consult the content thread before initiating a gesture. (If both flags are
1014
* set, ForceEmptyHitRegion takes priority.)
1015
*/
1016
/**
1017
* CONSTRUCTION PHASE ONLY
1018
* Set the event handling region.
1019
*/
1020
void SetEventRegions(const EventRegions& aRegions) {
1021
if (mEventRegions != aRegions) {
1022
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1023
this, ("Layer::Mutated(%p) eventregions were %s, now %s", this,
1024
mEventRegions.ToString().get(), aRegions.ToString().get()));
1025
mEventRegions = aRegions;
1026
Mutated();
1027
}
1028
}
1029
1030
/**
1031
* CONSTRUCTION PHASE ONLY
1032
* Set the opacity which will be applied to this layer as it
1033
* is composited to the destination.
1034
*/
1035
void SetOpacity(float aOpacity) {
1036
if (mSimpleAttrs.SetOpacity(aOpacity)) {
1037
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) Opacity", this));
1038
MutatedSimple();
1039
}
1040
}
1041
1042
void SetMixBlendMode(gfx::CompositionOp aMixBlendMode) {
1043
if (mSimpleAttrs.SetMixBlendMode(aMixBlendMode)) {
1044
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
1045
("Layer::Mutated(%p) MixBlendMode", this));
1046
MutatedSimple();
1047
}
1048
}
1049
1050
void SetForceIsolatedGroup(bool aForceIsolatedGroup) {
1051
if (mSimpleAttrs.SetForceIsolatedGroup(aForceIsolatedGroup)) {
1052
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1053
this, ("Layer::Mutated(%p) ForceIsolatedGroup", this));
1054
MutatedSimple();
1055
}
1056
}
1057
1058
bool GetForceIsolatedGroup() const {
1059
return mSimpleAttrs.GetForceIsolatedGroup();
1060
}
1061
1062
/**
1063
* CONSTRUCTION PHASE ONLY
1064
* Set a clip rect which will be applied to this layer as it is
1065
* composited to the destination. The coordinates are relative to
1066
* the parent layer (i.e. the contents of this layer
1067
* are transformed before this clip rect is applied).
1068
* For the root layer, the coordinates are relative to the widget,
1069
* in device pixels.
1070
* If aRect is null no clipping will be performed.
1071
*/
1072
void SetClipRect(const Maybe<ParentLayerIntRect>& aRect) {
1073
if (mClipRect) {
1074
if (!aRect) {
1075
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1076
this, ("Layer::Mutated(%p) ClipRect was %d,%d,%d,%d is <none>",
1077
this, mClipRect->X(), mClipRect->Y(), mClipRect->Width(),
1078
mClipRect->Height()));
1079
mClipRect.reset();
1080
Mutated();
1081
} else {
1082
if (!aRect->IsEqualEdges(*mClipRect)) {
1083
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1084
this,
1085
("Layer::Mutated(%p) ClipRect was %d,%d,%d,%d is %d,%d,%d,%d",
1086
this, mClipRect->X(), mClipRect->Y(), mClipRect->Width(),
1087
mClipRect->Height(), aRect->X(), aRect->Y(), aRect->Width(),
1088
aRect->Height()));
1089
mClipRect = aRect;
1090
Mutated();
1091
}
1092
}
1093
} else {
1094
if (aRect) {
1095
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1096
this,
1097
("Layer::Mutated(%p) ClipRect was <none> is %d,%d,%d,%d", this,
1098
aRect->X(), aRect->Y(), aRect->Width(), aRect->Height()));
1099
mClipRect = aRect;
1100
Mutated();
1101
}
1102
}
1103
}
1104
1105
/**
1106
* CONSTRUCTION PHASE ONLY
1107
* Set an optional scrolled clip on the layer.
1108
* The scrolled clip, if present, consists of a clip rect and an optional
1109
* mask. This scrolled clip is always scrolled by all scroll frames associated
1110
* with this layer. (By contrast, the scroll clips stored in ScrollMetadata
1111
* are only scrolled by scroll frames above that ScrollMetadata, and the
1112
* layer's mClipRect is always fixed to the layer contents (which may or may
1113
* not be scrolled by some of the scroll frames associated with the layer,
1114
* depending on whether the layer is fixed).)
1115
*/
1116
void SetScrolledClip(const Maybe<LayerClip>& aScrolledClip) {
1117
if (mSimpleAttrs.SetScrolledClip(aScrolledClip)) {
1118
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
1119
("Layer::Mutated(%p) ScrolledClip", this));
1120
MutatedSimple();
1121
}
1122
}
1123
1124
/**
1125
* CONSTRUCTION PHASE ONLY
1126
* Set a layer to mask this layer.
1127
*
1128
* The mask layer should be applied using its effective transform (after it
1129
* is calculated by ComputeEffectiveTransformForMaskLayer), this should use
1130
* this layer's parent's transform and the mask layer's transform, but not
1131
* this layer's. That is, the mask layer is specified relative to this layer's
1132
* position in it's parent layer's coord space.
1133
* Currently, only 2D translations are supported for the mask layer transform.
1134
*
1135
* Ownership of aMaskLayer passes to this.
1136
* Typical use would be an ImageLayer with an alpha image used for masking.
1137
* See also ContainerState::BuildMaskLayer in FrameLayerBuilder.cpp.
1138
*/
1139
void SetMaskLayer(Layer* aMaskLayer) {
1140
#ifdef DEBUG
1141
if (aMaskLayer) {
1142
bool maskIs2D = aMaskLayer->GetTransform().CanDraw2D();
1143
NS_ASSERTION(maskIs2D, "Mask layer has invalid transform.");
1144
}
1145
#endif
1146
1147
if (mMaskLayer != aMaskLayer) {
1148
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
1149
("Layer::Mutated(%p) MaskLayer", this));
1150
mMaskLayer = aMaskLayer;
1151
Mutated();
1152
}
1153
}
1154
1155
/**
1156
* CONSTRUCTION PHASE ONLY
1157
* Add mask layers associated with LayerClips.
1158
*/
1159
void SetAncestorMaskLayers(const nsTArray<RefPtr<Layer>>& aLayers) {
1160
if (aLayers != mAncestorMaskLayers) {
1161
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1162
this, ("Layer::Mutated(%p) AncestorMaskLayers", this));
1163
mAncestorMaskLayers = aLayers;
1164
Mutated();
1165
}
1166
}
1167
1168
/**
1169
* CONSTRUCTION PHASE ONLY
1170
* Add a mask layer associated with a LayerClip.
1171
*/
1172
void AddAncestorMaskLayer(const RefPtr<Layer>& aLayer) {
1173
mAncestorMaskLayers.AppendElement(aLayer);
1174
Mutated();
1175
}
1176
1177
/**
1178
* CONSTRUCTION PHASE ONLY
1179
* Tell this layer what its transform should be. The transformation
1180
* is applied when compositing the layer into its parent container.
1181
*/
1182
void SetBaseTransform(const gfx::Matrix4x4& aMatrix) {
1183
NS_ASSERTION(!aMatrix.IsSingular(),
1184
"Shouldn't be trying to draw with a singular matrix!");
1185
mPendingTransform = nullptr;
1186
if (!mSimpleAttrs.SetTransform(aMatrix)) {
1187
return;
1188
}
1189
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
1190
("Layer::Mutated(%p) BaseTransform", this));
1191
MutatedSimple();
1192
}
1193
1194
/**
1195
* Can be called at any time.
1196
*
1197
* Like SetBaseTransform(), but can be called before the next
1198
* transform (i.e. outside an open transaction). Semantically, this
1199
* method enqueues a new transform value to be set immediately after
1200
* the next transaction is opened.
1201
*/
1202
void SetBaseTransformForNextTransaction(const gfx::Matrix4x4& aMatrix) {
1203
mPendingTransform = mozilla::MakeUnique<gfx::Matrix4x4>(aMatrix);
1204
}
1205
1206
void SetPostScale(float aXScale, float aYScale) {
1207
if (!mSimpleAttrs.SetPostScale(aXScale, aYScale)) {
1208
return;
1209
}
1210
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) PostScale", this));
1211
MutatedSimple();
1212
}
1213
1214
/**
1215
* CONSTRUCTION PHASE ONLY
1216
* A layer is "fixed position" when it draws content from a content
1217
* (not chrome) document, the topmost content document has a root scrollframe
1218
* with a displayport, but the layer does not move when that displayport
1219
* scrolls.
1220
*/
1221
void SetIsFixedPosition(bool aFixedPosition) {
1222
if (mSimpleAttrs.SetIsFixedPosition(aFixedPosition)) {
1223
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1224
this, ("Layer::Mutated(%p) IsFixedPosition", this));
1225
MutatedSimple();
1226
}
1227
}
1228
1229
void SetIsAsyncZoomContainer(const Maybe<FrameMetrics::ViewID>& aViewId) {
1230
if (mSimpleAttrs.SetIsAsyncZoomContainer(aViewId)) {
1231
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1232
this, ("Layer::Mutated(%p) IsAsyncZoomContainer", this));
1233
MutatedSimple();
1234
}
1235
}
1236
1237
/**
1238
* CONSTRUCTION PHASE ONLY
1239
* This flag is true when the transform on the layer is a perspective
1240
* transform. The compositor treats perspective transforms specially
1241
* for async scrolling purposes.
1242
*/
1243
void SetTransformIsPerspective(bool aTransformIsPerspective) {
1244
if (mSimpleAttrs.SetTransformIsPerspective(aTransformIsPerspective)) {
1245
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1246
this, ("Layer::Mutated(%p) TransformIsPerspective", this));
1247
MutatedSimple();
1248
}
1249
}
1250
// This is only called when the layer tree is updated. Do not call this from
1251
// layout code. To add an animation to this layer, use AddAnimation.
1252
void SetCompositorAnimations(
1253
const CompositorAnimations& aCompositorAnimations);
1254
// Go through all animations in this layer and its children and, for
1255
// any animations with a null start time, update their start time such
1256
// that at |aReadyTime| the animation's current time corresponds to its
1257
// 'initial current time' value.
1258
void StartPendingAnimations(const TimeStamp& aReadyTime);
1259
1260
void ClearCompositorAnimations();
1261
1262
/**
1263
* CONSTRUCTION PHASE ONLY
1264
* If a layer represents a fixed position element, this data is stored on the
1265
* layer for use by the compositor.
1266
*
1267
* - |aScrollId| identifies the scroll frame that this element is fixed
1268
* with respect to.
1269
*
1270
* - |aAnchor| is the point on the layer that is considered the "anchor"
1271
* point, that is, the point which remains in the same position when
1272
* compositing the layer tree with a transformation (such as when
1273
* asynchronously scrolling and zooming).
1274
*
1275
* - |aSides| is the set of sides to which the element is fixed relative to.
1276
* This is used if the viewport size is changed in the compositor and
1277
* fixed position items need to shift accordingly. This value is made up
1278
* combining appropriate values from mozilla::SideBits.
1279
*/
1280
void SetFixedPositionData(ScrollableLayerGuid::ViewID aScrollId,
1281
const LayerPoint& aAnchor, SideBits aSides) {
1282
if (mSimpleAttrs.SetFixedPositionData(aScrollId, aAnchor, aSides)) {
1283
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1284
this, ("Layer::Mutated(%p) FixedPositionData", this));
1285
MutatedSimple();
1286
}
1287
}
1288
1289
/**
1290
* CONSTRUCTION PHASE ONLY
1291
* If a layer is "sticky position", |aScrollId| holds the scroll identifier
1292
* of the scrollable content that contains it. The difference between the two
1293
* rectangles |aOuter| and |aInner| is treated as two intervals in each
1294
* dimension, with the current scroll position at the origin. For each
1295
* dimension, while that component of the scroll position lies within either
1296
* interval, the layer should not move relative to its scrolling container.
1297
*/
1298
void SetStickyPositionData(ScrollableLayerGuid::ViewID aScrollId,
1299
LayerRectAbsolute aOuter,
1300
LayerRectAbsolute aInner) {
1301
if (mSimpleAttrs.SetStickyPositionData(aScrollId, aOuter, aInner)) {
1302
MOZ_LAYERS_LOG_IF_SHADOWABLE(
1303
this, ("Layer::Mutated(%p) StickyPositionData", this));
1304
MutatedSimple();
1305
}
1306
}
1307
1308
/**
1309
* CONSTRUCTION PHASE ONLY
1310
* If a layer is a scroll thumb container layer or a scrollbar container
1311
* layer, set the scroll identifier of the scroll frame scrolled by
1312
* the scrollbar, and other data related to the scrollbar.
1313
*/
1314
void SetScrollbarData(const ScrollbarData& aThumbData) {
1315
if (mSimpleAttrs.SetScrollbarData(aThumbData)) {
1316
MOZ_LAYERS_LOG_IF_SHADOWABLE(this,
1317
("Layer::Mutated(%p) ScrollbarData", this));
1318
MutatedSimple();
1319
}
1320
}
1321
1322
// Used when forwarding transactions. Do not use at any other time.
1323
void SetSimpleAttributes(const SimpleLayerAttributes& aAttrs) {
1324
mSimpleAttrs = aAttrs;
1325
}
1326
const SimpleLayerAttributes& GetSimpleAttributes() const {
1327
return mSimpleAttrs;
1328
}
1329
1330
// These getters can be used anytime.
1331
float GetOpacity() { return mSimpleAttrs.GetOpacity(); }
1332
gfx::CompositionOp GetMixBlendMode() const {
1333
return mSimpleAttrs.GetMixBlendMode();
1334
}
1335
const Maybe<ParentLayerIntRect>& GetClipRect() const { return mClipRect; }
1336
const Maybe<LayerClip>& GetScrolledClip() const {
1337
return mSimpleAttrs.GetScrolledClip();
1338
}
1339
Maybe<ParentLayerIntRect> GetScrolledClipRect() const;
1340
uint32_t GetContentFlags() { return mSimpleAttrs.GetContentFlags(); }
1341
const LayerIntRegion& GetVisibleRegion() const { return mVisibleRegion; }
1342
const ScrollMetadata& GetScrollMetadata(uint32_t aIndex) const;
1343
const FrameMetrics& GetFrameMetrics(uint32_t aIndex) const;
1344
uint32_t GetScrollMetadataCount() const { return mScrollMetadata.Length(); }
1345
const nsTArray<ScrollMetadata>& GetAllScrollMetadata() {
1346
return mScrollMetadata;
1347
}
1348
bool HasScrollableFrameMetrics() const;
1349
bool IsScrollableWithoutContent() const;
1350
const EventRegions& GetEventRegions() const { return mEventRegions; }
1351
ContainerLayer* GetParent() { return mParent; }
1352
Layer* GetNextSibling() {
1353
if (mNextSibling) {
1354
mNextSibling->CheckCanary();
1355
}
1356
return mNextSibling;
1357
}
1358
const Layer* GetNextSibling() const {
1359
if (mNextSibling) {
1360
mNextSibling->CheckCanary();
1361
}
1362
return mNextSibling;
1363
}
1364
Layer* GetPrevSibling() { return mPrevSibling; }
1365
const Layer* GetPrevSibling() const { return mPrevSibling; }
1366
virtual Layer* GetFirstChild() const { return nullptr; }
1367
virtual Layer* GetLastChild() const { return nullptr; }
1368
gfx::Matrix4x4 GetTransform() const;
1369
// Same as GetTransform(), but returns the transform as a strongly-typed
1370
// matrix. Eventually this will replace GetTransform().
1371
const CSSTransformMatrix GetTransformTyped() const;
1372
const gfx::Matrix4x4& GetBaseTransform() const {
1373
return mSimpleAttrs.GetTransform();
1374
}
1375
// Note: these are virtual because ContainerLayerComposite overrides them.
1376
virtual float GetPostXScale() const { return mSimpleAttrs.GetPostXScale(); }
1377
virtual float GetPostYScale() const { return mSimpleAttrs.GetPostYScale(); }
1378
bool GetIsFixedPosition() { return mSimpleAttrs.IsFixedPosition(); }
1379
Maybe<FrameMetrics::ViewID> IsAsyncZoomContainer() {
1380
return mSimpleAttrs.IsAsyncZoomContainer();
1381
}
1382
bool GetTransformIsPerspective() const {
1383
return mSimpleAttrs.GetTransformIsPerspective();
1384
}
1385
bool GetIsStickyPosition() { return mSimpleAttrs.IsStickyPosition(); }
1386
ScrollableLayerGuid::ViewID GetFixedPositionScrollContainerId() {
1387
return mSimpleAttrs.GetFixedPositionScrollContainerId();
1388
}
1389
LayerPoint GetFixedPositionAnchor() {
1390
return mSimpleAttrs.GetFixedPositionAnchor();
1391
}
1392
SideBits GetFixedPositionSides() {
1393
return mSimpleAttrs.GetFixedPositionSides();
1394
}
1395
ScrollableLayerGuid::ViewID GetStickyScrollContainerId() {
1396
return mSimpleAttrs.GetStickyScrollContainerId();
1397
}
1398
const LayerRectAbsolute& GetStickyScrollRangeOuter() {
1399
return mSimpleAttrs.GetStickyScrollRangeOuter();
1400
}
1401
const LayerRectAbsolute& GetStickyScrollRangeInner() {
1402
return mSimpleAttrs.GetStickyScrollRangeInner();
1403
}
1404
const ScrollbarData& GetScrollbarData() const {
1405
return mSimpleAttrs.GetScrollbarData();
1406
}
1407
bool IsScrollbarContainer() const;
1408
Layer* GetMaskLayer() const { return mMaskLayer; }
1409
bool HasPendingTransform() const { return !!mPendingTransform; }
1410
1411
void CheckCanary() const { mCanary.Check(); }
1412
1413
// Ancestor mask layers are associated with FrameMetrics, but for simplicity
1414
// in maintaining the layer tree structure we attach them to the layer.
1415
size_t GetAncestorMaskLayerCount() const {
1416
return mAncestorMaskLayers.Length();
1417
}
1418
Layer* GetAncestorMaskLayerAt(size_t aIndex) const {
1419
return mAncestorMaskLayers.ElementAt(aIndex);
1420
}
1421
const nsTArray<RefPtr<Layer>>& GetAllAncestorMaskLayers() const {
1422
return mAncestorMaskLayers;
1423
}
1424
1425
bool HasMaskLayers() const {
1426
return GetMaskLayer() || mAncestorMaskLayers.Length() > 0;
1427
}
1428
1429
/*
1430
* Get the combined clip rect of the Layer clip and all clips on FrameMetrics.
1431
* This is intended for use in Layout. The compositor needs to apply async
1432
* transforms to find the combined clip.
1433
*/
1434
Maybe<ParentLayerIntRect> GetCombinedClipRect() const;
1435
1436
/**
1437
* Retrieve the root level visible region for |this| taking into account
1438
* clipping applied to parent layers of |this| as well as subtracting
1439
* visible regions of higher siblings of this layer and each ancestor.
1440
*
1441
* Note translation values for offsets of visible regions and accumulated
1442
* aLayerOffset are integer rounded using IntPoint::Round.
1443
*
1444
* @param aResult - the resulting visible region of this layer.
1445
* @param aLayerOffset - this layer's total offset from the root layer.
1446
* @return - false if during layer tree traversal a parent or sibling
1447
* transform is found to be non-translational. This method returns early
1448
* in this case, results will not be valid. Returns true on successful
1449
* traversal.
1450
*/
1451
bool GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
1452
nsIntPoint* aLayerOffset);
1453
1454
// Note that all lengths in animation data are either in CSS pixels or app
1455
// units and must be converted to device pixels by the compositor.
1456
// Besides, this should only be called on the compositor thread.
1457
AnimationArray& GetAnimations() { return mAnimationInfo.GetAnimations(); }
1458
uint64_t GetCompositorAnimationsId() {
1459
return mAnimationInfo.GetCompositorAnimationsId();
1460
}
1461
nsTArray<PropertyAnimationGroup>& GetPropertyAnimationGroups() {
1462
return mAnimationInfo.GetPropertyAnimationGroups();
1463
}
1464
const Maybe<TransformData>& GetTransformData() const {
1465
return mAnimationInfo.GetTransformData();
1466
}
1467
1468
Maybe<uint64_t> GetAnimationGeneration() const {
1469
return mAnimationInfo.GetAnimationGeneration();
1470
}
1471
1472
gfx::Path* CachedMotionPath() { return mAnimationInfo.CachedMotionPath(); }
1473
1474
bool HasTransformAnimation() const;
1475
1476
/**
1477
* Returns the local transform for this layer: either mTransform or,
1478
* for shadow layers, GetShadowBaseTransform(), in either case with the
1479
* pre- and post-scales applied.
1480
*/
1481
gfx::Matrix4x4 GetLocalTransform();
1482
1483
/**
1484
* Same as GetLocalTransform(), but returns a strongly-typed matrix.
1485
* Eventually, this will replace GetLocalTransform().
1486
*/
1487
const LayerToParentLayerMatrix4x4 GetLocalTransformTyped();
1488
1489
/**
1490
* Returns the local opacity for this layer: either mOpacity or,
1491
* for shadow layers, GetShadowOpacity()
1492
*/
1493
float GetLocalOpacity();
1494
1495
/**
1496
* DRAWING PHASE ONLY
1497
*
1498
* Apply pending changes to layers before drawing them, if those
1499
* pending changes haven't been overridden by later changes.
1500
*
1501
* Returns a list of scroll ids which had pending updates.
1502
*/
1503
std::unordered_set<ScrollableLayerGuid::ViewID>
1504
ApplyPendingUpdatesToSubtree();
1505
1506
/**
1507
* DRAWING PHASE ONLY
1508
*
1509
* Write layer-subtype-specific attributes into aAttrs. Used to
1510
* synchronize layer attributes to their shadows'.
1511
*/
1512
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) {}
1513
1514
// Returns true if it's OK to save the contents of aLayer in an
1515
// opaque surface (a surface without an alpha channel).
1516
// If we can use a surface without an alpha channel, we should, because
1517
// it will often make painting of antialiased text faster and higher
1518
// quality.
1519
bool CanUseOpaqueSurface();
1520
1521
SurfaceMode GetSurfaceMode() {
1522
if (CanUseOpaqueSurface()) return SurfaceMode::SURFACE_OPAQUE;
1523
if (GetContentFlags() & CONTENT_COMPONENT_ALPHA)
1524
return SurfaceMode::SURFACE_COMPONENT_ALPHA;
1525
return SurfaceMode::SURFACE_SINGLE_CHANNEL_ALPHA;
1526
}
1527
1528
// Returns true if this layer can be treated as opaque for visibility
1529
// computation. A layer may be non-opaque for visibility even if it
1530
// is not transparent, for example, if it has a mix-blend-mode.
1531
bool IsOpaqueForVisibility();
1532
1533
/**
1534
* This setter can be used anytime. The user data for all keys is
1535
* initially null. Ownership pases to the layer manager.
1536
*/
1537
void SetUserData(
1538
void* aKey, LayerUserData* aData,
1539
void (*aDestroy)(void*) = LayerManager::LayerUserDataDestroy) {
1540
mUserData.Add(static_cast<gfx::UserDataKey*>(aKey), aData, aDestroy);
1541
}
1542
/**
1543
* This can be used anytime. Ownership passes to the caller!
1544
*/
1545
UniquePtr<LayerUserData> RemoveUserData(void* aKey);
1546
/**
1547
* This getter can be used anytime.
1548
*/
1549
bool HasUserData(void* aKey) {
1550
return mUserData.Has(static_cast<gfx::UserDataKey*>(aKey));
1551
}
1552
/**
1553
* This getter can be used anytime. Ownership is retained by the layer
1554
* manager.
1555
*/
1556
LayerUserData* GetUserData(void* aKey) const {
1557
return static_cast<LayerUserData*>(
1558
mUserData.Get(static_cast<gfx::UserDataKey*>(aKey)));
1559
}
1560
1561
/**
1562
* |Disconnect()| is used by layers hooked up over IPC. It may be
1563
* called at any time, and may not be called at all. Using an
1564
* IPC-enabled layer after Destroy() (drawing etc.) results in a
1565
* safe no-op; no crashy or uaf etc.
1566
*
1567
* XXX: this interface is essentially LayerManager::Destroy, but at
1568
* Layer granularity. It might be beneficial to unify them.
1569
*/
1570
virtual void Disconnect() {}
1571
1572
/**
1573
* Dynamic downcast to a PaintedLayer. Returns null if this is not
1574
* a PaintedLayer.
1575
*/
1576
virtual PaintedLayer* AsPaintedLayer() { return nullptr; }
1577
1578
/**
1579
* Dynamic cast to a ContainerLayer. Returns null if this is not
1580
* a ContainerLayer.
1581
*/
1582
virtual ContainerLayer* AsContainerLayer() { return nullptr; }
1583
virtual const ContainerLayer* AsContainerLayer() const { return nullptr; }
1584
1585
/**
1586
* Dynamic cast to a RefLayer. Returns null if this is not a
1587
* RefLayer.
1588
*/
1589
virtual RefLayer* AsRefLayer() { return nullptr; }
1590
1591
/**
1592
* Dynamic cast to a Color. Returns null if this is not a
1593
* ColorLayer.
1594
*/
1595
virtual ColorLayer* AsColorLayer() { return nullptr; }
1596
1597
/**
1598
* Dynamic cast to a Canvas. Returns null if this is not a
1599
* ColorLayer.
1600
*/
1601
virtual CanvasLayer* AsCanvasLayer() { return nullptr; }
1602
1603
/**
1604
* Dynamic cast to an Image. Returns null if this is not a
1605
* ColorLayer.
1606
*/
1607
virtual ImageLayer* AsImageLayer() { return nullptr; }
1608
1609
/**
1610
* Dynamic cast to a LayerComposite. Return null if this is not a
1611
* LayerComposite. Can be used anytime.
1612
*/
1613
virtual HostLayer* AsHostLayer() { return nullptr; }
1614
1615
/**
1616
* Dynamic cast to a ShadowableLayer. Return null if this is not a
1617
* ShadowableLayer. Can be used anytime.
1618
*/
1619
virtual ShadowableLayer* AsShadowableLayer() { return nullptr; }
1620
1621
// These getters can be used anytime. They return the effective
1622
// values that should be used when drawing this layer to screen,
1623
// accounting for this layer possibly being a shadow.
1624
const Maybe<ParentLayerIntRect>& GetLocalClipRect();
1625
const LayerIntRegion& GetLocalVisibleRegion();
1626
1627
bool Extend3DContext() {
1628
return GetContentFlags() & CONTENT_EXTEND_3D_CONTEXT;
1629
}
1630
bool Combines3DTransformWithAncestors() {
1631
return GetParent() &&
1632
reinterpret_cast<Layer*>(GetParent())->Extend3DContext();
1633
}
1634
bool Is3DContextLeaf() {
1635
return !Extend3DContext() && Combines3DTransformWithAncestors();
1636
}
1637
/**
1638
* It is true if the user can see the back of the layer and the
1639
* backface is hidden. The compositor should skip the layer if the
1640
* result is true.
1641
*/
1642
bool IsBackfaceHidden();
1643
bool IsVisible() {
1644
// For containers extending 3D context, visible region
1645
// is meaningless, since they are just intermediate result of
1646
// content.
1647
return !GetLocalVisibleRegion().IsEmpty() || Extend3DContext();
1648
}
1649
1650
/**
1651
* Return true if current layer content is opaque.
1652
* It does not guarantee that layer content is always opaque.
1653
*/
1654
virtual bool IsOpaque() { return GetContentFlags() & CONTENT_OPAQUE; }
1655
1656
/**
1657
* Returns the product of the opacities of this layer and all ancestors up
1658
* to and excluding the nearest ancestor that has UseIntermediateSurface()
1659
* set.
1660
*/
1661
float GetEffectiveOpacity();
1662
1663
/**
1664
* Returns the blendmode of this layer.
1665
*/
1666
gfx::CompositionOp GetEffectiveMixBlendMode();
1667
1668
/**
1669
* This returns the effective transform computed by
1670
* ComputeEffectiveTransforms. Typically this is a transform that transforms
1671
* this layer all the way to some intermediate surface or destination
1672
* surface. For non-BasicLayers this will be a transform to the nearest
1673
* ancestor with UseIntermediateSurface() (or to the root, if there is no
1674
* such ancestor), but for BasicLayers it's different.
1675
*/
1676
const gfx::Matrix4x4& GetEffectiveTransform() const {
1677
return mEffectiveTransform;
1678
}
1679
1680
/**
1681
* This returns the effective transform for Layer's buffer computed by
1682
* ComputeEffectiveTransforms. Typically this is a transform that transforms
1683
* this layer's buffer all the way to some intermediate surface or destination
1684
* surface. For non-BasicLayers this will be a transform to the nearest
1685
* ancestor with UseIntermediateSurface() (or to the root, if there is no
1686
* such ancestor), but for BasicLayers it's different.
1687
*
1688
* By default, its value is same to GetEffectiveTransform().
1689
* When ImageLayer is rendered with ScaleMode::STRETCH,
1690
* it becomes different from GetEffectiveTransform().
1691
*/
1692
virtual const gfx::Matrix4x4& GetEffectiveTransformForBuffer() const {
1693
return mEffectiveTransform;
1694
}
1695
1696
/**
1697
* If the current layers participates in a preserve-3d
1698
* context (returns true for Combines3DTransformWithAncestors),
1699
* returns the combined transform up to the preserve-3d (nearest
1700
* ancestor that doesn't Extend3DContext()). Otherwise returns
1701
* the local transform.
1702
*/
1703
gfx::Matrix4x4 ComputeTransformToPreserve3DRoot();
1704
1705
/**
1706
* @param aTransformToSurface the composition of the transforms
1707
* from the parent layer (if any) to the destination pixel grid.
1708
*
1709
* Computes mEffectiveTransform for this layer and all its descendants.
1710
* mEffectiveTransform transforms this layer up to the destination
1711
* pixel grid (whatever aTransformToSurface is relative to).
1712
*
1713
* We promise that when this is called on a layer, all ancestor layers
1714
* have already had ComputeEffectiveTransforms called.
1715
*/
1716
virtual void ComputeEffectiveTransforms(
1717
const gfx::Matrix4x4& aTransformToSurface) = 0;
1718
1719
/**
1720
* Computes the effective transform for mask layers, if this layer has any.
1721
*/
1722
void ComputeEffectiveTransformForMaskLayers(
1723
const gfx::Matrix4x4& aTransformToSurface);
1724
static void ComputeEffectiveTransformForMaskLayer(
1725
Layer* aMaskLayer, const gfx::Matrix4x4& aTransformToSurface);
1726
1727
/**
1728
* Calculate the scissor rect required when rendering this layer.
1729
* Returns a rectangle relative to the intermediate surface belonging to the
1730
* nearest ancestor that has an intermediate surface, or relative to the root
1731
* viewport if no ancestor has an intermediate surface, corresponding to the
1732
* clip rect for this layer intersected with aCurrentScissorRect.
1733
*/
1734
RenderTargetIntRect CalculateScissorRect(
1735
const RenderTargetIntRect& aCurrentScissorRect);
1736
1737
virtual const char* Name() const = 0;
1738
virtual LayerType GetType() const = 0;
1739
1740
/**
1741
* Only the implementation should call this. This is per-implementation
1742
* private data. Normally, all layers with a given layer manager
1743
* use the same type of ImplData.
1744
*/
1745
void* ImplData() { return mImplData; }
1746
1747
/**
1748
* Only the implementation should use these methods.
1749
*/
1750
void SetParent(ContainerLayer* aParent) { mParent = aParent; }
1751
void SetNextSibling(Layer* aSibling) { mNextSibling = aSibling; }
1752
void SetPrevSibling(Layer* aSibling) { mPrevSibling = aSibling; }
1753
1754
/**
1755
* Dump information about this layer manager and its managed tree to
1756
* aStream.
1757
*/
1758
void Dump(std::stringstream& aStream, const char* aPrefix = "",
1759
bool aDumpHtml = false, bool aSorted = false,
1760
const Maybe<gfx::Polygon>& aGeometry = Nothing());
1761
/**
1762
* Dump information about just this layer manager itself to aStream.
1763
*/
1764
void DumpSelf(std::stringstream& aStream, const char* aPrefix = "",
1765
const Maybe<gfx::Polygon>& aGeometry = Nothing());
1766
1767
/**
1768
* Dump information about this layer and its child & sibling layers to
1769
* layerscope packet.
1770
*/
1771
void Dump(layerscope::LayersPacket* aPacket, const void* aParent);
1772
1773
/**
1774
* Log information about this layer manager and its managed tree to
1775
* the NSPR log (if enabled for "Layers").
1776
*/
1777
void Log(const char* aPrefix = "");
1778
/**
1779
* Log information about just this layer manager itself to the NSPR
1780
* log (if enabled for "Layers").
1781
*/
1782
void LogSelf(const char* aPrefix = "");
1783
1784
// Print interesting information about this into aStream. Internally
1785
// used to implement Dump*() and Log*(). If subclasses have
1786
// additional interesting properties, they should override this with
1787
// an implementation that first calls the base implementation then
1788
// appends additional info to aTo.
1789
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);
1790
1791
// Just like PrintInfo, but this function dump information into layerscope
1792
// packet, instead of a StringStream. It is also internally used to implement
1793
// Dump();
1794
virtual void DumpPacket(layerscope::LayersPacket* aPacket,
1795
const void* aParent);
1796
1797
/**
1798
* Store display list log.
1799
*/
1800
void SetDisplayListLog(const char* log);
1801
1802
/**
1803
* Return display list log.
1804
*/
1805
void GetDisplayListLog(nsCString& log);
1806
1807
static bool IsLogEnabled() { return LayerManager::IsLogEnabled(); }
1808
1809
/**
1810
* Returns the current area of the layer (in layer-space coordinates)
1811
* marked as needed to be recomposited.
1812
*/
1813
const virtual gfx::TiledIntRegion& GetInvalidRegion() {
1814
return mInvalidRegion;
1815
}
1816
void AddInvalidRegion(const nsIntRegion& aRegion) {
1817
mInvalidRegion.Add(aRegion);
1818
}
1819
1820
/**
1821
* Mark the entirety of the layer's visible region as being invalid.
1822
*/
1823
void SetInvalidRectToVisibleRegion() {
1824
mInvalidRegion.SetEmpty();
1825
mInvalidRegion.Add(GetVisibleRegion().ToUnknownRegion());
1826
}
1827
1828
/**
1829
* Adds to the current invalid rect.
1830
*/
1831
void AddInvalidRect(const gfx::IntRect& aRect) { mInvalidRegion.Add(aRect); }
1832
1833
/**
1834
* Clear the invalid rect, marking the layer as being identical to what is
1835
* currently composited.
1836
*/
1837
virtual void ClearInvalidRegion() { mInvalidRegion.SetEmpty(); }
1838
1839
// These functions allow attaching an AsyncPanZoomController to this layer,
1840
// and can be used anytime.
1841
// A layer has an APZC at index aIndex only-if
1842
// GetFrameMetrics(aIndex).IsScrollable(); attempting to get an APZC for a
1843
// non-scrollable metrics will return null. The reverse is also generally true
1844
// (that if GetFrameMetrics(aIndex).IsScrollable() is true, then the layer
1845
// will have an APZC). However, it only holds on the the compositor-side layer
1846
// tree, and only after the APZ code has had a chance to rebuild its internal
1847
// hit-testing tree using the layer tree. Also, it may not hold in certain
1848
// "exceptional" scenarios such as if the layer tree doesn't have a
1849
// GeckoContentController registered for it, or if there is a malicious
1850
// content process trying to trip up the compositor over IPC. The aIndex for
1851
// these functions must be less than GetScrollMetadataCount().
1852
void SetAsyncPanZoomController(uint32_t aIndex,
1853
AsyncPanZoomController* controller);
1854
AsyncPanZoomController* GetAsyncPanZoomController(uint32_t aIndex) const;
1855
// The ScrollMetadataChanged function is used internally to ensure the APZC
1856
// array length matches the frame metrics array length.
1857
1858
virtual void ClearCachedResources() {}
1859
1860
virtual bool SupportsAsyncUpdate() { return false; }
1861
1862
private:
1863
void ScrollMetadataChanged();
1864
1865
public:
1866
void ApplyPendingUpdatesForThisTransaction();
1867
1868
#ifdef DEBUG
1869
void SetDebugColorIndex(uint32_t aIndex) { mDebugColorIndex = aIndex; }
1870
uint32_t GetDebugColorIndex() { return mDebugColorIndex; }
1871
#endif
1872
1873
void Mutated() { mManager->Mutated(this); }
1874
void MutatedSimple() { mManager->MutatedSimple(this); }
1875
1876
virtual int32_t GetMaxLayerSize() { return Manager()->GetMaxTextureSize(); }
1877
1878
/**
1879
* Returns true if this layer's effective transform is not just
1880
* a translation by integers, or if this layer or some ancestor layer
1881
* is marked as having a transform that may change without a full layer
1882
* transaction.
1883
*
1884
* Note: This function ignores ancestor layers across layer tree boundaries
1885
* so that it returns a consistent value when compositing and when painting.
1886
*/
1887
bool MayResample();
1888
1889
RenderTargetRect TransformRectToRenderTarget(const LayerIntRect& aRect);
1890
1891
/**
1892
* Add debugging information to the layer dump.
1893
*/
1894
void AddExtraDumpInfo(const nsACString& aStr) {
1895
#ifdef MOZ_DUMP_PAINTING
1896
mExtraDumpInfo.AppendElement(aStr);
1897
#endif
1898
}
1899
1900
/**
1901
* Clear debugging information. Useful for recycling.
1902
*/
1903
void ClearExtraDumpInfo() {
1904
#ifdef MOZ_DUMP_PAINTING
1905
mExtraDumpInfo.Clear();
1906
#endif
1907
}
1908
1909
AnimationInfo& GetAnimationInfo() { return mAnimationInfo; }
1910
1911
protected:
1912
Layer(LayerManager* aManager, void* aImplData);
1913
1914
// Protected destructor, to discourage deletion outside of Release():
1915
virtual ~Layer();
1916
1917
/**
1918
* We can snap layer transforms for two reasons:
1919
* 1) To avoid unnecessary resampling when a transform is a translation
1920
* by a non-integer number of pixels.
1921
* Snapping the translation to an integer number of pixels avoids
1922
* blurring the layer and can be faster to composite.
1923
* 2) When a layer is used to render a rectangular object, we need to
1924
* emulate the rendering of rectangular inactive content and snap the
1925
* edges of the rectangle to pixel boundaries. This is both to ensure
1926
* layer rendering is consistent with inactive content rendering, and to
1927
* avoid seams.
1928
* This function implements type 1 snapping. If aTransform is a 2D
1929
* translation, and this layer's layer manager has enabled snapping
1930
* (which is the default), return aTransform with the translation snapped
1931
* to nearest pixels. Otherwise just return aTransform. Call this when the
1932
* layer does not correspond to a single rectangular content object.
1933
* This function does not try to snap if aTransform has a scale, because in
1934
* that case resampling is inevitable and there's no point in trying to
1935
* avoid it. In fact snapping can cause problems because pixel edges in the
1936
* layer's content can be rendered unpredictably (jiggling) as the scale
1937
* interacts with the snapping of the translation, especially with animated
1938
* transforms.
1939
* @param aResidualTransform a transform to apply before the result transform
1940
* in order to get the results to completely match aTransform.
1941
*/
1942
gfx::Matrix4x4 SnapTransformTranslation(const gfx::Matrix4x4& aTransform,
1943
gfx::Matrix* aResidualTransform);
1944
gfx::Matrix4x4 SnapTransformTranslation3D(const gfx::Matrix4x4& aTransform,
1945
gfx::Matrix* aResidualTransform);
1946
/**
1947
* See comment for SnapTransformTranslation.
1948
* This function implements type 2 snapping. If aTransform is a translation
1949
* and/or scale, transform aSnapRect by aTransform, snap to pixel boundaries,
1950
* and return the transform that maps aSnapRect to that rect. Otherwise
1951
* just return aTransform.
1952
* @param aSnapRect a rectangle whose edges should be snapped to pixel
1953
* boundaries in the destination surface.
1954
* @param aResidualTransform a transform to apply before the result transform
1955
* in order to get the results to completely match aTransform.
1956
*/
1957
gfx::Matrix4x4 SnapTransform(const gfx::Matrix4x4& aTransform,
1958
const gfxRect& aSnapRect,
1959
gfx::Matrix* aResidualTransform);
1960
1961
LayerManager* mManager;
1962
ContainerLayer* mParent;
1963
Layer* mNextSibling;
1964
Layer* mPrevSibling;
1965
void* mImplData;
1966
RefPtr<Layer> mMaskLayer;
1967
nsTArray<RefPtr<Layer>> mAncestorMaskLayers;
1968
// Look for out-of-bound in the middle of the structure
1969
mozilla::CorruptionCanary mCanary;
1970
gfx::UserData mUserData;
1971