FileDocCategorySizeDatePackage
BaseSurfaceHolder.javaAPI DocAndroid 5.1 API6770Thu Mar 12 22:22:10 GMT 2015com.android.internal.view

BaseSurfaceHolder

public abstract class BaseSurfaceHolder extends Object implements android.view.SurfaceHolder

Fields Summary
private static final String
TAG
static final boolean
DEBUG
public final ArrayList
mCallbacks
SurfaceHolder.Callback[]
mGottenCallbacks
boolean
mHaveGottenCallbacks
public final ReentrantLock
mSurfaceLock
public android.view.Surface
mSurface
int
mRequestedWidth
int
mRequestedHeight
protected int
mRequestedFormat
int
mRequestedType
long
mLastLockTime
int
mType
final android.graphics.Rect
mSurfaceFrame
android.graphics.Rect
mTmpDirty
Constructors Summary
Methods Summary
public voidaddCallback(Callback callback)

        synchronized (mCallbacks) {
            // This is a linear search, but in practice we'll 
            // have only a couple callbacks, so it doesn't matter.
            if (mCallbacks.contains(callback) == false) {      
                mCallbacks.add(callback);
            }
        }
    
public SurfaceHolder.Callback[]getCallbacks()

        if (mHaveGottenCallbacks) {
            return mGottenCallbacks;
        }
        
        synchronized (mCallbacks) {
            final int N = mCallbacks.size();
            if (N > 0) {
                if (mGottenCallbacks == null || mGottenCallbacks.length != N) {
                    mGottenCallbacks = new SurfaceHolder.Callback[N];
                }
                mCallbacks.toArray(mGottenCallbacks);
            } else {
                mGottenCallbacks = null;
            }
            mHaveGottenCallbacks = true;
        }
        
        return mGottenCallbacks;
    
public intgetRequestedFormat()

        return mRequestedFormat;
    
public intgetRequestedHeight()

        return mRequestedHeight;
    
public intgetRequestedType()

        return mRequestedType;
    
public intgetRequestedWidth()

    
       
       
       
    
       
        return mRequestedWidth;
    
public android.view.SurfacegetSurface()

        return mSurface;
    
public android.graphics.RectgetSurfaceFrame()

        return mSurfaceFrame;
    
private final android.graphics.CanvasinternalLockCanvas(android.graphics.Rect dirty)

        if (mType == SURFACE_TYPE_PUSH_BUFFERS) {
            throw new BadSurfaceTypeException(
                    "Surface type is SURFACE_TYPE_PUSH_BUFFERS");
        }
        mSurfaceLock.lock();

        if (DEBUG) Log.i(TAG, "Locking canvas..,");

        Canvas c = null;
        if (onAllowLockCanvas()) {
            if (dirty == null) {
                if (mTmpDirty == null) {
                    mTmpDirty = new Rect();
                }
                mTmpDirty.set(mSurfaceFrame);
                dirty = mTmpDirty;
            }

            try {
                c = mSurface.lockCanvas(dirty);
            } catch (Exception e) {
                Log.e(TAG, "Exception locking surface", e);
            }
        }

        if (DEBUG) Log.i(TAG, "Returned canvas: " + c);
        if (c != null) {
            mLastLockTime = SystemClock.uptimeMillis();
            return c;
        }
        
        // If the Surface is not ready to be drawn, then return null,
        // but throttle calls to this function so it isn't called more
        // than every 100ms.
        long now = SystemClock.uptimeMillis();
        long nextTime = mLastLockTime + 100;
        if (nextTime > now) {
            try {
                Thread.sleep(nextTime-now);
            } catch (InterruptedException e) {
            }
            now = SystemClock.uptimeMillis();
        }
        mLastLockTime = now;
        mSurfaceLock.unlock();
        
        return null;
    
public android.graphics.CanvaslockCanvas()

        return internalLockCanvas(null);
    
public android.graphics.CanvaslockCanvas(android.graphics.Rect dirty)

        return internalLockCanvas(dirty);
    
public abstract booleanonAllowLockCanvas()

public abstract voidonRelayoutContainer()

public abstract voidonUpdateSurface()

public voidremoveCallback(Callback callback)

        synchronized (mCallbacks) {
            mCallbacks.remove(callback);
        }
    
public voidsetFixedSize(int width, int height)

        if (mRequestedWidth != width || mRequestedHeight != height) {
            mRequestedWidth = width;
            mRequestedHeight = height;
            onRelayoutContainer();
        }
    
public voidsetFormat(int format)

        if (mRequestedFormat != format) {
            mRequestedFormat = format;
            onUpdateSurface();
        }
    
public voidsetSizeFromLayout()

        if (mRequestedWidth != -1 || mRequestedHeight != -1) {
            mRequestedWidth = mRequestedHeight = -1;
            onRelayoutContainer();
        }
    
public voidsetSurfaceFrameSize(int width, int height)

        mSurfaceFrame.top = 0;
        mSurfaceFrame.left = 0;
        mSurfaceFrame.right = width;
        mSurfaceFrame.bottom = height;
    
public voidsetType(int type)

        switch (type) {
        case SURFACE_TYPE_HARDWARE:
        case SURFACE_TYPE_GPU:
            // these are deprecated, treat as "NORMAL"
            type = SURFACE_TYPE_NORMAL;
            break;
        }
        switch (type) {
        case SURFACE_TYPE_NORMAL:
        case SURFACE_TYPE_PUSH_BUFFERS:
            if (mRequestedType != type) {
                mRequestedType = type;
                onUpdateSurface();
            }
            break;
        }
    
public voidungetCallbacks()

        mHaveGottenCallbacks = false;
    
public voidunlockCanvasAndPost(android.graphics.Canvas canvas)

        mSurface.unlockCanvasAndPost(canvas);
        mSurfaceLock.unlock();