diff options
author | Chris Loer <chris.loer@gmail.com> | 2017-03-31 14:53:18 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2017-04-04 11:33:12 -0700 |
commit | 5cdf838a387cae446dba500ac49a1c5524bf7949 (patch) | |
tree | 3b438034a7842c36a7804096785fca1a6ad6fa80 /test/text | |
parent | 64beba3accb0f2088b2e01fad710f915c81d99c7 (diff) | |
download | qtlocation-mapboxgl-5cdf838a387cae446dba500ac49a1c5524bf7949.tar.gz |
[core] De-mutex GlyphAtlas and SpriteAtlas
- Expose glyph and icon information to workers via message interface.
- Glyph/SpriteAtlas track which tiles have outstanding requests
and send messages to them when glyphs/icons become available.
- Remove obsolete "updateSymbolDependentTiles" pathway
- Symbol preparation for a tile now depends on all glyphs becoming
available before it can start.
- Start tracking individual icons needed for a tile, although we don't
do anything with the information yet.
- Introduce typedef for GlyphID
Diffstat (limited to 'test/text')
-rw-r--r-- | test/text/glyph_atlas.test.cpp | 46 | ||||
-rw-r--r-- | test/text/glyph_pbf.test.cpp | 2 |
2 files changed, 34 insertions, 14 deletions
diff --git a/test/text/glyph_atlas.test.cpp b/test/text/glyph_atlas.test.cpp index 3679cabc1b..fe27e4c6fe 100644 --- a/test/text/glyph_atlas.test.cpp +++ b/test/text/glyph_atlas.test.cpp @@ -11,12 +11,14 @@ using namespace mbgl; -class GlyphAtlasTest { +class GlyphAtlasTest : public GlyphRequestor { public: util::RunLoop loop; StubFileSource fileSource; StubStyleObserver observer; GlyphAtlas glyphAtlas{ { 32, 32 }, fileSource }; + GlyphPositionMap glyphPositions; + GlyphRangeSet loadedRanges; void run(const std::string& url, const FontStack& fontStack, const GlyphRangeSet& glyphRanges) { // Squelch logging. @@ -24,14 +26,31 @@ public: glyphAtlas.setObserver(&observer); glyphAtlas.setURL(url); + GlyphDependencies glyphDependencies; + for (const auto& range : glyphRanges) { + glyphDependencies[fontStack].insert(range.first); + } + glyphAtlas.getGlyphs(*this, glyphDependencies); glyphAtlas.hasGlyphRanges(fontStack, glyphRanges); loop.run(); } + void addGlyphs(GlyphRequestor& requestor, const GlyphDependencies& glyphDependencies) { + glyphAtlas.addGlyphs(requestor, glyphDependencies); + } + + bool hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet& ranges) const { + return glyphAtlas.hasGlyphRanges(fontStack, ranges); + } void end() { loop.stop(); } + + virtual void onGlyphsAvailable(GlyphPositionMap positions, GlyphRangeSet _loadedRanges) { + glyphPositions = std::move(positions); + loadedRanges = std::move(_loadedRanges); + } }; TEST(GlyphAtlas, LoadingSuccess) { @@ -50,11 +69,11 @@ TEST(GlyphAtlas, LoadingSuccess) { }; test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) { - if (!test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}, {256, 511}})) + if (!test.hasGlyphRanges({{"Test Stack"}}, {{0, 255}, {256, 511}})) return; - auto glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); - ASSERT_FALSE(glyphSet->getSDFs().empty()); + auto& glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); + ASSERT_FALSE(glyphSet.getSDFs().empty()); test.end(); }; @@ -83,8 +102,8 @@ TEST(GlyphAtlas, LoadingFail) { EXPECT_TRUE(error != nullptr); EXPECT_EQ(util::toString(error), "Failed by the test case"); - ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}})->getSDFs().empty()); - ASSERT_FALSE(test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); + ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}}).getSDFs().empty()); + ASSERT_FALSE(test.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); test.end(); }; @@ -111,8 +130,8 @@ TEST(GlyphAtlas, LoadingCorrupted) { EXPECT_TRUE(error != nullptr); EXPECT_EQ(util::toString(error), "unknown pbf field type exception"); - ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}})->getSDFs().empty()); - ASSERT_FALSE(test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); + ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}}).getSDFs().empty()); + ASSERT_FALSE(test.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); test.end(); }; @@ -145,19 +164,20 @@ TEST(GlyphAtlas, InvalidSDFGlyph) { const FontStack fontStack{ "Mock Font" }; GlyphAtlasTest test; - GlyphPositions positions; - auto glyphSet = test.glyphAtlas.getGlyphSet(fontStack); - glyphSet->insert(66, SDFGlyph{ 66 /* ASCII 'B' */, + auto& glyphSet = test.glyphAtlas.getGlyphSet(fontStack); + glyphSet.insert(66, SDFGlyph{ 66 /* ASCII 'B' */, AlphaImage({7, 7}), /* correct */ { 1 /* width */, 1 /* height */, 0 /* left */, 0 /* top */, 0 /* advance */ } }); - glyphSet->insert(67, SDFGlyph{ 67 /* ASCII 'C' */, + glyphSet.insert(67, SDFGlyph{ 67 /* ASCII 'C' */, AlphaImage({518, 8}), /* correct */ { 512 /* width */, 2 /* height */, 0 /* left */, 0 /* top */, 0 /* advance */ } }); - test.glyphAtlas.addGlyphs(1, std::u16string{u"ABC"}, fontStack, glyphSet, positions); + GlyphDependencies glyphDependencies = {{fontStack, {'A','B','C'}}}; + test.addGlyphs(test, glyphDependencies); + GlyphPositions positions = test.glyphPositions[fontStack]; ASSERT_EQ(2u, positions.size()); diff --git a/test/text/glyph_pbf.test.cpp b/test/text/glyph_pbf.test.cpp index be3ca3359b..48b2d7a07c 100644 --- a/test/text/glyph_pbf.test.cpp +++ b/test/text/glyph_pbf.test.cpp @@ -44,7 +44,7 @@ TEST(GlyphPBF, Parsing) { glyphAtlasObserver.glyphsLoaded = [&](const FontStack&, const GlyphRange&) { loop.stop(); - const auto& sdfs = glyphAtlas.getGlyphSet(fontStack)->getSDFs(); + const auto& sdfs = glyphAtlas.getGlyphSet(fontStack).getSDFs(); // The fake glyphs don't contain a glyph that has the ID 0; it only contains glyphs with // undefined IDs, but the parser should remove them. |