mobile/android/base/gfx/TextureReaper.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/gfx/TextureReaper.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.gfx;
    1.10 +
    1.11 +import android.opengl.GLES20;
    1.12 +
    1.13 +import java.util.ArrayList;
    1.14 +
    1.15 +/** Manages a list of dead tiles, so we don't leak resources. */
    1.16 +public class TextureReaper {
    1.17 +    private static TextureReaper sSharedInstance;
    1.18 +    private ArrayList<Integer> mDeadTextureIDs;
    1.19 +
    1.20 +    private TextureReaper() { mDeadTextureIDs = new ArrayList<Integer>(); }
    1.21 +
    1.22 +    public static TextureReaper get() {
    1.23 +        if (sSharedInstance == null)
    1.24 +            sSharedInstance = new TextureReaper();
    1.25 +        return sSharedInstance;
    1.26 +    }
    1.27 +
    1.28 +    public void add(int[] textureIDs) {
    1.29 +        for (int textureID : textureIDs)
    1.30 +            add(textureID);
    1.31 +    }
    1.32 +
    1.33 +    public void add(int textureID) {
    1.34 +        mDeadTextureIDs.add(textureID);
    1.35 +    }
    1.36 +
    1.37 +    public void reap() {
    1.38 +        int numTextures = mDeadTextureIDs.size();
    1.39 +        // Adreno 200 will generate INVALID_VALUE if len == 0 is passed to glDeleteTextures,
    1.40 +        // even though it's not supposed to.
    1.41 +        if (numTextures == 0)
    1.42 +            return;
    1.43 +
    1.44 +        int[] deadTextureIDs = new int[numTextures];
    1.45 +        for (int i = 0; i < numTextures; i++) {
    1.46 +            deadTextureIDs[i] = mDeadTextureIDs.get(i);
    1.47 +        }
    1.48 +        mDeadTextureIDs.clear();
    1.49 +
    1.50 +        GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0);
    1.51 +    }
    1.52 +}
    1.53 +
    1.54 +

mercurial