Commit Graph

4593 Commits (fb8cb95fbc63f3d64b2a5fbe385c680608e65171)

Author SHA1 Message Date
Sam Lantinga fb8cb95fbc Fixed compiler warning 2019-01-12 12:12:43 -08:00
Sam Lantinga 390459d83e Updated minimum supported Android version to API 16, to match latest NDK toolchain 2019-01-12 12:11:06 -08:00
Sylvain Becker be991f3a78 Fixed bug 4453 - GLES / GLES2: first white renderer clear cmd is drawn as black 2019-01-12 13:34:03 +01:00
Sylvain Becker 7b42f03fd9 Android: move and group JNIEnv helper functions 2019-01-11 21:52:43 +01:00
Sylvain Becker 7f3478305f Android: change the way JNIEnv is retrieved
- Currently, it tries to Attach the JVM first and update the thread local storage, which are two operations.
  Now, it simply gives back the JNI Env stored for the thread.

- Android_JNI_SetupThreadi() should only be used for external.
  For internal SDL thread, it's already called in RunThread() (SDL_systhread.c),
  and other thread are Java threads which don't need to be attached. i
  (even if it doesn't hurt to do it, since it's a no-op).

- JNI_OnLoad is filled with pthread_create, GetEnv, AttachCurrentThread...
  It's called for all shared libraries which may don't want this setup,
  and loading libraries can be also modified to be done from a static context,
  or with relinker. So it's not really clear how, who and what it sets up.
  => Reduce this function to the minimal
2019-01-11 21:42:52 +01:00
Sylvain Becker dc10d96cde Android: use the same naming for JNI env local variables 2019-01-11 15:36:16 +01:00
Sylvain Becker 3cfd907df7 Android: Audio thread is already setup for the JVM
In 'src/thread/pthread/SDL_systhread.c' RunThread() calls first 'Android_JNI_SetupThread()'
2019-01-11 15:33:02 +01:00
Sylvain Becker 9d82f4e985 Android: use pthread_once for creating thread key 'mThreadKey' 2019-01-11 15:27:53 +01:00
Sylvain Becker 9a98e5afe1 Android: don't call Android_JNI_ThreadDestroyed() for Java SDLThread
SDLThread is a Java Thread, it's not needed to call 'Detach' from the JVM.
Clear mThreadKey, so that the pthread_create destructor is not called for this
thread.
2019-01-11 14:50:43 +01:00
Sylvain Becker 42e18bd0c2 Android: fix bad merge from previous commit 2019-01-11 14:25:32 +01:00
Sylvain Becker b44a7aea8f Android: fix prototype of Android_JNI_InitTouch 2019-01-10 21:49:00 +01:00
Sylvain Becker 7a1d1baefc Android: add name for Touch devices and simplification, from bug 3958 2019-01-10 21:40:57 +01:00
Sylvain Becker d23c2f07e3 Fixed bug 3930 - Android, set thread priorities and names
SDLActivity thread priority is unchanged, by default -10 (THREAD_PRIORITY_VIDEO).

SDLAudio thread priority was -4 (SDL_SetThreadPriority was ignored) and is now -16 (THREAD_PRIORITY_AUDIO).

SDLThread thread priority was 0 (THREAD_PRIORITY_DEFAULT) and is -4 (THREAD_PRIORITY_DISPLAY).
2019-01-10 18:05:56 +01:00
Sylvain Becker 0e0e0272b8 Android: remove deprecated PixelFormat in surfaceChanged()
Can be check by adding in build.grable:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
}

SDLActivity.java:1691: warning: [deprecation] A_8 in PixelFormat has been deprecated
        case PixelFormat.A_8:
SDLActivity.java:1694: warning: [deprecation] LA_88 in PixelFormat has been deprecated
SDLActivity.java:1697: warning: [deprecation] L_8 in PixelFormat has been deprecated
SDLActivity.java:1700: warning: [deprecation] RGBA_4444 in PixelFormat has been deprecated
SDLActivity.java:1704: warning: [deprecation] RGBA_5551 in PixelFormat has been deprecated
SDLActivity.java:1716: warning: [deprecation] RGB_332 in PixelFormat has been deprecated
2019-01-10 16:04:52 +01:00
Sylvain Becker 5c11e5ef92 Android: some simplification, don't need mExitCalledFromJava 2019-01-10 15:48:43 +01:00
Sylvain Becker 66fbfe1d00 Android: nativeQuit for SDLActivity thread
- destroy Android_ActivityMutex
- display any SDL error message that may have occured in this thread,
  since SDL_GetError() is thread specific, and user has no access to it.
