mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-30 11:02:31 -06:00
192 lines
8.1 KiB
Java
192 lines
8.1 KiB
Java
package io.flutter.embedding.android;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Region;
|
|
import android.util.AttributeSet;
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceView;
|
|
import io.flutter.Log;
|
|
import io.flutter.embedding.engine.renderer.FlutterRenderer;
|
|
import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
|
|
import io.flutter.embedding.engine.renderer.RenderSurface;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class FlutterSurfaceView extends SurfaceView implements RenderSurface {
|
|
private static final String TAG = "FlutterSurfaceView";
|
|
private FlutterRenderer flutterRenderer;
|
|
private final FlutterUiDisplayListener flutterUiDisplayListener;
|
|
private boolean isPaused;
|
|
private boolean isSurfaceAvailableForRendering;
|
|
private final boolean renderTransparently;
|
|
private final SurfaceHolder.Callback surfaceCallback;
|
|
|
|
/* 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 FlutterSurfaceView(Context context) {
|
|
this(context, null, false);
|
|
}
|
|
|
|
public FlutterSurfaceView(Context context, boolean z) {
|
|
this(context, null, z);
|
|
}
|
|
|
|
public FlutterSurfaceView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, false);
|
|
}
|
|
|
|
private FlutterSurfaceView(Context context, AttributeSet attributeSet, boolean z) {
|
|
super(context, attributeSet);
|
|
this.isSurfaceAvailableForRendering = false;
|
|
this.isPaused = false;
|
|
this.surfaceCallback = new SurfaceHolder.Callback() { // from class: io.flutter.embedding.android.FlutterSurfaceView.1
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceCreated(SurfaceHolder surfaceHolder) {
|
|
Log.v(FlutterSurfaceView.TAG, "SurfaceHolder.Callback.startRenderingToSurface()");
|
|
FlutterSurfaceView.this.isSurfaceAvailableForRendering = true;
|
|
if (FlutterSurfaceView.this.shouldNotify()) {
|
|
FlutterSurfaceView.this.connectSurfaceToRenderer();
|
|
}
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
|
|
Log.v(FlutterSurfaceView.TAG, "SurfaceHolder.Callback.surfaceChanged()");
|
|
if (FlutterSurfaceView.this.shouldNotify()) {
|
|
FlutterSurfaceView.this.changeSurfaceSize(i2, i3);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.SurfaceHolder.Callback
|
|
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
|
|
Log.v(FlutterSurfaceView.TAG, "SurfaceHolder.Callback.stopRenderingToSurface()");
|
|
FlutterSurfaceView.this.isSurfaceAvailableForRendering = false;
|
|
if (FlutterSurfaceView.this.shouldNotify()) {
|
|
FlutterSurfaceView.this.disconnectSurfaceFromRenderer();
|
|
}
|
|
}
|
|
};
|
|
this.flutterUiDisplayListener = new FlutterUiDisplayListener() { // from class: io.flutter.embedding.android.FlutterSurfaceView.2
|
|
@Override // io.flutter.embedding.engine.renderer.FlutterUiDisplayListener
|
|
public void onFlutterUiNoLongerDisplayed() {
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.renderer.FlutterUiDisplayListener
|
|
public void onFlutterUiDisplayed() {
|
|
Log.v(FlutterSurfaceView.TAG, "onFlutterUiDisplayed()");
|
|
FlutterSurfaceView.this.setAlpha(1.0f);
|
|
if (FlutterSurfaceView.this.flutterRenderer != null) {
|
|
FlutterSurfaceView.this.flutterRenderer.removeIsDisplayingFlutterUiListener(this);
|
|
}
|
|
}
|
|
};
|
|
this.renderTransparently = z;
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
if (this.renderTransparently) {
|
|
getHolder().setFormat(-2);
|
|
setZOrderOnTop(true);
|
|
}
|
|
getHolder().addCallback(this.surfaceCallback);
|
|
setAlpha(0.0f);
|
|
}
|
|
|
|
@Override // android.view.SurfaceView, android.view.View
|
|
public boolean gatherTransparentRegion(Region region) {
|
|
if (getAlpha() < 1.0f) {
|
|
return false;
|
|
}
|
|
int[] iArr = new int[2];
|
|
getLocationInWindow(iArr);
|
|
int i = iArr[0];
|
|
region.op(i, iArr[1], (getRight() + i) - getLeft(), (iArr[1] + getBottom()) - getTop(), Region.Op.DIFFERENCE);
|
|
return true;
|
|
}
|
|
|
|
@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.removeIsDisplayingFlutterUiListener(this.flutterUiDisplayListener);
|
|
}
|
|
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();
|
|
setAlpha(0.0f);
|
|
this.flutterRenderer.removeIsDisplayingFlutterUiListener(this.flutterUiDisplayListener);
|
|
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() {
|
|
FlutterRenderer flutterRenderer = this.flutterRenderer;
|
|
if (flutterRenderer == null) {
|
|
Log.w(TAG, "resume() invoked when no FlutterRenderer was attached.");
|
|
return;
|
|
}
|
|
flutterRenderer.addIsDisplayingFlutterUiListener(this.flutterUiDisplayListener);
|
|
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 || getHolder() == null) {
|
|
throw new IllegalStateException("connectSurfaceToRenderer() should only be called when flutterRenderer and getHolder() are non-null.");
|
|
}
|
|
this.flutterRenderer.startRenderingToSurface(getHolder().getSurface(), 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();
|
|
}
|
|
}
|