clang-format in src/unix/

This commit is contained in:
Jasmine Iwanek
2022-09-18 17:17:34 -04:00
parent d4c4ef6a5d
commit acbe718f1e
5 changed files with 744 additions and 848 deletions

View File

@@ -13,11 +13,10 @@
CF_IMPLICIT_BRIDGING_ENABLED
CF_EXTERN_C_BEGIN
void getDefaultROMPath(char*);
int toto();
void getDefaultROMPath(char *);
int toto();
CF_EXTERN_C_END
CF_IMPLICIT_BRIDGING_DISABLED
#endif /* macOSXGlue_h */

File diff suppressed because it is too large Load Diff

View File

@@ -39,8 +39,6 @@
#include <86box/plat.h>
#include <86box/ui.h>
void
cassette_mount(char *fn, uint8_t wp)
{
@@ -49,49 +47,45 @@ cassette_mount(char *fn, uint8_t wp)
cassette_ui_writeprot = wp;
pc_cas_set_fname(cassette, fn);
if (fn != NULL)
memcpy(cassette_fname, fn, MIN(511, strlen(fn)));
memcpy(cassette_fname, fn, MIN(511, strlen(fn)));
ui_sb_update_icon_state(SB_CASSETTE, (fn == NULL) ? 1 : 0);
//media_menu_update_cassette();
// media_menu_update_cassette();
ui_sb_update_tip(SB_CASSETTE);
config_save();
}
void
cassette_eject(void)
{
pc_cas_set_fname(cassette, NULL);
memset(cassette_fname, 0x00, sizeof(cassette_fname));
ui_sb_update_icon_state(SB_CASSETTE, 1);
//media_menu_update_cassette();
// media_menu_update_cassette();
ui_sb_update_tip(SB_CASSETTE);
config_save();
}
void
cartridge_mount(uint8_t id, char *fn, uint8_t wp)
{
cart_close(id);
cart_load(id, fn);
ui_sb_update_icon_state(SB_CARTRIDGE | id, strlen(cart_fns[id]) ? 0 : 1);
//media_menu_update_cartridge(id);
// media_menu_update_cartridge(id);
ui_sb_update_tip(SB_CARTRIDGE | id);
config_save();
}
void
cartridge_eject(uint8_t id)
{
cart_close(id);
ui_sb_update_icon_state(SB_CARTRIDGE | id, 1);
//media_menu_update_cartridge(id);
// media_menu_update_cartridge(id);
ui_sb_update_tip(SB_CARTRIDGE | id);
config_save();
}
void
floppy_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -99,36 +93,34 @@ floppy_mount(uint8_t id, char *fn, uint8_t wp)
ui_writeprot[id] = wp;
fdd_load(id, fn);
ui_sb_update_icon_state(SB_FLOPPY | id, strlen(floppyfns[id]) ? 0 : 1);
//media_menu_update_floppy(id);
// media_menu_update_floppy(id);
ui_sb_update_tip(SB_FLOPPY | id);
config_save();
}
void
floppy_eject(uint8_t id)
{
fdd_close(id);
ui_sb_update_icon_state(SB_FLOPPY | id, 1);
//media_menu_update_floppy(id);
// media_menu_update_floppy(id);
ui_sb_update_tip(SB_FLOPPY | id);
config_save();
}
void
plat_cdrom_ui_update(uint8_t id, uint8_t reload)
{
cdrom_t *drv = &cdrom[id];
if (drv->host_drive == 0) {
ui_sb_update_icon_state(SB_CDROM|id, 1);
ui_sb_update_icon_state(SB_CDROM | id, 1);
} else {
ui_sb_update_icon_state(SB_CDROM|id, 0);
ui_sb_update_icon_state(SB_CDROM | id, 0);
}
//media_menu_update_cdrom(id);
ui_sb_update_tip(SB_CDROM|id);
// media_menu_update_cdrom(id);
ui_sb_update_tip(SB_CDROM | id);
}
void
@@ -137,20 +129,20 @@ cdrom_mount(uint8_t id, char *fn)
cdrom[id].prev_host_drive = cdrom[id].host_drive;
strcpy(cdrom[id].prev_image_path, cdrom[id].image_path);
if (cdrom[id].ops && cdrom[id].ops->exit)
cdrom[id].ops->exit(&(cdrom[id]));
cdrom[id].ops->exit(&(cdrom[id]));
cdrom[id].ops = NULL;
memset(cdrom[id].image_path, 0, sizeof(cdrom[id].image_path));
cdrom_image_open(&(cdrom[id]), fn);
/* Signal media change to the emulated machine. */
if (cdrom[id].insert)
cdrom[id].insert(cdrom[id].priv);
cdrom[id].insert(cdrom[id].priv);
cdrom[id].host_drive = (strlen(cdrom[id].image_path) == 0) ? 0 : 200;
if (cdrom[id].host_drive == 200) {
ui_sb_update_icon_state(SB_CDROM | id, 0);
ui_sb_update_icon_state(SB_CDROM | id, 0);
} else {
ui_sb_update_icon_state(SB_CDROM | id, 1);
ui_sb_update_icon_state(SB_CDROM | id, 1);
}
//media_menu_update_cdrom(id);
// media_menu_update_cdrom(id);
ui_sb_update_tip(SB_CDROM | id);
config_save();
}
@@ -162,17 +154,16 @@ mo_eject(uint8_t id)
mo_disk_close(dev);
if (mo_drives[id].bus_type) {
/* Signal disk change to the emulated machine. */
mo_insert(dev);
/* Signal disk change to the emulated machine. */
mo_insert(dev);
}
ui_sb_update_icon_state(SB_MO | id, 1);
//media_menu_update_mo(id);
// media_menu_update_mo(id);
ui_sb_update_tip(SB_MO | id);
config_save();
}
void
mo_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -184,13 +175,12 @@ mo_mount(uint8_t id, char *fn, uint8_t wp)
mo_insert(dev);
ui_sb_update_icon_state(SB_MO | id, strlen(mo_drives[id].image_path) ? 0 : 1);
//media_menu_update_mo(id);
// media_menu_update_mo(id);
ui_sb_update_tip(SB_MO | id);
config_save();
}
void
mo_reload(uint8_t id)
{
@@ -198,13 +188,13 @@ mo_reload(uint8_t id)
mo_disk_reload(dev);
if (strlen(mo_drives[id].image_path) == 0) {
ui_sb_update_icon_state(SB_MO|id, 1);
ui_sb_update_icon_state(SB_MO | id, 1);
} else {
ui_sb_update_icon_state(SB_MO|id, 0);
ui_sb_update_icon_state(SB_MO | id, 0);
}
//media_menu_update_mo(id);
ui_sb_update_tip(SB_MO|id);
// media_menu_update_mo(id);
ui_sb_update_tip(SB_MO | id);
config_save();
}
@@ -216,17 +206,16 @@ zip_eject(uint8_t id)
zip_disk_close(dev);
if (zip_drives[id].bus_type) {
/* Signal disk change to the emulated machine. */
zip_insert(dev);
/* Signal disk change to the emulated machine. */
zip_insert(dev);
}
ui_sb_update_icon_state(SB_ZIP | id, 1);
//media_menu_update_zip(id);
// media_menu_update_zip(id);
ui_sb_update_tip(SB_ZIP | id);
config_save();
}
void
zip_mount(uint8_t id, char *fn, uint8_t wp)
{
@@ -238,13 +227,12 @@ zip_mount(uint8_t id, char *fn, uint8_t wp)
zip_insert(dev);
ui_sb_update_icon_state(SB_ZIP | id, strlen(zip_drives[id].image_path) ? 0 : 1);
//media_menu_update_zip(id);
// media_menu_update_zip(id);
ui_sb_update_tip(SB_ZIP | id);
config_save();
}
void
zip_reload(uint8_t id)
{
@@ -252,13 +240,13 @@ zip_reload(uint8_t id)
zip_disk_reload(dev);
if (strlen(zip_drives[id].image_path) == 0) {
ui_sb_update_icon_state(SB_ZIP|id, 1);
ui_sb_update_icon_state(SB_ZIP | id, 1);
} else {
ui_sb_update_icon_state(SB_ZIP|id, 0);
ui_sb_update_icon_state(SB_ZIP | id, 0);
}
//media_menu_update_zip(id);
ui_sb_update_tip(SB_ZIP|id);
// media_menu_update_zip(id);
ui_sb_update_tip(SB_ZIP | id);
config_save();
}

