1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/gl/GfxTexturesReporter.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "GfxTexturesReporter.h" 1.11 +#include "GLDefs.h" 1.12 + 1.13 +using namespace mozilla; 1.14 +using namespace mozilla::gl; 1.15 + 1.16 +NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter) 1.17 + 1.18 +int64_t GfxTexturesReporter::sAmount = 0; 1.19 + 1.20 +static uint32_t 1.21 +GetBitsPerTexel(GLenum format, GLenum type) 1.22 +{ 1.23 + // If there is no defined format or type, we're not taking up any memory 1.24 + if (!format || !type) { 1.25 + return 0; 1.26 + } 1.27 + 1.28 + if (format == LOCAL_GL_DEPTH_COMPONENT) { 1.29 + if (type == LOCAL_GL_UNSIGNED_SHORT) 1.30 + return 2*8; 1.31 + else if (type == LOCAL_GL_UNSIGNED_INT) 1.32 + return 4*8; 1.33 + } else if (format == LOCAL_GL_DEPTH_STENCIL) { 1.34 + if (type == LOCAL_GL_UNSIGNED_INT_24_8_EXT) 1.35 + return 4*8; 1.36 + } 1.37 + 1.38 + if (type == LOCAL_GL_UNSIGNED_BYTE || type == LOCAL_GL_FLOAT) { 1.39 + uint32_t multiplier = type == LOCAL_GL_FLOAT ? 32 : 8; 1.40 + switch (format) { 1.41 + case LOCAL_GL_ALPHA: 1.42 + case LOCAL_GL_LUMINANCE: 1.43 + return 1 * multiplier; 1.44 + case LOCAL_GL_LUMINANCE_ALPHA: 1.45 + return 2 * multiplier; 1.46 + case LOCAL_GL_RGB: 1.47 + return 3 * multiplier; 1.48 + case LOCAL_GL_RGBA: 1.49 + return 4 * multiplier; 1.50 + case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1: 1.51 + case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1: 1.52 + return 2; 1.53 + case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 1.54 + case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 1.55 + case LOCAL_GL_ATC_RGB: 1.56 + case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1: 1.57 + case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1: 1.58 + case LOCAL_GL_ETC1_RGB8_OES: 1.59 + return 4; 1.60 + case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 1.61 + case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 1.62 + case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA: 1.63 + case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA: 1.64 + return 8; 1.65 + default: 1.66 + break; 1.67 + } 1.68 + } else if (type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 || 1.69 + type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 || 1.70 + type == LOCAL_GL_UNSIGNED_SHORT_5_6_5) 1.71 + { 1.72 + return 2*8; 1.73 + } 1.74 + 1.75 + MOZ_ASSERT(false); 1.76 + return 0; 1.77 +} 1.78 + 1.79 +/* static */ void 1.80 +GfxTexturesReporter::UpdateAmount(MemoryUse action, GLenum format, 1.81 + GLenum type, int32_t tileWidth, 1.82 + int32_t tileHeight) 1.83 +{ 1.84 + int64_t bitsPerTexel = GetBitsPerTexel(format, type); 1.85 + int64_t bytes = int64_t(tileWidth) * int64_t(tileHeight) * bitsPerTexel/8; 1.86 + if (action == MemoryFreed) { 1.87 + sAmount -= bytes; 1.88 + } else { 1.89 + sAmount += bytes; 1.90 + } 1.91 +}