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.

     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/. */
     6 package org.mozilla.gecko.gfx;
     8 import android.opengl.GLES20;
    10 import java.util.ArrayList;
    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;
    17     private TextureReaper() { mDeadTextureIDs = new ArrayList<Integer>(); }
    19     public static TextureReaper get() {
    20         if (sSharedInstance == null)
    21             sSharedInstance = new TextureReaper();
    22         return sSharedInstance;
    23     }
    25     public void add(int[] textureIDs) {
    26         for (int textureID : textureIDs)
    27             add(textureID);
    28     }
    30     public void add(int textureID) {
    31         mDeadTextureIDs.add(textureID);
    32     }
    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;
    41         int[] deadTextureIDs = new int[numTextures];
    42         for (int i = 0; i < numTextures; i++) {
    43             deadTextureIDs[i] = mDeadTextureIDs.get(i);
    44         }
    45         mDeadTextureIDs.clear();
    47         GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0);
    48     }
    49 }

mercurial