From 863b4577e42737762141301864ad1d304d400eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:02:08 +0200 Subject: [PATCH 01/18] compute unique clip ids per tile, taking covering children into account fixes #206 fixes #220 refs #229 --- include/mbgl/map/source.hpp | 1 + include/mbgl/map/tile.hpp | 12 +- include/mbgl/map/tile_data.hpp | 4 + include/mbgl/util/clip_ids.hpp | 25 +- include/mbgl/util/math.hpp | 4 + src/map/map.cpp | 12 +- src/map/source.cpp | 13 +- src/renderer/painter.cpp | 6 +- src/renderer/painter_clipping.cpp | 8 +- src/util/clip_ids.cpp | 233 +++++---------- test/clip_ids.cpp | 458 +++++++++++++----------------- 11 files changed, 337 insertions(+), 439 deletions(-) diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp index 4ffd09719..a9ff29e80 100644 --- a/include/mbgl/map/source.hpp +++ b/include/mbgl/map/source.hpp @@ -36,6 +36,7 @@ public: void finishRender(Painter &painter); std::forward_list getIDs() const; + std::forward_list getLoadedTiles() const; void updateClipIDs(const std::map &mapping); static std::string normalizeSourceURL(const std::string &url, const std::string &access_token); diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp index 9cf5ff534..09462604a 100644 --- a/include/mbgl/map/tile.hpp +++ b/include/mbgl/map/tile.hpp @@ -18,11 +18,15 @@ namespace mbgl { class TileData; struct ClipID { - explicit ClipID() {} - explicit ClipID(const std::bitset<8> &mask, uint8_t length) : mask(mask), length(length) {} - explicit ClipID(const std::string &mask, uint8_t length) : mask(mask), length(length) {} + inline ClipID() {} + inline ClipID(const std::string &mask_, const std::string &reference_) : mask(mask_), reference(reference_) {} + std::bitset<8> mask; - uint8_t length = 0; + std::bitset<8> reference; + + inline bool operator==(const ClipID &other) const { + return mask == other.mask && reference == other.reference; + } }; class Tile : private util::noncopyable { diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index 5991613a2..9bc76727a 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -49,6 +49,10 @@ public: void reparse(); const std::string toString() const; + inline bool ready() const { + return state == State::parsed; + } + // Override this in the child class. virtual void beforeParse(); virtual void parse() = 0; diff --git a/include/mbgl/util/clip_ids.hpp b/include/mbgl/util/clip_ids.hpp index 748d3d8f5..52c571d59 100644 --- a/include/mbgl/util/clip_ids.hpp +++ b/include/mbgl/util/clip_ids.hpp @@ -4,15 +4,34 @@ #include #include #include +#include +#include #include namespace mbgl { -static constexpr uint8_t clipMask[9] { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF }; +class ClipIDGenerator { +private: + struct Leaf { + Leaf(Tile &tile); + void add(const Tile::ID &p); + bool operator==(const Leaf &other) const; -void updateClipIDs(const std::list &array); + Tile &tile; + std::forward_list children; + }; + + typedef std::vector Pool; + std::forward_list pools; + uint8_t bit_offset = 0; + +private: + bool reuseExisting(Leaf &leaf); + +public: + void update(std::forward_list tiles); +}; -std::map computeClipIDs(std::forward_list array); } diff --git a/include/mbgl/util/math.hpp b/include/mbgl/util/math.hpp index fde2a4720..2bef5b18e 100644 --- a/include/mbgl/util/math.hpp +++ b/include/mbgl/util/math.hpp @@ -104,6 +104,10 @@ T smoothstep(T edge0, T edge1, T x) { return t * t * (T(3) - T(2) * t); } +// Computes the log2(x) rounded up to the next integer. +// (== number of bits required to store x) +uint32_t ceil_log2(uint64_t x); + } } diff --git a/src/map/map.cpp b/src/map/map.cpp index 6aa9071a4..d6597565b 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -509,18 +509,12 @@ void Map::updateTiles() { } void Map::updateRenderState() { - std::forward_list ids; - + // Update all clipping IDs. + ClipIDGenerator generator; for (const std::shared_ptr &source : getActiveSources()) { - ids.splice_after(ids.before_begin(), source->source->getIDs()); + generator.update(source->source->getLoadedTiles()); source->source->updateMatrices(painter.projMatrix, state); } - - const std::map clipIDs = computeClipIDs(ids); - - for (const std::shared_ptr &source : getActiveSources()) { - source->source->updateClipIDs(clipIDs); - } } void Map::prepare() { diff --git a/src/map/source.cpp b/src/map/source.cpp index 523a7f3bc..ecb0be8ef 100644 --- a/src/map/source.cpp +++ b/src/map/source.cpp @@ -102,7 +102,6 @@ void Source::finishRender(Painter &painter) { } } - std::forward_list Source::getIDs() const { std::forward_list ptrs; @@ -113,6 +112,18 @@ std::forward_list Source::getIDs() const { return ptrs; } +std::forward_list Source::getLoadedTiles() const { + std::forward_list ptrs; + auto it = ptrs.before_begin(); + for (const auto &pair : tiles) { + if (pair.second->data->ready()) { + it = ptrs.insert_after(it, pair.second.get()); + } + } + return ptrs; +} + + TileData::State Source::hasTile(const Tile::ID& id) { auto it = tiles.find(id); if (it != tiles.end()) { diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index e813ad24e..240aff688 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -169,9 +169,9 @@ void Painter::setStrata(float value) { } void Painter::prepareTile(const Tile& tile) { - GLint id = (GLint)tile.clip.mask.to_ulong(); - GLuint mask = clipMask[tile.clip.length]; - glStencilFunc(GL_EQUAL, id, mask); + const GLint ref = (GLint)tile.clip.reference.to_ulong(); + const GLuint mask = (GLuint)tile.clip.mask.to_ulong(); + glStencilFunc(GL_EQUAL, ref, mask); } void Painter::renderTileLayer(const Tile& tile, std::shared_ptr layer_desc, const mat4 &matrix) { diff --git a/src/renderer/painter_clipping.cpp b/src/renderer/painter_clipping.cpp index e94646d92..d8fa3693b 100644 --- a/src/renderer/painter_clipping.cpp +++ b/src/renderer/painter_clipping.cpp @@ -14,7 +14,6 @@ void Painter::drawClippingMasks(const std::set> &so depthMask(false); glColorMask(false, false, false, false); depthRange(1.0f, 1.0f); - glStencilMask(0xFF); coveringPlainArray.bind(*plainShader, tileStencilBuffer, BUFFER_OFFSET(0)); @@ -31,9 +30,10 @@ void Painter::drawClippingMasks(const std::set> &so void Painter::drawClippingMask(const mat4& matrix, const ClipID &clip) { plainShader->setMatrix(matrix); - GLint id = static_cast(clip.mask.to_ulong()); - GLuint mask = clipMask[clip.length]; - glStencilFunc(GL_ALWAYS, id, mask); + const GLint ref = (GLint)(clip.reference.to_ulong()); + const GLuint mask = (GLuint)(clip.mask.to_ulong()); + glStencilFunc(GL_ALWAYS, ref, mask); + glStencilMask(mask); glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()); } diff --git a/src/util/clip_ids.cpp b/src/util/clip_ids.cpp index d815876a0..9e940b3d1 100644 --- a/src/util/clip_ids.cpp +++ b/src/util/clip_ids.cpp @@ -12,187 +12,102 @@ namespace mbgl { -struct TileHierarchy { - TileHierarchy(Tile::ID id, std::list &&children) - : id(id), children(std::move(children)) {} +uint32_t ceil_log2(uint64_t x) { + static const uint64_t t[6] = {0xFFFFFFFF00000000, 0x00000000FFFF0000, + 0x000000000000FF00, 0x00000000000000F0, + 0x000000000000000C, 0x0000000000000002}; + uint32_t y = (((x & (x - 1)) == 0) ? 0 : 1); + uint32_t j = 32; - const Tile::ID id; - ClipID clip; - std::list children; -}; - -std::list partition(std::forward_list &&array) { - if (array.empty()) { - // We don't have to update the clipping mask because there are no tiles - // anyway. - return {}; + for (int32_t i = 0; i < 6; i++) { + const uint32_t k = (((x & t[i]) == 0) ? 0 : j); + y += k; + x >>= k; + j >>= 1; } - int8_t minZ = array.begin()->z; - - std::list result; - std::forward_list remainder; - auto remainder_it = remainder.before_begin(); - - while (!array.empty()) { - const Tile::ID id = array.front(); - array.pop_front(); - if (id.z == minZ) { - std::forward_list children; - auto children_it = children.before_begin(); - - array.remove_if([&id, &children, &children_it](const Tile::ID &child) { - if (child.isChildOf(id)) { - children_it = children.insert_after(children_it, child); - return true; - } else { - return false; - } - }); - - result.emplace_back(id, partition(std::move(children))); - } else { - remainder_it = remainder.insert_after(remainder_it, id); - } - } - - // Concatenate the remainder. - if (!remainder.empty()) { - result.splice(result.begin(), partition(std::move(remainder))); - } - - return result; + return y; } -uint8_t prefix(std::list &array, TileHierarchy *parent = nullptr) { - if (array.empty()) { - return 0; +ClipIDGenerator::Leaf::Leaf(Tile &tile_) : tile(tile_) {} + +void ClipIDGenerator::Leaf::add(const Tile::ID &p) { + if (p.isChildOf(tile.id)) { + // Ensure that no already present child is a parent of the new p. + for (const Tile::ID &child : children) { + if (p.isChildOf(child)) + return; + } + children.push_front(p); } +} - bool all_children_are_immediate = true; - uint8_t max_child_prefix_length = 0; +bool ClipIDGenerator::Leaf::operator==(const Leaf &other) const { + return tile.id == other.tile.id && children == other.children; +} - struct Huffman { - explicit Huffman(int prefix_length, TileHierarchy *item) - : prefix_length(prefix_length), children(1, item) {} - uint8_t prefix_length; - std::vector children; - }; - - // Create a temporary structure that we use for sorting the prefix tree. - std::list huffman; - std::transform(array.begin(), array.end(), std::back_inserter(huffman), [parent, &all_children_are_immediate, &max_child_prefix_length](TileHierarchy &item) { - uint8_t prefix_length = prefix(item.children, &item); - - if (prefix_length > max_child_prefix_length) { - max_child_prefix_length = prefix_length; +bool ClipIDGenerator::reuseExisting(Leaf &leaf) { + for (const std::vector &pool : pools) { + auto existing = std::find(pool.begin(), pool.end(), leaf); + if (existing != pool.end()) { + leaf.tile.clip = existing->tile.clip; + return true; } + } + return false; +} - if (!parent || item.id.z != parent->id.z + 1) { - all_children_are_immediate = false; - } +void ClipIDGenerator::update(std::forward_list tiles) { + Pool pool; - return Huffman { prefix_length + 1, &item }; + tiles.sort([](const Tile *a, const Tile *b) { + return a->id < b->id; }); - while (huffman.size() > 1) { - huffman.sort([](const Huffman &a, const Huffman &b) { - return a.prefix_length < b.prefix_length; - }); - - Huffman &first = *huffman.begin(); - Huffman &second = *(++huffman.begin()); - - assert(&first != &second); - - // Prefix with 0 - std::for_each(first.children.begin(), first.children.end(), [](TileHierarchy *child) { - child->clip.mask >>= 1; - child->clip.mask.set(7, false); // noop - child->clip.length++; - }); - first.prefix_length++; - - // Prefix with 1 - std::for_each(second.children.begin(), second.children.end(), [](TileHierarchy *child) { - child->clip.mask >>= 1; - child->clip.mask.set(7, true); - child->clip.length++; - }); - second.prefix_length++; - - second.children.insert(second.children.end(), first.children.begin(), first.children.end()); - second.prefix_length = first.prefix_length + second.prefix_length; - - // Remove the first child as we've just merged it into the second version. - huffman.erase(huffman.begin()); - } - - uint8_t prefix_length = 0; - - // Filter out all-zero bits - bool filter_zero = !all_children_are_immediate || array.size() != 4; - - for (TileHierarchy &item : array) { - if (filter_zero && !item.clip.mask.any()) { - // Make sure we don't have a prefix that is all zeros. - // item.clip.mask |= (0x80 >> item.length); - item.clip.mask.set(7 - item.clip.length); - item.clip.length++; + const auto end = tiles.end(); + for (auto it = tiles.begin(); it != end; it++) { + if (!*it) { + // Handle null pointers. + continue; } - if (item.clip.length > prefix_length) { - prefix_length = item.clip.length; + Tile &tile = **it; + Leaf clip { tile }; + + // Try to add all remaining ids as children. We sorted the tile list + // by z earlier, so all preceding items cannot be children of the current + // tile. + for (auto child_it = std::next(it); child_it != end; child_it++) { + clip.add((*child_it)->id); + } + clip.children.sort(); + + // Loop through all existing pools and try to find a matching ClipID. + if (!reuseExisting(clip)) { + // We haven't found an existing clip ID + pool.push_back(std::move(clip)); } } - return max_child_prefix_length + prefix_length; -} + if (pool.size()) { + const uint32_t bit_count = ceil_log2(pool.size() + 1); + const std::bitset<8> mask = uint64_t(((1 << bit_count) - 1) << bit_offset); -void propagate(std::map &mapping, std::list &array, const ClipID &parent = ClipID{}) { - for (auto &item : array) { - item.clip.mask >>= parent.length; - item.clip.mask |= parent.mask; - item.clip.length += parent.length; -#if defined(DEBUG) - auto result = mapping.emplace(item.id, item.clip); - assert("Tried to insert a duplicate item" && result.second == true); -#else - mapping.emplace(item.id, item.clip); -#endif - propagate(mapping, item.children, const_cast(item.clip)); - }; -} - -void updateClipIDs(const std::list &array) { - std::forward_list ids; - std::transform(array.begin(), array.end(), std::front_inserter(ids), [](Tile *item) { - return item->id; - }); - - const std::map mapping = computeClipIDs(ids); - - std::for_each(array.begin(), array.end(), [&mapping](Tile *item) { - auto it = mapping.find(item->id); - if (it != mapping.end()) { - item->clip = it->second; - } else { - item->clip = ClipID {}; + // We are starting our count with 1 since we need at least 1 bit set to distinguish between + // areas without any tiles whatsoever and the current area. + uint8_t count = 1; + for (Leaf &leaf : pool) { + leaf.tile.clip.mask = mask; + leaf.tile.clip.reference = count++ << bit_offset; } - }); -} -std::map computeClipIDs(std::forward_list array) { - // Sort by zoom level and make sure that we don't have duplicate elements. - array.sort(); - array.unique(); + bit_offset += bit_count; + pools.push_front(std::move(pool)); + } - std::list hierarchy = partition(std::move(array)); - prefix(hierarchy); - - std::map mapping; - propagate(mapping, hierarchy); - return mapping; + if (bit_offset > 8) { + fprintf(stderr, "stencil mask overflow\n"); + } } } diff --git a/test/clip_ids.cpp b/test/clip_ids.cpp index f2e8be98b..18ef9658e 100644 --- a/test/clip_ids.cpp +++ b/test/clip_ids.cpp @@ -8,298 +8,244 @@ using namespace mbgl; -TEST(ClipIDs, ClipMasks) { - ASSERT_EQ(0, clipMask[0]); - ASSERT_EQ(0x80, clipMask[1]); - ASSERT_EQ(0xC0, clipMask[2]); - ASSERT_EQ(0xE0, clipMask[3]); - ASSERT_EQ(0xF0, clipMask[4]); - ASSERT_EQ(0xF8, clipMask[5]); - ASSERT_EQ(0xFC, clipMask[6]); - ASSERT_EQ(0xFE, clipMask[7]); - ASSERT_EQ(0xFF, clipMask[8]); +template void generate(const T &sources) { + ClipIDGenerator generator; + + for (size_t j = 0; j < sources.size(); j++) { + std::forward_list tile_ptrs; + std::transform(sources[j].begin(), sources[j].end(), std::front_inserter(tile_ptrs), [](const std::shared_ptr &tile) { return tile.get(); }); + generator.update(tile_ptrs); + } } +template void print(const T &sources) { + for (size_t j = 0; j < sources.size(); j++) { + for (size_t i = 0; i < sources[j].size(); i++) { + std::cout << " ASSERT_EQ(ClipID(\"" << sources[j][i]->clip.mask << "\", \"" << sources[j][i]->clip.reference << "\"), sources[" << j << "][" << i << "]->clip);\n"; + } + } +} TEST(ClipIDs, ParentAndFourChildren) { - std::array, 5> tiles {{ - std::make_unique(Tile::ID { 1, 0, 0 }), // 1/0/0: 11000000 (3) - std::make_unique(Tile::ID { 1, 0, 1 }), // 1/0/1: 11100000 (3) - std::make_unique(Tile::ID { 1, 1, 0 }), // 1/1/0: 10000000 (3) - std::make_unique(Tile::ID { 1, 1, 1 }), // 1/1/1: 10100000 (3) - std::make_unique(Tile::ID { 0, 0, 0 }), // 0/0/0: 10000000 (1) - }}; + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 1, 0, 0 }), + std::make_shared(Tile::ID { 1, 0, 1 }), + std::make_shared(Tile::ID { 1, 1, 0 }), + std::make_shared(Tile::ID { 1, 1, 1 }), + std::make_shared(Tile::ID { 0, 0, 0 }), + }, + }; - std::list tile_ptrs; - std::transform(tiles.begin(), tiles.end(), std::back_inserter(tile_ptrs), [](std::unique_ptr &tile) { return tile.get(); }); + generate(sources); + // print(sources); - updateClipIDs(tile_ptrs); - - // for (const auto &it : tiles) { - // std::cout << std::string(it->id) << ": " << it->clip.mask << " (" << (int)it->clip.length << ")" << std::endl; - // } - - ASSERT_EQ(std::bitset<8>("11000000"), tiles[0]->clip.mask); ASSERT_EQ(3, tiles[0]->clip.length); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[1]->clip.mask); ASSERT_EQ(3, tiles[1]->clip.length); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[2]->clip.mask); ASSERT_EQ(3, tiles[2]->clip.length); - ASSERT_EQ(std::bitset<8>("10100000"), tiles[3]->clip.mask); ASSERT_EQ(3, tiles[3]->clip.length); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[4]->clip.mask); ASSERT_EQ(1, tiles[4]->clip.length); + ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][4]->clip); } TEST(ClipIDs, ParentAndFourChildrenNegative) { - std::array, 5> tiles {{ - std::make_unique(Tile::ID { 1, -2, 0 }), // 1/0/0: 11000000 (3) - std::make_unique(Tile::ID { 1, -2, 1 }), // 1/0/1: 11100000 (3) - std::make_unique(Tile::ID { 1, -1, 0 }), // 1/1/0: 10000000 (3) - std::make_unique(Tile::ID { 1, -1, 1 }), // 1/1/1: 10100000 (3) - std::make_unique(Tile::ID { 0, -1, 0 }), // 0/0/0: 10000000 (1) - }}; + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 1, -2, 0 }), + std::make_shared(Tile::ID { 1, -2, 1 }), + std::make_shared(Tile::ID { 1, -1, 0 }), + std::make_shared(Tile::ID { 1, -1, 1 }), + std::make_shared(Tile::ID { 0, -1, 0 }), + }, + }; - std::list tile_ptrs; - std::transform(tiles.begin(), tiles.end(), std::back_inserter(tile_ptrs), [](std::unique_ptr &tile) { return tile.get(); }); + generate(sources); + // print(sources); - updateClipIDs(tile_ptrs); - - // for (const auto &it : tiles) { - // std::cout << std::string(it->id) << ": " << it->clip.mask << " (" << (int)it->clip.length << ")" << std::endl; - // } - - ASSERT_EQ(std::bitset<8>("11000000"), tiles[0]->clip.mask); ASSERT_EQ(3, tiles[0]->clip.length); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[1]->clip.mask); ASSERT_EQ(3, tiles[1]->clip.length); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[2]->clip.mask); ASSERT_EQ(3, tiles[2]->clip.length); - ASSERT_EQ(std::bitset<8>("10100000"), tiles[3]->clip.mask); ASSERT_EQ(3, tiles[3]->clip.length); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[4]->clip.mask); ASSERT_EQ(1, tiles[4]->clip.length); + ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][4]->clip); } TEST(ClipIDs, NegativeParentAndMissingLevel) { - std::array, 5> tiles {{ - std::make_unique(Tile::ID { 1, -1, 0 }), // 1/-1/0: 10000000 (1) - std::make_unique(Tile::ID { 2, -1, 0 }), // 2/-1/0: 10000000 (3) - std::make_unique(Tile::ID { 2, -2, 1 }), // 2/-2/1: 11100000 (3) - std::make_unique(Tile::ID { 2, -1, 1 }), // 2/-1/1: 10100000 (3) - std::make_unique(Tile::ID { 2, -2, 0 }), // 2/-2/0: 11000000 (3) - }}; + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 1, -1, 0 }), + std::make_shared(Tile::ID { 2, -1, 0 }), + std::make_shared(Tile::ID { 2, -2, 1 }), + std::make_shared(Tile::ID { 2, -1, 1 }), + std::make_shared(Tile::ID { 2, -2, 0 }), + }, + }; - std::list tile_ptrs; - std::transform(tiles.begin(), tiles.end(), std::back_inserter(tile_ptrs), [](std::unique_ptr &tile) { return tile.get(); }); + generate(sources); + // print(sources); - updateClipIDs(tile_ptrs); - - // for (const auto &it : tiles) { - // std::cout << std::string(it->id) << ": " << it->clip.mask << " (" << (int)it->clip.length << ")" << std::endl; - // } - - ASSERT_EQ(std::bitset<8>("10000000"), tiles[0]->clip.mask); ASSERT_EQ(1, tiles[0]->clip.length); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[1]->clip.mask); ASSERT_EQ(3, tiles[1]->clip.length); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[2]->clip.mask); ASSERT_EQ(3, tiles[2]->clip.length); - ASSERT_EQ(std::bitset<8>("10100000"), tiles[3]->clip.mask); ASSERT_EQ(3, tiles[3]->clip.length); - ASSERT_EQ(std::bitset<8>("11000000"), tiles[4]->clip.mask); ASSERT_EQ(3, tiles[4]->clip.length); + ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][4]->clip); } TEST(ClipIDs, SevenOnSameLevel) { - std::array, 7> tiles {{ - std::make_unique(Tile::ID { 2, 0, 0 }), // 2/0/0: 11000000 (3) - std::make_unique(Tile::ID { 2, 0, 1 }), // 2/0/1: 11100000 (3) - std::make_unique(Tile::ID { 2, 0, 2 }), // 2/0/2: 10000000 (3) - std::make_unique(Tile::ID { 2, 1, 0 }), // 2/1/0: 10100000 (3) - std::make_unique(Tile::ID { 2, 1, 1 }), // 2/1/1: 01000000 (3) - std::make_unique(Tile::ID { 2, 1, 2 }), // 2/1/2: 01100000 (3) - std::make_unique(Tile::ID { 2, 2, 0 }), // 2/2/0: 00100000 (3) - }}; + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 2, 0, 0 }), + std::make_shared(Tile::ID { 2, 0, 1 }), + std::make_shared(Tile::ID { 2, 0, 2 }), + std::make_shared(Tile::ID { 2, 1, 0 }), + std::make_shared(Tile::ID { 2, 1, 1 }), + std::make_shared(Tile::ID { 2, 1, 2 }), + std::make_shared(Tile::ID { 2, 2, 0 }), + }, + }; - std::list tile_ptrs; - std::transform(tiles.begin(), tiles.end(), std::back_inserter(tile_ptrs), [](std::unique_ptr &tile) { return tile.get(); }); + generate(sources); + // print(sources); - updateClipIDs(tile_ptrs); - - // for (const auto &it : tiles) { - // std::cout << std::string(it->id) << ": " << it->clip.mask << " (" << (int)it->clip.length << ")" << std::endl; - // } - - ASSERT_EQ(std::bitset<8>("11000000"), tiles[0]->clip.mask); ASSERT_EQ(3, tiles[0]->clip.length); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[1]->clip.mask); ASSERT_EQ(3, tiles[1]->clip.length); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[2]->clip.mask); ASSERT_EQ(3, tiles[2]->clip.length); - ASSERT_EQ(std::bitset<8>("10100000"), tiles[3]->clip.mask); ASSERT_EQ(3, tiles[3]->clip.length); - ASSERT_EQ(std::bitset<8>("01000000"), tiles[4]->clip.mask); ASSERT_EQ(3, tiles[4]->clip.length); - ASSERT_EQ(std::bitset<8>("01100000"), tiles[5]->clip.mask); ASSERT_EQ(3, tiles[5]->clip.length); - ASSERT_EQ(std::bitset<8>("00100000"), tiles[6]->clip.mask); ASSERT_EQ(3, tiles[6]->clip.length); + ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00000111", "00000101"), sources[0][4]->clip); + ASSERT_EQ(ClipID("00000111", "00000110"), sources[0][5]->clip); + ASSERT_EQ(ClipID("00000111", "00000111"), sources[0][6]->clip); } TEST(ClipIDs, MultipleLevels) { - std::array, 12> tiles {{ - std::make_unique(Tile::ID { 2, 0, 0 }), // 2/0/0: 10000000 (1) - std::make_unique(Tile::ID { 3, 0, 0 }), // 3/0/0: 10000000 (3) - std::make_unique(Tile::ID { 3, 0, 1 }), // 3/0/1: 11100000 (3) - std::make_unique(Tile::ID { 4, 0, 2 }), // 4/0/2: 11110000 (5) - std::make_unique(Tile::ID { 4, 1, 2 }), // 4/0/3: 11111000 (5) - std::make_unique(Tile::ID { 4, 0, 3 }), // 4/1/2: 11100000 (5) - std::make_unique(Tile::ID { 4, 1, 3 }), // 4/1/3: 11101000 (5) - std::make_unique(Tile::ID { 3, 1, 0 }), // 3/1/0: 10100000 (3) - std::make_unique(Tile::ID { 3, 1, 1 }), // 3/1/1: 11000000 (3) - std::make_unique(Tile::ID { 2, 1, 0 }), // 2/1/0: 01000000 (2) - std::make_unique(Tile::ID { 3, 2, 0 }), // 3/2/0: 01010000 (4) - std::make_unique(Tile::ID { 3, 2, 1 }), // 3/2/1: 01100000 (3) - }}; + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 2, 0, 0 }), + std::make_shared(Tile::ID { 3, 0, 0 }), + std::make_shared(Tile::ID { 3, 0, 1 }), + std::make_shared(Tile::ID { 4, 0, 2 }), + std::make_shared(Tile::ID { 4, 1, 2 }), + std::make_shared(Tile::ID { 4, 0, 3 }), + std::make_shared(Tile::ID { 4, 1, 3 }), + std::make_shared(Tile::ID { 3, 1, 0 }), + std::make_shared(Tile::ID { 3, 1, 1 }), + std::make_shared(Tile::ID { 2, 1, 0 }), + std::make_shared(Tile::ID { 3, 2, 0 }), + std::make_shared(Tile::ID { 3, 2, 1 }), + }, + }; - // Use a random order to verify that the result of this algorithm is independent of the - std::random_shuffle(tiles.begin(), tiles.end()); + generate(sources); + // print(sources); - std::list tile_ptrs; - std::transform(tiles.begin(), tiles.end(), std::back_inserter(tile_ptrs), [](std::unique_ptr &tile) { return tile.get(); }); - - updateClipIDs(tile_ptrs); - - // Sort them by tile ID so that we know what order we have to test in. - std::sort(tiles.begin(), tiles.end(), [](const std::unique_ptr &a, const std::unique_ptr &b) { - return a->id < b->id; - }); - - // for (const auto &it : tiles) { - // std::cout << std::string(it->id) << ": " << it->clip.mask << " (" << (int)it->clip.length << ")" << std::endl; - // } - - ASSERT_EQ(std::string("2/0/0"), std::string(tiles[0]->id)); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[0]->clip.mask); - ASSERT_EQ(1, tiles[0]->clip.length); - - ASSERT_EQ(std::string("2/1/0"), std::string(tiles[1]->id)); - ASSERT_EQ(std::bitset<8>("01000000"), tiles[1]->clip.mask); - ASSERT_EQ(2, tiles[1]->clip.length); - - ASSERT_EQ(std::string("3/0/0"), std::string(tiles[2]->id)); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[2]->clip.mask); - ASSERT_EQ(3, tiles[2]->clip.length); - - ASSERT_EQ(std::string("3/0/1"), std::string(tiles[3]->id)); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[3]->clip.mask); - ASSERT_EQ(3, tiles[3]->clip.length); - - ASSERT_EQ(std::string("3/1/0"), std::string(tiles[4]->id)); - ASSERT_EQ(std::bitset<8>("10100000"), tiles[4]->clip.mask); - ASSERT_EQ(3, tiles[4]->clip.length); - - ASSERT_EQ(std::string("3/1/1"), std::string(tiles[5]->id)); - ASSERT_EQ(std::bitset<8>("11000000"), tiles[5]->clip.mask); - ASSERT_EQ(3, tiles[5]->clip.length); - - ASSERT_EQ(std::string("3/2/0"), std::string(tiles[6]->id)); - ASSERT_EQ(std::bitset<8>("01010000"), tiles[6]->clip.mask); - ASSERT_EQ(4, tiles[6]->clip.length); - - ASSERT_EQ(std::string("3/2/1"), std::string(tiles[7]->id)); - ASSERT_EQ(std::bitset<8>("01100000"), tiles[7]->clip.mask); - ASSERT_EQ(3, tiles[7]->clip.length); - - ASSERT_EQ(std::string("4/0/2"), std::string(tiles[8]->id)); - ASSERT_EQ(std::bitset<8>("11110000"), tiles[8]->clip.mask); - ASSERT_EQ(5, tiles[8]->clip.length); - - ASSERT_EQ(std::string("4/0/3"), std::string(tiles[9]->id)); - ASSERT_EQ(std::bitset<8>("11111000"), tiles[9]->clip.mask); - ASSERT_EQ(5, tiles[9]->clip.length); - - ASSERT_EQ(std::string("4/1/2"), std::string(tiles[10]->id)); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[10]->clip.mask); - ASSERT_EQ(5, tiles[10]->clip.length); - - ASSERT_EQ(std::string("4/1/3"), std::string(tiles[11]->id)); - ASSERT_EQ(std::bitset<8>("11101000"), tiles[11]->clip.mask); - ASSERT_EQ(5, tiles[11]->clip.length); + ASSERT_EQ(ClipID("00001111", "00000001"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00001111", "00000011"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00001111", "00000100"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00001111", "00001001"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00001111", "00001011"), sources[0][4]->clip); + ASSERT_EQ(ClipID("00001111", "00001010"), sources[0][5]->clip); + ASSERT_EQ(ClipID("00001111", "00001100"), sources[0][6]->clip); + ASSERT_EQ(ClipID("00001111", "00000101"), sources[0][7]->clip); + ASSERT_EQ(ClipID("00001111", "00000110"), sources[0][8]->clip); + ASSERT_EQ(ClipID("00001111", "00000010"), sources[0][9]->clip); + ASSERT_EQ(ClipID("00001111", "00000111"), sources[0][10]->clip); + ASSERT_EQ(ClipID("00001111", "00001000"), sources[0][11]->clip); } TEST(ClipIDs, Bug206) { - std::array, 11> tiles {{ - std::make_unique(Tile::ID { 10, 162, 395 }), // 10/162/395: 10000000 (3) - std::make_unique(Tile::ID { 10, 162, 396 }), // 10/162/396: 10100000 (3) - std::make_unique(Tile::ID { 10, 163, 395 }), // 10/163/395: 11000000 (2) - std::make_unique(Tile::ID { 11, 326, 791 }), // 11/326/791: 11100000 (4) - std::make_unique(Tile::ID { 12, 654, 1582 }), // 12/654/1582: 11001000 (5) - std::make_unique(Tile::ID { 12, 654, 1583 }), // 12/654/1583: 11010000 (4) - std::make_unique(Tile::ID { 12, 655, 1582 }), // 12/655/1582: 11110000 (5) - std::make_unique(Tile::ID { 12, 655, 1583 }), // 12/655/1583: 11111000 (5) - std::make_unique(Tile::ID { 10, 163, 396 }), // 10/163/396: 01000000 (3) - std::make_unique(Tile::ID { 10, 164, 395 }), // 10/164/395: 01100000 (3) - std::make_unique(Tile::ID { 10, 164, 396 }), // 10/164/396: 00100000 (3) - }}; + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 10, 162, 395 }), + std::make_shared(Tile::ID { 10, 162, 396 }), + std::make_shared(Tile::ID { 10, 163, 395 }), + std::make_shared(Tile::ID { 11, 326, 791 }), + std::make_shared(Tile::ID { 12, 654, 1582 }), + std::make_shared(Tile::ID { 12, 654, 1583 }), + std::make_shared(Tile::ID { 12, 655, 1582 }), + std::make_shared(Tile::ID { 12, 655, 1583 }), + std::make_shared(Tile::ID { 10, 163, 396 }), + std::make_shared(Tile::ID { 10, 164, 395 }), + std::make_shared(Tile::ID { 10, 164, 396 }), + }, + }; - std::list tile_ptrs; - std::transform(tiles.begin(), tiles.end(), std::back_inserter(tile_ptrs), [](std::unique_ptr &tile) { return tile.get(); }); - - updateClipIDs(tile_ptrs); - - // for (const auto &it : tiles) { - // std::cout << std::string(it->id) << ": " << it->clip.mask << " (" << (int)it->clip.length << ")" << std::endl; - // } - - ASSERT_EQ(std::string("10/162/395"), std::string(tiles[0]->id)); - ASSERT_EQ(std::bitset<8>("10000000"), tiles[0]->clip.mask); - ASSERT_EQ(3, tiles[0]->clip.length); - - ASSERT_EQ(std::string("10/162/396"), std::string(tiles[1]->id)); - ASSERT_EQ(std::bitset<8>("10100000"), tiles[1]->clip.mask); - ASSERT_EQ(3, tiles[1]->clip.length); - - ASSERT_EQ(std::string("10/163/395"), std::string(tiles[2]->id)); - ASSERT_EQ(std::bitset<8>("11000000"), tiles[2]->clip.mask); - ASSERT_EQ(2, tiles[2]->clip.length); - - ASSERT_EQ(std::string("11/326/791"), std::string(tiles[3]->id)); - ASSERT_EQ(std::bitset<8>("11100000"), tiles[3]->clip.mask); - ASSERT_EQ(4, tiles[3]->clip.length); - - ASSERT_EQ(std::string("12/654/1582"), std::string(tiles[4]->id)); - ASSERT_EQ(std::bitset<8>("11001000"), tiles[4]->clip.mask); - ASSERT_EQ(5, tiles[4]->clip.length); - - ASSERT_EQ(std::string("12/654/1583"), std::string(tiles[5]->id)); - ASSERT_EQ(std::bitset<8>("11010000"), tiles[5]->clip.mask); - ASSERT_EQ(4, tiles[5]->clip.length); - - ASSERT_EQ(std::string("12/655/1582"), std::string(tiles[6]->id)); - ASSERT_EQ(std::bitset<8>("11110000"), tiles[6]->clip.mask); - ASSERT_EQ(5, tiles[6]->clip.length); - - ASSERT_EQ(std::string("12/655/1583"), std::string(tiles[7]->id)); - ASSERT_EQ(std::bitset<8>("11111000"), tiles[7]->clip.mask); - ASSERT_EQ(5, tiles[7]->clip.length); - - ASSERT_EQ(std::string("10/163/396"), std::string(tiles[8]->id)); - ASSERT_EQ(std::bitset<8>("01000000"), tiles[8]->clip.mask); - ASSERT_EQ(3, tiles[8]->clip.length); - - ASSERT_EQ(std::string("10/164/395"), std::string(tiles[9]->id)); - ASSERT_EQ(std::bitset<8>("01100000"), tiles[9]->clip.mask); - ASSERT_EQ(3, tiles[9]->clip.length); - - ASSERT_EQ(std::string("10/164/396"), std::string(tiles[10]->id)); - ASSERT_EQ(std::bitset<8>("00100000"), tiles[10]->clip.mask); - ASSERT_EQ(3, tiles[10]->clip.length); + generate(sources); + // print(sources); + ASSERT_EQ(ClipID("00001111", "00000001"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00001111", "00000010"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00001111", "00000011"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00001111", "00000111"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00001111", "00001000"), sources[0][4]->clip); + ASSERT_EQ(ClipID("00001111", "00001001"), sources[0][5]->clip); + ASSERT_EQ(ClipID("00001111", "00001010"), sources[0][6]->clip); + ASSERT_EQ(ClipID("00001111", "00001011"), sources[0][7]->clip); + ASSERT_EQ(ClipID("00001111", "00000100"), sources[0][8]->clip); + ASSERT_EQ(ClipID("00001111", "00000101"), sources[0][9]->clip); + ASSERT_EQ(ClipID("00001111", "00000110"), sources[0][10]->clip); } + +TEST(ClipIDs, MultipleSources) { + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 0, 0, 0 }), + std::make_shared(Tile::ID { 1, 1, 1 }), + std::make_shared(Tile::ID { 2, 2, 1 }), + std::make_shared(Tile::ID { 2, 2, 2 }), + }, + { + std::make_shared(Tile::ID { 0, 0, 0 }), + std::make_shared(Tile::ID { 1, 1, 1 }), + std::make_shared(Tile::ID { 2, 1, 1 }), + std::make_shared(Tile::ID { 2, 2, 2 }), + }, + { + std::make_shared(Tile::ID { 1, 0, 0 }), + std::make_shared(Tile::ID { 1, 0, 1 }), + std::make_shared(Tile::ID { 1, 1, 0 }), + std::make_shared(Tile::ID { 1, 1, 1 }), + std::make_shared(Tile::ID { 2, 1, 1 }), + }, + }; + + generate(sources); + // print(sources); + + ASSERT_EQ(ClipID("00000111", "00000001"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00000111", "00000010"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00000111", "00000011"), sources[0][2]->clip); + ASSERT_EQ(ClipID("00000111", "00000100"), sources[0][3]->clip); + ASSERT_EQ(ClipID("00011000", "00001000"), sources[1][0]->clip); + ASSERT_EQ(ClipID("00000111", "00000010"), sources[1][1]->clip); + ASSERT_EQ(ClipID("00011000", "00010000"), sources[1][2]->clip); + ASSERT_EQ(ClipID("00000111", "00000100"), sources[1][3]->clip); + ASSERT_EQ(ClipID("11100000", "00100000"), sources[2][0]->clip); + ASSERT_EQ(ClipID("11100000", "01000000"), sources[2][1]->clip); + ASSERT_EQ(ClipID("11100000", "01100000"), sources[2][2]->clip); + ASSERT_EQ(ClipID("11100000", "10000000"), sources[2][3]->clip); + ASSERT_EQ(ClipID("00011000", "00010000"), sources[2][4]->clip); +} + + TEST(ClipIDs, DuplicateIDs) { + const std::vector>> sources = { + { + std::make_shared(Tile::ID { 2, 0, 0 }), + std::make_shared(Tile::ID { 2, 0, 1 }), + }, + { + std::make_shared(Tile::ID { 2, 0, 0 }), + std::make_shared(Tile::ID { 2, 0, 1 }), + std::make_shared(Tile::ID { 2, 0, 1 }), + } + }; - std::forward_list tiles {{ - Tile::ID { 2, 0, 0 }, - Tile::ID { 2, 0, 1 }, - Tile::ID { 2, 0, 0 }, - Tile::ID { 2, 0, 1 }, - Tile::ID { 2, 0, 1 }, - }}; + generate(sources); + // print(sources); - std::map mapping = computeClipIDs(tiles); - - ASSERT_EQ(2ull, mapping.size()); - - // for (const auto &it : mapping) { - // std::cout << std::string(it.first) << "(" << it.first << ")" << ": " << it.second.mask << " (" << (int)it.second.length << ")" << std::endl; - // } - - ASSERT_EQ(std::bitset<8>("01000000"), mapping[Tile::ID(2, 0, 0)].mask); - ASSERT_EQ(2, mapping[Tile::ID(2, 0, 0)].length); - - ASSERT_EQ(std::bitset<8>("10000000"), mapping[Tile::ID(2, 0, 1)].mask); - ASSERT_EQ(1, mapping[Tile::ID(2, 0, 1)].length); + ASSERT_EQ(ClipID("00000011", "00000001"), sources[0][0]->clip); + ASSERT_EQ(ClipID("00000011", "00000010"), sources[0][1]->clip); + ASSERT_EQ(ClipID("00000011", "00000001"), sources[1][0]->clip); + ASSERT_EQ(ClipID("00000011", "00000010"), sources[1][1]->clip); + ASSERT_EQ(ClipID("00000011", "00000010"), sources[1][2]->clip); } From 9c5f9218ac0316f2ea6e7d7de6420e967949188b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:10:01 +0200 Subject: [PATCH 02/18] add missing file --- src/util/math.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/util/math.cpp diff --git a/src/util/math.cpp b/src/util/math.cpp new file mode 100644 index 000000000..a7eab2d77 --- /dev/null +++ b/src/util/math.cpp @@ -0,0 +1,25 @@ +#include + +namespace mbgl { +namespace util { + +// From http://stackoverflow.com/questions/3272424/compute-fast-log-base-2-ceiling +uint32_t ceil_log2(uint64_t x) { + static const uint64_t t[6] = {0xFFFFFFFF00000000, 0x00000000FFFF0000, + 0x000000000000FF00, 0x00000000000000F0, + 0x000000000000000C, 0x0000000000000002}; + uint32_t y = (((x & (x - 1)) == 0) ? 0 : 1); + uint32_t j = 32; + + for (int32_t i = 0; i < 6; i++) { + const uint32_t k = (((x & t[i]) == 0) ? 0 : j); + y += k; + x >>= k; + j >>= 1; + } + + return y; +} + +} +} \ No newline at end of file From 671e3910d60eefbfefea92820f91114a87ee7252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:14:00 +0200 Subject: [PATCH 03/18] don't duplicate function --- src/util/clip_ids.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/util/clip_ids.cpp b/src/util/clip_ids.cpp index 9e940b3d1..9c391c38a 100644 --- a/src/util/clip_ids.cpp +++ b/src/util/clip_ids.cpp @@ -12,23 +12,6 @@ namespace mbgl { -uint32_t ceil_log2(uint64_t x) { - static const uint64_t t[6] = {0xFFFFFFFF00000000, 0x00000000FFFF0000, - 0x000000000000FF00, 0x00000000000000F0, - 0x000000000000000C, 0x0000000000000002}; - uint32_t y = (((x & (x - 1)) == 0) ? 0 : 1); - uint32_t j = 32; - - for (int32_t i = 0; i < 6; i++) { - const uint32_t k = (((x & t[i]) == 0) ? 0 : j); - y += k; - x >>= k; - j >>= 1; - } - - return y; -} - ClipIDGenerator::Leaf::Leaf(Tile &tile_) : tile(tile_) {} void ClipIDGenerator::Leaf::add(const Tile::ID &p) { @@ -90,7 +73,7 @@ void ClipIDGenerator::update(std::forward_list tiles) { } if (pool.size()) { - const uint32_t bit_count = ceil_log2(pool.size() + 1); + const uint32_t bit_count = util::ceil_log2(pool.size() + 1); const std::bitset<8> mask = uint64_t(((1 << bit_count) - 1) << bit_offset); // We are starting our count with 1 since we need at least 1 bit set to distinguish between From bbd42fe91f238b10416f2323cfb42c422bd2597d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:34:14 +0200 Subject: [PATCH 04/18] don't trip up certain stdlib implementations --- include/mbgl/util/clip_ids.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbgl/util/clip_ids.hpp b/include/mbgl/util/clip_ids.hpp index 52c571d59..5855b16af 100644 --- a/include/mbgl/util/clip_ids.hpp +++ b/include/mbgl/util/clip_ids.hpp @@ -22,7 +22,7 @@ private: }; typedef std::vector Pool; - std::forward_list pools; + std::forward_list pools; uint8_t bit_offset = 0; private: From 2c6e34a4fe4aa2d0d1a20028e972bfd0dc051cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:39:58 +0200 Subject: [PATCH 05/18] add != operator for certain stdlib implementations --- include/mbgl/map/tile.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/mbgl/map/tile.hpp b/include/mbgl/map/tile.hpp index 09462604a..24845c81a 100644 --- a/include/mbgl/map/tile.hpp +++ b/include/mbgl/map/tile.hpp @@ -51,6 +51,10 @@ public: return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y; } + inline bool operator!=(const ID& rhs) const { + return !operator==(rhs); + } + inline bool operator<(const ID &rhs) const { if (w != rhs.w) return w < rhs.w; if (z != rhs.z) return z < rhs.z; From 1fa3a3e85ae9ca247b61cd6bede0948dec0a641a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:46:20 +0200 Subject: [PATCH 06/18] add a few fixes for gcc fixes #437 --- include/mbgl/text/collision.hpp | 3 ++- include/mbgl/text/types.hpp | 2 +- include/mbgl/util/threadpool.hpp | 1 + include/mbgl/util/utf.hpp | 6 ++---- include/mbgl/util/vec.hpp | 2 +- src/text/collision.cpp | 4 ++-- src/text/rotation_range.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/mbgl/text/collision.hpp b/include/mbgl/text/collision.hpp index 7e65e979d..8eec30f21 100644 --- a/include/mbgl/text/collision.hpp +++ b/include/mbgl/text/collision.hpp @@ -5,8 +5,9 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" +#ifdef __clang__ #pragma GCC diagnostic ignored "-Wdeprecated-register" -#ifndef __clang__ +#else #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif diff --git a/include/mbgl/text/types.hpp b/include/mbgl/text/types.hpp index e2539bff6..dbb483ea8 100644 --- a/include/mbgl/text/types.hpp +++ b/include/mbgl/text/types.hpp @@ -101,7 +101,7 @@ struct PlacementProperty { : zoom(zoom), rotationRange(rotationRange) {} inline operator bool() const { - return !isnan(zoom) && zoom != std::numeric_limits::infinity() && + return !std::isnan(zoom) && zoom != std::numeric_limits::infinity() && rotationRange[0] != rotationRange[1]; } diff --git a/include/mbgl/util/threadpool.hpp b/include/mbgl/util/threadpool.hpp index 497d4e308..ff913ec50 100644 --- a/include/mbgl/util/threadpool.hpp +++ b/include/mbgl/util/threadpool.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace mbgl { namespace util { diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index 5dfc4ad2d..fa21df74c 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -4,11 +4,9 @@ #include // g++/libstdc++ is missing c++11 codecvt support -#ifdef __linux__ -#pragma GCC diagnostic push #ifndef __clang__ +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#endif #include #pragma GCC diagnostic pop #else @@ -20,7 +18,7 @@ namespace mbgl { namespace util { -#ifdef __linux__ +#ifndef __clang__ class utf8_to_utf32 { public: diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp index 0b9bf63d5..a5fbee477 100644 --- a/include/mbgl/util/vec.hpp +++ b/include/mbgl/util/vec.hpp @@ -71,7 +71,7 @@ struct vec2 { template::has_quiet_NaN, int>::type = 0> inline operator bool() const { - return !isnan(x) && !isnan(y); + return !std::isnan(x) && !std::isnan(y); } template::has_quiet_NaN, int>::type = 0> diff --git a/src/text/collision.cpp b/src/text/collision.cpp index 89e91d684..6326bea82 100644 --- a/src/text/collision.cpp +++ b/src/text/collision.cpp @@ -166,10 +166,10 @@ float Collision::getPlacementScale(const GlyphBoxes &glyphs, float minPlacementS float s4 = (ob.br.y - nb.tl.y + padding) / (na.y - oa.y); // scale at which new box is to the bottom of old box - if (isnan(s1) || isnan(s2)) { + if (std::isnan(s1) || std::isnan(s2)) { s1 = s2 = 1; } - if (isnan(s3) || isnan(s4)) { + if (std::isnan(s3) || std::isnan(s4)) { s3 = s4 = 1; } diff --git a/src/text/rotation_range.cpp b/src/text/rotation_range.cpp index 3ebdfe91c..664ea9c70 100644 --- a/src/text/rotation_range.cpp +++ b/src/text/rotation_range.cpp @@ -95,7 +95,7 @@ rotatingRotatingCollisions(const CollisionRect &a, const CollisionRect &b, std::vector f; for (size_t i = 0; i < c.size(); i++) { // Check if they are close enough to collide - if (!isnan(c[i]) && d_sq <= e[i]) { + if (!std::isnan(c[i]) && d_sq <= e[i]) { // So far, angles have been calulated as relative to the vector // between anchors. // Convert the angles to angles from north. From 6730beec0e7d515339a82e80263b9323c665f77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:51:10 +0200 Subject: [PATCH 07/18] remove unused threadpool class --- include/mbgl/util/threadpool.hpp | 46 --------------------------- src/util/threadpool.cpp | 54 -------------------------------- 2 files changed, 100 deletions(-) delete mode 100644 include/mbgl/util/threadpool.hpp delete mode 100644 src/util/threadpool.cpp diff --git a/include/mbgl/util/threadpool.hpp b/include/mbgl/util/threadpool.hpp deleted file mode 100644 index ff913ec50..000000000 --- a/include/mbgl/util/threadpool.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef MBGL_UTIL_THREADPOOL -#define MBGL_UTIL_THREADPOOL - -#include -#include -#include -#include - -namespace mbgl { -namespace util { - -class Threadpool { -private: - class Worker { - public: - Worker(Threadpool& pool); - ~Worker(); - static void *loop(void *ptr); - - private: - Threadpool& pool; - pthread_t thread; - }; - -public: - Threadpool(int max_workers = 4); - typedef void (*Callback)(void *); - void add(Callback callback, void *data); - -private: - typedef std::pair Task; - const int max_workers; - pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_cond_t condition = PTHREAD_COND_INITIALIZER; - std::forward_list workers; - int worker_count = 0; - std::queue tasks; -}; - -extern std::unique_ptr threadpool; - -} -} - -#endif - diff --git a/src/util/threadpool.cpp b/src/util/threadpool.cpp deleted file mode 100644 index f19032ee0..000000000 --- a/src/util/threadpool.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include - -using namespace mbgl::util; - -std::unique_ptr mbgl::util::threadpool = std::make_unique(std::thread::hardware_concurrency()); - -Threadpool::Threadpool(int max_workers) - : max_workers(max_workers) { -} - -void Threadpool::add(Callback callback, void *data) { - if (worker_count < max_workers) { - worker_count++; - workers.emplace_front(*this); - } - - pthread_mutex_lock(&mutex); - tasks.push(std::make_pair(callback, data)); - pthread_mutex_unlock(&mutex); - pthread_cond_signal(&condition); -} - -Threadpool::Worker::Worker(Threadpool& pool) - : pool(pool) { - pthread_create(&thread, nullptr, loop, (void *)this); -} - -Threadpool::Worker::~Worker() { - pthread_cancel(thread); -} - - -void *Threadpool::Worker::loop(void *ptr) { - Worker *worker = static_cast(ptr); - Threadpool& pool = worker->pool; - - pthread_mutex_lock(&pool.mutex); - while (true) { - if (pool.tasks.size()) { - Threadpool::Task task = pool.tasks.front(); - pool.tasks.pop(); - pthread_mutex_unlock(&pool.mutex); - task.first(task.second); - pthread_mutex_lock(&pool.mutex); - } else { - pthread_cond_wait(&pool.condition, &pool.mutex); - } - } - - return nullptr; -} From de822826c65408fafa59de0ec1181ca9fb4a16dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 15:52:27 +0200 Subject: [PATCH 08/18] never place infinitely deep symbols --- src/renderer/symbol_bucket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index e8c0fd182..f953f0716 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -296,7 +296,7 @@ void SymbolBucket::addFeature(const std::vector &line, const Shaping } // Insert final placement into collision tree and add glyphs/icons to buffers - if (glyphScale) { + if (glyphScale && std::isfinite(glyphScale)) { if (!properties.text.ignore_placement) { collision.insert(glyphPlacement.boxes, anchor, glyphScale, glyphRange, horizontalText); @@ -304,7 +304,7 @@ void SymbolBucket::addFeature(const std::vector &line, const Shaping if (inside) addSymbols(text, glyphPlacement.shapes, glyphScale, glyphRange); } - if (iconScale) { + if (iconScale && std::isfinite(iconScale)) { if (!properties.icon.ignore_placement) { collision.insert(iconPlacement.boxes, anchor, iconScale, iconRange, horizontalIcon); } From 178d8ca62d2b6a89b1ee9bcb6f8806d4494395b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 16:03:02 +0200 Subject: [PATCH 09/18] also use boost codecvt on linux --- include/mbgl/util/utf.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index fa21df74c..503fff8b1 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -4,12 +4,13 @@ #include // g++/libstdc++ is missing c++11 codecvt support -#ifndef __clang__ +#if ! defined(__clang__) || defined(__linux__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #include #pragma GCC diagnostic pop #else +// Assume that codecvt is present on clang on non-linux systems #include #include #endif From f4929b0e6ffe671fc8e73683bf565922b18800c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 21 Aug 2014 16:22:41 +0200 Subject: [PATCH 10/18] use correct implementation --- include/mbgl/util/utf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbgl/util/utf.hpp b/include/mbgl/util/utf.hpp index 503fff8b1..bb6317912 100644 --- a/include/mbgl/util/utf.hpp +++ b/include/mbgl/util/utf.hpp @@ -19,7 +19,7 @@ namespace mbgl { namespace util { -#ifndef __clang__ +#if ! defined(__clang__) || defined(__linux__) class utf8_to_utf32 { public: From 6610a6370b9702d6dbd107716d5df3227be42e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 12:37:23 +0200 Subject: [PATCH 11/18] use platform-specific NSString for case changes on OS X/iOS refs #309 --- common/platform_default.cpp | 25 +++++++++++++++++++++++++ common/platform_nsstring.mm | 21 +++++++++++++++++++++ include/mbgl/platform/platform.hpp | 6 ++++++ ios/mapbox-gl-cocoa | 2 +- linux/mapboxgl-app.gyp | 1 + macosx/mapboxgl-app.gyp | 1 + src/renderer/symbol_bucket.cpp | 5 ++--- 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 common/platform_default.cpp create mode 100644 common/platform_nsstring.mm diff --git a/common/platform_default.cpp b/common/platform_default.cpp new file mode 100644 index 000000000..1acbfa850 --- /dev/null +++ b/common/platform_default.cpp @@ -0,0 +1,25 @@ +#include + +#include + +namespace mbgl { +namespace platform { + +std::string uppercase(const std::string& string) { + // TODO: Use a proper Unicode Special Casing-aware algorithm. + const auto &convert = std::use_facet>(std::locale()); + std::string converted = string; + convert.toupper(&converted[0], &converted[0] + converted.size()); + return converted; +} + +std::string lowercase(const std::string& string) { + // TODO: Use a proper Unicode Special Casing-aware algorithm. + const auto &convert = std::use_facet>(std::locale()); + std::string converted = string; + convert.tolower(&converted[0], &converted[0] + converted.size()); + return converted; +} + +} +} diff --git a/common/platform_nsstring.mm b/common/platform_nsstring.mm new file mode 100644 index 000000000..9119f2a8f --- /dev/null +++ b/common/platform_nsstring.mm @@ -0,0 +1,21 @@ +#import + +#include + +namespace mbgl { +namespace platform { + +std::string uppercase(const std::string &string) { + NSString *nsstring = [[NSString alloc] initWithBytesNoCopy:const_cast(string.data()) length:string.size() encoding:NSUTF8StringEncoding freeWhenDone:NO]; + nsstring = [nsstring uppercaseString]; + return { [nsstring cStringUsingEncoding:NSUTF8StringEncoding], [nsstring lengthOfBytesUsingEncoding:NSUTF8StringEncoding] }; +} + +std::string lowercase(const std::string &string) { + NSString *nsstring = [[NSString alloc] initWithBytesNoCopy:const_cast(string.data()) length:string.size() encoding:NSUTF8StringEncoding freeWhenDone:NO]; + nsstring = [nsstring lowercaseString]; + return { [nsstring cStringUsingEncoding:NSUTF8StringEncoding], [nsstring lengthOfBytesUsingEncoding:NSUTF8StringEncoding] }; +} + +} +} \ No newline at end of file diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp index 43c6ce4f5..22405a4cf 100644 --- a/include/mbgl/platform/platform.hpp +++ b/include/mbgl/platform/platform.hpp @@ -28,6 +28,12 @@ std::shared_ptr request_http(const std::string &url, std::function callback, std::shared_ptr loop = nullptr); +// Uppercase a string, potentially using platform-specific routines. +std::string uppercase(const std::string &string); + +// Lowercase a string, potentially using platform-specific routines. +std::string lowercase(const std::string &string); + // Cancels an HTTP request. void cancel_request_http(const std::shared_ptr &req); diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index e1c709a8d..9631c7d6d 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit e1c709a8de0b69aa6bfbcd9ea4faf981b6e799b2 +Subproject commit 9631c7d6d9cf2a52a43820f6f54df90627b48759 diff --git a/linux/mapboxgl-app.gyp b/linux/mapboxgl-app.gyp index 7b703ed75..e19768caf 100644 --- a/linux/mapboxgl-app.gyp +++ b/linux/mapboxgl-app.gyp @@ -12,6 +12,7 @@ './main.cpp', '../common/settings_json.cpp', '../common/settings_json.hpp', + '../common/platform_default.cpp', '../common/glfw_view.hpp', '../common/glfw_view.cpp', '../common/curl_request.cpp', diff --git a/macosx/mapboxgl-app.gyp b/macosx/mapboxgl-app.gyp index 480dc2a11..da5c68ea3 100644 --- a/macosx/mapboxgl-app.gyp +++ b/macosx/mapboxgl-app.gyp @@ -12,6 +12,7 @@ './main.mm', '../common/settings_nsuserdefaults.hpp', '../common/settings_nsuserdefaults.mm', + '../common/platform_nsstring.mm', '../common/glfw_view.hpp', '../common/glfw_view.cpp', '../common/foundation_request.h', diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index e8c0fd182..fa12538e4 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -75,11 +75,10 @@ std::vector SymbolBucket::processFeatures(const VectorTileLayer & if (text) { std::string u8string = util::replaceTokens(properties.text.field, feature.properties); - auto &convert = std::use_facet>(std::locale()); if (properties.text.transform == TextTransformType::Uppercase) { - convert.toupper(&u8string[0], &u8string[0] + u8string.size()); + u8string = platform::uppercase(u8string); } else if (properties.text.transform == TextTransformType::Lowercase) { - convert.tolower(&u8string[0], &u8string[0] + u8string.size()); + u8string = platform::lowercase(u8string); } ft.label = ucs4conv.convert(u8string); From b68a2a4f7631c2b4556421b3d55d46bfe7b553f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 14:54:09 +0200 Subject: [PATCH 12/18] add uppercase/lowercase symbols to headless test --- test/test.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test.gyp b/test/test.gyp index 07709ecc8..fd7725bb0 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -201,6 +201,7 @@ "./headless.cpp", "../common/headless_view.hpp", "../common/headless_view.cpp", + "../common/platform_default.cpp", "./fixtures/fixture_request.cpp", "./fixtures/fixture_log.hpp", "./fixtures/fixture_log.cpp", From 4b7f861a6477b5f53c18e1eb1d72079b260b8841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 15:17:43 +0200 Subject: [PATCH 13/18] use submodule version for ios build --- ios/mapbox-gl-cocoa | 2 +- scripts/travis_script.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 9631c7d6d..cf1f1da00 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 9631c7d6d9cf2a52a43820f6f54df90627b48759 +Subproject commit cf1f1da000a8a5f2867d70b3828bd5b692445d89 diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index 4f02c5b7e..aaa8b54c0 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -20,7 +20,8 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # build iOS # - git clone --depth 1 https://github.com/mapbox/mapbox-gl-cocoa ios/mapbox-gl-cocoa + git submodule init + git submodule update make iproj-cli xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO fi From f566b6595b009c1b0896d2e5a55324c4ab4e3b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 22 Aug 2014 15:17:53 +0200 Subject: [PATCH 14/18] increase build concurrency --- scripts/travis_script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index aaa8b54c0..6aaabfed6 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -16,12 +16,12 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # build OS X # make xproj-cli - xcodebuild -project ./build/macosx/mapboxgl-app.xcodeproj + xcodebuild -project ./build/macosx/mapboxgl-app.xcodeproj -jobs 4 # # build iOS # git submodule init git submodule update make iproj-cli - xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO + xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -jobs 4 fi From 8f6a480344d9a6b56f6ea61626c7f182b9257ec5 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Aug 2014 15:43:41 -0700 Subject: [PATCH 15/18] Don't try to upload build artifacts for PRs --- scripts/travis_script.sh | 3 ++- setup-libraries.sh | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index 4f02c5b7e..a13d7531e 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -10,7 +10,8 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then make linux -j4 BUILDTYPE=${BUILDTYPE} make test -j4 BUILDTYPE=${BUILDTYPE} ./scripts/run_tests.sh - (cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true; ./bin/deploy_results.sh)) + (cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true; [[ $TRAVIS_PULL_REQUEST = "false" ]] && ./bin/deploy_results.sh)) + elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # build OS X diff --git a/setup-libraries.sh b/setup-libraries.sh index 9c83595a3..bccef226e 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -112,7 +112,7 @@ source MacOSX.sh ./scripts/make_universal.sh -if [ ! -z "${TRAVIS:-}" ]; then +if [[ $TRAVIS_PULL_REQUEST = "false" ]]; then tar -zcf out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz out/build-cpp11-libcpp-universal aws s3 cp out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz s3://mapbox-gl-testing/dependencies/ fi @@ -143,7 +143,7 @@ source Linux.sh if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libcurl.a ] ; then ./scripts/build_curl.sh ; fi if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libboost_regex.a ] ; then ./scripts/build_boost.sh --with-regex ; fi -if [ ! -z "${TRAVIS:-}" ]; then +if [[ $TRAVIS_PULL_REQUEST = "false" ]]; then if ! tar --compare -zf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ; then tar -zcf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz out/build-cpp11-libstdcpp-gcc-x86_64-linux aws s3 cp out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz s3://mapbox-gl-testing/dependencies/ From fe5f121bc4f04a36e5c1e30bca21bc946065e217 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Aug 2014 15:46:54 -0700 Subject: [PATCH 16/18] Set public-read ACL --- setup-libraries.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index bccef226e..93107817f 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -114,7 +114,7 @@ source MacOSX.sh if [[ $TRAVIS_PULL_REQUEST = "false" ]]; then tar -zcf out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz out/build-cpp11-libcpp-universal - aws s3 cp out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz s3://mapbox-gl-testing/dependencies/ + aws s3 cp --acl public-read out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz s3://mapbox-gl-testing/dependencies/ fi fi @@ -146,7 +146,7 @@ source Linux.sh if [[ $TRAVIS_PULL_REQUEST = "false" ]]; then if ! tar --compare -zf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ; then tar -zcf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz out/build-cpp11-libstdcpp-gcc-x86_64-linux - aws s3 cp out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz s3://mapbox-gl-testing/dependencies/ + aws s3 cp --acl public-read out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz s3://mapbox-gl-testing/dependencies/ fi fi From d531e3546b406addb90e9b87e2b7bf63371a4c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 26 Aug 2014 18:31:17 +0200 Subject: [PATCH 17/18] add hash of current directory since dependency builds are working dir-specific --- ios/mapbox-gl-cocoa | 2 +- setup-libraries.sh | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index cf1f1da00..e1c709a8d 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit cf1f1da000a8a5f2867d70b3828bd5b692445d89 +Subproject commit e1c709a8de0b69aa6bfbcd9ea4faf981b6e799b2 diff --git a/setup-libraries.sh b/setup-libraries.sh index 93107817f..0902d10de 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,8 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="6d7e83e8042" +MP_HASH="e741a075d28812e5d16b581e1540248fe19c52ce" +DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git fi @@ -66,9 +67,9 @@ export CXX11=true if [ ${UNAME} = 'Darwin' ]; then if [ ! -z "${TRAVIS:-}" ]; then - if aws s3 cp s3://mapbox-gl-testing/dependencies/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz ./out/ ; then + if aws s3 cp s3://mapbox-gl-testing/dependencies/build-cpp11-libcpp-universal_${MP_HASH}_${DIR_HASH}.tar.gz ./out/ ; then rm -rf out/build-cpp11-libcpp-universal - tar -xzf out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz + tar -xzf out/build-cpp11-libcpp-universal_${MP_HASH}_${DIR_HASH}.tar.gz fi fi @@ -113,8 +114,8 @@ source MacOSX.sh ./scripts/make_universal.sh if [[ $TRAVIS_PULL_REQUEST = "false" ]]; then - tar -zcf out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz out/build-cpp11-libcpp-universal - aws s3 cp --acl public-read out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz s3://mapbox-gl-testing/dependencies/ + tar -zcf out/build-cpp11-libcpp-universal_${MP_HASH}_${DIR_HASH}.tar.gz out/build-cpp11-libcpp-universal + aws s3 cp --acl public-read out/build-cpp11-libcpp-universal_${MP_HASH}_${DIR_HASH}.tar.gz s3://mapbox-gl-testing/dependencies/ fi fi From 60f7813544e4e49ef2cabcab493ea2903d888f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 26 Aug 2014 18:31:40 +0200 Subject: [PATCH 18/18] mapnik-packaging's output directories changed --- setup-libraries.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 0902d10de..5b7bf117e 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -81,13 +81,13 @@ source iPhoneOS.sh echo ' ...done' source iPhoneOSs.sh - if [ ! -f out/build-cpp11-libcpp-armv7s-iphoneos/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi - if [ ! -f out/build-cpp11-libcpp-armv7s-iphoneos/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi + if [ ! -f out/build-cpp11-libcpp-armv7s-iphoneoss/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi + if [ ! -f out/build-cpp11-libcpp-armv7s-iphoneoss/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' source iPhoneOS64.sh - if [ ! -f out/build-cpp11-libcpp-arm64-iphoneos/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi - if [ ! -f out/build-cpp11-libcpp-arm64-iphoneos/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi + if [ ! -f out/build-cpp11-libcpp-arm64-iphoneos64/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi + if [ ! -f out/build-cpp11-libcpp-arm64-iphoneos64/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' source iPhoneSimulator.sh