tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 0cba8e85148c30db16cabf7d573466b94ceb6a40
parent 6894c9a01b6f174c9b746299177e3129208da478
Author: Markus Stange <mstange.moz@gmail.com>
Date:   Thu,  2 Oct 2025 20:49:12 +0000

Bug 1987007 - Move NativeLayerCA::Representation out of NativeLayerCA and call it NativeLayerCARepresentation. r=bradwerth

Differential Revision: https://phabricator.services.mozilla.com/D267147

Diffstat:
Mgfx/layers/NativeLayerCA.h | 145+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Mgfx/layers/NativeLayerCA.mm | 16++++++++--------
2 files changed, 84 insertions(+), 77 deletions(-)

diff --git a/gfx/layers/NativeLayerCA.h b/gfx/layers/NativeLayerCA.h @@ -276,6 +276,80 @@ class NativeLayerRootSnapshotterCA final : public NativeLayerRootSnapshotter { }; #endif +// Wraps one CALayer representation of NativeLayerCA. +struct NativeLayerCARepresentation { + using UpdateType = NativeLayerCAUpdateType; + + NativeLayerCARepresentation(); + ~NativeLayerCARepresentation(); + + // Returns null if the layer is currently completely clipped out. + CALayer* UnderlyingCALayer() { + return mWrappingCALayerHasExtent ? mWrappingCALayer : nullptr; + } + + bool EnqueueSurface(IOSurfaceRef aSurfaceRef); + + // Applies buffered changes to the native CALayers. The contract with the + // caller is as follows: If any of these values have changed since the last + // call to ApplyChanges, mMutated[Field] needs to have been set to true + // before the call. If aUpdate is not All, then a partial update will be + // applied. In such a case, ApplyChanges may not make any changes that + // require a CATransacation, because no transaction will be created. In a + // a partial update, the return value will indicate if all the needed + // changes were able to be applied under these restrictions. A false return + // value indicates an All update is necessary. + bool ApplyChanges(NativeLayerCAUpdateType aUpdate, const gfx::IntSize& aSize, + bool aIsOpaque, const gfx::IntPoint& aPosition, + const gfx::Matrix4x4& aTransform, + const gfx::IntRect& aDisplayRect, + const Maybe<gfx::IntRect>& aClipRect, + const Maybe<gfx::RoundedRect>& aRoundedClip, + float aBackingScale, bool aSurfaceIsFlipped, + gfx::SamplingFilter aSamplingFilter, bool aSpecializeVideo, + CFTypeRefPtr<IOSurfaceRef> aFrontSurface, + CFTypeRefPtr<CGColorRef> aColor, bool aIsDRM, + bool aIsVideo); + + // Return whether any aspects of this layer representation have been mutated + // since the last call to ApplyChanges, i.e. whether ApplyChanges needs to + // be called. + // This is used to optimize away a CATransaction commit if no layers have + // changed. + NativeLayerCAUpdateType HasUpdate(bool aIsVideo); + + // Lazily initialized by first call to ApplyChanges. mWrappingLayer is the + // layer that applies the intersection of mDisplayRect and mClipRect (if + // set), and mContentCALayer is the layer that hosts the IOSurface. We do + // not share clip layers between consecutive NativeLayerCA objects with the + // same clip rect. + CALayer* mWrappingCALayer = nullptr; // strong + CALayer* mRoundedClipCALayer = nullptr; // strong + CALayer* mContentCALayer = nullptr; // strong + CALayer* mOpaquenessTintLayer = nullptr; // strong + +#ifdef NIGHTLY_BUILD + bool mLogNextVideoSurface = false; +#endif + + bool mWrappingCALayerHasExtent : 1; + + // These are all initialized to true by the constructor. + bool mMutatedPosition : 1; + bool mMutatedTransform : 1; + bool mMutatedDisplayRect : 1; + bool mMutatedClipRect : 1; + bool mMutatedRoundedClipRect : 1; + bool mMutatedBackingScale : 1; + bool mMutatedSize : 1; + bool mMutatedSurfaceIsFlipped : 1; + bool mMutatedFrontSurface : 1; + bool mMutatedSamplingFilter : 1; + bool mMutatedSpecializeVideo : 1; + bool mMutatedIsDRM : 1; + // Don't forget to update the constructor when you add a field here. +}; + // NativeLayerCA wraps a CALayer and lets you draw to it. It ensures that only // fully-drawn frames make their way to the screen, by maintaining a swap chain // of IOSurfaces. @@ -330,8 +404,10 @@ class NativeLayerCA : public NativeLayer { protected: friend class NativeLayerRootCA; + friend struct NativeLayerCARepresentation; using UpdateType = NativeLayerCAUpdateType; using WhichRepresentation = NativeLayerRootCA::WhichRepresentation; + using Representation = NativeLayerCARepresentation; NativeLayerCA(const gfx::IntSize& aSize, bool aIsOpaque, SurfacePoolHandleCA* aSurfacePoolHandle); @@ -378,75 +454,6 @@ class NativeLayerCA : public NativeLayer { const gfx::Matrix4x4& aTransform, const gfx::IntRect& aDisplayRect, const Maybe<gfx::IntRect>& aClipRect, float aBackingScale); - // Wraps one CALayer representation of this NativeLayer. - struct Representation { - Representation(); - ~Representation(); - - // Returns null if the layer is currently completely clipped out. - CALayer* UnderlyingCALayer() { - return mWrappingCALayerHasExtent ? mWrappingCALayer : nullptr; - } - - bool EnqueueSurface(IOSurfaceRef aSurfaceRef); - - // Applies buffered changes to the native CALayers. The contract with the - // caller is as follows: If any of these values have changed since the last - // call to ApplyChanges, mMutated[Field] needs to have been set to true - // before the call. If aUpdate is not All, then a partial update will be - // applied. In such a case, ApplyChanges may not make any changes that - // require a CATransacation, because no transaction will be created. In a - // a partial update, the return value will indicate if all the needed - // changes were able to be applied under these restrictions. A false return - // value indicates an All update is necessary. - bool ApplyChanges( - UpdateType aUpdate, const gfx::IntSize& aSize, bool aIsOpaque, - const gfx::IntPoint& aPosition, const gfx::Matrix4x4& aTransform, - const gfx::IntRect& aDisplayRect, const Maybe<gfx::IntRect>& aClipRect, - const Maybe<gfx::RoundedRect>& aRoundedClip, float aBackingScale, - bool aSurfaceIsFlipped, gfx::SamplingFilter aSamplingFilter, - bool aSpecializeVideo, CFTypeRefPtr<IOSurfaceRef> aFrontSurface, - CFTypeRefPtr<CGColorRef> aColor, bool aIsDRM, bool aIsVideo); - - // Return whether any aspects of this layer representation have been mutated - // since the last call to ApplyChanges, i.e. whether ApplyChanges needs to - // be called. - // This is used to optimize away a CATransaction commit if no layers have - // changed. - UpdateType HasUpdate(bool aIsVideo); - - // Lazily initialized by first call to ApplyChanges. mWrappingLayer is the - // layer that applies the intersection of mDisplayRect and mClipRect (if - // set), and mContentCALayer is the layer that hosts the IOSurface. We do - // not share clip layers between consecutive NativeLayerCA objects with the - // same clip rect. - CALayer* mWrappingCALayer = nullptr; // strong - CALayer* mRoundedClipCALayer = nullptr; // strong - CALayer* mContentCALayer = nullptr; // strong - CALayer* mOpaquenessTintLayer = nullptr; // strong - -#ifdef NIGHTLY_BUILD - bool mLogNextVideoSurface = false; -#endif - - bool mWrappingCALayerHasExtent : 1; - - // These are all initialized to true by the constructor. - bool mMutatedPosition : 1; - bool mMutatedTransform : 1; - bool mMutatedDisplayRect : 1; - bool mMutatedClipRect : 1; - bool mMutatedRoundedClipRect : 1; - bool mMutatedBackingScale : 1; - bool mMutatedSize : 1; - bool mMutatedSurfaceIsFlipped : 1; - bool mMutatedFrontSurface : 1; - bool mMutatedSamplingFilter : 1; - bool mMutatedSpecializeVideo : 1; - bool mMutatedIsDRM : 1; - // Don't forget to update the constructor when you add a field here. - }; - Representation& GetRepresentation(WhichRepresentation aRepresentation); template <typename F> void ForAllRepresentations(F aFn); diff --git a/gfx/layers/NativeLayerCA.mm b/gfx/layers/NativeLayerCA.mm @@ -1352,7 +1352,7 @@ void NativeLayerCA::SetSurfaceToPresent(CFTypeRefPtr<IOSurfaceRef> aSurfaceRef, }); } -NativeLayerCA::Representation::Representation() +NativeLayerCARepresentation::NativeLayerCARepresentation() : mWrappingCALayerHasExtent(false), mMutatedPosition(true), mMutatedTransform(true), @@ -1367,7 +1367,7 @@ NativeLayerCA::Representation::Representation() mMutatedSpecializeVideo(true), mMutatedIsDRM(true) {} -NativeLayerCA::Representation::~Representation() { +NativeLayerCARepresentation::~NativeLayerCARepresentation() { [mContentCALayer release]; [mOpaquenessTintLayer release]; [mWrappingCALayer release]; @@ -1425,7 +1425,7 @@ void NativeLayerCA::DiscardBackbuffers() { mSurfaceHandler->DiscardBackbuffers(); } -NativeLayerCA::Representation& NativeLayerCA::GetRepresentation( +NativeLayerCARepresentation& NativeLayerCA::GetRepresentation( WhichRepresentation aRepresentation) { switch (aRepresentation) { case WhichRepresentation::ONSCREEN: @@ -1557,7 +1557,7 @@ static NSString* NSStringForOSType(OSType type) { } } -bool NativeLayerCA::Representation::EnqueueSurface(IOSurfaceRef aSurfaceRef) { +bool NativeLayerCARepresentation::EnqueueSurface(IOSurfaceRef aSurfaceRef) { MOZ_ASSERT( [mContentCALayer isKindOfClass:[AVSampleBufferDisplayLayer class]]); AVSampleBufferDisplayLayer* videoLayer = @@ -1710,8 +1710,8 @@ bool NativeLayerCA::Representation::EnqueueSurface(IOSurfaceRef aSurfaceRef) { return true; } -bool NativeLayerCA::Representation::ApplyChanges( - NativeLayerCA::UpdateType aUpdate, const IntSize& aSize, bool aIsOpaque, +bool NativeLayerCARepresentation::ApplyChanges( + UpdateType aUpdate, const IntSize& aSize, bool aIsOpaque, const IntPoint& aPosition, const Matrix4x4& aTransform, const IntRect& aDisplayRect, const Maybe<IntRect>& aClipRect, const Maybe<gfx::RoundedRect>& aRoundedClip, float aBackingScale, @@ -1896,7 +1896,7 @@ bool NativeLayerCA::Representation::ApplyChanges( if (mMutatedBackingScale || mMutatedPosition || mMutatedDisplayRect || mMutatedClipRect || mMutatedRoundedClipRect || mMutatedTransform || mMutatedSurfaceIsFlipped || mMutatedSize || layerNeedsInitialization) { - Maybe<CGRect> scaledClipRect = CalculateClipGeometry( + Maybe<CGRect> scaledClipRect = NativeLayerCA::CalculateClipGeometry( aSize, aPosition, aTransform, aDisplayRect, aClipRect, aBackingScale); CGRect useClipRect; @@ -2083,7 +2083,7 @@ bool NativeLayerCA::Representation::ApplyChanges( return true; } -NativeLayerCA::UpdateType NativeLayerCA::Representation::HasUpdate( +NativeLayerCA::UpdateType NativeLayerCARepresentation::HasUpdate( bool aIsVideo) { if (!mWrappingCALayer) { return UpdateType::All;