summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@digia.com>2014-02-04 11:30:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-14 00:34:25 +0100
commit539196689e806f8c175bb50343a4dc2cab52e838 (patch)
tree8ec129220be28e3297f00a8c292b8c85bc35796e /src/plugins
parent4ce43b565f388c9327cb671887a4730225327006 (diff)
Android: Add Foreign Window support
Change-Id: Ie41edd3f17214805673311a375191cd93d2378f6 Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/android/android.pro6
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp29
-rw-r--r--src/plugins/platforms/android/androidjnimain.h1
-rw-r--r--src/plugins/platforms/android/qandroidplatformforeignwindow.cpp70
-rw-r--r--src/plugins/platforms/android/qandroidplatformforeignwindow.h61
-rw-r--r--src/plugins/platforms/android/qandroidplatformintegration.cpp6
6 files changed, 170 insertions, 3 deletions
diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro
index 4d873dd986..243eea071a 100644
--- a/src/plugins/platforms/android/android.pro
+++ b/src/plugins/platforms/android/android.pro
@@ -47,7 +47,8 @@ SOURCES += $$PWD/androidplatformplugin.cpp \
$$PWD/qandroidplatformopenglwindow.cpp \
$$PWD/qandroidplatformrasterwindow.cpp \
$$PWD/qandroidplatformbackingstore.cpp \
- $$PWD/qandroidplatformopenglcontext.cpp
+ $$PWD/qandroidplatformopenglcontext.cpp \
+ $$PWD/qandroidplatformforeignwindow.cpp
HEADERS += $$PWD/qandroidplatformintegration.h \
$$PWD/androidjnimain.h \
@@ -73,7 +74,8 @@ HEADERS += $$PWD/qandroidplatformintegration.h \
$$PWD/qandroidplatformopenglwindow.h \
$$PWD/qandroidplatformrasterwindow.h \
$$PWD/qandroidplatformbackingstore.h \
- $$PWD/qandroidplatformopenglcontext.h
+ $$PWD/qandroidplatformopenglcontext.h \
+ $$PWD/qandroidplatformforeignwindow.h
#Non-standard install directory, QTBUG-29859
DESTDIR = $$DESTDIR/android
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index 76129319c5..337e7419aa 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -84,6 +84,7 @@ static AAssetManager *m_assetManager = NULL;
static jobject m_resourcesObj;
static jobject m_activityObject = NULL;
static jmethodID m_createSurfaceMethodID = 0;
+static jmethodID m_insertNativeViewMethodID = 0;
static jmethodID m_setSurfaceGeometryMethodID = 0;
static jmethodID m_destroySurfaceMethodID = 0;
@@ -359,6 +360,33 @@ namespace QtAndroid
return surfaceId;
}
+ int insertNativeView(jobject view, const QRect &geometry)
+ {
+ QJNIEnvironmentPrivate env;
+ if (!env)
+ return 0;
+
+ m_surfacesMutex.lock();
+ const int surfaceId = m_surfaceId++;
+ 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);
+
+ return surfaceId;
+ }
+
void setSurfaceGeometry(int surfaceId, const QRect &geometry)
{
QJNIEnvironmentPrivate env;
@@ -653,6 +681,7 @@ static int registerNatives(JNIEnv *env)
}
GET_AND_CHECK_STATIC_METHOD(m_createSurfaceMethodID, m_applicationClass, "createSurface", "(IZIIII)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");
diff --git a/src/plugins/platforms/android/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h
index eb8dd87ae0..eb604c8da8 100644
--- a/src/plugins/platforms/android/androidjnimain.h
+++ b/src/plugins/platforms/android/androidjnimain.h
@@ -67,6 +67,7 @@ namespace QtAndroid
int createSurface(AndroidSurfaceClient * client, const QRect &geometry, bool onTop);
+ int insertNativeView(jobject view, const QRect &geometry);
void setSurfaceGeometry(int surfaceId, const QRect &geometry);
void destroySurface(int surfaceId);
diff --git a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp
new file mode 100644
index 0000000000..e6f9acb2c9
--- /dev/null
+++ b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qandroidplatformforeignwindow.h"
+#include "androidjnimain.h"
+#include <QtCore/qvariant.h>
+
+QAndroidPlatformForeignWindow::QAndroidPlatformForeignWindow(QWindow *window)
+ : QAndroidPlatformWindow(window)
+{
+ const WId wId = window->property("_q_foreignWinId").value<WId>();
+ if (wId) {
+ m_view = reinterpret_cast<jobject>(wId);
+ Q_ASSERT(m_view.isValid());
+ m_surfaceId = QtAndroid::insertNativeView(m_view.object(), geometry());
+ }
+}
+
+QAndroidPlatformForeignWindow::~QAndroidPlatformForeignWindow()
+{
+ if (m_surfaceId != -1)
+ QtAndroid::destroySurface(m_surfaceId);
+}
+
+void QAndroidPlatformForeignWindow::setGeometry(const QRect &rect)
+{
+ if (rect == geometry())
+ return;
+
+ QAndroidPlatformWindow::setGeometry(rect);
+ QtAndroid::setSurfaceGeometry(m_surfaceId, rect);
+}
diff --git a/src/plugins/platforms/android/qandroidplatformforeignwindow.h b/src/plugins/platforms/android/qandroidplatformforeignwindow.h
new file mode 100644
index 0000000000..88c87d0540
--- /dev/null
+++ b/src/plugins/platforms/android/qandroidplatformforeignwindow.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANDROIDPLATFORMFOREIGNWINDOW_H
+#define QANDROIDPLATFORMFOREIGNWINDOW_H
+
+#include "androidsurfaceclient.h"
+#include "qandroidplatformwindow.h"
+#include <QtCore/private/qjni_p.h>
+
+class QAndroidPlatformForeignWindow : public QAndroidPlatformWindow
+{
+public:
+ explicit QAndroidPlatformForeignWindow(QWindow *window);
+ ~QAndroidPlatformForeignWindow();
+ void setGeometry(const QRect &rect);
+
+private:
+ QJNIObjectPrivate m_view;
+ int m_surfaceId = -1;
+};
+
+#endif // QANDROIDPLATFORMFOREIGNWINDOW_H
diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp
index 3dc8632374..5848e94aca 100644
--- a/src/plugins/platforms/android/qandroidplatformintegration.cpp
+++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp
@@ -64,6 +64,7 @@
#include "qandroidplatformscreen.h"
#include "qandroidplatformtheme.h"
#include "qandroidsystemlocale.h"
+#include "qandroidplatformforeignwindow.h"
QT_BEGIN_NAMESPACE
@@ -148,6 +149,7 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const
case ApplicationState: return true;
case NativeWidgets: return true;
case OpenGL: return true;
+ case ForeignWindows: return true;
case ThreadedOpenGL:
if (needsWorkaround())
return false;
@@ -174,7 +176,9 @@ QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext
QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const
{
- if (window->surfaceType() == QSurface::RasterSurface)
+ if (window->type() == Qt::ForeignWindow)
+ return new QAndroidPlatformForeignWindow(window);
+ else if (window->surfaceType() == QSurface::RasterSurface)
return new QAndroidPlatformRasterWindow(window);
else
return new QAndroidPlatformOpenGLWindow(window, m_eglDisplay);