what-the-bank/sources/io/flutter/embedding/android/FlutterTextureView.java

169 lines
6.9 KiB
Java

package io.flutter.embedding.android;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.TextureView;
import io.flutter.Log;
import io.flutter.embedding.engine.renderer.FlutterRenderer;
import io.flutter.embedding.engine.renderer.RenderSurface;
/* loaded from: classes5.dex */
public class FlutterTextureView extends TextureView implements RenderSurface {
private static final String TAG = "FlutterTextureView";
private FlutterRenderer flutterRenderer;
private boolean isAttachedToFlutterRenderer;
private boolean isPaused;
private boolean isSurfaceAvailableForRendering;
private Surface renderSurface;
private final TextureView.SurfaceTextureListener surfaceTextureListener;
@Override // io.flutter.embedding.engine.renderer.RenderSurface
public FlutterRenderer getAttachedRenderer() {
return this.flutterRenderer;
}
public void setRenderSurface(Surface surface) {
this.renderSurface = surface;
}
public FlutterTextureView(Context context) {
this(context, null);
}
public FlutterTextureView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.isSurfaceAvailableForRendering = false;
this.isAttachedToFlutterRenderer = false;
this.isPaused = false;
this.surfaceTextureListener = new TextureView.SurfaceTextureListener(this) { // from class: io.flutter.embedding.android.FlutterTextureView.1
final FlutterTextureView this$0;
@Override // android.view.TextureView.SurfaceTextureListener
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
{
this.this$0 = this;
}
@Override // android.view.TextureView.SurfaceTextureListener
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
Log.v(FlutterTextureView.TAG, "SurfaceTextureListener.onSurfaceTextureAvailable()");
this.this$0.isSurfaceAvailableForRendering = true;
if (this.this$0.isAttachedToFlutterRenderer) {
this.this$0.connectSurfaceToRenderer();
}
}
@Override // android.view.TextureView.SurfaceTextureListener
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
Log.v(FlutterTextureView.TAG, "SurfaceTextureListener.onSurfaceTextureSizeChanged()");
if (this.this$0.isAttachedToFlutterRenderer) {
this.this$0.changeSurfaceSize(i, i2);
}
}
@Override // android.view.TextureView.SurfaceTextureListener
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
Log.v(FlutterTextureView.TAG, "SurfaceTextureListener.onSurfaceTextureDestroyed()");
this.this$0.isSurfaceAvailableForRendering = false;
if (this.this$0.isAttachedToFlutterRenderer) {
this.this$0.disconnectSurfaceFromRenderer();
}
if (this.this$0.renderSurface == null) {
return true;
}
this.this$0.renderSurface.release();
this.this$0.renderSurface = null;
return true;
}
};
init();
}
private void init() {
setSurfaceTextureListener(this.surfaceTextureListener);
}
@Override // io.flutter.embedding.engine.renderer.RenderSurface
public void attachToRenderer(FlutterRenderer flutterRenderer) {
Log.v(TAG, "Attaching to FlutterRenderer.");
if (this.flutterRenderer != null) {
Log.v(TAG, "Already connected to a FlutterRenderer. Detaching from old one and attaching to new one.");
this.flutterRenderer.stopRenderingToSurface();
}
this.flutterRenderer = flutterRenderer;
this.isAttachedToFlutterRenderer = true;
if (this.isSurfaceAvailableForRendering) {
Log.v(TAG, "Surface is available for rendering. Connecting FlutterRenderer to Android surface.");
connectSurfaceToRenderer();
}
}
@Override // io.flutter.embedding.engine.renderer.RenderSurface
public void detachFromRenderer() {
if (this.flutterRenderer != null) {
if (getWindowToken() != null) {
Log.v(TAG, "Disconnecting FlutterRenderer from Android surface.");
disconnectSurfaceFromRenderer();
}
this.flutterRenderer = null;
this.isAttachedToFlutterRenderer = false;
return;
}
Log.w(TAG, "detachFromRenderer() invoked when no FlutterRenderer was attached.");
}
@Override // io.flutter.embedding.engine.renderer.RenderSurface
public void pause() {
if (this.flutterRenderer == null) {
Log.w(TAG, "pause() invoked when no FlutterRenderer was attached.");
return;
}
this.flutterRenderer = null;
this.isPaused = true;
this.isAttachedToFlutterRenderer = false;
}
/* JADX INFO: Access modifiers changed from: private */
public void connectSurfaceToRenderer() {
if (this.flutterRenderer == null || getSurfaceTexture() == null) {
throw new IllegalStateException("connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null.");
}
Surface surface = this.renderSurface;
if (surface != null) {
surface.release();
this.renderSurface = null;
}
Surface surface2 = new Surface(getSurfaceTexture());
this.renderSurface = surface2;
this.flutterRenderer.startRenderingToSurface(surface2, this.isPaused);
this.isPaused = false;
}
/* JADX INFO: Access modifiers changed from: private */
public void changeSurfaceSize(int i, int i2) {
if (this.flutterRenderer == null) {
throw new IllegalStateException("changeSurfaceSize() should only be called when flutterRenderer is non-null.");
}
Log.v(TAG, "Notifying FlutterRenderer that Android surface size has changed to " + i + " x " + i2);
this.flutterRenderer.surfaceChanged(i, i2);
}
/* JADX INFO: Access modifiers changed from: private */
public void disconnectSurfaceFromRenderer() {
FlutterRenderer flutterRenderer = this.flutterRenderer;
if (flutterRenderer == null) {
throw new IllegalStateException("disconnectSurfaceFromRenderer() should only be called when flutterRenderer is non-null.");
}
flutterRenderer.stopRenderingToSurface();
Surface surface = this.renderSurface;
if (surface != null) {
surface.release();
this.renderSurface = null;
}
}
}