/* ljoy_init_joystick: [primary thread] * Initialise the joystick driver. */ static bool ljoy_init_joystick(void) { _al_vector_init(&joysticks, sizeof(ALLEGRO_JOYSTICK_LINUX *)); num_joysticks = 0; if (!(config_mutex = al_create_mutex())) { return false; } // Scan for joysticks ljoy_scan(false); ljoy_merge(); #ifdef SUPPORT_HOTPLUG if (!(hotplug_mutex = al_create_mutex())) { al_destroy_mutex(config_mutex); return false; } if (!(hotplug_cond = al_create_cond())) { al_destroy_mutex(config_mutex); al_destroy_mutex(hotplug_mutex); return false; } if (!(hotplug_thread = al_create_thread(hotplug_proc, NULL))) { al_destroy_mutex(config_mutex); al_destroy_mutex(hotplug_mutex); al_destroy_cond(hotplug_cond); return false; } al_start_thread(hotplug_thread); inotify_fd = inotify_init(); if (inotify_fd != -1) { fcntl(inotify_fd, F_SETFL, O_NONBLOCK); /* Modern Linux probably only needs to monitor /dev/input. */ inotify_add_watch(inotify_fd, "/dev/input", IN_CREATE|IN_DELETE); _al_unix_start_watching_fd(inotify_fd, ljoy_config_dev_changed, NULL); ALLEGRO_INFO("Hotplugging enabled\n"); } else { ALLEGRO_WARN("Hotplugging not enabled\n"); if (inotify_fd != -1) { close(inotify_fd); inotify_fd = -1; } } #endif return true; }
/* Function: al_create_voice */ ALLEGRO_VOICE *al_create_voice(unsigned int freq, ALLEGRO_AUDIO_DEPTH depth, ALLEGRO_CHANNEL_CONF chan_conf) { ALLEGRO_VOICE *voice = NULL; if (!freq) { _al_set_error(ALLEGRO_INVALID_PARAM, "Invalid Voice Frequency"); return NULL; } voice = calloc(1, sizeof(*voice)); if (!voice) { return NULL; } voice->depth = depth; voice->chan_conf = chan_conf; voice->frequency = freq; voice->mutex = al_create_mutex(); /* XXX why is this needed? there should only be one active driver */ voice->driver = _al_kcm_driver; ASSERT(_al_kcm_driver); if (_al_kcm_driver->allocate_voice(voice) != 0) { al_destroy_mutex(voice->mutex); free(voice); return NULL; } _al_kcm_register_destructor(voice, (void (*)(void *)) al_destroy_voice); return voice; }
/* ljoy_exit_joystick: [primary thread] * Shut down the joystick driver. */ static void ljoy_exit_joystick(void) { int i; #ifdef SUPPORT_HOTPLUG if (inotify_fd != -1) { _al_unix_stop_watching_fd(inotify_fd); close(inotify_fd); inotify_fd = -1; } hotplug_ended = true; al_signal_cond(hotplug_cond); al_join_thread(hotplug_thread, NULL); #endif al_destroy_mutex(config_mutex); config_mutex = NULL; for (i = 0; i < (int)_al_vector_size(&joysticks); i++) { ALLEGRO_JOYSTICK_LINUX **slot = _al_vector_ref(&joysticks, i); inactivate_joy(*slot); al_free(*slot); } _al_vector_free(&joysticks); num_joysticks = 0; }
/* closes down the input emulation */ void shutdown_input() { al_destroy_mutex(keybuf_mutex); keybuf_mutex = NULL; al_destroy_event_queue(input_queue); input_queue = NULL; }
void destroy_nine_patch_bitmap(NINE_PATCH_BITMAP *p9) { if (p9->destroy_bmp) al_destroy_bitmap(p9->bmp); al_destroy_mutex(p9->mutex); al_free(p9->h.m); al_free(p9->v.m); al_free(p9); }
/* Function: al_destroy_voice */ void al_destroy_voice(ALLEGRO_VOICE *voice) { if (voice) { _al_kcm_unregister_destructor(voice); al_detach_voice(voice); voice->driver->deallocate_voice(voice); al_destroy_mutex(voice->mutex); free(voice); } }
/* Destroy the specified player. */ void dumba5_destroy_player(DUMBA5_PLAYER * pp) { if(pp) { al_destroy_thread(pp->thread); al_destroy_mutex(pp->mutex); if(pp->sigrenderer) { duh_end_sigrenderer(pp->sigrenderer); // al_drain_stream(dp->stream); al_destroy_audio_stream(pp->stream); } free(pp); } }
static void pulseaudio_deallocate_voice(ALLEGRO_VOICE *voice) { PULSEAUDIO_VOICE *pv = voice->extra; /* We do NOT hold the voice mutex here, so this does NOT result in a * deadlock when the thread calls _al_voice_update. */ al_set_thread_should_stop(pv->poll_thread); al_join_thread(pv->poll_thread, NULL); al_destroy_thread(pv->poll_thread); al_destroy_mutex(pv->buffer_mutex); pa_simple_free(pv->s); al_free(pv); }
/* Function: al_destroy_voice */ void al_destroy_voice(ALLEGRO_VOICE *voice) { if (voice) { _al_kcm_unregister_destructor(voice); al_detach_voice(voice); ASSERT(al_get_voice_playing(voice) == false); /* We do NOT lock the voice mutex when calling this method. */ voice->driver->deallocate_voice(voice); al_destroy_mutex(voice->mutex); al_destroy_cond(voice->cond); al_free(voice); } }
/* [user thread] */ bool _al_gtk_init_args(void *ptr, size_t size) { ARGS_BASE *args = (ARGS_BASE *)ptr; memset(args, 0, size); args->mutex = al_create_mutex(); if (!args->mutex) { return false; } args->cond = al_create_cond(); if (!args->cond) { al_destroy_mutex(args->mutex); return false; } args->done = false; args->response = true; return args; }
static void hapxi_exit_haptic(void) { void *ret_value; ASSERT(hapxi_thread); ASSERT(hapxi_mutex); ASSERT(hapxi_cond); /* Request the event thread to shut down, signal the condition, then join the thread. */ al_set_thread_should_stop(hapxi_thread); al_signal_cond(hapxi_cond); al_join_thread(hapxi_thread, &ret_value); /* clean it all up. */ al_destroy_thread(hapxi_thread); al_destroy_cond(hapxi_cond); al_destroy_mutex(hapxi_mutex); hapxi_mutex = NULL; }
Overlay::~Overlay() { { CoreSuspender suspend; df::global::enabler->renderer = parent; } al_destroy_mutex(front_mutex); al_destroy_bitmap(front); al_destroy_bitmap(back); front = back = NULL; if(al_get_current_display() == NULL){ al_set_target_bitmap(NULL); } else { al_set_target_bitmap(al_get_backbuffer(al_get_current_display())); } }
/* [user thread] */ bool _al_gtk_wait_for_args(GSourceFunc func, void *data) { ARGS_BASE *args = (ARGS_BASE *) data; bool response; al_lock_mutex(args->mutex); g_timeout_add(0, func, data); while (args->done == false) { al_wait_cond(args->cond, args->mutex); } al_unlock_mutex(args->mutex); response = args->response; al_destroy_mutex(args->mutex); al_destroy_cond(args->cond); return response; }
static void pulseaudio_deallocate_voice(ALLEGRO_VOICE *voice) { PULSEAUDIO_VOICE *pv = voice->extra; al_lock_mutex(voice->mutex); pv->status = PV_JOIN; al_broadcast_cond(pv->status_cond); al_unlock_mutex(voice->mutex); /* We do NOT hold the voice mutex here, so this does NOT result in a * deadlock when the thread calls _al_voice_update. */ al_join_thread(pv->poll_thread, NULL); al_destroy_thread(pv->poll_thread); al_destroy_cond(pv->status_cond); al_destroy_mutex(pv->buffer_mutex); pa_simple_free(pv->s); al_free(pv); }
/* Function: al_close_native_text_log */ void al_close_native_text_log(ALLEGRO_TEXTLOG *textlog) { ALLEGRO_NATIVE_DIALOG *dialog = (ALLEGRO_NATIVE_DIALOG *)textlog; if (!dialog) return; if (!dialog->tl_init_error) { dialog->tl_done = false; if (TEXT_LOG_EXTRA_THREAD) { al_lock_mutex(dialog->tl_text_mutex); _al_close_native_text_log(dialog); while (!dialog->tl_done) { al_wait_cond(dialog->tl_text_cond, dialog->tl_text_mutex); } } else { _al_close_native_text_log(dialog); al_lock_mutex(dialog->tl_text_mutex); } _al_unregister_destructor(_al_dtor_list, dialog); } al_ustr_free(dialog->title); al_ustr_free(dialog->tl_pending_text); al_destroy_user_event_source(&dialog->tl_events); al_unlock_mutex(dialog->tl_text_mutex); if (TEXT_LOG_EXTRA_THREAD) { al_destroy_thread(dialog->tl_thread); } al_destroy_cond(dialog->tl_text_cond); al_destroy_mutex(dialog->tl_text_mutex); al_free(dialog); }
Framework::~Framework() { Settings->Save( "settings.cfg" ); #ifdef WRITE_LOG printf( "Framework: Shutdown\n" ); #endif al_destroy_event_queue( eventQueue ); al_destroy_display( displaySurface ); al_destroy_mutex( extraEventsMutex ); delete imageMgr; delete audioMgr; delete fontMgr; delete networkMgr; delete downloadMgr; // Shutdown Allegro if( mixer != 0 ) { al_destroy_mixer( mixer ); } if( voice != 0 ) { al_destroy_voice( voice ); } al_uninstall_keyboard(); al_uninstall_mouse(); al_shutdown_primitives_addon(); al_shutdown_ttf_addon(); al_shutdown_image_addon(); al_shutdown_font_addon(); al_uninstall_audio(); al_uninstall_joystick(); }
~DATA(){ al_destroy_mutex(mutex); al_destroy_cond(cond); }
static void iphone_shutdown_system(void) { al_destroy_mutex(_al_iphone_display_hotplug_mutex); }
int main(int argc, char **argv) { ALLEGRO_DISPLAY *display; ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; bool redraw = true; ALLEGRO_FONT *font; ALLEGRO_BITMAP *spin, *spin2; int current_bitmap = 0; int loaded_bitmap = 0; ALLEGRO_THREAD *thread; (void)argc; (void)argv; if (!al_init()) { abort_example("Could not init Allegro.\n"); } al_init_image_addon(); al_init_font_addon(); al_init_primitives_addon(); init_platform_specific(); open_log(); al_install_mouse(); al_install_keyboard(); spin = al_load_bitmap("data/cursor.tga"); log_printf("default bitmap without display: %p\n", spin); al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP); spin2 = al_load_bitmap("data/cursor.tga"); log_printf("video bitmap without display: %p\n", spin2); log_printf("%p before create_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); display = al_create_display(64, 64); if (!display) { abort_example("Error creating display\n"); } spin2 = al_load_bitmap("data/cursor.tga"); log_printf("video bitmap with display: %p\n", spin2); log_printf("%p after create_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); log_printf("%p after create_display: ", spin2); print_bitmap_flags(spin2); log_printf("\n"); al_destroy_display(display); log_printf("%p after destroy_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); log_printf("%p after destroy_display: ", spin2); print_bitmap_flags(spin2); log_printf("\n"); display = al_create_display(640, 480); log_printf("%p after create_display: ", spin); print_bitmap_flags(spin); log_printf("\n"); log_printf("%p after create_display: ", spin2); print_bitmap_flags(spin2); log_printf("\n"); font = al_load_font("data/fixed_font.tga", 0, 0); mutex = al_create_mutex(); thread = al_create_thread(loading_thread, NULL); al_start_thread(thread); timer = al_create_timer(1.0 / 30); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_display_event_source(display)); al_register_event_source(queue, al_get_timer_event_source(timer)); al_start_timer(timer); while (1) { ALLEGRO_EVENT event; al_wait_for_event(queue, &event); if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) break; if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; } if (event.type == ALLEGRO_EVENT_TIMER) redraw = true; if (redraw && al_is_event_queue_empty(queue)) { float x = 20, y = 320; int i; ALLEGRO_COLOR color = al_map_rgb_f(0, 0, 0); float t = al_current_time(); redraw = false; al_clear_to_color(al_map_rgb_f(0.5, 0.6, 1)); al_draw_textf(font, color, x + 40, y, 0, "Loading %d%%", 100 * load_count / load_total); al_lock_mutex(mutex); if (loaded_bitmap < load_count) { /* This will convert any video bitmaps without a display * (all the bitmaps being loaded in the loading_thread) to * video bitmaps we can use in the main thread. */ al_convert_bitmap(bitmaps[loaded_bitmap]); loaded_bitmap++; } al_unlock_mutex(mutex); if (current_bitmap < loaded_bitmap) { int bw; al_draw_bitmap(bitmaps[current_bitmap], 0, 0, 0); if (current_bitmap + 1 < loaded_bitmap) current_bitmap++; for (i = 0; i <= current_bitmap; i++) { bw = al_get_bitmap_width(bitmaps[i]); al_draw_scaled_rotated_bitmap(bitmaps[i], 0, 0, (i % 20) * 640 / 20, 360 + (i / 20) * 24, 32.0 / bw, 32.0 / bw, 0, 0); } } if (loaded_bitmap < load_total) { al_draw_scaled_rotated_bitmap(spin, 16, 16, x, y, 1.0, 1.0, t * ALLEGRO_PI * 2, 0); } al_flip_display(); } } al_join_thread(thread, NULL); al_destroy_mutex(mutex); al_destroy_font(font); al_destroy_display(display); close_log(true); return 0; }
//cleans up the resource manager; invoked from algui_cleanup void _algui_cleanup_resource_manager() { algui_destroy_resources(); al_destroy_mutex(_mutex); }
Framework::~Framework() { #ifdef WRITE_LOG fprintf( LogFile, "Framework: Save Config\n" ); #endif SaveSettings(); #ifdef PANDORA #ifdef WRITE_LOG fprintf( LogFile, "Framework: Hacky Pandora Shutdown\n" ); #endif raise(SIGKILL); #endif #ifdef WRITE_LOG fprintf( LogFile, "Framework: Clear stages\n" ); #endif if( ProgramStages != 0 ) { // Just make sure all stages are popped and deleted ShutdownFramework(); } #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown\n" ); #endif al_unregister_event_source( eventAllegro, DISPLAY->GetEventSource() ); al_destroy_event_queue( eventAllegro ); al_destroy_mutex( eventMutex ); al_destroy_timer( frameTimer ); #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown display\n" ); #endif DISPLAY->Shutdown(); delete DISPLAY; #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown audio\n" ); #endif delete AUDIO; #ifdef NETWORK_SUPPORT #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown enet\n" ); #endif enet_deinitialize(); #endif #ifdef DOWNLOAD_SUPPORT #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown downloads\n" ); #endif DOWNLOADS->AbortDownloads = true; delete DOWNLOADS; #endif #ifdef WRITE_LOG fprintf( LogFile, "Framework: Shutdown Allegro\n" ); #endif al_uninstall_system(); #ifdef WRITE_LOG fclose( LogFile ); #endif }
static bool open_video(ALLEGRO_VIDEO *video) { VideoState *is = av_mallocz(sizeof *is); int i; AVRational fps; is->video = video; init(); video->data = is; strncpy(is->filename, al_path_cstr(video->filename, '/'), sizeof(is->filename)); is->av_sync_type = DEFAULT_AV_SYNC_TYPE; // Open video file #ifdef FFMPEG_0_8 if (avformat_open_input(&is->format_context, is->filename, NULL, NULL) != 0) { #else if (av_open_input_file(&is->format_context, is->filename, NULL, 0, NULL) != 0) { #endif av_free(is); return false; } if (av_find_stream_info(is->format_context) < 0) { av_free(is); return false; } is->video_index = -1; is->audio_index = -1; for (i = 0; i < (int)is->format_context->nb_streams; i++) { if (is->format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && is->video_index < 0) { is->video_index = i; } if (is->format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && is->audio_index < 0) { is->audio_index = i; } } fps = is->format_context->streams[is->video_index]->r_frame_rate; video->fps = (double)fps.num / fps.den; video->audio_rate = is->format_context->streams[is->audio_index]-> codec->sample_rate; video->width = is->format_context->streams[is->video_index]->codec->width; video->height = is->format_context->streams[is->video_index]->codec->height; is->pictq_mutex = al_create_mutex(); is->pictq_cond = al_create_cond(); is->timer_mutex = al_create_mutex(); is->timer_cond = al_create_cond(); return true; } static bool close_video(ALLEGRO_VIDEO *video) { VideoState *is = video->data; is->quit = true; if (is->timer_thread) { al_lock_mutex(is->timer_mutex); al_signal_cond(is->timer_cond); al_unlock_mutex(is->timer_mutex); al_join_thread(is->timer_thread, NULL); } if (is->parse_thread) { al_join_thread(is->parse_thread, NULL); } al_destroy_mutex(is->timer_mutex); al_destroy_cond(is->timer_cond); av_free(is); return true; }
NINE_PATCH_BITMAP *create_nine_patch_bitmap(ALLEGRO_BITMAP *bmp, bool owns_bitmap) { int i; NINE_PATCH_BITMAP *p9; ALLEGRO_COLOR c; p9 = al_malloc(sizeof(*p9)); p9->bmp = bmp; p9->destroy_bmp = owns_bitmap; p9->h.m = NULL; p9->v.m = NULL; p9->cached_dw = 0; p9->cached_dh = 0; p9->mutex = al_create_mutex(); p9->width = al_get_bitmap_width(bmp) - 2; p9->height = al_get_bitmap_height(bmp) - 2; al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); if (p9->width <= 0 || p9->height <= 0) goto bad_bitmap; /* make sure all four corners are transparent */ #define _check_pixel(x, y) \ c = al_get_pixel(bmp, x, y); \ if (c.a != 0 && c.r + c.g + c.b + c.a != 4) goto bad_bitmap; _check_pixel(0,0); _check_pixel(al_get_bitmap_width(bmp) - 1, 0); _check_pixel(0, al_get_bitmap_height(bmp) - 1); _check_pixel(al_get_bitmap_width(bmp) - 1, al_get_bitmap_height(bmp) - 1); #undef _check_pixel p9->padding.top = p9->padding.right = p9->padding.bottom = p9->padding.left = -1; i = 1; while (i < al_get_bitmap_width(bmp)) { c = al_get_pixel(bmp, i, al_get_bitmap_height(bmp) - 1); if (c.r + c.g + c.b == 0 && c.a == 1) { if (p9->padding.left == -1) p9->padding.left = i - 1; else if (p9->padding.right != -1) goto bad_bitmap; } else if (c.a == 0 || c.r + c.g + c.b + c.a == 4) { if (p9->padding.left != -1 && p9->padding.right == -1) p9->padding.right = al_get_bitmap_width(bmp) - i - 1; } ++i; } i = 1; while (i < al_get_bitmap_height(bmp)) { c = al_get_pixel(bmp, al_get_bitmap_width(bmp) - 1, i); if (c.r + c.g + c.b == 0 && c.a == 1) { if (p9->padding.top == -1) p9->padding.top = i - 1; else if (p9->padding.bottom != -1) goto bad_bitmap; } else if (c.a == 0 || c.r + c.g + c.b + c.a == 4) { if (p9->padding.top != -1 && p9->padding.bottom == -1) p9->padding.bottom = al_get_bitmap_height(bmp) - i - 1; } ++i; } if (!init_nine_patch_side(&p9->h, bmp, 0) || !init_nine_patch_side(&p9->v, bmp, 1)) { bad_bitmap: al_destroy_mutex(p9->mutex); if (p9->h.m) al_free(p9->h.m); if (p9->v.m) al_free(p9->v.m); al_free(p9); p9 = NULL; } al_unlock_bitmap(bmp); return p9; }
void _al_glsl_shutdown_shaders(void) { _al_vector_free(&shaders); al_destroy_mutex(shaders_mutex); shaders_mutex = NULL; }