Expose method to create a SyncRtSurfaceTransactionApplier when attached
Test: Builds Change-Id: I0e90ce3976b953599740731393263dc00f0f3e63
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user