Bug 1036654 - Report the tile fragmentation overhead. r=njn,kats,cwiiis

This commit is contained in:
Benoit Girard 2014-07-24 13:34:43 -04:00
parent ea13f2e259
commit 46261cf888
4 changed files with 57 additions and 4 deletions

View File

@ -12,7 +12,8 @@ using namespace mozilla::gl;
NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter)
int64_t GfxTexturesReporter::sAmount = 0;
Atomic<int32_t> GfxTexturesReporter::sAmount(0);
Atomic<int32_t> GfxTexturesReporter::sTileWasteAmount(0);
static uint32_t
GetBitsPerTexel(GLenum format, GLenum type)

View File

@ -7,6 +7,7 @@
#ifndef GFXTEXTURESREPORTER_H_
#define GFXTEXTURESREPORTER_H_
#include "mozilla/Atomics.h"
#include "nsIMemoryReporter.h"
#include "GLTypes.h"
@ -43,16 +44,49 @@ public:
static void UpdateAmount(MemoryUse action, GLenum format, GLenum type,
int32_t tileWidth, int32_t tileHeight);
static void UpdateWasteAmount(int32_t delta) {
sTileWasteAmount += delta;
}
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData, bool aAnonymize)
{
MOZ_COLLECT_REPORT("gfx-tiles-waste", KIND_OTHER, UNITS_BYTES,
sTileWasteAmount,
"Memory lost due to tiles extending past content boundaries");
return MOZ_COLLECT_REPORT(
"gfx-textures", KIND_OTHER, UNITS_BYTES, sAmount,
"Memory used for storing GL textures.");
}
private:
static int64_t sAmount;
static Atomic<int32_t> sAmount;
// Count the amount of memory lost to tile waste
static Atomic<int32_t> sTileWasteAmount;
};
class GfxTextureWasteTracker {
public:
GfxTextureWasteTracker()
: mBytes(0)
{
MOZ_COUNT_CTOR(GfxTextureWasteTracker);
}
void Update(int32_t aPixelArea, int32_t aBytesPerPixel) {
GfxTexturesReporter::UpdateWasteAmount(-mBytes);
mBytes = aPixelArea * aBytesPerPixel;
GfxTexturesReporter::UpdateWasteAmount(mBytes);
}
~GfxTextureWasteTracker() {
GfxTexturesReporter::UpdateWasteAmount(-mBytes);
MOZ_COUNT_DTOR(GfxTextureWasteTracker);
}
private:
GfxTextureWasteTracker(const GfxTextureWasteTracker& aRef);
int32_t mBytes;
};
}

View File

@ -26,6 +26,7 @@
#include "nsAutoPtr.h" // for nsRefPtr
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsISupportsImpl.h" // for TextureImage::AddRef, etc
#include "GfxTexturesReporter.h"
class gfxReusableSurfaceWrapper;
class gfxImageSurface;
@ -344,6 +345,14 @@ public:
*/
virtual void WaitForBufferOwnership() {}
/**
* Track how much of this texture is wasted.
* For example we might allocate a 256x256 tile but only use 10x10.
*/
void SetWaste(int aWasteArea) {
mWasteTracker.Update(aWasteArea, BytesPerPixel(GetFormat()));
}
private:
/**
* Called once, just before the destructor.
@ -402,10 +411,11 @@ protected:
RefPtr<TextureChild> mActor;
RefPtr<ISurfaceAllocator> mAllocator;
TextureFlags mFlags;
bool mShared;
bool mValid;
FenceHandle mReleaseFenceHandle;
FenceHandle mAcquireFenceHandle;
gl::GfxTextureWasteTracker mWasteTracker;
bool mShared;
bool mValid;
friend class TextureChild;
friend class RemoveTextureFromCompositableTracker;

View File

@ -1036,6 +1036,14 @@ ClientTiledLayerBuffer::ValidateTile(TileClient aTile,
ctxt = nullptr;
drawTarget = nullptr;
nsIntRegion tileRegion =
nsIntRect(aTileOrigin.x, aTileOrigin.y,
GetScaledTileSize().width, GetScaledTileSize().height);
// Intersect this area with the portion that's invalid.
tileRegion = tileRegion.Sub(tileRegion, GetValidRegion());
tileRegion = tileRegion.Sub(tileRegion, aDirtyRegion); // Has now been validated
backBuffer->SetWaste(tileRegion.Area() * mResolution * mResolution);
backBuffer->Unlock();
if (createdTextureClient) {