mirror of https://github.com/encounter/SDL.git
Track android device panel width & height as well as window surface & height.
Expand SDLActivity::SDLSurface::surfaceChanged() callback to grab the panel width and height at the same time and pass that along to the native code. Only works on API 17+. Duplicates surface dimensions whenever it fails. Add Android_DeviceWidth/Android_DeviceHeight globals to native code. Disambiguate Android_ScreenWidth/Android_ScreenHeight -> Android_SurfaceWidth/Android_SurfaceHeight Use device width/height for all display mode settings.
This commit is contained in:
parent
db86e7a633
commit
fe196db774
|
@ -556,7 +556,7 @@ public class SDLActivity extends Activity {
|
|||
public static native void nativePause();
|
||||
public static native void nativeResume();
|
||||
public static native void onNativeDropFile(String filename);
|
||||
public static native void onNativeResize(int x, int y, int format, float rate);
|
||||
public static native void onNativeResize(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate);
|
||||
public static native void onNativeKeyDown(int keycode);
|
||||
public static native void onNativeKeyUp(int keycode);
|
||||
public static native void onNativeKeyboardFocusLost();
|
||||
|
@ -1378,8 +1378,23 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate());
|
||||
Log.v("SDL", "Window size: " + width + "x" + height);
|
||||
int nDeviceWidth = width;
|
||||
int nDeviceHeight = height;
|
||||
try
|
||||
{
|
||||
if ( android.os.Build.VERSION.SDK_INT >= 17 )
|
||||
{
|
||||
android.util.DisplayMetrics realMetrics = new android.util.DisplayMetrics();
|
||||
mDisplay.getRealMetrics( realMetrics );
|
||||
nDeviceWidth = realMetrics.widthPixels;
|
||||
nDeviceHeight = realMetrics.heightPixels;
|
||||
}
|
||||
}
|
||||
catch ( java.lang.Throwable throwable ) {}
|
||||
|
||||
Log.v("SDL", "Window size: " + width + "x" + height);
|
||||
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
|
||||
SDLActivity.onNativeResize(width, height, nDeviceWidth, nDeviceHeight, sdlFormat, mDisplay.getRefreshRate());
|
||||
|
||||
|
||||
boolean skip = false;
|
||||
|
|
|
@ -76,7 +76,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
|
|||
|
||||
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
||||
JNIEnv* env, jclass jcls,
|
||||
jint width, jint height, jint format, jfloat rate);
|
||||
jint surfaceWidth, jint surfaceHeight,
|
||||
jint deviceWidth, jint deviceHeight, jint format, jfloat rate);
|
||||
|
||||
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(
|
||||
JNIEnv* env, jclass jcls);
|
||||
|
@ -518,9 +519,10 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
|
|||
/* Resize */
|
||||
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
|
||||
JNIEnv* env, jclass jcls,
|
||||
jint width, jint height, jint format, jfloat rate)
|
||||
jint surfaceWidth, jint surfaceHeight,
|
||||
jint deviceWidth, jint deviceHeight, jint format, jfloat rate)
|
||||
{
|
||||
Android_SetScreenResolution(width, height, format, rate);
|
||||
Android_SetScreenResolution(surfaceWidth, surfaceHeight, deviceWidth, deviceHeight, format, rate);
|
||||
}
|
||||
|
||||
/* Paddown */
|
||||
|
|
|
@ -60,8 +60,10 @@ int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float
|
|||
|
||||
|
||||
/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
|
||||
int Android_ScreenWidth = 0;
|
||||
int Android_ScreenHeight = 0;
|
||||
int Android_SurfaceWidth = 0;
|
||||
int Android_SurfaceHeight = 0;
|
||||
int Android_DeviceWidth = 0;
|
||||
int Android_DeviceHeight = 0;
|
||||
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
||||
static int Android_ScreenRate = 0;
|
||||
|
||||
|
@ -176,8 +178,8 @@ Android_VideoInit(_THIS)
|
|||
SDL_DisplayMode mode;
|
||||
|
||||
mode.format = Android_ScreenFormat;
|
||||
mode.w = Android_ScreenWidth;
|
||||
mode.h = Android_ScreenHeight;
|
||||
mode.w = Android_DeviceWidth;
|
||||
mode.h = Android_DeviceHeight;
|
||||
mode.refresh_rate = Android_ScreenRate;
|
||||
mode.driverdata = NULL;
|
||||
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
||||
|
@ -209,12 +211,14 @@ Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * h
|
|||
}
|
||||
|
||||
void
|
||||
Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
|
||||
Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
|
||||
{
|
||||
SDL_VideoDevice* device;
|
||||
SDL_VideoDisplay *display;
|
||||
Android_ScreenWidth = width;
|
||||
Android_ScreenHeight = height;
|
||||
Android_SurfaceWidth = surfaceWidth;
|
||||
Android_SurfaceHeight = surfaceHeight;
|
||||
Android_DeviceWidth = deviceWidth;
|
||||
Android_DeviceHeight = deviceHeight;
|
||||
Android_ScreenFormat = format;
|
||||
Android_ScreenRate = rate;
|
||||
|
||||
|
@ -229,8 +233,8 @@ Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
|
|||
{
|
||||
display = &device->displays[0];
|
||||
display->desktop_mode.format = Android_ScreenFormat;
|
||||
display->desktop_mode.w = Android_ScreenWidth;
|
||||
display->desktop_mode.h = Android_ScreenHeight;
|
||||
display->desktop_mode.w = Android_DeviceWidth;
|
||||
display->desktop_mode.h = Android_DeviceHeight;
|
||||
display->desktop_mode.refresh_rate = Android_ScreenRate;
|
||||
}
|
||||
|
||||
|
@ -240,12 +244,12 @@ Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
|
|||
display = SDL_GetDisplayForWindow(Android_Window);
|
||||
|
||||
display->display_modes[0].format = format;
|
||||
display->display_modes[0].w = width;
|
||||
display->display_modes[0].h = height;
|
||||
display->display_modes[0].w = Android_DeviceWidth;
|
||||
display->display_modes[0].h = Android_DeviceHeight;
|
||||
display->display_modes[0].refresh_rate = rate;
|
||||
display->current_mode = display->display_modes[0];
|
||||
|
||||
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
|
||||
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, surfaceWidth, surfaceHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "../SDL_sysvideo.h"
|
||||
|
||||
/* Called by the JNI layer when the screen changes size or format */
|
||||
extern void Android_SetScreenResolution(int width, int height, Uint32 format, float rate);
|
||||
extern void Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate);
|
||||
|
||||
/* Private display data */
|
||||
|
||||
|
@ -37,8 +37,10 @@ typedef struct SDL_VideoData
|
|||
SDL_Rect textRect;
|
||||
} SDL_VideoData;
|
||||
|
||||
extern int Android_ScreenWidth;
|
||||
extern int Android_ScreenHeight;
|
||||
extern int Android_SurfaceWidth;
|
||||
extern int Android_SurfaceHeight;
|
||||
extern int Android_DeviceWidth;
|
||||
extern int Android_DeviceHeight;
|
||||
extern Uint32 Android_ScreenFormat;
|
||||
extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
|
||||
extern SDL_Window *Android_Window;
|
||||
|
|
|
@ -49,8 +49,8 @@ Android_CreateWindow(_THIS, SDL_Window * window)
|
|||
/* Adjust the window data to match the screen */
|
||||
window->x = 0;
|
||||
window->y = 0;
|
||||
window->w = Android_ScreenWidth;
|
||||
window->h = Android_ScreenHeight;
|
||||
window->w = Android_SurfaceWidth;
|
||||
window->h = Android_SurfaceHeight;
|
||||
|
||||
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
|
||||
window->flags &= ~SDL_WINDOW_HIDDEN;
|
||||
|
|
Loading…
Reference in New Issue