comparison render_sdl.c @ 2041:638eb2d25696 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Thu, 05 Aug 2021 09:29:33 -0700
parents 0757da8ee702
children 46ee354f29bd
comparison
equal deleted inserted replaced
1984:0d5f88e53dca 2041:638eb2d25696
169 SDL_DestroyCond(opaque); 169 SDL_DestroyCond(opaque);
170 } 170 }
171 171
172 void render_audio_created(audio_source *source) 172 void render_audio_created(audio_source *source)
173 { 173 {
174 if (render_is_audio_sync()) { 174 if (sync_src == SYNC_AUDIO) {
175 SDL_PauseAudio(0); 175 //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs
176 //since our callback can itself be stuck waiting on the audio_ready condition variable
177 //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock
178 //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here
179 if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) {
180 SDL_PauseAudio(0);
181 }
176 } 182 }
177 if (current_system && sync_src == SYNC_AUDIO_THREAD) { 183 if (current_system && sync_src == SYNC_AUDIO_THREAD) {
178 system_request_exit(current_system, 0); 184 system_request_exit(current_system, 0);
179 } 185 }
180 } 186 }
192 } 198 }
193 } 199 }
194 200
195 void render_source_resumed(audio_source *src) 201 void render_source_resumed(audio_source *src)
196 { 202 {
197 if (render_is_audio_sync()) { 203 if (sync_src == SYNC_AUDIO) {
198 SDL_PauseAudio(0); 204 //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs
205 //since our callback can itself be stuck waiting on the audio_ready condition variable
206 //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock
207 //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here
208 if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) {
209 SDL_PauseAudio(0);
210 }
199 } 211 }
200 if (current_system && sync_src == SYNC_AUDIO_THREAD) { 212 if (current_system && sync_src == SYNC_AUDIO_THREAD) {
201 system_request_exit(current_system, 0); 213 system_request_exit(current_system, 0);
202 } 214 }
203 } 215 }
392 tex_width = LINEBUF_SIZE; 404 tex_width = LINEBUF_SIZE;
393 tex_height = 294; //PAL height with full borders 405 tex_height = 294; //PAL height with full borders
394 } else { 406 } else {
395 tex_width = tex_height = 512; 407 tex_width = tex_height = 512;
396 } 408 }
397 printf("Using %dx%d textures\n", tex_width, tex_height); 409 debug_message("Using %dx%d textures\n", tex_width, tex_height);
398 for (int i = 0; i < 3; i++) 410 for (int i = 0; i < 3; i++)
399 { 411 {
400 glBindTexture(GL_TEXTURE_2D, textures[i]); 412 glBindTexture(GL_TEXTURE_2D, textures[i]);
401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); 413 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); 414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
1189 1201
1190 render_set_video_standard(VID_NTSC); 1202 render_set_video_standard(VID_NTSC);
1191 1203
1192 atexit(render_quit); 1204 atexit(render_quit);
1193 } 1205 }
1206
1207 void render_reset_mappings(void)
1208 {
1209 SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
1210 SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
1211 uint32_t db_size;
1212 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size);
1213 if (db_data) {
1214 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1);
1215 free(db_data);
1216 debug_message("Added %d game controller mappings from gamecontrollerdb.txt\n", added);
1217 }
1218 }
1194 static int in_toggle; 1219 static int in_toggle;
1195 1220
1196 void render_config_updated(void) 1221 void render_config_updated(void)
1197 { 1222 {
1198 free_surfaces(); 1223 free_surfaces();
1704 void render_video_loop(void) 1729 void render_video_loop(void)
1705 { 1730 {
1706 if (sync_src != SYNC_AUDIO_THREAD && sync_src != SYNC_EXTERNAL) { 1731 if (sync_src != SYNC_AUDIO_THREAD && sync_src != SYNC_EXTERNAL) {
1707 return; 1732 return;
1708 } 1733 }
1734 SDL_PauseAudio(0);
1709 SDL_LockMutex(frame_mutex); 1735 SDL_LockMutex(frame_mutex);
1710 for(;;) 1736 for(;;)
1711 { 1737 {
1712 while (!frame_queue_len && SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) 1738 while (!frame_queue_len && SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)
1713 { 1739 {