Commit Graph

917 Commits

Author SHA1 Message Date
Cameron Gutman
9b2202828a Fix use-after-free when pumping the event loop after SDL_DestroyWindow()
Closing the window is asynchronous, but we free the window data immediately,
so we can get an updateLayer callback before the window is really destroyed which
will cause us to access the freed memory.

Clearing the content view will cause it to be immediately released, so no further
updateLayer callbacks will occur.
2019-04-28 17:37:49 -07:00
Sam Lantinga
a4e33b9cc4 Added support for Bluetooth keyboards on iOS
In this case the keyboard is shown and immediately hidden, but we still want to accept text input
2019-05-20 14:31:03 -07:00
Sam Lantinga
582a3c994d Fixed mouse focus for touch events on iOS 2019-05-20 14:08:35 -07:00
Ryan C. Gordon
4bd808346a vulkan: Swapped out a free() that should have been an SDL_free().
Fixes (for real this time!) the Visual Studio builds.
2019-05-20 00:41:18 -04:00
Ryan C. Gordon
ebbb295e85 vulkan: Patched to compile on Visual Studio. 2019-05-19 23:29:50 -04:00
Ryan C. Gordon
d778b26dd1 Patched to compile in C89 mode. 2019-05-19 20:25:02 -04:00
Sam Lantinga
ee0a482a87 Fixed bug 4401 - SDL_GetWindowPosition() wrong after SDL_SetWindowPosition() until window is moved on macOS
Removed incorrect call to SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
If the position of the window isn't adjusted in the SetWindowPosition() call, then sending the window event would have no effect because x and y equals the window x and y. If the position of the window is adjusted in the SetWindowPosition() call, then we don't want to clobber it with values that the user passed in.
2019-05-19 11:52:25 -07:00
Sam Lantinga
8dea23c705 Fixed bug 3911 - SYSWM generic X11 events missing event data
Andrei Drexler

For X11 GenericEvents, the associated data is only available between a call to XGetEventData and the matching XFreeEventData, i.e. in X11_HandleGenericEvent. Trying to call XGetEventData a second time on the same event will fail, so an application that wants to inspect XInput2 events (e.g. for stylus pressure) has no way of retrieving its data from queued SYSWM events.

The attached patch (based on SDL-2.0.7-11629) sends SYSWM messages from X11_HandleGenericEvent while the data is still available, allowing client code to register an event filter/watcher and process the event inside the callback.
2019-05-19 10:44:14 -07:00
Wladimir J. van der Laan
29f3445316 video: Add Vulkan support for vivante fb
Vivante drivers use the VK_KHR_display extension for rendering directly
to the frame buffer. This patch adds support to the video driver for
Vulkan rendering using that method.

- Add an utility function SDL_Vulkan_Display_CreateSurface that creates
a surface using this extension. The display to use (if there are
multiple) can be overridden using the environment variable
"SDL_VULKAN_DISPLAY".

- Use this function in a new compilation unit SDL_vivantevideo.c,
which implements the SDL_VIDEO_VULKAN methods of the driver structure.
2019-05-19 10:36:44 -07:00
Sam Lantinga
59da5b7202 [SDL] ios Touch Fix. 2019-05-14 07:55:42 -07:00
Ryan C. Gordon
ba0fc92ded Patched to compile. 2019-05-11 12:41:21 -04:00
Charlie Birks
6eb0521131 Emscripten: Use EMSCRIPTEN_EVENT_TARGET_* 2019-05-09 12:09:45 +01:00
Charlie Birks
4e5b5cba12 Emscripten: Switch from canvas[XY] to target[XY]
Allows mouse/touch events to work on non-default canvases
2019-05-09 12:09:40 +01:00
Charlie Birks
60c48ed787 Emscripten: Store canvas id in WindowData
Also replace all hardcoded uses of "#canvas" or NULL
2019-05-09 12:09:34 +01:00
Sam Lantinga
f0a4fea89f Fixed bug 4608 - Android: not getting SDL_WINDOWEVENT_FOCUS_GAINED on start of our app
Dan Ginsburg

I've seen this on several devices including Moto Z running Android 7 and a Snapdragon 845 running Android 9.

What happens is as follows:

SDLActivity.onWindowFocusChanged(true) happens pretty early on, but it's before we've done SDL_CreateWindow and so Android_Window is 0x0 thus this message does not get sent:

JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeFocusChanged)(
                                    JNIEnv *env, jclass cls, jboolean hasFocus)
{
    SDL_LockMutex(Android_ActivityMutex);

    if (Android_Window) {
        __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeFocusChanged()");
        SDL_SendWindowEvent(Android_Window, (hasFocus ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST), 0, 0);
    }

    SDL_UnlockMutex(Android_ActivityMutex);
}

