From bfda7d73c1a48b6361df9c37c54e746d67671b04 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 15 Feb 2019 16:38:55 -0800 Subject: [PATCH] Fix frame player --- android/apps/questFramePlayer/CMakeLists.txt | 2 +- .../src/main/AndroidManifest.xml | 25 +++------ .../src/main/cpp/AndroidHelper.cpp | 33 ++++++++++++ .../src/main/cpp/AndroidHelper.h | 46 ++++++++++++++++ .../src/main/cpp/RenderThread.cpp | 44 +++++++++++----- .../questFramePlayer/src/main/cpp/main.cpp | 25 +++++---- .../frameplayer/QuestQtActivity.java | 52 ------------------- .../frameplayer/QuestRenderActivity.java | 8 --- .../src/main/AndroidManifest.xml | 2 +- .../questInterface/InterfaceActivitiy.java | 11 ++++ android/libraries/oculus/build.gradle | 2 +- .../oculus/OculusMobileActivity.java | 1 - libraries/gpu/src/gpu/FrameReader.cpp | 15 +++++- 13 files changed, 159 insertions(+), 107 deletions(-) create mode 100644 android/apps/questFramePlayer/src/main/cpp/AndroidHelper.cpp create mode 100644 android/apps/questFramePlayer/src/main/cpp/AndroidHelper.h delete mode 100644 android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestQtActivity.java create mode 100644 android/apps/questInterface/src/main/java/io/highfidelity/questInterface/InterfaceActivitiy.java diff --git a/android/apps/questFramePlayer/CMakeLists.txt b/android/apps/questFramePlayer/CMakeLists.txt index 5889585a6c..ea60e27a7d 100644 --- a/android/apps/questFramePlayer/CMakeLists.txt +++ b/android/apps/questFramePlayer/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_NAME questFramePlayer) setup_hifi_library(AndroidExtras) link_hifi_libraries(shared ktx shaders gpu gl oculusMobile ${PLATFORM_GL_BACKEND}) -target_include_directories(${TARGET_NAME} PRIVATE ${HIFI_ANDROID_PRECOMPILED}/ovr/VrApi/Include) + target_link_libraries(${TARGET_NAME} android log m) target_opengl() target_oculus_mobile() diff --git a/android/apps/questFramePlayer/src/main/AndroidManifest.xml b/android/apps/questFramePlayer/src/main/AndroidManifest.xml index 721e8cee89..ba14b04532 100644 --- a/android/apps/questFramePlayer/src/main/AndroidManifest.xml +++ b/android/apps/questFramePlayer/src/main/AndroidManifest.xml @@ -19,24 +19,6 @@ android:name="org.qtproject.qt5.android.bindings.QtApplication" tools:ignore="GoogleAppIndexingWarning,MissingApplicationIcon"> - - - - - - - - - + + + + + + + diff --git a/android/apps/questFramePlayer/src/main/cpp/AndroidHelper.cpp b/android/apps/questFramePlayer/src/main/cpp/AndroidHelper.cpp new file mode 100644 index 0000000000..40cadfaf7d --- /dev/null +++ b/android/apps/questFramePlayer/src/main/cpp/AndroidHelper.cpp @@ -0,0 +1,33 @@ +// +// AndroidHelper.cpp +// interface/src +// +// Created by Gabriel Calero & Cristian Duarte on 3/30/18. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "AndroidHelper.h" + +#include +#include + +AndroidHelper::AndroidHelper() { +} + +AndroidHelper::~AndroidHelper() { +} + +void AndroidHelper::notifyLoadComplete() { + emit qtAppLoadComplete(); +} + +void AndroidHelper::notifyEnterForeground() { + emit enterForeground(); +} + +void AndroidHelper::notifyEnterBackground() { + emit enterBackground(); +} + diff --git a/android/apps/questFramePlayer/src/main/cpp/AndroidHelper.h b/android/apps/questFramePlayer/src/main/cpp/AndroidHelper.h new file mode 100644 index 0000000000..7ee85294f1 --- /dev/null +++ b/android/apps/questFramePlayer/src/main/cpp/AndroidHelper.h @@ -0,0 +1,46 @@ +// +// AndroidHelper.h +// interface/src +// +// Created by Gabriel Calero & Cristian Duarte on 3/30/18. +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_Android_Helper_h +#define hifi_Android_Helper_h + +#include +#include +#include +#include + +class AndroidHelper : public QObject { + Q_OBJECT +public: + AndroidHelper(AndroidHelper const&) = delete; + void operator=(AndroidHelper const&) = delete; + + static AndroidHelper& instance() { + static AndroidHelper instance; + return instance; + } + + void notifyLoadComplete(); + void notifyEnterForeground(); + void notifyEnterBackground(); + + +signals: + void qtAppLoadComplete(); + void enterForeground(); + void enterBackground(); + +private: + AndroidHelper(); + ~AndroidHelper(); +}; + +#endif diff --git a/android/apps/questFramePlayer/src/main/cpp/RenderThread.cpp b/android/apps/questFramePlayer/src/main/cpp/RenderThread.cpp index 5eabe6b9b1..22cb85a889 100644 --- a/android/apps/questFramePlayer/src/main/cpp/RenderThread.cpp +++ b/android/apps/questFramePlayer/src/main/cpp/RenderThread.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -29,9 +30,9 @@ #include #include -static JNIEnv* _env { nullptr }; -static JavaVM* _vm { nullptr }; -static jobject _activity { nullptr }; +#include "AndroidHelper.h" + +//static jobject _activity { nullptr }; struct HandController{ ovrInputTrackedRemoteCapabilities caps {}; @@ -48,21 +49,43 @@ struct HandController{ }; std::vector devices; +QAndroidJniObject __interfaceActivity; extern "C" { -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *, void *) { +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void *) { __android_log_write(ANDROID_LOG_WARN, "QQQ", __FUNCTION__); return JNI_VERSION_1_6; } +JNIEXPORT void JNICALL +Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnCreate(JNIEnv *env, jobject obj) { + __android_log_print(ANDROID_LOG_INFO, "QQQ", __FUNCTION__); + __interfaceActivity = QAndroidJniObject(obj); + QObject::connect(&AndroidHelper::instance(), &AndroidHelper::qtAppLoadComplete, []() { + __interfaceActivity.callMethod("onAppLoadedComplete", "()V"); + QObject::disconnect(&AndroidHelper::instance(), &AndroidHelper::qtAppLoadComplete, nullptr, nullptr); + }); +} -JNIEXPORT void JNICALL Java_io_highfidelity_frameplayer_QuestQtActivity_nativeOnCreate(JNIEnv* env, jobject obj) { - env->GetJavaVM(&_vm); - _activity = env->NewGlobalRef(obj); +JNIEXPORT void +Java_io_highfidelity_oculus_OculusMobileActivity_questOnAppAfterLoad(JNIEnv *env, jobject obj) { + AndroidHelper::instance().moveToThread(qApp->thread()); } + +JNIEXPORT void JNICALL +Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnPause(JNIEnv *env, jobject obj) { + AndroidHelper::instance().notifyEnterBackground(); } +JNIEXPORT void JNICALL +Java_io_highfidelity_oculus_OculusMobileActivity_questNativeOnResume(JNIEnv *env, jobject obj) { + AndroidHelper::instance().notifyEnterForeground(); +} + +} + + static const char* FRAME_FILE = "assets:/frames/20190121_1220.json"; static void textureLoader(const std::string& filename, const gpu::TexturePointer& texture, uint16_t layer) { @@ -96,14 +119,7 @@ void RenderThread::setup() { // Wait until the context has been moved to this thread { std::unique_lock lock(_frameLock); } - ovr::VrHandler::initVr(); - __android_log_write(ANDROID_LOG_WARN, "QQQ", "Launching oculus activity"); - _vm->AttachCurrentThread(&_env, nullptr); - jclass cls = _env->GetObjectClass(_activity); - jmethodID mid = _env->GetMethodID(cls, "launchOculusActivity", "()V"); - _env->CallVoidMethod(_activity, mid); - __android_log_write(ANDROID_LOG_WARN, "QQQ", "Launching oculus activity done"); ovr::VrHandler::setHandler(this); makeCurrent(); diff --git a/android/apps/questFramePlayer/src/main/cpp/main.cpp b/android/apps/questFramePlayer/src/main/cpp/main.cpp index 4730d3fa15..123ba904f4 100644 --- a/android/apps/questFramePlayer/src/main/cpp/main.cpp +++ b/android/apps/questFramePlayer/src/main/cpp/main.cpp @@ -11,30 +11,33 @@ #include #include #include +#include #include #include "PlayerWindow.h" +#include "AndroidHelper.h" + void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { if (!message.isEmpty()) { - const char * local=message.toStdString().c_str(); + const char* local = message.toStdString().c_str(); switch (type) { case QtDebugMsg: - __android_log_write(ANDROID_LOG_DEBUG,"Interface",local); + __android_log_write(ANDROID_LOG_DEBUG, "Interface", local); break; case QtInfoMsg: - __android_log_write(ANDROID_LOG_INFO,"Interface",local); + __android_log_write(ANDROID_LOG_INFO, "Interface", local); break; case QtWarningMsg: - __android_log_write(ANDROID_LOG_WARN,"Interface",local); + __android_log_write(ANDROID_LOG_WARN, "Interface", local); break; case QtCriticalMsg: - __android_log_write(ANDROID_LOG_ERROR,"Interface",local); + __android_log_write(ANDROID_LOG_ERROR, "Interface", local); break; case QtFatalMsg: default: - __android_log_write(ANDROID_LOG_FATAL,"Interface",local); + __android_log_write(ANDROID_LOG_FATAL, "Interface", local); abort(); } } @@ -46,11 +49,13 @@ int main(int argc, char** argv) { auto oldMessageHandler = qInstallMessageHandler(messageHandler); DependencyManager::set(); PlayerWindow window; - __android_log_write(ANDROID_LOG_FATAL,"QQQ","Exec"); + QTimer::singleShot(10, []{ + __android_log_write(ANDROID_LOG_WARN, "QQQ", "notifyLoadComplete"); + AndroidHelper::instance().notifyLoadComplete(); + }); + __android_log_write(ANDROID_LOG_WARN, "QQQ", "Exec"); app.exec(); - __android_log_write(ANDROID_LOG_FATAL,"QQQ","Exec done"); + __android_log_write(ANDROID_LOG_WARN, "QQQ", "Exec done"); qInstallMessageHandler(oldMessageHandler); return 0; } - - diff --git a/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestQtActivity.java b/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestQtActivity.java deleted file mode 100644 index 6fed737266..0000000000 --- a/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestQtActivity.java +++ /dev/null @@ -1,52 +0,0 @@ -// -// Created by Bradley Austin Davis on 2018/11/20 -// Copyright 2013-2018 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -package io.highfidelity.frameplayer; - -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; - -import org.qtproject.qt5.android.bindings.QtActivity; - -import io.highfidelity.oculus.OculusMobileActivity; - - -public class QuestQtActivity extends QtActivity { - private native void nativeOnCreate(); - private boolean launchedQuestMode = false; - - @Override - public void onCreate(Bundle savedInstanceState) { - Log.w("QQQ_Qt", "QuestQtActivity::onCreate"); - super.onCreate(savedInstanceState); - nativeOnCreate(); - } - - @Override - public void onDestroy() { - Log.w("QQQ_Qt", "QuestQtActivity::onDestroy"); - super.onDestroy(); - } - - public void launchOculusActivity() { - Log.w("QQQ_Qt", "QuestQtActivity::launchOculusActivity"); - runOnUiThread(()->{ - launchedQuestMode = true; - moveTaskToBack(true); - startActivity(new Intent(this, QuestRenderActivity.class)); - }); - } - - @Override - public void onResume() { - super.onResume(); - if (launchedQuestMode) { - moveTaskToBack(true); - } - } -} diff --git a/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestRenderActivity.java b/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestRenderActivity.java index a395a32b68..9e7c0ab973 100644 --- a/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestRenderActivity.java +++ b/android/apps/questFramePlayer/src/main/java/io/highfidelity/frameplayer/QuestRenderActivity.java @@ -1,14 +1,6 @@ package io.highfidelity.frameplayer; -import android.content.Intent; -import android.os.Bundle; - import io.highfidelity.oculus.OculusMobileActivity; public class QuestRenderActivity extends OculusMobileActivity { - @Override - public void onCreate(Bundle savedState) { - super.onCreate(savedState); - startActivity(new Intent(this, QuestQtActivity.class)); - } } diff --git a/android/apps/questInterface/src/main/AndroidManifest.xml b/android/apps/questInterface/src/main/AndroidManifest.xml index a5029382cb..a5de47bdce 100644 --- a/android/apps/questInterface/src/main/AndroidManifest.xml +++ b/android/apps/questInterface/src/main/AndroidManifest.xml @@ -33,7 +33,7 @@ diff --git a/android/apps/questInterface/src/main/java/io/highfidelity/questInterface/InterfaceActivitiy.java b/android/apps/questInterface/src/main/java/io/highfidelity/questInterface/InterfaceActivitiy.java new file mode 100644 index 0000000000..3fe4bbc5d2 --- /dev/null +++ b/android/apps/questInterface/src/main/java/io/highfidelity/questInterface/InterfaceActivitiy.java @@ -0,0 +1,11 @@ +package io.highfidelity.questInterface; + +import io.highfidelity.oculus.OculusMobileActivity; + +public class InterfaceActivity extends OculusMobileActivity { + @Override + public void onCreate(Bundle savedInstanceState) { + HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath()); + super.onCreate(savedInstanceState); + } +} diff --git a/android/libraries/oculus/build.gradle b/android/libraries/oculus/build.gradle index 776c0c1e48..f31efcfe95 100644 --- a/android/libraries/oculus/build.gradle +++ b/android/libraries/oculus/build.gradle @@ -17,5 +17,5 @@ android { } dependencies { - compile project(path: ':qt') + implementation project(path: ':qt') } diff --git a/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java b/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java index cc71ba53a8..9ab07bb4dd 100644 --- a/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java +++ b/android/libraries/oculus/src/main/java/io/highfidelity/oculus/OculusMobileActivity.java @@ -40,7 +40,6 @@ public class OculusMobileActivity extends QtActivity implements SurfaceHolder.Ca public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - HifiUtils.upackAssets(getAssets(), getCacheDir().getAbsolutePath()); Log.w(TAG, "QQQ onCreate"); // Create a native surface for VR rendering (Qt GL surfaces are not suitable diff --git a/libraries/gpu/src/gpu/FrameReader.cpp b/libraries/gpu/src/gpu/FrameReader.cpp index 6e39a38097..2fe143ee90 100644 --- a/libraries/gpu/src/gpu/FrameReader.cpp +++ b/libraries/gpu/src/gpu/FrameReader.cpp @@ -388,10 +388,23 @@ ShaderPointer Deserializer::readShader(const json& node) { return nullptr; } + static std::map shadersIdsByName; + if (shadersIdsByName.empty()) { + for (const auto id : shader::allShaders()) { + const auto& shaderSource = shader::Source::get(id); + shadersIdsByName[shaderSource.name] = id; + } + } + // FIXME support procedural shaders Shader::Type type = node[keys::type]; std::string name = node[keys::name]; - uint32_t id = node[keys::id]; + // Using the serialized ID is bad, because it's generated at + // cmake time, and can change across platforms or when + // shaders are added or removed + // uint32_t id = node[keys::id]; + + uint32_t id = shadersIdsByName[name]; ShaderPointer result; switch (type) { //case Shader::Type::GEOMETRY: