Bug 1415013: Devirtualize PresShell::IsSafeToFlush. r?bz
MozReview-Commit-ID: BL5qcSFE6Hc
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -737,16 +737,17 @@ nsIPresShell::nsIPresShell()
#endif
#ifdef DEBUG
, mDrawEventTargetFrame(nullptr)
#endif
, mPaintCount(0)
, mAutoWeakFrames(nullptr)
, mCanvasBackgroundColor(NS_RGBA(0,0,0,0))
, mSelectionFlags(0)
+ , mChangeNestCount(0)
, mRenderFlags(0)
, mDidInitialize(false)
, mIsDestroying(false)
, mIsReflowing(false)
, mPaintingSuppressed(false)
, mIsActive(false)
, mFrozen(false)
, mIsFirstPaint(false)
@@ -782,17 +783,16 @@ PresShell::PresShell()
#endif
, mMouseLocation(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)
, mCurrentEventFrame(nullptr)
, mFirstCallbackEventRequest(nullptr)
, mLastCallbackEventRequest(nullptr)
, mLastReflowStart(0.0)
, mLastAnchorScrollPositionY(0)
, mAPZFocusSequenceNumber(0)
- , mChangeNestCount(0)
, mDocumentLoading(false)
, mIgnoreFrameDestruction(false)
, mHaveShutDown(false)
, mLastRootReflowHadUnconstrainedBSize(false)
, mNoDelayedMouseEvents(false)
, mNoDelayedKeyEvents(false)
, mIsDocumentGone(false)
, mShouldUnsuppressPainting(false)
@@ -4033,35 +4033,33 @@ PresShell::HandlePostedReflowCallbacks(b
FlushType flushType =
aInterruptible ? FlushType::InterruptibleLayout : FlushType::Layout;
if (shouldFlush && !mIsDestroying) {
FlushPendingNotifications(flushType);
}
}
bool
-PresShell::IsSafeToFlush() const
+nsIPresShell::IsSafeToFlush() const
{
// Not safe if we are reflowing or in the middle of frame construction
- bool isSafeToFlush = !mIsReflowing &&
- !mChangeNestCount;
-
- if (isSafeToFlush) {
+ if (mIsReflowing || mChangeNestCount) {
+ return false;
+ }
+
// Not safe if we are painting
- nsViewManager* viewManager = GetViewManager();
- if (viewManager) {
- bool isPainting = false;
- viewManager->IsPainting(isPainting);
- if (isPainting) {
- isSafeToFlush = false;
- }
- }
- }
-
- return isSafeToFlush;
+ if (nsViewManager* viewManager = GetViewManager()) {
+ bool isPainting = false;
+ viewManager->IsPainting(isPainting);
+ if (isPainting) {
+ return false;
+ }
+ }
+
+ return true;
}
void
PresShell::DoFlushPendingNotifications(FlushType aType)
{
// by default, flush animations if aType >= FlushType::Style
mozilla::ChangesToFlush flush(aType, aType >= FlushType::Style);
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -123,17 +123,16 @@ public:
virtual nsCanvasFrame* GetCanvasFrame() const override;
virtual void FrameNeedsReflow(nsIFrame *aFrame, IntrinsicDirty aIntrinsicDirty,
nsFrameState aBitToAdd,
ReflowRootHandling aRootHandling =
eInferFromBitToAdd) override;
virtual void FrameNeedsToContinueReflow(nsIFrame *aFrame) override;
virtual void CancelAllPendingReflows() override;
- virtual bool IsSafeToFlush() const override;
virtual void DoFlushPendingNotifications(mozilla::FlushType aType) override;
virtual void DoFlushPendingNotifications(mozilla::ChangesToFlush aType) override;
virtual void DestroyFramesForAndRestyle(mozilla::dom::Element* aElement) override;
/**
* Post a callback that should be handled after reflow has finished.
*/
virtual nsresult PostReflowCallback(nsIReflowCallback* aCallback) override;
@@ -852,21 +851,16 @@ protected:
// when target of pointer event was deleted during executing user handlers.
nsCOMPtr<nsIContent> mPointerEventTarget;
// The focus sequence number of the last processed input event
uint64_t mAPZFocusSequenceNumber;
// The focus information needed for async keyboard scrolling
FocusTarget mAPZFocusTarget;
- // This is used to protect ourselves from triggering reflow while in the
- // middle of frame construction and the like... it really shouldn't be
- // needed, one hopes, but it is for now.
- uint16_t mChangeNestCount;
-
bool mDocumentLoading : 1;
bool mIgnoreFrameDestruction : 1;
bool mHaveShutDown : 1;
bool mLastRootReflowHadUnconstrainedBSize : 1;
bool mNoDelayedMouseEvents : 1;
bool mNoDelayedKeyEvents : 1;
// We've been disconnected from the document. We will refuse to paint the
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -536,21 +536,19 @@ public:
nsRestyleHint aHint);
// ShadowRoot has APIs that can change styles so we only
// want to restyle elements in the ShadowRoot and not the whole
// document.
virtual void RecordShadowStyleChange(mozilla::dom::ShadowRoot* aShadowRoot) = 0;
/**
- * Determine if it is safe to flush all pending notifications
- * @param aIsSafeToFlush true if it is safe, false otherwise.
- *
+ * Determine if it is safe to flush all pending notifications.
*/
- virtual bool IsSafeToFlush() const = 0;
+ bool IsSafeToFlush() const;
/**
* Flush pending notifications of the type specified. This method
* will not affect the content model; it'll just affect style and
* frames. Callers that actually want up-to-date presentation (other
* than the document itself) should probably be calling
* nsIDocument::FlushPendingNotifications.
*
@@ -1703,16 +1701,21 @@ protected:
nscolor mCanvasBackgroundColor;
// Used to force allocation and rendering of proportionally more or
// less pixels in both dimensions.
mozilla::Maybe<float> mResolution;
int16_t mSelectionFlags;
+ // This is used to protect ourselves from triggering reflow while in the
+ // middle of frame construction and the like... it really shouldn't be
+ // needed, one hopes, but it is for now.
+ uint16_t mChangeNestCount;
+
// Flags controlling how our document is rendered. These persist
// between paints and so are tied with retained layer pixels.
// PresShell flushes retained layers when the rendering state
// changes in a way that prevents us from being able to (usefully)
// re-use old pixels.
RenderFlags mRenderFlags;
bool mDidInitialize : 1;
bool mIsDestroying : 1;