]> git.hungrycats.org Git - xscreensaver/blob - jwxyz/jwxyzI.h
From https://www.jwz.org/xscreensaver/xscreensaver-6.09.tar.gz
[xscreensaver] / jwxyz / jwxyzI.h
1 /* xscreensaver, Copyright © 1991-2021 Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  */
11
12 #ifndef __JWXYZ_I_H__
13 #define __JWXYZ_I_H__
14
15 #include <inttypes.h>
16 #include <stddef.h>
17
18 #include "jwxyz.h"
19
20 #define Assert(C, ...) do { if (!(C)) jwxyz_abort (__VA_ARGS__); } while(0)
21
22 #undef MAX
23 #undef MIN
24 #define MAX(a,b) ((a)>(b)?(a):(b))
25 #define MIN(a,b) ((a)<(b)?(a):(b))
26
27 #define JWXYZ_FONT_FAMILY       0 /* i.e. -[NSFont familyName] via XLFD */
28 #define JWXYZ_FONT_FACE         1 /*      -[NSFont fontName]   via native */
29 #define JWXYZ_FONT_RANDOM       2
30
31 #define JWXYZ_STYLE_BOLD        1
32 #define JWXYZ_STYLE_ITALIC      2
33 #define JWXYZ_STYLE_MONOSPACE   4
34
35 #define JWXYZ_QUERY_COLOR(dpy, pixel, mult, rgba) \
36   { \
37     Visual *_V = DefaultVisualOfScreen (DefaultScreenOfDisplay (dpy)); \
38     (rgba)[0] = ((pixel) & _V->red_mask)   * (mult) / _V->red_mask;    \
39     (rgba)[1] = ((pixel) & _V->green_mask) * (mult) / _V->green_mask;  \
40     (rgba)[2] = ((pixel) & _V->blue_mask)  * (mult) / _V->blue_mask;   \
41     (rgba)[3] = ((pixel) & _V->alpha_mask) * (mult) / _V->alpha_mask;  \
42   }
43
44 /* jwxyz.m, jwxyz-gl.c, jwxyz-image.c */
45 extern void jwxyz_window_resized (Display *);
46
47 /* jwxyz-cocoa.m, jwxyz-android.c */
48 extern const XRectangle *jwxyz_frame (Drawable d); /* XGetGeometry sux. */
49 extern unsigned int jwxyz_drawable_depth (Drawable d);
50
51 /* 'scale' is pixels per point, with 72 points per inch. This matches the
52    meaning of -[UIView contentScaleFactor] on iOS.
53  */
54 extern float jwxyz_scale (Window main_window);
55 extern float jwxyz_font_scale (Window main_window);
56
57 extern const char *jwxyz_default_font_family (int require);
58 extern void *jwxyz_load_native_font (Window main_window,
59                                      int traits_jwxyz, int mask_jwxyz,
60                                      const char *font_name_ptr,
61                                      size_t font_name_length,
62                                      int font_name_type, float size,
63                                      char **family_name_ret,
64                                      int *ascent_ret, int *descent_ret);
65 extern void jwxyz_release_native_font (Display *, void *native_font);
66
67 /* Text metrics for aliased and antialiased text must match. */
68 extern void jwxyz_render_text (Display *, void *native_font,
69                                const char *str, size_t len, Bool utf8_p,
70                                Bool antialias_p, XCharStruct *cs_ret,
71                                char **pixmap_ret);
72 extern void jwxyz_get_pos (Window w, XPoint *vpos, XPoint *p);
73 #ifndef current_device_rotation
74 extern double current_device_rotation (void);
75 extern Bool ignore_rotation_p (Display *);
76 #endif
77
78 /* jwxyz-common.c */
79 extern void jwxyz_validate_pixel (Display *dpy, unsigned long pixel,
80                                   unsigned int depth, Bool alpha_allowed_p);
81 extern Bool jwxyz_dumb_drawing_mode(Display *dpy, Drawable d, GC gc,
82                                     int x, int y,
83                                     unsigned width, unsigned height);
84 extern void jwxyz_blit (const void *src_data, ptrdiff_t src_pitch,
85                         unsigned src_x, unsigned src_y,
86                         void *dst_data, ptrdiff_t dst_pitch,
87                         unsigned dst_x, unsigned dst_y,
88                         unsigned width, unsigned height);
89 extern void jwxyz_fill_rect (Display *, Drawable, GC,
90                              int x, int y,
91                              unsigned int width, unsigned int height,
92                              unsigned long pixel);
93 extern void jwxyz_gcv_defaults (Display *dpy, XGCValues *gcv, int depth);
94 extern int jwxyz_draw_string (Display *dpy, Drawable d, GC gc, int x, int y,
95                               const char *str, size_t len, int utf8_p);
96 extern void *jwxyz_native_font (Font f);
97
98 #define SEEK_XY(dst, dst_pitch, x, y) \
99   ((uint32_t *)((char *)dst + dst_pitch * y + x * 4))
100
101 # ifdef JWXYZ_QUARTZ
102
103 #  include <CoreGraphics/CGGeometry.h>
104 #  include <CoreGraphics/CGContext.h>
105
106 extern Display *jwxyz_quartz_make_display (Window w);
107 extern void jwxyz_quartz_free_display (Display *);
108 extern void jwxyz_flush_context (Display *);
109
110 #  define jwxyz_assert_display(dpy)
111 #  define jwxyz_assert_drawable(main_window, d)
112 #  define jwxyz_assert_gl()
113
114 /* jwxyz-cocoa.m needs these from jwxyz.m for XCopyArea. */
115 extern void invalidate_drawable_cache (Drawable d);
116 extern void set_color (Display *dpy, CGContextRef cgc, unsigned long argb,
117                        unsigned int depth, Bool alpha_allowed_p, Bool fill_p);
118 extern void push_gc (Drawable d, GC gc);
119 extern void push_color_gc (Display *dpy, Drawable d, GC gc,
120                            unsigned long color,
121                            Bool antialias_p, Bool fill_p);
122 extern CGPoint map_point (Drawable d, int x, int y);
123 extern void jwxyz_quartz_copy_area (Display *dpy, Drawable src, Drawable dst,
124                                     GC gc, int src_x, int src_y,
125                                     unsigned int width, unsigned int height,
126                                     int dst_x, int dst_y);
127
128 #define pop_gc(d,gc) CGContextRestoreGState (d->cgc)
129
130 # endif /* JWXYZ_QUARTZ */
131
132 # ifdef JWXYZ_GL
133
134 #  if defined(HAVE_IPHONE)
135 #   include <OpenGLES/ES1/gl.h>
136 #  elif defined(HAVE_COCOA)
137 #   include <OpenGL/gl.h>
138 #  elif defined(HAVE_ANDROID)
139 #   include <GLES/gl.h>
140 #  else
141 #   include <GL/gl.h>
142 #  endif
143
144 /* utils/jwxyz-gl.c */
145 extern Display *jwxyz_gl_make_display (Window w);
146 extern void jwxyz_gl_free_display (Display *);
147 extern void jwxyz_set_matrices (Display *dpy, unsigned width, unsigned height,
148                                 Bool screen_p);
149 extern void jwxyz_gl_flush (Display *dpy);
150 extern void jwxyz_gl_set_gc (Display *dpy, GC gc);
151 extern void jwxyz_gl_copy_area (Display *dpy, Drawable src, Drawable dst,
152                                 GC gc, int src_x, int src_y,
153                                 unsigned int width, unsigned int height,
154                                 int dst_x, int dst_y);
155
156 /* Only works if both drawables share OpenGL objects. OpenGL context sharing
157    works on OS X, iOS, and some (but not all!) EGL implementations. This would
158    also work with FBOs and one context for everything. Surprisingly slow and
159    unreliable.
160  */
161 extern void jwxyz_gl_copy_area_read_tex_image (Display *dpy,
162                                                unsigned src_height,
163                                                int src_x, int src_y,
164                                                unsigned int width,
165                                                unsigned int height,
166                                                int dst_x, int dst_y);
167 extern void jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc,
168                                                 int src_x, int src_y,
169                                                 int src_depth,
170                                                 unsigned int width,
171                                                 unsigned int height,
172                                                 int dst_x, int dst_y);
173
174 extern void jwxyz_gl_draw_image (Display *dpy, GC gc,
175                                  GLenum gl_texture_target,
176                                  unsigned int tex_w, unsigned int tex_h,
177                                  int src_x, int src_y, int src_depth,
178                                  unsigned int width, unsigned int height,
179                                  int dst_x, int dst_y, Bool flip_y);
180
181 /* glReadPixels followed by glTexImage2D. This is terrible, so only use this
182    if nothing else works.
183  */
184 extern void jwxyz_gl_copy_area_read_pixels (Display *dpy, Drawable src,
185                                             Drawable dst, GC gc,
186                                             int src_x, int src_y,
187                                             unsigned int width,
188                                             unsigned int height,
189                                             int dst_x, int dst_y);
190
191 /* Platform-specific */
192 extern void jwxyz_bind_drawable (Display *dpy, Window w, Drawable d);
193 extern void jwxyz_assert_display (Display *);
194 extern void jwxyz_assert_drawable (Window main_window, Drawable d);
195 extern void jwxyz_assert_gl (void);
196
197 # endif /* JWXYZ_GL */
198
199 # ifdef JWXYZ_IMAGE
200
201 extern Display *jwxyz_image_make_display (Window w,
202                                           const unsigned char *rgba_bytes);
203 extern void jwxyz_image_free_display (Display *);
204
205 extern ptrdiff_t jwxyz_image_pitch (Drawable d);
206 extern void *jwxyz_image_data (Drawable d);
207
208 # endif /* JWXYZ_IMAGE */
209
210 #endif