diff options
| -rw-r--r-- | packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplier.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplier.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplier.java index a9cf857c3e50..807edf624db8 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplier.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplier.java @@ -25,6 +25,8 @@ import android.view.SurfaceControl.Transaction; import android.view.View; import android.view.ViewRootImpl; +import java.util.function.Consumer; + /** * Helper class to apply surface transactions in sync with RenderThread. */ @@ -78,6 +80,35 @@ public class SyncRtSurfaceTransactionApplier { applyParams(t.mTransaction, params, t.mTmpValues); } + /** + * Creates an instance of SyncRtSurfaceTransactionApplier, deferring until the target view is + * attached if necessary. + */ + public static void create(final View targetView, + final Consumer<SyncRtSurfaceTransactionApplier> callback) { + if (targetView == null) { + // No target view, no applier + callback.accept(null); + } else if (targetView.getViewRootImpl() != null) { + // Already attached, we're good to go + callback.accept(new SyncRtSurfaceTransactionApplier(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 SyncRtSurfaceTransactionApplier(targetView)); + } + + @Override + public void onViewDetachedFromWindow(View v) { + // Do nothing + } + }); + } + } + private static void applyParams(Transaction t, SurfaceParams params, float[] tmpFloat9) { t.setMatrix(params.surface, params.matrix, tmpFloat9); t.setWindowCrop(params.surface, params.windowCrop); |