1 /* xscreensaver, Copyright (c) 1991-2015 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;
76 unsigned long black, white;
82 XDefaultScreenOfDisplay (Display *dpy)
88 XBlackPixelOfScreen(Screen *screen)
94 XWhitePixelOfScreen(Screen *screen)
100 static void draw_rect(Display *, Drawable, GC,
101 int x, int y, unsigned int width,
102 unsigned int height, BOOL foreground_p, BOOL fill_p);
105 XParseColor(Display * dpy, Colormap cmap, const char *spec, XColor * ret)
107 unsigned char r = 0, g = 0, b = 0;
108 if (*spec == '#' && strlen(spec) == 7) {
109 static unsigned const char hex[] = { // yeah yeah, shoot me.
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4,
113 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
114 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
127 r = (hex[spec[1]] << 4) | hex[spec[2]];
128 g = (hex[spec[3]] << 4) | hex[spec[4]];
129 b = (hex[spec[5]] << 4) | hex[spec[6]];
130 } else if (!strcasecmp(spec, "black")) {
132 } else if (!strcasecmp(spec, "white")) {
134 } else if (!strcasecmp(spec, "red")) {
136 } else if (!strcasecmp(spec, "green")) {
138 } else if (!strcasecmp(spec, "blue")) {
140 } else if (!strcasecmp(spec, "cyan")) {
142 } else if (!strcasecmp(spec, "magenta")) {
144 } else if (!strcasecmp(spec, "yellow")) {
150 ret->red = (r << 8) | r;
151 ret->green = (g << 8) | g;
152 ret->blue = (b << 8) | b;
153 ret->flags = DoRed | DoGreen | DoBlue;
157 Status XAllocColor(Display * dpy, Colormap cmap, XColor * color)
159 // store 32 bit ARGB in the pixel field.
160 // (The uint32_t is so that 0xFF000000 doesn't become 0xFFFFFFFFFF000000)
161 color->pixel = (uint32_t)
163 (((color->red >> 8) & 0xFF) << 16) |
164 (((color->green >> 8) & 0xFF) << 8) |
165 (((color->blue >> 8) & 0xFF)));
169 // needs to be implemented in Android...
171 XFillRectangle(Display * dpy, Drawable d, GC gc, int x, int y,
172 unsigned int width, unsigned int height)
177 // needs to be implemented in Android...
179 XDrawString(Display * dpy, Drawable d, GC gc, int x, int y,
180 const char *str, int len)
182 return 0; // try this for now...
186 // needs to be implemented in Android...
187 int XFreeGC(Display * dpy, GC gc)
194 int XFreeFont(Display * dpy, XFontStruct * f)
199 int XFreeFontInfo(char **names, XFontStruct * info, int n)
203 for (i = 0; i < n; i++)
209 for (i = 0; i < n; i++)
210 if (info[i].per_char)
211 free(info[i].per_char);
218 // needs to be implemented in Android...
219 int XUnloadFont(Display * dpy, Font fid)
225 // needs to be implemented in Android...
227 XCreateGC(Display * dpy, Drawable d, unsigned long mask, XGCValues * xgcv)
232 // needs to be implemented in Android...
233 XFontStruct *XLoadQueryFont(Display * dpy, const char *name)
239 XGetWindowAttributes(Display * dpy, Window w, XWindowAttributes * xgwa)
242 // Assert (w && w->type == WINDOW, "not a window");
244 memset(xgwa, 0, sizeof(*xgwa));
245 xgwa->x = w->frame.origin.x;
246 xgwa->y = w->frame.origin.y;
247 xgwa->width = w->frame.size.width;
248 xgwa->height = w->frame.size.height;
250 xgwa->screen = dpy->screen;
251 xgwa->visual = dpy->screen->visual;
256 // needs to be implemented in Android...
257 int XSetFont(Display * dpy, GC gc, Font fid)
263 // needs to be implemented in Android...
264 int XClearWindow(Display * dpy, Window win)
268 // declared in utils/visual.h
269 int has_writable_cells(Screen * s, Visual * v)
275 XAllocColorCells(Display * dpy, Colormap cmap, Bool contig,
276 unsigned long *pmret, unsigned int npl,
277 unsigned long *pxret, unsigned int npx)
282 int XStoreColors(Display * dpy, Colormap cmap, XColor * colors, int n)
284 //Assert(0, "XStoreColors called");
289 XFreeColors(Display * dpy, Colormap cmap, unsigned long *px, int npixels,
290 unsigned long planes)
295 int XFlush(Display * dpy)
300 Display *XDisplayOfScreen(Screen * s)
305 // needs to be implemented in Android...
307 XLookupString(XKeyEvent * e, char *buf, int size, KeySym * k_ret,
313 int XScreenNumberOfScreen(Screen * s)
315 return s->screen_number;
318 int jwxyz_ScreenCount(Display * dpy)
320 return dpy->screen_count;
325 // should this be defined?
326 static Display *jwxyz_live_displays[20] = { 0, };
329 Display * jwxyz_make_display (void *nsview_arg, void *cgc_arg)
331 Display *d = (Display *) calloc(1, sizeof(*d));
332 d->screen = (Screen *) calloc(1, sizeof(Screen));
336 d->screen->screen_number = 0;
337 d->screen->black = 0xFF000000;
338 d->screen->white = 0xFFFFFFFF;
340 Visual *v = (Visual *) calloc(1, sizeof(Visual));
341 v->class = TrueColor;
342 v->red_mask = 0x00FF0000;
343 v->green_mask = 0x0000FF00;
344 v->blue_mask = 0x000000FF;
346 d->screen->visual = v;
348 Window w = (Window) calloc(1, sizeof(*w));
350 w->window.background = BlackPixelOfScreen(d->screen);
358 jwxyz_free_display (Display *dpy)
360 free (dpy->screen->visual);
362 free (dpy->main_window);
367 /* Call this when the Renderer calls onSurfaceChanged
370 jwxyz_window_resized (Display *dpy, Window w,
371 int new_x, int new_y, int new_width, int new_height,
374 w->frame.origin.x = new_x;
375 w->frame.origin.y = new_y;
376 w->frame.size.width = new_width;
377 w->frame.size.height = new_height;
380 Window XRootWindow(Display * dpy, int screen)
382 return dpy->main_window;
385 /* Handle an abort on Android
386 TODO: Test that Android handles aborts properly
389 jwxyz_abort (const char *fmt, ...)
397 va_start (args, fmt);
398 vsprintf (s, fmt, args);
401 /* Send error to Android device log */
402 __android_log_write(ANDROID_LOG_ERROR, "xscreensaver", s);
408 XCreatePixmap (Display *dpy, Drawable d,
409 unsigned int width, unsigned int height, unsigned int depth)
414 XDestroyImage (XImage *ximage)
416 if (ximage->data) free (ximage->data);
422 XDrawString16 (Display *dpy, Drawable d, GC gc, int x, int y,
423 const XChar2b *str, int len)
428 XFreePixmap (Display *d, Pixmap p)
433 XGetImage (Display *dpy, Drawable d, int x, int y,
434 unsigned int width, unsigned int height,
435 unsigned long plane_mask, int format)
440 XGetPixel (XImage *ximage, int x, int y)
445 XSetForeground (Display *dpy, GC gc, unsigned long fg)
450 XTextExtents16 (XFontStruct *f, const XChar2b *s, int length,
451 int *dir_ret, int *ascent_ret, int *descent_ret,
457 XPutPixel (XImage *ximage, int x, int y, unsigned long pixel)
462 XCreateImage (Display *dpy, Visual *visual, unsigned int depth,
463 int format, int offset, char *data,
464 unsigned int width, unsigned int height,
465 int bitmap_pad, int bytes_per_line)