diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-12-04 18:29:42 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-12-04 20:02:50 +0100 |
commit | abafb52f37beb5659efc2105ccd1568e1f754898 (patch) | |
tree | 6a60636d3497560ca61e5aae5f6d7061c4f18553 /include/mbgl | |
parent | bff6aeb4da41dee1f5f1cfa0be81b6c257257253 (diff) | |
download | qtlocation-mapboxgl-abafb52f37beb5659efc2105ccd1568e1f754898.tar.gz |
make most headers private
Diffstat (limited to 'include/mbgl')
106 files changed, 17 insertions, 5860 deletions
diff --git a/include/mbgl/geometry/anchor.hpp b/include/mbgl/geometry/anchor.hpp deleted file mode 100644 index d30394f0b9..0000000000 --- a/include/mbgl/geometry/anchor.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_GEOMETRY_ANCHOR -#define MBGL_GEOMETRY_ANCHOR - -#include <vector> - -namespace mbgl { - -struct Anchor { - float x = 0.0f; - float y = 0.0f; - float angle = 0.0f; - float scale = 0.0f; - int segment = -1; - - explicit Anchor(float x_, float y_, float angle_, float scale_) - : x(x_), y(y_), angle(angle_), scale(scale_) {} - explicit Anchor(float x_, float y_, float angle_, float scale_, int segment_) - : x(x_), y(y_), angle(angle_), scale(scale_), segment(segment_) {} -}; - -typedef std::vector<Anchor> Anchors; - -} - -#endif
\ No newline at end of file diff --git a/include/mbgl/geometry/binpack.hpp b/include/mbgl/geometry/binpack.hpp deleted file mode 100644 index 9aadaa202c..0000000000 --- a/include/mbgl/geometry/binpack.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef MBGL_GEOMETRY_BINPACK -#define MBGL_GEOMETRY_BINPACK - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/rect.hpp> -#include <cstdint> -#include <list> - -namespace mbgl { - -template <typename T> -class BinPack : private util::noncopyable { -public: - BinPack(T width, T height) - : free(1, Rect<uint16_t>{ 0, 0, width, height }) {} -public: - Rect<T> allocate(T width, T height) { - // Find the smallest free rect angle - auto smallest = free.end(); - for (auto it = free.begin(); it != free.end(); ++it) { - const Rect<T>& ref = *it; - const Rect<T>& rect = *smallest; - if (width <= ref.w && height <= ref.h) { - if (smallest == free.end() || (ref.y <= rect.y && ref.x <= rect.x)) { - smallest = it; - } - } - } - - if (smallest == free.end()) { - // There's no space left for this char. - return Rect<uint16_t>{ 0, 0, 0, 0 }; - } else { - Rect<T> rect = *smallest; - free.erase(smallest); - - // Shorter/Longer Axis Split Rule (SAS) - // http://clb.demon.fi/files/RectangleBinPack.pdf p. 15 - // Ignore the dimension of R and just split long the shorter dimension - // See Also: http://www.cs.princeton.edu/~chazelle/pubs/blbinpacking.pdf - if (rect.w < rect.h) { - // split horizontally - // +--+---+ - // |__|___| <-- b1 - // +------+ <-- b2 - if (rect.w > width) free.emplace_back(rect.x + width, rect.y, rect.w - width, height); - if (rect.h > height) free.emplace_back(rect.x, rect.y + height, rect.w, rect.h - height); - } else { - // split vertically - // +--+---+ - // |__| | <-- b1 - // +--|---+ <-- b2 - if (rect.w > width) free.emplace_back(rect.x + width, rect.y, rect.w - width, rect.h); - if (rect.h > height) free.emplace_back(rect.x, rect.y + height, width, rect.h - height); - } - - return Rect<uint16_t>{ rect.x, rect.y, width, height }; - } - } - - - void release(Rect<T> rect) { - // Simple algorithm to recursively merge the newly released cell with its - // neighbor. This doesn't merge more than two cells at a time, and fails - // for complicated merges. - for (auto it = free.begin(); it != free.end(); ++it) { - Rect<T> ref = *it; - if (ref.y == rect.y && ref.h == rect.h && ref.x + ref.w == rect.x) { - ref.w += rect.w; - } - else if (ref.x == rect.x && ref.w == rect.w && ref.y + ref.h == rect.y) { - ref.h += rect.h; - } - else if (rect.y == ref.y && rect.h == ref.h && rect.x + rect.w == ref.x) { - ref.x = rect.x; - ref.w += rect.w; - } - else if (rect.x == ref.x && rect.w == ref.w && rect.y + rect.h == ref.y) { - ref.y = rect.y; - ref.h += rect.h; - } else { - continue; - } - - free.erase(it); - release(ref); - return; - - } - - free.emplace_back(rect); - }; - -private: - std::list<Rect<T>> free; -}; - -} - -#endif diff --git a/include/mbgl/geometry/buffer.hpp b/include/mbgl/geometry/buffer.hpp deleted file mode 100644 index 80cc6b9d1a..0000000000 --- a/include/mbgl/geometry/buffer.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef MBGL_GEOMETRY_BUFFER -#define MBGL_GEOMETRY_BUFFER - -#include <mbgl/platform/gl.hpp> -#include <mbgl/util/noncopyable.hpp> - -#include <cstdlib> -#include <cassert> -#include <stdexcept> - -namespace mbgl { - -template < - size_t item_size, - int bufferType = GL_ARRAY_BUFFER, - size_t defaultLength = 8192, - bool retainAfterUpload = false -> -class Buffer : private util::noncopyable { -public: - ~Buffer() { - cleanup(); - if (buffer != 0) { - glDeleteBuffers(1, &buffer); - buffer = 0; - } - } - - // Returns the number of elements in this buffer. This is not the number of - // bytes, but rather the number of coordinates with associated information. - inline size_t index() const { - return pos / itemSize; - } - - inline bool empty() const { - return pos == 0; - } - - // Transfers this buffer to the GPU and binds the buffer to the GL context. - void bind(bool force = false) { - if (buffer == 0) { - glGenBuffers(1, &buffer); - force = true; - } - glBindBuffer(bufferType, buffer); - if (force) { - if (array == nullptr) { - throw std::runtime_error("Buffer was already deleted or doesn't contain elements"); - } - - glBufferData(bufferType, pos, array, GL_STATIC_DRAW); - if (!retainAfterUpload) { - cleanup(); - } - } - } - - void cleanup() { - if (array) { - free(array); - array = nullptr; - } - } - - inline GLuint getID() const { - return buffer; - } - -protected: - // increase the buffer size by at least /required/ bytes. - inline void *addElement() { - if (buffer != 0) { - throw std::runtime_error("Can't add elements after buffer was bound to GPU"); - } - if (length < pos + itemSize) { - while (length < pos + itemSize) length += defaultLength; - array = realloc(array, length); - if (array == nullptr) { - throw std::runtime_error("Buffer reallocation failed"); - } - } - pos += itemSize; - return static_cast<char *>(array) + (pos - itemSize); - } - - // Get a pointer to the item at a given index. - inline void *getElement(size_t i) { - if (array == nullptr) { - throw std::runtime_error("Buffer was already deleted or doesn't contain elements"); - } - - if (i * itemSize >= pos) { - throw new std::runtime_error("Can't get element after array bounds"); - } else { - return static_cast<char *>(array) + (i * itemSize); - } - } - -public: - static const size_t itemSize = item_size; - -private: - // CPU buffer - void *array = nullptr; - - // Byte position where we are writing. - size_t pos = 0; - - // Number of bytes that are valid in this buffer. - size_t length = 0; - - // GL buffer ID - GLuint buffer = 0; -}; - -} - -#endif diff --git a/include/mbgl/geometry/debug_font_buffer.hpp b/include/mbgl/geometry/debug_font_buffer.hpp deleted file mode 100644 index 7cceb0f576..0000000000 --- a/include/mbgl/geometry/debug_font_buffer.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef MBGL_GEOMETRY_DEBUG_FONT_BUFFER -#define MBGL_GEOMETRY_DEBUG_FONT_BUFFER - -#include "buffer.hpp" - -namespace mbgl { - -class DebugFontBuffer : public Buffer< - 4 // 2 bytes per coordinate, 2 coordinates -> { -public: - void addText(const char *text, double left, double baseline, double scale = 1); -}; - -} - -#endif diff --git a/include/mbgl/geometry/elements_buffer.hpp b/include/mbgl/geometry/elements_buffer.hpp deleted file mode 100644 index 045560f9aa..0000000000 --- a/include/mbgl/geometry/elements_buffer.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef MBGL_GEOMETRY_TRIANGLE_ELEMENTS_BUFFER -#define MBGL_GEOMETRY_TRIANGLE_ELEMENTS_BUFFER - -#include <mbgl/geometry/buffer.hpp> -#include <mbgl/geometry/vao.hpp> -#include <mbgl/util/noncopyable.hpp> - -#include <array> - -namespace mbgl { - -template <int count> -struct ElementGroup : public util::noncopyable { - std::array<VertexArrayObject, count> array; - uint32_t vertex_length; - uint32_t elements_length; - - ElementGroup() : vertex_length(0), elements_length(0) {} - ElementGroup(uint32_t vertex_length_, uint32_t elements_length_) - : vertex_length(vertex_length_), - elements_length(elements_length_) { - } - - ElementGroup(ElementGroup &&rhs) noexcept - : array(std::move(rhs.array)), - vertex_length(rhs.vertex_length), - elements_length(rhs.elements_length) {}; -}; - -class TriangleElementsBuffer : public Buffer< - 6, // bytes per triangle (3 * unsigned short == 6 bytes) - GL_ELEMENT_ARRAY_BUFFER -> { -public: - typedef uint16_t element_type; - - void add(element_type a, element_type b, element_type c); -}; - - -class LineElementsBuffer : public Buffer< - 4, // bytes per triangle (2 * unsigned short == 6 bytes) - GL_ELEMENT_ARRAY_BUFFER -> { -public: - typedef uint16_t element_type; - - void add(element_type a, element_type b); -}; - -class PointElementsBuffer : public Buffer< - 2, // bytes per point (1 unsigned short) - GL_ELEMENT_ARRAY_BUFFER -> { -public: - typedef uint16_t element_type; - - void add(element_type a); -}; - -} - -#endif diff --git a/include/mbgl/geometry/fill_buffer.hpp b/include/mbgl/geometry/fill_buffer.hpp deleted file mode 100644 index 4a3d5a5b38..0000000000 --- a/include/mbgl/geometry/fill_buffer.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MBGL_GEOMETRY_FILL_BUFFER -#define MBGL_GEOMETRY_FILL_BUFFER - -#include "buffer.hpp" -#include <vector> -#include <cstdint> - -namespace mbgl { - -class FillVertexBuffer : public Buffer< - 4 // bytes per coordinates (2 * unsigned short == 4 bytes) -> { -public: - typedef int16_t vertex_type; - - void add(vertex_type x, vertex_type y); -}; - -} - -#endif diff --git a/include/mbgl/geometry/geometry.hpp b/include/mbgl/geometry/geometry.hpp deleted file mode 100644 index 484d17b36d..0000000000 --- a/include/mbgl/geometry/geometry.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef MBGL_GEOMETRY_GEOMETRY -#define MBGL_GEOMETRY_GEOMETRY - -#include <mbgl/util/pbf.hpp> -#include <mbgl/util/noncopyable.hpp> - -#include <cstdlib> - -namespace mbgl { - -class Geometry : private util::noncopyable { - -public: - inline explicit Geometry(pbf& data); - - enum command : uint8_t { - end = 0, - move_to = 1, - line_to = 2, - close = 7 - }; - - inline command next(int32_t &rx, int32_t &ry); - -private: - pbf& data; - uint8_t cmd; - uint32_t length; - int32_t x, y; - int32_t ox, oy; -}; - -Geometry::Geometry(pbf& data_) - : data(data_), - cmd(1), - length(0), - x(0), y(0), - ox(0), oy(0) {} - -Geometry::command Geometry::next(int32_t &rx, int32_t &ry) { - if (data.data < data.end) { - if (length == 0) { - uint32_t cmd_length = static_cast<uint32_t>(data.varint()); - cmd = cmd_length & 0x7; - length = cmd_length >> 3; - } - - --length; - - if (cmd == move_to || cmd == line_to) { - rx = (x += data.svarint()); - ry = (y += data.svarint()); - - if (cmd == move_to) { - ox = x; - oy = y; - return move_to; - } else { - return line_to; - } - } else if (cmd == close) { - rx = ox; - ry = oy; - return close; - } else { - fprintf(stderr, "unknown command: %d\n", cmd); - // TODO: gracefully handle geometry parse failures - return end; - } - } else { - return end; - } -} - -} - -#endif diff --git a/include/mbgl/geometry/glyph_atlas.hpp b/include/mbgl/geometry/glyph_atlas.hpp deleted file mode 100644 index 7b3c223fe5..0000000000 --- a/include/mbgl/geometry/glyph_atlas.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef MBGL_GEOMETRY_GLYPH_ATLAS -#define MBGL_GEOMETRY_GLYPH_ATLAS - -#include <mbgl/geometry/binpack.hpp> -#include <mbgl/text/glyph_store.hpp> -#include <mbgl/util/noncopyable.hpp> - -#include <string> -#include <set> -#include <map> -#include <mutex> -#include <atomic> - -namespace mbgl { - -class GlyphAtlas : public util::noncopyable { -public: - -private: - struct GlyphValue { - GlyphValue(const Rect<uint16_t>& rect_, uint64_t id) - : rect(rect_), ids({ id }) {} - Rect<uint16_t> rect; - std::set<uint64_t> ids; - }; - - Rect<uint16_t> addGlyph_impl(uint64_t tile_id, const std::string& face_name, - const SDFGlyph& glyph); -public: - GlyphAtlas(uint16_t width, uint16_t height); - - Rect<uint16_t> addGlyph(uint64_t tile_id, const std::string& face_name, - const SDFGlyph& glyph); - void addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname, - FontStack const& fontStack, GlyphPositions & face); - void removeGlyphs(uint64_t tile_id); - void bind(); - -public: - const uint16_t width = 0; - const uint16_t height = 0; - -private: - std::mutex mtx; - BinPack<uint16_t> bin; - std::map<std::string, std::map<uint32_t, GlyphValue>> index; - std::unique_ptr<char[]> data; - std::atomic<bool> dirty; - uint32_t texture = 0; -}; - -}; - -#endif diff --git a/include/mbgl/geometry/icon_buffer.hpp b/include/mbgl/geometry/icon_buffer.hpp deleted file mode 100644 index e7e5f40355..0000000000 --- a/include/mbgl/geometry/icon_buffer.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MBGL_GEOMETRY_ICON_BUFFER -#define MBGL_GEOMETRY_ICON_BUFFER - -#include "buffer.hpp" - -#include <array> - -namespace mbgl { - - class IconVertexBuffer : public Buffer< - 20 - > { - public: - static const double angleFactor; - - size_t add(int16_t x, int16_t y, float ox, float oy, int16_t tx, int16_t ty, float angle, float minzoom, std::array<float, 2> range, float maxzoom, float labelminzoom); - - }; - -} - -#endif diff --git a/include/mbgl/geometry/line_buffer.hpp b/include/mbgl/geometry/line_buffer.hpp deleted file mode 100644 index 5012bb12ac..0000000000 --- a/include/mbgl/geometry/line_buffer.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MBGL_GEOMETRY_LINE_BUFFER -#define MBGL_GEOMETRY_LINE_BUFFER - -#include "buffer.hpp" - -namespace mbgl { - -class LineVertexBuffer : public Buffer< - 8 // 2 coordinates per vertex + 1 linesofar + 1 extrude coord pair == 4 (== 8 bytes) -> { -public: - typedef int16_t vertex_type; - - /* - * Scale the extrusion vector so that the normal length is this value. - * Contains the "texture" normals (-1..1). This is distinct from the extrude - * normals for line joins, because the x-value remains 0 for the texture - * normal array, while the extrude normal actually moves the vertex to create - * the acute/bevelled line join. - */ - static const int8_t extrudeScale = 63; - - /* - * Add a vertex to this buffer - * - * @param {number} x vertex position - * @param {number} y vertex position - * @param {number} ex extrude normal - * @param {number} ey extrude normal - * @param {number} tx texture normal - * @param {number} ty texture normal - */ - size_t add(vertex_type x, vertex_type y, float ex, float ey, int8_t tx, int8_t ty, int32_t linesofar = 0); -}; - - -} - -#endif diff --git a/include/mbgl/geometry/resample.hpp b/include/mbgl/geometry/resample.hpp deleted file mode 100644 index bcfe4ca53d..0000000000 --- a/include/mbgl/geometry/resample.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef MBGL_GEOMETRY_INTERPOLATE -#define MBGL_GEOMETRY_INTERPOLATE - -#include <mbgl/geometry/anchor.hpp> -#include <mbgl/util/math.hpp> - -namespace mbgl { - -Anchors resample(const std::vector<Coordinate> &vertices, float spacing, - float minScale, float maxScale, float tilePixelRatio, int start = 0); -} - -#endif diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp deleted file mode 100644 index 9fb42a30b5..0000000000 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef MBGL_GEOMETRY_SPRITE_ATLAS -#define MBGL_GEOMETRY_SPRITE_ATLAS - -#include <mbgl/geometry/binpack.hpp> -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/ptr.hpp> - -#include <string> -#include <map> -#include <mutex> -#include <atomic> -#include <set> -#include <array> - -namespace mbgl { - -class Sprite; -class SpritePosition; - -struct SpriteAtlasPosition { - std::array<float, 2> size; - std::array<float, 2> tl; - std::array<float, 2> br; -}; - -class SpriteAtlas : public util::noncopyable { -public: - typedef uint16_t dimension; - - // Add way to construct this from another SpriteAtlas (e.g. with another pixelRatio) - SpriteAtlas(dimension width, dimension height); - ~SpriteAtlas(); - - // Changes the pixel ratio. - bool resize(float newRatio); - - // Changes the source sprite. - void setSprite(util::ptr<Sprite> sprite); - - // Returns the coordinates of an image that is sourced from the sprite image. - // This getter attempts to read the image from the sprite if it is already loaded. - // In that case, it copies it into the sprite atlas and returns the dimensions. - // Otherwise, it returns a 0/0/0/0 rect. - Rect<dimension> getImage(const std::string& name); - - SpriteAtlasPosition getPosition(const std::string& name, bool repeating = false); - - // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out - // of date. - void bind(bool linear = false); - - inline float getWidth() const { return width; } - inline float getHeight() const { return height; } - inline float getTextureWidth() const { return width * pixelRatio; } - inline float getTextureHeight() const { return height * pixelRatio; } - inline float getPixelRatio() const { return pixelRatio; } - - const dimension width = 0; - const dimension height = 0; - -private: - void allocate(); - Rect<SpriteAtlas::dimension> allocateImage(size_t width, size_t height); - void copy(const Rect<dimension>& dst, const SpritePosition& src); - - std::recursive_mutex mtx; - float pixelRatio = 1.0f; - BinPack<dimension> bin; - util::ptr<Sprite> sprite; - std::map<std::string, Rect<dimension>> images; - std::set<std::string> uninitialized; - uint32_t *data = nullptr; - std::atomic<bool> dirty; - uint32_t texture = 0; - uint32_t filter = 0; - static const int buffer = 1; -}; - -}; - -#endif diff --git a/include/mbgl/geometry/static_vertex_buffer.hpp b/include/mbgl/geometry/static_vertex_buffer.hpp deleted file mode 100644 index ce932269f0..0000000000 --- a/include/mbgl/geometry/static_vertex_buffer.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MBGL_GEOMETRY_STATIC_VERTEX_BUFFER -#define MBGL_GEOMETRY_STATIC_VERTEX_BUFFER - -#include <mbgl/geometry/buffer.hpp> - -#include <vector> -#include <cstddef> -#include <cstdint> -#include <cmath> - -namespace mbgl { - -class StaticVertexBuffer : public Buffer< - 4, // bytes per vertex (2 * signed short == 4 bytes) - GL_ARRAY_BUFFER, - 32 // default length -> { -public: - typedef int16_t vertex_type; - - StaticVertexBuffer(std::initializer_list<std::pair<int16_t, int16_t>> init); -}; - -} - -#endif diff --git a/include/mbgl/geometry/text_buffer.hpp b/include/mbgl/geometry/text_buffer.hpp deleted file mode 100644 index 159f3207a8..0000000000 --- a/include/mbgl/geometry/text_buffer.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_GEOMETRY_TEXT_BUFFER -#define MBGL_GEOMETRY_TEXT_BUFFER - -#include "buffer.hpp" -#include <array> - -namespace mbgl { - -class TextVertexBuffer : public Buffer < - 16, - GL_ARRAY_BUFFER, - 32768 -> { -public: - typedef int16_t vertex_type; - - static const double angleFactor; - - size_t add(int16_t x, int16_t y, float ox, float oy, uint16_t tx, uint16_t ty, float angle, float minzoom, std::array<float, 2> range, float maxzoom, float labelminzoom); -}; - - -} - -#endif diff --git a/include/mbgl/geometry/vao.hpp b/include/mbgl/geometry/vao.hpp deleted file mode 100644 index 2ecba731f7..0000000000 --- a/include/mbgl/geometry/vao.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef MBGL_GEOMETRY_VAO -#define MBGL_GEOMETRY_VAO - -#include <mbgl/shader/shader.hpp> -#include <mbgl/platform/gl.hpp> -#include <mbgl/util/noncopyable.hpp> - -#include <stdexcept> - -namespace mbgl { - -class VertexArrayObject : public util::noncopyable { -public: - inline VertexArrayObject() {}; - - inline VertexArrayObject(VertexArrayObject &&rhs) noexcept - : vao(rhs.vao), - bound_shader(rhs.bound_shader), - bound_shader_name(rhs.bound_shader_name), - bound_vertex_buffer(rhs.bound_vertex_buffer), - bound_elements_buffer(rhs.bound_elements_buffer), - bound_offset(rhs.bound_offset) {}; - - template <typename Shader, typename VertexBuffer> - inline void bind(Shader& shader, VertexBuffer &vertexBuffer, char *offset) { - bindVertexArrayObject(); - if (bound_shader == 0) { - vertexBuffer.bind(); - shader.bind(offset); - if (vao) { - storeBinding(shader, vertexBuffer.getID(), 0, offset); - } - } else { - verifyBinding(shader, vertexBuffer.getID(), 0, offset); - } - } - - template <typename Shader, typename VertexBuffer, typename ElementsBuffer> - inline void bind(Shader& shader, VertexBuffer &vertexBuffer, ElementsBuffer &elementsBuffer, char *offset) { - bindVertexArrayObject(); - if (bound_shader == 0) { - vertexBuffer.bind(); - elementsBuffer.bind(); - shader.bind(offset); - if (vao) { - storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); - } - } else { - verifyBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset); - } - } - - ~VertexArrayObject(); - -private: - void bindVertexArrayObject(); - void storeBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, char *offset); - void verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer, char *offset); - - GLuint vao = 0; - - // For debug reasons, we're storing the bind information so that we can - // detect errors and report - GLuint bound_shader = 0; - const char *bound_shader_name = ""; - GLuint bound_vertex_buffer = 0; - GLuint bound_elements_buffer = 0; - char *bound_offset = 0; -}; - -} - -#endif diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 4e6eef89cf..3a50a70136 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -2,9 +2,6 @@ #define MBGL_MAP_MAP #include <mbgl/map/transform.hpp> -#include <mbgl/renderer/painter.hpp> -#include <mbgl/geometry/glyph_atlas.hpp> -#include <mbgl/geometry/sprite_atlas.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/time.hpp> #include <mbgl/util/uv.hpp> @@ -19,6 +16,7 @@ namespace mbgl { +class Painter; class GlyphStore; class LayerDescription; class Sprite; @@ -29,6 +27,8 @@ class StyleSource; class TexturePool; class FileSource; class View; +class GlyphAtlas; +class SpriteAtlas; class Map : private util::noncopyable { typedef void (*stop_callback)(void *); @@ -182,13 +182,13 @@ private: FileSource& fileSource; util::ptr<Style> style; - GlyphAtlas glyphAtlas; + const std::unique_ptr<GlyphAtlas> glyphAtlas; util::ptr<GlyphStore> glyphStore; - SpriteAtlas spriteAtlas; + const std::unique_ptr<SpriteAtlas> spriteAtlas; util::ptr<Sprite> sprite; util::ptr<TexturePool> texturePool; - Painter painter; + const std::unique_ptr<Painter> painter; std::string styleURL; std::string styleJSON = ""; diff --git a/include/mbgl/map/raster_tile_data.hpp b/include/mbgl/map/raster_tile_data.hpp deleted file mode 100644 index 42070d9c61..0000000000 --- a/include/mbgl/map/raster_tile_data.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MBGL_MAP_RASTER_TILE_DATA -#define MBGL_MAP_RASTER_TILE_DATA - -#include <mbgl/map/tile.hpp> -#include <mbgl/map/tile_data.hpp> -#include <mbgl/renderer/raster_bucket.hpp> - -namespace mbgl { - -class Painter; -class SourceInfo; -class StyleLayer; -class TexturePool; - -class RasterTileData : public TileData { - friend class TileParser; - -public: - RasterTileData(Tile::ID const& id, TexturePool&, const SourceInfo&); - ~RasterTileData(); - - virtual void parse(); - virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(StyleLayer const& layer_desc) const; - -protected: - StyleBucketRaster properties; - RasterBucket bucket; -}; - -} - -#endif diff --git a/include/mbgl/map/source.hpp b/include/mbgl/map/source.hpp deleted file mode 100644 index 8976f67b05..0000000000 --- a/include/mbgl/map/source.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef MBGL_MAP_SOURCE -#define MBGL_MAP_SOURCE - -#include <mbgl/map/tile.hpp> -#include <mbgl/map/tile_data.hpp> -#include <mbgl/style/style_source.hpp> - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/time.hpp> -#include <mbgl/util/mat4.hpp> -#include <mbgl/util/ptr.hpp> - -#include <cstdint> -#include <forward_list> -#include <iosfwd> -#include <map> - -namespace mbgl { - -class Map; -class GlyphAtlas; -class GlyphStore; -class SpriteAtlas; -class Sprite; -class FileSource; -class TexturePool; -class Style; -class Painter; -class StyleLayer; -class TransformState; -struct box; - -class Source : public std::enable_shared_from_this<Source>, private util::noncopyable { -public: - Source(SourceInfo&); - - void load(Map&, FileSource&); - void update(Map&, uv::worker&, - util::ptr<Style>, - GlyphAtlas&, GlyphStore&, - SpriteAtlas&, util::ptr<Sprite>, - TexturePool&, FileSource&, - std::function<void ()> callback); - - void updateMatrices(const mat4 &projMatrix, const TransformState &transform); - void drawClippingMasks(Painter &painter); - size_t getTileCount() const; - void render(Painter &painter, util::ptr<StyleLayer> layer_desc); - void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); - void finishRender(Painter &painter); - - std::forward_list<Tile::ID> getIDs() const; - std::forward_list<Tile *> getLoadedTiles() const; - void updateClipIDs(const std::map<Tile::ID, ClipID> &mapping); - -private: - bool findLoadedChildren(const Tile::ID& id, int32_t maxCoveringZoom, std::forward_list<Tile::ID>& retain); - bool findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::forward_list<Tile::ID>& retain); - int32_t coveringZoomLevel(const TransformState&) const; - std::forward_list<Tile::ID> coveringTiles(const TransformState&) const; - - TileData::State addTile(Map&, uv::worker&, - util::ptr<Style>, - GlyphAtlas&, GlyphStore&, - SpriteAtlas&, util::ptr<Sprite>, - FileSource&, TexturePool&, - const Tile::ID&, - std::function<void ()> callback); - - TileData::State hasTile(const Tile::ID& id); - - double getZoom(const TransformState &state) const; - - SourceInfo& info; - bool loaded = false; - - // Stores the time when this source was most recently updated. - timestamp updated = 0; - - std::map<Tile::ID, std::unique_ptr<Tile>> tiles; - std::map<Tile::ID, std::weak_ptr<TileData>> tile_data; -}; - -} - -#endif diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp deleted file mode 100644 index d4b54ba1b5..0000000000 --- a/include/mbgl/map/sprite.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef MBGL_STYLE_SPRITE -#define MBGL_STYLE_SPRITE - -#include <mbgl/util/image.hpp> -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/ptr.hpp> - -#include <cstdint> -#include <atomic> -#include <iosfwd> -#include <string> -#include <unordered_map> -#include <future> - -namespace mbgl { - -class FileSource; - -class SpritePosition { -public: - explicit SpritePosition() {} - explicit SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, float pixelRatio, bool sdf); - - operator bool() const { - return !(width == 0 && height == 0 && x == 0 && y == 0); - } - - uint16_t x = 0, y = 0; - uint16_t width = 0, height = 0; - float pixelRatio = 1.0f; - bool sdf = false; -}; - -class Sprite : public std::enable_shared_from_this<Sprite>, private util::noncopyable { -private: - struct Key {}; - void load(FileSource& fileSource); - -public: - Sprite(const Key &, const std::string& base_url, float pixelRatio); - static util::ptr<Sprite> Create(const std::string& base_url, float pixelRatio, FileSource& fileSource); - - const SpritePosition &getSpritePosition(const std::string& name) const; - - void waitUntilLoaded() const; - bool isLoaded() const; - - operator bool() const; - -private: - const bool valid; - -public: - const float pixelRatio; - const std::string spriteURL; - const std::string jsonURL; - std::unique_ptr<util::Image> raster; - -private: - void parseJSON(); - void parseImage(); - void complete(); - -private: - std::string body; - std::string image; - std::atomic<bool> loadedImage; - std::atomic<bool> loadedJSON; - std::unordered_map<std::string, SpritePosition> pos; - const SpritePosition empty; - - std::promise<void> promise; - std::future<void> future; - -}; - -} - -#endif diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp deleted file mode 100644 index 1ae215b204..0000000000 --- a/include/mbgl/map/tile_data.hpp +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef MBGL_MAP_TILE_DATA -#define MBGL_MAP_TILE_DATA - -#include <mbgl/map/tile.hpp> -#include <mbgl/renderer/debug_bucket.hpp> -#include <mbgl/geometry/debug_font_buffer.hpp> - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/ptr.hpp> - -#include <atomic> -#include <exception> -#include <iosfwd> -#include <string> -#include <functional> - -namespace uv { -class worker; -} - -namespace mbgl { - -class Map; -class FileSource; -class Painter; -class SourceInfo; -class StyleLayer; -class Request; - -class TileData : public std::enable_shared_from_this<TileData>, - private util::noncopyable { -public: - struct exception : std::exception {}; - struct geometry_too_long_exception : exception {}; - -public: - typedef util::ptr<TileData> Ptr; - - enum class State { - invalid, - initial, - loading, - loaded, - parsed, - obsolete - }; - -public: - TileData(Tile::ID const& id, const SourceInfo&); - ~TileData(); - - void request(uv::worker&, FileSource&, float pixelRatio, std::function<void ()> callback); - void reparse(uv::worker&, std::function<void ()> callback); - void cancel(); - const std::string toString() const; - - inline bool ready() const { - return state == State::parsed; - } - - // Override this in the child class. - virtual void parse() = 0; - virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix) = 0; - virtual bool hasData(StyleLayer const& layer_desc) const = 0; - - -public: - const Tile::ID id; - const std::string name; - std::atomic<State> state; - -public: - const SourceInfo& source; - -protected: - std::unique_ptr<Request> req; - std::string data; - - // Contains the tile ID string for painting debug information. - DebugFontBuffer debugFontBuffer; - -public: - DebugBucket debugBucket; -}; - -} - -#endif diff --git a/include/mbgl/map/tile_parser.hpp b/include/mbgl/map/tile_parser.hpp deleted file mode 100644 index beae3af831..0000000000 --- a/include/mbgl/map/tile_parser.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef MBGL_MAP_TILE_PARSER -#define MBGL_MAP_TILE_PARSER - -#include <mbgl/map/vector_tile.hpp> -#include <mbgl/style/filter_expression.hpp> -#include <mbgl/text/glyph.hpp> -#include <mbgl/util/ptr.hpp> -#include <mbgl/util/noncopyable.hpp> -#include <cstdint> -#include <iosfwd> -#include <string> - -namespace mbgl { - -class Bucket; -class TexturePool; -class FontStack; -class GlyphAtlas; -class GlyphStore; -class SpriteAtlas; -class Sprite; -class Style; -class StyleBucket; -class StyleBucketFill; -class StyleBucketRaster; -class StyleBucketLine; -class StyleBucketSymbol; -class StyleLayerGroup; -class VectorTileData; -class Collision; -class TexturePool; - -class TileParser : private util::noncopyable -{ -public: - TileParser(const std::string &data, VectorTileData &tile, - const util::ptr<const Style> &style, - GlyphAtlas & glyphAtlas, - GlyphStore & glyphStore, - SpriteAtlas & spriteAtlas, - const util::ptr<Sprite> &sprite, - TexturePool& texturePool); - ~TileParser(); - -public: - void parse(); - -private: - bool obsolete() const; - void parseStyleLayers(util::ptr<StyleLayerGroup> group); - std::unique_ptr<Bucket> createBucket(util::ptr<StyleBucket> bucket_desc); - - std::unique_ptr<Bucket> createFillBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketFill &fill); - std::unique_ptr<Bucket> createRasterBucket(const StyleBucketRaster &raster); - std::unique_ptr<Bucket> createLineBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketLine &line); - std::unique_ptr<Bucket> createSymbolBucket(const VectorTileLayer& layer, const FilterExpression &filter, const StyleBucketSymbol &symbol); - - template <class Bucket> void addBucketGeometries(Bucket& bucket, const VectorTileLayer& layer, const FilterExpression &filter); - -private: - const VectorTile vector_data; - VectorTileData& tile; - - // Cross-thread shared data. - util::ptr<const Style> style; - GlyphAtlas & glyphAtlas; - GlyphStore & glyphStore; - SpriteAtlas & spriteAtlas; - util::ptr<Sprite> sprite; - TexturePool& texturePool; - - std::unique_ptr<Collision> collision; -}; - -} - -#endif diff --git a/include/mbgl/map/transform_state.hpp b/include/mbgl/map/transform_state.hpp index bb330c1019..6dc34bd873 100644 --- a/include/mbgl/map/transform_state.hpp +++ b/include/mbgl/map/transform_state.hpp @@ -4,7 +4,6 @@ #include <mbgl/map/tile.hpp> #include <mbgl/util/mat4.hpp> -#include <mbgl/util/vec.hpp> #include <cstdint> #include <array> diff --git a/include/mbgl/map/vector_tile.hpp b/include/mbgl/map/vector_tile.hpp deleted file mode 100644 index 2d02ba3a0b..0000000000 --- a/include/mbgl/map/vector_tile.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef MBGL_MAP_VECTOR_TILE -#define MBGL_MAP_VECTOR_TILE - -#include <mbgl/style/filter_expression.hpp> -#include <mbgl/style/value.hpp> -#include <mbgl/text/glyph.hpp> -#include <mbgl/util/pbf.hpp> -#include <mbgl/util/optional.hpp> - -#include <cstdint> -#include <iosfwd> -#include <map> -#include <string> -#include <unordered_map> -#include <vector> - -namespace mbgl { - -class VectorTileLayer; - -enum class FeatureType { - Unknown = 0, - Point = 1, - LineString = 2, - Polygon = 3 -}; - -std::ostream& operator<<(std::ostream&, const FeatureType& type); - -class VectorTileFeature { -public: - VectorTileFeature(pbf feature, const VectorTileLayer& layer); - - uint64_t id = 0; - FeatureType type = FeatureType::Unknown; - std::map<std::string, Value> properties; - pbf geometry; -}; - -std::ostream& operator<<(std::ostream&, const VectorTileFeature& feature); - - -class VectorTileTagExtractor { -public: - VectorTileTagExtractor(const VectorTileLayer &layer); - - void setTags(const pbf &pbf); - mapbox::util::optional<Value> getValue(const std::string &key) const; - void setType(FeatureType type); - FeatureType getType() const; - -private: - const VectorTileLayer &layer_; - pbf tags_; - FeatureType type_ = FeatureType::Unknown; -}; - -/* - * Allows iterating over the features of a VectorTileLayer using a - * BucketDescription as filter. Only features matching the descriptions will - * be returned (as pbf). - */ -class FilteredVectorTileLayer { -public: - class iterator { - public: - iterator(const FilteredVectorTileLayer& filter, const pbf& data); - void operator++(); - bool operator!=(const iterator& other) const; - const pbf& operator*() const; - - private: - const FilteredVectorTileLayer& parent; - bool valid = false; - pbf feature; - pbf data; - }; - -public: - FilteredVectorTileLayer(const VectorTileLayer& layer, const FilterExpression &filterExpression); - - iterator begin() const; - iterator end() const; - -private: - const VectorTileLayer& layer; - const FilterExpression& filterExpression; -}; - -std::ostream& operator<<(std::ostream&, const PositionedGlyph& placement); - -class VectorTileLayer { -public: - VectorTileLayer(pbf data); - - const pbf data; - std::string name; - uint32_t extent = 4096; - std::vector<std::string> keys; - std::unordered_map<std::string, uint32_t> key_index; - std::vector<Value> values; - std::map<std::string, std::map<Value, Shaping>> shaping; -}; - -class VectorTile { -public: - VectorTile(); - VectorTile(pbf data); - VectorTile& operator=(VectorTile&& other); - - std::map<std::string, const VectorTileLayer> layers; -}; - - - -} - -#endif diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp deleted file mode 100644 index b9bf55a1b3..0000000000 --- a/include/mbgl/map/vector_tile_data.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef MBGL_MAP_VECTOR_TILE_DATA -#define MBGL_MAP_VECTOR_TILE_DATA - -#include <mbgl/map/tile.hpp> -#include <mbgl/map/tile_data.hpp> -#include <mbgl/geometry/elements_buffer.hpp> -#include <mbgl/geometry/fill_buffer.hpp> -#include <mbgl/geometry/icon_buffer.hpp> -#include <mbgl/geometry/line_buffer.hpp> -#include <mbgl/geometry/text_buffer.hpp> - -#include <iosfwd> -#include <memory> -#include <unordered_map> - -namespace mbgl { - -class Bucket; -class Painter; -class SourceInfo; -class StyleLayer; -class TileParser; -class GlyphAtlas; -class GlyphStore; -class SpriteAtlas; -class Sprite; -class TexturePool; -class Style; - -class VectorTileData : public TileData { - friend class TileParser; - -public: - VectorTileData(Tile::ID const&, - float mapMaxZoom, util::ptr<Style>, - GlyphAtlas&, GlyphStore&, - SpriteAtlas&, util::ptr<Sprite>, - TexturePool&, - const SourceInfo&); - ~VectorTileData(); - - virtual void parse(); - virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); - virtual bool hasData(StyleLayer const& layer_desc) const; - -protected: - // Holds the actual geometries in this tile. - FillVertexBuffer fillVertexBuffer; - LineVertexBuffer lineVertexBuffer; - IconVertexBuffer iconVertexBuffer; - TextVertexBuffer textVertexBuffer; - - TriangleElementsBuffer triangleElementsBuffer; - LineElementsBuffer lineElementsBuffer; - PointElementsBuffer pointElementsBuffer; - - // Holds the buckets of this tile. - // They contain the location offsets in the buffers stored above - std::unordered_map<std::string, std::unique_ptr<Bucket>> buckets; - - GlyphAtlas& glyphAtlas; - GlyphStore& glyphStore; - SpriteAtlas& spriteAtlas; - util::ptr<Sprite> sprite; - TexturePool& texturePool; - util::ptr<Style> style; - -public: - const float depth; -}; - -} - -#endif diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp index a63dd9b1fb..d16478dab9 100644 --- a/include/mbgl/platform/gl.hpp +++ b/include/mbgl/platform/gl.hpp @@ -134,9 +134,9 @@ extern PFNGLISVERTEXARRAYPROC IsVertexArray; // static int indent = 0; inline void start_group(const std::string &str) { if (gl::PushDebugGroup != nullptr) { - gl::PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, str.size(), str.c_str()); + gl::PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, GLsizei(str.size()), str.c_str()); } else if (gl::PushGroupMarkerEXT != nullptr) { - gl::PushGroupMarkerEXT(str.size(), str.c_str()); + gl::PushGroupMarkerEXT(GLsizei(str.size()), str.c_str()); } // fprintf(stderr, "%s%s\n", std::string(indent * 4, ' ').c_str(), str.c_str()); // indent++; diff --git a/include/mbgl/renderer/bucket.hpp b/include/mbgl/renderer/bucket.hpp deleted file mode 100644 index 696bfb1110..0000000000 --- a/include/mbgl/renderer/bucket.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef MBGL_RENDERER_BUCKET -#define MBGL_RENDERER_BUCKET - -#include <mbgl/map/tile.hpp> -#include <mbgl/util/noncopyable.hpp> - -#include <string> - -namespace mbgl { - -class Painter; -class StyleLayer; - -class Bucket : private util::noncopyable { -public: - virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix) = 0; - virtual bool hasData() const = 0; - virtual ~Bucket() {} - -}; - -} - -#endif diff --git a/include/mbgl/renderer/debug_bucket.hpp b/include/mbgl/renderer/debug_bucket.hpp deleted file mode 100644 index fb6cfb4cae..0000000000 --- a/include/mbgl/renderer/debug_bucket.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef MBGL_RENDERER_DEBUGBUCKET -#define MBGL_RENDERER_DEBUGBUCKET - -#include <mbgl/renderer/bucket.hpp> -#include <mbgl/geometry/debug_font_buffer.hpp> -#include <mbgl/geometry/vao.hpp> - -#include <vector> - -#ifndef BUFFER_OFFSET -#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) -#endif - -namespace mbgl { - -class PlainShader; - -class DebugBucket : public Bucket { -public: - DebugBucket(DebugFontBuffer& fontBuffer); - - virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - virtual bool hasData() const; - - void drawLines(PlainShader& shader); - void drawPoints(PlainShader& shader); - -private: - DebugFontBuffer& fontBuffer; - VertexArrayObject array; -}; - -} - -#endif diff --git a/include/mbgl/renderer/fill_bucket.hpp b/include/mbgl/renderer/fill_bucket.hpp deleted file mode 100644 index ae766ec28d..0000000000 --- a/include/mbgl/renderer/fill_bucket.hpp +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef MBGL_RENDERER_FILLBUCKET -#define MBGL_RENDERER_FILLBUCKET - -#include <mbgl/renderer/bucket.hpp> -#include <mbgl/geometry/elements_buffer.hpp> -#include <mbgl/geometry/fill_buffer.hpp> -#include <mbgl/style/style_bucket.hpp> - -#include <clipper/clipper.hpp> -#include <libtess2/tesselator.h> - -#include <vector> -#include <memory> - -#ifndef BUFFER_OFFSET -#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) -#endif - -namespace mbgl { - -class Style; -class FillVertexBuffer; -class TriangleElementsBuffer; -class LineElementsBuffer; -class BucketDescription; -class OutlineShader; -class PlainShader; -class PatternShader; -struct pbf; - -class FillBucket : public Bucket { - - static void *alloc(void *data, unsigned int size); - static void *realloc(void *data, void *ptr, unsigned int size); - static void free(void *userData, void *ptr); - - typedef ElementGroup<2> triangle_group_type; - typedef ElementGroup<1> line_group_type; - -public: - FillBucket(FillVertexBuffer& vertexBuffer, - TriangleElementsBuffer& triangleElementsBuffer, - LineElementsBuffer& lineElementsBuffer, - const StyleBucketFill& properties); - ~FillBucket(); - - virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - virtual bool hasData() const; - - void addGeometry(pbf& data); - void tessellate(); - - void drawElements(PlainShader& shader); - void drawElements(PatternShader& shader); - void drawVertices(OutlineShader& shader); - -public: - const StyleBucketFill &properties; - -private: - TESSalloc *allocator; - TESStesselator *tesselator; - ClipperLib::Clipper clipper; - - FillVertexBuffer& vertexBuffer; - TriangleElementsBuffer& triangleElementsBuffer; - LineElementsBuffer& lineElementsBuffer; - - // hold information on where the vertices are located in the FillBuffer - const size_t vertex_start; - const size_t triangle_elements_start; - const size_t line_elements_start; - VertexArrayObject array; - - std::vector<triangle_group_type> triangleGroups; - std::vector<line_group_type> lineGroups; - - std::vector<ClipperLib::IntPoint> line; - bool hasVertices = false; - - static const int vertexSize = 2; - static const int stride = sizeof(TESSreal) * vertexSize; - static const int vertices_per_group = 3; -}; - -} - -#endif diff --git a/include/mbgl/renderer/frame_history.hpp b/include/mbgl/renderer/frame_history.hpp deleted file mode 100644 index 61bb59da33..0000000000 --- a/include/mbgl/renderer/frame_history.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MBGL_RENDERER_FRAME_HISTORY -#define MBGL_RENDERER_FRAME_HISTORY - -#include <deque> -#include <cassert> -#include <cmath> - -#include <mbgl/platform/platform.hpp> -#include <mbgl/util/time.hpp> - -namespace mbgl { - -struct FrameSnapshot { - explicit inline FrameSnapshot(timestamp t_, float z_) : t(t_), z(z_) {} - float t; - float z; -}; - -struct FadeProperties { - float fadedist; - float minfadezoom; - float maxfadezoom; - float bump; -}; - -class FrameHistory { -public: - // Record frame history that will be used to calculate fading params - void record(timestamp now, float zoom); - - bool needsAnimation(timestamp duration) const; - FadeProperties getFadeProperties(timestamp duration); - -public: - std::deque<FrameSnapshot> history; -}; - -} - -#endif diff --git a/include/mbgl/renderer/line_bucket.hpp b/include/mbgl/renderer/line_bucket.hpp deleted file mode 100644 index 7337ca80ad..0000000000 --- a/include/mbgl/renderer/line_bucket.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef MBGL_RENDERER_LINEBUCKET -#define MBGL_RENDERER_LINEBUCKET - -#include <mbgl/renderer/bucket.hpp> -#include <mbgl/geometry/vao.hpp> -#include <mbgl/geometry/elements_buffer.hpp> -#include <mbgl/geometry/line_buffer.hpp> -#include <mbgl/style/style_bucket.hpp> - -#include <vector> - -namespace mbgl { - -class Style; -class LineVertexBuffer; -class TriangleElementsBuffer; -class LineShader; -class LinejoinShader; -class LinepatternShader; -struct pbf; - -class LineBucket : public Bucket { - typedef ElementGroup<2> triangle_group_type; - typedef ElementGroup<1> point_group_type; - -public: - LineBucket(LineVertexBuffer& vertexBuffer, - TriangleElementsBuffer& triangleElementsBuffer, - PointElementsBuffer& pointElementsBuffer, - const StyleBucketLine& properties); - - virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - virtual bool hasData() const; - - void addGeometry(pbf& data); - void addGeometry(const std::vector<Coordinate>& line); - - bool hasPoints() const; - - void drawLines(LineShader& shader); - void drawLinePatterns(LinepatternShader& shader); - void drawPoints(LinejoinShader& shader); - -public: - const StyleBucketLine &properties; - -private: - LineVertexBuffer& vertexBuffer; - TriangleElementsBuffer& triangleElementsBuffer; - PointElementsBuffer& pointElementsBuffer; - - const size_t vertex_start; - const size_t triangle_elements_start; - const size_t point_elements_start; - - std::vector<triangle_group_type> triangleGroups; - std::vector<point_group_type> pointGroups; -}; - -} - -#endif diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp deleted file mode 100644 index be4bd12710..0000000000 --- a/include/mbgl/renderer/painter.hpp +++ /dev/null @@ -1,259 +0,0 @@ -#ifndef MBGL_RENDERER_PAINTER -#define MBGL_RENDERER_PAINTER - -#include <mbgl/map/tile_data.hpp> -#include <mbgl/geometry/vao.hpp> -#include <mbgl/geometry/static_vertex_buffer.hpp> -#include <mbgl/util/mat4.hpp> -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/renderer/frame_history.hpp> -#include <mbgl/style/types.hpp> - -#include <mbgl/shader/plain_shader.hpp> -#include <mbgl/shader/outline_shader.hpp> -#include <mbgl/shader/pattern_shader.hpp> -#include <mbgl/shader/line_shader.hpp> -#include <mbgl/shader/linejoin_shader.hpp> -#include <mbgl/shader/linepattern_shader.hpp> -#include <mbgl/shader/icon_shader.hpp> -#include <mbgl/shader/raster_shader.hpp> -#include <mbgl/shader/sdf_shader.hpp> -#include <mbgl/shader/dot_shader.hpp> -#include <mbgl/shader/gaussian_shader.hpp> - -#include <mbgl/map/transform_state.hpp> -#include <mbgl/util/ptr.hpp> - -#include <map> -#include <unordered_map> -#include <set> - -namespace mbgl { - -enum class RenderPass : bool { Opaque, Translucent }; - -class Transform; -class Style; -class Tile; -class Sprite; -class SpriteAtlas; -class GlyphAtlas; -class Source; -class StyleSource; -class StyleLayerGroup; - -class FillBucket; -class LineBucket; -class SymbolBucket; -class RasterBucket; -class PrerenderedTexture; - -struct FillProperties; -struct RasterProperties; - -class LayerDescription; -class RasterTileData; - -class Painter : private util::noncopyable { -public: - Painter(SpriteAtlas&, GlyphAtlas&); - ~Painter(); - - void setup(); - - // Perform cleanup tasks that prepare shutting down the app. This doesn't mean that the - // app will be shut down. That means all operations must be automatically be reversed (e.g. through - // lazy initialization) in case rendering continues. - void cleanup(); - - void terminate(); - - // Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any - // tiles whatsoever. - void clear(); - - // Updates the default matrices to the current viewport dimensions. - void changeMatrix(); - - void render(const Style& style, - const std::set<util::ptr<StyleSource>>& sources, - TransformState state, - timestamp time); - - void renderLayers(util::ptr<StyleLayerGroup> group); - void renderLayer(util::ptr<StyleLayer> layer_desc, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); - - // Renders a particular layer from a tile. - void renderTileLayer(const Tile& tile, util::ptr<StyleLayer> layer_desc, const mat4 &matrix); - - // Renders debug information for a tile. - void renderTileDebug(const Tile& tile); - - // Renders the red debug frame around a tile, visualizing its perimeter. - void renderDebugFrame(const mat4 &matrix); - - void renderDebugText(DebugBucket& bucket, const mat4 &matrix); - void renderDebugText(const std::vector<std::string> &strings); - void renderFill(FillBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderSymbol(SymbolBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderRaster(RasterBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - void renderBackground(util::ptr<StyleLayer> layer_desc); - - float saturationFactor(float saturation); - float contrastFactor(float contrast); - std::array<float, 3> spinWeights(float spin_value); - - void preparePrerender(RasterBucket &bucket); - - void renderPrerenderedTexture(RasterBucket &bucket, const mat4 &matrix, const RasterProperties& properties); - - void createPrerendered(RasterBucket& bucket, util::ptr<StyleLayer> layer_desc, const Tile::ID& id); - - void resize(); - - // Changes whether debug information is drawn onto the map - void setDebug(bool enabled); - - // Opaque/Translucent pass setting - void setOpaque(); - void setTranslucent(); - - // Configures the painter strata that is used for early z-culling of fragments. - void setStrata(float strata); - - void drawClippingMasks(const std::set<util::ptr<StyleSource>> &sources); - void drawClippingMask(const mat4& matrix, const ClipID& clip); - - void resetFramebuffer(); - void bindFramebuffer(); - void pushFramebuffer(); - GLuint popFramebuffer(); - void discardFramebuffers(); - - bool needsAnimation() const; - -private: - void setupShaders(); - void deleteShaders(); - mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor); - - void prepareTile(const Tile& tile); - - template <typename BucketProperties, typename StyleProperties> - void renderSDF(SymbolBucket &bucket, - const Tile::ID &id, - const mat4 &matrixSymbol, - const BucketProperties& bucketProperties, - const StyleProperties& styleProperties, - float scaleDivisor, - std::array<float, 2> texsize, - SDFShader& sdfShader, - void (SymbolBucket::*drawSDF)(SDFShader&)); - -public: - void useProgram(uint32_t program); - void lineWidth(float lineWidth); - void depthMask(bool value); - void depthRange(float near, float far); - -public: - mat4 projMatrix; - mat4 nativeMatrix; - mat4 extrudeMatrix; - - // used to composite images and flips the geometry upside down - const mat4 flipMatrix = []{ - mat4 flip; - matrix::ortho(flip, 0, 4096, -4096, 0, 0, 1); - matrix::translate(flip, flip, 0, -4096, 0); - return flip; - }(); - - const mat4 identityMatrix = []{ - mat4 identity; - matrix::identity(identity); - return identity; - }(); - -private: - TransformState state; - - bool debug = false; - int indent = 0; - - uint32_t gl_program = 0; - float gl_lineWidth = 0; - bool gl_depthMask = true; - std::array<uint16_t, 2> gl_viewport = {{ 0, 0 }}; - std::array<float, 2> gl_depthRange = {{ 0, 1 }}; - float strata = 0; - RenderPass pass = RenderPass::Opaque; - const float strata_epsilon = 1.0f / (1 << 16); - -public: - FrameHistory frameHistory; - - SpriteAtlas& spriteAtlas; - GlyphAtlas& glyphAtlas; - - std::unique_ptr<PlainShader> plainShader; - std::unique_ptr<OutlineShader> outlineShader; - std::unique_ptr<LineShader> lineShader; - std::unique_ptr<LinejoinShader> linejoinShader; - std::unique_ptr<LinepatternShader> linepatternShader; - std::unique_ptr<PatternShader> patternShader; - std::unique_ptr<IconShader> iconShader; - std::unique_ptr<RasterShader> rasterShader; - std::unique_ptr<SDFGlyphShader> sdfGlyphShader; - std::unique_ptr<SDFIconShader> sdfIconShader; - std::unique_ptr<DotShader> dotShader; - std::unique_ptr<GaussianShader> gaussianShader; - - StaticVertexBuffer backgroundBuffer = { - { -1, -1 }, { 1, -1 }, - { -1, 1 }, { 1, 1 } - }; - - VertexArrayObject backgroundArray; - - // Set up the stencil quad we're using to generate the stencil mask. - StaticVertexBuffer tileStencilBuffer = { - // top left triangle - { 0, 0 }, - { 4096, 0 }, - { 0, 4096 }, - - // bottom right triangle - { 4096, 0 }, - { 0, 4096 }, - { 4096, 4096 }, - }; - - VertexArrayObject coveringPlainArray; - VertexArrayObject coveringRasterArray; - VertexArrayObject coveringGaussianArray; - - // Set up the tile boundary lines we're using to draw the tile outlines. - StaticVertexBuffer tileBorderBuffer = { - { 0, 0 }, - { 4096, 0 }, - { 4096, 4096 }, - { 0, 4096 }, - { 0, 0 }, - }; - - VertexArrayObject tileBorderArray; - - // Framebuffer management - std::vector<GLuint> fbos; - std::vector<GLuint> fbos_color; - GLuint fbo_depth_stencil; - int fbo_level = -1; - bool fbo_depth_stencil_valid = false; - -}; - -} - -#endif diff --git a/include/mbgl/renderer/prerendered_texture.hpp b/include/mbgl/renderer/prerendered_texture.hpp deleted file mode 100644 index e4dc610418..0000000000 --- a/include/mbgl/renderer/prerendered_texture.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef MBGL_RENDERER_PRERENDERED_TEXTURE -#define MBGL_RENDERER_PRERENDERED_TEXTURE - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/platform/gl.hpp> - -namespace mbgl { - -class StyleBucketRaster; -class Painter; - -class PrerenderedTexture : private util::noncopyable { -public: - PrerenderedTexture(const StyleBucketRaster &properties); - ~PrerenderedTexture(); - - void bindTexture(); - void bindFramebuffer(); - void unbindFramebuffer(); - - inline GLuint getTexture() const { return texture; } - - void blur(Painter& painter, uint16_t passes); - -public: - const StyleBucketRaster &properties; - -private: - GLint previous_fbo = 0; - GLuint fbo = 0; - GLuint texture = 0; - GLuint fbo_depth_stencil = 0; -}; - -} - -#endif diff --git a/include/mbgl/renderer/raster_bucket.hpp b/include/mbgl/renderer/raster_bucket.hpp deleted file mode 100644 index 0a7651d7cc..0000000000 --- a/include/mbgl/renderer/raster_bucket.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef MBGL_RENDERER_RASTERBUCKET -#define MBGL_RENDERER_RASTERBUCKET - -#include <mbgl/renderer/bucket.hpp> -#include <mbgl/util/raster.hpp> -#include <mbgl/renderer/prerendered_texture.hpp> -#include <mbgl/style/style_bucket.hpp> - - - -namespace mbgl { - -class RasterShader; -class StaticVertexBuffer; -class VertexArrayObject; - -class RasterBucket : public Bucket { -public: - RasterBucket(TexturePool&, const StyleBucketRaster&); - - virtual void render(Painter& painter, util::ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); - virtual bool hasData() const; - - bool setImage(const std::string &data); - - const StyleBucketRaster &properties; - PrerenderedTexture texture; - - void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array); - - void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture); - - Raster raster; -}; - -} - -#endif diff --git a/include/mbgl/renderer/symbol_bucket.hpp b/include/mbgl/renderer/symbol_bucket.hpp deleted file mode 100644 index 9a5da1d012..0000000000 --- a/include/mbgl/renderer/symbol_bucket.hpp +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef MBGL_RENDERER_SYMBOLBUCKET -#define MBGL_RENDERER_SYMBOLBUCKET - -#include "bucket.hpp" -#include <mbgl/geometry/vao.hpp> -#include <mbgl/geometry/elements_buffer.hpp> -#include <mbgl/geometry/text_buffer.hpp> -#include <mbgl/geometry/icon_buffer.hpp> -#include <mbgl/map/vector_tile.hpp> -#include <mbgl/text/types.hpp> -#include <mbgl/text/glyph.hpp> -#include <mbgl/style/style_bucket.hpp> - -#include <memory> -#include <map> -#include <vector> - -namespace mbgl { - -class Style; -class SDFShader; -class IconShader; -class DotShader; -class Collision; -class SpriteAtlas; -class Sprite; -class GlyphAtlas; -class GlyphStore; -class FontStack; - -class SymbolFeature { -public: - pbf geometry; - std::u32string label; - std::string sprite; -}; - - -class Symbol { -public: - vec2<float> tl, tr, bl, br; - Rect<uint16_t> tex; - float angle; - float minScale = 0.0f; - float maxScale = std::numeric_limits<float>::infinity(); - CollisionAnchor anchor; -}; - -typedef std::vector<Symbol> Symbols; - - -class SymbolBucket : public Bucket { - typedef ElementGroup<1> TextElementGroup; - typedef ElementGroup<2> IconElementGroup; - -public: - SymbolBucket(const StyleBucketSymbol &properties, Collision &collision); - - virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix); - virtual bool hasData() const; - virtual bool hasTextData() const; - virtual bool hasIconData() const; - - void addFeatures(const VectorTileLayer &layer, const FilterExpression &filter, - const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite, - GlyphAtlas &glyphAtlas, GlyphStore &glyphStore); - - void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange, - float zoom); - - void drawGlyphs(SDFShader& shader); - void drawIcons(SDFShader& shader); - void drawIcons(IconShader& shader); - -private: - - std::vector<SymbolFeature> processFeatures(const VectorTileLayer &layer, const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite); - - - void addFeature(const pbf &geom_pbf, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image); - void addFeature(const std::vector<Coordinate> &line, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image); - - - // Adds placed items to the buffer. - template <typename Buffer> - void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, PlacementRange placementRange); - - // Adds glyphs to the glyph atlas so that they have a left/top/width/height coordinates associated to them that we can use for writing to a buffer. - static void addGlyphsToAtlas(uint64_t tileid, const std::string stackname, const std::u32string &string, - const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face); - -public: - const StyleBucketSymbol &properties; - bool sdfIcons = false; - -private: - Collision &collision; - - struct { - TextVertexBuffer vertices; - TriangleElementsBuffer triangles; - std::vector<TextElementGroup> groups; - } text; - - struct { - IconVertexBuffer vertices; - TriangleElementsBuffer triangles; - std::vector<IconElementGroup> groups; - } icon; - -}; -} - -#endif diff --git a/include/mbgl/shader/dot_shader.hpp b/include/mbgl/shader/dot_shader.hpp deleted file mode 100644 index 2c4176f364..0000000000 --- a/include/mbgl/shader/dot_shader.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_DOT -#define MBGL_SHADER_SHADER_DOT - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class DotShader : public Shader { -public: - DotShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<float, 4>> u_color = {"u_color", *this}; - Uniform<float> u_size = {"u_size", *this}; - Uniform<float> u_blur = {"u_blur", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/gaussian_shader.hpp b/include/mbgl/shader/gaussian_shader.hpp deleted file mode 100644 index 0f494f5c7e..0000000000 --- a/include/mbgl/shader/gaussian_shader.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_RENDERER_SHADER_GAUSSIAN -#define MBGL_RENDERER_SHADER_GAUSSIAN - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class GaussianShader : public Shader { -public: - GaussianShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<float, 2>> u_offset = {"u_offset", *this}; - Uniform<int32_t> u_image = {"u_image", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/icon_shader.hpp b/include/mbgl/shader/icon_shader.hpp deleted file mode 100644 index 645d7e21b6..0000000000 --- a/include/mbgl/shader/icon_shader.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_ICON -#define MBGL_SHADER_SHADER_ICON - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class IconShader : public Shader { -public: - IconShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform<float> u_angle = {"u_angle", *this}; - Uniform<float> u_zoom = {"u_zoom", *this}; - Uniform<float> u_flip = {"u_flip", *this}; - Uniform<float> u_fadedist = {"u_fadedist", *this}; - Uniform<float> u_minfadezoom = {"u_minfadezoom", *this}; - Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform<float> u_fadezoom = {"u_fadezoom", *this}; - Uniform<float> u_opacity = {"u_opacity", *this}; - Uniform<std::array<float, 2>> u_texsize = {"u_texsize", *this}; - -private: - int32_t a_pos = -1; - int32_t a_offset = -1; - int32_t a_tex = -1; - int32_t a_angle = -1; - int32_t a_minzoom = -1; - int32_t a_maxzoom = -1; - int32_t a_rangeend = -1; - int32_t a_rangestart = -1; - int32_t a_labelminzoom = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/line_shader.hpp b/include/mbgl/shader/line_shader.hpp deleted file mode 100644 index b789330882..0000000000 --- a/include/mbgl/shader/line_shader.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINE -#define MBGL_SHADER_SHADER_LINE - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class LineShader : public Shader { -public: - LineShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform<std::array<float, 4>> u_color = {"u_color", *this}; - Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this}; - Uniform<std::array<float, 2>> u_dasharray = {"u_dasharray", *this}; - Uniform<float> u_ratio = {"u_ratio", *this}; - Uniform<float> u_blur = {"u_blur", *this}; - -private: - int32_t a_pos = -1; - int32_t a_extrude = -1; - int32_t a_linesofar = -1; -}; - - -} - -#endif diff --git a/include/mbgl/shader/linejoin_shader.hpp b/include/mbgl/shader/linejoin_shader.hpp deleted file mode 100644 index 61406fd45c..0000000000 --- a/include/mbgl/shader/linejoin_shader.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINEJOIN -#define MBGL_SHADER_SHADER_LINEJOIN - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class LinejoinShader : public Shader { -public: - LinejoinShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<float, 4>> u_color = {"u_color", *this}; - Uniform<std::array<float, 2>> u_world = {"u_world", *this}; - Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this}; - Uniform<float> u_size = {"u_size", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/linepattern_shader.hpp b/include/mbgl/shader/linepattern_shader.hpp deleted file mode 100644 index bf85940b8a..0000000000 --- a/include/mbgl/shader/linepattern_shader.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_LINEPATTERN -#define MBGL_SHADER_SHADER_LINEPATTERN - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class LinepatternShader : public Shader { -public: - LinepatternShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this}; - Uniform<std::array<float, 2>> u_pattern_size = {"u_pattern_size", *this}; - Uniform<std::array<float, 2>> u_pattern_tl = {"u_pattern_tl", *this}; - Uniform<std::array<float, 2>> u_pattern_br = {"u_pattern_br", *this}; - Uniform<float> u_ratio = {"u_ratio", *this}; - Uniform<float> u_point = {"u_point", *this}; - Uniform<float> u_blur = {"u_blur", *this}; - Uniform<float> u_fade = {"u_fade", *this}; - -private: - int32_t a_pos = -1; - int32_t a_extrude = -1; - int32_t a_linesofar = -1; -}; -} - -#endif diff --git a/include/mbgl/shader/outline_shader.hpp b/include/mbgl/shader/outline_shader.hpp deleted file mode 100644 index f3e8175fd7..0000000000 --- a/include/mbgl/shader/outline_shader.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_OUTLINE -#define MBGL_SHADER_SHADER_OUTLINE - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class OutlineShader : public Shader { -public: - OutlineShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<float, 4>> u_color = {"u_color", *this}; - Uniform<std::array<float, 2>> u_world = {"u_world", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/pattern_shader.hpp b/include/mbgl/shader/pattern_shader.hpp deleted file mode 100644 index 9fabd8e18a..0000000000 --- a/include/mbgl/shader/pattern_shader.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_PATTERN -#define MBGL_SHADER_SHADER_PATTERN - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class PatternShader : public Shader { -public: - PatternShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<float, 2>> u_pattern_tl = {"u_pattern_tl", *this}; - Uniform<std::array<float, 2>> u_pattern_br = {"u_pattern_br", *this}; - Uniform<float> u_opacity = {"u_opacity", *this}; - Uniform<float> u_mix = {"u_mix", *this}; - Uniform<int32_t> u_image = {"u_image", *this}; - UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/plain_shader.hpp b/include/mbgl/shader/plain_shader.hpp deleted file mode 100644 index 051501c3c9..0000000000 --- a/include/mbgl/shader/plain_shader.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef MBGL_SHADER_SHADER_PLAIN -#define MBGL_SHADER_SHADER_PLAIN - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class PlainShader : public Shader { -public: - PlainShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<float, 4>> u_color = {"u_color", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/raster_shader.hpp b/include/mbgl/shader/raster_shader.hpp deleted file mode 100644 index 8cf97055a2..0000000000 --- a/include/mbgl/shader/raster_shader.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MBGL_RENDERER_SHADER_RASTER -#define MBGL_RENDERER_SHADER_RASTER - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class RasterShader : public Shader { -public: - RasterShader(); - - void bind(char *offset); - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<int32_t> u_image = {"u_image", *this}; - Uniform<float> u_opacity = {"u_opacity", *this}; - Uniform<float> u_buffer = {"u_buffer", *this}; - Uniform<float> u_brightness_low = {"u_brightness_low", *this}; - Uniform<float> u_brightness_high = {"u_brightness_high", *this}; - Uniform<float> u_saturation_factor = {"u_saturation_factor", *this}; - Uniform<float> u_contrast_factor = {"u_contrast_factor", *this}; - Uniform<std::array<float, 3>> u_spin_weights = {"u_spin_weights", *this}; - -private: - int32_t a_pos = -1; -}; - -} - -#endif diff --git a/include/mbgl/shader/sdf_shader.hpp b/include/mbgl/shader/sdf_shader.hpp deleted file mode 100644 index 0737c25ee1..0000000000 --- a/include/mbgl/shader/sdf_shader.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef MBGL_SHADER_SDF_SHADER -#define MBGL_SHADER_SDF_SHADER - -#include <mbgl/shader/shader.hpp> -#include <mbgl/shader/uniform.hpp> - -namespace mbgl { - -class SDFShader : public Shader { -public: - SDFShader(); - - virtual void bind(char *offset) = 0; - - UniformMatrix<4> u_matrix = {"u_matrix", *this}; - UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; - Uniform<std::array<float, 4>> u_color = {"u_color", *this}; - Uniform<std::array<float, 2>> u_texsize = {"u_texsize", *this}; - Uniform<float> u_buffer = {"u_buffer", *this}; - Uniform<float> u_gamma = {"u_gamma", *this}; - Uniform<float> u_angle = {"u_angle", *this}; - Uniform<float> u_zoom = {"u_zoom", *this}; - Uniform<float> u_flip = {"u_flip", *this}; - Uniform<float> u_fadedist = {"u_fadedist", *this}; - Uniform<float> u_minfadezoom = {"u_minfadezoom", *this}; - Uniform<float> u_maxfadezoom = {"u_maxfadezoom", *this}; - Uniform<float> u_fadezoom = {"u_fadezoom", *this}; - -protected: - int32_t a_pos = -1; - int32_t a_offset = -1; - int32_t a_tex = -1; - int32_t a_angle = -1; - int32_t a_minzoom = -1; - int32_t a_maxzoom = -1; - int32_t a_rangeend = -1; - int32_t a_rangestart = -1; - int32_t a_labelminzoom = -1; -}; - -class SDFGlyphShader : public SDFShader { -public: - void bind(char *offset); -}; - -class SDFIconShader : public SDFShader { -public: - void bind(char *offset); -}; - -} - -#endif diff --git a/include/mbgl/shader/shader.hpp b/include/mbgl/shader/shader.hpp deleted file mode 100644 index 27e831a510..0000000000 --- a/include/mbgl/shader/shader.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MBGL_RENDERER_SHADER -#define MBGL_RENDERER_SHADER - -#include <cstdint> -#include <array> -#include <mbgl/util/noncopyable.hpp> - -namespace mbgl { - -class Shader : private util::noncopyable { -public: - Shader(const char *name, const char *vertex, const char *fragment); - ~Shader(); - const char *name; - bool valid; - uint32_t program; - - inline uint32_t getID() const { - return program; - } - -private: - bool compileShader(uint32_t *shader, uint32_t type, const char *source); -}; - -} - -#endif diff --git a/include/mbgl/shader/uniform.hpp b/include/mbgl/shader/uniform.hpp deleted file mode 100644 index a87bbd7aa3..0000000000 --- a/include/mbgl/shader/uniform.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef MBGL_SHADER_UNIFORM -#define MBGL_SHADER_UNIFORM - -#include <mbgl/shader/shader.hpp> -#include <mbgl/platform/gl.hpp> - -namespace mbgl { - -template <typename T> -class Uniform { -public: - Uniform(const GLchar* name, const Shader& shader) - : location(glGetUniformLocation(shader.program, name)) {} - - void operator=(const T& t) { - if (current != t) { - current = t; - bind(t); - } - } - -private: - void bind(const T&); - - T current; - GLint location; -}; - -template <size_t C, size_t R = C> -class UniformMatrix { -public: - typedef std::array<float, C*R> T; - - UniformMatrix(const GLchar* name, const Shader& shader) - : location(glGetUniformLocation(shader.program, name)) {} - - void operator=(const T& t) { - if (current != t) { - current = t; - bind(t); - } - } - -private: - void bind(const T&); - - T current; - GLint location; -}; - -} - -#endif diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp deleted file mode 100644 index 2913c5eae5..0000000000 --- a/include/mbgl/storage/base_request.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef MBGL_STORAGE_BASE_REQUEST -#define MBGL_STORAGE_BASE_REQUEST - -#include <mbgl/storage/request_callback.hpp> -#include <mbgl/util/ptr.hpp> - -#include <string> -#include <forward_list> -#include <functional> -#include <thread> - -typedef struct uv_loop_s uv_loop_t; -typedef struct uv_async_s uv_async_t; - -namespace mbgl { - -class Response; -class Request; - -class BaseRequest { -private: - // Make noncopyable and immovable - BaseRequest(const BaseRequest &) = delete; - BaseRequest(BaseRequest &&) = delete; - BaseRequest& operator=(const BaseRequest &) = delete; - BaseRequest& operator=(BaseRequest &&) = delete; - -public: - BaseRequest(const std::string &path); - virtual ~BaseRequest(); - - Callback *add(Callback &&callback, const util::ptr<BaseRequest> &request); - void remove(Callback *callback); - - // Must be called by subclasses when a valid Response object is available. It will notify - // all listeners. - void notify(); - - // This function is called when the request ought to be stopped. Any subclass must make sure this - // is also called in its destructor. Calling this function repeatedly must be safe. - // This function must call notify(). - virtual void cancel() = 0; - - // This function is called when the request should be reattempted immediately. This is typically - // reaction to a network status change. - virtual void retryImmediately(); - -public: - const std::thread::id thread_id; - const std::string path; - std::unique_ptr<Response> response; - -protected: - // This object may hold a shared_ptr to itself. It does this to prevent destruction of this object - // while a request is in progress. - util::ptr<BaseRequest> self; - std::forward_list<std::unique_ptr<Callback>> callbacks; -}; - -} - -#endif diff --git a/include/mbgl/platform/default/caching_http_file_source.hpp b/include/mbgl/storage/caching_http_file_source.hpp index c394474881..a093ef2441 100644 --- a/include/mbgl/platform/default/caching_http_file_source.hpp +++ b/include/mbgl/storage/caching_http_file_source.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_STORAGE_CACHING_HTTP_FILE_SOURCE #define MBGL_STORAGE_CACHING_HTTP_FILE_SOURCE -#include <mbgl/storage/file_source.hpp> +#include "file_source.hpp" #include <thread> #include <unordered_map> @@ -16,7 +16,7 @@ class SQLiteStore; class CachingHTTPFileSource : public FileSource { public: CachingHTTPFileSource(const std::string &path_); - ~CachingHTTPFileSource(); + virtual ~CachingHTTPFileSource(); // Stores and checks the libuv loop for requests void setLoop(uv_loop_t*); diff --git a/include/mbgl/storage/file_request.hpp b/include/mbgl/storage/file_request.hpp deleted file mode 100644 index 2f883728ff..0000000000 --- a/include/mbgl/storage/file_request.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MBGL_STORAGE_FILE_REQUEST -#define MBGL_STORAGE_FILE_REQUEST - -#include <mbgl/storage/base_request.hpp> - -namespace mbgl { - -typedef struct uv_loop_s uv_loop_t; - -struct FileRequestBaton; - -class FileRequest : public BaseRequest { -public: - FileRequest(const std::string &path, uv_loop_t *loop); - ~FileRequest(); - - void cancel(); - -private: - FileRequestBaton *ptr = nullptr; - - friend struct FileRequestBaton; -}; - -} - -#endif
\ No newline at end of file diff --git a/include/mbgl/storage/file_request_baton.hpp b/include/mbgl/storage/file_request_baton.hpp deleted file mode 100644 index 897c88061d..0000000000 --- a/include/mbgl/storage/file_request_baton.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MBGL_STORAGE_FILE_REQUEST_BATON -#define MBGL_STORAGE_FILE_REQUEST_BATON - -#include <mbgl/storage/file_request.hpp> -#include <thread> - -#include <uv.h> - -namespace mbgl { - -struct FileRequestBaton { - FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop); - ~FileRequestBaton(); - - void cancel(); - static void file_opened(uv_fs_t *req); - static void file_stated(uv_fs_t *req); - static void file_read(uv_fs_t *req); - static void file_closed(uv_fs_t *req); - static void notify_error(uv_fs_t *req); - static void cleanup(uv_fs_t *req); - - const std::thread::id thread_id; - FileRequest *request = nullptr; - uv_fs_t req; - uv_file fd = -1; - bool canceled = false; - std::string body; - uv_buf_t buffer; -}; - - -} - - -#endif diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index e825a9d61c..eeda529bf1 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -2,14 +2,15 @@ #define MBGL_STORAGE_FILE_SOURCE #include <mbgl/util/noncopyable.hpp> -#include <mbgl/storage/resource_type.hpp> -#include <mbgl/storage/request.hpp> +#include "resource_type.hpp" +#include "request.hpp" #include <string> #include <functional> typedef struct uv_loop_s uv_loop_t; + namespace mbgl { class FileSource : public util::noncopyable { diff --git a/include/mbgl/storage/http_request.hpp b/include/mbgl/storage/http_request.hpp deleted file mode 100644 index 71d6e8814c..0000000000 --- a/include/mbgl/storage/http_request.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef MBGL_STORAGE_HTTP_REQUEST -#define MBGL_STORAGE_HTTP_REQUEST - -#include <mbgl/storage/resource_type.hpp> -#include <mbgl/storage/base_request.hpp> -#include <mbgl/storage/http_request_baton.hpp> - -#include <string> -#include <memory> -#include <cassert> -#include <thread> - -typedef struct uv_loop_s uv_loop_t; -typedef struct uv_timer_s uv_timer_t; - -namespace mbgl { - -struct CacheRequestBaton; -struct HTTPRequestBaton; -struct CacheEntry; -class SQLiteStore; - -class HTTPRequest : public BaseRequest { -public: - HTTPRequest(ResourceType type, const std::string &path, uv_loop_t *loop, util::ptr<SQLiteStore> store); - ~HTTPRequest(); - - void cancel(); - void retryImmediately(); - -private: - void startCacheRequest(); - void handleCacheResponse(std::unique_ptr<Response> &&response); - void startHTTPRequest(std::unique_ptr<Response> &&res); - void handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr<Response> &&response); - - void retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t timeout); - - void removeCacheBaton(); - void removeHTTPBaton(); - void removeBackoffTimer(); - -private: - const std::thread::id thread_id; - uv_loop_t *const loop; - CacheRequestBaton *cache_baton = nullptr; - util::ptr<HTTPRequestBaton> http_baton; - uv_timer_t *backoff_timer = nullptr; - util::ptr<SQLiteStore> store; - const ResourceType type; - uint8_t attempts = 0; - - friend struct HTTPRequestBaton; -}; - -} - -#endif
\ No newline at end of file diff --git a/include/mbgl/storage/http_request_baton.hpp b/include/mbgl/storage/http_request_baton.hpp index 545f9e236c..74c0ff498e 100644 --- a/include/mbgl/storage/http_request_baton.hpp +++ b/include/mbgl/storage/http_request_baton.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_STORAGE_HTTP_REQUEST_BATON #define MBGL_STORAGE_HTTP_REQUEST_BATON -#include <mbgl/storage/response.hpp> +#include "response.hpp" #include <mbgl/util/ptr.hpp> #include <string> diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp index 11b5541d18..f63283aa2f 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -1,8 +1,9 @@ #ifndef MBGL_STORAGE_REQUEST #define MBGL_STORAGE_REQUEST -#include <mbgl/storage/request_callback.hpp> -#include <mbgl/storage/response.hpp> +#include "request_callback.hpp" +#include "response.hpp" + #include <mbgl/util/ptr.hpp> #include <thread> diff --git a/include/mbgl/storage/sqlite_store.hpp b/include/mbgl/storage/sqlite_store.hpp deleted file mode 100644 index a691b474e0..0000000000 --- a/include/mbgl/storage/sqlite_store.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef MBGL_STORAGE_SQLITE_STORE -#define MBGL_STORAGE_SQLITE_STORE - -#include <mbgl/storage/file_source.hpp> -#include <mbgl/storage/response.hpp> - -#include <uv.h> - -#include <string> -#include <thread> - -typedef struct uv_worker_s uv_worker_t; - -namespace mapbox { -namespace sqlite { -class Database; -} -} - -namespace mbgl { - -class SQLiteStore { -public: - SQLiteStore(uv_loop_t *loop, const std::string &path); - ~SQLiteStore(); - - typedef void (*GetCallback)(std::unique_ptr<Response> &&entry, void *ptr); - - void get(const std::string &path, GetCallback cb, void *ptr); - void put(const std::string &path, ResourceType type, const Response &entry); - void updateExpiration(const std::string &path, int64_t expires); - -private: - void createSchema(); - void closeDatabase(); - static void runGet(uv_work_t *req); - static void runPut(uv_work_t *req); - static void deliverResult(uv_work_t *req, int status); - -private: - const std::thread::id thread_id; - util::ptr<mapbox::sqlite::Database> db; - uv_worker_t *worker = nullptr; -}; - -} - -#endif diff --git a/include/mbgl/style/applied_class_properties.hpp b/include/mbgl/style/applied_class_properties.hpp deleted file mode 100644 index 827f15a2a1..0000000000 --- a/include/mbgl/style/applied_class_properties.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MBGL_STYLE_APPLIED_CLASS_PROPERTIES -#define MBGL_STYLE_APPLIED_CLASS_PROPERTIES - -#include <mbgl/style/property_value.hpp> -#include <mbgl/style/class_dictionary.hpp> -#include <mbgl/util/time.hpp> - -#include <list> - -namespace mbgl { - -class AppliedClassProperty { -public: - AppliedClassProperty(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value); - -public: - const ClassID name; - const timestamp begin; - const timestamp end; - const PropertyValue value; -}; - - -class AppliedClassProperties { -public: - std::list<AppliedClassProperty> properties; - -public: - // Returns thie ID of the most recent - ClassID mostRecent() const; - void add(ClassID class_id, timestamp begin, timestamp end, const PropertyValue &value); - bool hasTransitions() const; - void cleanup(timestamp now); - bool empty() const; -}; - -} - -#endif diff --git a/include/mbgl/style/class_dictionary.hpp b/include/mbgl/style/class_dictionary.hpp deleted file mode 100644 index ecf80be3e3..0000000000 --- a/include/mbgl/style/class_dictionary.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef MBGL_STYLE_CLASS_DICTIONARY -#define MBGL_STYLE_CLASS_DICTIONARY - -#include <cstdint> -#include <string> -#include <unordered_map> - -namespace mbgl { - -enum class ClassID : uint32_t { - Fallback = 0, // These values are from the fallback properties - Default = 1, // These values are from the default style for a layer - Named = 2 // These values (and all subsequent IDs) are from a named style from the layer -}; - -class ClassDictionary { -private: - ClassDictionary(); - -public: - static ClassDictionary &Get(); - - // Returns an ID for a class name. If the class name does not yet have an ID, one is - // auto-generated and stored for future reference. - ClassID lookup(const std::string &class_name); - - // Returns either Fallback, Default or Named, depending on the type of the class id. - ClassID normalize(ClassID id); - -private: - std::unordered_map<std::string, ClassID> store = { { "", ClassID::Default } }; - uint32_t offset = 0; -}; - -} - -#endif diff --git a/include/mbgl/style/class_properties.hpp b/include/mbgl/style/class_properties.hpp deleted file mode 100644 index 888a90c5d7..0000000000 --- a/include/mbgl/style/class_properties.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MBGL_STYLE_CLASS_PROPERTIES -#define MBGL_STYLE_CLASS_PROPERTIES - -#include <mbgl/style/property_key.hpp> -#include <mbgl/style/property_value.hpp> -#include <mbgl/style/property_transition.hpp> - -#include <map> - -namespace mbgl { - -class ClassProperties { -public: - inline ClassProperties() {} - inline ClassProperties(ClassProperties &&properties_) - : properties(std::move(properties_.properties)) {} - - inline void set(PropertyKey key, const PropertyValue &value) { - properties.emplace(key, value); - } - - inline void set(PropertyKey key, const PropertyTransition &transition) { - transitions.emplace(key, transition); - } - - const PropertyTransition &getTransition(PropertyKey key, const PropertyTransition &defaultTransition) const; - - // Route-through iterable interface so that you can iterate on the object as is. - inline std::map<PropertyKey, PropertyValue>::const_iterator begin() const { - return properties.begin(); - } - inline std::map<PropertyKey, PropertyValue>::const_iterator end() const { - return properties.end(); - } - -public: - std::map<PropertyKey, PropertyValue> properties; - std::map<PropertyKey, PropertyTransition> transitions; -}; - -} - -#endif diff --git a/include/mbgl/style/filter_expression.hpp b/include/mbgl/style/filter_expression.hpp deleted file mode 100644 index 8c6f447770..0000000000 --- a/include/mbgl/style/filter_expression.hpp +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef MBGL_STYLE_FILTER_EXPRESSION -#define MBGL_STYLE_FILTER_EXPRESSION - -#include <mbgl/style/value.hpp> - -#include <rapidjson/document.h> - -#include <string> -#include <vector> - -namespace mbgl { - -typedef mapbox::util::variant< - struct NullExpression, - struct EqualsExpression, - struct NotEqualsExpression, - struct LessThanExpression, - struct LessThanEqualsExpression, - struct GreaterThanExpression, - struct GreaterThanEqualsExpression, - struct InExpression, - struct NotInExpression, - struct AnyExpression, - struct AllExpression, - struct NoneExpression - > FilterExpression; - -FilterExpression parseFilterExpression(const rapidjson::Value&); - -template <class Extractor> -bool evaluate(const FilterExpression&, const Extractor&); - -struct NullExpression { - template <class Extractor> - bool evaluate(const Extractor&) const { return true; } -}; - -struct EqualsExpression { - std::string key; - Value value; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct NotEqualsExpression { - std::string key; - Value value; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct LessThanExpression { - std::string key; - Value value; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct LessThanEqualsExpression { - std::string key; - Value value; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct GreaterThanExpression { - std::string key; - Value value; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct GreaterThanEqualsExpression { - std::string key; - Value value; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct InExpression { - std::string key; - std::vector<Value> values; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct NotInExpression { - std::string key; - std::vector<Value> values; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct AnyExpression { - std::vector<FilterExpression> expressions; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct AllExpression { - std::vector<FilterExpression> expressions; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -struct NoneExpression { - std::vector<FilterExpression> expressions; - - template <class Extractor> - bool evaluate(const Extractor&) const; -}; - -} - -#endif diff --git a/include/mbgl/style/filter_expression_private.hpp b/include/mbgl/style/filter_expression_private.hpp deleted file mode 100644 index 381f8f617c..0000000000 --- a/include/mbgl/style/filter_expression_private.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#include <mbgl/util/optional.hpp> -#include <mbgl/style/value_comparison.hpp> - -namespace mbgl { - -template <class Extractor> -struct Evaluator : public mapbox::util::static_visitor<bool> -{ - const Extractor& extractor; - - Evaluator(const Extractor& extractor_) - : extractor(extractor_) {} - - template <class E> - bool operator()(const E& e) const { return e.evaluate(extractor); } -}; - -template <class Extractor> -bool evaluate(const FilterExpression& expression, const Extractor& extractor) { - return mapbox::util::apply_visitor(Evaluator<Extractor>(extractor), expression); -}; - -template <class Extractor> -bool EqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - return actual && util::relaxed_equal(*actual, value); -} - -template <class Extractor> -bool NotEqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - return !actual || util::relaxed_not_equal(*actual, value); -} - -template <class Extractor> -bool LessThanExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - return actual && util::relaxed_less(*actual, value); -} - -template <class Extractor> -bool LessThanEqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - return actual && util::relaxed_less_equal(*actual, value); -} - -template <class Extractor> -bool GreaterThanExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - return actual && util::relaxed_greater(*actual, value); -} - -template <class Extractor> -bool GreaterThanEqualsExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - return actual && util::relaxed_greater_equal(*actual, value); -} - -template <class Extractor> -bool InExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - if (!actual) - return false; - for (const auto& v: values) { - if (util::relaxed_equal(*actual, v)) { - return true; - } - } - return false; -} - -template <class Extractor> -bool NotInExpression::evaluate(const Extractor& extractor) const { - mapbox::util::optional<Value> actual = extractor.getValue(key); - if (!actual) - return true; - for (const auto& v: values) { - if (util::relaxed_equal(*actual, v)) { - return false; - } - } - return true; -} - -template <class Extractor> -bool AnyExpression::evaluate(const Extractor& extractor) const { - Evaluator<Extractor> evaluator(extractor); - for (const auto& e: expressions) { - if (mapbox::util::apply_visitor(evaluator, e)) { - return true; - } - } - return false; -} - -template <class Extractor> -bool AllExpression::evaluate(const Extractor& extractor) const { - Evaluator<Extractor> evaluator(extractor); - for (const auto& e: expressions) { - if (!mapbox::util::apply_visitor(evaluator, e)) { - return false; - } - } - return true; -} - -template <class Extractor> -bool NoneExpression::evaluate(const Extractor& extractor) const { - Evaluator<Extractor> evaluator(extractor); - for (const auto& e: expressions) { - if (mapbox::util::apply_visitor(evaluator, e)) { - return false; - } - } - return true; -} - -} diff --git a/include/mbgl/style/function_properties.hpp b/include/mbgl/style/function_properties.hpp deleted file mode 100644 index 924f192330..0000000000 --- a/include/mbgl/style/function_properties.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef MBGL_STYLE_FUNCTION_PROPERTIES -#define MBGL_STYLE_FUNCTION_PROPERTIES - -#include <mbgl/util/variant.hpp> - -#include <vector> - -namespace mbgl { - -template <typename T> -struct ConstantFunction { - inline ConstantFunction(const T &value_) : value(value_) {} - inline T evaluate(float) const { return value; } - -private: - const T value; -}; - -template <typename T> -struct StopsFunction { - inline StopsFunction(const std::vector<std::pair<float, T>> &values_, float base_) : values(values_), base(base_) {} - T evaluate(float z) const; - -private: - const std::vector<std::pair<float, T>> values; - const float base; -}; - -template <typename T> -using Function = mapbox::util::variant< - std::false_type, - ConstantFunction<T>, - StopsFunction<T> ->; - -template <typename T> -struct FunctionEvaluator { - typedef T result_type; - inline FunctionEvaluator(float z_) : z(z_) {} - - inline result_type operator()(const std::false_type &) { - return result_type(); - } - - template <template <typename> class Fn> - inline result_type operator()(const Fn<T>& fn) { - return fn.evaluate(z); - } -private: - float z; -}; - -} - -#endif diff --git a/include/mbgl/style/property_fallback.hpp b/include/mbgl/style/property_fallback.hpp deleted file mode 100644 index 5c5eae0cd6..0000000000 --- a/include/mbgl/style/property_fallback.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_FALLBACK -#define MBGL_STYLE_PROPERTY_FALLBACK - -#include <mbgl/style/property_key.hpp> -#include <mbgl/style/property_value.hpp> - -#include <map> - -namespace mbgl { - -class PropertyFallbackValue { -public: - static const PropertyValue &Get(PropertyKey key) { - auto it = properties.find(key); - if (it != properties.end()) { - return it->second; - } else { - return defaultProperty; - } - } - -private: - static const std::map<PropertyKey, PropertyValue> properties; - static const PropertyValue defaultProperty; -}; - -} - -#endif diff --git a/include/mbgl/style/property_key.hpp b/include/mbgl/style/property_key.hpp deleted file mode 100644 index efeebf0242..0000000000 --- a/include/mbgl/style/property_key.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_KEY -#define MBGL_STYLE_PROPERTY_KEY - -namespace mbgl { - -enum class PropertyKey { - FillAntialias, - FillOpacity, - FillColor, - FillOutlineColor, - FillTranslate, // for transitions only - FillTranslateX, - FillTranslateY, - FillTranslateAnchor, - FillImage, - - LineOpacity, - LineColor, - LineTranslate, // for transitions only - LineTranslateX, - LineTranslateY, - LineTranslateAnchor, - LineWidth, - LineGapWidth, - LineBlur, - LineDashArray, // for transitions only - LineDashLand, - LineDashGap, - LineImage, - - IconOpacity, - IconRotate, - IconSize, - IconColor, - IconHaloColor, - IconHaloWidth, - IconHaloBlur, - IconTranslate, // for transitions only - IconTranslateX, - IconTranslateY, - IconTranslateAnchor, - - TextOpacity, - TextSize, - TextColor, - TextHaloColor, - TextHaloWidth, - TextHaloBlur, - TextTranslate, // for transitions only - TextTranslateX, - TextTranslateY, - TextTranslateAnchor, - - RasterOpacity, - RasterHueRotate, - RasterBrightness, // for transitions only - RasterBrightnessLow, - RasterBrightnessHigh, - RasterSaturation, - RasterContrast, - RasterFade, - - BackgroundOpacity, - BackgroundColor, - BackgroundImage -}; - -} - -#endif diff --git a/include/mbgl/style/property_transition.hpp b/include/mbgl/style/property_transition.hpp deleted file mode 100644 index 07b7cfe288..0000000000 --- a/include/mbgl/style/property_transition.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_TRANSITION -#define MBGL_STYLE_PROPERTY_TRANSITION - -#include <cstdint> - -namespace mbgl { - -struct PropertyTransition { - uint16_t duration = 0; - uint16_t delay = 0; -}; - -} - -#endif
\ No newline at end of file diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp deleted file mode 100644 index 1b22b31177..0000000000 --- a/include/mbgl/style/property_value.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_VALUE -#define MBGL_STYLE_PROPERTY_VALUE - -#include <mbgl/util/variant.hpp> -#include <mbgl/style/function_properties.hpp> -#include <mbgl/style/types.hpp> - -namespace mbgl { - -typedef mapbox::util::variant< - std::string, - TranslateAnchorType, - RotateAnchorType, - Function<bool>, - Function<float>, - Function<Color> -> PropertyValue; - -} - -#endif diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp deleted file mode 100644 index 56f318ecbb..0000000000 --- a/include/mbgl/style/style.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef MBGL_STYLE_STYLE -#define MBGL_STYLE_STYLE - -#include <mbgl/style/property_transition.hpp> -#include <mbgl/style/style_source.hpp> - -#include <mbgl/util/time.hpp> -#include <mbgl/util/uv.hpp> -#include <mbgl/util/ptr.hpp> - -#include <cstdint> -#include <map> -#include <string> -#include <unordered_map> -#include <vector> -#include <set> - -namespace mbgl { - -class Sprite; -class StyleLayer; -class StyleLayerGroup; - -class Style { -public: - struct exception : std::runtime_error { exception(const char *msg) : std::runtime_error(msg) {} }; - -public: - Style(); - ~Style(); - - void loadJSON(const uint8_t *const data); - - size_t layerCount() const; - void updateProperties(float z, timestamp t); - - void setDefaultTransitionDuration(uint16_t duration_milliseconds = 0); - - void setAppliedClasses(const std::vector<std::string> &classes); - const std::vector<std::string> &getAppliedClasses() const; - void toggleClass(const std::string &name); - - // Updates the styling information to reflect the current array - // of applied classes. - void updateClasses(); - - bool hasTransitions() const; - - const std::string &getSpriteURL() const; - -public: - util::ptr<StyleLayerGroup> layers; - std::vector<std::string> appliedClasses; - std::string glyph_url; - -private: - std::string sprite_url; - -private: - PropertyTransition defaultTransition; - bool initial_render_complete = false; - - std::unique_ptr<uv::rwlock> mtx; -}; - -} - -#endif diff --git a/include/mbgl/style/style_bucket.hpp b/include/mbgl/style/style_bucket.hpp deleted file mode 100644 index d84d35d5b2..0000000000 --- a/include/mbgl/style/style_bucket.hpp +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_BUCKET -#define MBGL_STYLE_STYLE_BUCKET - -#include <mbgl/style/types.hpp> -#include <mbgl/style/filter_expression.hpp> -#include <mbgl/style/style_source.hpp> - -#include <mbgl/util/vec.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/ptr.hpp> - -#include <forward_list> - -namespace mbgl { - -class Source; - -class StyleBucketFill { -public: - WindingType winding = WindingType::NonZero; -}; - -class StyleBucketLine { -public: - CapType cap = CapType::Butt; - JoinType join = JoinType::Miter; - float miter_limit = 2.0f; - float round_limit = 1.0f; -}; - -class StyleBucketSymbol { -public: - // Make movable only. - inline StyleBucketSymbol() = default; - inline StyleBucketSymbol(StyleBucketSymbol &&) = default; - inline StyleBucketSymbol& operator=(StyleBucketSymbol &&) = default; - inline StyleBucketSymbol(const StyleBucketSymbol &) = delete; - inline StyleBucketSymbol& operator=(const StyleBucketSymbol &) = delete; - - PlacementType placement = PlacementType::Point; - float min_distance = 250.0f; - bool avoid_edges = false; - - struct { - bool allow_overlap = false; - bool ignore_placement = false; - bool optional = false; - RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport; - float max_size = 1.0f; - std::string image; - float rotate = 0.0f; - float padding = 2.0f; - bool keep_upright = false; - vec2<float> offset = {0, 0}; - } icon; - - struct { - RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport; - std::string field; - std::string font; - float max_size = 16.0f; - float max_width = 15.0f * 24 /* em */; - float line_height = 1.2f * 24 /* em */; - float letter_spacing = 0.0f * 24 /* em */; - TextJustifyType justify = TextJustifyType::Center; - TextAnchorType anchor = TextAnchorType::Center; - float max_angle = 45.0f /* degrees */; - float rotate = 0.0f; - float slant = 0.0f; - float padding = 2.0f; - bool keep_upright = true; - TextTransformType transform = TextTransformType::None; - vec2<float> offset = {0, 0}; - bool allow_overlap = false; - bool ignore_placement = false; - bool optional = false; - } text; -}; - -class StyleBucketRaster { -public: - bool prerendered = false; - uint16_t size = 256; - float blur = 0.0f; - float buffer = 0.03125f; -}; - -typedef mapbox::util::variant<StyleBucketFill, StyleBucketLine, StyleBucketSymbol, - StyleBucketRaster, std::false_type> StyleBucketRender; - - -class StyleBucket { -public: - typedef util::ptr<StyleBucket> Ptr; - - StyleBucket(StyleLayerType type); - - std::string name; - util::ptr<StyleSource> style_source; - std::string source_layer; - FilterExpression filter; - StyleBucketRender render = std::false_type(); - float min_zoom = -std::numeric_limits<float>::infinity(); - float max_zoom = std::numeric_limits<float>::infinity(); -}; - - - -}; - -#endif diff --git a/include/mbgl/style/style_layer.hpp b/include/mbgl/style/style_layer.hpp deleted file mode 100644 index 641dc1e71c..0000000000 --- a/include/mbgl/style/style_layer.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_LAYER -#define MBGL_STYLE_STYLE_LAYER - -#include <mbgl/style/class_dictionary.hpp> -#include <mbgl/style/class_properties.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/applied_class_properties.hpp> - -#include <mbgl/util/ptr.hpp> - -#include <vector> -#include <string> -#include <map> -#include <set> - -namespace mbgl { - -class StyleBucket; -class StyleLayerGroup; - -class StyleLayer { -public: - StyleLayer(const std::string &id, std::map<ClassID, ClassProperties> &&styles); - - template <typename T> const T &getProperties() { - if (properties.is<T>()) { - return properties.get<T>(); - } else { - return defaultStyleProperties<T>(); - } - } - - // Determines whether this layer is the background layer. - bool isBackground() const; - - // Updates the StyleProperties information in this layer by evaluating all - // pending transitions and applied classes in order. - void updateProperties(float z, timestamp now); - - // Sets the list of classes and creates transitions to the currently applied values. - void setClasses(const std::vector<std::string> &class_names, timestamp now, - const PropertyTransition &defaultTransition); - - bool hasTransitions() const; - -private: - // Applies all properties from a class, if they haven't been applied already. - void applyClassProperties(ClassID class_id, std::set<PropertyKey> &already_applied, - timestamp now, const PropertyTransition &defaultTransition); - - // Sets the properties of this object by evaluating all pending transitions and - // aplied classes in order. - template <typename T> void applyStyleProperties(float z, timestamp now); - template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, timestamp now); - template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, timestamp now); - - // Removes all expired style transitions. - void cleanupAppliedStyleProperties(timestamp now); - -public: - // The name of this layer. - const std::string id; - - StyleLayerType type = StyleLayerType::Unknown; - - // Bucket information, telling the renderer how to generate the geometries - // for this layer (feature property filters, tessellation instructions, ...). - util::ptr<StyleBucket> bucket; - - // Contains all style classes that can be applied to this layer. - const std::map<ClassID, ClassProperties> styles; - -private: - // For every property, stores a list of applied property values, with - // optional transition times. - std::map<PropertyKey, AppliedClassProperties> appliedStyle; - -public: - // Stores the evaluated, and cascaded styling information, specific to this - // layer's type. - StyleProperties properties; - - // Child layer array (if this layer has child layers). - util::ptr<StyleLayerGroup> layers; -}; - -} - -#endif diff --git a/include/mbgl/style/style_layer_group.hpp b/include/mbgl/style/style_layer_group.hpp deleted file mode 100644 index 1af6e23bd7..0000000000 --- a/include/mbgl/style/style_layer_group.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_LAYER_GROUP -#define MBGL_STYLE_STYLE_LAYER_GROUP - -#include <mbgl/style/style_layer.hpp> - -#include <vector> - -namespace mbgl { - -class StyleLayerGroup { -public: - void setClasses(const std::vector<std::string> &class_names, timestamp now, - const PropertyTransition &defaultTransition); - void updateProperties(float z, timestamp t); - - bool hasTransitions() const; -public: - std::vector<util::ptr<StyleLayer>> layers; -}; - -} - -#endif diff --git a/include/mbgl/style/style_parser.hpp b/include/mbgl/style/style_parser.hpp deleted file mode 100644 index c37e856034..0000000000 --- a/include/mbgl/style/style_parser.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_PARSER -#define MBGL_STYLE_STYLE_PARSER - -#include <rapidjson/document.h> -#include <mbgl/style/style.hpp> -#include <mbgl/style/style_source.hpp> -#include <mbgl/style/filter_expression.hpp> -#include <mbgl/style/class_properties.hpp> -#include <mbgl/style/style_bucket.hpp> - -#include <unordered_map> -#include <forward_list> -#include <tuple> - -namespace mbgl { - -enum class ClassID : uint32_t; - -class StyleLayer; -class StyleLayerGroup; - -class StyleParser { -public: - using JSVal = const rapidjson::Value&; - - StyleParser(); - - void parse(JSVal document); - - util::ptr<StyleLayerGroup> getLayers() { - return root; - } - - std::string getSprite() const { - return sprite; - } - - std::string getGlyphURL() const { - return glyph_url; - } - -private: - void parseConstants(JSVal value); - JSVal replaceConstant(JSVal value); - - void parseSources(JSVal value); - - std::unique_ptr<StyleLayerGroup> createLayers(JSVal value); - util::ptr<StyleLayer> createLayer(JSVal value); - void parseLayers(); - void parseLayer(std::pair<JSVal, util::ptr<StyleLayer>> &pair); - void parsePaints(JSVal value, std::map<ClassID, ClassProperties> &paints); - void parsePaint(JSVal, ClassProperties &properties); - void parseReference(JSVal value, util::ptr<StyleLayer> &layer); - void parseBucket(JSVal value, util::ptr<StyleLayer> &layer); - void parseLayout(JSVal value, util::ptr<StyleLayer> &layer); - void parseSprite(JSVal value); - void parseGlyphURL(JSVal value); - - // Parses optional properties into a render bucket. - template<typename T> - bool parseRenderProperty(JSVal value, T &target, const char *name); - template <typename Parser, typename T> - bool parseRenderProperty(JSVal value, T &target, const char *name); - - // Parses optional properties into style class properties. - template <typename T> - bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value); - template <typename T> - bool parseOptionalProperty(const char *property_name, const std::vector<PropertyKey> &keys, ClassProperties &klass, JSVal value); - template <typename T> - bool parseOptionalProperty(const char *property_name, T &target, JSVal value); - template <typename T> - bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass); - template <typename T> - bool setProperty(JSVal value, const char *property_name, T &target); - - template <typename T> - std::tuple<bool, T> parseProperty(JSVal value, const char *property_name); - - template <typename T> - bool parseFunction(PropertyKey key, ClassProperties &klass, JSVal value); - template <typename T> - std::tuple<bool, Function<T>> parseFunction(JSVal value); - template <typename T> - T parseFunctionArgument(JSVal value); - - FilterExpression parseFilter(JSVal); - -private: - std::unordered_map<std::string, const rapidjson::Value *> constants; - - std::unordered_map<std::string, const util::ptr<StyleSource>> sources; - - // This stores the root layer. - util::ptr<StyleLayerGroup> root; - - // This maps ids to Layer objects, with all items being at the root level. - std::unordered_map<std::string, std::pair<JSVal, util::ptr<StyleLayer>>> layers; - - // Store a stack of layers we're parsing right now. This is to prevent reference cycles. - std::forward_list<StyleLayer *> stack; - - // Base URL of the sprite image. - std::string sprite; - - // URL template for glyph PBFs. - std::string glyph_url; -}; - -} - -#endif diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp deleted file mode 100644 index c44b7c34c8..0000000000 --- a/include/mbgl/style/style_properties.hpp +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_PROPERTIES -#define MBGL_STYLE_STYLE_PROPERTIES - -#include <mbgl/util/variant.hpp> -#include <mbgl/style/types.hpp> -#include <mbgl/style/function_properties.hpp> - -#include <array> -#include <string> -#include <type_traits> -#include <memory> - -namespace mbgl { - -struct FillProperties { - FillProperties() {} - bool antialias = true; - float opacity = 1.0f; - Color fill_color = {{ 0, 0, 0, 1 }}; - Color stroke_color = {{ 0, 0, 0, -1 }}; - std::array<float, 2> translate = {{ 0, 0 }}; - TranslateAnchorType translateAnchor = TranslateAnchorType::Map; - std::string image; - - inline bool isVisible() const { - return opacity > 0 && (fill_color[3] > 0 || stroke_color[3] > 0); - } -}; - -struct LineProperties { - inline LineProperties() {} - float opacity = 1.0f; - Color color = {{ 0, 0, 0, 1 }}; - std::array<float, 2> translate = {{ 0, 0 }}; - TranslateAnchorType translateAnchor = TranslateAnchorType::Map; - float width = 1; - float gap_width = 0; - float blur = 0; - std::array<float, 2> dash_array = {{ 1, -1 }}; - std::string image; - - inline bool isVisible() const { - return opacity > 0 && color[3] > 0 && width > 0; - } -}; - -struct SymbolProperties { - inline SymbolProperties() {} - - struct { - float opacity = 1.0f; - float rotate = 0.0f; - float size = 1.0f; - Color color = {{ 0, 0, 0, 1 }}; - Color halo_color = {{ 0, 0, 0, 0 }}; - float halo_width = 0.0f; - float halo_blur = 0.0f; - std::array<float, 2> translate = {{ 0, 0 }}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Map; - } icon; - - struct { - float opacity = 1.0f; - float size = 16.0f; - Color color = {{ 0, 0, 0, 1 }}; - Color halo_color = {{ 0, 0, 0, 0 }}; - float halo_width = 0.0f; - float halo_blur = 0.0f; - std::array<float, 2> translate = {{ 0, 0 }}; - TranslateAnchorType translate_anchor = TranslateAnchorType::Map; - } text; - - inline bool isVisible() const { - return (icon.opacity > 0 && (icon.color[3] > 0 || icon.halo_color[3] > 0) && icon.size > 0) || - (text.opacity > 0 && (text.color[3] > 0 || text.halo_color[3] > 0) && text.size > 0); - } -}; - -struct RasterProperties { - inline RasterProperties() {} - float opacity = 1.0f; - float hue_rotate = 0.0f; - std::array<float, 2> brightness = {{ 0, 1 }}; - float saturation = 0.0f; - float contrast = 0.0f; - float fade = 0.0f; - - inline bool isVisible() const { - return opacity > 0; - } -}; - -struct BackgroundProperties { - inline BackgroundProperties() {} - float opacity = 1.0f; - Color color = {{ 0, 0, 0, 1 }}; - std::string image; -}; - -typedef mapbox::util::variant< - FillProperties, - LineProperties, - SymbolProperties, - RasterProperties, - BackgroundProperties, - std::false_type -> StyleProperties; - -template <typename T> -const T &defaultStyleProperties(); - -} - -#endif diff --git a/include/mbgl/style/style_source.hpp b/include/mbgl/style/style_source.hpp deleted file mode 100644 index 8c7d028880..0000000000 --- a/include/mbgl/style/style_source.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MBGL_STYLE_STYLE_SOURCE -#define MBGL_STYLE_STYLE_SOURCE - -#include <mbgl/style/types.hpp> -#include <mbgl/util/ptr.hpp> -#include <mbgl/util/noncopyable.hpp> -#include <rapidjson/document.h> - -#include <vector> -#include <string> - -namespace mbgl { - -class Source; - -class SourceInfo : private util::noncopyable { -public: - SourceType type = SourceType::Vector; - std::string url; - std::vector<std::string> tiles; - uint16_t tile_size = 512; - uint16_t min_zoom = 0; - uint16_t max_zoom = 22; - std::string attribution; - std::array<float, 3> center = {{0, 0, 0}}; - std::array<float, 4> bounds = {{-180, -90, 180, 90}}; - - void parseTileJSONProperties(const rapidjson::Value&); -}; - - -class StyleSource : private util::noncopyable { -public: - SourceInfo info; - bool enabled = false; - util::ptr<Source> source; -}; - -} - -#endif diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp deleted file mode 100644 index 2f7ca7683d..0000000000 --- a/include/mbgl/style/types.hpp +++ /dev/null @@ -1,196 +0,0 @@ -#ifndef MBGL_STYLE_TYPES -#define MBGL_STYLE_TYPES - -#include <mbgl/util/enum.hpp> - -#include <string> -#include <array> - -namespace mbgl { - -// Stores a premultiplied color, with all four channels ranging from 0..1 -typedef std::array<float, 4> Color; - -// ------------------------------------------------------------------------------------------------- - -enum class StyleLayerType : uint8_t { - Unknown, - Fill, - Line, - Symbol, - Raster, - Background -}; - -MBGL_DEFINE_ENUM_CLASS(StyleLayerTypeClass, StyleLayerType, { - { StyleLayerType::Unknown, "unknown" }, - { StyleLayerType::Fill, "fill" }, - { StyleLayerType::Line, "line" }, - { StyleLayerType::Symbol, "symbol" }, - { StyleLayerType::Raster, "raster" }, - { StyleLayerType::Background, "background" }, - { StyleLayerType(-1), "unknown" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class SourceType : uint8_t { - Vector, - Raster, - GeoJSON, - Video -}; - -MBGL_DEFINE_ENUM_CLASS(SourceTypeClass, SourceType, { - { SourceType::Vector, "vector" }, - { SourceType::Raster, "raster" }, - { SourceType::GeoJSON, "geojson" }, - { SourceType::Video, "video" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class WindingType : bool { - EvenOdd, - NonZero, -}; - -MBGL_DEFINE_ENUM_CLASS(WindingTypeClass, WindingType, { - { WindingType::EvenOdd, "even-odd" }, - { WindingType::NonZero, "non-zero" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class CapType : uint8_t { - Round, - Butt, - Square, -}; - -MBGL_DEFINE_ENUM_CLASS(CapTypeClass, CapType, { - { CapType::Round, "round" }, - { CapType::Butt, "butt" }, - { CapType::Square, "square" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class JoinType : uint8_t { - Miter, - Bevel, - Round -}; - -MBGL_DEFINE_ENUM_CLASS(JoinTypeClass, JoinType, { - { JoinType::Miter, "miter" }, - { JoinType::Bevel, "bevel" }, - { JoinType::Round, "round" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class TranslateAnchorType : bool { - Map, - Viewport -}; - -MBGL_DEFINE_ENUM_CLASS(TranslateAnchorTypeClass, TranslateAnchorType, { - { TranslateAnchorType::Map, "map" }, - { TranslateAnchorType::Viewport, "viewport" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class RotateAnchorType : bool { - Map, - Viewport, -}; - -MBGL_DEFINE_ENUM_CLASS(RotateAnchorTypeClass, RotateAnchorType, { - { RotateAnchorType::Map, "map" }, - { RotateAnchorType::Viewport, "viewport" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class PlacementType : bool { - Point, - Line, -}; - -MBGL_DEFINE_ENUM_CLASS(PlacementTypeClass, PlacementType, { - { PlacementType::Point, "point" }, - { PlacementType::Line, "line" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class RotationAlignmentType : bool { - Map, - Viewport, -}; - -MBGL_DEFINE_ENUM_CLASS(RotationAlignmentTypeClass, RotationAlignmentType, { - { RotationAlignmentType::Map, "map" }, - { RotationAlignmentType::Viewport, "viewport" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class TextJustifyType : uint8_t { - Center, - Left, - Right -}; - -MBGL_DEFINE_ENUM_CLASS(TextJustifyTypeClass, TextJustifyType, { - { TextJustifyType::Center, "center" }, - { TextJustifyType::Left, "left" }, - { TextJustifyType::Right, "right" }, -}); - -// ------------------------------------------------------------------------------------------------- - -enum class TextAnchorType : uint8_t { - Center, - Left, - Right, - Top, - Bottom, - TopLeft, - TopRight, - BottomLeft, - BottomRight -}; - -MBGL_DEFINE_ENUM_CLASS(TextAnchorTypeClass, TextAnchorType, { - { TextAnchorType::Center, "center" }, - { TextAnchorType::Left, "left" }, - { TextAnchorType::Right, "right" }, - { TextAnchorType::Top, "top" }, - { TextAnchorType::Bottom, "bottom" }, - { TextAnchorType::TopLeft, "top-left" }, - { TextAnchorType::TopRight, "top-right" }, - { TextAnchorType::BottomLeft, "bottom-left" }, - { TextAnchorType::BottomRight, "bottom-right" } -}); - -// ------------------------------------------------------------------------------------------------- - -enum class TextTransformType : uint8_t { - None, - Uppercase, - Lowercase, -}; - -MBGL_DEFINE_ENUM_CLASS(TextTransformTypeClass, TextTransformType, { - { TextTransformType::None, "none" }, - { TextTransformType::Uppercase, "uppercase" }, - { TextTransformType::Lowercase, "lowercase" }, -}); - -} - -#endif - diff --git a/include/mbgl/style/value.hpp b/include/mbgl/style/value.hpp deleted file mode 100644 index 87d6f4cda3..0000000000 --- a/include/mbgl/style/value.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef MBGL_STYLE_VALUE -#define MBGL_STYLE_VALUE - -#include <mbgl/util/variant.hpp> -#include <mbgl/util/pbf.hpp> -#include <rapidjson/document.h> - -#include <cstdlib> -#include <cerrno> - -namespace mbgl { - -typedef mapbox::util::variant<bool, int64_t, uint64_t, double, std::string> Value; - -std::string toString(const Value &value); - -Value parseValue(pbf data); -Value parseValue(const rapidjson::Value&); - -namespace util { -inline bool parseNumericString(const std::string &str, double &result) { - char *end = nullptr; - const char *begin = str.c_str(); - result = std::strtod(begin, &end); - while (*end != '\0' && isspace(*end)) end++; // eat whitespace after the end - return errno == 0 && end - begin == long(str.size()); -} -} - -template <typename T> -T toNumber(const Value &value) { - if (value.is<std::string>()) { - double val; - return util::parseNumericString(value.get<std::string>(), val) ? val : 0; - } - else if (value.is<bool>()) return value.get<bool>(); - else if (value.is<int64_t>()) return value.get<int64_t>(); - else if (value.is<uint64_t>()) return value.get<uint64_t>(); - else if (value.is<double>()) return value.get<double>(); - else return 0; -} - -} - -#endif diff --git a/include/mbgl/style/value_comparison.hpp b/include/mbgl/style/value_comparison.hpp deleted file mode 100644 index 98e29afa7c..0000000000 --- a/include/mbgl/style/value_comparison.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef MBGL_STYLE_VALUE_COMPARISON -#define MBGL_STYLE_VALUE_COMPARISON - -#include "value.hpp" -#include <cstdlib> -#include <cerrno> - -namespace mbgl { - -namespace util { - -namespace detail { - -template <typename Operator> -struct relaxed_operator_visitor { - typedef bool result_type; - - template <typename T0, typename T1> - inline bool operator()(T0, T1) const { return false; } - - template <typename T> - inline bool operator()(T lhs, T rhs) const { return Operator()(lhs, rhs); } - - inline bool operator()(int64_t lhs, uint64_t rhs) const { - return Operator()(double(lhs), double(rhs)); - } - - inline bool operator()(int64_t lhs, double rhs) const { - return Operator()(double(lhs), rhs); - } - - inline bool operator()(uint64_t lhs, int64_t rhs) const { - return Operator()(double(lhs), double(rhs)); - } - - inline bool operator()(uint64_t lhs, double rhs) const { - return Operator()(double(lhs), rhs); - } - - inline bool operator()(double lhs, uint64_t rhs) const { - return Operator()(lhs, double(rhs)); - } - - inline bool operator()(double lhs, int64_t rhs) const { - return Operator()(lhs, double(rhs)); - } -}; - -struct relaxed_equal_operator { - template <typename T0, typename T1> - inline bool operator()(T0 lhs, T1 rhs) const { return lhs == rhs; } -}; - -struct relaxed_not_equal_operator { - template <typename T0, typename T1> - inline bool operator()(T0 lhs, T1 rhs) const { return lhs != rhs; } -}; - -struct relaxed_greater_operator { - template <typename T0, typename T1> - inline bool operator()(T0 lhs, T1 rhs) const { return lhs > rhs; } -}; - -struct relaxed_greater_equal_operator { - template <typename T0, typename T1> - inline bool operator()(T0 lhs, T1 rhs) const { return lhs >= rhs; } -}; - -struct relaxed_less_operator { - template <typename T0, typename T1> - inline bool operator()(T0 lhs, T1 rhs) const { return lhs < rhs; } -}; - -struct relaxed_less_equal_operator { - template <typename T0, typename T1> - inline bool operator()(T0 lhs, T1 rhs) const { return lhs <= rhs; } -}; - -} // end namespace detail - -inline bool relaxed_equal(Value const &lhs, Value const &rhs) { - return apply_visitor(detail::relaxed_operator_visitor<detail::relaxed_equal_operator>(), lhs, rhs); -} - -inline bool relaxed_not_equal(Value const &lhs, Value const &rhs) { - return apply_visitor(detail::relaxed_operator_visitor<detail::relaxed_not_equal_operator>(), lhs, rhs); -} - -inline bool relaxed_greater(Value const &lhs, Value const &rhs) { - return apply_visitor(detail::relaxed_operator_visitor<detail::relaxed_greater_operator>(), lhs, rhs); -} - -inline bool relaxed_greater_equal(Value const &lhs, Value const &rhs) { - return apply_visitor(detail::relaxed_operator_visitor<detail::relaxed_greater_equal_operator>(), lhs, rhs); -} - -inline bool relaxed_less(Value const &lhs, Value const &rhs) { - return apply_visitor(detail::relaxed_operator_visitor<detail::relaxed_less_operator>(), lhs, rhs); -} - -inline bool relaxed_less_equal(Value const &lhs, Value const &rhs) { - return apply_visitor(detail::relaxed_operator_visitor<detail::relaxed_less_equal_operator>(), lhs, rhs); -} - -} - -} - -#endif diff --git a/include/mbgl/text/collision.hpp b/include/mbgl/text/collision.hpp deleted file mode 100644 index 3bf37a6a12..0000000000 --- a/include/mbgl/text/collision.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef MBGL_TEXT_COLLISION -#define MBGL_TEXT_COLLISION - -#include <mbgl/text/types.hpp> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wunused-variable" -#pragma GCC diagnostic ignored "-Wshadow" -#ifdef __clang__ -#pragma GCC diagnostic ignored "-Wdeprecated-register" -#else -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif -#include <boost/geometry.hpp> -#include <boost/geometry/geometries/point.hpp> -#include <boost/geometry/geometries/box.hpp> -#include <boost/geometry/index/rtree.hpp> -#pragma GCC diagnostic pop - -namespace mbgl { - -namespace bg = boost::geometry; -namespace bgm = bg::model; -namespace bgi = bg::index; -typedef bgm::point<float, 2, bg::cs::cartesian> Point; -typedef bgm::box<Point> Box; -typedef std::pair<Box, PlacementBox> PlacementValue; -typedef bgi::rtree<PlacementValue, bgi::linear<16,4>> Tree; - -class Collision { - -public: - Collision(float zoom, float tileExtent, float tileSize, float placementDepth = 1); - - float getPlacementScale(const GlyphBoxes &glyphs, float minPlacementScale, bool avoidEdges); - PlacementRange getPlacementRange(const GlyphBoxes &glyphs, float placementScale, - bool horizontal); - void insert(const GlyphBoxes &glyphs, const CollisionAnchor &anchor, float placementScale, - const PlacementRange &placementRange, bool horizontal); - -private: - Tree hTree; - Tree cTree; - PlacementValue leftEdge; - PlacementValue topEdge; - PlacementValue rightEdge; - PlacementValue bottomEdge; - -public: - const float tilePixelRatio; - const float zoom; - const float maxPlacementScale; -}; -} - -#endif diff --git a/include/mbgl/text/glyph.hpp b/include/mbgl/text/glyph.hpp deleted file mode 100644 index 4fbb75fc1e..0000000000 --- a/include/mbgl/text/glyph.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef MBGL_TEXT_GLYPH -#define MBGL_TEXT_GLYPH - -#include <mbgl/util/rect.hpp> - -#include <cstdint> -#include <vector> -#include <map> - -namespace mbgl { - -typedef std::pair<uint16_t, uint16_t> GlyphRange; - -// Note: this only works for the BMP -GlyphRange getGlyphRange(char32_t glyph); - -struct GlyphMetrics { - operator bool() const { - return !(width == 0 && height == 0 && advance == 0); - } - - // Glyph metrics. - uint32_t width = 0; - uint32_t height = 0; - int32_t left = 0; - int32_t top = 0; - uint32_t advance = 0; - -}; - -struct Glyph { - inline explicit Glyph() : rect(0, 0, 0, 0), metrics() {} - inline explicit Glyph(const Rect<uint16_t> &rect_, - const GlyphMetrics &metrics_) - : rect(rect_), metrics(metrics_) {} - - operator bool() const { - return metrics || rect; - } - - const Rect<uint16_t> rect; - const GlyphMetrics metrics; -}; - -typedef std::map<uint32_t, Glyph> GlyphPositions; - -class PositionedGlyph { -public: - inline explicit PositionedGlyph(uint32_t glyph_, float x_, float y_) - : glyph(glyph_), x(x_), y(y_) {} - - uint32_t glyph = 0; - float x = 0; - float y = 0; -}; - -typedef std::vector<PositionedGlyph> Shaping; -} - -#endif diff --git a/include/mbgl/text/glyph_store.hpp b/include/mbgl/text/glyph_store.hpp deleted file mode 100644 index 95ab92f307..0000000000 --- a/include/mbgl/text/glyph_store.hpp +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef MBGL_TEXT_GLYPH_STORE -#define MBGL_TEXT_GLYPH_STORE - -#include <mbgl/text/glyph.hpp> -#include <mbgl/util/pbf.hpp> -#include <mbgl/util/vec.hpp> -#include <mbgl/util/ptr.hpp> - -#include <cstdint> -#include <vector> -#include <future> -#include <map> -#include <set> -#include <unordered_map> - -namespace mbgl { - -class FileSource; - -class SDFGlyph { -public: - uint32_t id = 0; - - // A signed distance field of the glyph with a border of 3 pixels. - std::string bitmap; - - // Glyph metrics - GlyphMetrics metrics; -}; - -class FontStack { -public: - void insert(uint32_t id, const SDFGlyph &glyph); - const std::map<uint32_t, GlyphMetrics> &getMetrics() const; - const std::map<uint32_t, SDFGlyph> &getSDFs() const; - const Shaping getShaping(const std::u32string &string, float maxWidth, float lineHeight, - float horizontalAlign, float verticalAlign, float justify, - float spacing, const vec2<float> &translate) const; - void lineWrap(Shaping &shaping, float lineHeight, float maxWidth, float horizontalAlign, - float verticalAlign, float justify) const; - -private: - std::map<uint32_t, std::string> bitmaps; - std::map<uint32_t, GlyphMetrics> metrics; - std::map<uint32_t, SDFGlyph> sdfs; - mutable std::mutex mtx; -}; - -class GlyphPBF { -public: - GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource); - -private: - GlyphPBF(const GlyphPBF &) = delete; - GlyphPBF(GlyphPBF &&) = delete; - GlyphPBF &operator=(const GlyphPBF &) = delete; - GlyphPBF &operator=(GlyphPBF &&) = delete; - -public: - void parse(FontStack &stack); - - std::shared_future<GlyphPBF &> getFuture(); - -private: - std::string data; - std::promise<GlyphPBF &> promise; - std::shared_future<GlyphPBF &> future; - std::mutex mtx; -}; - -// Manages Glyphrange PBF loading. -class GlyphStore { -public: - GlyphStore(FileSource& fileSource); - - // Block until all specified GlyphRanges of the specified font stack are loaded. - void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges); - - FontStack &getFontStack(const std::string &fontStack); - - void setURL(const std::string &url); - -private: - // Loads an individual glyph range from the font stack and adds it to rangeSets - std::shared_future<GlyphPBF &> loadGlyphRange(const std::string &fontStack, std::map<GlyphRange, std::unique_ptr<GlyphPBF>> &rangeSets, GlyphRange range); - - FontStack &createFontStack(const std::string &fontStack); - - std::string glyphURL; - FileSource& fileSource; - std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges; - std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks; - std::mutex mtx; -}; - - -} - -#endif diff --git a/include/mbgl/text/placement.hpp b/include/mbgl/text/placement.hpp deleted file mode 100644 index 28eb8d5317..0000000000 --- a/include/mbgl/text/placement.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MBGL_TEXT_PLACEMENT -#define MBGL_TEXT_PLACEMENT - -#include <mbgl/text/types.hpp> -#include <mbgl/text/glyph.hpp> - -#include <mbgl/util/vec.hpp> - -namespace mbgl { - -struct Anchor; -class StyleBucketSymbol; - -class Placement { -public: - static Placement getIcon(Anchor &anchor, const Rect<uint16_t> &image, float iconBoxScale, - const std::vector<Coordinate> &line, const StyleBucketSymbol &props); - - static Placement getGlyphs(Anchor &anchor, const vec2<float> &origin, const Shaping &shaping, - const GlyphPositions &face, float boxScale, bool horizontal, - const std::vector<Coordinate> &line, const StyleBucketSymbol &props); - - static const float globalMinScale; - - GlyphBoxes boxes; - PlacedGlyphs shapes; - float minScale; -}; -} - -#endif diff --git a/include/mbgl/text/rotation_range.hpp b/include/mbgl/text/rotation_range.hpp deleted file mode 100644 index 4968fda164..0000000000 --- a/include/mbgl/text/rotation_range.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef MBGL_TEXT_ROTATION_RANGE -#define MBGL_TEXT_ROTATION_RANGE - -#include <mbgl/util/math.hpp> -#include <mbgl/text/types.hpp> - -#include <vector> -#include <cassert> - -namespace mbgl { - -/* - * Combine an array of collision ranges to form a continuous - * range that includes 0. Collisions within the ignoreRange are ignored - */ -CollisionRange mergeCollisions(const CollisionList &collisions, - PlacementRange ignoreRange); - -/* - * Calculate collision ranges for two rotating boxes.e - */ -CollisionList rotatingRotatingCollisions(const CollisionRect &a, - const CollisionRect &b, - const CollisionAnchor &anchorToAnchor); - -/* - * Return the intersection points of a circle and a line segment; - */ -void circleEdgeCollisions(std::back_insert_iterator<CollisionAngles> angles, - const CollisionPoint &corner, float radius, - const CollisionPoint &p1, const CollisionPoint &p2); - -/* - * Calculate the ranges for which the corner, - * rotatated around the anchor, is within the box; - */ -void cornerBoxCollisions(std::back_insert_iterator<CollisionList> collisions, - const CollisionPoint &corner, - const CollisionCorners &boxCorners, bool flip = false); - -/* - * Calculate collision ranges for a rotating box and a fixed box; - */ -CollisionList rotatingFixedCollisions(const CollisionRect &rotating, - const CollisionRect &fixed); - -/* - * Calculate the range a box conflicts with a second box - */ -CollisionRange rotationRange(const GlyphBox &inserting, - const PlacementBox &blocker, float scale); -} - -#endif diff --git a/include/mbgl/text/types.hpp b/include/mbgl/text/types.hpp deleted file mode 100644 index 23f49aa748..0000000000 --- a/include/mbgl/text/types.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef MBGL_TEXT_TYPES -#define MBGL_TEXT_TYPES - -#include <mbgl/util/vec.hpp> -#include <mbgl/util/rect.hpp> -#include <mbgl/util/optional.hpp> -#include <array> -#include <vector> - -namespace mbgl { - -typedef vec2<float> CollisionPoint; -typedef vec2<float> CollisionAnchor; - -typedef std::array<float, 2> PlacementRange; -typedef float CollisionAngle; -typedef std::vector<CollisionAngle> CollisionAngles; -typedef std::array<CollisionAngle, 2> CollisionRange; -typedef std::vector<CollisionRange> CollisionList; -typedef std::array<CollisionPoint, 4> CollisionCorners; - -struct CollisionRect { - CollisionPoint tl; - CollisionPoint br; - inline explicit CollisionRect() {} - inline explicit CollisionRect(CollisionPoint::Type ax, - CollisionPoint::Type ay, - CollisionPoint::Type bx, - CollisionPoint::Type by) - : tl(ax, ay), br(bx, by) {} - inline explicit CollisionRect(const CollisionPoint &tl_, - const CollisionPoint &br_) - : tl(tl_), br(br_) {} -}; - -// These are the glyph boxes that we want to have placed. -struct GlyphBox { - explicit GlyphBox() {} - explicit GlyphBox(const CollisionRect &box_, - const CollisionAnchor &anchor_, - float minScale_, - float maxScale_, - float padding_) - : box(box_), anchor(anchor_), minScale(minScale_), maxScale(maxScale_), padding(padding_) {} - explicit GlyphBox(const CollisionRect &box_, - float minScale_, - float padding_) - : box(box_), minScale(minScale_), padding(padding_) {} - - CollisionRect box; - CollisionAnchor anchor; - float minScale = 0.0f; - float maxScale = std::numeric_limits<float>::infinity(); - float padding = 0.0f; - mapbox::util::optional<CollisionRect> hBox; -}; - -typedef std::vector<GlyphBox> GlyphBoxes; - - -// TODO: Transform the vec2<float>s to vec2<int16_t> to save bytes -struct PlacedGlyph { - explicit PlacedGlyph(const vec2<float> &tl_, const vec2<float> &tr_, - const vec2<float> &bl_, const vec2<float> &br_, - const Rect<uint16_t> &tex_, float angle_, const vec2<float> &anchor_, - float minScale_, float maxScale_) - : tl(tl_), - tr(tr_), - bl(bl_), - br(br_), - tex(tex_), - angle(angle_), - anchor(anchor_), - minScale(minScale_), - maxScale(maxScale_) {} - - vec2<float> tl, tr, bl, br; - Rect<uint16_t> tex; - float angle; - vec2<float> anchor; - float minScale, maxScale; -}; - -typedef std::vector<PlacedGlyph> PlacedGlyphs; - -// These are the placed boxes contained in the rtree. -struct PlacementBox { - CollisionAnchor anchor; - CollisionRect box; - mapbox::util::optional<CollisionRect> hBox; - PlacementRange placementRange = {{0.0f, 0.0f}}; - float placementScale = 0.0f; - float maxScale = std::numeric_limits<float>::infinity(); - float padding = 0.0f; -}; - -struct PlacementProperty { - explicit PlacementProperty() {} - explicit PlacementProperty(float zoom_, const PlacementRange &rotationRange_) - : zoom(zoom_), rotationRange(rotationRange_) {} - - inline operator bool() const { - return !std::isnan(zoom) && zoom != std::numeric_limits<float>::infinity() && - rotationRange[0] != rotationRange[1]; - } - - float zoom = std::numeric_limits<float>::infinity(); - PlacementRange rotationRange = {{0.0f, 0.0f}}; -}; - -} - -#endif diff --git a/include/mbgl/util/clip_ids.hpp b/include/mbgl/util/clip_ids.hpp deleted file mode 100644 index 5855b16af7..0000000000 --- a/include/mbgl/util/clip_ids.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef MBGL_UTIL_CLIP_IDS -#define MBGL_UTIL_CLIP_IDS - -#include <mbgl/map/tile.hpp> -#include <list> -#include <set> -#include <vector> -#include <forward_list> -#include <map> - -namespace mbgl { - -class ClipIDGenerator { -private: - struct Leaf { - Leaf(Tile &tile); - void add(const Tile::ID &p); - bool operator==(const Leaf &other) const; - - Tile &tile; - std::forward_list<Tile::ID> children; - }; - - typedef std::vector<Leaf> Pool; - std::forward_list<Pool> pools; - uint8_t bit_offset = 0; - -private: - bool reuseExisting(Leaf &leaf); - -public: - void update(std::forward_list<Tile *> tiles); -}; - - -} - -#endif diff --git a/include/mbgl/util/compression.hpp b/include/mbgl/util/compression.hpp deleted file mode 100644 index a33b2476a7..0000000000 --- a/include/mbgl/util/compression.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_UTIL_COMPRESSION -#define MBGL_UTIL_COMPRESSION - -#include <string> - -namespace mbgl { -namespace util { - -std::string compress(const std::string &raw); -std::string decompress(const std::string &raw); - -} -} - -#endif diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp deleted file mode 100644 index 89e8af2ef1..0000000000 --- a/include/mbgl/util/constants.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MBGL_UTIL_CONSTANTS -#define MBGL_UTIL_CONSTANTS - -#include <cmath> - -#include "vec.hpp" - -namespace mbgl { - -namespace util { - -extern const float tileSize; - -} - -namespace debug { - -extern const bool tileParseWarnings; -extern const bool styleParseWarnings; -extern const bool spriteWarnings; -extern const bool renderWarnings; -extern const bool renderTree; -extern const bool labelTextMissingWarning; -extern const bool missingFontStackWarning; -extern const bool missingFontFaceWarning; -extern const bool glyphWarning; -extern const bool shapingWarning; - -} - -} - -#endif diff --git a/include/mbgl/util/error.hpp b/include/mbgl/util/error.hpp deleted file mode 100644 index 09fa8d3e21..0000000000 --- a/include/mbgl/util/error.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MBGL_UTIL_ERROR -#define MBGL_UTIL_ERROR - -#include <stdexcept> -#include <string> - -namespace mbgl { -namespace error { - -struct style_parse : std::exception { - inline style_parse(size_t offset_, const char *msg_) : offset(offset_), msg(msg_) {} - inline const char* what() const noexcept { return msg.c_str(); } - const size_t offset; - const std::string msg; -}; -} - -} - -#endif
\ No newline at end of file diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp deleted file mode 100644 index c9232db4eb..0000000000 --- a/include/mbgl/util/interpolate.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MBGL_UTIL_INTERPOLATE -#define MBGL_UTIL_INTERPOLATE - -#include <array> - -namespace mbgl { -namespace util { - -template <typename T> -T interpolate(const T a, const T b, const double t) { - return a * (1.0 - t) + b * t; -} - -template <typename T> -inline std::array<T, 4> interpolate(const std::array<T, 4>& a, const std::array<T, 4>& b, const double t) { - return {{ - interpolate(a[0], b[0], t), - interpolate(a[1], b[1], t), - interpolate(a[2], b[2], t), - interpolate(a[3], b[3], t) - }}; -} - -} -} - -#endif diff --git a/include/mbgl/util/io.hpp b/include/mbgl/util/io.hpp deleted file mode 100644 index e95fc16d9d..0000000000 --- a/include/mbgl/util/io.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_UTIL_IO -#define MBGL_UTIL_IO - -#include <string> - -namespace mbgl { -namespace util { - -void write_file(const std::string &filename, const std::string &data); -std::string read_file(const std::string &filename); - -} -} - -#endif diff --git a/include/mbgl/util/mapbox.hpp b/include/mbgl/util/mapbox.hpp deleted file mode 100644 index 0fbb9a91ed..0000000000 --- a/include/mbgl/util/mapbox.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef MBGL_UTIL_MAPBOX -#define MBGL_UTIL_MAPBOX - -#include <string> - -namespace mbgl { -namespace util { -namespace mapbox { - -std::string normalizeSourceURL(const std::string& url, const std::string& accessToken); -std::string normalizeGlyphsURL(const std::string& url, const std::string& accessToken); - -} -} -} - -#endif diff --git a/include/mbgl/util/mat3.hpp b/include/mbgl/util/mat3.hpp deleted file mode 100644 index fa40751764..0000000000 --- a/include/mbgl/util/mat3.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// This is an incomplete port of http://glmatrix.net/ -// -// Copyright (c) 2013 Brandon Jones, Colin MacKenzie IV -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the -// use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not claim -// that you wrote the original software. If you use this software in a -// product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. - -#ifndef MBGL_UTIL_MAT3 -#define MBGL_UTIL_MAT3 - -#include <array> - -namespace mbgl { - -typedef std::array<float, 9> mat3; - -namespace matrix { - -void identity(mat3& out); -void translate(mat3& out, const mat3& a, float x, float y); -void rotate(mat3& out, const mat3& a, float rad); -void scale(mat3& out, const mat3& a, float x, float y); - -} -} - -#endif diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp deleted file mode 100644 index 133e2c8f97..0000000000 --- a/include/mbgl/util/optional.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef MAPBOX_UTIL_OPTIONAL_HPP -#define MAPBOX_UTIL_OPTIONAL_HPP - -#include <type_traits> - -#include "variant.hpp" - -namespace mapbox -{ -namespace util -{ - -template <typename T> class optional -{ - static_assert(!std::is_reference<T>::value, "optional doesn't support references"); - - struct none_type - { - }; - - variant<none_type, T> variant_; - - public: - optional() = default; - - optional(optional const &rhs) - { - if (this != &rhs) - { // protect against invalid self-assignment - variant_ = rhs.variant_; - } - } - - optional(T const &v) { variant_ = v; } - - explicit operator bool() const noexcept { return variant_.template is<T>(); } - - T const &get() const { return variant_.template get<T>(); } - T &get() { return variant_.template get<T>(); } - - T const &operator*() const { return this->get(); } - T operator*() { return this->get(); } - - optional &operator=(T const &v) - { - variant_ = v; - return *this; - } - - optional &operator=(optional const &rhs) - { - if (this != &rhs) - { - variant_ = rhs.variant_; - } - return *this; - } - - template <typename... Args> void emplace(Args &&... args) - { - variant_ = T{std::forward<Args>(args)...}; - } - - void reset() { variant_ = none_type{}; } -}; -} -} - -#endif diff --git a/include/mbgl/util/pbf.hpp b/include/mbgl/util/pbf.hpp deleted file mode 100644 index d017219a52..0000000000 --- a/include/mbgl/util/pbf.hpp +++ /dev/null @@ -1,184 +0,0 @@ -#ifndef MBGL_UTIL_PBF -#define MBGL_UTIL_PBF - -/* - * Some parts are from upb - a minimalist implementation of protocol buffers. - * - * Copyright (c) 2008-2011 Google Inc. See LICENSE for details. - * Author: Josh Haberman <jhaberman@gmail.com> - */ - -#include <string> -#include <cstring> - -namespace mbgl { - -struct pbf { - struct exception : std::exception { const char *what() const noexcept { return "pbf exception"; } }; - struct unterminated_varint_exception : exception { const char *what() const noexcept { return "pbf unterminated varint exception"; } }; - struct varint_too_long_exception : exception { const char *what() const noexcept { return "pbf varint too long exception"; } }; - struct unknown_field_type_exception : exception { const char *what() const noexcept { return "pbf unknown field type exception"; } }; - struct end_of_buffer_exception : exception { const char *what() const noexcept { return "pbf end of buffer exception"; } }; - - inline pbf(const unsigned char *data, size_t length); - inline pbf(); - - inline operator bool() const; - - inline bool next(); - inline bool next(uint32_t tag); - template <typename T = uint32_t> inline T varint(); - template <typename T = uint32_t> inline T svarint(); - - template <typename T = uint32_t, int bytes = 4> inline T fixed(); - inline float float32(); - inline double float64(); - - inline std::string string(); - inline bool boolean(); - - inline pbf message(); - - inline void skip(); - inline void skipValue(uint32_t val); - inline void skipBytes(uint32_t bytes); - - const uint8_t *data = nullptr; - const uint8_t *end = nullptr; - uint32_t value = 0; - uint32_t tag = 0; -}; - -pbf::pbf(const unsigned char *data_, size_t length) - : data(data_), - end(data_ + length), - value(0), - tag(0) { -} - -pbf::pbf() - : data(nullptr), - end(nullptr), - value(0), - tag(0) { -} - - -pbf::operator bool() const { - return data < end; -} - -bool pbf::next() { - if (data < end) { - value = static_cast<uint32_t>(varint()); - tag = value >> 3; - return true; - } - return false; -} - -bool pbf::next(uint32_t requested_tag) { - while (next()) { - if (tag == requested_tag) { - return true; - } else { - skip(); - } - } - return false; -} - -template <typename T> -T pbf::varint() { - uint8_t byte = 0x80; - T result = 0; - int bitpos; - for (bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { - if (data >= end) { - throw unterminated_varint_exception(); - } - result |= ((T)(byte = *data) & 0x7F) << bitpos; - - data++; - } - if (bitpos == 70 && (byte & 0x80)) { - throw varint_too_long_exception(); - } - - return result; -} - -template <typename T> -T pbf::svarint() { - T n = varint<T>(); - return (n >> 1) ^ -(T)(n & 1); -} - -template <typename T, int bytes> -T pbf::fixed() { - skipBytes(bytes); - T result; - memcpy(&result, data - bytes, bytes); - return result; -} - -float pbf::float32() { - return fixed<float, 4>(); -} - -double pbf::float64() { - return fixed<double, 8>(); -} - -std::string pbf::string() { - uint32_t bytes = static_cast<uint32_t>(varint()); - const char *string_data = reinterpret_cast<const char*>(data); - skipBytes(bytes); - return std::string(string_data, bytes); -} - -bool pbf::boolean() { - skipBytes(1); - return *(bool *)(data - 1); -} - -pbf pbf::message() { - uint32_t bytes = static_cast<uint32_t>(varint()); - const uint8_t *pos = data; - skipBytes(bytes); - return pbf(pos, bytes); -} - -void pbf::skip() { - skipValue(value); -} - -void pbf::skipValue(uint32_t val) { - switch (val & 0x7) { - case 0: // varint - varint(); - break; - case 1: // 64 bit - skipBytes(8); - break; - case 2: // string/message - skipBytes(static_cast<uint32_t>(varint())); - break; - case 5: // 32 bit - skipBytes(4); - break; - default: - throw unknown_field_type_exception(); - } -} - -void pbf::skipBytes(uint32_t bytes) { - if (data + bytes > end) { - throw end_of_buffer_exception(); - } - data += bytes; -} - -} // end namespace mbgl - -#endif diff --git a/include/mbgl/util/queue.h b/include/mbgl/util/queue.h deleted file mode 100644 index fe02b454ea..0000000000 --- a/include/mbgl/util/queue.h +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl> - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef QUEUE_H_ -#define QUEUE_H_ - -typedef void *QUEUE[2]; - -/* Private macros. */ -#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0])) -#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1])) -#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q))) -#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q))) - -/* Public macros. */ -#define QUEUE_DATA(ptr, type, field) \ - ((type *) ((char *) (ptr) - ((char *) &((type *) 0)->field))) - -#define QUEUE_FOREACH(q, h) \ - for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q)) - -#define QUEUE_EMPTY(q) \ - ((const QUEUE *) (q) == (const QUEUE *) QUEUE_NEXT(q)) - -#define QUEUE_HEAD(q) \ - (QUEUE_NEXT(q)) - -#define QUEUE_INIT(q) \ - do { \ - QUEUE_NEXT(q) = (q); \ - QUEUE_PREV(q) = (q); \ - } \ - while (0) - -#define QUEUE_ADD(h, n) \ - do { \ - QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n); \ - QUEUE_NEXT_PREV(n) = QUEUE_PREV(h); \ - QUEUE_PREV(h) = QUEUE_PREV(n); \ - QUEUE_PREV_NEXT(h) = (h); \ - } \ - while (0) - -#define QUEUE_SPLIT(h, q, n) \ - do { \ - QUEUE_PREV(n) = QUEUE_PREV(h); \ - QUEUE_PREV_NEXT(n) = (n); \ - QUEUE_NEXT(n) = (q); \ - QUEUE_PREV(h) = QUEUE_PREV(q); \ - QUEUE_PREV_NEXT(h) = (h); \ - QUEUE_PREV(q) = (n); \ - } \ - while (0) - -#define QUEUE_INSERT_HEAD(h, q) \ - do { \ - QUEUE_NEXT(q) = QUEUE_NEXT(h); \ - QUEUE_PREV(q) = (h); \ - QUEUE_NEXT_PREV(q) = (q); \ - QUEUE_NEXT(h) = (q); \ - } \ - while (0) - -#define QUEUE_INSERT_TAIL(h, q) \ - do { \ - QUEUE_NEXT(q) = (h); \ - QUEUE_PREV(q) = QUEUE_PREV(h); \ - QUEUE_PREV_NEXT(q) = (q); \ - QUEUE_PREV(h) = (q); \ - } \ - while (0) - -#define QUEUE_REMOVE(q) \ - do { \ - QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q); \ - QUEUE_NEXT_PREV(q) = QUEUE_PREV(q); \ - } \ - while (0) - -#endif /* QUEUE_H_ */ diff --git a/include/mbgl/util/raster.hpp b/include/mbgl/util/raster.hpp deleted file mode 100644 index ff27f509f4..0000000000 --- a/include/mbgl/util/raster.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef MBGL_UTIL_RASTER -#define MBGL_UTIL_RASTER - -#include <mbgl/util/transition.hpp> -#include <mbgl/util/texture_pool.hpp> -#include <mbgl/util/image.hpp> -#include <mbgl/util/ptr.hpp> -#include <mbgl/renderer/prerendered_texture.hpp> - -#include <string> -#include <mutex> - -typedef struct uv_loop_s uv_loop_t; - -namespace mbgl { - -class Raster : public std::enable_shared_from_this<Raster> { - -public: - Raster(TexturePool&); - ~Raster(); - - // load image data - bool load(const std::string &img); - - // bind current texture - void bind(bool linear = false); - - // bind prerendered texture - void bind(const GLuint texture); - - // loaded status - bool isLoaded() const; - - // transitions - void beginFadeInTransition(); - bool needsTransition() const; - void updateTransitions(timestamp now); - -public: - // loaded image dimensions - uint32_t width = 0, height = 0; - - // has been uploaded to texture - bool textured = false; - - // the uploaded texture - uint32_t texture = 0; - - // texture opacity - double opacity = 0; - -private: - mutable std::mutex mtx; - - // raw pixels have been loaded - bool loaded = false; - - // shared texture pool - TexturePool& texturePool; - - // min/mag filter - uint32_t filter = 0; - - // the raw pixels - std::unique_ptr<util::Image> img; - - // fade in transition - util::ptr<util::transition> fade_transition = nullptr; -}; - -} - -#endif diff --git a/include/mbgl/util/rect.hpp b/include/mbgl/util/rect.hpp deleted file mode 100644 index f5c77f93d1..0000000000 --- a/include/mbgl/util/rect.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MBGL_UTIL_RECT -#define MBGL_UTIL_RECT - -namespace mbgl { - -template <typename T> -struct Rect { - inline Rect() {} - inline Rect(T x_, T y_, T w_, T h_) : x(x_), y(y_), w(w_), h(h_) {} - T x = 0, y = 0; - T w = 0, h = 0; - - template <typename Number> - Rect operator *(Number value) const { - return Rect(x * value, y * value, w * value, h * value); - } - - operator bool() const { return w != 0 && h != 0; } -}; -} - -#endif diff --git a/include/mbgl/util/sqlite3.hpp b/include/mbgl/util/sqlite3.hpp deleted file mode 100644 index 3e324f7ce1..0000000000 --- a/include/mbgl/util/sqlite3.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include <string> -#include <stdexcept> - -typedef struct sqlite3 sqlite3; -typedef struct sqlite3_stmt sqlite3_stmt; - -namespace mapbox { -namespace sqlite { - -enum OpenFlag : int { - ReadOnly = 0x00000001, - ReadWrite = 0x00000002, - Create = 0x00000004, - NoMutex = 0x00008000, - FullMutex = 0x00010000, - SharedCache = 0x00020000, - PrivateCache = 0x00040000, -}; - -struct Exception : std::runtime_error { - inline Exception(int err, const char *msg) : std::runtime_error(msg), code(err) {} - const int code = 0; -}; - -class Statement; - -class Database { -private: - Database(const Database &) = delete; - Database &operator=(const Database &) = delete; - -public: - Database(const std::string &filename, int flags = 0); - Database(Database &&); - ~Database(); - Database &operator=(Database &&); - - operator bool() const; - - void exec(const std::string &sql); - Statement prepare(const char *query); - -private: - sqlite3 *db = nullptr; -}; - -class Statement { -private: - Statement(const Statement &) = delete; - Statement &operator=(const Statement &) = delete; - -public: - Statement(sqlite3 *db, const char *sql); - Statement(Statement &&); - ~Statement(); - Statement &operator=(Statement &&); - - operator bool() const; - - template <typename T> void bind(int offset, T value); - void bind(int offset, const std::string &value, bool retain = true); - template <typename T> T get(int offset); - - bool run(); - void reset(); - -private: - sqlite3_stmt *stmt = nullptr; -}; - -} -} diff --git a/include/mbgl/util/stopwatch.hpp b/include/mbgl/util/stopwatch.hpp deleted file mode 100644 index 663bbb6fc7..0000000000 --- a/include/mbgl/util/stopwatch.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MBGL_UTIL_STOPWATCH -#define MBGL_UTIL_STOPWATCH - -#include <mbgl/platform/event.hpp> - -#include <string> - -namespace mbgl { -namespace util { - -#ifndef DISABLE_STOPWATCH -class stopwatch { -public: - stopwatch(Event event = Event::General); - stopwatch(EventSeverity severity, Event event = Event::General); - stopwatch(const std::string &name, Event event = Event::General); - stopwatch(const std::string &name, EventSeverity severity, Event event = Event::General); - void report(const std::string &name); - ~stopwatch(); - -private: - const std::string name; - EventSeverity severity = EventSeverity::Debug; - Event event = Event::General; - uint64_t start; -}; -#else -class stopwatch { - inline stopwatch(Event event = Event::General); - inline stopwatch(EventSeverity severity, Event event = Event::General); - inline stopwatch(const std::string &name, Event event = Event::General); - inline stopwatch(const std::string &name, EventSeverity severity, Event event = Event::General); - inline void report(const std::string &name) {} - inline ~stopwatch() {} -}; -#endif -} -} - -#endif diff --git a/include/mbgl/util/texture_pool.hpp b/include/mbgl/util/texture_pool.hpp deleted file mode 100644 index 95d918c237..0000000000 --- a/include/mbgl/util/texture_pool.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MBGL_UTIL_TEXTUREPOOL -#define MBGL_UTIL_TEXTUREPOOL - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/platform/gl.hpp> - -#include <set> -#include <mutex> - -namespace mbgl { - -class TexturePool : private util::noncopyable { - -public: - GLuint getTextureID(); - void removeTextureID(GLuint texture_id); - void clearTextureIDs(); - -private: - std::set<GLuint> texture_ids; -}; - -} - -#endif diff --git a/include/mbgl/util/token.hpp b/include/mbgl/util/token.hpp deleted file mode 100644 index 64192a99f9..0000000000 --- a/include/mbgl/util/token.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef MBGL_UTIL_TOKEN -#define MBGL_UTIL_TOKEN - -#include <map> -#include <string> -#include <algorithm> - -namespace mbgl { -namespace util { - -// Replaces {tokens} in a string by calling the lookup function. -template <typename Lookup> -std::string replaceTokens(const std::string &source, const Lookup &lookup) { - std::string result; - result.reserve(source.size()); - - auto pos = source.begin(); - const auto end = source.end(); - - while (pos != end) { - auto brace = std::find(pos, end, '{'); - result.append(pos, brace); - pos = brace; - if (pos != end) { - for (brace++; brace != end && (std::isalnum(*brace) || *brace == '_'); brace++); - if (brace != end && *brace == '}') { - result.append(lookup({ pos + 1, brace })); - pos = brace + 1; - } else { - result.append(pos, brace); - pos = brace; - } - } - } - - return result; -} - -template <typename T> -inline std::string replaceTokens(const std::string &source, const std::map<std::string, T> &properties) { - return replaceTokens(source, [&properties](const std::string &token) -> std::string { - const auto it_prop = properties.find(token); - return it_prop != properties.end() ? toString(it_prop->second) : ""; - }); -} - -} // end namespace util -} // end namespace mbgl - -#endif diff --git a/include/mbgl/util/transition.hpp b/include/mbgl/util/transition.hpp deleted file mode 100644 index b78abfa8fd..0000000000 --- a/include/mbgl/util/transition.hpp +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef MBGL_UTIL_TRANSITION -#define MBGL_UTIL_TRANSITION - -#include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/time.hpp> -#include <mbgl/style/types.hpp> - -namespace mbgl { -namespace util { - -class transition : private noncopyable { -public: - enum state { - running, - complete - }; - - inline transition(timestamp start_, timestamp duration_) - : start(start_), - duration(duration_) {} - - inline float progress(timestamp now) const { - if (duration == 0) return 1; - if (start > now) return 0; - - return (float)(now - start) / duration; - } - - virtual state update(timestamp now) const = 0; - virtual ~transition(); - -protected: - const timestamp start, duration; -}; - -template <typename T> -class ease_transition : public transition { -public: - ease_transition(T from_, T to_, T& value_, timestamp start_, timestamp duration_) - : transition(start_, duration_), - from(from_), - to(to_), - value(value_) {} - - state update(timestamp now) const; - -private: - const T from, to; - T& value; - -}; - -template <typename T> -class timeout : public transition { -public: - timeout(T final_value_, T& value_, timestamp start_, timestamp duration_) - : transition(start_, duration_), - final_value(final_value_), - value(value_) {} - - state update(timestamp now) const { - if (progress(now) >= 1) { - value = final_value; - return complete; - } else { - return running; - } - } - -private: - const T final_value; - T& value; -}; - -} -} - -#endif diff --git a/include/mbgl/util/unitbezier.hpp b/include/mbgl/util/unitbezier.hpp deleted file mode 100644 index 095e15f809..0000000000 --- a/include/mbgl/util/unitbezier.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2008 Apple Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MBGL_UTIL_UNITBEZIER -#define MBGL_UTIL_UNITBEZIER - -#include <cmath> - -namespace mbgl { -namespace util { - -struct UnitBezier { - UnitBezier(double p1x, double p1y, double p2x, double p2y) { - // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1). - cx = 3.0 * p1x; - bx = 3.0 * (p2x - p1x) - cx; - ax = 1.0 - cx - bx; - - cy = 3.0 * p1y; - by = 3.0 * (p2y - p1y) - cy; - ay = 1.0 - cy - by; - } - - double sampleCurveX(double t) { - // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule. - return ((ax * t + bx) * t + cx) * t; - } - - double sampleCurveY(double t) { - return ((ay * t + by) * t + cy) * t; - } - - double sampleCurveDerivativeX(double t) { - return (3.0 * ax * t + 2.0 * bx) * t + cx; - } - - // Given an x value, find a parametric value it came from. - double solveCurveX(double x, double epsilon) { - double t0; - double t1; - double t2; - double x2; - double d2; - int i; - - // First try a few iterations of Newton's method -- normally very fast. - for (t2 = x, i = 0; i < 8; ++i) { - x2 = sampleCurveX(t2) - x; - if (fabs (x2) < epsilon) - return t2; - d2 = sampleCurveDerivativeX(t2); - if (fabs(d2) < 1e-6) - break; - t2 = t2 - x2 / d2; - } - - // Fall back to the bisection method for reliability. - t0 = 0.0; - t1 = 1.0; - t2 = x; - - if (t2 < t0) - return t0; - if (t2 > t1) - return t1; - - while (t0 < t1) { - x2 = sampleCurveX(t2); - if (fabs(x2 - x) < epsilon) - return t2; - if (x > x2) - t0 = t2; - else - t1 = t2; - t2 = (t1 - t0) * .5 + t0; - } - - // Failure. - return t2; - } - - double solve(double x, double epsilon) { - return sampleCurveY(solveCurveX(x, epsilon)); - } - -private: - double ax; - double bx; - double cx; - - double ay; - double by; - double cy; -}; - -} -} - -#endif diff --git a/include/mbgl/util/url.hpp b/include/mbgl/util/url.hpp deleted file mode 100644 index a7e5291ec5..0000000000 --- a/include/mbgl/util/url.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MBGL_UTIL_URL -#define MBGL_UTIL_URL - -#include <string> - -namespace mbgl { -namespace util { - -std::string percentEncode(const std::string&); -std::string percentDecode(const std::string&); - -} -} - -#endif diff --git a/include/mbgl/util/uv-channel.h b/include/mbgl/util/uv-channel.h deleted file mode 100644 index ea5c279f65..0000000000 --- a/include/mbgl/util/uv-channel.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MBGL_UTIL_UV_CHANNEL -#define MBGL_UTIL_UV_CHANNEL - -#ifdef __cplusplus -extern "C" { -#endif - -#include <uv.h> - -// Taken from http://navaneeth.github.io/blog/2013/08/02/channels-in-libuv/ - -typedef struct uv_chan_s uv_chan_t; - -struct uv_chan_s { - uv_mutex_t mutex; - uv_cond_t cond; - void *q[2]; -}; - -int uv_chan_init(uv_chan_t *chan); -void uv_chan_send(uv_chan_t *chan, void *data); -void *uv_chan_receive(uv_chan_t *chan); -void uv_chan_destroy(uv_chan_t *chan); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/mbgl/util/uv-worker.h b/include/mbgl/util/uv-worker.h deleted file mode 100644 index cb2075d1c3..0000000000 --- a/include/mbgl/util/uv-worker.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MBGL_UTIL_UV_WORKER -#define MBGL_UTIL_UV_WORKER - -#ifdef __cplusplus -extern "C" { -#endif - -#include <mbgl/util/uv-messenger.h> -#include <mbgl/util/uv-channel.h> - -#include <stdlib.h> - -typedef struct uv_worker_s uv_worker_t; - -typedef void (*uv_worker_cb)(void *data); -typedef void (*uv_worker_after_cb)(void *data); -typedef void (*uv_worker_close_cb)(uv_worker_t *worker); - -struct uv_worker_s { -#ifndef NDEBUG - unsigned long thread_id; -#endif - uv_loop_t *loop; - uv_messenger_t *msgr; - uv_chan_t chan; - const char *name; - int count; - uv_worker_close_cb close_cb; - unsigned int active_items; -}; - -int uv_worker_init(uv_worker_t *worker, uv_loop_t *loop, int count, const char *name); -void uv_worker_send(uv_worker_t *worker, void *data, uv_worker_cb work_cb, - uv_worker_after_cb after_work_cb); -void uv_worker_close(uv_worker_t *worker, uv_worker_close_cb close_cb); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp deleted file mode 100644 index 99f5edc145..0000000000 --- a/include/mbgl/util/uv_detail.hpp +++ /dev/null @@ -1,177 +0,0 @@ -#ifndef MBGL_UTIL_UV_DETAIL -#define MBGL_UTIL_UV_DETAIL - -#include <mbgl/util/uv-worker.h> -#include <mbgl/util/noncopyable.hpp> - -#include <uv.h> - -#include <functional> -#include <cassert> -#include <memory> -#include <string> - -namespace uv { - -template <class T> -void close(std::unique_ptr<T> ptr) { - uv_close(reinterpret_cast<uv_handle_t*>(ptr.release()), [](uv_handle_t* handle) { - delete reinterpret_cast<T*>(handle); - }); -} - -class loop : public mbgl::util::noncopyable { -public: - inline loop() { -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - l = uv_loop_new(); - if (l == nullptr) { -#else - l = new uv_loop_t; - if (uv_loop_init(l) != 0) { -#endif - throw std::runtime_error("failed to initialize loop"); - } - } - - inline ~loop() { -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - uv_loop_delete(l); -#else - uv_loop_close(l); - delete l; -#endif - - } - - inline uv_loop_t *operator*() { return l; } - -private: - uv_loop_t *l = nullptr; -}; - -class async : public mbgl::util::noncopyable { -public: - inline async(uv_loop_t* loop, std::function<void ()> fn_) - : a(new uv_async_t) - , fn(fn_) - { - a->data = this; - if (uv_async_init(loop, a.get(), async_cb) != 0) { - throw std::runtime_error("failed to initialize async"); - } - } - - inline ~async() { - close(std::move(a)); - } - - inline void send() { - if (uv_async_send(a.get()) != 0) { - throw std::runtime_error("failed to async send"); - } - } - -private: -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - static void async_cb(uv_async_t* a, int) { -#else - static void async_cb(uv_async_t* a) { -#endif - reinterpret_cast<async*>(a->data)->fn(); - } - - std::unique_ptr<uv_async_t> a; - std::function<void ()> fn; -}; - -class rwlock : public mbgl::util::noncopyable { -public: - inline rwlock() { - if (uv_rwlock_init(&mtx) != 0) { - throw std::runtime_error("failed to initialize read-write lock"); - } - } - inline ~rwlock() { uv_rwlock_destroy(&mtx); } - inline void rdlock() { uv_rwlock_rdlock(&mtx); } - inline void wrlock() { uv_rwlock_wrlock(&mtx); } - inline void rdunlock() { uv_rwlock_rdunlock(&mtx); } - inline void wrunlock() { uv_rwlock_wrunlock(&mtx); } - -private: - uv_rwlock_t mtx; -}; - -class readlock : public mbgl::util::noncopyable { -public: - inline readlock(rwlock &mtx_) : mtx(mtx_) { mtx.rdlock(); } - inline readlock(const std::unique_ptr<rwlock> &mtx_) : mtx(*mtx_) { mtx.rdlock(); } - inline ~readlock() { mtx.rdunlock(); } - -private: - rwlock &mtx; -}; - -class writelock : public mbgl::util::noncopyable { -public: - inline writelock(rwlock &mtx_) : mtx(mtx_) { mtx.wrlock(); } - inline writelock(const std::unique_ptr<rwlock> &mtx_) : mtx(*mtx_) { mtx.wrlock(); } - inline ~writelock() { mtx.wrunlock(); } - -private: - rwlock &mtx; -}; - -class worker : public mbgl::util::noncopyable { -public: - inline worker(uv_loop_t *loop, unsigned int count, const char *name = nullptr) : w(new uv_worker_t) { - uv_worker_init(w, loop, count, name); - } - inline ~worker() { - uv_worker_close(w, [](uv_worker_t *worker_) { - delete worker_; - }); - } - inline void add(void *data, uv_worker_cb work_cb, uv_worker_after_cb after_work_cb) { - uv_worker_send(w, data, work_cb, after_work_cb); - } - -private: - uv_worker_t *w; -}; - -template <typename T> -class work : public mbgl::util::noncopyable { -public: - typedef std::function<void (T&)> work_callback; - typedef std::function<void (T&)> after_work_callback; - - template<typename... Args> - work(worker &worker, work_callback work_cb_, after_work_callback after_work_cb_, Args&&... args) - : data(std::forward<Args>(args)...), - work_cb(work_cb_), - after_work_cb(after_work_cb_) { - worker.add(this, do_work, after_work); - } - -private: - static void do_work(void *data) { - work<T> *w = reinterpret_cast<work<T> *>(data); - w->work_cb(w->data); - } - - static void after_work(void *data) { - work<T> *w = reinterpret_cast<work<T> *>(data); - w->after_work_cb(w->data); - delete w; - } - -private: - T data; - work_callback work_cb; - after_work_callback after_work_cb; -}; - -} - -#endif diff --git a/include/mbgl/util/vec.hpp b/include/mbgl/util/vec.hpp index 0179254fda..32de852758 100644 --- a/include/mbgl/util/vec.hpp +++ b/include/mbgl/util/vec.hpp @@ -105,11 +105,6 @@ struct vec4 { }; -struct box { - vec2<double> tl, tr, bl, br; - vec2<double> center; -}; - typedef vec2<int16_t> Coordinate; } |