Restructure and port surface init and convert to SDL3 #3371
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.
Surface init--
Why change this now? It's not just that it's nicer, one of the old code paths used an SDL_PixelFormat as a writeable thing, and since that no longer exists the code could not be directly ported.
Surface convert--
Surface.convert had a similar thing but even more dubious. The code
memcpy(&format, surf->format, sizeof(format));
does not seem particularly safe! These objects contain internal refcounts, internal references.It used a bunch of the same default masks, so just like surface init I translated them all into pixel format enums. This eliminates some logic around building formats up, although I did still have to build a format struct in the SDL2 code path to convert to a surface with a palette. In SDL3 I had access to a function that just took a pixelformat enum and a palette, like all the SDL3 things, so I used that instead.