summaryrefslogtreecommitdiffstats
path: root/hacks/xlockmoreI.h
blob: 3892e58e5ddd1ada94f56573f94475dc2c530d81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* xlockmore.h --- xscreensaver compatibility layer for xlockmore modules.
 * xscreensaver, Copyright (c) 1997-2021 Jamie Zawinski <jwz@jwz.org>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 *
 * See xlockmore.h and xlockmore.c.
 */

#ifndef __XLOCKMORE_INTERNAL_H__
#define __XLOCKMORE_INTERNAL_H__

#include <time.h>

#include "screenhackI.h"
#include "erase.h"


typedef struct ModeInfo ModeInfo;

/* Keep slots for these pointers in ModeInfo even if this header is
   included in a file that is not being compiled in GL-mode. so that
   sizeof(ModeInfo) doesn't vary.
 */
#if defined(HAVE_GL) && !defined(USE_GL)
# ifdef HAVE_JWZGLES
   typedef struct jwzgles_state jwzgles_state;
# endif
# ifdef HAVE_EGL
   typedef struct egl_data egl_data;
# elif !defined(HAVE_COCOA) && !defined(HAVE_ANDROID)
  typedef void *GLXContext;
# endif
#endif /* HAVE_GL && !USE_GL */

#ifdef HAVE_EGL
  typedef struct egl_data *GLXContext;
  typedef Drawable GLXDrawable;
#endif /* !HAVE_EGL */

#if defined(HAVE_EGL) && defined(USE_GL)
  typedef struct egl_data {
    EGLDisplay egl_display;
    EGLSurface egl_surface;
    EGLContext egl_context;  /* Unused */
    EGLConfig  egl_config;   /* Unused */
  } egl_data;

  extern Bool glXMakeCurrent (Display *, GLXDrawable, GLXContext);
  extern void glXSwapBuffers (Display *, GLXDrawable);
#endif /* HAVE_EGL && USE_GL */


#ifdef USE_GL
  extern GLXContext *init_GL (ModeInfo *);
  extern void xlockmore_reset_gl_state(void);
  extern void clear_gl_error (void);
  extern void check_gl_error (const char *type);

  extern Visual *xlockmore_pick_gl_visual (Screen *);
  extern Bool xlockmore_validate_gl_visual (Screen *, const char *, Visual *);
#endif /* USE_GL */


/* These are only used in GL mode, but I don't understand why XCode
   isn't seeing the prototypes for them in glx/fps-gl.c... */
extern void do_fps (ModeInfo *);
extern void xlockmore_gl_compute_fps (Display *, Window, fps_state *, void *);
extern void xlockmore_gl_draw_fps (ModeInfo *);
extern void xlockmore_gl_free_fps (fps_state *);
# define do_fps xlockmore_gl_draw_fps


extern void xlockmore_setup (struct xscreensaver_function_table *, void *);
extern void xlockmore_do_fps (Display *, Window, fps_state *, void *);
extern void xlockmore_mi_init (ModeInfo *, size_t, void **);
extern Bool xlockmore_no_events (ModeInfo *, XEvent *);

/* The xlockmore RNG API is implemented in utils/yarandom.h. */


struct ModeInfo {
  struct xlockmore_function_table *xlmft;
  Display *dpy;
  Window window;
  Bool root_p;
  int screen_number;
  int npixels;
  unsigned long *pixels;
  XColor *colors;
  Bool writable_p;
  unsigned long white;
  unsigned long black;
  XWindowAttributes xgwa;
  GC gc;
  long pause;
  Bool fullrandom;
  long cycles;
  long batchcount;
  long size;
  Bool threed;
  long threed_left_color;
  long threed_right_color;
  long threed_both_color;
  long threed_none_color;
  long threed_delta;
  Bool wireframe_p;
  Bool is_drawn;
  eraser_state *eraser;
  Bool needs_clear;

  /* Used only by OpenGL programs, since FPS is tricky there. */
  fps_state *fpst;
  Bool fps_p;
  unsigned long polygon_count;  /* These values are for -fps display only */
  double recursion_depth;

# ifdef HAVE_GL
#  ifndef HAVE_JWXYZ
    GLXContext glx_context;  /* or egl_data */
#  endif
#  ifdef HAVE_JWZGLES
    jwzgles_state *jwzgles_state;
#  endif
# endif /* HAVE_GL */
};

typedef enum {  t_String, t_Float, t_Int, t_Bool } xlockmore_type;

typedef struct {
  void *var;
  char *name;
  char *classname;
  char *def;
  xlockmore_type type;
} argtype;

typedef struct {
  char *opt;
  char *desc;
} OptionStruct;

typedef struct {
  int numopts;
  XrmOptionDescRec *opts;
  int numvarsdesc;
  argtype *vars;
  OptionStruct *desc;
} ModeSpecOpt;

struct xlockmore_function_table {
  const char *progclass;
  const char *defaults;
  Bool want_writable_colors;
  enum { color_scheme_default, color_scheme_uniform, 
         color_scheme_smooth, color_scheme_bright }
    desired_color_scheme;
  void (*hack_init) (ModeInfo *);
  void (*hack_draw) (ModeInfo *);
  void (*hack_reshape) (ModeInfo *, int, int);
  void (*hack_release) (ModeInfo *);
  void (*hack_free) (ModeInfo *);
  Bool (*hack_handle_events) (ModeInfo *, XEvent *);
  ModeSpecOpt *opts;

# ifdef HAVE_JWZGLES    /* set in xlock-gl-utils.c */
  void (*jwzgles_make_current) (jwzgles_state *);
  void (*jwzgles_free) (void);
# endif /* HAVE_JWZGLES */

  void **state_array;
  unsigned long live_displays, got_init;
};

#ifdef HAVE_JWXYZ
# define XLOCKMORE_NUM_SCREENS	\
  (sizeof(((struct xlockmore_function_table *)0)->live_displays) * 8)
#else
# define XLOCKMORE_NUM_SCREENS	2 /* For DEBUG_PAIR. */
#endif

#endif /* __XLOCKMORE_INTERNAL_H__ */