From 7eb2bed2246b6cdf849ce7b4bdb27b7e75283aed Mon Sep 17 00:00:00 2001 From: Tarandeep Singh Date: Tue, 11 Feb 2020 14:55:28 -0800 Subject: [PATCH] Apply Insets animation when hw acceleration unavailable On certain midrange and lower-specced devices, apps could be running without hardware acceleration. Insets animation relied on ThreadRenderer's frame-by-frame callbacks to animate system bars / IME. When hardware acceleration is not available, we should just animate it without any frame sync for now. Bug: 111084606 Bug: 149342281 Test: Manually tested on Go device 1. Use app like Messages which don't have hw accelaration 2. Tap on editor to verify IME appears. Change-Id: Icf453f09f4236a5092cf3ff7be99f98ece073979 --- core/java/android/view/InsetsController.java | 10 +++++-- .../view/SyncRtSurfaceTransactionApplier.java | 29 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 54de1bb3739d7..f3051a426f804 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -39,7 +39,6 @@ import android.util.Log; import android.util.Pair; import android.util.Property; import android.util.SparseArray; -import android.view.InputDevice.MotionRange; import android.view.InsetsSourceConsumer.ShowResult; import android.view.InsetsState.InternalInsetsType; import android.view.SurfaceControl.Transaction; @@ -680,7 +679,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } mApplier = new SyncRtSurfaceTransactionApplier(mViewRoot.mView); } - mApplier.scheduleApply(params); + if (mViewRoot.mView.isHardwareAccelerated()) { + mApplier.scheduleApply(params); + } else { + // Window doesn't support hardware acceleration, no synchronization for now. + // TODO(b/149342281): use mViewRoot.mSurface.getNextFrameNumber() to sync on every + // frame instead. + mApplier.applyParams(new Transaction(), -1 /* frame */, params); + } } void notifyControlRevoked(InsetsSourceConsumer consumer) { diff --git a/core/java/android/view/SyncRtSurfaceTransactionApplier.java b/core/java/android/view/SyncRtSurfaceTransactionApplier.java index abe44f45aba53..15252b11d5ac4 100644 --- a/core/java/android/view/SyncRtSurfaceTransactionApplier.java +++ b/core/java/android/view/SyncRtSurfaceTransactionApplier.java @@ -65,20 +65,33 @@ public class SyncRtSurfaceTransactionApplier { return; } Transaction t = new Transaction(); - for (int i = params.length - 1; i >= 0; i--) { - SurfaceParams surfaceParams = params[i]; - SurfaceControl surface = surfaceParams.surface; - t.deferTransactionUntil(surface, mTargetSc, frame); - applyParams(t, surfaceParams, mTmpFloat9); - } - t.setEarlyWakeup(); - t.apply(); + applyParams(t, frame, params); }); // Make sure a frame gets scheduled. mTargetViewRootImpl.getView().invalidate(); } + /** + * Applies surface parameters on the next frame. + * @param t transaction to apply all parameters in. + * @param frame frame to synchronize to. Set -1 when sync is not required. + * @param params The surface parameters to apply. DO NOT MODIFY the list after passing into + * this method to avoid synchronization issues. + */ + void applyParams(Transaction t, long frame, final SurfaceParams... params) { + for (int i = params.length - 1; i >= 0; i--) { + SurfaceParams surfaceParams = params[i]; + SurfaceControl surface = surfaceParams.surface; + if (frame > 0) { + t.deferTransactionUntil(surface, mTargetSc, frame); + } + applyParams(t, surfaceParams, mTmpFloat9); + } + t.setEarlyWakeup(); + t.apply(); + } + public static void applyParams(Transaction t, SurfaceParams params, float[] tmpFloat9) { if ((params.flags & FLAG_MATRIX) != 0) { t.setMatrix(params.surface, params.matrix, tmpFloat9);