diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-06-21 14:44:00 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-09-11 11:43:54 +0200 |
commit | 4a3c4edb59b6881a30056531bc71e52295ab1cb0 (patch) | |
tree | b1c466667efc84cd5f7345d977032155f315ec76 | |
parent | 30e570aae7d2ba5522feafb962b334ef3f35459e (diff) | |
download | qtlocation-mapboxgl-4a3c4edb59b6881a30056531bc71e52295ab1cb0.tar.gz |
[android] add support for gnustl
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | cmake/mason-dependencies.cmake | 2 | ||||
-rw-r--r-- | include/mbgl/math/log2.hpp | 11 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/build.gradle | 8 | ||||
-rw-r--r-- | platform/android/src/geojson/feature.cpp | 2 | ||||
-rw-r--r-- | platform/linux/src/headless_backend_egl.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_image_source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/expression/compound_expression.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/text/collision_feature.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/dtoa.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/util/tile_cover.cpp | 2 | ||||
-rw-r--r-- | test/map/transform.test.cpp | 6 | ||||
-rw-r--r-- | test/storage/http_file_source.test.cpp | 5 | ||||
-rw-r--r-- | test/storage/online_file_source.test.cpp | 5 | ||||
-rw-r--r-- | test/util/dtoa.test.cpp | 26 |
17 files changed, 59 insertions, 29 deletions
@@ -522,7 +522,8 @@ MBGL_ANDROID_LIBDIR = lib$(if $(filter arm-v8 x86-64,$1),64) MBGL_ANDROID_DALVIKVM = dalvikvm$(if $(filter arm-v8 x86-64,$1),64,32) MBGL_ANDROID_APK_SUFFIX = $(if $(filter Release,$(BUILDTYPE)),release-unsigned,debug) MBGL_ANDROID_CORE_TEST_DIR = platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/$(buildtype)/$2/core-tests -MBGL_ANDROID_GRADLE = ./gradlew --parallel --max-workers=$(JOBS) -Pmapbox.buildtype=$(buildtype) +MBGL_ANDROID_STL ?= c++_static +MBGL_ANDROID_GRADLE = ./gradlew --parallel --max-workers=$(JOBS) -Pmapbox.buildtype=$(buildtype) -Pmapbox.stl=$(MBGL_ANDROID_STL) # Lists all devices, and extracts the identifiers, then obtains the ABI for every one. # Some devices return \r\n, so we'll have to remove the carriage return before concatenating. diff --git a/cmake/mason-dependencies.cmake b/cmake/mason-dependencies.cmake index 6c571db259..a143ec8ee6 100644 --- a/cmake/mason-dependencies.cmake +++ b/cmake/mason-dependencies.cmake @@ -5,7 +5,7 @@ mason_use(variant VERSION 1.1.4 HEADER_ONLY) mason_use(unique_resource VERSION cba309e HEADER_ONLY) mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY) mason_use(boost VERSION 1.65.1 HEADER_ONLY) -mason_use(geojsonvt VERSION 6.6.0 HEADER_ONLY) +mason_use(geojsonvt VERSION 6.6.1 HEADER_ONLY) mason_use(supercluster VERSION 0.2.2 HEADER_ONLY) mason_use(kdbush VERSION 0.1.1-1 HEADER_ONLY) mason_use(earcut VERSION 0.12.4 HEADER_ONLY) diff --git a/include/mbgl/math/log2.hpp b/include/mbgl/math/log2.hpp index 3136ac22b4..4f5fde60d1 100644 --- a/include/mbgl/math/log2.hpp +++ b/include/mbgl/math/log2.hpp @@ -15,6 +15,17 @@ namespace util { // (== number of bits required to store x) uint32_t ceil_log2(uint64_t x); +template <typename T> +T log2(T x) { +// log2() is producing wrong results on ARMv5 binaries +// running on ARMv7+ CPUs. +#if defined(__ANDROID__) + return ::log(x) / M_LN2; +#else + return ::log2(x); +#endif +} + } // namespace util } // namespace mbgl diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index e796c35cee..d122687823 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -59,12 +59,18 @@ android { } } + // Allow determining the C++ STL we're using when building Mapbox GL. + def stl = 'c++_static' + if (project.hasProperty("mapbox.stl")) { + stl = project.getProperty("mapbox.stl") + } + defaultConfig { if (abi != 'none') { externalNativeBuild { cmake { arguments "-DANDROID_TOOLCHAIN=clang" - arguments "-DANDROID_STL=c++_static" + arguments "-DANDROID_STL=" + stl arguments "-DANDROID_CPP_FEATURES=rtti;exceptions" arguments "-DMBGL_PLATFORM=android" arguments "-DMASON_PLATFORM=android" diff --git a/platform/android/src/geojson/feature.cpp b/platform/android/src/geojson/feature.cpp index e79c238864..f0ed097842 100644 --- a/platform/android/src/geojson/feature.cpp +++ b/platform/android/src/geojson/feature.cpp @@ -2,6 +2,8 @@ #include "geometry.hpp" #include "../gson/json_object.hpp" +#include <mbgl/util/string.hpp> + namespace mbgl { namespace android { namespace geojson { diff --git a/platform/linux/src/headless_backend_egl.cpp b/platform/linux/src/headless_backend_egl.cpp index 089e344987..d72fbbfdea 100644 --- a/platform/linux/src/headless_backend_egl.cpp +++ b/platform/linux/src/headless_backend_egl.cpp @@ -1,5 +1,6 @@ #include <mbgl/gl/headless_backend.hpp> +#include <mbgl/util/string.hpp> #include <mbgl/util/logging.hpp> #include <EGL/egl.h> @@ -98,7 +99,7 @@ public: eglSurface = eglCreatePbufferSurface(eglDisplay->display, eglDisplay->config, surfAttribs); if (eglSurface == EGL_NO_SURFACE) { - throw std::runtime_error("Could not create surface: " + std::to_string(eglGetError())); + throw std::runtime_error("Could not create surface: " + util::toString(eglGetError())); } } diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index c177299485..ddac5c5c8f 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -402,7 +402,7 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo scaleY -= (padding.top() + padding.bottom()) / height; minScale = util::min(scaleX, scaleY); } - double zoom = transform.getZoom() + ::log2(minScale); + double zoom = transform.getZoom() + util::log2(minScale); zoom = util::clamp(zoom, transform.getState().getMinZoom(), transform.getState().getMaxZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index 948954570f..9ff68a1a60 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -270,7 +270,7 @@ double TransformState::zoomScale(double zoom) const { } double TransformState::scaleZoom(double s) const { - return ::log2(s); + return util::log2(s); } ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng) const { diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index d4577e787a..f9ae5588d1 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -139,7 +139,7 @@ void RenderImageSource::update(Immutable<style::Source::Impl> baseImpl_, auto dx = nePoint.x - swPoint.x; auto dy = nePoint.y - swPoint.y; auto dMax = std::max(dx, dy); - double zoom = std::max(0.0, std::floor(-::log2(dMax))); + double zoom = std::max(0.0, std::floor(-util::log2(dMax))); // Only enable if the long side of the image is > 2 pixels. Resulting in a // display of at least 2 x 1 px image diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index 2e823ff43d..6e87167d5a 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -467,7 +467,7 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali define("sqrt", [](double x) -> Result<double> { return sqrt(x); }); define("log10", [](double x) -> Result<double> { return log10(x); }); define("ln", [](double x) -> Result<double> { return log(x); }); - define("log2", [](double x) -> Result<double> { return log2(x); }); + define("log2", [](double x) -> Result<double> { return util::log2(x); }); define("sin", [](double x) -> Result<double> { return sin(x); }); define("cos", [](double x) -> Result<double> { return cos(x); }); define("tan", [](double x) -> Result<double> { return tan(x); }); diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp index ac4dbff2af..ee7322e692 100644 --- a/src/mbgl/text/collision_feature.cpp +++ b/src/mbgl/text/collision_feature.cpp @@ -52,7 +52,7 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoo // symbol spacing will put labels very close together in a pitched map. // To reduce the cost of adding extra collision circles, we slowly increase // them for overscaled tiles. - const float overscalingPaddingFactor = 1 + .4 * ::log2(static_cast<double>(overscaling)); + const float overscalingPaddingFactor = 1 + .4 * util::log2(static_cast<double>(overscaling)); const int nPitchPaddingBoxes = std::floor(nBoxes * overscalingPaddingFactor / 2); // offset the center of the first box by half a box so that the edge of the diff --git a/src/mbgl/util/dtoa.hpp b/src/mbgl/util/dtoa.hpp index 4cb81a94be..e6b1659aa2 100644 --- a/src/mbgl/util/dtoa.hpp +++ b/src/mbgl/util/dtoa.hpp @@ -1,11 +1,16 @@ #pragma once #include <string> +#include <cstdlib> namespace mbgl { namespace util { std::string dtoa(double value); +inline double stod(const std::string& str) { + return ::strtod(str.c_str(), nullptr); +} + } // end namespace util } // end namespace mbgl diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp index f58d1270bd..7979c550a9 100644 --- a/src/mbgl/util/tile_cover.cpp +++ b/src/mbgl/util/tile_cover.cpp @@ -131,7 +131,7 @@ std::vector<UnwrappedTileID> tileCover(const Point<double>& tl, } // namespace int32_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) { - zoom += ::log2(util::tileSize / size); + zoom += util::log2(util::tileSize / size); if (type == style::SourceType::Raster || type == style::SourceType::Video) { return ::round(zoom); } else { diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 11c2c1cc6b..44b5f49366 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -3,6 +3,8 @@ #include <mbgl/map/transform.hpp> #include <mbgl/util/geo.hpp> +#include <cmath> + using namespace mbgl; TEST(Transform, InvalidZoom) { @@ -15,7 +17,7 @@ TEST(Transform, InvalidZoom) { transform.setZoom(1); ASSERT_DOUBLE_EQ(1, transform.getZoom()); - const double invalid = std::nan(""); + const double invalid = NAN; transform.setZoom(invalid); @@ -67,7 +69,7 @@ TEST(Transform, InvalidBearing) { ASSERT_DOUBLE_EQ(1, transform.getZoom()); ASSERT_DOUBLE_EQ(2, transform.getAngle()); - const double invalid = std::nan(""); + const double invalid = NAN; transform.setAngle(invalid); ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude()); diff --git a/test/storage/http_file_source.test.cpp b/test/storage/http_file_source.test.cpp index 006b7a0fb3..42b4174e69 100644 --- a/test/storage/http_file_source.test.cpp +++ b/test/storage/http_file_source.test.cpp @@ -2,6 +2,7 @@ #include <mbgl/storage/http_file_source.hpp> #include <mbgl/util/exception.hpp> #include <mbgl/util/chrono.hpp> +#include <mbgl/util/string.hpp> #include <mbgl/util/run_loop.hpp> using namespace mbgl; @@ -177,12 +178,12 @@ TEST(HTTPFileSource, TEST_REQUIRES_SERVER(Load)) { std::function<void(int)> req = [&](int i) { const auto current = number++; reqs[i] = fs.request({ Resource::Unknown, - std::string("http://127.0.0.1:3000/load/") + std::to_string(current) }, + std::string("http://127.0.0.1:3000/load/") + util::toString(current) }, [&, i, current](Response res) { reqs[i].reset(); EXPECT_EQ(nullptr, res.error); ASSERT_TRUE(res.data.get()); - EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data); + EXPECT_EQ(std::string("Request ") + util::toString(current), *res.data); EXPECT_FALSE(bool(res.expires)); EXPECT_FALSE(res.mustRevalidate); EXPECT_FALSE(bool(res.modified)); diff --git a/test/storage/online_file_source.test.cpp b/test/storage/online_file_source.test.cpp index 70bfe3ac95..b5a7c139d3 100644 --- a/test/storage/online_file_source.test.cpp +++ b/test/storage/online_file_source.test.cpp @@ -4,6 +4,7 @@ #include <mbgl/util/chrono.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/timer.hpp> +#include <mbgl/util/string.hpp> #include <mbgl/util/constants.hpp> #include <gtest/gtest.h> @@ -240,12 +241,12 @@ TEST(OnlineFileSource, TEST_REQUIRES_SERVER(Load)) { std::function<void(int)> req = [&](int i) { const auto current = number++; reqs[i] = fs.request({ Resource::Unknown, - std::string("http://127.0.0.1:3000/load/") + std::to_string(current) }, + std::string("http://127.0.0.1:3000/load/") + util::toString(current) }, [&, i, current](Response res) { reqs[i].reset(); EXPECT_EQ(nullptr, res.error); ASSERT_TRUE(res.data.get()); - EXPECT_EQ(std::string("Request ") + std::to_string(current), *res.data); + EXPECT_EQ(std::string("Request ") + util::toString(current), *res.data); EXPECT_FALSE(bool(res.expires)); EXPECT_FALSE(res.mustRevalidate); EXPECT_FALSE(bool(res.modified)); diff --git a/test/util/dtoa.test.cpp b/test/util/dtoa.test.cpp index 8d2fba1877..ca13a51c40 100644 --- a/test/util/dtoa.test.cpp +++ b/test/util/dtoa.test.cpp @@ -8,17 +8,17 @@ using namespace mbgl; TEST(Dtoa, Precision) { - EXPECT_EQ(M_E, std::stod(util::dtoa(M_E))); - EXPECT_EQ(M_LOG2E, std::stod(util::dtoa(M_LOG2E))); - EXPECT_EQ(M_LOG10E, std::stod(util::dtoa(M_LOG10E))); - EXPECT_EQ(M_LN2, std::stod(util::dtoa(M_LN2))); - EXPECT_EQ(M_LN10, std::stod(util::dtoa(M_LN10))); - EXPECT_EQ(M_PI, std::stod(util::dtoa(M_PI))); - EXPECT_EQ(M_PI_2, std::stod(util::dtoa(M_PI_2))); - EXPECT_EQ(M_PI_4, std::stod(util::dtoa(M_PI_4))); - EXPECT_EQ(M_1_PI, std::stod(util::dtoa(M_1_PI))); - EXPECT_EQ(M_2_PI, std::stod(util::dtoa(M_2_PI))); - EXPECT_EQ(M_2_SQRTPI, std::stod(util::dtoa(M_2_SQRTPI))); - EXPECT_EQ(M_SQRT2, std::stod(util::dtoa(M_SQRT2))); - EXPECT_EQ(M_SQRT1_2, std::stod(util::dtoa(M_SQRT1_2))); + EXPECT_EQ(M_E, util::stod(util::dtoa(M_E))); + EXPECT_EQ(M_LOG2E, util::stod(util::dtoa(M_LOG2E))); + EXPECT_EQ(M_LOG10E, util::stod(util::dtoa(M_LOG10E))); + EXPECT_EQ(M_LN2, util::stod(util::dtoa(M_LN2))); + EXPECT_EQ(M_LN10, util::stod(util::dtoa(M_LN10))); + EXPECT_EQ(M_PI, util::stod(util::dtoa(M_PI))); + EXPECT_EQ(M_PI_2, util::stod(util::dtoa(M_PI_2))); + EXPECT_EQ(M_PI_4, util::stod(util::dtoa(M_PI_4))); + EXPECT_EQ(M_1_PI, util::stod(util::dtoa(M_1_PI))); + EXPECT_EQ(M_2_PI, util::stod(util::dtoa(M_2_PI))); + EXPECT_EQ(M_2_SQRTPI, util::stod(util::dtoa(M_2_SQRTPI))); + EXPECT_EQ(M_SQRT2, util::stod(util::dtoa(M_SQRT2))); + EXPECT_EQ(M_SQRT1_2, util::stod(util::dtoa(M_SQRT1_2))); } |