From e3f070a1728d5e0d0cc999ac19e75a0ad3771943 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Thu, 7 Apr 2022 18:11:20 +0800 Subject: [PATCH] [Re-land] Remove getSfInstance usage from ViewRootImpl The getSfInstance usage on ViewRootImpl is target to reduce jank when moving split divider, but legacy split is going to be depracated and it didn't used on new split too so we can remove whole related codes safely. Bug: 222696368 Test: build pass Change-Id: Id492c738942c2e01fce85c231350d16ef88242f5 --- .../android/view/SurfaceControlViewHost.java | 10 ++----- core/java/android/view/ViewRootImpl.java | 11 ++------ .../wm/shell/common/SystemWindows.java | 3 +-- .../dagger/WMShellConcurrencyModule.java | 27 ------------------- .../shell/windowdecor/WindowDecoration.java | 7 +++-- .../windowdecor/WindowDecorationTests.java | 12 +++------ .../UnfoldLightRevealOverlayAnimation.kt | 2 +- 7 files changed, 13 insertions(+), 59 deletions(-) diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java index 5721fa6dd11af..3acb0534e388e 100644 --- a/core/java/android/view/SurfaceControlViewHost.java +++ b/core/java/android/view/SurfaceControlViewHost.java @@ -28,8 +28,8 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.util.Log; -import android.window.WindowTokenClient; import android.view.accessibility.IAccessibilityEmbeddedConnection; +import android.window.WindowTokenClient; import java.util.Objects; @@ -271,14 +271,8 @@ public class SurfaceControlViewHost { /** @hide */ public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d, @NonNull WindowlessWindowManager wwm) { - this(c, d, wwm, false /* useSfChoreographer */); - } - - /** @hide */ - public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d, - @NonNull WindowlessWindowManager wwm, boolean useSfChoreographer) { mWm = wwm; - mViewRoot = new ViewRootImpl(c, d, mWm, new WindowlessWindowLayout(), useSfChoreographer); + mViewRoot = new ViewRootImpl(c, d, mWm, new WindowlessWindowLayout()); addConfigCallback(c, d); WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index fff6c60366014..4780764f8be2f 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -902,17 +902,11 @@ public final class ViewRootImpl implements ViewParent, private String mTag = TAG; public ViewRootImpl(Context context, Display display) { - this(context, display, WindowManagerGlobal.getWindowSession(), new WindowLayout(), - false /* useSfChoreographer */); + this(context, display, WindowManagerGlobal.getWindowSession(), new WindowLayout()); } public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session, WindowLayout windowLayout) { - this(context, display, session, windowLayout, false /* useSfChoreographer */); - } - - public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session, - WindowLayout windowLayout, boolean useSfChoreographer) { mContext = context; mWindowSession = session; mWindowLayout = windowLayout; @@ -944,8 +938,7 @@ public final class ViewRootImpl implements ViewParent, mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; mFallbackEventHandler = new PhoneFallbackEventHandler(context); // TODO(b/222696368): remove getSfInstance usage and use vsyncId for transactions - mChoreographer = useSfChoreographer - ? Choreographer.getSfInstance() : Choreographer.getInstance(); + mChoreographer = Choreographer.getInstance(); mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); mInsetsController = new InsetsController(new ViewRootInsetsControllerHost(this)); mHandwritingInitiator = new HandwritingInitiator(mViewConfiguration, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java index d5875c03ccd21..e270edb800bdf 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java @@ -221,8 +221,7 @@ public class SystemWindows { } final Display display = mDisplayController.getDisplay(mDisplayId); SurfaceControlViewHost viewRoot = - new SurfaceControlViewHost( - view.getContext(), display, wwm, true /* useSfChoreographer */); + new SurfaceControlViewHost(view.getContext(), display, wwm); attrs.flags |= FLAG_HARDWARE_ACCELERATED; viewRoot.setView(view, attrs); mViewRoots.put(view, viewRoot); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java index 35a309a8352c8..0cc545a7724a2 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellConcurrencyModule.java @@ -20,7 +20,6 @@ import static android.os.Process.THREAD_PRIORITY_BACKGROUND; import static android.os.Process.THREAD_PRIORITY_DISPLAY; import static android.os.Process.THREAD_PRIORITY_TOP_APP_BOOST; -import android.animation.AnimationHandler; import android.content.Context; import android.os.Build; import android.os.Handler; @@ -31,11 +30,9 @@ import android.view.Choreographer; import androidx.annotation.Nullable; -import com.android.internal.graphics.SfVsyncFrameCallbackProvider; import com.android.wm.shell.R; import com.android.wm.shell.common.HandlerExecutor; import com.android.wm.shell.common.ShellExecutor; -import com.android.wm.shell.common.annotations.ChoreographerSfVsync; import com.android.wm.shell.common.annotations.ExternalMainThread; import com.android.wm.shell.common.annotations.ShellAnimationThread; import com.android.wm.shell.common.annotations.ShellBackgroundThread; @@ -194,30 +191,6 @@ public abstract class WMShellConcurrencyModule { return new HandlerExecutor(shellSplashscreenThread.getThreadHandler()); } - /** - * Provide a Shell main-thread AnimationHandler. The AnimationHandler can be set on - * {@link android.animation.ValueAnimator}s and will ensure that the animation will run on - * the Shell main-thread with the SF vsync. - */ - @WMSingleton - @Provides - @ChoreographerSfVsync - public static AnimationHandler provideShellMainExecutorSfVsyncAnimationHandler( - @ShellMainThread ShellExecutor mainExecutor) { - try { - AnimationHandler handler = new AnimationHandler(); - mainExecutor.executeBlocking(() -> { - // This is called on the animation thread since it calls - // Choreographer.getSfInstance() which returns a thread-local Choreographer instance - // that uses the SF vsync - handler.setProvider(new SfVsyncFrameCallbackProvider()); - }); - return handler; - } catch (InterruptedException e) { - throw new RuntimeException("Failed to initialize SfVsync animation handler in 1s", e); - } - } - /** * Provides a Shell background thread Handler for low priority background tasks. */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java index 506a4c0f90f33..5e64a06e03265 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java @@ -248,7 +248,7 @@ public abstract class WindowDecoration lp.setTrustedOverlay(); if (mViewHost == null) { mViewHost = mSurfaceControlViewHostFactory.create(mDecorWindowContext, mDisplay, - mCaptionWindowManager, true); + mCaptionWindowManager); mViewHost.setView(outResult.mRootView, lp); } else { mViewHost.relayout(lp); @@ -345,9 +345,8 @@ public abstract class WindowDecoration } interface SurfaceControlViewHostFactory { - default SurfaceControlViewHost create( - Context c, Display d, WindowlessWindowManager wmm, boolean useSfChoreographer) { - return new SurfaceControlViewHost(c, d, wmm, useSfChoreographer); + default SurfaceControlViewHost create(Context c, Display d, WindowlessWindowManager wmm) { + return new SurfaceControlViewHost(c, d, wmm); } } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java index 226843eca64e0..e11be31aa40ea 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java @@ -24,7 +24,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.argThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; @@ -107,7 +106,7 @@ public class WindowDecorationTests extends ShellTestCase { mMockSurfaceControlFinishT = createMockSurfaceControlTransaction(); doReturn(mMockSurfaceControlViewHost).when(mMockSurfaceControlViewHostFactory) - .create(any(), any(), any(), anyBoolean()); + .create(any(), any(), any()); } @Test @@ -148,8 +147,7 @@ public class WindowDecorationTests extends ShellTestCase { verify(decorContainerSurfaceBuilder, never()).build(); verify(taskBackgroundSurfaceBuilder, never()).build(); - verify(mMockSurfaceControlViewHostFactory, never()) - .create(any(), any(), any(), anyBoolean()); + verify(mMockSurfaceControlViewHostFactory, never()).create(any(), any(), any()); verify(mMockSurfaceControlFinishT).hide(taskSurface); @@ -207,8 +205,7 @@ public class WindowDecorationTests extends ShellTestCase { verify(mMockSurfaceControlStartT).setLayer(taskBackgroundSurface, -1); verify(mMockSurfaceControlStartT).show(taskBackgroundSurface); - verify(mMockSurfaceControlViewHostFactory) - .create(any(), eq(defaultDisplay), any(), anyBoolean()); + verify(mMockSurfaceControlViewHostFactory).create(any(), eq(defaultDisplay), any()); verify(mMockSurfaceControlViewHost) .setView(same(mMockView), argThat(lp -> lp.height == 64 @@ -326,8 +323,7 @@ public class WindowDecorationTests extends ShellTestCase { verify(mMockDisplayController).removeDisplayWindowListener(same(listener)); assertThat(mRelayoutResult.mRootView).isSameInstanceAs(mMockView); - verify(mMockSurfaceControlViewHostFactory) - .create(any(), eq(mockDisplay), any(), anyBoolean()); + verify(mMockSurfaceControlViewHostFactory).create(any(), eq(mockDisplay), any()); verify(mMockSurfaceControlViewHost).setView(same(mMockView), any()); } diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt index 8f2a432d0ba1b..fc20ac241e387 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt @@ -138,7 +138,7 @@ constructor( ensureOverlayRemoved() - val newRoot = SurfaceControlViewHost(context, context.display!!, wwm, false) + val newRoot = SurfaceControlViewHost(context, context.display!!, wwm) val newView = LightRevealScrim(context, null).apply { revealEffect = createLightRevealEffect()