1 /* xscreensaver, Copyright (c) 1991-2014 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
14 But it's a bunch of function definitions that bear some resemblance to
15 Xlib and that do things that bear some resemblance to the
16 things that Xlib might have done.
22 #include <android/log.h>
25 #include "jwxyz-timers.h"
27 #include "screenhackI.h"
29 typedef signed char BOOL;
37 typedef struct CGPoint CGPoint;
43 typedef struct CGSize CGSize;
49 typedef struct CGRect CGRect;
51 struct jwxyz_Drawable {
52 enum { WINDOW, PIXMAP } type;
56 unsigned long background;
57 int last_mouse_x, last_mouse_y;
66 struct jwxyz_Display {
70 struct jwxyz_sources_data *timers_data;
80 static void draw_rect(Display *, Drawable, GC,
81 int x, int y, unsigned int width,
82 unsigned int height, BOOL foreground_p, BOOL fill_p);
85 XParseColor(Display * dpy, Colormap cmap, const char *spec, XColor * ret)
87 unsigned char r = 0, g = 0, b = 0;
88 if (*spec == '#' && strlen(spec) == 7) {
89 static unsigned const char hex[] = { // yeah yeah, shoot me.
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4,
93 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
94 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
107 r = (hex[spec[1]] << 4) | hex[spec[2]];
108 g = (hex[spec[3]] << 4) | hex[spec[4]];
109 b = (hex[spec[5]] << 4) | hex[spec[6]];
110 } else if (!strcasecmp(spec, "black")) {
112 } else if (!strcasecmp(spec, "white")) {
114 } else if (!strcasecmp(spec, "red")) {
116 } else if (!strcasecmp(spec, "green")) {
118 } else if (!strcasecmp(spec, "blue")) {
120 } else if (!strcasecmp(spec, "cyan")) {
122 } else if (!strcasecmp(spec, "magenta")) {
124 } else if (!strcasecmp(spec, "yellow")) {
130 ret->red = (r << 8) | r;
131 ret->green = (g << 8) | g;
132 ret->blue = (b << 8) | b;
133 ret->flags = DoRed | DoGreen | DoBlue;
137 Status XAllocColor(Display * dpy, Colormap cmap, XColor * color)
139 // store 32 bit ARGB in the pixel field.
140 // (The uint32_t is so that 0xFF000000 doesn't become 0xFFFFFFFFFF000000)
141 color->pixel = (uint32_t)
143 (((color->red >> 8) & 0xFF) << 16) |
144 (((color->green >> 8) & 0xFF) << 8) |
145 (((color->blue >> 8) & 0xFF)));
149 // needs to be implemented in Android...
151 XFillRectangle(Display * dpy, Drawable d, GC gc, int x, int y,
152 unsigned int width, unsigned int height)
157 // needs to be implemented in Android...
159 XDrawString(Display * dpy, Drawable d, GC gc, int x, int y,
160 const char *str, int len)
162 return 0; // try this for now...
166 // needs to be implemented in Android...
167 int XFreeGC(Display * dpy, GC gc)
174 int XFreeFont(Display * dpy, XFontStruct * f)
179 int XFreeFontInfo(char **names, XFontStruct * info, int n)
183 for (i = 0; i < n; i++)
189 for (i = 0; i < n; i++)
190 if (info[i].per_char)
191 free(info[i].per_char);
198 // needs to be implemented in Android...
199 int XUnloadFont(Display * dpy, Font fid)
205 // needs to be implemented in Android...
207 XCreateGC(Display * dpy, Drawable d, unsigned long mask, XGCValues * xgcv)
212 // needs to be implemented in Android...
213 XFontStruct *XLoadQueryFont(Display * dpy, const char *name)
219 XGetWindowAttributes(Display * dpy, Window w, XWindowAttributes * xgwa)
222 // Assert (w && w->type == WINDOW, "not a window");
224 memset(xgwa, 0, sizeof(*xgwa));
225 xgwa->x = w->frame.origin.x;
226 xgwa->y = w->frame.origin.y;
227 xgwa->width = w->frame.size.width;
228 xgwa->height = w->frame.size.height;
230 xgwa->screen = dpy->screen;
231 xgwa->visual = dpy->screen->visual;
236 // needs to be implemented in Android...
237 int XSetFont(Display * dpy, GC gc, Font fid)
243 // needs to be implemented in Android...
244 int XClearWindow(Display * dpy, Window win)
248 // declared in utils/visual.h
249 int has_writable_cells(Screen * s, Visual * v)
255 XAllocColorCells(Display * dpy, Colormap cmap, Bool contig,
256 unsigned long *pmret, unsigned int npl,
257 unsigned long *pxret, unsigned int npx)
262 int XStoreColors(Display * dpy, Colormap cmap, XColor * colors, int n)
264 //Assert(0, "XStoreColors called");
269 XFreeColors(Display * dpy, Colormap cmap, unsigned long *px, int npixels,
270 unsigned long planes)
275 int XFlush(Display * dpy)
280 Display *XDisplayOfScreen(Screen * s)
285 // needs to be implemented in Android...
287 XLookupString(XKeyEvent * e, char *buf, int size, KeySym * k_ret,
293 int XScreenNumberOfScreen(Screen * s)
295 return s->screen_number;
298 int jwxyz_ScreenCount(Display * dpy)
300 return dpy->screen_count;
305 // should this be defined?
306 static Display *jwxyz_live_displays[20] = { 0, };
309 Display * jwxyz_make_display (void *nsview_arg, void *cgc_arg)
311 Display *d = (Display *) calloc(1, sizeof(*d));
312 d->screen = (Screen *) calloc(1, sizeof(Screen));
316 d->screen->screen_number = 0;
318 Visual *v = (Visual *) calloc(1, sizeof(Visual));
319 v->class = TrueColor;
320 v->red_mask = 0x00FF0000;
321 v->green_mask = 0x0000FF00;
322 v->blue_mask = 0x000000FF;
324 d->screen->visual = v;
326 Window w = (Window) calloc(1, sizeof(*w));
328 w->window.background = BlackPixel(0, 0);
336 jwxyz_free_display (Display *dpy)
338 free (dpy->screen->visual);
340 free (dpy->main_window);
345 /* Call this when the Renderer calls onSurfaceChanged
348 jwxyz_window_resized (Display *dpy, Window w,
349 int new_x, int new_y, int new_width, int new_height,
352 w->frame.origin.x = new_x;
353 w->frame.origin.y = new_y;
354 w->frame.size.width = new_width;
355 w->frame.size.height = new_height;
358 Window XRootWindow(Display * dpy, int screen)
360 return dpy->main_window;
363 /* Handle an abort on Android
364 TODO: Test that Android handles aborts properly
367 jwxyz_abort (const char *fmt, ...)
375 va_start (args, fmt);
376 vsprintf (s, fmt, args);
379 /* Send error to Android device log */
380 __android_log_write(ANDROID_LOG_ERROR, "xscreensaver", s);
386 XCreatePixmap (Display *dpy, Drawable d,
387 unsigned int width, unsigned int height, unsigned int depth)
392 XDestroyImage (XImage *ximage)
394 if (ximage->data) free (ximage->data);
400 XDrawString16 (Display *dpy, Drawable d, GC gc, int x, int y,
401 const XChar2b *str, int len)
406 XFreePixmap (Display *d, Pixmap p)
411 XGetImage (Display *dpy, Drawable d, int x, int y,
412 unsigned int width, unsigned int height,
413 unsigned long plane_mask, int format)
418 XGetPixel (XImage *ximage, int x, int y)
423 XSetForeground (Display *dpy, GC gc, unsigned long fg)
428 XTextExtents16 (XFontStruct *f, const XChar2b *s, int length,
429 int *dir_ret, int *ascent_ret, int *descent_ret,