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

Commit 179a6b06 authored by Qasid Ahmad Sadiq's avatar Qasid Ahmad Sadiq
Browse files

Remove recycling magnificationSpec and region.

It doesn't seem like this would add a performance bump, but it does make
code quite ab it more complex (especially the prefetching CL).
Let's remove it to avoid bugs.

Test: CTSAccessibility* Tried it by hand.
Bug: 30969887
Change-Id: Ibc2fb856dbb1a0f7786882d4b89d71bbcb7e5af2
parent 027e0e0d
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -993,8 +992,6 @@ public final class AccessibilityInteractionController {
            }
        } catch (RemoteException re) {
            /* ignore - the other side will time out */
        } finally {
            recycleMagnificationSpecAndRegionIfNeeded(spec, interactiveRegion);
        }
    }

@@ -1013,24 +1010,6 @@ public final class AccessibilityInteractionController {
            callback.setFindAccessibilityNodeInfoResult(info, interactionId);
        } catch (RemoteException re) {
                /* ignore - the other side will time out */
        } finally {
            recycleMagnificationSpecAndRegionIfNeeded(spec, interactiveRegion);
        }
    }

    private void recycleMagnificationSpecAndRegionIfNeeded(MagnificationSpec spec, Region region) {
        if (android.os.Process.myPid() != Binder.getCallingPid()) {
            // Specs are cached in the system process and obtained from a pool when read from
            // a parcel, so only recycle the spec if called from another process.
            if (spec != null) {
                spec.recycle();
            }
        } else {
            // Regions are obtained in the system process and instantiated when read from
            // a parcel, so only recycle the region if caled from the same process.
            if (region != null) {
                region.recycle();
            }
        }
    }

+1 −28
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.view;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Pools.SynchronizedPool;

/**
 * This class represents spec for performing screen magnification.
@@ -27,9 +26,6 @@ import android.util.Pools.SynchronizedPool;
 * @hide
 */
public class MagnificationSpec implements Parcelable {
    private static final int MAX_POOL_SIZE = 20;
    private static final SynchronizedPool<MagnificationSpec> sPool =
            new SynchronizedPool<>(MAX_POOL_SIZE);

    /** The magnification scaling factor. */
    public float scale = 1.0f;
@@ -46,10 +42,6 @@ public class MagnificationSpec implements Parcelable {
     */
    public float offsetY;

    private MagnificationSpec() {
        /* do nothing - reducing visibility */
    }

    public void initialize(float scale, float offsetX, float offsetY) {
        if (scale < 1) {
            throw new IllegalArgumentException("Scale must be greater than or equal to one!");
@@ -63,24 +55,6 @@ public class MagnificationSpec implements Parcelable {
        return scale == 1.0f && offsetX == 0 && offsetY == 0;
    }

    public static MagnificationSpec obtain(MagnificationSpec other) {
        MagnificationSpec info = obtain();
        info.scale = other.scale;
        info.offsetX = other.offsetX;
        info.offsetY = other.offsetY;
        return info;
    }

    public static MagnificationSpec obtain() {
        MagnificationSpec spec = sPool.acquire();
        return (spec != null) ? spec : new MagnificationSpec();
    }

    public void recycle() {
        clear();
        sPool.release(this);
    }

    public void clear() {
       scale = 1.0f;
       offsetX = 0.0f;
@@ -103,7 +77,6 @@ public class MagnificationSpec implements Parcelable {
        parcel.writeFloat(scale);
        parcel.writeFloat(offsetX);
        parcel.writeFloat(offsetY);
        recycle();
    }

    @Override
@@ -155,7 +128,7 @@ public class MagnificationSpec implements Parcelable {

        @Override
        public MagnificationSpec createFromParcel(Parcel parcel) {
            MagnificationSpec spec = MagnificationSpec.obtain();
            MagnificationSpec spec = new MagnificationSpec();
            spec.initFromParcel(parcel);
            return spec;
        }
+1 −2
Original line number Diff line number Diff line
@@ -19,16 +19,15 @@ package com.android.server.accessibility;
import android.os.Binder;
import android.os.RemoteException;
import android.util.Slog;
import android.view.MagnificationSpec;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.view.accessibility.IAccessibilityInteractionConnection;
import android.view.accessibility.IAccessibilityInteractionConnectionCallback;

import com.android.internal.annotations.GuardedBy;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * If we are stripping and/or replacing the actions from a window, we need to intercept the
+9 −10
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ public class FullScreenMagnificationController {
         * The current magnification spec. If an animation is running, this
         * reflects the end state.
         */
        private final MagnificationSpec mCurrentMagnificationSpec = MagnificationSpec.obtain();
        private final MagnificationSpec mCurrentMagnificationSpec = new MagnificationSpec();

        private final Region mMagnificationRegion = Region.obtain();
        private final Rect mMagnificationBounds = new Rect();
@@ -1227,13 +1227,11 @@ public class FullScreenMagnificationController {
         * The magnification spec that was sent to the window manager. This should
         * only be accessed with the lock held.
         */
        private final MagnificationSpec mSentMagnificationSpec = MagnificationSpec.obtain();
        private final MagnificationSpec mSentMagnificationSpec = new MagnificationSpec();

        private final MagnificationSpec mStartMagnificationSpec = MagnificationSpec.obtain();
        private final MagnificationSpec mStartMagnificationSpec = new MagnificationSpec();

        private final MagnificationSpec mEndMagnificationSpec = MagnificationSpec.obtain();

        private final MagnificationSpec mTmpMagnificationSpec = MagnificationSpec.obtain();
        private final MagnificationSpec mEndMagnificationSpec = new MagnificationSpec();

        /**
         * The animator should only be accessed and modified on the main (e.g. animation) thread.
@@ -1335,15 +1333,16 @@ public class FullScreenMagnificationController {
            synchronized (mLock) {
                if (mEnabled) {
                    float fract = animation.getAnimatedFraction();
                    mTmpMagnificationSpec.scale = mStartMagnificationSpec.scale
                    MagnificationSpec magnificationSpec = new MagnificationSpec();
                    magnificationSpec.scale = mStartMagnificationSpec.scale
                            + (mEndMagnificationSpec.scale - mStartMagnificationSpec.scale) * fract;
                    mTmpMagnificationSpec.offsetX = mStartMagnificationSpec.offsetX
                    magnificationSpec.offsetX = mStartMagnificationSpec.offsetX
                            + (mEndMagnificationSpec.offsetX - mStartMagnificationSpec.offsetX)
                            * fract;
                    mTmpMagnificationSpec.offsetY = mStartMagnificationSpec.offsetY
                    magnificationSpec.offsetY = mStartMagnificationSpec.offsetY
                            + (mEndMagnificationSpec.offsetY - mStartMagnificationSpec.offsetY)
                            * fract;
                    setMagnificationSpecLocked(mTmpMagnificationSpec);
                    setMagnificationSpecLocked(magnificationSpec);
                }
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -654,7 +654,7 @@ final class AccessibilityController {

            private final Path mCircularPath;

            private final MagnificationSpec mMagnificationSpec = MagnificationSpec.obtain();
            private final MagnificationSpec mMagnificationSpec = new MagnificationSpec();

            private final float mBorderWidth;
            private final int mHalfBorderWidth;
Loading