Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade SDL to 2.30.0 for 1.5 #6920

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
switch:
docker:
- image: devkitpro/devkita64:latest
- image: devkitpro/devkita64@sha256:ff45e29f2efab7f70651cee39e1d98952d0db970d78c4d71bcd94efcfb0e4e5f
working_directory: ~/repo
steps:
- checkout
Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/SDL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(SDL_TEST_ENABLED_BY_DEFAULT OFF)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
FetchContent_Declare(SDL2
URL https://github.com/libsdl-org/SDL/archive/8b39eb9b1ff885978816dd9663277608187e8676.tar.gz
URL_HASH MD5=3cf9bf5f20375aa5dcc529193c809967
URL https://github.com/libsdl-org/SDL/releases/download/release-2.30.0/SDL2-2.30.0.tar.gz
URL_HASH SHA256=36e2e41557e0fa4a1519315c0f5958a87ccb27e25c51776beb6f1239526447b0
)
FetchContent_MakeAvailableExcludeFromAll(SDL2)
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public BluetoothGatt getGatt() {
// Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
// of TRANSPORT_LE. Let's force ourselves to connect low energy.
private BluetoothGatt connectGatt(boolean managed) {
if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) {
try {
return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
} catch (Exception e) {
Expand Down Expand Up @@ -429,7 +429,7 @@ public void run() {
}
});
}
}
}
else if (newState == 0) {
mIsConnected = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private boolean isXbox360Controller(UsbDevice usbDevice, UsbInterface usbInterfa
0x24c6, // PowerA
0x2c22, // Qanba
0x2dc8, // 8BitDo
0x9886, // ASTRO Gaming
};

if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
Expand All @@ -272,6 +273,7 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa
final int XB1_IFACE_SUBCLASS = 71;
final int XB1_IFACE_PROTOCOL = 208;
final int[] SUPPORTED_VENDORS = {
0x03f0, // HP
0x044f, // Thrustmaster
0x045e, // Microsoft
0x0738, // Mad Catz
Expand All @@ -283,6 +285,7 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa
0x24c6, // PowerA
0x2dc8, // 8BitDo
0x2e24, // Hyperkin
0x3537, // GameSir
};

if (usbInterface.getId() == 0 &&
Expand Down Expand Up @@ -356,13 +359,19 @@ private void connectHIDDeviceUSB(UsbDevice usbDevice) {
private void initializeBluetooth() {
Log.d(TAG, "Initializing Bluetooth");

if (Build.VERSION.SDK_INT <= 30 &&
if (Build.VERSION.SDK_INT >= 31 /* Android 12 */ &&
mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH_CONNECT, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH_CONNECT");
return;
}

if (Build.VERSION.SDK_INT <= 30 /* Android 11.0 (R) */ &&
mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH");
return;
}

if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18)) {
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18 /* Android 4.3 (JELLY_BEAN_MR2) */)) {
Log.d(TAG, "Couldn't initialize Bluetooth, this version of Android does not support Bluetooth LE");
return;
}
Expand Down Expand Up @@ -576,7 +585,7 @@ public boolean openDevice(int deviceID) {
try {
final int FLAG_MUTABLE = 0x02000000; // PendingIntent.FLAG_MUTABLE, but don't require SDK 31
int flags;
if (Build.VERSION.SDK_INT >= 31) {
if (Build.VERSION.SDK_INT >= 31 /* Android 12.0 (S) */) {
flags = FLAG_MUTABLE;
} else {
flags = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int getProductId() {
@Override
public String getSerialNumber() {
String result = null;
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
try {
result = mDevice.getSerialNumber();
}
Expand All @@ -74,7 +74,7 @@ public int getVersion() {
@Override
public String getManufacturerName() {
String result = null;
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
result = mDevice.getManufacturerName();
}
if (result == null) {
Expand All @@ -86,7 +86,7 @@ public String getManufacturerName() {
@Override
public String getProductName() {
String result = null;
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
result = mDevice.getProductName();
}
if (result == null) {
Expand Down
82 changes: 46 additions & 36 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL";
private static final int SDL_MAJOR_VERSION = 2;
private static final int SDL_MINOR_VERSION = 27;
private static final int SDL_MINOR_VERSION = 30;
private static final int SDL_MICRO_VERSION = 0;
/*
// Display InputType.SOURCE/CLASS of events and devices
Expand Down Expand Up @@ -93,7 +93,7 @@ public static void debugSource(int sources, String prefix) {

s2 = s_copy & InputDevice.SOURCE_ANY; // keep source only, no class;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= 23) {
tst = InputDevice.SOURCE_BLUETOOTH_STYLUS;
if ((s & tst) == tst) src += " BLUETOOTH_STYLUS";
s2 &= ~tst;
Expand All @@ -107,7 +107,7 @@ public static void debugSource(int sources, String prefix) {
if ((s & tst) == tst) src += " GAMEPAD";
s2 &= ~tst;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.VERSION.SDK_INT >= 21) {
tst = InputDevice.SOURCE_HDMI;
if ((s & tst) == tst) src += " HDMI";
s2 &= ~tst;
Expand Down Expand Up @@ -146,7 +146,7 @@ public static void debugSource(int sources, String prefix) {
if ((s & tst) == tst) src += " TOUCHSCREEN";
s2 &= ~tst;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (Build.VERSION.SDK_INT >= 18) {
tst = InputDevice.SOURCE_TOUCH_NAVIGATION;
if ((s & tst) == tst) src += " TOUCH_NAVIGATION";
s2 &= ~tst;
Expand All @@ -170,7 +170,7 @@ public static void debugSource(int sources, String prefix) {
*/

public static boolean mIsResumedCalled, mHasFocus;
public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24);
public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */);

// Cursor types
// private static final int SDL_SYSTEM_CURSOR_NONE = -1;
Expand Down Expand Up @@ -224,9 +224,9 @@ public enum NativeState {

protected static SDLGenericMotionListener_API12 getMotionListener() {
if (mMotionListener == null) {
if (Build.VERSION.SDK_INT >= 26) {
if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
mMotionListener = new SDLGenericMotionListener_API26();
} else if (Build.VERSION.SDK_INT >= 24) {
} else if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
mMotionListener = new SDLGenericMotionListener_API24();
} else {
mMotionListener = new SDLGenericMotionListener_API12();
Expand Down Expand Up @@ -404,7 +404,7 @@ public void onClick(DialogInterface dialog,int id) {
SDLActivity.onNativeOrientationChanged(mCurrentOrientation);

try {
if (Build.VERSION.SDK_INT < 24) {
if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) {
mCurrentLocale = getContext().getResources().getConfiguration().locale;
} else {
mCurrentLocale = getContext().getResources().getConfiguration().getLocales().get(0);
Expand Down Expand Up @@ -768,7 +768,7 @@ public void handleMessage(Message msg) {
}
break;
case COMMAND_CHANGE_WINDOW_STYLE:
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
if (context instanceof Activity) {
Window window = ((Activity) context).getWindow();
if (window != null) {
Expand Down Expand Up @@ -843,7 +843,7 @@ boolean sendCommand(int command, Object data) {
msg.obj = data;
boolean result = commandHandler.sendMessage(msg);

if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
if (command == COMMAND_CHANGE_WINDOW_STYLE) {
// Ensure we don't return until the resize has actually happened,
// or 500ms have passed.
Expand Down Expand Up @@ -1095,7 +1095,7 @@ public static boolean supportsRelativeMouse()
// thus SDK version 27. If we are in DeX mode and not API 27 or higher, as a result,
// we should stick to relative mode.
//
if ((Build.VERSION.SDK_INT < 27) && isDeXMode()) {
if (Build.VERSION.SDK_INT < 27 /* Android 8.1 (O_MR1) */ && isDeXMode()) {
return false;
}

Expand Down Expand Up @@ -1185,7 +1185,7 @@ public static boolean isChromebook() {
* This method is called by SDL using JNI.
*/
public static boolean isDeXMode() {
if (Build.VERSION.SDK_INT < 24) {
if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) {
return false;
}
try {
Expand Down Expand Up @@ -1345,23 +1345,6 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC
}
}

if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (isTextInputEvent(event)) {
if (ic != null) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} else {
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
}
onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
onNativeKeyUp(keyCode);
return true;
}
}

if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy
Expand All @@ -1376,6 +1359,21 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC
}
}

if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (isTextInputEvent(event)) {
if (ic != null) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} else {
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
}
onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
onNativeKeyUp(keyCode);
return true;
}

return false;
}

Expand Down Expand Up @@ -1622,7 +1620,7 @@ public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) {
private final Runnable rehideSystemUi = new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
Expand Down Expand Up @@ -1675,7 +1673,7 @@ public static int createCustomCursor(int[] colors, int width, int height, int ho
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
++mLastCursorID;

if (Build.VERSION.SDK_INT >= 24) {
if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try {
mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY));
} catch (Exception e) {
Expand All @@ -1691,7 +1689,7 @@ public static int createCustomCursor(int[] colors, int width, int height, int ho
* This method is called by SDL using JNI.
*/
public static void destroyCustomCursor(int cursorID) {
if (Build.VERSION.SDK_INT >= 24) {
if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try {
mCursors.remove(cursorID);
} catch (Exception e) {
Expand All @@ -1705,7 +1703,7 @@ public static void destroyCustomCursor(int cursorID) {
*/
public static boolean setCustomCursor(int cursorID) {

if (Build.VERSION.SDK_INT >= 24) {
if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try {
mSurface.setPointerIcon(mCursors.get(cursorID));
} catch (Exception e) {
Expand Down Expand Up @@ -1760,7 +1758,7 @@ public static boolean setSystemCursor(int cursorID) {
cursor_type = 1002; //PointerIcon.TYPE_HAND;
break;
}
if (Build.VERSION.SDK_INT >= 24) {
if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try {
mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type));
} catch (Exception e) {
Expand All @@ -1774,7 +1772,7 @@ public static boolean setSystemCursor(int cursorID) {
* This method is called by SDL using JNI.
*/
public static void requestPermission(String permission, int requestCode) {
if (Build.VERSION.SDK_INT < 23) {
if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
nativePermissionResult(requestCode, true);
return;
}
Expand Down Expand Up @@ -1803,7 +1801,7 @@ public static int openURL(String url)
i.setData(Uri.parse(url));

int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
} else {
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
Expand Down Expand Up @@ -2007,6 +2005,18 @@ public boolean setComposingText(CharSequence text, int newCursorPosition) {

@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
if (Build.VERSION.SDK_INT <= 29 /* Android 10.0 (Q) */) {
// Workaround to capture backspace key. Ref: http://stackoverflow.com/questions>/14560344/android-backspace-in-webview-baseinputconnection
// and https://bugzilla.libsdl.org/show_bug.cgi?id=2265
if (beforeLength > 0 && afterLength == 0) {
// backspace(s)
while (beforeLength-- > 0) {
nativeGenerateScancodeForUnichar('\b');
}
return true;
}
}

if (!super.deleteSurroundingText(beforeLength, afterLength)) {
return false;
}
Expand Down
Loading
Loading