Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "WebGLContext.h" |
michael@0 | 7 | #include "WebGLMemoryTracker.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace mozilla; |
michael@0 | 10 | |
michael@0 | 11 | NS_IMPL_ISUPPORTS(WebGLMemoryPressureObserver, nsIObserver) |
michael@0 | 12 | |
michael@0 | 13 | NS_IMETHODIMP |
michael@0 | 14 | WebGLMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport, |
michael@0 | 15 | nsISupports* aData) |
michael@0 | 16 | { |
michael@0 | 17 | #define REPORT(_path, _kind, _units, _amount, _desc) \ |
michael@0 | 18 | do { \ |
michael@0 | 19 | nsresult rv; \ |
michael@0 | 20 | rv = aHandleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \ |
michael@0 | 21 | _kind, _units, _amount, \ |
michael@0 | 22 | NS_LITERAL_CSTRING(_desc), aData); \ |
michael@0 | 23 | NS_ENSURE_SUCCESS(rv, rv); \ |
michael@0 | 24 | } while (0) |
michael@0 | 25 | |
michael@0 | 26 | REPORT("webgl-texture-memory", |
michael@0 | 27 | KIND_OTHER, UNITS_BYTES, GetTextureMemoryUsed(), |
michael@0 | 28 | "Memory used by WebGL textures.The OpenGL" |
michael@0 | 29 | " implementation is free to store these textures in either video" |
michael@0 | 30 | " memory or main memory. This measurement is only a lower bound," |
michael@0 | 31 | " actual memory usage may be higher for example if the storage" |
michael@0 | 32 | " is strided."); |
michael@0 | 33 | |
michael@0 | 34 | REPORT("webgl-texture-count", |
michael@0 | 35 | KIND_OTHER, UNITS_COUNT, GetTextureCount(), |
michael@0 | 36 | "Number of WebGL textures."); |
michael@0 | 37 | |
michael@0 | 38 | REPORT("webgl-buffer-memory", |
michael@0 | 39 | KIND_OTHER, UNITS_BYTES, GetBufferMemoryUsed(), |
michael@0 | 40 | "Memory used by WebGL buffers. The OpenGL" |
michael@0 | 41 | " implementation is free to store these buffers in either video" |
michael@0 | 42 | " memory or main memory. This measurement is only a lower bound," |
michael@0 | 43 | " actual memory usage may be higher for example if the storage" |
michael@0 | 44 | " is strided."); |
michael@0 | 45 | |
michael@0 | 46 | REPORT("explicit/webgl/buffer-cache-memory", |
michael@0 | 47 | KIND_HEAP, UNITS_BYTES, GetBufferCacheMemoryUsed(), |
michael@0 | 48 | "Memory used by WebGL buffer caches. The WebGL" |
michael@0 | 49 | " implementation caches the contents of element array buffers" |
michael@0 | 50 | " only.This adds up with the webgl-buffer-memory value, but" |
michael@0 | 51 | " contrary to it, this one represents bytes on the heap," |
michael@0 | 52 | " not managed by OpenGL."); |
michael@0 | 53 | |
michael@0 | 54 | REPORT("webgl-buffer-count", |
michael@0 | 55 | KIND_OTHER, UNITS_COUNT, GetBufferCount(), |
michael@0 | 56 | "Number of WebGL buffers."); |
michael@0 | 57 | |
michael@0 | 58 | REPORT("webgl-renderbuffer-memory", |
michael@0 | 59 | KIND_OTHER, UNITS_BYTES, GetRenderbufferMemoryUsed(), |
michael@0 | 60 | "Memory used by WebGL renderbuffers. The OpenGL" |
michael@0 | 61 | " implementation is free to store these renderbuffers in either" |
michael@0 | 62 | " video memory or main memory. This measurement is only a lower" |
michael@0 | 63 | " bound, actual memory usage may be higher for example if the" |
michael@0 | 64 | " storage is strided."); |
michael@0 | 65 | |
michael@0 | 66 | REPORT("webgl-renderbuffer-count", |
michael@0 | 67 | KIND_OTHER, UNITS_COUNT, GetRenderbufferCount(), |
michael@0 | 68 | "Number of WebGL renderbuffers."); |
michael@0 | 69 | |
michael@0 | 70 | REPORT("explicit/webgl/shader", |
michael@0 | 71 | KIND_HEAP, UNITS_BYTES, GetShaderSize(), |
michael@0 | 72 | "Combined size of WebGL shader ASCII sources and translation" |
michael@0 | 73 | " logs cached on the heap."); |
michael@0 | 74 | |
michael@0 | 75 | REPORT("webgl-shader-count", |
michael@0 | 76 | KIND_OTHER, UNITS_COUNT, GetShaderCount(), |
michael@0 | 77 | "Number of WebGL shaders."); |
michael@0 | 78 | |
michael@0 | 79 | REPORT("webgl-context-count", |
michael@0 | 80 | KIND_OTHER, UNITS_COUNT, GetContextCount(), |
michael@0 | 81 | "Number of WebGL contexts."); |
michael@0 | 82 | |
michael@0 | 83 | #undef REPORT |
michael@0 | 84 | |
michael@0 | 85 | return NS_OK; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter) |
michael@0 | 89 | |
michael@0 | 90 | StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance; |
michael@0 | 91 | |
michael@0 | 92 | WebGLMemoryTracker* WebGLMemoryTracker::UniqueInstance() |
michael@0 | 93 | { |
michael@0 | 94 | if (!sUniqueInstance) { |
michael@0 | 95 | sUniqueInstance = new WebGLMemoryTracker; |
michael@0 | 96 | sUniqueInstance->InitMemoryReporter(); |
michael@0 | 97 | } |
michael@0 | 98 | return sUniqueInstance; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | WebGLMemoryTracker::WebGLMemoryTracker() |
michael@0 | 102 | { |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | void |
michael@0 | 106 | WebGLMemoryTracker::InitMemoryReporter() |
michael@0 | 107 | { |
michael@0 | 108 | RegisterWeakMemoryReporter(this); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | WebGLMemoryTracker::~WebGLMemoryTracker() |
michael@0 | 112 | { |
michael@0 | 113 | UnregisterWeakMemoryReporter(this); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | MOZ_DEFINE_MALLOC_SIZE_OF(WebGLBufferMallocSizeOf) |
michael@0 | 117 | |
michael@0 | 118 | int64_t |
michael@0 | 119 | WebGLMemoryTracker::GetBufferCacheMemoryUsed() { |
michael@0 | 120 | const ContextsArrayType & contexts = Contexts(); |
michael@0 | 121 | int64_t result = 0; |
michael@0 | 122 | for(size_t i = 0; i < contexts.Length(); ++i) { |
michael@0 | 123 | for (const WebGLBuffer *buffer = contexts[i]->mBuffers.getFirst(); |
michael@0 | 124 | buffer; |
michael@0 | 125 | buffer = buffer->getNext()) |
michael@0 | 126 | { |
michael@0 | 127 | if (buffer->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER) |
michael@0 | 128 | result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf); |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | return result; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | MOZ_DEFINE_MALLOC_SIZE_OF(WebGLShaderMallocSizeOf) |
michael@0 | 135 | |
michael@0 | 136 | int64_t |
michael@0 | 137 | WebGLMemoryTracker::GetShaderSize() { |
michael@0 | 138 | const ContextsArrayType & contexts = Contexts(); |
michael@0 | 139 | int64_t result = 0; |
michael@0 | 140 | for(size_t i = 0; i < contexts.Length(); ++i) { |
michael@0 | 141 | for (const WebGLShader *shader = contexts[i]->mShaders.getFirst(); |
michael@0 | 142 | shader; |
michael@0 | 143 | shader = shader->getNext()) |
michael@0 | 144 | { |
michael@0 | 145 | result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf); |
michael@0 | 146 | } |
michael@0 | 147 | } |
michael@0 | 148 | return result; |
michael@0 | 149 | } |