From http://www.jwz.org/xscreensaver/xscreensaver-5.38.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     /* JWXYZ_GL */
33     EGLSurface egl_surface;
34     GLuint texture; /* If this is 0, it's the default framebuffer. */
35
36     /* JWXYZ_IMAGE */
37     void *image_data;
38   };
39   union {
40     struct {
41       struct running_hack *rh;
42       int last_mouse_x, last_mouse_y;
43     } window;
44     struct {
45       int depth;
46     } pixmap;
47   };
48 };
49
50 struct running_hack {
51   struct xscreensaver_function_table *xsft;
52   jint api;
53   Display *dpy;
54   Window window;
55   fps_state *fpst;
56   void *closure;
57   JNIEnv *jni_env;
58   jobject jobject;
59
60   Bool jwxyz_gl_p;
61
62   /* JWXYZ_GL */
63   EGLContext egl_ctx;
64   EGLSurface egl_surface;
65   EGLDisplay egl_display;
66   GLint fb_default;
67
68   EGLConfig egl_config;
69
70   PFNGLBINDFRAMEBUFFEROESPROC glBindFramebufferOES;
71   PFNGLFRAMEBUFFERTEXTURE2DOESPROC glFramebufferTexture2DOES;
72
73   struct jwxyz_Drawable frontbuffer;
74   GC copy_gc;
75   Bool gl_fbo_p, frontbuffer_p;
76   GLuint fb_pixmap;
77
78   Drawable current_drawable;
79
80   /* JWXYZ_IMAGE */
81   ANativeWindow *native_window;
82
83   Bool ignore_rotation_p;
84
85   jwzgles_state *gles_state;
86
87   unsigned long frame_count;
88   Bool initted_p;
89   struct event_queue *event_queue;
90 };
91
92
93 // Methods of the Java class org.jwz.jwxyz that are implemented in C.
94
95 JNIEXPORT void JNICALL
96 Java_org_jwz_xscreensaver_jwxyz_nativeInit (JNIEnv *, jobject thiz,
97                                             jstring jhack,
98                                             jobject defaults,
99                                             jint w, jint h,
100                                             jobject jni_surface);
101
102 JNIEXPORT void JNICALL
103 Java_org_jwz_xscreensaver_jwxyz_nativeResize (JNIEnv *, jobject thiz,
104                                               jint w, jint h, jdouble rot);
105
106 JNIEXPORT jlong JNICALL
107 Java_org_jwz_xscreensaver_jwxyz_nativeRender (JNIEnv *, jobject thiz);
108
109 JNIEXPORT void JNICALL
110 Java_org_jwz_xscreensaver_jwxyz_nativeDone (JNIEnv *, jobject thiz);
111
112 JNIEXPORT void JNICALL
113 Java_org_jwz_xscreensaver_jwxyz_sendButtonEvent (JNIEnv *, jobject thiz,
114                                                  int x, int y, jboolean down);
115
116 JNIEXPORT void JNICALL
117 Java_org_jwz_xscreensaver_jwxyz_sendMotionEvent (JNIEnv *, jobject thiz,
118                                                  int x, int y);
119
120 JNIEXPORT void JNICALL
121 Java_org_jwz_xscreensaver_jwxyz_sendKeyEvent (JNIEnv *, jobject thiz,
122                                               jboolean down_p,
123                                               int code, int mods);
124
125 #endif // __JWXYZ_ANDROID_H__