Skip to content

Commit

Permalink
Update SDL to the latest SDL2 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Jan 16, 2023
1 parent f4a3b54 commit 2dd5747
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 38 deletions.
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/741499dea777b98f6dee4479596f94ba02adbfdc.tar.gz
URL_HASH MD5=15a7923f0771d4c425569ecba3c71acf
URL https://github.com/libsdl-org/SDL/archive/5d1e6b28d9c97e5223281c0f0189f6c99a564b70.tar.gz
URL_HASH MD5=44c74cf0a55cccba738c5c4271bd23cd
)
FetchContent_MakeAvailableExcludeFromAll(SDL2)
2 changes: 1 addition & 1 deletion Packaging/xbox-one/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mkdir ..\..\build
cd ..\..\build

git clone https://github.com/libsdl-org/SDL.git
git -C SDL checkout c7097418711b57e786eeb464bbe366c056b19801
git -C SDL checkout 5d1e6b28d9c97e5223281c0f0189f6c99a564b70
msbuild /p:PlatformToolset=v143;TargetPlatformVersion=10.0.22000.0;TargetPlatformMinVersion=10.0.14393.0;ConfigurationType=StaticLibrary;Configuration=Release;Platform=x64 SDL\VisualC-WinRT\SDL-UWP.vcxproj

cmake -DUWP_LIB=1 -DUWP_SDL2_DIR="%CD%/SDL" -DCMAKE_BUILD_TYPE=x64-Release ..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa
final int XB1_IFACE_SUBCLASS = 71;
final int XB1_IFACE_PROTOCOL = 208;
final int[] SUPPORTED_VENDORS = {
0x044f, // Thrustmaster
0x045e, // Microsoft
0x0738, // Mad Catz
0x0e6f, // PDP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,18 @@ public void setOrientationBis(int w, int h, boolean resizable, String hint)
/* If set, hint "explicitly controls which UI orientations are allowed". */
if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) {
orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
} else if (hint.contains("LandscapeRight")) {
orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (hint.contains("LandscapeLeft")) {
orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (hint.contains("LandscapeRight")) {
orientation_landscape = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
}

if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) {
/* exact match to 'Portrait' to distinguish with PortraitUpsideDown */
boolean contains_Portrait = hint.contains("Portrait ") || hint.endsWith("Portrait");

if (contains_Portrait && hint.contains("PortraitUpsideDown")) {
orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
} else if (hint.contains("Portrait")) {
} else if (contains_Portrait) {
orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (hint.contains("PortraitUpsideDown")) {
orientation_portrait = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ public class SDLAudioManager {
protected static AudioRecord mAudioRecord;
protected static Context mContext;

private static final AudioDeviceCallback mAudioDeviceCallback = new AudioDeviceCallback() {
@Override
public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
Arrays.stream(addedDevices).forEach(deviceInfo -> addAudioDevice(deviceInfo.isSink(), deviceInfo.getId()));
}
private static final int[] NO_DEVICES = {};

@Override
public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
Arrays.stream(removedDevices).forEach(deviceInfo -> removeAudioDevice(deviceInfo.isSink(), deviceInfo.getId()));
}
};
private static AudioDeviceCallback mAudioDeviceCallback;

public static void initialize() {
mAudioTrack = null;
mAudioRecord = null;
mAudioDeviceCallback = null;

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
mAudioDeviceCallback = new AudioDeviceCallback() {
@Override
public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
Arrays.stream(addedDevices).forEach(deviceInfo -> addAudioDevice(deviceInfo.isSink(), deviceInfo.getId()));
}

@Override
public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
Arrays.stream(removedDevices).forEach(deviceInfo -> removeAudioDevice(deviceInfo.isSink(), deviceInfo.getId()));
}
};
}
}

public static void setContext(Context context) {
Expand Down Expand Up @@ -229,7 +237,7 @@ protected static int[] open(boolean isCapture, int sampleRate, int audioFormat,
return null;
}

if (deviceId != 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && deviceId != 0) {
mAudioRecord.setPreferredDevice(getOutputAudioDeviceInfo(deviceId));
}

Expand All @@ -256,7 +264,7 @@ protected static int[] open(boolean isCapture, int sampleRate, int audioFormat,
return null;
}

if (deviceId != 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && deviceId != 0) {
mAudioTrack.setPreferredDevice(getInputAudioDeviceInfo(deviceId));
}

Expand All @@ -275,45 +283,65 @@ protected static int[] open(boolean isCapture, int sampleRate, int audioFormat,
}

private static AudioDeviceInfo getInputAudioDeviceInfo(int deviceId) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS))
.filter(deviceInfo -> deviceInfo.getId() == deviceId)
.findFirst()
.orElse(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS))
.filter(deviceInfo -> deviceInfo.getId() == deviceId)
.findFirst()
.orElse(null);
} else {
return null;
}
}

private static AudioDeviceInfo getOutputAudioDeviceInfo(int deviceId) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS))
.filter(deviceInfo -> deviceInfo.getId() == deviceId)
.findFirst()
.orElse(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS))
.filter(deviceInfo -> deviceInfo.getId() == deviceId)
.findFirst()
.orElse(null);
} else {
return null;
}
}

private static void registerAudioDeviceCallback() {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, null);
}
}

private static void unregisterAudioDeviceCallback(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback);
}
}

/**
* This method is called by SDL using JNI.
*/
public static int[] getAudioOutputDevices() {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
} else {
return NO_DEVICES;
}
}

/**
* This method is called by SDL using JNI.
*/
public static int[] getAudioInputDevices() {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
} else {
return NO_DEVICES;
}
}

/**
Expand All @@ -332,6 +360,11 @@ public static void audioWriteFloatBuffer(float[] buffer) {
return;
}

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
Log.e(TAG, "Attempted to make an incompatible audio call with uninitialized audio! (floating-point output is supported since Android 5.0 Lollipop)");
return;
}

for (int i = 0; i < buffer.length;) {
int result = mAudioTrack.write(buffer, i, buffer.length - i, AudioTrack.WRITE_BLOCKING);
if (result > 0) {
Expand Down Expand Up @@ -410,7 +443,11 @@ public static int[] captureOpen(int sampleRate, int audioFormat, int desiredChan

/** This method is called by SDL using JNI. */
public static int captureReadFloatBuffer(float[] buffer, boolean blocking) {
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
if (Build.VERSION.SDK_INT < 23) {
return 0;
} else {
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
}
}

/** This method is called by SDL using JNI. */
Expand Down

0 comments on commit 2dd5747

Please sign in to comment.