Android: don't need to set the SurfaceHolder format from java code

It's already set with ANativeWindow_setGeometry, and eventually set/changed also by eglCreateWindowSurface.
 - avoid issues with older device where SurfaceView cycle create/changed/destroy appears broken:
   calling create/changed/changed, and leading to "deuqueBuffer failed at server side, error: -19", with black screen.
 - re-read the format after egl window surface is created, to report the correct one (sometimes, changed from RGBA8888 to RGB24)
This commit is contained in:
Sylvain
2021-04-22 18:06:17 +02:00
parent 8e3ec34d34
commit 98a966d1c2
6 changed files with 70 additions and 108 deletions

View File

@@ -605,7 +605,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
static final int COMMAND_CHANGE_TITLE = 1;
static final int COMMAND_CHANGE_WINDOW_STYLE = 2;
static final int COMMAND_TEXTEDIT_HIDE = 3;
static final int COMMAND_CHANGE_SURFACEVIEW_FORMAT = 4;
static final int COMMAND_SET_KEEP_SCREEN_ON = 5;
protected static final int COMMAND_USER = 0x8000;
@@ -703,32 +702,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
}
break;
}
case COMMAND_CHANGE_SURFACEVIEW_FORMAT:
{
int format = (Integer) msg.obj;
int pf;
if (SDLActivity.mSurface == null) {
return;
}
SurfaceHolder holder = SDLActivity.mSurface.getHolder();
if (holder == null) {
return;
}
if (format == 1) {
pf = PixelFormat.RGBA_8888;
} else if (format == 2) {
pf = PixelFormat.RGBX_8888;
} else {
pf = PixelFormat.RGB_565;
}
holder.setFormat(pf);
break;
}
default:
if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
Log.e(TAG, "error handling message, command is " + msg.arg1);
@@ -812,7 +785,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
public static native void nativeResume();
public static native void nativeFocusChanged(boolean hasFocus);
public static native void onNativeDropFile(String filename);
public static native void nativeSetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate);
public static native void nativeSetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float rate);
public static native void onNativeResize();
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
@@ -1218,13 +1191,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return SDLActivity.mSurface.getNativeSurface();
}
/**
* This method is called by SDL using JNI.
*/
public static void setSurfaceViewFormat(int format) {
mSingleton.sendCommand(COMMAND_CHANGE_SURFACEVIEW_FORMAT, format);
}
// Input
/**
@@ -1796,30 +1762,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
return;
}
int sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565 by default
switch (format) {
case PixelFormat.RGBA_8888:
Log.v("SDL", "pixel format RGBA_8888");
sdlFormat = 0x16462004; // SDL_PIXELFORMAT_RGBA8888
break;
case PixelFormat.RGBX_8888:
Log.v("SDL", "pixel format RGBX_8888");
sdlFormat = 0x16261804; // SDL_PIXELFORMAT_RGBX8888
break;
case PixelFormat.RGB_565:
Log.v("SDL", "pixel format RGB_565");
sdlFormat = 0x15151002; // SDL_PIXELFORMAT_RGB565
break;
case PixelFormat.RGB_888:
Log.v("SDL", "pixel format RGB_888");
// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
sdlFormat = 0x16161804; // SDL_PIXELFORMAT_RGB888
break;
default:
Log.v("SDL", "pixel format unknown " + format);
break;
}
mWidth = width;
mHeight = height;
int nDeviceWidth = width;
@@ -1842,7 +1784,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
Log.v("SDL", "Window size: " + width + "x" + height);
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate());
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, mDisplay.getRefreshRate());
SDLActivity.onNativeResize();
// Prevent a screen distortion glitch,