1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org
.mozilla
.gecko
.gfx
;
8 import android
.opengl
.GLES20
;
9 import android
.util
.Log
;
11 import java
.util
.ArrayList
;
14 * Manages a list of dead tiles, so we don't leak resources.
16 public class TextureReaper
{
17 private static TextureReaper sSharedInstance
;
18 private ArrayList
<Integer
> mDeadTextureIDs
= new ArrayList
<Integer
>();
19 private static final String LOGTAG
= TextureReaper
.class.getSimpleName();
21 private TextureReaper() {
24 public static TextureReaper
get() {
25 if (sSharedInstance
== null) {
26 sSharedInstance
= new TextureReaper();
28 return sSharedInstance
;
31 public void add(int[] textureIDs
) {
32 for (int textureID
: textureIDs
) {
37 public synchronized void add(int textureID
) {
38 mDeadTextureIDs
.add(textureID
);
41 public synchronized void reap() {
42 int numTextures
= mDeadTextureIDs
.size();
43 // Adreno 200 will generate INVALID_VALUE if len == 0 is passed to glDeleteTextures,
44 // even though it's not supposed to.
48 int[] deadTextureIDs
= new int[numTextures
];
49 for (int i
= 0; i
< numTextures
; i
++) {
50 Integer id
= mDeadTextureIDs
.get(i
);
52 deadTextureIDs
[i
] = 0;
53 Log
.e(LOGTAG
, "Dead texture id is null");
55 deadTextureIDs
[i
] = mDeadTextureIDs
.get(i
);
58 mDeadTextureIDs
.clear();
60 GLES20
.glDeleteTextures(deadTextureIDs
.length
, deadTextureIDs
, 0);