Skip to content

Commit 875e653

Browse files
committedSep 6, 2021
Bug 1728050 - Move opacity flattening to be part of WR DL serialization. r=miko
Differential Revision: https://phabricator.services.mozilla.com/D124005
1 parent 6aa0fe5 commit 875e653

8 files changed

+218
-293
lines changed
 

‎gfx/layers/wr/DisplayItemCache.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ Maybe<uint16_t> DisplayItemCache::CanReuseItem(
180180
return Nothing();
181181
}
182182

183+
if (mSuppressed) {
184+
slot.mOccupied = false;
185+
slotIndex = Nothing();
186+
return Nothing();
187+
}
188+
183189
if (!(aSpaceAndClip == slot.mSpaceAndClip)) {
184190
// Spatial id and clip id can change between display lists, if items that
185191
// generate them change their order.

‎gfx/layers/wr/DisplayItemCache.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ class DisplayItemCache final {
100100
/**
101101
* Suppress display item caching. This doesn't clear any existing cached
102102
* items or change the underlying capacity, it just makes IsEnabled() return
103-
* false. It is not meant to be flipped in the middle of a display list build,
104-
* but rather set before the display list build starts to suppress use of the
105-
* cache for that display list build.
103+
* false.
104+
* It will also make CanReuseItem return false for the duration of the
105+
* suppression.
106106
*/
107107
bool SetSuppressed(bool aSuppressed) {
108108
if (aSuppressed == mSuppressed) {

‎gfx/layers/wr/WebRenderCommandBuilder.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -2484,14 +2484,16 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
24842484

24852485
nsPoint maskOffset = aMaskItem->ToReferenceFrame() - bounds.TopLeft();
24862486

2487+
bool shouldHandleOpacity = aBuilder.GetInheritedOpacity() != 1.0f;
2488+
24872489
nsRect dirtyRect;
24882490
// If this mask item is being painted for the first time, some members of
24892491
// WebRenderMaskData are still default initialized. This is intentional.
24902492
if (aMaskItem->IsInvalid(dirtyRect) ||
24912493
!itemRect.IsEqualInterior(maskData->mItemRect) ||
24922494
!(aMaskItem->Frame()->StyleSVGReset()->mMask == maskData->mMaskStyle) ||
24932495
maskOffset != maskData->mMaskOffset || !sameScale ||
2494-
aMaskItem->ShouldHandleOpacity() != maskData->mShouldHandleOpacity) {
2496+
shouldHandleOpacity != maskData->mShouldHandleOpacity) {
24952497
IntSize size = itemRect.Size().ToUnknownSize();
24962498

24972499
if (!Factory::AllowedSurfaceSize(size)) {
@@ -2535,8 +2537,8 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
25352537
.PreScale(scale.width, scale.height));
25362538

25372539
bool maskPainted = false;
2538-
bool maskIsComplete =
2539-
aMaskItem->PaintMask(aDisplayListBuilder, context, &maskPainted);
2540+
bool maskIsComplete = aMaskItem->PaintMask(
2541+
aDisplayListBuilder, context, shouldHandleOpacity, &maskPainted);
25402542
if (!maskPainted) {
25412543
return Nothing();
25422544
}
@@ -2587,7 +2589,7 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
25872589
maskData->mMaskOffset = maskOffset;
25882590
maskData->mScale = scale;
25892591
maskData->mMaskStyle = aMaskItem->Frame()->StyleSVGReset()->mMask;
2590-
maskData->mShouldHandleOpacity = aMaskItem->ShouldHandleOpacity();
2592+
maskData->mShouldHandleOpacity = shouldHandleOpacity;
25912593
}
25922594
}
25932595

‎gfx/webrender_bindings/WebRenderAPI.h

+12
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,17 @@ class DisplayListBuilder final {
684684
mClipChainLeaf = aClipRect;
685685
}
686686

687+
// Used for opacity flattening. When we flatten away an opacity item,
688+
// we push the opacity value onto the builder.
689+
// Descendant items should pull the inherited opacity during
690+
// their CreateWebRenderCommands implementation. This can only happen if all
691+
// descendant items reported supporting this functionality, via
692+
// nsDisplayItem::CanApplyOpacity.
693+
float GetInheritedOpacity() { return mInheritedOpacity; }
694+
void SetInheritedOpacity(float aOpacity) { mInheritedOpacity = aOpacity; }
695+
696+
layers::DisplayItemCache* GetDisplayItemCache() { return mDisplayItemCache; }
697+
687698
// A chain of RAII objects, each holding a (ASR, ViewID, SideBits) tuple of
688699
// data. The topmost object is pointed to by the mActiveFixedPosTracker
689700
// pointer in the wr::DisplayListBuilder.
@@ -750,6 +761,7 @@ class DisplayListBuilder final {
750761

751762
layers::DisplayItemCache* mDisplayItemCache;
752763
Maybe<uint16_t> mCurrentCacheSlot;
764+
float mInheritedOpacity = 1.0f;
753765

754766
friend class WebRenderAPI;
755767
friend class SpaceAndClipChainHelper;

0 commit comments

Comments
 (0)
Failed to load comments.