Merge "Updating SurfaceTransactionApplier to handle view not being attached" into udc-dev am: 8b0fcbffb0 am: 0abdf52d79
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/23066497 Change-Id: Ic3492e1553db87b264a8064dd7fe71596b6ed470 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2114,12 +2114,11 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void linkRecentsViewScroll() {
|
protected void linkRecentsViewScroll() {
|
||||||
SurfaceTransactionApplier.create(mRecentsView, applier -> {
|
SurfaceTransactionApplier applier = new SurfaceTransactionApplier(mRecentsView);
|
||||||
runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTransformParams()
|
runActionOnRemoteHandles(remoteTargetHandle -> remoteTargetHandle.getTransformParams()
|
||||||
.setSyncTransactionApplier(applier));
|
.setSyncTransactionApplier(applier));
|
||||||
runOnRecentsAnimationAndLauncherBound(() ->
|
runOnRecentsAnimationAndLauncherBound(() ->
|
||||||
mRecentsAnimationTargets.addReleaseCheck(applier));
|
mRecentsAnimationTargets.addReleaseCheck(applier));
|
||||||
});
|
|
||||||
|
|
||||||
mRecentsView.addOnScrollChangedListener(mOnRecentsScrollListener);
|
mRecentsView.addOnScrollChangedListener(mOnRecentsScrollListener);
|
||||||
runOnRecentsAnimationAndLauncherBound(() ->
|
runOnRecentsAnimationAndLauncherBound(() ->
|
||||||
|
|||||||
@@ -22,13 +22,11 @@ import android.os.Message;
|
|||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
import android.view.SurfaceControl.Transaction;
|
import android.view.SurfaceControl.Transaction;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnAttachStateChangeListener;
|
||||||
import android.view.ViewRootImpl;
|
import android.view.ViewRootImpl;
|
||||||
|
|
||||||
import com.android.quickstep.RemoteAnimationTargets.ReleaseCheck;
|
import com.android.quickstep.RemoteAnimationTargets.ReleaseCheck;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to apply surface transactions in sync with RenderThread similar to
|
* Helper class to apply surface transactions in sync with RenderThread similar to
|
||||||
* android.view.SyncRtSurfaceTransactionApplier
|
* android.view.SyncRtSurfaceTransactionApplier
|
||||||
@@ -39,22 +37,47 @@ public class SurfaceTransactionApplier extends ReleaseCheck {
|
|||||||
|
|
||||||
private static final int MSG_UPDATE_SEQUENCE_NUMBER = 0;
|
private static final int MSG_UPDATE_SEQUENCE_NUMBER = 0;
|
||||||
|
|
||||||
private final SurfaceControl mBarrierSurfaceControl;
|
|
||||||
private final ViewRootImpl mTargetViewRootImpl;
|
|
||||||
private final Handler mApplyHandler;
|
private final Handler mApplyHandler;
|
||||||
|
|
||||||
|
private boolean mInitialized;
|
||||||
|
private SurfaceControl mBarrierSurfaceControl;
|
||||||
|
private ViewRootImpl mTargetViewRootImpl;
|
||||||
|
|
||||||
private int mLastSequenceNumber = 0;
|
private int mLastSequenceNumber = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param targetView The view in the surface that acts as synchronization anchor.
|
* @param targetView The view in the surface that acts as synchronization anchor.
|
||||||
*/
|
*/
|
||||||
public SurfaceTransactionApplier(View targetView) {
|
public SurfaceTransactionApplier(View targetView) {
|
||||||
mTargetViewRootImpl = targetView.getViewRootImpl();
|
if (targetView.isAttachedToWindow()) {
|
||||||
mBarrierSurfaceControl = mTargetViewRootImpl.getSurfaceControl();
|
initialize(targetView);
|
||||||
|
} else {
|
||||||
|
mInitialized = false;
|
||||||
|
targetView.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onViewAttachedToWindow(View v) {
|
||||||
|
if (!mInitialized) {
|
||||||
|
targetView.removeOnAttachStateChangeListener(this);
|
||||||
|
initialize(targetView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewDetachedFromWindow(View v) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
mApplyHandler = new Handler(this::onApplyMessage);
|
mApplyHandler = new Handler(this::onApplyMessage);
|
||||||
setCanRelease(true);
|
setCanRelease(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initialize(View view) {
|
||||||
|
mTargetViewRootImpl = view.getViewRootImpl();
|
||||||
|
mBarrierSurfaceControl = mTargetViewRootImpl.getSurfaceControl();
|
||||||
|
mInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean onApplyMessage(Message msg) {
|
protected boolean onApplyMessage(Message msg) {
|
||||||
if (msg.what == MSG_UPDATE_SEQUENCE_NUMBER) {
|
if (msg.what == MSG_UPDATE_SEQUENCE_NUMBER) {
|
||||||
setCanRelease(msg.arg1 == mLastSequenceNumber);
|
setCanRelease(msg.arg1 == mLastSequenceNumber);
|
||||||
@@ -70,6 +93,10 @@ public class SurfaceTransactionApplier extends ReleaseCheck {
|
|||||||
* this method to avoid synchronization issues.
|
* this method to avoid synchronization issues.
|
||||||
*/
|
*/
|
||||||
public void scheduleApply(SurfaceTransaction params) {
|
public void scheduleApply(SurfaceTransaction params) {
|
||||||
|
if (!mInitialized) {
|
||||||
|
params.getTransaction().apply();
|
||||||
|
return;
|
||||||
|
}
|
||||||
View view = mTargetViewRootImpl.getView();
|
View view = mTargetViewRootImpl.getView();
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
return;
|
return;
|
||||||
@@ -93,33 +120,4 @@ public class SurfaceTransactionApplier extends ReleaseCheck {
|
|||||||
// Make sure a frame gets scheduled.
|
// Make sure a frame gets scheduled.
|
||||||
view.invalidate();
|
view.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of SurfaceTransactionApplier, deferring until the target view is
|
|
||||||
* attached if necessary.
|
|
||||||
*/
|
|
||||||
public static void create(
|
|
||||||
final View targetView, final Consumer<SurfaceTransactionApplier> callback) {
|
|
||||||
if (targetView == null) {
|
|
||||||
// No target view, no applier
|
|
||||||
callback.accept(null);
|
|
||||||
} else if (targetView.isAttachedToWindow()) {
|
|
||||||
// Already attached, we're good to go
|
|
||||||
callback.accept(new SurfaceTransactionApplier(targetView));
|
|
||||||
} else {
|
|
||||||
// Haven't been attached before we can get the view root
|
|
||||||
targetView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onViewAttachedToWindow(View v) {
|
|
||||||
targetView.removeOnAttachStateChangeListener(this);
|
|
||||||
callback.accept(new SurfaceTransactionApplier(targetView));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewDetachedFromWindow(View v) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user