[android] add support for gnustl

This commit is contained in:
Konstantin Käfer
2018-06-21 14:44:00 +02:00
parent 30e570aae7
commit 4a3c4edb59
17 changed files with 59 additions and 29 deletions

View File

@@ -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.

View File

@@ -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)

View File

@@ -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

View File

@@ -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"

View File

@@ -2,6 +2,8 @@
#include "geometry.hpp"
#include "../gson/json_object.hpp"
#include <mbgl/util/string.hpp>
namespace mbgl {
namespace android {
namespace geojson {

View File

@@ -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()));
}
}

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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

View File

@@ -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); });

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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());

View File

@@ -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));

View File

@@ -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));

View File

@@ -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)));
}