2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2015-02-18 12:07:48 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup pythonintern
|
2015-02-18 12:07:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <Python.h>
|
2015-02-18 12:07:48 +01:00
|
|
|
|
2025-06-20 04:19:35 +00:00
|
|
|
#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
|
|
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_sdl.hh"
|
2015-02-18 12:07:48 +01:00
|
|
|
|
2024-09-24 15:25:36 +02:00
|
|
|
#include "../generic/py_capi_utils.hh"
|
2017-08-22 18:02:58 +10:00
|
|
|
|
2015-02-18 12:07:48 +01:00
|
|
|
#ifdef WITH_SDL
|
2016-02-23 09:44:54 +01:00
|
|
|
/* SDL force defines __SSE__ and __SSE2__ flags, which generates warnings
|
|
|
|
|
* because we pass those defines via command line as well. For until there's
|
2024-09-03 12:59:37 +10:00
|
|
|
* proper `ifndef` added to SDL headers we ignore the redefinition warning.
|
2016-02-23 09:44:54 +01:00
|
|
|
*/
|
|
|
|
|
# ifdef _MSC_VER
|
|
|
|
|
# pragma warning(push)
|
|
|
|
|
# pragma warning(disable : 4005)
|
|
|
|
|
# endif
|
2015-02-18 12:07:48 +01:00
|
|
|
# include "SDL.h"
|
2016-02-23 09:44:54 +01:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
|
# pragma warning(pop)
|
|
|
|
|
# endif
|
2015-02-18 12:07:48 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static PyTypeObject BlenderAppSDLType;
|
|
|
|
|
|
|
|
|
|
static PyStructSequence_Field app_sdl_info_fields[] = {
|
2019-12-20 10:42:57 +11:00
|
|
|
{"supported", ("Boolean, True when Blender is built with SDL support")},
|
|
|
|
|
{"version", ("The SDL version as a tuple of 3 numbers")},
|
|
|
|
|
{"version_string", ("The SDL version formatted as a string")},
|
2023-07-21 02:18:59 +02:00
|
|
|
{nullptr},
|
2015-02-18 12:07:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyStructSequence_Desc app_sdl_info_desc = {
|
2024-08-19 11:37:20 +10:00
|
|
|
/*name*/ "bpy.app.sdl",
|
|
|
|
|
/*doc*/ "This module contains information about SDL blender is linked against",
|
|
|
|
|
/*fields*/ app_sdl_info_fields,
|
|
|
|
|
/*n_in_sequence*/ ARRAY_SIZE(app_sdl_info_fields) - 1,
|
2015-02-18 12:07:48 +01:00
|
|
|
};
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
static PyObject *make_sdl_info()
|
2015-02-18 12:07:48 +01:00
|
|
|
{
|
|
|
|
|
PyObject *sdl_info;
|
|
|
|
|
int pos = 0;
|
|
|
|
|
#ifdef WITH_SDL
|
|
|
|
|
SDL_version version = {0, 0, 0};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
sdl_info = PyStructSequence_New(&BlenderAppSDLType);
|
2023-07-21 02:18:59 +02:00
|
|
|
if (sdl_info == nullptr) {
|
|
|
|
|
return nullptr;
|
2015-02-18 12:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SetStrItem(str) PyStructSequence_SET_ITEM(sdl_info, pos++, PyUnicode_FromString(str))
|
|
|
|
|
|
|
|
|
|
#define SetObjItem(obj) PyStructSequence_SET_ITEM(sdl_info, pos++, obj)
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_SDL
|
|
|
|
|
SetObjItem(PyBool_FromLong(1));
|
2024-09-13 22:44:35 +10:00
|
|
|
# if SDL_MAJOR_VERSION >= 2
|
2015-02-18 12:07:48 +01:00
|
|
|
SDL_GetVersion(&version);
|
2024-09-13 22:44:35 +10:00
|
|
|
# else
|
2015-02-18 12:07:48 +01:00
|
|
|
SDL_VERSION(&version);
|
|
|
|
|
# endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
SetObjItem(PyC_Tuple_Pack_I32({version.major, version.minor, version.patch}));
|
2024-09-13 22:44:35 +10:00
|
|
|
SetObjItem(PyUnicode_FromFormat("%d.%d.%d", version.major, version.minor, version.patch));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-18 12:07:48 +01:00
|
|
|
#else /* WITH_SDL=OFF */
|
|
|
|
|
SetObjItem(PyBool_FromLong(0));
|
2023-07-21 10:53:30 +10:00
|
|
|
SetObjItem(PyC_Tuple_Pack_I32({0, 0, 0}));
|
2015-02-18 12:07:48 +01:00
|
|
|
SetStrItem("Unknown");
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-03-04 15:46:07 +11:00
|
|
|
if (UNLIKELY(PyErr_Occurred())) {
|
|
|
|
|
Py_DECREF(sdl_info);
|
2023-07-21 02:18:59 +02:00
|
|
|
return nullptr;
|
2015-02-18 12:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef SetStrItem
|
|
|
|
|
#undef SetObjItem
|
|
|
|
|
|
|
|
|
|
return sdl_info;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
PyObject *BPY_app_sdl_struct()
|
2015-02-18 12:07:48 +01:00
|
|
|
{
|
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
|
|
PyStructSequence_InitType(&BlenderAppSDLType, &app_sdl_info_desc);
|
|
|
|
|
|
|
|
|
|
ret = make_sdl_info();
|
|
|
|
|
|
|
|
|
|
/* prevent user from creating new instances */
|
2023-07-21 02:18:59 +02:00
|
|
|
BlenderAppSDLType.tp_init = nullptr;
|
|
|
|
|
BlenderAppSDLType.tp_new = nullptr;
|
2023-05-24 11:21:18 +10:00
|
|
|
/* Without this we can't do `set(sys.modules)` #29635. */
|
2025-06-20 04:19:35 +00:00
|
|
|
BlenderAppSDLType.tp_hash = (hashfunc)Py_HashPointer;
|
2015-02-18 12:07:48 +01:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|