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

Commit 8435fa97 authored by Tyler Freeman's avatar Tyler Freeman Committed by Android (Google) Code Review
Browse files

Merge "Revert "Optimize magnifier viewport drawing"" into main

parents 659dee27 75599616
Loading
Loading
Loading
Loading
+17 −47
Original line number Original line Diff line number Diff line
@@ -448,16 +448,16 @@ final class AccessibilityController {
        }
        }
    }
    }


    void drawMagnifiedRegionBorderIfNeeded(int displayId) {
    void drawMagnifiedRegionBorderIfNeeded(int displayId, SurfaceControl.Transaction t) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            mAccessibilityTracing.logTrace(
            mAccessibilityTracing.logTrace(
                    TAG + ".drawMagnifiedRegionBorderIfNeeded",
                    TAG + ".drawMagnifiedRegionBorderIfNeeded",
                    FLAGS_MAGNIFICATION_CALLBACK,
                    FLAGS_MAGNIFICATION_CALLBACK,
                    "displayId=" + displayId);
                    "displayId=" + displayId + "; transaction={" + t + "}");
        }
        }
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        if (displayMagnifier != null) {
        if (displayMagnifier != null) {
            displayMagnifier.drawMagnifiedRegionBorderIfNeeded();
            displayMagnifier.drawMagnifiedRegionBorderIfNeeded(t);
        }
        }
        // Not relevant for the window observer.
        // Not relevant for the window observer.
    }
    }
