diff options
Diffstat (limited to 'src/mbgl/util')
35 files changed, 228 insertions, 235 deletions
diff --git a/src/mbgl/util/atomic.hpp b/src/mbgl/util/atomic.hpp deleted file mode 100644 index 3f68bf46a5..0000000000 --- a/src/mbgl/util/atomic.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include <atomic> -#include <mutex> - -namespace mbgl { -namespace util { - -// std::atomic<bool> is implemented lock free which -// is not supported by ARMv5 but the code generated -// seems to be using that and not working at all, -// thus, this naive implementation using mutexes. -#if defined(__ANDROID__) && defined(__ARM_ARCH_5TE__) - -template <typename T> -class Atomic { -public: - Atomic() = default; - explicit Atomic(const T& data_) : data(data_) {} - - void operator=(const T& other) { - std::lock_guard<std::mutex> lock(mtx); - data = other; - } - - operator bool() const { - std::lock_guard<std::mutex> lock(mtx); - - return data; - } - -private: - T data; - mutable std::mutex mtx; -}; - -#else - -template <typename T> -using Atomic = std::atomic<T>; - -#endif - -} // namespace util -} // namespace mbgl diff --git a/src/mbgl/util/clip_id.hpp b/src/mbgl/util/clip_id.hpp index 064a7acf94..de2dc51919 100644 --- a/src/mbgl/util/clip_id.hpp +++ b/src/mbgl/util/clip_id.hpp @@ -11,20 +11,18 @@ namespace mbgl { -class Tile; - struct ClipID { - inline ClipID() {} - inline ClipID(const std::string &mask_, const std::string &reference_) : mask(mask_), reference(reference_) {} + ClipID() {} + ClipID(const std::string &mask_, const std::string &reference_) : mask(mask_), reference(reference_) {} std::bitset<8> mask; std::bitset<8> reference; - inline bool operator==(const ClipID &other) const { + bool operator==(const ClipID &other) const { return mask == other.mask && reference == other.reference; } - inline ClipID& operator|=(const ClipID &other) { + ClipID& operator|=(const ClipID &other) { mask |= other.mask; reference |= other.reference; return *this; diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp new file mode 100644 index 0000000000..eea897d3ab --- /dev/null +++ b/src/mbgl/util/color.cpp @@ -0,0 +1,20 @@ +#include <mbgl/util/color.hpp> + +#include <csscolorparser/csscolorparser.hpp> + +namespace mbgl { + +optional<Color> Color::parse(const std::string& s) { + CSSColorParser::Color css_color = CSSColorParser::parse(s); + + // Premultiply the color. + const float factor = css_color.a / 255; + return {{ + css_color.r * factor, + css_color.g * factor, + css_color.b * factor, + css_color.a + }}; +} + +} // namespace mbgl diff --git a/src/mbgl/util/convert.cpp b/src/mbgl/util/convert.cpp new file mode 100644 index 0000000000..97bfe9108d --- /dev/null +++ b/src/mbgl/util/convert.cpp @@ -0,0 +1,9 @@ +#include <mbgl/util/convert.hpp> + +namespace mbgl { +namespace util { + +template std::array<float, 2> convert(const std::array<int32_t, 2>&); + +} // namespace util +} // namespace mbgl diff --git a/src/mbgl/util/dtoa.cpp b/src/mbgl/util/dtoa.cpp index 7ccee345f6..dd4fba0f89 100644 --- a/src/mbgl/util/dtoa.cpp +++ b/src/mbgl/util/dtoa.cpp @@ -9,7 +9,7 @@ namespace { // From https://github.com/miloyip/rapidjson/blob/master/include/rapidjson/internal/dtoa.h -inline char* Prettify(char* buffer, int length, int k) { +char* Prettify(char* buffer, int length, int k) { constexpr int maxDecimalPlaces = 324; const int kk = length + k; // 10^(kk-1) <= v < 10^kk @@ -93,5 +93,13 @@ char* dtoa(double value, char* buffer) { } } +std::string dtoa(double value) { + std::string data; + data.resize(25); + auto end = dtoa(value, const_cast<char*>(data.data())); + data.resize(end - data.data()); + return data; +} + } // namespace util } // namespace mbgl diff --git a/src/mbgl/util/dtoa.hpp b/src/mbgl/util/dtoa.hpp index 17614732db..db7d309452 100644 --- a/src/mbgl/util/dtoa.hpp +++ b/src/mbgl/util/dtoa.hpp @@ -6,14 +6,7 @@ namespace mbgl { namespace util { char* dtoa(double value, char* buffer); - -inline std::string dtoa(double value) { - std::string data; - data.resize(25); - auto end = dtoa(value, const_cast<char*>(data.data())); - data.resize(end - data.data()); - return data; -} +std::string dtoa(double value); } // end namespace util } // end namespace mbgl diff --git a/src/mbgl/util/exclusive.hpp b/src/mbgl/util/exclusive.hpp index 946604af69..844588dc90 100644 --- a/src/mbgl/util/exclusive.hpp +++ b/src/mbgl/util/exclusive.hpp @@ -10,12 +10,12 @@ namespace util { template <class T> class exclusive { public: - inline exclusive(T* val, std::unique_ptr<std::lock_guard<std::mutex>> mtx) : ptr(val), lock(std::move(mtx)) {} + exclusive(T* val, std::unique_ptr<std::lock_guard<std::mutex>> mtx) : ptr(val), lock(std::move(mtx)) {} - inline T* operator->() { return ptr; } - inline const T* operator->() const { return ptr; } - inline T* operator*() { return ptr; } - inline const T* operator*() const { return ptr; } + T* operator->() { return ptr; } + const T* operator->() const { return ptr; } + T* operator*() { return ptr; } + const T* operator*() const { return ptr; } private: T *ptr; diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp index dd40af882b..fe24334e82 100644 --- a/src/mbgl/util/geo.cpp +++ b/src/mbgl/util/geo.cpp @@ -8,12 +8,12 @@ namespace mbgl { namespace { -inline double lat(const uint8_t z, const int64_t y) { +double lat(const uint8_t z, const int64_t y) { const double n = M_PI - 2.0 * M_PI * y / std::pow(2.0, z); return util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n))); } -inline double lon(const uint8_t z, const int64_t x) { +double lon(const uint8_t z, const int64_t x) { return x / std::pow(2.0, z) * util::DEGREES_MAX - util::LONGITUDE_MAX; } diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp index 4877a90e72..b3afd3fdc8 100644 --- a/src/mbgl/util/grid_index.cpp +++ b/src/mbgl/util/grid_index.cpp @@ -1,5 +1,6 @@ #include <mbgl/util/grid_index.hpp> #include <mbgl/geometry/feature_index.hpp> +#include <mbgl/math/minmax.hpp> #include <unordered_set> @@ -17,7 +18,7 @@ GridIndex<T>::GridIndex(int32_t extent_, int32_t n_, int32_t padding_) : max(extent + double(padding) / n * extent) { cells.resize(d * d); - }; + } template <class T> void GridIndex<T>::insert(T&& t, const BBox& bbox) { @@ -28,9 +29,10 @@ void GridIndex<T>::insert(T&& t, const BBox& bbox) { auto cx2 = convertToCellCoord(bbox.max.x); auto cy2 = convertToCellCoord(bbox.max.y); - for (int32_t x = cx1; x <= cx2; x++) { - for (int32_t y = cy1; y <= cy2; y++) { - auto cellIndex = d * y + x; + int32_t x, y, cellIndex; + for (x = cx1; x <= cx2; ++x) { + for (y = cy1; y <= cy2; ++y) { + cellIndex = d * y + x; cells[cellIndex].push_back(uid); } } @@ -48,9 +50,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const { auto cx2 = convertToCellCoord(queryBBox.max.x); auto cy2 = convertToCellCoord(queryBBox.max.y); - for (int32_t x = cx1; x <= cx2; x++) { - for (int32_t y = cy1; y <= cy2; y++) { - auto cellIndex = d * y + x; + int32_t x, y, cellIndex; + for (x = cx1; x <= cx2; ++x) { + for (y = cy1; y <= cy2; ++y) { + cellIndex = d * y + x; for (auto uid : cells[cellIndex]) { if (seenUids.count(uid) == 0) { seenUids.insert(uid); @@ -75,8 +78,8 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const { template <class T> int32_t GridIndex<T>::convertToCellCoord(int32_t x) const { - return std::max(0.0, std::min(d - 1.0, std::floor(x * scale) + padding)); + return util::max(0.0, util::min(d - 1.0, std::floor(x * scale) + padding)); } template class GridIndex<IndexedSubfeature>; -} +} // namespace mbgl diff --git a/src/mbgl/util/grid_index.hpp b/src/mbgl/util/grid_index.hpp index 656a4bdbd8..8ef8fb35b7 100644 --- a/src/mbgl/util/grid_index.hpp +++ b/src/mbgl/util/grid_index.hpp @@ -35,4 +35,4 @@ private: }; -} +} // namespace mbgl diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp index 18a9e6bbc5..8b9929fa4a 100644 --- a/src/mbgl/util/interpolate.hpp +++ b/src/mbgl/util/interpolate.hpp @@ -5,6 +5,7 @@ #include <string> #include <type_traits> #include <utility> +#include <mbgl/util/color.hpp> namespace mbgl { namespace util { @@ -41,6 +42,19 @@ public: } }; +template <> +struct Interpolator<Color> { +public: + Color operator()(const Color& a, const Color& b, const double t) { + return { + interpolate(a.r, b.r, t), + interpolate(a.g, b.g, t), + interpolate(a.b, b.b, t), + interpolate(a.a, b.a, t) + }; + } +}; + struct Uninterpolated { template <class T> T operator()(const T&, const T& b, const double) const { diff --git a/src/mbgl/util/intersection_tests.cpp b/src/mbgl/util/intersection_tests.cpp index 3e4ae27cd8..74b3bec388 100644 --- a/src/mbgl/util/intersection_tests.cpp +++ b/src/mbgl/util/intersection_tests.cpp @@ -143,5 +143,5 @@ bool multiPolygonIntersectsMultiPolygon(const GeometryCollection& multiPolygonA, return false; } -} -} +} // namespace util +} // namespace mbgl diff --git a/src/mbgl/util/intersection_tests.hpp b/src/mbgl/util/intersection_tests.hpp index a3ffe65cbf..be89d14ed6 100644 --- a/src/mbgl/util/intersection_tests.hpp +++ b/src/mbgl/util/intersection_tests.hpp @@ -1,6 +1,6 @@ #pragma once -#include <mbgl/tile/geometry_tile.hpp> +#include <mbgl/tile/geometry_tile_data.hpp> namespace mbgl { namespace util { @@ -9,5 +9,5 @@ bool multiPolygonIntersectsBufferedMultiPoint(const GeometryCollection&, const G bool multiPolygonIntersectsBufferedMultiLine(const GeometryCollection&, const GeometryCollection&, float radius); bool multiPolygonIntersectsMultiPolygon(const GeometryCollection&, const GeometryCollection&); -} +} // namespace util } // namespace mbgl diff --git a/src/mbgl/util/io.hpp b/src/mbgl/util/io.hpp index 2679eb5360..795a465328 100644 --- a/src/mbgl/util/io.hpp +++ b/src/mbgl/util/io.hpp @@ -7,7 +7,7 @@ namespace mbgl { namespace util { struct IOException : std::runtime_error { - inline IOException(int err, const char* msg) : std::runtime_error(msg), code(err) { + IOException(int err, const char* msg) : std::runtime_error(msg), code(err) { } const int code = 0; }; diff --git a/src/mbgl/util/mat2.cpp b/src/mbgl/util/mat2.cpp index 6910244541..4fb5abafb8 100644 --- a/src/mbgl/util/mat2.cpp +++ b/src/mbgl/util/mat2.cpp @@ -24,7 +24,7 @@ #include <cmath> -using namespace mbgl; +namespace mbgl { void matrix::identity(mat2& out) { out[0] = 1.0f; @@ -41,7 +41,7 @@ void matrix::rotate(mat2& out, const mat2& a, double rad) { out[1] = a1 * c + a3 * s; out[2] = a0 * -s + a2 * c; out[3] = a1 * -s + a3 * c; -}; +} void matrix::scale(mat2& out, const mat2& a, double v0, double v1) { double a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; @@ -50,3 +50,5 @@ void matrix::scale(mat2& out, const mat2& a, double v0, double v1) { out[2] = a2 * v1; out[3] = a3 * v1; } + +} // namespace mbgl diff --git a/src/mbgl/util/mat3.cpp b/src/mbgl/util/mat3.cpp index f4ae8841d5..e2200867ce 100644 --- a/src/mbgl/util/mat3.cpp +++ b/src/mbgl/util/mat3.cpp @@ -24,7 +24,7 @@ #include <cmath> -using namespace mbgl; +namespace mbgl { void matrix::identity(mat3& out) { out[0] = 1.0f; @@ -80,7 +80,7 @@ void matrix::rotate(mat3& out, const mat3& a, double rad) { out[6] = a20; out[7] = a21; out[8] = a22; -}; +} void matrix::scale(mat3& out, const mat3& a, double x, double y) { out[0] = x * a[0]; @@ -93,3 +93,5 @@ void matrix::scale(mat3& out, const mat3& a, double x, double y) { out[7] = a[7]; out[8] = a[8]; } + +} // namespace mbgl diff --git a/src/mbgl/util/math.cpp b/src/mbgl/util/math.cpp index 0e86849ad3..7b1516c041 100644 --- a/src/mbgl/util/math.cpp +++ b/src/mbgl/util/math.cpp @@ -11,8 +11,8 @@ uint32_t ceil_log2(uint64_t x) { uint32_t y = (((x & (x - 1)) == 0) ? 0 : 1); uint32_t j = 32; - for (int32_t i = 0; i < 6; i++) { - const uint32_t k = (((x & t[i]) == 0) ? 0 : j); + for (const auto& i : t) { + const uint32_t k = (((x & i) == 0) ? 0 : j); y += k; x >>= k; j >>= 1; @@ -24,7 +24,7 @@ uint32_t ceil_log2(uint64_t x) { double log2(double x) { // log2() is producing wrong results on ARMv5 binaries // running on ARMv7+ CPUs. -#if defined(__ANDROID__) && defined(__ARM_ARCH_5TE__) +#if defined(__ANDROID__) return std::log(x) / 0.6931471805599453; // log(x) / log(2) #else return ::log2(x); diff --git a/src/mbgl/util/math.hpp b/src/mbgl/util/math.hpp index bfedc2a421..5d4220d0a2 100644 --- a/src/mbgl/util/math.hpp +++ b/src/mbgl/util/math.hpp @@ -14,18 +14,18 @@ namespace util { // Find the angle of the two vectors, solving the formula for the cross product // a x b = |a||b|sin(θ) for θ. template <typename T = double, typename S> -inline T angle_between(const Point<S>& a, const Point<S>& b) { +T angle_between(const Point<S>& a, const Point<S>& b) { return std::atan2((a.x * b.y - a.y * b.x), a.x * b.x + a.y * b.y); } template <typename T = double, typename S> -inline T angle_to(const Point<S>& a, const Point<S>& b) { +T angle_to(const Point<S>& a, const Point<S>& b) { return std::atan2(a.y - b.y, a.x - b.x); } // Reflect an angle around 0 degrees template <typename T> -inline std::array<T, 2> flip(const std::array<T, 2>& c) { +std::array<T, 2> flip(const std::array<T, 2>& c) { return {{ static_cast<T>(2 * M_PI - c[0]), static_cast<T>(2 * M_PI - c[1]) @@ -33,7 +33,7 @@ inline std::array<T, 2> flip(const std::array<T, 2>& c) { } template <typename T, typename S1, typename S2> -inline Point<T> normal(const S1& a, const S2& b) { +Point<T> normal(const S1& a, const S2& b) { T dx = b.x - a.x; T dy = b.y - a.y; T c = std::sqrt(dx * dx + dy * dy); @@ -41,12 +41,12 @@ inline Point<T> normal(const S1& a, const S2& b) { } template <typename T> -inline T perp(const T& a) { +T perp(const T& a) { return T(-a.y, a.x); } template <typename T, typename S1, typename S2> -inline T dist(const S1& a, const S2& b) { +T dist(const S1& a, const S2& b) { T dx = b.x - a.x; T dy = b.y - a.y; T c = std::sqrt(dx * dx + dy * dy); @@ -54,7 +54,7 @@ inline T dist(const S1& a, const S2& b) { } template <typename T, typename S1, typename S2> -inline T distSqr(const S1& a, const S2& b) { +T distSqr(const S1& a, const S2& b) { T dx = b.x - a.x; T dy = b.y - a.y; T c = dx * dx + dy * dy; @@ -62,23 +62,23 @@ inline T distSqr(const S1& a, const S2& b) { } template <typename T> -inline T round(const T& a) { +T round(const T& a) { return T(::round(a.x), ::round(a.y)); } template <typename T> -inline T length(T a, T b) { +T length(T a, T b) { return std::sqrt(a * a + b * b); } // Take the magnitude of vector a. template <typename T = double, typename S> -inline T mag(const S& a) { +T mag(const S& a) { return std::sqrt(a.x * a.x + a.y * a.y); } template <typename S> -inline S unit(const S& a) { +S unit(const S& a) { auto magnitude = mag(a); if (magnitude == 0) { return a; @@ -87,7 +87,7 @@ inline S unit(const S& a) { } template <typename T, typename S = double> -inline T rotate(const T& a, S angle) { +T rotate(const T& a, S angle) { S cos = std::cos(angle); S sin = std::sin(angle); S x = cos * a.x - sin * a.y; @@ -96,7 +96,7 @@ inline T rotate(const T& a, S angle) { } template <typename T> -inline Point<T> matrixMultiply(const std::array<T, 4>& m, const Point<T>& p) { +Point<T> matrixMultiply(const std::array<T, 4>& m, const Point<T>& p) { return Point<T>(m[0] * p.x + m[1] * p.y, m[2] * p.x + m[3] * p.y); } diff --git a/src/mbgl/util/ptr.hpp b/src/mbgl/util/ptr.hpp index 2dc8118181..87c4e9f7cf 100644 --- a/src/mbgl/util/ptr.hpp +++ b/src/mbgl/util/ptr.hpp @@ -10,14 +10,14 @@ template <typename T> class ptr : public ::std::shared_ptr<T> { public: template <typename... Args> - inline ptr(Args &&... args) + ptr(Args &&... args) : ::std::shared_ptr<T>(::std::forward<Args>(args)...) {} - inline auto operator->() const -> decltype(this->::std::shared_ptr<T>::operator->()) { + auto operator->() const -> decltype(this->::std::shared_ptr<T>::operator->()) { assert(*this); return ::std::shared_ptr<T>::operator->(); } - inline auto operator*() const -> decltype(this->::std::shared_ptr<T>::operator*()) { + auto operator*() const -> decltype(this->::std::shared_ptr<T>::operator*()) { assert(*this); return ::std::shared_ptr<T>::operator*(); } diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp index 3146a00513..3f9cb467b9 100644 --- a/src/mbgl/util/raster.cpp +++ b/src/mbgl/util/raster.cpp @@ -1,5 +1,6 @@ #include <mbgl/platform/platform.hpp> #include <mbgl/gl/gl.hpp> +#include <mbgl/gl/gl_config.hpp> #include <mbgl/platform/log.hpp> #include <mbgl/util/raster.hpp> @@ -7,59 +8,80 @@ #include <cassert> #include <cstring> -using namespace mbgl; - -Raster::Raster(gl::TexturePool& texturePool_) - : texturePool(texturePool_) -{} +namespace mbgl { bool Raster::isLoaded() const { - std::lock_guard<std::mutex> lock(mtx); return loaded; } -void Raster::load(PremultipliedImage image) { +void Raster::load(PremultipliedImage image, uint32_t mipmapLevel) { assert(image.data.get()); - img = std::move(image); - width = GLsizei(img.width); - height = GLsizei(img.height); + if (images.size() <= mipmapLevel) { + images.resize(mipmapLevel + 1); + } + images.at(mipmapLevel) = std::move(image); - std::lock_guard<std::mutex> lock(mtx); loaded = true; } +void Raster::bind(gl::ObjectStore& store, + gl::Config& config, + uint32_t unit, + Scaling newFilter, + MipMap newMipMap) { + bool updateFilter = false; -void Raster::bind(bool linear, gl::ObjectStore& store) { - if (!width || !height) { - Log::Error(Event::OpenGL, "trying to bind texture without dimension"); - return; + if (!texture) { + if (images.empty()) { + Log::Error(Event::OpenGL, "trying to bind texture without images"); + return; + } else { + upload(store, config, unit); + updateFilter = true; + } + } else { + if (config.texture[unit] != *texture) { + config.activeTexture = unit; + config.texture[unit] = *texture; + } + updateFilter = (filter != newFilter || mipmap != newMipMap); } - if (img.data && !texture) { - upload(store); - } else if (texture) { - MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture)); - } - - GLint new_filter = linear ? GL_LINEAR : GL_NEAREST; - if (new_filter != this->filter) { - MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, new_filter)); - MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, new_filter)); - filter = new_filter; + if (updateFilter) { + filter = newFilter; + mipmap = newMipMap; + config.activeTexture = unit; + MBGL_CHECK_ERROR(glTexParameteri( + GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + filter == Scaling::Linear + ? (mipmap == MipMap::Yes ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR) + : (mipmap == MipMap::Yes ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST))); + MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + filter == Scaling::Linear ? GL_LINEAR : GL_NEAREST)); } } -void Raster::upload(gl::ObjectStore& store) { - if (img.data && !texture) { - texture = texturePool.acquireTexture(store); - MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture)); +void Raster::upload(gl::ObjectStore& store, gl::Config& config, uint32_t unit) { + if (!images.empty() && !texture) { + texture = store.createTexture(); + config.activeTexture = unit; + config.texture[unit] = *texture; #ifndef GL_ES_VERSION_2_0 - MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); + MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, images.size())); #endif MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); - MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.get())); - img.data.reset(); + GLint level = 0; + for (auto& img : images) { + assert(img.data.get()); + MBGL_CHECK_ERROR(glTexImage2D( + GL_TEXTURE_2D, level++, GL_RGBA, static_cast<GLsizei>(img.width), + static_cast<GLsizei>(img.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.get())); + } + images.clear(); + images.shrink_to_fit(); } } + +} // namespace mbgl diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp index b539032d81..34e7c67678 100644 --- a/src/mbgl/util/raster.hpp +++ b/src/mbgl/util/raster.hpp @@ -1,58 +1,51 @@ #pragma once -#include <mbgl/gl/gl.hpp> -#include <mbgl/gl/texture_pool.hpp> +#include <mbgl/gl/object_store.hpp> #include <mbgl/util/image.hpp> -#include <mbgl/util/ptr.hpp> -#include <mbgl/util/chrono.hpp> #include <mbgl/util/optional.hpp> -#include <mutex> +#include <atomic> namespace mbgl { -class Raster : public std::enable_shared_from_this<Raster> { +namespace gl { +class Config; +} // namespace gl +class Raster { public: - Raster(gl::TexturePool&); + enum class MipMap : bool { No = false, Yes = true }; + enum class Scaling : bool { Nearest = false, Linear = true }; // load image data - void load(PremultipliedImage); + void load(PremultipliedImage, uint32_t mipmapLevel = 0); // bind current texture - void bind(bool linear, gl::ObjectStore&); + void bind(gl::ObjectStore&, + gl::Config&, + uint32_t unit, + Scaling = Scaling::Nearest, + MipMap = MipMap::No); // uploads the texture if it hasn't been uploaded yet. - void upload(gl::ObjectStore&); + void upload(gl::ObjectStore&, gl::Config&, uint32_t unit); // loaded status bool isLoaded() const; -public: - // loaded image dimensions - GLsizei width = 0; - GLsizei height = 0; - - // GL buffer object handle. - mbgl::optional<gl::PooledTexture> texture; - - // texture opacity - double opacity = 0; - private: - mutable std::mutex mtx; - // raw pixels have been loaded - bool loaded = false; - - // shared texture pool - gl::TexturePool& texturePool; + std::atomic<bool> loaded { false }; - // min/mag filter - GLint filter = 0; + // filters + Scaling filter = Scaling::Nearest; + MipMap mipmap = MipMap::No; // the raw pixels - PremultipliedImage img; + std::vector<PremultipliedImage> images; + + // GL buffer object handle. + mbgl::optional<gl::UniqueTexture> texture; }; } // namespace mbgl diff --git a/src/mbgl/util/rect.hpp b/src/mbgl/util/rect.hpp index 2b877db40d..f5937f5c94 100644 --- a/src/mbgl/util/rect.hpp +++ b/src/mbgl/util/rect.hpp @@ -4,21 +4,21 @@ namespace mbgl { template <typename T> struct Rect { - inline Rect() = default; - inline Rect(T x_, T y_, T w_, T h_) : x(x_), y(y_), w(w_), h(h_) {} + Rect() = default; + 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> - inline Rect operator *(Number value) const { + Rect operator *(Number value) const { return Rect(x * value, y * value, w * value, h * value); } template <typename R> - inline bool operator==(const R& r) const { + bool operator==(const R& r) const { return x == r.x && y == r.y && w == r.w && h == r.h; } - inline bool hasArea() const { return w != 0 && h != 0; } + bool hasArea() const { return w != 0 && h != 0; } }; } // namespace mbgl diff --git a/src/mbgl/util/stopwatch.cpp b/src/mbgl/util/stopwatch.cpp index bbc6bfba0c..d588b79254 100644 --- a/src/mbgl/util/stopwatch.cpp +++ b/src/mbgl/util/stopwatch.cpp @@ -7,7 +7,8 @@ #include <iostream> #include <atomic> -using namespace mbgl::util; +namespace mbgl { +namespace util { stopwatch::stopwatch(Event event_) : event(event_), start(Clock::now()) {} @@ -15,11 +16,11 @@ stopwatch::stopwatch(Event event_) stopwatch::stopwatch(EventSeverity severity_, Event event_) : severity(severity_), event(event_), start(Clock::now()) {} -stopwatch::stopwatch(const std::string &name_, Event event_) - : name(name_), event(event_), start(Clock::now()) {} +stopwatch::stopwatch(std::string name_, Event event_) + : name(std::move(name_)), event(event_), start(Clock::now()) {} -stopwatch::stopwatch(const std::string &name_, EventSeverity severity_, Event event_) - : name(name_), severity(severity_), event(event_), start(Clock::now()) {} +stopwatch::stopwatch(std::string name_, EventSeverity severity_, Event event_) + : name(std::move(name_)), severity(severity_), event(event_), start(Clock::now()) {} void stopwatch::report(const std::string &name_) { Duration duration = Clock::now() - start; @@ -33,4 +34,8 @@ stopwatch::~stopwatch() { report(name); } } + +} // namespace util +} // namespace mbgl + #endif diff --git a/src/mbgl/util/stopwatch.hpp b/src/mbgl/util/stopwatch.hpp index 23086b1747..74cc2c412d 100644 --- a/src/mbgl/util/stopwatch.hpp +++ b/src/mbgl/util/stopwatch.hpp @@ -13,8 +13,8 @@ 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); + stopwatch(std::string name, Event event = Event::General); + stopwatch(std::string name, EventSeverity severity, Event event = Event::General); void report(const std::string &name); ~stopwatch(); @@ -26,12 +26,12 @@ private: }; #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() {} + 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() {} }; #endif } // namespace util diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp index c5f9d7338a..cd90e08049 100644 --- a/src/mbgl/util/thread.hpp +++ b/src/mbgl/util/thread.hpp @@ -6,7 +6,6 @@ #include <utility> #include <functional> -#include <mbgl/util/atomic.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/thread_context.hpp> #include <mbgl/platform/platform.hpp> @@ -95,13 +94,7 @@ Thread<Object>::Thread(const ThreadContext& context, Args&&... args) { std::tuple<Args...> params = std::forward_as_tuple(::std::forward<Args>(args)...); thread = std::thread([&] { -#if defined(__APPLE__) - pthread_setname_np(context.name.c_str()); -#elif defined(__GLIBC__) && defined(__GLIBC_PREREQ) -#if __GLIBC_PREREQ(2, 12) - pthread_setname_np(pthread_self(), context.name.c_str()); -#endif -#endif + platform::setCurrentThreadName(context.name); if (context.priority == ThreadPriority::Low) { platform::makeThreadLowPriority(); diff --git a/src/mbgl/util/thread_context.cpp b/src/mbgl/util/thread_context.cpp index f728e32df7..fe64c2a686 100644 --- a/src/mbgl/util/thread_context.cpp +++ b/src/mbgl/util/thread_context.cpp @@ -1,10 +1,11 @@ #include <mbgl/util/thread_context.hpp> +#include <utility> namespace mbgl { namespace util { -ThreadContext::ThreadContext(const std::string& name_, ThreadPriority priority_) - : name(name_), +ThreadContext::ThreadContext(std::string name_, ThreadPriority priority_) + : name(std::move(name_)), priority(priority_) { } diff --git a/src/mbgl/util/thread_context.hpp b/src/mbgl/util/thread_context.hpp index 60b32b3b2a..a51dede404 100644 --- a/src/mbgl/util/thread_context.hpp +++ b/src/mbgl/util/thread_context.hpp @@ -12,7 +12,7 @@ enum class ThreadPriority : bool { struct ThreadContext { public: - ThreadContext(const std::string& name, ThreadPriority priority = ThreadPriority::Regular); + ThreadContext(std::string name, ThreadPriority priority = ThreadPriority::Regular); std::string name; ThreadPriority priority; diff --git a/src/mbgl/util/thread_local.hpp b/src/mbgl/util/thread_local.hpp index c3364c5d42..67e3842ec6 100644 --- a/src/mbgl/util/thread_local.hpp +++ b/src/mbgl/util/thread_local.hpp @@ -12,12 +12,12 @@ namespace util { template <class T> class ThreadLocal : public noncopyable { public: - inline ThreadLocal(T* val) { + ThreadLocal(T* val) { ThreadLocal(); set(val); } - inline ThreadLocal() { + ThreadLocal() { int ret = pthread_key_create(&key, [](void *ptr) { delete reinterpret_cast<T *>(ptr); }); @@ -27,13 +27,13 @@ public: } } - inline ~ThreadLocal() { + ~ThreadLocal() { if (pthread_key_delete(key)) { throw std::runtime_error("Failed to delete local storage key."); } } - inline T* get() { + T* get() { T* ret = reinterpret_cast<T*>(pthread_getspecific(key)); if (!ret) { return nullptr; @@ -42,7 +42,7 @@ public: return ret; } - inline void set(T* ptr) { + void set(T* ptr) { if (pthread_setspecific(key, ptr)) { throw std::runtime_error("Failed to set local storage."); } diff --git a/src/mbgl/util/tile_coordinate.cpp b/src/mbgl/util/tile_coordinate.cpp deleted file mode 100644 index d9a0ea352c..0000000000 --- a/src/mbgl/util/tile_coordinate.cpp +++ /dev/null @@ -1 +0,0 @@ -#include <mbgl/util/tile_coordinate.hpp> diff --git a/src/mbgl/util/tileset.hpp b/src/mbgl/util/tileset.hpp deleted file mode 100644 index 972fc51f8c..0000000000 --- a/src/mbgl/util/tileset.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <mbgl/util/constants.hpp> -#include <mbgl/util/geo.hpp> - -#include <array> -#include <vector> -#include <string> -#include <cstdint> - -namespace mbgl { - -class Tileset { -public: - std::vector<std::string> tiles; - uint8_t minZoom = 0; - uint8_t maxZoom = 22; - std::string attribution; - LatLng center; - double zoom = 0; - LatLngBounds bounds = LatLngBounds::world(); -}; - -} // namespace mbgl diff --git a/src/mbgl/util/utf.hpp b/src/mbgl/util/utf.hpp index 02aabfc4c2..560ca3ba7f 100644 --- a/src/mbgl/util/utf.hpp +++ b/src/mbgl/util/utf.hpp @@ -17,5 +17,5 @@ class utf8_to_utf32 { } }; -} // namespace mbgl } // namespace util +} // namespace mbgl diff --git a/src/mbgl/util/version_info.cpp b/src/mbgl/util/version_info.cpp index c545ddcc40..f0fb139bca 100644 --- a/src/mbgl/util/version_info.cpp +++ b/src/mbgl/util/version_info.cpp @@ -11,4 +11,4 @@ const char *string = MBGL_VERSION_STRING; const unsigned int number = MBGL_VERSION; } // namespace version -} // namespace mbgl
\ No newline at end of file +} // namespace mbgl diff --git a/src/mbgl/util/work_task.cpp b/src/mbgl/util/work_task.cpp deleted file mode 100644 index e69de29bb2..0000000000 --- a/src/mbgl/util/work_task.cpp +++ /dev/null diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp index 2bc545c704..50ecb93c02 100644 --- a/src/mbgl/util/worker.cpp +++ b/src/mbgl/util/worker.cpp @@ -3,7 +3,7 @@ #include <mbgl/util/work_request.hpp> #include <mbgl/platform/platform.hpp> #include <mbgl/renderer/raster_bucket.hpp> -#include <mbgl/tile/geometry_tile.hpp> +#include <mbgl/tile/geometry_tile_data.hpp> #include <mbgl/style/layer.hpp> #include <mbgl/text/collision_tile.hpp> @@ -31,11 +31,11 @@ public: void parseGeometryTile(TileWorker* worker, std::vector<std::unique_ptr<style::Layer>> layers, - std::unique_ptr<GeometryTile> tile, + std::unique_ptr<GeometryTileData> tileData, PlacementConfig config, std::function<void(TileParseResult)> callback) { try { - callback(worker->parseAllLayers(std::move(layers), std::move(tile), config)); + callback(worker->parseAllLayers(std::move(layers), std::move(tileData), config)); } catch (...) { callback(std::current_exception()); } @@ -80,12 +80,12 @@ Worker::parseRasterTile(std::unique_ptr<RasterBucket> bucket, std::unique_ptr<AsyncRequest> Worker::parseGeometryTile(TileWorker& worker, std::vector<std::unique_ptr<style::Layer>> layers, - std::unique_ptr<GeometryTile> tile, + std::unique_ptr<GeometryTileData> tileData, PlacementConfig config, std::function<void(TileParseResult)> callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parseGeometryTile, callback, &worker, - std::move(layers), std::move(tile), config); + std::move(layers), std::move(tileData), config); } std::unique_ptr<AsyncRequest> diff --git a/src/mbgl/util/worker.hpp b/src/mbgl/util/worker.hpp index 678dfaedb3..5ab86d1b9e 100644 --- a/src/mbgl/util/worker.hpp +++ b/src/mbgl/util/worker.hpp @@ -41,7 +41,7 @@ public: Request parseGeometryTile(TileWorker&, std::vector<std::unique_ptr<style::Layer>>, - std::unique_ptr<GeometryTile>, + std::unique_ptr<GeometryTileData>, PlacementConfig, std::function<void(TileParseResult)> callback); |