summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-06-14 16:21:02 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-22 08:04:39 -0700
commitbe7e9bbb8d54c775127f53d793c117c4bf5e2764 (patch)
tree2621c4aa950956af9e48205bda13960ac2ce8584 /src/mbgl/style
parente4201e207c3a6b33da64fdc2f9a00ec08586dc09 (diff)
downloadqtlocation-mapboxgl-be7e9bbb8d54c775127f53d793c117c4bf5e2764.tar.gz
[core] Refactor CustomLayer internals
Move the responsibility for initialization/deinitialization/rendering to RenderCustomLayer. This eliminates special case code from Map and Style.
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.cpp29
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.hpp5
-rw-r--r--src/mbgl/style/style.cpp19
3 files changed, 1 insertions, 52 deletions
diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp
index 10dd058861..42e60c582c 100644
--- a/src/mbgl/style/layers/custom_layer_impl.cpp
+++ b/src/mbgl/style/layers/custom_layer_impl.cpp
@@ -1,5 +1,4 @@
#include <mbgl/style/layers/custom_layer_impl.hpp>
-#include <mbgl/map/transform_state.hpp>
namespace mbgl {
namespace style {
@@ -23,33 +22,5 @@ bool CustomLayer::Impl::hasLayoutDifference(const Layer::Impl&) const {
void CustomLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
}
-void CustomLayer::Impl::initialize() const {
- assert(initializeFn);
- initializeFn(context);
-}
-
-void CustomLayer::Impl::deinitialize() const {
- if (deinitializeFn) {
- deinitializeFn(context);
- }
-}
-
-void CustomLayer::Impl::render(const TransformState& state) const {
- assert(renderFn);
-
- CustomLayerRenderParameters parameters;
-
- parameters.width = state.getSize().width;
- parameters.height = state.getSize().height;
- parameters.latitude = state.getLatLng().latitude();
- parameters.longitude = state.getLatLng().longitude();
- parameters.zoom = state.getZoom();
- parameters.bearing = -state.getAngle() * util::RAD2DEG;
- parameters.pitch = state.getPitch();
- parameters.fieldOfView = state.getFieldOfView();
-
- renderFn(context, parameters);
-}
-
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp
index 466d1f3e3f..defbbe6894 100644
--- a/src/mbgl/style/layers/custom_layer_impl.hpp
+++ b/src/mbgl/style/layers/custom_layer_impl.hpp
@@ -17,11 +17,6 @@ public:
CustomLayerDeinitializeFunction,
void* context);
- void initialize() const;
- void deinitialize() const;
- void render(const TransformState&) const;
-
-private:
bool hasLayoutDifference(const Layer::Impl&) const override;
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index d667ef656f..41b4310dcf 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -2,11 +2,8 @@
#include <mbgl/style/observer.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
-#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
-#include <mbgl/style/layers/custom_layer_impl.hpp>
#include <mbgl/style/layers/background_layer.hpp>
-#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
@@ -35,13 +32,7 @@ Style::Style(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio)
light->setObserver(this);
}
-Style::~Style() {
- for (const auto& layer : layers) {
- if (auto* customLayer = layer->as<CustomLayer>()) {
- customLayer->impl().deinitialize();
- }
- }
-}
+Style::~Style() = default;
void Style::setTransitionOptions(const TransitionOptions& options) {
transitionOptions = options;
@@ -153,10 +144,6 @@ Layer* Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> befor
throw std::runtime_error(std::string{"Layer "} + layer->getID() + " already exists");
}
- if (auto* customLayer = layer->as<CustomLayer>()) {
- customLayer->impl().initialize();
- }
-
layer->setObserver(this);
return layers.add(std::move(layer), before);
@@ -167,10 +154,6 @@ std::unique_ptr<Layer> Style::removeLayer(const std::string& id) {
if (layer) {
layer->setObserver(nullptr);
-
- if (auto* customLayer = layer->as<CustomLayer>()) {
- customLayer->impl().deinitialize();
- }
}
return layer;