summaryrefslogtreecommitdiff
path: root/src/mbgl/layer/raster_layer.cpp
blob: 3e3536afc3c4334f0dde1f64e7abd50c1fb0caab (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
47
48
49
50
51
52
53
54
55
56
57
58
#include <mbgl/layer/raster_layer.hpp>
#include <mbgl/style/property_parsing.hpp>
#include <mbgl/renderer/bucket.hpp>

namespace mbgl {

std::unique_ptr<StyleLayer> RasterLayer::clone() const {
    std::unique_ptr<RasterLayer> result = std::make_unique<RasterLayer>();
    result->copy(*this);
    result->paints.paints = paints.paints;
    return std::move(result);
}

void RasterLayer::parsePaints(const JSVal& layer) {
    paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) {
        parseProperty<Function<float>>("raster-opacity", PropertyKey::RasterOpacity, paint, value);
        parseProperty<PropertyTransition>("raster-opacity-transition", PropertyKey::RasterOpacity, paint, value);
        parseProperty<Function<float>>("raster-hue-rotate", PropertyKey::RasterHueRotate, paint, value);
        parseProperty<PropertyTransition>("raster-hue-rotate-transition", PropertyKey::RasterHueRotate, paint, value);
        parseProperty<Function<float>>("raster-brightness-min", PropertyKey::RasterBrightnessLow, paint, value);
        parseProperty<Function<float>>("raster-brightness-max", PropertyKey::RasterBrightnessHigh, paint, value);
        parseProperty<PropertyTransition>("raster-brightness-transition", PropertyKey::RasterBrightness, paint, value);
        parseProperty<Function<float>>("raster-saturation", PropertyKey::RasterSaturation, paint, value);
        parseProperty<PropertyTransition>("raster-saturation-transition", PropertyKey::RasterSaturation, paint, value);
        parseProperty<Function<float>>("raster-contrast", PropertyKey::RasterContrast, paint, value);
        parseProperty<PropertyTransition>("raster-contrast-transition", PropertyKey::RasterContrast, paint, value);
        parseProperty<Function<float>>("raster-fade-duration", PropertyKey::RasterFade, paint, value);
        parseProperty<PropertyTransition>("raster-fade-duration-transition", PropertyKey::RasterFade, paint, value);
    });
}

void RasterLayer::cascade(const StyleCascadeParameters& parameters) {
    paints.cascade(parameters);
}

bool RasterLayer::hasTransitions() const {
    return paints.hasTransitions();
}

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

    paints.calculateTransitioned(PropertyKey::RasterOpacity, properties.opacity, parameters);
    paints.calculateTransitioned(PropertyKey::RasterHueRotate, properties.hue_rotate, parameters);
    paints.calculateTransitioned(PropertyKey::RasterBrightnessLow, properties.brightness[0], parameters);
    paints.calculateTransitioned(PropertyKey::RasterBrightnessHigh, properties.brightness[1], parameters);
    paints.calculateTransitioned(PropertyKey::RasterSaturation, properties.saturation, parameters);
    paints.calculateTransitioned(PropertyKey::RasterContrast, properties.contrast, parameters);
    paints.calculateTransitioned(PropertyKey::RasterFade, properties.fade, parameters);

    passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None;
}

std::unique_ptr<Bucket> RasterLayer::createBucket(StyleBucketParameters&) const {
    return nullptr;
}

}