summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-10-30 10:21:17 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-11-11 18:20:01 +0200
commitc6f3cc8b60e0cff032020a780d4fd3de1cb2a112 (patch)
tree155fe444f21ae88dda664e81cfc8378e28297b0e /src/mbgl/renderer
parente1556fc539607db626b978040895716c1564c9b9 (diff)
downloadqtlocation-mapboxgl-c6f3cc8b60e0cff032020a780d4fd3de1cb2a112.tar.gz
[core] Implement image expression (#15877)
* [core] Bump gl-js version * [core] Implement image expression * [core] Use new image expression * [core] Coerce image expression to / from string * [core] Serialize evaluated image * [core] Pass available images to layout * [core] Pass images to evaluation context * [core] Set available flag value based on image availability * [core] Allow image coercion to boolean to indicate image availability * [core] Coalesce image expression * [core] Add image expression to next build system * [core] Align serialization format and evaluated type with gl-js * [core] Add images to expression evaluation method * [core] Add support for Image expression to expression test runner * [core] Unskip image expression tests * [core] Update unit tests * [core] Use image expression in annotation manager * [core] Add string to ImageExpression conversion * [core] Add image expression to expression dsl * [core] Convert tokens for implicitly created Image literal * [core] Fix clang format * [core] Split generated style code lines that are over 120 characters * [core] Add unit test for image expression equality * [core] Add image property expression evaluation unit test * [core] Unskip image expression render test * [core] Skip 'in' expression tests * [core] Ignore fill-pattern/update-feature-state render test * [core] Rename Image::serialize to Image::toValue
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/cross_faded_property_evaluator.cpp3
-rw-r--r--src/mbgl/renderer/data_driven_property_evaluator.hpp8
-rw-r--r--src/mbgl/renderer/image_manager.cpp6
-rw-r--r--src/mbgl/renderer/image_manager.hpp3
-rw-r--r--src/mbgl/renderer/layers/render_background_layer.cpp10
-rw-r--r--src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp32
-rw-r--r--src/mbgl/renderer/layers/render_fill_layer.cpp35
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp31
-rw-r--r--src/mbgl/renderer/possibly_evaluated_property_value.hpp11
9 files changed, 79 insertions, 60 deletions
diff --git a/src/mbgl/renderer/cross_faded_property_evaluator.cpp b/src/mbgl/renderer/cross_faded_property_evaluator.cpp
index 7be9c2bcf5..65f5b31467 100644
--- a/src/mbgl/renderer/cross_faded_property_evaluator.cpp
+++ b/src/mbgl/renderer/cross_faded_property_evaluator.cpp
@@ -1,4 +1,5 @@
#include <mbgl/renderer/cross_faded_property_evaluator.hpp>
+#include <mbgl/style/expression/image.hpp>
#include <mbgl/util/chrono.hpp>
#include <cmath>
@@ -30,7 +31,7 @@ Faded<T> CrossFadedPropertyEvaluator<T>::calculate(const T& min, const T& mid, c
: Faded<T> { max, mid };
}
-template class CrossFadedPropertyEvaluator<std::string>;
+template class CrossFadedPropertyEvaluator<style::expression::Image>;
template class CrossFadedPropertyEvaluator<std::vector<float>>;
} // namespace mbgl
diff --git a/src/mbgl/renderer/data_driven_property_evaluator.hpp b/src/mbgl/renderer/data_driven_property_evaluator.hpp
index efac9e4532..c2e6d9f283 100644
--- a/src/mbgl/renderer/data_driven_property_evaluator.hpp
+++ b/src/mbgl/renderer/data_driven_property_evaluator.hpp
@@ -26,14 +26,14 @@ public:
ResultType operator()(const style::PropertyExpression<T>& expression) const {
if (useIntegerZoom) { // Compiler will optimize out the unused branch.
- if (!expression.isFeatureConstant()) {
+ if (!expression.isFeatureConstant() || !expression.isRuntimeConstant()) {
auto returnExpression = expression;
returnExpression.useIntegerZoom = true;
return ResultType(returnExpression);
- }
+ }
return ResultType(expression.evaluate(floor(parameters.z)));
} else {
- if (!expression.isFeatureConstant()) {
+ if (!expression.isFeatureConstant() || !expression.isRuntimeConstant()) {
return ResultType(expression);
}
return ResultType(expression.evaluate(parameters.z));
@@ -63,7 +63,7 @@ public:
}
ResultType operator()(const style::PropertyExpression<T>& expression) const {
- if (!expression.isFeatureConstant()) {
+ if (!expression.isFeatureConstant() || !expression.isRuntimeConstant()) {
return ResultType(expression);
} else {
const T evaluated = expression.evaluate(floor(parameters.z));
diff --git a/src/mbgl/renderer/image_manager.cpp b/src/mbgl/renderer/image_manager.cpp
index 2ea753d8aa..4927ade8e9 100644
--- a/src/mbgl/renderer/image_manager.cpp
+++ b/src/mbgl/renderer/image_manager.cpp
@@ -43,6 +43,7 @@ void ImageManager::addImage(Immutable<style::Image::Impl> image_) {
if (requestedImages.find(image_->id) != requestedImages.end()) {
requestedImagesCacheSize += image_->image.bytes();
}
+ availableImages.emplace(image_->id);
images.emplace(image_->id, std::move(image_));
}
@@ -81,6 +82,7 @@ void ImageManager::removeImage(const std::string& id) {
requestedImages.erase(requestedIt);
}
images.erase(it);
+ availableImages.erase(id);
updatedImageVersions.erase(id);
}
@@ -169,6 +171,10 @@ void ImageManager::reduceMemoryUseIfCacheSizeExceedsLimit() {
}
}
+const std::set<std::string>& ImageManager::getAvailableImages() const {
+ return availableImages;
+}
+
void ImageManager::checkMissingAndNotify(ImageRequestor& requestor, const ImageRequestPair& pair) {
ImageDependencies missingDependencies;
diff --git a/src/mbgl/renderer/image_manager.hpp b/src/mbgl/renderer/image_manager.hpp
index 5ed6e237f0..7d5884edc1 100644
--- a/src/mbgl/renderer/image_manager.hpp
+++ b/src/mbgl/renderer/image_manager.hpp
@@ -47,6 +47,7 @@ public:
void notifyIfMissingImageAdded();
void reduceMemoryUse();
void reduceMemoryUseIfCacheSizeExceedsLimit();
+ const std::set<std::string>& getAvailableImages() const;
ImageVersionMap updatedImageVersions;
@@ -62,6 +63,8 @@ private:
std::map<std::string, std::set<ImageRequestor*>> requestedImages;
std::size_t requestedImagesCacheSize = 0ul;
ImageMap images;
+ // Mirror of 'ImageMap images;' keys.
+ std::set<std::string> availableImages;
ImageManagerObserver* observer = nullptr;
};
diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp
index 6f76efda7a..694addcc97 100644
--- a/src/mbgl/renderer/layers/render_background_layer.cpp
+++ b/src/mbgl/renderer/layers/render_background_layer.cpp
@@ -105,8 +105,10 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
const auto& evaluated = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).evaluated;
const auto& crossfade = static_cast<const BackgroundLayerProperties&>(*evaluatedProperties).crossfade;
if (!evaluated.get<BackgroundPattern>().to.empty()) {
- optional<ImagePosition> imagePosA = parameters.patternAtlas.getPattern(evaluated.get<BackgroundPattern>().from);
- optional<ImagePosition> imagePosB = parameters.patternAtlas.getPattern(evaluated.get<BackgroundPattern>().to);
+ optional<ImagePosition> imagePosA =
+ parameters.patternAtlas.getPattern(evaluated.get<BackgroundPattern>().from.id());
+ optional<ImagePosition> imagePosB =
+ parameters.patternAtlas.getPattern(evaluated.get<BackgroundPattern>().to.id());
if (!imagePosA || !imagePosB)
return;
@@ -176,8 +178,8 @@ void RenderBackgroundLayer::prepare(const LayerPrepareParameters& params) {
if (!evaluated.get<BackgroundPattern>().to.empty()) {
// Ensures that the pattern bitmap gets copied to atlas bitmap.
// Atlas bitmap is uploaded to atlas texture in upload.
- addPatternIfNeeded(evaluated.get<BackgroundPattern>().from, params);
- addPatternIfNeeded(evaluated.get<BackgroundPattern>().to, params);
+ addPatternIfNeeded(evaluated.get<BackgroundPattern>().from.id(), params);
+ addPatternIfNeeded(evaluated.get<BackgroundPattern>().to.id(), params);
}
}
diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
index fc830e462c..af0bc788d0 100644
--- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
@@ -1,20 +1,21 @@
-#include <mbgl/renderer/layers/render_fill_extrusion_layer.hpp>
+#include <mbgl/geometry/feature_index.hpp>
+#include <mbgl/gfx/cull_face_mode.hpp>
+#include <mbgl/gfx/render_pass.hpp>
+#include <mbgl/gfx/renderer_backend.hpp>
+#include <mbgl/programs/fill_extrusion_program.hpp>
+#include <mbgl/programs/programs.hpp>
#include <mbgl/renderer/buckets/fill_extrusion_bucket.hpp>
-#include <mbgl/renderer/render_tile.hpp>
-#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/image_manager.hpp>
+#include <mbgl/renderer/layers/render_fill_extrusion_layer.hpp>
+#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_static_data.hpp>
-#include <mbgl/programs/programs.hpp>
-#include <mbgl/programs/fill_extrusion_program.hpp>
-#include <mbgl/tile/tile.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/style/expression/image.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_impl.hpp>
-#include <mbgl/geometry/feature_index.hpp>
-#include <mbgl/util/math.hpp>
-#include <mbgl/util/intersection_tests.hpp>
#include <mbgl/tile/geometry_tile.hpp>
-#include <mbgl/gfx/renderer_backend.hpp>
-#include <mbgl/gfx/render_pass.hpp>
-#include <mbgl/gfx/cull_face_mode.hpp>
+#include <mbgl/tile/tile.hpp>
+#include <mbgl/util/intersection_tests.hpp>
+#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -171,7 +172,8 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
}
} else {
// Draw textured extrusions
- const auto fillPatternValue = evaluated.get<FillExtrusionPattern>().constantOr(mbgl::Faded<std::basic_string<char> >{"", ""});
+ const auto fillPatternValue =
+ evaluated.get<FillExtrusionPattern>().constantOr(mbgl::Faded<expression::Image>{"", ""});
auto drawTiles = [&](const gfx::StencilMode& stencilMode_, const gfx::ColorMode& colorMode_, const std::string& name) {
for (const RenderTile& tile : *renderTiles) {
const LayerRenderData* renderData = getRenderDataForPass(tile, parameters.pass);
@@ -179,8 +181,8 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) {
continue;
}
auto& bucket = static_cast<FillExtrusionBucket&>(*renderData->bucket);
- optional<ImagePosition> patternPosA = tile.getPattern(fillPatternValue.from);
- optional<ImagePosition> patternPosB = tile.getPattern(fillPatternValue.to);
+ optional<ImagePosition> patternPosA = tile.getPattern(fillPatternValue.from.id());
+ optional<ImagePosition> patternPosB = tile.getPattern(fillPatternValue.to.id());
draw(
parameters.programs.getFillExtrusionLayerPrograms().fillExtrusionPattern,
diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp
index e855866eea..bbfcef7aba 100644
--- a/src/mbgl/renderer/layers/render_fill_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_layer.cpp
@@ -1,21 +1,22 @@
-#include <mbgl/renderer/layers/render_fill_layer.hpp>
-#include <mbgl/renderer/buckets/fill_bucket.hpp>
-#include <mbgl/renderer/render_tile.hpp>
-#include <mbgl/renderer/render_source.hpp>
-#include <mbgl/renderer/paint_parameters.hpp>
-#include <mbgl/renderer/image_manager.hpp>
-#include <mbgl/programs/programs.hpp>
-#include <mbgl/programs/fill_program.hpp>
-#include <mbgl/tile/tile.hpp>
-#include <mbgl/style/layers/fill_layer_impl.hpp>
#include <mbgl/geometry/feature_index.hpp>
-#include <mbgl/gfx/renderer_backend.hpp>
-#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/context.hpp>
+#include <mbgl/gfx/cull_face_mode.hpp>
#include <mbgl/gfx/renderable.hpp>
-#include <mbgl/util/math.hpp>
-#include <mbgl/util/intersection_tests.hpp>
+#include <mbgl/gfx/renderer_backend.hpp>
+#include <mbgl/programs/fill_program.hpp>
+#include <mbgl/programs/programs.hpp>
+#include <mbgl/renderer/buckets/fill_bucket.hpp>
+#include <mbgl/renderer/image_manager.hpp>
+#include <mbgl/renderer/layers/render_fill_layer.hpp>
+#include <mbgl/renderer/paint_parameters.hpp>
+#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/style/expression/image.hpp>
+#include <mbgl/style/layers/fill_layer_impl.hpp>
#include <mbgl/tile/geometry_tile.hpp>
+#include <mbgl/tile/tile.hpp>
+#include <mbgl/util/intersection_tests.hpp>
+#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -171,9 +172,9 @@ void RenderFillLayer::render(PaintParameters& parameters) {
const auto& evaluated = getEvaluated<FillLayerProperties>(renderData->layerProperties);
const auto& crossfade = getCrossfade<FillLayerProperties>(renderData->layerProperties);
- const auto& fillPatternValue = evaluated.get<FillPattern>().constantOr(Faded<std::basic_string<char>>{"", ""});
- optional<ImagePosition> patternPosA = tile.getPattern(fillPatternValue.from);
- optional<ImagePosition> patternPosB = tile.getPattern(fillPatternValue.to);
+ const auto& fillPatternValue = evaluated.get<FillPattern>().constantOr(Faded<expression::Image>{"", ""});
+ optional<ImagePosition> patternPosA = tile.getPattern(fillPatternValue.from.id());
+ optional<ImagePosition> patternPosB = tile.getPattern(fillPatternValue.to.id());
auto draw = [&] (auto& programInstance,
const auto& drawMode,
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index e5bbe74bf9..588cf6286c 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -1,20 +1,21 @@
-#include <mbgl/renderer/layers/render_line_layer.hpp>
+#include <mbgl/geometry/feature_index.hpp>
+#include <mbgl/geometry/line_atlas.hpp>
+#include <mbgl/gfx/cull_face_mode.hpp>
+#include <mbgl/programs/line_program.hpp>
+#include <mbgl/programs/programs.hpp>
#include <mbgl/renderer/buckets/line_bucket.hpp>
-#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/renderer/image_manager.hpp>
+#include <mbgl/renderer/layers/render_line_layer.hpp>
+#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/upload_parameters.hpp>
-#include <mbgl/renderer/paint_parameters.hpp>
-#include <mbgl/renderer/image_manager.hpp>
-#include <mbgl/programs/programs.hpp>
-#include <mbgl/programs/line_program.hpp>
-#include <mbgl/geometry/line_atlas.hpp>
-#include <mbgl/tile/tile.hpp>
+#include <mbgl/style/expression/image.hpp>
#include <mbgl/style/layers/line_layer_impl.hpp>
-#include <mbgl/gfx/cull_face_mode.hpp>
-#include <mbgl/geometry/feature_index.hpp>
-#include <mbgl/util/math.hpp>
-#include <mbgl/util/intersection_tests.hpp>
#include <mbgl/tile/geometry_tile.hpp>
+#include <mbgl/tile/tile.hpp>
+#include <mbgl/util/intersection_tests.hpp>
+#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -168,11 +169,11 @@ void RenderLineLayer::render(PaintParameters& parameters) {
});
} else if (!unevaluated.get<LinePattern>().isUndefined()) {
- const auto& linePatternValue = evaluated.get<LinePattern>().constantOr(Faded<std::basic_string<char>>{ "", ""});
+ const auto& linePatternValue = evaluated.get<LinePattern>().constantOr(Faded<expression::Image>{"", ""});
const Size& texsize = tile.getIconAtlasTexture().size;
- optional<ImagePosition> posA = tile.getPattern(linePatternValue.from);
- optional<ImagePosition> posB = tile.getPattern(linePatternValue.to);
+ optional<ImagePosition> posA = tile.getPattern(linePatternValue.from.id());
+ optional<ImagePosition> posB = tile.getPattern(linePatternValue.to.id());
draw(parameters.programs.getLineLayerPrograms().linePattern,
LinePatternProgram::layoutUniformValues(
diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp
index 1198e43aae..5e412855a4 100644
--- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp
+++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp
@@ -93,16 +93,19 @@ public:
}
template <class Feature>
- Faded<T> evaluate(const Feature& feature, float zoom, T defaultValue) const {
+ Faded<T> evaluate(const Feature& feature,
+ float zoom,
+ const std::set<std::string>& availableImages,
+ T defaultValue) const {
return this->match(
[&] (const Faded<T>& constant_) { return constant_; },
[&] (const style::PropertyExpression<T>& expression) {
if (!expression.isZoomConstant()) {
- const T min = expression.evaluate(floor(zoom), feature, defaultValue);
- const T max = expression.evaluate(floor(zoom) + 1, feature, defaultValue);
+ const T min = expression.evaluate(floor(zoom), feature, availableImages, defaultValue);
+ const T max = expression.evaluate(floor(zoom) + 1, feature, availableImages, defaultValue);
return Faded<T> {min, max};
} else {
- const T evaluated = expression.evaluate(feature, defaultValue);
+ const T evaluated = expression.evaluate(feature, availableImages, defaultValue);
return Faded<T> {evaluated, evaluated};
}
}