gfx/gl/GfxTexturesReporter.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "GfxTexturesReporter.h"
michael@0 8 #include "GLDefs.h"
michael@0 9
michael@0 10 using namespace mozilla;
michael@0 11 using namespace mozilla::gl;
michael@0 12
michael@0 13 NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter)
michael@0 14
michael@0 15 int64_t GfxTexturesReporter::sAmount = 0;
michael@0 16
michael@0 17 static uint32_t
michael@0 18 GetBitsPerTexel(GLenum format, GLenum type)
michael@0 19 {
michael@0 20 // If there is no defined format or type, we're not taking up any memory
michael@0 21 if (!format || !type) {
michael@0 22 return 0;
michael@0 23 }
michael@0 24
michael@0 25 if (format == LOCAL_GL_DEPTH_COMPONENT) {
michael@0 26 if (type == LOCAL_GL_UNSIGNED_SHORT)
michael@0 27 return 2*8;
michael@0 28 else if (type == LOCAL_GL_UNSIGNED_INT)
michael@0 29 return 4*8;
michael@0 30 } else if (format == LOCAL_GL_DEPTH_STENCIL) {
michael@0 31 if (type == LOCAL_GL_UNSIGNED_INT_24_8_EXT)
michael@0 32 return 4*8;
michael@0 33 }
michael@0 34
michael@0 35 if (type == LOCAL_GL_UNSIGNED_BYTE || type == LOCAL_GL_FLOAT) {
michael@0 36 uint32_t multiplier = type == LOCAL_GL_FLOAT ? 32 : 8;
michael@0 37 switch (format) {
michael@0 38 case LOCAL_GL_ALPHA:
michael@0 39 case LOCAL_GL_LUMINANCE:
michael@0 40 return 1 * multiplier;
michael@0 41 case LOCAL_GL_LUMINANCE_ALPHA:
michael@0 42 return 2 * multiplier;
michael@0 43 case LOCAL_GL_RGB:
michael@0 44 return 3 * multiplier;
michael@0 45 case LOCAL_GL_RGBA:
michael@0 46 return 4 * multiplier;
michael@0 47 case LOCAL_GL_COMPRESSED_RGB_PVRTC_2BPPV1:
michael@0 48 case LOCAL_GL_COMPRESSED_RGBA_PVRTC_2BPPV1:
michael@0 49 return 2;
michael@0 50 case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
michael@0 51 case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
michael@0 52 case LOCAL_GL_ATC_RGB:
michael@0 53 case LOCAL_GL_COMPRESSED_RGB_PVRTC_4BPPV1:
michael@0 54 case LOCAL_GL_COMPRESSED_RGBA_PVRTC_4BPPV1:
michael@0 55 case LOCAL_GL_ETC1_RGB8_OES:
michael@0 56 return 4;
michael@0 57 case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
michael@0 58 case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
michael@0 59 case LOCAL_GL_ATC_RGBA_EXPLICIT_ALPHA:
michael@0 60 case LOCAL_GL_ATC_RGBA_INTERPOLATED_ALPHA:
michael@0 61 return 8;
michael@0 62 default:
michael@0 63 break;
michael@0 64 }
michael@0 65 } else if (type == LOCAL_GL_UNSIGNED_SHORT_4_4_4_4 ||
michael@0 66 type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 ||
michael@0 67 type == LOCAL_GL_UNSIGNED_SHORT_5_6_5)
michael@0 68 {
michael@0 69 return 2*8;
michael@0 70 }
michael@0 71
michael@0 72 MOZ_ASSERT(false);
michael@0 73 return 0;
michael@0 74 }
michael@0 75
michael@0 76 /* static */ void
michael@0 77 GfxTexturesReporter::UpdateAmount(MemoryUse action, GLenum format,
michael@0 78 GLenum type, int32_t tileWidth,
michael@0 79 int32_t tileHeight)
michael@0 80 {
michael@0 81 int64_t bitsPerTexel = GetBitsPerTexel(format, type);
michael@0 82 int64_t bytes = int64_t(tileWidth) * int64_t(tileHeight) * bitsPerTexel/8;
michael@0 83 if (action == MemoryFreed) {
michael@0 84 sAmount -= bytes;
michael@0 85 } else {
michael@0 86 sAmount += bytes;
michael@0 87 }
michael@0 88 }

mercurial