2012-02-20 03:58:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2012-02-20 03:58:08 +00:00
|
|
|
|
|
|
|
#include "WebGLContext.h"
|
2013-06-10 20:00:35 +00:00
|
|
|
#include "WebGLMemoryMultiReporterWrapper.h"
|
2012-02-20 03:58:08 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-10-09 18:39:51 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(WebGLMemoryPressureObserver, nsIObserver)
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-02-27 19:37:32 +00:00
|
|
|
class WebGLMemoryMultiReporter MOZ_FINAL : public nsIMemoryMultiReporter
|
2012-02-20 03:58:08 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYMULTIREPORTER
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(WebGLMemoryMultiReporter, nsIMemoryMultiReporter)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLMemoryMultiReporter::GetName(nsACString &aName)
|
|
|
|
{
|
|
|
|
aName.AssignLiteral("webgl");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebGLMemoryMultiReporter::CollectReports(nsIMemoryMultiReporterCallback* aCb,
|
|
|
|
nsISupports* aClosure)
|
|
|
|
{
|
2012-03-04 23:26:30 +00:00
|
|
|
#define REPORT(_path, _kind, _units, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
nsresult rv; \
|
|
|
|
rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), _kind, \
|
|
|
|
_units, _amount, NS_LITERAL_CSTRING(_desc), \
|
|
|
|
aClosure); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
REPORT("webgl-texture-memory",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetTextureMemoryUsed(),
|
|
|
|
"Memory used by WebGL textures.The OpenGL"
|
|
|
|
" implementation is free to store these textures in either video"
|
|
|
|
" memory or main memory. This measurement is only a lower bound,"
|
|
|
|
" actual memory usage may be higher for example if the storage"
|
|
|
|
" is strided.");
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-03-04 23:26:30 +00:00
|
|
|
REPORT("webgl-texture-count",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetTextureCount(),
|
|
|
|
"Number of WebGL textures.");
|
|
|
|
|
|
|
|
REPORT("webgl-buffer-memory",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetBufferMemoryUsed(),
|
|
|
|
"Memory used by WebGL buffers. The OpenGL"
|
|
|
|
" implementation is free to store these buffers in either video"
|
|
|
|
" memory or main memory. This measurement is only a lower bound,"
|
|
|
|
" actual memory usage may be higher for example if the storage"
|
|
|
|
" is strided.");
|
|
|
|
|
|
|
|
REPORT("explicit/webgl/buffer-cache-memory",
|
|
|
|
nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetBufferCacheMemoryUsed(),
|
|
|
|
"Memory used by WebGL buffer caches. The WebGL"
|
|
|
|
" implementation caches the contents of element array buffers"
|
|
|
|
" only.This adds up with the webgl-buffer-memory value, but"
|
|
|
|
" contrary to it, this one represents bytes on the heap,"
|
|
|
|
" not managed by OpenGL.");
|
|
|
|
|
|
|
|
REPORT("webgl-buffer-count",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetBufferCount(),
|
|
|
|
"Number of WebGL buffers.");
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-03-04 23:26:30 +00:00
|
|
|
REPORT("webgl-renderbuffer-memory",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetRenderbufferMemoryUsed(),
|
|
|
|
"Memory used by WebGL renderbuffers. The OpenGL"
|
|
|
|
" implementation is free to store these renderbuffers in either"
|
|
|
|
" video memory or main memory. This measurement is only a lower"
|
|
|
|
" bound, actual memory usage may be higher for example if the"
|
|
|
|
" storage is strided.");
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-03-04 23:26:30 +00:00
|
|
|
REPORT("webgl-renderbuffer-count",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetRenderbufferCount(),
|
|
|
|
"Number of WebGL renderbuffers.");
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-03-04 23:26:30 +00:00
|
|
|
REPORT("explicit/webgl/shader",
|
|
|
|
nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetShaderSize(),
|
|
|
|
"Combined size of WebGL shader ASCII sources and translation"
|
|
|
|
" logs cached on the heap.");
|
|
|
|
|
|
|
|
REPORT("webgl-shader-count",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetShaderCount(),
|
|
|
|
"Number of WebGL shaders.");
|
|
|
|
|
|
|
|
REPORT("webgl-context-count",
|
|
|
|
nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
|
|
|
|
WebGLMemoryMultiReporterWrapper::GetContextCount(),
|
|
|
|
"Number of WebGL contexts.");
|
|
|
|
|
|
|
|
#undef REPORT
|
2012-02-20 03:58:08 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
WebGLMemoryMultiReporterWrapper* WebGLMemoryMultiReporterWrapper::sUniqueInstance = nullptr;
|
2012-02-20 03:58:08 +00:00
|
|
|
|
|
|
|
WebGLMemoryMultiReporterWrapper* WebGLMemoryMultiReporterWrapper::UniqueInstance()
|
|
|
|
{
|
|
|
|
if (!sUniqueInstance) {
|
|
|
|
sUniqueInstance = new WebGLMemoryMultiReporterWrapper;
|
|
|
|
}
|
|
|
|
return sUniqueInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLMemoryMultiReporterWrapper::WebGLMemoryMultiReporterWrapper()
|
|
|
|
{
|
|
|
|
mReporter = new WebGLMemoryMultiReporter;
|
|
|
|
NS_RegisterMemoryMultiReporter(mReporter);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLMemoryMultiReporterWrapper::~WebGLMemoryMultiReporterWrapper()
|
|
|
|
{
|
|
|
|
NS_UnregisterMemoryMultiReporter(mReporter);
|
|
|
|
}
|
|
|
|
|
2012-12-24 00:59:51 +00:00
|
|
|
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(WebGLBufferMallocSizeOf)
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-05-23 16:07:01 +00:00
|
|
|
int64_t
|
2012-02-20 03:58:08 +00:00
|
|
|
WebGLMemoryMultiReporterWrapper::GetBufferCacheMemoryUsed() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 16:07:01 +00:00
|
|
|
int64_t result = 0;
|
2012-05-29 18:44:31 +00:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLBuffer *buffer = contexts[i]->mBuffers.getFirst();
|
|
|
|
buffer;
|
|
|
|
buffer = buffer->getNext())
|
|
|
|
{
|
|
|
|
if (buffer->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2012-12-24 00:59:51 +00:00
|
|
|
result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf);
|
2012-05-29 18:44:31 +00:00
|
|
|
}
|
2012-02-20 03:58:08 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-12-24 00:59:51 +00:00
|
|
|
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(WebGLShaderMallocSizeOf)
|
2012-02-20 03:58:08 +00:00
|
|
|
|
2012-05-23 16:07:01 +00:00
|
|
|
int64_t
|
2012-02-20 03:58:08 +00:00
|
|
|
WebGLMemoryMultiReporterWrapper::GetShaderSize() {
|
|
|
|
const ContextsArrayType & contexts = Contexts();
|
2012-05-23 16:07:01 +00:00
|
|
|
int64_t result = 0;
|
2012-05-29 18:44:31 +00:00
|
|
|
for(size_t i = 0; i < contexts.Length(); ++i) {
|
|
|
|
for (const WebGLShader *shader = contexts[i]->mShaders.getFirst();
|
|
|
|
shader;
|
|
|
|
shader = shader->getNext())
|
|
|
|
{
|
2012-12-24 00:59:51 +00:00
|
|
|
result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
|
2012-05-29 18:44:31 +00:00
|
|
|
}
|
2012-02-20 03:58:08 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|