[core] Create glyph manager at renderer construction time
Avoid unnecessary glyph manager presence check in `Renderer::Impl::()`.
This commit is contained in:
@@ -47,6 +47,7 @@ Renderer::Impl::Impl(gfx::RendererBackend& backend_,
|
||||
, pixelRatio(pixelRatio_)
|
||||
, programCacheDir(std::move(programCacheDir_))
|
||||
, localFontFamily(std::move(localFontFamily_))
|
||||
, glyphManager(std::make_unique<GlyphManager>(std::make_unique<LocalGlyphRasterizer>(localFontFamily)))
|
||||
, imageManager(std::make_unique<ImageManager>())
|
||||
, lineAtlas(std::make_unique<LineAtlas>(Size{ 256, 512 }))
|
||||
, imageImpls(makeMutable<std::vector<Immutable<style::Image::Impl>>>())
|
||||
@@ -54,6 +55,7 @@ Renderer::Impl::Impl(gfx::RendererBackend& backend_,
|
||||
, 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);
|
||||
imageManager->setObserver(this);
|
||||
}
|
||||
|
||||
@@ -77,12 +79,7 @@ void Renderer::Impl::setObserver(RendererObserver* observer_) {
|
||||
}
|
||||
|
||||
void Renderer::Impl::render(const UpdateParameters& updateParameters) {
|
||||
if (!glyphManager) {
|
||||
glyphManager = std::make_unique<GlyphManager>(updateParameters.fileSource, std::make_unique<LocalGlyphRasterizer>(localFontFamily));
|
||||
glyphManager->setObserver(this);
|
||||
}
|
||||
const bool isMapModeContinuous = updateParameters.mode == MapMode::Continuous;
|
||||
|
||||
if (!isMapModeContinuous) {
|
||||
// Reset zoom history state.
|
||||
zoomHistory.first = true;
|
||||
|
||||
@@ -11,15 +11,14 @@ namespace mbgl {
|
||||
|
||||
static GlyphManagerObserver nullObserver;
|
||||
|
||||
GlyphManager::GlyphManager(FileSource& fileSource_, std::unique_ptr<LocalGlyphRasterizer> localGlyphRasterizer_)
|
||||
: fileSource(fileSource_),
|
||||
observer(&nullObserver),
|
||||
GlyphManager::GlyphManager(std::unique_ptr<LocalGlyphRasterizer> localGlyphRasterizer_)
|
||||
: observer(&nullObserver),
|
||||
localGlyphRasterizer(std::move(localGlyphRasterizer_)) {
|
||||
}
|
||||
|
||||
GlyphManager::~GlyphManager() = default;
|
||||
|
||||
void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphDependencies) {
|
||||
void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphDependencies, FileSource& fileSource) {
|
||||
auto dependencies = std::make_shared<GlyphDependencies>(std::move(glyphDependencies));
|
||||
|
||||
// Figure out which glyph ranges need to be fetched. For each range that does need to
|
||||
@@ -47,7 +46,7 @@ void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphD
|
||||
if (it == entry.ranges.end() || !it->second.parsed) {
|
||||
GlyphRequest& request = entry.ranges[range];
|
||||
request.requestors[&requestor] = dependencies;
|
||||
requestRange(request, fontStack, range);
|
||||
requestRange(request, fontStack, range, fileSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +64,7 @@ Glyph GlyphManager::generateLocalSDF(const FontStack& fontStack, GlyphID glyphID
|
||||
return local;
|
||||
}
|
||||
|
||||
void GlyphManager::requestRange(GlyphRequest& request, const FontStack& fontStack, const GlyphRange& range) {
|
||||
void GlyphManager::requestRange(GlyphRequest& request, const FontStack& fontStack, const GlyphRange& range, FileSource& fileSource) {
|
||||
if (request.req) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <mbgl/text/glyph_manager_observer.hpp>
|
||||
#include <mbgl/text/glyph_range.hpp>
|
||||
#include <mbgl/text/local_glyph_rasterizer.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
#include <mbgl/util/immutable.hpp>
|
||||
|
||||
@@ -19,21 +18,25 @@ class Response;
|
||||
|
||||
class GlyphRequestor {
|
||||
public:
|
||||
virtual ~GlyphRequestor() = default;
|
||||
virtual void onGlyphsAvailable(GlyphMap) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~GlyphRequestor() = default;
|
||||
};
|
||||
|
||||
class GlyphManager : public util::noncopyable {
|
||||
class GlyphManager {
|
||||
public:
|
||||
GlyphManager(FileSource&, std::unique_ptr<LocalGlyphRasterizer> = std::make_unique<LocalGlyphRasterizer>(optional<std::string>()));
|
||||
GlyphManager(const GlyphManager&) = delete;
|
||||
GlyphManager& operator=(const GlyphManager&) = delete;
|
||||
explicit GlyphManager(std::unique_ptr<LocalGlyphRasterizer> = std::make_unique<LocalGlyphRasterizer>(optional<std::string>()));
|
||||
~GlyphManager();
|
||||
|
||||
// Workers send a `getGlyphs` message to the main thread once they have determined
|
||||
// their `GlyphDependencies`. If all glyphs are already locally available, GlyphManager
|
||||
// will provide them to the requestor immediately. Otherwise, it makes a request on the
|
||||
// FileSource is made for each range neeed, and notifies the observer when all are
|
||||
// FileSource is made for each range needed, and notifies the observer when all are
|
||||
// complete.
|
||||
void getGlyphs(GlyphRequestor&, GlyphDependencies);
|
||||
void getGlyphs(GlyphRequestor&, GlyphDependencies, FileSource&);
|
||||
void removeRequestor(GlyphRequestor&);
|
||||
|
||||
void setURL(const std::string& url) {
|
||||
@@ -47,8 +50,6 @@ public:
|
||||
|
||||
private:
|
||||
Glyph generateLocalSDF(const FontStack& fontStack, GlyphID glyphID);
|
||||
|
||||
FileSource& fileSource;
|
||||
std::string glyphURL;
|
||||
|
||||
struct GlyphRequest {
|
||||
@@ -64,7 +65,7 @@ private:
|
||||
|
||||
std::unordered_map<FontStack, Entry, FontStackHasher> entries;
|
||||
|
||||
void requestRange(GlyphRequest&, const FontStack&, const GlyphRange&);
|
||||
void requestRange(GlyphRequest&, const FontStack&, const GlyphRange&, FileSource& fileSource);
|
||||
void processResponse(const Response&, const FontStack&, const GlyphRange&);
|
||||
void notify(GlyphRequestor&, const GlyphDependencies&);
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_,
|
||||
parameters.mode,
|
||||
parameters.pixelRatio,
|
||||
parameters.debugOptions & MapDebugOptions::Collision),
|
||||
fileSource(parameters.fileSource),
|
||||
glyphManager(parameters.glyphManager),
|
||||
imageManager(parameters.imageManager),
|
||||
mode(parameters.mode),
|
||||
@@ -156,7 +157,7 @@ void GeometryTile::onGlyphsAvailable(GlyphMap glyphs) {
|
||||
}
|
||||
|
||||
void GeometryTile::getGlyphs(GlyphDependencies glyphDependencies) {
|
||||
glyphManager.getGlyphs(*this, std::move(glyphDependencies));
|
||||
glyphManager.getGlyphs(*this, std::move(glyphDependencies), fileSource);
|
||||
}
|
||||
|
||||
void GeometryTile::onImagesAvailable(ImageMap images, ImageMap patterns, ImageVersionMap versionMap, uint64_t imageCorrelationID) {
|
||||
|
||||
@@ -108,6 +108,7 @@ private:
|
||||
std::shared_ptr<Mailbox> mailbox;
|
||||
Actor<GeometryTileWorker> worker;
|
||||
|
||||
FileSource& fileSource;
|
||||
GlyphManager& glyphManager;
|
||||
ImageManager& imageManager;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user