1 /* xscreensaver, Copyright (c) 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
11 * Utility functions related to the hacks/ APIs.
18 #include <sys/utsname.h>
19 #include <android/log.h>
20 #include "screenhackI.h"
21 #include "xlockmoreI.h"
22 #include "textclient.h"
24 #if defined(USE_IPHONE) || (HAVE_ANDROID)
27 # include <OpenGL/OpenGL.h>
31 # define isupper(c) ((c) >= 'A' && (c) <= 'Z')
34 # define _tolower(c) ((c) - 'A' + 'a')
38 get_boolean_resource (Display *dpy, char *res_name, char *res_class)
41 char *s = get_string_resource (dpy, res_name, res_class);
44 for (tmp = buf; *s; s++)
45 *tmp++ = isupper (*s) ? _tolower (*s) : *s;
50 (buf[strlen(buf)-1] == ' ' ||
51 buf[strlen(buf)-1] == '\t'))
52 buf[strlen(buf)-1] = 0;
54 if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes"))
56 if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no"))
58 fprintf (stderr, "%s: %s must be boolean, not %s.\n",
59 progname, res_name, buf);
64 get_integer_resource (Display *dpy, char *res_name, char *res_class)
67 char c, *s = get_string_resource (dpy, res_name, res_class);
71 while (*ss && *ss <= ' ') ss++; /* skip whitespace */
73 if (ss[0] == '0' && (ss[1] == 'x' || ss[1] == 'X')) /* 0x: parse as hex */
75 if (1 == sscanf (ss+2, "%x %c", (unsigned int *) &val, &c))
81 else /* else parse as dec */
83 /* Allow integer values to end in ".0". */
85 if (L > 2 && ss[L-2] == '.' && ss[L-1] == '0')
88 if (1 == sscanf (ss, "%d %c", &val, &c))
95 fprintf (stderr, "%s: %s must be an integer, not %s.\n",
96 progname, res_name, s);
102 get_float_resource (Display *dpy, char *res_name, char *res_class)
105 char c, *s = get_string_resource (dpy, res_name, res_class);
107 if (1 == sscanf (s, " %lf %c", &val, &c))
112 fprintf (stderr, "%s: %s must be a float, not %s.\n",
113 progname, res_name, s);
120 textclient_mobile_date_string (void)
123 if (uname (&uts) < 0)
124 return strdup("uname() failed");
127 time_t now = time ((time_t *) 0);
128 char *ts = ctime (&now);
130 if ((s = strchr(uts.nodename, '.')))
132 buf = (char *) malloc(strlen(uts.machine) +
133 strlen(uts.sysname) +
134 strlen(uts.release) +
136 sprintf (buf, "%s %s %s\n%s", uts.machine, uts.sysname, uts.release, ts);
142 /* used by the OpenGL screen savers
145 /* Does nothing - prepareContext already did the work.
148 glXMakeCurrent (Display *dpy, Window window, GLXContext context)
153 /* clear away any lingering error codes */
155 clear_gl_error (void)
157 while (glGetError() != GL_NO_ERROR)
162 // needs to be implemented in Android...
163 /* Copy the back buffer to the front buffer.
166 glXSwapBuffers (Display *dpy, Window window)
171 /* Called by OpenGL savers using the XLockmore API.
174 init_GL (ModeInfo *mi)
176 // Window win = mi->window;
178 // Caller expects a pointer to an opaque struct... which it dereferences.
179 // Don't ask me, it's historical...
180 static int blort = -1;
181 return (void *) &blort;
184 /* report a GL error. */
186 check_gl_error (const char *type)
191 switch ((i = glGetError())) {
192 case GL_NO_ERROR: return;
193 case GL_INVALID_ENUM: e = "invalid enum"; break;
194 case GL_INVALID_VALUE: e = "invalid value"; break;
195 case GL_INVALID_OPERATION: e = "invalid operation"; break;
196 case GL_STACK_OVERFLOW: e = "stack overflow"; break;
197 case GL_STACK_UNDERFLOW: e = "stack underflow"; break;
198 case GL_OUT_OF_MEMORY: e = "out of memory"; break;
199 #ifdef GL_TABLE_TOO_LARGE_EXT
200 case GL_TABLE_TOO_LARGE_EXT: e = "table too large"; break;
202 #ifdef GL_TEXTURE_TOO_LARGE_EXT
203 case GL_TEXTURE_TOO_LARGE_EXT: e = "texture too large"; break;
206 e = buf; sprintf (buf, "unknown GL error %d", (int) i); break;
208 __android_log_write(ANDROID_LOG_ERROR, "xscreensaver", e);