[Qt] Share the same RunLoop if in the same thread
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <mbgl/storage/network_status.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/traits.hpp>
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
@@ -23,6 +24,7 @@
|
||||
#include <QMargins>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QThreadStorage>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -67,6 +69,12 @@ static_assert(mbgl::underlying_type(QMapboxGL::MapChangeWillStartRenderingMap) =
|
||||
static_assert(mbgl::underlying_type(QMapboxGL::MapChangeDidFinishRenderingMap) == mbgl::underlying_type(mbgl::MapChangeDidFinishRenderingMap), "error");
|
||||
static_assert(mbgl::underlying_type(QMapboxGL::MapChangeDidFinishRenderingMapFullyRendered) == mbgl::underlying_type(mbgl::MapChangeDidFinishRenderingMapFullyRendered), "error");
|
||||
|
||||
namespace {
|
||||
|
||||
QThreadStorage<std::shared_ptr<mbgl::util::RunLoop>> loop;
|
||||
|
||||
}
|
||||
|
||||
QMapboxGLSettings::QMapboxGLSettings()
|
||||
: m_mapMode(QMapboxGLSettings::ContinuousMap)
|
||||
, m_contextMode(QMapboxGLSettings::SharedGLContext)
|
||||
@@ -159,8 +167,14 @@ void QMapboxGLSettings::setAccessToken(const QString &token)
|
||||
|
||||
QMapboxGL::QMapboxGL(QObject *parent_, const QMapboxGLSettings &settings)
|
||||
: QObject(parent_)
|
||||
, d_ptr(new QMapboxGLPrivate(this, settings))
|
||||
{
|
||||
// Multiple QMapboxGL running on the same thread
|
||||
// will share the same mbgl::util::RunLoop
|
||||
if (!loop.hasLocalData()) {
|
||||
loop.setLocalData(std::make_shared<mbgl::util::RunLoop>());
|
||||
}
|
||||
|
||||
d_ptr = new QMapboxGLPrivate(this, settings);
|
||||
}
|
||||
|
||||
QMapboxGL::~QMapboxGL()
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <QMapboxGL>
|
||||
#include <QObject>
|
||||
@@ -34,8 +33,6 @@ public:
|
||||
|
||||
QMapboxGL *q_ptr = nullptr;
|
||||
|
||||
mbgl::util::RunLoop loop;
|
||||
|
||||
std::unique_ptr<mbgl::DefaultFileSource> fileSourceObj;
|
||||
std::unique_ptr<mbgl::Map> mapObj;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user