LibreOffice Module android (master) 1
TextureReaper.java
Go to the documentation of this file.
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
6package org.mozilla.gecko.gfx;
7
8import android.opengl.GLES20;
9import android.util.Log;
10
11import java.util.ArrayList;
12
16public class TextureReaper {
18 private ArrayList<Integer> mDeadTextureIDs = new ArrayList<Integer>();
19 private static final String LOGTAG = TextureReaper.class.getSimpleName();
20
21 private TextureReaper() {
22 }
23
24 public static TextureReaper get() {
25 if (sSharedInstance == null) {
27 }
28 return sSharedInstance;
29 }
30
31 public void add(int[] textureIDs) {
32 for (int textureID : textureIDs) {
33 add(textureID);
34 }
35 }
36
37 public synchronized void add(int textureID) {
38 mDeadTextureIDs.add(textureID);
39 }
40
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.
45 if (numTextures == 0)
46 return;
47
48 int[] deadTextureIDs = new int[numTextures];
49 for (int i = 0; i < numTextures; i++) {
50 Integer id = mDeadTextureIDs.get(i);
51 if (id == null) {
52 deadTextureIDs[i] = 0;
53 Log.e(LOGTAG, "Dead texture id is null");
54 } else {
55 deadTextureIDs[i] = mDeadTextureIDs.get(i);
56 }
57 }
58 mDeadTextureIDs.clear();
59
60 GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0);
61 }
62}
Manages a list of dead tiles, so we don't leak resources.
ArrayList< Integer > mDeadTextureIDs
static TextureReaper sSharedInstance
synchronized void add(int textureID)
int i