diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-06-28 16:32:00 -0700 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-07-18 10:45:12 +0200 |
commit | ee205ca9ca3f808fa2cc16295ebde0a7c3867381 (patch) | |
tree | f66be15105c449570eebe846723596a5dbaf9d99 | |
parent | 2e9fb06941720f7cc22fa8d8d54aa2d0b3fd71c0 (diff) | |
download | qtlocation-mapboxgl-ee205ca9ca3f808fa2cc16295ebde0a7c3867381.tar.gz |
[qt] rendering interface changes
-rw-r--r-- | platform/qt/qt.cmake | 2 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 22 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_p.hpp | 9 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_renderer_frontend_p.cpp | 32 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl_renderer_frontend_p.hpp | 35 |
5 files changed, 96 insertions, 4 deletions
diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index c8567bc2f3..0e9bbbb576 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -67,6 +67,8 @@ add_library(qmapboxgl SHARED platform/qt/src/qmapbox.cpp platform/qt/src/qmapboxgl.cpp platform/qt/src/qmapboxgl_p.hpp + platform/qt/src/qmapboxgl_renderer_frontend_p.hpp + platform/qt/src/qmapboxgl_renderer_frontend_p.cpp platform/default/mbgl/util/default_styles.hpp ) diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index ee08ba5730..aa02900c95 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1,5 +1,6 @@ #include "qmapboxgl.hpp" #include "qmapboxgl_p.hpp" +#include "qmapboxgl_renderer_frontend_p.hpp" #include "qt_conversion.hpp" #include "qt_geojson.hpp" @@ -17,6 +18,7 @@ #include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/image.hpp> +#include <mbgl/renderer/renderer.hpp> #include <mbgl/storage/network_status.hpp> #include <mbgl/util/color.hpp> #include <mbgl/util/constants.hpp> @@ -1448,7 +1450,7 @@ void QMapboxGL::render() mbgl::BackendScope scope { *d_ptr, mbgl::BackendScope::ScopeType::Implicit }; d_ptr->dirty = false; - d_ptr->mapObj->render(*d_ptr); + d_ptr->render(); } /*! @@ -1487,6 +1489,8 @@ void QMapboxGL::connectionEstablished() \a copyrightsHtml is a string with a HTML snippet. */ +class QMapboxGLRendererFrontend; + QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings, const QSize &size_, qreal pixelRatio) : QObject(q) , size(size_) @@ -1497,11 +1501,18 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin settings.cacheDatabaseMaximumSize())) , threadPool(mbgl::sharedThreadPool()) { + // Setup and connect the renderer frontend + frontend = std::make_unique<QMapboxGLRendererFrontend>( + std::make_unique<mbgl::Renderer>(*this, pixelRatio, *fileSourceObj, *threadPool, + static_cast<mbgl::GLContextMode>(settings.contextMode())), + *this); + connect(frontend.get(), SIGNAL(updated()), this, SLOT(invalidate())); + mapObj = std::make_unique<mbgl::Map>( - *this, *this, sanitizedSize(size), + *frontend, + *this, sanitizedSize(size), pixelRatio, *fileSourceObj, *threadPool, mbgl::MapMode::Continuous, - static_cast<mbgl::GLContextMode>(settings.contextMode()), static_cast<mbgl::ConstrainMode>(settings.constrainMode()), static_cast<mbgl::ViewportMode>(settings.viewportMode())); @@ -1541,6 +1552,11 @@ void QMapboxGLPrivate::invalidate() } } +void QMapboxGLPrivate::render() +{ + frontend->render(); +} + void QMapboxGLPrivate::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) { if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) { diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp index d89234531b..b9c1124551 100644 --- a/platform/qt/src/qmapboxgl_p.hpp +++ b/platform/qt/src/qmapboxgl_p.hpp @@ -1,6 +1,7 @@ #pragma once #include "qmapboxgl.hpp" +#include "qmapboxgl_renderer_frontend_p.hpp" #include <mbgl/map/map.hpp> #include <mbgl/map/backend.hpp> @@ -22,14 +23,17 @@ public: mbgl::Size framebufferSize() const; + // mbgl::View implementation. void bind() final; // mbgl::Backend implementation. void updateAssumedState() final; - void invalidate() final; void activate() final {} void deactivate() final {} + mbgl::BackendScope::ScopeType getScopeType() const final { + return mbgl::BackendScope::ScopeType::Implicit; + } // mbgl::MapObserver implementation. void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) final; @@ -55,6 +59,7 @@ public: std::shared_ptr<mbgl::DefaultFileSource> fileSourceObj; std::shared_ptr<mbgl::ThreadPool> threadPool; std::unique_ptr<mbgl::Map> mapObj; + std::unique_ptr<QMapboxGLRendererFrontend> frontend; bool dirty { false }; @@ -63,6 +68,8 @@ private: public slots: void connectionEstablished(); + void invalidate(); + void render(); signals: void needsRendering(); diff --git a/platform/qt/src/qmapboxgl_renderer_frontend_p.cpp b/platform/qt/src/qmapboxgl_renderer_frontend_p.cpp new file mode 100644 index 0000000000..836a9431b8 --- /dev/null +++ b/platform/qt/src/qmapboxgl_renderer_frontend_p.cpp @@ -0,0 +1,32 @@ +#include "qmapboxgl_renderer_frontend_p.hpp" + +#include <mbgl/map/backend_scope.hpp> +#include <mbgl/renderer/renderer.hpp> + +QMapboxGLRendererFrontend::QMapboxGLRendererFrontend(std::unique_ptr<mbgl::Renderer> renderer_, mbgl::View& view_) + : renderer(std::move(renderer_)) + , view(view_) { +} + +QMapboxGLRendererFrontend::~QMapboxGLRendererFrontend() = default; + +void QMapboxGLRendererFrontend::reset() { + if (renderer) { + renderer.reset(); + } +} + +void QMapboxGLRendererFrontend::update(std::shared_ptr<mbgl::UpdateParameters> updateParameters_) { + updateParameters = updateParameters_; + emit updated(); +} + +void QMapboxGLRendererFrontend::setObserver(mbgl::RendererObserver& observer_) { + if (!renderer) return; + renderer->setObserver(&observer_); +} + +void QMapboxGLRendererFrontend::render() { + if (!renderer || !updateParameters) return; + renderer->render(view, *updateParameters); +} diff --git a/platform/qt/src/qmapboxgl_renderer_frontend_p.hpp b/platform/qt/src/qmapboxgl_renderer_frontend_p.hpp new file mode 100644 index 0000000000..0a0546042a --- /dev/null +++ b/platform/qt/src/qmapboxgl_renderer_frontend_p.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include <mbgl/renderer/renderer_frontend.hpp> + +#include <QObject> + +namespace mbgl { + class View; + class Renderer; +} // namespace mbgl + +class QMapboxGLRendererFrontend : public QObject, public mbgl::RendererFrontend +{ + Q_OBJECT + +public: + explicit QMapboxGLRendererFrontend(std::unique_ptr<mbgl::Renderer>, mbgl::View&); + ~QMapboxGLRendererFrontend() override; + + void reset() override; + void setObserver(mbgl::RendererObserver&) override; + + void update(std::shared_ptr<mbgl::UpdateParameters>) override; + +public slots: + void render(); + +signals: + void updated(); + +private: + std::unique_ptr<mbgl::Renderer> renderer; + mbgl::View& view; + std::shared_ptr<mbgl::UpdateParameters> updateParameters; +}; |