2013-06-10 13:00:35 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
#ifndef WEBGL_MEMORY_TRACKER_H_
|
|
|
|
#define WEBGL_MEMORY_TRACKER_H_
|
2013-06-10 13:00:35 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "nsIMemoryReporter.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
#include "WebGLBuffer.h"
|
2014-11-13 20:03:50 -08:00
|
|
|
#include "WebGLContext.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
#include "WebGLVertexAttribData.h"
|
|
|
|
#include "WebGLProgram.h"
|
|
|
|
#include "WebGLRenderbuffer.h"
|
2014-11-13 20:03:50 -08:00
|
|
|
#include "WebGLShader.h"
|
|
|
|
#include "WebGLTexture.h"
|
|
|
|
#include "WebGLUniformLocation.h"
|
2013-06-10 13:00:35 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-12-07 21:39:47 -08:00
|
|
|
class WebGLMemoryTracker : public nsIMemoryReporter
|
2013-06-10 13:00:35 -07:00
|
|
|
{
|
2013-12-07 21:39:47 -08:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2013-11-25 16:01:52 -08:00
|
|
|
|
2013-11-25 16:03:38 -08:00
|
|
|
WebGLMemoryTracker();
|
|
|
|
static StaticRefPtr<WebGLMemoryTracker> sUniqueInstance;
|
2013-11-25 16:01:52 -08:00
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
// Here we store plain pointers, not RefPtrs: we don't want the
|
2013-11-25 16:03:38 -08:00
|
|
|
// WebGLMemoryTracker unique instance to keep alive all
|
2013-06-10 13:00:35 -07:00
|
|
|
// WebGLContexts ever created.
|
|
|
|
typedef nsTArray<const WebGLContext*> ContextsArrayType;
|
|
|
|
ContextsArrayType mContexts;
|
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
void InitMemoryReporter();
|
2013-06-10 13:00:35 -07:00
|
|
|
|
2013-11-25 16:03:38 -08:00
|
|
|
static WebGLMemoryTracker* UniqueInstance();
|
2013-06-10 13:00:35 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
static ContextsArrayType& Contexts() { return UniqueInstance()->mContexts; }
|
2013-06-10 13:00:35 -07:00
|
|
|
|
|
|
|
friend class WebGLContext;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static void AddWebGLContext(const WebGLContext* c) {
|
|
|
|
Contexts().AppendElement(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RemoveWebGLContext(const WebGLContext* c) {
|
|
|
|
ContextsArrayType & contexts = Contexts();
|
|
|
|
contexts.RemoveElement(c);
|
|
|
|
if (contexts.IsEmpty()) {
|
|
|
|
sUniqueInstance = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
private:
|
2014-06-26 06:30:49 -07:00
|
|
|
virtual ~WebGLMemoryTracker();
|
|
|
|
|
2013-06-10 13:00:35 -07:00
|
|
|
static int64_t GetTextureMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
texture;
|
|
|
|
texture = texture->getNext())
|
|
|
|
{
|
|
|
|
result += texture->MemoryUsage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetTextureCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
texture;
|
|
|
|
texture = texture->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetBufferMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
buffer;
|
|
|
|
buffer = buffer->getNext())
|
|
|
|
{
|
|
|
|
result += buffer->ByteLength();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetBufferCacheMemoryUsed();
|
|
|
|
|
|
|
|
static int64_t GetBufferCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
buffer;
|
|
|
|
buffer = buffer->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetRenderbufferMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
rb;
|
|
|
|
rb = rb->getNext())
|
|
|
|
{
|
|
|
|
result += rb->MemoryUsage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetRenderbufferCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
rb;
|
|
|
|
rb = rb->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetShaderSize();
|
|
|
|
|
|
|
|
static int64_t GetShaderCount() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
|
|
|
int64_t result = 0;
|
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
2014-11-13 20:03:50 -08:00
|
|
|
for (const WebGLShader* shader = contexts[i]->mShaders.getFirst();
|
2013-06-10 13:00:35 -07:00
|
|
|
shader;
|
|
|
|
shader = shader->getNext())
|
|
|
|
{
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t GetContextCount() {
|
|
|
|
return Contexts().Length();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
#endif // WEBGL_MEMORY_TRACKER_H_
|