From b1e95681a9cf4aa3ca916208963714f4237b3c99 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 9 Jan 2018 23:30:31 -0800 Subject: [PATCH] Cleanup android --- android/app/src/main/cpp/native.cpp | 94 ++++++++++++++++++++- interface/src/Application.cpp | 8 +- interface/src/main.cpp | 94 --------------------- libraries/ui/src/OffscreenQmlElement.h | 4 +- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 3 +- 5 files changed, 99 insertions(+), 104 deletions(-) diff --git a/android/app/src/main/cpp/native.cpp b/android/app/src/main/cpp/native.cpp index 6725256feb..90d8d55af9 100644 --- a/android/app/src/main/cpp/native.cpp +++ b/android/app/src/main/cpp/native.cpp @@ -1,16 +1,106 @@ - #include +#include +#include #include +#include +#include +#include + #include #include #include #include +void tempMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { + if (!message.isEmpty()) { + const char * local=message.toStdString().c_str(); + switch (type) { + case QtDebugMsg: + __android_log_write(ANDROID_LOG_DEBUG,"Interface",local); + break; + case QtInfoMsg: + __android_log_write(ANDROID_LOG_INFO,"Interface",local); + break; + case QtWarningMsg: + __android_log_write(ANDROID_LOG_WARN,"Interface",local); + break; + case QtCriticalMsg: + __android_log_write(ANDROID_LOG_ERROR,"Interface",local); + break; + case QtFatalMsg: + default: + __android_log_write(ANDROID_LOG_FATAL,"Interface",local); + abort(); + } + } +} + +void unpackAndroidAssets() { + const QString SOURCE_PREFIX { "assets:/" }; + const QString DEST_PREFIX = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/"; + QStringList filesToCopy; + QString dateStamp; + { + QFile file("assets:/cache_assets.txt"); + if (!file.open(QIODevice::ReadOnly)) { + throw std::runtime_error("Failed to open cache file list"); + } + QTextStream in(&file); + dateStamp = DEST_PREFIX + "/" + in.readLine(); + while (!in.atEnd()) { + QString line = in.readLine(); + filesToCopy << line; + } + file.close(); + } + qDebug() << "Checking date stamp" << dateStamp; + + if (QFileInfo(dateStamp).exists()) { + return; + } + + auto rootDir = QDir::root(); + for (const auto& fileToCopy : filesToCopy) { + auto sourceFileName = SOURCE_PREFIX + fileToCopy; + auto destFileName = DEST_PREFIX + fileToCopy; + auto destFolder = QFileInfo(destFileName).absoluteDir(); + if (!destFolder.exists()) { + qDebug() << "Creating folder" << destFolder.absolutePath(); + if (!rootDir.mkpath(destFolder.absolutePath())) { + throw std::runtime_error("Error creating output path"); + } + } + if (QFile::exists(destFileName)) { + qDebug() << "Removing old file" << destFileName; + if (!QFile::remove(destFileName)) { + throw std::runtime_error("Failed to remove existing file"); + } + } + + qDebug() << "Copying from" << sourceFileName << "to" << destFileName; + if (!QFile(sourceFileName).copy(destFileName)) { + throw std::runtime_error("Failed to unpack cache files"); + } + } + + { + qDebug() << "Writing date stamp" << dateStamp; + QFile file(dateStamp); + if (file.open(QIODevice::ReadWrite)) { + QTextStream(&file) << "touch" << endl; + file.close(); + } + } +} + extern "C" { JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCreate(JNIEnv* env, jobject obj, jobject instance, jobject asset_mgr) { qDebug() << "nativeOnCreate On thread " << QThread::currentThreadId(); + auto oldMessageHandler = qInstallMessageHandler(tempMessageHandler); + unpackAndroidAssets(); + qInstallMessageHandler(oldMessageHandler); } JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnPause(JNIEnv* env, jobject obj) { @@ -26,3 +116,5 @@ JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnExit } } + + diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2d8a63c24d..caa1af0485 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2206,9 +2206,7 @@ void Application::initializeGL() { _chromiumShareContext->setObjectName("ChromiumShareContext"); _chromiumShareContext->create(_glWidget->qglContext()); _chromiumShareContext->makeCurrent(); - if (nsightActive()) { - qt_gl_set_global_share_context(_chromiumShareContext->getContext()); - } + qt_gl_set_global_share_context(_chromiumShareContext->getContext()); _glWidget->makeCurrent(); gpu::Context::init(); @@ -2342,11 +2340,7 @@ void Application::initializeUi() { offscreenUi->setProxyWindow(_window->windowHandle()); // OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to // support the window management and scripting proxies for VR use -#ifdef Q_OS_ANDROID offscreenUi->createDesktop(PathUtils::qmlBasePath() + "hifi/Desktop.qml"); -#else - offscreenUi->createDesktop(QString("hifi/Desktop.qml")); -#endif // FIXME either expose so that dialogs can set this themselves or // do better detection in the offscreen UI of what has focus offscreenUi->setNavigationFocused(false); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7f3ca122d6..5c07bebc23 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -31,10 +31,6 @@ #include "UserActivityLogger.h" #include "MainWindow.h" -#if defined(Q_OS_ANDROID) -#include -#endif - #ifdef HAS_BUGSPLAT #include #include @@ -46,90 +42,6 @@ extern "C" { } #endif -#if defined(Q_OS_ANDROID) -void tempMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { - if (!message.isEmpty()) { - const char * local=message.toStdString().c_str(); - switch (type) { - case QtDebugMsg: - __android_log_write(ANDROID_LOG_DEBUG,"Interface",local); - break; - case QtInfoMsg: - __android_log_write(ANDROID_LOG_INFO,"Interface",local); - break; - case QtWarningMsg: - __android_log_write(ANDROID_LOG_WARN,"Interface",local); - break; - case QtCriticalMsg: - __android_log_write(ANDROID_LOG_ERROR,"Interface",local); - break; - case QtFatalMsg: - default: - __android_log_write(ANDROID_LOG_FATAL,"Interface",local); - abort(); - } - } -} - -void unpackAndroidAssets() { - const QString SOURCE_PREFIX { "assets:/" }; - const QString DEST_PREFIX = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/"; - QStringList filesToCopy; - QString dateStamp; - { - QFile file("assets:/cache_assets.txt"); - if (!file.open(QIODevice::ReadOnly)) { - throw std::runtime_error("Failed to open cache file list"); - } - QTextStream in(&file); - dateStamp = DEST_PREFIX + "/" + in.readLine(); - while (!in.atEnd()) { - QString line = in.readLine(); - filesToCopy << line; - } - file.close(); - } - qDebug() << "Checking date stamp" << dateStamp; - - if (QFileInfo(dateStamp).exists()) { - return; - } - - auto rootDir = QDir::root(); - for (const auto& fileToCopy : filesToCopy) { - auto sourceFileName = SOURCE_PREFIX + fileToCopy; - auto destFileName = DEST_PREFIX + fileToCopy; - auto destFolder = QFileInfo(destFileName).absoluteDir(); - if (!destFolder.exists()) { - qDebug() << "Creating folder" << destFolder.absolutePath(); - if (!rootDir.mkpath(destFolder.absolutePath())) { - throw std::runtime_error("Error creating output path"); - } - } - if (QFile::exists(destFileName)) { - qDebug() << "Removing old file" << destFileName; - if (!QFile::remove(destFileName)) { - throw std::runtime_error("Failed to remove existing file"); - } - } - - qDebug() << "Copying from" << sourceFileName << "to" << destFileName; - if (!QFile(sourceFileName).copy(destFileName)) { - throw std::runtime_error("Failed to unpack cache files"); - } - } - - { - qDebug() << "Writing date stamp" << dateStamp; - QFile file(dateStamp); - if (file.open(QIODevice::ReadWrite)) { - QTextStream(&file) << "touch" << endl; - file.close(); - } - } -} -#endif - int main(int argc, const char* argv[]) { #if HAS_BUGSPLAT static QString BUG_SPLAT_DATABASE = "interface_alpha"; @@ -193,12 +105,6 @@ int main(int argc, const char* argv[]) { if (allowMultipleInstances) { instanceMightBeRunning = false; } - -#if defined(Q_OS_ANDROID) - qInstallMessageHandler(tempMessageHandler); - unpackAndroidAssets(); -#endif - // this needs to be done here in main, as the mechanism for setting the // scripts directory appears not to work. See the bug report // https://highfidelity.fogbugz.com/f/cases/5759/Issues-changing-scripts-directory-in-ScriptsEngine diff --git a/libraries/ui/src/OffscreenQmlElement.h b/libraries/ui/src/OffscreenQmlElement.h index 3597add964..4f0be9c572 100644 --- a/libraries/ui/src/OffscreenQmlElement.h +++ b/libraries/ui/src/OffscreenQmlElement.h @@ -13,6 +13,8 @@ #define hifi_OffscreenQmlElement_h #include + +#include class QQmlContext; #define HIFI_QML_DECL \ @@ -40,7 +42,7 @@ public: \ private: #define HIFI_QML_DEF(x) \ - const QUrl x::QML = QUrl("qrc:///qml/" #x ".qml"); \ + const QUrl x::QML = QUrl(PathUtils::qmlBasePath() + #x ".qml"); \ const QString x::NAME = #x; \ \ void x::registerType() { \ diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 97cc3426f2..902f91f9b8 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -548,6 +548,7 @@ void OffscreenQmlSurface::render() { PROFILE_RANGE(render_qml_gl, __FUNCTION__) _canvas->makeCurrent(); + _renderControl->sync(); _quickWindow->setRenderTarget(_fbo, QSize(_size.x, _size.y)); @@ -840,7 +841,7 @@ QQmlContext* OffscreenQmlSurface::contextForUrl(const QUrl& qmlSource, QQuickIte QQmlContext* targetContext = parent ? QQmlEngine::contextForObject(parent) : _qmlContext; if (!targetContext) { - targetContext = _qmlContext; + targetContext = _qmlContext; } if (_rootItem && forceNewContext) { targetContext = new QQmlContext(targetContext);