michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "GfxTexturesReporter.h" michael@0: #include "GLDefs.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::gl; michael@0: michael@0: NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter) michael@0: michael@0: int64_t GfxTexturesReporter::sAmount = 0; michael@0: michael@0: static uint32_t michael@0: GetBitsPerTexel(GLenum format, GLenum type) michael@0: { michael@0: // If there is no defined format or type, we're not taking up any memory michael@0: if (!format || !type) { michael@0: return 0; michael@0: } michael@0: michael@0: if (format == LOCAL_GL_DEPTH_COMPONENT) { michael@0: if (type == LOCAL_GL_UNSIGNED_SHORT) michael@0: return 2*8; michael@0: else if (type == LOCAL_GL_UNSIGNED_INT) michael@0: return 4*8; michael@0: } else if (format == LOCAL_GL_DEPTH_STENCIL) { michael@0: if (type == LOCAL_GL_UNSIGNED_INT_24_8_EXT) michael@0: return 4*8; michael@0: } michael@0: michael@0: if (type == LOCAL_GL_UNSIGNED_BYTE || type == LOCAL_GL_FLOAT) { michael@0: uint32_t multiplier = type == LOCAL_GL_FLOAT ? 32 : 8; michael@0: switch (format) { michael@0: case LOCAL_GL_ALPHA: michael@0: case LOCAL_GL_LUMINANCE: michael@0: return 1 * multiplier; michael@0: case LOCAL_GL_LUMINANCE_ALPHA: michael@0: return 2 * multiplier; michael@0: case LOCAL_GL_RGB: michael@0: return 3 * multiplier; michael@0: case LOCAL_GL_RGBA: michael@0: return 4 * multiplier; michael@0: case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1: michael@0: case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1: michael@0: return 2; michael@0: case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT: michael@0: case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: michael@0: case LOCAL_GL_ATC_RGB: michael@0: case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1: michael@0: case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1: michael@0: case LOCAL_GL_ETC1_RGB8_OES: michael@0: return 4; michael@0: case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: michael@0: case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: michael@0: case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA: michael@0: case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA: michael@0: return 8; michael@0: default: michael@0: break; michael@0: } michael@0: } else if (type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 || michael@0: type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 || michael@0: type == LOCAL_GL_UNSIGNED_SHORT_5_6_5) michael@0: { michael@0: return 2*8; michael@0: } michael@0: michael@0: MOZ_ASSERT(false); michael@0: return 0; michael@0: } michael@0: michael@0: /* static */ void michael@0: GfxTexturesReporter::UpdateAmount(MemoryUse action, GLenum format, michael@0: GLenum type, int32_t tileWidth, michael@0: int32_t tileHeight) michael@0: { michael@0: int64_t bitsPerTexel = GetBitsPerTexel(format, type); michael@0: int64_t bytes = int64_t(tileWidth) * int64_t(tileHeight) * bitsPerTexel/8; michael@0: if (action == MemoryFreed) { michael@0: sAmount -= bytes; michael@0: } else { michael@0: sAmount += bytes; michael@0: } michael@0: }