@@ -855,12 +855,12 @@ final class AccessibilityController {
                    .sendToTarget();
                    .sendToTarget();
        }
        }


        void drawMagnifiedRegionBorderIfNeeded() {
        void drawMagnifiedRegionBorderIfNeeded(SurfaceControl.Transaction t) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
                mAccessibilityTracing.logTrace(LOG_TAG + ".drawMagnifiedRegionBorderIfNeeded",
                mAccessibilityTracing.logTrace(LOG_TAG + ".drawMagnifiedRegionBorderIfNeeded",
                        FLAGS_MAGNIFICATION_CALLBACK);
                        FLAGS_MAGNIFICATION_CALLBACK, "transition={" + t + "}");
            }
            }
            mMagnifedViewport.drawWindowIfNeeded();
            mMagnifedViewport.drawWindowIfNeeded(t);
        }
        }


        void dump(PrintWriter pw, String prefix) {
        void dump(PrintWriter pw, String prefix) {
@@ -1106,11 +1106,11 @@ final class AccessibilityController {
            }
            }


            void setMagnifiedRegionBorderShown(boolean shown, boolean animate) {
            void setMagnifiedRegionBorderShown(boolean shown, boolean animate) {
                if (mWindow.setShown(shown, animate)) {
                if (shown) {
                    mFullRedrawNeeded = true;
                    mFullRedrawNeeded = true;
                    // Clear the old region, so recomputeBounds will refresh the current region.
                    mOldMagnificationRegion.set(0, 0, 0, 0);
                    mOldMagnificationRegion.set(0, 0, 0, 0);
                }
                }
                mWindow.setShown(shown, animate);
            }
            }


            void getMagnifiedFrameInContentCoords(Rect rect) {
            void getMagnifiedFrameInContentCoords(Rect rect) {
@@ -1128,9 +1128,9 @@ final class AccessibilityController {
                return mMagnificationSpec;
                return mMagnificationSpec;
            }
            }


            void drawWindowIfNeeded() {
            void drawWindowIfNeeded(SurfaceControl.Transaction t) {
                recomputeBounds();
                recomputeBounds();
                mWindow.postDrawIfNeeded();
                mWindow.drawIfNeeded(t);
            }
            }


            void destroyWindow() {
            void destroyWindow() {
@@ -1158,7 +1158,7 @@ final class AccessibilityController {
                mWindow.dump(pw, prefix);
                mWindow.dump(pw, prefix);
            }
            }


            private final class ViewportWindow implements Runnable {
            private final class ViewportWindow {
                private static final String SURFACE_TITLE = "Magnification Overlay";
                private static final String SURFACE_TITLE = "Magnification Overlay";


                private final Region mBounds = new Region();
                private final Region mBounds = new Region();
@@ -1166,18 +1166,15 @@ final class AccessibilityController {
                private final Paint mPaint = new Paint();
                private final Paint mPaint = new Paint();


                private final SurfaceControl mSurfaceControl;
                private final SurfaceControl mSurfaceControl;
                /** After initialization, it should only be accessed from animation thread. */
                private final SurfaceControl.Transaction mTransaction;
                private final BLASTBufferQueue mBlastBufferQueue;
                private final BLASTBufferQueue mBlastBufferQueue;
                private final Surface mSurface;
                private final Surface mSurface;


                private final AnimationController mAnimationController;
                private final AnimationController mAnimationController;


                private boolean mShown;
                private boolean mShown;
                private boolean mLastSurfaceShown;
                private int mAlpha;
                private int mAlpha;


                private volatile boolean mInvalidated;
                private boolean mInvalidated;


                ViewportWindow(Context context) {
                ViewportWindow(Context context) {
                    SurfaceControl surfaceControl = null;
                    SurfaceControl surfaceControl = null;
@@ -1205,7 +1202,6 @@ final class AccessibilityController {
                    InputMonitor.setTrustedOverlayInputInfo(mSurfaceControl, t,
                    InputMonitor.setTrustedOverlayInputInfo(mSurfaceControl, t,
                            mDisplayContent.getDisplayId(), "Magnification Overlay");
                            mDisplayContent.getDisplayId(), "Magnification Overlay");
                    t.apply();
                    t.apply();
                    mTransaction = t;
                    mSurface = mBlastBufferQueue.createSurface();
                    mSurface = mBlastBufferQueue.createSurface();


                    mAnimationController = new AnimationController(context,
                    mAnimationController = new AnimationController(context,
@@ -1223,11 +1219,10 @@ final class AccessibilityController {
                    mInvalidated = true;
                    mInvalidated = true;
                }
                }


                /** Returns {@code true} if the shown state is changed. */
                void setShown(boolean shown, boolean animate) {
                boolean setShown(boolean shown, boolean animate) {
                    synchronized (mService.mGlobalLock) {
                    synchronized (mService.mGlobalLock) {
                        if (mShown == shown) {
                        if (mShown == shown) {
                            return false;
                            return;
                        }
                        }
                        mShown = shown;
                        mShown = shown;
                        mAnimationController.onFrameShownStateChanged(shown, animate);
                        mAnimationController.onFrameShownStateChanged(shown, animate);
@@ -1235,7 +1230,6 @@ final class AccessibilityController {
                            Slog.i(LOG_TAG, "ViewportWindow shown: " + mShown);
                            Slog.i(LOG_TAG, "ViewportWindow shown: " + mShown);
                        }
                        }
                    }
                    }
                    return true;
                }
                }


                @SuppressWarnings("unused")
                @SuppressWarnings("unused")
@@ -1291,22 +1285,7 @@ final class AccessibilityController {
                    mService.scheduleAnimationLocked();
                    mService.scheduleAnimationLocked();
                }
                }


                void postDrawIfNeeded() {
                void drawIfNeeded(SurfaceControl.Transaction t) {
                    if (mInvalidated) {
                        mService.mAnimationHandler.post(this);
                    }
                }

                @Override
                public void run() {
                    drawIfNeeded();
                }

                /**
                 * This method must only be called by animation handler directly to make sure
                 * thread safe and there is no lock held outside.
                 */
                private void drawIfNeeded() {
                    // Drawing variables (alpha, dirty rect, and bounds) access is synchronized
                    // Drawing variables (alpha, dirty rect, and bounds) access is synchronized
                    // using WindowManagerGlobalLock. Grab copies of these values before
                    // using WindowManagerGlobalLock. Grab copies of these values before
                    // drawing on the canvas so that drawing can be performed outside of the lock.
                    // drawing on the canvas so that drawing can be performed outside of the lock.
@@ -1335,7 +1314,6 @@ final class AccessibilityController {
                        }
                        }
                    }
                    }


                    final boolean showSurface;
                    // Draw without holding WindowManagerGlobalLock.
                    // Draw without holding WindowManagerGlobalLock.
                    if (alpha > 0) {
                    if (alpha > 0) {
                        Canvas canvas = null;
                        Canvas canvas = null;
@@ -1351,17 +1329,9 @@ final class AccessibilityController {
                        mPaint.setAlpha(alpha);
                        mPaint.setAlpha(alpha);
                        canvas.drawPath(drawingBounds.getBoundaryPath(), mPaint);
                        canvas.drawPath(drawingBounds.getBoundaryPath(), mPaint);
                        mSurface.unlockCanvasAndPost(canvas);
                        mSurface.unlockCanvasAndPost(canvas);
                        showSurface = true;
                        t.show(mSurfaceControl);
                    } else {
                    } else {
                        showSurface = false;
                        t.hide(mSurfaceControl);
                    }

                    if (showSurface && !mLastSurfaceShown) {
                        mTransaction.show(mSurfaceControl).apply();
                        mLastSurfaceShown = true;
                    } else if (!showSurface && mLastSurfaceShown) {
                        mTransaction.hide(mSurfaceControl).apply();
                        mLastSurfaceShown = false;
                    }
                    }
                }
                }


+2 −1
Original line number Original line Diff line number Diff line
@@ -148,7 +148,8 @@ public class WindowAnimator {


                dc.checkAppWindowsReadyToShow();
                dc.checkAppWindowsReadyToShow();
                if (accessibilityController.hasCallbacks()) {
                if (accessibilityController.hasCallbacks()) {
                    accessibilityController.drawMagnifiedRegionBorderIfNeeded(dc.mDisplayId);
                    accessibilityController.drawMagnifiedRegionBorderIfNeeded(dc.mDisplayId,
                            mTransaction);
                }
                }


                if (dc.isAnimating(animationFlags, ANIMATION_TYPE_ALL)) {
                if (dc.isAnimating(animationFlags, ANIMATION_TYPE_ALL)) {