From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / jwxyz / jwxyzI.h
1 /* xscreensaver, Copyright (c) 1991-2016 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
17 #include "jwxyz.h"
18
19 #define Assert(C, ...) do { if (!(C)) jwxyz_abort (__VA_ARGS__); } while(0)
20
21 /* OSX/jwxyz.m, utils/jwxyz-gl.c */
22 extern Display *jwxyz_make_display (Window w);
23 extern void jwxyz_free_display (Display *);
24 extern void jwxyz_window_resized (Display *);
25 extern uint32_t jwxyz_alloc_color (Display *dpy, uint16_t r, uint16_t g,
26                                    uint16_t b, uint16_t a);
27 extern void jwxyz_query_color (Display *dpy, unsigned long pixel,
28                                uint8_t *rgba);
29 extern unsigned long jwxyz_window_background (Display *);
30 extern int jwxyz_draw_arc (Display *dpy, Drawable d, GC gc, int x, int y,
31                            unsigned int width, unsigned int height,
32                            int angle1, int angle2, Bool fill_p);
33 extern void jwxyz_fill_rects (Display *dpy, Drawable d, GC gc,
34                               const XRectangle *rectangles,
35                               unsigned long nrects,
36                               unsigned long pixel);
37 extern XGCValues *jwxyz_gc_gcv (GC gc);
38 extern unsigned int jwxyz_gc_depth (GC gc);
39
40 /* OSX/jwxyz-cocoa.m, android/jwxyz-android.c */
41 extern const XRectangle *jwxyz_frame (Drawable d); /* XGetGeometry sux. */
42 extern unsigned int jwxyz_drawable_depth (Drawable d);
43 extern void jwxyz_get_pos (Window w, XPoint *vpos, XPoint *p);
44 extern void jwxyz_copy_area (Display *dpy, Drawable src, Drawable dst, GC gc,
45                              int src_x, int src_y,
46                              unsigned int width, unsigned int height,
47                              int dst_x, int dst_y);
48 #ifndef current_device_rotation
49 extern double current_device_rotation (void);
50 extern Bool ignore_rotation_p (Display *);
51 #endif
52
53 /* utils/jwxyz-common.c */
54 extern void jwxyz_validate_pixel (Display *dpy, unsigned long pixel,
55                                   unsigned int depth, Bool alpha_allowed_p);
56 extern Bool jwxyz_dumb_drawing_mode(Display *dpy, Drawable d, GC gc,
57                                     int x, int y,
58                                     unsigned width, unsigned height);
59 extern void jwxyz_fill_rect (Display *, Drawable, GC,
60                              int x, int y,
61                              unsigned int width, unsigned int height,
62                              unsigned long pixel);
63 extern void jwxyz_gcv_defaults (Display *dpy, XGCValues *gcv, int depth);
64
65 # if defined JWXYZ_QUARTZ
66
67 #  include <CoreGraphics/CGGeometry.h>
68 #  include <CoreGraphics/CGContext.h>
69
70 extern void jwxyz_flush_context (Display *);
71
72 #  define jwxyz_assert_display(dpy)
73 #  define jwxyz_assert_drawable(main_window, d)
74 #  define jwxyz_assert_gl()
75
76 /* jwxyz-cocoa.m needs these from jwxyz.m for XCopyArea. */
77 extern void invalidate_drawable_cache (Drawable d);
78 extern void set_color (Display *dpy, CGContextRef cgc, unsigned long argb,
79                        unsigned int depth, Bool alpha_allowed_p, Bool fill_p);
80 extern void push_gc (Drawable d, GC gc);
81 extern void push_color_gc (Display *dpy, Drawable d, GC gc,
82                            unsigned long color,
83                            Bool antialias_p, Bool fill_p);
84 extern CGPoint map_point (Drawable d, int x, int y);
85
86 #define seek_xy(dst, dst_pitch, x, y) \
87   ((void *)((char *)dst + dst_pitch * y + x * 4))
88
89 #define pop_gc(d,gc) CGContextRestoreGState (d->cgc)
90
91 # elif defined JWXYZ_GL
92
93 /* utils/jwxyz-gl.c */
94 extern void jwxyz_prepare_context (Display *dpy);
95 extern void jwxyz_set_matrices (Display *dpy, unsigned width, unsigned height,
96                                 Bool screen_p);
97
98 /* Only works if both drawables share OpenGL objects. OpenGL context sharing
99    works on OS X, iOS, and some (but not all!) EGL implementations. This would
100    also work with FBOs and one context for everything. Surprisingly slow and
101    unreliable.
102  */
103 extern void jwxyz_gl_copy_area_copy_tex_image (Display *dpy, Drawable src,
104                                                Drawable dst, GC gc,
105                                                int src_x, int src_y,
106                                                unsigned int width,
107                                                unsigned int height,
108                                                int dst_x, int dst_y);
109
110 /* glReadPixels followed by glTexImage2D. This is terrible, so only use this
111    if nothing else works.
112  */
113 extern void jwxyz_gl_copy_area_read_pixels (Display *dpy, Drawable src,
114                                             Drawable dst, GC gc,
115                                             int src_x, int src_y,
116                                             unsigned int width,
117                                             unsigned int height,
118                                             int dst_x, int dst_y);
119
120 /* Platform-specific */
121 extern void jwxyz_bind_drawable (Display *dpy, Window w, Drawable d);
122 extern void jwxyz_assert_display (Display *);
123 extern void jwxyz_assert_drawable (Window main_window, Drawable d);
124 extern void jwxyz_assert_gl (void);
125
126 extern void *jwxyz_load_native_font (Display *, const char *name,
127                                      char **native_name_ret, float *size_ret,
128                                      int *ascent_ret, int *descent_ret);
129 extern void jwxyz_release_native_font (Display *, void *native_font);
130 extern void jwxyz_render_text (Display *, void *native_font,
131                                const char *str, size_t len, int utf8_p,
132                                XCharStruct *cs_ret, char **pixmap_ret);
133
134 # endif /* JWXYZ_GL */
135
136 #endif