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

Commit f0412592 authored by Issei Suzuki's avatar Issei Suzuki
Browse files

Clean up SurfaceView

Bug: 136538998
Test: no-op refactoring CL. Existing unit tests still pass.
Change-Id: Ibd0310a87ed38aa48215be9cba54f1c7a2a8a9fa
parent 4cb04496
Loading
Loading
Loading
Loading
+19 −32
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@ import static android.view.WindowManagerPolicyConstants.APPLICATION_PANEL_SUBLAY
import android.annotation.UnsupportedAppUsage;
import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.res.CompatibilityInfo.Translator;
import android.content.res.CompatibilityInfo.Translator;
import android.content.res.Configuration;
import android.graphics.BlendMode;
import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
@@ -102,8 +101,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = false;


    @UnsupportedAppUsage
    @UnsupportedAppUsage
    final ArrayList<SurfaceHolder.Callback> mCallbacks
    final ArrayList<SurfaceHolder.Callback> mCallbacks = new ArrayList<>();
            = new ArrayList<SurfaceHolder.Callback>();


    final int[] mLocation = new int[2];
    final int[] mLocation = new int[2];


@@ -127,7 +125,6 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
    SurfaceControl mDeferredDestroySurfaceControl;
    SurfaceControl mDeferredDestroySurfaceControl;
    SurfaceControl mBackgroundControl;
    SurfaceControl mBackgroundControl;
    final Rect mTmpRect = new Rect();
    final Rect mTmpRect = new Rect();
    final Configuration mConfiguration = new Configuration();


    Paint mRoundedViewportPaint;
    Paint mRoundedViewportPaint;


@@ -137,24 +134,15 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
    boolean mIsCreating = false;
    boolean mIsCreating = false;
    private volatile boolean mRtHandlingPositionUpdates = false;
    private volatile boolean mRtHandlingPositionUpdates = false;


    private final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener
    private final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener =
            = new ViewTreeObserver.OnScrollChangedListener() {
            this::updateSurface;
                    @Override
                    public void onScrollChanged() {
                        updateSurface();
                    }
            };


    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private final ViewTreeObserver.OnPreDrawListener mDrawListener =
    private final ViewTreeObserver.OnPreDrawListener mDrawListener = () -> {
            new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
        // reposition ourselves where the surface is
        // reposition ourselves where the surface is
        mHaveFrame = getWidth() > 0 && getHeight() > 0;
        mHaveFrame = getWidth() > 0 && getHeight() > 0;
        updateSurface();
        updateSurface();
        return true;
        return true;
                }
    };
    };


    boolean mRequestedVisible = false;
    boolean mRequestedVisible = false;
@@ -190,7 +178,6 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    final Rect mSurfaceFrame = new Rect();
    final Rect mSurfaceFrame = new Rect();
    int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
    int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
    private Translator mTranslator;


    private boolean mGlobalListenersAdded;
    private boolean mGlobalListenersAdded;
    private boolean mAttachedToWindow;
    private boolean mAttachedToWindow;
@@ -555,9 +542,9 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
            return;
            return;
        }
        }


        mTranslator = viewRoot.mTranslator;
        final Translator translator = viewRoot.mTranslator;
        if (mTranslator != null) {
        if (translator != null) {
            mSurface.setCompatibilityTranslator(mTranslator);
            mSurface.setCompatibilityTranslator(translator);
        }
        }


        int myWidth = mRequestedWidth;
        int myWidth = mRequestedWidth;
@@ -596,8 +583,8 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
                mScreenRect.top = mWindowSpaceTop;
                mScreenRect.top = mWindowSpaceTop;
                mScreenRect.right = mWindowSpaceLeft + getWidth();
                mScreenRect.right = mWindowSpaceLeft + getWidth();
                mScreenRect.bottom = mWindowSpaceTop + getHeight();
                mScreenRect.bottom = mWindowSpaceTop + getHeight();
                if (mTranslator != null) {
                if (translator != null) {
                    mTranslator.translateRectInAppWindowToScreen(mScreenRect);
                    translator.translateRectInAppWindowToScreen(mScreenRect);
                }
                }


                final Rect surfaceInsets = getParentSurfaceInsets();
                final Rect surfaceInsets = getParentSurfaceInsets();
@@ -683,11 +670,11 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb


                    mSurfaceFrame.left = 0;
                    mSurfaceFrame.left = 0;
                    mSurfaceFrame.top = 0;
                    mSurfaceFrame.top = 0;
                    if (mTranslator == null) {
                    if (translator == null) {
                        mSurfaceFrame.right = mSurfaceWidth;
                        mSurfaceFrame.right = mSurfaceWidth;
                        mSurfaceFrame.bottom = mSurfaceHeight;
                        mSurfaceFrame.bottom = mSurfaceHeight;
                    } else {
                    } else {
                        float appInvertedScale = mTranslator.applicationInvertedScale;
                        float appInvertedScale = translator.applicationInvertedScale;
                        mSurfaceFrame.right = (int) (mSurfaceWidth * appInvertedScale + 0.5f);
                        mSurfaceFrame.right = (int) (mSurfaceWidth * appInvertedScale + 0.5f);
                        mSurfaceFrame.bottom = (int) (mSurfaceHeight * appInvertedScale + 0.5f);
                        mSurfaceFrame.bottom = (int) (mSurfaceHeight * appInvertedScale + 0.5f);
                    }
                    }
@@ -821,8 +808,8 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
                mScreenRect.set(mWindowSpaceLeft, mWindowSpaceTop,
                mScreenRect.set(mWindowSpaceLeft, mWindowSpaceTop,
                        mWindowSpaceLeft + mLocation[0], mWindowSpaceTop + mLocation[1]);
                        mWindowSpaceLeft + mLocation[0], mWindowSpaceTop + mLocation[1]);


                if (mTranslator != null) {
                if (translator != null) {
                    mTranslator.translateRectInAppWindowToScreen(mScreenRect);
                    translator.translateRectInAppWindowToScreen(mScreenRect);
                }
                }


                if (mSurfaceControl == null) {
                if (mSurfaceControl == null) {
@@ -1037,7 +1024,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
            synchronized (mCallbacks) {
            synchronized (mCallbacks) {
                // This is a linear search, but in practice we'll
                // This is a linear search, but in practice we'll
                // have only a couple callbacks, so it doesn't matter.
                // have only a couple callbacks, so it doesn't matter.
                if (mCallbacks.contains(callback) == false) {
                if (!mCallbacks.contains(callback)) {
                    mCallbacks.add(callback);
                    mCallbacks.add(callback);
                }
                }
            }
            }