Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594

(cherry picked from commit 5750bcb174)
This commit is contained in:
Sam Lantinga
2022-11-30 12:51:59 -08:00
parent 5c4bc807f7
commit b8d85c6939
764 changed files with 50598 additions and 54407 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -19,7 +19,6 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_emscriptenevents_h_
#define SDL_emscriptenevents_h_
@@ -37,4 +36,3 @@ Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userDat
#endif /* SDL_emscriptenevents_h_ */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -28,8 +28,7 @@
#include <emscripten/threading.h>
int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
const Uint32 surface_format = SDL_PIXELFORMAT_BGR888;
@@ -38,7 +37,7 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * form
Uint32 Rmask, Gmask, Bmask, Amask;
/* Free the old framebuffer surface */
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
surface = data->surface;
SDL_FreeSurface(surface);
@@ -59,11 +58,11 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * form
return 0;
}
int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
{
SDL_Surface *surface;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
surface = data->surface;
if (surface == NULL) {
return SDL_SetError("Couldn't find framebuffer surface for window");
@@ -71,6 +70,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec
/* Send the data to the display */
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM({
var w = $0;
var h = $1;
@@ -166,9 +166,9 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec
return 0;
}
void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
SDL_FreeSurface(data->surface);
data->surface = NULL;

View File

@@ -23,9 +23,9 @@
#ifndef SDL_emscriptenframebuffer_h_
#define SDL_emscriptenframebuffer_h_
extern int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
extern int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
extern void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
extern int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch);
extern int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window *window);
#endif /* SDL_emscriptenframebuffer_h_ */

View File

@@ -31,15 +31,14 @@
#include "../../events/SDL_mouse_c.h"
static SDL_Cursor*
Emscripten_CreateCursorFromString(const char* cursor_str, SDL_bool is_custom)
static SDL_Cursor *Emscripten_CreateCursorFromString(const char *cursor_str, SDL_bool is_custom)
{
SDL_Cursor* cursor;
SDL_Cursor *cursor;
Emscripten_CursorData *curdata;
cursor = SDL_calloc(1, sizeof(SDL_Cursor));
if (cursor) {
curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
curdata = (Emscripten_CursorData *)SDL_calloc(1, sizeof(*curdata));
if (curdata == NULL) {
SDL_OutOfMemory();
SDL_free(cursor);
@@ -56,15 +55,12 @@ Emscripten_CreateCursorFromString(const char* cursor_str, SDL_bool is_custom)
return cursor;
}
static SDL_Cursor*
Emscripten_CreateDefaultCursor()
static SDL_Cursor *Emscripten_CreateDefaultCursor()
{
return Emscripten_CreateCursorFromString("default", SDL_FALSE);
}
static SDL_Cursor*
Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
static SDL_Cursor *Emscripten_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
{
const char *cursor_url = NULL;
SDL_Surface *conv_surf;
@@ -75,6 +71,7 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
return NULL;
}
/* *INDENT-OFF* */ /* clang-format off */
cursor_url = (const char *)MAIN_THREAD_EM_ASM_INT({
var w = $0;
var h = $1;
@@ -124,68 +121,67 @@ Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
return urlBuf;
}, surface->w, surface->h, hot_x, hot_y, conv_surf->pixels);
/* *INDENT-ON* */ /* clang-format on */
SDL_FreeSurface(conv_surf);
return Emscripten_CreateCursorFromString(cursor_url, SDL_TRUE);
}
static SDL_Cursor*
Emscripten_CreateSystemCursor(SDL_SystemCursor id)
static SDL_Cursor *Emscripten_CreateSystemCursor(SDL_SystemCursor id)
{
const char *cursor_name = NULL;
switch(id) {
case SDL_SYSTEM_CURSOR_ARROW:
cursor_name = "default";
break;
case SDL_SYSTEM_CURSOR_IBEAM:
cursor_name = "text";
break;
case SDL_SYSTEM_CURSOR_WAIT:
cursor_name = "wait";
break;
case SDL_SYSTEM_CURSOR_CROSSHAIR:
cursor_name = "crosshair";
break;
case SDL_SYSTEM_CURSOR_WAITARROW:
cursor_name = "progress";
break;
case SDL_SYSTEM_CURSOR_SIZENWSE:
cursor_name = "nwse-resize";
break;
case SDL_SYSTEM_CURSOR_SIZENESW:
cursor_name = "nesw-resize";
break;
case SDL_SYSTEM_CURSOR_SIZEWE:
cursor_name = "ew-resize";
break;
case SDL_SYSTEM_CURSOR_SIZENS:
cursor_name = "ns-resize";
break;
case SDL_SYSTEM_CURSOR_SIZEALL:
cursor_name = "move";
break;
case SDL_SYSTEM_CURSOR_NO:
cursor_name = "not-allowed";
break;
case SDL_SYSTEM_CURSOR_HAND:
cursor_name = "pointer";
break;
default:
SDL_assert(0);
return NULL;
switch (id) {
case SDL_SYSTEM_CURSOR_ARROW:
cursor_name = "default";
break;
case SDL_SYSTEM_CURSOR_IBEAM:
cursor_name = "text";
break;
case SDL_SYSTEM_CURSOR_WAIT:
cursor_name = "wait";
break;
case SDL_SYSTEM_CURSOR_CROSSHAIR:
cursor_name = "crosshair";
break;
case SDL_SYSTEM_CURSOR_WAITARROW:
cursor_name = "progress";
break;
case SDL_SYSTEM_CURSOR_SIZENWSE:
cursor_name = "nwse-resize";
break;
case SDL_SYSTEM_CURSOR_SIZENESW:
cursor_name = "nesw-resize";
break;
case SDL_SYSTEM_CURSOR_SIZEWE:
cursor_name = "ew-resize";
break;
case SDL_SYSTEM_CURSOR_SIZENS:
cursor_name = "ns-resize";
break;
case SDL_SYSTEM_CURSOR_SIZEALL:
cursor_name = "move";
break;
case SDL_SYSTEM_CURSOR_NO:
cursor_name = "not-allowed";
break;
case SDL_SYSTEM_CURSOR_HAND:
cursor_name = "pointer";
break;
default:
SDL_assert(0);
return NULL;
}
return Emscripten_CreateCursorFromString(cursor_name, SDL_FALSE);
}
static void
Emscripten_FreeCursor(SDL_Cursor* cursor)
static void Emscripten_FreeCursor(SDL_Cursor *cursor)
{
Emscripten_CursorData *curdata;
if (cursor) {
curdata = (Emscripten_CursorData *) cursor->driverdata;
curdata = (Emscripten_CursorData *)cursor->driverdata;
if (curdata != NULL) {
if (curdata->is_custom) {
@@ -198,40 +194,41 @@ Emscripten_FreeCursor(SDL_Cursor* cursor)
}
}
static int
Emscripten_ShowCursor(SDL_Cursor* cursor)
static int Emscripten_ShowCursor(SDL_Cursor *cursor)
{
Emscripten_CursorData *curdata;
if (SDL_GetMouseFocus() != NULL) {
if (cursor && cursor->driverdata) {
curdata = (Emscripten_CursorData *) cursor->driverdata;
curdata = (Emscripten_CursorData *)cursor->driverdata;
if (curdata->system_cursor) {
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM({
if (Module['canvas']) {
Module['canvas'].style['cursor'] = UTF8ToString($0);
}
}, curdata->system_cursor);
/* *INDENT-ON* */ /* clang-format on */
}
} else {
/* *INDENT-OFF* */ /* clang-format off */
MAIN_THREAD_EM_ASM(
if (Module['canvas']) {
Module['canvas'].style['cursor'] = 'none';
}
);
/* *INDENT-ON* */ /* clang-format on */
}
}
return 0;
}
static void
Emscripten_WarpMouse(SDL_Window* window, int x, int y)
static void Emscripten_WarpMouse(SDL_Window *window, int x, int y)
{
SDL_Unsupported();
}
static int
Emscripten_SetRelativeMouseMode(SDL_bool enabled)
static int Emscripten_SetRelativeMouseMode(SDL_bool enabled)
{
SDL_Window *window;
SDL_WindowData *window_data;
@@ -243,7 +240,7 @@ Emscripten_SetRelativeMouseMode(SDL_bool enabled)
return -1;
}
window_data = (SDL_WindowData *) window->driverdata;
window_data = (SDL_WindowData *)window->driverdata;
if (emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
return 0;
@@ -256,27 +253,24 @@ Emscripten_SetRelativeMouseMode(SDL_bool enabled)
return -1;
}
void
Emscripten_InitMouse()
void Emscripten_InitMouse()
{
SDL_Mouse* mouse = SDL_GetMouse();
SDL_Mouse *mouse = SDL_GetMouse();
mouse->CreateCursor = Emscripten_CreateCursor;
mouse->ShowCursor = Emscripten_ShowCursor;
mouse->FreeCursor = Emscripten_FreeCursor;
mouse->WarpMouse = Emscripten_WarpMouse;
mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
mouse->CreateCursor = Emscripten_CreateCursor;
mouse->ShowCursor = Emscripten_ShowCursor;
mouse->FreeCursor = Emscripten_FreeCursor;
mouse->WarpMouse = Emscripten_WarpMouse;
mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
mouse->SetRelativeMouseMode = Emscripten_SetRelativeMouseMode;
SDL_SetDefaultCursor(Emscripten_CreateDefaultCursor());
}
void
Emscripten_FiniMouse()
void Emscripten_FiniMouse()
{
}
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -19,7 +19,6 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL_emscriptenmouse_h_
#define SDL_emscriptenmouse_h_

View File

@@ -85,8 +85,7 @@ Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
SDL_EGL_CreateContext_impl(Emscripten)
SDL_EGL_MakeCurrent_impl(Emscripten)
int
Emscripten_GLES_SwapWindow(_THIS, SDL_Window * window)
int Emscripten_GLES_SwapWindow(_THIS, SDL_Window *window)
{
EGLBoolean ret = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, SDL_TRUE)) {
@@ -99,4 +98,3 @@ Emscripten_GLES_SwapWindow(_THIS, SDL_Window * window)
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -40,35 +40,32 @@
/* Initialization/Query functions */
static int Emscripten_VideoInit(_THIS);
static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
static void Emscripten_VideoQuit(_THIS);
static int Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
static int Emscripten_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
static int Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
static int Emscripten_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
static int Emscripten_CreateWindow(_THIS, SDL_Window * window);
static void Emscripten_SetWindowSize(_THIS, SDL_Window * window);
static void Emscripten_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h);
static void Emscripten_DestroyWindow(_THIS, SDL_Window * window);
static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
static int Emscripten_CreateWindow(_THIS, SDL_Window *window);
static void Emscripten_SetWindowSize(_THIS, SDL_Window *window);
static void Emscripten_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h);
static void Emscripten_DestroyWindow(_THIS, SDL_Window *window);
static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
static void Emscripten_PumpEvents(_THIS);
static void Emscripten_SetWindowTitle(_THIS, SDL_Window * window);
static void Emscripten_SetWindowTitle(_THIS, SDL_Window *window);
/* Emscripten driver bootstrap functions */
static void
Emscripten_DeleteDevice(SDL_VideoDevice * device)
static void Emscripten_DeleteDevice(SDL_VideoDevice *device)
{
SDL_free(device);
}
static SDL_VideoDevice *
Emscripten_CreateDevice(void)
static SDL_VideoDevice *Emscripten_CreateDevice(void)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device == NULL) {
SDL_OutOfMemory();
return 0;
@@ -77,7 +74,7 @@ Emscripten_CreateDevice(void)
/* Firefox sends blur event which would otherwise prevent full screen
* when the user clicks to allow full screen.
* See https://bugzilla.mozilla.org/show_bug.cgi?id=1144964
*/
*/
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
/* Set the function pointers */
@@ -87,7 +84,6 @@ Emscripten_CreateDevice(void)
device->GetDisplayDPI = Emscripten_GetDisplayDPI;
device->SetDisplayMode = Emscripten_SetDisplayMode;
device->PumpEvents = Emscripten_PumpEvents;
device->CreateSDLWindow = Emscripten_CreateWindow;
@@ -132,9 +128,7 @@ VideoBootStrap Emscripten_bootstrap = {
Emscripten_CreateDevice
};
int
Emscripten_VideoInit(_THIS)
int Emscripten_VideoInit(_THIS)
{
SDL_DisplayMode mode;
@@ -156,21 +150,18 @@ Emscripten_VideoInit(_THIS)
return 0;
}
static int
Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
/* can't do this */
return 0;
}
static void
Emscripten_VideoQuit(_THIS)
static void Emscripten_VideoQuit(_THIS)
{
Emscripten_FiniMouse();
}
static int
Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
static int Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
{
if (rect) {
rect->x = 0;
@@ -185,8 +176,7 @@ Emscripten_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect *
return 0;
}
static int
Emscripten_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi_out, float * hdpi_out, float * vdpi_out)
static int Emscripten_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi_out, float *hdpi_out, float *vdpi_out)
{
const float dpi_reference = 96.0f;
float dpi;
@@ -206,21 +196,19 @@ Emscripten_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi_out, fl
return 0;
}
static void
Emscripten_PumpEvents(_THIS)
static void Emscripten_PumpEvents(_THIS)
{
/* do nothing. */
}
static int
Emscripten_CreateWindow(_THIS, SDL_Window * window)
static int Emscripten_CreateWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *wdata;
double scaled_w, scaled_h;
double css_w, css_h;
/* Allocate window internal data */
wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
if (wdata == NULL) {
return SDL_OutOfMemory();
}
@@ -289,12 +277,12 @@ Emscripten_CreateWindow(_THIS, SDL_Window * window)
return 0;
}
static void Emscripten_SetWindowSize(_THIS, SDL_Window * window)
static void Emscripten_SetWindowSize(_THIS, SDL_Window *window)
{
SDL_WindowData *data;
if (window->driverdata) {
data = (SDL_WindowData *) window->driverdata;
data = (SDL_WindowData *)window->driverdata;
/* update pixel ratio */
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
data->pixel_ratio = emscripten_get_device_pixel_ratio();
@@ -308,25 +296,22 @@ static void Emscripten_SetWindowSize(_THIS, SDL_Window * window)
}
}
static void
Emscripten_GetWindowSizeInPixels(_THIS, SDL_Window * window, int *w, int *h)
static void Emscripten_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h)
{
SDL_WindowData *data;
if (window->driverdata) {
data = (SDL_WindowData *) window->driverdata;
data = (SDL_WindowData *)window->driverdata;
*w = window->w * data->pixel_ratio;
*h = window->h * data->pixel_ratio;
}
}
static void
Emscripten_DestroyWindow(_THIS, SDL_Window * window)
static void Emscripten_DestroyWindow(_THIS, SDL_Window *window)
{
SDL_WindowData *data;
if (window->driverdata) {
data = (SDL_WindowData *) window->driverdata;
data = (SDL_WindowData *)window->driverdata;
Emscripten_UnregisterEventHandlers(data);
#if SDL_VIDEO_OPENGL_EGL
@@ -345,12 +330,11 @@ Emscripten_DestroyWindow(_THIS, SDL_Window * window)
}
}
static void
Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
{
SDL_WindowData *data;
if (window->driverdata) {
data = (SDL_WindowData *) window->driverdata;
data = (SDL_WindowData *)window->driverdata;
if (fullscreen) {
EmscriptenFullscreenStrategy strategy;
@@ -385,8 +369,8 @@ Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * di
}
}
static void
Emscripten_SetWindowTitle(_THIS, SDL_Window * window) {
static void Emscripten_SetWindowTitle(_THIS, SDL_Window *window)
{
emscripten_set_window_title(window->title);
}