Bug 711901 - When possible, measure, don't compute, the size of imgFrame::mImageSurface. r=joedrew.

--HG--
extra : rebase_source : 72dc61c2618166262ec6d83778d7bd2a3a7b5d61
This commit is contained in:
Nicholas Nethercote 2012-11-26 16:29:56 -08:00
parent c491e9d557
commit 0a76089154
5 changed files with 53 additions and 5 deletions

View File

@ -649,6 +649,19 @@ gfxASurface::RecordMemoryFreed()
}
}
size_t
gfxASurface::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
// We don't measure mSurface because cairo doesn't allow it.
return 0;
}
size_t
gfxASurface::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
#ifdef MOZ_DUMP_IMAGES
void
gfxASurface::WriteAsPNG(const char* aFile)

View File

@ -197,6 +197,9 @@ public:
virtual int32_t KnownMemoryUsed() { return mBytesRecorded; }
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
/**
* The memory used by this surface (as reported by KnownMemoryUsed()) can
* either live in this process's heap, in this process but outside the

View File

@ -174,6 +174,22 @@ gfxImageSurface::ComputeStride(const gfxIntSize& aSize, gfxImageFormat aFormat)
return stride;
}
size_t
gfxImageSurface::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
size_t n = gfxASurface::SizeOfExcludingThis(aMallocSizeOf);
if (mOwnsData) {
n += aMallocSizeOf(mData);
}
return n;
}
size_t
gfxImageSurface::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
// helper function for the CopyFrom methods
static void
CopyForStride(unsigned char* aDest, unsigned char* aSrc, const gfxIntSize& aSize, long aDestStride, long aSrcStride)

View File

@ -93,6 +93,12 @@ public:
const nsIntPoint& aDestTopLeft) MOZ_OVERRIDE;
static long ComputeStride(const gfxIntSize&, gfxImageFormat);
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
MOZ_OVERRIDE;
protected:
gfxImageSurface();
void InitWithData(unsigned char *aData, const gfxIntSize& aSize,

View File

@ -790,6 +790,9 @@ void imgFrame::SetCompositingFailed(bool val)
mCompositingFailed = val;
}
// If |aLocation| indicates this is heap memory, we try to measure things with
// |aMallocSizeOf|. If that fails (because the platform doesn't support it) or
// it's non-heap memory, we fall back to computing the size analytically.
size_t
imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxASurface::MemoryLocation aLocation, nsMallocSizeOfFun aMallocSizeOf) const
{
@ -803,11 +806,11 @@ imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxASurface::MemoryLocat
size_t n = 0;
if (mPalettedImageData && aLocation == gfxASurface::MEMORY_IN_PROCESS_HEAP) {
size_t usable = aMallocSizeOf(mPalettedImageData);
if (!usable) {
usable = GetImageDataLength() + PaletteDataLength();
size_t n2 = aMallocSizeOf(mPalettedImageData);
if (n2 == 0) {
n2 = GetImageDataLength() + PaletteDataLength();
}
n += usable;
n += n2;
}
// XXX: should pass aMallocSizeOf here. See bug 723827.
@ -822,7 +825,14 @@ imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxASurface::MemoryLocat
} else
#endif
if (mImageSurface && aLocation == mImageSurface->GetMemoryLocation()) {
n += mImageSurface->KnownMemoryUsed();
size_t n2 = 0;
if (aLocation == gfxASurface::MEMORY_IN_PROCESS_HEAP) { // HEAP: measure
n2 = mImageSurface->SizeOfIncludingThis(aMallocSizeOf);
}
if (n2 == 0) { // non-HEAP or computed fallback for HEAP
n2 = mImageSurface->KnownMemoryUsed();
}
n += n2;
}
if (mOptSurface && aLocation == mOptSurface->GetMemoryLocation()) {