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