tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2e9b491a3c67b9167f52dc2910aa9d85d16e2a50
parent 1a24cc95a2574d8297929a84634e27a9990d0f75
Author: Ting-Yu Lin <tlin@mozilla.com>
Date:   Mon, 10 Nov 2025 19:59:26 +0000

Bug 1998869 - Improve noisy reflow log. r=layout-reviewers,dholbert

* At the beginning of `ReflowAbsoluteFrame()`, instead of printing the
  delegating frame's computed size, it now prints the original containing block
  rect, which is a more important information in abspos reflow.
* Use `MOZ_DEFINE_ENUM_TOSTRING_FUNC` to implement `LineReflowStatus` to string
  helper.
* Add an indent when printing `LineReflowStatus`.

Differential Revision: https://phabricator.services.mozilla.com/D271734

Diffstat:
Mlayout/generic/AbsoluteContainingBlock.cpp | 40+++++++---------------------------------
Mlayout/generic/BlockReflowState.cpp | 11+++++------
Mlayout/generic/nsBlockFrame.cpp | 68+++++++++++++++++++++++---------------------------------------------
Mlayout/generic/nsBlockFrame.h | 5-----
4 files changed, 35 insertions(+), 89 deletions(-)

diff --git a/layout/generic/AbsoluteContainingBlock.cpp b/layout/generic/AbsoluteContainingBlock.cpp @@ -12,10 +12,10 @@ #include "mozilla/AbsoluteContainingBlock.h" #include "AnchorPositioningUtils.h" +#include "fmt/format.h" #include "mozilla/CSSAlignUtils.h" #include "mozilla/PresShell.h" #include "mozilla/ReflowInput.h" -#include "mozilla/Sprintf.h" #include "mozilla/ViewportFrame.h" #include "mozilla/dom/ViewTransition.h" #include "nsAtomicContainerFrame.h" @@ -30,18 +30,6 @@ #ifdef DEBUG # include "nsBlockFrame.h" - -static void PrettyUC(nscoord aSize, char* aBuf, int aBufSize) { - if (NS_UNCONSTRAINEDSIZE == aSize) { - strcpy(aBuf, "UC"); - } else { - if ((int32_t)0xdeadbeef == aSize) { - strcpy(aBuf, "deadbeef"); - } else { - snprintf(aBuf, aBufSize, "%d", aSize); - } - } -} #endif using namespace mozilla; @@ -1031,19 +1019,10 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( #ifdef DEBUG if (nsBlockFrame::gNoisyReflow) { nsIFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent); - printf("abs pos "); - nsAutoString name; - aKidFrame->GetFrameName(name); - printf("%s ", NS_LossyConvertUTF16toASCII(name).get()); - - char width[16]; - char height[16]; - PrettyUC(aReflowInput.AvailableWidth(), width, 16); - PrettyUC(aReflowInput.AvailableHeight(), height, 16); - printf(" a=%s,%s ", width, height); - PrettyUC(aReflowInput.ComputedWidth(), width, 16); - PrettyUC(aReflowInput.ComputedHeight(), height, 16); - printf("c=%s,%s \n", width, height); + fmt::println( + FMT_STRING("abspos {}: begin reflow: availSize={}, orig cbRect={}"), + aKidFrame->ListTag(), ToString(aReflowInput.AvailableSize()), + ToString(aOriginalContainingBlockRect)); } AutoNoisyIndenter indent(nsBlockFrame::gNoisy); #endif // DEBUG @@ -1518,14 +1497,9 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( #ifdef DEBUG if (nsBlockFrame::gNoisyReflow) { - const nsRect r = aKidFrame->GetRect(); nsIFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent - 1); - printf("abs pos "); - nsAutoString name; - aKidFrame->GetFrameName(name); - printf("%s ", NS_LossyConvertUTF16toASCII(name).get()); - printf("%p rect=%d,%d,%d,%d\n", static_cast<void*>(aKidFrame), r.x, r.y, - r.width, r.height); + fmt::println(FMT_STRING("abspos {}: rect {}"), aKidFrame->ListTag().get(), + ToString(aKidFrame->GetRect())); } #endif diff --git a/layout/generic/BlockReflowState.cpp b/layout/generic/BlockReflowState.cpp @@ -12,6 +12,7 @@ #include "LayoutLogging.h" #include "TextOverflow.h" +#include "fmt/format.h" #include "mozilla/AutoRestore.h" #include "mozilla/Preferences.h" #include "mozilla/StaticPrefs_layout.h" @@ -329,9 +330,8 @@ nsFlowAreaRect BlockReflowState::GetFloatAvailableSpaceWithState( #ifdef DEBUG if (nsBlockFrame::gNoisyReflow) { nsIFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent); - printf("%s: band=%d,%d,%d,%d hasfloats=%d\n", __func__, - result.mRect.IStart(wm), result.mRect.BStart(wm), - result.mRect.ISize(wm), result.mRect.BSize(wm), result.HasFloats()); + fmt::println(FMT_STRING("{} band={} hasFloats={}"), __func__, + ToString(result.mRect), YesOrNo(result.HasFloats())); } #endif return result; @@ -360,9 +360,8 @@ nsFlowAreaRect BlockReflowState::GetFloatAvailableSpaceForBSize( #ifdef DEBUG if (nsBlockFrame::gNoisyReflow) { nsIFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent); - printf("%s: space=%d,%d,%d,%d hasfloats=%d\n", __func__, - result.mRect.IStart(wm), result.mRect.BStart(wm), - result.mRect.ISize(wm), result.mRect.BSize(wm), result.HasFloats()); + fmt::println(FMT_STRING("{} band={} hasFloats={}"), __func__, + ToString(result.mRect), YesOrNo(result.HasFloats())); } #endif return result; diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp @@ -18,12 +18,14 @@ #include "BlockReflowState.h" #include "CounterStyleManager.h" #include "TextOverflow.h" +#include "fmt/format.h" #include "gfxContext.h" #include "mozilla/AbsoluteContainingBlock.h" #include "mozilla/AppUnits.h" #include "mozilla/Baseline.h" #include "mozilla/ComputedStyle.h" #include "mozilla/DebugOnly.h" +#include "mozilla/DefineEnum.h" #include "mozilla/Likely.h" #include "mozilla/Maybe.h" #include "mozilla/PresShell.h" @@ -375,24 +377,9 @@ const char* nsBlockFrame::kReflowCommandType[] = { "ContentChanged", "StyleChanged", "ReflowDirty", "Timeout", "UserDefined", }; -const char* nsBlockFrame::LineReflowStatusToString( - LineReflowStatus aLineReflowStatus) const { - switch (aLineReflowStatus) { - case LineReflowStatus::OK: - return "LINE_REFLOW_OK"; - case LineReflowStatus::Stop: - return "LINE_REFLOW_STOP"; - case LineReflowStatus::RedoNoPull: - return "LINE_REFLOW_REDO_NO_PULL"; - case LineReflowStatus::RedoMoreFloats: - return "LINE_REFLOW_REDO_MORE_FLOATS"; - case LineReflowStatus::RedoNextBand: - return "LINE_REFLOW_REDO_NEXT_BAND"; - case LineReflowStatus::Truncated: - return "LINE_REFLOW_TRUNCATED"; - } - return "unknown"; -} +MOZ_DEFINE_ENUM_TOSTRING_FUNC(LineReflowStatus, + (OK, Stop, RedoNoPull, RedoMoreFloats, + RedoNextBand, Truncated)); #endif @@ -1326,10 +1313,9 @@ void nsBlockFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics, #ifdef DEBUG if (gNoisyReflow) { IndentBy(stdout, gNoiseIndent); - ListTag(stdout); - printf(": begin reflow availSize=%d,%d computedSize=%d,%d\n", - aReflowInput.AvailableISize(), aReflowInput.AvailableBSize(), - aReflowInput.ComputedISize(), aReflowInput.ComputedBSize()); + fmt::println(FMT_STRING("{}: begin reflow: availSize={} computedSize={}"), + ListTag().get(), ToString(aReflowInput.AvailableSize()), + ToString(aReflowInput.ComputedSize())); } AutoNoisyIndenter indent(gNoisy); PRTime start = 0; // Initialize these variablies to silence the compiler. @@ -1759,18 +1745,13 @@ void nsBlockFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics, if (gNoisyReflow) { IndentBy(stdout, gNoiseIndent); - ListTag(stdout); - printf(": status=%s metrics=%d,%d carriedMargin=%d", - ToString(aStatus).c_str(), aMetrics.ISize(parentWM), - aMetrics.BSize(parentWM), aMetrics.mCarriedOutBEndMargin.Get()); + fmt::print(FMT_STRING("{}: status={} metrics={} carriedMargin={}"), + ListTag().get(), ToString(aStatus), ToString(aMetrics.Size(wm)), + aMetrics.mCarriedOutBEndMargin.Get()); if (HasOverflowAreas()) { - printf(" overflow-vis={%d,%d,%d,%d}", aMetrics.InkOverflow().x, - aMetrics.InkOverflow().y, aMetrics.InkOverflow().width, - aMetrics.InkOverflow().height); - printf(" overflow-scr={%d,%d,%d,%d}", aMetrics.ScrollableOverflow().x, - aMetrics.ScrollableOverflow().y, - aMetrics.ScrollableOverflow().width, - aMetrics.ScrollableOverflow().height); + fmt::print(FMT_STRING(" overflow-ink={} overflow-scr={}"), + ToString(aMetrics.InkOverflow()), + ToString(aMetrics.ScrollableOverflow())); } printf("\n"); } @@ -2953,17 +2934,14 @@ static void DumpLine(const BlockReflowState& aState, nsLineBox* aLine, nscoord aDeltaBCoord, int32_t aDeltaIndent) { #ifdef DEBUG if (nsBlockFrame::gNoisyReflow) { - nsRect ovis(aLine->InkOverflowRect()); - nsRect oscr(aLine->ScrollableOverflowRect()); nsBlockFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent + aDeltaIndent); - printf( - "line=%p mBCoord=%d dirty=%s oldBounds={%d,%d,%d,%d} " - "oldoverflow-vis={%d,%d,%d,%d} oldoverflow-scr={%d,%d,%d,%d} " - "deltaBCoord=%d mPrevBEndMargin=%d childCount=%d\n", - static_cast<void*>(aLine), aState.mBCoord, - aLine->IsDirty() ? "yes" : "no", aLine->IStart(), aLine->BStart(), - aLine->ISize(), aLine->BSize(), ovis.x, ovis.y, ovis.width, ovis.height, - oscr.x, oscr.y, oscr.width, oscr.height, aDeltaBCoord, + fmt::println( + FMT_STRING("line={} mBCoord={} dirty={} bounds={} overflow-ink={} " + "overflow-scr={} deltaBCoord={} mPrevBEndMargin={} " + "childCount={}"), + static_cast<void*>(aLine), aState.mBCoord, YesOrNo(aLine->IsDirty()), + ToString(aLine->GetBounds()), ToString(aLine->InkOverflowRect()), + ToString(aLine->ScrollableOverflowRect()), aDeltaBCoord, aState.mPrevBEndMargin.Get(), aLine->GetChildCount()); } #endif @@ -5136,8 +5114,8 @@ void nsBlockFrame::DoReflowInlineFrames( } #ifdef DEBUG if (gNoisyReflow) { - printf("Line reflow status = %s\n", - LineReflowStatusToString(lineReflowStatus)); + IndentBy(stdout, gNoiseIndent); + fmt::println(FMT_STRING("LineReflowStatus={}"), ToString(lineReflowStatus)); } #endif diff --git a/layout/generic/nsBlockFrame.h b/layout/generic/nsBlockFrame.h @@ -155,11 +155,6 @@ class nsBlockFrame : public nsContainerFrame { nsresult GetFrameName(nsAString& aResult) const override; #endif -#ifdef DEBUG - const char* LineReflowStatusToString( - LineReflowStatus aLineReflowStatus) const; -#endif - #ifdef ACCESSIBILITY mozilla::a11y::AccType AccessibleType() override; #endif