externals: update SDL2 to 2.0.16

This commit is contained in:
Jakub Czekański 2021-11-16 03:28:40 +01:00
parent 77d4a55d6d
commit a0f91c74c2
10 changed files with 1418 additions and 677 deletions

2
.gitmodules vendored
View file

@ -1,6 +1,6 @@
[submodule "externals/SDL2"]
path = externals/SDL2
url = https://github.com/spurious/SDL-mirror
url = https://github.com/libsdl-org/SDL
ignore = dirty
[submodule "externals/imgui"]
path = externals/imgui

View file

@ -7,6 +7,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.os.Build;
import android.util.Log;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -275,6 +276,7 @@ public class HIDDeviceManager {
0x15e4, // Numark
0x162e, // Joytech
0x1689, // Razer Onza
0x1949, // Lab126, Inc.
0x1bad, // Harmonix
0x24c6, // PowerA
};
@ -353,9 +355,18 @@ public class HIDDeviceManager {
private void connectHIDDeviceUSB(UsbDevice usbDevice) {
synchronized (this) {
int interface_mask = 0;
for (int interface_index = 0; interface_index < usbDevice.getInterfaceCount(); interface_index++) {
UsbInterface usbInterface = usbDevice.getInterface(interface_index);
if (isHIDDeviceInterface(usbDevice, usbInterface)) {
// Check to see if we've already added this interface
// This happens with the Xbox Series X controller which has a duplicate interface 0, which is inactive
int interface_id = usbInterface.getId();
if ((interface_mask & (1 << interface_id)) != 0) {
continue;
}
interface_mask |= (1 << interface_id);
HIDDeviceUSB device = new HIDDeviceUSB(this, usbDevice, interface_index);
int id = device.getId();
mDevicesById.put(id, device);
@ -373,6 +384,11 @@ public class HIDDeviceManager {
return;
}
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18)) {
Log.d(TAG, "Couldn't initialize Bluetooth, this version of Android does not support Bluetooth LE");
return;
}
// Find bonded bluetooth controllers and create SteamControllers for them
mBluetoothManager = (BluetoothManager)mContext.getSystemService(Context.BLUETOOTH_SERVICE);
if (mBluetoothManager == null) {

View file

@ -53,7 +53,12 @@ class HIDDeviceUSB implements HIDDevice {
public String getSerialNumber() {
String result = null;
if (Build.VERSION.SDK_INT >= 21) {
result = mDevice.getSerialNumber();
try {
result = mDevice.getSerialNumber();
}
catch (SecurityException exception) {
//Log.w(TAG, "App permissions mean we cannot get serial number for device " + getDeviceName() + " message: " + exception.getMessage());
}
}
if (result == null) {
result = "";

View file

@ -2,7 +2,8 @@ package org.libsdl.app;
import android.content.Context;
import java.lang.reflect.*;
import java.lang.Class;
import java.lang.reflect.Method;
/**
SDL library initialization
@ -51,16 +52,16 @@ public class SDL {
// To use ReLinker, just add it as a dependency. For more information, see
// https://github.com/KeepSafe/ReLinker for ReLinker's repository.
//
Class relinkClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker");
Class relinkListenerClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener");
Class contextClass = mContext.getClassLoader().loadClass("android.content.Context");
Class stringClass = mContext.getClassLoader().loadClass("java.lang.String");
Class<?> relinkClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker");
Class<?> relinkListenerClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener");
Class<?> contextClass = mContext.getClassLoader().loadClass("android.content.Context");
Class<?> stringClass = mContext.getClassLoader().loadClass("java.lang.String");
// Get a 'force' instance of the ReLinker, so we can ensure libraries are reinstalled if
// they've changed during updates.
Method forceMethod = relinkClass.getDeclaredMethod("force");
Object relinkInstance = forceMethod.invoke(null);
Class relinkInstanceClass = relinkInstance.getClass();
Class<?> relinkInstanceClass = relinkInstance.getClass();
// Actually load the library!
Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
@ -77,7 +78,7 @@ public class SDL {
catch (final SecurityException se) {
throw se;
}
}
}
}
protected static Context mContext;

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,10 @@
package org.libsdl.app;
import android.media.*;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaRecorder;
import android.os.Build;
import android.util.Log;
@ -199,7 +203,6 @@ public class SDLAudioManager
results[0] = mAudioRecord.getSampleRate();
results[1] = mAudioRecord.getAudioFormat();
results[2] = mAudioRecord.getChannelCount();
results[3] = desiredFrames;
} else {
if (mAudioTrack == null) {
@ -223,8 +226,8 @@ public class SDLAudioManager
results[0] = mAudioTrack.getSampleRate();
results[1] = mAudioTrack.getAudioFormat();
results[2] = mAudioTrack.getChannelCount();
results[3] = desiredFrames;
}
results[3] = desiredFrames;
Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", got " + results[3] + " frames of " + results[2] + " channel " + getAudioFormatString(results[1]) + " audio at " + results[0] + " Hz");

View file

@ -6,9 +6,14 @@ import java.util.Comparator;
import java.util.List;
import android.content.Context;
import android.os.*;
import android.view.*;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
public class SDLControllerManager
@ -98,7 +103,7 @@ public class SDLControllerManager
int sources = device.getSources();
/* This is called for every button press, so let's not spam the logs */
/**
/*
if ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
Log.v(TAG, "Input device " + device.getName() + " has class joystick.");
}
@ -108,7 +113,7 @@ public class SDLControllerManager
if ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
Log.v(TAG, "Input device " + device.getName() + " is a gamepad.");
}
**/
*/
return ((sources & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ||
((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
@ -167,7 +172,7 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
}
}
private ArrayList<SDLJoystick> mJoysticks;
private final ArrayList<SDLJoystick> mJoysticks;
public SDLJoystickHandler_API16() {
@ -177,13 +182,14 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
@Override
public void pollInputDevices() {
int[] deviceIds = InputDevice.getDeviceIds();
for(int i=0; i < deviceIds.length; ++i) {
SDLJoystick joystick = getJoystick(deviceIds[i]);
if (joystick == null) {
joystick = new SDLJoystick();
InputDevice joystickDevice = InputDevice.getDevice(deviceIds[i]);
if (SDLControllerManager.isDeviceSDLJoystick(deviceIds[i])) {
joystick.device_id = deviceIds[i];
for (int device_id : deviceIds) {
if (SDLControllerManager.isDeviceSDLJoystick(device_id)) {
SDLJoystick joystick = getJoystick(device_id);
if (joystick == null) {
InputDevice joystickDevice = InputDevice.getDevice(device_id);
joystick = new SDLJoystick();
joystick.device_id = device_id;
joystick.name = joystickDevice.getName();
joystick.desc = getJoystickDescriptor(joystickDevice);
joystick.axes = new ArrayList<InputDevice.MotionRange>();
@ -191,53 +197,57 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
List<InputDevice.MotionRange> ranges = joystickDevice.getMotionRanges();
Collections.sort(ranges, new RangeComparator());
for (InputDevice.MotionRange range : ranges ) {
for (InputDevice.MotionRange range : ranges) {
if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
if (range.getAxis() == MotionEvent.AXIS_HAT_X ||
range.getAxis() == MotionEvent.AXIS_HAT_Y) {
if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) {
joystick.hats.add(range);
}
else {
} else {
joystick.axes.add(range);
}
}
}
mJoysticks.add(joystick);
SDLControllerManager.nativeAddJoystick(joystick.device_id, joystick.name, joystick.desc, getVendorId(joystickDevice), getProductId(joystickDevice), false, getButtonMask(joystickDevice), joystick.axes.size(), joystick.hats.size()/2, 0);
SDLControllerManager.nativeAddJoystick(joystick.device_id, joystick.name, joystick.desc,
getVendorId(joystickDevice), getProductId(joystickDevice), false,
getButtonMask(joystickDevice), joystick.axes.size(), joystick.hats.size()/2, 0);
}
}
}
/* Check removed devices */
ArrayList<Integer> removedDevices = new ArrayList<Integer>();
for(int i=0; i < mJoysticks.size(); i++) {
int device_id = mJoysticks.get(i).device_id;
int j;
for (j=0; j < deviceIds.length; j++) {
if (device_id == deviceIds[j]) break;
ArrayList<Integer> removedDevices = null;
for (SDLJoystick joystick : mJoysticks) {
int device_id = joystick.device_id;
int i;
for (i = 0; i < deviceIds.length; i++) {
if (device_id == deviceIds[i]) break;
}
if (j == deviceIds.length) {
removedDevices.add(Integer.valueOf(device_id));
if (i == deviceIds.length) {
if (removedDevices == null) {
removedDevices = new ArrayList<Integer>();
}
removedDevices.add(device_id);
}
}
for(int i=0; i < removedDevices.size(); i++) {
int device_id = removedDevices.get(i).intValue();
SDLControllerManager.nativeRemoveJoystick(device_id);
for (int j=0; j < mJoysticks.size(); j++) {
if (mJoysticks.get(j).device_id == device_id) {
mJoysticks.remove(j);
break;
if (removedDevices != null) {
for (int device_id : removedDevices) {
SDLControllerManager.nativeRemoveJoystick(device_id);
for (int i = 0; i < mJoysticks.size(); i++) {
if (mJoysticks.get(i).device_id == device_id) {
mJoysticks.remove(i);
break;
}
}
}
}
}
protected SDLJoystick getJoystick(int device_id) {
for(int i=0; i < mJoysticks.size(); i++) {
if (mJoysticks.get(i).device_id == device_id) {
return mJoysticks.get(i);
for (SDLJoystick joystick : mJoysticks) {
if (joystick.device_id == device_id) {
return joystick;
}
}
return null;
@ -248,25 +258,21 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
int actionPointerIndex = event.getActionIndex();
int action = event.getActionMasked();
switch(action) {
case MotionEvent.ACTION_MOVE:
SDLJoystick joystick = getJoystick(event.getDeviceId());
if ( joystick != null ) {
for (int i = 0; i < joystick.axes.size(); i++) {
InputDevice.MotionRange range = joystick.axes.get(i);
/* Normalize the value to -1...1 */
float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
SDLControllerManager.onNativeJoy(joystick.device_id, i, value );
}
for (int i = 0; i < joystick.hats.size(); i+=2) {
int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) );
int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) );
SDLControllerManager.onNativeHat(joystick.device_id, i/2, hatX, hatY );
}
if (action == MotionEvent.ACTION_MOVE) {
SDLJoystick joystick = getJoystick(event.getDeviceId());
if (joystick != null) {
for (int i = 0; i < joystick.axes.size(); i++) {
InputDevice.MotionRange range = joystick.axes.get(i);
/* Normalize the value to -1...1 */
float value = (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin()) / range.getRange() * 2.0f - 1.0f;
SDLControllerManager.onNativeJoy(joystick.device_id, i, value);
}
break;
default:
break;
for (int i = 0; i < joystick.hats.size() / 2; i++) {
int hatX = Math.round(event.getAxisValue(joystick.hats.get(2 * i).getAxis(), actionPointerIndex));
int hatY = Math.round(event.getAxisValue(joystick.hats.get(2 * i + 1).getAxis(), actionPointerIndex));
SDLControllerManager.onNativeHat(joystick.device_id, i, hatX, hatY);
}
}
}
}
return true;
@ -432,13 +438,13 @@ class SDLHapticHandler_API26 extends SDLHapticHandler {
class SDLHapticHandler {
class SDLHaptic {
static class SDLHaptic {
public int device_id;
public String name;
public Vibrator vib;
}
private ArrayList<SDLHaptic> mHaptics;
private final ArrayList<SDLHaptic> mHaptics;
public SDLHapticHandler() {
mHaptics = new ArrayList<SDLHaptic>();
@ -504,37 +510,41 @@ class SDLHapticHandler {
}
/* Check removed devices */
ArrayList<Integer> removedDevices = new ArrayList<Integer>();
for(int i=0; i < mHaptics.size(); i++) {
int device_id = mHaptics.get(i).device_id;
int j;
for (j=0; j < deviceIds.length; j++) {
if (device_id == deviceIds[j]) break;
ArrayList<Integer> removedDevices = null;
for (SDLHaptic haptic : mHaptics) {
int device_id = haptic.device_id;
int i;
for (i = 0; i < deviceIds.length; i++) {
if (device_id == deviceIds[i]) break;
}
if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) {
// don't remove the vibrator if it is still present
} else if (j == deviceIds.length) {
removedDevices.add(device_id);
}
if (device_id != deviceId_VIBRATOR_SERVICE || !hasVibratorService) {
if (i == deviceIds.length) {
if (removedDevices == null) {
removedDevices = new ArrayList<Integer>();
}
removedDevices.add(device_id);
}
} // else: don't remove the vibrator if it is still present
}
for(int i=0; i < removedDevices.size(); i++) {
int device_id = removedDevices.get(i);
SDLControllerManager.nativeRemoveHaptic(device_id);
for (int j=0; j < mHaptics.size(); j++) {
if (mHaptics.get(j).device_id == device_id) {
mHaptics.remove(j);
break;
if (removedDevices != null) {
for (int device_id : removedDevices) {
SDLControllerManager.nativeRemoveHaptic(device_id);
for (int i = 0; i < mHaptics.size(); i++) {
if (mHaptics.get(i).device_id == device_id) {
mHaptics.remove(i);
break;
}
}
}
}
}
protected SDLHaptic getHaptic(int device_id) {
for(int i=0; i < mHaptics.size(); i++) {
if (mHaptics.get(i).device_id == device_id) {
return mHaptics.get(i);
for (SDLHaptic haptic : mHaptics) {
if (haptic.device_id == device_id) {
return haptic;
}
}
return null;
@ -655,8 +665,7 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API12 {
public float getEventX(MotionEvent event) {
if (mRelativeModeEnabled) {
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
}
else {
} else {
return event.getX(0);
}
}
@ -665,14 +674,12 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API12 {
public float getEventY(MotionEvent event) {
if (mRelativeModeEnabled) {
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
}
else {
} else {
return event.getY(0);
}
}
}
class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
// Generic Motion (mouse hover, joystick...) events go here
private boolean mRelativeModeEnabled;
@ -753,15 +760,12 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
if (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)) {
if (enabled) {
SDLActivity.getContentView().requestPointerCapture();
}
else {
} else {
SDLActivity.getContentView().releasePointerCapture();
}
mRelativeModeEnabled = enabled;
return true;
}
else
{
} else {
return false;
}
}

File diff suppressed because it is too large Load diff

2
externals/SDL2 vendored

@ -1 +1 @@
Subproject commit 863c4bd26b51892864c6042ad2db474e11b08fed
Subproject commit 25f9ed87ff6947d9576fc9d79dee0784e638ac58

View file

@ -29,6 +29,7 @@ project "sdl2"
"../externals/SDL2/src/audio/winmm/SDL_winmm.c",
"../externals/SDL2/src/audio/wasapi/SDL_wasapi.c",
"../externals/SDL2/src/audio/wasapi/SDL_wasapi_win32.c",
"../externals/SDL2/src/core/windows/SDL_hid.c",
"../externals/SDL2/src/core/windows/SDL_windows.c",
"../externals/SDL2/src/core/windows/SDL_xinput.c",
"../externals/SDL2/src/cpuinfo/SDL_cpuinfo.c",
@ -45,24 +46,32 @@ project "sdl2"
"../externals/SDL2/src/events/SDL_windowevents.c",
"../externals/SDL2/src/file/SDL_rwops.c",
"../externals/SDL2/src/filesystem/windows/SDL_sysfilesystem.c",
"../externals/SDL2/src/haptic/dummy/SDL_syshaptic.c",
"../externals/SDL2/src/haptic/SDL_haptic.c",
"../externals/SDL2/src/haptic/windows/SDL_dinputhaptic.c",
"../externals/SDL2/src/haptic/windows/SDL_windowshaptic.c",
"../externals/SDL2/src/haptic/windows/SDL_xinputhaptic.c",
"../externals/SDL2/src/hidapi/windows/hid.c",
"../externals/SDL2/src/hidapi/SDL_hidapi.c",
"../externals/SDL2/src/joystick/dummy/SDL_sysjoystick.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapijoystick.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_gamecube.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_luna.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_ps4.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_ps5.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_rumble.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_stadia.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_switch.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_xbox360.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_xbox360w.c",
"../externals/SDL2/src/joystick/hidapi/SDL_hidapi_xboxone.c",
"../externals/SDL2/src/joystick/SDL_gamecontroller.c",
"../externals/SDL2/src/joystick/SDL_joystick.c",
"../externals/SDL2/src/joystick/virtual/SDL_virtualjoystick.c",
"../externals/SDL2/src/joystick/windows/SDL_dinputjoystick.c",
"../externals/SDL2/src/joystick/windows/SDL_mmjoystick.c",
"../externals/SDL2/src/joystick/windows/SDL_rawinputjoystick.c",
"../externals/SDL2/src/joystick/windows/SDL_windowsjoystick.c",
"../externals/SDL2/src/joystick/windows/SDL_windows_gaming_input.c",
"../externals/SDL2/src/joystick/windows/SDL_xinputjoystick.c",
"../externals/SDL2/src/libm/e_atan2.c",
"../externals/SDL2/src/libm/e_exp.c",
@ -85,6 +94,10 @@ project "sdl2"
"../externals/SDL2/src/libm/s_sin.c",
"../externals/SDL2/src/libm/s_tan.c",
"../externals/SDL2/src/loadso/windows/SDL_sysloadso.c",
"../externals/SDL2/src/locale/SDL_locale.c",
"../externals/SDL2/src/locale/windows/SDL_syslocale.c",
"../externals/SDL2/src/misc/SDL_url.c",
"../externals/SDL2/src/misc/windows/SDL_sysurl.c",
"../externals/SDL2/src/power/SDL_power.c",
"../externals/SDL2/src/power/windows/SDL_syspower.c",
"../externals/SDL2/src/render/direct3d11/SDL_shaders_d3d11.c",
@ -113,6 +126,8 @@ project "sdl2"
"../externals/SDL2/src/SDL_log.c",
"../externals/SDL2/src/sensor/dummy/SDL_dummysensor.c",
"../externals/SDL2/src/sensor/SDL_sensor.c",
"../externals/SDL2/src/sensor/windows/SDL_windowssensor.c",
"../externals/SDL2/src/stdlib/SDL_crc32.c",
"../externals/SDL2/src/stdlib/SDL_getenv.c",
"../externals/SDL2/src/stdlib/SDL_iconv.c",
"../externals/SDL2/src/stdlib/SDL_malloc.c",
@ -122,6 +137,7 @@ project "sdl2"
"../externals/SDL2/src/stdlib/SDL_strtokr.c",
"../externals/SDL2/src/thread/generic/SDL_syscond.c",
"../externals/SDL2/src/thread/SDL_thread.c",
"../externals/SDL2/src/thread/windows/SDL_syscond_srw.c",
"../externals/SDL2/src/thread/windows/SDL_sysmutex.c",
"../externals/SDL2/src/thread/windows/SDL_syssem.c",
"../externals/SDL2/src/thread/windows/SDL_systhread.c",