platform/android: debug surface enabling/disabling, add notification for event_set_pause, fix wrong host.status, prevent rendering while no surface

This commit is contained in:
mittorn 2023-10-27 00:24:23 +03:00 committed by Alibek Omarov
parent ea35863c26
commit 7b4fd3bcad
2 changed files with 30 additions and 10 deletions

View File

@ -854,12 +854,12 @@ void Platform_RunEvents( void )
case event_set_pause: case event_set_pause:
// destroy EGL surface when hiding application // destroy EGL surface when hiding application
Con_Printf( "pause event %d\n", events.queue[i].arg );
if( !events.queue[i].arg ) if( !events.queue[i].arg )
{ {
SNDDMA_Activate( true ); SNDDMA_Activate( true );
// (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 ); // (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 );
Android_UpdateSurface( true ); Android_UpdateSurface( true );
host.status = HOST_FRAME;
SetBits( gl_vsync.flags, FCVAR_CHANGED ); // set swap interval SetBits( gl_vsync.flags, FCVAR_CHANGED ); // set swap interval
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
} }
@ -868,22 +868,27 @@ void Platform_RunEvents( void )
{ {
SNDDMA_Activate( false ); SNDDMA_Activate( false );
Android_UpdateSurface( false ); Android_UpdateSurface( false );
host.status = HOST_NOFOCUS;
// (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 ); // (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 );
} }
(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.notify );
break; break;
case event_resize: case event_resize:
// reinitialize EGL and change engine screen size // reinitialize EGL and change engine screen size
if( host.status == HOST_FRAME &&( refState.width != jni.width || refState.height != jni.height ) ) if( ( host.status == HOST_FRAME || host.status == HOST_NOFOCUS ) &&( refState.width != jni.width || refState.height != jni.height ))
{ {
// (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 ); // (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 );
// (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 ); // (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 );
Con_DPrintf("resize event\n");
Android_UpdateSurface( false ); Android_UpdateSurface( false );
Android_UpdateSurface( true ); Android_UpdateSurface( true );
SetBits( gl_vsync.flags, FCVAR_CHANGED ); // set swap interval SetBits( gl_vsync.flags, FCVAR_CHANGED ); // set swap interval
VID_SetMode(); VID_SetMode();
} }
else
{
Con_DPrintf("resize skip %d %d %d %d %d", jni.width, jni.height, refState.width, refState.height, host.status );
}
break; break;
case event_joyadd: case event_joyadd:
Joy_AddEvent(); Joy_AddEvent();
@ -934,14 +939,14 @@ void Platform_RunEvents( void )
#endif #endif
// disable sound during call/screen-off // disable sound during call/screen-off
SNDDMA_Activate( false ); SNDDMA_Activate( false );
// host.status = HOST_NOFOCUS; host.status = HOST_SLEEP;
// stop blocking UI thread // stop blocking UI thread
(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.notify ); (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.notify );
break; break;
case event_onresume: case event_onresume:
// re-enable sound after onPause // re-enable sound after onPause
// host.status = HOST_FRAME; host.status = HOST_FRAME;
SNDDMA_Activate( true ); SNDDMA_Activate( true );
host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME; host.force_draw_version_time = host.realtime + FORCE_DRAW_VERSION_TIME;
break; break;

View File

@ -122,9 +122,10 @@ Check if we may use native EGL without jni calls
void Android_UpdateSurface( qboolean active ) void Android_UpdateSurface( qboolean active )
{ {
vid_android.nativeegl = false; vid_android.nativeegl = false;
Con_Printf("1\n");
if( glw_state.software || eglstate.valid ) if( glw_state.software || ( eglstate.valid && !eglstate.imported ) )
{ {
Con_Printf("2\n");
if( vid_android.window && !active ) if( vid_android.window && !active )
{ {
nw.release( vid_android.window ); nw.release( vid_android.window );
@ -157,20 +158,33 @@ void Android_UpdateSurface( qboolean active )
} }
return; return;
} }
Con_Printf("3\n");
if( !vid_android.has_context ) if( !vid_android.has_context )
return; return;
if( ( active && host.status == HOST_FRAME ) || !active ) //if( ( active && host.status == HOST_FRAME ) || !active )
if( !active )
{
Con_Printf("toggleEGL 0\n");
(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 ); (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 0 );
}
host.status = HOST_SLEEP;
if( active ) if( active )
{
Con_Printf("toggleEGL 1\n");
(*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 ); (*jni.env)->CallStaticVoidMethod( jni.env, jni.actcls, jni.toggleEGL, 1 );
host.status = HOST_FRAME;
}
// todo: check opengl context here and set HOST_SLEEP if not
if( !Sys_CheckParm("-nativeegl") || !active ) if( !Sys_CheckParm("-nativeegl") || !active )
return; // enabled by user return; // enabled by user
vid_android.nativeegl = EGL_ImportContext(); vid_android.nativeegl = EGL_ImportContext();
if( vid_android.nativeegl )
Con_DPrintf( "nativeEGL success\n");
} }
/* /*
@ -270,6 +284,7 @@ qboolean R_Init_Video( const int type )
host.renderinfo_changed = false; host.renderinfo_changed = false;
host.status = HOST_FRAME; // where it should we done? We have broken host.status on all non-SDL platforms!
return true; return true;
} }