[core] Create glyph manager at renderer construction time

Avoid unnecessary glyph manager presence check in `Renderer::Impl::()`.
This commit is contained in:
Mikhail Pozdnyakov
2019-05-10 22:42:48 +03:00
parent 81823e35a6
commit 953ee5e81b
12 changed files with 31 additions and 32 deletions

View File

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

View File

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

View File

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

View File

@@ -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) {

View File

@@ -108,6 +108,7 @@ private:
std::shared_ptr<Mailbox> mailbox;
Actor<GeometryTileWorker> worker;
FileSource& fileSource;
GlyphManager& glyphManager;
ImageManager& imageManager;

View File

@@ -57,7 +57,7 @@ public:
Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
TileParameters tileParameters {
1.0,

View File

@@ -68,7 +68,7 @@ public:
StubFileSource fileSource;
StubGlyphManagerObserver observer;
StubGlyphRequestor requestor;
GlyphManager glyphManager{ fileSource, std::make_unique<StubLocalGlyphRasterizer>() };
GlyphManager glyphManager{ std::make_unique<StubLocalGlyphRasterizer>() };
void run(const std::string& url, GlyphDependencies dependencies) {
// Squelch logging.
@@ -76,7 +76,7 @@ public:
glyphManager.setURL(url);
glyphManager.setObserver(&observer);
glyphManager.getGlyphs(requestor, std::move(dependencies));
glyphManager.getGlyphs(requestor, std::move(dependencies), fileSource);
loop.run();
}
@@ -298,7 +298,7 @@ TEST(GlyphManager, ImmediateFileSource) {
StubFileSource fileSource = { StubFileSource::ResponseType::Synchronous };
StubGlyphManagerObserver observer;
StubGlyphRequestor requestor;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
void run(const std::string& url, GlyphDependencies dependencies) {
// Squelch logging.
@@ -306,7 +306,7 @@ TEST(GlyphManager, ImmediateFileSource) {
glyphManager.setURL(url);
glyphManager.setObserver(&observer);
glyphManager.getGlyphs(requestor, std::move(dependencies));
glyphManager.getGlyphs(requestor, std::move(dependencies), fileSource);
loop.run();
}

View File

@@ -28,7 +28,7 @@ public:
style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
TileParameters tileParameters {
1.0,

View File

@@ -27,7 +27,7 @@ public:
style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {

View File

@@ -22,7 +22,7 @@ public:
style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {

View File

@@ -22,7 +22,7 @@ public:
style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {

View File

@@ -28,7 +28,7 @@ public:
style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
GlyphManager glyphManager;
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
TileParameters tileParameters {
@@ -103,4 +103,4 @@ TEST(VectorTileData, ParseResults) {
ASSERT_EQ(properties.at("disputed"), *feature->getValue("disputed"));
ASSERT_EQ(feature->getValue("invalid"), nullopt);
}
}