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

Update SDL2, SDL2_ttf, SDL2_mixer, SDL2_image to latest releases #2673

Merged
merged 1 commit into from
Oct 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected void onPostExecute(String result) {
))) {
// Because sometimes the app will get stuck here and never
// actually run, ensure that it gets launched if we're active:
mActivity.onResume();
mActivity.resumeNativeThread();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
--- a/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/src/main/java/org/libsdl/app/SDLActivity.java
@@ -94,6 +94,8 @@
@@ -225,6 +225,8 @@
// This is what SDL runs in. It invokes SDL_main(), eventually
protected static Thread mSDLThread;

+ public static int keyboardInputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+
protected static SDLGenericMotionListener_API12 getMotionListener() {
if (mMotionListener == null) {
if (Build.VERSION.SDK_INT >= 26) {
@@ -196,6 +198,15 @@
@@ -323,6 +325,15 @@
Log.v(TAG, "onCreate()");
super.onCreate(savedInstanceState);

+ SDLActivity.initialize();
+ // So we can call stuff from static callbacks
+ mSingleton = this;
Expand All @@ -22,70 +22,54 @@
+ // and we can't run setup tasks until that thread completes.
+ protected void finishLoad() {
+
// Load shared libraries
String errorMsgBrokenLib = "";
try {
@@ -639,7 +650,7 @@
Thread.currentThread().setName("SDLActivity");
} catch (Exception e) {
@@ -824,7 +835,7 @@
Handler commandHandler = new SDLCommandHandler();

// Send a message from the SDLMain thread
- boolean sendCommand(int command, Object data) {
+ protected boolean sendCommand(int command, Object data) {
Message msg = commandHandler.obtainMessage();
msg.arg1 = command;
msg.obj = data;
@@ -1051,6 +1062,21 @@
return Arrays.copyOf(filtered, used);
@@ -1302,6 +1313,20 @@
return SDLActivity.mSurface.getNativeSurface();
}

+ /**
+ * Calls turnActive() on singleton to keep loading screen active
+ */
+ public static void triggerAppConfirmedActive() {
+ mSingleton.appConfirmedActive();
+ }
+
+ /**
+ * Trick needed for loading screen, overridden by PythonActivity
+ * to keep loading screen active
+ */
+ public void appConfirmedActive() {
+ }
+

+ /**
+ * Calls turnActive() on singleton to keep loading screen active
+ */
+ public static void triggerAppConfirmedActive() {
+ mSingleton.appConfirmedActive();
+ }
+
+ /**
+ * Trick needed for loading screen, overridden by PythonActivity
+ * to keep loading screen active
+ */
+ public void appConfirmedActive() {
+ }
+
// APK expansion files support

/** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
@@ -1341,14 +1367,13 @@
};

public void onSystemUiVisibilityChange(int visibility) {
- if (SDLActivity.mFullscreenModeActive && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
-
+ // SDL2 BUGFIX (see sdl bug #4424 ) - REMOVE WHEN FIXED IN UPSTREAM !!
+ if (SDLActivity.mFullscreenModeActive && ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 || (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0)) {
Handler handler = getWindow().getDecorView().getHandler();
if (handler != null) {
handler.removeCallbacks(rehideSystemUi); // Prevent a hide loop.
handler.postDelayed(rehideSystemUi, 2000);
}
-
// Input

/**
@@ -1795,7 +1820,7 @@
}
}

@@ -1475,6 +1500,7 @@
String[] arguments = SDLActivity.mSingleton.getArguments();


Log.v("SDL", "Running main function " + function + " from library " + library);
-
+ SDLActivity.mSingleton.appConfirmedActive();
SDLActivity.nativeRunMain(library, function, arguments);

Log.v("SDL", "Finished main function");
@@ -2002,7 +2028,7 @@
@@ -2316,7 +2341,7 @@
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
ic = new SDLInputConnection(this, true);

- outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
- outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
+ outAttrs.inputType = SDLActivity.keyboardInputType;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
| EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;

22 changes: 21 additions & 1 deletion pythonforandroid/recipes/kivy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import glob
from os.path import basename, exists, join
import sys
import packaging.version

import sh
from pythonforandroid.recipe import CythonRecipe
from pythonforandroid.toolchain import current_directory, shprint


def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
with current_directory(join(recipe.get_build_dir(arch.arch), "kivy")):
kivy_version = shprint(
sh.Command(sys.executable),
"-c",
"import _version; print(_version.__version__)",
)

return packaging.version.parse(
str(kivy_version)
) < packaging.version.Version("2.2.0.dev0")


class KivyRecipe(CythonRecipe):
version = '2.1.0'
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
Expand All @@ -14,6 +29,11 @@ class KivyRecipe(CythonRecipe):
depends = ['sdl2', 'pyjnius', 'setuptools']
python_depends = ['certifi']

# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
# See: https://github.com/kivy/kivy/pull/8025
# WARNING: Remove this patch when a new Kivy version is released.
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]

def cythonize_build(self, env, build_dir='.'):
super().cythonize_build(env, build_dir=build_dir)

Expand Down Expand Up @@ -48,7 +68,7 @@ def get_recipe_env(self, arch):
env['KIVY_SDL2_PATH'] = ':'.join([
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer', 'include'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
])

Expand Down
32 changes: 32 additions & 0 deletions pythonforandroid/recipes/kivy/sdl-gl-swapwindow-nogil.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/kivy/core/window/_window_sdl2.pyx b/kivy/core/window/_window_sdl2.pyx
index 46e15ec63..5002cd0f9 100644
--- a/kivy/core/window/_window_sdl2.pyx
+++ b/kivy/core/window/_window_sdl2.pyx
@@ -746,7 +746,13 @@ cdef class _WindowSDL2Storage:
pass

def flip(self):
- SDL_GL_SwapWindow(self.win)
+ # On Android (and potentially other platforms), SDL_GL_SwapWindow may
+ # lock the thread waiting for a mutex from another thread to be
+ # released. Calling SDL_GL_SwapWindow with the GIL released allow the
+ # other thread to run (e.g. to process the event filter callback) and
+ # release the mutex SDL_GL_SwapWindow is waiting for.
+ with nogil:
+ SDL_GL_SwapWindow(self.win)

def save_bytes_in_png(self, filename, data, int width, int height):
cdef SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
diff --git a/kivy/lib/sdl2.pxi b/kivy/lib/sdl2.pxi
index 6a539de6d..3a5a69d23 100644
--- a/kivy/lib/sdl2.pxi
+++ b/kivy/lib/sdl2.pxi
@@ -627,7 +627,7 @@ cdef extern from "SDL.h":
cdef SDL_GLContext SDL_GL_GetCurrentContext()
cdef int SDL_GL_SetSwapInterval(int interval)
cdef int SDL_GL_GetSwapInterval()
- cdef void SDL_GL_SwapWindow(SDL_Window * window)
+ cdef void SDL_GL_SwapWindow(SDL_Window * window) nogil
cdef void SDL_GL_DeleteContext(SDL_GLContext context)

cdef int SDL_NumJoysticks()
8 changes: 4 additions & 4 deletions pythonforandroid/recipes/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


class LibSDL2Recipe(BootstrapNDKRecipe):
version = "2.0.9"
url = "https://www.libsdl.org/release/SDL2-{version}.tar.gz"
md5sum = 'f2ecfba915c54f7200f504d8b48a5dfe'
version = "2.24.0"
url = "https://github.com/libsdl-org/SDL/releases/download/release-{version}/SDL2-{version}.tar.gz"
md5sum = 'cf539ffe9e0dd6f943ac9de75fd2e56e'

dir_name = 'SDL'

Expand All @@ -22,7 +22,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True, with_python=True):

def should_build(self, arch):
libdir = join(self.get_build_dir(arch.arch), "../..", "libs", arch.arch)
libs = ['libhidapi.so', 'libmain.so', 'libSDL2.so', 'libSDL2_image.so', 'libSDL2_mixer.so', 'libSDL2_ttf.so']
libs = ['libmain.so', 'libSDL2.so', 'libSDL2_image.so', 'libSDL2_mixer.so', 'libSDL2_ttf.so']
return not all(exists(join(libdir, x)) for x in libs)

def build_arch(self, arch):
Expand Down
21 changes: 16 additions & 5 deletions pythonforandroid/recipes/sdl2_image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import os
import sh
from pythonforandroid.logger import shprint
from pythonforandroid.recipe import BootstrapNDKRecipe
from pythonforandroid.util import current_directory


class LibSDL2Image(BootstrapNDKRecipe):
version = '2.0.4'
url = 'https://www.libsdl.org/projects/SDL_image/release/SDL2_image-{version}.tar.gz'
version = '2.6.2'
url = 'https://github.com/libsdl-org/SDL_image/releases/download/release-{version}/SDL2_image-{version}.tar.gz'
dir_name = 'SDL2_image'

patches = ['toggle_jpg_png_webp.patch',
'extra_cflags.patch',
]
patches = ['enable-webp.patch']

def prebuild_arch(self, arch):
# We do not have a folder for each arch on BootstrapNDKRecipe, so we
# need to skip the external deps download if we already have done it.
external_deps_dir = os.path.join(self.get_build_dir(arch.arch), "external")
if not os.path.exists(os.path.join(external_deps_dir, "libwebp")):
with current_directory(external_deps_dir):
shprint(sh.Command("./download.sh"))
super().prebuild_arch(arch)


recipe = LibSDL2Image()

This file was deleted.

12 changes: 12 additions & 0 deletions pythonforandroid/recipes/sdl2_image/enable-webp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff -Naur SDL2_image.orig/Android.mk SDL2_image/Android.mk
--- SDL2_image.orig/Android.mk 2022-10-03 20:51:52.000000000 +0200
+++ SDL2_image/Android.mk 2022-10-03 20:52:48.000000000 +0200
@@ -32,7 +32,7 @@

# Enable this if you want to support loading WebP images
# The library path should be a relative path to this directory.
-SUPPORT_WEBP ?= false
+SUPPORT_WEBP := true
WEBP_LIBRARY_PATH := external/libwebp


11 changes: 0 additions & 11 deletions pythonforandroid/recipes/sdl2_image/extra_cflags.patch

This file was deleted.

25 changes: 0 additions & 25 deletions pythonforandroid/recipes/sdl2_image/toggle_jpg_png_webp.patch

This file was deleted.

6 changes: 2 additions & 4 deletions pythonforandroid/recipes/sdl2_mixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@


class LibSDL2Mixer(BootstrapNDKRecipe):
version = '2.0.4'
url = 'https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-{version}.tar.gz'
version = '2.6.2'
url = 'https://github.com/libsdl-org/SDL_mixer/releases/download/release-{version}/SDL2_mixer-{version}.tar.gz'
dir_name = 'SDL2_mixer'

patches = ['toggle_modplug_mikmod_smpeg_ogg.patch']


recipe = LibSDL2Mixer()

This file was deleted.

4 changes: 2 additions & 2 deletions pythonforandroid/recipes/sdl2_ttf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class LibSDL2TTF(BootstrapNDKRecipe):
version = '2.0.15'
url = 'https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-{version}.tar.gz'
version = '2.20.1'
url = 'https://github.com/libsdl-org/SDL_ttf/releases/download/release-{version}/SDL2_ttf-{version}.tar.gz'
dir_name = 'SDL2_ttf'


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
install_reqs = [
'appdirs', 'colorama>=0.3.3', 'jinja2',
'sh>=1.10; sys_platform!="nt"',
'pep517', 'toml',
'pep517', 'toml', 'packaging',
]
# (pep517 and toml are used by pythonpackage.py)

Expand Down