forked from Green-Sky/tomato
Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'
This commit is contained in:
32
external/sdl/SDL/test/testnative.c
vendored
32
external/sdl/SDL/test/testnative.c
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -30,6 +30,9 @@ static NativeWindowFactory *factories[] = {
|
||||
#ifdef TEST_NATIVE_WINDOWS
|
||||
&WindowsWindowFactory,
|
||||
#endif
|
||||
#ifdef TEST_NATIVE_WAYLAND
|
||||
&WaylandWindowFactory,
|
||||
#endif
|
||||
#ifdef TEST_NATIVE_X11
|
||||
&X11WindowFactory,
|
||||
#endif
|
||||
@ -47,10 +50,10 @@ static SDLTest_CommonState *state;
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
if (native_window != NULL && factory != NULL) {
|
||||
if (native_window && factory) {
|
||||
factory->DestroyNativeWindow(native_window);
|
||||
}
|
||||
SDL_Quit();
|
||||
SDLTest_CommonDestroyState(state);
|
||||
/* Let 'main()' return normally */
|
||||
if (rc != 0) {
|
||||
@ -100,6 +103,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
const char *driver;
|
||||
SDL_PropertiesID props;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *sprite;
|
||||
@ -109,7 +113,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
if (state == NULL) {
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -135,19 +139,25 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (factory == NULL) {
|
||||
if (!factory) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
|
||||
driver);
|
||||
quit(2);
|
||||
}
|
||||
SDL_Log("Creating native window for %s driver\n", driver);
|
||||
native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
|
||||
if (native_window == NULL) {
|
||||
if (!native_window) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n");
|
||||
quit(3);
|
||||
}
|
||||
window = SDL_CreateWindowFrom(native_window);
|
||||
if (window == NULL) {
|
||||
props = SDL_CreateProperties();
|
||||
SDL_SetProperty(props, "sdl2-compat.external_window", native_window);
|
||||
SDL_SetBooleanProperty(props, SDL_PROPERTY_WINDOW_CREATE_OPENGL_BOOLEAN, SDL_TRUE);
|
||||
SDL_SetNumberProperty(props, SDL_PROPERTY_WINDOW_CREATE_WIDTH_NUMBER, WINDOW_W);
|
||||
SDL_SetNumberProperty(props, SDL_PROPERTY_WINDOW_CREATE_HEIGHT_NUMBER, WINDOW_H);
|
||||
window = SDL_CreateWindowWithProperties(props);
|
||||
SDL_DestroyProperties(props);
|
||||
if (!window) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());
|
||||
quit(4);
|
||||
}
|
||||
@ -155,7 +165,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Create the renderer */
|
||||
renderer = SDL_CreateRenderer(window, NULL, 0);
|
||||
if (renderer == NULL) {
|
||||
if (!renderer) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
quit(5);
|
||||
}
|
||||
@ -165,7 +175,7 @@ int main(int argc, char *argv[])
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
|
||||
if (sprite == NULL) {
|
||||
if (!sprite) {
|
||||
quit(6);
|
||||
}
|
||||
|
||||
@ -174,7 +184,7 @@ int main(int argc, char *argv[])
|
||||
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
|
||||
positions = (SDL_FRect *)SDL_malloc(NUM_SPRITES * sizeof(*positions));
|
||||
velocities = (SDL_FRect *)SDL_malloc(NUM_SPRITES * sizeof(*velocities));
|
||||
if (positions == NULL || velocities == NULL) {
|
||||
if (!positions || !velocities) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user