View File

@@ -18,34 +18,33 @@
#include <86box/version.h>
#include <86box/unix_sdl.h>
#define RENDERER_FULL_SCREEN 1
#define RENDERER_HARDWARE 2
#define RENDERER_OPENGL 4
#define RENDERER_FULL_SCREEN 1
#define RENDERER_HARDWARE 2
#define RENDERER_OPENGL 4
typedef struct sdl_blit_params
{
typedef struct sdl_blit_params {
int x, y, w, h;
} sdl_blit_params;
extern sdl_blit_params params;
extern int blitreq;
extern int blitreq;
SDL_Window *sdl_win = NULL;
SDL_Renderer *sdl_render = NULL;
static SDL_Texture *sdl_tex = NULL;
int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y;
static int sdl_fs, sdl_flags = -1;
static int cur_w, cur_h;
static int cur_wx = 0, cur_wy = 0, cur_ww =0, cur_wh = 0;
static volatile int sdl_enabled = 1;
static SDL_mutex* sdl_mutex = NULL;
int mouse_capture;
int title_set = 0;
int resize_pending = 0;
int resize_w = 0;
int resize_h = 0;
double mouse_sensitivity = 1.0; /* Unused. */
double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */
static uint8_t interpixels[17842176];
SDL_Window *sdl_win = NULL;
SDL_Renderer *sdl_render = NULL;
static SDL_Texture *sdl_tex = NULL;
int sdl_w = SCREEN_RES_X, sdl_h = SCREEN_RES_Y;
static int sdl_fs, sdl_flags = -1;
static int cur_w, cur_h;
static int cur_wx = 0, cur_wy = 0, cur_ww = 0, cur_wh = 0;
static volatile int sdl_enabled = 1;
static SDL_mutex *sdl_mutex = NULL;
int mouse_capture;
int title_set = 0;
int resize_pending = 0;
int resize_w = 0;
int resize_h = 0;
double mouse_sensitivity = 1.0; /* Unused. */
double mouse_x_error = 0.0, mouse_y_error = 0.0; /* Unused. */
static uint8_t interpixels[17842176];
extern void RenderImGui();
static void
@@ -54,11 +53,11 @@ sdl_integer_scale(double *d, double *g)
double ratio;
if (*d > *g) {
ratio = floor(*d / *g);
*d = *g * ratio;
ratio = floor(*d / *g);
*d = *g * ratio;
} else {
ratio = ceil(*d / *g);
*d = *g / ratio;
ratio = ceil(*d / *g);
*d = *g / ratio;
}
}
@@ -68,66 +67,65 @@ static void
sdl_stretch(int *w, int *h, int *x, int *y)
{
double hw, gw, hh, gh, dx, dy, dw, dh, gsr, hsr;
int real_sdl_w, real_sdl_h;
int real_sdl_w, real_sdl_h;
SDL_GL_GetDrawableSize(sdl_win, &real_sdl_w, &real_sdl_h);
hw = (double) real_sdl_w;
hh = (double) real_sdl_h;
gw = (double) *w;
gh = (double) *h;
hw = (double) real_sdl_w;
hh = (double) real_sdl_h;
gw = (double) *w;
gh = (double) *h;
hsr = hw / hh;
switch (video_fullscreen_scale) {
case FULLSCR_SCALE_FULL:
default:
*w = real_sdl_w;
*h = real_sdl_h;
*x = 0;
*y = 0;
break;
case FULLSCR_SCALE_43:
case FULLSCR_SCALE_KEEPRATIO:
if (video_fullscreen_scale == FULLSCR_SCALE_43)
gsr = 4.0 / 3.0;
else
gsr = gw / gh;
if (gsr <= hsr) {
dw = hh * gsr;
dh = hh;
} else {
dw = hw;
dh = hw / gsr;
}
dx = (hw - dw) / 2.0;
dy = (hh - dh) / 2.0;
*w = (int) dw;
*h = (int) dh;
*x = (int) dx;
*y = (int) dy;
break;
case FULLSCR_SCALE_INT:
gsr = gw / gh;
if (gsr <= hsr) {
dw = hh * gsr;
dh = hh;
} else {
dw = hw;
dh = hw / gsr;
}
sdl_integer_scale(&dw, &gw);
sdl_integer_scale(&dh, &gh);
dx = (hw - dw) / 2.0;
dy = (hh - dh) / 2.0;
*w = (int) dw;
*h = (int) dh;
*x = (int) dx;
*y = (int) dy;
break;
case FULLSCR_SCALE_FULL:
default:
*w = real_sdl_w;
*h = real_sdl_h;
*x = 0;
*y = 0;
break;
case FULLSCR_SCALE_43:
case FULLSCR_SCALE_KEEPRATIO:
if (video_fullscreen_scale == FULLSCR_SCALE_43)
gsr = 4.0 / 3.0;
else
gsr = gw / gh;
if (gsr <= hsr) {
dw = hh * gsr;
dh = hh;
} else {
dw = hw;
dh = hw / gsr;
}
dx = (hw - dw) / 2.0;
dy = (hh - dh) / 2.0;
*w = (int) dw;
*h = (int) dh;
*x = (int) dx;
*y = (int) dy;
break;
case FULLSCR_SCALE_INT:
gsr = gw / gh;
if (gsr <= hsr) {
dw = hh * gsr;
dh = hh;
} else {
dw = hw;
dh = hw / gsr;
}
sdl_integer_scale(&dw, &gw);
sdl_integer_scale(&dh, &gh);
dx = (hw - dw) / 2.0;
dy = (hh - dh) / 2.0;
*w = (int) dw;
*h = (int) dh;
*x = (int) dx;
*y = (int) dy;
break;
}
}
void
sdl_blit_shim(int x, int y, int w, int h, int monitor_index)
{
@@ -136,9 +134,9 @@ sdl_blit_shim(int x, int y, int w, int h, int monitor_index)
params.w = w;
params.h = h;
if (!(!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) || (monitor_index >= 1))
video_copy(interpixels, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t));
video_copy(interpixels, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t));
if (screenshots)
video_screenshot(interpixels, 0, 0, 2048);
video_screenshot(interpixels, 0, 0, 2048);
blitreq = 1;
video_blit_complete_monitor(monitor_index);
}
@@ -146,30 +144,26 @@ sdl_blit_shim(int x, int y, int w, int h, int monitor_index)
void ui_window_title_real();
void
sdl_real_blit(SDL_Rect* r_src)
sdl_real_blit(SDL_Rect *r_src)
{
SDL_Rect r_dst;
int ret, winx, winy;
int ret, winx, winy;
SDL_GL_GetDrawableSize(sdl_win, &winx, &winy);
SDL_RenderClear(sdl_render);
r_dst = *r_src;
r_dst = *r_src;
r_dst.x = r_dst.y = 0;
if (sdl_fs)
{
sdl_stretch(&r_dst.w, &r_dst.h, &r_dst.x, &r_dst.y);
if (sdl_fs) {
sdl_stretch(&r_dst.w, &r_dst.h, &r_dst.x, &r_dst.y);
} else {
r_dst.w *= ((float) winx / (float) r_dst.w);
r_dst.h *= ((float) winy / (float) r_dst.h);
}
else
{
r_dst.w *= ((float)winx / (float) r_dst.w);
r_dst.h *= ((float)winy / (float) r_dst.h);
}
ret = SDL_RenderCopy(sdl_render, sdl_tex, r_src, &r_dst);
if (ret)
fprintf(stderr, "SDL: unable to copy texture to renderer (%s)\n", SDL_GetError());
fprintf(stderr, "SDL: unable to copy texture to renderer (%s)\n", SDL_GetError());
SDL_RenderPresent(sdl_render);
}
@@ -180,20 +174,20 @@ sdl_blit(int x, int y, int w, int h)
SDL_Rect r_src;
if (!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) {
r_src.x = x;
r_src.y = y;
r_src.w = w;
r_src.h = h;
sdl_real_blit(&r_src);
blitreq = 0;
return;
r_src.x = x;
r_src.y = y;
r_src.w = w;
r_src.h = h;
sdl_real_blit(&r_src);
blitreq = 0;
return;
}
SDL_LockMutex(sdl_mutex);
if (resize_pending)
{
if (!video_fullscreen) sdl_resize(resize_w, resize_h);
if (resize_pending) {
if (!video_fullscreen)
sdl_resize(resize_w, resize_h);
resize_pending = 0;
}
r_src.x = x;
@@ -211,27 +205,24 @@ static void
sdl_destroy_window(void)
{
if (sdl_win != NULL) {
if (window_remember)
{
SDL_GetWindowSize(sdl_win, &window_w, &window_h);
if (strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0)
{
SDL_GetWindowPosition(sdl_win, &window_x, &window_y);
if (window_remember) {
SDL_GetWindowSize(sdl_win, &window_w, &window_h);
if (strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0) {
SDL_GetWindowPosition(sdl_win, &window_x, &window_y);
}
}
}
SDL_DestroyWindow(sdl_win);
sdl_win = NULL;
SDL_DestroyWindow(sdl_win);
sdl_win = NULL;
}
}
static void
sdl_destroy_texture(void)
{
/* SDL_DestroyRenderer also automatically destroys all associated textures. */
if (sdl_render != NULL) {
SDL_DestroyRenderer(sdl_render);
sdl_render = NULL;
SDL_DestroyRenderer(sdl_render);
sdl_render = NULL;
}
}
@@ -239,17 +230,17 @@ void
sdl_close(void)
{
if (sdl_mutex != NULL)
SDL_LockMutex(sdl_mutex);
SDL_LockMutex(sdl_mutex);
/* Unregister our renderer! */
video_setblit(NULL);
if (sdl_enabled)
sdl_enabled = 0;
sdl_enabled = 0;
if (sdl_mutex != NULL) {
SDL_DestroyMutex(sdl_mutex);
sdl_mutex = NULL;
SDL_DestroyMutex(sdl_mutex);
sdl_mutex = NULL;
}
sdl_destroy_texture();
@@ -266,14 +257,14 @@ void
sdl_enable(int enable)
{
if (sdl_flags == -1)
return;
return;
SDL_LockMutex(sdl_mutex);
sdl_enabled = !!enable;
if (enable == 1) {
SDL_SetWindowSize(sdl_win, cur_ww, cur_wh);
sdl_reinit_texture();
SDL_SetWindowSize(sdl_win, cur_ww, cur_wh);
sdl_reinit_texture();
}
SDL_UnlockMutex(sdl_mutex);
@@ -282,16 +273,15 @@ sdl_enable(int enable)
static void
sdl_select_best_hw_driver(void)
{
int i;
int i;
SDL_RendererInfo renderInfo;
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i)
{
SDL_GetRenderDriverInfo(i, &renderInfo);
if (renderInfo.flags & SDL_RENDERER_ACCELERATED) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name);
return;
}
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
SDL_GetRenderDriverInfo(i, &renderInfo);
if (renderInfo.flags & SDL_RENDERER_ACCELERATED) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderInfo.name);
return;
}
}
}
@@ -301,14 +291,13 @@ sdl_reinit_texture()
sdl_destroy_texture();
if (sdl_flags & RENDERER_HARDWARE) {
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
} else
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE);
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE);
sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, 2048, 2048);
SDL_TEXTUREACCESS_STREAMING, 2048, 2048);
}
void
@@ -316,14 +305,14 @@ sdl_set_fs(int fs)
{
SDL_LockMutex(sdl_mutex);
SDL_SetWindowFullscreen(sdl_win, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
SDL_SetRelativeMouseMode((SDL_bool)mouse_capture);
SDL_SetRelativeMouseMode((SDL_bool) mouse_capture);
sdl_fs = fs;
if (fs)
sdl_flags |= RENDERER_FULL_SCREEN;
sdl_flags |= RENDERER_FULL_SCREEN;
else
sdl_flags &= ~RENDERER_FULL_SCREEN;
sdl_flags &= ~RENDERER_FULL_SCREEN;
sdl_reinit_texture();
SDL_UnlockMutex(sdl_mutex);
@@ -335,10 +324,10 @@ sdl_resize(int x, int y)
int ww = 0, wh = 0, wx = 0, wy = 0;
if (video_fullscreen & 2)
return;
return;
if ((x == cur_w) && (y == cur_h))
return;
return;
SDL_LockMutex(sdl_mutex);
@@ -363,19 +352,18 @@ sdl_resize(int x, int y)
void
sdl_reload(void)
{
if (sdl_flags & RENDERER_HARDWARE)
{
SDL_LockMutex(sdl_mutex);
if (sdl_flags & RENDERER_HARDWARE) {
SDL_LockMutex(sdl_mutex);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
sdl_reinit_texture();
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, video_filter_method ? "1" : "0");
sdl_reinit_texture();
SDL_UnlockMutex(sdl_mutex);
}
SDL_UnlockMutex(sdl_mutex);
}
}
int
plat_vidapi(char* api)
plat_vidapi(char *api)
{
return 0;
}
@@ -383,7 +371,7 @@ plat_vidapi(char* api)
static int
sdl_init_common(int flags)
{
wchar_t temp[128];
wchar_t temp[128];
SDL_version ver;
/* Get and log the version of the DLL we are using. */
@@ -392,30 +380,27 @@ sdl_init_common(int flags)
/* Initialize the SDL system. */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL: initialization failed (%s)\n", SDL_GetError());
return(0);
fprintf(stderr, "SDL: initialization failed (%s)\n", SDL_GetError());
return (0);
}
if (flags & RENDERER_HARDWARE) {
if (flags & RENDERER_OPENGL) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL");
}
else
sdl_select_best_hw_driver();
if (flags & RENDERER_OPENGL) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "OpenGL");
} else
sdl_select_best_hw_driver();
}
sdl_mutex = SDL_CreateMutex();
sdl_win = SDL_CreateWindow("86Box", strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_x : SDL_WINDOWPOS_CENTERED, strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_y : SDL_WINDOWPOS_CENTERED, scrnsz_x, scrnsz_y, SDL_WINDOW_OPENGL | (vid_resize & 1 ? SDL_WINDOW_RESIZABLE : 0));
sdl_win = SDL_CreateWindow("86Box", strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_x : SDL_WINDOWPOS_CENTERED, strncasecmp(SDL_GetCurrentVideoDriver(), "wayland", 7) != 0 && window_remember ? window_y : SDL_WINDOWPOS_CENTERED, scrnsz_x, scrnsz_y, SDL_WINDOW_OPENGL | (vid_resize & 1 ? SDL_WINDOW_RESIZABLE : 0));
sdl_set_fs(video_fullscreen);
if (!(video_fullscreen & 1))
{
if (!(video_fullscreen & 1)) {
if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y);
plat_resize(fixed_size_x, fixed_size_y);
else
plat_resize(scrnsz_x, scrnsz_y);
plat_resize(scrnsz_x, scrnsz_y);
}
if ((vid_resize < 2) && window_remember)
{
if ((vid_resize < 2) && window_remember) {
SDL_SetWindowSize(sdl_win, window_w, window_h);
}
@@ -427,7 +412,7 @@ sdl_init_common(int flags)
sdl_enabled = 1;
return(1);
return (1);
}
int
@@ -436,61 +421,58 @@ sdl_inits()
return sdl_init_common(0);
}
int
sdl_inith()
{
return sdl_init_common(RENDERER_HARDWARE);
}
int
sdl_initho()
{
return sdl_init_common(RENDERER_HARDWARE | RENDERER_OPENGL);
}
int
sdl_pause(void)
{
return(0);
return (0);
}
void
plat_mouse_capture(int on)
{
SDL_LockMutex(sdl_mutex);
SDL_SetRelativeMouseMode((SDL_bool)on);
SDL_SetRelativeMouseMode((SDL_bool) on);
mouse_capture = on;
SDL_UnlockMutex(sdl_mutex);
}
void plat_resize(int w, int h)
void
plat_resize(int w, int h)
{
SDL_LockMutex(sdl_mutex);
resize_w = w;
resize_h = h;
resize_w = w;
resize_h = h;
resize_pending = 1;
SDL_UnlockMutex(sdl_mutex);
}
wchar_t sdl_win_title[512] = { L'8', L'6', L'B', L'o', L'x', 0 };
SDL_mutex* titlemtx = NULL;
wchar_t sdl_win_title[512] = { L'8', L'6', L'B', L'o', L'x', 0 };
SDL_mutex *titlemtx = NULL;
void ui_window_title_real()
void
ui_window_title_real()
{
char* res;
if (sizeof(wchar_t) == 1)
{
SDL_SetWindowTitle(sdl_win, (char*)sdl_win_title);
char *res;
if (sizeof(wchar_t) == 1) {
SDL_SetWindowTitle(sdl_win, (char *) sdl_win_title);
return;
}
res = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char*)sdl_win_title, wcslen(sdl_win_title) * sizeof(wchar_t) + sizeof(wchar_t));
if (res)
{
res = SDL_iconv_string("UTF-8", sizeof(wchar_t) == 2 ? "UTF-16LE" : "UTF-32LE", (char *) sdl_win_title, wcslen(sdl_win_title) * sizeof(wchar_t) + sizeof(wchar_t));
if (res) {
SDL_SetWindowTitle(sdl_win, res);
SDL_free((void*)res);
SDL_free((void *) res);
}
title_set = 0;
}
@@ -498,9 +480,11 @@ extern SDL_threadID eventthread;
/* Only activate threading path on macOS, otherwise it will softlock Xorg.
Wayland doesn't seem to have this issue. */
wchar_t* ui_window_title(wchar_t* str)
wchar_t *
ui_window_title(wchar_t *str)
{
if (!str) return sdl_win_title;
if (!str)
return sdl_win_title;
#ifdef __APPLE__
if (eventthread == SDL_ThreadID())
#endif
@@ -518,10 +502,17 @@ wchar_t* ui_window_title(wchar_t* str)
return str;
}
void ui_init_monitor(int monitor_index) {}
void ui_deinit_monitor(int monitor_index) {}
void
ui_init_monitor(int monitor_index)
{
}
void
ui_deinit_monitor(int monitor_index)
{
}
void plat_resize_request(int w, int h, int monitor_index)
void
plat_resize_request(int w, int h, int monitor_index)
{
atomic_store((&doresize_monitors[monitor_index]), 1);
}

