diff --git a/.gitignore b/.gitignore index b253752e5..3e46c0a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ /ios/build /ios/app/build /test/build +/gyp/build +/gyp/java /test/node_modules /test/fixtures/*/*_actual.* /test/fixtures/api/1.png diff --git a/.mason b/.mason index abdc13127..1d5789dfa 160000 --- a/.mason +++ b/.mason @@ -1 +1 @@ -Subproject commit abdc131273c3e50e42f245b1166c27de4c34c582 +Subproject commit 1d5789dfadeffa5df8e58770e3326840d1e6d9c9 diff --git a/Makefile b/Makefile index 34af9b85e..59bd1dfef 100644 --- a/Makefile +++ b/Makefile @@ -1,225 +1,101 @@ -BUILDTYPE ?= Release -PYTHON ?= python -PREFIX ?= /usr/local -ANDROID_ABI ?= arm-v7 +export BUILDTYPE ?= Release +export BUILD_TEST ?= 1 +export BUILD_RENDER ?= 1 +# Determine build platform ifeq ($(shell uname -s), Darwin) -HOST = osx -HEADLESS = cgl -JOBS ?= $(shell sysctl -n hw.ncpu) -endif - -ifeq ($(shell uname -s), Linux) -HOST = linux -JOBS ?= $(shell grep --count processor /proc/cpuinfo) -BUILD_ROOT = $(shell pwd) -endif - -JOBS ?= 1 - -all: mbgl - -include config/defaults.mk - -#### Dependencies ############################################################## - -# Wildcard targets get removed after build by default, but we want to preserve the config. -.PRECIOUS: config/%.gypi -config/%.gypi: CMD = ./configure config/$*.gypi -config/%.gypi: configure - @$(ENV_$*) ./scripts/flock.py build/Configure.lock ./configure config/$*.gypi - -styles/styles: - git submodule update --init styles - -ifeq ($(shell uname -s), Darwin) -SMCalloutView: - git submodule update --init platform/ios/vendor/SMCalloutView +export BUILD = osx +export JOBS ?= $(shell sysctl -n hw.ncpu) +export XCPRETTY := $(shell ./scripts/xcpretty.sh) +else ifeq ($(shell uname -s), Linux) +export BUILD = linux +export JOBS ?= $(shell grep --count processor /proc/cpuinfo) else -SMCalloutView: +$(error Cannot determine build platform) +endif +export BUILD_VERSION = $(shell uname -m) + +RUN = @$(MAKE) -f scripts/main.mk + +default: ; @printf "You must specify a valid target\n" + +#### OS X targets ############################################################## + +ifeq ($(BUILD),osx) +.PHONY: osx xosx run-osx run-xosx +osx: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Makefile/osxapp +xosx: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Xcode/osxapp +run-osx: osx ; @"build/osx-x86_64/$(BUILDTYPE)/Mapbox GL.app/Contents/MacOS/Mapbox GL" +run-xosx: xosx ; @"gyp/build/$(BUILDTYPE)/Mapbox GL.app/Contents/MacOS/Mapbox GL" + +.PHONY: Xcode/osx Xcode/ios +Xcode/ios: ; $(RUN) HOST=ios Xcode/__project__ +Xcode/osx: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Xcode/__project__ + +.PHONY: xproj iproj +xproj: Xcode/osx ; @open ./build/osx-x86_64/gyp/osx.xcodeproj +iproj: Xcode/ios ; @open ./build/ios-all/gyp/ios.xcodeproj + +.PHONY: ios ibench isim +ios ibench isim: export XCODEBUILD_ARGS += PROVISIONING_PROFILE="$$(PROVISIONING_PROFILE)" + +ios: export XCODEBUILD_ARGS += -sdk iphoneos ARCHS="arm64 armv7 armv7s" +ios: ; $(RUN) HOST=ios Xcode/iosapp + +isim: export XCODEBUILD_ARGS += -sdk iphonesimulator ARCHS="x86_64 i386" +isim: ; $(RUN) HOST=ios Xcode/iosapp + +ibench: export XCODEBUILD_ARGS += -sdk iphoneos ARCHS="arm64" +ibench: ; $(RUN) HOST=ios Xcode/ios-bench + +.PHONY: ipackage ipackage-strip ipackage-sim itest +ipackage: Xcode/ios ; @JOBS=$(JOBS) ./scripts/ios/package.sh +ipackage-strip: Xcode/ios ; @JOBS=$(JOBS) ./scripts/ios/package.sh strip +ipackage-sim: Xcode/ios ; @JOBS=$(JOBS) ./scripts/ios/package.sh sim +itest: ipackage-sim ; ./scripts/ios/test.sh endif -geojsonvt: - git submodule update --init src/mbgl/util/geojsonvt +#### All platforms targets ##################################################### -KIF: - git submodule update --init test/ios/KIF - - -#### Build files ############################################################### - -.PRECIOUS: Makefile/project -Makefile/project: config/$(HOST).gypi styles/styles SMCalloutView geojsonvt - deps/run_gyp gyp/$(HOST).gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f make - -.PRECIOUS: Xcode/project -Xcode/project: config/$(HOST).gypi styles/styles SMCalloutView geojsonvt - deps/run_gyp gyp/$(HOST).gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f xcode - - -#### Library builds ############################################################ - -mbgl: Makefile/project - $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) everything - -standalone: Makefile/project - LINK=`pwd`/gyp/link.py $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) standalone - -install: Makefile/project - LINK=`pwd`/gyp/link.py $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) install - - -##### Test builds ############################################################## - -.PHONY: test -test: Makefile/project - $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) test - -test-%: test - ./scripts/run_tests.sh "build/$(HOST)/$(BUILDTYPE)/test" --gtest_filter=$* - -.PHONY: xtest -xtest: XCPRETTY := $(shell ./scripts/xcpretty.sh) -xtest: Xcode/project - xcodebuild -project ./build/osx/gyp/osx.xcodeproj -configuration $(BUILDTYPE) -target test -jobs $(JOBS) $(XCPRETTY) - -xtest-%: xtest - ./scripts/run_tests.sh "build/osx/Build/Products/$(BUILDTYPE)/test" --gtest_filter=$* - - -#### Mac OS X application builds ############################################### - -.PHONY: osx run-osx -osx: Makefile/project - $(MAKE) -C build/osx BUILDTYPE=$(BUILDTYPE) osxapp - -run-osx: osx - "build/osx/$(BUILDTYPE)/Mapbox GL.app/Contents/MacOS/Mapbox GL" - -run-valgrind-osx: osx - (valgrind --leak-check=full --suppressions=scripts/valgrind.sup build/osx/$(BUILDTYPE)/Mapbox\ GL.app/Contents/MacOS/Mapbox\ GL) - -.PHONY: xosx-proj xosx run-xosx -xosx-proj: Xcode/project - open ./build/osx/gyp/osx.xcodeproj - -xosx: XCPRETTY := $(shell ./scripts/xcpretty.sh) -xosx: Xcode/project - xcodebuild -project ./build/osx/gyp/osx.xcodeproj -configuration $(BUILDTYPE) -target osxapp -jobs $(JOBS) $(XCPRETTY) - -run-xosx: xosx - "gyp/build/$(BUILDTYPE)/Mapbox GL.app/Contents/MacOS/Mapbox GL" - -# Legacy name -xproj: xosx-proj - - - -#### iOS application builds #################################################### - -.PRECIOUS: Xcode/ios -Xcode/ios: gyp/ios.gyp config/ios.gypi styles/styles SMCalloutView geojsonvt - deps/run_gyp gyp/ios.gyp $(CONFIG_ios) $(LIBS_ios) --generator-output=./build/ios -f xcode - -.PHONY: ios-proj ios isim ipackage -ios-proj: Xcode/ios - open ./build/ios/gyp/ios.xcodeproj - -ios: XCPRETTY := $(shell ./scripts/xcpretty.sh) -ios: Xcode/ios - xcodebuild -sdk iphoneos ARCHS="arm64 armv7 armv7s" PROVISIONING_PROFILE="19324a54-7455-4f0b-8e1c-e6957c718ebc" -project ./build/ios/gyp/ios.xcodeproj -configuration Release -target iosapp -jobs $(JOBS) $(XCPRETTY) - -ibench: XCPRETTY := $(shell ./scripts/xcpretty.sh) -ibench: Xcode/ios - xcodebuild -sdk iphoneos ARCHS="arm64" PROVISIONING_PROFILE="19324a54-7455-4f0b-8e1c-e6957c718ebc" -project ./build/ios/gyp/ios.xcodeproj -configuration Release -target ios-bench -jobs $(JOBS) $(XCPRETTY) - -isim: XCPRETTY := $(shell ./scripts/xcpretty.sh) -isim: Xcode/ios - xcodebuild -sdk iphonesimulator ARCHS="x86_64 i386" -project ./build/ios/gyp/ios.xcodeproj -configuration Debug -target iosapp -jobs $(JOBS) $(XCPRETTY) - -ipackage: Xcode/ios - JOBS=$(JOBS) ./scripts/ios/package.sh - -ipackage-strip: Xcode/ios - JOBS=$(JOBS) ./scripts/ios/package.sh strip - -ipackage-sim: Xcode/ios - JOBS=$(JOBS) ./scripts/ios/package.sh sim - -itest: ipackage-sim KIF - ./scripts/ios/test.sh - -# Legacy name -iproj: ios-proj - - -#### Linux application builds ################################################## - -.PHONY: linux run-linux -linux: Makefile/project - $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) linuxapp - -run-linux: linux - (cd build/$(HOST)/$(BUILDTYPE) && ./mapbox-gl) - -run-valgrind-linux: linux - (cd build/$(HOST)/$(BUILDTYPE) && valgrind --leak-check=full --suppressions=$(BUILD_ROOT)/scripts/valgrind.sup ./mapbox-gl) - -.PHONY: xlinux run-xlinux -xlinux: XCPRETTY := $(shell ./scripts/xcpretty.sh) -xlinux: Xcode/project - xcodebuild -project ./build/osx/gyp/osx.xcodeproj -configuration $(BUILDTYPE) -target linuxapp -jobs $(JOBS) $(XCPRETTY) - -run-xlinux: xlinux - "gyp/build/$(BUILDTYPE)/mapbox-gl" - - -#### Android libaries ######################################################### - -.PRECIOUS: Makefile/android-% -Makefile/android-%: CMD = deps/run_gyp android/mapboxgl-app.gyp $(CONFIG_android-$*) $(LIBS_android) --generator-output=./build/android-$* -f make-android -Makefile/android-%: config/android-%.gypi styles/styles geojsonvt - @echo $(CMD) - @$(ENV_android-$*) $(CMD) +.PHONY: linux xlinux run-linux run-xlinux +linux: ; $(RUN) Makefile/linuxapp +.PHONY: android android-lib # Builds a particular android architecture. -android-lib-%: Makefile/android-% - @$(ENV_android-$*) ./scripts/flock.py -v build/Android.lock $(MAKE) -C build/android-$* BUILDTYPE=$(BUILDTYPE) androidapp +android-lib-%: ; $(RUN) HOST=android HOST_VERSION=$* Makefile/androidapp + +# Builds the default Android library +android-lib: ; $(RUN) HOST=android Makefile/androidapp # Builds the selected/default Android library -android-lib: android-lib-$(ANDROID_ABI) - -# Builds the selected/default Android library -android: android-lib-$(ANDROID_ABI) +android: android-lib cd android/java && ./gradlew --parallel-threads=$(JOBS) assemble$(BUILDTYPE) # Builds all android architectures. -android-all: $(ANDROID_ABIS) +android-all: android-lib-arm-v5 android-lib-arm-v7 android-lib-arm-v8 +android-all: android-lib-x86 android-lib-x86-64 +android-all: android-lib-mips android-lib-mips-64 cd android/java && ./gradlew --parallel-threads=$(JOBS) assemble$(BUILDTYPE) -# Full build of GL Core for each architecture, build the Android Library, publish to Maven Central -android-deploy: $(ANDROID_ABIS) - cd android/java/MapboxGLAndroidSDK && chmod ugo+x deploy.sh && ./deploy.sh +.PHONY: test +test: ; $(RUN) Makefile/test +test-%: ; $(RUN) test-$* +ifeq ($(BUILD),osx) +xtest: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Xcode/test +endif -android-project: android-lib - - -##### Render builds ############################################################ - -render: Makefile/project - $(MAKE) -C build/$(HOST) BUILDTYPE=$(BUILDTYPE) mbgl-render - -.PHONY: xrender -xrender: XCPRETTY := $(shell ./scripts/xcpretty.sh) -xrender: Xcode/project - xcodebuild -project ./build/osx/gyp/osx.xcodeproj -configuration $(BUILDTYPE) -target mbgl-render -jobs $(JOBS) $(XCPRETTY) +.PHONY: render xrender +render: ; $(RUN) Makefile/mbgl-render +ifeq ($(BUILD),osx) +xrender: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Xcode/mbgl-render +endif ##### Maintenace operations #################################################### .PHONY: clear_xcode_cache clear_xcode_cache: -ifeq ($(PLATFORM), osx) +ifeq ($(BUILD), osx) @CUSTOM_DD=`defaults read com.apple.dt.Xcode IDECustomDerivedDataLocation 2>/dev/null`; \ if [ $$CUSTOM_DD ]; then \ echo clearing files in $$CUSTOM_DD older than one day; \ @@ -233,7 +109,7 @@ endif .PHONY: clear_sqlite_cache clear_sqlite_cache: -ifeq ($(PLATFORM), osx) +ifeq ($(BUILD), osx) rm -f ~/Library/Application\ Support/Mapbox\ GL/cache.db else rm -f /tmp/mbgl-cache.db diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index 85022dbc0..eee6bd8f6 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -42,6 +42,12 @@ jmethodID latLngConstructorId = nullptr; jfieldID latLngLatitudeId = nullptr; jfieldID latLngLongitudeId = nullptr; +jclass latLngZoomClass = nullptr; +jmethodID latLngZoomConstructorId = nullptr; +jfieldID latLngZoomLatitudeId = nullptr; +jfieldID latLngZoomLongitudeId = nullptr; +jfieldID latLngZoomZoomId = nullptr; + jclass markerClass = nullptr; jmethodID markerConstructorId = nullptr; jfieldID markerPositionId = nullptr; @@ -65,13 +71,6 @@ jfieldID polygonStrokeWidthId = nullptr; jfieldID polygonPointsId = nullptr; jfieldID polygonHolesId = nullptr; - -jclass latLngZoomClass = nullptr; -jmethodID latLngZoomConstructorId = nullptr; -jfieldID latLngZoomLatitudeId = nullptr; -jfieldID latLngZoomLongitudeId = nullptr; -jfieldID latLngZoomZoomId = nullptr; - jclass runtimeExceptionClass = nullptr; jclass nullPointerExceptionClass = nullptr; @@ -156,21 +155,21 @@ std::vector std_vector_string_from_jobject(JNIEnv *env, jobject jli return vector; } - jobjectArray array = + jobjectArray jarray = reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); - if (env->ExceptionCheck() || (array == nullptr)) { + if (env->ExceptionCheck() || (jarray == nullptr)) { env->ExceptionDescribe(); return vector; } - jsize len = env->GetArrayLength(array); + jsize len = env->GetArrayLength(jarray); if (len < 0) { env->ExceptionDescribe(); return vector; } for (jsize i = 0; i < len; i++) { - jstring jstr = reinterpret_cast(env->GetObjectArrayElement(array, i)); + jstring jstr = reinterpret_cast(env->GetObjectArrayElement(jarray, i)); if (jstr == nullptr) { env->ExceptionDescribe(); return vector; @@ -179,61 +178,12 @@ std::vector std_vector_string_from_jobject(JNIEnv *env, jobject jli vector.push_back(std_string_from_jstring(env, jstr)); } + env->DeleteLocalRef(jarray); + jarray = nullptr; + return vector; } -mbgl::AnnotationSegment annotation_segment_from_latlng_jlist(JNIEnv *env, jobject jlist) { - mbgl::AnnotationSegment segment; - - if (jlist == nullptr) { - if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) { - env->ExceptionDescribe(); - return segment; - } - return segment; - } - - jobjectArray array = - reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); - if (env->ExceptionCheck() || (array == nullptr)) { - env->ExceptionDescribe(); - return segment; - } - - jsize len = env->GetArrayLength(array); - if (len < 0) { - env->ExceptionDescribe(); - return segment; - } - - segment.reserve(len); - - for (jsize i = 0; i < len; i++) { - jobject latLng = reinterpret_cast(env->GetObjectArrayElement(array, i)); - if (latLng == nullptr) { - env->ExceptionDescribe(); - return segment; - } - - jdouble latitude = env->GetDoubleField(latLng, latLngLatitudeId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return segment; - } - - jdouble longitude = env->GetDoubleField(latLng, latLngLongitudeId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return segment; - } - - segment.push_back(mbgl::LatLng(latitude, longitude)); - env->DeleteLocalRef(latLng); - } - env->DeleteLocalRef(array); - return segment; -} - jobject std_vector_string_to_jobject(JNIEnv *env, std::vector vector) { jobject jlist = env->NewObject(arrayListClass, arrayListConstructorId); if (jlist == nullptr) { @@ -273,6 +223,91 @@ jlongArray std_vector_uint_to_jobject(JNIEnv *env, std::vector vector) return jarray; } +mbgl::AnnotationSegment annotation_segment_from_latlng_jlist(JNIEnv *env, jobject jlist) { + mbgl::AnnotationSegment segment; + + if (jlist == nullptr) { + if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) { + env->ExceptionDescribe(); + return segment; + } + return segment; + } + + jobjectArray jarray = + reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); + if (env->ExceptionCheck() || (jarray == nullptr)) { + env->ExceptionDescribe(); + return segment; + } + + jsize len = env->GetArrayLength(jarray); + if (len < 0) { + env->ExceptionDescribe(); + return segment; + } + + segment.reserve(len); + + for (jsize i = 0; i < len; i++) { + jobject latLng = reinterpret_cast(env->GetObjectArrayElement(jarray, i)); + if (latLng == nullptr) { + env->ExceptionDescribe(); + return segment; + } + + jdouble latitude = env->GetDoubleField(latLng, latLngLatitudeId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return segment; + } + + jdouble longitude = env->GetDoubleField(latLng, latLngLongitudeId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return segment; + } + + segment.push_back(mbgl::LatLng(latitude, longitude)); + env->DeleteLocalRef(latLng); + } + + env->DeleteLocalRef(jarray); + jarray = nullptr; + + return segment; +} + +std::pair annotation_std_pair_from_polygon_jobject(JNIEnv *env, jobject polygon) { + jfloat alpha = env->GetFloatField(polygon, polygonAlphaId); + //jboolean visible = env->GetBooleanField(polygon, polygonVisibleId); + jint fillColor = env->GetIntField(polygon, polygonFillColorId); + jint strokeColor = env->GetIntField(polygon, polygonStrokeColorId); + + int rF = (fillColor >> 16) & 0xFF; + int gF = (fillColor >> 8) & 0xFF; + int bF = (fillColor) & 0xFF; + int aF = (fillColor >> 24) & 0xFF; + + int rS = (strokeColor >> 16) & 0xFF; + int gS = (strokeColor >> 8) & 0xFF; + int bS = (strokeColor) & 0xFF; + int aS = (strokeColor >> 24) & 0xFF; + + mbgl::StyleProperties shapeProperties; + mbgl::FillProperties fillProperties; + fillProperties.opacity = alpha; + fillProperties.stroke_color = {{ static_cast(rS) / 255.0f, static_cast(gS) / 255.0f, static_cast(bS) / 255.0f, static_cast(aS) / 255.0f }}; + fillProperties.fill_color = {{ static_cast(rF) / 255.0f, static_cast(gF) / 255.0f, static_cast(bF) / 255.0f, static_cast(aF) / 255.0f }}; + shapeProperties.set(fillProperties); + + jobject points = env->GetObjectField(polygon, polygonPointsId); + mbgl::AnnotationSegment segment = annotation_segment_from_latlng_jlist(env, points); + env->DeleteLocalRef(points); + + return std::make_pair(segment, shapeProperties); +} + } } @@ -530,271 +565,6 @@ void JNICALL nativeSetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, j nativeMapView->getMap().setLatLng(mbgl::LatLng(latitude, longitude), std::chrono::milliseconds(duration)); } -void JNICALL nativeSetSprite(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, - jstring symbol, jint width, jint height, jfloat scale, jbyteArray jpixels) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetSprite"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - - const std::string symbolName = std_string_from_jstring(env, symbol); - - jbyte* pixelData = env->GetByteArrayElements(jpixels, nullptr); - std::string pixels((char*)pixelData, width * height * 4); - env->ReleaseByteArrayElements(jpixels, pixelData, JNI_ABORT); - - auto spriteImage = std::make_shared( - uint16_t(width), - uint16_t(height), - float(scale), - std::move(pixels)); - - nativeMapView->getMap().setSprite(symbolName, spriteImage); -} - -jlong JNICALL nativeAddMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject marker) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarker"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - - jobject position = env->GetObjectField(marker, markerPositionId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - jstring jsprite = (jstring)env->GetObjectField(marker, markerSpriteId); - std::string sprite = std_string_from_jstring(env, jsprite); - - jdouble latitude = env->GetDoubleField(position, latLngLatitudeId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - jdouble longitude = env->GetDoubleField(position, latLngLongitudeId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - // Because Java only has int, not unsigned int, we need to bump the annotation id up to a long. - return (jlong) nativeMapView->getMap().addPointAnnotation(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), sprite)); -} - -jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polyline) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolyline"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - - // ***** Java fields ***** // - // float alpha; - // boolean visible; - // int color - // float width - // List points - - jfloat alpha = env->GetFloatField(polyline, polylineAlphaId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - jboolean visible = env->GetBooleanField(polyline, polylineVisibleId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - visible = JNI_TRUE; - - jint color = env->GetIntField(polyline, polylineColorId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - int r = (color>>16)&0xFF; - int g = (color>>8)&0xFF; - int b = (color)&0xFF; - int a = (color>>24)&0xFF; - - jfloat width = env->GetFloatField(polyline, polylineWidthId); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - mbgl::StyleProperties shapeProperties; - mbgl::LineProperties lineProperties; - lineProperties.opacity = alpha; - lineProperties.color = {{ (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f }}; - lineProperties.width = width; - shapeProperties.set(lineProperties); - - jobject points = env->GetObjectField(polyline, polylinePointsId); - mbgl::AnnotationSegment segment = annotation_segment_from_latlng_jlist(env, points); - - std::vector shapes; - shapes.emplace_back(mbgl::AnnotationSegments {{ segment }}, shapeProperties); - - std::vector shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); - uint32_t id = shapeAnnotationIDs.at(0); - return (jlong) id; -} - - -std::pair readPolygon(JNIEnv *env, jobject polygon) { - // ***** Java fields ***** // - // float alpha; - // boolean visible; - // int fillColor - // int strokeColor - // float strokeWidth - // List points - // List> holes - - jfloat alpha = env->GetFloatField(polygon, polygonAlphaId); - jboolean visible = env->GetBooleanField(polygon, polygonVisibleId); - visible = JNI_TRUE; - jint fillColor = env->GetIntField(polygon, polygonFillColorId); - jint strokeColor = env->GetIntField(polygon, polygonStrokeColorId); - - int rF = (fillColor>>16)&0xFF; - int gF = (fillColor>>8)&0xFF; - int bF = (fillColor)&0xFF; - int aF = (fillColor>>24)&0xFF; - - int rS = (strokeColor>>16)&0xFF; - int gS = (strokeColor>>8)&0xFF; - int bS = (strokeColor)&0xFF; - int aS = (strokeColor>>24)&0xFF; - - // jfloat strokeWidth = env->GetFloatField(polygon, polygonStrokeWidthId); - // if (env->ExceptionCheck()) { - // env->ExceptionDescribe(); - // return -1; - // } - - mbgl::StyleProperties shapeProperties; - mbgl::FillProperties fillProperties; - fillProperties.opacity = alpha; - fillProperties.stroke_color = {{ (float)rS / 255.0f, (float)gS / 255.0f, (float)bS / 255.0f, (float)aS / 255.0f }}; - fillProperties.fill_color = {{ (float)rF / 255.0f, (float)gF / 255.0f, (float)bF / 255.0f, (float)aF / 255.0f }}; - shapeProperties.set(fillProperties); - - jobject points = env->GetObjectField(polygon, polygonPointsId); - mbgl::AnnotationSegment segment = annotation_segment_from_latlng_jlist(env, points); - env->DeleteLocalRef(points); - - return std::make_pair(segment, shapeProperties); -} - -jlong JNICALL nativeAddPolygon(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polygon) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygon"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - - std::vector shapes; - std::pair segment = readPolygon(env, polygon); - - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return -1; - } - - shapes.emplace_back(mbgl::AnnotationSegments {{ segment.first }}, segment.second); - - std::vector shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); - uint32_t id = shapeAnnotationIDs.at(0); - return (jlong) id; -} - -jlongArray JNICALL nativeAddPolygons(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject jlist) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygons"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - - std::vector shapes; - - if (jlist == nullptr) { - if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) { - env->ExceptionDescribe(); - return nullptr; - } - return nullptr; - } - - jobjectArray array = - reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); - if (env->ExceptionCheck() || (array == nullptr)) { - env->ExceptionDescribe(); - return nullptr; - } - - jsize len = env->GetArrayLength(array); - if (len < 0) { - env->ExceptionDescribe(); - return nullptr; - } - - shapes.reserve(len); - - for (jsize i = 0; i < len; i++) { - jobject polygon = reinterpret_cast(env->GetObjectArrayElement(array, i)); - - std::pair segment = readPolygon(env, polygon); - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - return nullptr; - } - - shapes.emplace_back(mbgl::AnnotationSegments {{ segment.first }}, segment.second); - - env->DeleteLocalRef(polygon); - } - - std::vector shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); - return std_vector_uint_to_jobject(env, shapeAnnotationIDs); -} - -void JNICALL nativeRemoveAnnotation(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlong annotationId) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotation"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - nativeMapView->getMap().removeAnnotation((uint32_t)annotationId); -} - -void JNICALL nativeRemoveAnnotations(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlongArray array) { - mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotations"); - assert(nativeMapViewPtr != 0); - NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - - std::vector ids; - - if (env->ExceptionCheck() || (array == nullptr)) { - env->ExceptionDescribe(); - return; - } - - jsize len = env->GetArrayLength(array); - if (len < 0) { - env->ExceptionDescribe(); - return; - } - - ids.reserve(len); - jlong* jids = env->GetLongArrayElements(array, nullptr); - - for (jsize i = 0; i < len; i++) { - if(jids[i] == -1L) - continue; - ids.push_back((uint32_t) jids[i]); - } - - env->ReleaseLongArrayElements(array, jids, JNI_ABORT); - - nativeMapView->getMap().removeAnnotations(ids); -} - jobject JNICALL nativeGetLatLng(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetLatLng"); assert(nativeMapViewPtr != 0); @@ -956,6 +726,219 @@ void JNICALL nativeResetNorth(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) nativeMapView->getMap().resetNorth(); } +jlong JNICALL nativeAddMarker(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject marker) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddMarker"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + + jobject position = env->GetObjectField(marker, markerPositionId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + jstring jsprite = reinterpret_cast(env->GetObjectField(marker, markerSpriteId)); + std::string sprite = std_string_from_jstring(env, jsprite); + + jdouble latitude = env->GetDoubleField(position, latLngLatitudeId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + jdouble longitude = env->GetDoubleField(position, latLngLongitudeId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + // Because Java only has int, not unsigned int, we need to bump the annotation id up to a long. + return nativeMapView->getMap().addPointAnnotation(mbgl::PointAnnotation(mbgl::LatLng(latitude, longitude), sprite)); +} + +jlong JNICALL nativeAddPolyline(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polyline) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolyline"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + + jfloat alpha = env->GetFloatField(polyline, polylineAlphaId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + /*jboolean visible = env->GetBooleanField(polyline, polylineVisibleId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + }*/ + + jint color = env->GetIntField(polyline, polylineColorId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = (color) & 0xFF; + int a = (color >> 24) & 0xFF; + + jfloat width = env->GetFloatField(polyline, polylineWidthId); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + mbgl::StyleProperties shapeProperties; + mbgl::LineProperties lineProperties; + lineProperties.opacity = alpha; + lineProperties.color = {{ static_cast(r) / 255.0f, static_cast(g) / 255.0f, static_cast(b) / 255.0f, static_cast(a) / 255.0f }}; + lineProperties.width = width; + shapeProperties.set(lineProperties); + + jobject points = env->GetObjectField(polyline, polylinePointsId); + mbgl::AnnotationSegment segment = annotation_segment_from_latlng_jlist(env, points); + + std::vector shapes; + shapes.emplace_back(mbgl::AnnotationSegments { segment }, shapeProperties); + + std::vector shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); + uint32_t id = shapeAnnotationIDs.at(0); + + return id; +} + +jlong JNICALL nativeAddPolygon(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject polygon) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygon"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + + std::vector shapes; + std::pair segment = annotation_std_pair_from_polygon_jobject(env, polygon); + + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return -1; + } + + shapes.emplace_back(mbgl::AnnotationSegments { segment.first }, segment.second); + + std::vector shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); + uint32_t id = shapeAnnotationIDs.at(0); + return id; +} + +jlongArray JNICALL nativeAddPolygons(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject jlist) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddPolygons"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + + std::vector shapes; + + if (jlist == nullptr) { + if (env->ThrowNew(nullPointerExceptionClass, "List cannot be null.") < 0) { + env->ExceptionDescribe(); + return nullptr; + } + return nullptr; + } + + jobjectArray jarray = + reinterpret_cast(env->CallObjectMethod(jlist, listToArrayId)); + if (env->ExceptionCheck() || (jarray == nullptr)) { + env->ExceptionDescribe(); + return nullptr; + } + + jsize len = env->GetArrayLength(jarray); + if (len < 0) { + env->ExceptionDescribe(); + return nullptr; + } + + shapes.reserve(len); + + for (jsize i = 0; i < len; i++) { + jobject polygon = reinterpret_cast(env->GetObjectArrayElement(jarray, i)); + + std::pair segment = annotation_std_pair_from_polygon_jobject(env, polygon); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + return nullptr; + } + + shapes.emplace_back(mbgl::AnnotationSegments { segment.first }, segment.second); + + env->DeleteLocalRef(polygon); + } + + env->DeleteLocalRef(jarray); + + std::vector shapeAnnotationIDs = nativeMapView->getMap().addShapeAnnotations(shapes); + return std_vector_uint_to_jobject(env, shapeAnnotationIDs); +} + +void JNICALL nativeRemoveAnnotation(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlong annotationId) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotation"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + nativeMapView->getMap().removeAnnotation(static_cast(annotationId)); +} + +void JNICALL nativeRemoveAnnotations(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jlongArray jarray) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveAnnotations"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + + std::vector ids; + + if (env->ExceptionCheck() || (jarray == nullptr)) { + env->ExceptionDescribe(); + return; + } + + jsize len = env->GetArrayLength(jarray); + if (len < 0) { + env->ExceptionDescribe(); + return; + } + + ids.reserve(len); + jlong* jids = env->GetLongArrayElements(jarray, nullptr); + + for (jsize i = 0; i < len; i++) { + if(jids[i] == -1L) + continue; + ids.push_back(static_cast(jids[i])); + } + + env->ReleaseLongArrayElements(jarray, jids, JNI_ABORT); + + nativeMapView->getMap().removeAnnotations(ids); +} + +void JNICALL nativeSetSprite(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, + jstring symbol, jint width, jint height, jfloat scale, jbyteArray jpixels) { + mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetSprite"); + assert(nativeMapViewPtr != 0); + NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); + + const std::string symbolName = std_string_from_jstring(env, symbol); + + jbyte* pixelData = env->GetByteArrayElements(jpixels, nullptr); + std::string pixels(reinterpret_cast(pixelData), width * height * 4); + env->ReleaseByteArrayElements(jpixels, pixelData, JNI_ABORT); + + auto spriteImage = std::make_shared( + uint16_t(width), + uint16_t(height), + float(scale), + std::move(pixels)); + + nativeMapView->getMap().setSprite(symbolName, spriteImage); +} + void JNICALL nativeOnLowMemory(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeOnLowMemory"); assert(nativeMapViewPtr != 0); @@ -1179,6 +1162,36 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } + latLngZoomClass = env->FindClass("com/mapbox/mapboxgl/geometry/LatLngZoom"); + if (latLngZoomClass == nullptr) { + env->ExceptionDescribe(); + return JNI_ERR; + } + + latLngZoomConstructorId = env->GetMethodID(latLngZoomClass, "", "(DDD)V"); + if (latLngZoomConstructorId == nullptr) { + env->ExceptionDescribe(); + return JNI_ERR; + } + + latLngZoomLatitudeId = env->GetFieldID(latLngZoomClass, "latitude", "D"); + if (latLngZoomLatitudeId == nullptr) { + env->ExceptionDescribe(); + return JNI_ERR; + } + + latLngZoomLongitudeId = env->GetFieldID(latLngZoomClass, "longitude", "D"); + if (latLngZoomLongitudeId == nullptr) { + env->ExceptionDescribe(); + return JNI_ERR; + } + + latLngZoomZoomId = env->GetFieldID(latLngZoomClass, "zoom", "D"); + if (latLngZoomZoomId == nullptr) { + env->ExceptionDescribe(); + return JNI_ERR; + } + markerClass = env->FindClass("com/mapbox/mapboxgl/annotations/Marker"); if (markerClass == nullptr) { env->ExceptionDescribe(); @@ -1299,36 +1312,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - latLngZoomClass = env->FindClass("com/mapbox/mapboxgl/geometry/LatLngZoom"); - if (latLngZoomClass == nullptr) { - env->ExceptionDescribe(); - return JNI_ERR; - } - - latLngZoomConstructorId = env->GetMethodID(latLngZoomClass, "", "(DDD)V"); - if (latLngZoomConstructorId == nullptr) { - env->ExceptionDescribe(); - return JNI_ERR; - } - - latLngZoomLatitudeId = env->GetFieldID(latLngZoomClass, "latitude", "D"); - if (latLngZoomLatitudeId == nullptr) { - env->ExceptionDescribe(); - return JNI_ERR; - } - - latLngZoomLongitudeId = env->GetFieldID(latLngZoomClass, "longitude", "D"); - if (latLngZoomLongitudeId == nullptr) { - env->ExceptionDescribe(); - return JNI_ERR; - } - - latLngZoomZoomId = env->GetFieldID(latLngZoomClass, "zoom", "D"); - if (latLngZoomZoomId == nullptr) { - env->ExceptionDescribe(); - return JNI_ERR; - } - jclass nativeMapViewClass = env->FindClass("com/mapbox/mapboxgl/views/NativeMapView"); if (nativeMapViewClass == nullptr) { env->ExceptionDescribe(); @@ -1492,17 +1475,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { {"nativeMoveBy", "(JDDJ)V", reinterpret_cast(&nativeMoveBy)}, {"nativeSetLatLng", "(JLcom/mapbox/mapboxgl/geometry/LatLng;J)V", reinterpret_cast(&nativeSetLatLng)}, - {"nativeSetSprite", "(JLjava/lang/String;IIF[B)V", reinterpret_cast(&nativeSetSprite)}, - {"nativeAddMarker", "(JLcom/mapbox/mapboxgl/annotations/Marker;)J", - reinterpret_cast(&nativeAddMarker)}, - {"nativeAddPolyline", "(JLcom/mapbox/mapboxgl/annotations/Polyline;)J", - reinterpret_cast(&nativeAddPolyline)}, - {"nativeAddPolygon", "(JLcom/mapbox/mapboxgl/annotations/Polygon;)J", - reinterpret_cast(&nativeAddPolygon)}, - {"nativeAddPolygons", "(JLjava/util/List;)[J", - reinterpret_cast(&nativeAddPolygons)}, - {"nativeRemoveAnnotation", "(JJ)V", reinterpret_cast(&nativeRemoveAnnotation)}, - {"nativeRemoveAnnotations", "(J[J)V", reinterpret_cast(&nativeRemoveAnnotations)}, {"nativeGetLatLng", "(J)Lcom/mapbox/mapboxgl/geometry/LatLng;", reinterpret_cast(&nativeGetLatLng)}, {"nativeResetPosition", "(J)V", reinterpret_cast(&nativeResetPosition)}, @@ -1529,6 +1501,17 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { &nativeSetBearing))}, {"nativeGetBearing", "(J)D", reinterpret_cast(&nativeGetBearing)}, {"nativeResetNorth", "(J)V", reinterpret_cast(&nativeResetNorth)}, + {"nativeAddMarker", "(JLcom/mapbox/mapboxgl/annotations/Marker;)J", + reinterpret_cast(&nativeAddMarker)}, + {"nativeAddPolyline", "(JLcom/mapbox/mapboxgl/annotations/Polyline;)J", + reinterpret_cast(&nativeAddPolyline)}, + {"nativeAddPolygon", "(JLcom/mapbox/mapboxgl/annotations/Polygon;)J", + reinterpret_cast(&nativeAddPolygon)}, + {"nativeAddPolygons", "(JLjava/util/List;)[J", + reinterpret_cast(&nativeAddPolygons)}, + {"nativeRemoveAnnotation", "(JJ)V", reinterpret_cast(&nativeRemoveAnnotation)}, + {"nativeRemoveAnnotations", "(J[J)V", reinterpret_cast(&nativeRemoveAnnotations)}, + {"nativeSetSprite", "(JLjava/lang/String;IIF[B)V", reinterpret_cast(&nativeSetSprite)}, {"nativeOnLowMemory", "(J)V", reinterpret_cast(&nativeOnLowMemory)}, {"nativeSetDebug", "(JZ)V", reinterpret_cast(&nativeSetDebug)}, {"nativeToggleDebug", "(J)V", reinterpret_cast(&nativeToggleDebug)}, @@ -1558,28 +1541,37 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } + latLngZoomClass = reinterpret_cast(env->NewGlobalRef(latLngZoomClass)); + if (latLngZoomClass == nullptr) { + env->ExceptionDescribe(); + env->DeleteGlobalRef(latLngClass); + return JNI_ERR; + } + markerClass = reinterpret_cast(env->NewGlobalRef(markerClass)); if (markerClass == nullptr) { env->ExceptionDescribe(); + env->DeleteGlobalRef(latLngClass); + env->DeleteGlobalRef(latLngZoomClass); return JNI_ERR; } polylineClass = reinterpret_cast(env->NewGlobalRef(polylineClass)); if (polylineClass == nullptr) { env->ExceptionDescribe(); + env->DeleteGlobalRef(latLngClass); + env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(markerClass); return JNI_ERR; } polygonClass = reinterpret_cast(env->NewGlobalRef(polygonClass)); if (polygonClass == nullptr) { - env->ExceptionDescribe(); - return JNI_ERR; - } - - latLngZoomClass = reinterpret_cast(env->NewGlobalRef(latLngZoomClass)); - if (latLngZoomClass == nullptr) { env->ExceptionDescribe(); env->DeleteGlobalRef(latLngClass); + env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(markerClass); + env->DeleteGlobalRef(polylineClass); return JNI_ERR; } @@ -1588,6 +1580,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionDescribe(); env->DeleteGlobalRef(latLngClass); env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(markerClass); + env->DeleteGlobalRef(polylineClass); + env->DeleteGlobalRef(polygonClass); return JNI_ERR; } @@ -1597,6 +1592,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionDescribe(); env->DeleteGlobalRef(latLngClass); env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(markerClass); + env->DeleteGlobalRef(polylineClass); + env->DeleteGlobalRef(polygonClass); env->DeleteGlobalRef(runtimeExceptionClass); return JNI_ERR; } @@ -1606,6 +1604,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionDescribe(); env->DeleteGlobalRef(latLngClass); env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(markerClass); + env->DeleteGlobalRef(polylineClass); + env->DeleteGlobalRef(polygonClass); env->DeleteGlobalRef(runtimeExceptionClass); env->DeleteGlobalRef(nullPointerExceptionClass); return JNI_ERR; @@ -1616,18 +1617,23 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionDescribe(); env->DeleteGlobalRef(latLngClass); env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(markerClass); + env->DeleteGlobalRef(polylineClass); + env->DeleteGlobalRef(polygonClass); env->DeleteGlobalRef(runtimeExceptionClass); env->DeleteGlobalRef(nullPointerExceptionClass); env->DeleteGlobalRef(arrayListClass); return JNI_ERR; } - pointFClass = reinterpret_cast(env->NewGlobalRef(pointFClass)); if (pointFClass == nullptr) { env->ExceptionDescribe(); env->DeleteGlobalRef(latLngClass); + env->DeleteGlobalRef(markerClass); env->DeleteGlobalRef(latLngZoomClass); + env->DeleteGlobalRef(polylineClass); + env->DeleteGlobalRef(polygonClass); env->DeleteGlobalRef(runtimeExceptionClass); env->DeleteGlobalRef(nullPointerExceptionClass); env->DeleteGlobalRef(arrayListClass); @@ -1635,7 +1641,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_ERR; } - char release[PROP_VALUE_MAX] = ""; __system_property_get("ro.build.version.release", release); androidRelease = std::string(release); @@ -1659,6 +1664,13 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { latLngLongitudeId = nullptr; latLngLatitudeId = nullptr; + env->DeleteGlobalRef(latLngZoomClass); + latLngZoomClass = nullptr; + latLngZoomConstructorId = nullptr; + latLngZoomLongitudeId = nullptr; + latLngZoomLatitudeId = nullptr; + latLngZoomZoomId = nullptr; + env->DeleteGlobalRef(markerClass); markerClass = nullptr; markerConstructorId = nullptr; @@ -1685,14 +1697,6 @@ extern "C" JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { polygonPointsId = nullptr; polygonHolesId = nullptr; - - env->DeleteGlobalRef(latLngZoomClass); - latLngZoomClass = nullptr; - latLngZoomConstructorId = nullptr; - latLngZoomLongitudeId = nullptr; - latLngZoomLatitudeId = nullptr; - latLngZoomZoomId = nullptr; - onInvalidateId = nullptr; onMapChangedId = nullptr; onFpsChangedId = nullptr; diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/annotations/Annotation.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/annotations/Annotation.java index 6feb733f0..4f172c6e2 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/annotations/Annotation.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/annotations/Annotation.java @@ -10,20 +10,19 @@ public abstract class Annotation { * * Internal C++ id is stored as unsigned int. */ - protected Long id; // null unless added to a MapView + protected long id = -1; // -1 unless added to a MapView private MapView mapView; - float alpha = 1; + float alpha = 1.0f; boolean visible = true; - public Annotation() {} public float getAlpha() { return alpha; } - public Long getId() { + public long getId() { return id; } @@ -40,7 +39,7 @@ public abstract class Annotation { this.alpha = alpha; } - public void setId(Long id) { + public void setId(long id) { this.id = id; } diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index 27085d174..2fbc0ccb5 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -314,7 +314,7 @@ public class MapView extends FrameLayout implements LocationListener { public Marker addMarker(MarkerOptions markerOptions) { Marker marker = markerOptions.getMarker(); - Long id = mNativeMapView.addMarker(marker); + long id = mNativeMapView.addMarker(marker); marker.setId(id); // the annotation needs to know its id marker.setMapView(this); // the annotation needs to know which map view it is in annotations.add(marker); @@ -323,7 +323,7 @@ public class MapView extends FrameLayout implements LocationListener { public Polyline addPolyline(PolylineOptions polylineOptions) { Polyline polyline = polylineOptions.getPolyline(); - Long id = mNativeMapView.addPolyline(polyline); + long id = mNativeMapView.addPolyline(polyline); polyline.setId(id); polyline.setMapView(this); annotations.add(polyline); @@ -332,7 +332,7 @@ public class MapView extends FrameLayout implements LocationListener { public Polygon addPolygon(PolygonOptions polygonOptions) { Polygon polygon = polygonOptions.getPolygon(); - Long id = mNativeMapView.addPolygon(polygon); + long id = mNativeMapView.addPolygon(polygon); polygon.setId(id); polygon.setMapView(this); annotations.add(polygon); @@ -347,7 +347,7 @@ public class MapView extends FrameLayout implements LocationListener { long[] ids = mNativeMapView.addPolygons(polygons); - for(int i=0; i polygon) { - // NH TODO Throw exception if returns -1 - return nativeAddPolygons(mNativeMapViewPtr, polygon); - } - - public void removeAnnotation(long id) { - nativeRemoveAnnotation(mNativeMapViewPtr, id); - } - - public void removeAnnotations(long[] ids) { - nativeRemoveAnnotations(mNativeMapViewPtr, ids); - } - public LatLng getLatLng() { return nativeGetLatLng(mNativeMapViewPtr); } @@ -356,6 +325,34 @@ class NativeMapView { nativeResetNorth(mNativeMapViewPtr); } + public long addMarker(Marker marker) { + return nativeAddMarker(mNativeMapViewPtr, marker); + } + + public long addPolyline(Polyline polyline) { + return nativeAddPolyline(mNativeMapViewPtr, polyline); + } + + public long addPolygon(Polygon polygon) { + return nativeAddPolygon(mNativeMapViewPtr, polygon); + } + + public long[] addPolygons(List polygon) { + return nativeAddPolygons(mNativeMapViewPtr, polygon); + } + + public void removeAnnotation(long id) { + nativeRemoveAnnotation(mNativeMapViewPtr, id); + } + + public void removeAnnotations(long[] ids) { + nativeRemoveAnnotations(mNativeMapViewPtr, ids); + } + + public void setSprite(String symbol, int width, int height, float scale, byte[] pixels) { + nativeSetSprite(mNativeMapViewPtr, symbol, width, height, scale, pixels); + } + public void onLowMemory() { nativeOnLowMemory(mNativeMapViewPtr); } @@ -392,7 +389,7 @@ class NativeMapView { nativeSetReachability(mNativeMapViewPtr, status); } - //public void getWorldBoundsMeters(); + //public void (); //public void getWorldBoundsLatLng(); @@ -507,21 +504,6 @@ class NativeMapView { private native void nativeSetLatLng(long nativeMapViewPtr, LatLng latLng, long duration); - private native void nativeSetSprite(long nativeMapViewPtr, String symbol, - int width, int height, float scale, byte[] pixels); - - private native long nativeAddMarker(long nativeMapViewPtr, Marker marker); - - private native long nativeAddPolyline(long nativeMapViewPtr, Polyline polyline); - - private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon); - - private native long[] nativeAddPolygons(long mNativeMapViewPtr, List polygon); - - private native void nativeRemoveAnnotation(long nativeMapViewPtr, long id); - - private native void nativeRemoveAnnotations(long nativeMapViewPtr, long[] id); - private native LatLng nativeGetLatLng(long nativeMapViewPtr); private native void nativeResetPosition(long nativeMapViewPtr); @@ -563,6 +545,21 @@ class NativeMapView { private native void nativeResetNorth(long nativeMapViewPtr); + private native long nativeAddMarker(long nativeMapViewPtr, Marker marker); + + private native long nativeAddPolyline(long nativeMapViewPtr, Polyline polyline); + + private native long nativeAddPolygon(long mNativeMapViewPtr, Polygon polygon); + + private native long[] nativeAddPolygons(long mNativeMapViewPtr, List polygon); + + private native void nativeRemoveAnnotation(long nativeMapViewPtr, long id); + + private native void nativeRemoveAnnotations(long nativeMapViewPtr, long[] id); + + private native void nativeSetSprite(long nativeMapViewPtr, String symbol, + int width, int height, float scale, byte[] pixels); + private native void nativeOnLowMemory(long nativeMapViewPtr); private native void nativeSetDebug(long nativeMapViewPtr, boolean debug); diff --git a/android/java/build.gradle b/android/java/build.gradle index 909007098..b1f4c8d08 100644 --- a/android/java/build.gradle +++ b/android/java/build.gradle @@ -1,4 +1,4 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. task wrapper(type: Wrapper) { - gradleVersion = '2.2.1' + gradleVersion = '2.5' } diff --git a/android/java/gradle/wrapper/gradle-wrapper.jar b/android/java/gradle/wrapper/gradle-wrapper.jar index 8c0fb64a8..30d399d8d 100644 Binary files a/android/java/gradle/wrapper/gradle-wrapper.jar and b/android/java/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/java/gradle/wrapper/gradle-wrapper.properties b/android/java/gradle/wrapper/gradle-wrapper.properties index 5adf98860..e94a9459d 100644 --- a/android/java/gradle/wrapper/gradle-wrapper.properties +++ b/android/java/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Dec 06 12:43:10 EST 2014 +#Mon Aug 03 17:09:27 CDT 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip diff --git a/android/mapboxgl-app.gyp b/android/mapboxgl-app.gypi similarity index 76% rename from android/mapboxgl-app.gyp rename to android/mapboxgl-app.gypi index d16d1dd4a..e32775ff7 100644 --- a/android/mapboxgl-app.gyp +++ b/android/mapboxgl-app.gypi @@ -26,13 +26,13 @@ ], 'libraries': [ '<@(openssl_static_libs)', - '<@(curl_static_libs)', - '<@(png_static_libs)', + '<@(libcurl_static_libs)', + '<@(libpng_static_libs)', '<@(jpeg_static_libs)', - '<@(sqlite3_static_libs)', - '<@(uv_static_libs)', - '<@(nu_static_libs)', - '<@(zip_static_libs)', + '<@(sqlite_static_libs)', + '<@(libuv_static_libs)', + '<@(nunicode_static_libs)', + '<@(libzip_static_libs)', ], 'variables': { 'ldflags': [ @@ -42,13 +42,13 @@ '-lGLESv2', '-lstdc++', '-latomic', - '<@(png_ldflags)', + '<@(libpng_ldflags)', '<@(jpeg_ldflags)', - '<@(sqlite3_ldflags)', + '<@(sqlite_ldflags)', '<@(openssl_ldflags)', - '<@(curl_ldflags)', + '<@(libcurl_ldflags)', '<@(zlib_ldflags)', - '<@(zip_ldflags)', + '<@(libzip_ldflags)', ], }, 'conditions': [ @@ -77,7 +77,7 @@ '../common/ca-bundle.crt', '../styles/styles' ], - 'destination': '<(pwd)/java/MapboxGLAndroidSDK/src/main/assets' + 'destination': '<(pwd)/../android/java/MapboxGLAndroidSDK/src/main/assets' }, ], @@ -85,7 +85,7 @@ { 'action_name': 'Strip dynamic library', 'inputs': [ '<(PRODUCT_DIR)/lib.target/libmapbox-gl.so' ], - 'outputs': [ '<(pwd)/java/MapboxGLAndroidSDK/src/main/jniLibs/$(JNIDIR)/libmapbox-gl.so' ], + 'outputs': [ '<(pwd)/../android/java/MapboxGLAndroidSDK/src/main/jniLibs/$(JNIDIR)/libmapbox-gl.so' ], 'action': [ '$(STRIP)', '<@(_inputs)', '-o', '<@(_outputs)' ] }, ], diff --git a/bin/render.gypi b/bin/render.gypi index 2e1dbd8f7..45c9ebb0e 100644 --- a/bin/render.gypi +++ b/bin/render.gypi @@ -27,18 +27,18 @@ 'variables' : { 'cflags_cc': [ - '<@(glfw3_cflags)', - '<@(uv_cflags)', + '<@(glfw_cflags)', + '<@(libuv_cflags)', '<@(boost_cflags)', ], 'ldflags': [ - '<@(glfw3_ldflags)', - '<@(uv_ldflags)', + '<@(glfw_ldflags)', + '<@(libuv_ldflags)', ], 'libraries': [ - '<@(glfw3_static_libs)', - '<@(uv_static_libs)', - '<@(boost_program_options_static_libs)' + '<@(glfw_static_libs)', + '<@(libuv_static_libs)', + '<@(boost_libprogram_options_static_libs)' ], }, diff --git a/config/defaults.mk b/config/defaults.mk deleted file mode 100644 index 1449bf8e1..000000000 --- a/config/defaults.mk +++ /dev/null @@ -1,67 +0,0 @@ - -#### Configuration defaults #################################################### - -ENV_osx = MASON_PLATFORM=osx -CONFIG_osx = -Dhost=osx -Iconfig/osx.gypi -Dinstall_prefix=$(PREFIX) -LIBS_osx = -Dheadless_lib=$(word 1,$(HEADLESS) cgl) -LIBS_osx += -Dplatform_lib=$(word 1,$(PLATFORM) osx) -LIBS_osx += -Dasset_lib=$(word 1,$(ASSET) fs) -LIBS_osx += -Dhttp_lib=$(word 1,$(HTTP) nsurl) -LIBS_osx += -Dcache_lib=$(word 1,$(CACHE) sqlite) -LIBS_osx += --depth=. -Goutput_dir=. - - -ENV_ios = MASON_PLATFORM=ios -CONFIG_ios = -Dhost=ios -Iconfig/ios.gypi -Dinstall_prefix=$(PREFIX) -LIBS_ios = -Dheadless_lib=none -LIBS_ios += -Dplatform_lib=$(word 1,$(PLATFORM) ios) -LIBS_ios += -Dasset_lib=$(word 1,$(ASSET) fs) -LIBS_ios += -Dhttp_lib=$(word 1,$(HTTP) nsurl) -LIBS_ios += -Dcache_lib=$(word 1,$(CACHE) sqlite) -LIBS_ios += --depth=. -Goutput_dir=. - - -ENV_linux = MASON_PLATFORM=linux -CONFIG_linux = -Dhost=linux -Iconfig/linux.gypi -Dinstall_prefix=$(PREFIX) -LIBS_linux = -Dheadless_lib=$(word 1,$(HEADLESS) glx) -LIBS_linux += -Dplatform_lib=$(word 1,$(PLATFORM) linux) -LIBS_linux += -Dasset_lib=$(word 1,$(ASSET) fs) -LIBS_linux += -Dhttp_lib=$(word 1,$(HTTP) curl) -LIBS_linux += -Dcache_lib=$(word 1,$(CACHE) sqlite) -LIBS_linux += --depth=. -Goutput_dir=. - -ANDROID_ABIS += android-lib-arm-v8 -ENV_android-arm-v8 = $(shell MASON_ANDROID_ABI=arm-v8 ./scripts/android/toolchain.sh) -CONFIG_android-arm-v8 = -Dhost=android -Iconfig/android-arm-v8.gypi - -ANDROID_ABIS += android-lib-arm-v7 -ENV_android-arm-v7 = $(shell MASON_ANDROID_ABI=arm-v7 ./scripts/android/toolchain.sh) -CONFIG_android-arm-v7 = -Dhost=android -Iconfig/android-arm-v7.gypi - -ANDROID_ABIS += android-lib-arm-v5 -ENV_android-arm-v5 = $(shell MASON_ANDROID_ABI=arm-v5 ./scripts/android/toolchain.sh) -CONFIG_android-arm-v5 = -Dhost=android -Iconfig/android-arm-v5.gypi - -ANDROID_ABIS += android-lib-x86 -ENV_android-x86 = $(shell MASON_ANDROID_ABI=x86 ./scripts/android/toolchain.sh) -CONFIG_android-x86 = -Dhost=android -Iconfig/android-x86.gypi - -# OpenSSL build is incomplete. -# ANDROID_ABIS += android-lib-x86-64 -# ENV_android-x86-64 = $(shell MASON_ANDROID_ABI=x86-64 ./scripts/android/toolchain.sh) -# CONFIG_android-x86-64 = -Dhost=android -Iconfig/android-x86-64.gypi - -ANDROID_ABIS += android-lib-mips -ENV_android-mips = $(shell MASON_ANDROID_ABI=mips ./scripts/android/toolchain.sh) -CONFIG_android-mips = -Dhost=android -Iconfig/android-mips.gypi - -ANDROID_ABIS += android-lib-mips-64 -ENV_android-mips-64 = $(shell MASON_ANDROID_ABI=mips-64 ./scripts/android/toolchain.sh) -CONFIG_android-mips-64 = -Dhost=android -Iconfig/android-mips-64.gypi - -LIBS_android = -Dheadless_lib=none -LIBS_android += -Dplatform_lib=$(word 1,$(PLATFORM) android) -LIBS_android += -Dasset_lib=$(word 1,$(ASSET) zip) -LIBS_android += -Dhttp_lib=$(word 1,$(HTTP) curl) -LIBS_android += -Dcache_lib=$(word 1,$(CACHE) sqlite) -LIBS_android += --depth=. -Goutput_dir=. diff --git a/configure b/configure index c1f7f6da1..6fbaa9f7f 100755 --- a/configure +++ b/configure @@ -1,76 +1,56 @@ #!/usr/bin/env bash -set -e -set -o pipefail +set -euo pipefail CONFIG_FILE=$1 -if [ `uname -s` = 'Darwin' ]; then - MASON_PLATFORM=${MASON_PLATFORM:-osx} -fi - -function finish { - >&2 echo -en "\033[0m"; -} -trap finish EXIT - -# Install mason -git submodule update --init .mason -export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason" - -case ${MASON_PLATFORM} in - 'ios') - SQLITE_VERSION=system - LIBUV_VERSION=0.10.28 - ZLIB_VERSION=system - BOOST_VERSION=system - ;; - 'android') - SQLITE_VERSION=3.8.8.1 - LIBPNG_VERSION=1.6.16 - LIBJPEG_VERSION=v9a - OPENSSL_VERSION=1.0.1l - LIBCURL_VERSION=7.40.0 - LIBUV_VERSION=1.4.0 - ZLIB_VERSION=system - BOOST_VERSION=1.57.0 - NUNICODE_VERSION=1.5.1 - LIBZIP_VERSION=0.11.2 - ;; - *) - GLFW_VERSION=3.1 - SQLITE_VERSION=3.8.8.1 - LIBPNG_VERSION=1.6.16 - LIBJPEG_VERSION=v9a - LIBCURL_VERSION=system - LIBUV_VERSION=0.10.28 - ZLIB_VERSION=system - BOOST_VERSION=1.57.0 - BOOST_PROGRAM_OPTIONS_VERSION=1.57.0 - NUNICODE_VERSION=1.5.1 - LIBZIP_VERSION=0.11.2 - ;; -esac - -if [ ${MASON_PLATFORM} == 'linux' ] ; then - MESA_VERSION=10.4.3 - mason install mesa ${MESA_VERSION} - export PKG_CONFIG_PATH=`mason prefix mesa ${MESA_VERSION}`/lib/pkgconfig -fi - -function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; } - if [ -z ${CONFIG_FILE} ]; then abort 'You need to specify an output path for the configuration file' fi -if [[ ${MASON_PLATFORM} = 'android' && -z ${MASON_ANDROID_ABI} ]]; then - abort 'You need to specify an ABI for android platforms' -fi +# Make sure we clear all colors +trap '>&2 echo -en "\033[0m"' TERM INT -echo -n "MASON_PLATFORM=${MASON_PLATFORM} " -if [ ${MASON_PLATFORM} = 'android' ]; then echo -n "MASON_ANDROID_ABI=${MASON_ANDROID_ABI} " ; fi -echo $0 $@ +function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; } +function info { >&2 echo -e "\033[1m\033[33m$1\033[0m"; } +function warn { >&2 echo -e "\033[1m\033[33m$1\033[0m"; } + +# Install mason +export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason" + +# You can override the function for a particular set of flags by defining a +# print_XXX_flags function in your dependencies.sh file +function print_flags { + local NAME=$1; shift + if [ "$(type -t print_${NAME}_flags)" = 'function' ]; then + print_${NAME}_flags + else + local VERSION=`echo "${NAME}_VERSION" | tr "[:lower:]" "[:upper:]"` + if [ ! -z ${!VERSION:-} ] ; then + mason install ${NAME} ${!VERSION} + for FLAGS in "$@" ; do + CONFIG+=" '${NAME}_${FLAGS}%': $(quote_flags $(mason ${FLAGS} ${NAME} ${!VERSION})),"$LN + done + else + warn "* Not using ${NAME}" + fi + fi +} + +function print_default_flags { + : +} + +function print_opengl_flags { + CONFIG+=" 'opengl_cflags%': [],"$LN + CONFIG+=" 'opengl_ldflags%': [],"$LN +} + +# Load dependencies +source scripts/${MASON_PLATFORM}/configure.sh +if [ -e scripts/${MASON_PLATFORM}/${MASON_PLATFORM_VERSION}/configure.sh ]; then + source scripts/${MASON_PLATFORM}/${MASON_PLATFORM_VERSION}/configure.sh +fi PYTHON=`which python || abort 'Cannot find python'` @@ -78,12 +58,6 @@ PYTHON=`which python || abort 'Cannot find python'` >&2 ${PYTHON} --version >&2 echo -en "\033[0m"; -PKG_CONFIG=`which pkg-config || abort 'Cannot find pkg-config'` - ->&2 echo -en "\033[1m\033[32m* Using pkg-config " ->&2 ${PKG_CONFIG} --version ->&2 echo -en "\033[0m"; - function quote_flags { ${PYTHON} -c "import sys, re; print filter(None, re.split('(? ${CONFIG_FILE} cat ${CONFIG_FILE} diff --git a/gyp/android.gyp b/gyp/android.gyp new file mode 100644 index 000000000..0a09edb6c --- /dev/null +++ b/gyp/android.gyp @@ -0,0 +1,5 @@ +{ + 'includes': [ + '../android/mapboxgl-app.gypi', + ], +} diff --git a/gyp/asset-fs.gypi b/gyp/asset-fs.gypi index f7fbea1c7..e84fabb62 100644 --- a/gyp/asset-fs.gypi +++ b/gyp/asset-fs.gypi @@ -17,14 +17,14 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', '<@(boost_cflags)', ], 'ldflags': [ - '<@(uv_ldflags)', + '<@(libuv_ldflags)', ], 'libraries': [ - '<@(uv_static_libs)', + '<@(libuv_static_libs)', ], 'defines': [ '-DMBGL_ASSET_FS' diff --git a/gyp/asset-zip.gypi b/gyp/asset-zip.gypi index 8a195649f..e8854734e 100644 --- a/gyp/asset-zip.gypi +++ b/gyp/asset-zip.gypi @@ -18,21 +18,21 @@ 'variables': { 'cflags': [ - '<@(uv_cflags)', - '<@(zip_cflags)', + '<@(libuv_cflags)', + '<@(libzip_cflags)', ], 'cflags_cc': [ - '<@(uv_cflags)', - '<@(zip_cflags)', + '<@(libuv_cflags)', + '<@(libzip_cflags)', '<@(boost_cflags)', ], 'ldflags': [ - '<@(uv_ldflags)', - '<@(zip_ldflags)', + '<@(libuv_ldflags)', + '<@(libzip_ldflags)', ], 'libraries': [ - '<@(uv_static_libs)', - '<@(zip_static_libs)', + '<@(libuv_static_libs)', + '<@(libzip_static_libs)', ], 'defines': [ '-DMBGL_ASSET_ZIP' diff --git a/gyp/cache-sqlite.gypi b/gyp/cache-sqlite.gypi index a9d21924c..704dc490e 100644 --- a/gyp/cache-sqlite.gypi +++ b/gyp/cache-sqlite.gypi @@ -19,17 +19,17 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', - '<@(sqlite3_cflags)', + '<@(libuv_cflags)', + '<@(sqlite_cflags)', ], 'ldflags': [ - '<@(uv_ldflags)', - '<@(sqlite3_ldflags)', + '<@(libuv_ldflags)', + '<@(sqlite_ldflags)', '<@(zlib_ldflags)', ], 'libraries': [ - '<@(uv_static_libs)', - '<@(sqlite3_static_libs)', + '<@(libuv_static_libs)', + '<@(sqlite_static_libs)', '<@(zlib_static_libs)', ], }, diff --git a/gyp/common.gypi b/gyp/common.gypi index d7d21f761..b44f69868 100644 --- a/gyp/common.gypi +++ b/gyp/common.gypi @@ -20,6 +20,7 @@ '-Wno-variadic-macros', '-frtti', '-fexceptions', + '${CFLAGS}', ], 'GCC_WARN_PEDANTIC': 'YES', 'GCC_WARN_UNINITIALIZED_AUTOS': 'YES_AGGRESSIVE', @@ -37,6 +38,7 @@ '-Wno-c++1y-extensions', '-frtti', '-fexceptions', + '${CFLAGS}', ], }], ['OS=="linux"', { diff --git a/gyp/core.gypi b/gyp/core.gypi index 246419371..f9b361032 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -28,21 +28,21 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', '<@(opengl_cflags)', '<@(boost_cflags)', ], 'cflags': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', '<@(opengl_cflags)', '-fPIC' ], 'ldflags': [ - '<@(uv_ldflags)', + '<@(libuv_ldflags)', '<@(opengl_ldflags)', ], 'libraries': [ - '<@(uv_static_libs)', + '<@(libuv_static_libs)', ], }, diff --git a/gyp/http-curl.gypi b/gyp/http-curl.gypi index b7c583235..7ae5b1b75 100644 --- a/gyp/http-curl.gypi +++ b/gyp/http-curl.gypi @@ -17,17 +17,17 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', - '<@(curl_cflags)', + '<@(libuv_cflags)', + '<@(libcurl_cflags)', '<@(boost_cflags)', ], 'ldflags': [ - '<@(uv_ldflags)', - '<@(curl_ldflags)', + '<@(libuv_ldflags)', + '<@(libcurl_ldflags)', ], 'libraries': [ - '<@(uv_static_libs)', - '<@(curl_static_libs)', + '<@(libuv_static_libs)', + '<@(libcurl_static_libs)', ], 'defines': [ '-DMBGL_HTTP_CURL' @@ -38,9 +38,9 @@ ['host == "android"', { 'variables': { # Android uses libzip and openssl to set CURL's CA bundle. - 'cflags_cc': [ '<@(zip_cflags)', '<@(openssl_cflags)' ], - 'ldflags': [ '<@(zip_ldflags)', ], - 'libraries': [ '<@(zip_static_libs)', ], + 'cflags_cc': [ '<@(libzip_cflags)', '<@(openssl_cflags)' ], + 'ldflags': [ '<@(libzip_ldflags)', ], + 'libraries': [ '<@(libzip_static_libs)', ], }, }], ['OS == "mac"', { diff --git a/gyp/http-nsurl.gypi b/gyp/http-nsurl.gypi index a64c8508e..efd2c18a7 100644 --- a/gyp/http-nsurl.gypi +++ b/gyp/http-nsurl.gypi @@ -17,14 +17,14 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', ], 'ldflags': [ '-framework Foundation', # For NSURLRequest - '<@(uv_ldflags)', + '<@(libuv_ldflags)', ], 'libraries': [ - '<@(uv_static_libs)', + '<@(libuv_static_libs)', ], 'defines': [ '-DMBGL_HTTP_NSURL' diff --git a/gyp/linux.gyp b/gyp/linux.gyp index 0f7126934..6cc168ba8 100644 --- a/gyp/linux.gyp +++ b/gyp/linux.gyp @@ -1,7 +1,10 @@ { 'includes': [ '../linux/mapboxgl-app.gypi', - '../test/test.gypi', - '../bin/render.gypi', + ], + + 'conditions': [ + ['test', { 'includes': [ '../test/test.gypi' ] } ], + ['render', { 'includes': [ '../bin/render.gypi' ] } ], ], } diff --git a/gyp/platform-android.gypi b/gyp/platform-android.gypi index 7701393bb..41a5733ac 100644 --- a/gyp/platform-android.gypi +++ b/gyp/platform-android.gypi @@ -22,23 +22,23 @@ 'variables': { 'cflags_cc': [ - '<@(png_cflags)', + '<@(libpng_cflags)', '<@(jpeg_cflags)', - '<@(uv_cflags)', - '<@(nu_cflags)', + '<@(libuv_cflags)', + '<@(nunicode_cflags)', '<@(boost_cflags)', ], 'ldflags': [ - '<@(png_ldflags)', + '<@(libpng_ldflags)', '<@(jpeg_ldflags)', - '<@(uv_ldflags)', - '<@(nu_ldflags)', + '<@(libuv_ldflags)', + '<@(nunicode_ldflags)', ], 'libraries': [ - '<@(png_static_libs)', + '<@(libpng_static_libs)', '<@(jpeg_static_libs)', - '<@(uv_static_libs)', - '<@(nu_static_libs)', + '<@(libuv_static_libs)', + '<@(nunicode_static_libs)', ], }, diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi index 7baba06e5..481e0b2bb 100644 --- a/gyp/platform-ios.gypi +++ b/gyp/platform-ios.gypi @@ -65,11 +65,11 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', '<@(boost_cflags)', ], 'libraries': [ - '<@(uv_static_libs)', + '<@(libuv_static_libs)', ], 'ldflags': [ '-framework CoreLocation', diff --git a/gyp/platform-linux.gypi b/gyp/platform-linux.gypi index 394433870..f614b831e 100644 --- a/gyp/platform-linux.gypi +++ b/gyp/platform-linux.gypi @@ -23,23 +23,23 @@ 'variables': { 'cflags_cc': [ - '<@(png_cflags)', + '<@(libpng_cflags)', '<@(jpeg_cflags)', - '<@(uv_cflags)', - '<@(nu_cflags)', + '<@(libuv_cflags)', + '<@(nunicode_cflags)', '<@(boost_cflags)', ], 'ldflags': [ - '<@(png_ldflags)', + '<@(libpng_ldflags)', '<@(jpeg_ldflags)', - '<@(uv_ldflags)', - '<@(nu_ldflags)', + '<@(libuv_ldflags)', + '<@(nunicode_ldflags)', ], 'libraries': [ - '<@(png_static_libs)', + '<@(libpng_static_libs)', '<@(jpeg_static_libs)', - '<@(uv_static_libs)', - '<@(nu_static_libs)', + '<@(libuv_static_libs)', + '<@(nunicode_static_libs)', ], }, diff --git a/gyp/platform-osx.gypi b/gyp/platform-osx.gypi index ae5194761..af30019ee 100644 --- a/gyp/platform-osx.gypi +++ b/gyp/platform-osx.gypi @@ -20,11 +20,11 @@ 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', '<@(boost_cflags)', ], 'libraries': [ - '<@(uv_static_libs)', + '<@(libuv_static_libs)', ], 'ldflags': [ '-framework Foundation', diff --git a/include/mbgl/android/jni.hpp b/include/mbgl/android/jni.hpp index 48e2740b0..f27c8c844 100644 --- a/include/mbgl/android/jni.hpp +++ b/include/mbgl/android/jni.hpp @@ -31,6 +31,29 @@ extern jfieldID latLngZoomLatitudeId; extern jfieldID latLngZoomLongitudeId; extern jfieldID latLngZoomZoomId; +extern jclass markerClass; +extern jmethodID markerConstructorId; +extern jfieldID markerPositionId; +extern jfieldID markerSpriteId; + +extern jclass polylineClass; +extern jmethodID polylineConstructorId; +extern jfieldID polylineAlphaId; +extern jfieldID polylineVisibleId; +extern jfieldID polylineColorId; +extern jfieldID polylineWidthId; +extern jfieldID polylinePointsId; + +extern jclass polygonClass; +extern jmethodID polygonConstructorId; +extern jfieldID polygonAlphaId; +extern jfieldID polygonVisibleId; +extern jfieldID polygonFillColorId; +extern jfieldID polygonStrokeColorId; +extern jfieldID polygonStrokeWidthId; +extern jfieldID polygonPointsId; +extern jfieldID polygonHolesId; + extern jclass runtimeExceptionClass; extern jclass nullPointerExceptionClass; diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 4b21d5bad..212a43983 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -414,13 +414,24 @@ IB_DESIGNABLE // Responding to Map Position Changes -// TODO +/** Tells the delegate that the region displayed by the map view is about to change. + * + * This method is called whenever the currently displayed map region will start changing. + * @param mapView The map view whose visible region will change. + * @param animated Whether the change will cause an animated effect on the map. */ - (void)mapView:(MGLMapView *)mapView regionWillChangeAnimated:(BOOL)animated; -// TODO +/** Tells the delegate that the region displayed by the map view is changing. + * + * This method is called whenever the currently displayed map region changes. During movement, this method may be called many times to report updates to the map position. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting performance. + * @param mapView The map view whose visible region is changing. */ - (void)mapViewRegionIsChanging:(MGLMapView *)mapView; -// TODO +/** Tells the delegate that the region displayed by the map view just changed. + * + * This method is called whenever the currently displayed map region has finished changing. + * @param mapView The map view whose visible region changed. + * @param animated Whether the change caused an animated effect on the map. */ - (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated; #pragma mark - Loading the Map Data diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp index f65565c03..1bc210b29 100644 --- a/include/mbgl/platform/default/glfw_view.hpp +++ b/include/mbgl/platform/default/glfw_view.hpp @@ -3,7 +3,7 @@ #include -#ifdef NVIDIA +#ifdef MBGL_USE_GLES2 #define GLFW_INCLUDE_ES2 #endif #include diff --git a/include/mbgl/platform/gl.hpp b/include/mbgl/platform/gl.hpp index 73f0801fa..6bcb85fee 100644 --- a/include/mbgl/platform/gl.hpp +++ b/include/mbgl/platform/gl.hpp @@ -19,7 +19,7 @@ #else #error Unsupported Apple platform #endif -#elif __ANDROID__ +#elif __ANDROID__ || MBGL_USE_GLES2 #define GL_GLEXT_PROTOTYPES #include #include diff --git a/include/mbgl/util/gl_helper.hpp b/include/mbgl/util/gl_helper.hpp index cf007e8a6..288fc2c68 100644 --- a/include/mbgl/util/gl_helper.hpp +++ b/include/mbgl/util/gl_helper.hpp @@ -25,21 +25,21 @@ inline void setBlend(const bool& enabled) { enabled ? MBGL_CHECK_ERROR(glEnable(GL_BLEND)) : MBGL_CHECK_ERROR(glDisable(GL_BLEND)); } -inline std::array getClearColor() { - std::array color; - MBGL_CHECK_ERROR(glGetDoublev(GL_COLOR_CLEAR_VALUE, color.data())); +inline std::array getClearColor() { + std::array color; + MBGL_CHECK_ERROR(glGetFloatv(GL_COLOR_CLEAR_VALUE, color.data())); return color; } -inline void setClearColor(const std::array& color) { +inline void setClearColor(const std::array& color) { MBGL_CHECK_ERROR(glClearColor(color[0], color[1], color[2], color[3])); } inline std::array getBlendFunc() { GLint func[2]; - glGetIntegerv(GL_BLEND_SRC, &func[0]); - glGetIntegerv(GL_BLEND_DST, &func[1]); + glGetIntegerv(GL_BLEND_SRC_ALPHA, &func[0]); + glGetIntegerv(GL_BLEND_DST_ALPHA, &func[1]); return {{ static_cast(func[0]), static_cast(func[1]) }}; } @@ -47,7 +47,7 @@ inline void setBlendFunc(const std::array& func) { MBGL_CHECK_ERROR(glBlendFunc(func[0], func[1])); } - +#ifndef GL_ES_VERSION_2_0 inline std::array getPixelZoom() { std::array zoom; glGetDoublev(GL_ZOOM_X, &zoom[0]); @@ -69,17 +69,20 @@ inline std::array getRasterPos() { inline void setRasterPos(const std::array& pos) { MBGL_CHECK_ERROR(glRasterPos4d(pos[0], pos[1], pos[2], pos[3])); } - +#endif } // end anonymous namespace namespace mbgl { namespace gl { using PreserveBlend = Preserve; -using PreserveClearColor = Preserve, getClearColor, setClearColor>; +using PreserveClearColor = Preserve, getClearColor, setClearColor>; using PreserveBlendFunc = Preserve, getBlendFunc, setBlendFunc>; + +#ifndef GL_ES_VERSION_2_0 using PreservePixelZoom = Preserve, getPixelZoom, setPixelZoom>; using PreserveRasterPos = Preserve, getRasterPos, setRasterPos>; +#endif } } diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp index f301d9300..956390085 100644 --- a/include/mbgl/util/projection.hpp +++ b/include/mbgl/util/projection.hpp @@ -33,16 +33,16 @@ public: static inline double getMetersPerPixelAtLatitude(const double lat, const double zoom) { const double mapPixelWidthAtZoom = std::pow(2.0, zoom) * util::tileSize; - const double constrainedLatitude = std::fmin(std::fmax(lat, -util::LATITUDE_MAX), util::LATITUDE_MAX); + const double constrainedLatitude = ::fmin(::fmax(lat, -util::LATITUDE_MAX), util::LATITUDE_MAX); return std::cos(constrainedLatitude * util::DEG2RAD) * util::M2PI * util::EARTH_RADIUS_M / mapPixelWidthAtZoom; } static inline const ProjectedMeters projectedMetersForLatLng(const LatLng latLng) { - const double constrainedLatitude = std::fmin(std::fmax(latLng.latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); + const double constrainedLatitude = ::fmin(::fmax(latLng.latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); const double m = 1 - 1e-15; - const double f = std::fmin(std::fmax(std::sin(util::DEG2RAD * constrainedLatitude), -m), m); + const double f = ::fmin(::fmax(std::sin(util::DEG2RAD * constrainedLatitude), -m), m); const double easting = util::EARTH_RADIUS_M * latLng.longitude * util::DEG2RAD; const double northing = 0.5 * util::EARTH_RADIUS_M * std::log((1 + f) / (1 - f)); @@ -54,7 +54,7 @@ public: double latitude = (2 * std::atan(std::exp(projectedMeters.northing / util::EARTH_RADIUS_M)) - (M_PI / 2)) * util::RAD2DEG; double longitude = projectedMeters.easting * util::RAD2DEG / util::EARTH_RADIUS_M; - latitude = std::fmin(std::fmax(latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); + latitude = ::fmin(::fmax(latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); return LatLng(latitude, longitude); } diff --git a/linux/main.cpp b/linux/main.cpp index 9145b180f..c21d7446e 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include namespace { @@ -29,11 +31,11 @@ void quit_handler(int) { } int main(int argc, char *argv[]) { - int fullscreen_flag = 0; + bool fullscreen = false; std::string style; const struct option long_options[] = { - {"fullscreen", no_argument, &fullscreen_flag, 'f'}, + {"fullscreen", no_argument, 0, 'f'}, {"style", required_argument, 0, 's'}, {0, 0, 0, 0} }; @@ -48,7 +50,7 @@ int main(int argc, char *argv[]) { if (long_options[option_index].flag != 0) break; case 'f': - // handle fullscreen_flag + fullscreen = true; break; case 's': style = std::string("asset://") + std::string(optarg); @@ -65,7 +67,7 @@ int main(int argc, char *argv[]) { sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); - view = std::make_unique(); + view = std::make_unique(fullscreen); mbgl::SQLiteCache cache("/tmp/mbgl-cache.db"); mbgl::DefaultFileSource fileSource(&cache); diff --git a/linux/mapboxgl-app.gypi b/linux/mapboxgl-app.gypi index 35ca322e2..8457c2ce7 100644 --- a/linux/mapboxgl-app.gypi +++ b/linux/mapboxgl-app.gypi @@ -29,13 +29,15 @@ 'variables' : { 'cflags_cc': [ - '<@(glfw3_cflags)', + '<@(opengl_cflags)', + '<@(boost_cflags)', + '<@(glfw_cflags)', ], 'ldflags': [ - '<@(glfw3_ldflags)', + '<@(glfw_ldflags)', ], 'libraries': [ - '<@(glfw3_static_libs)', + '<@(glfw_static_libs)', ], }, diff --git a/macosx/mapboxgl-app.gypi b/macosx/mapboxgl-app.gypi index c56bca659..589ae29bd 100644 --- a/macosx/mapboxgl-app.gypi +++ b/macosx/mapboxgl-app.gypi @@ -34,14 +34,15 @@ 'variables' : { 'cflags_cc': [ - '<@(glfw3_cflags)', + '<@(boost_cflags)', + '<@(glfw_cflags)', ], 'ldflags': [ '-framework SystemConfiguration', # For NSUserDefaults and Reachability - '<@(glfw3_ldflags)', + '<@(glfw_ldflags)', ], 'libraries': [ - '<@(glfw3_static_libs)', + '<@(glfw_static_libs)', ], }, diff --git a/platform/default/asset_request_fs.cpp b/platform/default/asset_request_fs.cpp index 4511cf882..733e240fb 100644 --- a/platform/default/asset_request_fs.cpp +++ b/platform/default/asset_request_fs.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -131,7 +132,7 @@ void AssetRequest::fileStated(uv_fs_t *req) { #else self->response->modified = stat->st_mtime; #endif - self->response->etag = std::to_string(stat->st_ino); + self->response->etag = util::toString(stat->st_ino); const auto size = (unsigned int)(stat->st_size); self->response->data.resize(size); self->buffer = uv_buf_init(const_cast(self->response->data.data()), size); diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 49ae8c4f6..fb08b9234 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -188,7 +189,7 @@ void GLFWView::addRandomCustomPointAnnotations(int count) { for (int i = 0; i < count; i++) { static int spriteID = 1; - const auto name = std::string{ "marker-" } + std::to_string(spriteID++); + const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++); map->setSprite(name, makeSpriteImage(22, 22, 1)); spriteIDs.push_back(name); points.emplace_back(makeRandomPoint(), name); diff --git a/platform/default/http_request_curl.cpp b/platform/default/http_request_curl.cpp index 6b2c38e77..0f7f8c0ac 100644 --- a/platform/default/http_request_curl.cpp +++ b/platform/default/http_request_curl.cpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -20,6 +21,7 @@ #include #include #include +#include void handleError(CURLMcode code) { if (code != CURLM_OK) { @@ -468,7 +470,11 @@ HTTPCURLRequest::HTTPCURLRequest(HTTPCURLContext* context_, const Resource& reso handleError(curl_easy_setopt(handle, CURLOPT_WRITEDATA, this)); handleError(curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, headerCallback)); handleError(curl_easy_setopt(handle, CURLOPT_HEADERDATA, this)); +#if LIBCURL_VERSION_NUM >= ((7) << 16 | (21) << 8 | 6) // Renamed in 7.21.6 handleError(curl_easy_setopt(handle, CURLOPT_ACCEPT_ENCODING, "gzip, deflate")); +#else + handleError(curl_easy_setopt(handle, CURLOPT_ENCODING, "gzip, deflate")); +#endif handleError(curl_easy_setopt(handle, CURLOPT_USERAGENT, "MapboxGL/1.0")); handleError(curl_easy_setopt(handle, CURLOPT_SHARE, context->share)); @@ -700,12 +706,12 @@ void HTTPCURLRequest::handleResult(CURLcode code) { } else if (responseCode >= 500 && responseCode < 600) { // Server errors may be temporary, so back off exponentially. response->status = Response::Error; - response->message = "HTTP status code " + std::to_string(responseCode); + response->message = "HTTP status code " + util::toString(responseCode); return finish(ResponseStatus::TemporaryError); } else { // We don't know how to handle any other errors, so declare them as permanently failing. response->status = Response::Error; - response->message = "HTTP status code " + std::to_string(responseCode); + response->message = "HTTP status code " + util::toString(responseCode); return finish(ResponseStatus::PermanentError); } } diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 4f8596a7b..42b694609 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -157,7 +157,12 @@ void PngReader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char * double gamma; if (png_get_gAMA(png_ptr, info_ptr, &gamma)) png_set_gamma(png_ptr, 2.2, gamma); + +#ifdef PNG_ALPHA_PREMULTIPLIED png_set_alpha_mode(png_ptr, PNG_ALPHA_PREMULTIPLIED, PNG_GAMMA_LINEAR); +#else + // TODO: Manually premultiply the image data. +#endif if (x0 == 0 && y0 == 0 && w >= width_ && h >= height_) { diff --git a/platform/default/sqlite3.cpp b/platform/default/sqlite3.cpp index b2ae4e65b..ca525cd20 100644 --- a/platform/default/sqlite3.cpp +++ b/platform/default/sqlite3.cpp @@ -3,6 +3,7 @@ #include #include +#include // Check sqlite3 library version. const static bool sqliteVersionCheck = []() { diff --git a/scripts/android/configure.sh b/scripts/android/configure.sh new file mode 100644 index 000000000..667ea6891 --- /dev/null +++ b/scripts/android/configure.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +BOOST_VERSION=1.57.0 +LIBCURL_VERSION=7.40.0 +OPENSSL_VERSION=1.0.1l +LIBPNG_VERSION=1.6.16 +JPEG_VERSION=v9a +SQLITE_VERSION=3.8.8.1 +LIBUV_VERSION=1.4.0 +ZLIB_VERSION=system +NUNICODE_VERSION=1.5.1 +LIBZIP_VERSION=0.11.2 + +export MASON_ANDROID_ABI=${MASON_PLATFORM_VERSION} \ No newline at end of file diff --git a/scripts/android/defaults.mk b/scripts/android/defaults.mk new file mode 100644 index 000000000..436f9db71 --- /dev/null +++ b/scripts/android/defaults.mk @@ -0,0 +1,11 @@ +HEADLESS ?= none +PLATFORM ?= android +ASSET ?= zip +HTTP ?= curl +CACHE ?= sqlite + +GYP_FLAVOR_SUFFIX=-android + +HOST_VERSION ?= arm-v7 + +ENV = $(shell MASON_ANDROID_ABI=$(HOST_VERSION) ./scripts/android/toolchain.sh) diff --git a/scripts/ios/configure.sh b/scripts/ios/configure.sh new file mode 100644 index 000000000..0562e0e39 --- /dev/null +++ b/scripts/ios/configure.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +BOOST_VERSION=1.57.0 +SQLITE_VERSION=system +LIBUV_VERSION=0.10.28 +ZLIB_VERSION=system diff --git a/scripts/ios/defaults.mk b/scripts/ios/defaults.mk new file mode 100644 index 000000000..fafc33213 --- /dev/null +++ b/scripts/ios/defaults.mk @@ -0,0 +1,12 @@ +HEADLESS = none +PLATFORM ?= ios +ASSET ?= fs +HTTP ?= nsurl +CACHE ?= sqlite + +HOST_VERSION = all + +PROVISIONING_PROFILE ?= 19324a54-7455-4f0b-8e1c-e6957c718ebc + +export MASON_PLATFORM=$(HOST) +export MASON_PLATFORM_VERSION=$(HOST_VERSION) diff --git a/scripts/ios/package.sh b/scripts/ios/package.sh index b499f4a10..449cf5c25 100755 --- a/scripts/ios/package.sh +++ b/scripts/ios/package.sh @@ -50,7 +50,7 @@ if [[ "${BUILD_FOR_DEVICE}" == true ]]; then ARCHS="arm64 armv7 armv7s" \ ONLY_ACTIVE_ARCH=NO \ GCC_GENERATE_DEBUGGING_SYMBOLS=${GCC_GENERATE_DEBUGGING_SYMBOLS} \ - -project ./build/ios/mbgl.xcodeproj \ + -project ./build/ios-all/mbgl.xcodeproj \ -configuration ${BUILDTYPE} \ -target everything \ -jobs ${JOBS} | xcpretty -c @@ -61,7 +61,7 @@ xcodebuild -sdk iphonesimulator${IOS_SDK_VERSION} \ ARCHS="x86_64 i386" \ ONLY_ACTIVE_ARCH=NO \ GCC_GENERATE_DEBUGGING_SYMBOLS=${GCC_GENERATE_DEBUGGING_SYMBOLS} \ - -project ./build/ios/mbgl.xcodeproj \ + -project ./build/ios-all/mbgl.xcodeproj \ -configuration ${BUILDTYPE} \ -target everything \ -jobs ${JOBS} | xcpretty -c diff --git a/scripts/linux/configure.sh b/scripts/linux/configure.sh new file mode 100644 index 000000000..1099a6550 --- /dev/null +++ b/scripts/linux/configure.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +BOOST_VERSION=1.57.0 +BOOST_LIBPROGRAM_OPTIONS_VERSION=1.57.0 +LIBCURL_VERSION=system +GLFW_VERSION=3.1 +LIBPNG_VERSION=1.6.16 +JPEG_VERSION=v9a +SQLITE_VERSION=3.8.8.1 +LIBUV_VERSION=0.10.28 +ZLIB_VERSION=system +NUNICODE_VERSION=1.5.1 +LIBZIP_VERSION=0.11.2 + +function print_opengl_flags { + CONFIG+=" 'opengl_cflags%': $(quote_flags $(pkg-config gl x11 --cflags)),"$LN + CONFIG+=" 'opengl_ldflags%': $(quote_flags $(pkg-config gl x11 --libs)),"$LN +} diff --git a/scripts/linux/defaults.mk b/scripts/linux/defaults.mk new file mode 100644 index 000000000..126c8f99a --- /dev/null +++ b/scripts/linux/defaults.mk @@ -0,0 +1,5 @@ +HEADLESS ?= glx +PLATFORM ?= linux +ASSET ?= fs +HTTP ?= curl +CACHE ?= sqlite diff --git a/scripts/main.mk b/scripts/main.mk new file mode 100644 index 000000000..b641a6ffe --- /dev/null +++ b/scripts/main.mk @@ -0,0 +1,127 @@ +ifeq (,$(V)) + QUIET = @ +endif + +# Determine host platform +HOST ?= $(BUILD) + +# Defines host defaults +include scripts/$(HOST)/defaults.mk + +HOST_VERSION ?= $(BUILD_VERSION) + +# Optionally include version-specific host defaults +-include scripts/$(HOST)/$(HOST_VERSION)/defaults.mk + +export MASON_PLATFORM=$(HOST) +export MASON_PLATFORM_VERSION=$(HOST_VERSION) + +HOST_SLUG = $(HOST)-$(HOST_VERSION) +CONFIGURE_FILES = scripts/$(HOST)/configure.sh +ifneq (,$(wildcard scripts/$(HOST)/$(HOST_VERSION)/configure.sh)) + CONFIGURE_FILES += scripts/$(HOST)/$(HOST_VERSION)/configure.sh +endif + + +# Text formatting +TEXT_BOLD = \033[1m +COLOR_GREEN = \033[32m +COLOR_CYAN = \033[36m +COLOR_PINK = \033[35m +FORMAT_END = \033[0m + +default: ; + +#### Dependencies ############################################################## + +SUBMODULES += .mason/mason.sh +.mason/mason.sh: + ./scripts/flock.py .git/Submodule.lock git submodule update --init .mason + +SUBMODULES += styles/styles +styles/styles: + ./scripts/flock.py .git/Submodule.lock git submodule update --init styles + +SUBMODULES += src/mbgl/util/geojsonvt/geojsonvt.hpp +src/mbgl/util/geojsonvt/geojsonvt.hpp: + ./scripts/flock.py .git/Submodule.lock git submodule update --init src/mbgl/util/geojsonvt + +SUBMODULES += test/suite/package.json +test/suite/package.json: + ./scripts/flock.py .git/Submodule.lock git submodule update --init test/suite + +ifeq ($(HOST),ios) +SUBMODULES += platform/ios/vendor/SMCalloutView/SMCalloutView.h +platform/ios/vendor/SMCalloutView/SMCalloutView.h: + ./scripts/flock.py .git/Submodule.lock git submodule update --init platform/ios/vendor/SMCalloutView + +SUBMODULES += test/ios/KIF/KIF.xcodeproj +test/ios/KIF/KIF.xcodeproj: + ./scripts/flock.py .git/Submodule.lock git submodule update --init test/ios/KIF +endif + +# Wildcard targets get removed after build by default, but we want to preserve the config. +.PRECIOUS: config/%.gypi +config/%.gypi: $(SUBMODULES) configure $(CONFIGURE_FILES) + @printf "$(TEXT_BOLD)$(COLOR_GREEN)* Recreating project...$(FORMAT_END)\n" + $(QUIET)$(ENV) ./scripts/flock.py build/Configure.lock ./configure config/$*.gypi + + +#### Build files ############################################################### + +GYP_FLAGS += -Dhost=$(HOST) +GYP_FLAGS += -Iconfig/$(HOST_SLUG).gypi +GYP_FLAGS += -Dplatform_lib=$(PLATFORM) +GYP_FLAGS += -Dhttp_lib=$(HTTP) +GYP_FLAGS += -Dasset_lib=$(ASSET) +GYP_FLAGS += -Dcache_lib=$(CACHE) +GYP_FLAGS += -Dheadless_lib=$(HEADLESS) +GYP_FLAGS += -Dtest=$(BUILD_TEST) +GYP_FLAGS += -Drender=$(BUILD_RENDER) +GYP_FLAGS += --depth=. +GYP_FLAGS += -Goutput_dir=. +GYP_FLAGS += --generator-output=./build/$(HOST_SLUG) + +.PHONY: Makefile/__project__ +Makefile/__project__: print-env $(SUBMODULES) config/$(HOST_SLUG).gypi + @printf "$(TEXT_BOLD)$(COLOR_GREEN)* Recreating project...$(FORMAT_END)\n" + $(QUIET)$(ENV) deps/run_gyp gyp/$(HOST).gyp $(GYP_FLAGS) -f make$(GYP_FLAVOR_SUFFIX) + +.PHONY: Xcode/__project__ +Xcode/__project__: print-env $(SUBMODULES) config/$(HOST_SLUG).gypi + @printf "$(TEXT_BOLD)$(COLOR_GREEN)* Recreating project...$(FORMAT_END)\n" + $(QUIET)$(ENV) deps/run_gyp gyp/$(HOST).gyp $(GYP_FLAGS) -f xcode$(GYP_FLAVOR_SUFFIX) + +#### Build individual targets ################################################## + +Makefile/%: Makefile/__project__ + @printf "$(TEXT_BOLD)$(COLOR_GREEN)* Building target $*...$(FORMAT_END)\n" + $(QUIET)$(ENV) $(MAKE) -C build/$(HOST_SLUG) BUILDTYPE=$(BUILDTYPE) $* + +Xcode/%: Xcode/__project__ + @printf "$(TEXT_BOLD)$(COLOR_GREEN)* Building target $*...$(FORMAT_END)\n" + $(QUIET)$(ENV) xcodebuild \ + $(XCODEBUILD_ARGS) \ + -project ./build/$(HOST_SLUG)/gyp/$(HOST).xcodeproj \ + -configuration $(BUILDTYPE) \ + -target $* \ + -jobs $(JOBS) \ + $(XCPRETTY) + +#### Run tests ################################################################# + +test-%: Makefile/test + ./scripts/run_tests.sh "build/$(HOST_SLUG)/$(BUILDTYPE)/test" --gtest_filter=$* + +#### Helper targets ############################################################ + +.PHONY: print-env +print-env: $(SUBMODULES) + @printf "$(COLOR_PINK)build:$(FORMAT_END) $(BUILD)/$(BUILD_VERSION)\n" + @printf "$(COLOR_PINK)host:$(FORMAT_END) $(HOST)/$(HOST_VERSION)\n" + @printf "$(COLOR_PINK)libs:$(FORMAT_END) " + @printf "headless=$(COLOR_CYAN)%s$(FORMAT_END) " $(HEADLESS) + @printf "platform=$(COLOR_CYAN)%s$(FORMAT_END) " $(PLATFORM) + @printf "asset=$(COLOR_CYAN)%s$(FORMAT_END) " $(ASSET) + @printf "http=$(COLOR_CYAN)%s$(FORMAT_END) " $(HTTP) + @printf "cache=$(COLOR_CYAN)%s$(FORMAT_END)\n" $(CACHE) diff --git a/scripts/osx/configure.sh b/scripts/osx/configure.sh new file mode 100644 index 000000000..fc3c5f464 --- /dev/null +++ b/scripts/osx/configure.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +BOOST_VERSION=1.57.0 +BOOST_LIBPROGRAM_OPTIONS_VERSION=1.57.0 +LIBCURL_VERSION=system +GLFW_VERSION=3.1 +LIBPNG_VERSION=1.6.16 +JPEG_VERSION=v9a +SQLITE_VERSION=3.8.8.1 +LIBUV_VERSION=0.10.28 +ZLIB_VERSION=system +NUNICODE_VERSION=1.5.1 +LIBZIP_VERSION=0.11.2 diff --git a/scripts/osx/defaults.mk b/scripts/osx/defaults.mk new file mode 100644 index 000000000..f148f66d8 --- /dev/null +++ b/scripts/osx/defaults.mk @@ -0,0 +1,5 @@ +HEADLESS ?= cgl +PLATFORM ?= osx +ASSET ?= fs +HTTP ?= nsurl +CACHE ?= sqlite diff --git a/src/csscolorparser/csscolorparser.cpp b/src/csscolorparser/csscolorparser.cpp index 7ba989fde..8281eb420 100644 --- a/src/csscolorparser/csscolorparser.cpp +++ b/src/csscolorparser/csscolorparser.cpp @@ -116,7 +116,7 @@ const size_t namedColorCount = sizeof (namedColors) / sizeof (NamedColor); template uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255. - i = std::round(i); // Seems to be what Chrome does (vs truncation). + i = ::round(i); // Seems to be what Chrome does (vs truncation). return i < 0 ? 0 : i > 255 ? 255 : i; } diff --git a/src/mbgl/geometry/collision_box_buffer.cpp b/src/mbgl/geometry/collision_box_buffer.cpp index 050a999db..da9031c89 100644 --- a/src/mbgl/geometry/collision_box_buffer.cpp +++ b/src/mbgl/geometry/collision_box_buffer.cpp @@ -13,8 +13,8 @@ size_t CollisionBoxVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, f int16_t *shorts = static_cast(data); shorts[0] /* pos */ = x; shorts[1] /* pos */ = y; - shorts[2] /* offset */ = std::round(ox); // use 1/64 pixels for placement - shorts[3] /* offset */ = std::round(oy); + shorts[2] /* offset */ = ::round(ox); // use 1/64 pixels for placement + shorts[3] /* offset */ = ::round(oy); uint8_t *ubytes = static_cast(data); // a_data1 diff --git a/src/mbgl/geometry/debug_font_buffer.cpp b/src/mbgl/geometry/debug_font_buffer.cpp index 1ec71463e..e4af70766 100644 --- a/src/mbgl/geometry/debug_font_buffer.cpp +++ b/src/mbgl/geometry/debug_font_buffer.cpp @@ -23,8 +23,8 @@ void DebugFontBuffer::addText(const char *text, double left, double baseline, do if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) { prev = false; } else { - int16_t x = std::round(left + glyph.data[j] * scale); - int16_t y = std::round(baseline - glyph.data[j + 1] * scale); + int16_t x = ::round(left + glyph.data[j] * scale); + int16_t y = ::round(baseline - glyph.data[j + 1] * scale); if (prev) { coords = static_cast(addElement()); coords[0] = prev_x; diff --git a/src/mbgl/geometry/icon_buffer.cpp b/src/mbgl/geometry/icon_buffer.cpp index 2ca15b6c5..831ffc72a 100644 --- a/src/mbgl/geometry/icon_buffer.cpp +++ b/src/mbgl/geometry/icon_buffer.cpp @@ -13,8 +13,8 @@ size_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t t int16_t *shorts = static_cast(data); shorts[0] /* pos */ = x; shorts[1] /* pos */ = y; - shorts[2] /* offset */ = std::round(ox * 64); // use 1/64 pixels for placement - shorts[3] /* offset */ = std::round(oy * 64); + shorts[2] /* offset */ = ::round(ox * 64); // use 1/64 pixels for placement + shorts[3] /* offset */ = ::round(oy * 64); uint8_t *ubytes = static_cast(data); // a_data1 @@ -24,7 +24,7 @@ size_t IconVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, int16_t t // a_data2 ubytes[12] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160. - ubytes[13] /* maxzoom */ = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160. + ubytes[13] /* maxzoom */ = ::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160. return idx; } diff --git a/src/mbgl/geometry/line_buffer.cpp b/src/mbgl/geometry/line_buffer.cpp index 770483848..f475c63b2 100644 --- a/src/mbgl/geometry/line_buffer.cpp +++ b/src/mbgl/geometry/line_buffer.cpp @@ -14,8 +14,8 @@ size_t LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, i coords[1] = (y * 2) | ty; int8_t *extrude = static_cast(data); - extrude[4] = std::round(extrudeScale * ex); - extrude[5] = std::round(extrudeScale * ey); + extrude[4] = ::round(extrudeScale * ex); + extrude[5] = ::round(extrudeScale * ey); extrude[6] = static_cast(linesofar / 128); extrude[7] = static_cast(linesofar % 128); diff --git a/src/mbgl/geometry/text_buffer.cpp b/src/mbgl/geometry/text_buffer.cpp index e3f7117eb..8f312c9fa 100644 --- a/src/mbgl/geometry/text_buffer.cpp +++ b/src/mbgl/geometry/text_buffer.cpp @@ -13,8 +13,8 @@ size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t int16_t *shorts = static_cast(data); shorts[0] /* pos */ = x; shorts[1] /* pos */ = y; - shorts[2] /* offset */ = std::round(ox * 64); // use 1/64 pixels for placement - shorts[3] /* offset */ = std::round(oy * 64); + shorts[2] /* offset */ = ::round(ox * 64); // use 1/64 pixels for placement + shorts[3] /* offset */ = ::round(oy * 64); uint8_t *ubytes = static_cast(data); // a_data1 @@ -24,7 +24,7 @@ size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t // a_data2 ubytes[12] /* minzoom */ = minzoom * 10; // 1/10 zoom levels: z16 == 160. - ubytes[13] /* maxzoom */ = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160. + ubytes[13] /* maxzoom */ = ::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160. return idx; } diff --git a/src/mbgl/map/annotation.cpp b/src/mbgl/map/annotation.cpp index 9915bcb1f..874459797 100644 --- a/src/mbgl/map/annotation.cpp +++ b/src/mbgl/map/annotation.cpp @@ -6,6 +6,8 @@ #include #include #include +#include + #include #include @@ -66,7 +68,7 @@ uint32_t AnnotationManager::nextID() { vec2 AnnotationManager::projectPoint(const LatLng& point) { // Clamp to the latitude limits of Mercator. - const double constrainedLatitude = std::fmin(std::fmax(point.latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); + const double constrainedLatitude = ::fmin(::fmax(point.latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); // Project a coordinate into unit space in a square map. const double sine = std::sin(constrainedLatitude * M_PI / 180.0); @@ -109,7 +111,7 @@ AnnotationManager::addTileFeature(const uint32_t annotationID, std::vector points; for (size_t i = 0; i < segments[0].size(); ++i) { // first segment for now (no holes) - const double constraintedLatitude = std::fmin(std::fmax(segments[0][i].latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); + const double constraintedLatitude = ::fmin(::fmax(segments[0][i].latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX); points.push_back(LonLat(segments[0][i].longitude, constraintedLatitude)); } @@ -219,7 +221,7 @@ AnnotationManager::addTileFeature(const uint32_t annotationID, if (type == AnnotationType::Point) { layerID = PointLayerID; } else { - layerID = ShapeLayerID + "." + std::to_string(annotationID); + layerID = ShapeLayerID + "." + util::toString(annotationID); } if (tile_pos.second || tile_pos.first->second.second->getMutableLayer(layerID) == nullptr) { layer = std::make_shared(); @@ -382,7 +384,7 @@ std::unordered_set AnnotationManager::removeAnnotations(co // remove shape layer from tiles if relevant for (auto tile_it = tiles.begin(); tile_it != tiles.end(); ++tile_it) { if (tile_it->second.first.count(annotationID)) { - tile_it->second.second->removeLayer(ShapeLayerID + "." + std::to_string(annotationID)); + tile_it->second.second->removeLayer(ShapeLayerID + "." + util::toString(annotationID)); affectedTiles.insert(tile_it->first); } } @@ -507,7 +509,7 @@ const LiveTile* AnnotationManager::getTile(const TileID& id) { // create shape tile layers from GeoJSONVT queries for (auto& tiler_it : shapeTilers) { const auto annotationID = tiler_it.first; - const std::string layerID = ShapeLayerID + "." + std::to_string(annotationID); + const std::string layerID = ShapeLayerID + "." + util::toString(annotationID); // check for existing render layer auto renderLayer = renderTile->getMutableLayer(layerID); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 5b96b8319..f357c05e8 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -202,9 +202,9 @@ void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, const Duratio // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / size.x; double scaleY = (getHeight() - padding.top - padding.bottom) / size.y; - double minScale = std::fmin(scaleX, scaleY); - double zoom = std::log2(getScale() * minScale); - zoom = std::fmax(std::fmin(zoom, getMaxZoom()), getMinZoom()); + double minScale = ::fmin(scaleX, scaleY); + double zoom = ::log2(getScale() * minScale); + zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. vec2<> paddedNEPixel = { diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 55652272d..56bca24af 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -170,7 +171,7 @@ void MapContext::updateAnnotationTiles(const std::unordered_setgetOrderedShapeAnnotations()) { - const std::string shapeLayerID = shapeID + "." + std::to_string(shapeAnnotationID); + const std::string shapeLayerID = shapeID + "." + util::toString(shapeAnnotationID); const auto layer_it = std::find_if(style->layers.begin(), style->layers.end(), [&shapeLayerID](util::ptr layer) { diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 94931602e..7368d1b44 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -312,7 +312,7 @@ double Source::getZoom(const TransformState& state) const { int32_t Source::coveringZoomLevel(const TransformState& state) const { double zoom = getZoom(state); if (info.type == SourceType::Raster || info.type == SourceType::Video) { - zoom = std::round(zoom); + zoom = ::round(zoom); } else { zoom = std::floor(zoom); } @@ -407,7 +407,7 @@ bool Source::update(MapData& data, double zoom = getZoom(transformState); if (info.type == SourceType::Raster || info.type == SourceType::Video) { - zoom = std::round(zoom); + zoom = ::round(zoom); } else { zoom = std::floor(zoom); } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index b39614888..08cca3db2 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -101,7 +101,7 @@ void Transform::setLatLng(const LatLng latLng, const Duration& duration) { } const double m = 1 - 1e-15; - const double f = std::fmin(std::fmax(std::sin(util::DEG2RAD * latLng.latitude), -m), m); + const double f = ::fmin(::fmax(std::sin(util::DEG2RAD * latLng.latitude), -m), m); double xn = -latLng.longitude * state.Bc; double yn = 0.5 * state.Cc * std::log((1 + f) / (1 - f)); @@ -121,7 +121,7 @@ void Transform::setLatLngZoom(const LatLng latLng, const double zoom, const Dura state.Cc = s / util::M2PI; const double m = 1 - 1e-15; - const double f = std::fmin(std::fmax(std::sin(util::DEG2RAD * latLng.latitude), -m), m); + const double f = ::fmin(::fmax(std::sin(util::DEG2RAD * latLng.latitude), -m), m); double xn = -latLng.longitude * state.Bc; double yn = 0.5 * state.Cc * std::log((1 + f) / (1 - f)); diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index bb3e86d33..9a5e53092 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -140,11 +140,11 @@ double TransformState::getMinZoom() const { double test_y = y; constrain(test_scale, test_y); - return std::log2(std::fmin(min_scale, test_scale)); + return ::log2(::fmin(min_scale, test_scale)); } double TransformState::getMaxZoom() const { - return std::log2(max_scale); + return ::log2(max_scale); } diff --git a/src/mbgl/platform/gl.cpp b/src/mbgl/platform/gl.cpp index 76be580b9..d387f3fbf 100644 --- a/src/mbgl/platform/gl.cpp +++ b/src/mbgl/platform/gl.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -51,7 +52,7 @@ void checkError(const char *cmd, const char *file, int line) { default: error = "(unknown)"; break; } - throw ::mbgl::gl::Error(err, std::string(cmd) + ": Error GL_" + error + " - " + file + ":" + std::to_string(line)); + throw ::mbgl::gl::Error(err, std::string(cmd) + ": Error GL_" + error + " - " + file + ":" + util::toString(line)); } } diff --git a/src/mbgl/platform/log.cpp b/src/mbgl/platform/log.cpp index eec33444b..6daed4088 100644 --- a/src/mbgl/platform/log.cpp +++ b/src/mbgl/platform/log.cpp @@ -2,6 +2,7 @@ #include +#include #include #include diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index fd4df4314..151e4c4a4 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -141,7 +141,7 @@ void FillBucket::tessellate() { for (size_t i = 0; i < vertex_count; ++i) { if (vertex_indices[i] == TESS_UNDEF) { - vertexBuffer.add(std::round(vertices[i * 2]), std::round(vertices[i * 2 + 1])); + vertexBuffer.add(::round(vertices[i * 2]), ::round(vertices[i * 2 + 1])); vertex_indices[i] = (TESSindex)total_vertex_count; total_vertex_count++; } diff --git a/src/mbgl/renderer/frame_history.cpp b/src/mbgl/renderer/frame_history.cpp index c95e82631..cdc60f4eb 100644 --- a/src/mbgl/renderer/frame_history.cpp +++ b/src/mbgl/renderer/frame_history.cpp @@ -63,8 +63,8 @@ FadeProperties FrameHistory::getFadeProperties(const Duration& duration) { float startingZ = history.front().z; const FrameSnapshot lastFrame = history.back(); float endingZ = lastFrame.z; - float lowZ = std::fmin(startingZ, endingZ); - float highZ = std::fmax(startingZ, endingZ); + float lowZ = ::fmin(startingZ, endingZ); + float highZ = ::fmax(startingZ, endingZ); // Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one // duration diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 0860bbc03..f406c0d8f 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -70,7 +70,7 @@ void Painter::renderLine(LineBucket& bucket, const StyleLayer &layer_desc, const LinePatternPos posB = lineAtlas->getDashPosition(properties.dash_array.to, layout.cap == CapType::Round); lineAtlas->bind(); - float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0 * id.overscaling; + float patternratio = std::pow(2.0, std::floor(::log2(state.getScale())) - id.z) / 8.0 * id.overscaling; float scaleXA = patternratio / posA.width / properties.dash_line_width / properties.dash_array.fromScale; float scaleYA = -posA.height / 2.0; float scaleXB = patternratio / posB.width / properties.dash_line_width / properties.dash_array.toScale; diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index c4347febb..1ee90293d 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -448,7 +448,7 @@ template void SymbolBucket::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const bool alongLine) { const float zoom = collision.zoom; - const float placementZoom = std::fmax(std::log(scale) / std::log(2) + zoom, 0); + const float placementZoom = ::fmax(std::log(scale) / std::log(2) + zoom, 0); for (const auto& symbol : symbols) { const auto &tl = symbol.tl; diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp index 3c2d22a5b..1c7806a4e 100644 --- a/src/mbgl/text/collision_tile.cpp +++ b/src/mbgl/text/collision_tile.cpp @@ -44,7 +44,7 @@ float CollisionTile::placeFeature(const CollisionFeature &feature) { if (std::isnan(s1) || std::isnan(s2)) s1 = s2 = 1; if (std::isnan(s3) || std::isnan(s4)) s3 = s4 = 1; - float collisionFreeScale = std::fmin(std::fmax(s1, s2), std::fmax(s3, s4)); + float collisionFreeScale = ::fmin(::fmax(s1, s2), ::fmax(s3, s4)); if (collisionFreeScale > blocking.maxScale) { // After a box's maxScale the label has shrunk enough that the box is no longer needed to cover it, diff --git a/src/mbgl/text/font_stack.cpp b/src/mbgl/text/font_stack.cpp index d4d3a3947..6d06796e8 100644 --- a/src/mbgl/text/font_stack.cpp +++ b/src/mbgl/text/font_stack.cpp @@ -27,8 +27,8 @@ const Shaping FontStack::getShaping(const std::u32string &string, const float ma // the y offset *should* be part of the font metadata const int32_t yOffset = -17; - float x = std::round(translate.x * 24); // one em - const float y = std::round(translate.y * 24) + yOffset; // one em + float x = ::round(translate.x * 24); // one em + const float y = ::round(translate.y * 24) + yOffset; // one em // Loop through all characters of this label and shape. for (uint32_t chr : string) { diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp index ef8a75c02..6492fd067 100644 --- a/src/mbgl/text/get_anchors.cpp +++ b/src/mbgl/text/get_anchors.cpp @@ -32,7 +32,7 @@ Anchors resample(const std::vector &line, const float offset, const y = util::interpolate(float(a.y), float(b.y), t); if (x >= 0 && x < 4096 && y >= 0 && y < 4096) { - Anchor anchor(std::round(x), std::round(y), angle, 0.5f, i); + Anchor anchor(::round(x), ::round(y), angle, 0.5f, i); if (!angleWindowSize || checkMaxAngle(line, anchor, labelLength, angleWindowSize, maxAngle)) { anchors.push_back(anchor); diff --git a/src/mbgl/util/compression.cpp b/src/mbgl/util/compression.cpp index 3a1658b8f..139dba754 100644 --- a/src/mbgl/util/compression.cpp +++ b/src/mbgl/util/compression.cpp @@ -2,6 +2,7 @@ #include +#include #include #include diff --git a/src/mbgl/util/geojsonvt b/src/mbgl/util/geojsonvt index ed99a6290..995ffc72c 160000 --- a/src/mbgl/util/geojsonvt +++ b/src/mbgl/util/geojsonvt @@ -1 +1 @@ -Subproject commit ed99a6290fa42107a982e7f3675aae49d29026b1 +Subproject commit 995ffc72c556da4b4880a6036fbcf7159fc5ecce diff --git a/src/mbgl/util/io.cpp b/src/mbgl/util/io.cpp index bb4c3595c..0f7ce0e55 100644 --- a/src/mbgl/util/io.cpp +++ b/src/mbgl/util/io.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp index f410b8e81..9e444fec1 100644 --- a/src/mbgl/util/tile_cover.cpp +++ b/src/mbgl/util/tile_cover.cpp @@ -27,8 +27,8 @@ typedef const std::function ScanLine; // scan-line conversion static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine scanLine) { - double y0 = std::fmax(ymin, std::floor(e1.y0)); - double y1 = std::fmin(ymax, std::ceil(e1.y1)); + double y0 = ::fmax(ymin, std::floor(e1.y0)); + double y1 = ::fmin(ymax, std::ceil(e1.y1)); // sort edges by x-coordinate if ((e0.x0 == e1.x0 && e0.y0 == e1.y0) ? @@ -43,8 +43,8 @@ static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine sca double d0 = e0.dx > 0; // use y + 1 to compute x0 double d1 = e1.dx < 0; // use y + 1 to compute x1 for (int32_t y = y0; y < y1; y++) { - double x0 = m0 * std::fmax(0, std::fmin(e0.dy, y + d0 - e0.y0)) + e0.x0; - double x1 = m1 * std::fmax(0, std::fmin(e1.dy, y + d1 - e1.y0)) + e1.x0; + double x0 = m0 * ::fmax(0, ::fmin(e0.dy, y + d0 - e0.y0)) + e0.x0; + double x1 = m1 * ::fmax(0, ::fmin(e1.dy, y + d1 - e1.y0)) + e1.x0; scanLine(std::floor(x1), std::ceil(x0), y); } } diff --git a/src/mbgl/util/time.cpp b/src/mbgl/util/time.cpp index 94936acff..4612ae29b 100644 --- a/src/mbgl/util/time.cpp +++ b/src/mbgl/util/time.cpp @@ -1,6 +1,8 @@ #include #include +#include + namespace mbgl { namespace util { diff --git a/test/test.gypi b/test/test.gypi index 142445d98..4e669aee1 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -94,19 +94,19 @@ 'style/sprite.cpp', ], 'libraries': [ - '<@(uv_static_libs)', - '<@(sqlite3_static_libs)', + '<@(libuv_static_libs)', + '<@(sqlite_static_libs)', ], 'variables': { 'cflags_cc': [ - '<@(uv_cflags)', + '<@(libuv_cflags)', '<@(opengl_cflags)', '<@(boost_cflags)', - '<@(sqlite3_cflags)', + '<@(sqlite_cflags)', ], 'ldflags': [ - '<@(uv_ldflags)', - '<@(sqlite3_ldflags)', + '<@(libuv_ldflags)', + '<@(sqlite_ldflags)', ], }, 'conditions': [