Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 4b48af6

Browse files
committed
Bug 1690653 - Don't create a CATransaction if nothing changed. r=mattwoodrow
This avoids some overhead from committing the transaction. Differential Revision: https://phabricator.services.mozilla.com/D104085
1 parent 718867e commit 4b48af6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

gfx/layers/NativeLayerCA.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class NativeLayerCA : public NativeLayer {
244244
typedef NativeLayerRootCA::WhichRepresentation WhichRepresentation;
245245
CALayer* UnderlyingCALayer(WhichRepresentation aRepresentation);
246246
void ApplyChanges(WhichRepresentation aRepresentation);
247+
bool HasUpdate(WhichRepresentation aRepresentation);
247248
void SetBackingScale(float aBackingScale);
248249

249250
// Invalidates the specified region in all surfaces that are tracked by this
@@ -298,6 +299,13 @@ class NativeLayerCA : public NativeLayer {
298299
gfx::SamplingFilter aSamplingFilter,
299300
CFTypeRefPtr<IOSurfaceRef> aFrontSurface);
300301

302+
// Return whether any aspects of this layer representation have been mutated
303+
// since the last call to ApplyChanges, i.e. whether ApplyChanges needs to
304+
// be called.
305+
// This is used to optimize away a CATransaction commit if no layers have
306+
// changed.
307+
bool HasUpdate();
308+
301309
// Lazily initialized by first call to ApplyChanges. mWrappingLayer is the
302310
// layer that applies the intersection of mDisplayRect and mClipRect (if
303311
// set), and mContentCALayer is the layer that hosts the IOSurface. We do

gfx/layers/NativeLayerCA.mm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ bool DownscaleFrom(profiler_screenshots::RenderSource* aSource, const IntRect& a
283283

284284
void NativeLayerRootCA::Representation::Commit(WhichRepresentation aRepresentation,
285285
const nsTArray<RefPtr<NativeLayerCA>>& aSublayers) {
286+
if (!mMutated &&
287+
std::none_of(aSublayers.begin(), aSublayers.end(), [=](const RefPtr<NativeLayerCA>& layer) {
288+
return layer->HasUpdate(aRepresentation);
289+
})) {
290+
// No updates, skip creating the CATransaction altogether.
291+
return;
292+
}
293+
286294
AutoCATransaction transaction;
287295

288296
// Call ApplyChanges on our sublayers first, and then update the root layer's
@@ -805,6 +813,11 @@ bool DownscaleFrom(profiler_screenshots::RenderSource* aSource, const IntRect& a
805813
mSurfaceIsFlipped, mSamplingFilter, surface);
806814
}
807815

816+
bool NativeLayerCA::HasUpdate(WhichRepresentation aRepresentation) {
817+
MutexAutoLock lock(mMutex);
818+
return GetRepresentation(aRepresentation).HasUpdate();
819+
}
820+
808821
CALayer* NativeLayerCA::UnderlyingCALayer(WhichRepresentation aRepresentation) {
809822
MutexAutoLock lock(mMutex);
810823
return GetRepresentation(aRepresentation).UnderlyingCALayer();
@@ -961,6 +974,16 @@ bool DownscaleFrom(profiler_screenshots::RenderSource* aSource, const IntRect& a
961974
mMutatedSamplingFilter = false;
962975
}
963976

977+
bool NativeLayerCA::Representation::HasUpdate() {
978+
if (!mWrappingCALayer) {
979+
return true;
980+
}
981+
982+
return mMutatedPosition || mMutatedTransform || mMutatedDisplayRect || mMutatedClipRect ||
983+
mMutatedBackingScale || mMutatedSize || mMutatedSurfaceIsFlipped || mMutatedFrontSurface ||
984+
mMutatedSamplingFilter;
985+
}
986+
964987
// Called when mMutex is already being held by the current thread.
965988
Maybe<NativeLayerCA::SurfaceWithInvalidRegion> NativeLayerCA::GetUnusedSurfaceAndCleanUp(
966989
const MutexAutoLock&) {

0 commit comments

Comments
 (0)