Bug 831193 (part 10) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in parts of gfx/. r=bjacob.

--HG--
extra : rebase_source : 433b12748c8562b384a02fbee6d98e3bc991802d
This commit is contained in:
Nicholas Nethercote 2013-01-17 16:45:11 -08:00
parent 096351ca03
commit 23e35ad8e1
4 changed files with 77 additions and 48 deletions

View File

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 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/. */
@ -113,33 +114,21 @@ static const char *sExtensionNames[] = {
nullptr
};
static int64_t sTextureMemoryUsage = 0;
int64_t GfxTexturesReporter::sAmount = 0;
static int64_t
GetTextureMemoryUsage()
{
return sTextureMemoryUsage;
}
void
GLContext::UpdateTextureMemoryUsage(MemoryUse action, GLenum format, GLenum type, uint16_t tileSize)
/* static */ void
GfxTexturesReporter::UpdateAmount(MemoryUse action, GLenum format,
GLenum type, uint16_t tileSize)
{
uint32_t bytesPerTexel = mozilla::gl::GetBitsPerTexel(format, type) / 8;
int64_t bytes = (int64_t)(tileSize * tileSize * bytesPerTexel);
if (action == MemoryFreed) {
sTextureMemoryUsage -= bytes;
sAmount -= bytes;
} else {
sTextureMemoryUsage += bytes;
sAmount += bytes;
}
}
NS_MEMORY_REPORTER_IMPLEMENT(TextureMemoryUsage,
"gfx-textures",
KIND_OTHER,
UNITS_BYTES,
GetTextureMemoryUsage,
"Memory used for storing GL textures.")
/*
* XXX - we should really know the ARB/EXT variants of these
* instead of only handling the symbol if it's exposed directly.
@ -1002,7 +991,7 @@ void
GLContext::PlatformStartup()
{
CacheCanUploadNPOT();
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(TextureMemoryUsage));
NS_RegisterMemoryReporter(new GfxTexturesReporter());
}
void

View File

@ -1,4 +1,5 @@
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 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/. */
@ -40,6 +41,7 @@
#include "nsHashKeys.h"
#include "nsRegion.h"
#include "nsAutoPtr.h"
#include "nsIMemoryReporter.h"
#include "nsThreadUtils.h"
#include "GLContextTypes.h"
#include "GLTextureImage.h"
@ -3444,8 +3446,24 @@ public:
nsTArray<NamedResource> mTrackedBuffers;
nsTArray<NamedResource> mTrackedQueries;
#endif
};
class GfxTexturesReporter MOZ_FINAL : public MemoryReporterBase
{
public:
GfxTexturesReporter()
: MemoryReporterBase("gfx-textures", KIND_OTHER, UNITS_BYTES,
"Memory used for storing GL textures.")
{
#ifdef DEBUG
// There must be only one instance of this class, due to |sAmount|
// being static. Assert this.
static bool hasRun = false;
MOZ_ASSERT(!hasRun);
hasRun = true;
#endif
}
enum MemoryUse {
// when memory being allocated is reported to a memory reporter
MemoryAllocated,
@ -3453,12 +3471,15 @@ public:
MemoryFreed
};
// When memory is used/freed for tile textures, call this method
// to update the value reported by the memory reporter.
static void UpdateTextureMemoryUsage(MemoryUse action,
GLenum format,
GLenum type,
uint16_t tileSize);
// When memory is used/freed for tile textures, call this method to update
// the value reported by this memory reporter.
static void UpdateAmount(MemoryUse action, GLenum format, GLenum type,
uint16_t tileSize);
private:
int64_t Amount() MOZ_OVERRIDE { return sAmount; }
static int64_t sAmount;
};
inline bool

View File

