diff options
-rw-r--r-- | include/mbgl/style/conversion/light.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/light.hpp | 15 | ||||
-rw-r--r-- | include/mbgl/style/light.hpp.ejs | 15 | ||||
-rw-r--r-- | src/mbgl/renderer/render_light.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/renderer/render_light.hpp | 18 | ||||
-rw-r--r-- | src/mbgl/style/light.cpp | 71 | ||||
-rw-r--r-- | src/mbgl/style/light.cpp.ejs | 23 | ||||
-rw-r--r-- | src/mbgl/style/light_impl.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/style/light_impl.hpp | 20 | ||||
-rw-r--r-- | src/mbgl/style/light_observer.hpp | 16 | ||||
-rw-r--r-- | src/mbgl/style/parser.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 5 |
13 files changed, 155 insertions, 74 deletions
diff --git a/include/mbgl/style/conversion/light.hpp b/include/mbgl/style/conversion/light.hpp index 30bb906037..ba162516c0 100644 --- a/include/mbgl/style/conversion/light.hpp +++ b/include/mbgl/style/conversion/light.hpp @@ -113,7 +113,7 @@ public: return {}; } } - return { light }; + return { std::move(light) }; }; }; diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp index 7942d0d237..8212a58dcc 100644 --- a/include/mbgl/style/light.hpp +++ b/include/mbgl/style/light.hpp @@ -5,15 +5,19 @@ #include <mbgl/style/transition_options.hpp> #include <mbgl/style/types.hpp> -namespace mbgl { - -class RenderLight; +#include <memory> +namespace mbgl { namespace style { class Light { public: + class Impl; + + Light(); + ~Light(); + static LightAnchorType getDefaultAnchor(); PropertyValue<LightAnchorType> getAnchor() const; void setAnchor(PropertyValue<LightAnchorType>); @@ -38,10 +42,7 @@ public: void setIntensityTransition(const TransitionOptions&); TransitionOptions getIntensityTransition() const; -private: - IndexedTuple<LightProperties, LightProperties> properties; - - friend class mbgl::RenderLight; + std::shared_ptr<Impl> impl; }; } // namespace style diff --git a/include/mbgl/style/light.hpp.ejs b/include/mbgl/style/light.hpp.ejs index 40f85b66b5..601e0bd410 100644 --- a/include/mbgl/style/light.hpp.ejs +++ b/include/mbgl/style/light.hpp.ejs @@ -8,15 +8,19 @@ #include <mbgl/style/transition_options.hpp> #include <mbgl/style/types.hpp> -namespace mbgl { - -class RenderLight; +#include <memory> +namespace mbgl { namespace style { class Light { public: + class Impl; + + Light(); + ~Light(); + <% for (const property of properties) { -%> static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>(); <%- propertyValueType(property) %> get<%- camelize(property.name) %>() const; @@ -25,10 +29,7 @@ public: TransitionOptions get<%- camelize(property.name) %>Transition() const; <% } -%> -private: - IndexedTuple<LightProperties, LightProperties> properties; - - friend class mbgl::RenderLight; + std::shared_ptr<Impl> impl; }; } // namespace style diff --git a/src/mbgl/renderer/render_light.cpp b/src/mbgl/renderer/render_light.cpp index faf89bf9e2..134e1829e0 100644 --- a/src/mbgl/renderer/render_light.cpp +++ b/src/mbgl/renderer/render_light.cpp @@ -2,12 +2,21 @@ namespace mbgl { -RenderLight::RenderLight(const style::Light light_) - : light(std::move(light_)) { +RenderLight::RenderLight(std::shared_ptr<const style::Light::Impl> impl_) + : impl(std::move(impl_)) { +} + +RenderLight::RenderLight(std::shared_ptr<const style::Light::Impl> impl_, const TransitioningLight transitioning_) + : impl(std::move(impl_)) + , transitioning(transitioning_) { +} + +std::unique_ptr<RenderLight> RenderLight::copy(std::shared_ptr<const style::Light::Impl> impl_) const { + return std::make_unique<RenderLight>(std::move(impl_), transitioning); } void RenderLight::transition(const CascadeParameters& parameters) { - transitioning = TransitioningLight(light.properties, std::move(transitioning), parameters); + transitioning = TransitioningLight(impl->properties, std::move(transitioning), parameters); } void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) { diff --git a/src/mbgl/renderer/render_light.hpp b/src/mbgl/renderer/render_light.hpp index 1a813ab1f8..275f3ae8ba 100644 --- a/src/mbgl/renderer/render_light.hpp +++ b/src/mbgl/renderer/render_light.hpp @@ -1,12 +1,15 @@ #pragma once -#include <mbgl/style/light.hpp> +#include <mbgl/style/light_impl.hpp> +#include <mbgl/style/light_properties.hpp> #include <mbgl/renderer/transitioning_property.hpp> #include <mbgl/renderer/cascade_parameters.hpp> #include <mbgl/renderer/property_evaluator.hpp> #include <mbgl/renderer/property_evaluation_parameters.hpp> #include <mbgl/util/ignore.hpp> +#include <memory> + namespace mbgl { template <class TypeList> @@ -71,7 +74,14 @@ using EvaluatedLight = Evaluated<style::LightProperties>; class RenderLight { public: - RenderLight(const style::Light); + RenderLight(std::shared_ptr<const style::Light::Impl>); + + // Creates a copy intitalized with previous transitioning light + RenderLight(std::shared_ptr<const style::Light::Impl>, const TransitioningLight); + + // creates a copy initialized with previous transitioning + // values + std::unique_ptr<RenderLight> copy(std::shared_ptr<const style::Light::Impl>) const; void transition(const CascadeParameters&); void evaluate(const PropertyEvaluationParameters&); @@ -79,10 +89,12 @@ public: const EvaluatedLight& getEvaluated() const; + const std::shared_ptr<const style::Light::Impl> impl; + private: + TransitioningLight transitioning; EvaluatedLight evaluated; - style::Light light; }; } // namespace mbgl diff --git a/src/mbgl/style/light.cpp b/src/mbgl/style/light.cpp index 0a9cbbee9a..b54920713c 100644 --- a/src/mbgl/style/light.cpp +++ b/src/mbgl/style/light.cpp @@ -7,30 +7,32 @@ namespace mbgl { namespace style { +Light::Light() + : impl(std::make_unique<Impl>()) { +} + +Light::~Light() = default; + LightAnchorType Light::getDefaultAnchor() { return LightAnchor::defaultValue(); } PropertyValue<LightAnchorType> Light::getAnchor() const { - return properties.get<LightAnchor>().value; + return impl->properties.template get<LightAnchor>().value; } void Light::setAnchor(PropertyValue<LightAnchorType> property) { - properties.get<LightAnchor>().value = property; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightAnchor>().value = property; + impl->observer->onLightChanged(*this); } void Light::setAnchorTransition(const TransitionOptions& transition) { - properties.get<LightAnchor>().transition = transition; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightAnchor>().transition = transition; + impl->observer->onLightChanged(*this); } TransitionOptions Light::getAnchorTransition() const { - return properties.get<LightAnchor>().transition; + return impl->properties.template get<LightAnchor>().transition; } Position Light::getDefaultPosition() { @@ -38,25 +40,21 @@ Position Light::getDefaultPosition() { } PropertyValue<Position> Light::getPosition() const { - return properties.get<LightPosition>().value; + return impl->properties.template get<LightPosition>().value; } void Light::setPosition(PropertyValue<Position> property) { - properties.get<LightPosition>().value = property; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightPosition>().value = property; + impl->observer->onLightChanged(*this); } void Light::setPositionTransition(const TransitionOptions& transition) { - properties.get<LightPosition>().transition = transition; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightPosition>().transition = transition; + impl->observer->onLightChanged(*this); } TransitionOptions Light::getPositionTransition() const { - return properties.get<LightPosition>().transition; + return impl->properties.template get<LightPosition>().transition; } Color Light::getDefaultColor() { @@ -64,25 +62,21 @@ Color Light::getDefaultColor() { } PropertyValue<Color> Light::getColor() const { - return properties.get<LightColor>().value; + return impl->properties.template get<LightColor>().value; } void Light::setColor(PropertyValue<Color> property) { - properties.get<LightColor>().value = property; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightColor>().value = property; + impl->observer->onLightChanged(*this); } void Light::setColorTransition(const TransitionOptions& transition) { - properties.get<LightColor>().transition = transition; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightColor>().transition = transition; + impl->observer->onLightChanged(*this); } TransitionOptions Light::getColorTransition() const { - return properties.get<LightColor>().transition; + return impl->properties.template get<LightColor>().transition; } float Light::getDefaultIntensity() { @@ -90,26 +84,23 @@ float Light::getDefaultIntensity() { } PropertyValue<float> Light::getIntensity() const { - return properties.get<LightIntensity>().value; + return impl->properties.template get<LightIntensity>().value; } void Light::setIntensity(PropertyValue<float> property) { - properties.get<LightIntensity>().value = property; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightIntensity>().value = property; + impl->observer->onLightChanged(*this); } void Light::setIntensityTransition(const TransitionOptions& transition) { - properties.get<LightIntensity>().transition = transition; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<LightIntensity>().transition = transition; + impl->observer->onLightChanged(*this); } TransitionOptions Light::getIntensityTransition() const { - return properties.get<LightIntensity>().transition; + return impl->properties.template get<LightIntensity>().transition; } + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/light.cpp.ejs b/src/mbgl/style/light.cpp.ejs index 7d2e0ecc1e..c82c65c10c 100644 --- a/src/mbgl/style/light.cpp.ejs +++ b/src/mbgl/style/light.cpp.ejs @@ -10,33 +10,36 @@ namespace mbgl { namespace style { +Light::Light() + : impl(std::make_unique<Impl>()) { +} + +Light::~Light() = default; + <% for (const property of properties) { -%> <%- evaluatedType(property) %> Light::getDefault<%- camelize(property.name) %>() { return Light<%- camelize(property.name) %>::defaultValue(); } <%- propertyValueType(property) %> Light::get<%- camelize(property.name) %>() const { - return properties.get<Light<%- camelize(property.name) %>>().value; + return impl->properties.template get<Light<%- camelize(property.name) %>>().value; } void Light::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> property) { - properties.get<Light<%- camelize(property.name) %>>().value = property; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<Light<%- camelize(property.name) %>>().value = property; + impl->observer->onLightChanged(*this); } void Light::set<%- camelize(property.name) %>Transition(const TransitionOptions& transition) { - properties.get<Light<%- camelize(property.name) %>>().transition = transition; - if (observer) { - observer->onLightChanged(*this); - } + impl->properties.template get<Light<%- camelize(property.name) %>>().transition = transition; + impl->observer->onLightChanged(*this); } TransitionOptions Light::get<%- camelize(property.name) %>Transition() const { - return properties.get<Light<%- camelize(property.name) %>>().transition; + return impl->properties.template get<Light<%- camelize(property.name) %>>().transition; } <% } -%> + } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/light_impl.cpp b/src/mbgl/style/light_impl.cpp new file mode 100644 index 0000000000..e0ab1176ed --- /dev/null +++ b/src/mbgl/style/light_impl.cpp @@ -0,0 +1,11 @@ +#include <mbgl/style/light_impl.hpp> + +namespace mbgl { +namespace style { + +void Light::Impl::setObserver(LightObserver* observer_) { + observer = observer_; +} + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/light_impl.hpp b/src/mbgl/style/light_impl.hpp new file mode 100644 index 0000000000..b4fd886742 --- /dev/null +++ b/src/mbgl/style/light_impl.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include <mbgl/style/light_properties.hpp> +#include <mbgl/style/light_observer.hpp> + +namespace mbgl { +namespace style { + +class Light::Impl { +public: + + LightObserver nullObserver; + LightObserver* observer = &nullObserver; + void setObserver(LightObserver*); + + IndexedTuple<LightProperties, LightProperties> properties; +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/light_observer.hpp b/src/mbgl/style/light_observer.hpp new file mode 100644 index 0000000000..751a84850d --- /dev/null +++ b/src/mbgl/style/light_observer.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include <mbgl/style/light.hpp> + +namespace mbgl { +namespace style { + +class LightObserver { +public: + virtual ~LightObserver() = default; + + virtual void onLightChanged(const Light&) {} +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index c407e438fb..fc3ccf410b 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -120,7 +120,7 @@ void Parser::parseLight(const JSValue& value) { return; } - light = *converted; + light = std::move(*converted); } void Parser::parseSources(const JSValue& value) { diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 080911b746..4b694917c3 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -59,10 +59,11 @@ Style::Style(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio) spriteAtlas(std::make_unique<SpriteAtlas>(Size{ 1024, 1024 }, pixelRatio)), lineAtlas(std::make_unique<LineAtlas>(Size{ 256, 512 })), light(std::make_unique<Light>()), - renderLight(std::make_unique<RenderLight>(*light)), + renderLight(std::make_unique<RenderLight>(light->impl)), observer(&nullObserver) { glyphAtlas->setObserver(this); spriteAtlas->setObserver(this); + light->impl->setObserver(this); } Style::~Style() { @@ -78,6 +79,7 @@ Style::~Style() { glyphAtlas->setObserver(nullptr); spriteAtlas->setObserver(nullptr); + light->impl->setObserver(nullptr); } bool Style::addClass(const std::string& className) { @@ -313,7 +315,13 @@ void Style::removeRenderLayer(const std::string& id) { void Style::setLight(std::unique_ptr<Light> light_) { light = std::move(light_); - renderLight = std::make_unique<RenderLight>(*light); + light->impl->setObserver(this); + + // Copy renderlight to preserve the initialised + // transitioning light properties + renderLight = renderLight->copy(light->impl); + + onLightChanged(*light); } Light* Style::getLight() const { @@ -761,6 +769,10 @@ void Style::onLayerLayoutPropertyChanged(Layer& layer, const char * property) { : Update::Repaint); } +void Style::onLightChanged(const Light&) { + observer->onUpdate(Update::Classes | Update::RecalculateStyle); +} + void Style::dumpDebugLogs() const { for (const auto& source : sources) { source->baseImpl->dumpDebugLogs(); diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 2756be1edd..7d235dc665 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -5,6 +5,7 @@ #include <mbgl/style/source_observer.hpp> #include <mbgl/renderer/render_source_observer.hpp> #include <mbgl/style/layer_observer.hpp> +#include <mbgl/style/light_observer.hpp> #include <mbgl/style/update_batch.hpp> #include <mbgl/renderer/render_layer.hpp> #include <mbgl/renderer/render_light.hpp> @@ -48,6 +49,7 @@ class Style : public GlyphAtlasObserver, public SourceObserver, public RenderSourceObserver, public LayerObserver, + public LightObserver, public util::noncopyable { public: Style(Scheduler&, FileSource&, float pixelRatio); @@ -169,6 +171,9 @@ private: void onLayerDataDrivenPaintPropertyChanged(Layer&) override; void onLayerLayoutPropertyChanged(Layer&, const char *) override; + // LightObserver implementation. + void onLightChanged(const Light&) override; + Observer nullObserver; Observer* observer = &nullObserver; |