Permalink
Browse files

Merge pull request #9889 from hrydgard/android-misc-fixes

Android misc fixes
  • Loading branch information...
hrydgard committed Aug 8, 2017
2 parents 5e4e23f + 4b35e9e commit 3ad571a922e216aa00cd2f1115db856e41b379fa
View
@@ -252,7 +252,7 @@ int NativeMix(short *audio, int num_samples) {
num_samples = __AudioMix(audio, num_samples, sample_rate > 0 ? sample_rate : 44100);
#ifdef _WIN32
winAudioBackend->Update();
winAudioBackend->Update*();
#endif
return num_samples;
@@ -307,6 +307,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
InitFastMath(cpu_info.bNEON);
SetupAudioFormats();
// Make sure UI state is MENU.
ResetUIState();
bool skipLogo = false;
setlocale( LC_ALL, "C" );
std::string user_data_path = savegame_dir;
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1536M
@@ -362,10 +362,10 @@ static int deviceType;
// Should only be used for display detection during startup (for config defaults etc)
// This is the ACTUAL display size, not the hardware scaled display size.
static int display_dpi_x;
static int display_dpi_y;
static int display_xres;
static int display_yres;
static int display_dpi_x;
static int display_dpi_y;
static int backbuffer_format; // Android PixelFormat enum
static int desiredBackbufferSizeX;
@@ -722,10 +722,10 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
ILOG("g_dpi=%f g_dpi_scale_x=%f g_dpi_scale_y=%f", g_dpi, g_dpi_scale_x, g_dpi_scale_y);
ILOG("dp_xscale=%f dp_yscale=%f", dp_xscale, dp_yscale);
ILOG("dp_xres=%d dp_yres=%d", dp_xres, dp_yres);
ILOG("pixel_xres=%d pixel_yres=%d", pixel_xres, pixel_yres);
ILOG("g_dpi=%d g_dpi_scale_x=%f g_dpi_scale_y", g_dpi, g_dpi_scale_x, g_dpi_scale_y);
NativeResized();
}
@@ -48,23 +48,7 @@ public InputDeviceState(InputDevice device) {
}
NativeApp.sendMessage("inputDeviceConnected", device.getName());
}
public static float ProcessAxis(InputDevice.MotionRange range, float axisvalue) {
float absaxisvalue = Math.abs(axisvalue);
float deadzone = range.getFlat();
if (absaxisvalue <= deadzone) {
return 0.0f;
}
float normalizedvalue;
if (axisvalue < 0.0f) {
normalizedvalue = absaxisvalue / range.getMin();
} else {
normalizedvalue = absaxisvalue / range.getMax();
}
return normalizedvalue;
}
public boolean onKeyDown(KeyEvent event) {
int keyCode = event.getKeyCode();
boolean repeat = event.getRepeatCount() > 0;
@@ -84,7 +68,6 @@ public boolean onJoystickMotion(MotionEvent event) {
for (int i = 0; i < mAxes.length; i++) {
int axisId = mAxes[i];
float value = event.getAxisValue(axisId);
// TODO: Use processAxis or move that to the C++ code
NativeApp.joystickAxis(deviceId, axisId, value);
}
NativeApp.endJoystickEvent();
@@ -54,7 +54,7 @@
import android.widget.FrameLayout;
import android.widget.Toast;
public class NativeActivity extends Activity implements SurfaceHolder.Callback {
public abstract class NativeActivity extends Activity implements SurfaceHolder.Callback {
// Remember to loadLibrary your JNI .so in a static {} block
// Adjust these as necessary
@@ -91,20 +91,23 @@
private Vibrator vibrator;
private boolean isXperiaPlay;
// This is to avoid losing the game/menu state etc when we are just
// switched-away from or rotated etc.
private boolean shuttingDown;
private static int RESULT_LOAD_IMAGE = 1;
// Allow for multiple connected gamepads but just consider them the same for now.
// Actually this is not entirely true, see the code.
InputDeviceState inputPlayerA;
InputDeviceState inputPlayerB;
InputDeviceState inputPlayerC;
String inputPlayerADesc;
private InputDeviceState inputPlayerA;
private InputDeviceState inputPlayerB;
private InputDeviceState inputPlayerC;
private String inputPlayerADesc;
float densityDpi;
float refreshRate;
int pixelWidth;
int pixelHeight;
private float densityDpi;
private float refreshRate;
private int pixelWidth;
private int pixelHeight;
// Functions for the app activity to override to change behaviour.
@@ -348,7 +351,7 @@ public void run() {
Log.i(TAG, "Starting the render loop: " + mSurface);
// Start emulation using the provided Surface.
if (!runEGLRenderLoop(mSurface)) {
// TODO: Add an alert dialog or something
// Shouldn't happen.
Log.e(TAG, "Failed to start up OpenGL");
}
Log.i(TAG, "Left the render loop: " + mSurface);
@@ -455,13 +458,11 @@ public void surfaceCreated(SurfaceHolder holder) {
}
}
//
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.w(TAG, "Surface changed. Resolution: " + width + "x" + height + " Format: " + format);
NativeApp.backbufferResize(width, height, format);
mSurface = holder.getSurface();
if (!javaGL) {
// If we got a surface, this starts the thread. If not, it doesn't.
if (mSurface == null) {
@@ -472,6 +473,17 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mSurface = null;
Log.w(TAG, "Surface destroyed.");
if (!javaGL) {
joinRenderLoopThread();
}
// Autosize the next created surface.
holder.setSizeFromLayout();
}
// Invariants: After this, mRenderLoopThread will be set, and the thread will be running.
protected synchronized void ensureRenderLoop() {
if (javaGL) {
@@ -507,24 +519,11 @@ private synchronized void joinRenderLoopThread() {
Log.w(TAG, "Joined render loop thread.");
mRenderLoopThread = null;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (javaGL) {
Log.e(TAG, "JavaGL - should not get into surfaceDestroyed.");
return;
}
mSurface = null;
Log.w(TAG, "Surface destroyed.");
joinRenderLoopThread();
}
@TargetApi(19)
void setupSystemUiCallback() {
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
@@ -549,14 +548,17 @@ protected void onDestroy() {
if (javaGL) {
Log.i(TAG, "onDestroy");
mGLSurfaceView.onDestroy();
NativeApp.audioShutdown();
// Probably vain attempt to help the garbage collector...
mGLSurfaceView = null;
audioFocusChangeListener = null;
audioManager = null;
unregisterCallbacks();
} else {
mSurfaceView.onDestroy();
mSurfaceView = null;
}
NativeApp.audioShutdown();
if (shuttingDown || isFinishing()) {
unregisterCallbacks();
NativeApp.shutdown();
initialized = false;
}
@@ -595,7 +597,6 @@ private boolean detectOpenGLES30() {
return info.reqGlEsVersion >= 0x30000;
}
@Override
protected void onResume() {
super.onResume();
@@ -614,6 +615,10 @@ protected void onResume() {
} else {
Log.e(TAG, "mGLSurfaceView really shouldn't be null in onResume");
}
} else {
if (mSurfaceView != null) {
mSurfaceView.onResume();
}
}
gainAudioFocus(this.audioManager, this.audioFocusChangeListener);
@@ -860,7 +865,6 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
// Fall through
default:
// send the rest of the keys through.
// TODO: get rid of the three special cases above by adjusting the native side of the code.
// Log.d(TAG, "Key down: " + keyCode + ", KeyEvent: " + event);
return NativeApp.keyUp(0, keyCode);
}
@@ -1084,9 +1088,8 @@ public boolean processCommand(String command, String params) {
surfView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
break;
default:
if (vibrator != null) {
vibrator.vibrate(milliseconds);
}
// Requires the vibrate permission, which we don't have, so disabled.
// vibrator.vibrate(milliseconds);
break;
}
return true;
@@ -37,24 +37,6 @@ public NativeGLView(NativeActivity activity) {
super(activity);
mActivity = activity;
/*// TODO: This would be nice.
if (Build.VERSION.SDK_INT >= 11) {
try {
Method method_setPreserveEGLContextOnPause = GLSurfaceView.class.getMethod(
"setPreserveEGLContextOnPause", new Class[] { Boolean.class });
Log.i(TAG, "Invoking setPreserveEGLContextOnPause");
method_setPreserveEGLContextOnPause.invoke(this, true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}*/
mSensorManager = (SensorManager)activity.getSystemService(Activity.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
@@ -126,13 +126,13 @@ public void onResume() {
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
if (mController != null) {
mController.onResume();
// According to the docs, the Moga's state can be inconsistent here.
// We should do a one time poll. TODO
// Should we do a one time poll?
}
}
public void onDestroy() {
Log.i(TAG, "onDestroy");
if (mController != null) {
mController.exit();
}
@@ -13,7 +13,6 @@
/**
* Simple dialog to pick file.
* TODO: Use GameBrowser from MainScreen.cpp instead. Then remove this class.
*/
public class SimpleFileChooser {

0 comments on commit 3ad571a

Please sign in to comment.