When the window does get created, in Android_CreateWindow it does this:

 window->flags &= ~SDL_WINDOW_RESIZABLE;     /* window is NEVER resizeable */
    window->flags &= ~SDL_WINDOW_HIDDEN;
    window->flags |= SDL_WINDOW_SHOWN;          /* only one window on Android */
    window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */

    /* One window, it always has focus */
    SDL_SetMouseFocus(window);
    SDL_SetKeyboardFocus(window);

The SDL_SetKeyboardFocus does send an SDL_WINDOWEVENT_FOCUS_GAINED message, but it gets eaten in SDL_SendWindowEvent because we've forced SDL_WINDOW_INPUT_FOCUS beforehand:

 case SDL_WINDOWEVENT_FOCUS_GAINED:
        if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
            return 0;
        }
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
        SDL_OnWindowFocusGained(window);
        break;

I can fix the problem if I comment out this line from Android_CreateWindow:

    window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */

I would propose that as a fix unless there is a reason not to.
2019-04-25 14:17:07 -07:00
Sylvain Becker
2c92c8e85a Android: add static variable initialization in non blocking event loop 2019-04-23 14:24:58 +02:00
Sam Lantinga
cb18117c92 Added a helper function to tell whether or not a window can be minimized 2019-04-22 16:34:42 -07:00
Sam Lantinga
f1b57f3785 Only leave fullscreen mode if we're actually going to minimize 2019-04-22 16:25:49 -07:00
Alex Szpakowski
90b08881ab iOS: Remove code trying to support compilation on the iOS 7 SDK, the deployment target has been set to iOS 8 for years and there's other unconditionally compiled code that depends on newer SDKs so that code is useless. 2019-04-17 20:41:05 -03:00
Alex Szpakowski
9d7b26155a macOS: Fix compilation when using the 10.9 SDK or older. 2019-04-17 20:14:40 -03:00
Sylvain Becker
bd344c2287 Android: when event loop is not blocking in pause, backup EGL context (Bug 4578)
Backup the EGL context when SDL_APP_DIDENTERBACKGROUND has been removed from the
event queue.
2019-04-12 23:15:26 +02:00
Alex Szpakowski
00c824a8b0 Fix disabling OpenGL vsync on macOS 10.14.4+ (bug #4575). 2019-04-10 22:30:58 -03:00
Sam Lantinga
b6f33a6870 https://bugzilla.libsdl.org/show_bug.cgi?id=4577
SDL_GetWindowDisplayMode was returning an incorrect result on iPhone Plus devices (tested on iOS 12.1/12.2).  The problem was that the value returned by UIScreenMode was assumed to be the physical pixels on the display, rather than the scaled retina pixels.  The fix is to use the scale returned by UIScreen.scale rather than the nativeScale.
2019-04-05 07:51:11 -07:00
Sylvain Becker
05333a6e9f Android: add hint SDL_HINT_ANDROID_BLOCK_ON_PAUSE
to set whether the event loop will block itself when the app is paused.
2019-04-05 09:16:30 +02:00
Sylvain Becker
bfdd0b228a Android: remove SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH
java layer runs as if separate mouse and touch was 1,
Use SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS
for generating synthetic touch/mouse events
2019-04-04 17:01:02 +02:00
Sylvain Becker
236b86067f Bug 4576: one more warning 2019-04-02 18:07:27 +02:00
Sylvain Becker
b45abbb2a7 Bug 4576: fix warning and compile 2019-04-02 17:57:27 +02:00
Sylvain Becker
9b3c2258aa Bug 4576: remove touch/mouse duplication for Android 2019-04-02 17:23:55 +02:00
Sylvain Becker
9d28156f12 Bug 4576: remove touch/mouse duplication for IOS 2019-04-02 17:18:47 +02:00
Sylvain Becker
42de5f97cc Bug 4576: remove touch/mouse duplication for WinRT 2019-04-02 17:13:22 +02:00
Sylvain Becker
b086edc915 Bug 4576: remove touch/mouse duplication for Emscripten 2019-04-02 17:10:29 +02:00
Sylvain Becker
b8e5c561d8 Bug 4576: remove touch/mouse duplication for Wayland 2019-04-02 17:07:54 +02:00
Sylvain Becker
1a4c3b57b7 Bug 4576: remove touch/mouse duplication for Windows 2019-04-02 16:58:11 +02:00
Sam Lantinga
b2e76d860f Fixed Windows RT build 2019-03-19 16:52:09 -07:00
Sam Lantinga
de82759c84 Added support for building SDL as a dynamic library on iOS 2019-03-19 07:53:33 -07:00
Sebastian Krzyszkowiak
6311c7cf95 emscripten: force resize event when pixel ratio changes
Without this, applications can't react to changed canvas size on window zoom.
2019-03-16 19:08:59 -07:00
Sam Lantinga
8bc59f87ec Fixed CVE-2019-7635 and bug 4498 - Heap-Buffer Overflow in Blit1to4 pertaining to SDL_blit_1.c
Petr Pisar

The root cause is that the POC BMP file declares 3 colors used and 4 bpp palette, but pixel at line 28 and column 1 (counted from 0) has color number 3. Then when the image loaded into a surface is passed to SDL_DisplayFormat(), in order to convert it to a video format, a used bliting function looks up a color number 3 in a 3-element long color bliting map. (The map obviously has the same number entries as the surface format has colors.)

Proper fix should refuse broken BMP images that have a pixel with a color index higher than declared number of "used" colors. Possibly more advanced fix could try to relocate the out-of-range color index into a vacant index (if such exists).
2019-03-16 18:34:33 -07:00
Sylvain Becker
cbe80d4708 KMSDRM: valid file descriptors could positive or 0. -1 is invalid. (Bug 4530) 2019-03-13 14:54:51 +01:00
Sam Lantinga
82758efc46 [iOS DAC] Fix touch events getting from SDL2 to source2. 2019-03-12 14:45:04 -07:00
Sam Lantinga
d05eec7207 Fixed initial display orientation at Android app start 2019-03-12 14:44:25 -07:00
Sylvain Becker
cddb285cdb Fixed bug 4513 - Wayland, fix crash when remove event is sent (from Sebastian Krzyszkowiak) 2019-03-12 20:04:08 +01:00
Sylvain Becker
7b27594274 KMSDRM: missing return value in VideoInit() (Bug 4530) 2019-03-11 15:27:42 +01:00
Sylvain Becker
3b49ee5261 KMSDRM: change calls free() to SDL_free() (Bug 4529) 2019-03-11 15:22:40 +01:00
Sylvain Becker
2fd4aee149 Un-activate some routine on mips because they are slowers (Bug 4503) 2019-02-23 09:36:56 +01:00
Sylvain Becker
47fb781b94 BlitNtoN BlitNtoNKey: remove non-aligned word read/store (bpp 3<->4) (Bug 4503)
Mips and (old) ARM doesn't allow word read/write when adress isn't 4bytes
aligned. So just remove that.
2019-02-22 09:30:45 +01:00
Ryan C. Gordon
6fbe9e23fa raspberry: expose second display.
This lets apps see and choose between both an HDMI and DSI-connected display,
such as a television and the Pi Foundation's official touchscreen. It only
exposes the second display if the hardware reports that it is connected.
2019-02-19 23:46:54 -05:00
Sylvain Becker
90a075d75f Fix windows build 2019-02-18 22:48:14 +01:00
Sylvain Becker
e9a7b6973a Fix bug 4053: Blit issues on Big Endian CPU 2019-02-18 22:06:53 +01:00
Sam Lantinga
ea4c4cfc28 Fixed bug 4500 - Heap-Buffer Overflow in Map1toN pertaining to SDL_pixels.c
Petr Pisar

The reproducer has these data in BITMAPINFOHEADER:

biSize = 40
biBitCount = 8
biClrUsed = 131075

SDL_LoadBMP_RW() function passes biBitCount as a color depth to SDL_CreateRGBSurface(), thus 256-color pallete is allocated. But then biClrUsed colors are read from a file and stored into the palette. SDL_LoadBMP_RW should report an error if biClrUsed is greater than 2^biBitCount.
2019-02-18 07:50:33 -08:00
Sylvain Becker
afd1b3dae4 Fix invalid memory access and optimise Blit_3or4_to_3or4__*
Fix invalid write at last pixel of the surface:
  when surface has no padding (pitch == w * bpp) and bpp is 3
  with Blit, no colorkey, and NO_ALPHA same or inverse rgb triplet

Optimise by using int32 access:

BGR24 -> ARGB8888 :  faster x1.897875   (362405 -> 190953)
RGB24 -> ABGR8888 :  faster x1.660416   (363304 -> 218803)

ABGR8888 -> RGB24 :  faster x1.686319   (334962 -> 198635)
ARGB8888 -> BGR24 :  faster x1.691868   (324524 -> 191814)
BGR24 -> RGB888 :  faster x1.678459   (326811 -> 194709)
BGR888 -> RGB24 :  faster x1.731772   (327724 -> 189242)
RGB24 -> BGR888 :  faster x1.690989   (328916 -> 194511)
RGB888 -> BGR24 :  faster x1.698333   (326175 -> 192056)
2019-02-17 16:20:23 +01:00