FileDocCategorySizeDatePackage
CircularDisplayMask.javaAPI DocAndroid 5.1 API5075Thu Mar 12 22:22:42 GMT 2015com.android.server.wm

CircularDisplayMask

public class CircularDisplayMask extends Object

Fields Summary
private static final String
TAG
private int
mScreenOffset
private android.graphics.Point
mScreenSize
private final android.view.SurfaceControl
mSurfaceControl
private final android.view.Surface
mSurface
private int
mLastDW
private int
mLastDH
private boolean
mDrawNeeded
private android.graphics.Paint
mPaint
private int
mRotation
private boolean
mVisible
private boolean
mDimensionsUnequal
Constructors Summary
public CircularDisplayMask(android.view.Display display, android.view.SurfaceSession session, int zOrder, int screenOffset)


          
              
        mScreenSize = new Point();
        display.getSize(mScreenSize);
        if (mScreenSize.x != mScreenSize.y) {
            Slog.w(TAG, "Screen dimensions of displayId = " + display.getDisplayId() +
                    "are not equal, circularMask will not be drawn.");
            mDimensionsUnequal = true;
        }

        SurfaceControl ctrl = null;
        try {
            if (WindowManagerService.DEBUG_SURFACE_TRACE) {
                ctrl = new WindowStateAnimator.SurfaceTrace(session, "CircularDisplayMask",
                        mScreenSize.x, mScreenSize.y, PixelFormat.TRANSLUCENT,
                        SurfaceControl.HIDDEN);
            } else {
                ctrl = new SurfaceControl(session, "CircularDisplayMask", mScreenSize.x,
                        mScreenSize.y, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
            }
            ctrl.setLayerStack(display.getLayerStack());
            ctrl.setLayer(zOrder);
            ctrl.setPosition(0, 0);
            ctrl.show();
            mSurface.copyFrom(ctrl);
        } catch (OutOfResourcesException e) {
        }
        mSurfaceControl = ctrl;
        mDrawNeeded = true;
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mScreenOffset = screenOffset;
    
Methods Summary
private voiddrawIfNeeded()

        if (!mDrawNeeded || !mVisible || mDimensionsUnequal) {
            return;
        }
        mDrawNeeded = false;

        Rect dirty = new Rect(0, 0, mScreenSize.x, mScreenSize.y);
        Canvas c = null;
        try {
            c = mSurface.lockCanvas(dirty);
        } catch (IllegalArgumentException e) {
        } catch (Surface.OutOfResourcesException e) {
        }
        if (c == null) {
            return;
        }
        switch (mRotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_90:
            // chin bottom or right
            mSurfaceControl.setPosition(0, 0);
            break;
        case Surface.ROTATION_180:
            // chin top
            mSurfaceControl.setPosition(0, -mScreenOffset);
            break;
        case Surface.ROTATION_270:
            // chin left
            mSurfaceControl.setPosition(-mScreenOffset, 0);
            break;
        }

        int circleRadius = mScreenSize.x / 2;
        c.drawColor(Color.BLACK);

        // The radius is reduced by 1 to provide an anti aliasing effect on the display edges.
        c.drawCircle(circleRadius, circleRadius, circleRadius - 1, mPaint);
        mSurface.unlockCanvasAndPost(c);
    
voidpositionSurface(int dw, int dh, int rotation)

        if (mLastDW == dw && mLastDH == dh && mRotation == rotation) {
            return;
        }
        mLastDW = dw;
        mLastDH = dh;
        mDrawNeeded = true;
        mRotation = rotation;
        drawIfNeeded();
    
public voidsetVisibility(boolean on)

        if (mSurfaceControl == null) {
            return;
        }
        mVisible = on;
        drawIfNeeded();
        if (on) {
            mSurfaceControl.show();
        } else {
            mSurfaceControl.hide();
        }