From dc9780eb465e270af69473187e055b0b69dfe0ae Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Mon, 29 Oct 2018 20:03:47 +0100 Subject: [PATCH] Android: fix black screen at boot on some devices --- core/hw/pvr/Renderer_if.cpp | 5 +++++ core/linux/common.cpp | 16 ++++++++++++++-- core/stdclass.h | 2 +- core/windows/winmain.cpp | 4 ++-- .../reicast/src/main/jni/src/Android.cpp | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/core/hw/pvr/Renderer_if.cpp b/core/hw/pvr/Renderer_if.cpp index 6bf610c2d..f5750e222 100644 --- a/core/hw/pvr/Renderer_if.cpp +++ b/core/hw/pvr/Renderer_if.cpp @@ -269,7 +269,12 @@ bool rend_single_frame() do { #if !defined(TARGET_NO_THREADS) +#if defined(_ANDROID) + if (!rs.Wait(100)) + return false; +#else rs.Wait(); +#endif #endif if (!renderer_enabled) return false; diff --git a/core/linux/common.cpp b/core/linux/common.cpp index fecdea358..31e9808e3 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -169,9 +169,21 @@ void cResetEvent::Reset()//reset state=false; pthread_mutex_unlock( &mutx ); } -void cResetEvent::Wait(u32 msec)//Wait for signal , then reset +bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset { - verify(false); + bool rc = true; + pthread_mutex_lock( &mutx ); + if (!state) + { + struct timespec ts; + ts.tv_sec = msec / 1000; + ts.tv_nsec = (msec % 1000) * 1000; + rc = pthread_cond_timedwait( &cond, &mutx, &ts ) == 0; + } + state=false; + pthread_mutex_unlock( &mutx ); + + return rc; } void cResetEvent::Wait()//Wait for signal , then reset { diff --git a/core/stdclass.h b/core/stdclass.h index 6b76b4d35..9d98fc0de 100644 --- a/core/stdclass.h +++ b/core/stdclass.h @@ -201,7 +201,7 @@ public : ~cResetEvent(); void Set(); //Set state to signaled void Reset(); //Set state to non signaled - void Wait(u32 msec);//Wait for signal , then reset[if auto] + bool Wait(u32 msec);//Wait for signal , then reset[if auto]. Returns false if timed out void Wait(); //Wait for signal , then reset[if auto] }; diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index 6ff2a8f06..be44e63e5 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -785,12 +785,12 @@ void cResetEvent::Reset()//reset #endif ResetEvent(hEvent); } -void cResetEvent::Wait(u32 msec)//Wait for signal , then reset +bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset { #if defined(DEBUG_THREADS) Sleep(rand() % 10); #endif - WaitForSingleObject(hEvent,msec); + return WaitForSingleObject(hEvent,msec) == WAIT_OBJECT_0; } void cResetEvent::Wait()//Wait for signal , then reset { diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index 51d3e7758..533738cc3 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -521,7 +521,7 @@ JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_data(JNIEnv *env, job JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendframe(JNIEnv *env,jobject obj) { - while(!rend_single_frame()) ; + rend_single_frame(); } JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_kcode(JNIEnv * env, jobject obj, jintArray k_code, jintArray l_t, jintArray r_t, jintArray jx, jintArray jy)