[core] move *Observers to their own files
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/annotation/annotation_manager.hpp>
|
||||
#include <mbgl/annotation/annotation_tile.hpp>
|
||||
#include <mbgl/source/source.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/layer/symbol_layer.hpp>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mbgl/annotation/shape_annotation.hpp>
|
||||
#include <mbgl/annotation/annotation_manager.hpp>
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/style_observer.hpp>
|
||||
#include <mbgl/style/style_layer.hpp>
|
||||
#include <mbgl/style/property_transition.hpp>
|
||||
#include <mbgl/style/style_update_parameters.hpp>
|
||||
@@ -33,7 +34,7 @@ enum class RenderState {
|
||||
fully
|
||||
};
|
||||
|
||||
class Map::Impl : public Style::Observer {
|
||||
class Map::Impl : public StyleObserver {
|
||||
public:
|
||||
Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/source/source.hpp>
|
||||
#include <mbgl/source/source_observer.hpp>
|
||||
#include <mbgl/map/transform.hpp>
|
||||
#include <mbgl/tile/tile.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
@@ -39,6 +40,8 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static SourceObserver nullObserver;
|
||||
|
||||
Source::Source(SourceType type_,
|
||||
const std::string& id_,
|
||||
const std::string& url_,
|
||||
@@ -50,7 +53,8 @@ Source::Source(SourceType type_,
|
||||
url(url_),
|
||||
tileSize(tileSize_),
|
||||
info(std::move(info_)),
|
||||
geojsonvt(std::move(geojsonvt_)) {
|
||||
geojsonvt(std::move(geojsonvt_)),
|
||||
observer(&nullObserver) {
|
||||
}
|
||||
|
||||
Source::~Source() = default;
|
||||
@@ -380,7 +384,7 @@ void Source::onLowMemory() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
void Source::setObserver(Observer* observer_) {
|
||||
void Source::setObserver(SourceObserver* observer_) {
|
||||
observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,21 +32,10 @@ class AsyncRequest;
|
||||
class TransformState;
|
||||
class Tile;
|
||||
struct ClipID;
|
||||
class SourceObserver;
|
||||
|
||||
class Source : private util::noncopyable {
|
||||
public:
|
||||
class Observer {
|
||||
public:
|
||||
virtual ~Observer() = default;
|
||||
|
||||
virtual void onSourceLoaded(Source&) {};
|
||||
virtual void onSourceError(Source&, std::exception_ptr) {};
|
||||
|
||||
virtual void onTileLoaded(Source&, const OverscaledTileID&, bool /* isNewTile */) {};
|
||||
virtual void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) {};
|
||||
virtual void onPlacementRedone() {};
|
||||
};
|
||||
|
||||
Source(SourceType,
|
||||
const std::string& id,
|
||||
const std::string& url,
|
||||
@@ -86,7 +75,7 @@ public:
|
||||
void setCacheSize(size_t);
|
||||
void onLowMemory();
|
||||
|
||||
void setObserver(Observer* observer);
|
||||
void setObserver(SourceObserver* observer);
|
||||
void dumpDebugLogs() const;
|
||||
|
||||
const SourceType type;
|
||||
@@ -115,8 +104,7 @@ private:
|
||||
|
||||
std::unique_ptr<AsyncRequest> req;
|
||||
|
||||
Observer nullObserver;
|
||||
Observer* observer = &nullObserver;
|
||||
SourceObserver* observer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
24
src/mbgl/source/source_observer.hpp
Normal file
24
src/mbgl/source/source_observer.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef MBGL_MAP_SOURCE_OBSERVER
|
||||
#define MBGL_MAP_SOURCE_OBSERVER
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Source;
|
||||
class OverscaledTileID;
|
||||
|
||||
class SourceObserver {
|
||||
public:
|
||||
virtual ~SourceObserver() = default;
|
||||
|
||||
virtual void onSourceLoaded(Source&) {}
|
||||
virtual void onSourceError(Source&, std::exception_ptr) {}
|
||||
virtual void onTileLoaded(Source&, const OverscaledTileID&, bool /* isNewTile */) {}
|
||||
virtual void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) {}
|
||||
virtual void onPlacementRedone() {}
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/sprite/sprite_store.hpp>
|
||||
#include <mbgl/sprite/sprite_store_observer.hpp>
|
||||
#include <mbgl/sprite/sprite_parser.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
@@ -11,6 +12,8 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static SpriteStoreObserver nullObserver;
|
||||
|
||||
struct SpriteStore::Loader {
|
||||
std::shared_ptr<const std::string> image;
|
||||
std::shared_ptr<const std::string> json;
|
||||
@@ -19,7 +22,7 @@ struct SpriteStore::Loader {
|
||||
};
|
||||
|
||||
SpriteStore::SpriteStore(float pixelRatio_)
|
||||
: pixelRatio(pixelRatio_ > 1 ? 2 : 1) {
|
||||
: pixelRatio(pixelRatio_ > 1 ? 2 : 1), observer(&nullObserver) {
|
||||
}
|
||||
|
||||
SpriteStore::~SpriteStore() = default;
|
||||
@@ -80,7 +83,7 @@ void SpriteStore::emitSpriteLoadedIfComplete() {
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteStore::setObserver(Observer* observer_) {
|
||||
void SpriteStore::setObserver(SpriteStoreObserver* observer_) {
|
||||
observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,12 @@
|
||||
namespace mbgl {
|
||||
|
||||
class FileSource;
|
||||
class SpriteStoreObserver;
|
||||
|
||||
class SpriteStore : private util::noncopyable {
|
||||
public:
|
||||
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
|
||||
|
||||
class Observer {
|
||||
public:
|
||||
virtual ~Observer() = default;
|
||||
|
||||
virtual void onSpriteLoaded() {};
|
||||
virtual void onSpriteError(std::exception_ptr) {};
|
||||
};
|
||||
|
||||
SpriteStore(float pixelRatio);
|
||||
~SpriteStore();
|
||||
|
||||
@@ -35,7 +28,7 @@ public:
|
||||
|
||||
void dumpDebugLogs() const;
|
||||
|
||||
void setObserver(Observer* observer);
|
||||
void setObserver(SpriteStoreObserver* observer);
|
||||
|
||||
// Adds/replaces a Sprite image.
|
||||
void setSprite(const std::string&, std::shared_ptr<const SpriteImage> = nullptr);
|
||||
@@ -63,8 +56,7 @@ private:
|
||||
|
||||
bool loaded = false;
|
||||
|
||||
Observer nullObserver;
|
||||
Observer* observer = &nullObserver;
|
||||
SpriteStoreObserver* observer = nullptr;
|
||||
|
||||
// Lock for sprites and dirty maps.
|
||||
std::mutex mutex;
|
||||
|
||||
18
src/mbgl/sprite/sprite_store_observer.hpp
Normal file
18
src/mbgl/sprite/sprite_store_observer.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef MBGL_SPRITE_STORE_OBSERVER
|
||||
#define MBGL_SPRITE_STORE_OBSERVER
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class SpriteStoreObserver {
|
||||
public:
|
||||
virtual ~SpriteStoreObserver() = default;
|
||||
|
||||
virtual void onSpriteLoaded() {}
|
||||
virtual void onSpriteError(std::exception_ptr) {}
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/style_observer.hpp>
|
||||
#include <mbgl/source/source.hpp>
|
||||
#include <mbgl/tile/tile.hpp>
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
@@ -27,6 +28,8 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static StyleObserver nullObserver;
|
||||
|
||||
bool Style::addClass(const std::string& className, const PropertyTransition& properties) {
|
||||
if (std::find(classes.begin(), classes.end(), className) != classes.end()) return false;
|
||||
classes.push_back(className);
|
||||
@@ -64,6 +67,7 @@ Style::Style(FileSource& fileSource_, float pixelRatio)
|
||||
spriteStore(std::make_unique<SpriteStore>(pixelRatio)),
|
||||
spriteAtlas(std::make_unique<SpriteAtlas>(1024, 1024, pixelRatio, *spriteStore)),
|
||||
lineAtlas(std::make_unique<LineAtlas>(256, 512)),
|
||||
observer(&nullObserver),
|
||||
workers(4) {
|
||||
glyphStore->setObserver(this);
|
||||
spriteStore->setObserver(this);
|
||||
@@ -359,7 +363,7 @@ void Style::onLowMemory() {
|
||||
}
|
||||
}
|
||||
|
||||
void Style::setObserver(Observer* observer_) {
|
||||
void Style::setObserver(StyleObserver* observer_) {
|
||||
observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/style/property_transition.hpp>
|
||||
|
||||
#include <mbgl/source/source.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/sprite/sprite_store.hpp>
|
||||
#include <mbgl/source/source_observer.hpp>
|
||||
#include <mbgl/text/glyph_store_observer.hpp>
|
||||
#include <mbgl/sprite/sprite_store_observer.hpp>
|
||||
#include <mbgl/map/mode.hpp>
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -31,6 +32,7 @@ class SpriteAtlas;
|
||||
class LineAtlas;
|
||||
class StyleUpdateParameters;
|
||||
class StyleQueryParameters;
|
||||
class StyleObserver;
|
||||
|
||||
struct RenderData {
|
||||
Color backgroundColor = {{ 0, 0, 0, 0 }};
|
||||
@@ -38,31 +40,17 @@ struct RenderData {
|
||||
std::vector<RenderItem> order;
|
||||
};
|
||||
|
||||
class Style : public GlyphStore::Observer,
|
||||
public SpriteStore::Observer,
|
||||
public Source::Observer,
|
||||
class Style : public GlyphStoreObserver,
|
||||
public SpriteStoreObserver,
|
||||
public SourceObserver,
|
||||
public util::noncopyable {
|
||||
public:
|
||||
Style(FileSource&, float pixelRatio);
|
||||
~Style();
|
||||
|
||||
class Observer : public GlyphStore::Observer,
|
||||
public SpriteStore::Observer,
|
||||
public Source::Observer {
|
||||
public:
|
||||
/**
|
||||
* In addition to the individual glyph, sprite, and source events, the
|
||||
* following "rollup" events are provided for convenience. They are
|
||||
* strictly additive; e.g. when a source is loaded, both `onSourceLoaded`
|
||||
* and `onResourceLoaded` will be called.
|
||||
*/
|
||||
virtual void onResourceLoaded() {};
|
||||
virtual void onResourceError(std::exception_ptr) {};
|
||||
};
|
||||
|
||||
void setJSON(const std::string& data, const std::string& base);
|
||||
|
||||
void setObserver(Observer*);
|
||||
void setObserver(StyleObserver*);
|
||||
|
||||
bool isLoaded() const;
|
||||
|
||||
@@ -120,23 +108,22 @@ private:
|
||||
|
||||
std::vector<std::unique_ptr<StyleLayer>>::const_iterator findLayer(const std::string& layerID) const;
|
||||
|
||||
// GlyphStore::Observer implementation.
|
||||
// GlyphStoreObserver implementation.
|
||||
void onGlyphsLoaded(const FontStack&, const GlyphRange&) override;
|
||||
void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override;
|
||||
|
||||
// SpriteStore::Observer implementation.
|
||||
// SpriteStoreObserver implementation.
|
||||
void onSpriteLoaded() override;
|
||||
void onSpriteError(std::exception_ptr) override;
|
||||
|
||||
// Source::Observer implementation.
|
||||
// SourceObserver implementation.
|
||||
void onSourceLoaded(Source&) override;
|
||||
void onSourceError(Source&, std::exception_ptr) override;
|
||||
void onTileLoaded(Source&, const OverscaledTileID&, bool isNewTile) override;
|
||||
void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) override;
|
||||
void onPlacementRedone() override;
|
||||
|
||||
Observer nullObserver;
|
||||
Observer* observer = &nullObserver;
|
||||
StyleObserver* observer = nullptr;
|
||||
|
||||
std::exception_ptr lastError;
|
||||
|
||||
|
||||
26
src/mbgl/style/style_observer.hpp
Normal file
26
src/mbgl/style/style_observer.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef MBGL_STYLE_STYLE_OBSERVER
|
||||
#define MBGL_STYLE_STYLE_OBSERVER
|
||||
|
||||
#include <mbgl/text/glyph_store_observer.hpp>
|
||||
#include <mbgl/sprite/sprite_store_observer.hpp>
|
||||
#include <mbgl/source/source_observer.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class StyleObserver : public GlyphStoreObserver, public SpriteStoreObserver, public SourceObserver {
|
||||
public:
|
||||
virtual ~StyleObserver() = default;
|
||||
|
||||
/**
|
||||
* In addition to the individual glyph, sprite, and source events, the
|
||||
* following "rollup" events are provided for convenience. They are
|
||||
* strictly additive; e.g. when a source is loaded, both `onSourceLoaded`
|
||||
* and `onResourceLoaded` will be called.
|
||||
*/
|
||||
virtual void onResourceLoaded() {}
|
||||
virtual void onResourceError(std::exception_ptr) {}
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/text/glyph_store_observer.hpp>
|
||||
#include <mbgl/text/glyph_set.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
@@ -65,7 +65,7 @@ namespace mbgl {
|
||||
GlyphPBF::GlyphPBF(GlyphStore* store,
|
||||
const FontStack& fontStack,
|
||||
const GlyphRange& glyphRange,
|
||||
GlyphStore::Observer* observer_,
|
||||
GlyphStoreObserver* observer_,
|
||||
FileSource& fileSource)
|
||||
: parsed(false),
|
||||
observer(observer_) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
GlyphPBF(GlyphStore*,
|
||||
const FontStack&,
|
||||
const GlyphRange&,
|
||||
GlyphStore::Observer*,
|
||||
GlyphStoreObserver*,
|
||||
FileSource&);
|
||||
~GlyphPBF();
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
private:
|
||||
std::atomic<bool> parsed;
|
||||
std::unique_ptr<AsyncRequest> req;
|
||||
GlyphStore::Observer* observer = nullptr;
|
||||
GlyphStoreObserver* observer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/text/glyph_store_observer.hpp>
|
||||
#include <mbgl/text/glyph_pbf.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static GlyphStoreObserver nullObserver;
|
||||
|
||||
GlyphStore::GlyphStore(FileSource& fileSource_)
|
||||
: fileSource(fileSource_) {
|
||||
: fileSource(fileSource_), observer(&nullObserver) {
|
||||
}
|
||||
|
||||
GlyphStore::~GlyphStore() = default;
|
||||
@@ -66,7 +69,7 @@ util::exclusive<GlyphSet> GlyphStore::getGlyphSet(const FontStack& fontStack) {
|
||||
return { it->second.get(), std::move(lock) };
|
||||
}
|
||||
|
||||
void GlyphStore::setObserver(Observer* observer_) {
|
||||
void GlyphStore::setObserver(GlyphStoreObserver* observer_) {
|
||||
observer = observer_;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,20 +18,13 @@ namespace mbgl {
|
||||
|
||||
class FileSource;
|
||||
class GlyphPBF;
|
||||
class GlyphStoreObserver;
|
||||
|
||||
// The GlyphStore manages the loading and storage of Glyphs
|
||||
// and creation of GlyphSet objects. The GlyphStore lives
|
||||
// on the MapThread but can be queried from any thread.
|
||||
class GlyphStore : private util::noncopyable {
|
||||
public:
|
||||
class Observer {
|
||||
public:
|
||||
virtual ~Observer() = default;
|
||||
|
||||
virtual void onGlyphsLoaded(const FontStack&, const GlyphRange&) {};
|
||||
virtual void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) {};
|
||||
};
|
||||
|
||||
GlyphStore(FileSource&);
|
||||
~GlyphStore();
|
||||
|
||||
@@ -52,7 +45,7 @@ public:
|
||||
return glyphURL;
|
||||
}
|
||||
|
||||
void setObserver(Observer* observer);
|
||||
void setObserver(GlyphStoreObserver* observer);
|
||||
|
||||
private:
|
||||
void requestGlyphRange(const FontStack&, const GlyphRange&);
|
||||
@@ -68,8 +61,7 @@ private:
|
||||
|
||||
util::WorkQueue workQueue;
|
||||
|
||||
Observer nullObserver;
|
||||
Observer* observer = &nullObserver;
|
||||
GlyphStoreObserver* observer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
21
src/mbgl/text/glyph_store_observer.hpp
Normal file
21
src/mbgl/text/glyph_store_observer.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef MBGL_TEXT_GLYPH_STORE_OBSERVER
|
||||
#define MBGL_TEXT_GLYPH_STORE_OBSERVER
|
||||
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/text/glyph_range.hpp>
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class GlyphStoreObserver {
|
||||
public:
|
||||
virtual ~GlyphStoreObserver() = default;
|
||||
|
||||
virtual void onGlyphsLoaded(const FontStack&, const GlyphRange&) {}
|
||||
virtual void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) {}
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef MBGL_TEST_STUB_STYLE_OBSERVER
|
||||
#define MBGL_TEST_STUB_STYLE_OBSERVER
|
||||
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/style/style_observer.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
/**
|
||||
* An implementation of Style::Observer that forwards all methods to dynamically-settable lambas.
|
||||
* An implementation of StyleObserver that forwards all methods to dynamically-settable lambas.
|
||||
*/
|
||||
class StubStyleObserver : public Style::Observer {
|
||||
class StubStyleObserver : public StyleObserver {
|
||||
public:
|
||||
void onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) override {
|
||||
if (glyphsLoaded) glyphsLoaded(fontStack, glyphRange);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
|
||||
#include <mbgl/style/style.hpp>
|
||||
#include <mbgl/source/source.hpp>
|
||||
#include <mbgl/util/io.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
Reference in New Issue
Block a user