@ -183,19 +183,35 @@ ContentTypeFromPixelFormat(android::PixelFormat aFormat)
return gfxASurface::ContentFromFormat(ImageFormatForPixelFormat(aFormat));
}
static size_t sCurrentAlloc;
static int64_t GetGrallocSize() { return sCurrentAlloc; }
class GrallocReporter MOZ_FINAL : public MemoryReporterBase
{
friend class GrallocBufferActor;
NS_MEMORY_REPORTER_IMPLEMENT(GrallocBufferActor,
"gralloc",
KIND_OTHER,
UNITS_BYTES,
GetGrallocSize,
"Special RAM that can be shared between processes and directly "
"accessed by both the CPU and GPU. Gralloc memory is usually a "
"relatively precious resource, with much less available than generic "
"RAM. When it's exhausted, graphics performance can suffer. "
"This value can be incorrect because of race conditions.");
public:
GrallocReporter()
: MemoryReporterBase("gralloc", KIND_OTHER, UNITS_BYTES,
"Special RAM that can be shared between processes and directly accessed by "
"both the CPU and GPU. Gralloc memory is usually a relatively precious "
"resource, with much less available than generic RAM. When it's exhausted, "
"graphics performance can suffer. This value can be incorrect because of race "
"conditions.")
{
#ifdef DEBUG
// There must be only one instance of this class, due to |sAmount|
// being static. Assert this.
static bool hasRun = false;
MOZ_ASSERT(!hasRun);
hasRun = true;
#endif
}
private:
int64_t Amount() MOZ_OVERRIDE { return sAmount; }
static int64_t sAmount;
};
int64_t GrallocReporter::sAmount = 0;
GrallocBufferActor::GrallocBufferActor()
: mAllocBytes(0)
@ -207,7 +223,7 @@ GrallocBufferActor::GrallocBufferActor()
// the main thread.
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(GrallocBufferActor));
NS_RegisterMemoryReporter(new GrallocReporter());
registered = true;
}
}
@ -215,7 +231,7 @@ GrallocBufferActor::GrallocBufferActor()
GrallocBufferActor::~GrallocBufferActor()
{
if (mAllocBytes > 0) {
sCurrentAlloc -= mAllocBytes;
GrallocReporter::sAmount -= mAllocBytes;
}
}
@ -242,7 +258,7 @@ GrallocBufferActor::Create(const gfxIntSize& aSize,
size_t bpp = BytesPerPixelForPixelFormat(format);
actor->mAllocBytes = aSize.width * aSize.height * bpp;
sCurrentAlloc += actor->mAllocBytes;
GrallocReporter::sAmount += actor->mAllocBytes;
actor->mGraphicBuffer = buffer;
*aOutHandle = MagicGrallocBufferHandle(buffer);

View File

@ -848,8 +848,9 @@ TiledDeprecatedTextureHostOGL::DeleteTextures()
mGL->MakeCurrent();
mGL->fDeleteTextures(1, &mTextureHandle);
gl::GLContext::UpdateTextureMemoryUsage(gl::GLContext::MemoryFreed, mGLFormat,
GetTileType(), TILEDLAYERBUFFER_TILE_SIZE);
gl::GfxTexturesReporter::UpdateAmount(gl::GfxTexturesReporter::MemoryFreed,
mGLFormat, GetTileType(),
TILEDLAYERBUFFER_TILE_SIZE);
mTextureHandle = 0;
}
}
@ -871,8 +872,9 @@ TiledDeprecatedTextureHostOGL::Update(gfxReusableSurfaceWrapper* aReusableSurfac
mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
// We're re-using a texture, but the format may change. Update the memory
// reporter with a free and alloc (below) using the old and new formats.
gl::GLContext::UpdateTextureMemoryUsage(gl::GLContext::MemoryFreed, mGLFormat,
GetTileType(), TILEDLAYERBUFFER_TILE_SIZE);
gl::GfxTexturesReporter::UpdateAmount(gl::GfxTexturesReporter::MemoryFreed,
mGLFormat, GetTileType(),
TILEDLAYERBUFFER_TILE_SIZE);
}
GLenum type;
@ -883,8 +885,9 @@ TiledDeprecatedTextureHostOGL::Update(gfxReusableSurfaceWrapper* aReusableSurfac
TILEDLAYERBUFFER_TILE_SIZE, TILEDLAYERBUFFER_TILE_SIZE, 0,
mGLFormat, type, buf);
gl::GLContext::UpdateTextureMemoryUsage(gl::GLContext::MemoryAllocated, mGLFormat,
type, TILEDLAYERBUFFER_TILE_SIZE);
gl::GfxTexturesReporter::UpdateAmount(gl::GfxTexturesReporter::MemoryAllocated,
mGLFormat, type,
TILEDLAYERBUFFER_TILE_SIZE);
if (mGLFormat == LOCAL_GL_RGB) {
mFormat = FORMAT_R8G8B8X8;