[core] Add runtime API for setting tile prefetch delta for Source

New setPrefetchZoomDelta(optional<uint8_t> delta) method allow overriding
default tile prefetch setting that is defined by the Map instance. The
method can be moved to generic style specification if found to be useful
for gl-js engine.
This commit is contained in:
Alexander Shalamov
2020-02-06 09:44:49 +02:00
parent a231005860
commit fce4129435
16 changed files with 77 additions and 2 deletions

View File

@@ -73,6 +73,8 @@ public:
SourceObserver* observer = nullptr;
virtual void loadDescription(FileSource&) = 0;
void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept;
optional<uint8_t> getPrefetchZoomDelta() const noexcept;
void dumpDebugLogs() const;
virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0;
@@ -85,6 +87,9 @@ public:
mapbox::base::TypeWrapper peer;
virtual mapbox::base::WeakPtr<Source> makeWeakPtr() = 0;
protected:
virtual Mutable<Impl> createMutable() const noexcept = 0;
};
} // namespace style

View File

@@ -50,6 +50,10 @@ public:
mapbox::base::WeakPtr<Source> makeWeakPtr() override {
return weakFactory.makeWeakPtr();
}
protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
std::shared_ptr<ThreadPool> threadPool;
std::unique_ptr<Actor<CustomTileLoader>> loader;

View File

@@ -81,6 +81,9 @@ public:
return weakFactory.makeWeakPtr();
}
protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
optional<std::string> url;
std::unique_ptr<AsyncRequest> req;

View File

@@ -33,6 +33,10 @@ public:
mapbox::base::WeakPtr<Source> makeWeakPtr() override {
return weakFactory.makeWeakPtr();
}
protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
optional<std::string> url;
std::unique_ptr<AsyncRequest> req;

View File

@@ -31,6 +31,9 @@ public:
return weakFactory.makeWeakPtr();
}
protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;

View File

@@ -30,6 +30,9 @@ public:
return weakFactory.makeWeakPtr();
}
protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;

View File

@@ -14,6 +14,10 @@ AnnotationSource::Impl::Impl()
: Source::Impl(SourceType::Annotations, AnnotationManager::SourceID) {
}
const AnnotationSource::Impl& AnnotationSource::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
void AnnotationSource::loadDescription(FileSource&) {
loaded = true;
}
@@ -26,4 +30,8 @@ bool AnnotationSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info)
return !std::strcmp(info->type, "line") || !std::strcmp(info->type, "symbol") || !std::strcmp(info->type, "fill");
}
Mutable<Source::Impl> AnnotationSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
} // namespace mbgl

View File

@@ -12,13 +12,15 @@ public:
class Impl;
const Impl& impl() const;
protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
void loadDescription(FileSource&) final;
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
mapbox::base::WeakPtr<Source> makeWeakPtr() override {
return weakFactory.makeWeakPtr();
}
Mutable<Impl> mutableImpl() const;
mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};

View File

@@ -31,6 +31,18 @@ void Source::setObserver(SourceObserver* observer_) {
observer = observer_ ? observer_ : &nullObserver;
}
void Source::setPrefetchZoomDelta(optional<uint8_t> delta) noexcept {
if (getPrefetchZoomDelta() == delta) return;
auto newImpl = createMutable();
newImpl->setPrefetchZoomDelta(std::move(delta));
baseImpl = std::move(newImpl);
observer->onSourceChanged(*this);
}
optional<uint8_t> Source::getPrefetchZoomDelta() const noexcept {
return baseImpl->getPrefetchZoomDelta();
}
void Source::dumpDebugLogs() const {
Log::Info(Event::General, "Source::id: %s", getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);

View File

@@ -8,5 +8,13 @@ Source::Impl::Impl(SourceType type_, std::string id_)
id(std::move(id_)) {
}
void Source::Impl::setPrefetchZoomDelta(optional<uint8_t> delta) noexcept {
prefetchZoomDelta = std::move(delta);
}
optional<uint8_t> Source::Impl::getPrefetchZoomDelta() const noexcept {
return prefetchZoomDelta;
}
} // namespace style
} // namespace mbgl

View File

@@ -20,9 +20,12 @@ public:
Impl& operator=(const Impl&) = delete;
virtual optional<std::string> getAttribution() const = 0;
void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept;
optional<uint8_t> getPrefetchZoomDelta() const noexcept;
const SourceType type;
const std::string id;
optional<uint8_t> prefetchZoomDelta;
protected:
Impl(SourceType, std::string);

View File

@@ -27,7 +27,7 @@ const CustomGeometrySource::Impl& CustomGeometrySource::impl() const {
}
void CustomGeometrySource::loadDescription(FileSource&) {
baseImpl = makeMutable<CustomGeometrySource::Impl>(impl(), loader->self());
baseImpl = makeMutable<Impl>(impl(), loader->self());
loaded = true;
observer->onSourceLoaded(*this);
}
@@ -49,5 +49,9 @@ void CustomGeometrySource::invalidateRegion(const LatLngBounds& bounds) {
loader->self().invoke(&CustomTileLoader::invalidateRegion, bounds, impl().getZoomRange());
}
Mutable<Source::Impl> CustomGeometrySource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
} // namespace style
} // namespace mbgl

View File

@@ -120,5 +120,9 @@ bool GeoJSONSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) co
return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> GeoJSONSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
} // namespace style
} // namespace mbgl

View File

@@ -87,5 +87,9 @@ bool ImageSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) cons
return mbgl::underlying_type(Tile::Kind::Raster) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> ImageSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
} // namespace style
} // namespace mbgl

View File

@@ -87,5 +87,9 @@ bool RasterSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) con
return mbgl::underlying_type(Tile::Kind::Raster) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> RasterSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
} // namespace style
} // namespace mbgl

View File

@@ -91,5 +91,9 @@ bool VectorSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) con
return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
}
Mutable<Source::Impl> VectorSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}
} // namespace style
} // namespace mbgl