Rabbit-R1/original r1/java/sources/io/flutter/embedding/android/FlutterTextureView.java
2024-05-21 17:08:36 -04:00

171 lines
7 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: classes3.dex */
public class FlutterTextureView extends TextureView implements RenderSurface {
private static final String TAG = "FlutterTextureView";
private FlutterRenderer flutterRenderer;
private boolean isPaused;
private boolean isSurfaceAvailableForRendering;
private Surface renderSurface;
private final TextureView.SurfaceTextureListener surfaceTextureListener;
/* JADX INFO: Access modifiers changed from: private */
public boolean shouldNotify() {
return (this.flutterRenderer == null || this.isPaused) ? false : true;
}
@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.isPaused = false;
this.surfaceTextureListener = new TextureView.SurfaceTextureListener() { // from class: io.flutter.embedding.android.FlutterTextureView.1
@Override // android.view.TextureView.SurfaceTextureListener
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
@Override // android.view.TextureView.SurfaceTextureListener
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
Log.v(FlutterTextureView.TAG, "SurfaceTextureListener.onSurfaceTextureAvailable()");
FlutterTextureView.this.isSurfaceAvailableForRendering = true;
if (FlutterTextureView.this.shouldNotify()) {
FlutterTextureView.this.connectSurfaceToRenderer();
}
}
@Override // android.view.TextureView.SurfaceTextureListener
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
Log.v(FlutterTextureView.TAG, "SurfaceTextureListener.onSurfaceTextureSizeChanged()");
if (FlutterTextureView.this.shouldNotify()) {
FlutterTextureView.this.changeSurfaceSize(i, i2);
}
}
@Override // android.view.TextureView.SurfaceTextureListener
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
Log.v(FlutterTextureView.TAG, "SurfaceTextureListener.onSurfaceTextureDestroyed()");
FlutterTextureView.this.isSurfaceAvailableForRendering = false;
if (FlutterTextureView.this.shouldNotify()) {
FlutterTextureView.this.disconnectSurfaceFromRenderer();
}
if (FlutterTextureView.this.renderSurface == null) {
return true;
}
FlutterTextureView.this.renderSurface.release();
FlutterTextureView.this.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;
resume();
}
@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();
}
pause();
this.flutterRenderer = null;
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.");
} else {
this.isPaused = true;
}
}
@Override // io.flutter.embedding.engine.renderer.RenderSurface
public void resume() {
if (this.flutterRenderer == null) {
Log.w(TAG, "resume() invoked when no FlutterRenderer was attached.");
return;
}
if (this.isSurfaceAvailableForRendering) {
Log.v(TAG, "Surface is available for rendering. Connecting FlutterRenderer to Android surface.");
connectSurfaceToRenderer();
}
this.isPaused = 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);
}
/* 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;
}
}
}