pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
847 stars 140 forks source link

SDL2 video ideas, revisited #1932

Open Mega-JC opened 1 year ago

Mega-JC commented 1 year ago

This GH issue aims to both port and superseed https://github.com/pygame/pygame/issues/2691 , to help bring the _sdl2.video API to a stage that allows for straightforward porting to C, as proposed in #1929 , and a proper adoption in pygame.

The idea here is to have a list of actionable ideas in a checklist, which can either be branched out into separate issues or can be linked to a PR. The list can also be expanded by repository admins if necessary.

None of these ideas are final, and discussion around them is encouraged.

robertpfeiffer commented 1 year ago

We might be able to lock and memory-map a texture to a write-only PyGame Surface: https://wiki.libsdl.org/SDL2/SDL_LockTexture, but please understand the performance implications

yunline commented 1 year ago
  • Remove readonly attributes from Window, Texture and Renderer

There are currently 2 readonly attributes in Window. One is display_index (which i think is useful and doesn't need to be removed).

Another one is id. We don't need to get the SDL window id. We've already had an 'id()' function in python. A SDL window should be represented by only one pygame Window object, so that we can use id(window) instead of window.id. However, currently, one SDL window can be represented by multiple pygame Window objects:

import pygame
from pygame._sdl2 import video

pygame.display.set_mode((64,64))

w2=video.Window.from_display_module()
w1=video.Window.from_display_module()

print(id(w1))
print(id(w2))

print(w1.id)
print(w2.id)

# pygame-ce 2.1.4.dev1 (SDL 2.0.22, Python 3.10.6)
# 2765039017232
# 2765576044496
# 1
# 1
Starbuck5 commented 1 year ago

@yunline The functionality doesn't need to be removed, I was just thinking of removing the attributes and turning them into explicit getters instead.

yunline commented 1 year ago

The functionality doesn't need to be removed, I was just thinking of removing the attributes and turning them into explicit getters instead.

@Starbuck5 Shall other attributes turned into getters and setters? Like: image

robertpfeiffer commented 1 year ago

Another one is id. We don't need to get the SDL window id. We've already had an 'id()' function in python. A SDL window should be represented by only one pygame Window object, so that we can use id(window) instead of window.id. However, currently, one SDL window can be represented by multiple pygame Window objects.

Python object ID is different from window ID, and yes, getting a window from the display module is not idempotent for dumb implementation and memory management reasons, but those are different types of ID to begin with! I don't see a way to solve the memory management problems completely unless we replace display.c with Cython or similar in the long term.