From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / jwxyz / jwxyz-android.h
1 /* xscreensaver, Copyright (c) 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_ANDROID_H__
13 #define __JWXYZ_ANDROID_H__
14
15 #include "jwxyz.h"
16 #include "../hacks/fps.h"
17
18 #include <android/log.h>
19 #include <EGL/egl.h>
20 #include <jni.h>
21
22 /* Keep synchronized with check-configs.pl and jwxyz.java. */
23 #define API_XLIB 0
24 #define API_GL   1
25
26 struct running_hack {
27   struct xscreensaver_function_table *xsft;
28   jint api;
29   Display *dpy;
30   Window window;
31   fps_state *fpst;
32   void *closure;
33   JNIEnv *jni_env;
34   jobject jobject;
35
36   EGLDisplay egl_display;
37   EGLConfig egl_config;
38   EGLContext egl_window_ctx, egl_xlib_ctx;
39   Drawable current_drawable;
40   Bool ignore_rotation_p;
41
42   unsigned long frame_count;
43   Bool initted_p;
44   double next_frame_time;  // time_t in milliseconds of when to tick the frame
45   struct event_queue *event_queue;
46 };
47
48 struct jwxyz_Drawable {
49   enum { WINDOW, PIXMAP } type;
50   XRectangle frame;
51   EGLSurface egl_surface;
52   union {
53     struct {
54       struct running_hack *rh;
55       int last_mouse_x, last_mouse_y;
56     } window;
57     struct {
58       int depth;
59     } pixmap;
60   };
61 };
62
63 extern void do_logv(int prio, const char *fmt, va_list args);
64
65 extern void Log(const char *format, ...); // TODO: GCC can verify printf strings.
66 #define Logv(format, args) (do_logv(ANDROID_LOG_INFO, format, args))
67
68 extern void prepare_context (struct running_hack *rh);
69
70
71 // Methods of the Java class org.jwz.jwxyz that are implemented in C.
72
73 JNIEXPORT void JNICALL
74 Java_org_jwz_xscreensaver_jwxyz_nativeInit (JNIEnv *, jobject thiz,
75                                             jstring jhack, jint api,
76                                             jobject defaults,
77                                             jint w, jint h);
78
79 JNIEXPORT void JNICALL
80 Java_org_jwz_xscreensaver_jwxyz_nativeResize (JNIEnv *, jobject thiz,
81                                               jint w, jint h, jdouble rot);
82
83 JNIEXPORT void JNICALL
84 Java_org_jwz_xscreensaver_jwxyz_nativeRender (JNIEnv *, jobject thiz);
85
86 JNIEXPORT void JNICALL
87 Java_org_jwz_xscreensaver_jwxyz_nativeDone (JNIEnv *, jobject thiz);
88
89 JNIEXPORT void JNICALL
90 Java_org_jwz_xscreensaver_jwxyz_allnativeSettings (JNIEnv *, jobject thiz,
91                                                    jstring jhack,
92                                                    jstring hackPref,
93                                                    jint draw, jstring key);
94
95 JNIEXPORT jboolean JNICALL
96 Java_org_jwz_xscreensaver_jwxyz_ignoreRotation (JNIEnv *, jobject thiz);
97
98 JNIEXPORT jboolean JNICALL
99 Java_org_jwz_xscreensaver_jwxyz_suppressRotationAnimation (JNIEnv *,
100                                                            jobject thiz);
101
102 JNIEXPORT void JNICALL
103 Java_org_jwz_xscreensaver_jwxyz_sendButtonEvent (JNIEnv *, jobject thiz,
104                                                  int x, int y, jboolean down);
105
106 JNIEXPORT void JNICALL
107 Java_org_jwz_xscreensaver_jwxyz_sendMotionEvent (JNIEnv *, jobject thiz,
108                                                  int x, int y);
109
110 JNIEXPORT void JNICALL
111 Java_org_jwz_xscreensaver_jwxyz_sendKeyEvent (JNIEnv *, jobject thiz,
112                                               jboolean down_p,
113                                               int code, int mods);
114
115 #endif // __JWXYZ_ANDROID_H__