summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-05-10 22:42:48 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-05-14 11:29:24 +0300
commit953ee5e81bee613680468438e3efe4f7c3ff68f6 (patch)
tree453d9145093448a0222c4b54edce4cf2dac4e81f /src
parent81823e35a68eb87d9433457fe9983d06793a77bf (diff)
downloadqtlocation-mapboxgl-953ee5e81bee613680468438e3efe4f7c3ff68f6.tar.gz
[core] Create glyph manager at renderer construction time
Avoid unnecessary glyph manager presence check in `Renderer::Impl::()`.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp7
-rw-r--r--src/mbgl/text/glyph_manager.cpp11
-rw-r--r--src/mbgl/text/glyph_manager.hpp19
-rw-r--r--src/mbgl/tile/geometry_tile.cpp3
-rw-r--r--src/mbgl/tile/geometry_tile.hpp1
5 files changed, 20 insertions, 21 deletions
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index 3db9439b5c..b14a255024 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -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;
diff --git a/src/mbgl/text/glyph_manager.cpp b/src/mbgl/text/glyph_manager.cpp
index b947ef72c8..daa142e38f 100644
--- a/src/mbgl/text/glyph_manager.cpp
+++ b/src/mbgl/text/glyph_manager.cpp
@@ -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;
}
diff --git a/src/mbgl/text/glyph_manager.hpp b/src/mbgl/text/glyph_manager.hpp
index 831d84719c..8603a320d2 100644
--- a/src/mbgl/text/glyph_manager.hpp
+++ b/src/mbgl/text/glyph_manager.hpp
@@ -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&);
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index d110b2f826..3057712176 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -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) {
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 975c7aab0e..fadc0aab41 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -108,6 +108,7 @@ private:
std::shared_ptr<Mailbox> mailbox;
Actor<GeometryTileWorker> worker;
+ FileSource& fileSource;
GlyphManager& glyphManager;
ImageManager& imageManager;