content/canvas/src/WebGLContextReporter.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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(WebGLMemoryPressureObserver, nsIObserver)
    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)
    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;
    86 }
    88 NS_IMPL_ISUPPORTS(WebGLMemoryTracker, nsIMemoryReporter)
    90 StaticRefPtr<WebGLMemoryTracker> WebGLMemoryTracker::sUniqueInstance;
    92 WebGLMemoryTracker* WebGLMemoryTracker::UniqueInstance()
    93 {
    94     if (!sUniqueInstance) {
    95         sUniqueInstance = new WebGLMemoryTracker;
    96         sUniqueInstance->InitMemoryReporter();
    97     }
    98     return sUniqueInstance;
    99 }
   101 WebGLMemoryTracker::WebGLMemoryTracker()
   102 {
   103 }
   105 void
   106 WebGLMemoryTracker::InitMemoryReporter()
   107 {
   108     RegisterWeakMemoryReporter(this);
   109 }
   111 WebGLMemoryTracker::~WebGLMemoryTracker()
   112 {
   113     UnregisterWeakMemoryReporter(this);
   114 }
   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())
   126         {
   127             if (buffer->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
   128                 result += buffer->SizeOfIncludingThis(WebGLBufferMallocSizeOf);
   129         }
   130     }
   131     return result;
   132 }
   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())
   144         {
   145             result += shader->SizeOfIncludingThis(WebGLShaderMallocSizeOf);
   146         }
   147     }
   148     return result;
   149 }

mercurial