Apply just the changes from the MLT branch which aren't really part of that work (#3793)

This commit is contained in:
Tim Sylvester
2025-09-11 16:39:58 -07:00
committed by GitHub
parent 921251b973
commit bc025fca49
44 changed files with 181 additions and 123 deletions

View File

@@ -26,7 +26,7 @@ void Scheduler::SetCurrent(Scheduler* scheduler) {
Scheduler* Scheduler::GetCurrent(bool init) {
if (!localScheduler && init) {
thread_local util::RunLoop runLoop;
static thread_local util::RunLoop runLoop;
SetCurrent(&runLoop);
}
return localScheduler;

View File

@@ -135,10 +135,10 @@ void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& ann
void AnnotationManager::remove(const AnnotationID& id) {
CHECK_ANNOTATIONS_ENABLED_AND_RETURN_NOARG();
if (symbolAnnotations.find(id) != symbolAnnotations.end()) {
if (symbolAnnotations.contains(id)) {
symbolTree.remove(symbolAnnotations.at(id));
symbolAnnotations.erase(id);
} else if (shapeAnnotations.find(id) != shapeAnnotations.end()) {
} else if (shapeAnnotations.contains(id)) {
auto it = shapeAnnotations.find(id);
(void)*style.get().impl->removeLayer(it->second->layerID);
shapeAnnotations.erase(it);

View File

@@ -154,7 +154,7 @@ struct glyph {
// Font data From Hershey Simplex Font
// http://paulbourke.net/dataformats/hershey/
// NOLINTBEGIN(modernize-use-designated-initializers)
const glyph simplex[] = {
/* 32 */ {16, 0, nullptr},
/* 33 ! */
@@ -346,3 +346,4 @@ const glyph simplex[] = {
/* 126 ~ */
{24, sizeof(simplex_94), simplex_94},
};
// NOLINTEND(modernize-use-designated-initializers)

View File

@@ -210,8 +210,9 @@ void DashPatternTexture::upload(gfx::UploadPass& uploadPass) {
if (std::holds_alternative<AlphaImage>(texture)) {
auto tempTexture = uploadPass.getContext().createTexture2D();
tempTexture->upload(std::get<AlphaImage>(texture));
tempTexture->setSamplerConfiguration(
{gfx::TextureFilterType::Linear, gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Clamp});
tempTexture->setSamplerConfiguration({.filter = gfx::TextureFilterType::Linear,
.wrapU = gfx::TextureWrapType::Repeat,
.wrapV = gfx::TextureWrapType::Clamp});
texture = std::move(tempTexture);
}
}

View File

@@ -107,7 +107,8 @@ UniqueGPUExpression GPUExpression::create(const Expression& expression, const Zo
}
float GPUExpression::evaluateFloat(const float zoom) const {
const auto index = std::distance(&inputs[0], std::upper_bound(&inputs[0], &inputs[stopCount], zoom));
const auto index = static_cast<std::uint16_t>(
std::distance(&inputs[0], std::upper_bound(&inputs[0], &inputs[stopCount], zoom)));
if (index == 0) {
return stops.floats[0];
} else if (index == stopCount) {
@@ -153,7 +154,8 @@ Color GPUExpression::getColor(std::size_t index) const {
}
Color GPUExpression::evaluateColor(const float zoom) const {
const auto index = std::distance(&inputs[0], std::upper_bound(&inputs[0], &inputs[stopCount], zoom));
const auto index = static_cast<std::uint16_t>(
std::distance(&inputs[0], std::upper_bound(&inputs[0], &inputs[stopCount], zoom)));
if (index == 0) {
return getColor(0);
} else if (index == stopCount) {

View File

@@ -93,14 +93,14 @@ void PolylineGenerator<PLV, PS>::generate(const GeometryCoordinates& coordinates
const std::size_t first = [&coordinates, &len] {
std::size_t i = 0;
// If the line has duplicate vertices at the start, adjust index to remove them.
while (i < len - 1 && coordinates[i] == coordinates[i + 1]) {
while (i + 1 < len && coordinates[i] == coordinates[i + 1]) {
i++;
}
return i;
}();
// Ignore invalid geometry.
if (len < (options.type == FeatureType::Polygon ? 3 : 2)) {
if (len < ((options.type == FeatureType::Polygon) ? 3u : 2u)) {
return;
}

View File

@@ -5,7 +5,6 @@
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/util/monotonic_timer.hpp>
#include <algorithm>
#include <initializer_list>
#include <sstream>
#include <iomanip>
@@ -26,7 +25,7 @@ bool RenderingStats::isZero() const {
memIndexBuffers,
memVertexBuffers,
memUniformBuffers};
return std::all_of(expectedZeros.begin(), expectedZeros.end(), [](auto x) { return x == 0; });
return std::ranges::all_of(expectedZeros, [](auto x) { return x == 0; });
}
RenderingStats& RenderingStats::operator+=(const RenderingStats& r) {

View File

@@ -6,7 +6,7 @@ namespace gfx {
bool ShaderGroup::isShader(const std::string& shaderName) const noexcept {
std::shared_lock<std::shared_mutex> readerLock(programLock);
return programs.find(shaderName) != programs.end();
return programs.contains(shaderName);
}
const std::shared_ptr<gfx::Shader> ShaderGroup::getShader(const std::string& shaderName) const noexcept {
@@ -25,7 +25,7 @@ bool ShaderGroup::replaceShader(std::shared_ptr<gfx::Shader>&& shader) noexcept
bool ShaderGroup::replaceShader(std::shared_ptr<Shader>&& shader, const std::string& shaderName) noexcept {
std::unique_lock<std::shared_mutex> writerLock(programLock);
if (programs.find(shaderName) == programs.end()) {
if (!programs.contains(shaderName)) {
return false;
}
@@ -39,7 +39,7 @@ bool ShaderGroup::registerShader(std::shared_ptr<gfx::Shader>&& shader) noexcept
bool ShaderGroup::registerShader(std::shared_ptr<Shader>&& shader, const std::string& shaderName) noexcept {
std::unique_lock<std::shared_mutex> writerLock(programLock);
if (programs.find(shaderName) != programs.end()) {
if (programs.contains(shaderName)) {
return false;
}

View File

@@ -13,7 +13,7 @@ ShaderGroup& ShaderRegistry::getLegacyGroup() noexcept {
bool ShaderRegistry::isShaderGroup(const std::string& shaderGroupName) const noexcept {
std::shared_lock<std::shared_mutex> readerLock(shaderGroupLock);
return shaderGroups.find(shaderGroupName) != shaderGroups.end();
return shaderGroups.contains(shaderGroupName);
}
const ShaderGroupPtr ShaderRegistry::getShaderGroup(const std::string& shaderGroupName) const noexcept {
@@ -28,7 +28,7 @@ const ShaderGroupPtr ShaderRegistry::getShaderGroup(const std::string& shaderGro
bool ShaderRegistry::replaceShader(ShaderGroupPtr&& shader, const std::string& shaderGroupName) noexcept {
std::unique_lock<std::shared_mutex> writerLock(shaderGroupLock);
if (shaderGroups.find(shaderGroupName) == shaderGroups.end()) {
if (!shaderGroups.contains(shaderGroupName)) {
return false;
}
@@ -38,7 +38,7 @@ bool ShaderRegistry::replaceShader(ShaderGroupPtr&& shader, const std::string& s
bool ShaderRegistry::registerShaderGroup(ShaderGroupPtr&& shader, const std::string& shaderGroupName) noexcept {
std::unique_lock<std::shared_mutex> writerLock(shaderGroupLock);
if (shaderGroups.find(shaderGroupName) != shaderGroups.end()) {
if (shaderGroups.contains(shaderGroupName)) {
return false;
}

View File

@@ -45,7 +45,7 @@ public:
const auto& sortKeyProperty = layout.template get<style::CircleSortKey>();
float sortKey = sortKeyProperty.evaluate(*feature, zoom, style::CircleSortKey::defaultValue());
CircleFeature circleFeature{i, std::move(feature), sortKey};
CircleFeature circleFeature{.i = i, .feature = std::move(feature), .sortKey = sortKey};
const auto sortPosition = std::lower_bound(features.cbegin(), features.cend(), circleFeature);
features.insert(sortPosition, std::move(circleFeature));
}

View File

@@ -7,7 +7,7 @@ namespace util {
// Map of key -> index into features
using Index = std::unordered_map<size_t, size_t>;
namespace {
size_t mergeFromRight(std::vector<SymbolFeature>& features,
Index& rightIndex,
Index::iterator left,
@@ -40,7 +40,7 @@ size_t mergeFromLeft(std::vector<SymbolFeature>& features,
size_t getKey(const std::u16string& text, const GeometryCoordinate& coord) {
return util::hash(text, coord.x, coord.y);
}
} // namespace
void mergeLines(std::vector<SymbolFeature>& features) {
Index leftIndex;
Index rightIndex;

View File

@@ -8,6 +8,8 @@
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/util/containers.hpp>
#include <list>
namespace mbgl {
class PatternDependency {
@@ -54,8 +56,8 @@ struct PatternFeatureInserter<void> {
template <typename PropertiesType>
static void insert(std::vector<PatternFeature>& features,
std::size_t index,
std::unique_ptr<GeometryTileFeature> feature,
PatternLayerMap patternDependencyMap,
std::unique_ptr<GeometryTileFeature>&& feature,
PatternLayerMap&& patternDependencyMap,
float /*zoom*/,
const PropertiesType&,
const CanonicalTileID&) {
@@ -68,8 +70,8 @@ struct PatternFeatureInserter {
template <typename PropertiesType>
static void insert(std::vector<PatternFeature>& features,
std::size_t index,
std::unique_ptr<GeometryTileFeature> feature,
PatternLayerMap patternDependencyMap,
std::unique_ptr<GeometryTileFeature>&& feature,
PatternLayerMap&& patternDependencyMap,
float zoom,
const PropertiesType& properties,
const CanonicalTileID& canonical) {
@@ -91,7 +93,7 @@ class PatternLayout : public Layout {
public:
PatternLayout(const BucketParameters& parameters,
const std::vector<Immutable<style::LayerProperties>>& group,
std::unique_ptr<GeometryTileLayer> sourceLayer_,
std::unique_ptr<GeometryTileLayer>&& sourceLayer_,
const LayoutParameters& layoutParameters)
: sourceLayer(std::move(sourceLayer_)),
zoom(parameters.tileID.overscaledZ),

View File

@@ -4,7 +4,6 @@
#include <mbgl/text/tagged_string.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <array>
#include <string>
#include <optional>

View File

@@ -27,13 +27,13 @@ namespace mbgl {
using namespace style;
namespace {
template <class Property>
static bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) {
bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) {
return layout.get<Property>().match([](const typename Property::Type& t) { return !t.empty(); },
[](const auto&) { return true; });
}
namespace {
expression::Value sectionOptionsToValue(const SectionOptions& options) {
std::unordered_map<std::string, expression::Value> result;
// TODO: Data driven properties that can be overridden on per section basis.

View File

@@ -689,7 +689,7 @@ ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng,
TileCoordinate TransformState::screenCoordinateToTileCoordinate(const ScreenCoordinate& point, uint8_t atZoom) const {
if (size.isEmpty()) {
return {{}, 0};
return {.p = {}, .z = 0};
}
float targetZ = 0;
@@ -718,7 +718,7 @@ TileCoordinate TransformState::screenCoordinateToTileCoordinate(const ScreenCoor
double t = z0 == z1 ? 0 : (targetZ - z0) / (z1 - z0);
Point<double> p = util::interpolate(p0, p1, t) / scale * static_cast<double>(1 << atZoom);
return {{p.x, p.y}, static_cast<double>(atZoom)};
return {.p = {p.x, p.y}, .z = static_cast<double>(atZoom)};
}
LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, LatLng::WrapMode wrapMode) const {

View File

@@ -40,7 +40,7 @@ public:
const ImagePositions&,
const PatternLayerMap&,
std::size_t,
const CanonicalTileID&) {};
const CanonicalTileID&) {}
virtual void update(const FeatureStates&, const GeometryTileLayer&, const std::string&, const ImagePositions&) {}

View File

@@ -13,12 +13,14 @@ DebugBucket::DebugBucket(const OverscaledTileID& id,
const bool complete_,
std::optional<Timestamp> modified_,
std::optional<Timestamp> expires_,
MapDebugOptions debugMode_)
MapDebugOptions debugMode_,
std::string sourceName_)
: renderable(renderable_),
complete(complete_),
modified(std::move(modified_)),
expires(std::move(expires_)),
debugMode(debugMode_) {
debugMode(debugMode_),
sourceName(std::move(sourceName_)) {
auto addText = [&](const std::string& text, double left, double baseline, double scale) {
for (uint8_t c : text) {
if (c < 32 || c >= 127) continue;
@@ -53,7 +55,8 @@ DebugBucket::DebugBucket(const OverscaledTileID& id,
const std::string text = util::toString(id) + " - " +
(complete ? "complete"
: renderable ? "renderable"
: "pending");
: "pending") +
" " + sourceName;
addText(text, 50, baseline, 5);
baseline += 200;
}

View File

@@ -22,7 +22,8 @@ public:
bool complete,
std::optional<Timestamp> modified,
std::optional<Timestamp> expires,
MapDebugOptions);
MapDebugOptions,
std::string sourceName);
void upload(gfx::UploadPass&);
@@ -31,6 +32,7 @@ public:
const std::optional<Timestamp> modified;
const std::optional<Timestamp> expires;
const MapDebugOptions debugMode;
const std::string sourceName;
gfx::VertexVector<FillLayoutVertex> vertices;
gfx::IndexVector<gfx::Lines> indices;

View File

@@ -428,12 +428,13 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
}
// Prepare. Update all matrices and generate data that we should upload to the GPU.
for (const auto& entry : renderSources) {
for (const auto& [name, renderSource] : renderSources) {
MLN_TRACE_ZONE(prepare source);
if (entry.second->isEnabled()) {
entry.second->prepare({.transform = renderTreeParameters->transformParams,
if (renderSource->isEnabled()) {
renderSource->prepare({.transform = renderTreeParameters->transformParams,
.debugOptions = updateParameters->debugOptions,
.imageManager = *imageManager});
.imageManager = *imageManager,
.sourceName = name});
}
}

View File

@@ -43,6 +43,7 @@ public:
const TransformParameters& transform;
const MapDebugOptions& debugOptions;
const ImageManager& imageManager;
const std::string sourceName;
};
using RenderTiles = std::shared_ptr<const std::vector<std::reference_wrapper<const RenderTile>>>;

View File

@@ -120,8 +120,13 @@ void RenderTile::prepare(const SourcePrepareParameters& parameters) {
(!debugBucket || debugBucket->renderable != tile.isRenderable() || debugBucket->complete != tile.isComplete() ||
!(debugBucket->modified == tile.modified) || !(debugBucket->expires == tile.expires) ||
debugBucket->debugMode != parameters.debugOptions)) {
debugBucket = std::make_unique<DebugBucket>(
tile.id, tile.isRenderable(), tile.isComplete(), tile.modified, tile.expires, parameters.debugOptions);
debugBucket = std::make_unique<DebugBucket>(tile.id,
tile.isRenderable(),
tile.isComplete(),
tile.modified,
tile.expires,
parameters.debugOptions,
parameters.sourceName);
} else if (parameters.debugOptions == MapDebugOptions::NoDebug) {
debugBucket.reset();
}

View File

@@ -45,6 +45,7 @@ public:
std::unique_ptr<gl::ProgramBase<Name>> programBase;
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility) We don't want to list every derived class as a friend
Program([[maybe_unused]] const ProgramParameters& programParameters) {
switch (gfx::Backend::GetType()) {
#if MLN_RENDER_BACKEND_METAL

View File

@@ -14,13 +14,15 @@
#include <mapbox/eternal.hpp>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numbers>
namespace mbgl {
namespace style {
namespace expression {
namespace {
/*
Represents the parameter list for an expression that takes an arbitrary
number of arguments (of a specific type).
@@ -39,7 +41,7 @@ struct Varargs : std::vector<T> {
explicit Varargs(Args&&... args)
: std::vector<T>(std::forward<Args>(args)...) {}
};
} // namespace
namespace detail {
// Base class for the Signature<Fn> structs that are used to determine
// each CompoundExpression definition's type::Type data from the type of its
@@ -225,16 +227,17 @@ struct SignatureType<Lambda, std::enable_if_t<std::is_class_v<Lambda>>> {
using Type = typename SignatureType<decltype(&Lambda::operator())>::Type;
};
namespace {
template <typename Fn>
static std::unique_ptr<detail::SignatureBase> makeSignature(std::string name,
Fn evaluateFunction,
Dependency dependencies = Dependency::None) {
std::unique_ptr<detail::SignatureBase> makeSignature(std::string name,
Fn evaluateFunction,
Dependency dependencies = Dependency::None) {
return std::make_unique<Signature<typename SignatureType<Fn>::Type>>(
evaluateFunction, std::move(name), dependencies);
}
} // namespace
} // namespace detail
namespace {
Value featureIdAsExpressionValue(const EvaluationContext& params) {
assert(params.feature);
auto id = params.feature->getID();
@@ -297,17 +300,17 @@ std::optional<std::string> featureIdAsString(const EvaluationContext& params) {
};
const auto& eCompoundExpression() {
static auto signature = detail::makeSignature("e", []() -> Result<double> { return 2.718281828459045; });
static auto signature = detail::makeSignature("e", []() -> Result<double> { return std::numbers::e; });
return signature;
}
const auto& piCompoundExpression() {
static auto signature = detail::makeSignature("pi", []() -> Result<double> { return 3.141592653589793; });
static auto signature = detail::makeSignature("pi", []() -> Result<double> { return std::numbers::pi; });
return signature;
}
const auto& ln2CompoundExpression() {
static auto signature = detail::makeSignature("ln2", []() -> Result<double> { return 0.6931471805599453; });
static auto signature = detail::makeSignature("ln2", []() -> Result<double> { return std::numbers::ln2; });
return signature;
}
@@ -956,8 +959,8 @@ const auto& filterTypeInCompoundExpression() {
"filter-type-in",
[](const EvaluationContext& params, const Varargs<std::string>& types) -> Result<bool> {
assert(params.feature);
std::optional<std::string> type = featureTypeAsString(params.feature->getType());
return std::find(types.begin(), types.end(), type) != types.end();
const auto type = featureTypeAsString(params.feature->getType());
return std::ranges::find(types, type) != types.end();
},
Dependency::Feature);
return signature;
@@ -967,8 +970,8 @@ const auto& filterIdInCompoundExpression() {
static auto signature = detail::makeSignature(
"filter-id-in",
[](const EvaluationContext& params, const Varargs<Value>& ids) -> Result<bool> {
auto id = featureIdAsExpressionValue(params);
return std::find(ids.begin(), ids.end(), id) != ids.end();
const auto id = featureIdAsExpressionValue(params);
return std::ranges::find(ids, id) != ids.end();
},
Dependency::Feature);
return signature;
@@ -1113,9 +1116,9 @@ std::string expectedTypesError(const Definitions& definitions, const std::vector
return "Expected arguments of type " + signatures + ", but found (" + actualTypes + ") instead.";
}
static ParseResult createCompoundExpression(const Definitions& definitions,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx) {
ParseResult createCompoundExpression(const Definitions& definitions,
std::vector<std::unique_ptr<Expression>> args,
ParsingContext& ctx) {
ParsingContext signatureContext(ctx.getKey());
for (auto it = definitions.first; it != definitions.second; ++it) {
@@ -1162,6 +1165,8 @@ static ParseResult createCompoundExpression(const Definitions& definitions,
return ParseResult();
}
} // namespace
ParseResult parseCompoundExpression(const std::string& name, const Convertible& value, ParsingContext& ctx) {
assert(isArray(value) && arrayLength(value) > 0);

View File

@@ -14,7 +14,6 @@
#include <memory>
#include <unordered_map>
#include <vector>
#include <optional>
namespace mbgl {

View File

@@ -20,7 +20,8 @@ using namespace std::numbers;
namespace mbgl {
static double signedArea(const GeometryCoordinates& ring) {
namespace {
double signedArea(const GeometryCoordinates& ring) {
double sum = 0;
for (std::size_t i = 0, len = ring.size(), j = len - 1; i < len; j = i++) {
@@ -32,7 +33,7 @@ static double signedArea(const GeometryCoordinates& ring) {
return sum;
}
static LinearRing<int32_t> toWagyuPath(const GeometryCoordinates& ring) {
LinearRing<int32_t> toWagyuPath(const GeometryCoordinates& ring) {
MLN_TRACE_FUNC();
LinearRing<int32_t> result;
@@ -43,7 +44,7 @@ static LinearRing<int32_t> toWagyuPath(const GeometryCoordinates& ring) {
return result;
}
static GeometryCollection toGeometryCollection(MultiPolygon<int16_t>&& multipolygon) {
GeometryCollection toGeometryCollection(MultiPolygon<int16_t>&& multipolygon) {
MLN_TRACE_FUNC();
GeometryCollection result;
@@ -54,6 +55,7 @@ static GeometryCollection toGeometryCollection(MultiPolygon<int16_t>&& multipoly
}
return result;
}
} // namespace
GeometryCollection fixupPolygons(const GeometryCollection& rings) {
MLN_TRACE_FUNC();

View File

@@ -47,9 +47,8 @@ TileLoader<T>::TileLoader(T& tile_,
// initial std::optional part of the request.
loadFromCache();
} else if (necessity == TileNecessity::Required) {
// When the file source doesn't support cache-only requests, and we
// definiitely need this data, we can start out with a network request
// immediately.
// When the file source doesn't support cache-only requests, and we definitely
// need this data, we can start out with a network request immediately.
loadFromNetwork();
} else {
// When the FileSource doesn't support cache-only requests, we do

View File

@@ -49,9 +49,9 @@ void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine& scanLine)
// scan lines!
const double m0 = e0.dx / e0.dy;
const double m1 = e1.dx / e1.dy;
const double d0 = e0.dx > 0; // use y + 1 to compute x0
const double d1 = e1.dx < 0; // use y + 1 to compute x1
for (double y = y0; y < y1; y++) {
const double d0 = e0.dx > 0; // use y + 1 to compute x0
const double d1 = e1.dx < 0; // use y + 1 to compute x1
for (double y = y0; y < y1; y++) { // NOLINT(clang-analyzer-security.FloatLoopCounter)
double x0 = m0 * ::fmax(0, ::fmin(e0.dy, y + d0 - e0.y0)) + e0.x0;
double x1 = m1 * ::fmax(0, ::fmin(e1.dy, y + d1 - e1.y0)) + e1.x0;
scanLine(static_cast<int32_t>(std::floor(x1)), static_cast<int32_t>(std::ceil(x0)), static_cast<int32_t>(y));