1 /* xscreensaver, Copyright (c) 1991-2016 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
19 #define Assert(C, ...) do { if (!(C)) jwxyz_abort (__VA_ARGS__); } while(0)
23 #define MAX(a,b) ((a)>(b)?(a):(b))
24 #define MIN(a,b) ((a)<(b)?(a):(b))
26 #define JWXYZ_FONT_FAMILY 0 /* i.e. -[NSFont familyName] via XLFD */
27 #define JWXYZ_FONT_FACE 1 /* -[NSFont fontName] via native */
28 #define JWXYZ_FONT_RANDOM 2
30 #define JWXYZ_STYLE_BOLD 1
31 #define JWXYZ_STYLE_ITALIC 2
32 #define JWXYZ_STYLE_MONOSPACE 4
34 /* jwxyz.m, jwxyz-gl.c */
35 extern Display *jwxyz_make_display (Window w);
36 extern void jwxyz_free_display (Display *);
37 extern void jwxyz_window_resized (Display *);
38 extern uint32_t jwxyz_alloc_color (Display *dpy, uint16_t r, uint16_t g,
39 uint16_t b, uint16_t a);
40 extern void jwxyz_query_color (Display *dpy, unsigned long pixel,
42 extern unsigned long jwxyz_window_background (Display *);
43 extern int jwxyz_draw_arc (Display *dpy, Drawable d, GC gc, int x, int y,
44 unsigned int width, unsigned int height,
45 int angle1, int angle2, Bool fill_p);
46 extern void jwxyz_fill_rects (Display *dpy, Drawable d, GC gc,
47 const XRectangle *rectangles,
50 extern XGCValues *jwxyz_gc_gcv (GC gc);
51 extern unsigned int jwxyz_gc_depth (GC gc);
52 extern int jwxyz_draw_string (Display *dpy, Drawable d, GC gc, int x, int y,
53 const char *str, size_t len, Bool utf8);
55 /* jwxyz-cocoa.m, jwxyz-android.c */
56 extern const XRectangle *jwxyz_frame (Drawable d); /* XGetGeometry sux. */
57 extern unsigned int jwxyz_drawable_depth (Drawable d);
59 /* 'scale' is pixels per point, with 72 points per inch. This matches the
60 meaning of -[UIView contentScaleFactor] on iOS.
62 extern float jwxyz_scale (Window main_window);
64 extern const char *jwxyz_default_font_family (int require);
65 extern void *jwxyz_load_native_font (Window main_window,
66 int traits_jwxyz, int mask_jwxyz,
67 const char *font_name_ptr,
68 size_t font_name_length,
69 int font_name_type, float size,
70 char **family_name_ret,
71 int *ascent_ret, int *descent_ret);
72 extern void jwxyz_release_native_font (Display *, void *native_font);
73 extern void jwxyz_render_text (Display *, void *native_font,
74 const char *str, size_t len, int utf8_p,
75 XCharStruct *cs_ret, char **pixmap_ret);
76 extern void jwxyz_get_pos (Window w, XPoint *vpos, XPoint *p);
77 extern void jwxyz_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc,
79 unsigned int width, unsigned int height,
80 int dst_x, int dst_y);
81 #ifndef current_device_rotation
82 extern double current_device_rotation (void);
83 extern Bool ignore_rotation_p (Display *);
87 extern void jwxyz_validate_pixel (Display *dpy, unsigned long pixel,
88 unsigned int depth, Bool alpha_allowed_p);
89 extern Bool jwxyz_dumb_drawing_mode(Display *dpy, Drawable d, GC gc,
91 unsigned width, unsigned height);
92 extern void jwxyz_fill_rect (Display *, Drawable, GC,
94 unsigned int width, unsigned int height,
96 extern void jwxyz_gcv_defaults (Display *dpy, XGCValues *gcv, int depth);
97 extern void *jwxyz_native_font (Font f);
99 # if defined JWXYZ_QUARTZ
101 # include <CoreGraphics/CGGeometry.h>
102 # include <CoreGraphics/CGContext.h>
104 extern void jwxyz_flush_context (Display *);
106 # define jwxyz_assert_display(dpy)
107 # define jwxyz_assert_drawable(main_window, d)
108 # define jwxyz_assert_gl()
110 /* jwxyz-cocoa.m needs these from jwxyz.m for XCopyArea. */
111 extern void invalidate_drawable_cache (Drawable d);
112 extern void set_color (Display *dpy, CGContextRef cgc, unsigned long argb,
113 unsigned int depth, Bool alpha_allowed_p, Bool fill_p);
114 extern void push_gc (Drawable d, GC gc);
115 extern void push_color_gc (Display *dpy, Drawable d, GC gc,
117 Bool antialias_p, Bool fill_p);
118 extern CGPoint map_point (Drawable d, int x, int y);
120 #define seek_xy(dst, dst_pitch, x, y) \
121 ((void *)((char *)dst + dst_pitch * y + x * 4))
123 #define pop_gc(d,gc) CGContextRestoreGState (d->cgc)
125 # elif defined JWXYZ_GL
127 # if defined(USE_IPHONE)
128 # include <OpenGLES/ES1/gl.h>
129 # elif defined(HAVE_COCOA)
130 # include <OpenGL/gl.h>
131 # elif defined(HAVE_ANDROID)
132 # include <GLES/gl.h>
137 /* utils/jwxyz-gl.c */
138 extern void jwxyz_prepare_context (Display *dpy);
139 extern void jwxyz_set_matrices (Display *dpy, unsigned width, unsigned height,
142 /* Only works if both drawables share OpenGL objects. OpenGL context sharing
143 works on OS X, iOS, and some (but not all!) EGL implementations. This would
144 also work with FBOs and one context for everything. Surprisingly slow and
147 extern void jwxyz_gl_copy_area_read_tex_image (Display *dpy,
149 int src_x, int src_y,
152 int dst_x, int dst_y);
153 extern void jwxyz_gl_copy_area_write_tex_image (Display *dpy, GC gc,
154 int src_x, int src_y,
157 int dst_x, int dst_y);
158 extern void jwxyz_gl_draw_image (GLenum target,
159 unsigned int tex_w, unsigned int tex_h,
160 int src_x, int src_y,
161 unsigned int width, unsigned int height,
162 int dst_x, int dst_y);
164 /* glReadPixels followed by glTexImage2D. This is terrible, so only use this
165 if nothing else works.
167 extern void jwxyz_gl_copy_area_read_pixels (Display *dpy, Drawable src,
169 int src_x, int src_y,
172 int dst_x, int dst_y);
174 /* Platform-specific */
175 extern void jwxyz_bind_drawable (Display *dpy, Window w, Drawable d);
176 extern void jwxyz_assert_display (Display *);
177 extern void jwxyz_assert_drawable (Window main_window, Drawable d);
178 extern void jwxyz_assert_gl (void);
180 # endif /* JWXYZ_GL */