X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fxlockmore.h;h=fe09961481869246ad0aea95c34c5233580d76c2;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=abb24818cc46c95135ef8d5baf799eca565107a1;hpb=c1b9b55ad8d59dc05ef55e316aebf5863e7dfa56;p=xscreensaver diff --git a/hacks/xlockmore.h b/hacks/xlockmore.h index abb24818..fe099614 100644 --- a/hacks/xlockmore.h +++ b/hacks/xlockmore.h @@ -1,5 +1,5 @@ /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules. - * xscreensaver, Copyright (c) 1997-2008 Jamie Zawinski + * xscreensaver, Copyright (c) 1997-2012 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -29,27 +29,15 @@ ERROR! Sorry, xlockmore.h requires ANSI C (gcc, for example.) #include "screenhackI.h" #include "xlockmoreI.h" -#ifdef USE_GL - -# ifdef HAVE_COCOA -# include -# include -# else /* !HAVE_COCOA -- real Xlib */ -# include -# include -# endif /* !HAVE_COCOA */ - -# define FreeAllGL(dpy) /* */ -#endif /* USE_GL */ - # define ENTRYPOINT static /* Accessor macros for the ModeInfo structure */ #define MI_DISPLAY(MI) ((MI)->dpy) #define MI_WINDOW(MI) ((MI)->window) -#define MI_NUM_SCREENS(MI) ((MI)->num_screens) +#define MI_NUM_SCREENS(MI) XLOCKMORE_NUM_SCREENS #define MI_SCREEN(MI) ((MI)->screen_number) +#define MI_SCREENPTR(MI) ((MI)->xgwa.screen) #define MI_WIN_WHITE_PIXEL(MI) ((MI)->white) #define MI_WIN_BLACK_PIXEL(MI) ((MI)->black) #define MI_NPIXELS(MI) ((MI)->npixels) @@ -102,6 +90,45 @@ ERROR! Sorry, xlockmore.h requires ANSI C (gcc, for example.) #define MI_CLEARWINDOW(mi) XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)) +/* MI_INIT and MI_ABORT are XScreenSaver extensions. These exist primarily for + the sake of ports to macOS, iOS, and Android, all of which need to restart + individual screenhacks repeatedly in the same process. This requires + reusing MI_SCREEN() numbers; previously many xlockmore API hacks did not + support this the way they were supposed to. + */ + +/* MI_INIT implements the following pattern, as seen in various forms at the + beginning of init_##(): + + if(!state_array) { + state_array = (state_t *)calloc(MI_NUM_SCREENS(mi), sizeof(state_t)); + if(!state_array) { + fprintf(stderr, "%s: out of memory\n", progname); + return; + } + } + hack_free_state(mi); + memset(&state_array[MI_SCREEN(mi)], 0, sizeof(*state_array)); + + It also enables hack_free_state to run when a screen is no longer in use. + This is called at some point after the last call to draw_##, but before + release_##. + */ + +#define MI_INIT(mi, state_array, hack_free_state) \ + xlockmore_mi_init ((mi), sizeof(*(state_array)), (void **)&(state_array), \ + hack_free_state) + +/* Use MI_ABORT if an init_## or draw_## hook needs to shut everything down. + This replaces explicit calls to release_## hooks when things go wrong from + inside an xlockmore API screenhack. + + At some point this may do something other than just abort(). + */ +#define MI_ABORT(mi) abort(); + +#define FreeAllGL(dpy) /* */ + /* Some other utility macros. */ #define SINF(n) ((float)sin((double)(n))) @@ -123,10 +150,10 @@ ERROR! Sorry, xlockmore.h requires ANSI C (gcc, for example.) a struct in `MODULENAME_xscreensaver_function_table', and a pointer to that in `xscreensaver_function_table'. - In a Cocoa world, we only define the prefixed symbol; + In a Cocoa or Android world, we only define the prefixed symbol; the un-prefixed symbol does not exist. */ -#ifdef HAVE_COCOA +#ifdef HAVE_MOBILE # define XSCREENSAVER_LINK(NAME) #else # define XSCREENSAVER_LINK(NAME) \ @@ -134,14 +161,16 @@ ERROR! Sorry, xlockmore.h requires ANSI C (gcc, for example.) #endif -# if !defined(USE_GL) || defined(HAVE_COCOA) +# if !defined(USE_GL) || defined(HAVE_COCOA) || defined(HAVE_ANDROID) # define xlockmore_pick_gl_visual 0 # define xlockmore_validate_gl_visual 0 -# endif /* !USE_GL || HAVE_COCOA */ +# endif /* !USE_GL || HAVE_COCOA || HAVE_ANDROID */ -# ifndef USE_GL -# define xlockmore_gl_compute_fps 0 -# endif /* !USE_GL */ +# ifdef USE_GL +# define XLOCKMORE_FPS xlockmore_gl_compute_fps +# else +# define XLOCKMORE_FPS xlockmore_do_fps +# endif #ifdef WRITABLE_COLORS # undef WRITABLE_COLORS @@ -197,7 +226,7 @@ ERROR! Sorry, xlockmore.h requires ANSI C (gcc, for example.) xlockmore_setup, \ & NAME ## _xlockmore_function_table, \ 0, 0, 0, 0, 0, \ - xlockmore_gl_compute_fps, \ + XLOCKMORE_FPS, \ xlockmore_pick_gl_visual, \ xlockmore_validate_gl_visual }; \ \