Bug 915940. Memory reporter for memory image surfaces. r=njn,mattwoodrow

This commit is contained in:
Nicholas Cameron 2013-09-24 10:59:26 +12:00
Родитель f2cad8ef9c
Коммит a6633f8396
5 изменённых файлов: 50 добавлений и 2 удалений

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

@ -211,6 +211,7 @@ MemoryTextureClient::Allocate(uint32_t aSize)
{
MOZ_ASSERT(!mBuffer);
mBuffer = new uint8_t[aSize];
GfxHeapTexturesReporter::OnAlloc(mBuffer);
mBufSize = aSize;
return true;
}
@ -228,9 +229,10 @@ MemoryTextureClient::MemoryTextureClient(CompositableClient* aCompositable,
MemoryTextureClient::~MemoryTextureClient()
{
MOZ_COUNT_DTOR(MemoryTextureClient);
if (ShouldDeallocateInDestructor()) {
if (ShouldDeallocateInDestructor() && mBuffer) {
// if the buffer has never been shared we must deallocate it or ir would
// leak.
GfxHeapTexturesReporter::OnFree(mBuffer);
delete mBuffer;
}
}

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

@ -537,6 +537,9 @@ MemoryTextureHost::~MemoryTextureHost()
void
MemoryTextureHost::DeallocateSharedData()
{
if (mBuffer) {
GfxHeapTexturesReporter::OnFree(mBuffer);
}
delete[] mBuffer;
}

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

@ -27,6 +27,8 @@ using namespace mozilla::ipc;
namespace mozilla {
namespace layers {
mozilla::Atomic<int32_t> GfxHeapTexturesReporter::sAmount;
SharedMemory::SharedMemoryType OptimalShmemType()
{
return SharedMemory::TYPE_BASIC;
@ -88,6 +90,7 @@ ISurfaceAllocator::AllocSurfaceDescriptorWithCaps(const gfxIntSize& aSize,
if (!data) {
return false;
}
GfxHeapTexturesReporter::OnAlloc(data);
#ifdef XP_MACOSX
// Workaround a bug in Quartz where drawing an a8 surface to another a8
// surface with OPERATOR_SOURCE still requires the destination to be clear.
@ -135,7 +138,8 @@ ISurfaceAllocator::DestroySharedSurface(SurfaceDescriptor* aSurface)
case SurfaceDescriptor::TSurfaceDescriptorD3D10:
break;
case SurfaceDescriptor::TMemoryImage:
delete [] (unsigned char *)aSurface->get_MemoryImage().data();
GfxHeapTexturesReporter::OnFree((uint8_t*)aSurface->get_MemoryImage().data());
delete [] (uint8_t*)aSurface->get_MemoryImage().data();
break;
case SurfaceDescriptor::Tnull_t:
case SurfaceDescriptor::T__None:

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

@ -11,6 +11,8 @@
#include "gfxTypes.h"
#include "gfxPoint.h" // for gfxIntSize
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
#include "nsIMemoryReporter.h" // for MemoryUniReporter
#include "mozilla/Atomics.h" // for Atomic
/*
* FIXME [bjacob] *** PURE CRAZYNESS WARNING ***
@ -24,6 +26,8 @@
#endif
class gfxSharedImageSurface;
class MemoryTextureClient;
class MemoryTextureHost;
namespace base {
class Thread;
@ -132,6 +136,38 @@ protected:
~ISurfaceAllocator() {}
};
class GfxHeapTexturesReporter MOZ_FINAL : public mozilla::MemoryUniReporter
{
public:
GfxHeapTexturesReporter()
: MemoryUniReporter("explicit/gfx/heap-textures", KIND_HEAP, UNITS_BYTES,
"Heap memory shared between threads by texture clients and hosts.")
{
#ifdef DEBUG
// There must be only one instance of this class, due to |sAmount|
// being static.
static bool hasRun = false;
MOZ_ASSERT(!hasRun);
hasRun = true;
#endif
}
static void OnAlloc(void* aPointer)
{
sAmount += MallocSizeOfOnAlloc(aPointer);
}
static void OnFree(void* aPointer)
{
sAmount -= MallocSizeOfOnFree(aPointer);
}
private:
int64_t Amount() MOZ_OVERRIDE { return sAmount; }
static mozilla::Atomic<int32_t> sAmount;
};
} // namespace
} // namespace

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

@ -10,6 +10,7 @@
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/ISurfaceAllocator.h" // for GfxHeapTexturesReporter
#include "prlog.h"
#include "prenv.h"
@ -441,6 +442,8 @@ gfxPlatform::Init()
false);
CreateCMSOutputProfile();
NS_RegisterMemoryReporter(new GfxHeapTexturesReporter());
}
void