[core] Lazy-load {Image,Glyph}Manager on Renderer::Impl

This commit is contained in:
Bruno de Oliveira Abinader
2019-03-13 16:16:33 +02:00
parent 8be135231d
commit 1b39f456fd
2 changed files with 18 additions and 9 deletions

View File

@@ -48,17 +48,14 @@ Renderer::Impl::Impl(RendererBackend& backend_,
, observer(&nullObserver())
, contextMode(contextMode_)
, pixelRatio(pixelRatio_)
, programCacheDir(programCacheDir_)
, glyphManager(std::make_unique<GlyphManager>(fileSource, std::make_unique<LocalGlyphRasterizer>(localFontFamily_)))
, imageManager(std::make_unique<ImageManager>())
, programCacheDir(std::move(programCacheDir_))
, localFontFamily(std::move(localFontFamily_))
, lineAtlas(std::make_unique<LineAtlas>(Size{ 256, 512 }))
, imageImpls(makeMutable<std::vector<Immutable<style::Image::Impl>>>())
, sourceImpls(makeMutable<std::vector<Immutable<style::Source::Impl>>>())
, layerImpls(makeMutable<std::vector<Immutable<style::Layer::Impl>>>())
, renderLight(makeMutable<Light::Impl>())
, placement(std::make_unique<Placement>(TransformState{}, MapMode::Static, TransitionOptions{}, true)) {
glyphManager->setObserver(this);
}
, placement(std::make_unique<Placement>(TransformState{}, MapMode::Static, TransitionOptions{}, true)) {}
Renderer::Impl::~Impl() {
assert(BackendScope::exists());
@@ -80,6 +77,15 @@ void Renderer::Impl::setObserver(RendererObserver* observer_) {
}
void Renderer::Impl::render(const UpdateParameters& updateParameters) {
if (!glyphManager) {
glyphManager = std::make_unique<GlyphManager>(fileSource, std::make_unique<LocalGlyphRasterizer>(localFontFamily));
glyphManager->setObserver(this);
}
if (!imageManager) {
imageManager = std::make_unique<ImageManager>();
}
if (updateParameters.mode != MapMode::Continuous) {
// Reset zoom history state.
zoomHistory.first = true;
@@ -748,7 +754,9 @@ void Renderer::Impl::dumDebugLogs() {
entry.second->dumpDebugLogs();
}
imageManager->dumpDebugLogs();
if (imageManager) {
imageManager->dumpDebugLogs();
}
}
RenderLayer* Renderer::Impl::getRenderLayer(const std::string& id) {
@@ -808,7 +816,7 @@ bool Renderer::Impl::isLoaded() const {
}
}
if (!imageManager->isLoaded()) {
if (!imageManager || !imageManager->isLoaded()) {
return false;
}

View File

@@ -38,7 +38,7 @@ class Renderer::Impl : public GlyphManagerObserver,
public RenderSourceObserver{
public:
Impl(RendererBackend&, float pixelRatio_, FileSource&, Scheduler&, GLContextMode,
const optional<std::string> programCacheDir, const optional<std::string> localFontFamily);
const optional<std::string> programCacheDir, const optional<std::string> localFontFamily_);
~Impl() final;
void markContextLost() {
@@ -98,6 +98,7 @@ private:
const GLContextMode contextMode;
const float pixelRatio;
const optional<std::string> programCacheDir;
const optional<std::string> localFontFamily;
enum class RenderState {
Never,