From http://www.jwz.org/xscreensaver/xscreensaver-5.40.tar.gz
[xscreensaver] / jwxyz / jwxyz.h
index 335df69100b0c788a776e6336930a61a1b089201..c70bdbe862ef0da3c5702d3109d19df686a31f81 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1991-2016 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1991-2018 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
@@ -20,6 +20,7 @@
 #define __JWXYZ_H__
 
 #include <stdlib.h> /* For abort(). */
+#include <stdarg.h>
 
 #if defined __FreeBSD__ || defined __MACH__ && defined __APPLE__
 # include <sys/cdefs.h>
@@ -45,11 +46,10 @@ typedef void * XPointer;
 typedef unsigned long Time;
 typedef unsigned int KeySym;
 typedef unsigned int KeyCode;
-typedef unsigned int VisualID;
 typedef unsigned long Atom; /* Must be as large as a char *. */
 
 typedef struct jwxyz_Display           Display;
-typedef struct jwxyz_Screen            Screen;
+typedef struct jwxyz_Display           Screen;
 typedef struct jwxyz_Visual            Visual;
 typedef struct jwxyz_Drawable *                Drawable;
 typedef struct jwxyz_Colormap *                Colormap;
@@ -92,6 +92,8 @@ typedef struct jwxyz_XtIntervalId *   XtIntervalId;
 typedef struct jwxyz_XtInputId *       XtInputId;
 typedef void *                         XtPointer;
 typedef unsigned long                  XtInputMask;
+typedef struct jwxyz_linked_point      linked_point;
+
 #define XtInputReadMask                        (1L<<0)
 #define XtInputWriteMask               (1L<<1)
 #define XtInputExceptMask              (1L<<2)
@@ -309,16 +311,11 @@ typedef unsigned long                     XtInputMask;
 #define XHeightOfScreen(s) (DisplayHeight(DisplayOfScreen(s),0))
 #define XWidthMMOfScreen(s) (XDisplayWidthMM(DisplayOfScreen(s),0))
 #define XHeightMMOfScreen(s) (XDisplayHeightMM(DisplayOfScreen(s),0))
+#define XDefaultScreenOfDisplay(d) (d)
+#define XDisplayOfScreen(s) (s)
+#define XDisplayNumberOfScreen(s) 0
+#define XScreenNumberOfScreen(s) 0
 
-#define ScreenCount(dpy) jwxyz_ScreenCount(dpy)
-extern int jwxyz_ScreenCount(Display *);
-
-extern Window XRootWindow (Display *, int screen);
-extern Screen *XDefaultScreenOfDisplay (Display *);
-extern Visual *XDefaultVisualOfScreen (Screen *);
-extern Display *XDisplayOfScreen (Screen *);
-extern int XDisplayNumberOfScreen (Screen *);
-extern int XScreenNumberOfScreen (Screen *);
 extern int XDisplayWidth (Display *, int);
 extern int XDisplayHeight (Display *, int);
 extern int XDisplayWidthMM (Display *, int);
@@ -329,14 +326,9 @@ unsigned long XWhitePixelOfScreen(Screen *);
 unsigned long XCellsOfScreen(Screen *);
 
 extern int XDrawPoint (Display *, Drawable, GC, int x, int y);
-extern int XDrawPoints (Display *, Drawable, GC, XPoint *, int n, int mode);
-extern int XDrawSegments (Display *, Drawable, GC, XSegment *, int n);
 
-extern GC XCreateGC (Display *, Drawable, unsigned long mask, XGCValues *);
 extern int XChangeGC (Display *, GC, unsigned long mask, XGCValues *);
-extern int XFreeGC (Display *, GC);
 
-extern int XClearWindow (Display *, Window);
 extern int XClearArea (Display *, Window, int x, int y, int w, int h,Bool exp);
 extern int XSetWindowBackground (Display *, Window, unsigned long);
 extern Status XGetWindowAttributes (Display *, Window, XWindowAttributes *);
@@ -362,8 +354,6 @@ extern int XSetFunction (Display *, GC, int);
 extern int XSetSubwindowMode (Display *, GC, int);
 extern int XSetLineAttributes (Display *, GC, unsigned int line_width,
                                int line_style, int cap_style, int join_style);
