use filesource object for loading all http stuff

This commit is contained in:
Konstantin Käfer
2014-08-08 15:08:41 +02:00
parent 70a31baf5c
commit a045d9c9d4
9 changed files with 117 additions and 30 deletions

View File

@@ -27,6 +27,7 @@ class StyleLayer;
class StyleLayerGroup;
class StyleSource;
class Texturepool;
class FileSource;
class View;
class Map : private util::noncopyable {
@@ -64,7 +65,7 @@ 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 setStyleJSON(std::string newStyleJSON, const std::string &base = "");
std::string getStyleJSON() const;
void setAccessToken(std::string access_token);
std::string getAccessToken() const;
@@ -111,6 +112,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; }
@@ -150,6 +152,14 @@ private:
void renderLayers(std::shared_ptr<StyleLayerGroup> group);
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.
@@ -170,6 +180,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 +201,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;
};
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -0,0 +1,47 @@
#ifndef MBGL_UTIL_FILESOURCE
#define MBGL_UTIL_FILESOURCE
#include <string>
#include <memory>
#include <functional>
namespace uv {
class loop;
}
namespace mbgl {
namespace platform {
class Response;
}
enum class ResourceType : uint8_t {
Unknown,
Tile,
Glyphs,
Image,
JSON
};
class FileSource {
public:
FileSource(const std::shared_ptr<uv::loop> &loop);
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);
private:
std::shared_ptr<uv::loop> loop;
// 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