diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index f0f53b6d5e20..20790ee4805e 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -8,6 +8,7 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/BasicEvents.h" +#include "mozilla/ClearOnShutdown.h" #include "mozilla/EventDispatcher.h" #include "mozilla/FloatingPoint.h" #include "mozilla/gfx/PathHelpers.h" @@ -2881,7 +2882,20 @@ nsLayoutUtils::CombineBreakType(uint8_t aOrigBreakType, #include static bool gDumpEventList = false; -int gPaintCount = 0; + +// nsLayoutUtils::PaintFrame() can call itself recursively, so rather than +// maintaining a single paint count, we need a stack. +StaticAutoPtr> gPaintCountStack; + +struct AutoNestedPaintCount { + AutoNestedPaintCount() { + gPaintCountStack->AppendElement(0); + } + ~AutoNestedPaintCount() { + gPaintCountStack->RemoveElementAt(gPaintCountStack->Length() - 1); + } +}; + #endif nsIFrame* @@ -3086,6 +3100,17 @@ nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFram PROFILER_LABEL("nsLayoutUtils", "PaintFrame", js::ProfileEntry::Category::GRAPHICS); +#ifdef MOZ_DUMP_PAINTING + if (!gPaintCountStack) { + gPaintCountStack = new nsTArray(); + ClearOnShutdown(&gPaintCountStack); + + gPaintCountStack->AppendElement(0); + } + ++gPaintCountStack->LastElement(); + AutoNestedPaintCount nestedPaintCount; +#endif + if (aFlags & PAINT_WIDGET_LAYERS) { nsView* view = aFrame->GetView(); if (!(view && view->GetWidget() && GetDisplayRootFrame(aFrame) == aFrame)) { @@ -3277,8 +3302,10 @@ nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFram // Include the process ID in the dump file name, to make sure that in an // e10s setup different processes don't clobber each other's dump files. string.AppendInt(getpid()); - string.AppendLiteral("-"); - string.AppendInt(gPaintCount); + for (int paintCount : *gPaintCountStack) { + string.AppendLiteral("-"); + string.AppendInt(paintCount); + } string.AppendLiteral(".html"); gfxUtils::sDumpPaintFile = fopen(string.BeginReading(), "w"); } else { @@ -3366,7 +3393,6 @@ nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFram fclose(gfxUtils::sDumpPaintFile); } gfxUtils::sDumpPaintFile = savedDumpFile; - gPaintCount++; #endif std::stringstream lsStream;