michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 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: package org.mozilla.gecko.gfx; michael@0: michael@0: import android.opengl.GLES20; michael@0: michael@0: import java.util.ArrayList; michael@0: michael@0: /** Manages a list of dead tiles, so we don't leak resources. */ michael@0: public class TextureReaper { michael@0: private static TextureReaper sSharedInstance; michael@0: private ArrayList mDeadTextureIDs; michael@0: michael@0: private TextureReaper() { mDeadTextureIDs = new ArrayList(); } michael@0: michael@0: public static TextureReaper get() { michael@0: if (sSharedInstance == null) michael@0: sSharedInstance = new TextureReaper(); michael@0: return sSharedInstance; michael@0: } michael@0: michael@0: public void add(int[] textureIDs) { michael@0: for (int textureID : textureIDs) michael@0: add(textureID); michael@0: } michael@0: michael@0: public void add(int textureID) { michael@0: mDeadTextureIDs.add(textureID); michael@0: } michael@0: michael@0: public void reap() { michael@0: int numTextures = mDeadTextureIDs.size(); michael@0: // Adreno 200 will generate INVALID_VALUE if len == 0 is passed to glDeleteTextures, michael@0: // even though it's not supposed to. michael@0: if (numTextures == 0) michael@0: return; michael@0: michael@0: int[] deadTextureIDs = new int[numTextures]; michael@0: for (int i = 0; i < numTextures; i++) { michael@0: deadTextureIDs[i] = mDeadTextureIDs.get(i); michael@0: } michael@0: mDeadTextureIDs.clear(); michael@0: michael@0: GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0); michael@0: } michael@0: } michael@0: michael@0: