diff options
author | Artem Pavlenko <artem@mapnik.org> | 2020-02-13 11:29:04 +0000 |
---|---|---|
committer | Artem Pavlenko <artem@mapnik.org> | 2020-02-13 11:29:04 +0000 |
commit | e4b90f316f3879508736f3b4c988a68909171125 (patch) | |
tree | 120d86c4768c0a89d6367504f2f7e5e9b28a5b0d /include | |
parent | 4b0eef6104bf8c33bf105b7173dbc5f0f65e1efb (diff) | |
parent | d3535f1ca9f7c12b3c2290da3f347e4f95210425 (diff) | |
download | qtlocation-mapboxgl-e4b90f316f3879508736f3b4c988a68909171125.tar.gz |
Merge branch 'master' into galinelle_setStyle++
Diffstat (limited to 'include')
18 files changed, 211 insertions, 25 deletions
diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/gl/custom_layer.hpp index 5dce484980..5dce484980 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/gl/custom_layer.hpp diff --git a/include/mbgl/layermanager/custom_layer_factory.hpp b/include/mbgl/gl/custom_layer_factory.hpp index 963a3dc2fd..963a3dc2fd 100644 --- a/include/mbgl/layermanager/custom_layer_factory.hpp +++ b/include/mbgl/gl/custom_layer_factory.hpp diff --git a/include/mbgl/platform/gl_functions.hpp b/include/mbgl/platform/gl_functions.hpp index fab3e3aa36..b617b35610 100644 --- a/include/mbgl/platform/gl_functions.hpp +++ b/include/mbgl/platform/gl_functions.hpp @@ -334,4 +334,4 @@ void glCheckError(const char *cmd, const char *file, int line); #endif } // namespace platform -} // namespace mbgl
\ No newline at end of file +} // namespace mbgl diff --git a/include/mbgl/platform/settings.hpp b/include/mbgl/platform/settings.hpp new file mode 100644 index 0000000000..80bfe1d60f --- /dev/null +++ b/include/mbgl/platform/settings.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include <mapbox/value.hpp> + +#include <memory> + +namespace mbgl { +namespace platform { + +#define DECLARE_MAPBOX_SETTING(name, value) constexpr const char* name = "mapbox_" #value + +// The value for EXPERIMENTAL_THREAD_PRIORITY_* keys, must be a double. +DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_WORKER, thread_priority_worker); +DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_FILE, thread_priority_file); +DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_NETWORK, thread_priority_network); +DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_DATABASE, thread_priority_database); + +// Settings class provides non-persistent, in-process key-value storage. +class Settings final { +public: + // Returns singleton instance + static Settings& getInstance() noexcept; + + // Sets setting value for a specified key. + void set(const std::string& key, mapbox::base::Value value) noexcept; + + // Sets multiple setting values by merging current Settings object + // with provided `values` object. + void set(mapbox::base::ValueObject values) noexcept; + + // Returns setting value for a specified key or NullValue if element + // for specified key is missing. + mapbox::base::Value get(const std::string& key) const noexcept; + + // Returns values for settings whose keys are equal to the ones provided in `keys` argument. + // Null values would be provided for keys whose elements are missing in Settings. + mapbox::base::ValueObject get(const std::vector<std::string>& keys) const noexcept; + +private: + Settings(); + +private: + class Impl; + std::unique_ptr<Impl> impl; +}; + +} // namespace platform +} // namespace mbgl diff --git a/include/mbgl/storage/database_file_source.hpp b/include/mbgl/storage/database_file_source.hpp index 81e5315fd8..9fb9ccdb3e 100644 --- a/include/mbgl/storage/database_file_source.hpp +++ b/include/mbgl/storage/database_file_source.hpp @@ -7,6 +7,12 @@ namespace mbgl { +// Properties that may be supported by database file sources. + +// Property to set database mode. When set, database opens in read-only mode; database opens in read-write-create mode +// otherwise. type: bool +constexpr const char* READ_ONLY_MODE_KEY = "read-only-mode"; + class ResourceOptions; // TODO: Split DatabaseFileSource into Ambient cache and Database interfaces. diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 9893daa8c4..0fd5c4959e 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -1,11 +1,12 @@ #pragma once -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/util/color.hpp> +#include <mbgl/style/expression/parsing_context.hpp> #include <mbgl/style/expression/type.hpp> #include <mbgl/style/expression/value.hpp> -#include <mbgl/style/expression/parsing_context.hpp> +#include <mbgl/tile/tile_id.hpp> +#include <mbgl/util/color.hpp> +#include <mbgl/util/optional.hpp> +#include <mbgl/util/variant.hpp> #include <array> #include <vector> @@ -53,14 +54,20 @@ public: return *this; }; + EvaluationContext& withCanonicalTileID(const mbgl::CanonicalTileID* canonical_) noexcept { + canonical = canonical_; + return *this; + }; + optional<float> zoom; optional<mbgl::Value> accumulated; - GeometryTileFeature const * feature = nullptr; + GeometryTileFeature const* feature = nullptr; optional<double> colorRampParameter; // Contains formatted section object, std::unordered_map<std::string, Value>. const Value* formattedSection = nullptr; const FeatureState* featureState = nullptr; const std::set<std::string>* availableImages = nullptr; + const mbgl::CanonicalTileID* canonical = nullptr; }; template <typename T> @@ -160,7 +167,8 @@ enum class Kind : int32_t { FormatExpression, FormatSectionOverride, NumberFormat, - ImageExpression + ImageExpression, + Within }; class Expression { @@ -183,6 +191,11 @@ public: const Feature& feature, optional<double> colorRampParameter, const std::set<std::string>& availableImages) const; + EvaluationResult evaluate(optional<float> zoom, + const Feature& feature, + optional<double> colorRampParameter, + const std::set<std::string>& availableImages, + const CanonicalTileID& canonical) const; EvaluationResult evaluate(optional<mbgl::Value> accumulated, const Feature& feature) const; /** diff --git a/include/mbgl/style/expression/within.hpp b/include/mbgl/style/expression/within.hpp new file mode 100644 index 0000000000..7e4050509d --- /dev/null +++ b/include/mbgl/style/expression/within.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/expression/expression.hpp> +#include <mbgl/style/expression/parsing_context.hpp> +#include <mbgl/util/geojson.hpp> + +#include <memory> + +namespace mbgl { +namespace style { +namespace expression { + +class Within final : public Expression { +public: + explicit Within(GeoJSON geojson); + + ~Within() override; + + EvaluationResult evaluate(const EvaluationContext&) const override; + + static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); + + void eachChild(const std::function<void(const Expression&)>&) const override {} + + bool operator==(const Expression& e) const override { + if (e.getKind() == Kind::Within) { + auto rhs = static_cast<const Within*>(&e); + return geoJSONSource == rhs->geoJSONSource; + } + return false; + } + + std::vector<optional<Value>> possibleOutputs() const override { return {{true}, {false}}; } + + mbgl::Value serialize() const override; + std::string getOperator() const override { return "within"; } + +private: + GeoJSON geoJSONSource; +}; + +} // namespace expression +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/image.hpp b/include/mbgl/style/image.hpp index 0d9c863e85..dd62d9e0ae 100644 --- a/include/mbgl/style/image.hpp +++ b/include/mbgl/style/image.hpp @@ -69,6 +69,7 @@ public: class Impl; Immutable<Impl> baseImpl; + explicit Image(Immutable<Impl> baseImpl_) : baseImpl(std::move(baseImpl_)) {} }; } // namespace style diff --git a/include/mbgl/style/property_expression.hpp b/include/mbgl/style/property_expression.hpp index 7dcd818dde..8502bfefbd 100644 --- a/include/mbgl/style/property_expression.hpp +++ b/include/mbgl/style/property_expression.hpp @@ -21,6 +21,11 @@ public: Range<float> getCoveringStops(const float, const float) const noexcept; const expression::Expression& getExpression() const noexcept; + // Can be used for aggregating property expressions from multiple + // properties(layers) into single match / case expression. Method may + // be removed if a better way of aggregation is found. + std::shared_ptr<const expression::Expression> getSharedExpression() const noexcept; + bool useIntegerZoom = false; protected: @@ -68,6 +73,20 @@ public: finalDefaultValue); } + T evaluate(const GeometryTileFeature& feature, const CanonicalTileID& canonical, T finalDefaultValue) const { + return evaluate(expression::EvaluationContext(&feature).withCanonicalTileID(&canonical), finalDefaultValue); + } + + T evaluate(const GeometryTileFeature& feature, + const std::set<std::string>& availableImages, + const CanonicalTileID& canonical, + T finalDefaultValue) const { + return evaluate(expression::EvaluationContext(&feature) + .withAvailableImages(&availableImages) + .withCanonicalTileID(&canonical), + finalDefaultValue); + } + T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const { return evaluate(expression::EvaluationContext(zoom, &feature), finalDefaultValue); } @@ -80,6 +99,25 @@ public: finalDefaultValue); } + T evaluate(float zoom, + const GeometryTileFeature& feature, + const std::set<std::string>& availableImages, + const CanonicalTileID& canonical, + T finalDefaultValue) const { + return evaluate(expression::EvaluationContext(zoom, &feature) + .withAvailableImages(&availableImages) + .withCanonicalTileID(&canonical), + finalDefaultValue); + } + + T evaluate(float zoom, + const GeometryTileFeature& feature, + const CanonicalTileID& canonical, + T finalDefaultValue) const { + return evaluate(expression::EvaluationContext(zoom, &feature).withCanonicalTileID(&canonical), + finalDefaultValue); + } + T evaluate(float zoom, const GeometryTileFeature& feature, const FeatureState& state, T finalDefaultValue) const { assert(!isFeatureConstant()); return evaluate(expression::EvaluationContext(zoom, &feature, &state), finalDefaultValue); diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index c3c0609a9f..59afd6916e 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -73,6 +73,8 @@ public: SourceObserver* observer = nullptr; virtual void loadDescription(FileSource&) = 0; + void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept; + optional<uint8_t> getPrefetchZoomDelta() const noexcept; void dumpDebugLogs() const; virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0; @@ -85,6 +87,9 @@ public: mapbox::base::TypeWrapper peer; virtual mapbox::base::WeakPtr<Source> makeWeakPtr() = 0; + +protected: + virtual Mutable<Impl> createMutable() const noexcept = 0; }; } // namespace style diff --git a/include/mbgl/style/sources/custom_geometry_source.hpp b/include/mbgl/style/sources/custom_geometry_source.hpp index ff04505699..504ec42ea8 100644 --- a/include/mbgl/style/sources/custom_geometry_source.hpp +++ b/include/mbgl/style/sources/custom_geometry_source.hpp @@ -50,6 +50,10 @@ public: mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } + +protected: + Mutable<Source::Impl> createMutable() const noexcept final; + private: std::shared_ptr<ThreadPool> threadPool; std::unique_ptr<Actor<CustomTileLoader>> loader; diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index 750d29627d..4bd250b895 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -81,6 +81,9 @@ public: return weakFactory.makeWeakPtr(); } +protected: + Mutable<Source::Impl> createMutable() const noexcept final; + private: optional<std::string> url; std::unique_ptr<AsyncRequest> req; diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp index 699a3c6494..d2b7c37bdf 100644 --- a/include/mbgl/style/sources/image_source.hpp +++ b/include/mbgl/style/sources/image_source.hpp @@ -33,6 +33,10 @@ public: mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } + +protected: + Mutable<Source::Impl> createMutable() const noexcept final; + private: optional<std::string> url; std::unique_ptr<AsyncRequest> req; diff --git a/include/mbgl/style/sources/raster_source.hpp b/include/mbgl/style/sources/raster_source.hpp index 00a3b788c2..e06c3404e9 100644 --- a/include/mbgl/style/sources/raster_source.hpp +++ b/include/mbgl/style/sources/raster_source.hpp @@ -31,6 +31,9 @@ public: return weakFactory.makeWeakPtr(); } +protected: + Mutable<Source::Impl> createMutable() const noexcept final; + private: const variant<std::string, Tileset> urlOrTileset; std::unique_ptr<AsyncRequest> req; diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp index 4165af0a61..83fcae95d6 100644 --- a/include/mbgl/style/sources/vector_source.hpp +++ b/include/mbgl/style/sources/vector_source.hpp @@ -30,6 +30,9 @@ public: return weakFactory.makeWeakPtr(); } +protected: + Mutable<Source::Impl> createMutable() const noexcept final; + private: const variant<std::string, Tileset> urlOrTileset; std::unique_ptr<AsyncRequest> req; diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index 1b39c3cbf3..e8d02e41b0 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -1,8 +1,10 @@ #pragma once -#include <mbgl/style/transition_options.hpp> #include <mbgl/map/camera.hpp> +#include <mbgl/style/image.hpp> +#include <mbgl/style/transition_options.hpp> #include <mbgl/util/geo.hpp> +#include <mbgl/util/immutable.hpp> #include <string> #include <vector> @@ -16,7 +18,6 @@ class ResourceOptions; namespace style { class Light; -class Image; class Source; class Layer; class StyleImpl; @@ -48,7 +49,7 @@ public: void setLight(std::unique_ptr<Light>); // Images - const Image* getImage(const std::string&) const; + optional<Image> getImage(const std::string&) const; void addImage(std::unique_ptr<Image>); void removeImage(const std::string&); diff --git a/include/mbgl/util/platform.hpp b/include/mbgl/util/platform.hpp index 3544659740..917b98483d 100644 --- a/include/mbgl/util/platform.hpp +++ b/include/mbgl/util/platform.hpp @@ -22,5 +22,9 @@ void setCurrentThreadName(const std::string& name); // Makes the current thread low priority. void makeThreadLowPriority(); +// Sets priority of a current thread. Platform implementation +// must validate provided value. +void setCurrentThreadPriority(double priority); + } // namespace platform } // namespace mbgl diff --git a/include/mbgl/util/thread.hpp b/include/mbgl/util/thread.hpp index ab0403e44e..4bc948fdbd 100644 --- a/include/mbgl/util/thread.hpp +++ b/include/mbgl/util/thread.hpp @@ -3,10 +3,10 @@ #include <mbgl/actor/actor.hpp> #include <mbgl/actor/mailbox.hpp> #include <mbgl/actor/scheduler.hpp> +#include <mbgl/platform/thread.hpp> #include <mbgl/util/platform.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/util.hpp> -#include <mbgl/platform/thread.hpp> #include <cassert> #include <future> @@ -37,25 +37,20 @@ namespace util { // - A `RunLoop` is created for the `Object` thread. // - `Object` can use `Timer` and do asynchronous I/O, like wait for sockets events. // -template<class Object> +template <typename Object> class Thread { public: - template <class... Args> - Thread(const std::string& name, Args&&... args) { - + template <typename TupleArgs> + Thread(std::function<void()> prioritySetter_, const std::string& name, TupleArgs&& args) { std::promise<void> running_; running = running_.get_future(); - - auto capturedArgs = std::make_tuple(std::forward<Args>(args)...); - - thread = std::thread([ - this, - name, - capturedArgs = std::move(capturedArgs), - runningPromise = std::move(running_) - ] () mutable { + thread = std::thread([this, + name, + capturedArgs = std::forward<TupleArgs>(args), + runningPromise = std::move(running_), + prioritySetter = std::move(prioritySetter_)]() mutable { platform::setCurrentThreadName(name); - platform::makeThreadLowPriority(); + if (prioritySetter) prioritySetter(); platform::attachThread(); // narrowing the scope to release the Object before we detach the thread @@ -77,6 +72,14 @@ public: }); } + template <typename... Args> + Thread(const std::string& name, Args&&... args) + : Thread([] { platform::makeThreadLowPriority(); }, name, std::make_tuple(std::forward<Args>(args)...)) {} + + template <typename... Args> + Thread(std::function<void()> prioritySetter, const std::string& name, Args&&... args) + : Thread(std::move(prioritySetter), name, std::make_tuple(std::forward<Args>(args)...)) {} + ~Thread() { if (paused) { resume(); @@ -158,5 +161,10 @@ private: util::RunLoop* loop = nullptr; }; +// Returns function, that once invoked, will set a thread priority for +// a thread `threadType` based on a setting provided by corresponding +// Settings' platform::EXPERIMENTAL_THREAD_PRIORITY_* value. +std::function<void()> makeThreadPrioritySetter(std::string threadType); + } // namespace util } // namespace mbgl |