diff options
author | Will Osborn <willosborn@google.com> | 2019-03-29 09:27:02 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-03-29 09:27:02 -0700 |
commit | f4ca034aec4fb6a95b227f6281bf2a65bf9e5b1a (patch) | |
tree | c380d4902bcb9615e8e7c3963ffad1e7db0d228d | |
parent | 25d61327f980fdc5690017de305c78db6d373c0f (diff) | |
parent | 72066c179cc432142e562ea9afd03f5d3dc22a84 (diff) | |
download | gamesdk-f4ca034aec4fb6a95b227f6281bf2a65bf9e5b1a.tar.gz |
Fix swappy crash on <21 devices and make tftestapp degrade gracefully am: 41d9eb1bde
am: 72066c179c
Change-Id: I421af31db328aba86afc737e606ef14411df1a4c
-rw-r--r-- | samples/tuningfork/tftestapp/app/src/main/cpp/Renderer.cpp | 13 | ||||
-rw-r--r-- | samples/tuningfork/tftestapp/app/src/main/cpp/tftestapp.cpp | 29 | ||||
-rw-r--r-- | src/swappy/Swappy.cpp | 6 |
3 files changed, 44 insertions, 4 deletions
diff --git a/samples/tuningfork/tftestapp/app/src/main/cpp/Renderer.cpp b/samples/tuningfork/tftestapp/app/src/main/cpp/Renderer.cpp index d8803b52..ddf8dac7 100644 --- a/samples/tuningfork/tftestapp/app/src/main/cpp/Renderer.cpp +++ b/samples/tuningfork/tftestapp/app/src/main/cpp/Renderer.cpp @@ -32,9 +32,12 @@ #include "swappy/swappy.h" #include "swappy/swappy_extra.h" +#include "tuningfork/tuningfork.h" #include "Scene.h" +extern bool swappy_enabled; + using namespace std::chrono_literals; namespace samples { @@ -227,7 +230,8 @@ void Renderer::draw(State *state) { return; } - Swappy_recordFrameStart(state->display, state->surface); + if (swappy_enabled) + Swappy_recordFrameStart(state->display, state->surface); calculateFps(); @@ -252,7 +256,12 @@ void Renderer::draw(State *state) { state->scene.draw(aspectRatio, mTesselation); - Swappy_swap(state->display, state->surface); + if (swappy_enabled) + Swappy_swap(state->display, state->surface); + else { + TuningFork_frameTick(TFTICK_SYSCPU); + eglSwapBuffers(state->display, state->surface); + } // If we're still started, request another frame requestDraw(); diff --git a/samples/tuningfork/tftestapp/app/src/main/cpp/tftestapp.cpp b/samples/tuningfork/tftestapp/app/src/main/cpp/tftestapp.cpp index 7b18e29e..7ec27372 100644 --- a/samples/tuningfork/tftestapp/app/src/main/cpp/tftestapp.cpp +++ b/samples/tuningfork/tftestapp/app/src/main/cpp/tftestapp.cpp @@ -36,6 +36,8 @@ namespace proto_tf = com::google::tuningfork; namespace tf = tuningfork; using namespace samples; +bool swappy_enabled = false; + namespace { constexpr TFInstrumentKey TFTICK_CHOREOGRAPHER = 4; @@ -184,7 +186,8 @@ extern "C" { JNIEXPORT void JNICALL Java_com_google_tuningfork_TFTestActivity_initTuningFork(JNIEnv *env, jobject activity) { Swappy_init(env, activity); - if (Swappy_isEnabled()) { + swappy_enabled = Swappy_isEnabled(); + if (swappy_enabled) { int defaultFPIndex = 3; // i.e. dev_tuningfork_fidelityparams_3.bin int initialTimeoutMs = 1000; int ultimateTimeoutMs = 100000; @@ -199,7 +202,29 @@ Java_com_google_tuningfork_TFTestActivity_initTuningFork(JNIEnv *env, jobject ac ALOGW("Error initializing TuningFork: %d", c); } } else { - ALOGW("Couldn't enable Swappy. Tuning Fork is not enabled either"); + ALOGW("Couldn't enable Swappy."); + CProtobufSerialization settings = {}; + TuningFork_findSettingsInAPK(env, activity, &settings); + TuningFork_init(&settings, env, activity); + tuningfork::CProtobufSerialization_Free(&settings); + int fp_count; + TuningFork_findFidelityParamsInAPK(env, activity, NULL, &fp_count); + CProtobufSerialization fps = {}; + std::vector<CProtobufSerialization> defaultFPs(fp_count); + TuningFork_findFidelityParamsInAPK(env, activity, defaultFPs.data(), &fp_count); + CProtobufSerialization* defaultFP = &defaultFPs[fp_count/2-1]; // Middle settings level + if (TuningFork_getFidelityParameters(defaultFP, &fps, 1000)) { + SetFidelityParams(&fps); + tuningfork::CProtobufSerialization_Free(&fps); + } + else { + SetFidelityParams(defaultFP); + } + for(auto& a: defaultFPs) { + tuningfork::CProtobufSerialization_Free(&a); + } + TuningFork_setUploadCallback(UploadCallback); + SetAnnotations(); } } diff --git a/src/swappy/Swappy.cpp b/src/swappy/Swappy.cpp index fa4ea2bb..d4a32d31 100644 --- a/src/swappy/Swappy.cpp +++ b/src/swappy/Swappy.cpp @@ -78,6 +78,12 @@ void Swappy::init(JNIEnv *env, jobject jactivity) { displayClass, "getAppVsyncOffsetNanos", "()J"); + // getAppVsyncOffsetNanos was only added in API 21. + // Return gracefully if this device doesn't support it. + if (getAppVsyncOffsetNanos == 0 || env->ExceptionOccurred()) { + env->ExceptionClear(); + return; + } const long appVsyncOffsetNanos = env->CallLongMethod(display, getAppVsyncOffsetNanos); jmethodID getPresentationDeadlineNanos = env->GetMethodID( |