Skip to content
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

Restructure and port surface init and convert to SDL3 #3371

Open
wants to merge 1 commit 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
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.

1 participant