/src/mozilla-central/dom/canvas/WebGLMemoryTracker.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #include "WebGLMemoryTracker.h" |
7 | | |
8 | | #include "WebGLBuffer.h" |
9 | | #include "WebGLContext.h" |
10 | | #include "WebGLVertexAttribData.h" |
11 | | #include "WebGLProgram.h" |
12 | | #include "WebGLRenderbuffer.h" |
13 | | #include "WebGLShader.h" |
14 | | #include "WebGLTexture.h" |
15 | | #include "WebGLUniformLocation.h" |
16 | | |
17 | | namespace mozilla { |
18 | | |
19 | | NS_IMETHODIMP |
20 | | WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport, |
21 | | nsISupports* aData, bool) |
22 | 0 | { |
23 | 0 | MOZ_COLLECT_REPORT( |
24 | 0 | "webgl-texture-memory", KIND_OTHER, UNITS_BYTES, GetTextureMemoryUsed(), |
25 | 0 | "Memory used by WebGL textures. The OpenGL implementation is free to " |
26 | 0 | "store these textures in either video memory or main memory. This " |
27 | 0 | "measurement is only a lower bound, actual memory usage may be higher " |
28 | 0 | "for example if the storage is strided."); |
29 | 0 |
|
30 | 0 | MOZ_COLLECT_REPORT( |
31 | 0 | "webgl-texture-count", KIND_OTHER, UNITS_COUNT, GetTextureCount(), |
32 | 0 | "Number of WebGL textures."); |
33 | 0 |
|
34 | 0 | MOZ_COLLECT_REPORT( |
35 | 0 | "webgl-buffer-memory", KIND_OTHER, UNITS_BYTES, GetBufferMemoryUsed(), |
36 | 0 | "Memory used by WebGL buffers. The OpenGL implementation is free to " |
37 | 0 | "store these buffers in either video memory or main memory. This " |
38 | 0 | "measurement is only a lower bound, actual memory usage may be higher " |
39 | 0 | "for example if the storage is strided."); |
40 | 0 |
|
41 | 0 | MOZ_COLLECT_REPORT( |
42 | 0 | "explicit/webgl/buffer-cache-memory", KIND_HEAP, UNITS_BYTES, |
43 | 0 | GetBufferCacheMemoryUsed(), |
44 | 0 | "Memory used by WebGL buffer caches. The WebGL implementation caches " |
45 | 0 | "the contents of element array buffers only. This adds up with the " |
46 | 0 | "'webgl-buffer-memory' value, but contrary to it, this one represents " |
47 | 0 | "bytes on the heap, not managed by OpenGL."); |
48 | 0 |
|
49 | 0 | MOZ_COLLECT_REPORT( |
50 | 0 | "webgl-buffer-count", KIND_OTHER, UNITS_COUNT, GetBufferCount(), |
51 | 0 | "Number of WebGL buffers."); |
52 | 0 |
|
53 | 0 | MOZ_COLLECT_REPORT( |
54 | 0 | "webgl-renderbuffer-memory", KIND_OTHER, UNITS_BYTES, |
55 | 0 | GetRenderbufferMemoryUsed(), |
56 | 0 | "Memory used by WebGL renderbuffers. The OpenGL implementation is free " |
57 | 0 | "to store these renderbuffers in either video memory or main memory. " |
58 | 0 | "This measurement is only a lower bound, actual memory usage may be " |
59 | 0 | "higher, for example if the storage is strided."); |
60 | 0 |
|
61 | 0 | MOZ_COLLECT_REPORT( |
62 | 0 | "webgl-renderbuffer-count", KIND_OTHER, UNITS_COUNT, |
63 | 0 | GetRenderbufferCount(), |
64 | 0 | "Number of WebGL renderbuffers."); |
65 | 0 |
|
66 | 0 | MOZ_COLLECT_REPORT( |
67 | 0 | "explicit/webgl/shader", KIND_HEAP, UNITS_BYTES, GetShaderSize(), |
68 | 0 | "Combined size of WebGL shader ASCII sources and translation logs " |
69 | 0 | "cached on the heap."); |
70 | 0 |
|
71 | 0 | MOZ_COLLECT_REPORT( |
72 | 0 | "webgl-shader-count", KIND_OTHER, UNITS_COUNT, GetShaderCount(), |
73 | 0 | "Number of WebGL shaders."); |
74 | 0 |
|
75 | 0 | MOZ_COLLECT_REPORT( |
76 | 0 | "webgl-context-count", KIND_OTHER, UNITS_COUNT, GetContextCount(), |
77 | 0 | "Number of WebGL contexts."); |
78 | 0 |
|
79 | 0 | return NS_OK; |
80 | 0 | } |
81 | | |
82 | | NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter) |
83 | | |
84 | | StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance; |
85 | | |
86 | | WebGLMemoryTracker* |
87 | | WebGLMemoryTracker::UniqueInstance() |
88 | 0 | { |
89 | 0 | if (!sUniqueInstance) { |
90 | 0 | sUniqueInstance = new WebGLMemoryTracker; |
91 | 0 | sUniqueInstance->InitMemoryReporter(); |
92 | 0 | } |
93 | 0 | return sUniqueInstance; |
94 | 0 | } |
95 | | |
96 | | WebGLMemoryTracker::WebGLMemoryTracker() |
97 | 0 | { |
98 | 0 | } |
99 | | |
100 | | void |
101 | | WebGLMemoryTracker::InitMemoryReporter() |
102 | 0 | { |
103 | 0 | RegisterWeakMemoryReporter(this); |
104 | 0 | } |
105 | | |
106 | | WebGLMemoryTracker::~WebGLMemoryTracker() |
107 | 0 | { |
108 | 0 | UnregisterWeakMemoryReporter(this); |
109 | 0 | } |
110 | | |
111 | | MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf) |
112 | | |
113 | | int64_t |
114 | | WebGLMemoryTracker::GetBufferCacheMemoryUsed() |
115 | 0 | { |
116 | 0 | const ContextsArrayType& contexts = Contexts(); |
117 | 0 | int64_t result = 0; |
118 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
119 | 0 | for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); |
120 | 0 | buffer; |
121 | 0 | buffer = buffer->getNext()) |
122 | 0 | { |
123 | 0 | if (buffer->Content() == WebGLBuffer::Kind::ElementArray) { |
124 | 0 | result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf); |
125 | 0 | } |
126 | 0 | } |
127 | 0 | } |
128 | 0 | return result; |
129 | 0 | } |
130 | | |
131 | | MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf) |
132 | | |
133 | | int64_t |
134 | | WebGLMemoryTracker::GetShaderSize() |
135 | 0 | { |
136 | 0 | const ContextsArrayType& contexts = Contexts(); |
137 | 0 | int64_t result = 0; |
138 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
139 | 0 | for (const WebGLShader* shader = contexts[i]->mShaders.getFirst(); |
140 | 0 | shader; |
141 | 0 | shader = shader->getNext()) |
142 | 0 | { |
143 | 0 | result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf); |
144 | 0 | } |
145 | 0 | } |
146 | 0 | return result; |
147 | 0 | } |
148 | | |
149 | | /*static*/ int64_t |
150 | | WebGLMemoryTracker::GetTextureMemoryUsed() |
151 | 0 | { |
152 | 0 | const ContextsArrayType & contexts = Contexts(); |
153 | 0 | int64_t result = 0; |
154 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
155 | 0 | for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst(); |
156 | 0 | texture; |
157 | 0 | texture = texture->getNext()) |
158 | 0 | { |
159 | 0 | result += texture->MemoryUsage(); |
160 | 0 | } |
161 | 0 | } |
162 | 0 | return result; |
163 | 0 | } |
164 | | |
165 | | /*static*/ int64_t |
166 | | WebGLMemoryTracker::GetTextureCount() |
167 | 0 | { |
168 | 0 | const ContextsArrayType & contexts = Contexts(); |
169 | 0 | int64_t result = 0; |
170 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
171 | 0 | for (const WebGLTexture* texture = contexts[i]->mTextures.getFirst(); |
172 | 0 | texture; |
173 | 0 | texture = texture->getNext()) |
174 | 0 | { |
175 | 0 | result++; |
176 | 0 | } |
177 | 0 | } |
178 | 0 | return result; |
179 | 0 | } |
180 | | |
181 | | /*static*/ int64_t |
182 | | WebGLMemoryTracker::GetBufferMemoryUsed() |
183 | 0 | { |
184 | 0 | const ContextsArrayType & contexts = Contexts(); |
185 | 0 | int64_t result = 0; |
186 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
187 | 0 | for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); |
188 | 0 | buffer; |
189 | 0 | buffer = buffer->getNext()) |
190 | 0 | { |
191 | 0 | result += buffer->ByteLength(); |
192 | 0 | } |
193 | 0 | } |
194 | 0 | return result; |
195 | 0 | } |
196 | | |
197 | | /*static*/ int64_t |
198 | | WebGLMemoryTracker::GetBufferCount() |
199 | 0 | { |
200 | 0 | const ContextsArrayType & contexts = Contexts(); |
201 | 0 | int64_t result = 0; |
202 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
203 | 0 | for (const WebGLBuffer* buffer = contexts[i]->mBuffers.getFirst(); |
204 | 0 | buffer; |
205 | 0 | buffer = buffer->getNext()) |
206 | 0 | { |
207 | 0 | result++; |
208 | 0 | } |
209 | 0 | } |
210 | 0 | return result; |
211 | 0 | } |
212 | | |
213 | | /*static*/ int64_t |
214 | | WebGLMemoryTracker::GetRenderbufferMemoryUsed() |
215 | 0 | { |
216 | 0 | const ContextsArrayType & contexts = Contexts(); |
217 | 0 | int64_t result = 0; |
218 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
219 | 0 | for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst(); |
220 | 0 | rb; |
221 | 0 | rb = rb->getNext()) |
222 | 0 | { |
223 | 0 | result += rb->MemoryUsage(); |
224 | 0 | } |
225 | 0 | } |
226 | 0 | return result; |
227 | 0 | } |
228 | | |
229 | | /*static*/ int64_t |
230 | | WebGLMemoryTracker::GetRenderbufferCount() |
231 | 0 | { |
232 | 0 | const ContextsArrayType & contexts = Contexts(); |
233 | 0 | int64_t result = 0; |
234 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
235 | 0 | for (const WebGLRenderbuffer* rb = contexts[i]->mRenderbuffers.getFirst(); |
236 | 0 | rb; |
237 | 0 | rb = rb->getNext()) |
238 | 0 | { |
239 | 0 | result++; |
240 | 0 | } |
241 | 0 | } |
242 | 0 | return result; |
243 | 0 | } |
244 | | |
245 | | /*static*/ int64_t |
246 | | WebGLMemoryTracker::GetShaderCount() |
247 | 0 | { |
248 | 0 | const ContextsArrayType & contexts = Contexts(); |
249 | 0 | int64_t result = 0; |
250 | 0 | for(size_t i = 0; i < contexts.Length(); ++i) { |
251 | 0 | for (const WebGLShader* shader = contexts[i]->mShaders.getFirst(); |
252 | 0 | shader; |
253 | 0 | shader = shader->getNext()) |
254 | 0 | { |
255 | 0 | result++; |
256 | 0 | } |
257 | 0 | } |
258 | 0 | return result; |
259 | 0 | } |
260 | | |
261 | | } // namespace mozilla |