mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-12 17:19:28 +01:00
android: Cleanup of dpi/refresh variables
This commit is contained in:
1 parent
3b45ca1d2f
commit
326504baf8
7 files changed
+36
-43
No files matched your search
+12
-23
@@ -152,7 +152,7 @@ extern "C" jstring Java_com_henrikrydgard_libnative_NativeApp_queryConfig
|
||||
}
|
||||
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeApp_init
|
||||
(JNIEnv *env, jclass, jint dpi, jstring jdevicetype, jstring jlangRegion, jstring japkpath,
|
||||
(JNIEnv *env, jclass, jstring jdevicetype, jstring jlangRegion, jstring japkpath,
|
||||
jstring jdataDir, jstring jexternalDir, jstring jlibraryDir, jstring jshortcutParam,
|
||||
jstring jinstallID, jboolean juseNativeAudio) {
|
||||
jniEnvUI = env;
|
||||
@@ -193,10 +193,6 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_init
|
||||
|
||||
net::Init();
|
||||
|
||||
g_dpi = dpi;
|
||||
g_dpi_scale = 240.0f / (float)g_dpi;
|
||||
ILOG("DPI detected: %i %f", dpi, g_dpi_scale);
|
||||
|
||||
NativeGetAppInfo(&app_name, &app_nice_name, &landscape);
|
||||
|
||||
|
||||
@@ -262,39 +258,32 @@ extern "C" void Java_com_henrikrydgard_libnative_NativeApp_shutdown(JNIEnv *, jc
|
||||
static jmethodID postCommand;
|
||||
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeRenderer_displayInit(JNIEnv * env, jobject obj) {
|
||||
ILOG("NativeApp.displayInit(pixel_xres = %i, pixel_yres = %i)", pixel_xres, pixel_yres);
|
||||
ILOG("NativeApp.displayInit()");
|
||||
if (!renderer_inited) {
|
||||
// We default to 240 dpi and all UI code is written to assume it. (DENSITY_HIGH, like Nexus S).
|
||||
// Note that we don't compute dp_xscale and dp_yscale until later! This is so that NativeGetAppInfo
|
||||
// can change the dp resolution if it feels like it.
|
||||
dp_xres = pixel_xres * g_dpi_scale;
|
||||
dp_yres = pixel_yres * g_dpi_scale;
|
||||
|
||||
NativeInitGraphics();
|
||||
ILOG("NativeInitGraphics() completed: dpi = %i, dp_xres = %i, dp_yres = %i", g_dpi, dp_xres, dp_yres);
|
||||
|
||||
dp_xscale = (float)dp_xres / pixel_xres;
|
||||
dp_yscale = (float)dp_yres / pixel_yres;
|
||||
renderer_inited = true;
|
||||
} else {
|
||||
NativeDeviceLost();
|
||||
ILOG("NativeDeviceLost completed.");
|
||||
NativeDeviceLost(); // ???
|
||||
ILOG("displayInit: NativeDeviceLost completed.");
|
||||
}
|
||||
|
||||
DLOG("(Re)-fetching method ID to postCommand...");
|
||||
jclass cls = env->GetObjectClass(obj);
|
||||
postCommand = env->GetMethodID(cls, "postCommand", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
postCommand = env->GetMethodID(env->GetObjectClass(obj), "postCommand", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
}
|
||||
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeRenderer_displayResize(JNIEnv *, jobject clazz, jint w, jint h) {
|
||||
ILOG("NativeApp.displayResize(%i, %i)", w, h);
|
||||
extern "C" void Java_com_henrikrydgard_libnative_NativeRenderer_displayResize(JNIEnv *, jobject clazz, jint w, jint h, jint dpi, jfloat refreshRate) {
|
||||
ILOG("NativeApp.displayResize(%i x %i, dpi=%i, refresh=%0.2f)", w, h, dpi, refreshRate);
|
||||
|
||||
g_dpi = dpi;
|
||||
g_dpi_scale = 240.0f / (float)g_dpi;
|
||||
|
||||
// TODO: Move some of the logic from displayInit here?
|
||||
pixel_xres = w;
|
||||
pixel_yres = h;
|
||||
dp_xres = pixel_xres * g_dpi_scale;
|
||||
dp_yres = pixel_yres * g_dpi_scale;
|
||||
dp_xscale = (float)dp_xres / pixel_xres;
|
||||
dp_yscale = (float)dp_yres / pixel_yres;
|
||||
display_hz = refreshRate;
|
||||
|
||||
NativeResized();
|
||||
}
|
||||
|
||||
@@ -185,32 +185,23 @@ public class NativeActivity extends Activity {
|
||||
|
||||
String libraryDir = getApplicationLibraryDir(appInfo);
|
||||
File sdcard = Environment.getExternalStorageDirectory();
|
||||
Display display = ((WindowManager)this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
@SuppressWarnings("deprecation")
|
||||
|
||||
float scrRefreshRate = display.getRefreshRate();
|
||||
String externalStorageDir = sdcard.getAbsolutePath();
|
||||
String dataDir = this.getFilesDir().getAbsolutePath();
|
||||
String apkFilePath = appInfo.sourceDir;
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
int dpi = metrics.densityDpi;
|
||||
|
||||
String deviceType = Build.MANUFACTURER + ":" + Build.MODEL;
|
||||
String languageRegion = Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry();
|
||||
|
||||
NativeApp.audioConfig(optimalFramesPerBuffer, optimalSampleRate);
|
||||
NativeApp.init(dpi, deviceType, languageRegion, apkFilePath, dataDir, externalStorageDir, libraryDir, shortcutParam, installID, useOpenSL());
|
||||
NativeApp.init(deviceType, languageRegion, apkFilePath, dataDir, externalStorageDir, libraryDir, shortcutParam, installID, useOpenSL());
|
||||
|
||||
// OK, config should be initialized, we can query for screen rotation.
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
updateScreenRotation();
|
||||
}
|
||||
|
||||
Log.i(TAG, "Device: " + deviceType);
|
||||
Log.i(TAG, " rate: " + scrRefreshRate + " dpi: " + dpi);
|
||||
|
||||
// Detect OpenGL support.
|
||||
// We don't currently use this detection for anything but good to have in the log.
|
||||
if (!detectOpenGLES20()) {
|
||||
@@ -272,7 +263,6 @@ public class NativeActivity extends Activity {
|
||||
}
|
||||
if (useImmersive) {
|
||||
flags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
Log.i(TAG, "Setting immersive mode");
|
||||
}
|
||||
if (getWindow().getDecorView() != null) {
|
||||
getWindow().getDecorView().setSystemUiVisibility(flags);
|
||||
@@ -315,6 +305,7 @@ public class NativeActivity extends Activity {
|
||||
NativeApp.audioInit();
|
||||
|
||||
mGLSurfaceView = new NativeGLView(this);
|
||||
nativeRenderer = new NativeRenderer(this);
|
||||
|
||||
mGLSurfaceView.setEGLContextClientVersion(2);
|
||||
|
||||
@@ -339,7 +330,6 @@ public class NativeActivity extends Activity {
|
||||
mGLSurfaceView.setEGLConfigChooser(new NativeEGLConfigChooser());
|
||||
}
|
||||
|
||||
nativeRenderer = new NativeRenderer(this);
|
||||
mGLSurfaceView.setRenderer(nativeRenderer);
|
||||
setContentView(mGLSurfaceView);
|
||||
|
||||
|
||||
@@ -6,7 +6,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(int dpi, String deviceType, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String shortcutParam, String installID, boolean useOpenSL);
|
||||
public static native void init(String deviceType, String languageRegion, String apkPath, String dataDir, String externalDir, String libraryDir, String shortcutParam, String installID, boolean useOpenSL);
|
||||
|
||||
public static native void audioInit();
|
||||
public static native void audioShutdown();
|
||||
|
||||
@@ -3,18 +3,31 @@ package com.henrikrydgard.libnative;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.content.Context;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
import android.view.Display;
|
||||
|
||||
public class NativeRenderer implements GLSurfaceView.Renderer {
|
||||
private static String TAG = "NativeRenderer";
|
||||
NativeActivity mActivity;
|
||||
private NativeActivity mActivity;
|
||||
private boolean isDark = false;
|
||||
private int dpi;
|
||||
private float refreshRate;
|
||||
|
||||
NativeRenderer(NativeActivity act) {
|
||||
mActivity = act;
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
Display display = act.getWindowManager().getDefaultDisplay();
|
||||
display.getMetrics(metrics);
|
||||
dpi = metrics.densityDpi;
|
||||
refreshRate = display.getRefreshRate();
|
||||
|
||||
// Log.i(TAG, "Display name: " + display.getName());
|
||||
Log.i(TAG, " rate: " + refreshRate + " dpi: " + dpi);
|
||||
}
|
||||
|
||||
public void setDark(boolean d) {
|
||||
@@ -42,7 +55,7 @@ public class NativeRenderer implements GLSurfaceView.Renderer {
|
||||
@Override
|
||||
public void onSurfaceChanged(GL10 unused, int width, int height) {
|
||||
Log.i(TAG, "onSurfaceChanged");
|
||||
displayResize(width, height);
|
||||
displayResize(width, height, dpi, refreshRate);
|
||||
}
|
||||
|
||||
// Not override, it's custom.
|
||||
@@ -55,7 +68,7 @@ public class NativeRenderer implements GLSurfaceView.Renderer {
|
||||
// Note: This also means "device lost" and you should reload
|
||||
// all buffered objects.
|
||||
public native void displayInit();
|
||||
public native void displayResize(int w, int h);
|
||||
public native void displayResize(int w, int h, int dpi, float refreshRate);
|
||||
public native void displayRender();
|
||||
public native void displayShutdown();
|
||||
|
||||
|
||||
+1
-2
@@ -16,8 +16,6 @@ struct AxisInput;
|
||||
|
||||
// The first function to get called, just write strings to the two pointers.
|
||||
// This might get called multiple times in some implementations, you must be able to handle that.
|
||||
// The detected DP dimensions of the screen are set as dp_xres and dp_yres and you're free to change
|
||||
// them if you have a fixed-size app that needs to stretch a little to fit.
|
||||
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape);
|
||||
|
||||
// Generic host->C++ messaging, used for functionality like system-native popup input boxes.
|
||||
@@ -38,6 +36,7 @@ bool NativeIsAtTopLevel();
|
||||
void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID);
|
||||
|
||||
// Runs after NativeInit() at some point. May (and probably should) call OpenGL.
|
||||
// Should not initialize anything screen-size-dependent - do that in NativeResized.
|
||||
void NativeInitGraphics();
|
||||
|
||||
// Signals that you need to destroy and recreate all buffered OpenGL resources,
|
||||
|
||||
@@ -9,3 +9,4 @@ int pixel_yres;
|
||||
int g_dpi = 1; // will be overwritten
|
||||
float g_dpi_scale = 1.0f;
|
||||
float pixel_in_dps = 1.0f;
|
||||
float display_hz = 60.0f;
|
||||
+2
-1
@@ -10,4 +10,5 @@ extern int pixel_yres;
|
||||
|
||||
extern int g_dpi;
|
||||
extern float g_dpi_scale;
|
||||
extern float pixel_in_dps;
|
||||
extern float pixel_in_dps;
|
||||
extern float display_hz;
|
||||
Reference in new issue
Block a user