mobile/android/base/gfx/TextureReaper.java

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:47ca63b0d0ab
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/. */
5
6 package org.mozilla.gecko.gfx;
7
8 import android.opengl.GLES20;
9
10 import java.util.ArrayList;
11
12 /** Manages a list of dead tiles, so we don't leak resources. */
13 public class TextureReaper {
14 private static TextureReaper sSharedInstance;
15 private ArrayList<Integer> mDeadTextureIDs;
16
17 private TextureReaper() { mDeadTextureIDs = new ArrayList<Integer>(); }
18
19 public static TextureReaper get() {
20 if (sSharedInstance == null)
21 sSharedInstance = new TextureReaper();
22 return sSharedInstance;
23 }
24
25 public void add(int[] textureIDs) {
26 for (int textureID : textureIDs)
27 add(textureID);
28 }
29
30 public void add(int textureID) {
31 mDeadTextureIDs.add(textureID);
32 }
33
34 public void reap() {
35 int numTextures = mDeadTextureIDs.size();
36 // Adreno 200 will generate INVALID_VALUE if len == 0 is passed to glDeleteTextures,
37 // even though it's not supposed to.
38 if (numTextures == 0)
39 return;
40
41 int[] deadTextureIDs = new int[numTextures];
42 for (int i = 0; i < numTextures; i++) {
43 deadTextureIDs[i] = mDeadTextureIDs.get(i);
44 }
45 mDeadTextureIDs.clear();
46
47 GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0);
48 }
49 }
50
51

mercurial