summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-08-11 16:57:33 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-08-11 16:57:33 +0200
commit7a98ad4cf949dd1279719bf926bd08da0133210f (patch)
tree66ef1177038f1edefc08cc72a78cb49421b01e5c /include/mbgl
parente39ae931b9890bbe23013049df132243af454c49 (diff)
parent225b5e01cbadc46727f77ccf185c711b5f6956a7 (diff)
downloadqtlocation-mapboxgl-7a98ad4cf949dd1279719bf926bd08da0133210f.tar.gz
Merge pull request #407 from mapbox/filesource
Use style.json directory as base path for loading sprite images
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/map/map.hpp22
-rw-r--r--include/mbgl/map/sprite.hpp6
-rw-r--r--include/mbgl/text/glyph_store.hpp6
-rw-r--r--include/mbgl/util/filesource.hpp45
-rw-r--r--include/mbgl/util/uv.hpp14
5 files changed, 80 insertions, 13 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 0a94fc7ed2..be01b456cc 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -27,6 +27,7 @@ class StyleLayer;
class StyleLayerGroup;
class StyleSource;
class Texturepool;
+class FileSource;
class View;
class Map : private util::noncopyable {
@@ -64,7 +65,8 @@ public:
void toggleClass(const std::string &name);
const std::vector<std::string> &getAppliedClasses() const;
void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0);
- void setStyleJSON(std::string newStyleJSON);
+ void setStyleURL(const std::string &url);
+ void setStyleJSON(std::string newStyleJSON, const std::string &base = "");
std::string getStyleJSON() const;
void setAccessToken(std::string access_token);
std::string getAccessToken() const;
@@ -111,6 +113,7 @@ public:
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; }
@@ -151,6 +154,14 @@ private:
void renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass);
private:
+ bool async = false;
+ std::shared_ptr<uv::loop> loop;
+ uv_thread_t thread;
+ uv_async_t *async_terminate = nullptr;
+ uv_async_t *async_render = nullptr;
+ uv_async_t *async_cleanup = nullptr;
+
+private:
// If cleared, the next time the render thread attempts to render the map, it will *actually*
// render the map.
std::atomic_flag is_clean = ATOMIC_FLAG_INIT;
@@ -170,6 +181,8 @@ private:
Transform transform;
TransformState state;
+ std::shared_ptr<FileSource> fileSource;
+
std::shared_ptr<Style> style;
std::shared_ptr<GlyphAtlas> glyphAtlas;
std::shared_ptr<GlyphStore> glyphStore;
@@ -189,13 +202,6 @@ private:
std::set<std::shared_ptr<StyleSource>> activeSources;
-private:
- bool async = false;
- std::shared_ptr<uv::loop> loop;
- uv_thread_t thread;
- uv_async_t *async_terminate = nullptr;
- uv_async_t *async_render = nullptr;
- uv_async_t *async_cleanup = nullptr;
};
}
diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp
index 969f15c161..967f1d6614 100644
--- a/include/mbgl/map/sprite.hpp
+++ b/include/mbgl/map/sprite.hpp
@@ -14,7 +14,7 @@
namespace mbgl {
-class Map;
+class FileSource;
class SpritePosition {
public:
@@ -33,11 +33,11 @@ public:
class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable {
private:
struct Key {};
- void load();
+ void load(const std::shared_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);
+ static std::shared_ptr<Sprite> Create(const std::string& base_url, float pixelRatio, const std::shared_ptr<FileSource> &fileSource);
const SpritePosition &getSpritePosition(const std::string& name) const;
diff --git a/include/mbgl/text/glyph_store.hpp b/include/mbgl/text/glyph_store.hpp
index fbfd0dde67..e0c0391c73 100644
--- a/include/mbgl/text/glyph_store.hpp
+++ b/include/mbgl/text/glyph_store.hpp
@@ -14,6 +14,7 @@
namespace mbgl {
+class FileSource;
class SDFGlyph {
public:
@@ -46,7 +47,7 @@ private:
class GlyphPBF {
public:
- GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange);
+ GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const std::shared_ptr<FileSource> &fileSource);
void parse(FontStack &stack);
@@ -62,7 +63,7 @@ private:
// Manages Glyphrange PBF loading.
class GlyphStore {
public:
- GlyphStore();
+ GlyphStore(const std::shared_ptr<FileSource> &fileSource);
// Block until all specified GlyphRanges of the specified font stack are loaded.
void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges);
@@ -81,6 +82,7 @@ public:
std::string glyphURL;
private:
+ const std::shared_ptr<FileSource> fileSource;
std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;
std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks;
std::mutex mtx;
diff --git a/include/mbgl/util/filesource.hpp b/include/mbgl/util/filesource.hpp
new file mode 100644
index 0000000000..0d339cbac7
--- /dev/null
+++ b/include/mbgl/util/filesource.hpp
@@ -0,0 +1,45 @@
+#ifndef MBGL_UTIL_FILESOURCE
+#define MBGL_UTIL_FILESOURCE
+
+#include <string>
+#include <memory>
+#include <functional>
+
+namespace uv {
+class loop;
+}
+
+namespace mbgl {
+
+namespace platform {
+struct Response;
+}
+
+enum class ResourceType : uint8_t {
+ Unknown,
+ Tile,
+ Glyphs,
+ Image,
+ JSON
+};
+
+class FileSource {
+public:
+ FileSource();
+
+ void setBase(const std::string &value);
+ const std::string &getBase() const;
+
+ void load(ResourceType type, const std::string &url, std::function<void(platform::Response *)> callback, const std::shared_ptr<uv::loop> loop = nullptr);
+
+private:
+ // Stores a URL that is used as a base for loading resources with relative path.
+ std::string base;
+
+ // Stores the absolute path to the cache directory.
+ const std::string cache;
+};
+
+}
+
+#endif
diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp
index a11d9b19cf..518e007afe 100644
--- a/include/mbgl/util/uv.hpp
+++ b/include/mbgl/util/uv.hpp
@@ -16,9 +16,23 @@
#pragma clang diagnostic pop
#endif
+#include <string>
+
namespace uv {
+inline std::string cwd() {
+ size_t max = 0;
+ std::string dir;
+ do {
+ max += 256;
+ dir.resize(max);
+ uv_cwd(const_cast<char *>(dir.data()), &max);
+ } while (max == dir.size());
+ dir.resize(max - 1);
+ return dir;
+}
+
class loop {
public:
inline loop() {