Bumping manifests a=b2g-bump
[gecko.git] / dom / canvas / WebGLContextReporter.cpp
blob0135467c1fedff9f59e449280b2e38dfa0f0070c
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLContext.h"
7 #include "WebGLMemoryTracker.h"
9 using namespace mozilla;
11 NS_IMPL_ISUPPORTS(WebGLObserver, nsIObserver)
13 NS_IMETHODIMP
14 WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
15 nsISupports* aData, bool aAnonymize)
17 #define REPORT(_path, _kind, _units, _amount, _desc) \
18 do { \
19 nsresult rv; \
20 rv = aHandleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
21 _kind, _units, _amount, \
22 NS_LITERAL_CSTRING(_desc), aData); \
23 NS_ENSURE_SUCCESS(rv, rv); \
24 } while (0)
26 REPORT("webgl-texture-memory",
27 KIND_OTHER, UNITS_BYTES, GetTextureMemoryUsed(),
28 "Memory used by WebGL textures.The OpenGL"
29 " implementation is free to store these textures in either video"
30 " memory or main memory. This measurement is only a lower bound,"
31 " actual memory usage may be higher for example if the storage"
32 " is strided.");
34 REPORT("webgl-texture-count",
35 KIND_OTHER, UNITS_COUNT, GetTextureCount(),
36 "Number of WebGL textures.");
38 REPORT("webgl-buffer-memory",
39 KIND_OTHER, UNITS_BYTES, GetBufferMemoryUsed(),
40 "Memory used by WebGL buffers. The OpenGL"
41 " implementation is free to store these buffers in either video"
42 " memory or main memory. This measurement is only a lower bound,"
43 " actual memory usage may be higher for example if the storage"
44 " is strided.");
46 REPORT("explicit/webgl/buffer-cache-memory",
47 KIND_HEAP, UNITS_BYTES, GetBufferCacheMemoryUsed(),
48 "Memory used by WebGL buffer caches. The WebGL"
49 " implementation caches the contents of element array buffers"
50 " only.This adds up with the webgl-buffer-memory value, but"
51 " contrary to it, this one represents bytes on the heap,"
52 " not managed by OpenGL.");
54 REPORT("webgl-buffer-count",
55 KIND_OTHER, UNITS_COUNT, GetBufferCount(),
56 "Number of WebGL buffers.");
58 REPORT("webgl-renderbuffer-memory",
59 KIND_OTHER, UNITS_BYTES, GetRenderbufferMemoryUsed(),
60 "Memory used by WebGL renderbuffers. The OpenGL"
61 " implementation is free to store these renderbuffers in either"
62 " video memory or main memory. This measurement is only a lower"
63 " bound, actual memory usage may be higher for example if the"
64 " storage is strided.");
66 REPORT("webgl-renderbuffer-count",
67 KIND_OTHER, UNITS_COUNT, GetRenderbufferCount(),
68 "Number of WebGL renderbuffers.");
70 REPORT("explicit/webgl/shader",
71 KIND_HEAP, UNITS_BYTES, GetShaderSize(),
72 "Combined size of WebGL shader ASCII sources and translation"
73 " logs cached on the heap.");
75 REPORT("webgl-shader-count",
76 KIND_OTHER, UNITS_COUNT, GetShaderCount(),
77 "Number of WebGL shaders.");
79 REPORT("webgl-context-count",
80 KIND_OTHER, UNITS_COUNT, GetContextCount(),
81 "Number of WebGL contexts.");
83 #undef REPORT
85 return NS_OK;
88 NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter)
90 StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance;
92 WebGLMemoryTracker* WebGLMemoryTracker::UniqueInstance()
94 if (!sUniqueInstance) {
95 sUniqueInstance = new WebGLMemoryTracker;
96 sUniqueInstance->InitMemoryReporter();
98 return sUniqueInstance;
101 WebGLMemoryTracker::WebGLMemoryTracker()
105 void
106 WebGLMemoryTracker::InitMemoryReporter()
108 RegisterWeakMemoryReporter(this);
111 WebGLMemoryTracker::~WebGLMemoryTracker()
113 UnregisterWeakMemoryReporter(this);
116 MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf)
118 int64_t
119 WebGLMemoryTracker::GetBufferCacheMemoryUsed() {
120 const ContextsArrayType & contexts = Contexts();
121 int64_t result = 0;
122 for(size_t i = 0; i < contexts.Length(); ++i) {
123 for (const WebGLBuffer *buffer = contexts[i]->mBuffers.getFirst();
124 buffer;
125 buffer = buffer->getNext())
127 if (buffer->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
128 result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf);
131 return result;
134 MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf)
136 int64_t
137 WebGLMemoryTracker::GetShaderSize() {
138 const ContextsArrayType & contexts = Contexts();
139 int64_t result = 0;
140 for(size_t i = 0; i < contexts.Length(); ++i) {
141 for (const WebGLShader *shader = contexts[i]->mShaders.getFirst();
142 shader;
143 shader = shader->getNext())
145 result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
148 return result;