android: Allow querying the real display resolution as detected on start

This commit is contained in:
Henrik Rydgard 2014-07-21 00:34:12 +02:00
parent dcd27e134d
commit a4a17415a7
4 changed files with 20 additions and 8 deletions

View File

@ -55,6 +55,10 @@ int optimalFramesPerBuffer = 0;
int optimalSampleRate = 0;
static int androidVersion;
// Should only be used for display detection during startup (for config defaults etc)
static int display_xres;
static int display_yres;
// Android implementation of callbacks to the Java part of the app
void SystemToast(const char *text) {
lock_guard guard(frameCommandLock);
@ -108,6 +112,10 @@ int System_GetPropertyInt(SystemProperty prop) {
switch (prop) {
case SYSPROP_SYSTEMVERSION:
return androidVersion;
case SYSPROP_DISPLAY_XRES:
return display_xres;
case SYSPROP_DISPLAY_YRES:
return display_yres;
default:
return -1;
}
@ -162,7 +170,7 @@ extern "C" jstring Java_com_henrikrydgard_libnative_NativeApp_queryConfig
}
extern "C" void Java_com_henrikrydgard_libnative_NativeApp_init
(JNIEnv *env, jclass, jstring jdevicetype, jstring jlangRegion, jstring japkpath,
(JNIEnv *env, jclass, jstring jdevicetype, jint jxres, jint jyres, jstring jlangRegion, jstring japkpath,
jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jshortcutParam,
jstring jinstallID, jboolean juseNativeAudio, jint jAndroidVersion) {
jniEnvUI = env;
@ -182,6 +190,8 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_init
right_joystick_y_async = 0;
hat_joystick_x_async = 0;
hat_joystick_y_async = 0;
display_xres = jxres;
display_yres = jyres;
std::string apkPath = GetJavaString(env, japkpath);
VFSRegister("", new ZipAssetReader(apkPath.c_str(), "assets/"));

View File

@ -206,12 +206,14 @@ public class NativeActivity extends Activity {
String externalStorageDir = sdcard.getAbsolutePath();
String dataDir = this.getFilesDir().getAbsolutePath();
String apkFilePath = appInfo.sourceDir;
String deviceType = Build.MANUFACTURER + ":" + Build.MODEL;
String languageRegion = Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry();
Point displaySize = new Point();
GetScreenSize(displaySize);
NativeApp.audioConfig(optimalFramesPerBuffer, optimalSampleRate);
NativeApp.init(deviceType, languageRegion, apkFilePath, dataDir, externalStorageDir, libraryDir, shortcutParam, installID, useOpenSL(), Build.VERSION.SDK_INT);
NativeApp.init(deviceType, displaySize.x, displaySize.y, languageRegion, apkFilePath, dataDir, externalStorageDir, libraryDir, shortcutParam, installID, useOpenSL(), Build.VERSION.SDK_INT);
// OK, config should be initialized, we can query for screen rotation.
if (Build.VERSION.SDK_INT >= 9) {
@ -301,9 +303,6 @@ public class NativeActivity extends Activity {
// Override this to scale the backbuffer (use the Android hardware scaler)
public void getDesiredBackbufferSize(Point sz) {
// GetScreenSize(sz, useImmersive());
// sz.x /= 2;
// sz.y /= 2;
sz.x = 0;
sz.y = 0;
}
@ -337,6 +336,7 @@ public class NativeActivity extends Activity {
Point sz = new Point();
getDesiredBackbufferSize(sz);
if (sz.x > 0) {
Log.i(TAG, "Requesting fixed size buffer: " + sz.x + "x" + sz.y);
// Auto-calculates new DPI and forwards to the correct call on mGLSurfaceView.getHolder()
nativeRenderer.setFixedSize(sz.x, sz.y, mGLSurfaceView);
}

View File

@ -9,7 +9,7 @@ public class NativeApp {
public final static int DEVICE_ID_MOUSE = 2;
public final static int DEVICE_ID_PAD_0 = 10;
public static native void init(String deviceType, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String shortcutParam, String installID, boolean useOpenSL, int androidVersion);
public static native void init(String deviceType, int xres, int yres, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String shortcutParam, String installID, boolean useOpenSL, int androidVersion);
public static native void audioInit();
public static native void audioShutdown();

View File

@ -126,6 +126,8 @@ enum SystemProperty {
// Available as Int:
SYSPROP_SYSTEMVERSION,
SYSPROP_DISPLAY_XRES,
SYSPROP_DISPLAY_YRES,
};
std::string System_GetProperty(SystemProperty prop);