diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-06-06 16:03:29 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-06-10 19:36:47 +0300 |
commit | f77af317c4e33902eedd2bf8c0527dacb1910522 (patch) | |
tree | 9edc059d9b59e2e6bfe60a23447c7c4706ae8a30 | |
parent | 737665bc070e9db4544b5d78ca69baf72ec958dc (diff) | |
download | qtlocation-mapboxgl-f77af317c4e33902eedd2bf8c0527dacb1910522.tar.gz |
[core] Update algorithm::updateTileMasks tests
-rw-r--r-- | benchmark/parse/tile_mask.benchmark.cpp | 34 | ||||
-rw-r--r-- | test/algorithm/update_tile_masks.test.cpp | 137 |
2 files changed, 75 insertions, 96 deletions
diff --git a/benchmark/parse/tile_mask.benchmark.cpp b/benchmark/parse/tile_mask.benchmark.cpp index 79ab685c28..a31e0b5eab 100644 --- a/benchmark/parse/tile_mask.benchmark.cpp +++ b/benchmark/parse/tile_mask.benchmark.cpp @@ -4,34 +4,32 @@ using namespace mbgl; -class MaskedRenderable { +class FakeTile { public: - MaskedRenderable(const UnwrappedTileID& id_, TileMask&& mask_) - : id(id_), mask(std::move(mask_)) { + FakeTile(TileMask mask_) + : mask(std::move(mask_)) { } - - UnwrappedTileID id; - TileMask mask; - bool used = true; - - void setMask(TileMask&& mask_) { + void setMask(TileMask mask_) { mask = std::move(mask_); } + + const bool usedByRenderedLayers = true; + TileMask mask; }; static void TileMaskGeneration(benchmark::State& state) { - std::vector<MaskedRenderable> renderables = { - MaskedRenderable{ UnwrappedTileID{ 12, 1028, 1456 }, {} }, - MaskedRenderable{ UnwrappedTileID{ 13, 2056, 2912 }, {} }, - MaskedRenderable{ UnwrappedTileID{ 13, 2056, 2913 }, {} }, - MaskedRenderable{ UnwrappedTileID{ 14, 4112, 5824 }, {} }, - MaskedRenderable{ UnwrappedTileID{ 14, 4112, 5827 }, {} }, - MaskedRenderable{ UnwrappedTileID{ 14, 4114, 5824 }, {} }, - MaskedRenderable{ UnwrappedTileID{ 14, 4114, 5825 }, {} }, + std::map<UnwrappedTileID, FakeTile> renderables = { + { UnwrappedTileID{ 12, 1028, 1456 }, TileMask{} }, + { UnwrappedTileID{ 13, 2056, 2912 }, TileMask{} }, + { UnwrappedTileID{ 13, 2056, 2913 }, TileMask{} }, + { UnwrappedTileID{ 14, 4112, 5824 }, TileMask{} }, + { UnwrappedTileID{ 14, 4112, 5827 }, TileMask{} }, + { UnwrappedTileID{ 14, 4114, 5824 }, TileMask{} }, + { UnwrappedTileID{ 14, 4114, 5825 }, TileMask{} }, }; while (state.KeepRunning()) { - algorithm::updateTileMasks<MaskedRenderable>({ renderables.begin(), renderables.end() }); + algorithm::updateTileMasks(renderables); } } diff --git a/test/algorithm/update_tile_masks.test.cpp b/test/algorithm/update_tile_masks.test.cpp index 381a6628cf..5c14ec650b 100644 --- a/test/algorithm/update_tile_masks.test.cpp +++ b/test/algorithm/update_tile_masks.test.cpp @@ -1,135 +1,116 @@ #include <mbgl/test/util.hpp> - #include <mbgl/algorithm/update_tile_masks.hpp> using namespace mbgl; namespace { -class MaskedRenderable { +class FakeTile { public: - MaskedRenderable(const UnwrappedTileID& id_, TileMask&& mask_) - : id(id_), mask(std::move(mask_)) { + FakeTile(TileMask mask_) + : mask(std::move(mask_)) { } - - UnwrappedTileID id; - TileMask mask; - bool used = true; - - void setMask(TileMask&& mask_) { + void setMask(TileMask mask_) { mask = std::move(mask_); } -}; -bool operator==(const MaskedRenderable& lhs, const MaskedRenderable& rhs) { - return lhs.id == rhs.id && lhs.mask == rhs.mask; -} + const bool usedByRenderedLayers = true; + TileMask mask; +}; -::std::ostream& operator<<(::std::ostream& os, const MaskedRenderable& rhs) { - os << "MaskedRenderable{ " << rhs.id << ", { "; - bool first = true; - for (auto& id : rhs.mask) { - if (!first) { - os << ", "; - } else { - first = false; - } - os << id; - } - return os << " } }"; +bool operator==(const FakeTile& lhs, const FakeTile& rhs) { + return lhs.mask == rhs.mask; } } // namespace -void validate(const std::vector<MaskedRenderable> expected) { - std::vector<MaskedRenderable> actual = expected; +void validate(std::map<UnwrappedTileID, FakeTile> expected) { + auto actual = expected; std::for_each(actual.begin(), actual.end(), - [](auto& renderable) { renderable.mask.clear(); }); - std::vector<std::reference_wrapper<MaskedRenderable>> sorted(actual.begin(), actual.end()); - std::sort(sorted.begin(), sorted.end(), - [](const MaskedRenderable& a, const MaskedRenderable& b){ return a.id < b.id; }); - algorithm::updateTileMasks<MaskedRenderable>(std::move(sorted)); + [](auto& renderable) { renderable.second.mask.clear(); }); + + algorithm::updateTileMasks(actual); EXPECT_EQ(expected, actual); } TEST(UpdateTileMasks, NoChildren) { validate({ - MaskedRenderable{ UnwrappedTileID{ 0, 0, 0 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, 0, 0 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } } }); validate({ - MaskedRenderable{ UnwrappedTileID{ 4, 3, 8 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 4, 3, 8 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); validate({ - MaskedRenderable{ UnwrappedTileID{ 1, 0, 0 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 1, 1, 1 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 0, 0 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 1, 1 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); validate({ - MaskedRenderable{ UnwrappedTileID{ 1, 0, 0 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 2, 2, 3 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 0, 0 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 2, 2, 3 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); } TEST(UpdateTileMasks, ParentAndFourChildren) { validate({ // Mask is empty (== not rendered!) because we have four covering children. - MaskedRenderable{ UnwrappedTileID{ 0, 0, 0 }, {} }, + { UnwrappedTileID{ 0, 0, 0 }, TileMask{} }, // All four covering children - MaskedRenderable{ UnwrappedTileID{ 1, 0, 0 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 1, 0, 1 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 1, 1, 0 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 1, 1, 1 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 0, 0 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 0, 1 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 1, 0 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 1, 1, 1 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); } TEST(UpdateTileMasks, OneChild) { validate({ - MaskedRenderable{ UnwrappedTileID{ 0, 0, 0 }, - // Only render the three children that aren't covering the other tile. - { CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, - CanonicalTileID{ 1, 1, 1 } } }, - MaskedRenderable{ UnwrappedTileID{ 1, 0, 0 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, 0, 0 }, + // Only render the three children that aren't covering the other tile. + TileMask{ CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, + CanonicalTileID{ 1, 1, 1 } } }, + { UnwrappedTileID{ 1, 0, 0 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); } TEST(UpdateTileMasks, Complex) { validate({ - MaskedRenderable{ UnwrappedTileID{ 0, 0, 0 }, - { CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, - CanonicalTileID{ 2, 2, 3 }, CanonicalTileID{ 2, 3, 2 }, - CanonicalTileID{ 3, 6, 7 }, CanonicalTileID{ 3, 7, 6 } } }, - MaskedRenderable{ UnwrappedTileID{ 0, { 1, 0, 0 } }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 0, { 2, 2, 2 } }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 0, { 3, 7, 7 } }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 0, { 3, 6, 6 } }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, 0, 0 }, + TileMask{ CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, + CanonicalTileID{ 2, 2, 3 }, CanonicalTileID{ 2, 3, 2 }, + CanonicalTileID{ 3, 6, 7 }, CanonicalTileID{ 3, 7, 6 } } }, + { UnwrappedTileID{ 0, { 1, 0, 0 } }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, { 2, 2, 2 } }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, { 3, 7, 7 } }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, { 3, 6, 6 } }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); validate({ - MaskedRenderable{ UnwrappedTileID{ 0, 0, 0 }, - { CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, - CanonicalTileID{ 1, 1, 1 }, CanonicalTileID{ 2, 0, 0 }, - CanonicalTileID{ 2, 0, 1 }, CanonicalTileID{ 2, 1, 0 }, - CanonicalTileID{ 3, 2, 3 }, CanonicalTileID{ 3, 3, 2 }, - CanonicalTileID{ 3, 3, 3 }, CanonicalTileID{ 4, 4, 5 }, - CanonicalTileID{ 4, 5, 4 }, CanonicalTileID{ 4, 5, 5 } } }, - MaskedRenderable{ UnwrappedTileID{ 4, 4, 4 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 0, 0, 0 }, + TileMask{ CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, + CanonicalTileID{ 1, 1, 1 }, CanonicalTileID{ 2, 0, 0 }, + CanonicalTileID{ 2, 0, 1 }, CanonicalTileID{ 2, 1, 0 }, + CanonicalTileID{ 3, 2, 3 }, CanonicalTileID{ 3, 3, 2 }, + CanonicalTileID{ 3, 3, 3 }, CanonicalTileID{ 4, 4, 5 }, + CanonicalTileID{ 4, 5, 4 }, CanonicalTileID{ 4, 5, 5 } } }, + { UnwrappedTileID{ 4, 4, 4 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); validate({ - MaskedRenderable{ UnwrappedTileID{ 12, 1028, 1456 }, - { CanonicalTileID{ 1, 1, 1 }, CanonicalTileID{ 2, 3, 0 }, - CanonicalTileID{ 2, 3, 1 } } }, - MaskedRenderable{ UnwrappedTileID{ 13, 2056, 2912 }, - { CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, - CanonicalTileID{ 1, 1, 1 } } }, - MaskedRenderable{ UnwrappedTileID{ 13, 2056, 2913 }, - { CanonicalTileID{ 1, 0, 0 }, CanonicalTileID{ 1, 1, 0 }, - CanonicalTileID{ 1, 1, 1 } } }, - MaskedRenderable{ UnwrappedTileID{ 14, 4112, 5824 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 14, 4112, 5827 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 14, 4114, 5824 }, { CanonicalTileID{ 0, 0, 0 } } }, - MaskedRenderable{ UnwrappedTileID{ 14, 4114, 5825 }, { CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 12, 1028, 1456 }, + TileMask{ CanonicalTileID{ 1, 1, 1 }, CanonicalTileID{ 2, 3, 0 }, + CanonicalTileID{ 2, 3, 1 } } }, + { UnwrappedTileID{ 13, 2056, 2912 }, + TileMask{ CanonicalTileID{ 1, 0, 1 }, CanonicalTileID{ 1, 1, 0 }, + CanonicalTileID{ 1, 1, 1 } } }, + { UnwrappedTileID{ 13, 2056, 2913 }, + TileMask{ CanonicalTileID{ 1, 0, 0 }, CanonicalTileID{ 1, 1, 0 }, + CanonicalTileID{ 1, 1, 1 } } }, + { UnwrappedTileID{ 14, 4112, 5824 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 14, 4112, 5827 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 14, 4114, 5824 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, + { UnwrappedTileID{ 14, 4114, 5825 }, TileMask{ CanonicalTileID{ 0, 0, 0 } } }, }); } |