2019-01-10 15:43:07 +01:00
Sylvain Becker dad8161103 Android: only send Quit event to SDLThread if it's not already terminated
And it avoids reporting errors using Android_Pause/ResumeSem that are NULL.
2019-01-10 15:35:46 +01:00
Sylvain Becker 61d37de099 Android: un-needed transition to Pause state.
- Don't need to go into Pause state, since onPause() has been called before.
- Don't need to call nativePause is SDLThread is already ended
2019-01-10 15:29:37 +01:00
Sylvain Becker 8dd915507e Android: prevent a dummy error message sending SDL_DISPLAYEVENT_ORIENTATION
In the usual case, first call to onNativeOrientationChanged() is done before
SDL has been initialised and would just set an error message
"Video subsystem has not been initialized" without sending the event.
2019-01-09 23:19:26 +01:00
Sylvain Becker 02f292eb13 Android: add some SetError for Android_SetWindowFullscreen
First error could happen if Android_SetWindowFullscreen somehow gets
called between SurfaceDestroyed() and SurfaceCreated()

Second error should not happen has native_window validity is guaranteed.
(It would happens previously with error -19)
2019-01-09 22:49:49 +01:00
Sylvain Becker 68c0e69f0a Android: native_window validity is guaranteed between surfaceCreated and Destroyed
It's currently still available after surfaceDestroyed().
And available (but invalid) between surfaceCreated() and surfaceChanged().

Which means ANativewindow_getWidth/Height/Format() fail in those cases.

https://developer.android.com/reference/android/view/SurfaceHolder.html#getSurface()
2019-01-09 22:41:52 +01:00
Sylvain Becker 1803944bb2 Android: concurrency issue for Android_SetWindowFullscreen()
It accesses data->native_window, which can be changed by onNativeSurfacedChanged().

Currently, Android_SetWindowFullscreen() may access data->native_window after it
has been released, and before a new reference is acquired.

