From 793e57b78c30e5f3b94ed88286b95248791ce73f Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Tue, 13 Mar 2001 01:47:22 +0000 Subject: [PATCH] Display frame reflow counts (turned via config file define) Bug 71514 r=kmclusk sr=attinasi git-svn-id: svn://10.0.0.236/trunk@89416 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsIPresShell.h | 7 +- mozilla/layout/base/nsPresContext.cpp | 9 + mozilla/layout/base/nsPresContext.h | 20 ++ mozilla/layout/base/nsPresShell.cpp | 200 ++++++++++++++---- mozilla/layout/base/public/nsIPresContext.h | 20 ++ mozilla/layout/base/public/nsIPresShell.h | 7 +- mozilla/layout/base/public/nsPresContext.h | 20 ++ mozilla/layout/base/src/nsPresContext.cpp | 9 + mozilla/layout/base/src/nsPresContext.h | 1 + mozilla/layout/forms/nsFieldSetFrame.cpp | 1 + mozilla/layout/forms/nsListControlFrame.cpp | 1 + .../generic/nsAbsoluteContainingBlock.cpp | 1 - mozilla/layout/generic/nsBulletFrame.cpp | 9 +- mozilla/layout/generic/nsFrameFrame.cpp | 1 + mozilla/layout/generic/nsLeafFrame.cpp | 1 + mozilla/layout/generic/nsObjectFrame.cpp | 1 + mozilla/layout/generic/nsPlaceholderFrame.cpp | 1 + mozilla/layout/generic/nsTextFrame.cpp | 1 + .../base/src/nsAbsoluteContainingBlock.cpp | 1 - .../layout/html/base/src/nsBulletFrame.cpp | 9 +- mozilla/layout/html/base/src/nsLeafFrame.cpp | 1 + .../layout/html/base/src/nsObjectFrame.cpp | 1 + .../html/base/src/nsPlaceholderFrame.cpp | 1 + mozilla/layout/html/base/src/nsPresShell.cpp | 200 ++++++++++++++---- mozilla/layout/html/base/src/nsTextFrame.cpp | 1 + .../layout/html/document/src/nsFrameFrame.cpp | 1 + .../layout/html/forms/src/nsFieldSetFrame.cpp | 1 + .../html/forms/src/nsGfxTextControlFrame2.cpp | 4 +- .../html/forms/src/nsListControlFrame.cpp | 1 + .../html/table/src/nsTableCellFrame.cpp | 1 + .../layout/html/table/src/nsTableFrame.cpp | 1 + mozilla/layout/tables/nsTableCellFrame.cpp | 1 + mozilla/layout/tables/nsTableFrame.cpp | 1 + 33 files changed, 450 insertions(+), 85 deletions(-) diff --git a/mozilla/layout/base/nsIPresShell.h b/mozilla/layout/base/nsIPresShell.h index 131d74b1bce..c85127132ec 100644 --- a/mozilla/layout/base/nsIPresShell.h +++ b/mozilla/layout/base/nsIPresShell.h @@ -511,9 +511,14 @@ public: #ifdef MOZ_REFLOW_PERF - NS_IMETHOD ClearTotals() = 0; NS_IMETHOD DumpReflows() = 0; NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; + NS_IMETHOD PaintCount(const char * aName, + nsIRenderingContext* aRenderingContext, + nsIPresContext * aPresContext, + nsIFrame * aFrame, + PRUint32 aColor) = 0; + NS_IMETHOD SetPaintFrameCount(PRBool aOn) = 0; #endif #ifdef IBMBIDI diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index e553d21239d..39fa0fee40c 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -1505,4 +1505,13 @@ nsPresContext::CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFram } return NS_OK; } + +NS_IMETHODIMP +nsPresContext::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIFrame * aFrame, PRUint32 aColor) +{ + if (mShell) { + mShell->PaintCount(aName, aRenderingContext, this, aFrame, aColor); + } + return NS_OK; +} #endif diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index eb0c1ae10f7..5c8f25ae0e5 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -67,6 +67,10 @@ class nsIURI; class nsILookAndFeel; class nsICSSPseudoComparator; +#ifdef MOZ_REFLOW_PERF +class nsIRenderingContext; +#endif + #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } @@ -474,6 +478,7 @@ public: #ifdef MOZ_REFLOW_PERF NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; + NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRendingContext, nsIFrame * aFrame, PRUint32 aColor) = 0; #endif }; @@ -495,10 +500,25 @@ extern NS_LAYOUT nsresult #ifdef MOZ_REFLOW_PERF + #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ aPresContext->CountReflows((_name), (_type), (nsIFrame*)this); #else #define DO_GLOBAL_REFLOW_COUNT(_name, _type) #endif // MOZ_REFLOW_PERF +#if defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF) +#define DO_GLOBAL_REFLOW_COUNT_DSP(_name, _rend) \ + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { \ + aPresContext->PaintCount((_name), (_rend), (nsIFrame*)this, 0); \ + } +#define DO_GLOBAL_REFLOW_COUNT_DSP_J(_name, _rend, _just) \ + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { \ + aPresContext->PaintCount((_name), (_rend), (nsIFrame*)this, (_just)); \ + } +#else +#define DO_GLOBAL_REFLOW_COUNT_DSP(_name, _rend) +#define DO_GLOBAL_REFLOW_COUNT_DSP_J(_name, _rend, _just) +#endif // MOZ_REFLOW_PERF_DSP + #endif /* nsIPresContext_h___ */ diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 3e18cf18117..cae6809a249 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -107,6 +107,11 @@ #include "nsIFrameDebug.h" #endif +#ifdef MOZ_REFLOW_PERF_DSP +#include "nsIRenderingContext.h" +#include "nsIFontMetrics.h" +#endif + #include "nsIReflowCallback.h" #include "nsIScriptGlobalObject.h" @@ -188,6 +193,8 @@ static NS_DEFINE_CID(kHTMLConverterCID, NS_HTMLFORMATCONVERTER_CID); #undef NOISY +//======================================================================== +//======================================================================== //======================================================================== #ifdef MOZ_REFLOW_PERF class ReflowCountMgr; @@ -223,34 +230,33 @@ protected: PRUint32 mTotals[NUM_REFLOW_TYPES]; PRUint32 mCacheTotals[NUM_REFLOW_TYPES]; - ReflowCountMgr * mMgr; + ReflowCountMgr * mMgr; // weak reference (don't delete) }; // Counting Class class IndiReflowCounter { public: - IndiReflowCounter(ReflowCountMgr * aMgr = nsnull):mMgr(aMgr),mCounter(aMgr),mFrame(nsnull),mParent(nsnull), mCount(0), mHasBeenOutput(PR_FALSE) {} + IndiReflowCounter(ReflowCountMgr * aMgr = nsnull):mMgr(aMgr),mCounter(aMgr),mFrame(nsnull), mCount(0), mHasBeenOutput(PR_FALSE) {} virtual ~IndiReflowCounter() {} nsAutoString mName; - nsIFrame * mFrame; - nsIFrame * mParent; + nsIFrame * mFrame; // weak reference (don't delete) PRInt32 mCount; - ReflowCountMgr * mMgr; + ReflowCountMgr * mMgr; // weak reference (don't delete) ReflowCounter mCounter; PRBool mHasBeenOutput; }; +//-------------------- // Manager Class +//-------------------- class ReflowCountMgr { public: ReflowCountMgr(); - //static ReflowCountMgr * GetInstance() { return &gReflowCountMgr; } - - ~ReflowCountMgr(); + virtual ~ReflowCountMgr(); void ClearTotals(); void ClearGrandTotals(); @@ -261,12 +267,18 @@ public: void Add(const char * aName, nsReflowReason aType, nsIFrame * aFrame); ReflowCounter * LookUp(const char * aName); + void PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor); + FILE * GetOutFile() { return mFD; } PLHashTable * GetIndiFrameHT() { return mIndiFrameCounts; } - void SetPresContext(nsIPresContext * aPresContext) { mPresContext = aPresContext; } // weak reference - void SetPresShell(nsIPresShell* aPresShell) { mPresShell= aPresShell; } // weak reference + void SetPresContext(nsIPresContext * aPresContext) { mPresContext = aPresContext; } // weak reference + void SetPresShell(nsIPresShell* aPresShell) { mPresShell= aPresShell; } // weak reference + + void SetDumpFrameCounts(PRBool aVal) { mDumpFrameCounts = aVal; } + void SetDumpFrameByFrameCounts(PRBool aVal) { mDumpFrameByFrameCounts = aVal; } + void SetPaintFrameCounts(PRBool aVal) { mPaintFrameByFrameCounts = aVal; } protected: void DisplayTotals(PRUint32 * aArray, PRUint32 * aDupArray, char * aTitle); @@ -297,6 +309,10 @@ protected: PLHashTable * mIndiFrameCounts; FILE * mFD; + PRBool mDumpFrameCounts; + PRBool mDumpFrameByFrameCounts; + PRBool mPaintFrameByFrameCounts; + PRBool mCycledOnce; // Root Frame for Individual Tracking @@ -994,9 +1010,12 @@ public: NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); #ifdef MOZ_REFLOW_PERF - NS_IMETHOD ClearTotals(); NS_IMETHOD DumpReflows(); NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame); + NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor); + + NS_IMETHOD SetPaintFrameCount(PRBool aOn); + #endif protected: @@ -1502,6 +1521,25 @@ PresShell::Init(nsIDocument* aDocument, // setup the preference style rules up (no forced reflow) SetPreferenceStyleRules(PR_FALSE); +#ifdef MOZ_REFLOW_PERF + // Get the prefs service + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &result); + if (NS_SUCCEEDED(result)) { + if (mReflowCountMgr != nsnull) { + PRBool paintFrameCounts; + PRBool dumpFrameCounts; + PRBool dumpFrameByFrameCounts; + prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts); + + mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); + mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); + mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts); + } + } +#endif + return NS_OK; } @@ -6076,17 +6114,12 @@ nsresult CtlStyleWatch(PRUint32 aCtlValue, nsIStyleSet *aStyleSet) } -//------------------------------------------------------------- -//-- Reflow counts -//------------------------------------------------------------- +//============================================================= +//============================================================= +//-- Debug Reflow Counts +//============================================================= +//============================================================= #ifdef MOZ_REFLOW_PERF -//------------------------------------------------------------- -NS_IMETHODIMP -PresShell::ClearTotals() -{ - return NS_OK; -} - //------------------------------------------------------------- NS_IMETHODIMP PresShell::DumpReflows() @@ -6118,10 +6151,29 @@ PresShell::CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) return NS_OK; } +//------------------------------------------------------------- +NS_IMETHODIMP +PresShell::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor) +{ + if (mReflowCountMgr) { + mReflowCountMgr->PaintCount(aName, aRenderingContext, aPresContext, aFrame, aColor); + } + return NS_OK; +} + +//------------------------------------------------------------- +NS_IMETHODIMP +PresShell::SetPaintFrameCount(PRBool aPaintFrameCounts) +{ + if (mReflowCountMgr) { + mReflowCountMgr->SetPaintFrameCounts(aPaintFrameCounts); + } + return NS_OK; +} + //------------------------------------------------------------------ //-- Reflow Counter Classes Impls //------------------------------------------------------------------ -//ReflowCountMgr ReflowCountMgr::gReflowCountMgr; //------------------------------------------------------------------ ReflowCounter::ReflowCounter(ReflowCountMgr * aMgr) : @@ -6134,7 +6186,7 @@ ReflowCounter::ReflowCounter(ReflowCountMgr * aMgr) : //------------------------------------------------------------------ ReflowCounter::~ReflowCounter() { - //DisplayTotals(mTotals, "Grand Totals"); + } //------------------------------------------------------------------ @@ -6240,6 +6292,8 @@ void ReflowCounter::DisplayHTMLTotals(PRUint32 * aArray, const char * aTitle) fprintf(fd, "
%d
\n", total); } +//------------------------------------------------------------------ +//-- ReflowCountMgr //------------------------------------------------------------------ ReflowCountMgr::ReflowCountMgr() { @@ -6247,15 +6301,15 @@ ReflowCountMgr::ReflowCountMgr() PL_CompareValues, nsnull, nsnull); mIndiFrameCounts = PL_NewHashTable(10, PL_HashString, PL_CompareStrings, PL_CompareValues, nsnull, nsnull); - mCycledOnce = PR_FALSE; + mCycledOnce = PR_FALSE; + mDumpFrameCounts = PR_FALSE; + mDumpFrameByFrameCounts = PR_FALSE; + mPaintFrameByFrameCounts = PR_FALSE; } //------------------------------------------------------------------ ReflowCountMgr::~ReflowCountMgr() { - //if (GetInstance() == this) { - // DoGrandTotals(); - //} CleanUp(); } @@ -6275,7 +6329,7 @@ void ReflowCountMgr::Add(const char * aName, nsReflowReason aType, nsIFrame * aF { NS_ASSERTION(aName != nsnull, "Name shouldn't be null!"); - if (nsnull != mCounts) { + if (mDumpFrameCounts && nsnull != mCounts) { ReflowCounter * counter = (ReflowCounter *)PL_HashTableLookup(mCounts, aName); if (counter == nsnull) { counter = new ReflowCounter(this); @@ -6287,7 +6341,9 @@ void ReflowCountMgr::Add(const char * aName, nsReflowReason aType, nsIFrame * aF counter->Add(aType); } - if (nsnull != mIndiFrameCounts && aFrame != nsnull) { + if ((mDumpFrameByFrameCounts || mPaintFrameByFrameCounts) && + nsnull != mIndiFrameCounts && + aFrame != nsnull) { char * key = new char[16]; sprintf(key, "%p", aFrame); IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key); @@ -6295,18 +6351,81 @@ void ReflowCountMgr::Add(const char * aName, nsReflowReason aType, nsIFrame * aF counter = new IndiReflowCounter(this); NS_ASSERTION(counter != nsnull, "null ptr"); counter->mFrame = aFrame; - aFrame->GetParent(&counter->mParent); counter->mName.AssignWithConversion(aName); PL_HashTableAdd(mIndiFrameCounts, key, counter); } // this eliminates extra counts from super classes - if (counter->mName.EqualsWithConversion(aName)) { + if (counter != nsnull && counter->mName.EqualsWithConversion(aName)) { counter->mCount++; counter->mCounter.Add(aType, 1); } } } +//------------------------------------------------------------------ +void ReflowCountMgr::PaintCount(const char * aName, + nsIRenderingContext* aRenderingContext, + nsIPresContext* aPresContext, + nsIFrame* aFrame, + PRUint32 aColor) +{ + if (mPaintFrameByFrameCounts && + nsnull != mIndiFrameCounts && + aFrame != nsnull) { + char * key = new char[16]; + sprintf(key, "%p", aFrame); + IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key); + if (counter != nsnull && counter->mName.EqualsWithConversion(aName)) { + aRenderingContext->PushState(); + nsFont font("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(8)); + + nsCOMPtr fm; + aPresContext->GetMetricsFor(font, getter_AddRefs(fm)); + aRenderingContext->SetFont(fm); + char buf[16]; + sprintf(buf, "%d", counter->mCount); + nscoord width, height; + aRenderingContext->GetWidth((char*)buf, width); + fm->GetHeight(height); + + nsRect r; + aFrame->GetRect(r); + + nscoord x = 0; + PRUint32 color; + PRUint32 color2; + if (aColor != 0) { + color = aColor; + color2 = NS_RGB(0,0,0); + } else { + PRUint8 rc,gc,bc = 0; + if (counter->mCount < 5) { + rc = 255; + gc = 255; + } else if ( counter->mCount < 11) { + gc = 255; + } else { + rc = 255; + } + color = NS_RGB(rc,gc,bc); + color2 = NS_RGB(rc/2,gc/2,bc/2); + } + + nsRect rect(0,0, width+15, height+15); + aRenderingContext->SetColor(NS_RGB(0,0,0)); + aRenderingContext->FillRect(rect); + aRenderingContext->SetColor(color2); + aRenderingContext->DrawString(buf, strlen(buf), x+15,15); + aRenderingContext->SetColor(color); + aRenderingContext->DrawString(buf, strlen(buf), x,0); + + PRBool clipEmpty; + aRenderingContext->PopState(clipEmpty); + } + } +} + //------------------------------------------------------------------ PRIntn ReflowCountMgr::RemoveItems(PLHashEntry *he, PRIntn i, void *arg) { @@ -6334,11 +6453,14 @@ void ReflowCountMgr::CleanUp() { if (nsnull != mCounts) { PL_HashTableEnumerateEntries(mCounts, RemoveItems, nsnull); - PL_HashTableEnumerateEntries(mIndiFrameCounts, RemoveIndiItems, nsnull); PL_HashTableDestroy(mCounts); - PL_HashTableDestroy(mIndiFrameCounts); mCounts = nsnull; - mCounts = mIndiFrameCounts; + } + + if (nsnull != mIndiFrameCounts) { + PL_HashTableEnumerateEntries(mIndiFrameCounts, RemoveIndiItems, nsnull); + PL_HashTableDestroy(mIndiFrameCounts); + mIndiFrameCounts = nsnull; } } @@ -6490,8 +6612,12 @@ void ReflowCountMgr::DoGrandHTMLTotals() void ReflowCountMgr::DisplayTotals(const char * aStr) { printf("%s\n", aStr?aStr:"No name"); - DoGrandTotals(); - DoIndiTotalsTree(); + if (mDumpFrameCounts) { + DoGrandTotals(); + } + if (mDumpFrameByFrameCounts) { + DoIndiTotalsTree(); + } } //------------------------------------ @@ -6612,3 +6738,5 @@ void ColorToString(nscolor aColor, nsAutoString &aString) if (tmp.Length() < 2) tmp.AppendInt(0,16); aString.Append(tmp); } + + diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index eb0c1ae10f7..5c8f25ae0e5 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -67,6 +67,10 @@ class nsIURI; class nsILookAndFeel; class nsICSSPseudoComparator; +#ifdef MOZ_REFLOW_PERF +class nsIRenderingContext; +#endif + #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } @@ -474,6 +478,7 @@ public: #ifdef MOZ_REFLOW_PERF NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; + NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRendingContext, nsIFrame * aFrame, PRUint32 aColor) = 0; #endif }; @@ -495,10 +500,25 @@ extern NS_LAYOUT nsresult #ifdef MOZ_REFLOW_PERF + #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ aPresContext->CountReflows((_name), (_type), (nsIFrame*)this); #else #define DO_GLOBAL_REFLOW_COUNT(_name, _type) #endif // MOZ_REFLOW_PERF +#if defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF) +#define DO_GLOBAL_REFLOW_COUNT_DSP(_name, _rend) \ + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { \ + aPresContext->PaintCount((_name), (_rend), (nsIFrame*)this, 0); \ + } +#define DO_GLOBAL_REFLOW_COUNT_DSP_J(_name, _rend, _just) \ + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { \ + aPresContext->PaintCount((_name), (_rend), (nsIFrame*)this, (_just)); \ + } +#else +#define DO_GLOBAL_REFLOW_COUNT_DSP(_name, _rend) +#define DO_GLOBAL_REFLOW_COUNT_DSP_J(_name, _rend, _just) +#endif // MOZ_REFLOW_PERF_DSP + #endif /* nsIPresContext_h___ */ diff --git a/mozilla/layout/base/public/nsIPresShell.h b/mozilla/layout/base/public/nsIPresShell.h index 131d74b1bce..c85127132ec 100644 --- a/mozilla/layout/base/public/nsIPresShell.h +++ b/mozilla/layout/base/public/nsIPresShell.h @@ -511,9 +511,14 @@ public: #ifdef MOZ_REFLOW_PERF - NS_IMETHOD ClearTotals() = 0; NS_IMETHOD DumpReflows() = 0; NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; + NS_IMETHOD PaintCount(const char * aName, + nsIRenderingContext* aRenderingContext, + nsIPresContext * aPresContext, + nsIFrame * aFrame, + PRUint32 aColor) = 0; + NS_IMETHOD SetPaintFrameCount(PRBool aOn) = 0; #endif #ifdef IBMBIDI diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index eb0c1ae10f7..5c8f25ae0e5 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -67,6 +67,10 @@ class nsIURI; class nsILookAndFeel; class nsICSSPseudoComparator; +#ifdef MOZ_REFLOW_PERF +class nsIRenderingContext; +#endif + #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } @@ -474,6 +478,7 @@ public: #ifdef MOZ_REFLOW_PERF NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) = 0; + NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRendingContext, nsIFrame * aFrame, PRUint32 aColor) = 0; #endif }; @@ -495,10 +500,25 @@ extern NS_LAYOUT nsresult #ifdef MOZ_REFLOW_PERF + #define DO_GLOBAL_REFLOW_COUNT(_name, _type) \ aPresContext->CountReflows((_name), (_type), (nsIFrame*)this); #else #define DO_GLOBAL_REFLOW_COUNT(_name, _type) #endif // MOZ_REFLOW_PERF +#if defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF) +#define DO_GLOBAL_REFLOW_COUNT_DSP(_name, _rend) \ + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { \ + aPresContext->PaintCount((_name), (_rend), (nsIFrame*)this, 0); \ + } +#define DO_GLOBAL_REFLOW_COUNT_DSP_J(_name, _rend, _just) \ + if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { \ + aPresContext->PaintCount((_name), (_rend), (nsIFrame*)this, (_just)); \ + } +#else +#define DO_GLOBAL_REFLOW_COUNT_DSP(_name, _rend) +#define DO_GLOBAL_REFLOW_COUNT_DSP_J(_name, _rend, _just) +#endif // MOZ_REFLOW_PERF_DSP + #endif /* nsIPresContext_h___ */ diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index e553d21239d..39fa0fee40c 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -1505,4 +1505,13 @@ nsPresContext::CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFram } return NS_OK; } + +NS_IMETHODIMP +nsPresContext::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIFrame * aFrame, PRUint32 aColor) +{ + if (mShell) { + mShell->PaintCount(aName, aRenderingContext, this, aFrame, aColor); + } + return NS_OK; +} #endif diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index c7e97b64483..4a30f027033 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -164,6 +164,7 @@ public: #ifdef MOZ_REFLOW_PERF NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame); + NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIFrame * aFrame, PRUint32 aColor); #endif // nsIObserver method diff --git a/mozilla/layout/forms/nsFieldSetFrame.cpp b/mozilla/layout/forms/nsFieldSetFrame.cpp index c84cdba9c59..ed4b7b1e8b4 100644 --- a/mozilla/layout/forms/nsFieldSetFrame.cpp +++ b/mozilla/layout/forms/nsFieldSetFrame.cpp @@ -252,6 +252,7 @@ nsFieldSetFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height); } #endif + DO_GLOBAL_REFLOW_COUNT_DSP("nsFieldSetFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index b3fcbb06dcc..9d62ff8cf79 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -335,6 +335,7 @@ nsListControlFrame::Paint(nsIPresContext* aPresContext, return nsScrollFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); } + DO_GLOBAL_REFLOW_COUNT_DSP("nsListControlFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/generic/nsAbsoluteContainingBlock.cpp b/mozilla/layout/generic/nsAbsoluteContainingBlock.cpp index 96cf42a16b8..e0ed0c67f9d 100644 --- a/mozilla/layout/generic/nsAbsoluteContainingBlock.cpp +++ b/mozilla/layout/generic/nsAbsoluteContainingBlock.cpp @@ -180,7 +180,6 @@ nsAbsoluteContainingBlock::Reflow(nsIFrame* aDelegatingFrame, nscoord aContainingBlockHeight, nsRect& aChildBounds) { - DO_GLOBAL_REFLOW_COUNT("nsAbsoluteContainingBlock", aReflowState.reason); // Initialize OUT parameter aChildBounds.SetRect(0, 0, 0, 0); diff --git a/mozilla/layout/generic/nsBulletFrame.cpp b/mozilla/layout/generic/nsBulletFrame.cpp index ad864fa323e..e909cab56c6 100644 --- a/mozilla/layout/generic/nsBulletFrame.cpp +++ b/mozilla/layout/generic/nsBulletFrame.cpp @@ -112,7 +112,7 @@ nsBulletFrame::GetFrameType(nsIAtom** aType) const #include "nsIDOMNode.h" NS_IMETHODIMP -nsBulletFrame::Paint(nsIPresContext* aCX, +nsBulletFrame::Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) @@ -122,7 +122,7 @@ nsBulletFrame::Paint(nsIPresContext* aCX, } PRBool isVisible; - if (NS_SUCCEEDED(IsVisibleForPainting(aCX, aRenderingContext, PR_TRUE, &isVisible)) && isVisible) { + if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && isVisible) { const nsStyleList* myList = (const nsStyleList*)mStyleContext->GetStyleData(eStyleStruct_List); PRUint8 listStyleType = myList->mListStyleType; @@ -256,8 +256,8 @@ nsBulletFrame::Paint(nsIPresContext* aCX, case NS_STYLE_LIST_STYLE_LAO: case NS_STYLE_LIST_STYLE_MYANMAR: case NS_STYLE_LIST_STYLE_KHMER: - aCX->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); - GetListItemText(aCX, *myList, text); + aPresContext->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + GetListItemText(aPresContext, *myList, text); aRenderingContext.SetFont(fm); aRenderingContext.DrawString(text, mPadding.left, mPadding.top); break; @@ -288,6 +288,7 @@ nsBulletFrame::Paint(nsIPresContext* aCX, } #endif // IBMBIDI } + DO_GLOBAL_REFLOW_COUNT_DSP("nsBulletFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 87cc676893a..33ef267b2ac 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -665,6 +665,7 @@ nsHTMLFrameInnerFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.SetColor(color->mBackgroundColor); aRenderingContext.FillRect(mRect); } + DO_GLOBAL_REFLOW_COUNT_DSP("nsHTMLFrameInnerFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/generic/nsLeafFrame.cpp b/mozilla/layout/generic/nsLeafFrame.cpp index 5d1a0a78a75..18e6895f44f 100644 --- a/mozilla/layout/generic/nsLeafFrame.cpp +++ b/mozilla/layout/generic/nsLeafFrame.cpp @@ -66,6 +66,7 @@ nsLeafFrame::Paint(nsIPresContext* aPresContext, aDirtyRect, rect, *myBorder, *myOutline, mStyleContext, 0); } } + DO_GLOBAL_REFLOW_COUNT_DSP("nsLeafFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 349e7512eb2..0b92283b4ff 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -1345,6 +1345,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, } } #endif /* !XP_MAC */ + DO_GLOBAL_REFLOW_COUNT_DSP("nsObjectFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/generic/nsPlaceholderFrame.cpp b/mozilla/layout/generic/nsPlaceholderFrame.cpp index bdb583a9ba6..1957c72ebc8 100644 --- a/mozilla/layout/generic/nsPlaceholderFrame.cpp +++ b/mozilla/layout/generic/nsPlaceholderFrame.cpp @@ -90,6 +90,7 @@ nsPlaceholderFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.FillRect(0, y, NSIntPixelsToTwips(3, p2t), NSIntPixelsToTwips(10, p2t)); } + DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 64ab6a93c49..c2fab0b001b 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -1287,6 +1287,7 @@ nsTextFrame::Paint(nsIPresContext* aPresContext, } } + DO_GLOBAL_REFLOW_COUNT_DSP("nsTextFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsAbsoluteContainingBlock.cpp b/mozilla/layout/html/base/src/nsAbsoluteContainingBlock.cpp index 96cf42a16b8..e0ed0c67f9d 100644 --- a/mozilla/layout/html/base/src/nsAbsoluteContainingBlock.cpp +++ b/mozilla/layout/html/base/src/nsAbsoluteContainingBlock.cpp @@ -180,7 +180,6 @@ nsAbsoluteContainingBlock::Reflow(nsIFrame* aDelegatingFrame, nscoord aContainingBlockHeight, nsRect& aChildBounds) { - DO_GLOBAL_REFLOW_COUNT("nsAbsoluteContainingBlock", aReflowState.reason); // Initialize OUT parameter aChildBounds.SetRect(0, 0, 0, 0); diff --git a/mozilla/layout/html/base/src/nsBulletFrame.cpp b/mozilla/layout/html/base/src/nsBulletFrame.cpp index ad864fa323e..e909cab56c6 100644 --- a/mozilla/layout/html/base/src/nsBulletFrame.cpp +++ b/mozilla/layout/html/base/src/nsBulletFrame.cpp @@ -112,7 +112,7 @@ nsBulletFrame::GetFrameType(nsIAtom** aType) const #include "nsIDOMNode.h" NS_IMETHODIMP -nsBulletFrame::Paint(nsIPresContext* aCX, +nsBulletFrame::Paint(nsIPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) @@ -122,7 +122,7 @@ nsBulletFrame::Paint(nsIPresContext* aCX, } PRBool isVisible; - if (NS_SUCCEEDED(IsVisibleForPainting(aCX, aRenderingContext, PR_TRUE, &isVisible)) && isVisible) { + if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && isVisible) { const nsStyleList* myList = (const nsStyleList*)mStyleContext->GetStyleData(eStyleStruct_List); PRUint8 listStyleType = myList->mListStyleType; @@ -256,8 +256,8 @@ nsBulletFrame::Paint(nsIPresContext* aCX, case NS_STYLE_LIST_STYLE_LAO: case NS_STYLE_LIST_STYLE_MYANMAR: case NS_STYLE_LIST_STYLE_KHMER: - aCX->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); - GetListItemText(aCX, *myList, text); + aPresContext->GetMetricsFor(myFont->mFont, getter_AddRefs(fm)); + GetListItemText(aPresContext, *myList, text); aRenderingContext.SetFont(fm); aRenderingContext.DrawString(text, mPadding.left, mPadding.top); break; @@ -288,6 +288,7 @@ nsBulletFrame::Paint(nsIPresContext* aCX, } #endif // IBMBIDI } + DO_GLOBAL_REFLOW_COUNT_DSP("nsBulletFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsLeafFrame.cpp b/mozilla/layout/html/base/src/nsLeafFrame.cpp index 5d1a0a78a75..18e6895f44f 100644 --- a/mozilla/layout/html/base/src/nsLeafFrame.cpp +++ b/mozilla/layout/html/base/src/nsLeafFrame.cpp @@ -66,6 +66,7 @@ nsLeafFrame::Paint(nsIPresContext* aPresContext, aDirtyRect, rect, *myBorder, *myOutline, mStyleContext, 0); } } + DO_GLOBAL_REFLOW_COUNT_DSP("nsLeafFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 349e7512eb2..0b92283b4ff 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -1345,6 +1345,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, } } #endif /* !XP_MAC */ + DO_GLOBAL_REFLOW_COUNT_DSP("nsObjectFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsPlaceholderFrame.cpp b/mozilla/layout/html/base/src/nsPlaceholderFrame.cpp index bdb583a9ba6..1957c72ebc8 100644 --- a/mozilla/layout/html/base/src/nsPlaceholderFrame.cpp +++ b/mozilla/layout/html/base/src/nsPlaceholderFrame.cpp @@ -90,6 +90,7 @@ nsPlaceholderFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.FillRect(0, y, NSIntPixelsToTwips(3, p2t), NSIntPixelsToTwips(10, p2t)); } + DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 3e18cf18117..cae6809a249 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -107,6 +107,11 @@ #include "nsIFrameDebug.h" #endif +#ifdef MOZ_REFLOW_PERF_DSP +#include "nsIRenderingContext.h" +#include "nsIFontMetrics.h" +#endif + #include "nsIReflowCallback.h" #include "nsIScriptGlobalObject.h" @@ -188,6 +193,8 @@ static NS_DEFINE_CID(kHTMLConverterCID, NS_HTMLFORMATCONVERTER_CID); #undef NOISY +//======================================================================== +//======================================================================== //======================================================================== #ifdef MOZ_REFLOW_PERF class ReflowCountMgr; @@ -223,34 +230,33 @@ protected: PRUint32 mTotals[NUM_REFLOW_TYPES]; PRUint32 mCacheTotals[NUM_REFLOW_TYPES]; - ReflowCountMgr * mMgr; + ReflowCountMgr * mMgr; // weak reference (don't delete) }; // Counting Class class IndiReflowCounter { public: - IndiReflowCounter(ReflowCountMgr * aMgr = nsnull):mMgr(aMgr),mCounter(aMgr),mFrame(nsnull),mParent(nsnull), mCount(0), mHasBeenOutput(PR_FALSE) {} + IndiReflowCounter(ReflowCountMgr * aMgr = nsnull):mMgr(aMgr),mCounter(aMgr),mFrame(nsnull), mCount(0), mHasBeenOutput(PR_FALSE) {} virtual ~IndiReflowCounter() {} nsAutoString mName; - nsIFrame * mFrame; - nsIFrame * mParent; + nsIFrame * mFrame; // weak reference (don't delete) PRInt32 mCount; - ReflowCountMgr * mMgr; + ReflowCountMgr * mMgr; // weak reference (don't delete) ReflowCounter mCounter; PRBool mHasBeenOutput; }; +//-------------------- // Manager Class +//-------------------- class ReflowCountMgr { public: ReflowCountMgr(); - //static ReflowCountMgr * GetInstance() { return &gReflowCountMgr; } - - ~ReflowCountMgr(); + virtual ~ReflowCountMgr(); void ClearTotals(); void ClearGrandTotals(); @@ -261,12 +267,18 @@ public: void Add(const char * aName, nsReflowReason aType, nsIFrame * aFrame); ReflowCounter * LookUp(const char * aName); + void PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor); + FILE * GetOutFile() { return mFD; } PLHashTable * GetIndiFrameHT() { return mIndiFrameCounts; } - void SetPresContext(nsIPresContext * aPresContext) { mPresContext = aPresContext; } // weak reference - void SetPresShell(nsIPresShell* aPresShell) { mPresShell= aPresShell; } // weak reference + void SetPresContext(nsIPresContext * aPresContext) { mPresContext = aPresContext; } // weak reference + void SetPresShell(nsIPresShell* aPresShell) { mPresShell= aPresShell; } // weak reference + + void SetDumpFrameCounts(PRBool aVal) { mDumpFrameCounts = aVal; } + void SetDumpFrameByFrameCounts(PRBool aVal) { mDumpFrameByFrameCounts = aVal; } + void SetPaintFrameCounts(PRBool aVal) { mPaintFrameByFrameCounts = aVal; } protected: void DisplayTotals(PRUint32 * aArray, PRUint32 * aDupArray, char * aTitle); @@ -297,6 +309,10 @@ protected: PLHashTable * mIndiFrameCounts; FILE * mFD; + PRBool mDumpFrameCounts; + PRBool mDumpFrameByFrameCounts; + PRBool mPaintFrameByFrameCounts; + PRBool mCycledOnce; // Root Frame for Individual Tracking @@ -994,9 +1010,12 @@ public: NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); #ifdef MOZ_REFLOW_PERF - NS_IMETHOD ClearTotals(); NS_IMETHOD DumpReflows(); NS_IMETHOD CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame); + NS_IMETHOD PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor); + + NS_IMETHOD SetPaintFrameCount(PRBool aOn); + #endif protected: @@ -1502,6 +1521,25 @@ PresShell::Init(nsIDocument* aDocument, // setup the preference style rules up (no forced reflow) SetPreferenceStyleRules(PR_FALSE); +#ifdef MOZ_REFLOW_PERF + // Get the prefs service + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &result); + if (NS_SUCCEEDED(result)) { + if (mReflowCountMgr != nsnull) { + PRBool paintFrameCounts; + PRBool dumpFrameCounts; + PRBool dumpFrameByFrameCounts; + prefs->GetBoolPref("layout.reflow.showframecounts", &paintFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframecounts", &dumpFrameCounts); + prefs->GetBoolPref("layout.reflow.dumpframebyframecounts", &dumpFrameByFrameCounts); + + mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); + mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); + mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts); + } + } +#endif + return NS_OK; } @@ -6076,17 +6114,12 @@ nsresult CtlStyleWatch(PRUint32 aCtlValue, nsIStyleSet *aStyleSet) } -//------------------------------------------------------------- -//-- Reflow counts -//------------------------------------------------------------- +//============================================================= +//============================================================= +//-- Debug Reflow Counts +//============================================================= +//============================================================= #ifdef MOZ_REFLOW_PERF -//------------------------------------------------------------- -NS_IMETHODIMP -PresShell::ClearTotals() -{ - return NS_OK; -} - //------------------------------------------------------------- NS_IMETHODIMP PresShell::DumpReflows() @@ -6118,10 +6151,29 @@ PresShell::CountReflows(const char * aName, PRUint32 aType, nsIFrame * aFrame) return NS_OK; } +//------------------------------------------------------------- +NS_IMETHODIMP +PresShell::PaintCount(const char * aName, nsIRenderingContext* aRenderingContext, nsIPresContext* aPresContext, nsIFrame * aFrame, PRUint32 aColor) +{ + if (mReflowCountMgr) { + mReflowCountMgr->PaintCount(aName, aRenderingContext, aPresContext, aFrame, aColor); + } + return NS_OK; +} + +//------------------------------------------------------------- +NS_IMETHODIMP +PresShell::SetPaintFrameCount(PRBool aPaintFrameCounts) +{ + if (mReflowCountMgr) { + mReflowCountMgr->SetPaintFrameCounts(aPaintFrameCounts); + } + return NS_OK; +} + //------------------------------------------------------------------ //-- Reflow Counter Classes Impls //------------------------------------------------------------------ -//ReflowCountMgr ReflowCountMgr::gReflowCountMgr; //------------------------------------------------------------------ ReflowCounter::ReflowCounter(ReflowCountMgr * aMgr) : @@ -6134,7 +6186,7 @@ ReflowCounter::ReflowCounter(ReflowCountMgr * aMgr) : //------------------------------------------------------------------ ReflowCounter::~ReflowCounter() { - //DisplayTotals(mTotals, "Grand Totals"); + } //------------------------------------------------------------------ @@ -6240,6 +6292,8 @@ void ReflowCounter::DisplayHTMLTotals(PRUint32 * aArray, const char * aTitle) fprintf(fd, "
%d
\n", total); } +//------------------------------------------------------------------ +//-- ReflowCountMgr //------------------------------------------------------------------ ReflowCountMgr::ReflowCountMgr() { @@ -6247,15 +6301,15 @@ ReflowCountMgr::ReflowCountMgr() PL_CompareValues, nsnull, nsnull); mIndiFrameCounts = PL_NewHashTable(10, PL_HashString, PL_CompareStrings, PL_CompareValues, nsnull, nsnull); - mCycledOnce = PR_FALSE; + mCycledOnce = PR_FALSE; + mDumpFrameCounts = PR_FALSE; + mDumpFrameByFrameCounts = PR_FALSE; + mPaintFrameByFrameCounts = PR_FALSE; } //------------------------------------------------------------------ ReflowCountMgr::~ReflowCountMgr() { - //if (GetInstance() == this) { - // DoGrandTotals(); - //} CleanUp(); } @@ -6275,7 +6329,7 @@ void ReflowCountMgr::Add(const char * aName, nsReflowReason aType, nsIFrame * aF { NS_ASSERTION(aName != nsnull, "Name shouldn't be null!"); - if (nsnull != mCounts) { + if (mDumpFrameCounts && nsnull != mCounts) { ReflowCounter * counter = (ReflowCounter *)PL_HashTableLookup(mCounts, aName); if (counter == nsnull) { counter = new ReflowCounter(this); @@ -6287,7 +6341,9 @@ void ReflowCountMgr::Add(const char * aName, nsReflowReason aType, nsIFrame * aF counter->Add(aType); } - if (nsnull != mIndiFrameCounts && aFrame != nsnull) { + if ((mDumpFrameByFrameCounts || mPaintFrameByFrameCounts) && + nsnull != mIndiFrameCounts && + aFrame != nsnull) { char * key = new char[16]; sprintf(key, "%p", aFrame); IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key); @@ -6295,18 +6351,81 @@ void ReflowCountMgr::Add(const char * aName, nsReflowReason aType, nsIFrame * aF counter = new IndiReflowCounter(this); NS_ASSERTION(counter != nsnull, "null ptr"); counter->mFrame = aFrame; - aFrame->GetParent(&counter->mParent); counter->mName.AssignWithConversion(aName); PL_HashTableAdd(mIndiFrameCounts, key, counter); } // this eliminates extra counts from super classes - if (counter->mName.EqualsWithConversion(aName)) { + if (counter != nsnull && counter->mName.EqualsWithConversion(aName)) { counter->mCount++; counter->mCounter.Add(aType, 1); } } } +//------------------------------------------------------------------ +void ReflowCountMgr::PaintCount(const char * aName, + nsIRenderingContext* aRenderingContext, + nsIPresContext* aPresContext, + nsIFrame* aFrame, + PRUint32 aColor) +{ + if (mPaintFrameByFrameCounts && + nsnull != mIndiFrameCounts && + aFrame != nsnull) { + char * key = new char[16]; + sprintf(key, "%p", aFrame); + IndiReflowCounter * counter = (IndiReflowCounter *)PL_HashTableLookup(mIndiFrameCounts, key); + if (counter != nsnull && counter->mName.EqualsWithConversion(aName)) { + aRenderingContext->PushState(); + nsFont font("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(8)); + + nsCOMPtr fm; + aPresContext->GetMetricsFor(font, getter_AddRefs(fm)); + aRenderingContext->SetFont(fm); + char buf[16]; + sprintf(buf, "%d", counter->mCount); + nscoord width, height; + aRenderingContext->GetWidth((char*)buf, width); + fm->GetHeight(height); + + nsRect r; + aFrame->GetRect(r); + + nscoord x = 0; + PRUint32 color; + PRUint32 color2; + if (aColor != 0) { + color = aColor; + color2 = NS_RGB(0,0,0); + } else { + PRUint8 rc,gc,bc = 0; + if (counter->mCount < 5) { + rc = 255; + gc = 255; + } else if ( counter->mCount < 11) { + gc = 255; + } else { + rc = 255; + } + color = NS_RGB(rc,gc,bc); + color2 = NS_RGB(rc/2,gc/2,bc/2); + } + + nsRect rect(0,0, width+15, height+15); + aRenderingContext->SetColor(NS_RGB(0,0,0)); + aRenderingContext->FillRect(rect); + aRenderingContext->SetColor(color2); + aRenderingContext->DrawString(buf, strlen(buf), x+15,15); + aRenderingContext->SetColor(color); + aRenderingContext->DrawString(buf, strlen(buf), x,0); + + PRBool clipEmpty; + aRenderingContext->PopState(clipEmpty); + } + } +} + //------------------------------------------------------------------ PRIntn ReflowCountMgr::RemoveItems(PLHashEntry *he, PRIntn i, void *arg) { @@ -6334,11 +6453,14 @@ void ReflowCountMgr::CleanUp() { if (nsnull != mCounts) { PL_HashTableEnumerateEntries(mCounts, RemoveItems, nsnull); - PL_HashTableEnumerateEntries(mIndiFrameCounts, RemoveIndiItems, nsnull); PL_HashTableDestroy(mCounts); - PL_HashTableDestroy(mIndiFrameCounts); mCounts = nsnull; - mCounts = mIndiFrameCounts; + } + + if (nsnull != mIndiFrameCounts) { + PL_HashTableEnumerateEntries(mIndiFrameCounts, RemoveIndiItems, nsnull); + PL_HashTableDestroy(mIndiFrameCounts); + mIndiFrameCounts = nsnull; } } @@ -6490,8 +6612,12 @@ void ReflowCountMgr::DoGrandHTMLTotals() void ReflowCountMgr::DisplayTotals(const char * aStr) { printf("%s\n", aStr?aStr:"No name"); - DoGrandTotals(); - DoIndiTotalsTree(); + if (mDumpFrameCounts) { + DoGrandTotals(); + } + if (mDumpFrameByFrameCounts) { + DoIndiTotalsTree(); + } } //------------------------------------ @@ -6612,3 +6738,5 @@ void ColorToString(nscolor aColor, nsAutoString &aString) if (tmp.Length() < 2) tmp.AppendInt(0,16); aString.Append(tmp); } + + diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 64ab6a93c49..c2fab0b001b 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -1287,6 +1287,7 @@ nsTextFrame::Paint(nsIPresContext* aPresContext, } } + DO_GLOBAL_REFLOW_COUNT_DSP("nsTextFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 87cc676893a..33ef267b2ac 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -665,6 +665,7 @@ nsHTMLFrameInnerFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.SetColor(color->mBackgroundColor); aRenderingContext.FillRect(mRect); } + DO_GLOBAL_REFLOW_COUNT_DSP("nsHTMLFrameInnerFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp b/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp index c84cdba9c59..ed4b7b1e8b4 100644 --- a/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp @@ -252,6 +252,7 @@ nsFieldSetFrame::Paint(nsIPresContext* aPresContext, aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height); } #endif + DO_GLOBAL_REFLOW_COUNT_DSP("nsFieldSetFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index 4c1d73216e5..07d7c6b8465 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -2026,7 +2026,9 @@ nsGfxTextControlFrame2::Paint(nsIPresContext* aPresContext, if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && !isVisible) { return NS_OK; } - return nsStackFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + nsresult rv = nsStackFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + DO_GLOBAL_REFLOW_COUNT_DSP("nsGfxTextControlFrame2", &aRenderingContext); + return rv; } diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index b3fcbb06dcc..9d62ff8cf79 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -335,6 +335,7 @@ nsListControlFrame::Paint(nsIPresContext* aPresContext, return nsScrollFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); } + DO_GLOBAL_REFLOW_COUNT_DSP("nsListControlFrame", &aRenderingContext); return NS_OK; } diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 0141ec29828..af33bc6820d 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -392,6 +392,7 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext* aPresContext, } } + DO_GLOBAL_REFLOW_COUNT_DSP_J("nsTableCellFrame", &aRenderingContext, 0); return NS_OK; /*nsFrame::Paint(aPresContext, aRenderingContext, diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 9647c300ccb..1913ad06a74 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -1377,6 +1377,7 @@ NS_METHOD nsTableFrame::Paint(nsIPresContext* aPresContext, #endif PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + DO_GLOBAL_REFLOW_COUNT_DSP_J("nsTableFrame", &aRenderingContext, NS_RGB(255,128,255)); return NS_OK; /*nsFrame::Paint(aPresContext, aRenderingContext, diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 0141ec29828..af33bc6820d 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -392,6 +392,7 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext* aPresContext, } } + DO_GLOBAL_REFLOW_COUNT_DSP_J("nsTableCellFrame", &aRenderingContext, 0); return NS_OK; /*nsFrame::Paint(aPresContext, aRenderingContext, diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 9647c300ccb..1913ad06a74 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -1377,6 +1377,7 @@ NS_METHOD nsTableFrame::Paint(nsIPresContext* aPresContext, #endif PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); + DO_GLOBAL_REFLOW_COUNT_DSP_J("nsTableFrame", &aRenderingContext, NS_RGB(255,128,255)); return NS_OK; /*nsFrame::Paint(aPresContext, aRenderingContext,