Bug 820132 - Measure imgFrame::mOptSurface's size where possible, instead of calculating it. r=joedrew.

--HG--
extra : rebase_source : da7616356429242e924a09df1124b1dbab13ad60
This commit is contained in:
Nicholas Nethercote 2012-12-18 21:59:30 -08:00
Родитель 95ed36320f
Коммит 51f20b1833
4 изменённых файлов: 28 добавлений и 5 удалений

Просмотреть файл

@ -199,6 +199,14 @@ public:
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
// gfxASurface has many sub-classes. This method indicates if a sub-class
// is capable of measuring its own size accurately. If not, the caller
// must fall back to a computed size. (Note that gfxASurface can actually
// measure itself, but we must |return false| here because it serves as the
// (conservative) default for all the sub-classes. Therefore, this
// function should only be called on a |gfxASurface*| that actually points
// to a sub-class of gfxASurface.)
virtual bool SizeOfIsMeasured() const { return false; }
/**
* The memory used by this surface (as reported by KnownMemoryUsed()) can

Просмотреть файл

@ -190,6 +190,12 @@ gfxImageSurface::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
bool
gfxImageSurface::SizeOfIsMeasured() const
{
return true;
}
// helper function for the CopyFrom methods
static void
CopyForStride(unsigned char* aDest, unsigned char* aSrc, const gfxIntSize& aSize, long aDestStride, long aSrcStride)

Просмотреть файл

@ -98,6 +98,7 @@ public:
MOZ_OVERRIDE;
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
MOZ_OVERRIDE;
virtual bool SizeOfIsMeasured() const MOZ_OVERRIDE;
protected:
gfxImageSurface();

Просмотреть файл

@ -1,6 +1,6 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -813,7 +813,6 @@ imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxASurface::MemoryLocat
n += n2;
}
// XXX: should pass aMallocSizeOf here. See bug 723827.
#ifdef USE_WIN_SURFACE
if (mWinSurface && aLocation == mWinSurface->GetMemoryLocation()) {
n += mWinSurface->KnownMemoryUsed();
@ -836,7 +835,16 @@ imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxASurface::MemoryLocat
}
if (mOptSurface && aLocation == mOptSurface->GetMemoryLocation()) {
n += mOptSurface->KnownMemoryUsed();
size_t n2 = 0;
if (aLocation == gfxASurface::MEMORY_IN_PROCESS_HEAP &&
mOptSurface->SizeOfIsMeasured()) {
// HEAP: measure (but only if the sub-class is capable of measuring)
n2 = mOptSurface->SizeOfIncludingThis(aMallocSizeOf);
}
if (n2 == 0) { // non-HEAP or computed fallback for HEAP
n2 = mOptSurface->KnownMemoryUsed();
}
n += n2;
}
return n;