You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
misc cleanup, address some warnings
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* parts of this file originally from AOSP:
|
||||||
* Copyright (C) 2010 The Android Open Source Project
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -40,13 +41,13 @@
|
|||||||
//#include "android_view_KeyEvent.h"
|
//#include "android_view_KeyEvent.h"
|
||||||
|
|
||||||
|
|
||||||
static struct {
|
/*static struct {
|
||||||
jmethodID finish;
|
jmethodID finish;
|
||||||
jmethodID setWindowFlags;
|
jmethodID setWindowFlags;
|
||||||
jmethodID setWindowFormat;
|
jmethodID setWindowFormat;
|
||||||
jmethodID showIme;
|
jmethodID showIme;
|
||||||
jmethodID hideIme;
|
jmethodID hideIme;
|
||||||
} gNativeActivityClassInfo;
|
} gNativeActivityClassInfo;*/
|
||||||
|
|
||||||
typedef void ANativeActivity_createFunc(ANativeActivity* activity, void* savedState, size_t savedStateSize);
|
typedef void ANativeActivity_createFunc(ANativeActivity* activity, void* savedState, size_t savedStateSize);
|
||||||
|
|
||||||
@@ -66,8 +67,9 @@ enum {
|
|||||||
CMD_HIDE_SOFT_INPUT,
|
CMD_HIDE_SOFT_INPUT,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void write_work(int fd, int32_t cmd, int32_t arg1, int32_t arg2) {
|
/*static void write_work(int fd, int32_t cmd, int32_t arg1, int32_t arg2)
|
||||||
/* struct ActivityWork work;
|
{
|
||||||
|
struct ActivityWork work;
|
||||||
work.cmd = cmd;
|
work.cmd = cmd;
|
||||||
work.arg1 = arg1;
|
work.arg1 = arg1;
|
||||||
work.arg2 = arg2;
|
work.arg2 = arg2;
|
||||||
@@ -83,18 +85,19 @@ restart:
|
|||||||
if (res == sizeof(work)) return;
|
if (res == sizeof(work)) return;
|
||||||
|
|
||||||
if (res < 0) printf("Failed writing to work fd: %s", strerror(errno));
|
if (res < 0) printf("Failed writing to work fd: %s", strerror(errno));
|
||||||
else printf("Truncated writing to work fd: %d", res);*/
|
else printf("Truncated writing to work fd: %d", res);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
static bool read_work(int fd, struct ActivityWork* outWork) {
|
/*static bool read_work(int fd, struct ActivityWork* outWork)
|
||||||
/* int res = read(fd, outWork, sizeof(struct ActivityWork));
|
{
|
||||||
|
int res = read(fd, outWork, sizeof(struct ActivityWork));
|
||||||
// no need to worry about EINTR, poll loop will just come back again.
|
// no need to worry about EINTR, poll loop will just come back again.
|
||||||
if (res == sizeof(struct ActivityWork)) return true;
|
if (res == sizeof(struct ActivityWork)) return true;
|
||||||
|
|
||||||
if (res < 0) printf("Failed reading work fd: %s", strerror(errno));
|
if (res < 0) printf("Failed reading work fd: %s", strerror(errno));
|
||||||
else printf("Truncated reading work fd: %d", res);
|
else printf("Truncated reading work fd: %d", res);
|
||||||
*/ return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Native state for interacting with the NativeActivity class.
|
* Native state for interacting with the NativeActivity class.
|
||||||
@@ -118,26 +121,29 @@ struct NativeCode {
|
|||||||
int32_t lastWindowHeight;
|
int32_t lastWindowHeight;
|
||||||
|
|
||||||
// These are used to wake up the main thread to process work.
|
// These are used to wake up the main thread to process work.
|
||||||
int mainWorkRead;
|
// int mainWorkRead;
|
||||||
int mainWorkWrite;
|
// int mainWorkWrite;
|
||||||
// MessageQueue *messageQueue;
|
// MessageQueue *messageQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NativeCode * NativeCode_new(void* _dlhandle, ANativeActivity_createFunc* _createFunc) {
|
struct NativeCode * NativeCode_new(void* _dlhandle, ANativeActivity_createFunc* _createFunc)
|
||||||
|
{
|
||||||
struct NativeCode *this = malloc(sizeof(struct NativeCode));
|
struct NativeCode *this = malloc(sizeof(struct NativeCode));
|
||||||
memset(&this->callbacks, 0, sizeof(this->callbacks));
|
memset(&this->callbacks, 0, sizeof(this->callbacks));
|
||||||
this->dlhandle = _dlhandle;
|
this->dlhandle = _dlhandle;
|
||||||
this->createActivityFunc = _createFunc;
|
this->createActivityFunc = _createFunc;
|
||||||
this->nativeWindow = NULL;
|
this->nativeWindow = NULL;
|
||||||
this->mainWorkRead = this->mainWorkWrite = -1;
|
// this->mainWorkRead = this->mainWorkWrite = -1;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this is currently in libandroid.so, which is not necessarily requested by the app and therefore loaded
|
// FIXME: this is currently in libandroid.so, which is not necessarily requested by the app and therefore loaded
|
||||||
ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
|
ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
|
||||||
|
void ANativeWindow_release(ANativeWindow *native_window);
|
||||||
|
|
||||||
void NativeCode_setSurface(struct NativeCode *this, jobject _surface) {
|
void NativeCode_setSurface(struct NativeCode *this, jobject _surface)
|
||||||
|
{
|
||||||
if (_surface != NULL) {
|
if (_surface != NULL) {
|
||||||
this->nativeWindow = ANativeWindow_fromSurface(this->native_activity.env, _surface);
|
this->nativeWindow = ANativeWindow_fromSurface(this->native_activity.env, _surface);
|
||||||
} else {
|
} else {
|
||||||
@@ -148,7 +154,8 @@ void NativeCode_setSurface(struct NativeCode *this, jobject _surface) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeCode_destroy(struct NativeCode *this) {
|
void NativeCode_destroy(struct NativeCode *this)
|
||||||
|
{
|
||||||
if (this->callbacks.onDestroy != NULL) {
|
if (this->callbacks.onDestroy != NULL) {
|
||||||
this->callbacks.onDestroy((struct ANativeActivity *)this);
|
this->callbacks.onDestroy((struct ANativeActivity *)this);
|
||||||
}
|
}
|
||||||
@@ -159,8 +166,8 @@ void NativeCode_destroy(struct NativeCode *this) {
|
|||||||
// messageQueue->getLooper()->removeFd(mainWorkRead);
|
// messageQueue->getLooper()->removeFd(mainWorkRead);
|
||||||
// }
|
// }
|
||||||
NativeCode_setSurface(this, NULL);
|
NativeCode_setSurface(this, NULL);
|
||||||
if (this->mainWorkRead >= 0) close(this->mainWorkRead);
|
// if (this->mainWorkRead >= 0) close(this->mainWorkRead);
|
||||||
if (this->mainWorkWrite >= 0) close(this->mainWorkWrite);
|
// if (this->mainWorkWrite >= 0) close(this->mainWorkWrite);
|
||||||
if (this->dlhandle != NULL) {
|
if (this->dlhandle != NULL) {
|
||||||
// for now don't unload... we probably should clean this
|
// for now don't unload... we probably should clean this
|
||||||
// up and only keep one open dlhandle per proc, since there
|
// up and only keep one open dlhandle per proc, since there
|
||||||
@@ -176,22 +183,23 @@ void NativeCode_destroy(struct NativeCode *this) {
|
|||||||
/*
|
/*
|
||||||
* Callback for handling native events on the application's main thread.
|
* Callback for handling native events on the application's main thread.
|
||||||
*/
|
*/
|
||||||
static int mainWorkCallback(int fd, int events, void* data) {
|
/*static int mainWorkCallback(int fd, int events, void* data)
|
||||||
|
{
|
||||||
struct NativeCode* code = (struct NativeCode*)data;
|
struct NativeCode* code = (struct NativeCode*)data;
|
||||||
if ((events & POLLIN) == 0) {
|
if ((events & POLLIN) == 0) {
|
||||||
printf("STUB - mainWorkCallback - returning -1\n");
|
printf("STUB - mainWorkCallback - returning -1\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* struct ActivityWork work;
|
struct ActivityWork work;
|
||||||
if (!read_work(code->mainWorkRead, &work)) {
|
if (!read_work(code->mainWorkRead, &work)) {
|
||||||
return 1;
|
return 1;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
printf("STUB - mainWorkCallback\n");
|
printf("STUB - mainWorkCallback\n");
|
||||||
// printf("mainWorkCallback: cmd=%d", work.cmd);
|
// printf("mainWorkCallback: cmd=%d", work.cmd);
|
||||||
|
|
||||||
/* switch (work.cmd) {
|
switch (work.cmd) {
|
||||||
case CMD_FINISH: {
|
case CMD_FINISH: {
|
||||||
code->(*env)->CallVoidMethod(env, code->clazz, gNativeActivityClassInfo.finish);
|
code->(*env)->CallVoidMethod(env, code->clazz, gNativeActivityClassInfo.finish);
|
||||||
code->messageQueue->raiseAndClearException(code->env, "finish");
|
code->messageQueue->raiseAndClearException(code->env, "finish");
|
||||||
@@ -219,10 +227,10 @@ static int mainWorkCallback(int fd, int events, void* data) {
|
|||||||
default:
|
default:
|
||||||
printf("Unknown work command: %d", work.cmd);
|
printf("Unknown work command: %d", work.cmd);
|
||||||
break;
|
break;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -247,8 +255,7 @@ static void * looper_thread_worker(void *looper)
|
|||||||
printf("!!!!! pollOnce returned\n");
|
printf("!!!!! pollOnce returned\n");
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
jlong
|
jlong Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
|
||||||
Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
|
|
||||||
jobject messageQueue, jstring internalDataDir, jstring obbDir,
|
jobject messageQueue, jstring internalDataDir, jstring obbDir,
|
||||||
jstring externalDataDir, int sdkVersion,
|
jstring externalDataDir, int sdkVersion,
|
||||||
jobject jAssetMgr, jbyteArray savedState)
|
jobject jAssetMgr, jbyteArray savedState)
|
||||||
@@ -285,19 +292,20 @@ Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz, jstri
|
|||||||
NativeCode_destroy(code);
|
NativeCode_destroy(code);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
code->mainWorkRead = msgpipe[0];
|
code->mainWorkRead = msgpipe[0];
|
||||||
code->mainWorkWrite = msgpipe[1];
|
code->mainWorkWrite = msgpipe[1];
|
||||||
int result = fcntl(code->mainWorkRead, F_SETFL, O_NONBLOCK);
|
int result = fcntl(code->mainWorkRead, F_SETFL, O_NONBLOCK);
|
||||||
// SLOGW_IF(result != 0, "Could not make main work read pipe "
|
SLOGW_IF(result != 0, "Could not make main work read pipe "
|
||||||
// "non-blocking: %s", strerror(errno));
|
"non-blocking: %s", strerror(errno));
|
||||||
result = fcntl(code->mainWorkWrite, F_SETFL, O_NONBLOCK);
|
result = fcntl(code->mainWorkWrite, F_SETFL, O_NONBLOCK);
|
||||||
// SLOGW_IF(result != 0, "Could not make main work write pipe "
|
SLOGW_IF(result != 0, "Could not make main work write pipe "
|
||||||
// "non-blocking: %s", strerror(errno));
|
"non-blocking: %s", strerror(errno));
|
||||||
// code->messageQueue->getLooper()->addFd(
|
code->messageQueue->getLooper()->addFd(
|
||||||
// code->mainWorkRead, 0, ALOOPER_EVENT_INPUT, mainWorkCallback, code);
|
code->mainWorkRead, 0, ALOOPER_EVENT_INPUT, mainWorkCallback, code);
|
||||||
|
|
||||||
// new android::Looper()
|
// new android::Looper()
|
||||||
#if 0
|
|
||||||
void *a_looper = malloc(224/*sizeof(android::Looper)*/);
|
void *a_looper = malloc(224/*sizeof(android::Looper)*/);
|
||||||
_ZN7android6LooperC2Eb(a_looper, true); // TODO: or false?
|
_ZN7android6LooperC2Eb(a_looper, true); // TODO: or false?
|
||||||
// android::Looper::addFd
|
// android::Looper::addFd
|
||||||
@@ -314,11 +322,11 @@ Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz, jstri
|
|||||||
code->native_activity.clazz = (*env)->NewGlobalRef(env, clazz);
|
code->native_activity.clazz = (*env)->NewGlobalRef(env, clazz);
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
code->native_activity.internalDataPath = strdup(tmp = (*env)->GetStringUTFChars(env, internalDataDir, NULL));
|
code->native_activity.internalDataPath = strdup(tmp = (char *)((*env)->GetStringUTFChars(env, internalDataDir, NULL)));
|
||||||
(*env)->ReleaseStringUTFChars(env, internalDataDir, tmp);
|
(*env)->ReleaseStringUTFChars(env, internalDataDir, tmp);
|
||||||
|
|
||||||
if (externalDataDir != NULL) {
|
if (externalDataDir != NULL) {
|
||||||
code->native_activity.externalDataPath = strdup(tmp = (*env)->GetStringUTFChars(env, externalDataDir, NULL));
|
code->native_activity.externalDataPath = strdup(tmp = (char *)((*env)->GetStringUTFChars(env, externalDataDir, NULL)));
|
||||||
(*env)->ReleaseStringUTFChars(env, externalDataDir, tmp);
|
(*env)->ReleaseStringUTFChars(env, externalDataDir, tmp);
|
||||||
} else {
|
} else {
|
||||||
code->native_activity.externalDataPath = NULL; // TODO: or ""?
|
code->native_activity.externalDataPath = NULL; // TODO: or ""?
|
||||||
@@ -349,11 +357,10 @@ Java_android_app_NativeActivity_loadNativeCode(JNIEnv* env, jobject clazz, jstri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (jlong)code; // sus, surely this is broken on 64bit?
|
return _INTPTR(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_unloadNativeCode(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_unloadNativeCode(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - unloadNativeCode_native\n");
|
printf("STUB - unloadNativeCode_native\n");
|
||||||
/*if (handle != 0) {
|
/*if (handle != 0) {
|
||||||
@@ -362,31 +369,28 @@ Java_android_app_NativeActivity_unloadNativeCode(JNIEnv* env, jobject clazz, jlo
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onStartNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onStartNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
if (handle != 0) {
|
if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onStart != NULL) {
|
if (code->callbacks.onStart != NULL) {
|
||||||
code->callbacks.onStart(code);
|
code->callbacks.onStart((ANativeActivity *)code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onResumeNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onResumeNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onResume_native\n");
|
printf("STUB - onResume_native\n");
|
||||||
if (handle != 0) {
|
if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onResume != NULL) {
|
if (code->callbacks.onResume != NULL) {
|
||||||
code->callbacks.onResume(code);
|
code->callbacks.onResume((ANativeActivity *)code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jbyteArray
|
jbyteArray Java_android_app_NativeActivity_onSaveInstanceStateNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onSaveInstanceStateNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onSaveInstanceState_native\n");
|
printf("STUB - onSaveInstanceState_native\n");
|
||||||
/*
|
/*
|
||||||
@@ -396,7 +400,7 @@ Java_android_app_NativeActivity_onSaveInstanceStateNative(JNIEnv* env, jobject c
|
|||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onSaveInstanceState != NULL) {
|
if (code->callbacks.onSaveInstanceState != NULL) {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
jbyte* state = (jbyte*)code->callbacks.onSaveInstanceState(code, &len);
|
jbyte* state = (jbyte*)code->callbacks.onSaveInstanceState((ANativeActivity *)code, &len);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
array = (*env)->NewByteArray(env, len);
|
array = (*env)->NewByteArray(env, len);
|
||||||
if (array != NULL) {
|
if (array != NULL) {
|
||||||
@@ -412,81 +416,73 @@ Java_android_app_NativeActivity_onSaveInstanceStateNative(JNIEnv* env, jobject c
|
|||||||
return array;*/return NULL;
|
return array;*/return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onPauseNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onPauseNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onPause_native\n");
|
printf("STUB - onPause_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onPause != NULL) {
|
if (code->callbacks.onPause != NULL) {
|
||||||
code->callbacks.onPause(code);
|
code->callbacks.onPause((ANativeActivity *)code);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onStopNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onStopNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onStop_native\n");
|
printf("STUB - onStop_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onStop != NULL) {
|
if (code->callbacks.onStop != NULL) {
|
||||||
code->callbacks.onStop(code);
|
code->callbacks.onStop((ANativeActivity *)code);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onConfigurationChangedNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onConfigurationChangedNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onConfigurationChanged_native\n");
|
printf("STUB - onConfigurationChanged_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onConfigurationChanged != NULL) {
|
if (code->callbacks.onConfigurationChanged != NULL) {
|
||||||
code->callbacks.onConfigurationChanged(code);
|
code->callbacks.onConfigurationChanged((ANativeActivity *)code);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onLowMemoryNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onLowMemoryNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onLowMemory_native\n");
|
printf("STUB - onLowMemory_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onLowMemory != NULL) {
|
if (code->callbacks.onLowMemory != NULL) {
|
||||||
code->callbacks.onLowMemory(code);
|
code->callbacks.onLowMemory((ANativeActivity *)code);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onWindowFocusChangedNative(JNIEnv* env, jobject clazz, jlong handle, jboolean focused)
|
||||||
Java_android_app_NativeActivity_onWindowFocusChangedNative(JNIEnv* env, jobject clazz, jlong handle, jboolean focused)
|
|
||||||
{
|
{
|
||||||
if (handle != 0) {
|
if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onWindowFocusChanged != NULL) {
|
if (code->callbacks.onWindowFocusChanged != NULL) {
|
||||||
code->callbacks.onWindowFocusChanged(code, focused ? 1 : 0);
|
code->callbacks.onWindowFocusChanged((ANativeActivity *)code, focused ? 1 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onSurfaceCreatedNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface)
|
||||||
Java_android_app_NativeActivity_onSurfaceCreatedNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onSurfaceCreated_native\n");
|
printf("STUB - onSurfaceCreated_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
code->setSurface(surface);
|
code->setSurface(surface);
|
||||||
if (code->nativeWindow != NULL && code->callbacks.onNativeWindowCreated != NULL) {
|
if (code->nativeWindow != NULL && code->callbacks.onNativeWindowCreated != NULL) {
|
||||||
code->callbacks.onNativeWindowCreated(code,
|
code->callbacks.onNativeWindowCreated((ANativeActivity *)code, code->nativeWindow.get());
|
||||||
code->nativeWindow.get());
|
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onSurfaceChangedNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface,
|
||||||
Java_android_app_NativeActivity_onSurfaceChangedNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface,
|
|
||||||
jint format, jint width, jint height)
|
jint format, jint width, jint height)
|
||||||
{
|
{
|
||||||
if (handle != 0) {
|
if (handle != 0) {
|
||||||
@@ -495,13 +491,12 @@ Java_android_app_NativeActivity_onSurfaceChangedNative(JNIEnv* env, jobject claz
|
|||||||
NativeCode_setSurface(code, surface);
|
NativeCode_setSurface(code, surface);
|
||||||
if (oldNativeWindow != code->nativeWindow) {
|
if (oldNativeWindow != code->nativeWindow) {
|
||||||
if (oldNativeWindow != NULL && code->callbacks.onNativeWindowDestroyed != NULL) {
|
if (oldNativeWindow != NULL && code->callbacks.onNativeWindowDestroyed != NULL) {
|
||||||
code->callbacks.onNativeWindowDestroyed(code, oldNativeWindow);
|
code->callbacks.onNativeWindowDestroyed((ANativeActivity *)code, oldNativeWindow);
|
||||||
ANativeWindow_release(oldNativeWindow); // TODO: can it happen that this will be done by the callback and we will have double free?
|
ANativeWindow_release(oldNativeWindow); // TODO: can it happen that this will be done by the callback and we will have double free?
|
||||||
}
|
}
|
||||||
if (code->nativeWindow != NULL) {
|
if (code->nativeWindow != NULL) {
|
||||||
if (code->callbacks.onNativeWindowCreated != NULL) {
|
if (code->callbacks.onNativeWindowCreated != NULL) {
|
||||||
code->callbacks.onNativeWindowCreated(code,
|
code->callbacks.onNativeWindowCreated((ANativeActivity *)code, code->nativeWindow);
|
||||||
code->nativeWindow);
|
|
||||||
}
|
}
|
||||||
code->lastWindowWidth = width;
|
code->lastWindowWidth = width;
|
||||||
code->lastWindowHeight = height;
|
code->lastWindowHeight = height;
|
||||||
@@ -511,28 +506,25 @@ Java_android_app_NativeActivity_onSurfaceChangedNative(JNIEnv* env, jobject claz
|
|||||||
if (width != code->lastWindowWidth
|
if (width != code->lastWindowWidth
|
||||||
|| height != code->lastWindowHeight) {
|
|| height != code->lastWindowHeight) {
|
||||||
if (code->callbacks.onNativeWindowResized != NULL) {
|
if (code->callbacks.onNativeWindowResized != NULL) {
|
||||||
code->callbacks.onNativeWindowResized(code,
|
code->callbacks.onNativeWindowResized((ANativeActivity *)code, code->nativeWindow);
|
||||||
code->nativeWindow);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onSurfaceRedrawNeededNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface/*?*/)
|
||||||
Java_android_app_NativeActivity_onSurfaceRedrawNeededNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface/*?*/)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onSurfaceRedrawNeeded_native\n");
|
printf("STUB - onSurfaceRedrawNeeded_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->nativeWindow != NULL && code->callbacks.onNativeWindowRedrawNeeded != NULL) {
|
if (code->nativeWindow != NULL && code->callbacks.onNativeWindowRedrawNeeded != NULL) {
|
||||||
code->callbacks.onNativeWindowRedrawNeeded(code, code->nativeWindow.get());
|
code->callbacks.onNativeWindowRedrawNeeded((ANativeActivity *)code, code->nativeWindow.get());
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onSurfaceDestroyedNative(JNIEnv* env, jobject clazz, jlong handle)
|
||||||
Java_android_app_NativeActivity_onSurfaceDestroyedNative(JNIEnv* env, jobject clazz, jlong handle)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onSurfaceDestroyed_native\n");
|
printf("STUB - onSurfaceDestroyed_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
@@ -545,33 +537,30 @@ Java_android_app_NativeActivity_onSurfaceDestroyedNative(JNIEnv* env, jobject cl
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onInputQueueCreatedNative(JNIEnv* env, jobject clazz, jlong handle, jlong queue)
|
||||||
Java_android_app_NativeActivity_onInputQueueCreatedNative(JNIEnv* env, jobject clazz, jlong handle, jlong queue)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onInputChannelCreated_native\n");
|
printf("STUB - onInputChannelCreated_native\n");
|
||||||
if (handle != 0) {
|
if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onInputQueueCreated != NULL) {
|
if (code->callbacks.onInputQueueCreated != NULL) {
|
||||||
code->callbacks.onInputQueueCreated(code, queue);
|
code->callbacks.onInputQueueCreated((ANativeActivity *)code, (AInputQueue *)queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onInputQueueDestroyedNative(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
|
||||||
Java_android_app_NativeActivity_onInputQueueDestroyedNative(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
|
|
||||||
{
|
{
|
||||||
printf("STUB - onInputChannelDestroyed_native\n");
|
printf("STUB - onInputChannelDestroyed_native\n");
|
||||||
/* if (handle != 0) {
|
/* if (handle != 0) {
|
||||||
struct NativeCode* code = (struct NativeCode*)handle;
|
struct NativeCode* code = (struct NativeCode*)handle;
|
||||||
if (code->callbacks.onInputQueueDestroyed != NULL) {
|
if (code->callbacks.onInputQueueDestroyed != NULL) {
|
||||||
AInputQueue* queue = reinterpret_cast<AInputQueue*>(queuePtr);
|
AInputQueue* queue = reinterpret_cast<AInputQueue*>(queuePtr);
|
||||||
code->callbacks.onInputQueueDestroyed(code, queue);
|
code->callbacks.onInputQueueDestroyed((ANativeActivity *)code, queue);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Java_android_app_NativeActivity_onContentRectChangedNative(JNIEnv* env, jobject clazz, jlong handle,
|
||||||
Java_android_app_NativeActivity_onContentRectChangedNative(JNIEnv* env, jobject clazz, jlong handle,
|
|
||||||
jint x, jint y, jint w, jint h)
|
jint x, jint y, jint w, jint h)
|
||||||
{
|
{
|
||||||
printf("STUB - onContentRectChanged_native\n");
|
printf("STUB - onContentRectChanged_native\n");
|
||||||
@@ -583,7 +572,7 @@ Java_android_app_NativeActivity_onContentRectChangedNative(JNIEnv* env, jobject
|
|||||||
rect.top = y;
|
rect.top = y;
|
||||||
rect.right = x+w;
|
rect.right = x+w;
|
||||||
rect.bottom = y+h;
|
rect.bottom = y+h;
|
||||||
code->callbacks.onContentRectChanged(code, &rect);
|
code->callbacks.onContentRectChanged((ANativeActivity *)code, &rect);
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ JNIEXPORT jlong JNICALL Java_com_google_android_gles_1jni_EGLImpl_native_1eglCre
|
|||||||
jint* attrib_base = get_int_array_crit(env, attrib_list);
|
jint* attrib_base = get_int_array_crit(env, attrib_list);
|
||||||
|
|
||||||
EGLContext egl_context = eglCreateContext(_PTR(egl_display), _PTR(egl_config), NULL, attrib_base);
|
EGLContext egl_context = eglCreateContext(_PTR(egl_display), _PTR(egl_config), NULL, attrib_base);
|
||||||
printf("egl_context: %d\n", egl_context);
|
printf("egl_context: %p\n", egl_context);
|
||||||
|
|
||||||
release_int_array_crit(env, attrib_list, attrib_base);
|
release_int_array_crit(env, attrib_list, attrib_base);
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ JNIEXPORT jboolean JNICALL Java_com_google_android_gles_1jni_EGLImpl_native_1egl
|
|||||||
jint* num_config_base = get_int_array_crit(env, num_config);
|
jint* num_config_base = get_int_array_crit(env, num_config);
|
||||||
|
|
||||||
ret = eglChooseConfig(_PTR(egl_display), attrib_base, egl_configs ? _PTR(configs_base) : NULL, config_size, num_config_base);
|
ret = eglChooseConfig(_PTR(egl_display), attrib_base, egl_configs ? _PTR(configs_base) : NULL, config_size, num_config_base);
|
||||||
printf(".. eglChooseConfig: egl_display: %p, egl_configs: %d, _PTR(configs_base): %p, config_size: %d, num_config_base[0]: %d\n", egl_display, egl_configs, _PTR(configs_base), config_size, num_config_base[0]);
|
printf(".. eglChooseConfig: egl_display: %ld, egl_configs: %p, _PTR(configs_base): %p, config_size: %d, num_config_base[0]: %d\n", egl_display, egl_configs, _PTR(configs_base), config_size, num_config_base[0]);
|
||||||
|
|
||||||
release_int_array_crit(env, attrib_list, attrib_base);
|
release_int_array_crit(env, attrib_list, attrib_base);
|
||||||
release_long_array_crit(env, egl_configs, configs_base);
|
release_long_array_crit(env, egl_configs, configs_base);
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
|
* parts of this file originally from AOSP:
|
||||||
|
*
|
||||||
* Copyright (C) 2010 The Android Open Source Project
|
* Copyright (C) 2010 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
@@ -17,16 +16,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup NativeActivity Native Activity
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file native_window.h
|
|
||||||
* @brief API for accessing a native window.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -526,6 +515,9 @@ VkResult bionic_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSu
|
|||||||
};
|
};
|
||||||
|
|
||||||
return vkCreateXlibSurfaceKHR(instance, &x11_create_info, pAllocator, pSurface);
|
return vkCreateXlibSurfaceKHR(instance, &x11_create_info, pAllocator, pSurface);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "bionic_vkCreateAndroidSurfaceKHR: the GDK backend is neither Wayland nor X11, no SurfaceView for you");
|
||||||
|
return VK_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user