diff options
author | Dane Springmeyer <dane@mapbox.com> | 2014-10-29 21:40:02 -0400 |
---|---|---|
committer | Dane Springmeyer <dane@mapbox.com> | 2014-10-29 21:40:02 -0400 |
commit | 761f753cbdba350411785ce4e82d4e843bf03224 (patch) | |
tree | b4c33738c6d5afe8a93a830e436d82ce8570e4f9 /include | |
parent | 9dbcf18d14c0054b9d090d8921c6caa01979382c (diff) | |
parent | 88361f02fa9df3d643ed6d5c3fc45b6898f0f32f (diff) | |
download | qtlocation-mapboxgl-761f753cbdba350411785ce4e82d4e843bf03224.tar.gz |
merge with mbgl-config
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/geometry/sprite_atlas.hpp | 29 | ||||
-rw-r--r-- | include/mbgl/map/map.hpp | 25 | ||||
-rw-r--r-- | include/mbgl/map/raster_tile_data.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/map/tile_data.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/map/tile_parser.hpp | 13 | ||||
-rw-r--r-- | include/mbgl/map/transform.hpp | 7 | ||||
-rw-r--r-- | include/mbgl/map/transform_state.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/map/vector_tile_data.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/renderer/painter.hpp | 20 |
9 files changed, 49 insertions, 62 deletions
diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 0946f0fc48..9fb42a30b5 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -3,6 +3,7 @@ #include <mbgl/geometry/binpack.hpp> #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/ptr.hpp> #include <string> #include <map> @@ -26,7 +27,6 @@ class SpriteAtlas : public util::noncopyable { public: typedef uint16_t dimension; -public: // Add way to construct this from another SpriteAtlas (e.g. with another pixelRatio) SpriteAtlas(dimension width, dimension height); ~SpriteAtlas(); @@ -34,22 +34,16 @@ public: // Changes the pixel ratio. bool resize(float newRatio); - // Update uninitialized (= outdated) sprites in this atlas from the given sprite. - void update(const Sprite &sprite); + // Changes the source sprite. + void setSprite(util::ptr<Sprite> sprite); // Returns the coordinates of an image that is sourced from the sprite image. // This getter attempts to read the image from the sprite if it is already loaded. // In that case, it copies it into the sprite atlas and returns the dimensions. // Otherwise, it returns a 0/0/0/0 rect. - Rect<dimension> getImage(const std::string &name, const Sprite &sprite); - - // Returns the coordinates of an image that is sourced from the sprite image. - // This getter waits until the sprite image was loaded, copies it into the sprite - // image and returns the dimensions. - // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. - Rect<dimension> waitForImage(const std::string &name, const Sprite &sprite); + Rect<dimension> getImage(const std::string& name); - SpriteAtlasPosition getPosition(const std::string &name, const Sprite &sprite, bool repeating = false); + SpriteAtlasPosition getPosition(const std::string& name, bool repeating = false); // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out // of date. @@ -61,19 +55,18 @@ public: inline float getTextureHeight() const { return height * pixelRatio; } inline float getPixelRatio() const { return pixelRatio; } -private: - void allocate(); - Rect<SpriteAtlas::dimension> allocateImage(size_t width, size_t height); - void copy(const Rect<dimension> &dst, const SpritePosition &src, const Sprite &sprite); - -public: const dimension width = 0; const dimension height = 0; private: - std::mutex mtx; + void allocate(); + Rect<SpriteAtlas::dimension> allocateImage(size_t width, size_t height); + void copy(const Rect<dimension>& dst, const SpritePosition& src); + + std::recursive_mutex mtx; float pixelRatio = 1.0f; BinPack<dimension> bin; + util::ptr<Sprite> sprite; std::map<std::string, Rect<dimension>> images; std::set<std::string> uninitialized; uint32_t *data = nullptr; diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index bc67e5b35b..6aa86fcc85 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -3,12 +3,12 @@ #include <mbgl/map/transform.hpp> #include <mbgl/renderer/painter.hpp> - +#include <mbgl/geometry/glyph_atlas.hpp> +#include <mbgl/geometry/sprite_atlas.hpp> #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> @@ -17,10 +17,8 @@ namespace mbgl { -class GlyphAtlas; class GlyphStore; class LayerDescription; -class SpriteAtlas; class Sprite; class Style; class StyleLayer; @@ -55,8 +53,6 @@ public: // Triggers a lazy rerender: only performs a render when the map is not clean. void rerender(); - 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(); @@ -133,12 +129,11 @@ public: inline const TransformState &getState() const { return state; } inline util::ptr<FileSource> getFileSource() const { return fileSource; } inline util::ptr<Style> getStyle() const { return style; } - inline util::ptr<GlyphAtlas> getGlyphAtlas() { return glyphAtlas; } + inline GlyphAtlas & getGlyphAtlas() { return glyphAtlas; } inline util::ptr<GlyphStore> getGlyphStore() { return glyphStore; } - inline util::ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; } + inline 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; } @@ -156,22 +151,18 @@ private: void updateSources(); void updateSources(const util::ptr<StyleLayerGroup> &group); - void updateRenderState(); - size_t countLayers(const std::vector<LayerDescription>& layers); // Prepares a map render by updating the tiles we need for the current view, as well as updating // the stylesheet. void prepare(); - // Unconditionally performs a render with the current map state. void render(); - void renderLayers(util::ptr<StyleLayerGroup> group); private: bool async = false; - util::ptr<uv::loop> loop; + std::unique_ptr<uv::loop> loop; std::unique_ptr<uv::worker> workers; std::unique_ptr<uv::thread> thread; std::unique_ptr<uv_async_t> async_terminate; @@ -209,9 +200,9 @@ private: util::ptr<FileSource> fileSource; util::ptr<Style> style; - util::ptr<GlyphAtlas> glyphAtlas; + GlyphAtlas glyphAtlas; util::ptr<GlyphStore> glyphStore; - util::ptr<SpriteAtlas> spriteAtlas; + SpriteAtlas spriteAtlas; util::ptr<Sprite> sprite; util::ptr<Texturepool> texturepool; @@ -224,8 +215,6 @@ private: bool debug = false; timestamp animationTime = 0; - int indent = 0; - 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 14833c0d84..8ae898f989 100644 --- a/include/mbgl/map/raster_tile_data.hpp +++ b/include/mbgl/map/raster_tile_data.hpp @@ -21,7 +21,7 @@ public: virtual void parse(); virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(util::ptr<StyleLayer> layer_desc) const; + virtual bool hasData(StyleLayer const& layer_desc) const; protected: StyleBucketRaster properties; diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index 07cf19c5c8..70297c7f34 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -53,11 +53,9 @@ public: } // Override this in the child class. - virtual void beforeParse(); virtual void parse() = 0; - virtual void afterParse(); virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix) = 0; - virtual bool hasData(util::ptr<StyleLayer> layer_desc) const = 0; + virtual bool hasData(StyleLayer const& layer_desc) const = 0; public: diff --git a/include/mbgl/map/tile_parser.hpp b/include/mbgl/map/tile_parser.hpp index ddb4b98820..576c18ec94 100644 --- a/include/mbgl/map/tile_parser.hpp +++ b/include/mbgl/map/tile_parser.hpp @@ -5,7 +5,7 @@ #include <mbgl/style/filter_expression.hpp> #include <mbgl/text/glyph.hpp> #include <mbgl/util/ptr.hpp> - +#include <mbgl/util/noncopyable.hpp> #include <cstdint> #include <iosfwd> #include <string> @@ -29,13 +29,14 @@ class StyleLayerGroup; class VectorTileData; class Collision; -class TileParser { +class TileParser : private util::noncopyable +{ public: TileParser(const std::string &data, VectorTileData &tile, const util::ptr<const Style> &style, - const util::ptr<GlyphAtlas> &glyphAtlas, + GlyphAtlas & glyphAtlas, const util::ptr<GlyphStore> &glyphStore, - const util::ptr<SpriteAtlas> &spriteAtlas, + SpriteAtlas & spriteAtlas, const util::ptr<Sprite> &sprite); ~TileParser(); @@ -60,9 +61,9 @@ private: // Cross-thread shared data. util::ptr<const Style> style; - util::ptr<GlyphAtlas> glyphAtlas; + GlyphAtlas & glyphAtlas; util::ptr<GlyphStore> glyphStore; - util::ptr<SpriteAtlas> spriteAtlas; + SpriteAtlas & spriteAtlas; util::ptr<Sprite> sprite; util::ptr<Texturepool> texturePool; diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index 5404f333c1..e3604edd8b 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -3,14 +3,12 @@ #include <mbgl/util/time.hpp> #include <mbgl/map/transform_state.hpp> - #include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/uv.hpp> #include <cstdint> #include <cmath> #include <forward_list> -#include <memory> +#include <mutex> namespace mbgl { @@ -80,7 +78,7 @@ private: private: View &view; - std::unique_ptr<uv::rwlock> mtx; + mutable std::recursive_mutex mtx; // This reflects the current state of the transform, representing the actual position of the // map. After calling a transform function with a timer, this will likely remain the same until @@ -91,7 +89,6 @@ private: TransformState final; // Limit the amount of zooming possible on the map. - // TODO: make these modifiable from outside. const double min_scale = std::pow(2, 0); const double max_scale = std::pow(2, 18); diff --git a/include/mbgl/map/transform_state.hpp b/include/mbgl/map/transform_state.hpp index ed49dc3e99..bb330c1019 100644 --- a/include/mbgl/map/transform_state.hpp +++ b/include/mbgl/map/transform_state.hpp @@ -33,6 +33,7 @@ public: float lngX(float lon) const; float latY(float lat) const; std::array<float, 2> locationCoordinate(float lon, float lat) const; + void getLonLat(double &lon, double &lat) const; // Zoom float getNormalizedZoom() const; @@ -69,7 +70,7 @@ private: // map position double x = 0, y = 0; double angle = 0; - double scale = std::numeric_limits<double>::infinity(); + double scale = 1; }; } diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index 9de666c84f..9f611fd69c 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -28,12 +28,9 @@ class VectorTileData : public TileData { public: 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, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(util::ptr<StyleLayer> layer_desc) const; + virtual bool hasData(StyleLayer const& layer_desc) const; protected: // Holds the actual geometries in this tile. @@ -49,9 +46,6 @@ protected: // Holds the buckets of this tile. // They contain the location offsets in the buffers stored above std::unordered_map<std::string, std::unique_ptr<Bucket>> buckets; - - std::unique_ptr<TileParser> parser; - public: const float depth; }; diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index a8229a0978..be4bd12710 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -35,9 +35,12 @@ enum class RenderPass : bool { Opaque, Translucent }; class Transform; class Style; class Tile; +class Sprite; +class SpriteAtlas; class GlyphAtlas; class Source; class StyleSource; +class StyleLayerGroup; class FillBucket; class LineBucket; @@ -53,10 +56,9 @@ class RasterTileData; class Painter : private util::noncopyable { public: - Painter(Map &map); + Painter(SpriteAtlas&, GlyphAtlas&); ~Painter(); - void setup(); // Perform cleanup tasks that prepare shutting down the app. This doesn't mean that the @@ -73,6 +75,14 @@ public: // Updates the default matrices to the current viewport dimensions. void changeMatrix(); + void render(const Style& style, + const std::set<util::ptr<StyleSource>>& sources, + TransformState state, + timestamp time); + + void renderLayers(util::ptr<StyleLayerGroup> group); + void renderLayer(util::ptr<StyleLayer> layer_desc, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); + // Renders a particular layer from a tile. void renderTileLayer(const Tile& tile, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); @@ -167,9 +177,10 @@ public: }(); private: - Map& map; + TransformState state; bool debug = false; + int indent = 0; uint32_t gl_program = 0; float gl_lineWidth = 0; @@ -183,6 +194,9 @@ private: public: FrameHistory frameHistory; + SpriteAtlas& spriteAtlas; + GlyphAtlas& glyphAtlas; + std::unique_ptr<PlainShader> plainShader; std::unique_ptr<OutlineShader> outlineShader; std::unique_ptr<LineShader> lineShader; |