Skip to content

Restructure and port surface init and convert to SDL3 #3371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Starbuck5
Copy link
Member

@Starbuck5 Starbuck5 commented Mar 3, 2025

Surface init--

# Before, each codepath would output bpp and masks, which was then used to construct a format enum.
depth + masks -> bpp and masks
depth -> bpp + default masks
surface -> format -> bpp and masks
default window surface -> format -> bpp and masks

# Now, each codepath outputs a format enum itself.
depth + masks -> format enum
depth -> default format enum
surface -> format enum
default window surface -> format enum

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.

@Starbuck5 Starbuck5 added Surface pygame.Surface sdl3 labels Mar 3, 2025
@Starbuck5 Starbuck5 requested a review from a team as a code owner March 3, 2025 08:06
@Starbuck5 Starbuck5 marked this pull request as draft March 3, 2025 08:06
@Starbuck5 Starbuck5 marked this pull request as ready for review March 3, 2025 08:37
Copy link
Member

@damusss damusss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, the code looks much cleaner, the changes makes sense, and the sdl3 differences are clear. I guess that shocking code should be dealt with sooner or later. Thanks, LGTM! 👍

@Starbuck5 Starbuck5 force-pushed the surface-init-convert-sdl3 branch from 7b00794 to 710466e Compare May 15, 2025 06:35
@Starbuck5 Starbuck5 force-pushed the surface-init-convert-sdl3 branch from df5b318 to 2e02ed4 Compare May 15, 2025 06:36
@Starbuck5
Copy link
Member Author

@ankith26 @damusss As discussed on discord I've now made this PR less risky and easier to review by putting the SDL3 codepath fully separate from the SDL2 codepath, rather than modifying the SDL2 codepath to work in SDL3. I'd like to get this in, it significantly reduces the amount of compilations errors in surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdl3 Surface pygame.Surface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants