fix(SDLSurface): Return native window from MinecraftGLSurface

We can't have SDLSurface using its own native surface if a mod wants to
use SDL for outputting the rendered window (LWJGL3ify)
This commit is contained in:
tomikun
2026-04-23 19:54:31 +08:00
parent 632108ef75
commit a6bfbd2d14
2 changed files with 14 additions and 7 deletions

View File

@@ -84,6 +84,7 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
final Object mSurfaceReadyListenerLock = new Object();
/* View holding the surface, either a SurfaceView or a TextureView */
View mSurface;
Surface mNativeSurface;
String TAG = "MinecraftGLSurface";
private final InGameEventProcessor mIngameProcessor = new InGameEventProcessor(mSensitivityFactor);
@@ -127,18 +128,19 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
if(useSurfaceView){
SurfaceView surfaceView = new SurfaceView(getContext());
mSurface = surfaceView;
mNativeSurface = surfaceView.getHolder().getSurface();
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
private boolean isCalled = isAlreadyRunning;
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder) {
if(isCalled) {
JREUtils.setupBridgeWindow(surfaceView.getHolder().getSurface());
JREUtils.setupBridgeWindow(mNativeSurface);
return;
}
isCalled = true;
realStart(surfaceView.getHolder().getSurface());
realStart(mNativeSurface);
}
@Override
@@ -169,14 +171,14 @@ public class MinecraftGLSurface extends View implements GrabListener, DirectGame
private boolean isCalled = isAlreadyRunning;
@Override
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
Surface tSurface = new Surface(surface);
mNativeSurface = new Surface(surface);
if(isCalled) {
JREUtils.setupBridgeWindow(tSurface);
JREUtils.setupBridgeWindow(mNativeSurface);
return;
}
isCalled = true;
realStart(tSurface);
realStart(mNativeSurface);
}
@Override

View File

@@ -52,6 +52,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Pinch events
private final ScaleGestureDetector scaleGestureDetector;
static Surface mNativeSurface;
// Startup
public SDLSurface(Context context) {
@@ -93,8 +94,12 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
enableSensor(Sensor.TYPE_ACCELEROMETER, true);
}
protected Surface getNativeSurface() {
return getHolder().getSurface();
public static Surface getNativeSurface() {
return mNativeSurface;
}
public static void setNativeSurface(Surface nativeSurface) {
mNativeSurface = nativeSurface;
}
// Called when we have a valid drawing surface