mobile/android/base/gfx/TextureReaper.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.gfx;
michael@0 7
michael@0 8 import android.opengl.GLES20;
michael@0 9
michael@0 10 import java.util.ArrayList;
michael@0 11
michael@0 12 /** Manages a list of dead tiles, so we don't leak resources. */
michael@0 13 public class TextureReaper {
michael@0 14 private static TextureReaper sSharedInstance;
michael@0 15 private ArrayList<Integer> mDeadTextureIDs;
michael@0 16
michael@0 17 private TextureReaper() { mDeadTextureIDs = new ArrayList<Integer>(); }
michael@0 18
michael@0 19 public static TextureReaper get() {
michael@0 20 if (sSharedInstance == null)
michael@0 21 sSharedInstance = new TextureReaper();
michael@0 22 return sSharedInstance;
michael@0 23 }
michael@0 24
michael@0 25 public void add(int[] textureIDs) {
michael@0 26 for (int textureID : textureIDs)
michael@0 27 add(textureID);
michael@0 28 }
michael@0 29
michael@0 30 public void add(int textureID) {
michael@0 31 mDeadTextureIDs.add(textureID);
michael@0 32 }
michael@0 33
michael@0 34 public void reap() {
michael@0 35 int numTextures = mDeadTextureIDs.size();
michael@0 36 // Adreno 200 will generate INVALID_VALUE if len == 0 is passed to glDeleteTextures,
michael@0 37 // even though it's not supposed to.
michael@0 38 if (numTextures == 0)
michael@0 39 return;
michael@0 40
michael@0 41 int[] deadTextureIDs = new int[numTextures];
michael@0 42 for (int i = 0; i < numTextures; i++) {
michael@0 43 deadTextureIDs[i] = mDeadTextureIDs.get(i);
michael@0 44 }
michael@0 45 mDeadTextureIDs.clear();
michael@0 46
michael@0 47 GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0);
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51

mercurial