diff options
author | Christian Strømme <christian.stromme@digia.com> | 2014-08-28 12:18:14 +0200 |
---|---|---|
committer | Christian Stromme <christian.stromme@digia.com> | 2014-09-26 23:44:42 +0200 |
commit | 8b0d9a16db7bcfb5d6439b8863aded5c583f9ed5 (patch) | |
tree | 5fca60950d6e7dba1f12f9ceda0e564965d35116 /src/plugins/platforms/android/androidjnimain.cpp | |
parent | c30687f519de47279a70c3eca95eec2191eddbb1 (diff) |
Android: Improve the foreign-window implementation
Adds:
- Improved geometry calculations (e.g, inside a parent)
- Change visibility
- proper stacking order. Native views now reserve the top of the stack
to ensure that they stay visible.
- React to application state changes.
Change-Id: I35de0396937fff37ffcd272c9a7d8e9873a91dfb
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/plugins/platforms/android/androidjnimain.cpp')
-rw-r--r-- | src/plugins/platforms/android/androidjnimain.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index be1fd49c0c..17a587b333 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -69,7 +69,6 @@ static AAssetManager *m_assetManager = Q_NULLPTR; static jobject m_resourcesObj = Q_NULLPTR; static jobject m_activityObject = Q_NULLPTR; static jmethodID m_createSurfaceMethodID = Q_NULLPTR; -static jmethodID m_insertNativeViewMethodID = Q_NULLPTR; static jmethodID m_setSurfaceGeometryMethodID = Q_NULLPTR; static jmethodID m_destroySurfaceMethodID = Q_NULLPTR; @@ -345,27 +344,24 @@ namespace QtAndroid int insertNativeView(jobject view, const QRect &geometry) { - QJNIEnvironmentPrivate env; - if (!env) - return 0; - m_surfacesMutex.lock(); const int surfaceId = m_surfaceId++; + m_surfaces[surfaceId] = Q_NULLPTR; // dummy m_surfacesMutex.unlock(); jint x = 0, y = 0, w = -1, h = -1; - if (!geometry.isNull()) { - x = geometry.x(); - y = geometry.y(); - w = std::max(geometry.width(), 1); - h = std::max(geometry.height(), 1); - } - - env->CallStaticVoidMethod(m_applicationClass, - m_insertNativeViewMethodID, - surfaceId, - view, - x, y, w, h); + if (!geometry.isNull()) + geometry.getRect(&x, &y, &w, &h); + + QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, + "insertNativeView", + "(ILandroid/view/View;IIII)V", + surfaceId, + view, + x, + y, + qMax(w, 1), + qMax(h, 1)); return surfaceId; } @@ -539,6 +535,9 @@ static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, { QMutexLocker lock(&m_surfacesMutex); const auto &it = m_surfaces.find(id); + if (it.value() == Q_NULLPTR) // This should never happen... + return; + if (it == m_surfaces.end()) { qWarning()<<"Can't find surface" << id; return; @@ -718,7 +717,6 @@ static int registerNatives(JNIEnv *env) } GET_AND_CHECK_STATIC_METHOD(m_createSurfaceMethodID, m_applicationClass, "createSurface", "(IZIIIII)V"); - GET_AND_CHECK_STATIC_METHOD(m_insertNativeViewMethodID, m_applicationClass, "insertNativeView", "(ILandroid/view/View;IIII)V"); GET_AND_CHECK_STATIC_METHOD(m_setSurfaceGeometryMethodID, m_applicationClass, "setSurfaceGeometry", "(IIIII)V"); GET_AND_CHECK_STATIC_METHOD(m_destroySurfaceMethodID, m_applicationClass, "destroySurface", "(I)V"); |