From ace21d28f776eb76f5eb586b372945c5c0ec9b7c Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Sat, 1 Oct 2022 17:56:16 +0200 Subject: [PATCH] Fix C++ comments --- audio/drivers/gx_audio.c | 7 +- audio/drivers/switch_thread_audio.c | 2 +- audio/librsound.c | 113 ++-- gfx/common/ctr_common.h | 2 +- gfx/common/fpga_common.h | 2 +- gfx/common/metal/metal_renderer.m | 32 +- gfx/common/metal_common.m | 556 ++++++++---------- gfx/video_filters/super2xsai.c | 25 +- input/common/wayland_common.c | 21 +- input/drivers/cocoa_input.c | 4 +- input/drivers/psl1ght_input.c | 179 +++--- input/drivers/qnx_input.c | 69 +-- input/drivers_hid/btstack_hid.c | 8 +- input/drivers_joypad/mfi_joypad.m | 52 +- .../drivers_keyboard/keyboard_event_android.h | 5 +- input/input_keymaps.c | 2 +- ui/drivers/ui_cocoa.m | 4 +- ui/drivers/ui_cocoatouch.m | 10 +- ui/drivers/ui_win32.c | 2 +- 19 files changed, 530 insertions(+), 565 deletions(-) diff --git a/audio/drivers/gx_audio.c b/audio/drivers/gx_audio.c index 95b24b07f5..f594863b98 100644 --- a/audio/drivers/gx_audio.c +++ b/audio/drivers/gx_audio.c @@ -79,13 +79,14 @@ static void *gx_audio_init(const char *device, AIInit(NULL); AIRegisterDMACallback(dma_callback); - //ranges 0-32000 (default low) and 40000-47999 (in settings going down from 48000) -> set to 32000 hz + /* Ranges 0-32000 (default low) and 40000-47999 + (in settings going down from 48000) -> set to 32000 hz */ if (rate <= 32000 || (rate >= 40000 && rate < 48000)) { AISetDSPSampleRate(AI_SAMPLERATE_32KHZ); *new_rate = 32000; } - else //ranges 32001-39999 (in settings going up from 32000) and 48000-max (default high) -> set to 48000 hz + else /* Ranges 32001-39999 (in settings going up from 32000) and 48000-max (default high) -> set to 48000 hz */ { AISetDSPSampleRate(AI_SAMPLERATE_48KHZ); *new_rate = 48000; @@ -93,7 +94,7 @@ static void *gx_audio_init(const char *device, wa->dma_write = BLOCKS - 1; DCFlushRange(wa->data, sizeof(wa->data)); - stop_audio = false; + stop_audio = false; AIInitDMA((uint32_t)wa->data[wa->dma_next], CHUNK_SIZE); AIStartDMA(); diff --git a/audio/drivers/switch_thread_audio.c b/audio/drivers/switch_thread_audio.c index 3b58fd3c2a..3a530b24f0 100644 --- a/audio/drivers/switch_thread_audio.c +++ b/audio/drivers/switch_thread_audio.c @@ -274,7 +274,7 @@ fail_audio_output: fail_audio_ipc: switch_audio_ipc_finalize(); fail: - free(swa); // freeing a null ptr is valid + free(swa); /* freeing a NULL ptr is valid */ return NULL; } diff --git a/audio/librsound.c b/audio/librsound.c index bbd1c2d955..88a47a2256 100644 --- a/audio/librsound.c +++ b/audio/librsound.c @@ -94,7 +94,7 @@ **************************************************************************** */ -// Internal enumerations +/* Internal enumerations */ enum rsd_logtype { RSD_LOG_DEBUG = 0, @@ -111,7 +111,7 @@ enum rsd_conn_type RSD_CONN_PROTO = 0x100 }; -// Some logging macros. +/* Some logging macros. */ #define RSD_WARN(fmt, args...) #define RSD_ERR(fmt, args...) #define RSD_DEBUG(fmt, args...) @@ -159,7 +159,7 @@ static size_t rsnd_get_delay(rsound_t *rd); static size_t rsnd_get_ptr(rsound_t *rd); static int rsnd_reset(rsound_t *rd); -// Protocol functions +/* Protocol functions */ static int rsnd_send_identity_info(rsound_t *rd); static int rsnd_close_ctl(rsound_t *rd); static int rsnd_send_info_query(rsound_t *rd); @@ -328,7 +328,7 @@ static int rsnd_send_header_info(rsound_t *rd) uint16_t temp_bits = 8 * rsnd_format_to_samplesize(rd->format); uint16_t temp_format = rd->format; - // Checks the format for native endian which will need to be set properly. + /* Checks the format for native endian which will need to be set properly. */ switch ( temp_format ) { case RSD_S16_NE: @@ -365,7 +365,7 @@ static int rsnd_send_header_info(rsound_t *rd) to determine whether we're running it or not, so we can byte swap accordingly. Could determine this compile time, but it was simpler to do it this way. */ - // Fancy macros for embedding little endian values into the header. + /* Fancy macros for embedding little endian values into the header. */ #define SET32(buf,offset,x) (*((uint32_t*)(buf+offset)) = x) #define SET16(buf,offset,x) (*((uint16_t*)(buf+offset)) = x) @@ -383,7 +383,7 @@ static int rsnd_send_header_info(rsound_t *rd) LSB32(temp32); SET32(header, 16, temp32); - temp16 = 0; // PCM data + temp16 = 0; /* PCM data */ switch( rd->format ) { @@ -404,10 +404,10 @@ static int rsnd_send_header_info(rsound_t *rd) LSB16(temp16); SET16(header, 20, temp16); - // Channels here + /* Channels here */ LSB16(temp_channels); SET16(header, CHANNEL, temp_channels); - // Samples per sec + /* Samples per sec */ LSB32(temp_rate); SET32(header, RATE, temp_rate); @@ -419,7 +419,7 @@ static int rsnd_send_header_info(rsound_t *rd) LSB16(temp16); SET16(header, 32, temp16); - // Bits per sample + /* Bits per sample */ LSB16(temp_bits); SET16(header, FRAMESIZE, temp_bits); @@ -450,7 +450,7 @@ static int rsnd_get_backend_info ( rsound_t *rd ) #define LATENCY 0 #define CHUNKSIZE 1 - // Header is 2 uint32_t's. = 8 bytes. + /* Header is 2 uint32_t's. = 8 bytes. */ uint32_t rsnd_header[2] = {0}; if ( rsnd_recv_chunk(rd->conn.socket, rsnd_header, RSND_HEADER_SIZE, 1) != RSND_HEADER_SIZE ) @@ -470,7 +470,7 @@ static int rsnd_get_backend_info ( rsound_t *rd ) rd->backend_info.latency = rsnd_header[LATENCY]; rd->backend_info.chunk_size = rsnd_header[CHUNKSIZE]; -#define MAX_CHUNK_SIZE 1024 // We do not want larger chunk sizes than this. +#define MAX_CHUNK_SIZE 1024 /* We do not want larger chunk sizes than this. */ if ( rd->backend_info.chunk_size > MAX_CHUNK_SIZE || rd->backend_info.chunk_size <= 0 ) rd->backend_info.chunk_size = MAX_CHUNK_SIZE; @@ -487,7 +487,7 @@ static int rsnd_get_backend_info ( rsound_t *rd ) return -1; } - // Only bother with setting network buffer size if we're doing TCP. + /* Only bother with setting network buffer size if we're doing TCP. */ if ( rd->conn_type & RSD_CONN_TCP ) { #define MAX_TCP_BUFSIZE (1 << 14) @@ -507,17 +507,17 @@ static int rsnd_get_backend_info ( rsound_t *rd ) setsockopt(rd->conn.ctl_socket, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)); } - // Can we read the last 8 bytes so we can use the protocol interface? - // This is non-blocking. + /* Can we read the last 8 bytes so we can use the protocol interface? */ + /* This is non-blocking. */ if ( rsnd_recv_chunk(rd->conn.socket, rsnd_header, RSND_HEADER_SIZE, 0) == RSND_HEADER_SIZE ) rd->conn_type |= RSD_CONN_PROTO; else { RSD_DEBUG("[RSound] Failed to get new proto.\n"); } - // We no longer want to read from this socket. + /* We no longer want to read from this socket. */ #ifdef _WIN32 net_shutdown(rd->conn.socket, SD_RECEIVE); -#elif !defined(__APPLE__) // OSX doesn't seem to like shutdown() +#elif !defined(__APPLE__) /* OSX doesn't seem to like shutdown() */ net_shutdown(rd->conn.socket, SHUT_RD); #endif @@ -727,7 +727,7 @@ static int64_t rsnd_get_time_usec(void) { #if defined(_WIN32) static LARGE_INTEGER freq; - if (!freq.QuadPart && !QueryPerformanceFrequency(&freq)) // Frequency is guaranteed to not change. + if (!freq.QuadPart && !QueryPerformanceFrequency(&freq)) /* Frequency is guaranteed to not change. */ return 0; LARGE_INTEGER count; @@ -738,7 +738,7 @@ static int64_t rsnd_get_time_usec(void) return sysGetSystemTime(); #elif defined(GEKKO) return ticks_to_microsecs(gettime()); -#elif defined(__MACH__) // OSX doesn't have clock_gettime ... +#elif defined(__MACH__) /* OSX doesn't have clock_gettime ... */ clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); @@ -818,10 +818,14 @@ static size_t rsnd_fill_buffer(rsound_t *rd, const char *buf, size_t size) slock_lock(rd->thread.mutex); fifo_write(rd->fifo_buffer, buf, size); slock_unlock(rd->thread.mutex); - //RSD_DEBUG("[RSound] fill_buffer: Wrote to buffer.\n"); +#if 0 + RSD_DEBUG("[RSound] fill_buffer: Wrote to buffer.\n"); +#endif /* Send signal to thread that buffer has been updated */ - //RSD_DEBUG("[RSound] fill_buffer: Waking up thread.\n"); +#if 0 + RSD_DEBUG("[RSound] fill_buffer: Waking up thread.\n"); +#endif scond_signal(rd->thread.cond); return size; @@ -941,7 +945,7 @@ static int rsnd_close_ctl(rsound_t *rd) else if ( fd.revents & POLLHUP ) return 0; - // Let's wait for reply (or POLLHUP) + /* Let's wait for reply (or POLLHUP) */ fd.events = POLLIN; int index = 0; @@ -958,14 +962,14 @@ static int rsnd_close_ctl(rsound_t *rd) if (fd.revents & POLLIN) { const char *subchar; - - // We just read everything in large chunks until we find what we're looking for + /* We just read everything in large chunks until we find + * what we're looking for */ int rc = net_recv(rd->conn.ctl_socket, buf + index, RSD_PROTO_MAXSIZE*2 - 1 - index, 0); if (rc <= 0 ) return -1; - // Can we find it directly? + /* Can we find it directly? */ if ( strstr(buf, "RSD 12 CLOSECTL OK") != NULL ) break; else if ( strstr(buf, "RSD 15 CLOSECTL ERROR") != NULL ) @@ -989,8 +993,9 @@ static int rsnd_close_ctl(rsound_t *rd) return 0; } -// Sends delay info request to server on the ctl socket. This code section isn't critical, and will work if it works. -// It will never block. +/* Sends delay info request to server on the ctl socket. + * This code section isn't critical, and will work if it works. + * It will never block. */ static int rsnd_send_info_query(rsound_t *rd) { char tmpbuf[RSD_PROTO_MAXSIZE]; @@ -1007,15 +1012,15 @@ static int rsnd_send_info_query(rsound_t *rd) return 0; } -// We check if there's any pending delay information from the server. -// In that case, we read the packet. +/* We check if there's any pending delay information from the server. + * In that case, we read the packet. */ static int rsnd_update_server_info(rsound_t *rd) { long long int client_ptr = -1; long long int serv_ptr = -1; char temp[RSD_PROTO_MAXSIZE + 1] = {0}; - // We read until we have the last (most recent) data in the network buffer. + /* We read until we have the last (most recent) data in the network buffer. */ for (;;) { ssize_t rc; @@ -1023,7 +1028,7 @@ static int rsnd_update_server_info(rsound_t *rd) char *tmpstr; memset(temp, 0, sizeof(temp)); - // We first recieve the small header. We just use the larger buffer as it is disposable. + /* We first recieve the small header. We just use the larger buffer as it is disposable. */ rc = rsnd_recv_chunk(rd->conn.ctl_socket, temp, RSD_PROTO_CHUNKSIZE, 0); if ( rc == 0 ) break; @@ -1035,22 +1040,22 @@ static int rsnd_update_server_info(rsound_t *rd) if (!(substr = strstr(temp, "RSD"))) return -1; - // Jump over "RSD" in header + /* Jump over "RSD" in header */ substr += 3; - // The length of the argument message is stored in the small 8 byte header. + /* The length of the argument message is stored in the small 8 byte header. */ long int len = strtol(substr, NULL, 0); - // Recieve the rest of the data. + /* Recieve the rest of the data. */ if ( rsnd_recv_chunk(rd->conn.ctl_socket, temp, len, 0) < len ) return -1; - // We only bother if this is an INFO message. + /* We only bother if this is an INFO message. */ substr = strstr(temp, "INFO"); if (!substr) continue; - // Jump over "INFO" in header + /* Jump over "INFO" in header */ substr += 4; client_ptr = strtoull(substr, &tmpstr, 0); @@ -1074,7 +1079,7 @@ static int rsnd_update_server_info(rsound_t *rd) RSD_DEBUG("[RSound] Delay: %d, Delta: %d.\n", delay, delta); - // We only update the pointer if the data we got is quite recent. + /* We only update the pointer if the data we got is quite recent. */ if ( rd->total_written - client_ptr < 4 * rd->backend_info.chunk_size && rd->total_written > client_ptr ) { int offset_delta = delta - delay; @@ -1094,7 +1099,7 @@ static int rsnd_update_server_info(rsound_t *rd) return 0; } -// Sort of simulates the behavior of pthread_cancel() +/* Sort of simulates the behavior of pthread_cancel() */ #define _TEST_CANCEL() \ if ( !rd->thread_active ) \ break @@ -1115,8 +1120,8 @@ static void rsnd_thread ( void * thread_data ) { _TEST_CANCEL(); - // We ask the server to send its latest backend data. Do not really care about errors atm. - // We only bother to check after 1 sec of audio has been played, as it might be quite inaccurate in the start of the stream. + /* We ask the server to send its latest backend data. Do not really care about errors atm. + * We only bother to check after 1 sec of audio has been played, as it might be quite inaccurate in the start of the stream. */ if ( (rd->conn_type & RSD_CONN_PROTO) && (rd->total_written > rd->channels * rd->rate * rd->samplesize) ) { rsnd_send_info_query(rd); @@ -1175,8 +1180,9 @@ static void rsnd_thread ( void * thread_data ) if ( rd->thread_active ) { - // There is a very slim change of getting a deadlock using the cond_wait scheme. - // This solution is rather dirty, but avoids complete deadlocks at the very least. + /* There is a very slim change of getting a deadlock using the cond_wait scheme. + * This solution is rather dirty, but avoids complete deadlocks at the very least. + */ slock_lock(rd->thread.cond_mutex); scond_signal(rd->thread.cond); @@ -1243,9 +1249,10 @@ static void rsnd_cb_thread(void *thread_data) } else { - // The network might do things in large chunks, so it may request large amounts of data in short periods of time. - // This breaks when the caller cannot buffer up big buffers beforehand, so do short sleeps inbetween. - // This is somewhat dirty, but I cannot see a better solution + /* The network might do things in large chunks, so it may request large amounts of data in short periods of time. + * This breaks when the caller cannot buffer up big buffers beforehand, so do short sleeps inbetween. + * This is somewhat dirty, but I cannot see a better solution + */ retro_sleep(1); } } @@ -1306,13 +1313,13 @@ static int rsnd_reset(rsound_t *rd) int rsd_stop(rsound_t *rd) { + const char buf[] = "RSD 5 STOP"; + retro_assert(rd != NULL); rsnd_stop_thread(rd); - const char buf[] = "RSD 5 STOP"; - - // Do not really care about errors here. - // The socket will be closed down in any case in rsnd_reset(). + /* Do not really care about errors here. + * The socket will be closed down in any case in rsnd_reset(). */ rsnd_send_chunk(rd->conn.ctl_socket, buf, strlen(buf), 0); rsnd_reset(rd); @@ -1364,7 +1371,7 @@ int rsd_exec(rsound_t *rsound) retro_assert(rsound != NULL); RSD_DEBUG("[RSound] rsd_exec().\n"); - // Makes sure we have a working connection + /* Makes sure we have a working connection */ if ( rsound->conn.socket < 0 ) { RSD_DEBUG("[RSound] Calling rsd_start().\n"); @@ -1459,7 +1466,7 @@ int rsd_set_param(rsound_t *rd, enum rsd_settings option, void* param) rd->max_latency = *((int*)param); break; - // Checks if format is valid. + /* Checks if format is valid. */ case RSD_FORMAT: rd->format = (uint16_t)(*((int*)param)); rd->samplesize = rsnd_format_to_samplesize(rd->format); @@ -1555,7 +1562,8 @@ int rsd_pause(rsound_t* rsound, int enable) int rsd_init(rsound_t** rsound) { - *rsound = calloc(1, sizeof(rsound_t)); + int format = RSD_S16_LE; + *rsound = calloc(1, sizeof(rsound_t)); if (*rsound == NULL) return -1; @@ -1569,8 +1577,7 @@ int rsd_init(rsound_t** rsound) (*rsound)->cb_lock = slock_new(); (*rsound)->thread.cond = scond_new(); - // Assumes default of S16_LE samples. - int format = RSD_S16_LE; + /* Assumes default of S16_LE samples. */ rsd_set_param(*rsound, RSD_FORMAT, &format); rsd_set_param(*rsound, RSD_HOST, RSD_DEFAULT_HOST); diff --git a/gfx/common/ctr_common.h b/gfx/common/ctr_common.h index 986f958750..b6c1245acd 100644 --- a/gfx/common/ctr_common.h +++ b/gfx/common/ctr_common.h @@ -205,4 +205,4 @@ static INLINE void ctr_set_scale_vector(ctr_scale_vector_t* vec, vec->v = -1.0 / texture_height; } -#endif // CTR_COMMON_H__ +#endif /* CTR_COMMON_H__ */ diff --git a/gfx/common/fpga_common.h b/gfx/common/fpga_common.h index 3989ae9597..97fc55cdab 100644 --- a/gfx/common/fpga_common.h +++ b/gfx/common/fpga_common.h @@ -18,7 +18,7 @@ #ifndef __FPGA_COMMON_H #define __FPGA_COMMON_H -#define NUMBER_OF_WRITE_FRAMES 1//XPAR_AXIVDMA_0_NUM_FSTORES +#define NUMBER_OF_WRITE_FRAMES 1 /* XPAR_AXIVDMA_0_NUM_FSTORES */ #define STORAGE_SIZE NUMBER_OF_WRITE_FRAMES * ((1920*1080)<<2) #define FRAME_SIZE (STORAGE_SIZE / NUMBER_OF_WRITE_FRAMES) diff --git a/gfx/common/metal/metal_renderer.m b/gfx/common/metal/metal_renderer.m index 7ef27e5d85..2c8fd2a8f4 100644 --- a/gfx/common/metal/metal_renderer.m +++ b/gfx/common/metal/metal_renderer.m @@ -159,9 +159,9 @@ matrix_float4x4 matrix_rotate_z(float rot) id _drawable; video_viewport_t _viewport; id _samplers[TEXTURE_FILTER_MIPMAP_NEAREST + 1]; - Filter *_filters[RPixelFormatCount]; // convert to bgra8888 + Filter *_filters[RPixelFormatCount]; /* convert to BGRA8888 */ - // main render pass state + /* Main render pass state */ id _rce; id _blitCommandBuffer; @@ -402,9 +402,9 @@ matrix_float4x4 matrix_rotate_z(float rot) { vals = [MTLFunctionConstantValues new]; float values[3] = { - 1.25f, // baseScale - 0.50f, // density - 0.15f, // speed + 1.25f, /* baseScale */ + 0.50f, /* density */ + 0.15f, /* speed */ }; [vals setConstantValue:&values[0] type:MTLDataTypeFloat withName:@"snowBaseScale"]; [vals setConstantValue:&values[1] type:MTLDataTypeFloat withName:@"snowDensity"]; @@ -423,9 +423,9 @@ matrix_float4x4 matrix_rotate_z(float rot) { vals = [MTLFunctionConstantValues new]; float values[3] = { - 3.50f, // baseScale - 0.70f, // density - 0.25f, // speed + 3.50f, /* baseScale */ + 0.70f, /* density */ + 0.25f, /* speed */ }; [vals setConstantValue:&values[0] type:MTLDataTypeFloat withName:@"snowBaseScale"]; [vals setConstantValue:&values[1] type:MTLDataTypeFloat withName:@"snowDensity"]; @@ -633,8 +633,10 @@ matrix_float4x4 matrix_rotate_z(float rot) if (_captureEnabled == captureEnabled) return; - _captureEnabled = captureEnabled; - //_layer.framebufferOnly = !captureEnabled; + _captureEnabled = captureEnabled; +#if 0 + _layer.framebufferOnly = !captureEnabled; +#endif } - (bool)captureEnabled @@ -772,7 +774,7 @@ matrix_float4x4 matrix_rotate_z(float rot) [bce endEncoding]; } #endif - // pending blits for mipmaps or render passes for slang shaders + /* Pending blits for mipmaps or render passes for slang shaders */ [_blitCommandBuffer commit]; [_blitCommandBuffer waitUntilCompleted]; _blitCommandBuffer = nil; @@ -829,7 +831,7 @@ matrix_float4x4 matrix_rotate_z(float rot) id _device; NSUInteger _blockLen; BufferNode *_head; - NSUInteger _offset; // offset into _current + NSUInteger _offset; /* offset into _current */ BufferNode *_current; NSUInteger _length; NSUInteger _allocated; @@ -1285,13 +1287,13 @@ static const NSUInteger kConstantAlignment = 4; @implementation TexturedView { Context *_context; - id _texture; // optimal render texture + id _texture; /* Optimal render texture */ Vertex _v[4]; - CGSize _size; // size of view in pixels + CGSize _size; /* Size of view in pixels */ CGRect _frame; NSUInteger _bpp; - id _src; // source texture + id _src; /* Source texture */ bool _srcDirty; } diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index 5ebaeac1e4..594455bd67 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -45,33 +45,24 @@ #define STRUCT_ASSIGN(x, y) \ { \ NSObject * __y = y; \ - if (x != nil) { \ + if (x != nil) \ + { \ NSObject * __foo = (__bridge_transfer NSObject *)(__bridge void *)(x); \ __foo = nil; \ x = (__bridge __typeof__(x))nil; \ } \ if (__y != nil) \ - x = (__bridge __typeof__(x))(__bridge_retained void *)((NSObject *)__y); \ - } + x = (__bridge __typeof__(x))(__bridge_retained void *)((NSObject *)__y) @implementation MetalView #if !defined(HAVE_COCOATOUCH) -- (void)keyDown:(NSEvent*)theEvent -{ -} +- (void)keyDown:(NSEvent*)theEvent { } #endif /* Stop the annoying sound when pressing a key. */ -- (BOOL)acceptsFirstResponder -{ - return YES; -} - -- (BOOL)isFlipped -{ - return YES; -} +- (BOOL)acceptsFirstResponder { return YES; } +- (BOOL)isFlipped { return YES; } @end #pragma mark - private categories @@ -110,15 +101,14 @@ CAMetalLayer *_layer; - // render target layer state + /* Render target layer state */ id _t_pipelineState; id _t_pipelineStateNoAlpha; id _samplerStateLinear; id _samplerStateNearest; - // other state - Uniforms _viewportMVP; + Uniforms _viewportMVP; /* Other state */ } - (instancetype)initWithVideo:(const video_info_t *)video @@ -127,61 +117,61 @@ { if (self = [super init]) { - _device = MTLCreateSystemDefaultDevice(); - MetalView *view = (MetalView *)apple_platform.renderView; - view.device = _device; - view.delegate = self; - _layer = (CAMetalLayer *)view.layer; + gfx_ctx_mode_t mode; + _device = MTLCreateSystemDefaultDevice(); + MetalView *view = (MetalView *)apple_platform.renderView; + view.device = _device; + view.delegate = self; + _layer = (CAMetalLayer *)view.layer; if (![self _initMetal]) - { return nil; - } - _video = *video; - _viewport = (video_viewport_t *)calloc(1, sizeof(video_viewport_t)); + _video = *video; + _viewport = (video_viewport_t *)calloc(1, sizeof(video_viewport_t)); _viewportMVP.projectionMatrix = matrix_proj_ortho(0, 1, 0, 1); - _keepAspect = _video.force_aspect; + _keepAspect = _video.force_aspect; - gfx_ctx_mode_t mode = { - .width = _video.width, - .height = _video.height, - .fullscreen = _video.fullscreen, - }; + mode.width = _video.width; + mode.height = _video.height; + mode.fullscreen = _video.fullscreen; if (mode.width == 0 || mode.height == 0) { - // 0 indicates full screen, so we'll use the view's dimensions, which should already be full screen - // If this turns out to be the wrong assumption, we can use NSScreen to query the dimensions + /* 0 indicates full screen, so we'll use the view's dimensions, + * which should already be full screen. + * If this turns out to be the wrong assumption, + * we can use NSScreen to query the dimensions */ CGSize size = view.frame.size; - mode.width = (unsigned int)size.width; + mode.width = (unsigned int)size.width; mode.height = (unsigned int)size.height; } [apple_platform setVideoMode:mode]; - *input = NULL; + *input = NULL; *inputData = NULL; - // graphics display driver - _display = [[MenuDisplay alloc] initWithContext:_context]; + /* Graphics display driver */ + _display = [[MenuDisplay alloc] initWithContext:_context]; + /* Menu view */ + _menu = [[MetalMenu alloc] initWithContext:_context]; - // menu view - _menu = [[MetalMenu alloc] initWithContext:_context]; - - // frame buffer view + /* Framebuffer view */ { - ViewDescriptor *vd = [ViewDescriptor new]; - vd.format = _video.rgb32 ? RPixelFormatBGRX8Unorm : RPixelFormatB5G6R5Unorm; - vd.size = CGSizeMake(video->width, video->height); - vd.filter = _video.smooth ? RTextureFilterLinear : RTextureFilterNearest; - _frameView = [[FrameView alloc] initWithDescriptor:vd context:_context]; + ViewDescriptor *vd = [ViewDescriptor new]; + vd.format = _video.rgb32 + ? RPixelFormatBGRX8Unorm + : RPixelFormatB5G6R5Unorm; + vd.size = CGSizeMake(video->width, video->height); + vd.filter = _video.smooth ? RTextureFilterLinear : RTextureFilterNearest; + _frameView = [[FrameView alloc] initWithDescriptor:vd context:_context]; _frameView.viewport = _viewport; [_frameView setFilteringIndex:0 smooth:video->smooth]; } - // overlay view + /* Overlay view */ _overlay = [[Overlay alloc] initWithContext:_context]; font_driver_init_osd((__bridge void *)self, @@ -207,34 +197,35 @@ { _library = [_device newDefaultLibrary]; _context = [[Context alloc] initWithDevice:_device - layer:_layer - library:_library]; + layer:_layer library:_library]; { - MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; - vd.attributes[0].offset = 0; - vd.attributes[0].format = MTLVertexFormatFloat3; - vd.attributes[1].offset = offsetof(Vertex, texCoord); - vd.attributes[1].format = MTLVertexFormatFloat2; - vd.layouts[0].stride = sizeof(Vertex); - - MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new]; - psd.label = @"Pipeline+Alpha"; - - MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0]; - ca.pixelFormat = _layer.pixelFormat; - ca.blendingEnabled = YES; - ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; - ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; - ca.destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha; - ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha; - - psd.sampleCount = 1; - psd.vertexDescriptor = vd; - psd.vertexFunction = [_library newFunctionWithName:@"basic_vertex_proj_tex"]; - psd.fragmentFunction = [_library newFunctionWithName:@"basic_fragment_proj_tex"]; - NSError *err; + MTLRenderPipelineDescriptor *psd; + MTLRenderPipelineColorAttachmentDescriptor *ca; + MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; + vd.attributes[0].offset = 0; + vd.attributes[0].format = MTLVertexFormatFloat3; + vd.attributes[1].offset = offsetof(Vertex, texCoord); + vd.attributes[1].format = MTLVertexFormatFloat2; + vd.layouts[0].stride = sizeof(Vertex); + + psd = [MTLRenderPipelineDescriptor new]; + psd.label = @"Pipeline+Alpha"; + + ca = psd.colorAttachments[0]; + ca.pixelFormat = _layer.pixelFormat; + ca.blendingEnabled = YES; + ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; + ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; + ca.destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha; + ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha; + + psd.sampleCount = 1; + psd.vertexDescriptor = vd; + psd.vertexFunction = [_library newFunctionWithName:@"basic_vertex_proj_tex"]; + psd.fragmentFunction = [_library newFunctionWithName:@"basic_fragment_proj_tex"]; + _t_pipelineState = [_device newRenderPipelineStateWithDescriptor:psd error:&err]; if (err != nil) { @@ -242,9 +233,9 @@ return NO; } - psd.label = @"Pipeline+No Alpha"; - ca.blendingEnabled = NO; - _t_pipelineStateNoAlpha = [_device newRenderPipelineStateWithDescriptor:psd error:&err]; + psd.label = @"Pipeline+No Alpha"; + ca.blendingEnabled = NO; + _t_pipelineStateNoAlpha = [_device newRenderPipelineStateWithDescriptor:psd error:&err]; if (err != nil) { RARCH_ERR("[Metal]: error creating pipeline state (no alpha) %s\n", err.localizedDescription.UTF8String); @@ -254,11 +245,11 @@ { MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new]; - _samplerStateNearest = [_device newSamplerStateWithDescriptor:sd]; + _samplerStateNearest = [_device newSamplerStateWithDescriptor:sd]; - sd.minFilter = MTLSamplerMinMagFilterLinear; - sd.magFilter = MTLSamplerMinMagFilterLinear; - _samplerStateLinear = [_device newSamplerStateWithDescriptor:sd]; + sd.minFilter = MTLSamplerMinMagFilterLinear; + sd.magFilter = MTLSamplerMinMagFilterLinear; + _samplerStateLinear = [_device newSamplerStateWithDescriptor:sd]; } return YES; @@ -266,37 +257,32 @@ - (void)setViewportWidth:(unsigned)width height:(unsigned)height forceFull:(BOOL)forceFull allowRotate:(BOOL)allowRotate { - _viewport->full_width = width; - _viewport->full_height = height; + _viewport->full_width = width; + _viewport->full_height = height; video_driver_set_size(_viewport->full_width, _viewport->full_height); - _layer.drawableSize = CGSizeMake(width, height); + _layer.drawableSize = CGSizeMake(width, height); video_driver_update_viewport(_viewport, forceFull, _keepAspect); - - // update matrix - _context.viewport = _viewport; + _context.viewport = _viewport; /* Update matrix */ _viewportMVP.outputSize = simd_make_float2(_viewport->full_width, _viewport->full_height); } #pragma mark - video -- (void)setVideo:(const video_info_t *)video -{ - -} +- (void)setVideo:(const video_info_t *)video { } - (bool)renderFrame:(const void *)frame - data:(void*)data - width:(unsigned)width + data:(void*)data + width:(unsigned)width height:(unsigned)height - frameCount:(uint64_t)frameCount - pitch:(unsigned)pitch - msg:(const char *)msg - info:(video_frame_info_t *)video_info + frameCount:(uint64_t)frameCount + pitch:(unsigned)pitch + msg:(const char *)msg + info:(video_frame_info_t *)video_info { @autoreleasepool { - bool statistics_show = video_info->statistics_show; + bool statistics_show = video_info->statistics_show; [self _beginFrame]; @@ -391,9 +377,9 @@ width += x2; height += y2; - r = bgcolor_red / 255.0f; + r = bgcolor_red / 255.0f; g = bgcolor_green / 255.0f; - b = bgcolor_blue / 255.0f; + b = bgcolor_blue / 255.0f; a = bgcolor_opacity; [_context resetRenderViewport:kFullscreenViewport]; @@ -418,7 +404,7 @@ { id rce = _context.rce; - /* draw back buffer */ + /* Draw back buffer */ [rce pushDebugGroup:@"core frame"]; [_frameView drawWithContext:_context]; @@ -427,13 +413,9 @@ [rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms]; [rce setRenderPipelineState:_t_pipelineStateNoAlpha]; if (_frameView.filter == RTextureFilterNearest) - { [rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw]; - } else - { [rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw]; - } [_frameView drawWithEncoder:rce]; } [rce popDebugGroup]; @@ -455,13 +437,9 @@ [rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms]; [rce setRenderPipelineState:_t_pipelineState]; if (_menu.view.filter == RTextureFilterNearest) - { [rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw]; - } else - { [rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw]; - } [_menu.view drawWithEncoder:rce]; [rce popDebugGroup]; } @@ -476,31 +454,23 @@ #endif } -- (void)_endFrame -{ - [_context end]; -} - -- (void)setNeedsResize -{ - // TODO(sgc): resize all drawables -} +/* TODO/FIXME (sgc): resize all drawables */ +- (void)setNeedsResize { } +- (void)_endFrame { [_context end]; } - (void)setRotation:(unsigned)rotation { [_context setRotation:rotation]; } - -- (Uniforms *)viewportMVP -{ - return &_viewportMVP; -} +- (Uniforms *)viewportMVP { return &_viewportMVP; } #pragma mark - MTKViewDelegate - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size { +#ifndef NDEBUG NSLog(@"mtkView drawableSizeWillChange to: %f x %f",size.width,size.height); +#endif #ifdef HAVE_COCOATOUCH CGFloat scale = [[UIScreen mainScreen] scale]; [self setViewportWidth:(unsigned int)view.bounds.size.width*scale height:(unsigned int)view.bounds.size.height*scale forceFull:NO allowRotate:YES]; @@ -509,11 +479,7 @@ #endif } -- (void)drawInMTKView:(MTKView *)view -{ - -} - +- (void)drawInMTKView:(MTKView *)view { } @end @implementation MetalMenu @@ -526,9 +492,7 @@ - (instancetype)initWithContext:(Context *)context { if (self = [super init]) - { _context = context; - } return self; } @@ -561,19 +525,17 @@ if (!(CGSizeEqualToSize(_view.size, size) && _view.format == format && _view.filter == filter)) - { _view = nil; - } } if (!_view) { ViewDescriptor *vd = [ViewDescriptor new]; - vd.format = format; - vd.filter = filter; - vd.size = size; - _view = [[TexturedView alloc] initWithDescriptor:vd context:_context]; - _view.visible = _enabled; + vd.format = format; + vd.filter = filter; + vd.size = size; + _view = [[TexturedView alloc] initWithDescriptor:vd context:_context]; + _view.visible = _enabled; } } @@ -632,14 +594,14 @@ typedef struct MTLALIGN(16) @implementation FrameView { Context *_context; - id _texture; // final render texture + id _texture; /* Final render texture */ Vertex _v[4]; VertexSlang _vertex[4]; - CGSize _size; // size of view in pixels + CGSize _size; /* Size of view in pixels */ CGRect _frame; NSUInteger _bpp; - id _src; // src texture + id _src; /* Source texture */ bool _srcDirty; id _samplers[RARCH_FILTER_MAX][RARCH_WRAP_MAX]; @@ -657,28 +619,25 @@ typedef struct MTLALIGN(16) self = [super init]; if (self) { - _context = c; - _format = d.format; - _bpp = RPixelFormatToBPP(_format); - _filter = d.filter; - if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm) - { - _drawState = ViewDrawStateEncoder; - } + _context = c; + _format = d.format; + _bpp = RPixelFormatToBPP(_format); + _filter = d.filter; + if ( _format == RPixelFormatBGRA8Unorm + || _format == RPixelFormatBGRX8Unorm) + _drawState = ViewDrawStateEncoder; else - { - _drawState = ViewDrawStateAll; - } - _visible = YES; - _engine.mvp = matrix_proj_ortho(0, 1, 0, 1); + _drawState = ViewDrawStateAll; + _visible = YES; + _engine.mvp = matrix_proj_ortho(0, 1, 0, 1); [self _initSamplers]; - self.size = d.size; - self.frame = CGRectMake(0, 0, 1, 1); + self.size = d.size; + self.frame = CGRectMake(0, 0, 1, 1); resize_render_targets = YES; - // init slang vertex buffer - VertexSlang v[4] = { + /* Initialize slang vertex buffer */ + VertexSlang v[4] = { {simd_make_float4(0, 1, 0, 1), simd_make_float2(0, 1)}, {simd_make_float4(1, 1, 0, 1), simd_make_float2(1, 1)}, {simd_make_float4(0, 0, 0, 1), simd_make_float2(0, 0)}, @@ -691,11 +650,14 @@ typedef struct MTLALIGN(16) - (void)_initSamplers { + int i; MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new]; /* Initialize samplers */ - for (unsigned i = 0; i < RARCH_WRAP_MAX; i++) + for (i = 0; i < RARCH_WRAP_MAX; i++) { + id ss; + switch (i) { case RARCH_WRAP_BORDER: @@ -721,18 +683,18 @@ typedef struct MTLALIGN(16) default: continue; } - sd.tAddressMode = sd.sAddressMode; - sd.rAddressMode = sd.sAddressMode; - sd.minFilter = MTLSamplerMinMagFilterLinear; - sd.magFilter = MTLSamplerMinMagFilterLinear; + sd.tAddressMode = sd.sAddressMode; + sd.rAddressMode = sd.sAddressMode; + sd.minFilter = MTLSamplerMinMagFilterLinear; + sd.magFilter = MTLSamplerMinMagFilterLinear; - id ss = [_context.device newSamplerStateWithDescriptor:sd]; - _samplers[RARCH_FILTER_LINEAR][i] = ss; + ss = [_context.device newSamplerStateWithDescriptor:sd]; + _samplers[RARCH_FILTER_LINEAR][i] = ss; - sd.minFilter = MTLSamplerMinMagFilterNearest; - sd.magFilter = MTLSamplerMinMagFilterNearest; + sd.minFilter = MTLSamplerMinMagFilterNearest; + sd.magFilter = MTLSamplerMinMagFilterNearest; - ss = [_context.device newSamplerStateWithDescriptor:sd]; + ss = [_context.device newSamplerStateWithDescriptor:sd]; _samplers[RARCH_FILTER_NEAREST][i] = ss; } } @@ -757,12 +719,14 @@ typedef struct MTLALIGN(16) resize_render_targets = YES; - if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm) + if ( _format != RPixelFormatBGRA8Unorm + && _format != RPixelFormatBGRX8Unorm) { - MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint - width:(NSUInteger)size.width - height:(NSUInteger)size.height - mipmapped:NO]; + MTLTextureDescriptor *td = [MTLTextureDescriptor + texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint + width:(NSUInteger)size.width + height:(NSUInteger)size.height + mipmapped:NO]; _src = [_context.device newTextureWithDescriptor:td]; } } @@ -777,17 +741,14 @@ typedef struct MTLALIGN(16) if (CGRectEqualToRect(_frame, frame)) return; - _frame = frame; - - // update vertices - CGPoint o = frame.origin; - CGSize s = frame.size; - - CGFloat l = o.x; - CGFloat t = o.y; - CGFloat r = o.x + s.width; - CGFloat b = o.y + s.height; - + _frame = frame; + /* Update vertices */ + CGPoint o = frame.origin; + CGSize s = frame.size; + CGFloat l = o.x; + CGFloat t = o.y; + CGFloat r = o.x + s.width; + CGFloat b = o.y + s.height; Vertex v[4] = { {simd_make_float3(l, b, 0), simd_make_float2(0, 1)}, {simd_make_float3(r, b, 0), simd_make_float2(1, 1)}, @@ -797,10 +758,7 @@ typedef struct MTLALIGN(16) memcpy(_v, v, sizeof(_v)); } -- (CGRect)frame -{ - return _frame; -} +- (CGRect)frame { return _frame; } - (void)_convertFormat { @@ -840,24 +798,23 @@ typedef struct MTLALIGN(16) if (_engine.frame.texture[0].size_data.x != _size.width || _engine.frame.texture[0].size_data.y != _size.height) { - MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm - width:(NSUInteger)_size.width - height:(NSUInteger)_size.height - mipmapped:false]; - td.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite; + MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm width:(NSUInteger)_size.width height:(NSUInteger)_size.height mipmapped:false]; + td.usage = MTLTextureUsageShaderRead + | MTLTextureUsageShaderWrite; [self _initTexture:&_engine.frame.texture[0] withDescriptor:td]; } } - (bool)readViewport:(uint8_t *)buffer isIdle:(bool)isIdle { + bool res; bool enabled = _context.captureEnabled; if (!enabled) _context.captureEnabled = YES; video_driver_cached_frame(); - bool res = [_context readBackBuffer:buffer]; + res = [_context readBackBuffer:buffer]; if (!enabled) _context.captureEnabled = NO; @@ -915,11 +872,10 @@ typedef struct MTLALIGN(16) - (void)_initHistory { int i; - MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm - width:(NSUInteger)_size.width - height:(NSUInteger)_size.height - mipmapped:false]; - td.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite | MTLTextureUsageRenderTarget; + MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm width:(NSUInteger)_size.width height:(NSUInteger)_size.height mipmapped:false]; + td.usage = MTLTextureUsageShaderRead + | MTLTextureUsageShaderWrite + | MTLTextureUsageRenderTarget; for (i = 0; i < _shader->history_size + 1; i++) [self _initTexture:&_engine.frame.texture[i] withDescriptor:td]; @@ -939,7 +895,10 @@ typedef struct MTLALIGN(16) - (void)drawWithContext:(Context *)ctx { - unsigned i; + int i; + id cb; + MTLRenderPassDescriptor *rpd; + _texture = _engine.frame.texture[0].view; [self _convertFormat]; @@ -956,23 +915,25 @@ typedef struct MTLALIGN(16) } } - id cb = ctx.blitCommandBuffer; + cb = ctx.blitCommandBuffer; [cb pushDebugGroup:@"shaders"]; - MTLRenderPassDescriptor *rpd = [MTLRenderPassDescriptor new]; - rpd.colorAttachments[0].loadAction = MTLLoadActionDontCare; + rpd = [MTLRenderPassDescriptor new]; + rpd.colorAttachments[0].loadAction = MTLLoadActionDontCare; rpd.colorAttachments[0].storeAction = MTLStoreActionStore; - for (unsigned i = 0; i < _shader->passes; i++) + for (i = 0; i < _shader->passes; i++) { + int j; + NSURL *shader_path; + __unsafe_unretained id textures[SLANG_NUM_BINDINGS] = {NULL}; + id samplers[SLANG_NUM_BINDINGS] = {NULL}; + texture_sem_t *texture_sem = NULL; id rce = nil; - - BOOL backBuffer = (_engine.pass[i].rt.view == nil); + BOOL backBuffer = (_engine.pass[i].rt.view == nil); if (backBuffer) - { rce = _context.rce; - } else { rpd.colorAttachments[0].texture = _engine.pass[i].rt.view; @@ -981,8 +942,8 @@ typedef struct MTLALIGN(16) [rce setRenderPipelineState:_engine.pass[i]._state]; - NSURL *shaderPath = [NSURL fileURLWithPath:_engine.pass[i]._state.label]; - rce.label = shaderPath.lastPathComponent.stringByDeletingPathExtension; + shader_path = [NSURL fileURLWithPath:_engine.pass[i]._state.label]; + rce.label = shader_path.lastPathComponent.stringByDeletingPathExtension; _engine.pass[i].frame_count = (uint32_t)_frameCount; if (_shader->pass[i].frame_count_mod) @@ -996,14 +957,14 @@ typedef struct MTLALIGN(16) _engine.pass[i].frame_direction = 1; #endif - for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++) + for (j = 0; j < SLANG_CBUFFER_MAX; j++) { - id buffer = _engine.pass[i].buffers[j]; + id buffer = _engine.pass[i].buffers[j]; cbuffer_sem_t *buffer_sem = &_engine.pass[i].semantics.cbuffers[j]; if (buffer_sem->stage_mask && buffer_sem->uniforms) { - void *data = buffer.contents; + void *data = buffer.contents; uniform_sem_t *uniform = buffer_sem->uniforms; while (uniform->size) @@ -1024,27 +985,21 @@ typedef struct MTLALIGN(16) } } - __unsafe_unretained id textures[SLANG_NUM_BINDINGS] = {NULL}; - id samplers[SLANG_NUM_BINDINGS] = {NULL}; + texture_sem = _engine.pass[i].semantics.textures; - texture_sem_t *texture_sem = _engine.pass[i].semantics.textures; while (texture_sem->stage_mask) { - int binding = texture_sem->binding; + int binding = texture_sem->binding; id tex = (__bridge id)*(void **)texture_sem->texture_data; - textures[binding] = tex; - samplers[binding] = _samplers[texture_sem->filter][texture_sem->wrap]; + textures[binding] = tex; + samplers[binding] = _samplers[texture_sem->filter][texture_sem->wrap]; texture_sem++; } if (backBuffer) - { [rce setViewport:_engine.frame.viewport]; - } else - { [rce setViewport:_engine.pass[i].viewport]; - } [rce setFragmentTextures:textures withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)]; [rce setFragmentSamplerStates:samplers withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)]; @@ -1052,9 +1007,7 @@ typedef struct MTLALIGN(16) [rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; if (!backBuffer) - { [rce endEncoding]; - } _texture = _engine.pass[i].rt.view; } @@ -1069,10 +1022,13 @@ typedef struct MTLALIGN(16) - (void)_updateRenderTargets { - if (!_shader || !resize_render_targets) return; + int i; + NSUInteger width, height; + if (!_shader || !resize_render_targets) + return; - // release existing targets - for (int i = 0; i < _shader->passes; i++) + /* release existing targets */ + for (i = 0; i < _shader->passes; i++) { STRUCT_ASSIGN(_engine.pass[i].rt.view, nil); STRUCT_ASSIGN(_engine.pass[i].feedback.view, nil); @@ -1080,10 +1036,12 @@ typedef struct MTLALIGN(16) memset(&_engine.pass[i].feedback, 0, sizeof(_engine.pass[i].feedback)); } - NSUInteger width = (NSUInteger)_size.width, height = (NSUInteger)_size.height; + width = (NSUInteger)_size.width; + height = (NSUInteger)_size.height; - for (unsigned i = 0; i < _shader->passes; i++) + for (i = 0; i < _shader->passes; i++) { + MTLPixelFormat fmt; struct video_shader_pass *shader_pass = &_shader->pass[i]; if (shader_pass->fbo.valid) @@ -1137,29 +1095,30 @@ typedef struct MTLALIGN(16) } /* Updating framebuffer size */ + fmt = SelectOptimalPixelFormat(glslang_format_to_metal( + _engine.pass[i].semantics.format)); - MTLPixelFormat fmt = SelectOptimalPixelFormat(glslang_format_to_metal(_engine.pass[i].semantics.format)); if ((i != (_shader->passes - 1)) || (width != _viewport->width) || (height != _viewport->height) || fmt != MTLPixelFormatBGRA8Unorm) { - _engine.pass[i].viewport.width = width; - _engine.pass[i].viewport.height = height; - _engine.pass[i].viewport.znear = 0.0; - _engine.pass[i].viewport.zfar = 1.0; + MTLTextureDescriptor *td; - MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:fmt - width:width - height:height - mipmapped:false]; - td.storageMode = MTLStorageModePrivate; - td.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget; + _engine.pass[i].viewport.width = width; + _engine.pass[i].viewport.height = height; + _engine.pass[i].viewport.znear = 0.0f; + _engine.pass[i].viewport.zfar = 1.0f; + + td = [MTLTextureDescriptor + texture2DDescriptorWithPixelFormat:fmt width:width height:height + mipmapped:false]; + td.storageMode = MTLStorageModePrivate; + td.usage = MTLTextureUsageShaderRead + | MTLTextureUsageRenderTarget; [self _initTexture:&_engine.pass[i].rt withDescriptor:td]; if (shader_pass->feedback) - { [self _initTexture:&_engine.pass[i].feedback withDescriptor:td]; - } } else { @@ -1175,11 +1134,13 @@ typedef struct MTLALIGN(16) - (void)_freeVideoShader:(struct video_shader *)shader { + int i; if (!shader) return; - for (int i = 0; i < GFX_MAX_SHADERS; i++) + for (i = 0; i < GFX_MAX_SHADERS; i++) { + int j; STRUCT_ASSIGN(_engine.pass[i].rt.view, nil); STRUCT_ASSIGN(_engine.pass[i].feedback.view, nil); memset(&_engine.pass[i].rt, 0, sizeof(_engine.pass[i].rt)); @@ -1187,13 +1148,13 @@ typedef struct MTLALIGN(16) STRUCT_ASSIGN(_engine.pass[i]._state, nil); - for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++) + for (j = 0; j < SLANG_CBUFFER_MAX; j++) { STRUCT_ASSIGN(_engine.pass[i].buffers[j], nil); } } - for (int i = 0; i < GFX_MAX_TEXTURES; i++) + for (i = 0; i < GFX_MAX_TEXTURES; i++) { STRUCT_ASSIGN(_engine.luts[i].view, nil); } @@ -1213,7 +1174,7 @@ typedef struct MTLALIGN(16) @try { - unsigned i; + int i; texture_t *source = NULL; if (!video_shader_load_preset_into_shader(path.UTF8String, shader)) return NO; @@ -1276,26 +1237,26 @@ typedef struct MTLALIGN(16) @try { NSError *err; - MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; - vd.attributes[0].offset = offsetof(VertexSlang, position); - vd.attributes[0].format = MTLVertexFormatFloat4; - vd.attributes[0].bufferIndex = 4; - vd.attributes[1].offset = offsetof(VertexSlang, texCoord); - vd.attributes[1].format = MTLVertexFormatFloat2; - vd.attributes[1].bufferIndex = 4; - vd.layouts[4].stride = sizeof(VertexSlang); - vd.layouts[4].stepFunction = MTLVertexStepFunctionPerVertex; + MTLRenderPipelineColorAttachmentDescriptor *ca; + MTLRenderPipelineDescriptor *psd; + MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; + vd.attributes[0].offset = offsetof(VertexSlang, position); + vd.attributes[0].format = MTLVertexFormatFloat4; + vd.attributes[0].bufferIndex = 4; + vd.attributes[1].offset = offsetof(VertexSlang, texCoord); + vd.attributes[1].format = MTLVertexFormatFloat2; + vd.attributes[1].bufferIndex = 4; + vd.layouts[4].stride = sizeof(VertexSlang); + vd.layouts[4].stepFunction = MTLVertexStepFunctionPerVertex; - MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new]; + psd = [MTLRenderPipelineDescriptor new]; + psd.label = [[NSString stringWithUTF8String:shader->pass[i].source.path] stringByReplacingOccurrencesOfString:shadersPath withString:@""]; + ca = psd.colorAttachments[0]; + ca.pixelFormat = SelectOptimalPixelFormat( + glslang_format_to_metal(_engine.pass[i].semantics.format)); - psd.label = [[NSString stringWithUTF8String:shader->pass[i].source.path] - stringByReplacingOccurrencesOfString:shadersPath withString:@""]; - - MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0]; - - ca.pixelFormat = SelectOptimalPixelFormat(glslang_format_to_metal(_engine.pass[i].semantics.format)); - - /* TODO(sgc): confirm we never need blending for render passes */ + /* TODO/FIXME (sgc): confirm we never + * need blending for render passes */ ca.blendingEnabled = NO; ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; @@ -1338,6 +1299,7 @@ typedef struct MTLALIGN(16) STRUCT_ASSIGN(_engine.pass[i]._state, [_context.device newRenderPipelineStateWithDescriptor:psd error:&err]); + if (err != nil) { save_msl = true; @@ -1395,39 +1357,34 @@ typedef struct MTLALIGN(16) for (i = 0; i < shader->luts; i++) { + MTLTextureDescriptor *td; struct texture_image image = {0}; image.supports_rgba = true; if (!image_texture_load(&image, shader->lut[i].path)) return NO; - MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm - width:image.width - height:image.height - mipmapped:shader->lut[i].mipmap]; + td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:image.width height:image.height mipmapped:shader->lut[i].mipmap]; td.usage = MTLTextureUsageShaderRead; [self _initTexture:&_engine.luts[i] withDescriptor:td]; - [_engine.luts[i].view replaceRegion:MTLRegionMake2D(0, 0, image.width, image.height) mipmapLevel:0 withBytes:image.pixels bytesPerRow:4 * image.width]; - /* TODO(sgc): generate mip maps */ + /* TODO/FIXME (sgc): generate mip maps */ image_texture_free(&image); } _shader = shader; - shader = nil; + shader = nil; } @finally { if (shader) - { [self _freeVideoShader:shader]; - } } resize_render_targets = YES; - init_history = YES; + init_history = YES; return YES; } @@ -1445,25 +1402,23 @@ typedef struct MTLALIGN(16) - (instancetype)initWithContext:(Context *)context { if (self = [super init]) - { _context = context; - } return self; } - (bool)loadImages:(const struct texture_image *)images count:(NSUInteger)count { + NSUInteger needed, i; + [self _freeImages]; _images = [NSMutableArray arrayWithCapacity:count]; + needed = sizeof(SpriteVertex) * count * 4; - NSUInteger needed = sizeof(SpriteVertex) * count * 4; if (!_vert || _vert.length < needed) - { _vert = [_context.device newBufferWithLength:needed options:PLATFORM_METAL_RESOURCE_STORAGE_MODE]; - } - for (NSUInteger i = 0; i < count; i++) + for (i = 0; i < count; i++) { _images[i] = [_context newTexture:images[i] mipmapped:NO]; [self updateVertexX:0 y:0 w:1 h:1 index:i]; @@ -1478,6 +1433,7 @@ typedef struct MTLALIGN(16) - (void)drawWithEncoder:(id)rce { + NSUInteger count, i; #if !defined(HAVE_COCOATOUCH) if (_vertDirty) { @@ -1486,8 +1442,8 @@ typedef struct MTLALIGN(16) } #endif - NSUInteger count = _images.count; - for (NSUInteger i = 0; i < count; ++i) + count = _images.count; + for (i = 0; i < count; ++i) { NSUInteger offset = sizeof(SpriteVertex) * 4 * i; [rce setVertexBuffer:_vert offset:offset atIndex:BufferIndexPositions]; @@ -1505,12 +1461,12 @@ typedef struct MTLALIGN(16) - (void)_updateColorRed:(float)r green:(float)g blue:(float)b alpha:(float)a index:(NSUInteger)index { simd_float4 color = simd_make_float4(r, g, b, a); - SpriteVertex *pv = [self _getForIndex:index]; - pv[0].color = color; - pv[1].color = color; - pv[2].color = color; - pv[3].color = color; - _vertDirty = YES; + SpriteVertex *pv = [self _getForIndex:index]; + pv[0].color = color; + pv[1].color = color; + pv[2].color = color; + pv[3].color = color; + _vertDirty = YES; } - (void)updateAlpha:(float)alpha index:(NSUInteger)index @@ -1521,21 +1477,21 @@ typedef struct MTLALIGN(16) - (void)updateVertexX:(float)x y:(float)y w:(float)w h:(float)h index:(NSUInteger)index { SpriteVertex *pv = [self _getForIndex:index]; - pv[0].position = simd_make_float2(x, y); - pv[1].position = simd_make_float2(x + w, y); - pv[2].position = simd_make_float2(x, y + h); - pv[3].position = simd_make_float2(x + w, y + h); - _vertDirty = YES; + pv[0].position = simd_make_float2(x, y); + pv[1].position = simd_make_float2(x + w, y); + pv[2].position = simd_make_float2(x, y + h); + pv[3].position = simd_make_float2(x + w, y + h); + _vertDirty = YES; } - (void)updateTextureCoordsX:(float)x y:(float)y w:(float)w h:(float)h index:(NSUInteger)index { SpriteVertex *pv = [self _getForIndex:index]; - pv[0].texCoord = simd_make_float2(x, y); - pv[1].texCoord = simd_make_float2(x + w, y); - pv[2].texCoord = simd_make_float2(x, y + h); - pv[3].texCoord = simd_make_float2(x + w, y + h); - _vertDirty = YES; + pv[0].texCoord = simd_make_float2(x, y); + pv[1].texCoord = simd_make_float2(x + w, y); + pv[2].texCoord = simd_make_float2(x, y + h); + pv[3].texCoord = simd_make_float2(x + w, y + h); + _vertDirty = YES; } - (void)_freeImages @@ -1605,6 +1561,8 @@ MTLPixelFormat SelectOptimalPixelFormat(MTLPixelFormat fmt) return MTLPixelFormatBGRA8Unorm_sRGB; default: - return fmt; + break; } + + return fmt; } diff --git a/gfx/video_filters/super2xsai.c b/gfx/video_filters/super2xsai.c index f9dc321a9c..0b57398259 100644 --- a/gfx/video_filters/super2xsai.c +++ b/gfx/video_filters/super2xsai.c @@ -216,11 +216,12 @@ static void supertwoxsai_generic_xrgb8888(unsigned width, unsigned height, { supertwoxsai_declare_variables(uint32_t, in, nextline); - //--------------------------- B1 B2 - // 4 5 6 S2 - // 1 2 3 S1 - // A1 A2 - //-------------------------------------- + /*--------------------------- B1 B2 + * 4 5 6 S2 + * 1 2 3 S1 + * A1 A2 + *-------------------------------------- + */ supertwoxsai_function(supertwoxsai_result, supertwoxsai_interpolate_xrgb8888, supertwoxsai_interpolate2_xrgb8888); } @@ -246,11 +247,12 @@ static void supertwoxsai_generic_rgb565(unsigned width, unsigned height, { supertwoxsai_declare_variables(uint16_t, in, nextline); - //--------------------------- B1 B2 - // 4 5 6 S2 - // 1 2 3 S1 - // A1 A2 - //-------------------------------------- + /*--------------------------- B1 B2 + * 4 5 6 S2 + * 1 2 3 S1 + * A1 A2 + *-------------------------------------- + */ supertwoxsai_function(supertwoxsai_result, supertwoxsai_interpolate_rgb565, supertwoxsai_interpolate2_rgb565); } @@ -311,7 +313,8 @@ static void supertwoxsai_generic_packets(void *data, thr->width = width; thr->height = y_end - y_start; - // Workers need to know if they can access pixels outside their given buffer. + /* Workers need to know if they can access pixels + * outside their given buffer. */ thr->first = y_start; thr->last = y_end == height; diff --git a/input/common/wayland_common.c b/input/common/wayland_common.c index 11d611c84c..8f745a7ef8 100644 --- a/input/common/wayland_common.c +++ b/input/common/wayland_common.c @@ -13,7 +13,7 @@ * If not, see . */ -// Needed for memfd_create +/* Needed for memfd_create */ #ifndef _GNU_SOURCE #define _GNU_SOURCE /* See feature_test_macros(7) */ #endif @@ -85,7 +85,7 @@ static void keyboard_handle_leave(void *data, gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; wl->input.keyboard_focus = false; - // Release all keys + /* Release all keys */ memset(wl->input.key_state, 0, sizeof(wl->input.key_state)); } @@ -727,7 +727,7 @@ void* wayland_data_offer_receive(struct wl_display *display, struct wl_data_offe { wl_data_offer_receive(offer, mime_type, pipefd[1]); - // Wait for sending client to transfer + /* Wait for sending client to transfer */ wl_display_roundtrip(display); close(pipefd[1]); @@ -849,9 +849,12 @@ static void data_device_handle_drop(void *data, line[strcspn(line, "\r\n")] = 0; RARCH_LOG("[Wayland]: > \"%s\"\n", line); - // TODO: Convert from file:// URI, Implement file loading - //if (wayland_load_content_from_drop(g_filename_from_uri(line, NULL, NULL))) - // RARCH_WARN("----- wayland_load_content_from_drop success\n"); + /* TODO/FIXME: Convert from file:// URI, Implement file loading + * Drag and Drop */ +#if 0 + if (wayland_load_content_from_drop(g_filename_from_uri(line, NULL, NULL))) + RARCH_WARN("----- wayland_load_content_from_drop success\n"); +#endif } fclose(stream); @@ -867,7 +870,7 @@ static void data_offer_handle_offer(void *data, struct wl_data_offer *offer, { data_offer_ctx *offer_data = data; - // TODO: Keep list of mime types for offer if beneficial + /* TODO: Keep list of mime types for offer if beneficial */ if (string_is_equal(mime_type, FILE_MIME)) offer_data->is_file_mime_type = true; } @@ -875,8 +878,8 @@ static void data_offer_handle_offer(void *data, struct wl_data_offer *offer, static void data_offer_handle_source_actions(void *data, struct wl_data_offer *offer, enum wl_data_device_manager_dnd_action actions) { - // Report of actions for this offer supported by compositor - data_offer_ctx *offer_data = data; + /* Report of actions for this offer supported by compositor */ + data_offer_ctx *offer_data = data; offer_data->supported_actions = actions; } diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index a614bf276e..8a7e91c6fd 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -42,8 +42,8 @@ float cocoa_screen_get_backing_scale_factor(void); static bool apple_key_state[MAX_KEYS]; -// Send keyboard inputs directly using RETROK_* codes -// Used by the iOS custom keyboard implementation +/* Send keyboard inputs directly using RETROK_* codes + * Used by the iOS custom keyboard implementation */ void apple_direct_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod, unsigned device) { diff --git a/input/drivers/psl1ght_input.c b/input/drivers/psl1ght_input.c index e44b16d0c6..f64d8c95b4 100644 --- a/input/drivers/psl1ght_input.c +++ b/input/drivers/psl1ght_input.c @@ -358,64 +358,58 @@ static inline void initAttributeGem(gemAttribute * attribute, int initGemVideoConvert(ps3_input_t *ps3) { - int ret; - - ps3->gem_video_convert.version = 2; - ps3->gem_video_convert.format = 2; //GEM_RGBA_640x480; - ps3->gem_video_convert.conversion= GEM_AUTO_WHITE_BALANCE | GEM_COMBINE_PREVIOUS_INPUT_FRAME | - GEM_FILTER_OUTLIER_PIXELS | GEM_GAMMA_BOOST; - ps3->gem_video_convert.gain = 1.0f; - ps3->gem_video_convert.red_gain = 1.0f; - ps3->gem_video_convert.green_gain = 1.0f; - ps3->gem_video_convert.blue_gain = 1.0f; - ps3->buffer_mem = (void *)memalign(128, 640*480); - ps3->video_out = (void *)ps3->video_frame; - ps3->gem_video_convert.buffer_memory = ps3->buffer_mem; + ps3->gem_video_convert.version = 2; + ps3->gem_video_convert.format = 2; /* GEM_RGBA_640x480; */ + ps3->gem_video_convert.conversion = GEM_AUTO_WHITE_BALANCE + | GEM_COMBINE_PREVIOUS_INPUT_FRAME + | GEM_FILTER_OUTLIER_PIXELS + | GEM_GAMMA_BOOST; + ps3->gem_video_convert.gain = 1.0f; + ps3->gem_video_convert.red_gain = 1.0f; + ps3->gem_video_convert.green_gain = 1.0f; + ps3->gem_video_convert.blue_gain = 1.0f; + ps3->buffer_mem = (void *)memalign(128, 640*480); + ps3->video_out = (void *)ps3->video_frame; + ps3->gem_video_convert.buffer_memory = ps3->buffer_mem; ps3->gem_video_convert.video_data_out = ps3->video_out; - ps3->gem_video_convert.alpha = 255; - ret = gemPrepareVideoConvert(&ps3->gem_video_convert); - return ret; + ps3->gem_video_convert.alpha = 255; + + return gemPrepareVideoConvert(&ps3->gem_video_convert); } int initGem(ps3_input_t *ps3) { - int ret; int i; - - ret = initSpurs(ps3); - if (ret) - { + gemAttribute gem_attr; + u8 gem_spu_priorities[8] = { 1, 1, 1, 1, 1, 0, 0, 0 }; /* execute */ + /* libgem jobs */ + /* on 5 SPUs */ + if (initSpurs(ps3)) return -1; - } - ret = gemGetMemorySize(1); - ps3->gem_memory = (void *)malloc(ret); + ps3->gem_memory = (void *)malloc(gemGetMemorySize(1)); if (!ps3->gem_memory) return -1; - u8 gem_spu_priorities[8] = { 1, 1, 1, 1, 1, 0, 0, 0 }; // execute - // libgem jobs - // on 5 spu - gemAttribute gem_attr; + initAttributeGem(&gem_attr, 1, ps3->gem_memory, + ps3->spurs, gem_spu_priorities); - initAttributeGem(&gem_attr, 1, ps3->gem_memory, ps3->spurs, gem_spu_priorities); + gemInit (&gem_attr); + initGemVideoConvert(ps3); + gemPrepareCamera (128, 0.5); + gemReset(0); - ret = gemInit (&gem_attr); - ret= initGemVideoConvert(ps3); - ret = gemPrepareCamera (128, 0.5); - ret = gemReset(0); return 0; } void readGemPad(ps3_input_t *ps3, int num_gem) { - int ret; unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 }; - ret = gemGetState (0, 0, -22000, &ps3->gem_state); + int ret = gemGetState(0, 0, -22000, &ps3->gem_state); - ps3->newGemPad = ps3->gem_state.paddata.buttons & (~ps3->oldGemPad); - ps3->newGemAnalogT = ps3->gem_state.paddata.ANA_T; - ps3->oldGemPad = ps3->gem_state.paddata.buttons; + ps3->newGemPad = ps3->gem_state.paddata.buttons & (~ps3->oldGemPad); + ps3->newGemAnalogT = ps3->gem_state.paddata.ANA_T; + ps3->oldGemPad = ps3->gem_state.paddata.buttons; switch (ret) { @@ -441,10 +435,8 @@ void readGemAccPosition(int num_gem) void readGemInertial(ps3_input_t *ps3, int num_gem) { - int ret; VmathVector4 v; - - ret = gemGetInertialState(num_gem, 0, -22000, &ps3->gem_inertial_state); + int ret = gemGetInertialState(num_gem, 0, -22000, &ps3->gem_inertial_state); v.vec128 = ps3->gem_inertial_state.accelerometer; v.vec128 = ps3->gem_inertial_state.accelerometer_bias; v.vec128 = ps3->gem_inertial_state.gyro; @@ -453,14 +445,16 @@ void readGemInertial(ps3_input_t *ps3, int num_gem) void readGem(ps3_input_t *ps3) { + VmathVector4 v; + proccessGem(ps3, 0); proccessGem(ps3, 1); proccessGem(ps3, 2); proccessGem(ps3, 3); - readGemPad(ps3, 0); // This will read buttons from Move - VmathVector4 v; + readGemPad(ps3, 0); /* This will read buttons from Move */ v.vec128 = ps3->gem_state.pos; - switch (ps3->newGemPad) { + switch (ps3->newGemPad) + { case 1: ps3->select_pressed++; break; @@ -478,23 +472,27 @@ void readGem(ps3_input_t *ps3) break; case 16: ps3->triangle_pressed++; - break; - case 32: + break; + case 32: ps3->circle_pressed++; break; case 64: ps3->cross_pressed++; - //readGemAccPosition(0); +#if 0 + readGemAccPosition(0); +#endif break; case 128: ps3->square_pressed++; - //readGemInertial(ps3, 0); +#if 0 + readGemInertial(ps3, 0); +#endif break; default: break; } } -#endif // HAVE_LIGHTGUN +#endif /* HAVE_LIGHTGUN */ static void ps3_input_poll(void *data) { @@ -665,11 +663,14 @@ static int16_t ps3_mouse_device_state(ps3_input_t *ps3, static int16_t ps3_lightgun_device_state(ps3_input_t *ps3, unsigned user, unsigned id) { - if (!ps3->gem_connected || !ps3->gem_init) - return 0; - - readCamera(ps3); - readGem(ps3); + float center_x; + float center_y; + float pointer_x; + float pointer_y; + videoState state; + videoConfiguration vconfig; + videoResolution res; + VmathVector4 ray_start, ray_dir; struct video_viewport vp; const int edge_detect = 32700; bool inside = false; @@ -677,29 +678,27 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3, int16_t res_y = 0; int16_t res_screen_x = 0; int16_t res_screen_y = 0; - float center_x; - float center_y; - float pointer_x; - float pointer_y; - float sensitivity = 1.0f; + float sensitivity = 1.0f; + if (!ps3->gem_connected || !ps3->gem_init) + return 0; + + readCamera(ps3); + readGem(ps3); - videoState state; - videoConfiguration vconfig; - videoResolution res; videoGetState(0, 0, &state); videoGetResolution(state.displayMode.resolution, &res); if (res.height == 720) { - // 720p offset adjustments - center_x = 645.0f; - center_y = 375.0f; + /* 720p offset adjustments */ + center_x = 645.0f; + center_y = 375.0f; } else if (res.height == 1080) { - // 1080p offset adjustments - center_x = 960.0f; - center_y = 565.0f; + /* 1080p offset adjustments */ + center_x = 960.0f; + center_y = 565.0f; } vp.x = 0; @@ -709,25 +708,23 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3, vp.full_width = 0; vp.full_height = 0; -#if 1 - // tracking mode 1: laser pointer mode (this is closest to actual lightgun behavior) - VmathVector4 ray_start; - ray_start.vec128 = ps3->gem_state.pos; - VmathVector4 ray_tmp = {.vec128 = {0.0f,0.0f,-1.0f,0.0f}}; - const VmathQuat *quat = &ps3->gem_state.quat; - VmathVector4 ray_dir; + /* tracking mode 1: laser pointer mode (this is closest + to actual lightgun behavior) */ + ray_start.vec128 = ps3->gem_state.pos; + VmathVector4 ray_tmp = {.vec128 = {0.0f,0.0f,-1.0f,0.0f}}; + const VmathQuat *quat = &ps3->gem_state.quat; vmathQRotate(&ray_dir, quat, &ray_tmp); - float t = -ray_start.vec128[2] / ray_dir.vec128[2]; - pointer_x = ray_start.vec128[0] + ray_dir.vec128[0]*t; - pointer_y = ray_start.vec128[1] + ray_dir.vec128[1]*t; -#endif + float t = -ray_start.vec128[2] / ray_dir.vec128[2]; + pointer_x = ray_start.vec128[0] + ray_dir.vec128[0]*t; + pointer_y = ray_start.vec128[1] + ray_dir.vec128[1]*t; #if 0 - // tracking mode 2: 3D coordinate system (move pointer position by moving the whole controller) + /* tracking mode 2: 3D coordinate system (move pointer position by moving the + * whole controller) */ VmathVector4 v; - v.vec128 = ps3->gem_state.pos; - pointer_x = v.vec128[0]; - pointer_y = v.vec128[1]; + v.vec128 = ps3->gem_state.pos; + pointer_x = v.vec128[0]; + pointer_y = v.vec128[1]; #endif if (video_driver_translate_coord_viewport_wrap(&vp, @@ -782,15 +779,11 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3, break; case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: if (inside) - { return (res_x); - } break; case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: if (inside) - { return (~res_y); - } break; case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: return !inside; @@ -825,7 +818,7 @@ static int16_t ps3_input_state( case RETRO_DEVICE_JOYPAD: if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { - unsigned i; + int i; int16_t ret = 0; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) @@ -880,7 +873,10 @@ static void ps3_input_free_input(void *data) static void* ps3_input_init(const char *joypad_driver) { - unsigned i; + int i; +#ifdef HAVE_LIGHTGUN + gemInfo gem_info; +#endif ps3_input_t *ps3 = (ps3_input_t*)calloc(1, sizeof(*ps3)); if (!ps3) return NULL; @@ -902,8 +898,7 @@ static void* ps3_input_init(const char *joypad_driver) ioMouseInit(MAX_MICE); #endif #ifdef HAVE_LIGHTGUN - ps3->gem_init = 0; - gemInfo gem_info; + ps3->gem_init = 0; gemGetInfo(&gem_info); ps3->gem_connected = gem_info.connected; if (ps3->gem_connected) @@ -918,9 +913,7 @@ static void* ps3_input_init(const char *joypad_driver) if (!setupCamera(ps3)); { if (!initGem(ps3)) - { ps3->gem_init = 1; - } } } } diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index 4ae9a9b688..448c6dcbb4 100644 --- a/input/drivers/qnx_input.c +++ b/input/drivers/qnx_input.c @@ -177,17 +177,17 @@ static void qnx_process_joystick_event(qnx_input_t *qnx, screen_event_t screen_e int displacement[2]; screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_DISPLACEMENT, displacement); - if(displacement != 0) + if (displacement != 0) { qnx->trackpad_acc[0] += displacement[0]; - if(abs(qnx->trackpad_acc[0]) > TRACKPAD_THRESHOLD) + if (abs(qnx->trackpad_acc[0]) > TRACKPAD_THRESHOLD) { - if(qnx->trackpad_acc < 0) + if (qnx->trackpad_acc < 0) { input_keyboard_event(true, RETROK_LEFT, 0, 0, RETRO_DEVICE_KEYBOARD); input_keyboard_event(false, RETROK_LEFT, 0, 0, RETRO_DEVICE_KEYBOARD); } - else if(qnx->trackpad_acc > 0) + else if (qnx->trackpad_acc > 0) { input_keyboard_event(true, RETROK_RIGHT, 0, 0, RETRO_DEVICE_KEYBOARD); input_keyboard_event(false, RETROK_RIGHT, 0, 0, RETRO_DEVICE_KEYBOARD); @@ -197,14 +197,14 @@ static void qnx_process_joystick_event(qnx_input_t *qnx, screen_event_t screen_e } qnx->trackpad_acc[1] += displacement[1]; - if(abs(qnx->trackpad_acc[1]) > TRACKPAD_THRESHOLD) + if (abs(qnx->trackpad_acc[1]) > TRACKPAD_THRESHOLD) { - if(qnx->trackpad_acc < 0) + if (qnx->trackpad_acc < 0) { input_keyboard_event(true, RETROK_UP, 0, 0, RETRO_DEVICE_KEYBOARD); input_keyboard_event(false, RETROK_UP, 0, 0, RETRO_DEVICE_KEYBOARD); } - else if(qnx->trackpad_acc > 0) + else if (qnx->trackpad_acc > 0) { input_keyboard_event(true, RETROK_DOWN, 0, 0, RETRO_DEVICE_KEYBOARD); input_keyboard_event(false, RETROK_DOWN, 0, 0, RETRO_DEVICE_KEYBOARD); @@ -228,9 +228,9 @@ static void qnx_input_autodetect_gamepad(qnx_input_t *qnx, return; name_buf[0] = '\0'; - if(controller && controller->type == SCREEN_EVENT_GAMEPAD) + if (controller && controller->type == SCREEN_EVENT_GAMEPAD) { - if(strstr(controller->id, "0-054C-05C4-1.0")) + if (strstr(controller->id, "0-054C-05C4-1.0")) strlcpy(name_buf, "DS4 Controller", sizeof(name_buf)); else strlcpy(name_buf, "QNX Gamepad", sizeof(name_buf)); @@ -372,33 +372,26 @@ static void qnx_process_keyboard_event( qnx_input_t *qnx, screen_event_t event, int type) { - // Get key properties from screen event - int flags = 0; + /* Get key properties from screen event */ + int flags = 0, cap = 0, mod = 0; screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags); - - int cap = 0; screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap); - - int mod = 0; screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); - // Calculate state + /* Calculate state */ unsigned keycode = input_keymaps_translate_keysym_to_rk(cap); - bool keydown = flags & KEY_DOWN; - bool keyrepeat = flags & KEY_REPEAT; - - // Fire keyboard event - if(!keyrepeat) - { + bool keydown = flags & KEY_DOWN; + bool keyrepeat = flags & KEY_REPEAT; + /* Fire keyboard event */ + if (!keyrepeat) input_keyboard_event(keydown, keycode, 0, mod, RETRO_DEVICE_KEYBOARD); - } - // Apply keyboard state - if(keydown && !keyrepeat) + /* Apply keyboard state */ + if (keydown && !keyrepeat) { BIT_SET(qnx->keyboard_state, cap); } - else if(!keydown && !keyrepeat) + else if (!keydown && !keyrepeat) { BIT_CLEAR(qnx->keyboard_state, cap); } @@ -421,7 +414,7 @@ static void qnx_process_touch_event( /* Find a free touch struct. */ for (i = 0; i < MAX_TOUCH; ++i) { - if(qnx->pointer[i].contact_id == -1) + if (qnx->pointer[i].contact_id == -1) { struct video_viewport vp; @@ -458,7 +451,7 @@ static void qnx_process_touch_event( case SCREEN_EVENT_MTOUCH_RELEASE: for (i = 0; i < MAX_TOUCH; ++i) { - if(qnx->pointer[i].contact_id == contact_id) + if (qnx->pointer[i].contact_id == contact_id) { /* Invalidate the finger. */ qnx->pointer[i].contact_id = -1; @@ -488,7 +481,7 @@ static void qnx_process_touch_event( /* Find the finger we're tracking and update. */ for (i = 0; i < qnx->pointer_count; ++i) { - if(qnx->pointer[i].contact_id == contact_id) + if (qnx->pointer[i].contact_id == contact_id) { struct video_viewport vp; @@ -507,14 +500,14 @@ static void qnx_process_touch_event( * numbers larger than the screen resolution. * * Normalize. */ - if(pos[0] < 0) + if (pos[0] < 0) pos[0] = 0; - if(pos[0] > gl->full_x) + if (pos[0] > gl->full_x) pos[0] = gl->full_x; - if(pos[1] < 0) + if (pos[1] < 0) pos[1] = 0; - if(pos[1] > gl->full_y) + if (pos[1] > gl->full_y) pos[1] = gl->full_y; #endif @@ -647,12 +640,12 @@ static void qnx_handle_navigator_event( bps_get_event(&event_pause, -1); event_code = bps_event_get_code(event_pause); - if(event_code == NAVIGATOR_WINDOW_STATE) + if (event_code == NAVIGATOR_WINDOW_STATE) { - if(navigator_event_get_window_state(event_pause) == NAVIGATOR_WINDOW_FULLSCREEN) + if (navigator_event_get_window_state(event_pause) == NAVIGATOR_WINDOW_FULLSCREEN) break; } - else if(event_code == NAVIGATOR_EXIT) + else if (event_code == NAVIGATOR_EXIT) goto shutdown; } break; @@ -714,7 +707,7 @@ static void qnx_input_poll(void *data) bps_event_t *event = NULL; int rc = bps_get_event(&event, 0); - if(rc == BPS_SUCCESS) + if (rc == BPS_SUCCESS) { int domain; @@ -742,7 +735,7 @@ static int16_t qnx_pointer_input_state(qnx_input_t *qnx, int16_t x; int16_t y; - if(screen) + if (screen) { x = qnx->pointer[idx].full_x; y = qnx->pointer[idx].full_y; diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index 43dfcc740d..9a43119c3e 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -279,16 +279,16 @@ BTDIMPORT const hci_cmd_t* l2cap_decline_connection_ptr; /* RFCOMM EVENTS */ -// data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16) +/* data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16) */ #define RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE 0x80 -// data: event(8), len(8), rfcomm_cid(16) +/* data: event(8), len(8), rfcomm_cid(16) */ #define RFCOMM_EVENT_CHANNEL_CLOSED 0x81 -// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) +/* data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) */ #define RFCOMM_EVENT_INCOMING_CONNECTION 0x82 -// data: event (8), len(8), rfcommid (16), ... +/* data: event (8), len(8), rfcommid (16), ... */ #define RFCOMM_EVENT_REMOTE_LINE_STATUS 0x83 /* data: event(8), len(8), rfcomm_cid(16), credits(8) */ diff --git a/input/drivers_joypad/mfi_joypad.m b/input/drivers_joypad/mfi_joypad.m index 95cccecd4e..6a86441b81 100644 --- a/input/drivers_joypad/mfi_joypad.m +++ b/input/drivers_joypad/mfi_joypad.m @@ -60,7 +60,7 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller) return; slot = (uint32_t)controller.playerIndex; - // if we have not assigned a slot to this controller yet, ignore it. + /* If we have not assigned a slot to this controller yet, ignore it. */ if (slot >= MAX_USERS) return; buttons = &mfi_buttons[slot]; @@ -68,13 +68,14 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller) /* retain the values from the paused controller handler and pass them through */ if (@available(iOS 13, *)) { - // The menu button can be pressed/unpressed like any other button in iOS 13 - // so no need to passthrough anything + /* The menu button can be pressed/unpressed + * like any other button in iOS 13, + * so no need to passthrough anything */ *buttons = 0; } else { - // Use the paused controller handler for iOS versions below 13 + /* Use the paused controller handler for iOS versions below 13 */ pause = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_START); select = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT); l3 = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_L3); @@ -110,14 +111,15 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller) #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 if (@available(iOS 13, *)) { - // Support "Options" button present in PS4 / XBox One controllers + /* Support "Options" button present in PS4 / XBox One controllers */ *buttons |= gp.buttonOptions.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; - // Support buttons that aren't supported by older mFi controller via "hotkey" combinations: - // - // LS + Menu => Select - // LT + Menu => L3 - // RT + Menu => R3 + /* Support buttons that aren't supported by older mFi controller via "hotkey" combinations: + * + * LS + Menu => Select + * LT + Menu => L3 + * RT + Menu => R3 + */ if (gp.buttonMenu.pressed ) { if (gp.leftShoulder.pressed) @@ -138,7 +140,8 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller) mfi_axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f; } -// GCGamepad is deprecated + + /* GCGamepad is deprecated */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated" else if (controller.gamepad) @@ -168,19 +171,21 @@ static void apple_gamecontroller_joypad_poll(void) apple_gamecontroller_joypad_poll_internal(controller); } -// GCGamepad is deprecated +/* GCGamepad is deprecated */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated" static void apple_gamecontroller_joypad_register(GCGamepad *gamepad) { #ifdef __IPHONE_14_0 - // dont let tvOS or iOS do anything with **our** buttons!! - // iOS will start a screen recording if you hold or dbl click the OPTIONS button, we dont want that. - if (@available(iOS 14.0, tvOS 14.0, *)) { + /* Don't let tvOS or iOS do anything with **our** buttons!! + * iOS will start a screen recording if you hold or doubleclick + * the OPTIONS button, we don't want that. */ + if (@available(iOS 14.0, tvOS 14.0, *)) + { GCExtendedGamepad *gp = (GCExtendedGamepad *)gamepad.controller.extendedGamepad; gp.buttonOptions.preferredSystemGestureState = GCSystemGestureStateDisabled; - gp.buttonMenu.preferredSystemGestureState = GCSystemGestureStateDisabled; - gp.buttonHome.preferredSystemGestureState = GCSystemGestureStateDisabled; + gp.buttonMenu.preferredSystemGestureState = GCSystemGestureStateDisabled; + gp.buttonHome.preferredSystemGestureState = GCSystemGestureStateDisabled; } #endif @@ -189,13 +194,12 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad) apple_gamecontroller_joypad_poll_internal(updateGamepad.controller); }; + /* controllerPausedHandler is deprecated in favor + * of being able to deal with the menu + * button as any other button */ if (@available(iOS 13, *)) - { - // controllerPausedHandler is deprecated in favor of being able to deal with the menu - // button as any other button return; - } - else + { gamepad.controller.controllerPausedHandler = ^(GCController *controller) @@ -294,11 +298,11 @@ static void apple_gamecontroller_joypad_connect(GCController *controller) } } -// GCGamepad is deprecated +/* GCGamepad is deprecated */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated" [mfiControllers addObject:controller]; - // move any non-game controllers (like the siri remote) to the end + /* Move any non-game controllers (like the siri remote) to the end */ if (mfiControllers.count > 1) { int newPlayerIndex = 0; diff --git a/input/drivers_keyboard/keyboard_event_android.h b/input/drivers_keyboard/keyboard_event_android.h index ccc8d268d3..25168ec7ae 100644 --- a/input/drivers_keyboard/keyboard_event_android.h +++ b/input/drivers_keyboard/keyboard_event_android.h @@ -16,8 +16,9 @@ #ifndef _KEYBOARD_EVENT_ANDROID_H #define _KEYBOARD_EVENT_ANDROID_H -// The list of defined Android keycodes is incomplete in SDK version 12 and lower. -// If using an SDK lower than 13 then add missing keycodes here +/* The list of defined Android keycodes is incomplete in SDK version 12 + * and lower. + * If using an SDK lower than 13, add missing keycodes here */ #if __ANDROID_API__ < 13 /* diff --git a/input/input_keymaps.c b/input/input_keymaps.c index 96c65798de..ce888148f4 100644 --- a/input/input_keymaps.c +++ b/input/input_keymaps.c @@ -1459,7 +1459,7 @@ const struct rarch_key_map rarch_key_map_qnx[] = { { KEYCODE_RIGHT_CTRL, RETROK_RCTRL }, { KEYCODE_LEFT_ALT, RETROK_LALT }, { KEYCODE_RIGHT_ALT, RETROK_RALT }, - // TODO/FIXME: Code for 'sym' key on BB keyboards. Figure out which sys/keycodes.h define this maps to. + /* TODO/FIXME: Code for 'sym' key on BB keyboards. Figure out which sys/keycodes.h define this maps to. */ { 61651, RETROK_RSUPER }, { KEYCODE_DOLLAR, RETROK_DOLLAR }, { KEYCODE_MENU, RETROK_MENU }, diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 35fc9a9766..50f274ce79 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -337,7 +337,7 @@ static ui_application_t ui_application_cocoa = { void *data; enum event_command cmd; } -@end // @interface CommandPerformer +@end /* @interface CommandPerformer */ @implementation CommandPerformer @@ -358,7 +358,7 @@ static ui_application_t ui_application_cocoa = { command_event(self->cmd, self->data); } -@end // @implementation CommandPerformer +@end /* @implementation CommandPerformer */ #if defined(HAVE_COCOA_METAL) @interface RAWindow : NSWindow diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 141ad856fa..f997e86515 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -310,9 +310,9 @@ enum /* Keyboard event hack for iOS versions prior to iOS 7. * * Derived from: - * http://nacho4d-nacho4d.blogspot.com/2012/01/ - * catching-keyboard-events-in-ios.html - */ + * http://nacho4d-nacho4d.blogspot.com/2012/01/ + * catching-keyboard-events-in-ios.html + */ const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]); int eventType = eventMem ? *(int*)&eventMem[8] : 0; @@ -471,8 +471,8 @@ enum NSString *filename = (NSString*)url.path.lastPathComponent; NSError *error = nil; NSString *destination = [self.documentsDirectory stringByAppendingPathComponent:filename]; - - // copy file to documents directory if its not already inside of documents directory + /* Copy file to documents directory if it's not already + * inside Documents directory */ if ([url startAccessingSecurityScopedResource]) { if (![[url path] containsString: self.documentsDirectory]) if (![manager fileExistsAtPath:destination]) diff --git a/ui/drivers/ui_win32.c b/ui/drivers/ui_win32.c index 647000c5fc..e54d969607 100644 --- a/ui/drivers/ui_win32.c +++ b/ui/drivers/ui_win32.c @@ -28,7 +28,7 @@ #define IDI_ICON 1 #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K +#define _WIN32_WINNT 0x0500 /* _WIN32_WINNT_WIN2K */ #endif #ifndef _WIN32_IE