summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-06 07:06:51 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-12 16:57:52 -0700
commit08101921633ded8978c003179c5f324c91aac266 (patch)
treecf65d7ff383548ada33791c01f95d1b5070098de /src/mbgl/text
parent258ac8219a741476965581a6c6ab866ab8c57fe5 (diff)
downloadqtlocation-mapboxgl-08101921633ded8978c003179c5f324c91aac266.tar.gz
[core] Inline GlyphSet into GlyphAtlas
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/glyph_atlas.cpp102
-rw-r--r--src/mbgl/text/glyph_atlas.hpp8
-rw-r--r--src/mbgl/text/glyph_set.cpp30
-rw-r--r--src/mbgl/text/glyph_set.hpp18
4 files changed, 68 insertions, 90 deletions
diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp
index 3e8bb0fe9c..2256805606 100644
--- a/src/mbgl/text/glyph_atlas.cpp
+++ b/src/mbgl/text/glyph_atlas.cpp
@@ -25,10 +25,10 @@ GlyphAtlas::GlyphAtlas(const Size size, FileSource& fileSource_)
GlyphAtlas::~GlyphAtlas() = default;
-GlyphSet& GlyphAtlas::getGlyphSet(const FontStack& fontStack) {
- return entries[fontStack].glyphSet;
+std::map<uint32_t, SDFGlyph>& GlyphAtlas::getGlyphSet(const FontStack& fontStack) {
+ return entries[fontStack].sdfs;
}
-
+
bool GlyphAtlas::hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet& ranges) const {
for (const auto& range : ranges) {
if (!hasGlyphRange(fontStack,range)) {
@@ -87,45 +87,70 @@ GlyphAtlas::GlyphRequest& GlyphAtlas::requestRange(Entry& entry, const FontStack
return request;
}
- request.req = fileSource.request(Resource::glyphs(glyphURL, fontStack, range),
- [this, &entry, &request, fontStack, range](Response res) {
- if (res.error) {
- observer->onGlyphsError(fontStack, range, std::make_exception_ptr(std::runtime_error(res.error->message)));
- } else if (res.notModified) {
- return;
- } else {
- if (!res.noContent) {
- std::vector<SDFGlyph> glyphs;
-
- try {
- glyphs = parseGlyphPBF(range, *res.data);
- } catch (...) {
- observer->onGlyphsError(fontStack, range, std::current_exception());
- return;
- }
-
- for (auto& glyph : glyphs) {
- entry.glyphSet.insert(std::move(glyph));
- }
- }
+ request.req = fileSource.request(Resource::glyphs(glyphURL, fontStack, range), [this, fontStack, range](Response res) {
+ processResponse(res, fontStack, range);
+ });
+
+ return request;
+}
- request.parsed = true;
+void GlyphAtlas::processResponse(const Response& res, const FontStack& fontStack, const GlyphRange& range) {
+ if (res.error) {
+ observer->onGlyphsError(fontStack, range, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ return;
+ }
- for (auto& pair : request.requestors) {
- GlyphRequestor& requestor = *pair.first;
- const std::shared_ptr<GlyphDependencies>& dependencies = pair.second;
- if (dependencies.unique()) {
- addGlyphs(requestor, *dependencies);
- }
- }
+ if (res.notModified) {
+ return;
+ }
+
+ Entry& entry = entries[fontStack];
+ GlyphRequest& request = entry.ranges[range];
+
+ if (!res.noContent) {
+ std::vector<SDFGlyph> glyphs;
- request.requestors.clear();
+ try {
+ glyphs = parseGlyphPBF(range, *res.data);
+ } catch (...) {
+ observer->onGlyphsError(fontStack, range, std::current_exception());
+ return;
+ }
- observer->onGlyphsLoaded(fontStack, range);
+ for (auto& glyph : glyphs) {
+ auto it = entry.sdfs.find(glyph.id);
+ if (it == entry.sdfs.end()) {
+ // Glyph doesn't exist yet.
+ entry.sdfs.emplace(glyph.id, std::move(glyph));
+ } else if (it->second.metrics == glyph.metrics) {
+ if (it->second.bitmap != glyph.bitmap) {
+ // The actual bitmap was updated; this is unsupported.
+ Log::Warning(Event::Glyph, "Modified glyph changed bitmap represenation");
+ }
+ // At least try to update it in case it's currently unused.
+ // If it is already used, we won't attempt to update the glyph atlas texture.
+ it->second.bitmap = std::move(glyph.bitmap);
+ } else {
+ // The metrics were updated; this is unsupported.
+ Log::Warning(Event::Glyph, "Modified glyph has different metrics");
+ return;
}
- });
+ }
+ }
- return request;
+ request.parsed = true;
+
+ for (auto& pair : request.requestors) {
+ GlyphRequestor& requestor = *pair.first;
+ const std::shared_ptr<GlyphDependencies>& dependencies = pair.second;
+ if (dependencies.unique()) {
+ addGlyphs(requestor, *dependencies);
+ }
+ }
+
+ request.requestors.clear();
+
+ observer->onGlyphsLoaded(fontStack, range);
}
void GlyphAtlas::setObserver(GlyphAtlasObserver* observer_) {
@@ -142,12 +167,11 @@ void GlyphAtlas::addGlyphs(GlyphRequestor& requestor, const GlyphDependencies& g
GlyphPositions& positions = glyphPositions[fontStack];
Entry& entry = entries[fontStack];
- const auto& sdfs = entry.glyphSet.getSDFs();
for (const auto& glyphID : glyphIDs) {
loadedRanges.insert(getGlyphRange(glyphID));
- auto it = sdfs.find(glyphID);
- if (it == sdfs.end())
+ auto it = entry.sdfs.find(glyphID);
+ if (it == entry.sdfs.end())
continue;
addGlyph(requestor, fontStack, it->second);
diff --git a/src/mbgl/text/glyph_atlas.hpp b/src/mbgl/text/glyph_atlas.hpp
index f6491a6d81..2003c8e593 100644
--- a/src/mbgl/text/glyph_atlas.hpp
+++ b/src/mbgl/text/glyph_atlas.hpp
@@ -3,7 +3,7 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/text/glyph_atlas_observer.hpp>
#include <mbgl/text/glyph_range.hpp>
-#include <mbgl/text/glyph_set.hpp>
+#include <mbgl/text/glyph_pbf.hpp>
#include <mbgl/geometry/binpack.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
@@ -23,6 +23,7 @@ namespace mbgl {
class FileSource;
class AsyncRequest;
+class Response;
namespace gl {
class Context;
@@ -38,7 +39,7 @@ public:
GlyphAtlas(Size, FileSource&);
~GlyphAtlas();
- GlyphSet& getGlyphSet(const FontStack&);
+ std::map<uint32_t, SDFGlyph>& getGlyphSet(const FontStack&);
// Workers send a `getGlyphs` message to the main thread once they have determined
// which glyphs they will need. Invoking this method will increment reference
@@ -86,7 +87,7 @@ private:
struct Entry {
std::map<GlyphRange, GlyphRequest> ranges;
- GlyphSet glyphSet;
+ std::map<uint32_t, SDFGlyph> sdfs;
std::map<uint32_t, GlyphValue> glyphValues;
};
@@ -99,6 +100,7 @@ private:
bool rangeIsParsed(const std::map<GlyphRange, GlyphRequest>&, const GlyphRange&) const;
GlyphRequest& requestRange(Entry&, const FontStack&, const GlyphRange&);
+ void processResponse(const Response&, const FontStack&, const GlyphRange&);
void addGlyphs(GlyphRequestor&, const GlyphDependencies&);
void addGlyph(GlyphRequestor&, const FontStack&, const SDFGlyph&);
diff --git a/src/mbgl/text/glyph_set.cpp b/src/mbgl/text/glyph_set.cpp
deleted file mode 100644
index 3305d4136e..0000000000
--- a/src/mbgl/text/glyph_set.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <mbgl/text/glyph_set.hpp>
-#include <mbgl/util/logging.hpp>
-
-namespace mbgl {
-
-void GlyphSet::insert(SDFGlyph&& glyph) {
- auto it = sdfs.find(glyph.id);
- if (it == sdfs.end()) {
- // Glyph doesn't exist yet.
- sdfs.emplace(glyph.id, std::move(glyph));
- } else if (it->second.metrics == glyph.metrics) {
- if (it->second.bitmap != glyph.bitmap) {
- // The actual bitmap was updated; this is unsupported.
- Log::Warning(Event::Glyph, "Modified glyph changed bitmap represenation");
- }
- // At least try to update it in case it's currently unsused.
- // If it is already used; we won't attempt to update the glyph atlas texture.
- it->second.bitmap = std::move(glyph.bitmap);
- } else {
- // The metrics were updated; this is unsupported.
- Log::Warning(Event::Glyph, "Modified glyph has different metrics");
- return;
- }
-}
-
-const std::map<uint32_t, SDFGlyph>& GlyphSet::getSDFs() const {
- return sdfs;
-}
-
-} // end namespace mbgl
diff --git a/src/mbgl/text/glyph_set.hpp b/src/mbgl/text/glyph_set.hpp
deleted file mode 100644
index 8b56ccd7a3..0000000000
--- a/src/mbgl/text/glyph_set.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <mbgl/text/glyph_pbf.hpp>
-
-#include <map>
-
-namespace mbgl {
-
-class GlyphSet {
-public:
- void insert(SDFGlyph&&);
- const std::map<uint32_t, SDFGlyph>& getSDFs() const;
-
-private:
- std::map<uint32_t, SDFGlyph> sdfs;
-};
-
-} // end namespace mbgl