mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-19 05:50:48 +00:00
Simplified SDL_SetProperty() and added SDL_SetPropertyWithCleanup()
Most of the time people won't need to set a cleanup callback, so we can simplify the more commonly used API.
This commit is contained in:
@@ -183,7 +183,12 @@ void SDL_UnlockProperties(SDL_PropertiesID props)
|
||||
SDL_UnlockMutex(properties->lock);
|
||||
}
|
||||
|
||||
int SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata)
|
||||
int SDL_SetProperty(SDL_PropertiesID props, const char *name, void *value)
|
||||
{
|
||||
return SDL_SetPropertyWithCleanup(props, name, value, NULL, NULL);
|
||||
}
|
||||
|
||||
int SDL_SetPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, void (SDLCALL *cleanup)(void *userdata, void *value), void *userdata)
|
||||
{
|
||||
SDL_Properties *properties = NULL;
|
||||
SDL_Property *property = NULL;
|
||||
@@ -274,7 +279,7 @@ void *SDL_GetProperty(SDL_PropertiesID props, const char *name)
|
||||
|
||||
int SDL_ClearProperty(SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
return SDL_SetProperty(props, name, NULL, NULL, NULL);
|
||||
return SDL_SetProperty(props, name, NULL);
|
||||
}
|
||||
|
||||
void SDL_DestroyProperties(SDL_PropertiesID props)
|
||||
|
||||
@@ -921,6 +921,7 @@ SDL3_0.0.0 {
|
||||
SDL_RWvprintf;
|
||||
SDL_AllocateEventMemory;
|
||||
SDL_GetDisplayProperties;
|
||||
SDL_SetPropertyWithCleanup;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -946,3 +946,4 @@
|
||||
#define SDL_RWvprintf SDL_RWvprintf_REAL
|
||||
#define SDL_AllocateEventMemory SDL_AllocateEventMemory_REAL
|
||||
#define SDL_GetDisplayProperties SDL_GetDisplayProperties_REAL
|
||||
#define SDL_SetPropertyWithCleanup SDL_SetPropertyWithCleanup_REAL
|
||||
|
||||
@@ -962,7 +962,7 @@ SDL_DYNAPI_PROC(IDXGIResource*,SDL_GetTextureDXGIResource,(SDL_Texture *a),(a),r
|
||||
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_CreateProperties,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_LockProperties,(SDL_PropertiesID a),(a),return)
|
||||
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(int,SDL_SetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),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)
|
||||
@@ -979,3 +979,4 @@ SDL_DYNAPI_PROC(int,SDL_EnterAppMainCallbacks,(int a, char *b[], SDL_AppInit_fun
|
||||
SDL_DYNAPI_PROC(size_t,SDL_RWvprintf,(SDL_RWops *a, const char *b, va_list c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(void*,SDL_AllocateEventMemory,(size_t a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetDisplayProperties,(SDL_DisplayID a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SetPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, void (SDLCALL *d)(void *userdata, void *value), void *e),(a,b,c,d,e),return)
|
||||
|
||||
@@ -929,7 +929,7 @@ SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, const char *name, Uint32 fl
|
||||
renderer->hidden = SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_SetProperty(SDL_GetWindowProperties(window), SDL_WINDOWRENDERDATA, renderer, NULL, NULL);
|
||||
SDL_SetProperty(SDL_GetWindowProperties(window), SDL_WINDOWRENDERDATA, renderer);
|
||||
|
||||
SDL_SetRenderViewport(renderer, NULL);
|
||||
|
||||
|
||||
@@ -1714,7 +1714,7 @@ SDL_Renderer *D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
|
||||
data->drawstate.blend = SDL_BLENDMODE_INVALID;
|
||||
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d9.device", data->device, NULL, NULL);
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d9.device", data->device);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@@ -668,7 +668,7 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer)
|
||||
ID3D11DeviceContext_VSSetShader(data->d3dContext, data->vertexShader, NULL, 0);
|
||||
ID3D11DeviceContext_VSSetConstantBuffers(data->d3dContext, 0, 1, &data->vertexShaderConstants);
|
||||
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d11.device", data->d3dDevice, NULL, NULL);
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d11.device", data->d3dDevice);
|
||||
|
||||
done:
|
||||
SAFE_RELEASE(d3dDevice);
|
||||
|
||||
@@ -1070,7 +1070,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
|
||||
}
|
||||
data->srvPoolHead = &data->srvPoolNodes[0];
|
||||
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d12.device", data->d3dDevice, NULL, NULL);
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), "SDL.renderer.d3d12.device", data->d3dDevice);
|
||||
|
||||
done:
|
||||
SAFE_RELEASE(d3dDevice);
|
||||
|
||||
@@ -280,7 +280,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
|
||||
SDL_DestroyRenderer(renderer);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_SetProperty(props, SDL_WINDOWTEXTUREDATA, data, SDL_CleanupWindowTextureData, NULL);
|
||||
SDL_SetPropertyWithCleanup(props, SDL_WINDOWTEXTUREDATA, data, SDL_CleanupWindowTextureData, NULL);
|
||||
|
||||
data->renderer = renderer;
|
||||
} else {
|
||||
|
||||
@@ -48,7 +48,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
|
||||
}
|
||||
|
||||
/* Save the info and return! */
|
||||
SDL_SetProperty(SDL_GetWindowProperties(window), DUMMY_SURFACE, surface, CleanupSurface, NULL);
|
||||
SDL_SetPropertyWithCleanup(SDL_GetWindowProperties(window), DUMMY_SURFACE, surface, CleanupSurface, NULL);
|
||||
*format = surface_format;
|
||||
*pixels = surface->pixels;
|
||||
*pitch = surface->pitch;
|
||||
|
||||
@@ -57,7 +57,7 @@ int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_SetProperty(SDL_GetWindowProperties(window), N3DS_SURFACE, framebuffer, CleanupSurface, NULL);
|
||||
SDL_SetPropertyWithCleanup(SDL_GetWindowProperties(window), N3DS_SURFACE, framebuffer, CleanupSurface, NULL);
|
||||
*format = FRAMEBUFFER_FORMAT;
|
||||
*pixels = framebuffer->pixels;
|
||||
*pitch = framebuffer->pitch;
|
||||
|
||||
@@ -48,7 +48,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi
|
||||
}
|
||||
|
||||
/* Save the info and return! */
|
||||
SDL_SetProperty(SDL_GetWindowProperties(window), OFFSCREEN_SURFACE, surface, CleanupSurface, NULL);
|
||||
SDL_SetPropertyWithCleanup(SDL_GetWindowProperties(window), OFFSCREEN_SURFACE, surface, CleanupSurface, NULL);
|
||||
*format = surface_format;
|
||||
*pixels = surface->pixels;
|
||||
*pitch = surface->pitch;
|
||||
|
||||
Reference in New Issue
Block a user