From http://www.jwz.org/xscreensaver/xscreensaver-5.37.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 /* Native EGL is Android 2.3/API 9. EGL in Java is available from API 1. */
20 #include <EGL/egl.h>
21 #include <GLES/glext.h>
22 #include <jni.h>
23
24 /* Keep synchronized with check-configs.pl and jwxyz.java. */
25 #define API_XLIB 0
26 #define API_GL   1
27
28 struct jwxyz_Drawable {
29   enum { WINDOW, PIXMAP } type;
30   XRectangle frame;
31   union {
32     EGLSurface egl_surface;
33     GLuint texture; /* If this is 0, it's the default framebuffer. */
34   };
35   union {
36     struct {
37       struct running_hack *rh;
38       int last_mouse_x, last_mouse_y;
39     } window;
40     struct {
41       int depth;
42     } pixmap;
43   };
44 };
45
46 struct running_hack {
47   struct xscreensaver_function_table *xsft;
48   jint api;
49   Display *dpy;
50   Window window;
51   fps_state *fpst;
52   void *closure;
53   JNIEnv *jni_env;
54   jobject jobject;
55
56   /* These are set up in Java by the GLSurfaceView. */
57   EGLContext egl_ctx;
58   EGLSurface egl_surface;
59   EGLDisplay egl_display;
60   GLint fb_default;
61
62   EGLConfig egl_config;
63
64   PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOES;
65   PFNGLFRAMEBUFFERTEXTURE2DOESPROC glFramebufferTexture2DOES;
66
67   struct jwxyz_Drawable frontbuffer;
68   GC copy_gc;
69   Bool gl_fbo_p, frontbuffer_p;
70   GLuint fb_pixmap;
71
72   Drawable current_drawable;
73   Bool ignore_rotation_p;
74
75   jwzgles_state *gles_state;
76
77   unsigned long frame_count;
78   Bool initted_p;
79   struct event_queue *event_queue;
80 };
81
82
83 extern void prepare_context (struct running_hack *rh);
84
85
86 // Methods of the Java class org.jwz.jwxyz that are implemented in C.
87
88 JNIEXPORT void JNICALL
89 Java_org_jwz_xscreensaver_jwxyz_nativeInit (JNIEnv *, jobject thiz,
90                                             jstring jhack,
91                                             jobject defaults,
92                                             jint w, jint h);
93
94 JNIEXPORT void JNICALL
95 Java_org_jwz_xscreensaver_jwxyz_nativeResize (JNIEnv *, jobject thiz,
96                                               jint w, jint h, jdouble rot);
97
98 JNIEXPORT jlong JNICALL
99 Java_org_jwz_xscreensaver_jwxyz_nativeRender (JNIEnv *, jobject thiz);
100
101 JNIEXPORT void JNICALL
102 Java_org_jwz_xscreensaver_jwxyz_nativeDone (JNIEnv *, jobject thiz);
103
104 JNIEXPORT void JNICALL
105 Java_org_jwz_xscreensaver_jwxyz_allnativeSettings (JNIEnv *, jobject thiz,
106                                                    jstring jhack,
107                                                    jstring hackPref,
108                                                    jint draw, jstring key);
109
110 JNIEXPORT jboolean JNICALL
111 Java_org_jwz_xscreensaver_jwxyz_ignoreRotation (JNIEnv *, jobject thiz);
112
113 JNIEXPORT jboolean JNICALL
114 Java_org_jwz_xscreensaver_jwxyz_suppressRotationAnimation (JNIEnv *,
115                                                            jobject thiz);
116
117 JNIEXPORT void JNICALL
118 Java_org_jwz_xscreensaver_jwxyz_sendButtonEvent (JNIEnv *, jobject thiz,
119                                                  int x, int y, jboolean down);
120
121 JNIEXPORT void JNICALL
122 Java_org_jwz_xscreensaver_jwxyz_sendMotionEvent (JNIEnv *, jobject thiz,
123                                                  int x, int y);
124
125 JNIEXPORT void JNICALL
126 Java_org_jwz_xscreensaver_jwxyz_sendKeyEvent (JNIEnv *, jobject thiz,
127                                               jboolean down_p,
128                                               int code, int mods);
129
130 #endif // __JWXYZ_ANDROID_H__