Added properties to various SDL objects

The following objects now have properties that can be user modified:
* SDL_AudioStream
* SDL_Gamepad
* SDL_Joystick
* SDL_RWops
* SDL_Renderer
* SDL_Sensor
* SDL_Surface
* SDL_Texture
* SDL_Window
This commit is contained in:
Sam Lantinga
2023-10-11 16:59:51 -07:00
parent 973c8b3273
commit 4368f70ff9
32 changed files with 434 additions and 292 deletions

View File

@@ -265,6 +265,11 @@ void *SDL_GetProperty(SDL_PropertiesID props, const char *name)
return value;
}
int SDL_ClearProperty(SDL_PropertiesID props, const char *name)
{
return SDL_SetProperty(props, name, NULL, NULL, NULL);
}
void SDL_DestroyProperties(SDL_PropertiesID props)
{
if (!props) {

View File

@@ -438,6 +438,18 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
return retval;
}
SDL_PropertiesID SDL_GetAudioStreamProperties(SDL_AudioStream *stream)
{
if (!stream) {
SDL_InvalidParamError("stream");
return 0;
}
if (stream->props == 0) {
stream->props = SDL_CreateProperties();
}
return stream->props;
}
int SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata)
{
if (!stream) {
@@ -1161,6 +1173,8 @@ void SDL_DestroyAudioStream(SDL_AudioStream *stream)
return;
}
SDL_DestroyProperties(stream->props);
OnAudioStreamDestroy(stream);
const SDL_bool simplified = stream->simplified;

View File

@@ -170,6 +170,8 @@ struct SDL_AudioStream
{
SDL_Mutex* lock;
SDL_PropertiesID props;
SDL_AudioStreamCallback get_callback;
void *get_callback_userdata;
SDL_AudioStreamCallback put_callback;

View File

@@ -330,7 +330,6 @@ SDL3_0.0.0 {
SDL_GetTextureBlendMode;
SDL_GetTextureColorMod;
SDL_GetTextureScaleMode;
SDL_GetTextureUserData;
SDL_GetThreadID;
SDL_GetThreadName;
SDL_GetTicks;
@@ -342,7 +341,6 @@ SDL3_0.0.0 {
SDL_GetVersion;
SDL_GetVideoDriver;
SDL_GetWindowBordersSize;
SDL_GetWindowData;
SDL_GetWindowDisplayScale;
SDL_GetWindowFlags;
SDL_GetWindowFromID;
@@ -601,11 +599,9 @@ SDL3_0.0.0 {
SDL_SetTextureBlendMode;
SDL_SetTextureColorMod;
SDL_SetTextureScaleMode;
SDL_SetTextureUserData;
SDL_SetThreadPriority;
SDL_SetWindowAlwaysOnTop;
SDL_SetWindowBordered;
SDL_SetWindowData;
SDL_SetWindowFullscreen;
SDL_SetWindowFullscreenMode;
SDL_SetWindowGrab;
@@ -914,6 +910,16 @@ SDL3_0.0.0 {
SDL_SetProperty;
SDL_GetProperty;
SDL_DestroyProperties;
SDL_GetAudioStreamProperties;
SDL_GetGamepadProperties;
SDL_GetJoystickProperties;
SDL_GetRendererProperties;
SDL_GetTextureProperties;
SDL_GetRWProperties;
SDL_GetSensorProperties;
SDL_GetSurfaceProperties;
SDL_GetWindowProperties;
SDL_ClearProperty;
# extra symbols go here (don't modify this line)
local: *;
};

View File

@@ -354,7 +354,6 @@
#define SDL_GetTextureBlendMode SDL_GetTextureBlendMode_REAL
#define SDL_GetTextureColorMod SDL_GetTextureColorMod_REAL
#define SDL_GetTextureScaleMode SDL_GetTextureScaleMode_REAL
#define SDL_GetTextureUserData SDL_GetTextureUserData_REAL
#define SDL_GetThreadID SDL_GetThreadID_REAL
#define SDL_GetThreadName SDL_GetThreadName_REAL
#define SDL_GetTicks SDL_GetTicks_REAL
@@ -366,7 +365,6 @@
#define SDL_GetVersion SDL_GetVersion_REAL
#define SDL_GetVideoDriver SDL_GetVideoDriver_REAL
#define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL
#define SDL_GetWindowData SDL_GetWindowData_REAL
#define SDL_GetWindowDisplayScale SDL_GetWindowDisplayScale_REAL
#define SDL_GetWindowFlags SDL_GetWindowFlags_REAL
#define SDL_GetWindowFromID SDL_GetWindowFromID_REAL
@@ -624,11 +622,9 @@
#define SDL_SetTextureBlendMode SDL_SetTextureBlendMode_REAL
#define SDL_SetTextureColorMod SDL_SetTextureColorMod_REAL
#define SDL_SetTextureScaleMode SDL_SetTextureScaleMode_REAL
#define SDL_SetTextureUserData SDL_SetTextureUserData_REAL
#define SDL_SetThreadPriority SDL_SetThreadPriority_REAL
#define SDL_SetWindowAlwaysOnTop SDL_SetWindowAlwaysOnTop_REAL
#define SDL_SetWindowBordered SDL_SetWindowBordered_REAL
#define SDL_SetWindowData SDL_SetWindowData_REAL
#define SDL_SetWindowFullscreen SDL_SetWindowFullscreen_REAL
#define SDL_SetWindowFullscreenMode SDL_SetWindowFullscreenMode_REAL
#define SDL_SetWindowGrab SDL_SetWindowGrab_REAL
@@ -939,3 +935,13 @@
#define SDL_SetProperty SDL_SetProperty_REAL
#define SDL_GetProperty SDL_GetProperty_REAL
#define SDL_DestroyProperties SDL_DestroyProperties_REAL
#define SDL_GetAudioStreamProperties SDL_GetAudioStreamProperties_REAL
#define SDL_GetGamepadProperties SDL_GetGamepadProperties_REAL
#define SDL_GetJoystickProperties SDL_GetJoystickProperties_REAL
#define SDL_GetRendererProperties SDL_GetRendererProperties_REAL
#define SDL_GetTextureProperties SDL_GetTextureProperties_REAL
#define SDL_GetRWProperties SDL_GetRWProperties_REAL
#define SDL_GetSensorProperties SDL_GetSensorProperties_REAL
#define SDL_GetSurfaceProperties SDL_GetSurfaceProperties_REAL
#define SDL_GetWindowProperties SDL_GetWindowProperties_REAL
#define SDL_ClearProperty SDL_ClearProperty_REAL

View File

@@ -427,7 +427,6 @@ SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaMod,(SDL_Texture *a, Uint8 *b),(a,b),retu
SDL_DYNAPI_PROC(int,SDL_GetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_GetTextureUserData,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(SDL_threadID,SDL_GetThreadID,(SDL_Thread *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetThreadName,(SDL_Thread *a),(a),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetTicks,(void),(),return)
@@ -439,7 +438,6 @@ SDL_DYNAPI_PROC(const char*,SDL_GetTouchName,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetVersion,(SDL_version *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetVideoDriver,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void*,SDL_GetWindowData,(SDL_Window *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(float,SDL_GetWindowDisplayScale,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(Uint32,SDL_GetWindowFlags,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowFromID,(Uint32 a),(a),return)
@@ -680,11 +678,9 @@ SDL_DYNAPI_PROC(int,SDL_SetTextureAlphaMod,(SDL_Texture *a, Uint8 b),(a,b),retur
SDL_DYNAPI_PROC(int,SDL_SetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetTextureColorMod,(SDL_Texture *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_SetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetTextureUserData,(SDL_Texture *a, void *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetThreadPriority,(SDL_ThreadPriority a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowAlwaysOnTop,(SDL_Window *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowBordered,(SDL_Window *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_SetWindowData,(SDL_Window *a, const char *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreen,(SDL_Window *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreenMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowGrab,(SDL_Window *a, SDL_bool b),(a,b),return)
@@ -985,3 +981,13 @@ SDL_DYNAPI_PROC(void,SDL_UnlockProperties,(SDL_PropertiesID a),(a),)
SDL_DYNAPI_PROC(int,SDL_SetProperty,(SDL_PropertiesID a, const char *b, void *c, void (SDLCALL *d)(void *userdata, void *value), void *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void*,SDL_GetProperty,(SDL_PropertiesID a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_DestroyProperties,(SDL_PropertiesID a),(a),)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetAudioStreamProperties,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGamepadProperties,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetJoystickProperties,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetRendererProperties,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetTextureProperties,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetRWProperties,(SDL_RWops *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSensorProperties,(SDL_Sensor *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSurfaceProperties,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetWindowProperties,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_ClearProperty,(SDL_PropertiesID a, const char *b),(a,b),return)

View File

@@ -619,6 +619,7 @@ SDL_RWops *SDL_CreateRW(void)
void SDL_DestroyRW(SDL_RWops *context)
{
SDL_DestroyProperties(context->props);
SDL_free(context);
}
@@ -698,6 +699,19 @@ void *SDL_LoadFile(const char *file, size_t *datasize)
return SDL_LoadFile_RW(SDL_RWFromFile(file, "rb"), datasize, SDL_TRUE);
}
SDL_PropertiesID SDL_GetRWProperties(SDL_RWops *context)
{
if (!context) {
SDL_InvalidParamError("context");
return 0;
}
if (context->props == 0) {
context->props = SDL_CreateProperties();
}
return context->props;
}
Sint64 SDL_RWsize(SDL_RWops *context)
{
if (!context) {

View File

@@ -2925,6 +2925,21 @@ SDL_JoystickID SDL_GetGamepadInstanceID(SDL_Gamepad *gamepad)
return SDL_GetJoystickInstanceID(joystick);
}
SDL_PropertiesID SDL_GetGamepadProperties(SDL_Gamepad *gamepad)
{
SDL_PropertiesID retval = 0;
SDL_LockJoysticks();
{
CHECK_GAMEPAD_MAGIC(gamepad, 0);
retval = SDL_GetJoystickProperties(gamepad->joystick);
}
SDL_UnlockJoysticks();
return retval;
}
const char *SDL_GetGamepadName(SDL_Gamepad *gamepad)
{
const char *retval = NULL;

View File

@@ -1213,6 +1213,27 @@ SDL_Joystick *SDL_GetJoystickFromPlayerIndex(int player_index)
return joystick;
}
/*
* Get the properties associated with a joystick
*/
SDL_PropertiesID SDL_GetJoystickProperties(SDL_Joystick *joystick)
{
SDL_PropertiesID retval;
SDL_LockJoysticks();
{
CHECK_JOYSTICK_MAGIC(joystick, 0);
if (joystick->props == 0) {
joystick->props = SDL_CreateProperties();
}
retval = joystick->props;
}
SDL_UnlockJoysticks();
return retval;
}
/*
* Get the friendly name of this joystick
*/
@@ -1465,6 +1486,8 @@ void SDL_CloseJoystick(SDL_Joystick *joystick)
return;
}
SDL_DestroyProperties(joystick->props);
if (joystick->rumble_expiration) {
SDL_RumbleJoystick(joystick, 0, 0, 0);
}

View File

@@ -125,6 +125,8 @@ struct SDL_Joystick
struct joystick_hwdata *hwdata _guarded; /* Driver dependent information */
SDL_PropertiesID props _guarded;
int ref_count _guarded; /* Reference count for multiple opens */
struct SDL_Joystick *next _guarded; /* pointer to next joystick we have allocated */

View File

@@ -929,7 +929,7 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, const char *name, Uint32 fl
renderer->hidden = SDL_FALSE;
}
SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
SDL_SetProperty(SDL_GetWindowProperties(window), SDL_WINDOWRENDERDATA, renderer, NULL, NULL);
SDL_SetRenderViewport(renderer, NULL);
@@ -994,7 +994,7 @@ SDL_Renderer *SDL_CreateSoftwareRenderer(SDL_Surface *surface)
SDL_Renderer *SDL_GetRenderer(SDL_Window *window)
{
return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA);
return (SDL_Renderer *)SDL_GetProperty(SDL_GetWindowProperties(window), SDL_WINDOWRENDERDATA);
}
SDL_Window *SDL_GetRenderWindow(SDL_Renderer *renderer)
@@ -1007,10 +1007,20 @@ int SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_RendererInfo *info)
{
CHECK_RENDERER_MAGIC(renderer, -1);
*info = renderer->info;
SDL_copyp(info, &renderer->info);
return 0;
}
SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)
{
CHECK_RENDERER_MAGIC(renderer, 0);
if (renderer->props == 0) {
renderer->props = SDL_CreateProperties();
}
return renderer->props;
}
int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
{
CHECK_RENDERER_MAGIC(renderer, -1);
@@ -1365,6 +1375,16 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
return texture;
}
SDL_PropertiesID SDL_GetTextureProperties(SDL_Texture *texture)
{
CHECK_TEXTURE_MAGIC(texture, 0);
if (texture->props == 0) {
texture->props = SDL_CreateProperties();
}
return texture->props;
}
int SDL_QueryTexture(SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h)
{
CHECK_TEXTURE_MAGIC(texture, -1);
@@ -1497,21 +1517,6 @@ int SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode)
return 0;
}
int SDL_SetTextureUserData(SDL_Texture *texture, void *userdata)
{
CHECK_TEXTURE_MAGIC(texture, -1);
texture->userdata = userdata;
return 0;
}
void *SDL_GetTextureUserData(SDL_Texture *texture)
{
CHECK_TEXTURE_MAGIC(texture, NULL);
return texture->userdata;
}
#if SDL_HAVE_YUV
static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
const void *pixels, int pitch)
@@ -4021,6 +4026,8 @@ static int SDL_DestroyTextureInternal(SDL_Texture *texture, SDL_bool is_destroyi
CHECK_TEXTURE_MAGIC(texture, -1);
SDL_DestroyProperties(texture->props);
renderer = texture->renderer;
if (is_destroying) {
/* Renderer get destroyed, avoid to queue more commands */
@@ -4103,6 +4110,8 @@ void SDL_DestroyRenderer(SDL_Renderer *renderer)
{
CHECK_RENDERER_MAGIC(renderer,);
SDL_DestroyProperties(renderer->props);
SDL_DelEventWatch(SDL_RendererEventWatch, renderer);
SDL_DiscardAllCommands(renderer);
@@ -4118,7 +4127,7 @@ void SDL_DestroyRenderer(SDL_Renderer *renderer)
SDL_free(renderer->vertex_data);
if (renderer->window) {
SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL);
SDL_ClearProperty(SDL_GetWindowProperties(renderer->window), SDL_WINDOWRENDERDATA);
}
/* It's no longer magical... */

View File

@@ -83,8 +83,9 @@ struct SDL_Texture
Uint32 last_command_generation; /* last command queue generation this texture was in. */
SDL_PropertiesID props;
void *driverdata; /**< Driver specific texture representation */
void *userdata;
SDL_Texture *prev;
SDL_Texture *next;
@@ -272,6 +273,8 @@ struct SDL_Renderer
size_t vertex_data_used;
size_t vertex_data_allocation;
SDL_PropertiesID props;
void *driverdata;
};

View File

@@ -393,6 +393,27 @@ SDL_Sensor *SDL_GetSensorFromInstanceID(SDL_SensorID instance_id)
return sensor;
}
/*
* Get the properties associated with a sensor.
*/
SDL_PropertiesID SDL_GetSensorProperties(SDL_Sensor *sensor)
{
SDL_PropertiesID retval;
SDL_LockSensors();
{
CHECK_SENSOR_MAGIC(sensor, 0);
if (sensor->props == 0) {
sensor->props = SDL_CreateProperties();
}
retval = sensor->props;
}
SDL_UnlockSensors();
return retval;
}
/*
* Get the friendly name of this sensor
*/
@@ -500,6 +521,8 @@ void SDL_CloseSensor(SDL_Sensor *sensor)
return;
}
SDL_DestroyProperties(sensor->props);
sensor->driver->Close(sensor);
sensor->hwdata = NULL;

View File

@@ -45,6 +45,8 @@ struct SDL_Sensor
struct sensor_hwdata *hwdata _guarded; /* Driver dependent information */
SDL_PropertiesID props _guarded;
int ref_count _guarded; /* Reference count for multiple opens */
struct SDL_Sensor *next _guarded; /* pointer to next sensor we have allocated */

View File

@@ -211,9 +211,7 @@ SDL_Surface *SDL_CreateSurface(int width, int height, Uint32 format)
* Create an RGB surface from an existing memory buffer using the given given
* enum SDL_PIXELFORMAT_* format
*/
SDL_Surface *SDL_CreateSurfaceFrom(void *pixels,
int width, int height, int pitch,
Uint32 format)
SDL_Surface *SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitch, Uint32 format)
{
SDL_Surface *surface;
@@ -256,10 +254,23 @@ SDL_Surface *SDL_CreateSurfaceFrom(void *pixels,
return surface;
}
SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
{
if (surface == NULL) {
SDL_InvalidParamError("surface");
return 0;
}
if (surface->props == 0) {
surface->props = SDL_CreateProperties();
}
return surface->props;
}
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
{
if (surface == NULL) {
return SDL_InvalidParamError("SDL_SetSurfacePalette(): surface");
return SDL_InvalidParamError("surface");
}
if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
return -1;
@@ -1550,13 +1561,14 @@ void SDL_DestroySurface(SDL_Surface *surface)
if (surface->flags & SDL_DONTFREE) {
return;
}
SDL_InvalidateMap(surface->map);
SDL_InvalidateAllBlitMap(surface);
if (--surface->refcount > 0) {
return;
}
SDL_DestroyProperties(surface->props);
SDL_InvalidateMap(surface->map);
SDL_InvalidateAllBlitMap(surface);
while (surface->locked > 0) {
SDL_UnlockSurface(surface);
}

View File

@@ -58,13 +58,6 @@ struct SDL_ShapeDriver
int (*SetWindowShape)(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
};
typedef struct SDL_WindowUserData
{
char *name;
void *data;
struct SDL_WindowUserData *next;
} SDL_WindowUserData;
/* Define the SDL window structure, corresponding to toplevel windows */
struct SDL_Window
{
@@ -111,7 +104,7 @@ struct SDL_Window
SDL_HitTest hit_test;
void *hit_test_data;
SDL_WindowUserData *data;
SDL_PropertiesID props;
SDL_WindowData *driverdata;

View File

@@ -209,10 +209,25 @@ static Uint32 SDL_DefaultGraphicsBackends(SDL_VideoDevice *_this)
return 0;
}
static void SDL_CleanupWindowTextureData(void *userdata, void *value)
{
SDL_WindowTextureData *data = (SDL_WindowTextureData *)value;
if (data->texture) {
SDL_DestroyTexture(data->texture);
}
if (data->renderer) {
SDL_DestroyRenderer(data->renderer);
}
SDL_free(data->pixels);
SDL_free(data);
}
static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
{
SDL_RendererInfo info;
SDL_WindowTextureData *data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_WindowTextureData *data = (SDL_WindowTextureData *)SDL_GetProperty(props, SDL_WINDOWTEXTUREDATA);
const int transparent = (window->flags & SDL_WINDOW_TRANSPARENT) ? SDL_TRUE : SDL_FALSE;
int i;
int w, h;
@@ -265,7 +280,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
SDL_DestroyRenderer(renderer);
return SDL_OutOfMemory();
}
SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
SDL_SetProperty(props, SDL_WINDOWTEXTUREDATA, data, SDL_CleanupWindowTextureData, NULL);
data->renderer = renderer;
} else {
@@ -335,7 +350,7 @@ static int SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window *window,
SDL_GetWindowSizeInPixels(window, &w, &h);
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
data = SDL_GetProperty(SDL_GetWindowProperties(window), SDL_WINDOWTEXTUREDATA);
if (data == NULL || !data->texture) {
return SDL_SetError("No window texture data");
}
@@ -360,27 +375,14 @@ static int SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window *window,
static void SDL_DestroyWindowTexture(SDL_VideoDevice *unused, SDL_Window *window)
{
SDL_WindowTextureData *data;
data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL);
if (data == NULL) {
return;
}
if (data->texture) {
SDL_DestroyTexture(data->texture);
}
if (data->renderer) {
SDL_DestroyRenderer(data->renderer);
}
SDL_free(data->pixels);
SDL_free(data);
SDL_ClearProperty(SDL_GetWindowProperties(window), SDL_WINDOWTEXTUREDATA);
}
int SDL_SetWindowTextureVSync(SDL_Window *window, int vsync)
{
SDL_WindowTextureData *data;
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
data = SDL_GetProperty(SDL_GetWindowProperties(window), SDL_WINDOWTEXTUREDATA);
if (data == NULL) {
return -1;
}
@@ -2305,6 +2307,16 @@ SDL_Window *SDL_GetWindowParent(SDL_Window *window)
return window->parent;
}
SDL_PropertiesID SDL_GetWindowProperties(SDL_Window *window)
{
CHECK_WINDOW_MAGIC(window, 0);
if (window->props == 0) {
window->props = SDL_CreateProperties();
}
return window->props;
}
Uint32 SDL_GetWindowFlags(SDL_Window *window)
{
CHECK_WINDOW_MAGIC(window, 0);
@@ -2360,72 +2372,6 @@ int SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon)
return _this->SetWindowIcon(_this, window, window->icon);
}
void *SDL_SetWindowData(SDL_Window *window, const char *name, void *userdata)
{
SDL_WindowUserData *prev, *data;
CHECK_WINDOW_MAGIC(window, NULL);
/* Input validation */
if (name == NULL || name[0] == '\0') {
SDL_InvalidParamError("name");
return NULL;
}
/* See if the named data already exists */
prev = NULL;
for (data = window->data; data; prev = data, data = data->next) {
if (data->name && SDL_strcmp(data->name, name) == 0) {
void *last_value = data->data;
if (userdata) {
/* Set the new value */
data->data = userdata;
} else {
/* Delete this value */
if (prev) {
prev->next = data->next;
} else {
window->data = data->next;
}
SDL_free(data->name);
SDL_free(data);
}
return last_value;
}
}
/* Add new data to the window */
if (userdata) {
data = (SDL_WindowUserData *)SDL_malloc(sizeof(*data));
data->name = SDL_strdup(name);
data->data = userdata;
data->next = window->data;
window->data = data;
}
return NULL;
}
void *SDL_GetWindowData(SDL_Window *window, const char *name)
{
SDL_WindowUserData *data;
CHECK_WINDOW_MAGIC(window, NULL);
/* Input validation */
if (name == NULL || name[0] == '\0') {
SDL_InvalidParamError("name");
return NULL;
}
for (data = window->data; data; data = data->next) {
if (data->name && SDL_strcmp(data->name, name) == 0) {
return data->data;
}
}
return NULL;
}
int SDL_SetWindowPosition(SDL_Window *window, int x, int y)
{
SDL_DisplayID original_displayID;
@@ -3657,13 +3603,6 @@ void SDL_DestroyWindow(SDL_Window *window)
/* Free memory associated with the window */
SDL_free(window->title);
SDL_DestroySurface(window->icon);
while (window->data) {
SDL_WindowUserData *data = window->data;
window->data = data->next;
SDL_free(data->name);
SDL_free(data);
}
/* Unlink the window from the list */
if (window->next) {

View File

@@ -27,16 +27,20 @@
#define DUMMY_SURFACE "_SDL_DummySurface"
static void CleanupSurface(void *userdata, void *value)
{
SDL_Surface *surface = (SDL_Surface *)value;
SDL_DestroySurface(surface);
}
int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_XRGB8888;
int w, h;
/* Free the old framebuffer surface */
SDL_DUMMY_DestroyWindowFramebuffer(_this, window);
/* Create a new one */
/* Create a new framebuffer */
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateSurface(w, h, surface_format);
if (surface == NULL) {
@@ -44,7 +48,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
}
/* Save the info and return! */
SDL_SetWindowData(window, DUMMY_SURFACE, surface);
SDL_SetProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE, surface, CleanupSurface, NULL);
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
@@ -56,7 +60,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
static int frame_number;
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_GetWindowData(window, DUMMY_SURFACE);
surface = (SDL_Surface *)SDL_GetProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE);
if (surface == NULL) {
return SDL_SetError("Couldn't find dummy surface for window");
}
@@ -73,10 +77,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
SDL_DestroySurface(surface);
SDL_ClearProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE);
}
#endif /* SDL_VIDEO_DRIVER_DUMMY */

View File

@@ -33,44 +33,37 @@ typedef struct
int width, height;
} Dimensions;
static void FreePreviousWindowFramebuffer(SDL_Window *window);
static SDL_Surface *CreateNewWindowFramebuffer(SDL_Window *window);
static void CopyFramebuffertoN3DS(u32 *dest, const Dimensions dest_dim, const u32 *source, const Dimensions source_dim);
static int GetDestOffset(int x, int y, int dest_width);
static int GetSourceOffset(int x, int y, int source_width);
static void FlushN3DSBuffer(const void *buffer, u32 bufsize, gfxScreen_t screen);
static void CleanupSurface(void *userdata, void *value)
{
SDL_Surface *surface = (SDL_Surface *)value;
SDL_DestroySurface(surface);
}
int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
{
SDL_Surface *framebuffer;
int w, h;
FreePreviousWindowFramebuffer(window);
framebuffer = CreateNewWindowFramebuffer(window);
SDL_GetWindowSizeInPixels(window, &w, &h);
framebuffer = SDL_CreateSurface(w, h, FRAMEBUFFER_FORMAT);
if (framebuffer == NULL) {
return SDL_OutOfMemory();
}
SDL_SetWindowData(window, N3DS_SURFACE, framebuffer);
SDL_SetProperty(SDL_GetWindowProperties(window), N3DS_SURFACE, framebuffer, CleanupSurface, NULL);
*format = FRAMEBUFFER_FORMAT;
*pixels = framebuffer->pixels;
*pitch = framebuffer->pitch;
return 0;
}
static void FreePreviousWindowFramebuffer(SDL_Window *window)
{
SDL_Surface *surface = (SDL_Surface *)SDL_GetWindowData(window, N3DS_SURFACE);
SDL_DestroySurface(surface);
}
static SDL_Surface *CreateNewWindowFramebuffer(SDL_Window *window)
{
int w, h;
SDL_GetWindowSizeInPixels(window, &w, &h);
return SDL_CreateSurface(w, h, FRAMEBUFFER_FORMAT);
}
int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
{
SDL_WindowData *drv_data = window->driverdata;
@@ -79,7 +72,7 @@ int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
u32 *framebuffer;
u32 bufsize;
surface = (SDL_Surface *)SDL_GetWindowData(window, N3DS_SURFACE);
surface = (SDL_Surface *)SDL_GetProperty(SDL_GetWindowProperties(window), N3DS_SURFACE);
if (surface == NULL) {
return SDL_SetError("%s: Unable to get the window surface.", __func__);
}
@@ -127,9 +120,7 @@ static void FlushN3DSBuffer(const void *buffer, u32 bufsize, gfxScreen_t screen)
void SDL_N3DS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_SetWindowData(window, N3DS_SURFACE, NULL);
SDL_DestroySurface(surface);
SDL_ClearProperty(SDL_GetWindowProperties(window), N3DS_SURFACE);
}
#endif /* SDL_VIDEO_DRIVER_N3DS */

View File

@@ -27,16 +27,20 @@
#define OFFSCREEN_SURFACE "_SDL_DummySurface"
static void CleanupSurface(void *userdata, void *value)
{
SDL_Surface *surface = (SDL_Surface *)value;
SDL_DestroySurface(surface);
}
int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_XRGB8888;
int w, h;
/* Free the old framebuffer surface */
SDL_OFFSCREEN_DestroyWindowFramebuffer(_this, window);
/* Create a new one */
/* Create a new framebuffer */
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateSurface(w, h, surface_format);
if (surface == NULL) {
@@ -44,7 +48,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi
}
/* Save the info and return! */
SDL_SetWindowData(window, OFFSCREEN_SURFACE, surface);
SDL_SetProperty(SDL_GetWindowProperties(window), OFFSCREEN_SURFACE, surface, CleanupSurface, NULL);
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
@@ -57,7 +61,7 @@ int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi
static int frame_number;
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_GetWindowData(window, OFFSCREEN_SURFACE);
surface = (SDL_Surface *)SDL_GetProperty(SDL_GetWindowProperties(window), OFFSCREEN_SURFACE);
if (surface == NULL) {
return SDL_SetError("Couldn't find offscreen surface for window");
}
@@ -74,10 +78,7 @@ int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi
void SDL_OFFSCREEN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_Surface *surface;
surface = (SDL_Surface *)SDL_SetWindowData(window, OFFSCREEN_SURFACE, NULL);
SDL_DestroySurface(surface);
SDL_ClearProperty(SDL_GetWindowProperties(window), OFFSCREEN_SURFACE);
}
#endif /* SDL_VIDEO_DRIVER_OFFSCREEN */