Skip to content

Commit bec183a

Browse files
committedSep 10, 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 26534cd commit bec183a

13 files changed

+211
-303
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

+14-7
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,8 @@ void WebRenderCommandBuilder::CreateWebRenderCommands(
16941694
void WebRenderCommandBuilder::CreateWebRenderCommandsFromDisplayList(
16951695
nsDisplayList* aDisplayList, nsDisplayItem* aWrappingItem,
16961696
nsDisplayListBuilder* aDisplayListBuilder, const StackingContextHelper& aSc,
1697-
wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources) {
1697+
wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
1698+
bool aNewClipList) {
16981699
if (mDoGrouping) {
16991700
MOZ_RELEASE_ASSERT(
17001701
aWrappingItem,
@@ -1715,7 +1716,9 @@ void WebRenderCommandBuilder::CreateWebRenderCommandsFromDisplayList(
17151716
}
17161717

17171718
mDumpIndent++;
1718-
mClipManager.BeginList(aSc);
1719+
if (aNewClipList) {
1720+
mClipManager.BeginList(aSc);
1721+
}
17191722

17201723
bool apzEnabled = mManager->AsyncPanZoomEnabled();
17211724

@@ -1912,7 +1915,9 @@ void WebRenderCommandBuilder::CreateWebRenderCommandsFromDisplayList(
19121915
}
19131916

19141917
mDumpIndent--;
1915-
mClipManager.EndList(aSc);
1918+
if (aNewClipList) {
1919+
mClipManager.EndList(aSc);
1920+
}
19161921
}
19171922

19181923
void WebRenderCommandBuilder::PushOverrideForASR(
@@ -2484,14 +2489,16 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
24842489

24852490
nsPoint maskOffset = aMaskItem->ToReferenceFrame() - bounds.TopLeft();
24862491

2492+
bool shouldHandleOpacity = aBuilder.GetInheritedOpacity() != 1.0f;
2493+
24872494
nsRect dirtyRect;
24882495
// If this mask item is being painted for the first time, some members of
24892496
// WebRenderMaskData are still default initialized. This is intentional.
24902497
if (aMaskItem->IsInvalid(dirtyRect) ||
24912498
!itemRect.IsEqualInterior(maskData->mItemRect) ||
24922499
!(aMaskItem->Frame()->StyleSVGReset()->mMask == maskData->mMaskStyle) ||
24932500
maskOffset != maskData->mMaskOffset || !sameScale ||
2494-
aMaskItem->ShouldHandleOpacity() != maskData->mShouldHandleOpacity) {
2501+
shouldHandleOpacity != maskData->mShouldHandleOpacity) {
24952502
IntSize size = itemRect.Size().ToUnknownSize();
24962503

24972504
if (!Factory::AllowedSurfaceSize(size)) {
@@ -2535,8 +2542,8 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
25352542
.PreScale(scale.width, scale.height));
25362543

25372544
bool maskPainted = false;
2538-
bool maskIsComplete =
2539-
aMaskItem->PaintMask(aDisplayListBuilder, context, &maskPainted);
2545+
bool maskIsComplete = aMaskItem->PaintMask(
2546+
aDisplayListBuilder, context, shouldHandleOpacity, &maskPainted);
25402547
if (!maskPainted) {
25412548
return Nothing();
25422549
}
@@ -2587,7 +2594,7 @@ Maybe<wr::ImageMask> WebRenderCommandBuilder::BuildWrMaskImage(
25872594
maskData->mMaskOffset = maskOffset;
25882595
maskData->mScale = scale;
25892596
maskData->mMaskStyle = aMaskItem->Frame()->StyleSVGReset()->mMask;
2590-
maskData->mShouldHandleOpacity = aMaskItem->ShouldHandleOpacity();
2597+
maskData->mShouldHandleOpacity = shouldHandleOpacity;
25912598
}
25922599
}
25932600

‎gfx/layers/wr/WebRenderCommandBuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class WebRenderCommandBuilder final {
101101
nsDisplayList* aDisplayList, nsDisplayItem* aWrappingItem,
102102
nsDisplayListBuilder* aDisplayListBuilder,
103103
const StackingContextHelper& aSc, wr::DisplayListBuilder& aBuilder,
104-
wr::IpcResourceUpdateQueue& aResources);
104+
wr::IpcResourceUpdateQueue& aResources, bool aNewClipList = true);
105105

106106
// aWrappingItem has to be non-null.
107107
void DoGroupingForDisplayList(nsDisplayList* aDisplayList,

‎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.