diff options
Diffstat (limited to 'include')
31 files changed, 257 insertions, 519 deletions
diff --git a/include/mbgl/gl/implementation.hpp b/include/mbgl/gl/implementation.hpp deleted file mode 100644 index a0101085fa..0000000000 --- a/include/mbgl/gl/implementation.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#if defined(__QT__) - #define MBGL_USE_QT 1 -#elif defined(__APPLE__) - #include <TargetConditionals.h> - #if TARGET_OS_IOS - #define MBGL_USE_EAGL 1 - #else - #define MBGL_USE_CGL 1 - #endif -#elif defined(__OSMESA__) - #define MBGL_USE_OSMESA 1 -#else - #define MBGL_USE_GLX 1 -#endif diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 092cfbe291..c80420371d 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -6,6 +6,7 @@ #include <mbgl/util/geo.hpp> #include <mbgl/util/feature.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/size.hpp> #include <mbgl/annotation/annotation.hpp> #include <mbgl/style/transition_options.hpp> @@ -33,7 +34,7 @@ class Layer; class Map : private util::noncopyable { public: explicit Map(Backend&, - std::array<uint16_t, 2> size, + Size size, float pixelRatio, FileSource&, Scheduler&, @@ -136,9 +137,8 @@ public: ViewportMode getViewportMode() const; // Size - void setSize(const std::array<uint16_t, 2>&); - uint16_t getWidth() const; - uint16_t getHeight() const; + void setSize(Size); + Size getSize() const; // Projection double getMetersPerPixelAtLatitude(double lat, double zoom) const; diff --git a/include/mbgl/math/log2.hpp b/include/mbgl/math/log2.hpp new file mode 100644 index 0000000000..8a3bc7f1c0 --- /dev/null +++ b/include/mbgl/math/log2.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include <cmath> +#include <cstdint> +#include <type_traits> + +namespace mbgl { +namespace util { + +// Computes the log2(x) rounded up to the next integer. +// (== number of bits required to store x) +uint32_t ceil_log2(uint64_t x); + +template <typename T> +typename std::enable_if_t<std::is_floating_point<T>::value, T> log2(T x) +{ +// log2() is producing wrong results on ARMv5 binaries +// running on ARMv7+ CPUs. +#if defined(__ANDROID__) + return std::log(x) / M_LN2; +#else + return std::log2(x); +#endif +} + +} // namespace util +} // namespace mbgl diff --git a/include/mbgl/mbgl.hpp b/include/mbgl/mbgl.hpp deleted file mode 100644 index 5cfc9cb45f..0000000000 --- a/include/mbgl/mbgl.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#include "map/map.hpp" -#include "map/view.hpp" diff --git a/include/mbgl/platform/darwin/reachability.h b/include/mbgl/platform/darwin/reachability.h deleted file mode 100644 index 78e302eafc..0000000000 --- a/include/mbgl/platform/darwin/reachability.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#import <Foundation/Foundation.h> -#import <SystemConfiguration/SystemConfiguration.h> - - -/** - * Create NS_ENUM macro if it does not exist on the targeted version of iOS or OS X. - * - * @see http://nshipster.com/ns_enum-ns_options/ - **/ -#ifndef NS_ENUM -#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type -#endif - -extern NSString *const kMGLReachabilityChangedNotification; - -typedef NS_ENUM(NSInteger, NetworkStatus) { - // Apple NetworkStatus Compatible Names. - NotReachable = 0, - ReachableViaWiFi = 2, - ReachableViaWWAN = 1 -}; - -@class MGLReachability; - -typedef void (^NetworkReachable)(MGLReachability * reachability); -typedef void (^NetworkUnreachable)(MGLReachability * reachability); - - -@interface MGLReachability : NSObject - -@property (nonatomic, copy) NetworkReachable reachableBlock; -@property (nonatomic, copy) NetworkUnreachable unreachableBlock; - -@property (nonatomic, assign) BOOL reachableOnWWAN; - - -+(instancetype)reachabilityWithHostname:(NSString*)hostname; -// This is identical to the function above, but is here to maintain -//compatibility with Apples original code. (see .m) -+(instancetype)reachabilityWithHostName:(NSString*)hostname; -+(instancetype)reachabilityForInternetConnection; -+(instancetype)reachabilityWithAddress:(void *)hostAddress; -+(instancetype)reachabilityForLocalWiFi; - --(instancetype)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; - --(BOOL)startNotifier; --(void)stopNotifier; - --(BOOL)isReachable; --(BOOL)isReachableViaWWAN; --(BOOL)isReachableViaWiFi; - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired; // Identical DDG variant. --(BOOL)connectionRequired; // Apple's routine. -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand; -// Is user intervention required? --(BOOL)isInterventionRequired; - --(NetworkStatus)currentReachabilityStatus; --(SCNetworkReachabilityFlags)reachabilityFlags; --(NSString*)currentReachabilityString; --(NSString*)currentReachabilityFlags; - -@end diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp deleted file mode 100644 index e832cd70d1..0000000000 --- a/include/mbgl/platform/default/glfw_view.hpp +++ /dev/null @@ -1,111 +0,0 @@ -#pragma once - -#include <mbgl/mbgl.hpp> -#include <mbgl/map/backend.hpp> -#include <mbgl/util/run_loop.hpp> -#include <mbgl/util/timer.hpp> -#include <mbgl/util/geometry.hpp> - -#if MBGL_USE_GLES2 -#define GLFW_INCLUDE_ES2 -#endif -#define GL_GLEXT_PROTOTYPES -#include <GLFW/glfw3.h> - -class GLFWView : public mbgl::View, public mbgl::Backend { -public: - GLFWView(bool fullscreen = false, bool benchmark = false); - ~GLFWView() override; - - float getPixelRatio() const; - - void setMap(mbgl::Map*); - - // Callback called when the user presses the key mapped to style change. - // The expected action is to set a new style, different to the current one. - void setChangeStyleCallback(std::function<void()> callback); - - void setShouldClose(); - - void setWindowTitle(const std::string&); - - void run(); - - // mbgl::View implementation - void updateViewBinding(); - void bind() override; - std::array<uint16_t, 2> getSize() const; - std::array<uint16_t, 2> getFramebufferSize() const; - - // mbgl::Backend implementation - void activate() override; - void deactivate() override; - void invalidate() override; - -private: - // Window callbacks - static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods); - static void onScroll(GLFWwindow *window, double xoffset, double yoffset); - static void onWindowResize(GLFWwindow *window, int width, int height); - static void onFramebufferResize(GLFWwindow *window, int width, int height); - static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers); - static void onMouseMove(GLFWwindow *window, double x, double y); - - // Internal - void report(float duration); - - void setMapChangeCallback(std::function<void(mbgl::MapChange)> callback); - void notifyMapChange(mbgl::MapChange change) override; - - mbgl::Color makeRandomColor() const; - mbgl::Point<double> makeRandomPoint() const; - static std::shared_ptr<const mbgl::SpriteImage> - makeSpriteImage(int width, int height, float pixelRatio); - - void nextOrientation(); - - void addRandomPointAnnotations(int count); - void addRandomLineAnnotations(int count); - void addRandomShapeAnnotations(int count); - void addRandomCustomPointAnnotations(int count); - - void clearAnnotations(); - void popAnnotation(); - - mbgl::AnnotationIDs annotationIDs; - std::vector<std::string> spriteIDs; - - std::function<void(mbgl::MapChange)> mapChangeCallback; - -private: - mbgl::Map* map = nullptr; - - bool fullscreen = false; - const bool benchmark = false; - bool tracking = false; - bool rotating = false; - bool pitching = false; - - // Frame timer - int frames = 0; - float frameTime = 0; - double lastReported = 0; - - int width = 1024; - int height = 768; - int fbWidth; - int fbHeight; - float pixelRatio; - - double lastX = 0, lastY = 0; - - double lastClick = -1; - - std::function<void()> changeStyleCallback; - - mbgl::util::RunLoop runLoop; - mbgl::util::Timer frameTick; - - GLFWwindow *window = nullptr; - bool dirty = false; -}; diff --git a/include/mbgl/platform/default/headless_backend.hpp b/include/mbgl/platform/default/headless_backend.hpp deleted file mode 100644 index b6c654943f..0000000000 --- a/include/mbgl/platform/default/headless_backend.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include <mbgl/gl/implementation.hpp> - -#if MBGL_USE_QT -class QGLWidget; -#elif MBGL_USE_CGL -#include <OpenGL/OpenGL.h> -#elif MBGL_USE_GLX -typedef struct _XDisplay Display; -typedef struct __GLXcontextRec* GLXContext; -typedef struct __GLXFBConfigRec* GLXFBConfig; -typedef long unsigned int XID; -typedef XID GLXPbuffer; -#elif MBGL_USE_OSMESA -#include <GL/osmesa.h> -#endif - -#include <mbgl/map/backend.hpp> -#include <mbgl/gl/extension.hpp> - -#include <memory> -#include <functional> - -namespace mbgl { - -class HeadlessDisplay; - -class HeadlessBackend : public Backend { -public: - HeadlessBackend(); - HeadlessBackend(std::shared_ptr<HeadlessDisplay>); - ~HeadlessBackend() override; - - void invalidate() override; - void activate() override; - void deactivate() override; - void notifyMapChange(MapChange) override; - - void setMapChangeCallback(std::function<void(MapChange)>&& cb) { mapChangeCallback = std::move(cb); } - -private: - void activateContext(); - void deactivateContext(); - -private: - // Implementation specific functions - static gl::glProc initializeExtension(const char*); - void createContext(); - void destroyContext(); - - std::shared_ptr<HeadlessDisplay> display; - - bool extensionsLoaded = false; - bool active = false; - -#if MBGL_USE_QT - QGLWidget* glContext = nullptr; -#endif - -#if MBGL_USE_CGL - CGLContextObj glContext = nullptr; -#endif - -#if MBGL_USE_EAGL - void *glContext = nullptr; -#endif - -#if MBGL_USE_GLX - Display *xDisplay = nullptr; - GLXFBConfig *fbConfigs = nullptr; - GLXContext glContext = nullptr; - GLXPbuffer glxPbuffer = 0; -#endif - -#if MBGL_USE_OSMESA - OSMesaContext glContext = nullptr; - GLubyte fakeBuffer = 0; -#endif - - std::function<void(MapChange)> mapChangeCallback; - -}; - -} // namespace mbgl diff --git a/include/mbgl/platform/default/headless_display.hpp b/include/mbgl/platform/default/headless_display.hpp deleted file mode 100644 index f43e61340f..0000000000 --- a/include/mbgl/platform/default/headless_display.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include <mbgl/gl/implementation.hpp> - -#if MBGL_USE_CGL -#include <OpenGL/OpenGL.h> -#elif MBGL_USE_GLX -typedef struct _XDisplay Display; -typedef struct __GLXFBConfigRec* GLXFBConfig; -#endif - -namespace mbgl { - -class HeadlessDisplay { -public: - HeadlessDisplay(); - ~HeadlessDisplay(); - -#if MBGL_USE_CGL - CGLPixelFormatObj pixelFormat = nullptr; -#endif - -#if MBGL_USE_GLX - Display *xDisplay = nullptr; - GLXFBConfig *fbConfigs = nullptr; -#endif -}; - -} // namespace mbgl diff --git a/include/mbgl/platform/default/offscreen_view.hpp b/include/mbgl/platform/default/offscreen_view.hpp deleted file mode 100644 index 034aa3aaf3..0000000000 --- a/include/mbgl/platform/default/offscreen_view.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include <mbgl/map/view.hpp> -#include <mbgl/gl/framebuffer.hpp> -#include <mbgl/gl/renderbuffer.hpp> -#include <mbgl/util/optional.hpp> -#include <mbgl/util/image.hpp> - -namespace mbgl { - -namespace gl { -class Context; -} // namespace gl - -class OffscreenView : public View { -public: - OffscreenView(gl::Context&, std::array<uint16_t, 2> size = {{ 256, 256 }}); - - void bind() override; - - PremultipliedImage readStillImage(); - - std::array<uint16_t, 2> getSize() const; - -private: - gl::Context& context; - std::array<uint16_t, 2> size; - optional<gl::Framebuffer> framebuffer; - optional<gl::Renderbuffer<gl::RenderbufferType::RGBA>> color; - optional<gl::Renderbuffer<gl::RenderbufferType::DepthStencil>> depthStencil; -}; - -} // namespace mbgl diff --git a/include/mbgl/platform/default/settings_json.hpp b/include/mbgl/platform/default/settings_json.hpp deleted file mode 100644 index eb23b28bc8..0000000000 --- a/include/mbgl/platform/default/settings_json.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <mbgl/map/mode.hpp> - -namespace mbgl { - -class Settings_JSON { -public: - Settings_JSON(); - void load(); - void save(); - void clear(); - -public: - double longitude = 0; - double latitude = 0; - double zoom = 0; - double bearing = 0; - double pitch = 0; - - EnumType debug = 0; -}; - -} // namespace mbgl diff --git a/include/mbgl/platform/default/thread_pool.hpp b/include/mbgl/platform/default/thread_pool.hpp deleted file mode 100644 index a14d16d771..0000000000 --- a/include/mbgl/platform/default/thread_pool.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include <mbgl/actor/scheduler.hpp> - -#include <condition_variable> -#include <mutex> -#include <queue> -#include <thread> - -namespace mbgl { - -class ThreadPool : public Scheduler { -public: - ThreadPool(std::size_t count); - ~ThreadPool() override; - - void schedule(std::weak_ptr<Mailbox>) override; - -private: - std::vector<std::thread> threads; - std::queue<std::weak_ptr<Mailbox>> queue; - std::mutex mutex; - std::condition_variable cv; - bool terminate { false }; -}; - -} // namespace mbgl diff --git a/include/mbgl/sprite/sprite_image.hpp b/include/mbgl/sprite/sprite_image.hpp index 7900b90b66..05d9871bf9 100644 --- a/include/mbgl/sprite/sprite_image.hpp +++ b/include/mbgl/sprite/sprite_image.hpp @@ -22,8 +22,8 @@ public: // Whether this image should be interpreted as a signed distance field icon. const bool sdf; - float getWidth() const { return image.width / pixelRatio; } - float getHeight() const { return image.height / pixelRatio; } + float getWidth() const { return image.size.width / pixelRatio; } + float getHeight() const { return image.size.height / pixelRatio; } }; } // namespace mbgl diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index f14b5089be..6a0b67618f 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -25,6 +25,10 @@ struct Converter<Function<T>> { return Error { "function stops must be an array" }; } + if (arrayLength(*stopsValue) == 0) { + return Error { "function must have at least one stop" }; + } + std::vector<std::pair<float, T>> stops; for (std::size_t i = 0; i < arrayLength(*stopsValue); ++i) { const auto& stopValue = arrayMember(*stopsValue, i); diff --git a/include/mbgl/style/conversion/make_property_setters.hpp b/include/mbgl/style/conversion/make_property_setters.hpp index a3ba5e5d5a..e30359937e 100644 --- a/include/mbgl/style/conversion/make_property_setters.hpp +++ b/include/mbgl/style/conversion/make_property_setters.hpp @@ -8,6 +8,7 @@ #include <mbgl/style/layers/line_layer.hpp> #include <mbgl/style/layers/symbol_layer.hpp> #include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/fill_extrusion_layer.hpp> #include <mbgl/style/layers/raster_layer.hpp> #include <mbgl/style/layers/background_layer.hpp> @@ -67,6 +68,7 @@ auto makeLayoutPropertySetters() { + return result; } @@ -115,6 +117,17 @@ auto makePaintPropertySetters() { result["circle-translate"] = makePropertySetter<V>(&CircleLayer::setCircleTranslate); result["circle-translate-anchor"] = makePropertySetter<V>(&CircleLayer::setCircleTranslateAnchor); result["circle-pitch-scale"] = makePropertySetter<V>(&CircleLayer::setCirclePitchScale); + result["circle-stroke-width"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeWidth); + result["circle-stroke-color"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeColor); + result["circle-stroke-opacity"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeOpacity); + + result["fill-extrusion-opacity"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionOpacity); + result["fill-extrusion-color"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionColor); + result["fill-extrusion-translate"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionTranslate); + result["fill-extrusion-translate-anchor"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionTranslateAnchor); + result["fill-extrusion-pattern"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionPattern); + result["fill-extrusion-height"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionHeight); + result["fill-extrusion-base"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionBase); result["raster-opacity"] = makePropertySetter<V>(&RasterLayer::setRasterOpacity); result["raster-hue-rotate"] = makePropertySetter<V>(&RasterLayer::setRasterHueRotate); diff --git a/include/mbgl/style/conversion/make_property_setters.hpp.ejs b/include/mbgl/style/conversion/make_property_setters.hpp.ejs index 54e3958180..ed8f6e891c 100644 --- a/include/mbgl/style/conversion/make_property_setters.hpp.ejs +++ b/include/mbgl/style/conversion/make_property_setters.hpp.ejs @@ -5,7 +5,7 @@ #include <mbgl/style/conversion/property_setter.hpp> <% for (const layer of locals.layers) { -%> -#include <mbgl/style/layers/<%- layer.type %>_layer.hpp> +#include <mbgl/style/layers/<%- layer.type.replace('-', '_') %>_layer.hpp> <% } -%> #include <unordered_map> diff --git a/include/mbgl/style/function.hpp b/include/mbgl/style/function.hpp index 97e880b280..b023229e4f 100644 --- a/include/mbgl/style/function.hpp +++ b/include/mbgl/style/function.hpp @@ -1,7 +1,8 @@ #pragma once -#include <vector> +#include <cassert> #include <utility> +#include <vector> namespace mbgl { namespace style { @@ -12,28 +13,28 @@ public: using Stop = std::pair<float, T>; using Stops = std::vector<Stop>; - explicit Function(Stops stops_, float base_) - : base(base_), stops(std::move(stops_)) {} + Function(Stops stops_, float base_) + : base(base_), stops(std::move(stops_)) { + assert(stops.size() > 0); + } float getBase() const { return base; } const std::vector<std::pair<float, T>>& getStops() const { return stops; } + T evaluate(float z) const; + + friend bool operator==(const Function& lhs, const Function& rhs) { + return lhs.base == rhs.base && lhs.stops == rhs.stops; + } + + friend bool operator!=(const Function& lhs, const Function& rhs) { + return !(lhs == rhs); + } + private: float base = 1; std::vector<std::pair<float, T>> stops; - - template <class S> friend bool operator==(const Function<S>&, const Function<S>&); }; -template <class T> -bool operator==(const Function<T>& lhs, const Function<T>& rhs) { - return lhs.base == rhs.base && lhs.stops == rhs.stops; -} - -template <class T> -bool operator!=(const Function<T>& lhs, const Function<T>& rhs) { - return !(lhs == rhs); -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 925629a349..dc02cb09b2 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -15,6 +15,7 @@ class SymbolLayer; class RasterLayer; class BackgroundLayer; class CustomLayer; +class FillExtrusionLayer; /** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style @@ -42,6 +43,7 @@ protected: Raster, Background, Custom, + FillExtrusion, }; class Impl; @@ -95,6 +97,8 @@ public: return visitor(*as<BackgroundLayer>()); case Type::Custom: return visitor(*as<CustomLayer>()); + case Type::FillExtrusion: + return visitor(*as<FillExtrusionLayer>()); } } diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 587f0023e3..5562126c2f 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -54,6 +54,18 @@ public: PropertyValue<CirclePitchScaleType> getCirclePitchScale(const optional<std::string>& klass = {}) const; void setCirclePitchScale(PropertyValue<CirclePitchScaleType>, const optional<std::string>& klass = {}); + static PropertyValue<float> getDefaultCircleStrokeWidth(); + PropertyValue<float> getCircleStrokeWidth(const optional<std::string>& klass = {}) const; + void setCircleStrokeWidth(PropertyValue<float>, const optional<std::string>& klass = {}); + + static PropertyValue<Color> getDefaultCircleStrokeColor(); + PropertyValue<Color> getCircleStrokeColor(const optional<std::string>& klass = {}) const; + void setCircleStrokeColor(PropertyValue<Color>, const optional<std::string>& klass = {}); + + static PropertyValue<float> getDefaultCircleStrokeOpacity(); + PropertyValue<float> getCircleStrokeOpacity(const optional<std::string>& klass = {}) const; + void setCircleStrokeOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); + // Private implementation class Impl; diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp new file mode 100644 index 0000000000..08728af309 --- /dev/null +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -0,0 +1,72 @@ +// This file is generated. Do not edit. + +#pragma once + +#include <mbgl/style/layer.hpp> +#include <mbgl/style/filter.hpp> +#include <mbgl/style/property_value.hpp> + +#include <mbgl/util/color.hpp> + +namespace mbgl { +namespace style { + +class FillExtrusionLayer : public Layer { +public: + FillExtrusionLayer(const std::string& layerID, const std::string& sourceID); + ~FillExtrusionLayer() final; + + // Source + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + void setSourceLayer(const std::string& sourceLayer); + + void setFilter(const Filter&); + const Filter& getFilter() const; + + // Paint properties + + static PropertyValue<float> getDefaultFillExtrusionOpacity(); + PropertyValue<float> getFillExtrusionOpacity(const optional<std::string>& klass = {}) const; + void setFillExtrusionOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); + + static PropertyValue<Color> getDefaultFillExtrusionColor(); + PropertyValue<Color> getFillExtrusionColor(const optional<std::string>& klass = {}) const; + void setFillExtrusionColor(PropertyValue<Color>, const optional<std::string>& klass = {}); + + static PropertyValue<std::array<float, 2>> getDefaultFillExtrusionTranslate(); + PropertyValue<std::array<float, 2>> getFillExtrusionTranslate(const optional<std::string>& klass = {}) const; + void setFillExtrusionTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {}); + + static PropertyValue<TranslateAnchorType> getDefaultFillExtrusionTranslateAnchor(); + PropertyValue<TranslateAnchorType> getFillExtrusionTranslateAnchor(const optional<std::string>& klass = {}) const; + void setFillExtrusionTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {}); + + static PropertyValue<std::string> getDefaultFillExtrusionPattern(); + PropertyValue<std::string> getFillExtrusionPattern(const optional<std::string>& klass = {}) const; + void setFillExtrusionPattern(PropertyValue<std::string>, const optional<std::string>& klass = {}); + + static PropertyValue<float> getDefaultFillExtrusionHeight(); + PropertyValue<float> getFillExtrusionHeight(const optional<std::string>& klass = {}) const; + void setFillExtrusionHeight(PropertyValue<float>, const optional<std::string>& klass = {}); + + static PropertyValue<float> getDefaultFillExtrusionBase(); + PropertyValue<float> getFillExtrusionBase(const optional<std::string>& klass = {}) const; + void setFillExtrusionBase(PropertyValue<float>, const optional<std::string>& klass = {}); + + // Private implementation + + class Impl; + Impl* const impl; + + FillExtrusionLayer(const Impl&); + FillExtrusionLayer(const FillExtrusionLayer&) = delete; +}; + +template <> +inline bool Layer::is<FillExtrusionLayer>() const { + return type == Type::FillExtrusion; +} + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index d7e160fdca..83c4b4cf1b 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -17,7 +17,13 @@ private: using Value = variant<Undefined, T, Function<T>>; Value value; - template <class S> friend bool operator==(const PropertyValue<S>&, const PropertyValue<S>&); + friend bool operator==(const PropertyValue& lhs, const PropertyValue& rhs) { + return lhs.value == rhs.value; + } + + friend bool operator!=(const PropertyValue& lhs, const PropertyValue& rhs) { + return !(lhs == rhs); + } public: PropertyValue() : value() {} @@ -33,21 +39,11 @@ public: explicit operator bool() const { return !isUndefined(); }; - template <typename Visitor> - static auto visit(const PropertyValue<T>& value, Visitor&& visitor) { - return Value::visit(value.value, visitor); + template <typename Evaluator> + auto evaluate(const Evaluator& evaluator) const { + return Value::visit(value, evaluator); } }; -template <class T> -bool operator==(const PropertyValue<T>& lhs, const PropertyValue<T>& rhs) { - return lhs.value == rhs.value; -} - -template <class T> -bool operator!=(const PropertyValue<T>& lhs, const PropertyValue<T>& rhs) { - return !(lhs == rhs); -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/transition_options.hpp b/include/mbgl/style/transition_options.hpp index d7a6633f0c..e2a156e665 100644 --- a/include/mbgl/style/transition_options.hpp +++ b/include/mbgl/style/transition_options.hpp @@ -6,9 +6,21 @@ namespace mbgl { namespace style { -struct TransitionOptions { +class TransitionOptions { +public: optional<Duration> duration = {}; optional<Duration> delay = {}; + + TransitionOptions reverseMerge(const TransitionOptions& defaults) const { + return { + duration ? duration : defaults.duration, + delay ? delay : defaults.delay + }; + } + + explicit operator bool() const { + return duration || delay; + } }; } // namespace style diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp index 4be380fde3..178d0dc758 100644 --- a/include/mbgl/util/color.hpp +++ b/include/mbgl/util/color.hpp @@ -2,6 +2,7 @@ #include <mbgl/util/optional.hpp> +#include <cassert> #include <string> namespace mbgl { @@ -9,6 +10,19 @@ namespace mbgl { // Stores a premultiplied color, with all four channels ranging from 0..1 class Color { public: + constexpr Color() = default; + constexpr Color(float r_, float g_, float b_, float a_) + : r(r_), g(g_), b(b_), a(a_) { + assert(r_ >= 0.0f); + assert(r_ <= 1.0f); + assert(g_ >= 0.0f); + assert(g_ <= 1.0f); + assert(b_ >= 0.0f); + assert(b_ <= 1.0f); + assert(a_ >= 0.0f); + assert(a_ <= 1.0f); + } + float r = 0.0f; float g = 0.0f; float b = 0.0f; @@ -17,6 +31,10 @@ public: static constexpr Color black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; }; static constexpr Color white() { return { 1.0f, 1.0f, 1.0f, 1.0f }; }; + static constexpr Color red() { return { 1.0f, 0.0f, 0.0f, 1.0f }; }; + static constexpr Color green() { return { 0.0f, 1.0f, 0.0f, 1.0f }; }; + static constexpr Color blue() { return { 0.0f, 0.0f, 1.0f, 1.0f }; }; + static optional<Color> parse(const std::string&); }; @@ -29,6 +47,8 @@ constexpr bool operator!=(const Color& colorA, const Color& colorB) { } constexpr Color operator*(const Color& color, float alpha) { + assert(alpha >= 0.0f); + assert(alpha <= 1.0f); return { color.r * alpha, color.g * alpha, diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index e6e9f6e67d..85e19c2ff0 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -35,6 +35,8 @@ constexpr double DEGREES_MAX = 360; constexpr double PITCH_MAX = M_PI / 3; constexpr double MIN_ZOOM = 0.0; constexpr double MAX_ZOOM = 25.5; +constexpr float MIN_ZOOM_F = MIN_ZOOM; +constexpr float MAX_ZOOM_F = MAX_ZOOM; constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024; diff --git a/include/mbgl/util/default_styles.hpp b/include/mbgl/util/default_styles.hpp deleted file mode 100644 index eb7e034722..0000000000 --- a/include/mbgl/util/default_styles.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include <vector> -#include <string> - -namespace mbgl { -namespace util { -namespace default_styles { - -struct DefaultStyle { - const char* url; - const char* name; -}; - -extern const DefaultStyle streets; -extern const DefaultStyle outdoors; -extern const DefaultStyle light; -extern const DefaultStyle dark; -extern const DefaultStyle satellite; -extern const DefaultStyle satelliteStreets; - -const DefaultStyle orderedStyles[] = { - streets, outdoors, light, dark, satellite, satelliteStreets, -}; -const size_t numOrderedStyles = sizeof(orderedStyles) / sizeof(DefaultStyle); - -static const unsigned currentVersion = 9; - -} // end namespace default_styles -} // end namespace util -} // end namespace mbgl diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/util/event.hpp index 7ad3d914e8..7ad3d914e8 100644 --- a/include/mbgl/platform/event.hpp +++ b/include/mbgl/util/event.hpp diff --git a/include/mbgl/util/exception.hpp b/include/mbgl/util/exception.hpp index 7c331636d4..46de8528c7 100644 --- a/include/mbgl/util/exception.hpp +++ b/include/mbgl/util/exception.hpp @@ -20,10 +20,5 @@ struct MisuseException : Exception { MisuseException(const std::string &msg) : Exception(msg) {} }; -struct ShaderException : Exception { - ShaderException(const char *msg) : Exception(msg) {} - ShaderException(const std::string &msg) : Exception(msg) {} -}; - } // namespace util } // namespace mbgl diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index 795d1f9d1a..1d84d4824a 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/size.hpp> #include <string> #include <memory> @@ -8,9 +9,10 @@ namespace mbgl { -enum ImageAlphaMode { +enum class ImageAlphaMode { Unassociated, - Premultiplied + Premultiplied, + Exclusive, // Alpha-channel only }; template <ImageAlphaMode Mode> @@ -18,44 +20,45 @@ class Image : private util::noncopyable { public: Image() = default; - Image(uint16_t w, uint16_t h) - : width(w), - height(h), - data(std::make_unique<uint8_t[]>(size())) {} + Image(Size size_) + : size(std::move(size_)), + data(std::make_unique<uint8_t[]>(bytes())) {} - Image(uint16_t w, uint16_t h, std::unique_ptr<uint8_t[]> data_) - : width(w), - height(h), + Image(Size size_, std::unique_ptr<uint8_t[]> data_) + : size(std::move(size_)), data(std::move(data_)) {} Image(Image&& o) - : width(o.width), - height(o.height), + : size(o.size), data(std::move(o.data)) {} Image& operator=(Image&& o) { - width = o.width; - height = o.height; + size = o.size; data = std::move(o.data); return *this; } bool operator==(const Image& rhs) const { - return width == rhs.width && height == rhs.height && - std::equal(data.get(), data.get() + size(), rhs.data.get(), - rhs.data.get() + rhs.size()); + return size == rhs.size && + std::equal(data.get(), data.get() + bytes(), rhs.data.get(), + rhs.data.get() + rhs.bytes()); } - size_t stride() const { return static_cast<size_t>(width) * 4; } - size_t size() const { return static_cast<size_t>(width) * height * 4; } + bool valid() const { + return size && data.get() != nullptr; + } + + size_t stride() const { return channels * size.width; } + size_t bytes() const { return stride() * size.height; } - uint16_t width = 0; - uint16_t height = 0; + Size size; + static constexpr size_t channels = Mode == ImageAlphaMode::Exclusive ? 1 : 4; std::unique_ptr<uint8_t[]> data; }; using UnassociatedImage = Image<ImageAlphaMode::Unassociated>; using PremultipliedImage = Image<ImageAlphaMode::Premultiplied>; +using AlphaImage = Image<ImageAlphaMode::Exclusive>; // TODO: don't use std::string for binary data. PremultipliedImage decodeImage(const std::string&); diff --git a/include/mbgl/platform/log.hpp b/include/mbgl/util/logging.hpp index d5bb1c2fcc..d072673e76 100644 --- a/include/mbgl/platform/log.hpp +++ b/include/mbgl/util/logging.hpp @@ -1,6 +1,6 @@ #pragma once -#include <mbgl/platform/event.hpp> +#include <mbgl/util/event.hpp> #include <mbgl/util/noncopyable.hpp> diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/util/platform.hpp index cc8327c470..cc8327c470 100644 --- a/include/mbgl/platform/platform.hpp +++ b/include/mbgl/util/platform.hpp diff --git a/include/mbgl/util/range.hpp b/include/mbgl/util/range.hpp index 8da2dd45bb..f7fa92eb8b 100644 --- a/include/mbgl/util/range.hpp +++ b/include/mbgl/util/range.hpp @@ -5,7 +5,7 @@ namespace mbgl { template <class T> class Range { public: - Range(const T& min_, const T& max_) + constexpr Range(const T& min_, const T& max_) : min(min_), max(max_) {} T min; diff --git a/include/mbgl/util/size.hpp b/include/mbgl/util/size.hpp new file mode 100644 index 0000000000..1af85bcff5 --- /dev/null +++ b/include/mbgl/util/size.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include <cstdint> +#include <array> + +namespace mbgl { + +class Size { +public: + constexpr Size() : width(0), height(0) { + } + + constexpr Size(const uint32_t width_, const uint32_t height_) : width(width_), height(height_) { + } + + constexpr explicit operator bool() const { + return width > 0 && height > 0; + } + + uint32_t width; + uint32_t height; +}; + +constexpr inline bool operator==(const Size& a, const Size& b) { + return a.width == b.width && a.height == b.height; +} + +constexpr inline bool operator!=(const Size& a, const Size& b) { + return !(a == b); +} + +} // namespace mbgl |