Fix non-deterministic ctor load issues and use singleton for video_backend module access

This commit is contained in:
Aaron Culliney 2015-04-16 21:22:47 -07:00 committed by Aaron Culliney
parent 4d3b1189d4
commit af95212a19
10 changed files with 77 additions and 70 deletions

View File

@ -90,19 +90,19 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsChanged(JNIEnv *env, jobject obj, jint width, jint height) {
LOG("%s", "native graphicsChanged...");
video_backend->reshape(width, height);
video_backendInstance()->reshape(width, height);
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
LOG("native graphicsInitialized width:%d height:%d", width, height);
static bool graphicsPreviouslyInitialized = false;
if (graphicsPreviouslyInitialized) {
video_backend->shutdown();
video_backendInstance()->shutdown();
}
graphicsPreviouslyInitialized = true;
video_backend->reshape(width, height);
video_backend->init((void *)0);
video_backendInstance()->reshape(width, height);
video_backendInstance()->init((void *)0);
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobject obj) {
@ -149,7 +149,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject
if (!nativePaused) {
_vid_dirty = true;// HACK HACK HACK FIXME TODO : efficiency and battery life gains if we can fix this ...
}
video_backend->render();
video_backendInstance()->render();
}
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jobject obj) {
@ -220,8 +220,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeIncreaseCPUSpeed(JNIEnv *en
LOG("native set emulation percentage to %f", cpu_scale_factor);
if (video_backend->video_animation_show_cpuspeed) {
video_backend->video_animation_show_cpuspeed();
if (video_backendInstance()->video_animation_show_cpuspeed) {
video_backendInstance()->video_animation_show_cpuspeed();
}
#warning HACK TODO FIXME ... refactor timing stuff
@ -253,8 +253,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeDecreaseCPUSpeed(JNIEnv *en
LOG("native set emulation percentage to %f", cpu_scale_factor);
if (video_backend->video_animation_show_cpuspeed) {
video_backend->video_animation_show_cpuspeed();
if (video_backendInstance()->video_animation_show_cpuspeed) {
video_backendInstance()->video_animation_show_cpuspeed();
}
#warning HACK TODO FIXME ... refactor timing stuff

View File

@ -196,10 +196,10 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
// Init our renderer. Use 0 for the defaultFBO which is appropriate for
// OSX (but not iOS since iOS apps must create their own FBO)
#if TARGET_OS_MAC
video_backend->init(0);
video_backendInstance()->init(0);
#elif TARGET_OS_IPHONE
# error "FBO FIXME TODO"
video_backend->init(otherFBO);
video_backendInstance()->init(otherFBO);
#else
# error "unknown/unsupported Apple platform
#endif
@ -246,7 +246,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
#endif // !SUPPORT_RETINA_RESOLUTION
// Set the new dimensions in our renderer
video_backend->reshape((int)viewRectPixels.size.width, (int)viewRectPixels.size.height);
video_backendInstance()->reshape((int)viewRectPixels.size.width, (int)viewRectPixels.size.height);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
@ -276,7 +276,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
- (void)drawView
{
CGLLockContext([[self openGLContext] CGLContextObj]);
video_backend->render();
video_backendInstance()->render();
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
[[NSNotificationCenter defaultCenter] postNotificationName:(NSString *)kDrawTimerNotification object:nil];
@ -296,7 +296,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
#endif
// shut down common OpenGL stuff AFTER display link has been released
video_backend->shutdown();
video_backendInstance()->shutdown();
[super dealloc];
}

View File

@ -16,6 +16,12 @@
#ifdef __APPLE__
#import <libkern/OSAtomic.h>
#define spin_lock_t OSSpinLock
#define spin_lock_lock OSSpinLockLock
#define spin_lock_unlock OSSpinLockUnlock
#define CLOCK_MONOTONIC 1
int clock_gettime(int, struct timespec *);

View File

@ -25,7 +25,6 @@ static uint8_t vga_mem_page_0[SCANWIDTH*SCANHEIGHT];
static uint8_t vga_mem_page_1[SCANWIDTH*SCANHEIGHT];
A2Color_s colormap[256] = { { 0 } };
video_backend_s *video_backend = NULL;
static uint8_t video__wider_font[0x8000];
static uint8_t video__font[0x4000];
@ -491,7 +490,7 @@ void video_loadfont(int first, int quantity, const uint8_t *data, int mode) {
}
}
static void video_loadfont_int(int first, int quantity, const uint8_t *data) {
static void video_loadfont_interface(int first, int quantity, const uint8_t *data) {
unsigned int i = quantity * 8;
while (i--) {
unsigned int j = 8;
@ -721,15 +720,15 @@ GLUE_C_WRITE(video__write_2e_text1_mixed)
// ----------------------------------------------------------------------------
// Classic interface and printing HUD messages
static void _load_interface_fonts(void) {
video_loadfont_int(0x00,0x40,ucase_glyphs);
video_loadfont_int(0x40,0x20,ucase_glyphs);
video_loadfont_int(0x60,0x20,lcase_glyphs);
video_loadfont_int(0x80,0x40,ucase_glyphs);
video_loadfont_int(0xC0,0x20,ucase_glyphs);
video_loadfont_int(0xE0,0x20,lcase_glyphs);
video_loadfont_int(0x80,11,interface_glyphs);
video_loadfont_int(MOUSETEXT_BEGIN,0x20,mousetext_glyphs);
void video_loadfonts_interface(void) {
video_loadfont_interface(0x00,0x40,ucase_glyphs);
video_loadfont_interface(0x40,0x20,ucase_glyphs);
video_loadfont_interface(0x60,0x20,lcase_glyphs);
video_loadfont_interface(0x80,0x40,ucase_glyphs);
video_loadfont_interface(0xC0,0x20,ucase_glyphs);
video_loadfont_interface(0xE0,0x20,lcase_glyphs);
video_loadfont_interface(0x80,11,interface_glyphs);
video_loadfont_interface(MOUSETEXT_BEGIN,0x20,mousetext_glyphs);
}
void interface_plotChar(uint8_t *fb, int fb_pix_width, int col, int row, interface_colorscheme_t cs, uint8_t c) {
@ -1058,7 +1057,7 @@ void video_init(void) {
#if !defined(__APPLE__)
#if !defined(ANDROID)
if (!is_headless) {
video_backend->init((void*)0);
video_backendInstance()->init((void*)0);
}
#endif
#endif
@ -1068,7 +1067,7 @@ void video_init(void) {
void video_shutdown(void) {
#if !HEADLESS
if (!is_headless) {
video_backend->shutdown();
video_backendInstance()->shutdown();
}
#if !defined(__APPLE__)
exit(0);
@ -1078,7 +1077,7 @@ void video_shutdown(void) {
void video_main_loop(void) {
#if !HEADLESS
video_backend->main_loop();
video_backendInstance()->main_loop();
#endif
}
@ -1272,10 +1271,3 @@ uint8_t floating_bus_hibit(const bool hibit) {
uint8_t b = apple_ii_64k[0][scanner_addr];
return (b & ~0x80) | (hibit ? 0x80 : 0);
}
__attribute__((constructor))
static void _init_interface(void) {
LOG("display subsystem startup");
_load_interface_fonts();
}

View File

@ -253,8 +253,8 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
if (current_key == kF9)
{
timing_toggle_cpu_speed();
if (video_backend->video_animation_show_cpuspeed) {
video_backend->video_animation_show_cpuspeed();
if (video_backendInstance()->video_animation_show_cpuspeed) {
video_backendInstance()->video_animation_show_cpuspeed();
}
break;
}
@ -284,8 +284,8 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
cpu_scale_factor = scale;
}
if (video_backend->video_animation_show_cpuspeed) {
video_backend->video_animation_show_cpuspeed();
if (video_backendInstance()->video_animation_show_cpuspeed) {
video_backendInstance()->video_animation_show_cpuspeed();
}
#warning HACK TODO FIXME ... refactor timing stuff
timing_toggle_cpu_speed();
@ -313,8 +313,8 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked)
cpu_scale_factor = scale;
}
if (video_backend->video_animation_show_cpuspeed) {
video_backend->video_animation_show_cpuspeed();
if (video_backendInstance()->video_animation_show_cpuspeed) {
video_backendInstance()->video_animation_show_cpuspeed();
}
#warning HACK TODO FIXME ... refactor timing stuff
timing_toggle_cpu_speed();

View File

@ -31,7 +31,7 @@ color_mode_t color_mode = COLOR;
const char *data_dir = NULL;
__attribute__((constructor))
static void _init_common() {
static void _init_common(void) {
error_log = stderr;
#if defined(CONFIG_DATADIR)
data_dir = strdup(CONFIG_DATADIR "/" PACKAGE_NAME);
@ -599,6 +599,8 @@ void c_initialize_firsttime(void) {
#ifdef DEBUGGER
c_debugger_init();
#endif
video_loadfonts_interface();
}
#if !TESTING && !defined(__APPLE__) && !defined(ANDROID)

View File

@ -161,8 +161,7 @@ static bool cpuanim_onTouchEvent(interface_touch_event_t action, int pointer_cou
__attribute__((constructor))
static void _init_glcpuanim(void) {
LOG("Registering CPU speed animations");
video_backend->video_animation_show_cpuspeed = &cpuanim_show;
video_backendInstance()->video_animation_show_cpuspeed = &cpuanim_show;
glnode_registerNode(RENDER_MIDDLE, (GLNode){
.setup = &cpuanim_init,
.shutdown = &cpuanim_shutdown,

View File

@ -47,8 +47,6 @@ static GLuint texcoordBufferName = UNINITIALIZED_GL;
static GLuint elementBufferName = UNINITIALIZED_GL;
static GLModel *crtModel = NULL;
static video_backend_s glvideo_backend = { 0 };
#if USE_GLUT
static int glutWindow = -1;
#endif
@ -879,16 +877,19 @@ static void gldriver_main_loop(void) {
// fall through if not GLUT
}
__attribute__((constructor))
static void _init_glvideo(void) {
LOG("Initializing OpenGL renderer");
glvideo_backend.init = &gldriver_init;
glvideo_backend.main_loop = &gldriver_main_loop;
glvideo_backend.reshape = &gldriver_reshape;
glvideo_backend.render = &gldriver_render;
glvideo_backend.shutdown = &gldriver_shutdown;
video_backend = &glvideo_backend;
video_backend_s *video_backendInstance(void) {
static video_backend_s *glvideo_backend = NULL;
spin_lock_t lock = 0L;
spin_lock_lock(&lock);
if (glvideo_backend == NULL) {
glvideo_backend = malloc(sizeof(video_backend_s));
glvideo_backend->init = &gldriver_init;
glvideo_backend->main_loop = &gldriver_main_loop;
glvideo_backend->reshape = &gldriver_reshape;
glvideo_backend->render = &gldriver_render;
glvideo_backend->shutdown = &gldriver_shutdown;
}
spin_lock_unlock(&lock);
return glvideo_backend;
}

View File

@ -34,7 +34,7 @@ typedef struct video_backend_s {
/*
* The registered video backend (renderer).
*/
extern video_backend_s *video_backend;
extern video_backend_s *video_backendInstance(void);
/*
* Color structure
@ -103,6 +103,11 @@ void video_set(int flags);
*/
void video_loadfont(int first, int qty, const uint8_t *data, int mode);
/*
* Load interface fonts.
*/
void video_loadfonts_interface(void);
/*
* Redraw the display. This is called after exiting an interface display,
* when changes have been made to the Apple's emulated framebuffer that

View File

@ -60,7 +60,6 @@ static int xshmeventtype;
// pad pixels to uint32_t boundaries
static int bitmap_pad = sizeof(uint32_t);
static video_backend_s xvideo_backend = { 0 };
static bool request_set_mode = false;
static int request_mode = 0;
@ -938,16 +937,19 @@ static void xdriver_render(void) {
// no-op
}
__attribute__((constructor))
static void _init_xvideo(void) {
LOG("Initializing X11 renderer");
xvideo_backend.init = &xdriver_init;
xvideo_backend.main_loop = &xdriver_main_loop;
xvideo_backend.reshape = &xdriver_reshape;
xvideo_backend.render = &xdriver_render;
xvideo_backend.shutdown = &xdriver_shutdown;
video_backend = &xvideo_backend;
video_backend_s *video_backendInstance(void) {
static video_backend_s *xvideo_backend = NULL;
spin_lock_t lock = 0L;
spin_lock_lock(&lock);
if (xvideo_backend == NULL) {
xvideo_backend = malloc(sizeof(video_backend_s));
xvideo_backend->init = &xdriver_init;
xvideo_backend->main_loop = &xdriver_main_loop;
xvideo_backend->reshape = &xdriver_reshape;
xvideo_backend->render = &xdriver_render;
xvideo_backend->shutdown = &xdriver_shutdown;
}
spin_lock_unlock(&lock);
return xvideo_backend;
}