Index glyph use by tile pointer value, not tile ID

There can be multiple tiles with the same ID, but from different
sources.

Fixes #957
This commit is contained in:
John Firebaugh
2015-03-12 17:46:52 -07:00
parent 96682a02af
commit 6325f1e25a
6 changed files with 21 additions and 18 deletions

View File

@@ -18,7 +18,7 @@ GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_)
dirty(true) {
}
void GlyphAtlas::addGlyphs(uint64_t tileID,
void GlyphAtlas::addGlyphs(uintptr_t tileUID,
const std::u32string& text,
const std::string& stackName,
const FontStack& fontStack,
@@ -36,12 +36,12 @@ void GlyphAtlas::addGlyphs(uint64_t tileID,
}
const SDFGlyph& sdf = sdf_it->second;
Rect<uint16_t> rect = addGlyph(tileID, stackName, sdf);
Rect<uint16_t> rect = addGlyph(tileUID, stackName, sdf);
face.emplace(chr, Glyph{rect, sdf.metrics});
}
}
Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tileID,
Rect<uint16_t> GlyphAtlas::addGlyph(uintptr_t tileUID,
const std::string& stackName,
const SDFGlyph& glyph)
{
@@ -54,7 +54,7 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tileID,
// The glyph is already in this texture.
if (it != face.end()) {
GlyphValue& value = it->second;
value.ids.insert(tileID);
value.ids.insert(tileUID);
return value.rect;
}
@@ -85,7 +85,7 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tileID,
assert(rect.x + rect.w <= width);
assert(rect.y + rect.h <= height);
face.emplace(glyph.id, GlyphValue { rect, tileID });
face.emplace(glyph.id, GlyphValue { rect, tileUID });
// Copy the bitmap
char *target = data.get();
@@ -103,14 +103,14 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tileID,
return rect;
}
void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
std::lock_guard<std::mutex> lock(mtx);
for (auto& faces : index) {
std::map<uint32_t, GlyphValue>& face = faces.second;
for (auto it = face.begin(); it != face.end(); /* we advance in the body */) {
GlyphValue& value = it->second;
value.ids.erase(tile_id);
value.ids.erase(tileUID);
if (!value.ids.size()) {
const Rect<uint16_t>& rect = value.rect;

View File

@@ -17,12 +17,12 @@ class GlyphAtlas : public util::noncopyable {
public:
GlyphAtlas(uint16_t width, uint16_t height);
void addGlyphs(uint64_t tileID,
void addGlyphs(uintptr_t tileUID,
const std::u32string& text,
const std::string& stackName,
const FontStack&,
GlyphPositions&);
void removeGlyphs(uint64_t tile_id);
void removeGlyphs(uintptr_t tileUID);
void bind();
@@ -31,13 +31,13 @@ public:
private:
struct GlyphValue {
GlyphValue(const Rect<uint16_t>& rect_, uint64_t id)
GlyphValue(const Rect<uint16_t>& rect_, uintptr_t id)
: rect(rect_), ids({ id }) {}
Rect<uint16_t> rect;
std::set<uint64_t> ids;
std::set<uintptr_t> ids;
};
Rect<uint16_t> addGlyph(uint64_t tileID,
Rect<uint16_t> addGlyph(uintptr_t tileID,
const std::string& stackName,
const SDFGlyph&);

View File

@@ -256,7 +256,7 @@ std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer&
auto symbol = parseStyleLayoutSymbol(bucket_desc, tile.id.z);
auto bucket = util::make_unique<SymbolBucket>(std::move(symbol), *collision);
bucket->addFeatures(
layer, bucket_desc.filter, tile.id, spriteAtlas, *sprite, glyphAtlas, glyphStore);
layer, bucket_desc.filter, reinterpret_cast<uintptr_t>(&tile), spriteAtlas, *sprite, glyphAtlas, glyphStore);
return obsolete() ? nullptr : std::move(bucket);
}
}

View File

@@ -25,7 +25,7 @@ VectorTileData::VectorTileData(Tile::ID const& id_,
}
VectorTileData::~VectorTileData() {
glyphAtlas.removeGlyphs(id.to_uint64());
glyphAtlas.removeGlyphs(reinterpret_cast<uintptr_t>(this));
}

View File

@@ -124,8 +124,11 @@ std::vector<SymbolFeature> SymbolBucket::processFeatures(const GeometryTileLayer
void SymbolBucket::addFeatures(const GeometryTileLayer& layer,
const FilterExpression& filter,
const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite,
GlyphAtlas & glyphAtlas, GlyphStore &glyphStore) {
uintptr_t tileUID,
SpriteAtlas& spriteAtlas,
Sprite& sprite,
GlyphAtlas& glyphAtlas,
GlyphStore& glyphStore) {
auto &layout = *styleLayout;
const std::vector<SymbolFeature> features = processFeatures(layer, filter, glyphStore, sprite);
@@ -193,7 +196,7 @@ void SymbolBucket::addFeatures(const GeometryTileLayer& layer,
// Add the glyphs we need for this label to the glyph atlas.
if (shaping.size()) {
glyphAtlas.addGlyphs(id.to_uint64(), feature.label, layout.text.font, fontStack, face);
glyphAtlas.addGlyphs(tileUID, feature.label, layout.text.font, fontStack, face);
}
}

View File

@@ -67,7 +67,7 @@ public:
void addFeatures(const GeometryTileLayer&,
const FilterExpression&,
const Tile::ID&,
uintptr_t tileUID,
SpriteAtlas&,
Sprite&,
GlyphAtlas&,