FileDocCategorySizeDatePackage
BasicTexture.javaAPI DocAndroid 5.1 API6657Thu Mar 12 22:22:42 GMT 2015com.android.gallery3d.glrenderer

BasicTexture

public abstract class BasicTexture extends Object implements Texture

Fields Summary
private static final String
TAG
protected static final int
UNSPECIFIED
protected static final int
STATE_UNLOADED
protected static final int
STATE_LOADED
protected static final int
STATE_ERROR
private static final int
MAX_TEXTURE_SIZE
protected int
mId
protected int
mState
protected int
mWidth
protected int
mHeight
protected int
mTextureWidth
protected int
mTextureHeight
private boolean
mHasBorder
protected GLCanvas
mCanvasRef
private static WeakHashMap
sAllTextures
private static ThreadLocal
sInFinalizer
Constructors Summary
protected BasicTexture(GLCanvas canvas, int id, int state)


           
        setAssociatedCanvas(canvas);
        mId = id;
        mState = state;
        synchronized (sAllTextures) {
            sAllTextures.put(this, null);
        }
    
protected BasicTexture()

        this(null, 0, STATE_UNLOADED);
    
Methods Summary
public voiddraw(GLCanvas canvas, int x, int y)

        canvas.drawTexture(this, x, y, getWidth(), getHeight());
    
public voiddraw(GLCanvas canvas, int x, int y, int w, int h)

        canvas.drawTexture(this, x, y, w, h);
    
protected voidfinalize()

        sInFinalizer.set(BasicTexture.class);
        recycle();
        sInFinalizer.set(null);
    
private voidfreeResource()

        GLCanvas canvas = mCanvasRef;
        if (canvas != null && mId != -1) {
            canvas.unloadTexture(this);
            mId = -1; // Don't free it again.
        }
        mState = STATE_UNLOADED;
        setAssociatedCanvas(null);
    
public intgetHeight()

        return mHeight;
    
public intgetId()

        return mId;
    
protected abstract intgetTarget()

public intgetTextureHeight()

        return mTextureHeight;
    
public intgetTextureWidth()

        return mTextureWidth;
    
public intgetWidth()

        return mWidth;
    
public booleanhasBorder()

        return mHasBorder;
    
public static booleaninFinalizer()

        return sInFinalizer.get() != null;
    
public static voidinvalidateAllTextures()

        synchronized (sAllTextures) {
            for (BasicTexture t : sAllTextures.keySet()) {
                t.mState = STATE_UNLOADED;
                t.setAssociatedCanvas(null);
            }
        }
    
public booleanisFlippedVertically()

      return false;
    
public booleanisLoaded()

        return mState == STATE_LOADED;
    
protected abstract booleanonBind(GLCanvas canvas)

public voidrecycle()

        freeResource();
    
protected voidsetAssociatedCanvas(GLCanvas canvas)

        mCanvasRef = canvas;
    
protected voidsetBorder(boolean hasBorder)

        mHasBorder = hasBorder;
    
public voidsetSize(int width, int height)
Sets the content size of this texture. In OpenGL, the actual texture size must be of power of 2, the size of the content may be smaller.

        mWidth = width;
        mHeight = height;
        mTextureWidth = width > 0 ? Utils.nextPowerOf2(width) : 0;
        mTextureHeight = height > 0 ? Utils.nextPowerOf2(height) : 0;
        if (mTextureWidth > MAX_TEXTURE_SIZE || mTextureHeight > MAX_TEXTURE_SIZE) {
            Log.w(TAG, String.format("texture is too large: %d x %d",
                    mTextureWidth, mTextureHeight), new Exception());
        }
    
public voidyield()

        freeResource();
    
public static voidyieldAllTextures()

        synchronized (sAllTextures) {
            for (BasicTexture t : sAllTextures.keySet()) {
                t.yield();
            }
        }