History

Merging echoline's android and fbdev forks

Lorenzo Bivens committed 5 years ago

Commit 96209041 parent a130d4427 files · +2398 −0Browse files

Showing the changes to gui-android/cpp/native-lib.c (1 of 27 files). Show all

Unified · Split

gui-android/cpp/native-lib.c+173−0
@@ -0,0 +1,173 @@
1+#include <jni.h>
2+#include <android/native_window.h>
3+#include <android/native_window_jni.h>
4+#include <android/log.h>
5+#include "u.h"
6+#include "lib.h"
7+#include "dat.h"
8+#include "fns.h"
9+#include "error.h"
10+#include <draw.h>
11+#include <string.h>
12+#include <keyboard.h>
13+
14+void absmousetrack(int, int, int, ulong);
15+ulong ticks(void);
16+int dt_main(int, char**);
17+int screenWidth;
18+int screenHeight;
19+Point mousept = {0, 0};
20+int buttons = 0;
21+float ws = 1;
22+float hs = 1;
23+extern char *snarfbuf;
24+int mPaused = 0;
25+ANativeWindow *window = NULL;
26+jobject mainActivityObj;
27+JavaVM *jvm;
28+void flushmemscreen(Rectangle r);
29+extern uchar *cambuf;
30+extern int camlen;
31+
32+JNIEXPORT void JNICALL
33+Java_org_echoline_drawterm_MainActivity_setObject(
34+ JNIEnv *env,
35+ jobject obj) {
36+ mainActivityObj = (*env)->NewGlobalRef(env, obj);
37+ jint rs = (*env)->GetJavaVM(env, &jvm);
38+ assert(rs == JNI_OK);
39+}
40+
41+JNIEXPORT void JNICALL
42+Java_org_echoline_drawterm_MainActivity_keyDown(
43+ JNIEnv *env,
44+ jobject obj,
45+ jint c) {
46+ kbdkey(c, 1);
47+}
48+
49+JNIEXPORT void JNICALL
50+Java_org_echoline_drawterm_MainActivity_keyUp(
51+ JNIEnv *env,
52+ jobject obj,
53+ jint c) {
54+ kbdkey(c, 0);
55+}
56+
57+JNIEXPORT void JNICALL
58+Java_org_echoline_drawterm_MainActivity_setPass(
59+ JNIEnv *env,
60+ jobject obj,
61+ jstring str) {
62+ setenv("PASS", (char*)(*env)->GetStringUTFChars(env, str, 0), 1);
63+}
64+
65+JNIEXPORT void JNICALL
66+Java_org_echoline_drawterm_MainActivity_setWidth(
67+ JNIEnv *env,
68+ jobject obj,
69+ jint width) {
70+ screenWidth = width;
71+}
72+
73+JNIEXPORT void JNICALL
74+Java_org_echoline_drawterm_MainActivity_setHeight(
75+ JNIEnv *env,
76+ jobject obj,
77+ jint height) {
78+ screenHeight = height;
79+}
80+
81+JNIEXPORT void JNICALL
82+Java_org_echoline_drawterm_MainActivity_setWidthScale(
83+ JNIEnv *env,
84+ jobject obj,
85+ jfloat s) {
86+ ws = s;
87+}
88+
89+JNIEXPORT void JNICALL
90+Java_org_echoline_drawterm_MainActivity_setHeightScale(
91+ JNIEnv *env,
92+ jobject obj,
93+ jfloat s) {
94+ hs = s;
95+}
96+
97+JNIEXPORT jint JNICALL
98+Java_org_echoline_drawterm_MainActivity_dtmain(
99+ JNIEnv *env,
100+ jobject obj,
101+ jobjectArray argv) {
102+ int i, ret;
103+ char **args = (char **) malloc(((*env)->GetArrayLength(env, argv)+1) * sizeof(char *));
104+
105+ for (i = 0; i < (*env)->GetArrayLength(env, argv); i++) {
106+ jobject str = (jobject) (*env)->GetObjectArrayElement(env, argv, i);
107+ args[i] = strdup((char*)(*env)->GetStringUTFChars(env, (jstring)str, 0));
108+ }
109+ args[(*env)->GetArrayLength(env, argv)] = NULL;
110+
111+ ret = dt_main(i, args);
112+
113+ for (i = 0; args[i] != NULL; i++) {
114+ free(args[i]);
115+ }
116+ free(args);
117+
118+ return ret;
119+}
120+
121+JNIEXPORT void JNICALL
122+Java_org_echoline_drawterm_MainActivity_setMouse(
123+ JNIEnv *env,
124+ jobject obj,
125+ jintArray args) {
126+ jboolean isCopy;
127+ jint *data;
128+ if ((*env)->GetArrayLength(env, args) < 3)
129+ return;
130+ data = (*env)->GetIntArrayElements(env, args, &isCopy);
131+ mousept.x = (int)(data[0] / ws);
132+ mousept.y = (int)(data[1] / hs);
133+ buttons = data[2];
134+ (*env)->ReleaseIntArrayElements(env, args, data, 0);
135+ absmousetrack(mousept.x, mousept.y, buttons, ticks());
136+}
137+
138+JNIEXPORT void JNICALL
139+Java_org_echoline_drawterm_MainActivity_setDTSurface(
140+ JNIEnv* jenv,
141+ jobject obj,
142+ jobject surface) {
143+ if (surface != NULL) {
144+ window = ANativeWindow_fromSurface(jenv, surface);
145+ ANativeWindow_setBuffersGeometry(window, screenWidth, screenHeight,
146+ AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM);
147+ flushmemscreen(Rect(0, 0, screenWidth, screenHeight));
148+ } else if (window != NULL) {
149+ ANativeWindow_release(window);
150+ window = NULL;
151+ }
152+}
153+
154+JNIEXPORT void JNICALL
155+Java_org_echoline_drawterm_MainActivity_exitDT(
156+ JNIEnv* jenv,
157+ jobject obj) {
158+ exit(0);
159+}
160+
161+JNIEXPORT void JNICALL
162+Java_org_echoline_drawterm_MainActivity_sendPicture(
163+ JNIEnv* env,
164+ jobject obj,
165+ jbyteArray array) {
166+ jint len = (*env)->GetArrayLength(env, array);
167+ jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL);
168+ camlen = len;
169+ cambuf = malloc(camlen);
170+ memcpy(cambuf, bytes, camlen);
171+ (*env)->ReleaseByteArrayElements(env, array, bytes, 0);
172+}
173+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t