summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-03-29 16:49:52 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-03-29 17:25:30 -0700
commit46383bb4ee64798cecff42baea5f565c8a8148a0 (patch)
treebf61adcf12695ee00f05bfe034f9e36733edede8
parent6bca0f0ff15d1c52e004f20bcc7b593a7217576d (diff)
downloadqtlocation-mapboxgl-46383bb4ee64798cecff42baea5f565c8a8148a0.tar.gz
[qt] Implement CustomLayerHost using a forwarding wrapper.
-rw-r--r--platform/qt/include/qmapbox.hpp12
-rw-r--r--platform/qt/include/qmapboxgl.hpp5
-rw-r--r--platform/qt/src/qmapbox.cpp22
-rw-r--r--platform/qt/src/qmapboxgl.cpp43
4 files changed, 44 insertions, 38 deletions
diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp
index 5a5198108c..369890343f 100644
--- a/platform/qt/include/qmapbox.hpp
+++ b/platform/qt/include/qmapbox.hpp
@@ -112,12 +112,16 @@ struct Q_MAPBOXGL_EXPORT CustomLayerRenderParameters {
double zoom;
double bearing;
double pitch;
- double altitude;
+ double fieldOfView;
};
-typedef void (*CustomLayerInitializeFunction)(void* context) ;
-typedef void (*CustomLayerRenderFunction)(void* context, const CustomLayerRenderParameters&);
-typedef void (*CustomLayerDeinitializeFunction)(void* context);
+class Q_MAPBOXGL_EXPORT CustomLayerHostInterface {
+public:
+ virtual ~CustomLayerHostInterface() = default;
+ virtual void initialize() = 0;
+ virtual void render(const CustomLayerRenderParameters&) = 0;
+ virtual void deinitialize() = 0;
+};
} // namespace QMapbox
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index bc18eaba59..70fe270902 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -223,10 +223,7 @@ public:
void removeImage(const QString &name);
void addCustomLayer(const QString &id,
- QMapbox::CustomLayerInitializeFunction,
- QMapbox::CustomLayerRenderFunction,
- QMapbox::CustomLayerDeinitializeFunction,
- void* context,
+ QScopedPointer<QMapbox::CustomLayerHostInterface>& host,
const QString& before = QString());
void addLayer(const QVariantMap &params, const QString& before = QString());
bool layerExists(const QString &id);
diff --git a/platform/qt/src/qmapbox.cpp b/platform/qt/src/qmapbox.cpp
index ec76ebfe53..87a9358772 100644
--- a/platform/qt/src/qmapbox.cpp
+++ b/platform/qt/src/qmapbox.cpp
@@ -158,27 +158,9 @@ namespace QMapbox {
*/
/*!
- \typedef QMapbox::CustomLayerDeinitializeFunction
+ \class QMapbox::CustomLayerHostInterface
- Represents a callback to be called when destroying a custom layer.
-
- \warning This is used for delegating the rendering of a layer to the user of
- this API and is not officially supported. Use at your own risk.
-*/
-
-/*!
- \typedef QMapbox::CustomLayerInitializeFunction
-
- Represents a callback to be called when initializing a custom layer.
-
- \warning This is used for delegating the rendering of a layer to the user of
- this API and is not officially supported. Use at your own risk.
-*/
-
-/*!
- \typedef QMapbox::CustomLayerRenderFunction
-
- Represents a callback to be called on each render pass for a custom layer.
+ Represents a host interface to be implemented for rendering custom layers.
\warning This is used for delegating the rendering of a layer to the user of
this API and is not officially supported. Use at your own risk.
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 414b65255c..2e736c0aa2 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1343,20 +1343,43 @@ void QMapboxGL::removeSource(const QString& id)
this API and is not officially supported. Use at your own risk.
*/
void QMapboxGL::addCustomLayer(const QString &id,
- QMapbox::CustomLayerInitializeFunction initFn,
- QMapbox::CustomLayerRenderFunction renderFn,
- QMapbox::CustomLayerDeinitializeFunction deinitFn,
- void *context,
+ QScopedPointer<QMapbox::CustomLayerHostInterface>& host,
const QString& before)
{
+ class HostWrapper : public mbgl::style::CustomLayerHost {
+ public:
+ QScopedPointer<QMapbox::CustomLayerHostInterface> ptr;
+ HostWrapper(QScopedPointer<QMapbox::CustomLayerHostInterface>& p)
+ : ptr(p.take()) {
+ }
+
+ void initialize() {
+ ptr->initialize();
+ }
+
+ void render(const mbgl::style::CustomLayerRenderParameters& params) {
+ QMapbox::CustomLayerRenderParameters renderParams;
+ renderParams.width = params.width;
+ renderParams.height = params.height;
+ renderParams.latitude = params.latitude;
+ renderParams.longitude = params.longitude;
+ renderParams.zoom = params.zoom;
+ renderParams.bearing = params.bearing;
+ renderParams.pitch = params.pitch;
+ renderParams.fieldOfView = params.fieldOfView;
+ ptr->render(renderParams);
+ }
+
+ void contextLost() { }
+
+ void deinitialize() {
+ ptr->deinitialize();
+ }
+ };
+
d_ptr->mapObj->getStyle().addLayer(std::make_unique<mbgl::style::CustomLayer>(
id.toStdString(),
- reinterpret_cast<mbgl::style::CustomLayerInitializeFunction>(initFn),
- // This cast is safe as long as both mbgl:: and QMapbox::
- // CustomLayerRenderParameters members remains the same.
- (mbgl::style::CustomLayerRenderFunction)renderFn,
- reinterpret_cast<mbgl::style::CustomLayerDeinitializeFunction>(deinitFn),
- context),
+ std::make_unique<HostWrapper>(host)),
before.isEmpty() ? mbgl::optional<std::string>() : mbgl::optional<std::string>(before.toStdString()));
}