Add PG_CreateSurface(From) for SDL2/3 compat #2481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was the end goal of my previous PRs switching out SDL_CreateRGBSurface for SDL_CreateRGBSurfaceWithFormat. This allows us to write our create surface calls in "SDL3 form" on both on SDL2 and SDL3, because of the macro.
You might be wondering about the depth argument always being 0. This is okay. In SDL2's SDL_CreateRGBSurfaceWithFormat, the depth argument is ignored. (https://github.com/libsdl-org/SDL/blob/f9dc49c21c99cd6eb63d80d60b6e706a51234b46/src/video/SDL_surface.c#L72-L78). This makes sense, as the depth info is in the pixelformat.
I like this patch as well because it actually simplifies the calling code (at least makes it shorter), as you can see with the line count reduction in this PR.
There are still a small few SDL_CreateRGBSurface calls in the wilds of the codebase, they'll get handled eventually.