| 1 |
#include <allegro5/internal/aintern_iphone.h> |
| 2 |
#include <allegro5/platform/aintiphone.h> |
| 3 |
#include <allegro5/platform/aintunix.h> |
| 4 |
|
| 5 |
ALLEGRO_DEBUG_CHANNEL("iphone") |
| 6 |
|
| 7 |
ALLEGRO_SYSTEM_IPHONE *iphone; |
| 8 |
static ALLEGRO_SYSTEM_INTERFACE *vt; |
| 9 |
|
| 10 |
extern ALLEGRO_MUTEX *_al_iphone_display_hotplug_mutex; |
| 11 |
|
| 12 |
/* al_init will call this. */ |
| 13 |
ALLEGRO_SYSTEM *iphone_initialize(int flags) |
| 14 |
{ |
| 15 |
(void)flags; |
| 16 |
iphone = al_calloc(1, sizeof *iphone); |
| 17 |
|
| 18 |
ALLEGRO_SYSTEM *sys = &iphone->system; |
| 19 |
|
| 20 |
iphone->mutex = al_create_mutex(); |
| 21 |
iphone->cond = al_create_cond(); |
| 22 |
sys->vt = _al_get_iphone_system_interface(); |
| 23 |
_al_vector_init(&sys->displays, sizeof (ALLEGRO_DISPLAY_IPHONE *)); |
| 24 |
|
| 25 |
_al_unix_init_time(); |
| 26 |
_al_iphone_init_path(); |
| 27 |
|
| 28 |
return sys; |
| 29 |
} |
| 30 |
|
| 31 |
static void iphone_shutdown_system(void) |
| 32 |
{ |
| 33 |
al_destroy_mutex(_al_iphone_display_hotplug_mutex); |
| 34 |
} |
| 35 |
|
| 36 |
/* This is called from the termination message - it has to return soon as the |
| 37 |
* user expects the app to close when it is closed. |
| 38 |
*/ |
| 39 |
void _al_iphone_await_termination(void) |
| 40 |
{ |
| 41 |
ALLEGRO_INFO("Application awaiting termination.\n"); |
| 42 |
al_lock_mutex(iphone->mutex); |
| 43 |
while (!iphone->has_shutdown) { |
| 44 |
al_wait_cond(iphone->cond, iphone->mutex); |
| 45 |
} |
| 46 |
al_unlock_mutex(iphone->mutex); |
| 47 |
} |
| 48 |
|
| 49 |
static ALLEGRO_DISPLAY_INTERFACE *iphone_get_display_driver(void) |
| 50 |
{ |
| 51 |
return _al_get_iphone_display_interface(); |
| 52 |
} |
| 53 |
|
| 54 |
static int iphone_get_num_video_adapters(void) |
| 55 |
{ |
| 56 |
return _al_iphone_get_num_video_adapters(); |
| 57 |
} |
| 58 |
|
| 59 |
static bool iphone_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info) |
| 60 |
{ |
| 61 |
int w, h; |
| 62 |
_al_iphone_get_screen_size(adapter, &w, &h); |
| 63 |
info->x1 = 0; |
| 64 |
info->y1 = 0; |
| 65 |
info->x2 = w; |
| 66 |
info->y2 = h; |
| 67 |
return true; |
| 68 |
} |
| 69 |
|
| 70 |
/* There is no cursor. */ |
| 71 |
static bool iphone_get_cursor_position(int *ret_x, int *ret_y) |
| 72 |
{ |
| 73 |
(void)ret_x; |
| 74 |
(void)ret_y; |
| 75 |
return false; |
| 76 |
} |
| 77 |
|
| 78 |
ALLEGRO_SYSTEM_INTERFACE *_al_get_iphone_system_interface(void) |
| 79 |
{ |
| 80 |
if (vt) |
| 81 |
return vt; |
| 82 |
|
| 83 |
vt = al_calloc(1, sizeof *vt); |
| 84 |
|
| 85 |
vt->id = ALLEGRO_SYSTEM_ID_IPHONE; |
| 86 |
vt->initialize = iphone_initialize; |
| 87 |
vt->get_display_driver = iphone_get_display_driver; |
| 88 |
vt->get_keyboard_driver = _al_get_iphone_keyboard_driver; |
| 89 |
vt->get_mouse_driver = _al_get_iphone_mouse_driver; |
| 90 |
vt->get_touch_input_driver = _al_get_iphone_touch_input_driver; |
| 91 |
vt->get_joystick_driver = _al_get_iphone_joystick_driver; |
| 92 |
//xglx_vt->get_num_display_modes = _al_xglx_get_num_display_modes; |
| 93 |
//xglx_vt->get_display_mode = _al_xglx_get_display_mode; |
| 94 |
//xglx_vt->shutdown_system = xglx_shutdown_system; |
| 95 |
vt->shutdown_system = iphone_shutdown_system; |
| 96 |
vt->get_num_video_adapters = iphone_get_num_video_adapters; |
| 97 |
vt->get_monitor_info = iphone_get_monitor_info; |
| 98 |
vt->get_cursor_position = iphone_get_cursor_position; |
| 99 |
vt->get_path = _al_iphone_get_path; |
| 100 |
//xglx_vt->inhibit_screensaver = xglx_inhibit_screensaver; |
| 101 |
|
| 102 |
return vt; |
| 103 |
} |
| 104 |
|
| 105 |
/* This is a function each platform must define to register all available |
| 106 |
* system drivers. |
| 107 |
*/ |
| 108 |
void _al_register_system_interfaces(void) |
| 109 |
{ |
| 110 |
ALLEGRO_SYSTEM_INTERFACE **add; |
| 111 |
|
| 112 |
add = _al_vector_alloc_back(&_al_system_interfaces); |
| 113 |
*add = _al_get_iphone_system_interface(); |
| 114 |
} |