Source code

Revision control

Other Tools

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* structures that represent things to be painted (ordered in z-order),
* used during painting and hit testing
*/
#include "nsDisplayList.h"
#include <stdint.h>
#include <algorithm>
#include <limits>
#include "gfxContext.h"
#include "gfxUtils.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/ServiceWorkerRegistration.h"
#include "mozilla/dom/SVGElement.h"
#include "mozilla/dom/TouchEvent.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/layers/PLayerTransaction.h"
#include "mozilla/PresShell.h"
#include "mozilla/ShapeUtils.h"
#include "mozilla/StaticPrefs_apz.h"
#include "mozilla/StaticPrefs_gfx.h"
#include "mozilla/StaticPrefs_layers.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/ViewportUtils.h"
#include "nsCSSRendering.h"
#include "nsCSSRenderingGradients.h"
#include "nsRegion.h"
#include "nsStyleStructInlines.h"
#include "nsStyleTransformMatrix.h"
#include "nsTransitionManager.h"
#include "gfxMatrix.h"
#include "nsSVGIntegrationUtils.h"
#include "nsSVGUtils.h"
#include "nsLayoutUtils.h"
#include "nsIScrollableFrame.h"
#include "nsIFrameInlines.h"
#include "nsStyleConsts.h"
#include "BorderConsts.h"
#include "LayerTreeInvalidation.h"
#include "mozilla/MathAlgorithms.h"
#include "imgIContainer.h"
#include "BasicLayers.h"
#include "nsBoxFrame.h"
#include "nsImageFrame.h"
#include "nsSubDocumentFrame.h"
#include "SVGObserverUtils.h"
#include "nsSVGClipPathFrame.h"
#include "GeckoProfiler.h"
#include "nsViewManager.h"
#include "ImageLayers.h"
#include "ImageContainer.h"
#include "nsCanvasFrame.h"
#include "nsSubDocumentFrame.h"
#include "StickyScrollContainer.h"
#include "mozilla/AnimationPerformanceWarning.h"
#include "mozilla/AnimationUtils.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/EffectCompositor.h"
#include "mozilla/EffectSet.h"
#include "mozilla/EventStates.h"
#include "mozilla/HashTable.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/OperatorNewExtensions.h"
#include "mozilla/PendingAnimationTracker.h"
#include "mozilla/Preferences.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/Telemetry.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
#include "mozilla/ViewportFrame.h"
#include "mozilla/gfx/gfxVars.h"
#include "ActiveLayerTracker.h"
#include "nsPrintfCString.h"
#include "UnitTransforms.h"
#include "LayerAnimationInfo.h"
#include "LayersLogging.h"
#include "FrameLayerBuilder.h"
#include "mozilla/EventStateManager.h"
#include "nsCaret.h"
#include "nsDOMTokenList.h"
#include "nsCSSProps.h"
#include "nsSVGMaskFrame.h"
#include "nsTableCellFrame.h"
#include "nsTableColFrame.h"
#include "nsTextFrame.h"
#include "nsSliderFrame.h"
#include "nsFocusManager.h"
#include "ClientLayerManager.h"
#include "mozilla/layers/AnimationHelper.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/InputAPZContext.h"
#include "mozilla/layers/RenderRootStateManager.h"
#include "mozilla/layers/StackingContextHelper.h"
#include "mozilla/layers/TreeTraversal.h"
#include "mozilla/layers/WebRenderBridgeChild.h"
#include "mozilla/layers/WebRenderLayerManager.h"
#include "mozilla/layers/WebRenderMessages.h"
#include "mozilla/layers/WebRenderScrollData.h"
using namespace mozilla;
using namespace mozilla::layers;
using namespace mozilla::dom;
using namespace mozilla::layout;
using namespace mozilla::gfx;
typedef ScrollableLayerGuid::ViewID ViewID;
typedef nsStyleTransformMatrix::TransformReferenceBox TransformReferenceBox;
#ifdef DEBUG
static bool SpammyLayoutWarningsEnabled() {
static bool sValue = false;
static bool sValueInitialized = false;
if (!sValueInitialized) {
Preferences::GetBool("layout.spammy_warnings.enabled", &sValue);
sValueInitialized = true;
}
return sValue;
}
#endif
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
void AssertUniqueItem(nsDisplayItem* aItem) {
nsIFrame::DisplayItemArray* items =
aItem->Frame()->GetProperty(nsIFrame::DisplayItems());
if (!items) {
return;
}
for (nsDisplayItemBase* i : *items) {
if (i != aItem && !i->HasDeletedFrame() && i->Frame() == aItem->Frame() &&
i->GetPerFrameKey() == aItem->GetPerFrameKey()) {
if (i->IsPreProcessedItem()) {
continue;
}
MOZ_DIAGNOSTIC_ASSERT(false, "Duplicate display item!");
}
}
}
#endif
bool ShouldBuildItemForEventsOrPlugins(const DisplayItemType aType) {
return aType == DisplayItemType::TYPE_COMPOSITOR_HITTEST_INFO ||
aType == DisplayItemType::TYPE_PLUGIN ||
(GetDisplayItemFlagsForType(aType) & TYPE_IS_CONTAINER);
}
void UpdateDisplayItemData(nsPaintedDisplayItem* aItem) {
for (mozilla::DisplayItemData* did : aItem->Frame()->DisplayItemData()) {
if (did->GetDisplayItemKey() == aItem->GetPerFrameKey() &&
did->GetLayer()->AsPaintedLayer()) {
if (!did->HasMergedFrames()) {
aItem->SetDisplayItemData(did, did->GetLayer()->Manager());
}
return;
}
}
}
/* static */
bool ActiveScrolledRoot::IsAncestor(const ActiveScrolledRoot* aAncestor,
const ActiveScrolledRoot* aDescendant) {
if (!aAncestor) {
// nullptr is the root
return true;
}
if (Depth(aAncestor) > Depth(aDescendant)) {
return false;
}
const ActiveScrolledRoot* asr = aDescendant;
while (asr) {
if (asr == aAncestor) {
return true;
}
asr = asr->mParent;
}
return false;
}
/* static */
nsCString ActiveScrolledRoot::ToString(
const ActiveScrolledRoot* aActiveScrolledRoot) {
nsAutoCString str;
for (auto* asr = aActiveScrolledRoot; asr; asr = asr->mParent) {
str.AppendPrintf("<0x%p>", asr->mScrollableFrame);
if (asr->mParent) {
str.AppendLiteral(", ");
}
}
return std::move(str);
}
static uint64_t AddAnimationsForWebRender(
nsDisplayItem* aItem, mozilla::layers::RenderRootStateManager* aManager,
nsDisplayListBuilder* aDisplayListBuilder) {
EffectSet* effects =
EffectSet::GetEffectSetForFrame(aItem->Frame(), aItem->GetType());
if (!effects || effects->IsEmpty()) {
// If there is no animation on the nsIFrame, that means
// 1) we've never created any animations on this frame or
// 2) the frame was reconstruced or
// 3) all animations on the frame have finished
// in such cases we don't need do anything here.
//
// Even if there is a WebRenderAnimationData for the display item type on
// this frame, it's going to be discarded since it's not marked as being
// used.
return 0;
}
RefPtr<WebRenderAnimationData> animationData =
aManager->CommandBuilder()
.CreateOrRecycleWebRenderUserData<WebRenderAnimationData>(aItem);
AnimationInfo& animationInfo = animationData->GetAnimationInfo();
animationInfo.AddAnimationsForDisplayItem(aItem->Frame(), aDisplayListBuilder,
aItem, aItem->GetType(),
layers::LayersBackend::LAYERS_WR);
animationInfo.StartPendingAnimations(
aManager->LayerManager()->GetAnimationReadyTime());
// Note that animationsId can be 0 (uninitialized in AnimationInfo) if there
// are no active animations.
uint64_t animationsId = animationInfo.GetCompositorAnimationsId();
if (!animationInfo.GetAnimations().IsEmpty()) {
OpAddCompositorAnimations anim(
CompositorAnimations(animationInfo.GetAnimations(), animationsId));
aManager->WrBridge()->AddWebRenderParentCommand(anim);
aManager->AddActiveCompositorAnimationId(animationsId);
} else if (animationsId) {
aManager->AddCompositorAnimationsIdForDiscard(animationsId);
animationsId = 0;
}
return animationsId;
}
static bool GenerateAndPushTextMask(nsIFrame* aFrame, gfxContext* aContext,
const nsRect& aFillRect,
nsDisplayListBuilder* aBuilder) {
if (aBuilder->IsForGenerateGlyphMask()) {
return false;
}
SVGObserverUtils::GetAndObserveBackgroundClip(aFrame);
// The main function of enabling background-clip:text property value.
// When a nsDisplayBackgroundImage detects "text" bg-clip style, it will call
// this function to
// 1. Generate a mask by all descendant text frames
// 2. Push the generated mask into aContext.
gfxContext* sourceCtx = aContext;
LayoutDeviceRect bounds = LayoutDeviceRect::FromAppUnits(
aFillRect, aFrame->PresContext()->AppUnitsPerDevPixel());
// Create a mask surface.
RefPtr<DrawTarget> sourceTarget = sourceCtx->GetDrawTarget();
RefPtr<DrawTarget> maskDT = sourceTarget->CreateClippedDrawTarget(
bounds.ToUnknownRect(), SurfaceFormat::A8);
if (!maskDT || !maskDT->IsValid()) {
return false;
}
RefPtr<gfxContext> maskCtx =
gfxContext::CreatePreservingTransformOrNull(maskDT);
MOZ_ASSERT(maskCtx);
maskCtx->Multiply(Matrix::Translation(bounds.TopLeft().ToUnknownPoint()));
// Shade text shape into mask A8 surface.
nsLayoutUtils::PaintFrame(
maskCtx, aFrame, nsRect(nsPoint(0, 0), aFrame->GetSize()),
NS_RGB(255, 255, 255), nsDisplayListBuilderMode::GenerateGlyph);
// Push the generated mask into aContext, so that the caller can pop and
// blend with it.
Matrix currentMatrix = sourceCtx->CurrentMatrix();
Matrix invCurrentMatrix = currentMatrix;
invCurrentMatrix.Invert();
RefPtr<SourceSurface> maskSurface = maskDT->Snapshot();
sourceCtx->PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, 1.0,
maskSurface, invCurrentMatrix);
return true;
}
/* static */
void nsDisplayListBuilder::AddAnimationsAndTransitionsToLayer(
Layer* aLayer, nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem,
nsIFrame* aFrame, DisplayItemType aType) {
// This function can be called in two ways: from
// nsDisplay*::BuildLayer while constructing a layer (with all
// pointers non-null), or from RestyleManager's handling of
// UpdateOpacityLayer/UpdateTransformLayer hints.
MOZ_ASSERT(!aBuilder == !aItem,
"should only be called in two configurations, with both "
"aBuilder and aItem, or with neither");
MOZ_ASSERT(!aItem || aFrame == aItem->Frame(), "frame mismatch");
// Only send animations to a layer that is actually using
// off-main-thread compositing.
LayersBackend backend = aLayer->Manager()->GetBackendType();
if (!(backend == layers::LayersBackend::LAYERS_CLIENT ||
backend == layers::LayersBackend::LAYERS_WR)) {
return;
}
AnimationInfo& animationInfo = aLayer->GetAnimationInfo();
animationInfo.AddAnimationsForDisplayItem(
aFrame, aBuilder, aItem, aType, layers::LayersBackend::LAYERS_CLIENT);
animationInfo.TransferMutatedFlagToLayer(aLayer);
}
nsDisplayWrapList* nsDisplayListBuilder::MergeItems(
nsTArray<nsDisplayWrapList*>& aItems) {
// For merging, we create a temporary item by cloning the last item of the
// mergeable items list. This ensures that the temporary item will have the
// correct frame and bounds.
nsDisplayWrapList* merged = nullptr;
for (nsDisplayWrapList* item : Reversed(aItems)) {
MOZ_ASSERT(item);
if (!merged) {
// Create the temporary item.
merged = item->Clone(this);
MOZ_ASSERT(merged);
AddTemporaryItem(merged);
} else {
// Merge the item properties (frame/bounds/etc) with the previously
// created temporary item.
MOZ_ASSERT(merged->CanMerge(item));
merged->Merge(item);
}
// Create nsDisplayWrapList that points to the internal display list of the
// item we are merging. This nsDisplayWrapList is added to the display list
// of the temporary item.
merged->MergeDisplayListFromItem(this, item);
}
return merged;
}
void nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter::
SetCurrentActiveScrolledRoot(
const ActiveScrolledRoot* aActiveScrolledRoot) {
MOZ_ASSERT(!mUsed);
// Set the builder's mCurrentActiveScrolledRoot.
mBuilder->mCurrentActiveScrolledRoot = aActiveScrolledRoot;
// We also need to adjust the builder's mCurrentContainerASR.
// mCurrentContainerASR needs to be an ASR that all the container's
// contents have finite bounds with respect to. If aActiveScrolledRoot
// is an ancestor ASR of mCurrentContainerASR, that means we need to
// set mCurrentContainerASR to aActiveScrolledRoot, because otherwise
// the items that will be created with aActiveScrolledRoot wouldn't
// have finite bounds with respect to mCurrentContainerASR. There's one
// exception, in the case where there's a content clip on the builder
// that is scrolled by a descendant ASR of aActiveScrolledRoot. This
// content clip will clip all items that are created while this
// AutoCurrentActiveScrolledRootSetter exists. This means that the items
// created during our lifetime will have finite bounds with respect to
// the content clip's ASR, even if the items' actual ASR is an ancestor
// of that. And it also means that mCurrentContainerASR only needs to be
// set to the content clip's ASR and not all the way to aActiveScrolledRoot.
// This case is tested by fixed-pos-scrolled-clip-opacity-layerize.html
// and fixed-pos-scrolled-clip-opacity-inside-layerize.html.
// finiteBoundsASR is the leafmost ASR that all items created during
// object's lifetime have finite bounds with respect to.
const ActiveScrolledRoot* finiteBoundsASR =
ActiveScrolledRoot::PickDescendant(mContentClipASR, aActiveScrolledRoot);
// mCurrentContainerASR is adjusted so that it's still an ancestor of
// finiteBoundsASR.
mBuilder->mCurrentContainerASR = ActiveScrolledRoot::PickAncestor(
mBuilder->mCurrentContainerASR, finiteBoundsASR);
// If we are entering out-of-flow content inside a CSS filter, mark
// scroll frames wrt. which the content is fixed as containing such content.
if (mBuilder->mFilterASR && ActiveScrolledRoot::IsAncestor(
aActiveScrolledRoot, mBuilder->mFilterASR)) {
for (const ActiveScrolledRoot* asr = mBuilder->mFilterASR;
asr && asr != aActiveScrolledRoot; asr = asr->mParent) {
asr->mScrollableFrame->SetHasOutOfFlowContentInsideFilter();
}
}
mUsed = true;
}
void nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter::
InsertScrollFrame(nsIScrollableFrame* aScrollableFrame) {
MOZ_ASSERT(!mUsed);
size_t descendantsEndIndex = mBuilder->mActiveScrolledRoots.Length();
const ActiveScrolledRoot* parentASR = mBuilder->mCurrentActiveScrolledRoot;
const ActiveScrolledRoot* asr =
mBuilder->AllocateActiveScrolledRoot(parentASR, aScrollableFrame);
mBuilder->mCurrentActiveScrolledRoot = asr;
// All child ASRs of parentASR that were created while this
// AutoCurrentActiveScrolledRootSetter object was on the stack belong to us
// now. Reparent them to asr.
for (size_t i = mDescendantsStartIndex; i < descendantsEndIndex; i++) {
ActiveScrolledRoot* descendantASR = mBuilder->mActiveScrolledRoots[i];
if (ActiveScrolledRoot::IsAncestor(parentASR, descendantASR)) {
descendantASR->IncrementDepth();
if (descendantASR->mParent == parentASR) {
descendantASR->mParent = asr;
}
}
}
mUsed = true;
}
/* static */
nsRect nsDisplayListBuilder::OutOfFlowDisplayData::ComputeVisibleRectForFrame(
nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
const nsRect& aVisibleRect, const nsRect& aDirtyRect,
nsRect* aOutDirtyRect) {
nsRect visible = aVisibleRect;
nsRect dirtyRectRelativeToDirtyFrame = aDirtyRect;
if (StaticPrefs::apz_allow_zooming() &&
nsLayoutUtils::IsFixedPosFrameInDisplayPort(aFrame) &&
aBuilder->IsPaintingToWindow()) {
dirtyRectRelativeToDirtyFrame =
nsRect(nsPoint(0, 0), aFrame->GetParent()->GetSize());
// If there's a visual viewport size set, restrict the amount of the
// fixed-position element we paint to the visual viewport. (In general
// the fixed-position element can be as large as the layout viewport,
// which at a high zoom level can cause us to paint too large of an
// area.)
PresShell* presShell = aFrame->PresShell();
if (presShell->IsVisualViewportSizeSet()) {
dirtyRectRelativeToDirtyFrame =
nsRect(presShell->GetVisualViewportOffset(),
presShell->GetVisualViewportSize());
// But if we have a displayport, expand it to the displayport, so
// that async-scrolling the visual viewport within the layout viewport
// will not checkerboard.
if (nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame()) {
nsRect displayport;
// Note that the displayport here is already in the right coordinate
// space: it's relative to the scroll port (= layout viewport), but
// covers the visual viewport with some margins around it, which is
// exactly what we want.
if (nsLayoutUtils::GetHighResolutionDisplayPort(
rootScrollFrame->GetContent(), &displayport)) {
dirtyRectRelativeToDirtyFrame = displayport;
}
}
}
visible = dirtyRectRelativeToDirtyFrame;
if (StaticPrefs::apz_test_logging_enabled() &&
presShell->GetDocument()->IsContentDocument()) {
nsLayoutUtils::LogAdditionalTestData(
aBuilder, "fixedPosDisplayport",
ToString(CSSSize::FromAppUnits(visible)));
}
}
*aOutDirtyRect = dirtyRectRelativeToDirtyFrame - aFrame->GetPosition();
visible -= aFrame->GetPosition();
nsRect overflowRect = aFrame->GetVisualOverflowRect();
if (aFrame->IsTransformed() &&
mozilla::EffectCompositor::HasAnimationsForCompositor(
aFrame, DisplayItemType::TYPE_TRANSFORM)) {
/**
* Add a fuzz factor to the overflow rectangle so that elements only
* just out of view are pulled into the display list, so they can be
* prerendered if necessary.
*/
overflowRect.Inflate(nsPresContext::CSSPixelsToAppUnits(32));
}
visible.IntersectRect(visible, overflowRect);
aOutDirtyRect->IntersectRect(*aOutDirtyRect, overflowRect);
return visible;
}
nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame,
nsDisplayListBuilderMode aMode,
bool aBuildCaret,
bool aRetainingDisplayList)
: mReferenceFrame(aReferenceFrame),
mIgnoreScrollFrame(nullptr),
mCurrentActiveScrolledRoot(nullptr),
mCurrentContainerASR(nullptr),
mCurrentFrame(aReferenceFrame),
mCurrentReferenceFrame(aReferenceFrame),
mRootAGR(AnimatedGeometryRoot::CreateAGRForFrame(
aReferenceFrame, nullptr, true, aRetainingDisplayList)),
mCurrentAGR(mRootAGR),
mBuildingExtraPagesForPageNum(0),
mUsedAGRBudget(0),
mDirtyRect(-1, -1, -1, -1),
mGlassDisplayItem(nullptr),
mCaretFrame(nullptr),
mScrollInfoItemsForHoisting(nullptr),
mFirstClipChainToDestroy(nullptr),
mMode(aMode),
mTableBackgroundSet(nullptr),
mCurrentScrollParentId(ScrollableLayerGuid::NULL_SCROLL_ID),
mCurrentScrollbarTarget(ScrollableLayerGuid::NULL_SCROLL_ID),
mFilterASR(nullptr),
mContainsBlendMode(false),
mIsBuildingScrollbar(false),
mCurrentScrollbarWillHaveLayer(false),
mBuildCaret(aBuildCaret),
mRetainingDisplayList(aRetainingDisplayList),
mPartialUpdate(false),
mIgnoreSuppression(false),
mIncludeAllOutOfFlows(false),
mDescendIntoSubdocuments(true),
mSelectedFramesOnly(false),
mAllowMergingAndFlattening(true),
mWillComputePluginGeometry(false),
mInTransform(false),
mInEventsAndPluginsOnly(false),
mInFilter(false),
mInPageSequence(false),
mIsInChromePresContext(false),
mSyncDecodeImages(false),
mIsPaintingToWindow(false),
mIsPaintingForWebRender(false),
mIsCompositingCheap(false),
mContainsPluginItem(false),
mAncestorHasApzAwareEventHandler(false),
mHaveScrollableDisplayPort(false),
mWindowDraggingAllowed(false),
mIsBuildingForPopup(nsLayoutUtils::IsPopup(aReferenceFrame)),
mForceLayerForScrollParent(false),
mAsyncPanZoomEnabled(nsLayoutUtils::AsyncPanZoomEnabled(aReferenceFrame)),
mBuildingInvisibleItems(false),
mHitTestIsForVisibility(false),
mIsBuilding(false),
mInInvalidSubtree(false),
mDisablePartialUpdates(false),
mPartialBuildFailed(false),
mIsInActiveDocShell(false),
mBuildAsyncZoomContainer(false),
mContainsBackdropFilter(false),
mIsRelativeToLayoutViewport(false),
mHitTestArea(),
mHitTestInfo(CompositorHitTestInvisibleToHit) {
MOZ_COUNT_CTOR(nsDisplayListBuilder);
mBuildCompositorHitTestInfo = mAsyncPanZoomEnabled && IsForPainting();
ShouldRebuildDisplayListDueToPrefChange();
static_assert(
static_cast<uint32_t>(DisplayItemType::TYPE_MAX) < (1 << TYPE_BITS),
"Check TYPE_MAX should not overflow");
}
static PresShell* GetFocusedPresShell() {
nsPIDOMWindowOuter* focusedWnd =
nsFocusManager::GetFocusManager()->GetFocusedWindow();
if (!focusedWnd) {
return nullptr;
}
nsCOMPtr<nsIDocShell> focusedDocShell = focusedWnd->GetDocShell();
if (!focusedDocShell) {
return nullptr;
}
return focusedDocShell->GetPresShell();
}
void nsDisplayListBuilder::BeginFrame() {
nsCSSRendering::BeginFrameTreesLocked();
mCurrentAGR = mRootAGR;
mFrameToAnimatedGeometryRootMap.Put(mReferenceFrame, mRootAGR);
mIsPaintingToWindow = false;
mIgnoreSuppression = false;
mInTransform = false;
mInFilter = false;
mSyncDecodeImages = false;
if (!mBuildCaret) {
return;
}
RefPtr<PresShell> presShell = GetFocusedPresShell();
if (presShell) {
RefPtr<nsCaret> caret = presShell->GetCaret();
mCaretFrame = caret->GetPaintGeometry(&mCaretRect);
// The focused pres shell may not be in the document that we're
// painting, or be in a popup. Check if the display root for
// the caret matches the display root that we're painting, and
// only use it if it matches.
if (mCaretFrame &&
nsLayoutUtils::GetDisplayRootFrame(mCaretFrame) !=
nsLayoutUtils::GetDisplayRootFrame(mReferenceFrame)) {
mCaretFrame = nullptr;
}
}
}
void nsDisplayListBuilder::EndFrame() {
NS_ASSERTION(!mInInvalidSubtree,
"Someone forgot to cleanup mInInvalidSubtree!");
mFrameToAnimatedGeometryRootMap.Clear();
mAGRBudgetSet.Clear();
mActiveScrolledRoots.Clear();
mEffectsUpdates.Clear();
FreeClipChains();
FreeTemporaryItems();
nsCSSRendering::EndFrameTreesLocked();
mCaretFrame = nullptr;
}
void nsDisplayListBuilder::MarkFrameForDisplay(nsIFrame* aFrame,
const nsIFrame* aStopAtFrame) {
mFramesMarkedForDisplay.AppendElement(aFrame);
for (nsIFrame* f = aFrame; f;
f = nsLayoutUtils::GetParentOrPlaceholderForCrossDoc(f)) {
if (f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO) {
return;
}
f->AddStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
if (f == aStopAtFrame) {
// we've reached a frame that we know will be painted, so we can stop.
break;
}
}
}
void nsDisplayListBuilder::AddFrameMarkedForDisplayIfVisible(nsIFrame* aFrame) {
mFramesMarkedForDisplayIfVisible.AppendElement(aFrame);
}
void nsDisplayListBuilder::MarkFrameForDisplayIfVisible(
nsIFrame* aFrame, const nsIFrame* aStopAtFrame) {
AddFrameMarkedForDisplayIfVisible(aFrame);
for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetDisplayListParent(f)) {
if (f->ForceDescendIntoIfVisible()) {
return;
}
f->SetForceDescendIntoIfVisible(true);
if (f == aStopAtFrame) {
// we've reached a frame that we know will be painted, so we can stop.
break;
}
}
}
void nsDisplayListBuilder::SetGlassDisplayItem(nsDisplayItem* aItem) {
// Web pages or extensions could trigger the "Multiple glass backgrounds
// found?" warning by using -moz-appearance:win-borderless-glass etc on their
// own elements (as long as they are DocElementBoxFrames, which is rare as
// each xul doc only gets one near the root). We only care about first one,
// since that will be the background of the root window.
if (IsPartialUpdate()) {
if (aItem->Frame()->IsDocElementBoxFrame()) {
#ifdef DEBUG
if (mHasGlassItemDuringPartial) {
NS_WARNING("Multiple glass backgrounds found?");
} else
#endif
if (!mHasGlassItemDuringPartial) {
mHasGlassItemDuringPartial = true;
aItem->SetIsGlassItem();
}
}
return;
}
if (aItem->Frame()->IsDocElementBoxFrame()) {
#ifdef DEBUG
if (mGlassDisplayItem) {
NS_WARNING("Multiple glass backgrounds found?");
} else
#endif
if (!mGlassDisplayItem) {
mGlassDisplayItem = aItem;
mGlassDisplayItem->SetIsGlassItem();
}
}
}
bool nsDisplayListBuilder::NeedToForceTransparentSurfaceForItem(
nsDisplayItem* aItem) {
return aItem == mGlassDisplayItem || aItem->ClearsBackground();
}
AnimatedGeometryRoot* nsDisplayListBuilder::WrapAGRForFrame(
nsIFrame* aAnimatedGeometryRoot, bool aIsAsync,
AnimatedGeometryRoot* aParent /* = nullptr */) {
DebugOnly<bool> dummy;
MOZ_ASSERT(IsAnimatedGeometryRoot(aAnimatedGeometryRoot, dummy) == AGR_YES);
RefPtr<AnimatedGeometryRoot> result;
if (!mFrameToAnimatedGeometryRootMap.Get(aAnimatedGeometryRoot, &result)) {
MOZ_ASSERT(nsLayoutUtils::IsAncestorFrameCrossDoc(RootReferenceFrame(),
aAnimatedGeometryRoot));
RefPtr<AnimatedGeometryRoot> parent = aParent;
if (!parent) {
nsIFrame* parentFrame =
nsLayoutUtils::GetCrossDocParentFrame(aAnimatedGeometryRoot);
if (parentFrame) {
bool isAsync;
nsIFrame* parentAGRFrame =
FindAnimatedGeometryRootFrameFor(parentFrame, isAsync);
parent = WrapAGRForFrame(parentAGRFrame, isAsync);
}
}
result = AnimatedGeometryRoot::CreateAGRForFrame(
aAnimatedGeometryRoot, parent, aIsAsync, IsRetainingDisplayList());
mFrameToAnimatedGeometryRootMap.Put(aAnimatedGeometryRoot, result);
}
MOZ_ASSERT(!aParent || result->mParentAGR == aParent);
return result;
}
AnimatedGeometryRoot* nsDisplayListBuilder::AnimatedGeometryRootForASR(
const ActiveScrolledRoot* aASR) {
if (!aASR) {
return GetRootAnimatedGeometryRoot();
}
nsIFrame* scrolledFrame = aASR->mScrollableFrame->GetScrolledFrame();
return FindAnimatedGeometryRootFor(scrolledFrame);
}
AnimatedGeometryRoot* nsDisplayListBuilder::FindAnimatedGeometryRootFor(
nsIFrame* aFrame) {
if (!IsPaintingToWindow()) {
return mRootAGR;
}
if (aFrame == mCurrentFrame) {
return mCurrentAGR;
}
RefPtr<AnimatedGeometryRoot> result;
if (mFrameToAnimatedGeometryRootMap.Get(aFrame, &result)) {
return result;
}
bool isAsync;
nsIFrame* agrFrame = FindAnimatedGeometryRootFrameFor(aFrame, isAsync);
result = WrapAGRForFrame(agrFrame, isAsync);
mFrameToAnimatedGeometryRootMap.Put(aFrame, result);
return result;
}
AnimatedGeometryRoot* nsDisplayListBuilder::FindAnimatedGeometryRootFor(
nsDisplayItem* aItem) {
if (aItem->ShouldFixToViewport(this)) {
// Make its active scrolled root be the active scrolled root of
// the enclosing viewport, since it shouldn't be scrolled by scrolled
// frames in its document. InvalidateFixedBackgroundFramesFromList in
// nsGfxScrollFrame will not repaint this item when scrolling occurs.
nsIFrame* viewportFrame = nsLayoutUtils::GetClosestFrameOfType(
aItem->Frame(), LayoutFrameType::Viewport, RootReferenceFrame());
if (viewportFrame) {
return FindAnimatedGeometryRootFor(viewportFrame);
}
}
return FindAnimatedGeometryRootFor(aItem->Frame());
}
void nsDisplayListBuilder::SetIsRelativeToLayoutViewport() {
mIsRelativeToLayoutViewport = true;
UpdateShouldBuildAsyncZoomContainer();
}
void nsDisplayListBuilder::UpdateShouldBuildAsyncZoomContainer() {
Document* document = mReferenceFrame->PresContext()->Document();
mBuildAsyncZoomContainer = !mIsRelativeToLayoutViewport &&
nsLayoutUtils::AllowZoomingForDocument(document);
}
// Certain prefs may cause display list items to be added or removed when they
// are toggled. In those cases, we need to fully rebuild the display list.
bool nsDisplayListBuilder::ShouldRebuildDisplayListDueToPrefChange() {
// If we transition between wrapping the RCD-RSF contents into an async
// zoom container vs. not, we need to rebuild the display list. This only
// happens when the zooming or container scrolling prefs are toggled
// (manually by the user, or during test setup).
bool didBuildAsyncZoomContainer = mBuildAsyncZoomContainer;
UpdateShouldBuildAsyncZoomContainer();
if (didBuildAsyncZoomContainer != mBuildAsyncZoomContainer) {
return true;
}
return false;
}
bool nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay(
nsIFrame* aDirtyFrame, nsIFrame* aFrame, const nsRect& aVisibleRect,
const nsRect& aDirtyRect) {
MOZ_ASSERT(aFrame->GetParent() == aDirtyFrame);
nsRect dirty;
nsRect visible = OutOfFlowDisplayData::ComputeVisibleRectForFrame(
this, aFrame, aVisibleRect, aDirtyRect, &dirty);
if (!(aFrame->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO) &&
visible.IsEmpty()) {
return false;
}
// Only MarkFrameForDisplay if we're dirty. If this is a nested out-of-flow
// frame, then it will also mark any outer frames to ensure that building
// reaches the dirty feame.
if (!dirty.IsEmpty() || aFrame->ForceDescendIntoIfVisible()) {
MarkFrameForDisplay(aFrame, aDirtyFrame);
}
return true;
}
static void UnmarkFrameForDisplay(nsIFrame* aFrame,
const nsIFrame* aStopAtFrame) {
for (nsIFrame* f = aFrame; f;
f = nsLayoutUtils::GetParentOrPlaceholderForCrossDoc(f)) {
if (!(f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)) {
return;
}
f->RemoveStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
if (f == aStopAtFrame) {
// we've reached a frame that we know will be painted, so we can stop.
break;
}
}
}
static void UnmarkFrameForDisplayIfVisible(nsIFrame* aFrame) {
for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetDisplayListParent(f)) {
if (!f->ForceDescendIntoIfVisible()) {
return;
}
f->SetForceDescendIntoIfVisible(false);
}
}
nsDisplayListBuilder::~nsDisplayListBuilder() {
NS_ASSERTION(mFramesMarkedForDisplay.Length() == 0,
"All frames should have been unmarked");
NS_ASSERTION(mFramesWithOOFData.Length() == 0,
"All OOF data should have been removed");
NS_ASSERTION(mPresShellStates.Length() == 0,
"All presshells should have been exited");
DisplayItemClipChain* c = mFirstClipChainToDestroy;
while (c) {
DisplayItemClipChain* next = c->mNextClipChainToDestroy;
c->DisplayItemClipChain::~DisplayItemClipChain();
c = next;
}
MOZ_COUNT_DTOR(nsDisplayListBuilder);
}
uint32_t nsDisplayListBuilder::GetBackgroundPaintFlags() {
uint32_t flags = 0;
if (mSyncDecodeImages) {
flags |= nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES;
}
if (mIsPaintingToWindow) {
flags |= nsCSSRendering::PAINTBG_TO_WINDOW;
}
return flags;
}
uint32_t nsDisplayListBuilder::GetImageDecodeFlags() const {
uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
if (mSyncDecodeImages) {
flags |= imgIContainer::FLAG_SYNC_DECODE;
} else {
flags |= imgIContainer::FLAG_SYNC_DECODE_IF_FAST;
}
if (mIsPaintingToWindow) {
flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
}
return flags;
}
void nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion,
const nsRegion& aRegion) {
if (aRegion.IsEmpty()) {
return;
}
nsRegion tmp;
tmp.Sub(*aVisibleRegion, aRegion);
// Don't let *aVisibleRegion get too complex, but don't let it fluff out
// to its bounds either, which can be very bad (see bug 516740).
// Do let aVisibleRegion get more complex if by doing so we reduce its
// area by at least half.
if (GetAccurateVisibleRegions() || tmp.GetNumRects() <= 15 ||
tmp.Area() <= aVisibleRegion->Area() / 2) {
*aVisibleRegion = tmp;
}
}
nsCaret* nsDisplayListBuilder::GetCaret() {
RefPtr<nsCaret> caret = CurrentPresShellState()->mPresShell->GetCaret();
return caret;
}
void nsDisplayListBuilder::IncrementPresShellPaintCount(PresShell* aPresShell) {
if (mIsPaintingToWindow) {
mReferenceFrame->AddPaintedPresShell(aPresShell);
aPresShell->IncrementPaintCount();
}
}
void nsDisplayListBuilder::EnterPresShell(const nsIFrame* aReferenceFrame,
bool aPointerEventsNoneDoc) {
PresShellState* state = mPresShellStates.AppendElement();
state->mPresShell = aReferenceFrame->PresShell();
state->mFirstFrameMarkedForDisplay = mFramesMarkedForDisplay.Length();
state->mFirstFrameWithOOFData = mFramesWithOOFData.Length();
nsIScrollableFrame* sf = state->mPresShell->GetRootScrollFrameAsScrollable();
if (sf && IsInSubdocument()) {
// We are forcing a rebuild of nsDisplayCanvasBackgroundColor to make sure
// that the canvas background color will be set correctly, and that only one
// unscrollable item will be created.
// This is done to avoid, for example, a case where only scrollbar frames
// are invalidated - we would skip creating nsDisplayCanvasBackgroundColor
// and possibly end up with an extra nsDisplaySolidColor item.
// We skip this for the root document, since we don't want to use
// MarkFrameForDisplayIfVisible before ComputeRebuildRegion. We'll
// do it manually there.
nsCanvasFrame* canvasFrame = do_QueryFrame(sf->GetScrolledFrame());
if (canvasFrame) {
MarkFrameForDisplayIfVisible(canvasFrame, aReferenceFrame);
}
}
#ifdef DEBUG
state->mAutoLayoutPhase.emplace(aReferenceFrame->PresContext(),
nsLayoutPhase::DisplayListBuilding);
#endif
state->mPresShell->UpdateCanvasBackground();
bool buildCaret = mBuildCaret;
if (mIgnoreSuppression || !state->mPresShell->IsPaintingSuppressed()) {
state->mIsBackgroundOnly = false;
} else {
state->mIsBackgroundOnly = true;
buildCaret = false;
}
bool pointerEventsNone = aPointerEventsNoneDoc;
if (IsInSubdocument()) {
pointerEventsNone |= mPresShellStates[mPresShellStates.Length() - 2]
.mInsidePointerEventsNoneDoc;
}
state->mInsidePointerEventsNoneDoc = pointerEventsNone;
state->mPresShellIgnoreScrollFrame =
state->mPresShell->IgnoringViewportScrolling()
? state->mPresShell->GetRootScrollFrame()
: nullptr;
nsPresContext* pc = aReferenceFrame->PresContext();
mIsInChromePresContext = pc->IsChrome();
nsIDocShell* docShell = pc->GetDocShell();
if (docShell) {
docShell->GetWindowDraggingAllowed(&mWindowDraggingAllowed);
}
state->mTouchEventPrefEnabledDoc = dom::TouchEvent::PrefEnabled(docShell);
if (!buildCaret) {
return;
}
// Caret frames add visual area to their frame, but we don't update the
// overflow area. Use flags to make sure we build display items for that frame
// instead.
if (mCaretFrame && mCaretFrame->PresShell() == state->mPresShell) {
MarkFrameForDisplay(mCaretFrame, aReferenceFrame);
}
}
// A non-blank paint is a paint that does not just contain the canvas
// background.
static bool DisplayListIsNonBlank(nsDisplayList* aList) {
for (nsDisplayItem* i : *aList) {
switch (i->GetType()) {
case DisplayItemType::TYPE_COMPOSITOR_HITTEST_INFO:
case DisplayItemType::TYPE_CANVAS_BACKGROUND_COLOR:
case DisplayItemType::TYPE_CANVAS_BACKGROUND_IMAGE:
continue;
case DisplayItemType::TYPE_SOLID_COLOR:
case DisplayItemType::TYPE_BACKGROUND:
case DisplayItemType::TYPE_BACKGROUND_COLOR:
if (i->Frame()->IsCanvasFrame()) {
continue;
}
return true;
default:
return true;
}
}
return false;
}
// A contentful paint is a paint that does contains DOM content (text,
// images, non-blank canvases, SVG): "First Contentful Paint entry
// contains a DOMHighResTimeStamp reporting the time when the browser
// first rendered any text, image (including background images),
// non-white canvas or SVG. This excludes any content of iframes, but
// includes text with pending webfonts. This is the first time users
// could start consuming page content."
static bool DisplayListIsContentful(nsDisplayList* aList) {
for (nsDisplayItem* i : *aList) {
DisplayItemType type = i->GetType();
nsDisplayList* children = i->GetChildren();
switch (type) {
case DisplayItemType::TYPE_SUBDOCUMENT: // iframes are ignored
break;
// CANVASes check if they may have been modified (as a stand-in
// actually tracking all modifications)
default:
if (i->IsContentful()) {
return true;
}
if (children) {
if (DisplayListIsContentful(children)) {
return true;
}
}
break;
}
}
return false;
}
void nsDisplayListBuilder::LeavePresShell(const nsIFrame* aReferenceFrame,
nsDisplayList* aPaintedContents) {
NS_ASSERTION(
CurrentPresShellState()->mPresShell == aReferenceFrame->PresShell(),
"Presshell mismatch");
if (mIsPaintingToWindow && aPaintedContents) {
nsPresContext* pc = aReferenceFrame->PresContext();
if (!pc->HadNonBlankPaint()) {
if (!CurrentPresShellState()->mIsBackgroundOnly &&
DisplayListIsNonBlank(aPaintedContents)) {
pc->NotifyNonBlankPaint();
}
}
if (!pc->HadContentfulPaint()) {
if (!CurrentPresShellState()->mIsBackgroundOnly &&
DisplayListIsContentful(aPaintedContents)) {
pc->NotifyContentfulPaint();
}
}
}
ResetMarkedFramesForDisplayList(aReferenceFrame);
mPresShellStates.RemoveLastElement();
if (!mPresShellStates.IsEmpty()) {
nsPresContext* pc = CurrentPresContext();
nsIDocShell* docShell = pc->GetDocShell();
if (docShell) {
docShell->GetWindowDraggingAllowed(&mWindowDraggingAllowed);
}
mIsInChromePresContext = pc->IsChrome();
} else {
mCurrentAGR = mRootAGR;
for (uint32_t i = 0; i < mFramesMarkedForDisplayIfVisible.Length(); ++i) {
UnmarkFrameForDisplayIfVisible(mFramesMarkedForDisplayIfVisible[i]);
}
mFramesMarkedForDisplayIfVisible.SetLength(0);
}
}
void nsDisplayListBuilder::FreeClipChains() {
// Iterate the clip chains from newest to oldest (forward
// iteration), so that we destroy descendants first which
// will drop the ref count on their ancestors.
DisplayItemClipChain** indirect = &mFirstClipChainToDestroy;
while (*indirect) {
if (!(*indirect)->mRefCount) {
DisplayItemClipChain* next = (*indirect)->mNextClipChainToDestroy;
mClipDeduplicator.erase(*indirect);
(*indirect)->DisplayItemClipChain::~DisplayItemClipChain();
Destroy(DisplayListArenaObjectId::CLIPCHAIN, *indirect);
*indirect = next;
} else {
indirect = &(*indirect)->mNextClipChainToDestroy;
}
}
}
void nsDisplayListBuilder::FreeTemporaryItems() {
for (nsDisplayItem* i : mTemporaryItems) {
// Temporary display items are not added to the frames.
MOZ_ASSERT(i->Frame());
i->RemoveFrame(i->Frame());
i->Destroy(this);
}
mTemporaryItems.Clear();
}
void nsDisplayListBuilder::ResetMarkedFramesForDisplayList(
const nsIFrame* aReferenceFrame) {
// Unmark and pop off the frames marked for display in this pres shell.
uint32_t firstFrameForShell =
CurrentPresShellState()->mFirstFrameMarkedForDisplay;
for (uint32_t i = firstFrameForShell; i < mFramesMarkedForDisplay.Length();
++i) {
UnmarkFrameForDisplay(mFramesMarkedForDisplay[i], aReferenceFrame);
}
mFramesMarkedForDisplay.SetLength(firstFrameForShell);
firstFrameForShell = CurrentPresShellState()->mFirstFrameWithOOFData;
for (uint32_t i = firstFrameForShell; i < mFramesWithOOFData.Length(); ++i) {
mFramesWithOOFData[i]->RemoveProperty(OutOfFlowDisplayDataProperty());
}
mFramesWithOOFData.SetLength(firstFrameForShell);
}
void nsDisplayListBuilder::ClearFixedBackgroundDisplayData() {
CurrentPresShellState()->mFixedBackgroundDisplayData = Nothing();
}
void nsDisplayListBuilder::MarkFramesForDisplayList(
nsIFrame* aDirtyFrame, const nsFrameList& aFrames) {
nsRect visibleRect = GetVisibleRect();
nsRect dirtyRect = GetDirtyRect();
// If we are entering content that is fixed to the RCD-RSF, we are
// crossing the async zoom container boundary, and need to convert from
// visual to layout coordinates.
if (ViewportFrame* viewportFrame = do_QueryFrame(aDirtyFrame)) {
if (IsForEventDelivery() && ShouldBuildAsyncZoomContainer() &&
viewportFrame->PresContext()->IsRootContentDocumentCrossProcess()) {
if (viewportFrame->PresShell()->GetRootScrollFrame()) {
#ifdef DEBUG
for (nsIFrame* f : aFrames) {
MOZ_ASSERT(ViewportUtils::IsZoomedContentRoot(f));
}
#endif
visibleRect = ViewportUtils::VisualToLayout(visibleRect,
viewportFrame->PresShell());
dirtyRect = ViewportUtils::VisualToLayout(dirtyRect,
viewportFrame->PresShell());
}
#ifdef DEBUG
else {
// This is an edge case that should only happen if we are in a
// document with a XUL root element so that it does not have a root
// scroll frame but it has fixed pos content and all of the frames in
// aFrames are that fixed pos content.
for (nsIFrame* f : aFrames) {
MOZ_ASSERT(!ViewportUtils::IsZoomedContentRoot(f) &&
f->GetParent() == aDirtyFrame &&
f->StyleDisplay()->mPosition ==
StylePositionProperty::Fixed);
}
// There's no root scroll frame so there can't be any zooming or async
// panning so we don't need to adjust the visible and dirty rects.
}
#endif
}
}
bool markedFrames = false;
for (nsIFrame* e : aFrames) {
// Skip the AccessibleCaret frame when building no caret.
if (!IsBuildingCaret()) {
nsIContent* content = e->GetContent();
if (content && content->IsInNativeAnonymousSubtree() &&
content->IsElement()) {
auto classList = content->AsElement()->ClassList();
if (classList->Contains(NS_LITERAL_STRING("moz-accessiblecaret"))) {
continue;
}
}
}
if (MarkOutOfFlowFrameForDisplay(aDirtyFrame, e, visibleRect, dirtyRect)) {
markedFrames = true;
}
}
if (markedFrames) {
// mClipState.GetClipChainForContainingBlockDescendants can return pointers
// to objects on the stack, so we need to clone the chain.
const DisplayItemClipChain* clipChain =
CopyWholeChain(mClipState.GetClipChainForContainingBlockDescendants());
const DisplayItemClipChain* combinedClipChain =
mClipState.GetCurrentCombinedClipChain(this);
const ActiveScrolledRoot* asr = mCurrentActiveScrolledRoot;
OutOfFlowDisplayData* data = new OutOfFlowDisplayData(
clipChain, combinedClipChain, asr, visibleRect, dirtyRect);
aDirtyFrame->SetProperty(
nsDisplayListBuilder::OutOfFlowDisplayDataProperty(), data);
mFramesWithOOFData.AppendElement(aDirtyFrame);
}
if (!aDirtyFrame->GetParent()) {
// This is the viewport frame of aDirtyFrame's presshell.
// Store the current display data so that it can be used for fixed
// background images.
NS_ASSERTION(
CurrentPresShellState()->mPresShell == aDirtyFrame->PresShell(),
"Presshell mismatch");
MOZ_ASSERT(!CurrentPresShellState()->mFixedBackgroundDisplayData,
"already traversed this presshell's root frame?");
const DisplayItemClipChain* clipChain =
CopyWholeChain(mClipState.GetClipChainForContainingBlockDescendants());
const DisplayItemClipChain* combinedClipChain =
mClipState.GetCurrentCombinedClipChain(this);
const ActiveScrolledRoot* asr = mCurrentActiveScrolledRoot;
CurrentPresShellState()->mFixedBackgroundDisplayData.emplace(
clipChain, combinedClipChain, asr, GetVisibleRect(), GetDirtyRect());
}
}
/**
* Mark all preserve-3d children with
* NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO to make sure
* nsFrame::BuildDisplayListForChild() would visit them. Also compute
* dirty rect for preserve-3d children.
*
* @param aDirtyFrame is the frame to mark children extending context.
*/
void nsDisplayListBuilder::MarkPreserve3DFramesForDisplayList(
nsIFrame* aDirtyFrame) {
for (const auto& childList : aDirtyFrame->ChildLists()) {
for (nsIFrame* child : childList.mList) {
if (child->Combines3DTransformWithAncestors()) {
MarkFrameForDisplay(child, aDirtyFrame);
}
if (child->IsBlockWrapper()) {
// Mark preserve-3d frames inside the block wrapper.
MarkPreserve3DFramesForDisplayList(child);
}
}
}
}
ActiveScrolledRoot* nsDisplayListBuilder::AllocateActiveScrolledRoot(
const ActiveScrolledRoot* aParent, nsIScrollableFrame* aScrollableFrame) {
RefPtr<ActiveScrolledRoot> asr = ActiveScrolledRoot::CreateASRForFrame(
aParent, aScrollableFrame, IsRetainingDisplayList());
mActiveScrolledRoots.AppendElement(asr);
return asr;
}
const DisplayItemClipChain* nsDisplayListBuilder::AllocateDisplayItemClipChain(
const DisplayItemClip& aClip, const ActiveScrolledRoot* aASR,
const DisplayItemClipChain* aParent) {
MOZ_ASSERT(!(aParent && aParent->mOnStack));
void* p = Allocate(sizeof(DisplayItemClipChain),
DisplayListArenaObjectId::CLIPCHAIN);
DisplayItemClipChain* c = new (KnownNotNull, p)
DisplayItemClipChain(aClip, aASR, aParent, mFirstClipChainToDestroy);
#ifdef DEBUG
c->mOnStack = false;
#endif
auto result = mClipDeduplicator.insert(c);
if (!result.second) {
// An equivalent clip chain item was already created, so let's return that
// instead. Destroy the one we just created.
// Note that this can cause clip chains from different coordinate systems to
// collapse into the same clip chain object, because clip chains do not keep
// track of the reference frame that they were created in.
c->DisplayItemClipChain::~DisplayItemClipChain();
Destroy(DisplayListArenaObjectId::CLIPCHAIN, c);
return *(result.first);
}
mFirstClipChainToDestroy = c;
return c;
}
struct ClipChainItem {
DisplayItemClip clip;
const ActiveScrolledRoot* asr;
};
const DisplayItemClipChain* nsDisplayListBuilder::CreateClipChainIntersection(
const DisplayItemClipChain* aAncestor,
const DisplayItemClipChain* aLeafClip1,
const DisplayItemClipChain* aLeafClip2) {
AutoTArray<ClipChainItem, 8> intersectedClips;
const DisplayItemClipChain* clip1 = aLeafClip1;
const DisplayItemClipChain* clip2 = aLeafClip2;
const ActiveScrolledRoot* asr = ActiveScrolledRoot::PickDescendant(
clip1 ? clip1->mASR : nullptr, clip2 ? clip2->mASR : nullptr);
// Build up the intersection from the leaf to the root and put it into
// intersectedClips. The loop below will convert intersectedClips into an
// actual DisplayItemClipChain.
// (We need to do this in two passes because we need the parent clip in order
// to create the DisplayItemClipChain object, but the parent clip has not
// been created at that point.)
while (!aAncestor || asr != aAncestor->mASR) {
if (clip1 && clip1->mASR == asr) {
if (clip2 && clip2->mASR == asr) {
DisplayItemClip intersection = clip1->mClip;
intersection.IntersectWith(clip2->mClip);
intersectedClips.AppendElement(ClipChainItem{intersection, asr});
clip2 = clip2->mParent;
} else {
intersectedClips.AppendElement(ClipChainItem{clip1->mClip, asr});
}
clip1 = clip1->mParent;
} else if (clip2 && clip2->mASR == asr) {
intersectedClips.AppendElement(ClipChainItem{clip2->mClip, asr});
clip2 = clip2->mParent;
}
if (!asr) {
MOZ_ASSERT(!aAncestor, "We should have exited this loop earlier");
break;
}
asr = asr->mParent;
}
// Convert intersectedClips into a DisplayItemClipChain.
const DisplayItemClipChain* parentSC = aAncestor;
for (auto& sc : Reversed(intersectedClips)) {
parentSC = AllocateDisplayItemClipChain(sc.clip, sc.asr, parentSC);
}
return parentSC;
}
const DisplayItemClipChain* nsDisplayListBuilder::CopyWholeChain(
const DisplayItemClipChain* aClipChain) {
return CreateClipChainIntersection(nullptr, aClipChain, nullptr);
}
const DisplayItemClipChain* nsDisplayListBuilder::FuseClipChainUpTo(
const DisplayItemClipChain* aClipChain, const ActiveScrolledRoot* aASR) {
if (!aClipChain) {
return nullptr;
}
const DisplayItemClipChain* sc = aClipChain;
DisplayItemClip mergedClip;
while (sc && ActiveScrolledRoot::PickDescendant(aASR, sc->mASR) == sc->mASR) {
mergedClip.IntersectWith(sc->mClip);
sc = sc->mParent;
}
if (!mergedClip.HasClip()) {
return nullptr;
}
return AllocateDisplayItemClipChain(mergedClip, aASR, sc);
}
const nsIFrame* nsDisplayListBuilder::FindReferenceFrameFor(
const nsIFrame* aFrame, nsPoint* aOffset) const {
if (aFrame == mCurrentFrame) {
if (aOffset) {
*aOffset = mCurrentOffsetToReferenceFrame;
}
return mCurrentReferenceFrame;
}
for (const nsIFrame* f = aFrame; f;
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
if (f == mReferenceFrame || f->IsTransformed()) {
if (aOffset) {
*aOffset = aFrame->GetOffsetToCrossDoc(f);
}
return f;
}
}
if (aOffset) {
*aOffset = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
}
return mReferenceFrame;
}
// Sticky frames are active if their nearest scrollable frame is also active.
static bool IsStickyFrameActive(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame, nsIFrame* aParent) {
MOZ_ASSERT(aFrame->StyleDisplay()->mPosition ==
StylePositionProperty::Sticky);
// Find the nearest scrollframe.
nsIScrollableFrame* sf = nsLayoutUtils::GetNearestScrollableFrame(
aFrame->GetParent(), nsLayoutUtils::SCROLLABLE_SAME_DOC |
nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
if (!sf) {
return false;
}
return sf->IsScrollingActive(aBuilder);
}
nsDisplayListBuilder::AGRState nsDisplayListBuilder::IsAnimatedGeometryRoot(
nsIFrame* aFrame, bool& aIsAsync, nsIFrame** aParent) {
// We can return once we know that this frame is an AGR, and we're either
// async, or sure that none of the later conditions might make us async.
// The exception to this is when IsPaintingToWindow() == false.
aIsAsync = false;
if (aFrame == mReferenceFrame) {
aIsAsync = true;
return AGR_YES;
}
if (!IsPaintingToWindow()) {
if (aParent) {
*aParent = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
}
return AGR_NO;
}
nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
if (!parent) {
aIsAsync = true;
return AGR_YES;
}
if (aFrame->StyleDisplay()->mPosition == StylePositionProperty::Sticky &&
IsStickyFrameActive(this, aFrame, parent)) {
aIsAsync = true;
return AGR_YES;
}
if (aFrame->IsTransformed()) {
aIsAsync = EffectCompositor::HasAnimationsForCompositor(
aFrame, DisplayItemType::TYPE_TRANSFORM);
return AGR_YES;
}
LayoutFrameType parentType = parent->Type();
if (parentType == LayoutFrameType::Scroll ||
parentType == LayoutFrameType::ListControl) {
nsIScrollableFrame* sf = do_QueryFrame(parent);
if (sf->GetScrolledFrame() == aFrame && sf->IsScrollingActive(this)) {
MOZ_ASSERT(!aFrame->IsTransformed());
aIsAsync = sf->IsMaybeAsynchronouslyScrolled();
return AGR_YES;
}
}
// Treat the slider thumb as being as an active scrolled root when it wants
// its own layer so that it can move without repainting.
if (parentType == LayoutFrameType::Slider) {
auto* sf = static_cast<nsSliderFrame*>(parent)->GetScrollFrame();
// The word "Maybe" in IsMaybeScrollingActive might be confusing but we do
// indeed need to always consider scroll thumbs as AGRs if
// IsMaybeScrollingActive is true because that is the same condition we use
// in ScrollFrameHelper::AppendScrollPartsTo to layerize scroll thumbs.
if (sf && sf->IsMaybeScrollingActive()) {
return AGR_YES;
}
}
if (nsLayoutUtils::IsPopup(aFrame)) {
return AGR_YES;
}
if (ActiveLayerTracker::IsOffsetStyleAnimated(aFrame)) {
const bool inBudget = AddToAGRBudget(aFrame);
if (inBudget) {
return AGR_YES;
}
}
if (!aFrame->GetParent() &&
nsLayoutUtils::ViewportHasDisplayPort(aFrame->PresContext())) {
// Viewport frames in a display port need to be animated geometry roots
// for background-attachment:fixed elements.
return AGR_YES;
}
// Fixed-pos frames are parented by the viewport frame, which has no parent.
if (nsLayoutUtils::IsFixedPosFrameInDisplayPort(aFrame)) {
return AGR_YES;
}
if (aParent) {
*aParent = parent;
}
return AGR_NO;
}
nsIFrame* nsDisplayListBuilder::FindAnimatedGeometryRootFrameFor(
nsIFrame* aFrame, bool& aIsAsync) {
MOZ_ASSERT(
nsLayoutUtils::IsAncestorFrameCrossDoc(RootReferenceFrame(), aFrame));
nsIFrame* cursor = aFrame;
while (cursor != RootReferenceFrame()) {
nsIFrame* next;
if (IsAnimatedGeometryRoot(cursor, aIsAsync, &next) == AGR_YES) {
return cursor;
}
cursor = next;
}
// Root frame is always an async agr.
aIsAsync = true;
return cursor;
}
void nsDisplayListBuilder::RecomputeCurrentAnimatedGeometryRoot() {
bool isAsync;
if (*mCurrentAGR != mCurrentFrame &&
IsAnimatedGeometryRoot(const_cast<nsIFrame*>(mCurrentFrame), isAsync) ==
AGR_YES) {
AnimatedGeometryRoot* oldAGR = mCurrentAGR;
mCurrentAGR = WrapAGRForFrame(const_cast<nsIFrame*>(mCurrentFrame), isAsync,
mCurrentAGR);
// Iterate the AGR cache and look for any objects that reference the old AGR
// and check to see if they need to be updated. AGRs can be in the cache
// multiple times, so we may end up doing the work multiple times for AGRs
// that don't change.
for (auto iter = mFrameToAnimatedGeometryRootMap.Iter(); !iter.Done();
iter.Next()) {
RefPtr<AnimatedGeometryRoot> cached = iter.UserData();
if (cached->mParentAGR == oldAGR && cached != mCurrentAGR) {
// It's possible that this cached AGR struct that has the old AGR as a
// parent should instead have mCurrentFrame has a parent.
nsIFrame* parent = FindAnimatedGeometryRootFrameFor(*cached, isAsync);
MOZ_ASSERT(parent == mCurrentFrame || parent == *oldAGR);
if (parent == mCurrentFrame) {
cached->mParentAGR = mCurrentAGR;
}
}
}
}
}
static nsRect ApplyAllClipNonRoundedIntersection(
const DisplayItemClipChain* aClipChain, const nsRect& aRect) {
nsRect result = aRect;
while (aClipChain) {
result = aClipChain->mClip.ApplyNonRoundedIntersection(result);
aClipChain = aClipChain->mParent;
}
return result;
}
void nsDisplayListBuilder::AdjustWindowDraggingRegion(nsIFrame* aFrame) {
if (!mWindowDraggingAllowed || !IsForPainting()) {
return;
}
const nsStyleUIReset* styleUI = aFrame->StyleUIReset();
if (styleUI->mWindowDragging == StyleWindowDragging::Default) {
// This frame has the default value and doesn't influence the window
// dragging region.
return;
}
LayoutDeviceToLayoutDeviceMatrix4x4 referenceFrameToRootReferenceFrame;
// The const_cast is for nsLayoutUtils::GetTransformToAncestor.
nsIFrame* referenceFrame =
const_cast<nsIFrame*>(FindReferenceFrameFor(aFrame));
if (IsInTransform()) {
// Only support 2d rectilinear transforms. Transform support is needed for
// the horizontal flip transform that's applied to the urlbar textbox in
// RTL mode - it should be able to exclude itself from the draggable region.
referenceFrameToRootReferenceFrame =
ViewAs<LayoutDeviceToLayoutDeviceMatrix4x4>(
nsLayoutUtils::GetTransformToAncestor(RelativeTo{referenceFrame},
RelativeTo{mReferenceFrame})
.GetMatrix());
Matrix referenceFrameToRootReferenceFrame2d;
if (!referenceFrameToRootReferenceFrame.Is2D(
&referenceFrameToRootReferenceFrame2d) ||
!referenceFrameToRootReferenceFrame2d.IsRectilinear()) {
return;
}
} else {
MOZ_ASSERT(referenceFrame == mReferenceFrame,
"referenceFrameToRootReferenceFrame needs to be adjusted");
}
// We do some basic visibility checking on the frame's border box here.
// We intersect it both with the current dirty rect and with the current
// clip. Either one is just a conservative approximation on its own, but
// their intersection luckily works well enough for our purposes, so that
// we don't have to do full-blown visibility computations.
// The most important case we need to handle is the scrolled-off tab:
// If the tab bar overflows, tab parts that are clipped by the scrollbox
// should not be allowed to interfere with the window dragging region. Using
// just the current DisplayItemClip is not enough to cover this case
// completely because clips are reset while building stacking context
// contents, so for example we'd fail to clip frames that have a clip path
// applied to them. But the current dirty rect doesn't get reset in that
// case, so we use it to make this case work.
nsRect borderBox = aFrame->GetRectRelativeToSelf().Intersect(mVisibleRect);
borderBox += ToReferenceFrame(aFrame);
const DisplayItemClipChain* clip =
ClipState().GetCurrentCombinedClipChain(this);
borderBox = ApplyAllClipNonRoundedIntersection(clip, borderBox);
if (borderBox.IsEmpty()) {
return;
}
LayoutDeviceRect devPixelBorderBox = LayoutDevicePixel::FromAppUnits(
borderBox, aFrame->PresContext()->AppUnitsPerDevPixel());
LayoutDeviceRect transformedDevPixelBorderBox =
TransformBy(referenceFrameToRootReferenceFrame, devPixelBorderBox);
transformedDevPixelBorderBox.Round();
LayoutDeviceIntRect transformedDevPixelBorderBoxInt;
if (!transformedDevPixelBorderBox.ToIntRect(
&transformedDevPixelBorderBoxInt)) {
return;
}
LayoutDeviceIntRegion& region =
styleUI->mWindowDragging == StyleWindowDragging::Drag
? mWindowDraggingRegion
: mWindowNoDraggingRegion;
if (!IsRetainingDisplayList()) {
region.OrWith(transformedDevPixelBorderBoxInt);
return;
}
mozilla::gfx::IntRect rect(transformedDevPixelBorderBoxInt.ToUnknownRect());
if (styleUI->mWindowDragging == StyleWindowDragging::Drag) {
mRetainedWindowDraggingRegion.Add(aFrame, rect);
} else {
mRetainedWindowNoDraggingRegion.Add(aFrame, rect);
}
}
LayoutDeviceIntRegion nsDisplayListBuilder::GetWindowDraggingRegion() const {
LayoutDeviceIntRegion result;
if (!IsRetainingDisplayList()) {
result.Sub(mWindowDraggingRegion, mWindowNoDraggingRegion);
return result;
}
LayoutDeviceIntRegion dragRegion =
mRetainedWindowDraggingRegion.ToLayoutDeviceIntRegion();
LayoutDeviceIntRegion noDragRegion =
mRetainedWindowNoDraggingRegion.ToLayoutDeviceIntRegion();
result.Sub(dragRegion, noDragRegion);
return result;
}
void nsDisplayHitTestInfoBase::AddSizeOfExcludingThis(
nsWindowSizes& aSizes) const {
nsPaintedDisplayItem::AddSizeOfExcludingThis(aSizes);
aSizes.mLayoutRetainedDisplayListSize +=
aSizes.mState.mMallocSizeOf(mHitTestInfo.get());
}
void nsDisplayTransform::AddSizeOfExcludingThis(nsWindowSizes& aSizes) const {
nsDisplayHitTestInfoBase::AddSizeOfExcludingThis(aSizes);
aSizes.mLayoutRetainedDisplayListSize +=
aSizes.mState.mMallocSizeOf(mTransformPreserves3D.get());
}
void nsDisplayListBuilder::AddSizeOfExcludingThis(nsWindowSizes& aSizes) const {
mPool.AddSizeOfExcludingThis(aSizes, Arena::ArenaKind::DisplayList);
size_t n = 0;
MallocSizeOf mallocSizeOf = aSizes.mState.mMallocSizeOf;
n += mDocumentWillChangeBudgets.ShallowSizeOfExcludingThis(mallocSizeOf);
n += mFrameWillChangeBudgets.ShallowSizeOfExcludingThis(mallocSizeOf);
n += mAGRBudgetSet.ShallowSizeOfExcludingThis(mallocSizeOf);
n += mEffectsUpdates.ShallowSizeOfExcludingThis(mallocSizeOf);
n += mWindowExcludeGlassRegion.SizeOfExcludingThis(mallocSizeOf);
n += mRetainedWindowDraggingRegion.SizeOfExcludingThis(mallocSizeOf);
n += mRetainedWindowNoDraggingRegion.SizeOfExcludingThis(mallocSizeOf);
n += mRetainedWindowOpaqueRegion.SizeOfExcludingThis(mallocSizeOf);
// XXX can't measure mClipDeduplicator since it uses std::unordered_set.
aSizes.mLayoutRetainedDisplayListSize += n;
}
void RetainedDisplayList::AddSizeOfExcludingThis(nsWindowSizes& aSizes) const {
for (nsDisplayItem* item : *this) {
item->AddSizeOfExcludingThis(aSizes);
if (RetainedDisplayList* children = item->GetChildren()) {
children->AddSizeOfExcludingThis(aSizes);
}
}
size_t n = 0;
n += mDAG.mDirectPredecessorList.ShallowSizeOfExcludingThis(
aSizes.mState.mMallocSizeOf);
n += mDAG.mNodesInfo.ShallowSizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
n += mOldItems.ShallowSizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
aSizes.mLayoutRetainedDisplayListSize += n;
}
size_t nsDisplayListBuilder::WeakFrameRegion::SizeOfExcludingThis(
MallocSizeOf aMallocSizeOf) const {
size_t n = 0;
n += mFrames.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto& frame : mFrames) {
const UniquePtr<WeakFrame>& weakFrame = frame.mWeakFrame;
n += aMallocSizeOf(weakFrame.get());
}
n += mRects.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}
/**
* Removes modified frames and rects from this WeakFrameRegion.
*/
void nsDisplayListBuilder::WeakFrameRegion::RemoveModifiedFramesAndRects() {
MOZ_ASSERT(mFrames.Length() == mRects.Length());
uint32_t i = 0;
uint32_t length = mFrames.Length();
while (i < length) {
auto& wrapper = mFrames[i];
if (!wrapper.mWeakFrame->IsAlive() ||
AnyContentAncestorModified(wrapper.mWeakFrame->GetFrame())) {
// To avoid multiple O(n) shifts in the array, move the last element of
// the array to the current position and decrease the array length.
mFrameSet.RemoveEntry(wrapper.mFrame);
mFrames[i] = std::move(mFrames[length - 1]);
mRects[i] = std::move(mRects[length - 1]);
length--;
} else {
i++;
}
}
mFrames.TruncateLength(length);
mRects.TruncateLength(length);
}
void nsDisplayListBuilder::RemoveModifiedWindowRegions() {
mRetainedWindowDraggingRegion.RemoveModifiedFramesAndRects();
mRetainedWindowNoDraggingRegion.RemoveModifiedFramesAndRects();
mWindowExcludeGlassRegion.RemoveModifiedFramesAndRects();
mRetainedWindowOpaqueRegion.RemoveModifiedFramesAndRects();
mHasGlassItemDuringPartial = false;
}
void nsDisplayListBuilder::ClearRetainedWindowRegions() {
mRetainedWindowDraggingRegion.Clear();
mRetainedWindowNoDraggingRegion.Clear();
mWindowExcludeGlassRegion.Clear();
mRetainedWindowOpaqueRegion.Clear();
mGlassDisplayItem = nullptr;
}
const uint32_t gWillChangeAreaMultiplier = 3;
static uint32_t GetLayerizationCost(const nsSize& aSize) {
// There's significant overhead for each layer created from Gecko
// (IPC+Shared Objects) and from the backend (like an OpenGL texture).
// Therefore we set a minimum cost threshold of a 64x64 area.
const int minBudgetCost = 64 * 64;
const uint32_t budgetCost = std::max(
minBudgetCost, nsPresContext::AppUnitsToIntCSSPixels(aSize.width) *
nsPresContext::AppUnitsToIntCSSPixels(aSize.height));
return budgetCost;
}
bool nsDisplayListBuilder::AddToWillChangeBudget(nsIFrame* aFrame,
const nsSize& aSize) {
MOZ_ASSERT(IsForPainting());
if (aFrame->MayHaveWillChangeBudget()) {
// The frame is already in the will-change budget.
return true;
}
const nsPresContext* presContext = aFrame->PresContext();
const nsRect area = presContext->GetVisibleArea();
const uint32_t budgetLimit =
nsPresContext::AppUnitsToIntCSSPixels(area.width) *
nsPresContext::AppUnitsToIntCSSPixels(area.height);
const uint32_t cost = GetLayerizationCost(aSize);
DocumentWillChangeBudget& documentBudget =
mDocumentWillChangeBudgets.GetOrInsert(presContext);
const bool onBudget =
(documentBudget + cost) / gWillChangeAreaMultiplier < budgetLimit;
if (onBudget) {
documentBudget += cost;
mFrameWillChangeBudgets.Put(aFrame,
FrameWillChangeBudget(presContext, cost));
aFrame->SetMayHaveWillChangeBudget(true);
}
return onBudget;
}
bool nsDisplayListBuilder::IsInWillChangeBudget(nsIFrame* aFrame,
const nsSize& aSize) {
if (!IsForPainting()) {
// If this nsDisplayListBuilder is not for painting, the layerization should
// not matter. Do the simple thing and return false.
return false;
}
const bool onBudget = AddToWillChangeBudget(aFrame, aSize);
if (onBudget) {
return true;
}
auto* pc = aFrame->PresContext();
auto* doc = pc->Document();
if (!doc->HasWarnedAbout(Document::eIgnoringWillChangeOverBudget)) {
AutoTArray<nsString, 2> params;
params.AppendElement()->AppendInt(gWillChangeAreaMultiplier);
nsRect area = pc->GetVisibleArea();
uint32_t budgetLimit = nsPresContext::AppUnitsToIntCSSPixels(area.width) *
nsPresContext::AppUnitsToIntCSSPixels(area.height);
params.AppendElement()->AppendInt(budgetLimit);
doc->WarnOnceAbout(Document::eIgnoringWillChangeOverBudget, false, params);
}
return false;
}
void nsDisplayListBuilder::ClearWillChangeBudgetStatus(nsIFrame* aFrame) {
MOZ_ASSERT(IsForPainting());
if (!aFrame->MayHaveWillChangeBudget()) {
return;
}
aFrame->SetMayHaveWillChangeBudget(false);
RemoveFromWillChangeBudgets(aFrame);
}
void nsDisplayListBuilder::RemoveFromWillChangeBudgets(const nsIFrame* aFrame) {
if (auto entry = mFrameWillChangeBudgets.Lookup(aFrame)) {
const FrameWillChangeBudget& frameBudget = entry.Data();
DocumentWillChangeBudget* documentBudget =
mDocumentWillChangeBudgets.GetValue(frameBudget.mPresContext);
if (documentBudget) {
*documentBudget -= frameBudget.mUsage;
}
entry.Remove();
}
}
void nsDisplayListBuilder::ClearWillChangeBudgets() {
mFrameWillChangeBudgets.Clear();
mDocumentWillChangeBudgets.Clear();
}
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
const float gAGRBudgetAreaMultiplier = 0.3;
#else
const float gAGRBudgetAreaMultiplier = 3.0;
#endif
bool nsDisplayListBuilder::AddToAGRBudget(nsIFrame* aFrame) {
if (mAGRBudgetSet.Contains(aFrame)) {
return true;
}
const nsPresContext* presContext =
aFrame->PresContext()->GetRootPresContext();