1
0
mirror of https://github.com/libretro/RetroArch synced 2025-04-21 14:42:38 +00:00

Fix C++ comments

This commit is contained in:
LibretroAdmin 2022-10-01 17:56:16 +02:00
parent 6be8dccd46
commit ace21d28f7
19 changed files with 530 additions and 565 deletions

@ -79,13 +79,14 @@ static void *gx_audio_init(const char *device,
AIInit(NULL); AIInit(NULL);
AIRegisterDMACallback(dma_callback); 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)) if (rate <= 32000 || (rate >= 40000 && rate < 48000))
{ {
AISetDSPSampleRate(AI_SAMPLERATE_32KHZ); AISetDSPSampleRate(AI_SAMPLERATE_32KHZ);
*new_rate = 32000; *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); AISetDSPSampleRate(AI_SAMPLERATE_48KHZ);
*new_rate = 48000; *new_rate = 48000;

@ -274,7 +274,7 @@ fail_audio_output:
fail_audio_ipc: fail_audio_ipc:
switch_audio_ipc_finalize(); switch_audio_ipc_finalize();
fail: fail:
free(swa); // freeing a null ptr is valid free(swa); /* freeing a NULL ptr is valid */
return NULL; return NULL;
} }

@ -94,7 +94,7 @@
**************************************************************************** ****************************************************************************
*/ */
// Internal enumerations /* Internal enumerations */
enum rsd_logtype enum rsd_logtype
{ {
RSD_LOG_DEBUG = 0, RSD_LOG_DEBUG = 0,
@ -111,7 +111,7 @@ enum rsd_conn_type
RSD_CONN_PROTO = 0x100 RSD_CONN_PROTO = 0x100
}; };
// Some logging macros. /* Some logging macros. */
#define RSD_WARN(fmt, args...) #define RSD_WARN(fmt, args...)
#define RSD_ERR(fmt, args...) #define RSD_ERR(fmt, args...)
#define RSD_DEBUG(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 size_t rsnd_get_ptr(rsound_t *rd);
static int rsnd_reset(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_send_identity_info(rsound_t *rd);
static int rsnd_close_ctl(rsound_t *rd); static int rsnd_close_ctl(rsound_t *rd);
static int rsnd_send_info_query(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_bits = 8 * rsnd_format_to_samplesize(rd->format);
uint16_t temp_format = 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 ) switch ( temp_format )
{ {
case RSD_S16_NE: 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. 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. */ 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 SET32(buf,offset,x) (*((uint32_t*)(buf+offset)) = x)
#define SET16(buf,offset,x) (*((uint16_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); LSB32(temp32);
SET32(header, 16, temp32); SET32(header, 16, temp32);
temp16 = 0; // PCM data temp16 = 0; /* PCM data */
switch( rd->format ) switch( rd->format )
{ {
@ -404,10 +404,10 @@ static int rsnd_send_header_info(rsound_t *rd)
LSB16(temp16); LSB16(temp16);
SET16(header, 20, temp16); SET16(header, 20, temp16);
// Channels here /* Channels here */
LSB16(temp_channels); LSB16(temp_channels);
SET16(header, CHANNEL, temp_channels); SET16(header, CHANNEL, temp_channels);
// Samples per sec /* Samples per sec */
LSB32(temp_rate); LSB32(temp_rate);
SET32(header, RATE, temp_rate); SET32(header, RATE, temp_rate);
@ -419,7 +419,7 @@ static int rsnd_send_header_info(rsound_t *rd)
LSB16(temp16); LSB16(temp16);
SET16(header, 32, temp16); SET16(header, 32, temp16);
// Bits per sample /* Bits per sample */
LSB16(temp_bits); LSB16(temp_bits);
SET16(header, FRAMESIZE, temp_bits); SET16(header, FRAMESIZE, temp_bits);
@ -450,7 +450,7 @@ static int rsnd_get_backend_info ( rsound_t *rd )
#define LATENCY 0 #define LATENCY 0
#define CHUNKSIZE 1 #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}; uint32_t rsnd_header[2] = {0};
if ( rsnd_recv_chunk(rd->conn.socket, rsnd_header, RSND_HEADER_SIZE, 1) != RSND_HEADER_SIZE ) 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.latency = rsnd_header[LATENCY];
rd->backend_info.chunk_size = rsnd_header[CHUNKSIZE]; 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 ) if ( rd->backend_info.chunk_size > MAX_CHUNK_SIZE || rd->backend_info.chunk_size <= 0 )
rd->backend_info.chunk_size = MAX_CHUNK_SIZE; rd->backend_info.chunk_size = MAX_CHUNK_SIZE;
@ -487,7 +487,7 @@ static int rsnd_get_backend_info ( rsound_t *rd )
return -1; 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 ) if ( rd->conn_type & RSD_CONN_TCP )
{ {
#define MAX_TCP_BUFSIZE (1 << 14) #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)); 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? /* Can we read the last 8 bytes so we can use the protocol interface? */
// This is non-blocking. /* This is non-blocking. */
if ( rsnd_recv_chunk(rd->conn.socket, rsnd_header, RSND_HEADER_SIZE, 0) == RSND_HEADER_SIZE ) if ( rsnd_recv_chunk(rd->conn.socket, rsnd_header, RSND_HEADER_SIZE, 0) == RSND_HEADER_SIZE )
rd->conn_type |= RSD_CONN_PROTO; rd->conn_type |= RSD_CONN_PROTO;
else else
{ RSD_DEBUG("[RSound] Failed to get new proto.\n"); } { 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 #ifdef _WIN32
net_shutdown(rd->conn.socket, SD_RECEIVE); 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); net_shutdown(rd->conn.socket, SHUT_RD);
#endif #endif
@ -727,7 +727,7 @@ static int64_t rsnd_get_time_usec(void)
{ {
#if defined(_WIN32) #if defined(_WIN32)
static LARGE_INTEGER freq; 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; return 0;
LARGE_INTEGER count; LARGE_INTEGER count;
@ -738,7 +738,7 @@ static int64_t rsnd_get_time_usec(void)
return sysGetSystemTime(); return sysGetSystemTime();
#elif defined(GEKKO) #elif defined(GEKKO)
return ticks_to_microsecs(gettime()); 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; clock_serv_t cclock;
mach_timespec_t mts; mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); 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); slock_lock(rd->thread.mutex);
fifo_write(rd->fifo_buffer, buf, size); fifo_write(rd->fifo_buffer, buf, size);
slock_unlock(rd->thread.mutex); 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 */ /* 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); scond_signal(rd->thread.cond);
return size; return size;
@ -941,7 +945,7 @@ static int rsnd_close_ctl(rsound_t *rd)
else if ( fd.revents & POLLHUP ) else if ( fd.revents & POLLHUP )
return 0; return 0;
// Let's wait for reply (or POLLHUP) /* Let's wait for reply (or POLLHUP) */
fd.events = POLLIN; fd.events = POLLIN;
int index = 0; int index = 0;
@ -958,14 +962,14 @@ static int rsnd_close_ctl(rsound_t *rd)
if (fd.revents & POLLIN) if (fd.revents & POLLIN)
{ {
const char *subchar; const char *subchar;
/* We just read everything in large chunks until we find
// We just read everything in large chunks until we find what we're looking for * what we're looking for */
int rc = net_recv(rd->conn.ctl_socket, buf + index, RSD_PROTO_MAXSIZE*2 - 1 - index, 0); int rc = net_recv(rd->conn.ctl_socket, buf + index, RSD_PROTO_MAXSIZE*2 - 1 - index, 0);
if (rc <= 0 ) if (rc <= 0 )
return -1; return -1;
// Can we find it directly? /* Can we find it directly? */
if ( strstr(buf, "RSD 12 CLOSECTL OK") != NULL ) if ( strstr(buf, "RSD 12 CLOSECTL OK") != NULL )
break; break;
else if ( strstr(buf, "RSD 15 CLOSECTL ERROR") != NULL ) else if ( strstr(buf, "RSD 15 CLOSECTL ERROR") != NULL )
@ -989,8 +993,9 @@ static int rsnd_close_ctl(rsound_t *rd)
return 0; return 0;
} }
// Sends delay info request to server on the ctl socket. This code section isn't critical, and will work if it works. /* Sends delay info request to server on the ctl socket.
// It will never block. * 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) static int rsnd_send_info_query(rsound_t *rd)
{ {
char tmpbuf[RSD_PROTO_MAXSIZE]; char tmpbuf[RSD_PROTO_MAXSIZE];
@ -1007,15 +1012,15 @@ static int rsnd_send_info_query(rsound_t *rd)
return 0; return 0;
} }
// We check if there's any pending delay information from the server. /* We check if there's any pending delay information from the server.
// In that case, we read the packet. * In that case, we read the packet. */
static int rsnd_update_server_info(rsound_t *rd) static int rsnd_update_server_info(rsound_t *rd)
{ {
long long int client_ptr = -1; long long int client_ptr = -1;
long long int serv_ptr = -1; long long int serv_ptr = -1;
char temp[RSD_PROTO_MAXSIZE + 1] = {0}; 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 (;;) for (;;)
{ {
ssize_t rc; ssize_t rc;
@ -1023,7 +1028,7 @@ static int rsnd_update_server_info(rsound_t *rd)
char *tmpstr; char *tmpstr;
memset(temp, 0, sizeof(temp)); 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); rc = rsnd_recv_chunk(rd->conn.ctl_socket, temp, RSD_PROTO_CHUNKSIZE, 0);
if ( rc == 0 ) if ( rc == 0 )
break; break;
@ -1035,22 +1040,22 @@ static int rsnd_update_server_info(rsound_t *rd)
if (!(substr = strstr(temp, "RSD"))) if (!(substr = strstr(temp, "RSD")))
return -1; return -1;
// Jump over "RSD" in header /* Jump over "RSD" in header */
substr += 3; 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); 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 ) if ( rsnd_recv_chunk(rd->conn.ctl_socket, temp, len, 0) < len )
return -1; return -1;
// We only bother if this is an INFO message. /* We only bother if this is an INFO message. */
substr = strstr(temp, "INFO"); substr = strstr(temp, "INFO");
if (!substr) if (!substr)
continue; continue;
// Jump over "INFO" in header /* Jump over "INFO" in header */
substr += 4; substr += 4;
client_ptr = strtoull(substr, &tmpstr, 0); 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); 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 ) if ( rd->total_written - client_ptr < 4 * rd->backend_info.chunk_size && rd->total_written > client_ptr )
{ {
int offset_delta = delta - delay; int offset_delta = delta - delay;
@ -1094,7 +1099,7 @@ static int rsnd_update_server_info(rsound_t *rd)
return 0; return 0;
} }
// Sort of simulates the behavior of pthread_cancel() /* Sort of simulates the behavior of pthread_cancel() */
#define _TEST_CANCEL() \ #define _TEST_CANCEL() \
if ( !rd->thread_active ) \ if ( !rd->thread_active ) \
break break
@ -1115,8 +1120,8 @@ static void rsnd_thread ( void * thread_data )
{ {
_TEST_CANCEL(); _TEST_CANCEL();
// We ask the server to send its latest backend data. Do not really care about errors atm. /* 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 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) ) if ( (rd->conn_type & RSD_CONN_PROTO) && (rd->total_written > rd->channels * rd->rate * rd->samplesize) )
{ {
rsnd_send_info_query(rd); rsnd_send_info_query(rd);
@ -1175,8 +1180,9 @@ static void rsnd_thread ( void * thread_data )
if ( rd->thread_active ) if ( rd->thread_active )
{ {
// There is a very slim change of getting a deadlock using the cond_wait scheme. /* 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. * This solution is rather dirty, but avoids complete deadlocks at the very least.
*/
slock_lock(rd->thread.cond_mutex); slock_lock(rd->thread.cond_mutex);
scond_signal(rd->thread.cond); scond_signal(rd->thread.cond);
@ -1243,9 +1249,10 @@ static void rsnd_cb_thread(void *thread_data)
} }
else else
{ {
// The network might do things in large chunks, so it may request large amounts of data in short periods of time. /* 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 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 * This is somewhat dirty, but I cannot see a better solution
*/
retro_sleep(1); retro_sleep(1);
} }
} }
@ -1306,13 +1313,13 @@ static int rsnd_reset(rsound_t *rd)
int rsd_stop(rsound_t *rd) int rsd_stop(rsound_t *rd)
{ {
const char buf[] = "RSD 5 STOP";
retro_assert(rd != NULL); retro_assert(rd != NULL);
rsnd_stop_thread(rd); 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_send_chunk(rd->conn.ctl_socket, buf, strlen(buf), 0);
rsnd_reset(rd); rsnd_reset(rd);
@ -1364,7 +1371,7 @@ int rsd_exec(rsound_t *rsound)
retro_assert(rsound != NULL); retro_assert(rsound != NULL);
RSD_DEBUG("[RSound] rsd_exec().\n"); 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 ) if ( rsound->conn.socket < 0 )
{ {
RSD_DEBUG("[RSound] Calling rsd_start().\n"); 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); rd->max_latency = *((int*)param);
break; break;
// Checks if format is valid. /* Checks if format is valid. */
case RSD_FORMAT: case RSD_FORMAT:
rd->format = (uint16_t)(*((int*)param)); rd->format = (uint16_t)(*((int*)param));
rd->samplesize = rsnd_format_to_samplesize(rd->format); rd->samplesize = rsnd_format_to_samplesize(rd->format);
@ -1555,6 +1562,7 @@ int rsd_pause(rsound_t* rsound, int enable)
int rsd_init(rsound_t** rsound) int rsd_init(rsound_t** rsound)
{ {
int format = RSD_S16_LE;
*rsound = calloc(1, sizeof(rsound_t)); *rsound = calloc(1, sizeof(rsound_t));
if (*rsound == NULL) if (*rsound == NULL)
return -1; return -1;
@ -1569,8 +1577,7 @@ int rsd_init(rsound_t** rsound)
(*rsound)->cb_lock = slock_new(); (*rsound)->cb_lock = slock_new();
(*rsound)->thread.cond = scond_new(); (*rsound)->thread.cond = scond_new();
// Assumes default of S16_LE samples. /* Assumes default of S16_LE samples. */
int format = RSD_S16_LE;
rsd_set_param(*rsound, RSD_FORMAT, &format); rsd_set_param(*rsound, RSD_FORMAT, &format);
rsd_set_param(*rsound, RSD_HOST, RSD_DEFAULT_HOST); rsd_set_param(*rsound, RSD_HOST, RSD_DEFAULT_HOST);

@ -205,4 +205,4 @@ static INLINE void ctr_set_scale_vector(ctr_scale_vector_t* vec,
vec->v = -1.0 / texture_height; vec->v = -1.0 / texture_height;
} }
#endif // CTR_COMMON_H__ #endif /* CTR_COMMON_H__ */

@ -18,7 +18,7 @@
#ifndef __FPGA_COMMON_H #ifndef __FPGA_COMMON_H
#define __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 STORAGE_SIZE NUMBER_OF_WRITE_FRAMES * ((1920*1080)<<2)
#define FRAME_SIZE (STORAGE_SIZE / NUMBER_OF_WRITE_FRAMES) #define FRAME_SIZE (STORAGE_SIZE / NUMBER_OF_WRITE_FRAMES)

@ -159,9 +159,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
id<CAMetalDrawable> _drawable; id<CAMetalDrawable> _drawable;
video_viewport_t _viewport; video_viewport_t _viewport;
id<MTLSamplerState> _samplers[TEXTURE_FILTER_MIPMAP_NEAREST + 1]; id<MTLSamplerState> _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<MTLRenderCommandEncoder> _rce; id<MTLRenderCommandEncoder> _rce;
id<MTLCommandBuffer> _blitCommandBuffer; id<MTLCommandBuffer> _blitCommandBuffer;
@ -402,9 +402,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
{ {
vals = [MTLFunctionConstantValues new]; vals = [MTLFunctionConstantValues new];
float values[3] = { float values[3] = {
1.25f, // baseScale 1.25f, /* baseScale */
0.50f, // density 0.50f, /* density */
0.15f, // speed 0.15f, /* speed */
}; };
[vals setConstantValue:&values[0] type:MTLDataTypeFloat withName:@"snowBaseScale"]; [vals setConstantValue:&values[0] type:MTLDataTypeFloat withName:@"snowBaseScale"];
[vals setConstantValue:&values[1] type:MTLDataTypeFloat withName:@"snowDensity"]; [vals setConstantValue:&values[1] type:MTLDataTypeFloat withName:@"snowDensity"];
@ -423,9 +423,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
{ {
vals = [MTLFunctionConstantValues new]; vals = [MTLFunctionConstantValues new];
float values[3] = { float values[3] = {
3.50f, // baseScale 3.50f, /* baseScale */
0.70f, // density 0.70f, /* density */
0.25f, // speed 0.25f, /* speed */
}; };
[vals setConstantValue:&values[0] type:MTLDataTypeFloat withName:@"snowBaseScale"]; [vals setConstantValue:&values[0] type:MTLDataTypeFloat withName:@"snowBaseScale"];
[vals setConstantValue:&values[1] type:MTLDataTypeFloat withName:@"snowDensity"]; [vals setConstantValue:&values[1] type:MTLDataTypeFloat withName:@"snowDensity"];
@ -634,7 +634,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
return; return;
_captureEnabled = captureEnabled; _captureEnabled = captureEnabled;
//_layer.framebufferOnly = !captureEnabled; #if 0
_layer.framebufferOnly = !captureEnabled;
#endif
} }
- (bool)captureEnabled - (bool)captureEnabled
@ -772,7 +774,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
[bce endEncoding]; [bce endEncoding];
} }
#endif #endif
// pending blits for mipmaps or render passes for slang shaders /* Pending blits for mipmaps or render passes for slang shaders */
[_blitCommandBuffer commit]; [_blitCommandBuffer commit];
[_blitCommandBuffer waitUntilCompleted]; [_blitCommandBuffer waitUntilCompleted];
_blitCommandBuffer = nil; _blitCommandBuffer = nil;
@ -829,7 +831,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
id<MTLDevice> _device; id<MTLDevice> _device;
NSUInteger _blockLen; NSUInteger _blockLen;
BufferNode *_head; BufferNode *_head;
NSUInteger _offset; // offset into _current NSUInteger _offset; /* offset into _current */
BufferNode *_current; BufferNode *_current;
NSUInteger _length; NSUInteger _length;
NSUInteger _allocated; NSUInteger _allocated;
@ -1285,13 +1287,13 @@ static const NSUInteger kConstantAlignment = 4;
@implementation TexturedView @implementation TexturedView
{ {
Context *_context; Context *_context;
id<MTLTexture> _texture; // optimal render texture id<MTLTexture> _texture; /* Optimal render texture */
Vertex _v[4]; Vertex _v[4];
CGSize _size; // size of view in pixels CGSize _size; /* Size of view in pixels */
CGRect _frame; CGRect _frame;
NSUInteger _bpp; NSUInteger _bpp;
id<MTLTexture> _src; // source texture id<MTLTexture> _src; /* Source texture */
bool _srcDirty; bool _srcDirty;
} }

@ -45,33 +45,24 @@
#define STRUCT_ASSIGN(x, y) \ #define STRUCT_ASSIGN(x, y) \
{ \ { \
NSObject * __y = y; \ NSObject * __y = y; \
if (x != nil) { \ if (x != nil) \
{ \
NSObject * __foo = (__bridge_transfer NSObject *)(__bridge void *)(x); \ NSObject * __foo = (__bridge_transfer NSObject *)(__bridge void *)(x); \
__foo = nil; \ __foo = nil; \
x = (__bridge __typeof__(x))nil; \ x = (__bridge __typeof__(x))nil; \
} \ } \
if (__y != nil) \ if (__y != nil) \
x = (__bridge __typeof__(x))(__bridge_retained void *)((NSObject *)__y); \ x = (__bridge __typeof__(x))(__bridge_retained void *)((NSObject *)__y)
}
@implementation MetalView @implementation MetalView
#if !defined(HAVE_COCOATOUCH) #if !defined(HAVE_COCOATOUCH)
- (void)keyDown:(NSEvent*)theEvent - (void)keyDown:(NSEvent*)theEvent { }
{
}
#endif #endif
/* Stop the annoying sound when pressing a key. */ /* Stop the annoying sound when pressing a key. */
- (BOOL)acceptsFirstResponder - (BOOL)acceptsFirstResponder { return YES; }
{ - (BOOL)isFlipped { return YES; }
return YES;
}
- (BOOL)isFlipped
{
return YES;
}
@end @end
#pragma mark - private categories #pragma mark - private categories
@ -110,15 +101,14 @@
CAMetalLayer *_layer; CAMetalLayer *_layer;
// render target layer state /* Render target layer state */
id<MTLRenderPipelineState> _t_pipelineState; id<MTLRenderPipelineState> _t_pipelineState;
id<MTLRenderPipelineState> _t_pipelineStateNoAlpha; id<MTLRenderPipelineState> _t_pipelineStateNoAlpha;
id<MTLSamplerState> _samplerStateLinear; id<MTLSamplerState> _samplerStateLinear;
id<MTLSamplerState> _samplerStateNearest; id<MTLSamplerState> _samplerStateNearest;
// other state Uniforms _viewportMVP; /* Other state */
Uniforms _viewportMVP;
} }
- (instancetype)initWithVideo:(const video_info_t *)video - (instancetype)initWithVideo:(const video_info_t *)video
@ -127,6 +117,7 @@
{ {
if (self = [super init]) if (self = [super init])
{ {
gfx_ctx_mode_t mode;
_device = MTLCreateSystemDefaultDevice(); _device = MTLCreateSystemDefaultDevice();
MetalView *view = (MetalView *)apple_platform.renderView; MetalView *view = (MetalView *)apple_platform.renderView;
view.device = _device; view.device = _device;
@ -134,9 +125,7 @@
_layer = (CAMetalLayer *)view.layer; _layer = (CAMetalLayer *)view.layer;
if (![self _initMetal]) if (![self _initMetal])
{
return nil; return nil;
}
_video = *video; _video = *video;
_viewport = (video_viewport_t *)calloc(1, sizeof(video_viewport_t)); _viewport = (video_viewport_t *)calloc(1, sizeof(video_viewport_t));
@ -144,16 +133,16 @@
_keepAspect = _video.force_aspect; _keepAspect = _video.force_aspect;
gfx_ctx_mode_t mode = { mode.width = _video.width;
.width = _video.width, mode.height = _video.height;
.height = _video.height, mode.fullscreen = _video.fullscreen;
.fullscreen = _video.fullscreen,
};
if (mode.width == 0 || mode.height == 0) 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 /* 0 indicates full screen, so we'll use the view's dimensions,
// If this turns out to be the wrong assumption, we can use NSScreen to query the 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; CGSize size = view.frame.size;
mode.width = (unsigned int)size.width; mode.width = (unsigned int)size.width;
mode.height = (unsigned int)size.height; mode.height = (unsigned int)size.height;
@ -164,16 +153,17 @@
*input = NULL; *input = NULL;
*inputData = NULL; *inputData = NULL;
// graphics display driver /* Graphics display driver */
_display = [[MenuDisplay alloc] initWithContext:_context]; _display = [[MenuDisplay alloc] initWithContext:_context];
/* Menu view */
// menu view
_menu = [[MetalMenu alloc] initWithContext:_context]; _menu = [[MetalMenu alloc] initWithContext:_context];
// frame buffer view /* Framebuffer view */
{ {
ViewDescriptor *vd = [ViewDescriptor new]; ViewDescriptor *vd = [ViewDescriptor new];
vd.format = _video.rgb32 ? RPixelFormatBGRX8Unorm : RPixelFormatB5G6R5Unorm; vd.format = _video.rgb32
? RPixelFormatBGRX8Unorm
: RPixelFormatB5G6R5Unorm;
vd.size = CGSizeMake(video->width, video->height); vd.size = CGSizeMake(video->width, video->height);
vd.filter = _video.smooth ? RTextureFilterLinear : RTextureFilterNearest; vd.filter = _video.smooth ? RTextureFilterLinear : RTextureFilterNearest;
_frameView = [[FrameView alloc] initWithDescriptor:vd context:_context]; _frameView = [[FrameView alloc] initWithDescriptor:vd context:_context];
@ -181,7 +171,7 @@
[_frameView setFilteringIndex:0 smooth:video->smooth]; [_frameView setFilteringIndex:0 smooth:video->smooth];
} }
// overlay view /* Overlay view */
_overlay = [[Overlay alloc] initWithContext:_context]; _overlay = [[Overlay alloc] initWithContext:_context];
font_driver_init_osd((__bridge void *)self, font_driver_init_osd((__bridge void *)self,
@ -207,10 +197,12 @@
{ {
_library = [_device newDefaultLibrary]; _library = [_device newDefaultLibrary];
_context = [[Context alloc] initWithDevice:_device _context = [[Context alloc] initWithDevice:_device
layer:_layer layer:_layer library:_library];
library:_library];
{ {
NSError *err;
MTLRenderPipelineDescriptor *psd;
MTLRenderPipelineColorAttachmentDescriptor *ca;
MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
vd.attributes[0].offset = 0; vd.attributes[0].offset = 0;
vd.attributes[0].format = MTLVertexFormatFloat3; vd.attributes[0].format = MTLVertexFormatFloat3;
@ -218,10 +210,10 @@
vd.attributes[1].format = MTLVertexFormatFloat2; vd.attributes[1].format = MTLVertexFormatFloat2;
vd.layouts[0].stride = sizeof(Vertex); vd.layouts[0].stride = sizeof(Vertex);
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new]; psd = [MTLRenderPipelineDescriptor new];
psd.label = @"Pipeline+Alpha"; psd.label = @"Pipeline+Alpha";
MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0]; ca = psd.colorAttachments[0];
ca.pixelFormat = _layer.pixelFormat; ca.pixelFormat = _layer.pixelFormat;
ca.blendingEnabled = YES; ca.blendingEnabled = YES;
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
@ -234,7 +226,6 @@
psd.vertexFunction = [_library newFunctionWithName:@"basic_vertex_proj_tex"]; psd.vertexFunction = [_library newFunctionWithName:@"basic_vertex_proj_tex"];
psd.fragmentFunction = [_library newFunctionWithName:@"basic_fragment_proj_tex"]; psd.fragmentFunction = [_library newFunctionWithName:@"basic_fragment_proj_tex"];
NSError *err;
_t_pipelineState = [_device newRenderPipelineStateWithDescriptor:psd error:&err]; _t_pipelineState = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil) if (err != nil)
{ {
@ -271,19 +262,14 @@
video_driver_set_size(_viewport->full_width, _viewport->full_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); video_driver_update_viewport(_viewport, forceFull, _keepAspect);
_context.viewport = _viewport; /* Update matrix */
// update matrix
_context.viewport = _viewport;
_viewportMVP.outputSize = simd_make_float2(_viewport->full_width, _viewport->full_height); _viewportMVP.outputSize = simd_make_float2(_viewport->full_width, _viewport->full_height);
} }
#pragma mark - video #pragma mark - video
- (void)setVideo:(const video_info_t *)video - (void)setVideo:(const video_info_t *)video { }
{
}
- (bool)renderFrame:(const void *)frame - (bool)renderFrame:(const void *)frame
data:(void*)data data:(void*)data
@ -418,7 +404,7 @@
{ {
id<MTLRenderCommandEncoder> rce = _context.rce; id<MTLRenderCommandEncoder> rce = _context.rce;
/* draw back buffer */ /* Draw back buffer */
[rce pushDebugGroup:@"core frame"]; [rce pushDebugGroup:@"core frame"];
[_frameView drawWithContext:_context]; [_frameView drawWithContext:_context];
@ -427,13 +413,9 @@
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms]; [rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
[rce setRenderPipelineState:_t_pipelineStateNoAlpha]; [rce setRenderPipelineState:_t_pipelineStateNoAlpha];
if (_frameView.filter == RTextureFilterNearest) if (_frameView.filter == RTextureFilterNearest)
{
[rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw]; [rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw];
}
else else
{
[rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw]; [rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw];
}
[_frameView drawWithEncoder:rce]; [_frameView drawWithEncoder:rce];
} }
[rce popDebugGroup]; [rce popDebugGroup];
@ -455,13 +437,9 @@
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms]; [rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
[rce setRenderPipelineState:_t_pipelineState]; [rce setRenderPipelineState:_t_pipelineState];
if (_menu.view.filter == RTextureFilterNearest) if (_menu.view.filter == RTextureFilterNearest)
{
[rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw]; [rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw];
}
else else
{
[rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw]; [rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw];
}
[_menu.view drawWithEncoder:rce]; [_menu.view drawWithEncoder:rce];
[rce popDebugGroup]; [rce popDebugGroup];
} }
@ -476,31 +454,23 @@
#endif #endif
} }
- (void)_endFrame /* TODO/FIXME (sgc): resize all drawables */
{ - (void)setNeedsResize { }
[_context end];
}
- (void)setNeedsResize
{
// TODO(sgc): resize all drawables
}
- (void)_endFrame { [_context end]; }
- (void)setRotation:(unsigned)rotation - (void)setRotation:(unsigned)rotation
{ {
[_context setRotation:rotation]; [_context setRotation:rotation];
} }
- (Uniforms *)viewportMVP { return &_viewportMVP; }
- (Uniforms *)viewportMVP
{
return &_viewportMVP;
}
#pragma mark - MTKViewDelegate #pragma mark - MTKViewDelegate
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size
{ {
#ifndef NDEBUG
NSLog(@"mtkView drawableSizeWillChange to: %f x %f",size.width,size.height); NSLog(@"mtkView drawableSizeWillChange to: %f x %f",size.width,size.height);
#endif
#ifdef HAVE_COCOATOUCH #ifdef HAVE_COCOATOUCH
CGFloat scale = [[UIScreen mainScreen] scale]; 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]; [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 #endif
} }
- (void)drawInMTKView:(MTKView *)view - (void)drawInMTKView:(MTKView *)view { }
{
}
@end @end
@implementation MetalMenu @implementation MetalMenu
@ -526,9 +492,7 @@
- (instancetype)initWithContext:(Context *)context - (instancetype)initWithContext:(Context *)context
{ {
if (self = [super init]) if (self = [super init])
{
_context = context; _context = context;
}
return self; return self;
} }
@ -561,10 +525,8 @@
if (!(CGSizeEqualToSize(_view.size, size) && if (!(CGSizeEqualToSize(_view.size, size) &&
_view.format == format && _view.format == format &&
_view.filter == filter)) _view.filter == filter))
{
_view = nil; _view = nil;
} }
}
if (!_view) if (!_view)
{ {
@ -632,14 +594,14 @@ typedef struct MTLALIGN(16)
@implementation FrameView @implementation FrameView
{ {
Context *_context; Context *_context;
id<MTLTexture> _texture; // final render texture id<MTLTexture> _texture; /* Final render texture */
Vertex _v[4]; Vertex _v[4];
VertexSlang _vertex[4]; VertexSlang _vertex[4];
CGSize _size; // size of view in pixels CGSize _size; /* Size of view in pixels */
CGRect _frame; CGRect _frame;
NSUInteger _bpp; NSUInteger _bpp;
id<MTLTexture> _src; // src texture id<MTLTexture> _src; /* Source texture */
bool _srcDirty; bool _srcDirty;
id<MTLSamplerState> _samplers[RARCH_FILTER_MAX][RARCH_WRAP_MAX]; id<MTLSamplerState> _samplers[RARCH_FILTER_MAX][RARCH_WRAP_MAX];
@ -661,14 +623,11 @@ typedef struct MTLALIGN(16)
_format = d.format; _format = d.format;
_bpp = RPixelFormatToBPP(_format); _bpp = RPixelFormatToBPP(_format);
_filter = d.filter; _filter = d.filter;
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm) if ( _format == RPixelFormatBGRA8Unorm
{ || _format == RPixelFormatBGRX8Unorm)
_drawState = ViewDrawStateEncoder; _drawState = ViewDrawStateEncoder;
}
else else
{
_drawState = ViewDrawStateAll; _drawState = ViewDrawStateAll;
}
_visible = YES; _visible = YES;
_engine.mvp = matrix_proj_ortho(0, 1, 0, 1); _engine.mvp = matrix_proj_ortho(0, 1, 0, 1);
[self _initSamplers]; [self _initSamplers];
@ -677,7 +636,7 @@ typedef struct MTLALIGN(16)
self.frame = CGRectMake(0, 0, 1, 1); self.frame = CGRectMake(0, 0, 1, 1);
resize_render_targets = YES; resize_render_targets = YES;
// init slang vertex buffer /* Initialize slang vertex buffer */
VertexSlang v[4] = { VertexSlang v[4] = {
{simd_make_float4(0, 1, 0, 1), simd_make_float2(0, 1)}, {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(1, 1, 0, 1), simd_make_float2(1, 1)},
@ -691,11 +650,14 @@ typedef struct MTLALIGN(16)
- (void)_initSamplers - (void)_initSamplers
{ {
int i;
MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new]; MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new];
/* Initialize samplers */ /* Initialize samplers */
for (unsigned i = 0; i < RARCH_WRAP_MAX; i++) for (i = 0; i < RARCH_WRAP_MAX; i++)
{ {
id<MTLSamplerState> ss;
switch (i) switch (i)
{ {
case RARCH_WRAP_BORDER: case RARCH_WRAP_BORDER:
@ -726,7 +688,7 @@ typedef struct MTLALIGN(16)
sd.minFilter = MTLSamplerMinMagFilterLinear; sd.minFilter = MTLSamplerMinMagFilterLinear;
sd.magFilter = MTLSamplerMinMagFilterLinear; sd.magFilter = MTLSamplerMinMagFilterLinear;
id<MTLSamplerState> ss = [_context.device newSamplerStateWithDescriptor:sd]; ss = [_context.device newSamplerStateWithDescriptor:sd];
_samplers[RARCH_FILTER_LINEAR][i] = ss; _samplers[RARCH_FILTER_LINEAR][i] = ss;
sd.minFilter = MTLSamplerMinMagFilterNearest; sd.minFilter = MTLSamplerMinMagFilterNearest;
@ -757,9 +719,11 @@ typedef struct MTLALIGN(16)
resize_render_targets = YES; resize_render_targets = YES;
if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm) if ( _format != RPixelFormatBGRA8Unorm
&& _format != RPixelFormatBGRX8Unorm)
{ {
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint MTLTextureDescriptor *td = [MTLTextureDescriptor
texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint
width:(NSUInteger)size.width width:(NSUInteger)size.width
height:(NSUInteger)size.height height:(NSUInteger)size.height
mipmapped:NO]; mipmapped:NO];
@ -778,16 +742,13 @@ typedef struct MTLALIGN(16)
return; return;
_frame = frame; _frame = frame;
/* Update vertices */
// update vertices
CGPoint o = frame.origin; CGPoint o = frame.origin;
CGSize s = frame.size; CGSize s = frame.size;
CGFloat l = o.x; CGFloat l = o.x;
CGFloat t = o.y; CGFloat t = o.y;
CGFloat r = o.x + s.width; CGFloat r = o.x + s.width;
CGFloat b = o.y + s.height; CGFloat b = o.y + s.height;
Vertex v[4] = { Vertex v[4] = {
{simd_make_float3(l, b, 0), simd_make_float2(0, 1)}, {simd_make_float3(l, b, 0), simd_make_float2(0, 1)},
{simd_make_float3(r, b, 0), simd_make_float2(1, 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)); memcpy(_v, v, sizeof(_v));
} }
- (CGRect)frame - (CGRect)frame { return _frame; }
{
return _frame;
}
- (void)_convertFormat - (void)_convertFormat
{ {
@ -840,24 +798,23 @@ typedef struct MTLALIGN(16)
if (_engine.frame.texture[0].size_data.x != _size.width || if (_engine.frame.texture[0].size_data.x != _size.width ||
_engine.frame.texture[0].size_data.y != _size.height) _engine.frame.texture[0].size_data.y != _size.height)
{ {
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm width:(NSUInteger)_size.width height:(NSUInteger)_size.height mipmapped:false];
width:(NSUInteger)_size.width td.usage = MTLTextureUsageShaderRead
height:(NSUInteger)_size.height | MTLTextureUsageShaderWrite;
mipmapped:false];
td.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite;
[self _initTexture:&_engine.frame.texture[0] withDescriptor:td]; [self _initTexture:&_engine.frame.texture[0] withDescriptor:td];
} }
} }
- (bool)readViewport:(uint8_t *)buffer isIdle:(bool)isIdle - (bool)readViewport:(uint8_t *)buffer isIdle:(bool)isIdle
{ {
bool res;
bool enabled = _context.captureEnabled; bool enabled = _context.captureEnabled;
if (!enabled) if (!enabled)
_context.captureEnabled = YES; _context.captureEnabled = YES;
video_driver_cached_frame(); video_driver_cached_frame();
bool res = [_context readBackBuffer:buffer]; res = [_context readBackBuffer:buffer];
if (!enabled) if (!enabled)
_context.captureEnabled = NO; _context.captureEnabled = NO;
@ -915,11 +872,10 @@ typedef struct MTLALIGN(16)
- (void)_initHistory - (void)_initHistory
{ {
int i; int i;
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm width:(NSUInteger)_size.width height:(NSUInteger)_size.height mipmapped:false];
width:(NSUInteger)_size.width td.usage = MTLTextureUsageShaderRead
height:(NSUInteger)_size.height | MTLTextureUsageShaderWrite
mipmapped:false]; | MTLTextureUsageRenderTarget;
td.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite | MTLTextureUsageRenderTarget;
for (i = 0; i < _shader->history_size + 1; i++) for (i = 0; i < _shader->history_size + 1; i++)
[self _initTexture:&_engine.frame.texture[i] withDescriptor:td]; [self _initTexture:&_engine.frame.texture[i] withDescriptor:td];
@ -939,7 +895,10 @@ typedef struct MTLALIGN(16)
- (void)drawWithContext:(Context *)ctx - (void)drawWithContext:(Context *)ctx
{ {
unsigned i; int i;
id<MTLCommandBuffer> cb;
MTLRenderPassDescriptor *rpd;
_texture = _engine.frame.texture[0].view; _texture = _engine.frame.texture[0].view;
[self _convertFormat]; [self _convertFormat];
@ -956,23 +915,25 @@ typedef struct MTLALIGN(16)
} }
} }
id<MTLCommandBuffer> cb = ctx.blitCommandBuffer; cb = ctx.blitCommandBuffer;
[cb pushDebugGroup:@"shaders"]; [cb pushDebugGroup:@"shaders"];
MTLRenderPassDescriptor *rpd = [MTLRenderPassDescriptor new]; rpd = [MTLRenderPassDescriptor new];
rpd.colorAttachments[0].loadAction = MTLLoadActionDontCare; rpd.colorAttachments[0].loadAction = MTLLoadActionDontCare;
rpd.colorAttachments[0].storeAction = MTLStoreActionStore; 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<MTLTexture> textures[SLANG_NUM_BINDINGS] = {NULL};
id<MTLSamplerState> samplers[SLANG_NUM_BINDINGS] = {NULL};
texture_sem_t *texture_sem = NULL;
id<MTLRenderCommandEncoder> rce = nil; id<MTLRenderCommandEncoder> rce = nil;
BOOL backBuffer = (_engine.pass[i].rt.view == nil); BOOL backBuffer = (_engine.pass[i].rt.view == nil);
if (backBuffer) if (backBuffer)
{
rce = _context.rce; rce = _context.rce;
}
else else
{ {
rpd.colorAttachments[0].texture = _engine.pass[i].rt.view; rpd.colorAttachments[0].texture = _engine.pass[i].rt.view;
@ -981,8 +942,8 @@ typedef struct MTLALIGN(16)
[rce setRenderPipelineState:_engine.pass[i]._state]; [rce setRenderPipelineState:_engine.pass[i]._state];
NSURL *shaderPath = [NSURL fileURLWithPath:_engine.pass[i]._state.label]; shader_path = [NSURL fileURLWithPath:_engine.pass[i]._state.label];
rce.label = shaderPath.lastPathComponent.stringByDeletingPathExtension; rce.label = shader_path.lastPathComponent.stringByDeletingPathExtension;
_engine.pass[i].frame_count = (uint32_t)_frameCount; _engine.pass[i].frame_count = (uint32_t)_frameCount;
if (_shader->pass[i].frame_count_mod) if (_shader->pass[i].frame_count_mod)
@ -996,7 +957,7 @@ typedef struct MTLALIGN(16)
_engine.pass[i].frame_direction = 1; _engine.pass[i].frame_direction = 1;
#endif #endif
for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++) for (j = 0; j < SLANG_CBUFFER_MAX; j++)
{ {
id<MTLBuffer> buffer = _engine.pass[i].buffers[j]; id<MTLBuffer> buffer = _engine.pass[i].buffers[j];
cbuffer_sem_t *buffer_sem = &_engine.pass[i].semantics.cbuffers[j]; cbuffer_sem_t *buffer_sem = &_engine.pass[i].semantics.cbuffers[j];
@ -1024,10 +985,8 @@ typedef struct MTLALIGN(16)
} }
} }
__unsafe_unretained id<MTLTexture> textures[SLANG_NUM_BINDINGS] = {NULL}; texture_sem = _engine.pass[i].semantics.textures;
id<MTLSamplerState> samplers[SLANG_NUM_BINDINGS] = {NULL};
texture_sem_t *texture_sem = _engine.pass[i].semantics.textures;
while (texture_sem->stage_mask) while (texture_sem->stage_mask)
{ {
int binding = texture_sem->binding; int binding = texture_sem->binding;
@ -1038,13 +997,9 @@ typedef struct MTLALIGN(16)
} }
if (backBuffer) if (backBuffer)
{
[rce setViewport:_engine.frame.viewport]; [rce setViewport:_engine.frame.viewport];
}
else else
{
[rce setViewport:_engine.pass[i].viewport]; [rce setViewport:_engine.pass[i].viewport];
}
[rce setFragmentTextures:textures withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)]; [rce setFragmentTextures:textures withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
[rce setFragmentSamplerStates:samplers 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]; [rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
if (!backBuffer) if (!backBuffer)
{
[rce endEncoding]; [rce endEncoding];
}
_texture = _engine.pass[i].rt.view; _texture = _engine.pass[i].rt.view;
} }
@ -1069,10 +1022,13 @@ typedef struct MTLALIGN(16)
- (void)_updateRenderTargets - (void)_updateRenderTargets
{ {
if (!_shader || !resize_render_targets) return; int i;
NSUInteger width, height;
if (!_shader || !resize_render_targets)
return;
// release existing targets /* release existing targets */
for (int i = 0; i < _shader->passes; i++) for (i = 0; i < _shader->passes; i++)
{ {
STRUCT_ASSIGN(_engine.pass[i].rt.view, nil); STRUCT_ASSIGN(_engine.pass[i].rt.view, nil);
STRUCT_ASSIGN(_engine.pass[i].feedback.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)); 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]; struct video_shader_pass *shader_pass = &_shader->pass[i];
if (shader_pass->fbo.valid) if (shader_pass->fbo.valid)
@ -1137,30 +1095,31 @@ typedef struct MTLALIGN(16)
} }
/* Updating framebuffer size */ /* 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)) || if ((i != (_shader->passes - 1)) ||
(width != _viewport->width) || (height != _viewport->height) || (width != _viewport->width) || (height != _viewport->height) ||
fmt != MTLPixelFormatBGRA8Unorm) fmt != MTLPixelFormatBGRA8Unorm)
{ {
MTLTextureDescriptor *td;
_engine.pass[i].viewport.width = width; _engine.pass[i].viewport.width = width;
_engine.pass[i].viewport.height = height; _engine.pass[i].viewport.height = height;
_engine.pass[i].viewport.znear = 0.0; _engine.pass[i].viewport.znear = 0.0f;
_engine.pass[i].viewport.zfar = 1.0; _engine.pass[i].viewport.zfar = 1.0f;
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:fmt td = [MTLTextureDescriptor
width:width texture2DDescriptorWithPixelFormat:fmt width:width height:height
height:height
mipmapped:false]; mipmapped:false];
td.storageMode = MTLStorageModePrivate; td.storageMode = MTLStorageModePrivate;
td.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget; td.usage = MTLTextureUsageShaderRead
| MTLTextureUsageRenderTarget;
[self _initTexture:&_engine.pass[i].rt withDescriptor:td]; [self _initTexture:&_engine.pass[i].rt withDescriptor:td];
if (shader_pass->feedback) if (shader_pass->feedback)
{
[self _initTexture:&_engine.pass[i].feedback withDescriptor:td]; [self _initTexture:&_engine.pass[i].feedback withDescriptor:td];
} }
}
else else
{ {
_engine.pass[i].rt.size_data.x = width; _engine.pass[i].rt.size_data.x = width;
@ -1175,11 +1134,13 @@ typedef struct MTLALIGN(16)
- (void)_freeVideoShader:(struct video_shader *)shader - (void)_freeVideoShader:(struct video_shader *)shader
{ {
int i;
if (!shader) if (!shader)
return; 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].rt.view, nil);
STRUCT_ASSIGN(_engine.pass[i].feedback.view, nil); STRUCT_ASSIGN(_engine.pass[i].feedback.view, nil);
memset(&_engine.pass[i].rt, 0, sizeof(_engine.pass[i].rt)); 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); 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); 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); STRUCT_ASSIGN(_engine.luts[i].view, nil);
} }
@ -1213,7 +1174,7 @@ typedef struct MTLALIGN(16)
@try @try
{ {
unsigned i; int i;
texture_t *source = NULL; texture_t *source = NULL;
if (!video_shader_load_preset_into_shader(path.UTF8String, shader)) if (!video_shader_load_preset_into_shader(path.UTF8String, shader))
return NO; return NO;
@ -1276,6 +1237,8 @@ typedef struct MTLALIGN(16)
@try @try
{ {
NSError *err; NSError *err;
MTLRenderPipelineColorAttachmentDescriptor *ca;
MTLRenderPipelineDescriptor *psd;
MTLVertexDescriptor *vd = [MTLVertexDescriptor new]; MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
vd.attributes[0].offset = offsetof(VertexSlang, position); vd.attributes[0].offset = offsetof(VertexSlang, position);
vd.attributes[0].format = MTLVertexFormatFloat4; vd.attributes[0].format = MTLVertexFormatFloat4;
@ -1286,16 +1249,14 @@ typedef struct MTLALIGN(16)
vd.layouts[4].stride = sizeof(VertexSlang); vd.layouts[4].stride = sizeof(VertexSlang);
vd.layouts[4].stepFunction = MTLVertexStepFunctionPerVertex; 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] /* TODO/FIXME (sgc): confirm we never
stringByReplacingOccurrencesOfString:shadersPath withString:@""]; * need blending for render passes */
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 */
ca.blendingEnabled = NO; ca.blendingEnabled = NO;
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha; ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha; ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
@ -1338,6 +1299,7 @@ typedef struct MTLALIGN(16)
STRUCT_ASSIGN(_engine.pass[i]._state, STRUCT_ASSIGN(_engine.pass[i]._state,
[_context.device newRenderPipelineStateWithDescriptor:psd error:&err]); [_context.device newRenderPipelineStateWithDescriptor:psd error:&err]);
if (err != nil) if (err != nil)
{ {
save_msl = true; save_msl = true;
@ -1395,24 +1357,21 @@ typedef struct MTLALIGN(16)
for (i = 0; i < shader->luts; i++) for (i = 0; i < shader->luts; i++)
{ {
MTLTextureDescriptor *td;
struct texture_image image = {0}; struct texture_image image = {0};
image.supports_rgba = true; image.supports_rgba = true;
if (!image_texture_load(&image, shader->lut[i].path)) if (!image_texture_load(&image, shader->lut[i].path))
return NO; return NO;
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:image.width height:image.height mipmapped:shader->lut[i].mipmap];
width:image.width
height:image.height
mipmapped:shader->lut[i].mipmap];
td.usage = MTLTextureUsageShaderRead; td.usage = MTLTextureUsageShaderRead;
[self _initTexture:&_engine.luts[i] withDescriptor:td]; [self _initTexture:&_engine.luts[i] withDescriptor:td];
[_engine.luts[i].view replaceRegion:MTLRegionMake2D(0, 0, image.width, image.height) [_engine.luts[i].view replaceRegion:MTLRegionMake2D(0, 0, image.width, image.height)
mipmapLevel:0 withBytes:image.pixels mipmapLevel:0 withBytes:image.pixels
bytesPerRow:4 * image.width]; bytesPerRow:4 * image.width];
/* TODO(sgc): generate mip maps */ /* TODO/FIXME (sgc): generate mip maps */
image_texture_free(&image); image_texture_free(&image);
} }
_shader = shader; _shader = shader;
@ -1421,10 +1380,8 @@ typedef struct MTLALIGN(16)
@finally @finally
{ {
if (shader) if (shader)
{
[self _freeVideoShader:shader]; [self _freeVideoShader:shader];
} }
}
resize_render_targets = YES; resize_render_targets = YES;
init_history = YES; init_history = YES;
@ -1445,25 +1402,23 @@ typedef struct MTLALIGN(16)
- (instancetype)initWithContext:(Context *)context - (instancetype)initWithContext:(Context *)context
{ {
if (self = [super init]) if (self = [super init])
{
_context = context; _context = context;
}
return self; return self;
} }
- (bool)loadImages:(const struct texture_image *)images count:(NSUInteger)count - (bool)loadImages:(const struct texture_image *)images count:(NSUInteger)count
{ {
NSUInteger needed, i;
[self _freeImages]; [self _freeImages];
_images = [NSMutableArray arrayWithCapacity:count]; _images = [NSMutableArray arrayWithCapacity:count];
needed = sizeof(SpriteVertex) * count * 4;
NSUInteger needed = sizeof(SpriteVertex) * count * 4;
if (!_vert || _vert.length < needed) if (!_vert || _vert.length < needed)
{
_vert = [_context.device newBufferWithLength:needed options:PLATFORM_METAL_RESOURCE_STORAGE_MODE]; _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]; _images[i] = [_context newTexture:images[i] mipmapped:NO];
[self updateVertexX:0 y:0 w:1 h:1 index:i]; [self updateVertexX:0 y:0 w:1 h:1 index:i];
@ -1478,6 +1433,7 @@ typedef struct MTLALIGN(16)
- (void)drawWithEncoder:(id<MTLRenderCommandEncoder>)rce - (void)drawWithEncoder:(id<MTLRenderCommandEncoder>)rce
{ {
NSUInteger count, i;
#if !defined(HAVE_COCOATOUCH) #if !defined(HAVE_COCOATOUCH)
if (_vertDirty) if (_vertDirty)
{ {
@ -1486,8 +1442,8 @@ typedef struct MTLALIGN(16)
} }
#endif #endif
NSUInteger count = _images.count; count = _images.count;
for (NSUInteger i = 0; i < count; ++i) for (i = 0; i < count; ++i)
{ {
NSUInteger offset = sizeof(SpriteVertex) * 4 * i; NSUInteger offset = sizeof(SpriteVertex) * 4 * i;
[rce setVertexBuffer:_vert offset:offset atIndex:BufferIndexPositions]; [rce setVertexBuffer:_vert offset:offset atIndex:BufferIndexPositions];
@ -1605,6 +1561,8 @@ MTLPixelFormat SelectOptimalPixelFormat(MTLPixelFormat fmt)
return MTLPixelFormatBGRA8Unorm_sRGB; return MTLPixelFormatBGRA8Unorm_sRGB;
default: default:
return fmt; break;
} }
return fmt;
} }

@ -216,11 +216,12 @@ static void supertwoxsai_generic_xrgb8888(unsigned width, unsigned height,
{ {
supertwoxsai_declare_variables(uint32_t, in, nextline); supertwoxsai_declare_variables(uint32_t, in, nextline);
//--------------------------- B1 B2 /*--------------------------- B1 B2
// 4 5 6 S2 * 4 5 6 S2
// 1 2 3 S1 * 1 2 3 S1
// A1 A2 * A1 A2
//-------------------------------------- *--------------------------------------
*/
supertwoxsai_function(supertwoxsai_result, supertwoxsai_interpolate_xrgb8888, supertwoxsai_interpolate2_xrgb8888); 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); supertwoxsai_declare_variables(uint16_t, in, nextline);
//--------------------------- B1 B2 /*--------------------------- B1 B2
// 4 5 6 S2 * 4 5 6 S2
// 1 2 3 S1 * 1 2 3 S1
// A1 A2 * A1 A2
//-------------------------------------- *--------------------------------------
*/
supertwoxsai_function(supertwoxsai_result, supertwoxsai_interpolate_rgb565, supertwoxsai_interpolate2_rgb565); 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->width = width;
thr->height = y_end - y_start; 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->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;

@ -13,7 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
// Needed for memfd_create /* Needed for memfd_create */
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE /* See feature_test_macros(7) */ #define _GNU_SOURCE /* See feature_test_macros(7) */
#endif #endif
@ -85,7 +85,7 @@ static void keyboard_handle_leave(void *data,
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
wl->input.keyboard_focus = false; wl->input.keyboard_focus = false;
// Release all keys /* Release all keys */
memset(wl->input.key_state, 0, sizeof(wl->input.key_state)); 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]); 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); wl_display_roundtrip(display);
close(pipefd[1]); close(pipefd[1]);
@ -849,9 +849,12 @@ static void data_device_handle_drop(void *data,
line[strcspn(line, "\r\n")] = 0; line[strcspn(line, "\r\n")] = 0;
RARCH_LOG("[Wayland]: > \"%s\"\n", line); RARCH_LOG("[Wayland]: > \"%s\"\n", line);
// TODO: Convert from file:// URI, Implement file loading /* TODO/FIXME: Convert from file:// URI, Implement file loading
//if (wayland_load_content_from_drop(g_filename_from_uri(line, NULL, NULL))) * Drag and Drop */
// RARCH_WARN("----- wayland_load_content_from_drop success\n"); #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); 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; 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)) if (string_is_equal(mime_type, FILE_MIME))
offer_data->is_file_mime_type = true; offer_data->is_file_mime_type = true;
} }
@ -875,7 +878,7 @@ static void data_offer_handle_offer(void *data, struct wl_data_offer *offer,
static void data_offer_handle_source_actions(void *data, static void data_offer_handle_source_actions(void *data,
struct wl_data_offer *offer, enum wl_data_device_manager_dnd_action actions) struct wl_data_offer *offer, enum wl_data_device_manager_dnd_action actions)
{ {
// Report of actions for this offer supported by compositor /* Report of actions for this offer supported by compositor */
data_offer_ctx *offer_data = data; data_offer_ctx *offer_data = data;
offer_data->supported_actions = actions; offer_data->supported_actions = actions;
} }

@ -42,8 +42,8 @@ float cocoa_screen_get_backing_scale_factor(void);
static bool apple_key_state[MAX_KEYS]; static bool apple_key_state[MAX_KEYS];
// Send keyboard inputs directly using RETROK_* codes /* Send keyboard inputs directly using RETROK_* codes
// Used by the iOS custom keyboard implementation * Used by the iOS custom keyboard implementation */
void apple_direct_input_keyboard_event(bool down, void apple_direct_input_keyboard_event(bool down,
unsigned code, uint32_t character, uint32_t mod, unsigned device) unsigned code, uint32_t character, uint32_t mod, unsigned device)
{ {

@ -358,12 +358,12 @@ static inline void initAttributeGem(gemAttribute * attribute,
int initGemVideoConvert(ps3_input_t *ps3) int initGemVideoConvert(ps3_input_t *ps3)
{ {
int ret;
ps3->gem_video_convert.version = 2; ps3->gem_video_convert.version = 2;
ps3->gem_video_convert.format = 2; //GEM_RGBA_640x480; ps3->gem_video_convert.format = 2; /* GEM_RGBA_640x480; */
ps3->gem_video_convert.conversion= GEM_AUTO_WHITE_BALANCE | GEM_COMBINE_PREVIOUS_INPUT_FRAME | ps3->gem_video_convert.conversion = GEM_AUTO_WHITE_BALANCE
GEM_FILTER_OUTLIER_PIXELS | GEM_GAMMA_BOOST; | GEM_COMBINE_PREVIOUS_INPUT_FRAME
| GEM_FILTER_OUTLIER_PIXELS
| GEM_GAMMA_BOOST;
ps3->gem_video_convert.gain = 1.0f; ps3->gem_video_convert.gain = 1.0f;
ps3->gem_video_convert.red_gain = 1.0f; ps3->gem_video_convert.red_gain = 1.0f;
ps3->gem_video_convert.green_gain = 1.0f; ps3->gem_video_convert.green_gain = 1.0f;
@ -373,45 +373,39 @@ int initGemVideoConvert(ps3_input_t *ps3)
ps3->gem_video_convert.buffer_memory = ps3->buffer_mem; ps3->gem_video_convert.buffer_memory = ps3->buffer_mem;
ps3->gem_video_convert.video_data_out = ps3->video_out; ps3->gem_video_convert.video_data_out = ps3->video_out;
ps3->gem_video_convert.alpha = 255; ps3->gem_video_convert.alpha = 255;
ret = gemPrepareVideoConvert(&ps3->gem_video_convert);
return ret; return gemPrepareVideoConvert(&ps3->gem_video_convert);
} }
int initGem(ps3_input_t *ps3) int initGem(ps3_input_t *ps3)
{ {
int ret;
int i; int i;
gemAttribute gem_attr;
ret = initSpurs(ps3); u8 gem_spu_priorities[8] = { 1, 1, 1, 1, 1, 0, 0, 0 }; /* execute */
if (ret) /* libgem jobs */
{ /* on 5 SPUs */
if (initSpurs(ps3))
return -1; return -1;
}
ret = gemGetMemorySize(1); ps3->gem_memory = (void *)malloc(gemGetMemorySize(1));
ps3->gem_memory = (void *)malloc(ret);
if (!ps3->gem_memory) if (!ps3->gem_memory)
return -1; return -1;
u8 gem_spu_priorities[8] = { 1, 1, 1, 1, 1, 0, 0, 0 }; // execute initAttributeGem(&gem_attr, 1, ps3->gem_memory,
// libgem jobs ps3->spurs, gem_spu_priorities);
// on 5 spu
gemAttribute gem_attr;
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; return 0;
} }
void readGemPad(ps3_input_t *ps3, int num_gem) void readGemPad(ps3_input_t *ps3, int num_gem)
{ {
int ret;
unsigned int hues[] = { 4 << 24, 4 << 24, 4 << 24, 4 << 24 }; 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->newGemPad = ps3->gem_state.paddata.buttons & (~ps3->oldGemPad);
ps3->newGemAnalogT = ps3->gem_state.paddata.ANA_T; ps3->newGemAnalogT = ps3->gem_state.paddata.ANA_T;
@ -441,10 +435,8 @@ void readGemAccPosition(int num_gem)
void readGemInertial(ps3_input_t *ps3, int num_gem) void readGemInertial(ps3_input_t *ps3, int num_gem)
{ {
int ret;
VmathVector4 v; VmathVector4 v;
int ret = gemGetInertialState(num_gem, 0, -22000, &ps3->gem_inertial_state);
ret = gemGetInertialState(num_gem, 0, -22000, &ps3->gem_inertial_state);
v.vec128 = ps3->gem_inertial_state.accelerometer; v.vec128 = ps3->gem_inertial_state.accelerometer;
v.vec128 = ps3->gem_inertial_state.accelerometer_bias; v.vec128 = ps3->gem_inertial_state.accelerometer_bias;
v.vec128 = ps3->gem_inertial_state.gyro; 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) void readGem(ps3_input_t *ps3)
{ {
VmathVector4 v;
proccessGem(ps3, 0); proccessGem(ps3, 0);
proccessGem(ps3, 1); proccessGem(ps3, 1);
proccessGem(ps3, 2); proccessGem(ps3, 2);
proccessGem(ps3, 3); proccessGem(ps3, 3);
readGemPad(ps3, 0); // This will read buttons from Move readGemPad(ps3, 0); /* This will read buttons from Move */
VmathVector4 v;
v.vec128 = ps3->gem_state.pos; v.vec128 = ps3->gem_state.pos;
switch (ps3->newGemPad) { switch (ps3->newGemPad)
{
case 1: case 1:
ps3->select_pressed++; ps3->select_pressed++;
break; break;
@ -484,17 +478,21 @@ void readGem(ps3_input_t *ps3)
break; break;
case 64: case 64:
ps3->cross_pressed++; ps3->cross_pressed++;
//readGemAccPosition(0); #if 0
readGemAccPosition(0);
#endif
break; break;
case 128: case 128:
ps3->square_pressed++; ps3->square_pressed++;
//readGemInertial(ps3, 0); #if 0
readGemInertial(ps3, 0);
#endif
break; break;
default: default:
break; break;
} }
} }
#endif // HAVE_LIGHTGUN #endif /* HAVE_LIGHTGUN */
static void ps3_input_poll(void *data) 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, static int16_t ps3_lightgun_device_state(ps3_input_t *ps3,
unsigned user, unsigned id) unsigned user, unsigned id)
{ {
if (!ps3->gem_connected || !ps3->gem_init) float center_x;
return 0; float center_y;
float pointer_x;
readCamera(ps3); float pointer_y;
readGem(ps3); videoState state;
videoConfiguration vconfig;
videoResolution res;
VmathVector4 ray_start, ray_dir;
struct video_viewport vp; struct video_viewport vp;
const int edge_detect = 32700; const int edge_detect = 32700;
bool inside = false; bool inside = false;
@ -677,27 +678,25 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3,
int16_t res_y = 0; int16_t res_y = 0;
int16_t res_screen_x = 0; int16_t res_screen_x = 0;
int16_t res_screen_y = 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); videoGetState(0, 0, &state);
videoGetResolution(state.displayMode.resolution, &res); videoGetResolution(state.displayMode.resolution, &res);
if (res.height == 720) if (res.height == 720)
{ {
// 720p offset adjustments /* 720p offset adjustments */
center_x = 645.0f; center_x = 645.0f;
center_y = 375.0f; center_y = 375.0f;
} }
else if (res.height == 1080) else if (res.height == 1080)
{ {
// 1080p offset adjustments /* 1080p offset adjustments */
center_x = 960.0f; center_x = 960.0f;
center_y = 565.0f; center_y = 565.0f;
} }
@ -709,21 +708,19 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3,
vp.full_width = 0; vp.full_width = 0;
vp.full_height = 0; vp.full_height = 0;
#if 1 /* tracking mode 1: laser pointer mode (this is closest
// tracking mode 1: laser pointer mode (this is closest to actual lightgun behavior) to actual lightgun behavior) */
VmathVector4 ray_start;
ray_start.vec128 = ps3->gem_state.pos; ray_start.vec128 = ps3->gem_state.pos;
VmathVector4 ray_tmp = {.vec128 = {0.0f,0.0f,-1.0f,0.0f}}; VmathVector4 ray_tmp = {.vec128 = {0.0f,0.0f,-1.0f,0.0f}};
const VmathQuat *quat = &ps3->gem_state.quat; const VmathQuat *quat = &ps3->gem_state.quat;
VmathVector4 ray_dir;
vmathQRotate(&ray_dir, quat, &ray_tmp); vmathQRotate(&ray_dir, quat, &ray_tmp);
float t = -ray_start.vec128[2] / ray_dir.vec128[2]; float t = -ray_start.vec128[2] / ray_dir.vec128[2];
pointer_x = ray_start.vec128[0] + ray_dir.vec128[0]*t; pointer_x = ray_start.vec128[0] + ray_dir.vec128[0]*t;
pointer_y = ray_start.vec128[1] + ray_dir.vec128[1]*t; pointer_y = ray_start.vec128[1] + ray_dir.vec128[1]*t;
#endif
#if 0 #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; VmathVector4 v;
v.vec128 = ps3->gem_state.pos; v.vec128 = ps3->gem_state.pos;
pointer_x = v.vec128[0]; pointer_x = v.vec128[0];
@ -782,15 +779,11 @@ static int16_t ps3_lightgun_device_state(ps3_input_t *ps3,
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X: case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
if (inside) if (inside)
{
return (res_x); return (res_x);
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y: case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
if (inside) if (inside)
{
return (~res_y); return (~res_y);
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN: case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside; return !inside;
@ -825,7 +818,7 @@ static int16_t ps3_input_state(
case RETRO_DEVICE_JOYPAD: case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK) if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{ {
unsigned i; int i;
int16_t ret = 0; int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) 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) 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)); ps3_input_t *ps3 = (ps3_input_t*)calloc(1, sizeof(*ps3));
if (!ps3) if (!ps3)
return NULL; return NULL;
@ -903,7 +899,6 @@ static void* ps3_input_init(const char *joypad_driver)
#endif #endif
#ifdef HAVE_LIGHTGUN #ifdef HAVE_LIGHTGUN
ps3->gem_init = 0; ps3->gem_init = 0;
gemInfo gem_info;
gemGetInfo(&gem_info); gemGetInfo(&gem_info);
ps3->gem_connected = gem_info.connected; ps3->gem_connected = gem_info.connected;
if (ps3->gem_connected) if (ps3->gem_connected)
@ -918,14 +913,12 @@ static void* ps3_input_init(const char *joypad_driver)
if (!setupCamera(ps3)); if (!setupCamera(ps3));
{ {
if (!initGem(ps3)) if (!initGem(ps3))
{
ps3->gem_init = 1; ps3->gem_init = 1;
} }
} }
} }
} }
} }
}
#endif #endif
return ps3; return ps3;
} }

@ -177,17 +177,17 @@ static void qnx_process_joystick_event(qnx_input_t *qnx, screen_event_t screen_e
int displacement[2]; int displacement[2];
screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_DISPLACEMENT, displacement); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_DISPLACEMENT, displacement);
if(displacement != 0) if (displacement != 0)
{ {
qnx->trackpad_acc[0] += 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(true, RETROK_LEFT, 0, 0, RETRO_DEVICE_KEYBOARD);
input_keyboard_event(false, 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(true, RETROK_RIGHT, 0, 0, RETRO_DEVICE_KEYBOARD);
input_keyboard_event(false, 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]; 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(true, RETROK_UP, 0, 0, RETRO_DEVICE_KEYBOARD);
input_keyboard_event(false, 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(true, RETROK_DOWN, 0, 0, RETRO_DEVICE_KEYBOARD);
input_keyboard_event(false, 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; return;
name_buf[0] = '\0'; 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)); strlcpy(name_buf, "DS4 Controller", sizeof(name_buf));
else else
strlcpy(name_buf, "QNX Gamepad", sizeof(name_buf)); strlcpy(name_buf, "QNX Gamepad", sizeof(name_buf));
@ -372,33 +372,26 @@ static void qnx_process_keyboard_event(
qnx_input_t *qnx, qnx_input_t *qnx,
screen_event_t event, int type) screen_event_t event, int type)
{ {
// Get key properties from screen event /* Get key properties from screen event */
int flags = 0; int flags = 0, cap = 0, mod = 0;
screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags); 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); 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); screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &mod);
// Calculate state /* Calculate state */
unsigned keycode = input_keymaps_translate_keysym_to_rk(cap); unsigned keycode = input_keymaps_translate_keysym_to_rk(cap);
bool keydown = flags & KEY_DOWN; bool keydown = flags & KEY_DOWN;
bool keyrepeat = flags & KEY_REPEAT; bool keyrepeat = flags & KEY_REPEAT;
/* Fire keyboard event */
// Fire keyboard event if (!keyrepeat)
if(!keyrepeat)
{
input_keyboard_event(keydown, keycode, 0, mod, RETRO_DEVICE_KEYBOARD); input_keyboard_event(keydown, keycode, 0, mod, RETRO_DEVICE_KEYBOARD);
}
// Apply keyboard state /* Apply keyboard state */
if(keydown && !keyrepeat) if (keydown && !keyrepeat)
{ {
BIT_SET(qnx->keyboard_state, cap); BIT_SET(qnx->keyboard_state, cap);
} }
else if(!keydown && !keyrepeat) else if (!keydown && !keyrepeat)
{ {
BIT_CLEAR(qnx->keyboard_state, cap); BIT_CLEAR(qnx->keyboard_state, cap);
} }
@ -421,7 +414,7 @@ static void qnx_process_touch_event(
/* Find a free touch struct. */ /* Find a free touch struct. */
for (i = 0; i < MAX_TOUCH; ++i) 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; struct video_viewport vp;
@ -458,7 +451,7 @@ static void qnx_process_touch_event(
case SCREEN_EVENT_MTOUCH_RELEASE: case SCREEN_EVENT_MTOUCH_RELEASE:
for (i = 0; i < MAX_TOUCH; ++i) 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. */ /* Invalidate the finger. */
qnx->pointer[i].contact_id = -1; qnx->pointer[i].contact_id = -1;
@ -488,7 +481,7 @@ static void qnx_process_touch_event(
/* Find the finger we're tracking and update. */ /* Find the finger we're tracking and update. */
for (i = 0; i < qnx->pointer_count; ++i) 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; struct video_viewport vp;
@ -507,14 +500,14 @@ static void qnx_process_touch_event(
* numbers larger than the screen resolution. * numbers larger than the screen resolution.
* *
* Normalize. */ * Normalize. */
if(pos[0] < 0) if (pos[0] < 0)
pos[0] = 0; pos[0] = 0;
if(pos[0] > gl->full_x) if (pos[0] > gl->full_x)
pos[0] = gl->full_x; pos[0] = gl->full_x;
if(pos[1] < 0) if (pos[1] < 0)
pos[1] = 0; pos[1] = 0;
if(pos[1] > gl->full_y) if (pos[1] > gl->full_y)
pos[1] = gl->full_y; pos[1] = gl->full_y;
#endif #endif
@ -647,12 +640,12 @@ static void qnx_handle_navigator_event(
bps_get_event(&event_pause, -1); bps_get_event(&event_pause, -1);
event_code = bps_event_get_code(event_pause); 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; break;
} }
else if(event_code == NAVIGATOR_EXIT) else if (event_code == NAVIGATOR_EXIT)
goto shutdown; goto shutdown;
} }
break; break;
@ -714,7 +707,7 @@ static void qnx_input_poll(void *data)
bps_event_t *event = NULL; bps_event_t *event = NULL;
int rc = bps_get_event(&event, 0); int rc = bps_get_event(&event, 0);
if(rc == BPS_SUCCESS) if (rc == BPS_SUCCESS)
{ {
int domain; int domain;
@ -742,7 +735,7 @@ static int16_t qnx_pointer_input_state(qnx_input_t *qnx,
int16_t x; int16_t x;
int16_t y; int16_t y;
if(screen) if (screen)
{ {
x = qnx->pointer[idx].full_x; x = qnx->pointer[idx].full_x;
y = qnx->pointer[idx].full_y; y = qnx->pointer[idx].full_y;

@ -279,16 +279,16 @@ BTDIMPORT const hci_cmd_t* l2cap_decline_connection_ptr;
/* RFCOMM EVENTS */ /* 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 #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 #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 #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 #define RFCOMM_EVENT_REMOTE_LINE_STATUS 0x83
/* data: event(8), len(8), rfcomm_cid(16), credits(8) */ /* data: event(8), len(8), rfcomm_cid(16), credits(8) */

@ -60,7 +60,7 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller)
return; return;
slot = (uint32_t)controller.playerIndex; 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) if (slot >= MAX_USERS)
return; return;
buttons = &mfi_buttons[slot]; 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 */ /* retain the values from the paused controller handler and pass them through */
if (@available(iOS 13, *)) if (@available(iOS 13, *))
{ {
// The menu button can be pressed/unpressed like any other button in iOS 13 /* The menu button can be pressed/unpressed
// so no need to passthrough anything * like any other button in iOS 13,
* so no need to passthrough anything */
*buttons = 0; *buttons = 0;
} }
else 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); pause = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_START);
select = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT); select = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT);
l3 = *buttons & (1 << RETRO_DEVICE_ID_JOYPAD_L3); 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 __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13, *)) 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; *buttons |= gp.buttonOptions.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
// Support buttons that aren't supported by older mFi controller via "hotkey" combinations: /* Support buttons that aren't supported by older mFi controller via "hotkey" combinations:
// *
// LS + Menu => Select * LS + Menu => Select
// LT + Menu => L3 * LT + Menu => L3
// RT + Menu => R3 * RT + Menu => R3
*/
if (gp.buttonMenu.pressed ) if (gp.buttonMenu.pressed )
{ {
if (gp.leftShoulder.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; mfi_axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f;
} }
// GCGamepad is deprecated
/* GCGamepad is deprecated */
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated"
else if (controller.gamepad) else if (controller.gamepad)
@ -168,15 +171,17 @@ static void apple_gamecontroller_joypad_poll(void)
apple_gamecontroller_joypad_poll_internal(controller); apple_gamecontroller_joypad_poll_internal(controller);
} }
// GCGamepad is deprecated /* GCGamepad is deprecated */
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated"
static void apple_gamecontroller_joypad_register(GCGamepad *gamepad) static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
{ {
#ifdef __IPHONE_14_0 #ifdef __IPHONE_14_0
// dont let tvOS or iOS do anything with **our** buttons!! /* Don't 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. * iOS will start a screen recording if you hold or doubleclick
if (@available(iOS 14.0, tvOS 14.0, *)) { * the OPTIONS button, we don't want that. */
if (@available(iOS 14.0, tvOS 14.0, *))
{
GCExtendedGamepad *gp = (GCExtendedGamepad *)gamepad.controller.extendedGamepad; GCExtendedGamepad *gp = (GCExtendedGamepad *)gamepad.controller.extendedGamepad;
gp.buttonOptions.preferredSystemGestureState = GCSystemGestureStateDisabled; gp.buttonOptions.preferredSystemGestureState = GCSystemGestureStateDisabled;
gp.buttonMenu.preferredSystemGestureState = GCSystemGestureStateDisabled; gp.buttonMenu.preferredSystemGestureState = GCSystemGestureStateDisabled;
@ -189,13 +194,12 @@ static void apple_gamecontroller_joypad_register(GCGamepad *gamepad)
apple_gamecontroller_joypad_poll_internal(updateGamepad.controller); 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, *)) if (@available(iOS 13, *))
{
// controllerPausedHandler is deprecated in favor of being able to deal with the menu
// button as any other button
return; return;
}
else
{ {
gamepad.controller.controllerPausedHandler = ^(GCController *controller) 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 push
#pragma clang diagnostic ignored "-Wdeprecated" #pragma clang diagnostic ignored "-Wdeprecated"
[mfiControllers addObject:controller]; [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) if (mfiControllers.count > 1)
{ {
int newPlayerIndex = 0; int newPlayerIndex = 0;

@ -16,8 +16,9 @@
#ifndef _KEYBOARD_EVENT_ANDROID_H #ifndef _KEYBOARD_EVENT_ANDROID_H
#define _KEYBOARD_EVENT_ANDROID_H #define _KEYBOARD_EVENT_ANDROID_H
// The list of defined Android keycodes is incomplete in SDK version 12 and lower. /* The list of defined Android keycodes is incomplete in SDK version 12
// If using an SDK lower than 13 then add missing keycodes here * and lower.
* If using an SDK lower than 13, add missing keycodes here */
#if __ANDROID_API__ < 13 #if __ANDROID_API__ < 13
/* /*

@ -1459,7 +1459,7 @@ const struct rarch_key_map rarch_key_map_qnx[] = {
{ KEYCODE_RIGHT_CTRL, RETROK_RCTRL }, { KEYCODE_RIGHT_CTRL, RETROK_RCTRL },
{ KEYCODE_LEFT_ALT, RETROK_LALT }, { KEYCODE_LEFT_ALT, RETROK_LALT },
{ KEYCODE_RIGHT_ALT, RETROK_RALT }, { 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 }, { 61651, RETROK_RSUPER },
{ KEYCODE_DOLLAR, RETROK_DOLLAR }, { KEYCODE_DOLLAR, RETROK_DOLLAR },
{ KEYCODE_MENU, RETROK_MENU }, { KEYCODE_MENU, RETROK_MENU },

@ -337,7 +337,7 @@ static ui_application_t ui_application_cocoa = {
void *data; void *data;
enum event_command cmd; enum event_command cmd;
} }
@end // @interface CommandPerformer @end /* @interface CommandPerformer */
@implementation CommandPerformer @implementation CommandPerformer
@ -358,7 +358,7 @@ static ui_application_t ui_application_cocoa = {
command_event(self->cmd, self->data); command_event(self->cmd, self->data);
} }
@end // @implementation CommandPerformer @end /* @implementation CommandPerformer */
#if defined(HAVE_COCOA_METAL) #if defined(HAVE_COCOA_METAL)
@interface RAWindow : NSWindow @interface RAWindow : NSWindow

@ -471,8 +471,8 @@ enum
NSString *filename = (NSString*)url.path.lastPathComponent; NSString *filename = (NSString*)url.path.lastPathComponent;
NSError *error = nil; NSError *error = nil;
NSString *destination = [self.documentsDirectory stringByAppendingPathComponent:filename]; NSString *destination = [self.documentsDirectory stringByAppendingPathComponent:filename];
/* Copy file to documents directory if it's not already
// copy file to documents directory if its not already inside of documents directory * inside Documents directory */
if ([url startAccessingSecurityScopedResource]) { if ([url startAccessingSecurityScopedResource]) {
if (![[url path] containsString: self.documentsDirectory]) if (![[url path] containsString: self.documentsDirectory])
if (![manager fileExistsAtPath:destination]) if (![manager fileExistsAtPath:destination])

@ -28,7 +28,7 @@
#define IDI_ICON 1 #define IDI_ICON 1
#ifndef _WIN32_WINNT #ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500 //_WIN32_WINNT_WIN2K #define _WIN32_WINNT 0x0500 /* _WIN32_WINNT_WIN2K */
#endif #endif
#ifndef _WIN32_IE #ifndef _WIN32_IE