View File

@@ -7,30 +7,23 @@
#include <86box/plat.h>
#include <86box/thread.h>
typedef struct event_pthread_t
{
pthread_cond_t cond;
pthread_mutex_t mutex;
int state;
typedef struct event_pthread_t {
pthread_cond_t cond;
pthread_mutex_t mutex;
int state;
} event_pthread_t;
typedef struct thread_param
{
void (*thread_rout)(void*);
void * param;
typedef struct thread_param {
void (*thread_rout)(void *);
void *param;
} thread_param;
typedef struct pt_mutex_t
{
pthread_mutex_t mutex;
typedef struct pt_mutex_t {
pthread_mutex_t mutex;
} pt_mutex_t;
void *
thread_run_wrapper(thread_param* arg)
thread_run_wrapper(thread_param *arg)
{
thread_param localparam = *arg;
free(arg);
@@ -38,28 +31,25 @@ thread_run_wrapper(thread_param* arg)
return NULL;
}
thread_t *
thread_create(void (*thread_rout)(void *param), void *param)
{
pthread_t *thread = malloc(sizeof(pthread_t));
pthread_t *thread = malloc(sizeof(pthread_t));
thread_param *thrparam = malloc(sizeof(thread_param));
thrparam->thread_rout = thread_rout;
thrparam->param = param;
thrparam->thread_rout = thread_rout;
thrparam->param = param;
pthread_create(thread, NULL, (void* (*)(void*))thread_run_wrapper, thrparam);
pthread_create(thread, NULL, (void *(*) (void *) ) thread_run_wrapper, thrparam);
return thread;
}
int
thread_wait(thread_t *arg)
{
return pthread_join(*(pthread_t*)(arg), NULL);
return pthread_join(*(pthread_t *) (arg), NULL);
}
event_t *
thread_create_event()
{
@@ -69,14 +59,13 @@ thread_create_event()
pthread_mutex_init(&event->mutex, NULL);
event->state = 0;
return (event_t *)event;
return (event_t *) event;
}
void
thread_set_event(event_t *handle)
{
event_pthread_t *event = (event_pthread_t *)handle;
event_pthread_t *event = (event_pthread_t *) handle;
pthread_mutex_lock(&event->mutex);
event->state = 1;
@@ -84,48 +73,45 @@ thread_set_event(event_t *handle)
pthread_mutex_unlock(&event->mutex);
}
void
thread_reset_event(event_t *handle)
{
event_pthread_t *event = (event_pthread_t *)handle;
event_pthread_t *event = (event_pthread_t *) handle;
pthread_mutex_lock(&event->mutex);
event->state = 0;
pthread_mutex_unlock(&event->mutex);
}
int
thread_wait_event(event_t *handle, int timeout)
{
event_pthread_t *event = (event_pthread_t *)handle;
struct timespec abstime;
event_pthread_t *event = (event_pthread_t *) handle;
struct timespec abstime;
clock_gettime(CLOCK_REALTIME, &abstime);
abstime.tv_nsec += (timeout % 1000) * 1000000;
abstime.tv_sec += (timeout / 1000);
if (abstime.tv_nsec > 1000000000) {
abstime.tv_nsec -= 1000000000;
abstime.tv_sec++;
abstime.tv_nsec -= 1000000000;
abstime.tv_sec++;
}
pthread_mutex_lock(&event->mutex);
if (timeout == -1) {
while (!event->state)
pthread_cond_wait(&event->cond, &event->mutex);
while (!event->state)
pthread_cond_wait(&event->cond, &event->mutex);
} else if (!event->state)
pthread_cond_timedwait(&event->cond, &event->mutex, &abstime);
pthread_cond_timedwait(&event->cond, &event->mutex, &abstime);
pthread_mutex_unlock(&event->mutex);
return 0;
}
void
thread_destroy_event(event_t *handle)
{
event_pthread_t *event = (event_pthread_t *)handle;
event_pthread_t *event = (event_pthread_t *) handle;
pthread_cond_destroy(&event->cond);
pthread_mutex_destroy(&event->mutex);
@@ -133,7 +119,6 @@ thread_destroy_event(event_t *handle)
free(event);
}
mutex_t *
thread_create_mutex(void)
{
@@ -144,46 +129,40 @@ thread_create_mutex(void)
return mutex;
}
int
thread_wait_mutex(mutex_t *_mutex)
{
if (_mutex == NULL)
return(0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex;
return (0);
pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
return
pthread_mutex_lock(&mutex->mutex) != 0;
return pthread_mutex_lock(&mutex->mutex) != 0;
}
int
thread_test_mutex(mutex_t *_mutex)
{
if (_mutex == NULL)
return(0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex;
return (0);
pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
return
pthread_mutex_trylock(&mutex->mutex) != 0;
return pthread_mutex_trylock(&mutex->mutex) != 0;
}
int
thread_release_mutex(mutex_t *_mutex)
{
if (_mutex == NULL)
return(0);
pt_mutex_t *mutex = (pt_mutex_t *)_mutex;
return (0);
pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
return pthread_mutex_unlock(&mutex->mutex) != 0;
}
void
thread_close_mutex(mutex_t *_mutex)
{
pt_mutex_t *mutex = (pt_mutex_t *)_mutex;
pt_mutex_t *mutex = (pt_mutex_t *) _mutex;
pthread_mutex_destroy(&mutex->mutex);