summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2018-01-24 23:17:25 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2018-02-09 20:28:54 +0200
commita062f3e17b6f42252a283b50bd36de3411571b7d (patch)
treeaea1942a1450aca9be73d827d61b38729182ced0 /platform
parente7e8cb4547aff3d7fe2e9c1fb04e82bfb2a7dc47 (diff)
downloadqtlocation-mapboxgl-a062f3e17b6f42252a283b50bd36de3411571b7d.tar.gz
[qt] Update map rendering via RendererObserver
Diffstat (limited to 'platform')
-rw-r--r--platform/qt/src/qmapboxgl.cpp18
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.cpp5
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.hpp2
-rw-r--r--platform/qt/src/qmapboxgl_p.hpp8
-rw-r--r--platform/qt/src/qmapboxgl_renderer_observer.hpp51
5 files changed, 81 insertions, 3 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index af94eb9f71..cf6be2c9a7 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -2,6 +2,7 @@
#include "qmapboxgl_p.hpp"
#include "qmapboxgl_map_observer.hpp"
+#include "qmapboxgl_renderer_observer.hpp"
#include "qt_conversion.hpp"
#include "qt_geojson.hpp"
@@ -1486,6 +1487,7 @@ void QMapboxGL::render()
}
#endif
+ d_ptr->renderQueued.clear();
d_ptr->mapRenderer->render();
}
@@ -1567,7 +1569,8 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
static_cast<mbgl::ViewportMode>(settings.viewportMode()));
- connect(this, SIGNAL(needsRendering()), q_ptr, SIGNAL(needsRendering()));
+ // Needs to be Queued to give time to discard redundant draw calls via the `renderQueued` flag.
+ connect(this, SIGNAL(needsRendering()), q_ptr, SIGNAL(needsRendering()), Qt::QueuedConnection);
}
QMapboxGLPrivate::~QMapboxGLPrivate()
@@ -1577,5 +1580,16 @@ QMapboxGLPrivate::~QMapboxGLPrivate()
void QMapboxGLPrivate::update(std::shared_ptr<mbgl::UpdateParameters> parameters)
{
mapRenderer->updateParameters(std::move(parameters));
- emit needsRendering();
+
+ if (!renderQueued.test_and_set()) {
+ emit needsRendering();
+ }
+}
+
+void QMapboxGLPrivate::setObserver(mbgl::RendererObserver &observer)
+{
+ m_rendererObserver = std::make_shared<QMapboxGLRendererObserver>(
+ *mbgl::util::RunLoop::Get(), observer);
+
+ mapRenderer->setObserver(m_rendererObserver);
}
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp
index c0293c2079..a343d56668 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.cpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.cpp
@@ -41,3 +41,8 @@ void QMapboxGLMapRenderer::render()
m_renderer->render(*params);
}
+
+void QMapboxGLMapRenderer::setObserver(std::shared_ptr<mbgl::RendererObserver> observer)
+{
+ m_renderer->setObserver(observer.get());
+}
diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp
index d0c70b97ca..5769432f0f 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.hpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.hpp
@@ -5,6 +5,7 @@
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/renderer/renderer_backend.hpp>
+#include <mbgl/renderer/renderer_observer.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/shared_thread_pool.hpp>
@@ -26,6 +27,7 @@ public:
virtual ~QMapboxGLMapRenderer();
void render();
+ void setObserver(std::shared_ptr<mbgl::RendererObserver>);
// Thread-safe, called by the Frontend
void updateParameters(std::shared_ptr<mbgl::UpdateParameters>);
diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp
index 55377eb51e..b9a4b37ae5 100644
--- a/platform/qt/src/qmapboxgl_p.hpp
+++ b/platform/qt/src/qmapboxgl_p.hpp
@@ -15,6 +15,7 @@
#include <QObject>
#include <QSize>
+#include <atomic>
#include <memory>
class QMapboxGLPrivate : public QObject, public mbgl::RendererFrontend
@@ -27,7 +28,7 @@ public:
// mbgl::RendererFrontend implementation.
void reset() final {}
- void setObserver(mbgl::RendererObserver &) final {}
+ void setObserver(mbgl::RendererObserver &) final;
void update(std::shared_ptr<mbgl::UpdateParameters>) final;
mbgl::EdgeInsets margins;
@@ -40,7 +41,12 @@ public:
std::unique_ptr<QMapboxGLMapObserver> mapObserver;
std::unique_ptr<QMapboxGLMapRenderer> mapRenderer;
+ std::shared_ptr<mbgl::RendererObserver> rendererObserver;
+ QMapboxGLSettings::GLContextMode mode;
+ qreal pixelRatio;
+
+ std::atomic_flag renderQueued = ATOMIC_FLAG_INIT;
signals:
void needsRendering();
diff --git a/platform/qt/src/qmapboxgl_renderer_observer.hpp b/platform/qt/src/qmapboxgl_renderer_observer.hpp
new file mode 100644
index 0000000000..ee340113ff
--- /dev/null
+++ b/platform/qt/src/qmapboxgl_renderer_observer.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include <mbgl/actor/actor.hpp>
+#include <mbgl/actor/actor_ref.hpp>
+#include <mbgl/actor/mailbox.hpp>
+#include <mbgl/renderer/renderer_observer.hpp>
+#include <mbgl/util/run_loop.hpp>
+
+#include <memory>
+
+// Forwards RendererObserver signals to the given
+// Delegate RendererObserver on the given RunLoop
+class QMapboxGLRendererObserver : public mbgl::RendererObserver {
+public:
+ QMapboxGLRendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_)
+ : mailbox(std::make_shared<mbgl::Mailbox>(mapRunLoop))
+ , delegate(delegate_, mailbox) {
+ }
+
+ ~QMapboxGLRendererObserver() {
+ mailbox->close();
+ }
+
+ void onInvalidate() final {
+ delegate.invoke(&mbgl::RendererObserver::onInvalidate);
+ }
+
+ void onResourceError(std::exception_ptr err) final {
+ delegate.invoke(&mbgl::RendererObserver::onResourceError, err);
+ }
+
+ void onWillStartRenderingMap() final {
+ delegate.invoke(&mbgl::RendererObserver::onWillStartRenderingMap);
+ }
+
+ void onWillStartRenderingFrame() final {
+ delegate.invoke(&mbgl::RendererObserver::onWillStartRenderingFrame);
+ }
+
+ void onDidFinishRenderingFrame(RenderMode mode, bool repaintNeeded) final {
+ delegate.invoke(&mbgl::RendererObserver::onDidFinishRenderingFrame, mode, repaintNeeded);
+ }
+
+ void onDidFinishRenderingMap() final {
+ delegate.invoke(&mbgl::RendererObserver::onDidFinishRenderingMap);
+ }
+
+private:
+ std::shared_ptr<mbgl::Mailbox> mailbox;
+ mbgl::ActorRef<mbgl::RendererObserver> delegate;
+};