LCOV - code coverage report
Current view: directory - content/canvas/src - WebGLContextReporter.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 48 0 0.0 %
Date: 2012-06-02 Functions: 14 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  *   Mozilla Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "WebGLContext.h"
      40                 : #include "nsIMemoryReporter.h"
      41                 : 
      42                 : using namespace mozilla;
      43                 : 
      44                 : 
      45                 : class WebGLMemoryMultiReporter MOZ_FINAL : public nsIMemoryMultiReporter 
      46               0 : {
      47                 :   public:
      48                 :     NS_DECL_ISUPPORTS
      49                 :     NS_DECL_NSIMEMORYMULTIREPORTER
      50                 : };
      51                 : 
      52               0 : NS_IMPL_ISUPPORTS1(WebGLMemoryMultiReporter, nsIMemoryMultiReporter)
      53                 : 
      54                 : NS_IMETHODIMP
      55               0 : WebGLMemoryMultiReporter::GetName(nsACString &aName)
      56                 : {
      57               0 :   aName.AssignLiteral("webgl");
      58               0 :   return NS_OK;
      59                 : }
      60                 : 
      61                 : NS_IMETHODIMP
      62               0 : WebGLMemoryMultiReporter::GetExplicitNonHeap(PRInt64 *aAmount)
      63                 : {
      64                 :     // WebGLMemoryMultiReporterWrapper has no KIND_NONHEAP measurements.
      65               0 :     *aAmount = 0;
      66               0 :     return NS_OK;
      67                 : }
      68                 : 
      69                 : NS_IMETHODIMP
      70               0 : WebGLMemoryMultiReporter::CollectReports(nsIMemoryMultiReporterCallback* aCb, 
      71                 :                                          nsISupports* aClosure)
      72                 : {
      73                 : #define REPORT(_path, _kind, _units, _amount, _desc)                          \
      74                 :     do {                                                                      \
      75                 :       nsresult rv;                                                            \
      76                 :       rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), _kind,    \
      77                 :                          _units, _amount, NS_LITERAL_CSTRING(_desc),          \
      78                 :                          aClosure);                                           \
      79                 :       NS_ENSURE_SUCCESS(rv, rv);                                              \
      80                 :     } while (0)
      81                 : 
      82               0 :     REPORT("webgl-texture-memory",
      83                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES,
      84                 :            WebGLMemoryMultiReporterWrapper::GetTextureMemoryUsed(),
      85                 :            "Memory used by WebGL textures.The OpenGL"
      86                 :            " implementation is free to store these textures in either video"
      87                 :            " memory or main memory. This measurement is only a lower bound,"
      88                 :            " actual memory usage may be higher for example if the storage" 
      89                 :            " is strided.");
      90                 :    
      91               0 :     REPORT("webgl-texture-count",
      92                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
      93                 :            WebGLMemoryMultiReporterWrapper::GetTextureCount(), 
      94                 :            "Number of WebGL textures.");
      95                 : 
      96               0 :     REPORT("webgl-buffer-memory",
      97                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES,
      98                 :            WebGLMemoryMultiReporterWrapper::GetBufferMemoryUsed(), 
      99                 :            "Memory used by WebGL buffers. The OpenGL"
     100                 :            " implementation is free to store these buffers in either video"
     101                 :            " memory or main memory. This measurement is only a lower bound,"
     102                 :            " actual memory usage may be higher for example if the storage"
     103                 :            " is strided.");
     104                 : 
     105               0 :     REPORT("explicit/webgl/buffer-cache-memory",
     106                 :            nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
     107                 :            WebGLMemoryMultiReporterWrapper::GetBufferCacheMemoryUsed(),
     108                 :            "Memory used by WebGL buffer caches. The WebGL"
     109                 :            " implementation caches the contents of element array buffers"
     110                 :            " only.This adds up with the webgl-buffer-memory value, but"
     111                 :            " contrary to it, this one represents bytes on the heap,"
     112                 :            " not managed by OpenGL.");
     113                 : 
     114               0 :     REPORT("webgl-buffer-count",
     115                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
     116                 :            WebGLMemoryMultiReporterWrapper::GetBufferCount(),
     117                 :            "Number of WebGL buffers."); 
     118                 :    
     119               0 :     REPORT("webgl-renderbuffer-memory",
     120                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_BYTES,
     121                 :            WebGLMemoryMultiReporterWrapper::GetRenderbufferMemoryUsed(), 
     122                 :            "Memory used by WebGL renderbuffers. The OpenGL"
     123                 :            " implementation is free to store these renderbuffers in either"
     124                 :            " video memory or main memory. This measurement is only a lower"
     125                 :            " bound, actual memory usage may be higher for example if the"
     126                 :            " storage is strided.");
     127                 :    
     128               0 :     REPORT("webgl-renderbuffer-count",
     129                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
     130                 :            WebGLMemoryMultiReporterWrapper::GetRenderbufferCount(),
     131                 :            "Number of WebGL renderbuffers.");
     132                 :   
     133               0 :     REPORT("explicit/webgl/shader",
     134                 :            nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
     135                 :            WebGLMemoryMultiReporterWrapper::GetShaderSize(), 
     136                 :            "Combined size of WebGL shader ASCII sources and translation"
     137                 :            " logs cached on the heap."); 
     138                 : 
     139               0 :     REPORT("webgl-shader-count",
     140                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
     141                 :            WebGLMemoryMultiReporterWrapper::GetShaderCount(), 
     142                 :            "Number of WebGL shaders."); 
     143                 : 
     144               0 :     REPORT("webgl-context-count",
     145                 :            nsIMemoryReporter::KIND_OTHER, nsIMemoryReporter::UNITS_COUNT,
     146                 :            WebGLMemoryMultiReporterWrapper::GetContextCount(), 
     147                 :            "Number of WebGL contexts."); 
     148                 : 
     149                 : #undef REPORT
     150                 : 
     151               0 :     return NS_OK;
     152                 : }
     153                 : 
     154                 : WebGLMemoryMultiReporterWrapper* WebGLMemoryMultiReporterWrapper::sUniqueInstance = nsnull;
     155                 : 
     156               0 : WebGLMemoryMultiReporterWrapper* WebGLMemoryMultiReporterWrapper::UniqueInstance()
     157                 : {
     158               0 :     if (!sUniqueInstance) {
     159               0 :         sUniqueInstance = new WebGLMemoryMultiReporterWrapper;
     160                 :     }
     161               0 :     return sUniqueInstance;     
     162                 : }
     163                 : 
     164               0 : WebGLMemoryMultiReporterWrapper::WebGLMemoryMultiReporterWrapper()
     165                 : { 
     166               0 :     mReporter = new WebGLMemoryMultiReporter;   
     167               0 :     NS_RegisterMemoryMultiReporter(mReporter);
     168               0 : }
     169                 : 
     170               0 : WebGLMemoryMultiReporterWrapper::~WebGLMemoryMultiReporterWrapper()
     171                 : {
     172               0 :     NS_UnregisterMemoryMultiReporter(mReporter);
     173               0 : }
     174                 : 
     175               0 : NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(WebGLBufferMallocSizeOfFun, "webgl-buffer")
     176                 : 
     177                 : PRInt64 
     178               0 : WebGLMemoryMultiReporterWrapper::GetBufferCacheMemoryUsed() {
     179               0 :     const ContextsArrayType & contexts = Contexts();
     180               0 :     PRInt64 result = 0;
     181               0 :     for (size_t i = 0; i < contexts.Length(); ++i) {
     182               0 :         for (size_t j = 0; j < contexts[i]->mBuffers.Length(); ++j) 
     183               0 :             if (contexts[i]->mBuffers[j]->Target() == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
     184               0 :                result += contexts[i]->mBuffers[j]->SizeOfIncludingThis(WebGLBufferMallocSizeOfFun);
     185                 :     }
     186               0 :     return result;
     187                 : }
     188                 : 
     189               0 : NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(WebGLShaderMallocSizeOfFun, "webgl-shader")
     190                 : 
     191                 : PRInt64 
     192               0 : WebGLMemoryMultiReporterWrapper::GetShaderSize() {
     193               0 :     const ContextsArrayType & contexts = Contexts();
     194               0 :     PRInt64 result = 0;
     195               0 :     for (size_t i = 0; i < contexts.Length(); ++i) {
     196               0 :         for (size_t j = 0; j < contexts[i]->mShaders.Length(); ++j) 
     197               0 :             result += contexts[i]->mShaders[j]->SizeOfIncludingThis(WebGLShaderMallocSizeOfFun);
     198                 :     }
     199               0 :     return result;
     200                 : }

Generated by: LCOV version 1.7