summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-03-31 14:53:18 -0700
committerChris Loer <chris.loer@mapbox.com>2017-04-04 11:33:12 -0700
commit5cdf838a387cae446dba500ac49a1c5524bf7949 (patch)
tree3b438034a7842c36a7804096785fca1a6ad6fa80 /test
parent64beba3accb0f2088b2e01fad710f915c81d99c7 (diff)
downloadqtlocation-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')
-rw-r--r--test/sprite/sprite_atlas.test.cpp34
-rw-r--r--test/text/glyph_atlas.test.cpp46
-rw-r--r--test/text/glyph_pbf.test.cpp2
3 files changed, 53 insertions, 29 deletions
diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp
index 2c425a95d2..2335165715 100644
--- a/test/sprite/sprite_atlas.test.cpp
+++ b/test/sprite/sprite_atlas.test.cpp
@@ -29,15 +29,17 @@ TEST(SpriteAtlas, Basic) {
EXPECT_EQ(112u, atlas.getSize().height);
auto metro = *atlas.getIcon("metro");
+ float imagePixelRatio = metro.relativePixelRatio * atlas.getPixelRatio();
EXPECT_EQ(0, metro.pos.x);
EXPECT_EQ(0, metro.pos.y);
EXPECT_EQ(20, metro.pos.w);
EXPECT_EQ(20, metro.pos.h);
- EXPECT_EQ(18, metro.spriteImage->getWidth());
- EXPECT_EQ(18, metro.spriteImage->getHeight());
- EXPECT_EQ(18u, metro.spriteImage->image.size.width);
- EXPECT_EQ(18u, metro.spriteImage->image.size.height);
- EXPECT_EQ(1.0f, metro.spriteImage->pixelRatio);
+ EXPECT_EQ(18, metro.width);
+ EXPECT_EQ(18, metro.height);
+ EXPECT_EQ(18u, metro.width * imagePixelRatio);
+ EXPECT_EQ(18u, metro.height * imagePixelRatio);
+ EXPECT_EQ(1.0f, imagePixelRatio);
+
EXPECT_EQ(63u, atlas.getAtlasImage().size.width);
EXPECT_EQ(112u, atlas.getAtlasImage().size.height);
@@ -82,15 +84,16 @@ TEST(SpriteAtlas, Size) {
EXPECT_EQ(112u, atlas.getSize().height);
auto metro = *atlas.getIcon("metro");
+ float imagePixelRatio = metro.relativePixelRatio * atlas.getPixelRatio();
EXPECT_EQ(0, metro.pos.x);
EXPECT_EQ(0, metro.pos.y);
EXPECT_EQ(16, metro.pos.w);
EXPECT_EQ(16, metro.pos.h);
- EXPECT_EQ(18, metro.spriteImage->getWidth());
- EXPECT_EQ(18, metro.spriteImage->getHeight());
- EXPECT_EQ(18u, metro.spriteImage->image.size.width);
- EXPECT_EQ(18u, metro.spriteImage->image.size.height);
- EXPECT_EQ(1.0f, metro.spriteImage->pixelRatio);
+ EXPECT_EQ(18, metro.width);
+ EXPECT_EQ(18, metro.height);
+ EXPECT_EQ(18u, metro.width * imagePixelRatio);
+ EXPECT_EQ(18u, metro.height * imagePixelRatio);
+ EXPECT_EQ(1.0f, imagePixelRatio);
// Now the image was created lazily.
EXPECT_EQ(89u, atlas.getAtlasImage().size.width);
@@ -108,15 +111,16 @@ TEST(SpriteAtlas, Updates) {
atlas.setSprite("one", std::make_shared<SpriteImage>(PremultipliedImage({ 16, 12 }), 1));
auto one = *atlas.getIcon("one");
+ float imagePixelRatio = one.relativePixelRatio * atlas.getPixelRatio();
EXPECT_EQ(0, one.pos.x);
EXPECT_EQ(0, one.pos.y);
EXPECT_EQ(20, one.pos.w);
EXPECT_EQ(16, one.pos.h);
- EXPECT_EQ(16, one.spriteImage->getWidth());
- EXPECT_EQ(12, one.spriteImage->getHeight());
- EXPECT_EQ(16u, one.spriteImage->image.size.width);
- EXPECT_EQ(12u, one.spriteImage->image.size.height);
- EXPECT_EQ(1.0f, one.spriteImage->pixelRatio);
+ EXPECT_EQ(16, one.width);
+ EXPECT_EQ(12, one.height);
+ EXPECT_EQ(16u, one.width * imagePixelRatio);
+ EXPECT_EQ(12u, one.height * imagePixelRatio);
+ EXPECT_EQ(1.0f, imagePixelRatio);
// Now the image was created lazily.
EXPECT_EQ(32u, atlas.getAtlasImage().size.width);
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.