-extern int XSetClipMask (Display *, GC, Pixmap);
-extern int XSetClipOrigin (Display *, GC, int x, int y);
 extern int jwxyz_XSetAlphaAllowed (Display *, GC, Bool);
 extern int jwxyz_XSetAntiAliasing (Display *, GC, Bool);
 
@@ -371,8 +361,6 @@ extern int XFlush (Display *);
 extern int XSync (Display *, Bool);
 extern int XFreeColors (Display *, Colormap, unsigned long *px, int n,
                         unsigned long planes);
-extern int XFillPolygon (Display *, Drawable, GC, 
-                         XPoint * points, int npoints, int shape, int mode);
 extern int XCopyArea (Display *, Drawable src, Drawable dest, GC, 
                       int src_x, int src_y, 
                       unsigned int width, unsigned int height, 
@@ -384,7 +372,6 @@ extern int XCopyPlane (Display *, Drawable, Drawable, GC,
                        unsigned long plane);
 
 extern int XDrawLine (Display *, Drawable, GC, int x1, int y1, int x2, int y2);
-extern int XDrawLines (Display *, Drawable, GC, XPoint *, int n, int mode);
 extern int XDrawArc (Display *, Drawable, GC, int x, int y, 
                      unsigned int width, unsigned int height,
                      int angle1, int angle2);
@@ -426,9 +413,6 @@ extern XImage *XSubImage (XImage *, int x, int y,
 extern unsigned long XGetPixel (XImage *, int x, int y);
 extern int XPutPixel (XImage *, int x, int y, unsigned long);
 extern int XDestroyImage (XImage *);
-extern int XPutImage (Display *, Drawable, GC, XImage *, 
-                      int src_x, int src_y, int dest_x, int dest_y,
-                      unsigned int w, unsigned int h);
 extern XImage *XGetImage (Display *, Drawable, int x, int y,
                           unsigned int w, unsigned int h,
                           unsigned long pm, int fmt);
@@ -436,7 +420,7 @@ extern Pixmap XCreatePixmapFromBitmapData (Display *, Drawable,
                                            const char *data,
                                            unsigned int w, unsigned int h,
                                            unsigned long fg,
-                                           unsigned int bg,
+                                           unsigned long bg,
                                            unsigned int depth);
 extern XPixmapFormatValues *XListPixmapFormats (Display *, int *count_ret);
 
@@ -444,6 +428,8 @@ extern void jwxyz_draw_NSImage_or_CGImage (Display *, Drawable,
                                            Bool nsimg_p, void *NSImage_arg,
                                            XRectangle *geom_ret, 
                                            int exif_rotation);
+extern XImage *jwxyz_png_to_ximage (Display *, Visual *,
+                                    const unsigned char *, unsigned long size);
 
 extern int XSetGraphicsExposures (Display *, GC, Bool);
 extern Bool XTranslateCoordinates (Display *, Window src_w, Window dest_w,
@@ -460,7 +446,7 @@ extern int XUnloadFont (Display *, Font);
 extern int XTextExtents (XFontStruct *, const char *, int length,
                          int *dir_ret, int *ascent_ret, int *descent_ret,
                          XCharStruct *overall_ret);
-extern char * jwxyz_unicode_character_name (Font, unsigned long uc);
+extern char * jwxyz_unicode_character_name (Display *, Font, unsigned long uc);
 extern int XTextExtents16 (XFontStruct *, const XChar2b *, int length,
                            int *dir_ret, int *ascent_ret, int *descent_ret,
                            XCharStruct *overall_ret);
@@ -478,7 +464,6 @@ extern int Xutf8TextExtents (XFontSet, const char *, int num_bytes,
                              XRectangle *overall_logical_return);
 extern void Xutf8DrawString (Display *, Drawable, XFontSet, GC,
                              int x, int y, const char *, int num_bytes);
-extern const char *jwxyz_nativeFontName (Font, float *size);
 
 extern Pixmap XCreatePixmap (Display *, Drawable,
                              unsigned int width, unsigned int height,
@@ -487,6 +472,31 @@ extern int XFreePixmap (Display *, Pixmap);
 
 extern char *XGetAtomName (Display *, Atom);
 
+extern void set_points_list(XPoint *points, int npoints, linked_point *root);
+extern void traverse_points_list(Display *dpy, linked_point * root);
+extern void draw_three_vertices(Display *dpy, linked_point * a,
+                                Bool triangle);
+extern double compute_edge_length(linked_point * a, linked_point * b);
+extern double get_angle(double a, double b, double c);
+extern Bool is_same_slope(linked_point * a);
+extern Bool is_an_ear(linked_point * a);
+extern Bool is_three_point_loop(linked_point * head);
+
+extern int draw_arc_gl(Display *dpy, Drawable d, GC gc, int x, int y,
+                   unsigned int width, unsigned int height,
+                   int angle1, int angle2, Bool fill_p);
+
+// Log()/Logv(), for debugging JWXYZ. Screenhacks should still use
+// fprintf(stderr, ...).
+extern void Log(const char *format, ...)
+#if defined __GNUC__ || defined __clang__
+  __attribute__((format(printf, 1, 2)))
+#endif
+  ;
+
+extern void jwxyz_logv(Bool error, const char *fmt, va_list args);
+#define Logv(format, args) (jwxyz_logv(False, format, args))
+
 // Xt timers and fds
 extern XtAppContext XtDisplayToApplicationContext (Display *);
 typedef void (*XtTimerCallbackProc) (XtPointer closure, XtIntervalId *);
@@ -499,7 +509,6 @@ extern XtInputId XtAppAddInput (XtAppContext, int fd, XtPointer flags,
 extern void XtRemoveInput (XtInputId);
 extern XtInputMask XtAppPending (XtAppContext);
 extern void XtAppProcessEvent (XtAppContext, XtInputMask);
-extern struct jwxyz_sources_data *display_sources_data (Display *);
 
 // Some GLX stuff that also doesn't technically belong here...
 // from XScreenSaverGLView.m
@@ -509,9 +518,13 @@ extern void glXMakeCurrent (Display *, Window, GLXContext);
 // also declared in utils/visual.h
 extern int has_writable_cells (Screen *, Visual *);
 extern int visual_depth (Screen *, Visual *);
+extern int visual_pixmap_depth (Screen *, Visual *);
 extern int visual_cells (Screen *, Visual *);
 extern int visual_class (Screen *, Visual *);
-extern int get_bits_per_pixel (Display *, int);
+extern void visual_rgb_masks (Screen *screen, Visual *visual,
+                              unsigned long *red_mask,
+                              unsigned long *green_mask,
+                              unsigned long *blue_mask);
 extern int screen_number (Screen *);
 
 // also declared in utils/grabclient.h
@@ -521,12 +534,12 @@ extern Bool use_subwindow_mode_p (Screen *, Window);
 extern void clear_gl_error (void);
 extern void check_gl_error (const char *type);
 
+// A Visual is supposed to be an opaque type, even though Xlib.h defines it.
+// Only utils/xft.c uses this, out of necessity.
 struct jwxyz_Visual {
-  VisualID visualid;   /* visual id of this visual */
   int class;           /* class of screen (monochrome, etc.) */
-  unsigned long red_mask, green_mask, blue_mask;       /* mask values */
-  int bits_per_rgb;    /* log base 2 of distinct color values */
-//  int map_entries;   /* color map entries */
+  unsigned long red_mask, green_mask, blue_mask;       /* same as Xlib.h */
+  unsigned long alpha_mask;                            /* new */
 };
 
 struct jwxyz_XGCValues {
@@ -813,4 +826,81 @@ struct jwxyz_XChar2b {
   unsigned char byte2;
 };
 
+
+struct jwxyz_vtbl {
+  Window (*root) (Display *);
+  Visual *(*visual) (Display *);
+  struct jwxyz_sources_data *(*display_sources_data) (Display *);
+
+  unsigned long *(*window_background) (Display *);
+  int (*draw_arc) (Display *dpy, Drawable d, GC gc, int x, int y,
+                   unsigned int width, unsigned int height,
+                   int angle1, int angle2, Bool fill_p);
+  void (*fill_rects) (Display *dpy, Drawable d, GC gc,
+                      const XRectangle *rectangles,
+                      unsigned long nrects, unsigned long pixel);
+  XGCValues *(*gc_gcv) (GC gc);
+  unsigned int (*gc_depth) (GC gc);
+  int (*draw_string) (Display *dpy, Drawable d, GC gc, int x, int y,
+                      const char *str, size_t len, Bool utf8);
+
+  void (*copy_area) (Display *dpy, Drawable src, Drawable dst, GC gc,
+                     int src_x, int src_y,
+                     unsigned int width, unsigned int height,
+                     int dst_x, int dst_y);
+
+  int (*DrawPoints) (Display *, Drawable, GC, XPoint *, int n, int mode);
+  int (*DrawSegments) (Display *, Drawable, GC, XSegment *, int n);
+  GC (*CreateGC) (Display *, Drawable, unsigned long mask, XGCValues *);
+  int (*FreeGC) (Display *, GC);
+  int (*ClearWindow) (Display *, Window);
+  int (*SetClipMask) (Display *, GC, Pixmap);
+  int (*SetClipOrigin) (Display *, GC, int x, int y);
+  int (*FillPolygon) (Display *, Drawable, GC,
+                      XPoint * points, int npoints, int shape, int mode);
+  int (*DrawLines) (Display *, Drawable, GC, XPoint *, int n, int mode);
+
+  int (*PutImage) (Display *, Drawable, GC, XImage *,
+                    int src_x, int src_y, int dest_x, int dest_y,
+                    unsigned int w, unsigned int h);
+  XImage *(*GetSubImage) (Display *dpy, Drawable d, int x, int y,
+                          unsigned int width, unsigned int height,
+                          unsigned long plane_mask, int format,
+                          XImage *dest_image, int dest_x, int dest_y);
+};
+
+#define JWXYZ_VTBL(dpy) (*(struct jwxyz_vtbl **)(dpy))
+
+#define XRootWindow(dpy, screen) \
+  ((dpy) ? JWXYZ_VTBL(dpy)->root(dpy) : 0)
+#define XDefaultVisualOfScreen(screen) \
+  ((screen) ? JWXYZ_VTBL(screen)->visual(screen) : 0)
+
+#define XDrawPoints(dpy, d, gc, points, n, mode) \
+  (JWXYZ_VTBL(dpy)->DrawPoints (dpy, d, gc, points, n, mode))
+#define XDrawSegments(dpy, d, gc, segments, n) \
+  (JWXYZ_VTBL(dpy)->DrawSegments (dpy, d, gc, segments, n))
+#define XCreateGC(dpy, d, mask, gcv) \
+  (JWXYZ_VTBL(dpy)->CreateGC (dpy, d, mask, gcv))
+#define XFreeGC(dpy, gc) \
+  (JWXYZ_VTBL(dpy)->FreeGC (dpy, gc))
+#define XClearWindow(dpy, win) \
+  (JWXYZ_VTBL(dpy)->ClearWindow(dpy, win))
+#define XSetClipMask(dpy, gc, m) \
+  (JWXYZ_VTBL(dpy)->SetClipMask (dpy, gc, m))
+#define XSetClipOrigin(dpy, gc, x, y) \
+  (JWXYZ_VTBL(dpy)->SetClipOrigin (dpy, gc, x, y))
+#define XFillPolygon(dpy, d, gc, points, npoints, shape, mode) \
+  (JWXYZ_VTBL(dpy)->FillPolygon (dpy, d, gc, points, npoints, shape, mode))
+#define XDrawLines(dpy, d, gc, points, n, mode) \
+  (JWXYZ_VTBL(dpy)->DrawLines (dpy, d, gc, points, n, mode))
+#define XPutImage(dpy, d, gc, image, src_x, src_y, dest_x, dest_y, w, h) \
+  (JWXYZ_VTBL(dpy)->PutImage (dpy, d, gc, image, src_x, src_y, \
+                              dest_x, dest_y, w, h))
+#define XGetSubImage(dpy, d, x, y, width, height, plane_mask, \
+                     format, dest_image, dest_x, dest_y) \
+  (JWXYZ_VTBL(dpy)->GetSubImage (dpy, d, x, y, width, height, plane_mask, \
+                                 format, dest_image, dest_x, dest_y))
+
+
 #endif /* __JWXYZ_H__ */