1 /* xscreensaver, Copyright (c) 1991-2018 Jamie Zawinski <jwz@jwz.org>
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
20 #define Assert(C, ...) do { if (!(C)) jwxyz_abort (__VA_ARGS__); } while(0)
24 #define MAX(a,b) ((a)>(b)?(a):(b))
25 #define MIN(a,b) ((a)<(b)?(a):(b))
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
31 #define JWXYZ_STYLE_BOLD 1
32 #define JWXYZ_STYLE_ITALIC 2
33 #define JWXYZ_STYLE_MONOSPACE 4
35 #define JWXYZ_QUERY_COLOR(dpy, pixel, mult, rgba) \
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; \
44 /* jwxyz.m, jwxyz-gl.c, jwxyz-image.c */
45 extern void jwxyz_window_resized (Display *);
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);
51 /* 'scale' is pixels per point, with 72 points per inch. This matches the
52 meaning of -[UIView contentScaleFactor] on iOS.
54 extern float jwxyz_scale (Window main_window);
56 extern const char *jwxyz_default_font_family (int require);
57 extern void *jwxyz_load_native_font (Window main_window,
58 int traits_jwxyz, int mask_jwxyz,
59 const char *font_name_ptr,
60 size_t font_name_length,
61 int font_name_type, float size,
62 char **family_name_ret,
63 int *ascent_ret, int *descent_ret);
64 extern void jwxyz_release_native_font (Display *, void *native_font);
66 /* Text metrics for aliased and antialiased text must match. */
67 extern void jwxyz_render_text (Display *, void *native_font,
68 const char *str, size_t len, Bool utf8_p,
69 Bool antialias_p, XCharStruct *cs_ret,
71 extern void jwxyz_get_pos (Window w, XPoint *vpos, XPoint *p);
72 #ifndef current_device_rotation
73 extern double current_device_rotation (void);
74 extern Bool ignore_rotation_p (Display *);
78 extern void jwxyz_validate_pixel (Display *dpy, unsigned long pixel,
79 unsigned int depth, Bool alpha_allowed_p);
80 extern Bool jwxyz_dumb_drawing_mode(Display *dpy, Drawable d, GC gc,
82 unsigned width, unsigned height);
83 extern void jwxyz_blit (const void *src_data, ptrdiff_t src_pitch,
84 unsigned src_x, unsigned src_y,
85 void *dst_data, ptrdiff_t dst_pitch,
86 unsigned dst_x, unsigned dst_y,
87 unsigned width, unsigned height);
88 extern void jwxyz_fill_rect (Display *, Drawable, GC,
90 unsigned int width, unsigned int height,
92 extern void jwxyz_gcv_defaults (Display *dpy, XGCValues *gcv, int depth);
93 extern int jwxyz_draw_string (Display *dpy, Drawable d, GC gc, int x, int y,
94 const char *str, size_t len, int utf8_p);
95 extern void *jwxyz_native_font (Font f);
97 #define SEEK_XY(dst, dst_pitch, x, y) \
98 ((uint32_t *)((char *)dst + dst_pitch * y + x * 4))
102 # include <CoreGraphics/CGGeometry.h>
103 # include <CoreGraphics/CGContext.h>
105 extern Display *jwxyz_quartz_make_display (Window w);
106 extern void jwxyz_quartz_free_display (Display *);
107 extern void jwxyz_flush_context (Display *);
109 # define jwxyz_assert_display(dpy)
110 # define jwxyz_assert_drawable(main_window, d)
111 # define jwxyz_assert_gl()
113 /* jwxyz-cocoa.m needs these from jwxyz.m for XCopyArea. */
114 extern void invalidate_drawable_cache (Drawable d);
115 extern void set_color (Display *dpy, CGContextRef cgc, unsigned long argb,
116 unsigned int depth, Bool alpha_allowed_p, Bool fill_p);
117 extern void push_gc (Drawable d, GC gc);
118 extern void push_color_gc (Display *dpy, Drawable d, GC gc,
120 Bool antialias_p, Bool fill_p);
121 extern CGPoint map_point (Drawable d, int x, int y);
122 extern void jwxyz_quartz_copy_area (Display *dpy, Drawable src, Drawable dst,
123 GC gc, int src_x, int src_y,
124 unsigned int width, unsigned int height,
125 int dst_x, int dst_y);
127 #define pop_gc(d,gc) CGContextRestoreGState (d->cgc)
129 # endif /* JWXYZ_QUARTZ */
133 # if defined(USE_IPHONE)
134 # include <OpenGLES/ES1/gl.h>
135 # elif defined(HAVE_COCOA)
136 # include <OpenGL/gl.h>
137 # elif defined(HAVE_ANDROID)
138 # include <GLES/gl.h>
143 /* utils/jwxyz-gl.c */
144 extern Display *jwxyz_gl_make_display (Window w);
145 extern void jwxyz_gl_free_display (Display *);
146 extern void jwxyz_set_matrices (Display *dpy, unsigned width, unsigned height,
148 extern void jwxyz_gl_flush (Display *dpy);
149 extern void jwxyz_gl_set_gc (Display *dpy, GC gc);
150 extern void jwxyz_gl_copy_area (Display *dpy, Drawable src, Drawable dst,
151 GC gc, int src_x, int src_y,
152 unsigned int width, unsigned int height,
153 int dst_x, int dst_y);
155 /* Only works if both drawables share OpenGL objects. OpenGL context sharing
156 works on OS X, iOS, and some (but not all!) EGL implementations. This would
157 also work with FBOs and one context for everything. Surprisingly slow and
160 extern void jwxyz_gl_copy_area_read_tex_image (Display *dpy,
162 int src_x, int src_y,
165 int dst_x, int dst_y);
166 extern void jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc,
167 int src_x, int src_y,
170 int dst_x, int dst_y);
172 extern void jwxyz_gl_draw_image (Display *dpy, GC gc,
173 GLenum gl_texture_target,
174 unsigned int tex_w, unsigned int tex_h,
175 int src_x, int src_y, int src_depth,
176 unsigned int width, unsigned int height,
177 int dst_x, int dst_y, Bool flip_y);
179 /* glReadPixels followed by glTexImage2D. This is terrible, so only use this
180 if nothing else works.
182 extern void jwxyz_gl_copy_area_read_pixels (Display *dpy, Drawable src,
184 int src_x, int src_y,
187 int dst_x, int dst_y);
189 /* Platform-specific */
190 extern void jwxyz_bind_drawable (Display *dpy, Window w, Drawable d);
191 extern void jwxyz_assert_display (Display *);
192 extern void jwxyz_assert_drawable (Window main_window, Drawable d);
193 extern void jwxyz_assert_gl (void);
195 # endif /* JWXYZ_GL */
199 extern Display *jwxyz_image_make_display (Window w,
200 const unsigned char *rgba_bytes);
201 extern void jwxyz_image_free_display (Display *);
203 extern ptrdiff_t jwxyz_image_pitch (Drawable d);
204 extern void *jwxyz_image_data (Drawable d);
206 # endif /* JWXYZ_IMAGE */