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

Port Image to C code #3331

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildconfig/Setup.Android.SDL2.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ math src_c/math.c $(SDL) $(DEBUG)
pixelcopy src_c/pixelcopy.c $(SDL) $(DEBUG)
newbuffer src_c/newbuffer.c $(SDL) $(DEBUG)
window src_c/window.c $(SDL) $(DEBUG)
_renderer src_c/renderer.c $(SDL) $(DEBUG)
geometry src_c/geometry.c $(SDL) $(DEBUG)
1 change: 1 addition & 0 deletions buildconfig/Setup.Emscripten.SDL2.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ rect src_c/void.c
rwobject src_c/void.c
system src_c/void.c
window src_c/void.c
_renderer src_c/void.c
geometry src_c/void.c

#_sdl2.controller src_c/_sdl2/controller.c $(SDL) $(DEBUG) -Isrc_c
Expand Down
1 change: 1 addition & 0 deletions buildconfig/Setup.SDL2.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ newbuffer src_c/newbuffer.c $(SDL) $(DEBUG)
system src_c/system.c $(SDL) $(DEBUG)
geometry src_c/geometry.c $(SDL) $(DEBUG)
window src_c/window.c $(SDL) $(DEBUG)
_renderer src_c/renderer.c $(SDL) $(DEBUG)
1 change: 1 addition & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ typedef enum {
#define PYGAMEAPI_BASE_NUMSLOTS 30
#define PYGAMEAPI_EVENT_NUMSLOTS 10
#define PYGAMEAPI_WINDOW_NUMSLOTS 1
#define PYGAMEAPI_RENDERER_NUMSLOTS 3
#define PYGAMEAPI_GEOMETRY_NUMSLOTS 2

#endif /* _PYGAME_INTERNAL_H */
46 changes: 46 additions & 0 deletions src_c/include/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,50 @@ typedef struct {
#define import_pygame_window() IMPORT_PYGAME_MODULE(window)
#endif

typedef struct pgTextureObject pgTextureObject;

/*
* Renderer module
*/
typedef struct {
PyObject_HEAD SDL_Renderer *renderer;
pgWindowObject *window;
pgTextureObject *target;
SDL_bool _is_borrowed;
} pgRendererObject;

struct pgTextureObject {
PyObject_HEAD SDL_Texture *texture;
pgRendererObject *renderer;
int width;
int height;
};

typedef struct {
PyObject_HEAD pgTextureObject *texture;
pgRectObject *srcrect;
pgColorObject *color;
float angle;
float alpha;
SDL_bool has_origin;
SDL_FPoint origin;
SDL_bool flip_x;
SDL_bool flip_y;
SDL_BlendMode blend_mode;
} pgImageObject;

#ifndef PYGAMEAPI_RENDERER_INTERNAL
#define pgRenderer_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(_renderer, 0))
#define pgTexture_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(_renderer, 1))
#define pgImage_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(_renderer, 2))
#define pgRenderer_Check(x) \
(PyObject_IsInstance((x), (PyObject *)&pgRenderer_Type))
#define pgTexture_Check(x) \
(PyObject_IsInstance((x), (PyObject *)&pgTexture_Type))
#define pgImage_Check(x) (PyObject_IsInstance((x), (PyObject *)&pgImage_Type))
#define import_pygame_renderer() IMPORT_PYGAME_MODULE(_renderer)
#endif /* PYGAMEAPI_RENDERER_INTERNAL */

#define IMPORT_PYGAME_MODULE _IMPORT_PYGAME_MODULE

/*
Expand All @@ -539,6 +583,7 @@ PYGAMEAPI_DEFINE_SLOTS(pixelarray);
PYGAMEAPI_DEFINE_SLOTS(color);
PYGAMEAPI_DEFINE_SLOTS(math);
PYGAMEAPI_DEFINE_SLOTS(window);
PYGAMEAPI_DEFINE_SLOTS(_renderer);
PYGAMEAPI_DEFINE_SLOTS(geometry);
#else /* ~PYGAME_H */
PYGAMEAPI_EXTERN_SLOTS(base);
Expand All @@ -553,6 +598,7 @@ PYGAMEAPI_EXTERN_SLOTS(pixelarray);
PYGAMEAPI_EXTERN_SLOTS(color);
PYGAMEAPI_EXTERN_SLOTS(math);
PYGAMEAPI_EXTERN_SLOTS(window);
PYGAMEAPI_EXTERN_SLOTS(_renderer);
PYGAMEAPI_EXTERN_SLOTS(geometry);

#endif /* ~PYGAME_H */
Expand Down
12 changes: 12 additions & 0 deletions src_c/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@ window = py.extension_module(
subdir: pg,
)

# TODO: support SDL3
if sdl_api != 3
_renderer = py.extension_module(
'_renderer',
'renderer.c',
c_args: warnings_error,
dependencies: pg_base_deps,
install: true,
subdir: pg,
)
endif

# TODO: support SDL3
if sdl_api != 3
gfxdraw = py.extension_module(
Expand Down
Loading
Loading