[core] delegate light changes to render light

This commit is contained in:
Ivo van Dongen
2017-05-04 19:21:08 +03:00
committed by Ivo van Dongen
parent feae5e22ee
commit 6fd40867d6
13 changed files with 155 additions and 74 deletions

View File

@@ -113,7 +113,7 @@ public:
return {};
}
}
return { light };
return { std::move(light) };
};
};

View File

@@ -5,15 +5,19 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
#include <memory>
namespace mbgl {
class RenderLight;
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

View File

@@ -8,15 +8,19 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
#include <memory>
namespace mbgl {
class RenderLight;
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

View File

@@ -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) {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -120,7 +120,7 @@ void Parser::parseLight(const JSValue& value) {
return;
}
light = *converted;
light = std::move(*converted);
}
void Parser::parseSources(const JSValue& value) {

View File

@@ -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();

View File

@@ -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;