content/canvas/src/WebGLContextReporter.cpp

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:d41d1dac5b0c
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 "WebGLContext.h"
7 #include "WebGLMemoryTracker.h"
8
9 using namespace mozilla;
10
11 NS_IMPL_ISUPPORTS(WebGLMemoryPressureObserver, nsIObserver)
12
13 NS_IMETHODIMP
14 WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
15 nsISupports* aData)
16 {
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)
25
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.");
33
34 REPORT("webgl-texture-count",
35 KIND_OTHER, UNITS_COUNT, GetTextureCount(),
36 "Number of WebGL textures.");
37
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.");
45
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.");
53
54 REPORT("webgl-buffer-count",
55 KIND_OTHER, UNITS_COUNT, GetBufferCount(),
56 "Number of WebGL buffers.");
57
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.");
65
66 REPORT("webgl-renderbuffer-count",
67 KIND_OTHER, UNITS_COUNT, GetRenderbufferCount(),
68 "Number of WebGL renderbuffers.");
69
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.");
74
75 REPORT("webgl-shader-count",
76 KIND_OTHER, UNITS_COUNT, GetShaderCount(),
77 "Number of WebGL shaders.");
78
79 REPORT("webgl-context-count",
80 KIND_OTHER, UNITS_COUNT, GetContextCount(),
81 "Number of WebGL contexts.");
82
83 #undef REPORT
84
85 return NS_OK;
86 }
87
88 NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter)
89
90 StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance;
91
92 WebGLMemoryTracker* WebGLMemoryTracker::UniqueInstance()
93 {
94 if (!sUniqueInstance) {
95 sUniqueInstance = new WebGLMemoryTracker;
96 sUniqueInstance->InitMemoryReporter();
97 }
98 return sUniqueInstance;
99 }
100
101 WebGLMemoryTracker::WebGLMemoryTracker()
102 {
103 }
104
105 void
106 WebGLMemoryTracker::InitMemoryReporter()
107 {
108 RegisterWeakMemoryReporter(this);
109 }
110
111 WebGLMemoryTracker::~WebGLMemoryTracker()
112 {
113 UnregisterWeakMemoryReporter(this);
114 }
115
116 MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf)
117
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())
126 {
127 if (buffer->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
128 result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf);
129 }
130 }
131 return result;
132 }
133
134 MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf)
135
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())
144 {
145 result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
146 }
147 }
148 return result;
149 }

mercurial