Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1ab884a authored by Craig Mautner's avatar Craig Mautner Committed by Android (Google) Code Review
Browse files

Merge "resolved conflicts for merge of 1e6706ab to master"

parents 8108d7f3 7119c071
Loading
Loading
Loading
Loading
+0 −133
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wm;


import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.view.Display;
import android.view.Surface;
import android.view.Surface.OutOfResourcesException;
import android.view.SurfaceControl;
import android.view.SurfaceSession;

class CircularDisplayMask {
    private static final String TAG = "CircularDisplayMask";

    private static final int STROKE_WIDTH = 2;
    // half the screen size
    private static final int CIRCLE_RADIUS = 160;
    // size of the chin
    private static final int SCREEN_OFFSET = 30;

    private final SurfaceControl mSurfaceControl;
    private final Surface mSurface = new Surface();
    private int mLastDW;
    private int mLastDH;
    private boolean mDrawNeeded;
    private Paint mPaint;
    private int mRotation;
    private boolean mVisible;

    public CircularDisplayMask(Display display, SurfaceSession session, int zOrder) {
        SurfaceControl ctrl = null;
        try {
            ctrl = new SurfaceControl(session, "CircularDisplayMask",
                320, 320, 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.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
        mPaint.setStrokeWidth(STROKE_WIDTH);
    }

    private void drawIfNeeded() {
        if (!mDrawNeeded || !mVisible) {
            return;
        }
        mDrawNeeded = false;

        Rect dirty = new Rect(0, 0, 320, 320);
        Canvas c = null;
        try {
            c = mSurface.lockCanvas(dirty);
        } catch (IllegalArgumentException e) {
        } catch (Surface.OutOfResourcesException e) {
        }
        if (c == null) {
            return;
        }
        c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC);
        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, -SCREEN_OFFSET);
            break;
        case Surface.ROTATION_270:
            // chin left
            mSurfaceControl.setPosition(-SCREEN_OFFSET, 0);
            break;
        }
        c.drawCircle(CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, mPaint);
        mSurface.unlockCanvasAndPost(c);
    }

    // Note: caller responsible for being inside
    // Surface.openTransaction() / closeTransaction()
    public void setVisibility(boolean on) {
        if (mSurfaceControl == null) {
            return;
        }
        mVisible = on;
        drawIfNeeded();
        if (on) {
            mSurfaceControl.show();
        } else {
            mSurfaceControl.hide();
        }
    }

    void positionSurface(int dw, int dh, int rotation) {
        if (mLastDW == dw && mLastDH == dh && mRotation == rotation) {
            return;
        }
        mLastDW = dw;
        mLastDH = dh;
        mDrawNeeded = true;
        mRotation = rotation;
        drawIfNeeded();
    }

}
+2 −47
Original line number Diff line number Diff line
@@ -433,7 +433,6 @@ public class WindowManagerService extends IWindowManager.Stub
    final SurfaceSession mFxSession;
    Watermark mWatermark;
    StrictModeFlash mStrictModeFlash;
    CircularDisplayMask mCircularDisplayMask;
    FocusedStackFrame mFocusedStackFrame;

    int mFocusedStackLayer;
@@ -846,8 +845,6 @@ public class WindowManagerService extends IWindowManager.Stub
        } finally {
            SurfaceControl.closeTransaction();
        }

        showCircularDisplayMaskIfNeeded();
    }

    public InputMonitor getInputMonitor() {
@@ -5574,39 +5571,6 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    public void showCircularDisplayMaskIfNeeded() {
        // we're fullscreen and not hosted in an ActivityView
        if (mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_windowIsRound)) {
            mH.sendMessage(mH.obtainMessage(H.SHOW_DISPLAY_MASK));
        }
    }

    public void showCircularMask() {
        synchronized(mWindowMap) {

            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                    ">>> OPEN TRANSACTION showDisplayMask");
            SurfaceControl.openTransaction();
            try {
                // TODO(multi-display): support multiple displays
                if (mCircularDisplayMask == null) {
                    mCircularDisplayMask = new CircularDisplayMask(
                            getDefaultDisplayContentLocked().getDisplay(),
                            mFxSession,
                            mPolicy.windowTypeToLayerLw(
                                    WindowManager.LayoutParams.TYPE_POINTER)
                                    * TYPE_LAYER_MULTIPLIER + 10);
                }
                mCircularDisplayMask.setVisibility(true);
            } finally {
                SurfaceControl.closeTransaction();
                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
                        "<<< CLOSE TRANSACTION showDisplayMask");
            }
        }
    }

    // TODO: more accounting of which pid(s) turned it on, keep count,
    // only allow disables from pids which have count on, etc.
    @Override
@@ -7213,10 +7177,9 @@ public class WindowManagerService extends IWindowManager.Stub
        public static final int TAP_OUTSIDE_STACK = 31;
        public static final int NOTIFY_ACTIVITY_DRAWN = 32;

        public static final int SHOW_DISPLAY_MASK = 33;
        public static final int ALL_WINDOWS_DRAWN = 34;
        public static final int ALL_WINDOWS_DRAWN = 33;

        public static final int NEW_ANIMATOR_SCALE = 35;
        public static final int NEW_ANIMATOR_SCALE = 34;

        @Override
        public void handleMessage(Message msg) {
@@ -7615,11 +7578,6 @@ public class WindowManagerService extends IWindowManager.Stub
                    break;
                }

                case SHOW_DISPLAY_MASK: {
                    showCircularMask();
                    break;
                }

                case DO_ANIMATION_CALLBACK: {
                    try {
                        ((IRemoteCallback)msg.obj).sendResult(null);
@@ -9135,9 +9093,6 @@ public class WindowManagerService extends IWindowManager.Stub
            if (mStrictModeFlash != null) {
                mStrictModeFlash.positionSurface(defaultDw, defaultDh);
            }
            if (mCircularDisplayMask != null) {
                mCircularDisplayMask.positionSurface(defaultDw, defaultDh, mRotation);
            }

            boolean focusDisplayed = false;