began for maemo
[xscreensaver] / xscreensaver / hacks / xlockmoreI.h
1 /* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
2  * xscreensaver, Copyright (c) 1997-2002, 2006 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
22 #ifdef HAVE_XSHM_EXTENSION
23 # include "xshm.h"
24 #endif /* HAVE_XSHM_EXTENSION */
25
26
27 typedef struct ModeInfo ModeInfo;
28
29 #ifdef USE_GL
30
31 /* I'm told that the Sun version of OpenGL needs to have the constant
32    SUN_OGL_NO_VERTEX_MACROS defined in order for morph3d to compile
33    (the number of arguments to the glNormal3f macro changes...)
34    Verified with gcc 2.7.2.2 and Sun cc 4.2 with OpenGL 1.1.1 dev 4
35    on Solaris 2.5.1.
36  */
37 # ifndef HAVE_MESA_GL
38 #  if defined(__sun) && defined(__SVR4) /* Solaris */
39 #   define SUN_OGL_NO_VERTEX_MACROS 1
40 #  endif /* Solaris */
41 # endif /* !HAVE_MESA_GL */
42
43 # ifdef HAVE_COCOA
44 #  include <OpenGL/gl.h>
45 # else
46 #  include <GL/gl.h>
47 #  include <GL/glx.h>
48 # endif
49
50   extern GLXContext *init_GL (ModeInfo *);
51   extern void clear_gl_error (void);
52   extern void check_gl_error (const char *type);
53
54   extern void do_fps (ModeInfo *);
55   extern GLfloat fps_1 (ModeInfo *);
56   extern void    fps_2 (ModeInfo *);
57
58   extern Visual *xlockmore_pick_gl_visual (Screen *);
59   extern Bool xlockmore_validate_gl_visual (Screen *, const char *, Visual *);
60
61 #endif /* !USE_GL */
62
63 extern void xlockmore_setup (struct xscreensaver_function_table *, void *);
64
65
66 /* Compatibility with the xlockmore RNG API
67    (note that the xlockmore hacks never expect negative numbers.)
68  */
69 #define LRAND()                 ((long) (random() & 0x7fffffff))
70 #define NRAND(n)                ((int) (LRAND() % (n)))
71 #define MAXRAND                 (2147483648.0) /* unsigned 1<<31 as a float */
72 #define SRAND(n)                /* already seeded by screenhack.c */
73
74
75 struct ModeInfo {
76   struct xlockmore_function_table *xlmft;
77   Display *dpy;
78   Window window;
79   Bool root_p;
80   int num_screens;
81   int screen_number;
82   int npixels;
83   unsigned long *pixels;
84   XColor *colors;
85   Bool writable_p;
86   unsigned long white;
87   unsigned long black;
88   XWindowAttributes xgwa;
89   GC gc;
90   long pause;
91   Bool fullrandom;
92   long cycles;
93   long batchcount;
94   long size;
95   Bool threed;
96   long threed_left_color;
97   long threed_right_color;
98   long threed_both_color;
99   long threed_none_color;
100   long threed_delta;
101   Bool wireframe_p;
102   Bool is_drawn;
103   
104   Bool fps_p;
105   struct fps_state *fps_state;  /* private data for fps.c */
106   
107   unsigned long polygon_count;  /* used only by FPS display */
108
109 #ifdef HAVE_XSHM_EXTENSION
110   Bool use_shm;
111   XShmSegmentInfo shm_info;
112 #endif
113 };
114
115 typedef enum {  t_String, t_Float, t_Int, t_Bool } xlockmore_type;
116
117 typedef struct {
118   void *var;
119   char *name;
120   char *classname;
121   char *def;
122   xlockmore_type type;
123 } argtype;
124
125 typedef struct {
126   char *opt;
127   char *desc;
128 } OptionStruct;
129
130 typedef struct {
131   int numopts;
132   XrmOptionDescRec *opts;
133   int numvarsdesc;
134   argtype *vars;
135   OptionStruct *desc;
136 } ModeSpecOpt;
137
138 struct xlockmore_function_table {
139   const char *progclass;
140   const char *defaults;
141   Bool want_writable_colors;
142   enum { color_scheme_default, color_scheme_uniform, 
143          color_scheme_smooth, color_scheme_bright }
144     desired_color_scheme;
145   void (*hack_init) (ModeInfo *);
146   void (*hack_draw) (ModeInfo *);
147   void (*hack_reshape) (ModeInfo *, int, int);
148   void (*hack_refresh) (ModeInfo *);
149   void (*hack_free) (ModeInfo *);
150   Bool (*hack_handle_events) (ModeInfo *, XEvent *);
151   ModeSpecOpt *opts;
152 };
153
154 #endif /* __XLOCKMORE_INTERNAL_H__ */