(can be reproduced by adding some SDL_Delay() in onNativeSurfacedChanged and
Android_SetWindowFullscreen() ).
2019-01-09 15:18:41 +01:00
Sylvain Becker 59df6d6b13 Android: don't allow multiple instance of SDLActivity
Default launch mode (standard) allows multiple instances of the SDLActivity.
( https://developer.android.com/guide/topics/manifest/activity-element#lmode )

Not sure this is intended in SDL as this doesn't work. There are static
 variables in Java, in C code which make this impossible (allow one android_window) and
 also Audio print errors.

There is also some code added in onDestroy as if it would be able to
re-initialize: https://hg.libsdl.org/SDL/rev/27686adb08c3

Bug Android activity life-cycle seems to show there is not transition to get out
of onDestroy()
https://developer.android.com/reference/android/app/Activity#ActivityLifecycle

( can be tested with "adb shell am start  my.package.org/.MainActivity"
  and "adb shell am start -n  my.package.org/.MainActivity" )

Send me a message if there are real use-case for this !
2019-01-07 17:06:50 +01:00
Sylvain Becker cfe2924d07 Android: some robustness when quitting application from onDestroy()
Make sure there is not pending Pause accumulated, so the the application doesn't
remain paused and stucked in onDestroy().

Can be tested by adding:
 SDLActivity.nativePause();
 SDLActivity.nativePause();
 mSingleton.finish();
2019-01-07 11:35:31 +01:00
Sylvain Becker 462e62e154 Android: better fix for bug 3186. Run those commands from SDL thread. 2019-01-06 20:25:54 +01:00
Sylvain Becker 9f23d1815f Android: allow multiple calls to nativeResume()
Doesn't seem to happen manually, but symetrical to the pause handling.

Can be tested by adding:

mNextNativeState = SDLActivity.NativeState.PAUSED;
handleNativeState();
mNextNativeState = SDLActivity.NativeState.RESUMED;
handleNativeState();
mNextNativeState = SDLActivity.NativeState.PAUSED;
handleNativeState();
mNextNativeState = SDLActivity.NativeState.RESUMED;
handleNativeState();

Before, it ends in 'paused' state.
Now, it ends in 'resumed' state.
2019-01-06 17:35:42 +01:00
Sylvain Becker 911f1d3e67 Android: remove SURFACE_TYPE_GPU, deprecated in API level 5.
https://developer.android.com/reference/android/view/SurfaceHolder

This constant was deprecated in API level 5. this is ignored, this value is set automatically when needed.
2019-01-05 22:49:50 +01:00
Sylvain Becker e4f558a50c Android: un-needed check of "isPausing" and minor typos 2019-01-05 22:46:52 +01:00
Sylvain Becker 35722b6423 Android: fix wrong state after immediate sequence pause() / resume() / pause()
It may happen to have the sequence pause()/resume()/pause(), before polling
any events.

Before, it ends in 'resumed' state because as the check is greedy.
Now, always increase the Pause semaphore, and stop at each pause.
It ends in 'paused' state.

Related to bug 3250: set up a reconfiguration of SurfaceView holder.
Turn the screen off manually before the app starts
(repro rate is not 100%..)
2019-01-05 22:27:25 +01:00
Sam Lantinga d4c0f498db Fixed bug 4255 - SDL_GetGlobalMouseState() returns incorrect Y on secondary display
Julian Raschke

I use an open Mac laptop with an additional external monitor. The coordinate spaces from SDL_GetGlobalMouseState() and SDL_GetWindowPosition() match on the primary display, but not on the secondary display.

Cocoa window coordinates are vertically flipped in relation to the primary display:

https://github.com/spurious/SDL-mirror/blob/release-2.0.8/src/video/cocoa/SDL_cocoawindow.m#L219-L222

However, Cocoa_GetGlobalMouseState inverts the cursor Y coordinate per-display:

https://github.com/spurious/SDL-mirror/blob/release-2.0.8/src/video/cocoa/SDL_cocoamouse.m#L320-L323

Suggested fix: Replace the for-loop with this simpler calculation:

    *x = (int) cocoaLocation.x;
    *y = (int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
2019-01-04 22:09:38 -08:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Sylvain Becker 2a885eb036 Android: fixed immediate transition to pause and resume.
"Pause" transition will add events:
 SDL_WINDOWEVENT_ENTER
 SDL_WINDOWEVENT_FOCUS_LOST
 SDL_WINDOWEVENT_MINIMIZED
 SDL_APP_WILL ENTER BACKGROUND
 SDL_APP_DID ENTER BACKGROUND

"Resume" transition will add events:
 SDL_APP_WILL ENTER FOREGROUND
 SDL_APP_DID ENTER FOREGROUND
 SDL_WINDOWEVENT_FOCUS_GAINED
 SDL_WINDOWEVENT_RESTORED

If Android application doesn't empty the event loop in between, it enters in
"paused" state when SDL_WINDOWEVENT_RESTORED is fetched.

See bug 3250 for pratical case.
2019-01-04 23:39:27 +01:00
Sylvain Becker cf12234454 Android: make Android_PumpEvents() more readable
No behavior change in this commit.
2019-01-04 23:11:21 +01:00
Sylvain Becker ca184ac386 Android: concurrency issue with egl_surface EGL_BAD_SURFACE - (bug 4142)
Occurs when application goes to background:
- Java activity is destroying SurfaceView holder and "egl_surface" (in onNativeSurfaceDestroyed())
- While native thread is in Android_GLES_SwapWindow(), prepared to call SDL_EGL_SwapBuffers()

The error is "call to eglSwapBuffers failed, reporting an error of EGL_BAD_SURFACE"

It an be reproduced easily by adding a SDL_Delay(100) at the begining of SDL_EGL_SwapBuffers(),
and putting the application into background.
2019-01-03 23:22:50 +01:00
Sylvain Becker 2e19343df6 Android: use Mutex instead of Semphore for bug 4142 2019-01-03 20:18:29 +01:00
Sylvain Becker 23478642bd Android: prevent the error message from SDL_EGL_CreateSurface() to be masked. 2019-01-03 16:22:33 +01:00
Sylvain Becker cc8f1136b6 Fixed bug 4142 - Concurrency issues in Android backend
Use a semaphore to prevent concurrency issues between Java Activity and Native thread code, when using 'Android_Window'.
(Eg. Java sending Touch events, while native code is destroying the main SDL_Window. )
2019-01-03 14:18:06 +01:00
Sylvain Becker d11f7615fa Android: minor preparation for bug 4142 (concurrency issues) 2019-01-03 13:38:33 +01:00
Sylvain Becker 5dc25fef3b Android: preparation bug 4142, reduce usage of global variable Android_Window 2019-01-03 13:14:16 +01:00
Sylvain Becker a95f91bcea Fixed bug 3250 - Wrong backbuffer pixel format on Android, keep getting RGB_565
Use the egl format to reconfigure java SurfaceView holder format.
If there is a change, it triggers a surfaceDestroyed/Created/Change sequence.
2019-01-02 18:06:33 +01:00
Sylvain Becker a02998a292 Android: make sure surfaceChanged try to enter into 'resumed' state. 2019-01-02 17:41:33 +01:00
Sylvain Becker 4d2b5c791e Fixed bug 4424 - Android windowed mode is broken (Thanks Jonas Thiem!) 2019-01-02 17:08:01 +01:00
Sylvain Becker 03b0e1dee0 Android: on rare occasion, prevent Android_JNI_GetNativeWindow() from crashing
If Java getNativeSurface() returns null, then ANativeWindow_fromSurface() would crash().
2018-12-30 22:44:25 +01:00
Sylvain Becker 1e22fc1513 Android: fixed comments and spaces 2018-12-30 15:41:28 +01:00
Sylvain Becker 2a412eb94c Fixed bug 3186 - Android SW keyboard not restored when app becomes foreground. 2018-12-30 15:39:37 +01:00
Sylvain Becker d09774a47c Fixed bug 3511 - documentation to end an Android application 2018-12-30 14:23:25 +01:00
Sylvain Becker 9cdd0dd996 PSP renderer: use colors from 'draw' union (very likely, but un-tested) 2018-12-29 17:59:34 +01:00
Sylvain Becker ebd9efb361 opengles 1: same fix as in bug #4433 2018-12-29 16:37:44 +01:00
Sylvain Becker 87b7636918 opengles 1: use color from 'draw' union in SetDrawState() 2018-12-29 16:34:50 +01:00
Alex Szpakowski dc3443602b render: Fix internal state getting out of sync when destroying a texture that was just rendered and then creating a new one, in the GL and GLES2 backends. Fixes bug #4433. 2018-12-21 20:53:31 -04:00