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

Commit 27e46ffb authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Automerger Merge Worker
Browse files

Merge "Change remaining trusted layers from BQL to Blast layer" into sc-dev am: 0e7cd4bd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14268688

Change-Id: I8a68f54f811138d8c849e7f44f0f4ff9a80318f1
parents 0c6a022c 0e7cd4bd
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ import android.annotation.NonNull;
import android.app.Application;
import android.app.Application;
import android.content.Context;
import android.content.Context;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal;
import android.graphics.BLASTBufferQueue;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Matrix;
@@ -1123,7 +1124,8 @@ final class AccessibilityController {
                private final Paint mPaint = new Paint();
                private final Paint mPaint = new Paint();


                private final SurfaceControl mSurfaceControl;
                private final SurfaceControl mSurfaceControl;
                private final Surface mSurface = mService.mSurfaceFactory.get();
                private final BLASTBufferQueue mBlastBufferQueue;
                private final Surface mSurface;


                private final AnimationController mAnimationController;
                private final AnimationController mAnimationController;


@@ -1135,11 +1137,10 @@ final class AccessibilityController {
                ViewportWindow(Context context) {
                ViewportWindow(Context context) {
                    SurfaceControl surfaceControl = null;
                    SurfaceControl surfaceControl = null;
                    try {
                    try {
                        mDisplay.getRealSize(mTempPoint);
                        surfaceControl = mDisplayContent
                        surfaceControl = mDisplayContent
                                .makeOverlay()
                                .makeOverlay()
                                .setName(SURFACE_TITLE)
                                .setName(SURFACE_TITLE)
                                .setBufferSize(mTempPoint.x, mTempPoint.y) // not a typo
                                .setBLASTLayer()
                                .setFormat(PixelFormat.TRANSLUCENT)
                                .setFormat(PixelFormat.TRANSLUCENT)
                                .setCallsite("ViewportWindow")
                                .setCallsite("ViewportWindow")
                                .build();
                                .build();
@@ -1147,6 +1148,9 @@ final class AccessibilityController {
                        /* ignore */
                        /* ignore */
                    }
                    }
                    mSurfaceControl = surfaceControl;
                    mSurfaceControl = surfaceControl;
                    mDisplay.getRealSize(mTempPoint);
                    mBlastBufferQueue = new BLASTBufferQueue(SURFACE_TITLE, mSurfaceControl,
                            mTempPoint.x, mTempPoint.y, PixelFormat.RGBA_8888);


                    final SurfaceControl.Transaction t = mService.mTransactionFactory.get();
                    final SurfaceControl.Transaction t = mService.mTransactionFactory.get();
                    final int layer =
                    final int layer =
@@ -1156,8 +1160,7 @@ final class AccessibilityController {
                    InputMonitor.setTrustedOverlayInputInfo(mSurfaceControl, t,
                    InputMonitor.setTrustedOverlayInputInfo(mSurfaceControl, t,
                            mDisplayContent.getDisplayId(), "Magnification Overlay");
                            mDisplayContent.getDisplayId(), "Magnification Overlay");
                    t.apply();
                    t.apply();

                    mSurface = mBlastBufferQueue.createSurface();
                    mSurface.copyFrom(mSurfaceControl);


                    mAnimationController = new AnimationController(context,
                    mAnimationController = new AnimationController(context,
                            mService.mH.getLooper());
                            mService.mH.getLooper());
@@ -1282,6 +1285,9 @@ final class AccessibilityController {
                }
                }


                void releaseSurface() {
                void releaseSurface() {
                    if (mBlastBufferQueue != null) {
                        mBlastBufferQueue.destroy();
                    }
                    mService.mTransactionFactory.get().remove(mSurfaceControl).apply();
                    mService.mTransactionFactory.get().remove(mSurfaceControl).apply();
                    mSurface.release();
                    mSurface.release();
                }
                }
+18 −17
Original line number Original line Diff line number Diff line
@@ -20,38 +20,39 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;


import android.content.Context;
import android.content.Context;
import android.graphics.BLASTBufferQueue;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.view.Display;
import android.view.Display;
import android.view.Surface;
import android.view.Surface;
import android.view.Surface.OutOfResourcesException;
import android.view.Surface.OutOfResourcesException;
import android.view.SurfaceControl;
import android.view.SurfaceControl;


import java.util.function.Supplier;

class EmulatorDisplayOverlay {
class EmulatorDisplayOverlay {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "EmulatorDisplayOverlay" : TAG_WM;
    private static final String TAG = TAG_WITH_CLASS_NAME ? "EmulatorDisplayOverlay" : TAG_WM;


    private static final String TITLE = "EmulatorDisplayOverlay";

    // Display dimensions
    // Display dimensions
    private Point mScreenSize;
    private Point mScreenSize;


    private final SurfaceControl mSurfaceControl;
    private final SurfaceControl mSurfaceControl;
    private final Surface mSurface;
    private final Surface mSurface;
    private final BLASTBufferQueue mBlastBufferQueue;

    private int mLastDW;
    private int mLastDW;
    private int mLastDH;
    private int mLastDH;
    private boolean mDrawNeeded;
    private boolean mDrawNeeded;
    private Drawable mOverlay;
    private final Drawable mOverlay;
    private int mRotation;
    private int mRotation;
    private boolean mVisible;
    private boolean mVisible;


    EmulatorDisplayOverlay(Supplier<Surface> surfaceFactory, Context context, DisplayContent dc,
    EmulatorDisplayOverlay(Context context, DisplayContent dc, int zOrder,
            int zOrder, SurfaceControl.Transaction t) {
            SurfaceControl.Transaction t) {
        mSurface = surfaceFactory.get();
        final Display display = dc.getDisplay();
        final Display display = dc.getDisplay();
        mScreenSize = new Point();
        mScreenSize = new Point();
        display.getSize(mScreenSize);
        display.getSize(mScreenSize);
@@ -59,24 +60,26 @@ class EmulatorDisplayOverlay {
        SurfaceControl ctrl = null;
        SurfaceControl ctrl = null;
        try {
        try {
            ctrl = dc.makeOverlay()
            ctrl = dc.makeOverlay()
                    .setName("EmulatorDisplayOverlay")
                    .setName(TITLE)
                    .setBufferSize(mScreenSize.x, mScreenSize.y)
                    .setBLASTLayer()
                    .setFormat(PixelFormat.TRANSLUCENT)
                    .setFormat(PixelFormat.TRANSLUCENT)
                    .setCallsite("EmulatorDisplayOverlay")
                    .setCallsite(TITLE)
                    .build();
                    .build();
            t.setLayer(ctrl, zOrder);
            t.setLayer(ctrl, zOrder);
            t.setPosition(ctrl, 0, 0);
            t.setPosition(ctrl, 0, 0);
            t.show(ctrl);
            t.show(ctrl);
            // Ensure we aren't considered as obscuring for Input purposes.
            // Ensure we aren't considered as obscuring for Input purposes.
            InputMonitor.setTrustedOverlayInputInfo(ctrl, t,
            InputMonitor.setTrustedOverlayInputInfo(ctrl, t, dc.getDisplayId(), TITLE);
                    dc.getDisplayId(), "EmulatorDisplayOverlay");
            mSurface.copyFrom(ctrl);
        } catch (OutOfResourcesException e) {
        } catch (OutOfResourcesException e) {
        }
        }
        mSurfaceControl = ctrl;
        mSurfaceControl = ctrl;
        mDrawNeeded = true;
        mDrawNeeded = true;
        mOverlay = context.getDrawable(
        mOverlay = context.getDrawable(
                com.android.internal.R.drawable.emulator_circular_window_overlay);
                com.android.internal.R.drawable.emulator_circular_window_overlay);

        mBlastBufferQueue = new BLASTBufferQueue(TITLE, mSurfaceControl, mScreenSize.x,
                mScreenSize.y, PixelFormat.RGBA_8888);
        mSurface = mBlastBufferQueue.createSurface();
    }
    }


    private void drawIfNeeded(SurfaceControl.Transaction t) {
    private void drawIfNeeded(SurfaceControl.Transaction t) {
@@ -85,12 +88,10 @@ class EmulatorDisplayOverlay {
        }
        }
        mDrawNeeded = false;
        mDrawNeeded = false;


        Rect dirty = new Rect(0, 0, mScreenSize.x, mScreenSize.y);
        Canvas c = null;
        Canvas c = null;
        try {
        try {
            c = mSurface.lockCanvas(dirty);
            c = mSurface.lockCanvas(null);
        } catch (IllegalArgumentException e) {
        } catch (IllegalArgumentException | OutOfResourcesException e) {
        } catch (OutOfResourcesException e) {
        }
        }
        if (c == null) {
        if (c == null) {
            return;
            return;
+16 −16
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.wm;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;


import android.graphics.BLASTBufferQueue;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
@@ -27,28 +28,27 @@ import android.view.Surface;
import android.view.Surface.OutOfResourcesException;
import android.view.Surface.OutOfResourcesException;
import android.view.SurfaceControl;
import android.view.SurfaceControl;


import java.util.function.Supplier;

class StrictModeFlash {
class StrictModeFlash {
    private static final String TAG = TAG_WITH_CLASS_NAME ? "StrictModeFlash" : TAG_WM;
    private static final String TAG = TAG_WITH_CLASS_NAME ? "StrictModeFlash" : TAG_WM;
    private static final String TITLE = "StrictModeFlash";


    private final SurfaceControl mSurfaceControl;
    private final SurfaceControl mSurfaceControl;
    private final Surface mSurface;
    private final Surface mSurface;
    private final BLASTBufferQueue mBlastBufferQueue;

    private int mLastDW;
    private int mLastDW;
    private int mLastDH;
    private int mLastDH;
    private boolean mDrawNeeded;
    private boolean mDrawNeeded;
    private final int mThickness = 20;
    private final int mThickness = 20;


    StrictModeFlash(Supplier<Surface> surfaceFactory, DisplayContent dc,
    StrictModeFlash(DisplayContent dc, SurfaceControl.Transaction t) {
            SurfaceControl.Transaction t) {
        mSurface = surfaceFactory.get();
        SurfaceControl ctrl = null;
        SurfaceControl ctrl = null;
        try {
        try {
            ctrl = dc.makeOverlay()
            ctrl = dc.makeOverlay()
                    .setName("StrictModeFlash")
                    .setName(TITLE)
                    .setBufferSize(1, 1)
                    .setBLASTLayer()
                    .setFormat(PixelFormat.TRANSLUCENT)
                    .setFormat(PixelFormat.TRANSLUCENT)
                    .setCallsite("StrictModeFlash")
                    .setCallsite(TITLE)
                    .build();
                    .build();


            // one more than Watermark? arbitrary.
            // one more than Watermark? arbitrary.
@@ -56,14 +56,15 @@ class StrictModeFlash {
            t.setPosition(ctrl, 0, 0);
            t.setPosition(ctrl, 0, 0);
            t.show(ctrl);
            t.show(ctrl);
            // Ensure we aren't considered as obscuring for Input purposes.
            // Ensure we aren't considered as obscuring for Input purposes.
            InputMonitor.setTrustedOverlayInputInfo(ctrl, t, dc.getDisplayId(),
            InputMonitor.setTrustedOverlayInputInfo(ctrl, t, dc.getDisplayId(), TITLE);
                    "StrictModeFlash");

            mSurface.copyFrom(ctrl);
        } catch (OutOfResourcesException e) {
        } catch (OutOfResourcesException e) {
        }
        }
        mSurfaceControl = ctrl;
        mSurfaceControl = ctrl;
        mDrawNeeded = true;
        mDrawNeeded = true;

        mBlastBufferQueue = new BLASTBufferQueue(TITLE, mSurfaceControl, 1 /* width */,
                1 /* height */, PixelFormat.RGBA_8888);
        mSurface = mBlastBufferQueue.createSurface();
    }
    }


    private void drawIfNeeded() {
    private void drawIfNeeded() {
@@ -73,13 +74,12 @@ class StrictModeFlash {
        mDrawNeeded = false;
        mDrawNeeded = false;
        final int dw = mLastDW;
        final int dw = mLastDW;
        final int dh = mLastDH;
        final int dh = mLastDH;
        mBlastBufferQueue.update(mSurfaceControl, dw, dh, PixelFormat.RGBA_8888);


        Rect dirty = new Rect(0, 0, dw, dh);
        Canvas c = null;
        Canvas c = null;
        try {
        try {
            c = mSurface.lockCanvas(dirty);
            c = mSurface.lockCanvas(null);
        } catch (IllegalArgumentException e) {
        } catch (IllegalArgumentException | OutOfResourcesException e) {
        } catch (Surface.OutOfResourcesException e) {
        }
        }
        if (c == null) {
        if (c == null) {
            return;
            return;
+52 −55
Original line number Original line Diff line number Diff line
@@ -18,30 +18,26 @@ package com.android.server.wm;


import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;


import android.graphics.BLASTBufferQueue;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Typeface;
import android.util.DisplayMetrics;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Log;
import android.util.TypedValue;
import android.util.TypedValue;
import android.view.Display;
import android.view.InputWindowHandle;
import android.view.Surface;
import android.view.Surface;
import android.view.Surface.OutOfResourcesException;
import android.view.Surface.OutOfResourcesException;
import android.view.SurfaceControl;
import android.view.SurfaceControl;


import java.util.function.Supplier;

/**
/**
 * Displays a watermark on top of the window manager's windows.
 * Displays a watermark on top of the window manager's windows.
 */
 */
class Watermark {
class Watermark {
    private final Display mDisplay;
    private static final String TITLE = "WatermarkSurface";
    private final String[] mTokens;

    private final String mText;
    private final String mText;
    private final Paint mTextPaint;
    private final Paint mTextPaint;
    private final int mTextWidth;
    private final int mTextWidth;
@@ -51,28 +47,26 @@ class Watermark {


    private final SurfaceControl mSurfaceControl;
    private final SurfaceControl mSurfaceControl;
    private final Surface mSurface;
    private final Surface mSurface;
    private final BLASTBufferQueue mBlastBufferQueue;

    private int mLastDW;
    private int mLastDW;
    private int mLastDH;
    private int mLastDH;
    private boolean mDrawNeeded;
    private boolean mDrawNeeded;


    Watermark(Supplier<Surface> surfaceFactory, DisplayContent dc, DisplayMetrics dm,
    Watermark(DisplayContent dc, DisplayMetrics dm, String[] tokens, SurfaceControl.Transaction t) {
            String[] tokens, SurfaceControl.Transaction t) {
        if (false) {
        if (false) {
            Log.i(TAG_WM, "*********************** WATERMARK");
            Log.i(TAG_WM, "*********************** WATERMARK");
            for (int i=0; i<tokens.length; i++) {
            for (int i=0; i<tokens.length; i++) {
                Log.i(TAG_WM, "  TOKEN #" + i + ": " + tokens[i]);
                Log.i(TAG_WM, "  TOKEN #" + i + ": " + tokens[i]);
            }
            }
        }
        }
        mSurface = surfaceFactory.get();
        mDisplay = dc.getDisplay();
        mTokens = tokens;


        StringBuilder builder = new StringBuilder(32);
        StringBuilder builder = new StringBuilder(32);
        int len = mTokens[0].length();
        int len = tokens[0].length();
        len = len & ~1;
        len = len & ~1;
        for (int i=0; i<len; i+=2) {
        for (int i=0; i<len; i+=2) {
            int c1 = mTokens[0].charAt(i);
            int c1 = tokens[0].charAt(i);
            int c2 = mTokens[0].charAt(i+1);
            int c2 = tokens[0].charAt(i + 1);
            if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
            if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
            else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
            else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
            else c1 -= '0';
            else c1 -= '0';
@@ -118,20 +112,22 @@ class Watermark {
        SurfaceControl ctrl = null;
        SurfaceControl ctrl = null;
        try {
        try {
            ctrl = dc.makeOverlay()
            ctrl = dc.makeOverlay()
                    .setName("WatermarkSurface")
                    .setName(TITLE)
                    .setBufferSize(1, 1)
                    .setBLASTLayer()
                    .setFormat(PixelFormat.TRANSLUCENT)
                    .setFormat(PixelFormat.TRANSLUCENT)
                    .setCallsite("Watermark")
                    .setCallsite(TITLE)
                    .build();
                    .build();
            t.setLayer(ctrl, WindowManagerService.TYPE_LAYER_MULTIPLIER * 100)
            t.setLayer(ctrl, WindowManagerService.TYPE_LAYER_MULTIPLIER * 100)
                    .setPosition(ctrl, 0, 0)
                    .setPosition(ctrl, 0, 0)
                    .show(ctrl);
                    .show(ctrl);
            // Ensure we aren't considered as obscuring for Input purposes.
            // Ensure we aren't considered as obscuring for Input purposes.
            InputMonitor.setTrustedOverlayInputInfo(ctrl, t, dc.getDisplayId(), "Watermark");
            InputMonitor.setTrustedOverlayInputInfo(ctrl, t, dc.getDisplayId(), TITLE);
            mSurface.copyFrom(ctrl);
        } catch (OutOfResourcesException e) {
        } catch (OutOfResourcesException e) {
        }
        }
        mSurfaceControl = ctrl;
        mSurfaceControl = ctrl;
        mBlastBufferQueue = new BLASTBufferQueue(TITLE, mSurfaceControl, 1 /* width */,
                1 /* height */, PixelFormat.RGBA_8888);
        mSurface = mBlastBufferQueue.createSurface();
    }
    }


    void positionSurface(int dw, int dh, SurfaceControl.Transaction t) {
    void positionSurface(int dw, int dh, SurfaceControl.Transaction t) {
@@ -144,17 +140,19 @@ class Watermark {
    }
    }


    void drawIfNeeded() {
    void drawIfNeeded() {
        if (mDrawNeeded) {
        if (!mDrawNeeded) {
            return;
        }

        final int dw = mLastDW;
        final int dw = mLastDW;
        final int dh = mLastDH;
        final int dh = mLastDH;


        mDrawNeeded = false;
        mDrawNeeded = false;
            Rect dirty = new Rect(0, 0, dw, dh);
        mBlastBufferQueue.update(mSurfaceControl, dw, dh, PixelFormat.RGBA_8888);
        Canvas c = null;
        Canvas c = null;
        try {
        try {
                c = mSurface.lockCanvas(dirty);
            c = mSurface.lockCanvas(null);
            } catch (IllegalArgumentException e) {
        } catch (IllegalArgumentException | OutOfResourcesException e) {
            } catch (Surface.OutOfResourcesException e) {
        }
        }
        if (c != null) {
        if (c != null) {
            c.drawColor(0, PorterDuff.Mode.CLEAR);
            c.drawColor(0, PorterDuff.Mode.CLEAR);
@@ -185,4 +183,3 @@ class Watermark {
        }
        }
    }
    }
}
}
}
+5 −5
Original line number Original line Diff line number Diff line
@@ -3659,7 +3659,7 @@ public class WindowManagerService extends IWindowManager.Stub


            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG_WM, ">>> showEmulatorDisplayOverlay");
            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG_WM, ">>> showEmulatorDisplayOverlay");
            if (mEmulatorDisplayOverlay == null) {
            if (mEmulatorDisplayOverlay == null) {
                mEmulatorDisplayOverlay = new EmulatorDisplayOverlay(mSurfaceFactory, mContext,
                mEmulatorDisplayOverlay = new EmulatorDisplayOverlay(mContext,
                        getDefaultDisplayContentLocked(),
                        getDefaultDisplayContentLocked(),
                        mPolicy.getWindowLayerFromTypeLw(WindowManager.LayoutParams.TYPE_POINTER)
                        mPolicy.getWindowLayerFromTypeLw(WindowManager.LayoutParams.TYPE_POINTER)
                                * TYPE_LAYER_MULTIPLIER + 10, mTransaction);
                                * TYPE_LAYER_MULTIPLIER + 10, mTransaction);
@@ -3699,8 +3699,8 @@ public class WindowManagerService extends IWindowManager.Stub
            // b/31532461
            // b/31532461
            // TODO(multi-display): support multiple displays
            // TODO(multi-display): support multiple displays
            if (mStrictModeFlash == null) {
            if (mStrictModeFlash == null) {
                mStrictModeFlash = new StrictModeFlash(mSurfaceFactory,
                mStrictModeFlash = new StrictModeFlash(getDefaultDisplayContentLocked(),
                        getDefaultDisplayContentLocked(), mTransaction);
                        mTransaction);
            }
            }
            mStrictModeFlash.setVisibility(on, mTransaction);
            mStrictModeFlash.setVisibility(on, mTransaction);
            mTransaction.apply();
            mTransaction.apply();
@@ -5895,8 +5895,8 @@ public class WindowManagerService extends IWindowManager.Stub
                if (toks != null && toks.length > 0) {
                if (toks != null && toks.length > 0) {
                    // TODO(multi-display): Show watermarks on secondary displays.
                    // TODO(multi-display): Show watermarks on secondary displays.
                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
                    mWatermark = new Watermark(mSurfaceFactory, displayContent,
                    mWatermark = new Watermark(displayContent, displayContent.mRealDisplayMetrics,
                            displayContent.mRealDisplayMetrics, toks, mTransaction);
                            toks, mTransaction);
                    mTransaction.apply();
                    mTransaction.apply();
                }
                }
            }
            }