Commit b2600341 authored by BogDan Vatra's avatar BogDan Vatra
Browse files

Android: Use the new QtAndroidPrivate::runOnAndroidThreadSync


Change-Id: I47cb99d84ad87f3b0f6578d3fbdc22d788b31c57
Reviewed-by: default avatarChristian Stromme <christian.stromme@theqtcompany.com>
Showing with 27 additions and 47 deletions
...@@ -137,8 +137,32 @@ AndroidSurfaceView::AndroidSurfaceView() ...@@ -137,8 +137,32 @@ AndroidSurfaceView::AndroidSurfaceView()
, m_surfaceHolder(0) , m_surfaceHolder(0)
, m_pendingVisible(-1) , m_pendingVisible(-1)
{ {
setAutoDelete(false); QtAndroidPrivate::runOnAndroidThreadSync([this] {
QtAndroidPrivate::runOnUiThread(this, QJNIEnvironmentPrivate()); m_surfaceView = QJNIObjectPrivate("android/view/SurfaceView",
"(Landroid/content/Context;)V",
QtAndroidPrivate::activity());
}, QJNIEnvironmentPrivate());
Q_ASSERT(m_surfaceView.isValid());
QJNIObjectPrivate holder = m_surfaceView.callObjectMethod("getHolder",
"()Landroid/view/SurfaceHolder;");
if (!holder.isValid()) {
m_surfaceView = QJNIObjectPrivate();
} else {
m_surfaceHolder = new AndroidSurfaceHolder(holder);
connect(m_surfaceHolder, &AndroidSurfaceHolder::surfaceCreated,
this, &AndroidSurfaceView::surfaceCreated);
{ // Lock now to avoid a race with handleSurfaceCreated()
QMutexLocker locker(shLock);
m_window = QWindow::fromWinId(WId(m_surfaceView.object()));
if (m_pendingVisible != -1)
m_window->setVisible(m_pendingVisible);
if (m_pendingGeometry.isValid())
m_window->setGeometry(m_pendingGeometry);
}
}
} }
AndroidSurfaceView::~AndroidSurfaceView() AndroidSurfaceView::~AndroidSurfaceView()
...@@ -168,43 +192,4 @@ void AndroidSurfaceView::setGeometry(int x, int y, int width, int height) ...@@ -168,43 +192,4 @@ void AndroidSurfaceView::setGeometry(int x, int y, int width, int height)
m_pendingGeometry = QRect(x, y, width, height); m_pendingGeometry = QRect(x, y, width, height);
} }
bool AndroidSurfaceView::event(QEvent *e)
{
if (e->type() == QEvent::User) {
Q_ASSERT(m_surfaceView.isValid());
QJNIObjectPrivate holder = m_surfaceView.callObjectMethod("getHolder",
"()Landroid/view/SurfaceHolder;");
if (!holder.isValid()) {
m_surfaceView = QJNIObjectPrivate();
} else {
m_surfaceHolder = new AndroidSurfaceHolder(holder);
connect(m_surfaceHolder, &AndroidSurfaceHolder::surfaceCreated,
this, &AndroidSurfaceView::surfaceCreated);
{ // Lock now to avoid a race with handleSurfaceCreated()
QMutexLocker locker(shLock);
m_window = QWindow::fromWinId(WId(m_surfaceView.object()));
if (m_pendingVisible != -1)
m_window->setVisible(m_pendingVisible);
if (m_pendingGeometry.isValid())
m_window->setGeometry(m_pendingGeometry);
}
}
return true;
}
return QObject::event(e);
}
// Called on the Android UI thread.
void AndroidSurfaceView::run()
{
m_surfaceView = QJNIObjectPrivate("android/view/SurfaceView",
"(Landroid/content/Context;)V",
QtAndroidPrivate::activity());
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
QT_END_NAMESPACE QT_END_NAMESPACE
...@@ -74,7 +74,7 @@ private: ...@@ -74,7 +74,7 @@ private:
friend class AndroidSurfaceView; friend class AndroidSurfaceView;
}; };
class AndroidSurfaceView : public QObject, public QRunnable class AndroidSurfaceView : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -86,14 +86,9 @@ public: ...@@ -86,14 +86,9 @@ public:
void setVisible(bool v); void setVisible(bool v);
void setGeometry(int x, int y, int width, int height); void setGeometry(int x, int y, int width, int height);
bool event(QEvent *);
Q_SIGNALS: Q_SIGNALS:
void surfaceCreated(); void surfaceCreated();
protected:
void run() override;
private: private:
QJNIObjectPrivate m_surfaceView; QJNIObjectPrivate m_surfaceView;
QWindow *m_window; QWindow *m_window;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment