Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1366097 - Part 8. Improve image memory reports to include SVG con…
…text information. r=tnikkel
  • Loading branch information
aosmond committed Nov 17, 2017
1 parent 2278b25 commit 19e321e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
43 changes: 43 additions & 0 deletions image/imgLoader.cpp
Expand Up @@ -40,6 +40,7 @@
#include "nsIFile.h"
#include "nsCRT.h"
#include "nsINetworkPredictor.h"
#include "nsReadableUtils.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/nsMixedContentBlocker.h"

Expand Down Expand Up @@ -312,6 +313,48 @@ class imgMemoryReporter final : public nsIMemoryReporter
surfacePathPrefix.AppendInt(uint32_t(counter.Key().Flags()),
/* aRadix = */ 16);
}

if (counter.Key().SVGContext()) {
const SVGImageContext& context = counter.Key().SVGContext().ref();
surfacePathPrefix.AppendLiteral(", svgContext:[ ");
if (context.GetViewportSize()) {
const CSSIntSize& size = context.GetViewportSize().ref();
surfacePathPrefix.AppendLiteral("viewport=(");
surfacePathPrefix.AppendInt(size.width);
surfacePathPrefix.AppendLiteral("x");
surfacePathPrefix.AppendInt(size.height);
surfacePathPrefix.AppendLiteral(") ");
}
if (context.GetPreserveAspectRatio()) {
nsAutoString aspect;
context.GetPreserveAspectRatio()->ToString(aspect);
surfacePathPrefix.AppendLiteral("preserveAspectRatio=(");
LossyAppendUTF16toASCII(aspect, surfacePathPrefix);
surfacePathPrefix.AppendLiteral(") ");
}
if (context.GetContextPaint()) {
const SVGEmbeddingContextPaint* paint = context.GetContextPaint();
surfacePathPrefix.AppendLiteral("contextPaint=(");
if (paint->GetFill()) {
surfacePathPrefix.AppendLiteral(" fill=");
surfacePathPrefix.AppendInt(paint->GetFill()->ToABGR(), 16);
}
if (paint->GetFillOpacity()) {
surfacePathPrefix.AppendLiteral(" fillOpa=");
surfacePathPrefix.AppendFloat(paint->GetFillOpacity());
}
if (paint->GetStroke()) {
surfacePathPrefix.AppendLiteral(" stroke=");
surfacePathPrefix.AppendInt(paint->GetStroke()->ToABGR(), 16);
}
if (paint->GetStrokeOpacity()) {
surfacePathPrefix.AppendLiteral(" strokeOpa=");
surfacePathPrefix.AppendFloat(paint->GetStrokeOpacity());
}
surfacePathPrefix.AppendLiteral(" ) ");
}
surfacePathPrefix.AppendLiteral("]");
}
} else if (counter.Type() == SurfaceMemoryCounterType::COMPOSITING) {
surfacePathPrefix.AppendLiteral(", compositing frame");
} else if (counter.Type() == SurfaceMemoryCounterType::COMPOSITING_PREV) {
Expand Down
6 changes: 6 additions & 0 deletions layout/svg/SVGContextPaint.h
Expand Up @@ -272,9 +272,15 @@ class SVGEmbeddingContextPaint : public SVGContextPaint
void SetFill(nscolor aFill) {
mFill.emplace(gfx::ToDeviceColor(aFill));
}
const Maybe<Color>& GetFill() const {
return mFill;
}
void SetStroke(nscolor aStroke) {
mStroke.emplace(gfx::ToDeviceColor(aStroke));
}
const Maybe<Color>& GetStroke() const {
return mStroke;
}

/**
* Returns a pattern of type PatternType::COLOR, or else nullptr.
Expand Down

0 comments on commit 19e321e

Please sign in to comment.