Commit graph

7024 commits

Author SHA1 Message Date
Sam Lantinga ec1b42557f Fixed memory leak at shutdown (thanks @1bsyl!)
Clean up the textures first, as destroying the current render target will queue viewport and clip rectangle commands
2023-02-05 09:10:21 -08:00
Leonardo Brondani Schenkel 6f06e4bc80 Add Linux mapping for 8BitDo Pro 2 Wired Controller for Xbox
Without these mappings, this controller "kinda" works out of the box:
- `SDL_GameControllerMapping()` works because it will notice "Xbox" in
  the name and use the default XInput mappings
- `SDL_GameControllerMappingForGUID()` will not find any mapping

lsusb:
```
ID 2dc8:2000 8BitDo 8BitDo Pro 2 Wired Controller for Xbox
```

In Linux this controller is supported by two drivers:
- `xpad` (built-in to the kernel), exposes the controller name from the
  USB descriptor and the GUID starts with 03 (0x03 = BUS_USB)
- `xone` (https://github.com/medusalix/xone), exposes a virtual
  controller which is always named "Microsoft X-Box One pad" and the
  GUID starts with 06 (0x06 = BUS_VIRTUAL)

This commit adds the 2 GUIDs from both drivers so mappings will always
be found and the real controller name will always be reported.

(cherry picked from commit 4266cf8504)
2023-02-05 08:45:24 -08:00
Sam Lantinga 1c03ddefc3 Sorted controller list 2023-02-05 08:43:26 -08:00
Antonis Geralis 52cd9fcbb0 Added Elecom 8button gamepad 2023-02-05 08:41:07 -08:00
Frank Praznik b2d8a1a58c wayland: Transform mode values for native portrait displays
Portrait displays may have native, physical resolutions that are taller than wide. Reverse the mode dimensions when dealing with these displays as well as those rotated via software means.
2023-02-04 11:40:55 -05:00
Sam Lantinga 2a83093b36 Use a reasonable upper bound on the number of pixels we'll try to draw when traversing a line
Fixes https://github.com/libsdl-org/SDL/issues/6116
2023-02-03 20:53:30 -08:00
Alynne 4dea13e02f Adds Stadia BT mapping 2023-02-03 15:01:49 -08:00
Sam Lantinga 14a4ce8b59 Fixed SDL_ScaleMode values for consistency 2023-02-03 14:20:51 -08:00
Sam Lantinga e5edce8e75
Fixed permissions on src/render/SDL_render.c (#7232) 2023-02-03 13:14:48 -08:00
Sylvain Becker cb6b8b0132
Simplify flags testing (#7220) 2023-02-03 13:08:42 -08:00
Sam Lantinga dcd17f5473 Renderer logical size is now implemented as a render target
This fixes rounding errors with coordinate scaling and gives more flexibility in the presentation, as well as making it easy to maintain device independent resolution as windows move between different pixel density displays.

By default when a renderer is created, it will match the window size so window coordinates and render coordinates are 1-1.

Mouse and touch events are no longer filtered to change their coordinates, instead you can call SDL_ConvertEventToRenderCoordinates() to explicitly map event coordinates into the rendering viewport.

SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been renamed SDL_RenderCoordinatesFromWindow() and SDL_RenderCoordinatesToWindow() and take floating point coordinates in both directions.

The viewport, clipping state, and scale for render targets are now persistent and will remain set whenever they are active.
2023-02-03 12:57:37 -08:00
Frank Praznik 0bf91e16b7 wayland: Fix non-floating libdecor window sizing 2023-02-03 11:07:31 -05:00
Ozkan Sezer 9f21bed729 dynapi: cast GetProcAddress() result to void* 2023-02-03 17:40:40 +03:00
Frank Praznik 7d439b87b0 video: Don't switch display modes when emulating mode changes
SDL uses window minimization to determine fullscreen window visibility and hide windows before changing the video mode back to the desktop. Wayland, however, does not have the concept of a minimized window and doesn't set the minimized flag (minimization can be requested, but what actually happens to the window is implementation dependent, and if a window is minimized via a desktop shortcut or decoration control, the application is not notified of any state changes). Make the video core mode setting a no-op so that the Wayland backend can handle reporting the display dimensions using its own internal logic.
2023-02-02 18:25:18 -08:00
Frank Praznik 7def1438c3 wayland: Refactor for video core changes
Accommodate the new video core changes.

The new video core changes allow for some window geometry calculation refactoring that simplify the system:

- Removal of helper functions
- Eliminate some discrepancies between the libdecor and xdg-toplevel paths
- No need to short-circuit the video core window size event deduplication check
- Exclusive fullscreen windows will always end up on the correct output, even when fullscreen is initiated from the compositor
- Better handling of cases where the desktop is scaled, but does not expose the viewport protocol
- Return the display bounds for the emulated mode if an exclusive fullscreen window has focus
- Fixed cases where changing display properties during runtime wouldn't update the display mode lists
- General cleanup
2023-02-02 18:25:18 -08:00
Frank Praznik 47cdb532f1 video: Don't rely on memcpy undefined behavior
The C specification states that passing a size of 0 to functions like memcpy is valid, but even if the size is 0 and the function is essentially a no-op, the result when passing any invalid pointers is considered undefined behavior. Don't rely on undefined behavior when copying the display or mode lists.
2023-02-02 15:11:36 -08:00
Frank Praznik 166afebcad video: Update self-referential pointers when reallocating the display list
The display list can contain self-referential pointers if the current mode pointer points to the desktop mode or a fullscreen mode array element, and reallocating the display or fullscreen mode lists without updating the current mode pointer in these cases can leave them pointing to freed memory or garbage data. Manually copy the list items and update the self-referential pointers if necessary.
2023-02-02 09:46:01 -08:00
Sam Lantinga 673bc57649 Don't accept official mappings for controllers that aren't unique
For example, the DragonRise Inc. Generic USB Joystick
See https://github.com/gabomdq/SDL_GameControllerDB/issues/202 for details
2023-02-02 08:39:54 -08:00
Sam Lantinga 917607c335 Fixed sort_controllers.py and resorted game controller database 2023-02-02 08:38:22 -08:00
Sam Lantinga d29e1f3632 Added gamepad mappings for the Xin-Mo Dual Arcade Fightstick 2023-02-01 23:09:53 -08:00
Sasha Szpakowski baca26d727 macOS: fix initial Metal drawable size in certain multi-display setups 2023-02-01 22:38:55 -08:00
Frank Praznik 98ae54ccc0 video: Set the ID of fullscreen modes when adding a display
When adding a display, traverse the list of added fullscreen modes and ensure the display ID is set to its final, valid value, or the modes added before calling SDL_AddVideoDisplay() will have an invalid display ID.
2023-02-01 16:37:57 -08:00
Anonymous Maarten d8f0715385 Revert "Remove unused SDL_GetCPUName"
This reverts commit 4e6ab13d6f.
2023-02-02 00:49:09 +01:00
Anonymous Maarten 69aede6c9e Add missing _ in SDL_EVENT_LOCALECHANGED and SSDL_EVENT_TEXTEDITING_EXT 2023-02-02 00:49:09 +01:00
Anonymous Maarten 08bcee8570 test: don't use wiki urls for documentation comments
Also make consistent use of \ as documentation escape character.
2023-02-02 00:49:09 +01:00
Anonymous Maarten 4e6ab13d6f Remove unused SDL_GetCPUName 2023-02-01 23:17:15 +01:00
Sam Lantinga 177a6f38e0 Only minimize the window for an assert if it's in exclusive fullscreen mode 2023-02-01 12:05:25 -08:00
Sam Lantinga ac75fe9324 Folded SDL_WINDOW_FULLSCREEN_EXCLUSIVE and SDL_WINDOW_FULLSCREEN_DESKTOP into a single SDL_WINDOW_FULLSCREEN flag
The fullscreen video mode used by the window can be used to determine whether it's in exclusive fullscreen or fullscreen desktop mode.
2023-02-01 12:05:25 -08:00
Sam Lantinga 14338ab459 Removed display mode flags
They weren't really adding any value and added complexity to the API
2023-02-01 12:05:25 -08:00
Sam Lantinga 9ff1055489 Workaround for Visual Studio 2019 const warning
Visual Studio 2022, gcc, and clang all agree that "const SDL_DisplayMode **" is a non-const pointer to const data, but Visual Studio 2019 warns about this, so we'll just add a cast to the SDL_free() call for now.

Apparently this was a legitimate bug that has been recently fixed:
https://stackoverflow.com/questions/10403713/why-does-visual-c-warn-on-implicit-cast-from-const-void-to-void-in-c-but
2023-02-01 12:05:25 -08:00
Sam Lantinga 6b137579ea Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
    SDL_DisplayID display = SDL_GetPrimaryDisplay();
    int num_modes = 0;
    SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
    if (modes) {
        for (i = 0; i < num_modes; ++i) {
            SDL_DisplayMode *mode = modes[i];
            SDL_Log("Display %" SDL_PRIu32 " mode %d:  %dx%d@%gHz, %d%% scale\n",
                    display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
        }
        SDL_free(modes);
    }
}

SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.

Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 12:05:25 -08:00
Anonymous Maarten 048df6260c Remove disabled self test main functions in src/SDL_error.c 2023-02-01 20:14:48 +01:00
Anonymous Maarten 4af93990a9 Remove disabled self test main functions 2023-02-01 20:13:34 +01:00
Frank Praznik d58693928d video: Return the display ID when the window is fully enclosed
If the window was fully enclosed, GetDisplayForRect() would return the index of the display ID in the array instead of the display ID itself. Return the display ID itself.
2023-01-31 20:23:52 +01:00
Sam Lantinga c5f570b30b Make sure count is 0 in out of memory conditions
This prevents a crash if the caller assumes that they can always dereference the returned pointer if there is a non-zero count.
2023-01-31 10:04:51 -08:00
Vladyslav Serhiienko 47deebe23f Fixes for Android builds 2023-01-31 08:39:51 -08:00
Sylvain d66f27376e Prevent setting an error "invalid display" when the parameter displayID hasn't been set. 2023-01-30 10:57:51 +01:00
Sam Lantinga b07f8e987b Fixed checking the return values of SDL_AddBasicVideoDisplay() and SDL_AddVideoDisplay()
Also fixed Wayland and Windows usage of SDL_DelVideoDisplay()

https://github.com/libsdl-org/SDL/issues/7192
2023-01-29 21:58:15 -08:00
Sam Lantinga de766fdcd7 Fixed Haiku build 2023-01-29 21:35:45 -08:00
Sam Lantinga 22c69bccdf Displays are now referenced by instance ID instead of index 2023-01-29 19:25:15 -08:00
Anonymous Maarten 758c0dd6d8 Rename mouse BUTTON(DOWN|UP) event to BUTTON_(DOWN|UP) 2023-01-29 19:24:48 -08:00
Frank Praznik e22f5ed7d3 wayland: Check that all required dynamic symbols have been successfully resolved at init time
Ensure that all hard dependencies are resolved when dynamically loading the libraries required for the Wayland backend and fail gracefully if a required module was not initialized successfully.
2023-01-29 11:23:08 -08:00
Sasha Szpakowski 90795291e4 Remove SDL_GL/Metal/Vulkan_GetDrawableSize().
SDL_GetWindowSizeInPixels supersedes those functions.
2023-01-29 11:20:33 -08:00
Sasha Szpakowski 0d0a34f79f iOS: fix the desktop display mode's display scale property. 2023-01-29 11:11:46 -08:00
Frank Praznik a67b441a10 wayland: Send a pixel sized change event when the drawable size changes 2023-01-28 18:37:15 -08:00
Aaron Barany 4667d65f77 Fixes for building on Mac with OpenGL disabled. 2023-01-28 17:24:25 -08:00
Sam Lantinga df7639f100 Call SDL_OnWindow* handlers after the event has been delivered
This guarantees that events which trigger other events will happen in dependency order, instead of being reversed.
2023-01-28 15:56:02 -08:00
Sam Lantinga 432af82a88 Don't deliver window events while it's being destroyed 2023-01-28 15:56:02 -08:00
Sam Lantinga bf4095359c Removed duplicated window size events, and added SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED 2023-01-28 15:56:02 -08:00
Sasha Szpakowski af0ec13fc3 iOS: fix display modes to have accurate pixel sizes and screen scales. 2023-01-28 15:48:08 -08:00