From http://www.jwz.org/xscreensaver/xscreensaver-5.36.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   struct event_queue *event_queue;
45 };
46
47 struct jwxyz_Drawable {
48   enum { WINDOW, PIXMAP } type;
49   XRectangle frame;
50   EGLSurface egl_surface;
51   union {
52     struct {
53       struct running_hack *rh;
54       int last_mouse_x, last_mouse_y;
55     } window;
56     struct {
57       int depth;
58     } pixmap;
59   };
60 };
61
62
63 extern void prepare_context (struct running_hack *rh);
64
65
66 // Methods of the Java class org.jwz.jwxyz that are implemented in C.
67
68 JNIEXPORT void JNICALL
69 Java_org_jwz_xscreensaver_jwxyz_nativeInit (JNIEnv *, jobject thiz,
70                                             jstring jhack, jint api,
71                                             jobject defaults,
72                                             jint w, jint h);
73
74 JNIEXPORT void JNICALL
75 Java_org_jwz_xscreensaver_jwxyz_nativeResize (JNIEnv *, jobject thiz,
76                                               jint w, jint h, jdouble rot);
77
78 JNIEXPORT jlong JNICALL
79 Java_org_jwz_xscreensaver_jwxyz_nativeRender (JNIEnv *, jobject thiz);
80
81 JNIEXPORT void JNICALL
82 Java_org_jwz_xscreensaver_jwxyz_nativeDone (JNIEnv *, jobject thiz);
83
84 JNIEXPORT void JNICALL
85 Java_org_jwz_xscreensaver_jwxyz_allnativeSettings (JNIEnv *, jobject thiz,
86                                                    jstring jhack,
87                                                    jstring hackPref,
88                                                    jint draw, jstring key);
89
90 JNIEXPORT jboolean JNICALL
91 Java_org_jwz_xscreensaver_jwxyz_ignoreRotation (JNIEnv *, jobject thiz);
92
93 JNIEXPORT jboolean JNICALL
94 Java_org_jwz_xscreensaver_jwxyz_suppressRotationAnimation (JNIEnv *,
95                                                            jobject thiz);
96
97 JNIEXPORT void JNICALL
98 Java_org_jwz_xscreensaver_jwxyz_sendButtonEvent (JNIEnv *, jobject thiz,
99                                                  int x, int y, jboolean down);
100
101 JNIEXPORT void JNICALL
102 Java_org_jwz_xscreensaver_jwxyz_sendMotionEvent (JNIEnv *, jobject thiz,
103                                                  int x, int y);
104
105 JNIEXPORT void JNICALL
106 Java_org_jwz_xscreensaver_jwxyz_sendKeyEvent (JNIEnv *, jobject thiz,
107                                               jboolean down_p,
108                                               int code, int mods);
109
110 #endif // __JWXYZ_ANDROID_H__