diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-06-07 12:45:35 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-06-13 10:18:43 -0700 |
commit | 0b687312071305c050d97e04fef1c80193f443c5 (patch) | |
tree | 64c20efaa17fefef9f902811a000fd6e425c849b /test | |
parent | 92252849c1a2ddf7887d1908841fa3c90dd59766 (diff) | |
download | qtlocation-mapboxgl-0b687312071305c050d97e04fef1c80193f443c5.tar.gz |
[core] Per-bucket icon atlases
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/image_manager/basic/expected.png | bin | 0 -> 646 bytes | |||
-rw-r--r-- | test/fixtures/image_manager/updates_after/expected.png | bin | 0 -> 136 bytes | |||
-rw-r--r-- | test/fixtures/image_manager/updates_before/expected.png | bin | 0 -> 123 bytes | |||
-rw-r--r-- | test/fixtures/sprite_atlas/basic/expected.png | bin | 673 -> 0 bytes | |||
-rw-r--r-- | test/fixtures/sprite_atlas/size/expected.png | bin | 609 -> 0 bytes | |||
-rw-r--r-- | test/fixtures/sprite_atlas/updates_after/expected.png | bin | 118 -> 0 bytes | |||
-rw-r--r-- | test/fixtures/sprite_atlas/updates_before/expected.png | bin | 96 -> 0 bytes | |||
-rw-r--r-- | test/renderer/image_manager.test.cpp | 147 | ||||
-rw-r--r-- | test/sprite/sprite_atlas.test.cpp | 187 | ||||
-rw-r--r-- | test/style/source.test.cpp | 6 | ||||
-rw-r--r-- | test/text/quads.test.cpp | 4 | ||||
-rw-r--r-- | test/tile/annotation_tile.test.cpp | 6 | ||||
-rw-r--r-- | test/tile/geojson_tile.test.cpp | 6 | ||||
-rw-r--r-- | test/tile/raster_tile.test.cpp | 6 | ||||
-rw-r--r-- | test/tile/vector_tile.test.cpp | 6 |
15 files changed, 164 insertions, 204 deletions
diff --git a/test/fixtures/image_manager/basic/expected.png b/test/fixtures/image_manager/basic/expected.png Binary files differnew file mode 100644 index 0000000000..8c615234dc --- /dev/null +++ b/test/fixtures/image_manager/basic/expected.png diff --git a/test/fixtures/image_manager/updates_after/expected.png b/test/fixtures/image_manager/updates_after/expected.png Binary files differnew file mode 100644 index 0000000000..db588c739b --- /dev/null +++ b/test/fixtures/image_manager/updates_after/expected.png diff --git a/test/fixtures/image_manager/updates_before/expected.png b/test/fixtures/image_manager/updates_before/expected.png Binary files differnew file mode 100644 index 0000000000..1466a92fe7 --- /dev/null +++ b/test/fixtures/image_manager/updates_before/expected.png diff --git a/test/fixtures/sprite_atlas/basic/expected.png b/test/fixtures/sprite_atlas/basic/expected.png Binary files differdeleted file mode 100644 index 2960891c04..0000000000 --- a/test/fixtures/sprite_atlas/basic/expected.png +++ /dev/null diff --git a/test/fixtures/sprite_atlas/size/expected.png b/test/fixtures/sprite_atlas/size/expected.png Binary files differdeleted file mode 100644 index 5b08197a82..0000000000 --- a/test/fixtures/sprite_atlas/size/expected.png +++ /dev/null diff --git a/test/fixtures/sprite_atlas/updates_after/expected.png b/test/fixtures/sprite_atlas/updates_after/expected.png Binary files differdeleted file mode 100644 index 626ceab58b..0000000000 --- a/test/fixtures/sprite_atlas/updates_after/expected.png +++ /dev/null diff --git a/test/fixtures/sprite_atlas/updates_before/expected.png b/test/fixtures/sprite_atlas/updates_before/expected.png Binary files differdeleted file mode 100644 index 0858c19f05..0000000000 --- a/test/fixtures/sprite_atlas/updates_before/expected.png +++ /dev/null diff --git a/test/renderer/image_manager.test.cpp b/test/renderer/image_manager.test.cpp new file mode 100644 index 0000000000..203e05d492 --- /dev/null +++ b/test/renderer/image_manager.test.cpp @@ -0,0 +1,147 @@ +#include <mbgl/test/util.hpp> +#include <mbgl/test/fixture_log_observer.hpp> +#include <mbgl/test/stub_file_source.hpp> +#include <mbgl/test/stub_style_observer.hpp> + +#include <mbgl/renderer/image_manager.hpp> +#include <mbgl/sprite/sprite_parser.hpp> +#include <mbgl/style/image_impl.hpp> +#include <mbgl/util/io.hpp> +#include <mbgl/util/image.hpp> +#include <mbgl/util/run_loop.hpp> +#include <mbgl/util/default_thread_pool.hpp> +#include <mbgl/util/string.hpp> + +#include <utility> + +using namespace mbgl; + +TEST(ImageManager, Missing) { + ImageManager imageManager; + EXPECT_FALSE(imageManager.getImage("doesnotexist")); +} + +TEST(ImageManager, Basic) { + FixtureLog log; + ImageManager imageManager; + + auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"), + util::read_file("test/fixtures/annotations/emerald.json")); + for (auto& image : images) { + imageManager.addImage(image->baseImpl); + } + + auto metro = *imageManager.getPattern("metro"); + EXPECT_EQ(1, metro.tl()[0]); + EXPECT_EQ(1, metro.tl()[1]); + EXPECT_EQ(19, metro.br()[0]); + EXPECT_EQ(19, metro.br()[1]); + EXPECT_EQ(18, metro.displaySize()[0]); + EXPECT_EQ(18, metro.displaySize()[1]); + EXPECT_EQ(1.0f, metro.pixelRatio); + EXPECT_EQ(imageManager.getPixelSize(), imageManager.getAtlasImage().size); + + test::checkImage("test/fixtures/image_manager/basic", imageManager.getAtlasImage()); +} + +TEST(ImageManager, Updates) { + ImageManager imageManager; + + PremultipliedImage imageA({ 16, 12 }); + imageA.fill(255); + imageManager.addImage(makeMutable<style::Image::Impl>("one", std::move(imageA), 1)); + + auto a = *imageManager.getPattern("one"); + EXPECT_EQ(1, a.tl()[0]); + EXPECT_EQ(1, a.tl()[1]); + EXPECT_EQ(17, a.br()[0]); + EXPECT_EQ(13, a.br()[1]); + EXPECT_EQ(16, a.displaySize()[0]); + EXPECT_EQ(12, a.displaySize()[1]); + EXPECT_EQ(1.0f, a.pixelRatio); + test::checkImage("test/fixtures/image_manager/updates_before", imageManager.getAtlasImage()); + + PremultipliedImage imageB({ 5, 5 }); + imageA.fill(200); + imageManager.updateImage(makeMutable<style::Image::Impl>("one", std::move(imageB), 1)); + + auto b = *imageManager.getPattern("one"); + EXPECT_EQ(1, b.tl()[0]); + EXPECT_EQ(1, b.tl()[1]); + EXPECT_EQ(6, b.br()[0]); + EXPECT_EQ(6, b.br()[1]); + EXPECT_EQ(5, b.displaySize()[0]); + EXPECT_EQ(5, b.displaySize()[1]); + EXPECT_EQ(1.0f, b.pixelRatio); + test::checkImage("test/fixtures/image_manager/updates_after", imageManager.getAtlasImage()); +} + +TEST(ImageManager, AddRemove) { + FixtureLog log; + ImageManager imageManager; + + imageManager.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2)); + imageManager.addImage(makeMutable<style::Image::Impl>("two", PremultipliedImage({ 16, 16 }), 2)); + imageManager.addImage(makeMutable<style::Image::Impl>("three", PremultipliedImage({ 16, 16 }), 2)); + + imageManager.removeImage("one"); + imageManager.removeImage("two"); + + EXPECT_NE(nullptr, imageManager.getImage("three")); + EXPECT_EQ(nullptr, imageManager.getImage("two")); + EXPECT_EQ(nullptr, imageManager.getImage("four")); +} + +TEST(ImageManager, RemoveReleasesBinPackRect) { + FixtureLog log; + ImageManager imageManager; + + imageManager.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1)); + EXPECT_TRUE(imageManager.getImage("big")); + + imageManager.removeImage("big"); + + imageManager.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1)); + EXPECT_TRUE(imageManager.getImage("big")); + EXPECT_TRUE(log.empty()); +} + +class StubImageRequestor : public ImageRequestor { +public: + void onImagesAvailable(ImageMap images) final { + if (imagesAvailable) imagesAvailable(images); + } + + std::function<void (ImageMap)> imagesAvailable; +}; + +TEST(ImageManager, NotifiesRequestorWhenSpriteIsLoaded) { + ImageManager imageManager; + StubImageRequestor requestor; + bool notified = false; + + requestor.imagesAvailable = [&] (ImageMap) { + notified = true; + }; + + imageManager.getImages(requestor, {"one"}); + ASSERT_FALSE(notified); + + imageManager.onSpriteLoaded(); + ASSERT_TRUE(notified); +} + +TEST(ImageManager, NotifiesRequestorImmediatelyIfDependenciesAreSatisfied) { + ImageManager imageManager; + StubImageRequestor requestor; + bool notified = false; + + requestor.imagesAvailable = [&] (ImageMap) { + notified = true; + }; + + imageManager.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2)); + imageManager.getImages(requestor, {"one"}); + + ASSERT_TRUE(notified); +} diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp deleted file mode 100644 index 78a5862475..0000000000 --- a/test/sprite/sprite_atlas.test.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include <mbgl/test/util.hpp> -#include <mbgl/test/fixture_log_observer.hpp> -#include <mbgl/test/stub_file_source.hpp> -#include <mbgl/test/stub_style_observer.hpp> - -#include <mbgl/sprite/sprite_atlas.hpp> -#include <mbgl/sprite/sprite_parser.hpp> -#include <mbgl/style/image_impl.hpp> -#include <mbgl/util/io.hpp> -#include <mbgl/util/image.hpp> -#include <mbgl/util/run_loop.hpp> -#include <mbgl/util/default_thread_pool.hpp> -#include <mbgl/util/string.hpp> - -#include <utility> - -using namespace mbgl; - -TEST(SpriteAtlas, Basic) { - FixtureLog log; - SpriteAtlas atlas; - - auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"), - util::read_file("test/fixtures/annotations/emerald.json")); - for (auto& image : images) { - atlas.addImage(image->baseImpl); - } - - auto metro = *atlas.getIcon("metro"); - EXPECT_EQ(1, metro.tl()[0]); - EXPECT_EQ(1, metro.tl()[1]); - EXPECT_EQ(19, metro.br()[0]); - EXPECT_EQ(19, metro.br()[1]); - EXPECT_EQ(18, metro.displaySize()[0]); - EXPECT_EQ(18, metro.displaySize()[1]); - EXPECT_EQ(1.0f, metro.pixelRatio); - - EXPECT_EQ(atlas.getPixelSize(), atlas.getAtlasImage().size); - - auto missing = atlas.getIcon("doesnotexist"); - EXPECT_FALSE(missing); - - EXPECT_EQ(1u, log.count({ - EventSeverity::Info, - Event::Sprite, - int64_t(-1), - "Can't find sprite named 'doesnotexist'", - })); - - // Different wrapping mode produces different image. - auto metro2 = *atlas.getPattern("metro"); - EXPECT_EQ(21, metro2.tl()[0]); - EXPECT_EQ(1, metro2.tl()[1]); - EXPECT_EQ(39, metro2.br()[0]); - EXPECT_EQ(19, metro2.br()[1]); - - test::checkImage("test/fixtures/sprite_atlas/basic", atlas.getAtlasImage()); -} - -TEST(SpriteAtlas, Size) { - SpriteAtlas atlas; - - auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"), - util::read_file("test/fixtures/annotations/emerald.json")); - for (auto& image : images) { - atlas.addImage(image->baseImpl); - } - - auto metro = *atlas.getIcon("metro"); - EXPECT_EQ(1, metro.tl()[0]); - EXPECT_EQ(1, metro.tl()[1]); - EXPECT_EQ(19, metro.br()[0]); - EXPECT_EQ(19, metro.br()[1]); - EXPECT_EQ(18, metro.displaySize()[0]); - EXPECT_EQ(18, metro.displaySize()[1]); - EXPECT_EQ(1.0f, metro.pixelRatio); - - test::checkImage("test/fixtures/sprite_atlas/size", atlas.getAtlasImage()); -} - -TEST(SpriteAtlas, Updates) { - SpriteAtlas atlas; - - atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 12 }), 1)); - auto one = *atlas.getIcon("one"); - EXPECT_EQ(1, one.tl()[0]); - EXPECT_EQ(1, one.tl()[1]); - EXPECT_EQ(17, one.br()[0]); - EXPECT_EQ(13, one.br()[1]); - EXPECT_EQ(16, one.displaySize()[0]); - EXPECT_EQ(12, one.displaySize()[1]); - EXPECT_EQ(1.0f, one.pixelRatio); - - test::checkImage("test/fixtures/sprite_atlas/updates_before", atlas.getAtlasImage()); - - // Update image - PremultipliedImage image2({ 16, 12 }); - for (size_t i = 0; i < image2.bytes(); i++) { - image2.data.get()[i] = 255; - } - atlas.updateImage(makeMutable<style::Image::Impl>("one", std::move(image2), 1)); - - test::checkImage("test/fixtures/sprite_atlas/updates_after", atlas.getAtlasImage()); -} - -TEST(SpriteAtlas, AddRemove) { - FixtureLog log; - SpriteAtlas atlas; - - atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2)); - atlas.addImage(makeMutable<style::Image::Impl>("two", PremultipliedImage({ 16, 16 }), 2)); - atlas.addImage(makeMutable<style::Image::Impl>("three", PremultipliedImage({ 16, 16 }), 2)); - - atlas.removeImage("one"); - atlas.removeImage("two"); - - EXPECT_NE(nullptr, atlas.getImage("three")); - EXPECT_EQ(nullptr, atlas.getImage("two")); - EXPECT_EQ(nullptr, atlas.getImage("four")); - - EXPECT_EQ(1u, log.count({ - EventSeverity::Info, - Event::Sprite, - int64_t(-1), - "Can't find sprite named 'two'", - })); - EXPECT_EQ(1u, log.count({ - EventSeverity::Info, - Event::Sprite, - int64_t(-1), - "Can't find sprite named 'four'", - })); -} - -TEST(SpriteAtlas, RemoveReleasesBinPackRect) { - FixtureLog log; - SpriteAtlas atlas; - - atlas.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1)); - EXPECT_TRUE(atlas.getIcon("big")); - - atlas.removeImage("big"); - - atlas.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1)); - EXPECT_TRUE(atlas.getIcon("big")); - EXPECT_TRUE(log.empty()); -} - -class StubIconRequestor : public IconRequestor { -public: - void onIconsAvailable(IconMap icons) final { - if (iconsAvailable) iconsAvailable(icons); - } - - std::function<void (IconMap)> iconsAvailable; -}; - -TEST(SpriteAtlas, NotifiesRequestorWhenSpriteIsLoaded) { - SpriteAtlas atlas; - StubIconRequestor requestor; - bool notified = false; - - requestor.iconsAvailable = [&] (IconMap) { - notified = true; - }; - - atlas.getIcons(requestor, {"one"}); - ASSERT_FALSE(notified); - - atlas.onSpriteLoaded(); - ASSERT_TRUE(notified); -} - -TEST(SpriteAtlas, NotifiesRequestorImmediatelyIfDependenciesAreSatisfied) { - SpriteAtlas atlas; - StubIconRequestor requestor; - bool notified = false; - - requestor.iconsAvailable = [&] (IconMap) { - notified = true; - }; - - atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2)); - atlas.getIcons(requestor, {"one"}); - - ASSERT_TRUE(notified); -} diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 630d701299..eaa3c72877 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -31,7 +31,7 @@ #include <mbgl/map/transform.hpp> #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/annotation/annotation_source.hpp> -#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/renderer/image_manager.hpp> #include <mbgl/text/glyph_manager.hpp> #include <cstdint> @@ -48,7 +48,7 @@ public: TransformState transformState; ThreadPool threadPool { 1 }; AnnotationManager annotationManager; - SpriteAtlas spriteAtlas; + ImageManager imageManager; GlyphManager glyphManager { fileSource }; TileParameters tileParameters { @@ -59,7 +59,7 @@ public: fileSource, MapMode::Continuous, annotationManager, - spriteAtlas, + imageManager, glyphManager }; diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp index 0a1dbbd1c9..efc3912aaa 100644 --- a/test/text/quads.test.cpp +++ b/test/text/quads.test.cpp @@ -12,7 +12,7 @@ using namespace mbgl::style; TEST(getIconQuads, normal) { SymbolLayoutProperties::Evaluated layout; Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0); - SpriteAtlasElement image = { + ImagePosition image = { mapbox::Bin(-1, 15, 11, 0, 0), style::Image::Impl("test", PremultipliedImage({1,1}), 1.0) }; @@ -42,7 +42,7 @@ TEST(getIconQuads, normal) { TEST(getIconQuads, style) { Anchor anchor(0.0, 0.0, 0.0, 0.5f, 0); - SpriteAtlasElement image = { + ImagePosition image = { mapbox::Bin(-1, 20, 20, 0, 0), style::Image::Impl("test", PremultipliedImage({1,1}), 1.0) }; diff --git a/test/tile/annotation_tile.test.cpp b/test/tile/annotation_tile.test.cpp index 168dbf5292..8aa91b1517 100644 --- a/test/tile/annotation_tile.test.cpp +++ b/test/tile/annotation_tile.test.cpp @@ -12,7 +12,7 @@ #include <mbgl/geometry/feature_index.hpp> #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/annotation/annotation_tile.hpp> -#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/renderer/image_manager.hpp> #include <mbgl/text/glyph_manager.hpp> #include <memory> @@ -27,7 +27,7 @@ public: ThreadPool threadPool { 1 }; AnnotationManager annotationManager; RenderStyle style { threadPool, fileSource }; - SpriteAtlas spriteAtlas; + ImageManager imageManager; GlyphManager glyphManager { fileSource }; TileParameters tileParameters { @@ -38,7 +38,7 @@ public: fileSource, MapMode::Continuous, annotationManager, - spriteAtlas, + imageManager, glyphManager }; }; diff --git a/test/tile/geojson_tile.test.cpp b/test/tile/geojson_tile.test.cpp index 9a9fe9a78f..2aa85c3860 100644 --- a/test/tile/geojson_tile.test.cpp +++ b/test/tile/geojson_tile.test.cpp @@ -10,7 +10,7 @@ #include <mbgl/renderer/tile_parameters.hpp> #include <mbgl/style/layers/circle_layer.hpp> #include <mbgl/annotation/annotation_manager.hpp> -#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/renderer/image_manager.hpp> #include <mbgl/text/glyph_manager.hpp> #include <memory> @@ -25,7 +25,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager; - SpriteAtlas spriteAtlas; + ImageManager imageManager; GlyphManager glyphManager { fileSource }; Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; @@ -37,7 +37,7 @@ public: fileSource, MapMode::Continuous, annotationManager, - spriteAtlas, + imageManager, glyphManager }; }; diff --git a/test/tile/raster_tile.test.cpp b/test/tile/raster_tile.test.cpp index ba296c0360..a0666c2146 100644 --- a/test/tile/raster_tile.test.cpp +++ b/test/tile/raster_tile.test.cpp @@ -9,7 +9,7 @@ #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/renderer/tile_parameters.hpp> #include <mbgl/renderer/buckets/raster_bucket.hpp> -#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/renderer/image_manager.hpp> #include <mbgl/text/glyph_manager.hpp> using namespace mbgl; @@ -21,7 +21,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager; - SpriteAtlas spriteAtlas; + ImageManager imageManager; GlyphManager glyphManager { fileSource }; Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; @@ -33,7 +33,7 @@ public: fileSource, MapMode::Continuous, annotationManager, - spriteAtlas, + imageManager, glyphManager }; }; diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index e1a1635bd3..c427a1a869 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -13,7 +13,7 @@ #include <mbgl/text/collision_tile.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/annotation/annotation_manager.hpp> -#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/renderer/image_manager.hpp> #include <mbgl/text/glyph_manager.hpp> #include <memory> @@ -27,7 +27,7 @@ public: util::RunLoop loop; ThreadPool threadPool { 1 }; AnnotationManager annotationManager; - SpriteAtlas spriteAtlas; + ImageManager imageManager; GlyphManager glyphManager { fileSource }; Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" }; @@ -39,7 +39,7 @@ public: fileSource, MapMode::Continuous, annotationManager, - spriteAtlas, + imageManager, glyphManager }; }; |