/src/mozilla-central/dom/canvas/WebGLMemoryTracker.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; 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 | | #ifndef WEBGL_MEMORY_TRACKER_H_ |
7 | | #define WEBGL_MEMORY_TRACKER_H_ |
8 | | |
9 | | #include "mozilla/StaticPtr.h" |
10 | | #include "nsIMemoryReporter.h" |
11 | | |
12 | | namespace mozilla { |
13 | | |
14 | | class WebGLContext; |
15 | | |
16 | | class WebGLMemoryTracker : public nsIMemoryReporter |
17 | | { |
18 | | NS_DECL_THREADSAFE_ISUPPORTS |
19 | | NS_DECL_NSIMEMORYREPORTER |
20 | | |
21 | | WebGLMemoryTracker(); |
22 | | static StaticRefPtr<WebGLMemoryTracker> sUniqueInstance; |
23 | | |
24 | | // Here we store plain pointers, not RefPtrs: we don't want the |
25 | | // WebGLMemoryTracker unique instance to keep alive all |
26 | | // WebGLContexts ever created. |
27 | | typedef nsTArray<const WebGLContext*> ContextsArrayType; |
28 | | ContextsArrayType mContexts; |
29 | | |
30 | | void InitMemoryReporter(); |
31 | | |
32 | | static WebGLMemoryTracker* UniqueInstance(); |
33 | | |
34 | 0 | static ContextsArrayType& Contexts() { return UniqueInstance()->mContexts; } |
35 | | |
36 | | friend class WebGLContext; |
37 | | |
38 | | public: |
39 | | |
40 | 0 | static void AddWebGLContext(const WebGLContext* c) { |
41 | 0 | Contexts().AppendElement(c); |
42 | 0 | } |
43 | | |
44 | 0 | static void RemoveWebGLContext(const WebGLContext* c) { |
45 | 0 | ContextsArrayType & contexts = Contexts(); |
46 | 0 | contexts.RemoveElement(c); |
47 | 0 | if (contexts.IsEmpty()) { |
48 | 0 | sUniqueInstance = nullptr; |
49 | 0 | } |
50 | 0 | } |
51 | | |
52 | | private: |
53 | | virtual ~WebGLMemoryTracker(); |
54 | | |
55 | | static int64_t GetTextureMemoryUsed(); |
56 | | |
57 | | static int64_t GetTextureCount(); |
58 | | |
59 | | static int64_t GetBufferMemoryUsed(); |
60 | | |
61 | | static int64_t GetBufferCacheMemoryUsed(); |
62 | | |
63 | | static int64_t GetBufferCount(); |
64 | | |
65 | | static int64_t GetRenderbufferMemoryUsed(); |
66 | | |
67 | | static int64_t GetRenderbufferCount(); |
68 | | |
69 | | static int64_t GetShaderSize(); |
70 | | |
71 | | static int64_t GetShaderCount(); |
72 | | |
73 | 0 | static int64_t GetContextCount() { |
74 | 0 | return Contexts().Length(); |
75 | 0 | } |
76 | | }; |
77 | | |
78 | | } // namespace mozilla |
79 | | |
80 | | #endif // WEBGL_MEMORY_TRACKER_H_ |