summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2017-03-27 18:28:23 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-03-27 16:02:17 +0000
commit93d174d276d208434b6615d73a7e9c805ea48ff9 (patch)
treee6c9597751a11fb7e241662fddab216bb06df158 /src/plugins
parenta1fd7d5d663ae96a78fee5f6dfc332507df3771d (diff)
downloadqtlocation-93d174d276d208434b6615d73a7e9c805ea48ff9.tar.gz
Better battery usage on Mapbox GL plugin with threaded GL
Stop the refresh timer hack when all the resources are loaded so we don't keep waking up for re-drawing when it is not needed. Change-Id: Iada46850adf4fec04dc70c9d3f7263b71c325d8a Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp36
-rw-r--r--src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h2
2 files changed, 29 insertions, 9 deletions
diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp
index ea4209e8..74bea76a 100644
--- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp
+++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp
@@ -91,15 +91,6 @@ QSGNode *QGeoMapMapboxGLPrivate::updateSceneGraph(QSGNode *node, QQuickWindow *w
{
Q_Q(QGeoMapMapboxGL);
- if (!m_warned) {
- if (window->openglContext()->thread() != QCoreApplication::instance()->thread()) {
- qWarning() << "Threaded rendering is not supported by Mapbox GL plugin.";
- QMetaObject::invokeMethod(&m_refresh, "start", Qt::QueuedConnection);
- }
-
- m_warned = true;
- }
-
QMapboxGL *map = 0;
if (m_useFBO) {
if (!node) {
@@ -151,6 +142,8 @@ QSGNode *QGeoMapMapboxGLPrivate::updateSceneGraph(QSGNode *node, QQuickWindow *w
static_cast<QSGMapboxGLTextureNode *>(node)->render(window);
}
+ threadedRenderingHack(window, map);
+
m_syncState = NoSync;
return node;
@@ -278,6 +271,31 @@ void QGeoMapMapboxGLPrivate::syncStyleChanges(QMapboxGL *map)
m_styleChanges.clear();
}
+void QGeoMapMapboxGLPrivate::threadedRenderingHack(QQuickWindow *window, QMapboxGL *map)
+{
+ // FIXME: Optimal support for threaded rendering needs core changes
+ // in Mapbox GL Native. Meanwhile we need to set a timer to update
+ // the map until all the resources are loaded, which is not exactly
+ // battery friendly, because might trigger more paints than we need.
+ if (!m_warned) {
+ m_threadedRendering = window->openglContext()->thread() != QCoreApplication::instance()->thread();
+
+ if (m_threadedRendering) {
+ qWarning() << "Threaded rendering is not optimal in the Mapbox GL plugin.";
+ }
+
+ m_warned = true;
+ }
+
+ if (m_threadedRendering) {
+ if (!map->isFullyLoaded()) {
+ QMetaObject::invokeMethod(&m_refresh, "start", Qt::QueuedConnection);
+ } else {
+ QMetaObject::invokeMethod(&m_refresh, "stop", Qt::QueuedConnection);
+ }
+ }
+}
+
/*
* QGeoMapMapboxGL implementation
*/
diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h
index b6527c01..15e5d167 100644
--- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h
+++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h
@@ -83,6 +83,7 @@ public:
QTimer m_refresh;
bool m_shouldRefresh = true;
bool m_warned = false;
+ bool m_threadedRendering = false;
bool m_styleLoaded = false;
SyncStates m_syncState = NoSync;
@@ -98,6 +99,7 @@ private:
Q_DISABLE_COPY(QGeoMapMapboxGLPrivate);
void syncStyleChanges(QMapboxGL *map);
+ void threadedRenderingHack(QQuickWindow *window, QMapboxGL *map);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QGeoMapMapboxGLPrivate::SyncStates)