diff options
| author | 2018-12-12 00:14:09 +0000 | |
|---|---|---|
| committer | 2018-12-12 00:14:09 +0000 | |
| commit | a56a145ed84a104428e7f07f2afb9942f3bda2fe (patch) | |
| tree | 6a0b09216f22e4a4c6b038fd8fa83a0b52df12fa | |
| parent | 7fed87622eb7d7b8b9faa2b0666bad3c65cdda8f (diff) | |
| parent | 71eda589c2a9de35da59876db7e6bf8096fe33e8 (diff) | |
Merge "Expose method to create a SyncRtSurfaceTransactionApplier when attached"
| -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); |