summaryrefslogtreecommitdiff
path: root/src/mbgl/layer/fill_layer.cpp
blob: 53bf0ac89c80aeabdc03e666a1dcd98a799d8427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <mbgl/layer/fill_layer.hpp>
#include <mbgl/style/property_parsing.hpp>

namespace mbgl {

void FillLayer::parsePaints(const JSVal& layer) {
    paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
        parseProperty<Function<bool>>("fill-antialias", PropertyKey::FillAntialias, paint, value);
        parseProperty<Function<float>>("fill-opacity", PropertyKey::FillOpacity, paint, value);
        parseProperty<PropertyTransition>("fill-opacity-transition", PropertyKey::FillOpacity, paint, value);
        parseProperty<Function<Color>>("fill-color", PropertyKey::FillColor, paint, value);
        parseProperty<PropertyTransition>("fill-color-transition", PropertyKey::FillColor, paint, value);
        parseProperty<Function<Color>>("fill-outline-color", PropertyKey::FillOutlineColor, paint, value);
        parseProperty<PropertyTransition>("fill-outline-color-transition", PropertyKey::FillOutlineColor, paint, value);
        parseProperty<Function<std::array<float, 2>>>("fill-translate", PropertyKey::FillTranslate, paint, value);
        parseProperty<PropertyTransition>("fill-translate-transition", PropertyKey::FillTranslate, paint, value);
        parseProperty<Function<TranslateAnchorType>>("fill-translate-anchor", PropertyKey::FillTranslateAnchor, paint, value);
        parseProperty<PiecewiseConstantFunction<Faded<std::string>>>("fill-pattern", PropertyKey::FillImage, paint, value, "fill-pattern-transition");
    });
}

void FillLayer::recalculate(const StyleCalculationParameters& parameters) {
    paints.removeExpiredTransitions(parameters.now);

    paints.calculate(PropertyKey::FillAntialias, properties.antialias, parameters);
    paints.calculateTransitioned(PropertyKey::FillOpacity, properties.opacity, parameters);
    paints.calculateTransitioned(PropertyKey::FillColor, properties.fill_color, parameters);
    paints.calculateTransitioned(PropertyKey::FillOutlineColor, properties.stroke_color, parameters);
    paints.calculateTransitioned(PropertyKey::FillTranslate, properties.translate, parameters);
    paints.calculate(PropertyKey::FillTranslateAnchor, properties.translateAnchor, parameters);
    paints.calculate(PropertyKey::FillImage, properties.image, parameters);

    passes = RenderPass::None;

    if (properties.antialias) {
        passes |= RenderPass::Translucent;
    }

    if (!properties.image.from.empty() || (properties.fill_color[3] * properties.opacity) < 1.0f) {
        passes |= RenderPass::Translucent;
    } else {
        passes |= RenderPass::Opaque;
    }
}

}