diff options
Diffstat (limited to 'include/mbgl/map')
-rw-r--r-- | include/mbgl/map/map.hpp | 80 | ||||
-rw-r--r-- | include/mbgl/map/raster_tile_data.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/map/source.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/map/sprite.hpp | 6 | ||||
-rw-r--r-- | include/mbgl/map/tile.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/map/tile_data.hpp | 17 | ||||
-rw-r--r-- | include/mbgl/map/tile_parser.hpp | 30 | ||||
-rw-r--r-- | include/mbgl/map/transform.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/map/vector_tile_data.hpp | 6 | ||||
-rw-r--r-- | include/mbgl/map/view.hpp | 2 |
10 files changed, 97 insertions, 74 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index ac33dba0ef..7e4687ea6f 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -7,11 +7,11 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/time.hpp> #include <mbgl/util/uv.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <atomic> #include <iosfwd> -#include <memory> #include <set> #include <vector> @@ -31,21 +31,31 @@ class FileSource; class View; class Map : private util::noncopyable { + typedef void (*stop_callback)(void *); + public: explicit Map(View &view); ~Map(); - // Start/stop the map render thread + // Start the map render thread. It is asynchronous. void start(); - void stop(); - // Runs the map event loop. + // Stop the map render thread. This call will block until the map rendering thread stopped. + // The optional callback function will be invoked repeatedly until the map thread is stopped. + // The callback function should wait until it is woken up again by view.notify(), otherwise + // this will be a busy waiting loop. The optional data parameter will be passed to the callback + // function. + void stop(stop_callback cb = nullptr, void *data = nullptr); + + // Runs the map event loop. ONLY run this function when you want to get render a single frame + // with this map object. It will *not* spawn a separate thread and instead block until the + // frame is completely rendered. void run(); // Triggers a lazy rerender: only performs a render when the map is not clean. void rerender(); - void renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); + void renderLayer(util::ptr<StyleLayer> layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); // Forces a map update: always triggers a rerender. void update(); @@ -65,7 +75,7 @@ public: void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height); // Styling - const std::set<std::shared_ptr<StyleSource>> getActiveSources() const; + const std::set<util::ptr<StyleSource>> getActiveSources() const; void setAppliedClasses(const std::vector<std::string> &classes); void toggleClass(const std::string &name); const std::vector<std::string> &getAppliedClasses() const; @@ -116,16 +126,20 @@ public: void toggleDebug(); bool getDebug() const; + // Call this when the network reachability changed. + void setReachability(bool status); + public: inline const TransformState &getState() const { return state; } - inline std::shared_ptr<FileSource> getFileSource() const { return fileSource; } - inline std::shared_ptr<Style> getStyle() const { return style; } - inline std::shared_ptr<GlyphAtlas> getGlyphAtlas() { return glyphAtlas; } - inline std::shared_ptr<GlyphStore> getGlyphStore() { return glyphStore; } - inline std::shared_ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; } - std::shared_ptr<Sprite> getSprite(); - inline std::shared_ptr<Texturepool> getTexturepool() { return texturepool; } - inline std::shared_ptr<uv::loop> getLoop() { return loop; } + inline util::ptr<FileSource> getFileSource() const { return fileSource; } + inline util::ptr<Style> getStyle() const { return style; } + inline util::ptr<GlyphAtlas> getGlyphAtlas() { return glyphAtlas; } + inline util::ptr<GlyphStore> getGlyphStore() { return glyphStore; } + inline util::ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; } + util::ptr<Sprite> getSprite(); + inline util::ptr<Texturepool> getTexturepool() { return texturepool; } + inline util::ptr<uv::loop> getLoop() { return loop; } + uv::worker &getWorker(); inline timestamp getAnimationTime() const { return animationTime; } inline timestamp getTime() const { return animationTime; } void updateTiles(); @@ -141,7 +155,7 @@ private: void setup(); void updateSources(); - void updateSources(const std::shared_ptr<StyleLayerGroup> &group); + void updateSources(const util::ptr<StyleLayerGroup> &group); void updateRenderState(); @@ -154,15 +168,16 @@ private: // Unconditionally performs a render with the current map state. void render(); - void renderLayers(std::shared_ptr<StyleLayerGroup> group); + void renderLayers(util::ptr<StyleLayerGroup> group); private: bool async = false; - std::shared_ptr<uv::loop> loop; + util::ptr<uv::loop> loop; + std::unique_ptr<uv::worker> workers; std::unique_ptr<uv::thread> thread; - uv_async_t *async_terminate = nullptr; - uv_async_t *async_render = nullptr; - uv_async_t *async_cleanup = nullptr; + std::unique_ptr<uv_async_t> async_terminate; + std::unique_ptr<uv_async_t> async_render; + std::unique_ptr<uv_async_t> async_cleanup; private: // If cleared, the next time the render thread attempts to render the map, it will *actually* @@ -177,24 +192,33 @@ private: // ready for rendering. std::atomic_flag is_rendered = ATOMIC_FLAG_INIT; + // Stores whether the map thread has been stopped already. + std::atomic_bool is_stopped; + public: View &view; private: +#ifndef NDEBUG + const unsigned long main_thread; + unsigned long map_thread = -1; +#endif + Transform transform; TransformState state; - std::shared_ptr<FileSource> fileSource; + util::ptr<FileSource> fileSource; - std::shared_ptr<Style> style; - std::shared_ptr<GlyphAtlas> glyphAtlas; - std::shared_ptr<GlyphStore> glyphStore; - std::shared_ptr<SpriteAtlas> spriteAtlas; - std::shared_ptr<Sprite> sprite; - std::shared_ptr<Texturepool> texturepool; + util::ptr<Style> style; + util::ptr<GlyphAtlas> glyphAtlas; + util::ptr<GlyphStore> glyphStore; + util::ptr<SpriteAtlas> spriteAtlas; + util::ptr<Sprite> sprite; + util::ptr<Texturepool> texturepool; Painter painter; + std::string styleURL; std::string styleJSON = ""; std::string accessToken = ""; @@ -203,7 +227,7 @@ private: int indent = 0; - std::set<std::shared_ptr<StyleSource>> activeSources; + std::set<util::ptr<StyleSource>> activeSources; }; diff --git a/include/mbgl/map/raster_tile_data.hpp b/include/mbgl/map/raster_tile_data.hpp index 98aa3baaf5..14833c0d84 100644 --- a/include/mbgl/map/raster_tile_data.hpp +++ b/include/mbgl/map/raster_tile_data.hpp @@ -5,8 +5,6 @@ #include <mbgl/map/tile_data.hpp> #include <mbgl/renderer/raster_bucket.hpp> -#include <memory> - namespace mbgl { class Map; @@ -18,12 +16,12 @@ class RasterTileData : public TileData { friend class TileParser; public: - RasterTileData(Tile::ID id, Map &map, const SourceInfo &source); + RasterTileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source); ~RasterTileData(); virtual void parse(); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const; + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); + virtual bool hasData(util::ptr<StyleLayer> layer_desc) const; protected: StyleBucketRaster properties; diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp index cb069db272..e74ddb9902 100644 --- a/include/mbgl/map/source.hpp +++ b/include/mbgl/map/source.hpp @@ -8,12 +8,12 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/time.hpp> #include <mbgl/util/mat4.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <forward_list> #include <iosfwd> #include <map> -#include <memory> namespace mbgl { @@ -25,7 +25,7 @@ struct box; class Source : public std::enable_shared_from_this<Source>, private util::noncopyable { public: - Source(SourceInfo& info); + Source(const util::ptr<SourceInfo>& info); void load(Map &map); @@ -33,8 +33,8 @@ public: void updateMatrices(const mat4 &projMatrix, const TransformState &transform); void drawClippingMasks(Painter &painter); size_t getTileCount() const; - void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc); - void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); + void render(Painter &painter, util::ptr<StyleLayer> layer_desc); + void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); void finishRender(Painter &painter); std::forward_list<Tile::ID> getIDs() const; @@ -54,7 +54,7 @@ private: double getZoom(const TransformState &state) const; - SourceInfo& info; + util::ptr<SourceInfo> info; bool loaded = false; // Stores the time when this source was most recently updated. diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp index 6461a5e33d..454ebd8886 100644 --- a/include/mbgl/map/sprite.hpp +++ b/include/mbgl/map/sprite.hpp @@ -3,11 +3,11 @@ #include <mbgl/util/image.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <atomic> #include <iosfwd> -#include <memory> #include <string> #include <unordered_map> #include <future> @@ -34,11 +34,11 @@ public: class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable { private: struct Key {}; - void load(const std::shared_ptr<FileSource> &fileSource); + void load(const util::ptr<FileSource> &fileSource); public: Sprite(const Key &, const std::string& base_url, float pixelRatio); - static std::shared_ptr<Sprite> Create(const std::string& base_url, float pixelRatio, const std::shared_ptr<FileSource> &fileSource); + static util::ptr<Sprite> Create(const std::string& base_url, float pixelRatio, const util::ptr<FileSource> &fileSource); const SpritePosition &getSpritePosition(const std::string& name) const; diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp index 75ced7e384..b9f0556add 100644 --- a/include/mbgl/map/tile.hpp +++ b/include/mbgl/map/tile.hpp @@ -3,6 +3,7 @@ #include <mbgl/util/mat4.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <bitset> @@ -10,7 +11,6 @@ #include <cstdint> #include <forward_list> #include <iosfwd> -#include <memory> #include <string> namespace mbgl { @@ -78,7 +78,7 @@ public: const Tile::ID id; ClipID clip; mat4 matrix; - std::shared_ptr<TileData> data; + util::ptr<TileData> data; }; } diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index 9aaef84e04..07cf19c5c8 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -6,11 +6,11 @@ #include <mbgl/geometry/debug_font_buffer.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <atomic> #include <exception> #include <iosfwd> -#include <memory> #include <string> namespace mbgl { @@ -19,8 +19,7 @@ class Map; class Painter; class SourceInfo; class StyleLayer; - -namespace platform { class Request; } +class Request; class TileData : public std::enable_shared_from_this<TileData>, private util::noncopyable { @@ -29,7 +28,7 @@ public: struct geometry_too_long_exception : exception {}; public: - typedef std::shared_ptr<TileData> Ptr; + typedef util::ptr<TileData> Ptr; enum class State { invalid, @@ -41,7 +40,7 @@ public: }; public: - TileData(Tile::ID id, Map &map, const SourceInfo &source); + TileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source); ~TileData(); void request(); @@ -57,8 +56,8 @@ public: virtual void beforeParse(); virtual void parse() = 0; virtual void afterParse(); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix) = 0; - virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const = 0; + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix) = 0; + virtual bool hasData(util::ptr<StyleLayer> layer_desc) const = 0; public: @@ -69,10 +68,10 @@ protected: Map ↦ public: - const SourceInfo &source; + util::ptr<SourceInfo> source; protected: - std::weak_ptr<platform::Request> req; + std::unique_ptr<Request> req; std::string data; // Contains the tile ID string for painting debug information. diff --git a/include/mbgl/map/tile_parser.hpp b/include/mbgl/map/tile_parser.hpp index fa64dad6d5..ddb4b98820 100644 --- a/include/mbgl/map/tile_parser.hpp +++ b/include/mbgl/map/tile_parser.hpp @@ -4,10 +4,10 @@ #include <mbgl/map/vector_tile.hpp> #include <mbgl/style/filter_expression.hpp> #include <mbgl/text/glyph.hpp> +#include <mbgl/util/ptr.hpp> #include <cstdint> #include <iosfwd> -#include <memory> #include <string> namespace mbgl { @@ -32,11 +32,11 @@ class Collision; class TileParser { public: TileParser(const std::string &data, VectorTileData &tile, - const std::shared_ptr<const Style> &style, - const std::shared_ptr<GlyphAtlas> &glyphAtlas, - const std::shared_ptr<GlyphStore> &glyphStore, - const std::shared_ptr<SpriteAtlas> &spriteAtlas, - const std::shared_ptr<Sprite> &sprite); + const util::ptr<const Style> &style, + const util::ptr<GlyphAtlas> &glyphAtlas, + const util::ptr<GlyphStore> &glyphStore, + const util::ptr<SpriteAtlas> &spriteAtlas, + const util::ptr<Sprite> &sprite); ~TileParser(); public: @@ -44,11 +44,11 @@ public: private: bool obsolete() const; - void parseStyleLayers(std::shared_ptr<StyleLayerGroup> group); - std::unique_ptr<Bucket> createBucket(std::shared_ptr<StyleBucket> bucket_desc); + void parseStyleLayers(util::ptr<StyleLayerGroup> group); + std::unique_ptr<Bucket> createBucket(util::ptr<StyleBucket> bucket_desc); std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketFill &fill); - std::unique_ptr<Bucket> createRasterBucket(const std::shared_ptr<Texturepool> &texturepool, const StyleBucketRaster &raster); + std::unique_ptr<Bucket> createRasterBucket(const util::ptr<Texturepool> &texturepool, const StyleBucketRaster &raster); std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketLine &line); std::unique_ptr<Bucket> createSymbolBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketSymbol &symbol); @@ -59,12 +59,12 @@ private: VectorTileData& tile; // Cross-thread shared data. - std::shared_ptr<const Style> style; - std::shared_ptr<GlyphAtlas> glyphAtlas; - std::shared_ptr<GlyphStore> glyphStore; - std::shared_ptr<SpriteAtlas> spriteAtlas; - std::shared_ptr<Sprite> sprite; - std::shared_ptr<Texturepool> texturePool; + util::ptr<const Style> style; + util::ptr<GlyphAtlas> glyphAtlas; + util::ptr<GlyphStore> glyphStore; + util::ptr<SpriteAtlas> spriteAtlas; + util::ptr<Sprite> sprite; + util::ptr<Texturepool> texturePool; std::unique_ptr<Collision> collision; }; diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index d0f56b7fba..5404f333c1 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -98,10 +98,10 @@ private: // cache values for spherical mercator math double Bc, Cc; - std::forward_list<std::shared_ptr<util::transition>> transitions; - std::shared_ptr<util::transition> scale_timeout; - std::shared_ptr<util::transition> rotate_timeout; - std::shared_ptr<util::transition> pan_timeout; + std::forward_list<util::ptr<util::transition>> transitions; + util::ptr<util::transition> scale_timeout; + util::ptr<util::transition> rotate_timeout; + util::ptr<util::transition> pan_timeout; }; } diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index deb628e485..9de666c84f 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -26,14 +26,14 @@ class VectorTileData : public TileData { friend class TileParser; public: - VectorTileData(Tile::ID id, Map &map, const SourceInfo &source); + VectorTileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source); ~VectorTileData(); virtual void beforeParse(); virtual void parse(); virtual void afterParse(); - virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const; + virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); + virtual bool hasData(util::ptr<StyleLayer> layer_desc) const; protected: // Holds the actual geometries in this tile. diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 3e2f1a4b5a..395a05d435 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -45,6 +45,8 @@ public: return 0; } + virtual void notify() = 0; + // Notifies a watcher of map x/y/scale/rotation changes. // Must only be called from the same thread that caused the change. // Must not be called from the render thread. |