From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / xlockmoreI.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2014 Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  *
12  * See xlockmore.h and xlockmore.c.
13  */
14
15 #ifndef __XLOCKMORE_INTERNAL_H__
16 #define __XLOCKMORE_INTERNAL_H__
17
18 #include <time.h>
19
20 #include "screenhackI.h"
21 #include "xshm.h"
22
23
24 typedef struct ModeInfo ModeInfo;
25
26 #ifdef USE_GL
27
28 /* I'm told that the Sun version of OpenGL needs to have the constant
29    SUN_OGL_NO_VERTEX_MACROS defined in order for morph3d to compile
30    (the number of arguments to the glNormal3f macro changes...)
31    Verified with gcc 2.7.2.2 and Sun cc 4.2 with OpenGL 1.1.1 dev 4
32    on Solaris 2.5.1.
33  */
34 # ifndef HAVE_MESA_GL
35 #  if defined(__sun) && defined(__SVR4) /* Solaris */
36 #   define SUN_OGL_NO_VERTEX_MACROS 1
37 #  endif /* Solaris */
38 # endif /* !HAVE_MESA_GL */
39
40 # ifdef HAVE_COCOA
41 #  ifndef USE_IPHONE
42 #   include <OpenGL/gl.h>
43 #   include <OpenGL/glu.h>
44 #  endif
45 # elif defined(HAVE_ANDROID)
46 #  include <GLES/gl.h>
47 # else
48 #  include <GL/gl.h>
49 #  include <GL/glu.h>
50 #  include <GL/glx.h>
51 # endif
52
53 # ifdef HAVE_JWZGLES
54 #  include "jwzgles.h"
55 # endif /* HAVE_JWZGLES */
56
57
58   extern GLXContext *init_GL (ModeInfo *);
59   extern void xlockmore_reset_gl_state(void);
60   extern void clear_gl_error (void);
61   extern void check_gl_error (const char *type);
62
63   extern Visual *xlockmore_pick_gl_visual (Screen *);
64   extern Bool xlockmore_validate_gl_visual (Screen *, const char *, Visual *);
65
66 #endif /* !USE_GL */
67
68 /* These are only used in GL mode, but I don't understand why XCode
69    isn't seeing the prototypes for them in glx/fps-gl.c... */
70 extern void do_fps (ModeInfo *);
71 extern void xlockmore_gl_compute_fps (Display *, Window, fps_state *, void *);
72 extern void xlockmore_gl_draw_fps (ModeInfo *);
73 # define do_fps xlockmore_gl_draw_fps
74
75
76 extern void xlockmore_setup (struct xscreensaver_function_table *, void *);
77 extern void xlockmore_do_fps (Display *, Window, fps_state *, void *);
78
79
80 extern void xlockmore_mi_init (ModeInfo *, size_t, void **,
81                                void (*) (ModeInfo *));
82
83
84 /* The xlockmore RNG API is implemented in utils/yarandom.h. */
85
86
87 struct ModeInfo {
88   struct xlockmore_function_table *xlmft;
89   Display *dpy;
90   Window window;
91   Bool root_p;
92   int screen_number;
93   int npixels;
94   unsigned long *pixels;
95   XColor *colors;
96   Bool writable_p;
97   unsigned long white;
98   unsigned long black;
99   XWindowAttributes xgwa;
100   GC gc;
101   long pause;
102   Bool fullrandom;
103   long cycles;
104   long batchcount;
105   long size;
106   Bool threed;
107   long threed_left_color;
108   long threed_right_color;
109   long threed_both_color;
110   long threed_none_color;
111   long threed_delta;
112   Bool wireframe_p;
113   Bool is_drawn;
114
115   /* Used only by OpenGL programs, since FPS is tricky there. */
116   fps_state *fpst;
117   Bool fps_p;
118   unsigned long polygon_count;  /* These values are for -fps display only */
119   double recursion_depth;
120 };
121
122 typedef enum {  t_String, t_Float, t_Int, t_Bool } xlockmore_type;
123
124 typedef struct {
125   void *var;
126   char *name;
127   char *classname;
128   char *def;
129   xlockmore_type type;
130 } argtype;
131
132 typedef struct {
133   char *opt;
134   char *desc;
135 } OptionStruct;
136
137 typedef struct {
138   int numopts;
139   XrmOptionDescRec *opts;
140   int numvarsdesc;
141   argtype *vars;
142   OptionStruct *desc;
143 } ModeSpecOpt;
144
145 struct xlockmore_function_table {
146   const char *progclass;
147   const char *defaults;
148   Bool want_writable_colors;
149   enum { color_scheme_default, color_scheme_uniform, 
150          color_scheme_smooth, color_scheme_bright }
151     desired_color_scheme;
152   void (*hack_init) (ModeInfo *);
153   void (*hack_draw) (ModeInfo *);
154   void (*hack_reshape) (ModeInfo *, int, int);
155   void (*hack_refresh) (ModeInfo *);
156   void (*hack_release) (ModeInfo *);
157   Bool (*hack_handle_events) (ModeInfo *, XEvent *);
158   ModeSpecOpt *opts;
159
160   size_t state_size;
161   void **state_array;
162   void (*hack_free_state) (ModeInfo *);
163   unsigned long live_displays, got_init;
164 };
165
166 #ifdef HAVE_JWXYZ
167 # define XLOCKMORE_NUM_SCREENS  \
168   (sizeof(((struct xlockmore_function_table *)0)->live_displays) * 8)
169 #else
170 # define XLOCKMORE_NUM_SCREENS  2 /* For DEBUG_PAIR. */
171 #endif
172
173 #endif /* __XLOCKMORE_INTERNAL_H__ */