fix android egl errors, implement android backspace in text input
This commit is contained in:
@@ -70,7 +70,7 @@ kKey convert_key(int android_key)
|
||||
CASE(AKEYCODE_EXPLORER, kKey::Unknown);
|
||||
CASE(AKEYCODE_ENVELOPE, kKey::Unknown);
|
||||
CASE(AKEYCODE_ENTER, kKey::Unknown);
|
||||
CASE(AKEYCODE_DEL, kKey::Unknown);
|
||||
CASE(AKEYCODE_DEL, kKey::KeyBackspace);
|
||||
CASE(AKEYCODE_GRAVE, kKey::Unknown);
|
||||
CASE(AKEYCODE_MINUS, kKey::Unknown);
|
||||
CASE(AKEYCODE_EQUALS, kKey::Unknown);
|
||||
|
||||
@@ -134,6 +134,16 @@ void android_async_lock(struct engine* engine)
|
||||
mutex_count++;
|
||||
}
|
||||
|
||||
bool android_async_trylock(struct engine* engine)
|
||||
{
|
||||
if (!mutex.try_lock())
|
||||
return false;
|
||||
if (mutex_count == 0)
|
||||
eglMakeCurrent(engine->display, engine->surface, engine->surface, engine->context);
|
||||
mutex_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void android_async_swap(struct engine* engine)
|
||||
{
|
||||
eglSwapBuffers(engine->display, engine->surface);
|
||||
@@ -280,16 +290,18 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickExternalCal
|
||||
JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_contentRectChanged(JNIEnv *end, jobject,
|
||||
jint wnd_w, jint wnd_h, jint rect_left, jint rect_top, jint rect_right, jint rect_bottom)
|
||||
{
|
||||
//if (!android_async_trylock(&g_engine))
|
||||
// return;
|
||||
LOG("resize wnd [%d %d] rect [%d %d %d %d]", wnd_w, wnd_h, rect_left, rect_top, rect_right, rect_bottom);
|
||||
locker _lock(&g_engine);
|
||||
App::I.width = wnd_w;
|
||||
App::I.height = (rect_bottom - rect_top);
|
||||
App::I.off_x = 0;
|
||||
App::I.off_y = wnd_h - (rect_bottom - rect_top);
|
||||
App::I.redraw = true;
|
||||
//App::I.redraw = true;
|
||||
//App::I.resize(App::I.width, App::I.height);
|
||||
g_engine.width = wnd_w;
|
||||
g_engine.height = wnd_h;
|
||||
//g_engine.width = wnd_w;
|
||||
//g_engine.height = wnd_h;
|
||||
//android_async_unlock(&g_engine);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,10 +700,10 @@ static void engine_draw_frame(struct engine* engine) {
|
||||
static float elapsed = 0;
|
||||
locker _lock(engine);
|
||||
|
||||
/*
|
||||
if (engine->display == NULL)
|
||||
if (engine->display == EGL_NO_DISPLAY)
|
||||
return;
|
||||
|
||||
/*
|
||||
int w, h;
|
||||
eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w);
|
||||
eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h);
|
||||
@@ -711,7 +723,7 @@ static void engine_draw_frame(struct engine* engine) {
|
||||
elapsed += dt.count();
|
||||
App::I.tick(dt.count());
|
||||
|
||||
if (engine->display == NULL || !(App::I.redraw || App::I.animate))
|
||||
if (!(App::I.redraw || App::I.animate))
|
||||
return;
|
||||
|
||||
App::I.clear();
|
||||
@@ -960,6 +972,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
//exit(0);
|
||||
break;
|
||||
case APP_CMD_GAINED_FOCUS:
|
||||
/*
|
||||
// When our app gains focus, we start monitoring the accelerometer.
|
||||
if (engine->accelerometerSensor != NULL) {
|
||||
ASensorEventQueue_enableSensor(engine->sensorEventQueue,
|
||||
@@ -970,8 +983,10 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
(1000L/60)*1000);
|
||||
}
|
||||
engine->animating = 1;
|
||||
*/
|
||||
break;
|
||||
case APP_CMD_LOST_FOCUS:
|
||||
/*
|
||||
// When our app loses focus, we stop monitoring the accelerometer.
|
||||
// This is to avoid consuming battery while not being used.
|
||||
if (engine->accelerometerSensor != NULL) {
|
||||
@@ -981,6 +996,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
// Also stop animating.
|
||||
engine->animating = 0;
|
||||
engine_draw_frame(engine);
|
||||
*/
|
||||
break;
|
||||
case APP_CMD_WINDOW_REDRAW_NEEDED:
|
||||
LOG("APP_CMD_WINDOW_REDRAW_NEEDED");
|
||||
@@ -996,7 +1012,8 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
LOG("APP_CMD_CONTENT_RECT_CHANGED");
|
||||
//App::I.width = engine->app->contentRect.right - engine->app->contentRect.left;
|
||||
//App::I.height = engine->app->contentRect.bottom - engine->app->contentRect.top;
|
||||
LOG("content rect %f %f", App::I.width, App::I.height);
|
||||
//LOG("content rect %f %f", App::I.width, App::I.height);
|
||||
App::I.redraw = true;
|
||||
ALooper_wake(engine->app->looper);
|
||||
break;
|
||||
}
|
||||
@@ -1047,14 +1064,11 @@ void android_main(struct android_app* state) {
|
||||
// If animating, we loop until all events are read, then continue
|
||||
// to draw the next frame of animation.
|
||||
bool used = false;
|
||||
while (!used && (ident=ALooper_pollOnce(100, NULL, &events,
|
||||
int timeout = g_engine.display != EGL_NO_DISPLAY ? 100 : -1;
|
||||
while (!used && (ident=ALooper_pollOnce(timeout, NULL, &events,
|
||||
(void**)&source)) != ALOOPER_POLL_ERROR) {
|
||||
|
||||
// Process this event.
|
||||
if (source != NULL) {
|
||||
source->process(state, source);
|
||||
used = true;
|
||||
}
|
||||
|
||||
// If a sensor has data, process it now.
|
||||
/*
|
||||
@@ -1069,8 +1083,15 @@ void android_main(struct android_app* state) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (source != NULL) {
|
||||
source->process(state, source);
|
||||
used = true;
|
||||
}
|
||||
|
||||
if (ident == ALOOPER_POLL_TIMEOUT || ident == ALOOPER_POLL_CALLBACK){
|
||||
if (g_engine.display == EGL_NO_DISPLAY || ident == ALOOPER_POLL_CALLBACK)
|
||||
continue;
|
||||
|
||||
if (ident == ALOOPER_POLL_TIMEOUT){
|
||||
App::I.redraw = true;
|
||||
engine_draw_frame(&g_engine);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user