This commit is contained in:
Peter Liu
2015-05-05 15:50:24 -07:00
257 changed files with 13100 additions and 3998 deletions

5
.gitignore vendored
View File

@@ -16,8 +16,13 @@
/test/build
/test/node_modules
/test/fixtures/*/*_actual.*
/test/fixtures/database/*.db
/include/mbgl/shader/shaders.hpp
/src/shader/shaders_gl.cpp
/src/shader/shaders_gles2.cpp
/bin/style.bin.js
*~
/ios/benchmark/assets/tiles/mapbox.mapbox-streets-v6/
/ios/benchmark/assets/tiles/mapbox.mapbox-terrain-v2/
/ios/benchmark/assets/glyphs/DIN Offc Pro*/

2
.mason

Submodule .mason updated: 03869fd11e...c43967404c

View File

@@ -1,100 +1,99 @@
language: cpp
language: android
sudo: false
matrix:
exclude:
- os: linux
include:
- os: linux
env: CONFIG=release MASON_PLATFORM=android MASON_ANDROID_ABI=arm-v7 TESTMUNK=yes
compiler: clang
env: FLAVOR=linux CXX=g++-4.9 BUILDTYPE=Release
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
env: CONFIG=debug MASON_PLATFORM=android MASON_ANDROID_ABI=arm-v7 TESTMUNK=no
compiler: clang
env: FLAVOR=linux CXX=clang++-3.5 BUILDTYPE=Debug
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
packages: [ 'gdb', 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
env: CONFIG=release MASON_PLATFORM=android MASON_ANDROID_ABI=arm-v5 TESTMUNK=no
compiler: clang
- os: linux
env: CONFIG=release MASON_PLATFORM=android MASON_ANDROID_ABI=arm-v8 TESTMUNK=no
compiler: clang
- os: linux
env: CONFIG=release MASON_PLATFORM=android MASON_ANDROID_ABI=x86 TESTMUNK=no
compiler: clang
- os: linux
env: CONFIG=release MASON_PLATFORM=android MASON_ANDROID_ABI=mips TESTMUNK=no
compiler: clang
- os: linux
env: CONFIG=release MASON_PLATFORM=android MASON_ANDROID_ABI=mips-64 TESTMUNK=no
compiler: clang
- os: linux
env: BUILDTYPE=Release JOBS=16
compiler: clang
- os: linux
env: BUILDTYPE=Debug JOBS=16
compiler: clang
- os: linux
env: BUILDTYPE=Release JOBS=8
compiler: gcc
env: FLAVOR=linux CXX=clang++-3.5 BUILDTYPE=Release
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
packages: [ 'gdb', 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: osx
env: BUILDTYPE=Debug JOBS=8 MASON_PLATFORM=osx
compiler: clang
env: FLAVOR=osx BUILDTYPE=Debug
- os: osx
env: BUILDTYPE=Release JOBS=8 MASON_PLATFORM=ios
compiler: clang
env: FLAVOR=ios BUILDTYPE=Release
- os: linux
env: FLAVOR=android ANDROID_ABI=arm-v7 BUILDTYPE=Release
android:
components: [ 'build-tools-22.0.0', 'android-22', 'extra' ]
addons:
apt:
packages: [ 'lib32stdc++6' ]
- os: linux
env: FLAVOR=android ANDROID_ABI=arm-v7 BUILDTYPE=Debug
android:
components: [ 'build-tools-22.0.0', 'android-22', 'extra' ]
addons:
apt:
packages: [ 'lib32stdc++6' ]
- os: linux
env: FLAVOR=android ANDROID_ABI=arm-v8 BUILDTYPE=Release
android:
components: [ 'build-tools-22.0.0', 'android-22', 'extra' ]
addons:
apt:
packages: [ 'lib32stdc++6' ]
- os: linux
env: FLAVOR=android ANDROID_ABI=x86 BUILDTYPE=Release
android:
components: [ 'build-tools-22.0.0', 'android-22', 'extra' ]
addons:
apt:
packages: [ 'lib32stdc++6' ]
- os: linux
env: FLAVOR=android ANDROID_ABI=mips BUILDTYPE=Release
android:
components: [ 'build-tools-22.0.0', 'android-22', 'extra' ]
addons:
apt:
packages: [ 'lib32stdc++6' ]
env:
global:
- secure: "MZHblLZXG/jWf2w0ZFlxCLDwx2qtGgRDODQyg1BR7JIuMz6AtWv8XR/sUczWLbiABCL0a/NzJF1g4v2pI7X69IntcjOdIABBgTh7++6+1TJ0Kp8viEltb55nQG3lHy/R6fOaI7Pj9tuCX0PCRtGA5C/fGnodLGEjy3RVOJ09ln0="
- secure: "KaSQbhgjtV7ZCkesHmvrNsbQVjk5SPfGKB1VkWenRGYhLF45HpSRNwSxMQddZ566Pg7qIFgF1iWl/B0QW3B6AWL5WmzQ5AOJgwS876pNIc/UT7ubMPtgAtjpvw1bQvQP3B8MrB+3OE5c6tD+a3LhR9krV//dOsfErR5Yy+3Mbkc="
- ANDROID_BUILD_INSTANCE_PROFILE: arn:aws:iam::234858372212:instance-profile/android-gl-build/travis/instance-profile/travis-mapbox-gl-native-AndroidInstanceProfile-13EA815DD8IQ9
- secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I="
- secure: "CHBiUM60TolDbQnn+4IRA/tvOKwKs3g9EDvv8YHSJMg3FuHmjKQkprBasvxf3hnTXg4WLZEubmeDcyJ6RRzPP5mMSr/hksYl0pSjj/6TUecE5fHPVVeN7txVqkpOBf9i45Y+iBUQMjBb1NnDK3pHXxpnAs1Q/pe7vReErj4GF1U="
- LD_LIBRARY_PATH: '/usr/local/lib'
- TERM: dumb
# begin iOS code signing
- secure: "I6Iu75X1E+js5tzijtKi1EGtIuBcA4/25nDYe0svV4HAtujY71ZJZ4eB6355CKhFXpLXrF3i7eKVX3v+zWS0QROPEWacgsqsvNg+Ba9cnznW/faUSOYekCfhzWd/6reYDM7KzKAQwSUHLk9JIWK/kkmi4r+vVJK7h+tjPllK5YA="
- IOS_APP_NAME="Mapbox GL"
- 'IOS_DEVELOPER_NAME="iPhone Distribution: Mapbox, Inc."'
- IOS_PROFILE_NAME="ios-in-house"
- secure: "nQqSM8rd7OHtV4MqmNqVnkrVHqxKqQsaWRYk4/nPdhbeVWtTtkk0df711LrF1TUtbEPEewHxYUvTZ/UXmwJNeoKdzTHavI8hnatRkgjyxGERPn1il1Otelht9I+LQQHf+plrpRjVWBrNIW0Zox1B3cqn6d3NglpbXrEQ2EjYGNA="
# end iOS code signing
- KIF_SCREENSHOTS="${TRAVIS_BUILD_DIR}/screenshots"
before_install:
- if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then sudo service mysql stop; fi
- if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then sudo service postgresql stop; fi
- source ./scripts/local_mason.sh
- source ./scripts/travis_helper.sh
- source ./scripts/install_node.sh
- source ./scripts/flags.sh
- ./scripts/travis_before_install.sh
- if [[ ${TRAVIS_OS_NAME} == "linux" && ${MASON_PLATFORM} != "android" ]]; then export LD_LIBRARY_PATH=`mason prefix mesa 10.4.3`/lib; fi
- if [[ ${TRAVIS_OS_NAME} == "linux" && ${MASON_PLATFORM} != "android" ]]; then glxinfo; fi
- if [[ ${TRAVIS_OS_NAME} == "osx" && ${TEST_OS} == "ios" ]]; then mkdir -p ${KIF_SCREENSHOTS}; fi
- TERM: dumb
# AWS
- secure: "MZHblLZXG/jWf2w0ZFlxCLDwx2qtGgRDODQyg1BR7JIuMz6AtWv8XR/sUczWLbiABCL0a/NzJF1g4v2pI7X69IntcjOdIABBgTh7++6+1TJ0Kp8viEltb55nQG3lHy/R6fOaI7Pj9tuCX0PCRtGA5C/fGnodLGEjy3RVOJ09ln0="
- secure: "KaSQbhgjtV7ZCkesHmvrNsbQVjk5SPfGKB1VkWenRGYhLF45HpSRNwSxMQddZ566Pg7qIFgF1iWl/B0QW3B6AWL5WmzQ5AOJgwS876pNIc/UT7ubMPtgAtjpvw1bQvQP3B8MrB+3OE5c6tD+a3LhR9krV//dOsfErR5Yy+3Mbkc="
# Access Token
- secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I="
# Testmunk
- secure: "CHBiUM60TolDbQnn+4IRA/tvOKwKs3g9EDvv8YHSJMg3FuHmjKQkprBasvxf3hnTXg4WLZEubmeDcyJ6RRzPP5mMSr/hksYl0pSjj/6TUecE5fHPVVeN7txVqkpOBf9i45Y+iBUQMjBb1NnDK3pHXxpnAs1Q/pe7vReErj4GF1U="
# iOS code signing
- secure: "I6Iu75X1E+js5tzijtKi1EGtIuBcA4/25nDYe0svV4HAtujY71ZJZ4eB6355CKhFXpLXrF3i7eKVX3v+zWS0QROPEWacgsqsvNg+Ba9cnznW/faUSOYekCfhzWd/6reYDM7KzKAQwSUHLk9JIWK/kkmi4r+vVJK7h+tjPllK5YA="
- IOS_APP_NAME="Mapbox GL"
- 'IOS_DEVELOPER_NAME="iPhone Distribution: Mapbox, Inc."'
- IOS_PROFILE_NAME="ios-in-house"
- secure: "nQqSM8rd7OHtV4MqmNqVnkrVHqxKqQsaWRYk4/nPdhbeVWtTtkk0df711LrF1TUtbEPEewHxYUvTZ/UXmwJNeoKdzTHavI8hnatRkgjyxGERPn1il1Otelht9I+LQQHf+plrpRjVWBrNIW0Zox1B3cqn6d3NglpbXrEQ2EjYGNA="
- KIF_SCREENSHOTS="${TRAVIS_BUILD_DIR}/screenshots"
install:
- ulimit -c
before_script:
# Set the core file limit to unlimited so a core file is generated upon crash
- ulimit -c unlimited -S
# begin iOS code signing
- openssl aes-256-cbc -k "$IOS_ENCRYPTION_SECRET" -in scripts/ios_travis/ios-in-house.mobileprovision.enc -d -a -out scripts/ios_travis/ios-in-house.mobileprovision
- openssl aes-256-cbc -k "$IOS_ENCRYPTION_SECRET" -in scripts/ios_travis/ios-dist.cer.enc -d -a -out scripts/ios_travis/ios-dist.cer
- openssl aes-256-cbc -k "$IOS_ENCRYPTION_SECRET" -in scripts/ios_travis/ios-dist.p12.enc -d -a -out scripts/ios_travis/ios-dist.p12
- ./scripts/ios_travis/add-key.sh
# end iOS code signing
- ./scripts/${FLAVOR}/install.sh
script:
- ./scripts/travis_script.sh
after_script:
- ./scripts/ios_travis/remove-key.sh
- ./scripts/${FLAVOR}/run.sh
after_failure:
- if [[ ${TRAVIS_OS_NAME} == "osx" && ${TEST_OS} == "ios" ]]; then ./scripts/ios_travis/upload_screenshots.sh; fi
- "[ -f scripts/${FLAVOR}/run.sh ] && scripts/${FLAVOR}/run.sh"
notifications:
slack:
secure: HHQYr7sF8M1SzoWSqgKVYtwAgGdLLCyTMsQjFhEEQNYO92ZwURE5s03qWTGH5k8+4Yqn26yrXt3NztLC4JIOpcGervN2mSZyq4dZgFTcWEd61igw0qwSenlwvFfbE1ASK/KYCzfyn9MIfHN+ovwLoRxXZkPwinKDvl3DXjBaFNg=
git:
submodules: false

View File

@@ -11,7 +11,7 @@ endif
ifeq ($(shell uname -s), Linux)
HOST = linux
JOBS ?= $(shell sysctl -n hw.ncpu)
JOBS ?= $(shell grep --count processor /proc/cpuinfo)
endif
JOBS ?= 1
@@ -31,8 +31,12 @@ config/%.gypi: configure
styles/styles:
git submodule update --init styles
ifeq ($(shell uname -s), Darwin)
SMCalloutView:
git submodule update --init platform/ios/vendor/SMCalloutView
else
SMCalloutView:
endif
KIF:
git submodule update --init test/ios/KIF
@@ -42,11 +46,11 @@ KIF:
.PRECIOUS: Makefile/project
Makefile/project: config/$(HOST).gypi styles/styles SMCalloutView
deps/run_gyp gyp/project.gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f make
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
deps/run_gyp gyp/project.gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f xcode
deps/run_gyp gyp/$(HOST).gyp $(CONFIG_$(HOST)) $(LIBS_$(HOST)) --generator-output=./build/$(HOST) -f xcode
#### Library builds ############################################################
@@ -71,8 +75,9 @@ 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/project.xcodeproj -configuration $(BUILDTYPE) -target test -jobs $(JOBS)
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=$*
@@ -89,10 +94,11 @@ run-osx: osx
.PHONY: xosx-proj xosx run-xosx
xosx-proj: Xcode/project
open ./build/osx/gyp/project.xcodeproj
open ./build/osx/gyp/osx.xcodeproj
xosx: XCPRETTY := $(shell ./scripts/xcpretty.sh)
xosx: Xcode/project
xcodebuild -project ./build/osx/gyp/project.xcodeproj -configuration $(BUILDTYPE) -target osxapp -jobs $(JOBS)
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"
@@ -105,24 +111,33 @@ xproj: xosx-proj
#### iOS application builds ####################################################
.PRECIOUS: Xcode/ios
Xcode/ios: ios/app/mapboxgl-app.gyp config/ios.gypi styles/styles SMCalloutView
deps/run_gyp ios/app/mapboxgl-app.gyp $(CONFIG_ios) $(LIBS_ios) --generator-output=./build/ios -f xcode
Xcode/ios: gyp/ios.gyp config/ios.gypi styles/styles SMCalloutView
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/ios/app/mapboxgl-app.xcodeproj
open ./build/ios/gyp/ios.xcodeproj
ios: XCPRETTY := $(shell ./scripts/xcpretty.sh)
ios: Xcode/ios
xcodebuild -sdk iphoneos ARCHS="arm64 armv7 armv7s" PROVISIONING_PROFILE="2b532944-bf3d-4bf4-aa6c-a81676984ae8" -project ./build/ios/ios/app/mapboxgl-app.xcodeproj -configuration Release -target iosapp -jobs $(JOBS)
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/ios/app/mapboxgl-app.xcodeproj -configuration Debug -target iosapp -jobs $(JOBS)
xcodebuild -sdk iphonesimulator ARCHS="x86_64 i386" -project ./build/ios/gyp/ios.xcodeproj -configuration Debug -target iosapp -jobs $(JOBS) $(XCPRETTY)
ipackage: clean Xcode/ios
./scripts/package_ios.sh
./scripts/ios/package.sh
itest: ipackage KIF
./scripts/test_ios.sh
ipackage-sim: clean Xcode/ios
./scripts/ios/package.sh sim
itest: ipackage-sim KIF
./scripts/ios/test.sh
# Legacy name
iproj: ios-proj
@@ -138,8 +153,9 @@ run-linux: linux
(cd build/$(HOST)/$(BUILDTYPE) && ./mapbox-gl)
.PHONY: xlinux run-xlinux
xlinux: XCPRETTY := $(shell ./scripts/xcpretty.sh)
xlinux: Xcode/project
xcodebuild -project ./build/osx/gyp/project.xcodeproj -configuration $(BUILDTYPE) -target linuxapp -jobs $(JOBS)
xcodebuild -project ./build/osx/gyp/osx.xcodeproj -configuration $(BUILDTYPE) -target linuxapp -jobs $(JOBS) $(XCPRETTY)
run-xlinux: xlinux
"gyp/build/$(BUILDTYPE)/mapbox-gl"
@@ -182,7 +198,7 @@ render: Makefile/project
.PHONY: xrender run-xrender
xrender: Xcode/project
xcodebuild -project ./build/osx/gyp/project.xcodeproj -configuration $(BUILDTYPE) -target mbgl-render -jobs $(JOBS)
xcodebuild -project ./build/osx/gyp/osx.xcodeproj -configuration $(BUILDTYPE) -target mbgl-render -jobs $(JOBS)
##### Maintenace operations ####################################################

View File

@@ -1,11 +1,10 @@
[![Travis](https://api.travis-ci.org/mapbox/mapbox-gl-native.svg?branch=master)](https://travis-ci.org/mapbox/mapbox-gl-native/builds)
An OpenGL renderer for [Mapbox Vector Tiles](https://www.mapbox.com/blog/vector-tiles),
implemented in C++11, currently targeting iOS, OS X, Android, and Ubuntu Linux.
An OpenGL renderer for [Mapbox Vector Tiles](https://www.mapbox.com/blog/vector-tiles), consisting of a C++ library for OS X and Linux and SDK bindings for iOS and Android.
# Depends
- Modern C++ compiler that supports `-std=c++11` (On OS X clang++, on Linux g++-4.8 or g++-4.9)
- Modern C++ compiler that supports `-std=c++14` (clang++ 3.5 or later or g++-4.9 or later)
- [Boost headers](http://boost.org/)
- [`zlib`](http://www.zlib.net/)
- [`libpng`](http://www.libpng.org/pub/png/libpng.html)
@@ -48,8 +47,8 @@ Target OS X: 10.9+
If you merely want to install the library for iOS and try it out as an Objective-C consumer:
0. Use [Homebrew](http://brew.sh/) to install Boost headers: `brew install boost`.
1. Run `./scripts/package_ios.sh`. The packaging script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, and a `Headers` folder.
0. Use [Homebrew](http://brew.sh/) to install Boost headers and [appledoc](http://gentlebytes.com/appledoc/): `brew install boost appledoc`.
1. Run `make ipackage`. The packaging script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, a `Headers` folder, and a `Docs` folder with HTML API documentation.
2. Copy the contents of `build/ios/pkg/static` into your project. It should happen automatically, but ensure that:
- `Headers` is in your *Header Search Paths* (`HEADER_SEARCH_PATHS`) build setting.
- `MapboxGL.bundle` is in your target's *Copy Bundle Resources* build phase.
@@ -68,24 +67,25 @@ If you merely want to install the library for iOS and try it out as an Objective
5. [Set the Mapbox API access token](#mapbox-api-access-tokens).
6. `#import "MapboxGL.h"`
If you want to build from source and/or contribute to development of the project, run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app.
If you want to build from source and/or contribute to development of the project, run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app. If you don't have an Apple Developer account, change the destination from "My Mac" to a simulator such as "iPhone 6" before you run and build the app.
You can also run `make itest` to run the included tests. Requires `brew install xcpretty`.
You can run `make itest` to run the included integration tests. Requires `gem install xcpretty`. If you want to run the tests in Xcode instead, first `make ipackage` to create a local static library version, then open `test/ios/ios-tests.xcodeproj`, and lastly `Command + U` on the `Mapbox GL Tests` application target.
Target devices: iPhone 4S and above (5, 5c, 5s, 6, 6 Plus) and iPad 2 and above (3, 4, Mini, Air, Mini 2, Air 2).
Target iOS: 7.0 through 8.1
Target iOS: 7.0 through latest 8.x.
## Linux
We are using Ubuntu for development. While the software should work on other distributions as well, we are not providing explicit build instructions here.
Install GCC 4.8+ if you are running Ubuntu 13.10 or older. Alternatively, you can also use Clang 3.4+.
Install GCC 4.9+ if you are running Ubuntu 13.10 or older. Alternatively, you can also use Clang 3.5+.
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.8 g++-4.8
sudo apt-get install gcc-4.9 g++-4.9
export CXX=g++-4.9
Ensure you have git and other build essentials:
@@ -110,10 +110,6 @@ Otherwise, you can just install
sudo apt-get install libboost-dev libboost-program-options-dev
Once you're done installing the build dependencies, you can get started by running
./configure
Then, you can then proceed to build the library:
git submodule update --init

View File

@@ -1,5 +1,6 @@
#include <cstdint>
#include <cinttypes>
#include <cassert>
#include <string>
#include <locale>
@@ -255,20 +256,6 @@ void JNICALL nativeDestroySurface(JNIEnv *env, jobject obj, jlong nativeMapViewP
nativeMapView->destroySurface();
}
void JNICALL nativeStart(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStart");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->start();
}
void JNICALL nativeStop(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeStop");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->stop();
}
void JNICALL nativePause(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativePause");
assert(nativeMapViewPtr != 0);
@@ -287,14 +274,7 @@ void JNICALL nativeUpdate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().triggerUpdate();
}
void JNICALL nativeTerminate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeTerminate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().terminate();
nativeMapView->getMap().update();
}
void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height,
@@ -310,7 +290,7 @@ void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint
assert(fbWidth <= UINT16_MAX);
assert(fbHeight <= UINT16_MAX);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->resize(width, height, ratio, fbWidth, fbHeight);
nativeMapView->getMap().resize(width, height, ratio);
}
void JNICALL nativeRemoveClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring clazz) {
@@ -938,12 +918,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativeCreateSurface", "(JLandroid/view/Surface;)V",
reinterpret_cast<void *>(&nativeCreateSurface)},
{"nativeDestroySurface", "(J)V", reinterpret_cast<void *>(&nativeDestroySurface)},
{"nativeStart", "(J)V", reinterpret_cast<void *>(&nativeStart)},
{"nativeStop", "(J)V", reinterpret_cast<void *>(&nativeStop)},
{"nativePause", "(J)V", reinterpret_cast<void *>(&nativePause)},
{"nativeResume", "(J)V", reinterpret_cast<void *>(&nativeResume)},
{"nativeUpdate", "(J)V", reinterpret_cast<void *>(&nativeUpdate)},
{"nativeTerminate", "(J)V", reinterpret_cast<void *>(&nativeTerminate)},
{"nativeResize", "(JIIFII)V",
reinterpret_cast<void *>(static_cast<void JNICALL (
*)(JNIEnv *, jobject, jlong, jint, jint, jfloat, jint, jint)>(&nativeResize))},

View File

@@ -1,5 +1,6 @@
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <memory>
#include <list>
#include <tuple>
@@ -16,6 +17,7 @@
#include <mbgl/platform/gl.hpp>
#include <mbgl/util/std.hpp>
#include <pthread.h>
pthread_once_t loadGLExtensions = PTHREAD_ONCE_INIT;
@@ -59,7 +61,7 @@ NativeMapView::NativeMapView(JNIEnv *env, jobject obj_)
: mbgl::View(*this),
fileCache(mbgl::android::cachePath + "/mbgl-cache.db"),
fileSource(&fileCache),
map(*this, fileSource) {
map(*this, fileSource, MapMode::Continuous, true) {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::NativeMapView");
assert(env != nullptr);
@@ -121,11 +123,11 @@ void NativeMapView::deactivate() {
}
}
void NativeMapView::invalidate() {
void NativeMapView::invalidate(std::function<void()> render) {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::invalidate");
if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE)) {
map.render();
render();
if (!eglSwapBuffers(display, surface)) {
mbgl::Log::Error(mbgl::Event::OpenGL, "eglSwapBuffers() returned error %d",
@@ -358,7 +360,7 @@ void NativeMapView::createSurface(ANativeWindow *window_) {
void NativeMapView::destroySurface() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::destroySurface");
pause(true);
pause();
if (surface != EGL_NO_SURFACE) {
if (!eglDestroySurface(display, surface)) {
@@ -576,23 +578,6 @@ EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfi
return configId;
}
void NativeMapView::start() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::start");
if (display == EGL_NO_DISPLAY) {
initializeDisplay();
}
if (context == EGL_NO_CONTEXT) {
initializeContext();
}
assert(display != EGL_NO_DISPLAY);
assert(context != EGL_NO_CONTEXT);
map.start(true);
}
void loadExtensions() {
const GLubyte *str = glGetString(GL_EXTENSIONS);
if (str == nullptr) {
@@ -689,20 +674,11 @@ void loadExtensions() {
}
}
void NativeMapView::stop() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::stop");
void NativeMapView::pause() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::pause");
if ((display != EGL_NO_DISPLAY) && (context != EGL_NO_CONTEXT)) {
map.stop();
}
}
void NativeMapView::pause(bool waitForPause) {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::pause %s",
(waitForPause) ? "true" : "false");
if ((display != EGL_NO_DISPLAY) && (context != EGL_NO_CONTEXT)) {
map.pause(waitForPause);
map.pause();
}
}
@@ -824,9 +800,5 @@ void NativeMapView::updateFps() {
env = nullptr;
}
void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) {
View::resize(width, height, ratio, fbWidth, fbHeight);
}
}
}

View File

@@ -419,7 +419,6 @@ public class MapView extends SurfaceView {
mNativeMapView.initializeDisplay();
mNativeMapView.initializeContext();
mNativeMapView.start();
}
// Called when we need to save instance state
@@ -441,7 +440,6 @@ public class MapView extends SurfaceView {
// Called when we need to clean up
// Must be called from Activity onDestroy
public void onDestroy() {
mNativeMapView.stop();
mNativeMapView.terminateContext();
mNativeMapView.terminateDisplay();
}

View File

@@ -73,14 +73,6 @@ class NativeMapView {
nativeDestroySurface(mNativeMapViewPtr);
}
public void start() {
nativeStart(mNativeMapViewPtr);
}
public void stop() {
nativeStop(mNativeMapViewPtr);
}
public void pause() {
nativePause(mNativeMapViewPtr);
}
@@ -386,18 +378,12 @@ class NativeMapView {
private native void nativeDestroySurface(long nativeMapViewPtr);
private native void nativeStart(long nativeMapViewPtr);
private native void nativeStop(long nativeMapViewPtr);
private native void nativePause(long nativeMapViewPtr);
private native void nativeResume(long nativeMapViewPtr);
private native void nativeUpdate(long nativeMapViewPtr);
private native void nativeTerminate(long nativeMapViewPtr);
private native void nativeResize(long nativeMapViewPtr, int width,
int height, float ratio, int fbWidth, int fbHeight);

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
export BUILDTYPE=Debug
./android/scripts/common.sh $1

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
export BUILDTYPE=Release
./android/scripts/common.sh $1

View File

@@ -1,40 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
NAME=$1
case `uname -s` in
'Darwin') export JOBS=`sysctl -n hw.ncpu` ;;
'Linux') export JOBS=`nproc` ;;
*) export JOBS=1 ;;
esac
export CC=clang CXX=clang++
export MASON_PLATFORM=android
mkdir -p ./android/java/MapboxGLAndroidSDKTestApp/src/main/res/raw/
echo "${MAPBOX_ACCESS_TOKEN}" >> ./android/java/MapboxGLAndroidSDKTestApp/src/main/res/raw/token.txt
make android -j$JOBS BUILDTYPE=$BUILDTYPE JOBS=$JOBS
S3_PREFIX=s3://mapbox/mapbox-gl-native/android/build/${NAME}
APK_OUTPUTS=./android/java/MapboxGLAndroidSDKTestApp/build/outputs/apk
# Upload the shared object.
aws s3 cp \
./build/android-${ANDROID_ABI}/${BUILDTYPE}/lib.target/libmapbox-gl.so \
${S3_PREFIX}/libmapbox-gl.so
# Upload either the debug or the release build
if [ ${BUILDTYPE} == "Debug" ] ; then
aws s3 cp \
${APK_OUTPUTS}/MapboxGLAndroidSDKTestApp-debug.apk \
${S3_PREFIX}/MapboxGLAndroidSDKTestApp-debug.apk
elif [ ${BUILDTYPE} == "Release" ] ; then
aws s3 cp \
${APK_OUTPUTS}/MapboxGLAndroidSDKTestApp-release-unsigned.apk \
${S3_PREFIX}/MapboxGLAndroidSDKTestApp-release-unsigned.apk
fi

View File

@@ -1,85 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
cwd=$(pwd)
region="us-east-1"
region_ami="ami-022e0c6a"
sleep=10
instance_name="android-gl-build-$TRAVIS_REPO_SLUG-$TRAVIS_JOB_NUMBER"
echo $ami_name
NAME=$TRAVIS_JOB_ID
user_data="#!/bin/bash
cd /android
git clone git://github.com/mapbox/mapbox-gl-native.git
pushd mapbox-gl-native
if [[ $TRAVIS_PULL_REQUEST == 'false' ]]; then
git checkout $TRAVIS_COMMIT
else
git fetch origin +refs/pull/$TRAVIS_PULL_REQUEST/merge:
git checkout FETCH_HEAD
fi
git submodule update --init --recursive
export ANDROID_NDK_PATH=/android/android-ndk-r10d
export JAVA_HOME=/android/jdk1.7.0_71
export ANDROID_HOME=/android/android-sdk-linux
export PATH=\$PATH:/android/jdk1.7.0_71/bin
export MAPBOX_ACCESS_TOKEN=$MAPBOX_ACCESS_TOKEN
export TESTMUNK_KEY=$TESTMUNK_KEY
export TESTMUNK=$TESTMUNK
export MASON_ANDROID_ABI=$MASON_ANDROID_ABI
export ANDROID_ABI=$MASON_ANDROID_ABI
if ./android/scripts/build-$CONFIG.sh $NAME &>../build.log; then
echo 'ANDROID BUILD PASSED'
else
echo 'ANDROID BUILD FAILED'
fi
popd
aws s3 cp --region us-east-1 build.log s3://mapbox/mapbox-gl-native/android/build/${NAME}/build-log.txt
shutdown -P now"
id=$(aws ec2 run-instances \
--region $region \
--image-id $region_ami \
--count 1 \
--instance-type m3.large \
--iam-instance-profile Arn="$ANDROID_BUILD_INSTANCE_PROFILE" \
--instance-initiated-shutdown-behavior terminate \
--user-data "$user_data" | jq -r '.Instances[0].InstanceId')
echo "Instance: $region $id"
sleep 10
result=$(aws ec2 create-tags --region $region --resources $id --tags "Key=Name,Value=$instance_name")
instance_status_terminated=$(aws ec2 describe-instances --region $region --instance-id $id | jq -r '.Reservations[0].Instances[0].State.Name')
until [ "$instance_status_terminated" = "terminated" ]; do
instance_status_terminated=$(aws ec2 describe-instances --region $region --instance-id $id | jq -r '.Reservations[0].Instances[0].State.Name')
echo "Instance terminating status $region $id: $instance_status_terminated"
sleep $sleep
done
echo "Build finished"
output=$(aws ec2 get-console-output --region $region --instance-id $id | jq -r '.Output')
aws s3 cp --region $region s3://mapbox/mapbox-gl-native/android/build/${NAME}/build-log.txt build.log
cat build.log
if [[ $output == *"ANDROID BUILD PASSED"* ]]; then
echo "ANDROID BUILD PASSED"
exit 0
else
echo "ANDROID BUILD FAILED"
exit 1
fi

View File

@@ -31,32 +31,32 @@ 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_env.sh)
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_env.sh)
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_env.sh)
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_env.sh)
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_env.sh)
# 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_env.sh)
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_env.sh)
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

5
configure vendored
View File

@@ -15,7 +15,8 @@ function finish {
trap finish EXIT
# Install mason
. ./scripts/local_mason.sh
git submodule update --init .mason
export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason"
case ${MASON_PLATFORM} in
'ios')
@@ -44,7 +45,7 @@ case ${MASON_PLATFORM} in
LIBCURL_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
BOOST_VERSION=1.57.0
NUNICODE_VERSION=1.5.1
LIBZIP_VERSION=0.11.2
;;

View File

@@ -1,26 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
export TRAVIS_OS_NAME=linux
cd build
source ./scripts/local_mason.sh
mason install mesa 10.4.3
export LD_LIBRARY_PATH=`mason prefix mesa 10.4.3`/lib
export DISPLAY=:99.0
Xvfb :99 -ac -screen 0 1024x768x24 &
if [[ ${CXX} == "g++" ]]; then
export CXX="g++-4.8"
export CC="gcc-4.8"
fi
source ./scripts/install_node.sh
make linux -j`nproc`
make test-* -j`nproc`
./scripts/compare_images.sh

View File

@@ -8,7 +8,7 @@
['OS=="mac"', {
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++14',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES',
@@ -27,14 +27,14 @@
},
}, {
'cflags_cc': [
'-std=c++11',
'-std=c++14',
'-Werror',
'-Wall',
'-Wextra',
'-Wshadow',
'-Wno-variadic-macros',
'-Wno-error=unused-parameter',
'-Wno-unknown-warning-option',
'-Wno-c++1y-extensions',
'-frtti',
'-fexceptions',
],

6
gyp/ios.gyp Normal file
View File

@@ -0,0 +1,6 @@
{
'includes': [
'../ios/app/mapboxgl-app.gypi',
'../ios/benchmark/benchmark-ios.gypi',
],
}

7
gyp/linux.gyp Normal file
View File

@@ -0,0 +1,7 @@
{
'includes': [
'../linux/mapboxgl-app.gypi',
'../test/test.gypi',
'../bin/render.gypi',
],
}

8
gyp/osx.gyp Normal file
View File

@@ -0,0 +1,8 @@
{
'includes': [
'../macosx/mapboxgl-app.gypi',
'../linux/mapboxgl-app.gypi',
'../test/test.gypi',
'../bin/render.gypi',
],
}

View File

@@ -12,6 +12,7 @@
'sources': [
'../platform/android/log_android.cpp',
'../platform/android/asset_root.cpp',
'../platform/default/thread.cpp',
'../platform/default/string_stdlib.cpp',
'../platform/default/image.cpp',
'../platform/default/image_reader.cpp',

View File

@@ -15,6 +15,7 @@
'../platform/darwin/application_root.mm',
'../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
'../platform/darwin/nsthread.mm',
'../platform/darwin/reachability.m',
'../include/mbgl/ios/MapboxGL.h',
'../include/mbgl/ios/MGLMapboxEvents.h',
@@ -22,6 +23,10 @@
'../include/mbgl/ios/MGLMapView.h',
'../include/mbgl/ios/MGLMapView+IBAdditions.h',
'../platform/ios/MGLMapView.mm',
'../platform/ios/MGLFileCache.h',
'../platform/ios/MGLFileCache.mm',
'../include/mbgl/ios/MGLAccountManager.h',
'../platform/ios/MGLAccountManager.m',
'../include/mbgl/ios/MGLAnnotation.h',
'../include/mbgl/ios/MGLUserLocation.h',
'../platform/ios/MGLUserLocation_Private.h',
@@ -31,6 +36,9 @@
'../include/mbgl/ios/MGLMetricsLocationManager.h',
'../platform/ios/MGLMetricsLocationManager.m',
'../include/mbgl/ios/MGLTypes.h',
'../platform/ios/NSBundle+MGLAdditions.h',
'../platform/ios/NSBundle+MGLAdditions.m',
'../platform/ios/NSException+MGLAdditions.h',
'../platform/ios/NSProcessInfo+MGLAdditions.h',
'../platform/ios/NSProcessInfo+MGLAdditions.m',
'../platform/ios/NSString+MGLAdditions.h',

View File

@@ -14,6 +14,7 @@
'../platform/default/string_stdlib.cpp',
'../platform/default/application_root.cpp',
'../platform/default/asset_root.cpp',
'../platform/default/thread.cpp',
'../platform/default/image.cpp',
'../platform/default/image_reader.cpp',
'../platform/default/png_reader.cpp',

View File

@@ -15,6 +15,7 @@
'../platform/darwin/application_root.mm',
'../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
'../platform/darwin/nsthread.mm',
],
'variables': {

View File

@@ -1,19 +0,0 @@
{
'conditions': [
['host == "osx"', {
'includes': [
'../macosx/mapboxgl-app.gypi',
'../linux/mapboxgl-app.gypi',
'../test/test.gypi',
'../bin/render.gypi',
]
}],
['host == "linux"', {
'includes': [
'../linux/mapboxgl-app.gypi',
'../test/test.gypi',
'../bin/render.gypi',
]
}],
],
}

View File

@@ -23,7 +23,7 @@ public:
void activate() override;
void deactivate() override;
void notify() override;
void invalidate() override;
void invalidate(std::function<void()> render) override;
void notifyMapChange(mbgl::MapChange change, Duration delay = Duration::zero()) override;
@@ -39,17 +39,12 @@ public:
void createSurface(ANativeWindow *window);
void destroySurface();
void start();
void stop();
void resume();
void pause(bool waitForPause = false);
void pause();
void enableFps(bool enable);
void updateFps();
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
private:
EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs);

View File

@@ -0,0 +1,6 @@
@interface MGLAccountManager : NSObject
+ (void) setAccessToken:(NSString *) accessToken;
+ (NSString *) accessToken;
@end

View File

@@ -20,6 +20,11 @@ IB_DESIGNABLE
/** @name Initializing a Map View */
/** Initialize a map view with the default style, given frame, and access token set in MapboxGL singleton.
* @param frame The frame with which to initialize the map view.
* @return An initialized map view, or `nil` if the map view was unable to be initialized. */
- (instancetype)initWithFrame:(CGRect)frame;
/** Initialize a map view with the default style and a given frame and access token.
* @param frame The frame with which to initialize the map view.
* @param accessToken A Mapbox API access token.
@@ -33,8 +38,6 @@ IB_DESIGNABLE
* @return An initialized map view, or `nil` if the map view was unable to be initialized. */
- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleURL:(NSURL *)styleURL;
- (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("Instantiating an MGLMapView requires setting a style and/or an access token.")));
#pragma mark - Authorizing Access
/** @name Authorizing Access */
@@ -46,11 +49,6 @@ IB_DESIGNABLE
/** @name Managing Constraints */
/** A view controller whose top and bottom layout guides to use for proper setup of constraints in the map view internals.
*
* Certain components of the map view, such as the heading compass and the data attribution button, need to be aware of the view controller layout in order to avoid positioning content under a top navigation bar or a bottom toolbar. */
@property (nonatomic, weak) IBOutlet UIViewController *viewControllerForLayoutGuides;
#pragma mark - Accessing Map Properties
/** @name Accessing Map Properties */
@@ -184,13 +182,17 @@ IB_DESIGNABLE
/** Currently active style classes, represented as an array of string identifiers. */
@property (nonatomic) NSArray *styleClasses;
/** Returns a Boolean value indicating whether the style class with the given identifier is currently active. */
/** Returns a Boolean value indicating whether the style class with the given identifier is currently active.
@param styleClass The style class to query for.
@return Whether the style class is currently active. */
- (BOOL)hasStyleClass:(NSString *)styleClass;
/** Activates the style class with the given identifier. */
/** Activates the style class with the given identifier.
@param styleClass The style class to activate. */
- (void)addStyleClass:(NSString *)styleClass;
/** Deactivates the style class with the given identifier. */
/** Deactivates the style class with the given identifier.
@param styleClass The style class to deactivate. */
- (void)removeStyleClass:(NSString *)styleClass;
#pragma mark - Annotating the Map

View File

@@ -0,0 +1,14 @@
#import <UIKit/UIKit.h>
@interface MGLMapView ()
#pragma mark - Debugging
/** Triggers another render pass even when it is not necessary. */
- (void)invalidate;
/** Returns whether the map view is currently loading or processing any assets required to render the map */
- (BOOL)isFullyLoaded;
@end

View File

@@ -4,6 +4,7 @@ extern NSString *const MGLEventTypeMapLoad;
extern NSString *const MGLEventTypeMapTap;
extern NSString *const MGLEventTypeMapDragEnd;
extern NSString *const MGLEventTypeLocation;
extern NSString *const MGLEventTypeVisit;
extern NSString *const MGLEventKeyLatitude;
extern NSString *const MGLEventKeyLongitude;
@@ -16,6 +17,8 @@ extern NSString *const MGLEventKeyVerticalAccuracy;
extern NSString *const MGLEventKeyPushEnabled;
extern NSString *const MGLEventKeyEmailEnabled;
extern NSString *const MGLEventKeyGestureID;
extern NSString *const MGLEventKeyArrivalDate;
extern NSString *const MGLEventKeyDepartureDate;
extern NSString *const MGLEventGestureSingleTap;
extern NSString *const MGLEventGestureDoubleTap;

View File

@@ -5,7 +5,9 @@
// These methods can be called from any thread.
//
+ (instancetype)sharedManager;
+ (void) startUpdatingLocation;
+ (void) stopUpdatingLocation;
- (void) startUpdatingLocation;
- (void) stopUpdatingLocation;
- (void) startMonitoringVisits;
- (void) stopMonitoringVisits;
@end

View File

@@ -2,3 +2,4 @@
#import "MGLMapView.h"
#import "MGLTypes.h"
#import "MGLUserLocation.h"
#import "MGLAccountManager.h"

View File

@@ -54,11 +54,6 @@ public:
// Only call this while the OpenGL context is exclusive to this thread.
void performCleanup();
// #############################################################################################
// Request to terminate the environment.
void terminate();
private:
unsigned id;
FileSource& fileSource;
@@ -67,9 +62,6 @@ private:
std::vector<uint32_t> abandonedVAOs;
std::vector<uint32_t> abandonedBuffers;
std::vector<uint32_t> abandonedTextures;
public:
uv_loop_t* const loop;
};
class EnvironmentScope final {

View File

@@ -1,96 +1,57 @@
#ifndef MBGL_MAP_MAP
#define MBGL_MAP_MAP
#include <mbgl/map/transform.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/vec.hpp>
#include <cstdint>
#include <atomic>
#include <thread>
#include <iosfwd>
#include <set>
#include <vector>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <string>
#include <functional>
namespace uv { class async; }
#include <vector>
#include <memory>
namespace mbgl {
class Painter;
class GlyphStore;
class LayerDescription;
class Sprite;
class Style;
class StyleLayer;
class TexturePool;
class FileSource;
class View;
class GlyphAtlas;
class SpriteAtlas;
class LineAtlas;
class Environment;
class EnvironmentScope;
class AnnotationManager;
class MapData;
class Worker;
class MapContext;
class StillImage;
namespace util {
template <class T> class Thread;
}
class Map : private util::noncopyable {
friend class View;
public:
enum class Mode : uint8_t {
None, // we're not doing any processing
Continuous, // continually updating map
Still, // a once-off still image.
};
explicit Map(View&, FileSource&);
explicit Map(View&, FileSource&,
MapMode mode = MapMode::Continuous,
bool startPaused = false);
~Map();
// Start the map render thread. It is asynchronous.
void start(bool startPaused = false, Mode mode = Mode::Continuous);
inline void start(Mode renderMode) { start(false, renderMode); }
// Stop the map render thread. This call will block until the map rendering thread stopped.
// The optional callback function will be invoked repeatedly until the map thread is stopped.
// The callback function should wait until it is woken up again by view.notify(), otherwise
// this will be a busy waiting loop.
void stop(std::function<void ()> callback = std::function<void ()>());
// Pauses the render thread. The render thread will stop running but will not be terminated and will not lose state until resumed.
void pause(bool waitForPause = false);
void pause();
// Resumes a paused render thread
void resume();
// Register a callback that will get called (on the render thread) when all resources have
// been loaded and a complete render occurs.
using StillImageCallback = std::function<void(std::unique_ptr<const StillImage>)>;
void renderStill(StillImageCallback callback);
// Triggers a synchronous or asynchronous render.
void renderSync();
// Unconditionally performs a render with the current map state. May only be called from the Map
// thread.
void render();
void renderAsync();
// Notifies the Map thread that the state has changed and an update might be necessary.
void triggerUpdate(Update = Update::Nothing);
// Triggers a render. Can be called from any thread.
void triggerRender();
// Releases resources immediately
void terminate();
void update(Update update = Update::Nothing);
// Styling
void addClass(const std::string&);
@@ -134,18 +95,23 @@ public:
double getBearing() const;
void resetNorth();
// Size
void resize(uint16_t width, uint16_t height, float ratio = 1);
uint16_t getWidth() const;
uint16_t getHeight() const;
// API
void setAccessToken(const std::string &token);
std::string getAccessToken() const;
// Projection
inline void getWorldBoundsMeters(ProjectedMeters &sw, ProjectedMeters &ne) const { Projection::getWorldBoundsMeters(sw, ne); }
inline void getWorldBoundsLatLng(LatLng &sw, LatLng &ne) const { Projection::getWorldBoundsLatLng(sw, ne); }
inline double getMetersPerPixelAtLatitude(const double lat, const double zoom) const { return Projection::getMetersPerPixelAtLatitude(lat, zoom); }
inline const ProjectedMeters projectedMetersForLatLng(const LatLng latLng) const { return Projection::projectedMetersForLatLng(latLng); }
inline const LatLng latLngForProjectedMeters(const ProjectedMeters projectedMeters) const { return Projection::latLngForProjectedMeters(projectedMeters); }
inline const vec2<double> pixelForLatLng(const LatLng latLng) const { return state.pixelForLatLng(latLng); }
inline const LatLng latLngForPixel(const vec2<double> pixel) const { return state.latLngForPixel(pixel); }
void getWorldBoundsMeters(ProjectedMeters &sw, ProjectedMeters &ne) const;
void getWorldBoundsLatLng(LatLng &sw, LatLng &ne) const;
double getMetersPerPixelAtLatitude(const double lat, const double zoom) const;
const ProjectedMeters projectedMetersForLatLng(const LatLng latLng) const;
const LatLng latLngForProjectedMeters(const ProjectedMeters projectedMeters) const;
const vec2<double> pixelForLatLng(const LatLng latLng) const;
const LatLng latLngForPixel(const vec2<double> pixel) const;
// Annotations
void setDefaultPointAnnotationSymbol(const std::string&);
@@ -160,112 +126,17 @@ public:
// Memory
void setSourceTileCacheSize(size_t);
size_t getSourceTileCacheSize() const { return sourceCacheSize; }
void onLowMemory();
// Debug
void setDebug(bool value);
void toggleDebug();
bool getDebug() const;
inline const TransformState &getState() const { return state; }
TimePoint getTime() const;
inline AnnotationManager& getAnnotationManager() const { return *annotationManager; }
bool isFullyLoaded() const;
private:
// Runs the map event loop. ONLY run this function when you want to get render a single frame
// with this map object. It will *not* spawn a separate thread and instead block until the
// frame is completely rendered.
void run();
// This may only be called by the View object.
void resize(uint16_t width, uint16_t height, float ratio = 1);
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
util::ptr<Sprite> getSprite();
Worker& getWorker();
// Checks if render thread needs to pause
void checkForPause();
// Setup
void setup();
void updateTiles();
// Triggered by triggerUpdate();
void update();
// Loads the style set in the data object. Called by Update::StyleInfo
void reloadStyle();
void loadStyleJSON(const std::string& json, const std::string& base);
// Prepares a map render by updating the tiles we need for the current view, as well as updating
// the stylesheet.
void prepare();
// Runs the function in the map thread.
void invokeTask(std::function<void()>&&);
template <typename Fn> auto invokeSyncTask(const Fn& fn) -> decltype(fn());
void processTasks();
void updateAnnotationTiles(const std::vector<TileID>&);
size_t sourceCacheSize;
Mode mode = Mode::None;
const std::unique_ptr<Environment> env;
std::unique_ptr<EnvironmentScope> scope;
View &view;
private:
std::unique_ptr<Worker> workers;
std::thread thread;
std::unique_ptr<uv::async> asyncTerminate;
std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<uv::async> asyncInvoke;
std::unique_ptr<uv::async> asyncRender;
bool terminating = false;
bool pausing = false;
bool isPaused = false;
std::mutex mutexRun;
std::condition_variable condRun;
std::mutex mutexPause;
std::condition_variable condPause;
// Used to signal that rendering completed.
bool rendered = false;
std::condition_variable condRendered;
std::mutex mutexRendered;
// Stores whether the map thread has been stopped already.
std::atomic_bool isStopped;
Transform transform;
TransformState state;
FileSource& fileSource;
util::ptr<Style> style;
std::unique_ptr<GlyphAtlas> glyphAtlas;
util::ptr<GlyphStore> glyphStore;
std::unique_ptr<SpriteAtlas> spriteAtlas;
util::ptr<Sprite> sprite;
std::unique_ptr<LineAtlas> lineAtlas;
util::ptr<TexturePool> texturePool;
std::unique_ptr<Painter> painter;
std::unique_ptr<AnnotationManager> annotationManager;
const std::unique_ptr<MapData> data;
std::atomic<UpdateType> updated;
std::mutex mutexTask;
std::queue<std::function<void()>> tasks;
StillImageCallback callback;
const std::unique_ptr<util::Thread<MapContext>> context;
};
}

15
include/mbgl/map/mode.hpp Normal file
View File

@@ -0,0 +1,15 @@
#ifndef MBGL_MAP_MODE
#define MBGL_MAP_MODE
#include <cstdint>
namespace mbgl {
enum class MapMode : uint8_t {
Continuous, // continually updating map
Still, // a once-off still image
};
}
#endif

View File

@@ -9,7 +9,6 @@ using UpdateType = uint32_t;
enum class Update : UpdateType {
Nothing = 0,
StyleInfo = 1 << 0,
Debug = 1 << 1,
DefaultTransitionDuration = 1 << 2,
Classes = 1 << 3,

View File

@@ -2,6 +2,7 @@
#define MBGL_MAP_VIEW
#include <mbgl/util/chrono.hpp>
#include <functional>
#include <memory>
@@ -39,13 +40,13 @@ public:
virtual void notify() = 0;
// Called from the render thread. The implementation must trigger a rerender.
// (i.e. map->renderSync() or map->renderAsync() must be called as a result of this)
virtual void invalidate() = 0;
// Called from the render thread. The implementation should resize the framebuffer.
virtual void resize(uint16_t width, uint16_t height, float pixelRatio);
// Called from the render (=GL) thread. Signals that the contents of the contents
// may be discarded. The default is a no-op.
virtual void discard();
// Called from the render thread. The implementation must trigger a rerender.
// (i.e. either the passed render() function for rendering immediately on the map thread,
// or map->renderSync() from the main thread must be called as a result of this)
virtual void invalidate(std::function<void()> render) = 0;
// Reads the pixel data from the current framebuffer. If your View implementation
// doesn't support reading from the framebuffer, return a null pointer.
@@ -58,10 +59,6 @@ public:
MapChange change,
Duration delay = Duration::zero());
protected:
// Resizes the view
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
protected:
mbgl::Map *map = nullptr;
};

View File

@@ -17,7 +17,7 @@ public:
void activate() override;
void deactivate() override;
void notify() override;
void invalidate() override;
void invalidate(std::function<void()> render) override;
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
@@ -25,7 +25,7 @@ public:
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void onMouseMove(GLFWwindow *window, double x, double y);
int run();
void run();
void fps();
public:

View File

@@ -17,6 +17,7 @@ typedef XID GLXPbuffer;
#include <mbgl/platform/gl.hpp>
#include <memory>
#include <thread>
namespace mbgl {
@@ -28,13 +29,11 @@ public:
HeadlessView(std::shared_ptr<HeadlessDisplay> display, uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1);
~HeadlessView();
void resize(uint16_t width, uint16_t height, float pixelRatio);
void activate() override;
void deactivate() override;
void notify() override;
void invalidate() override;
void discard() override;
void resize(uint16_t width, uint16_t height, float pixelRatio) override;
void invalidate(std::function<void()> render) override;
std::unique_ptr<StillImage> readStillImage() override;
private:
@@ -56,12 +55,7 @@ private:
float pixelRatio = 0;
};
// These are the values that represent the state of the current framebuffer.
Dimensions current;
// These are the values that will be used after the next discard() event.
std::mutex prospectiveMutex;
Dimensions prospective;
Dimensions dimensions;
#if MBGL_USE_CGL
CGLContextObj glContext = nullptr;

View File

@@ -10,10 +10,9 @@ extern "C"
}
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#include <boost/iostreams/stream.hpp>
#pragma GCC diagnostic pop

View File

@@ -12,10 +12,9 @@ extern "C"
#include <memory>
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#include <boost/iostreams/stream.hpp>
#pragma GCC diagnostic pop

View File

@@ -159,7 +159,7 @@ inline void start_group(const std::string &str) {
if (gl::PushDebugGroup != nullptr) {
MBGL_CHECK_ERROR(gl::PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, GLsizei(str.size()), str.c_str()));
} else if (gl::PushGroupMarkerEXT != nullptr) {
MBGL_CHECK_ERROR(gl::PushGroupMarkerEXT(GLsizei(str.size()), str.c_str()));
MBGL_CHECK_ERROR(gl::PushGroupMarkerEXT(GLsizei(str.size() + 1), str.c_str()));
}
// fprintf(stderr, "%s%s\n", std::string(indent * 4, ' ').c_str(), str.c_str());
// indent++;

View File

@@ -21,6 +21,9 @@ const std::string &applicationRoot();
// Returns the path to the asset location.
const std::string &assetRoot();
// Makes the current thread low priority.
void makeThreadLowPriority();
// Shows an alpha image with the specified dimensions in a named window.
void showDebugImage(std::string name, const char *data, size_t width, size_t height);

View File

@@ -16,12 +16,9 @@ public:
~DefaultFileSource() override;
// FileSource API
Request *request(const Resource &resource, uv_loop_t *loop, const Environment &env,
Callback callback) override;
void cancel(Request *request) override;
void request(const Resource &resource, const Environment &env, Callback callback) override;
void abort(const Environment &env) override;
Request* request(const Resource&, uv_loop_t*, Callback) override;
void cancel(Request*) override;
void request(const Resource&, Callback) override;
public:
class Impl;

View File

@@ -15,7 +15,6 @@ typedef struct uv_loop_s uv_loop_t;
namespace mbgl {
class Request;
class Environment;
class FileSource : private util::noncopyable {
protected:
@@ -28,19 +27,12 @@ public:
// These can be called from any thread. The callback will be invoked in the loop.
// You can only cancel a request from the same thread it was created in.
virtual Request *request(const Resource &resource, uv_loop_t *loop, const Environment &env,
Callback callback) = 0;
virtual void cancel(Request *request) = 0;
virtual Request* request(const Resource&, uv_loop_t*, Callback) = 0;
virtual void cancel(Request*) = 0;
// These can be called from any thread. The callback will be invoked in an arbitrary other thread.
// You cannot cancel these requests.
virtual void request(const Resource &resource, const Environment &env, Callback callback) = 0;
// This can be called from any thread. All requests with the environment pointer env should be
// notified as errored. Note that this is /different/ from canceling requests; a canceled
// request's callback is never called, while an aborted request's callback is called with
// a error message.
virtual void abort(const Environment &env) = 0;
virtual void request(const Resource&, Callback) = 0;
};
}

View File

@@ -17,14 +17,11 @@ typedef struct uv_loop_s uv_loop_t;
namespace mbgl {
class Response;
class Environment;
class Request : private util::noncopyable {
MBGL_STORE_THREAD(tid)
public:
using Callback = std::function<void(const Response &)>;
Request(const Resource &resource, uv_loop_t *loop, const Environment &env, Callback callback);
Request(const Resource &resource, uv_loop_t *loop, Callback callback);
public:
// May be called from any thread.
@@ -48,11 +45,6 @@ private:
public:
const Resource resource;
// The environment ref is used to associate requests with a particular environment. This allows
// us to only terminate requests associated with that environment, e.g. when the map the env
// belongs to is discarded.
const Environment &env;
};
}

View File

@@ -20,8 +20,9 @@ public:
void get(const Resource &resource, Callback callback) override;
void put(const Resource &resource, std::shared_ptr<const Response> response, Hint hint) override;
private:
class Impl;
private:
const std::unique_ptr<util::Thread<Impl>> thread;
};

View File

@@ -1,95 +0,0 @@
#ifndef MBGL_UTIL_ASYNC_QUEUE
#define MBGL_UTIL_ASYNC_QUEUE
#include "std.hpp"
#include <uv.h>
#include <thread>
#include <mutex>
#include <functional>
#include <queue>
#include <string>
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
#define UV_ASYNC_PARAMS(handle) uv_async_t *handle, int
#else
#define UV_ASYNC_PARAMS(handle) uv_async_t *handle
#endif
namespace mbgl {
namespace util {
template <typename T>
class AsyncQueue {
public:
AsyncQueue(uv_loop_t *loop, std::function<void(T &)> fn) :
callback(fn) {
async.data = this;
uv_async_init(loop, &async, [](UV_ASYNC_PARAMS(handle)) {
auto q = reinterpret_cast<AsyncQueue *>(handle->data);
q->process();
});
}
void send(T &&data) {
{
std::lock_guard<std::mutex> lock(mutex);
queue.push(util::make_unique<T>(std::move(data)));
}
uv_async_send(&async);
}
void send(std::unique_ptr<T> data) {
{
std::lock_guard<std::mutex> lock(mutex);
queue.push(std::move(data));
}
uv_async_send(&async);
}
void stop() {
uv_close((uv_handle_t *)&async, [](uv_handle_t *handle) {
delete reinterpret_cast<AsyncQueue *>(handle->data);
});
}
void ref() {
uv_ref((uv_handle_t *)&async);
}
void unref() {
uv_unref((uv_handle_t *)&async);
}
private:
~AsyncQueue() {
}
void process() {
std::unique_ptr<T> item;
while (true) {
mutex.lock();
if (queue.empty()) {
mutex.unlock();
break;
}
item = std::move(queue.front());
queue.pop();
mutex.unlock();
callback(*item);
}
}
private:
std::mutex mutex;
uv_async_t async;
std::queue<std::unique_ptr<T>> queue;
std::function<void(T &)> callback;
};
}
}
#endif

View File

@@ -0,0 +1,87 @@
#ifndef MBGL_UTIL_GL_HELPER
#define MBGL_UTIL_GL_HELPER
#include <mbgl/platform/gl.hpp>
#include <array>
namespace {
template <typename T, T (*Create)(), void (*Destroy)(const T&)>
class Preserve {
public:
Preserve() : data(Create()) {}
~Preserve() { Destroy(data); }
private:
const T data;
};
inline bool getBlend() {
return glIsEnabled(GL_BLEND);
}
inline void setBlend(const bool& enabled) {
enabled ? MBGL_CHECK_ERROR(glEnable(GL_BLEND)) : MBGL_CHECK_ERROR(glDisable(GL_BLEND));
}
inline std::array<double, 4> getClearColor() {
std::array<double, 4> color;
MBGL_CHECK_ERROR(glGetDoublev(GL_COLOR_CLEAR_VALUE, color.data()));
return color;
}
inline void setClearColor(const std::array<double, 4>& color) {
MBGL_CHECK_ERROR(glClearColor(color[0], color[1], color[2], color[3]));
}
inline std::array<GLenum, 2> getBlendFunc() {
GLint func[2];
glGetIntegerv(GL_BLEND_SRC, &func[0]);
glGetIntegerv(GL_BLEND_DST, &func[1]);
return {{ static_cast<GLenum>(func[0]), static_cast<GLenum>(func[1]) }};
}
inline void setBlendFunc(const std::array<GLenum, 2>& func) {
MBGL_CHECK_ERROR(glBlendFunc(func[0], func[1]));
}
inline std::array<double, 2> getPixelZoom() {
std::array<double, 2> zoom;
glGetDoublev(GL_ZOOM_X, &zoom[0]);
glGetDoublev(GL_ZOOM_Y, &zoom[1]);
return zoom;
}
inline void setPixelZoom(const std::array<double, 2>& func) {
MBGL_CHECK_ERROR(glPixelZoom(func[0], func[1]));
}
inline std::array<double, 4> getRasterPos() {
std::array<double, 4> pos;
MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos.data()));
return pos;
}
inline void setRasterPos(const std::array<double, 4>& pos) {
MBGL_CHECK_ERROR(glRasterPos4d(pos[0], pos[1], pos[2], pos[3]));
}
} // end anonymous namespace
namespace mbgl {
namespace gl {
using PreserveBlend = Preserve<bool, getBlend, setBlend>;
using PreserveClearColor = Preserve<std::array<double, 4>, getClearColor, setClearColor>;
using PreserveBlendFunc = Preserve<std::array<GLenum, 2>, getBlendFunc, setBlendFunc>;
using PreservePixelZoom = Preserve<std::array<double, 2>, getPixelZoom, setPixelZoom>;
using PreserveRasterPos = Preserve<std::array<double, 4>, getRasterPos, setRasterPos>;
}
}
#endif

View File

@@ -4,9 +4,8 @@
#include <string>
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic pop

View File

@@ -1,7 +1,7 @@
Pod::Spec.new do |m|
m.name = 'MapboxGL'
m.version = '0.2.15'
m.version = '0.2.21'
m.summary = 'Open source vector map solution for iOS with full styling capabilities.'
m.description = 'Open source OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa bindings.'

View File

@@ -1,11 +1,29 @@
#import "MBXAppDelegate.h"
#import "MBXViewController.h"
#import <mbgl/ios/MapboxGL.h>
#import <mbgl/ios/MGLAccountManager.h>
#import <mbgl/ios/MGLMapboxEvents.h>
@implementation MBXAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Set Access Token
NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"];
if (accessToken) {
// Store to preferences so that we can launch the app later on without having to specify
// token.
[[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"];
} else {
// Try to retrieve from preferences, maybe we've stored them there previously and can reuse
// the token.
accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
}
if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work.");
// Start Mapbox GL SDK
[MGLAccountManager setAccessToken:accessToken];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[MBXViewController new]];
[self.window makeKeyAndVisible];

View File

@@ -52,22 +52,8 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
{
[super viewDidLoad];
NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"];
if (accessToken) {
// Store to preferences so that we can launch the app later on without having to specify
// token.
[[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"];
} else {
// Try to retrieve from preferences, maybe we've stored them there previously and can reuse
// the token.
accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
}
if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work.");
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:accessToken];
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.viewControllerForLayoutGuides = self;
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
[self.view addSubview:self.mapView];

View File

@@ -9,18 +9,18 @@
'product_extension': 'app',
'mac_bundle': 1,
'mac_bundle_resources': [
'<!@(find ./img -type f)',
'<!@(find ../ios/app/img -type f)',
'./features.geojson',
'./Settings.bundle/'
],
'dependencies': [
'../../mbgl.gyp:bundle_styles',
'../../mbgl.gyp:core',
'../../mbgl.gyp:platform-<(platform_lib)',
'../../mbgl.gyp:http-<(http_lib)',
'../../mbgl.gyp:asset-<(asset_lib)',
'../../mbgl.gyp:cache-<(cache_lib)',
'../mbgl.gyp:bundle_styles',
'../mbgl.gyp:core',
'../mbgl.gyp:platform-<(platform_lib)',
'../mbgl.gyp:http-<(http_lib)',
'../mbgl.gyp:asset-<(asset_lib)',
'../mbgl.gyp:cache-<(cache_lib)',
],
'sources': [
@@ -38,7 +38,7 @@
'SDKROOT': 'iphoneos',
'SUPPORTED_PLATFORMS': 'iphonesimulator iphoneos',
'IPHONEOS_DEPLOYMENT_TARGET': '7.0',
'INFOPLIST_FILE': 'app-info.plist',
'INFOPLIST_FILE': '../ios/app/app-info.plist',
'TARGETED_DEVICE_FAMILY': '1,2',
'COMBINE_HIDPI_IMAGES': 'NO', # don't merge @2x.png images into .tiff files
'CLANG_ENABLE_OBJC_ARC': 'YES',

View File

@@ -0,0 +1,7 @@
#import <UIKit/UIKit.h>
@interface MBXBenchAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -0,0 +1,15 @@
#import "MBXBenchAppDelegate.h"
#import "MBXBenchViewController.h"
@implementation MBXBenchAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [MBXBenchViewController new];
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>
@interface MBXBenchViewController : UIViewController
@end

View File

@@ -0,0 +1,140 @@
#import "MBXBenchViewController.h"
#import <mbgl/ios/MGLMapView.h>
#import <mbgl/ios/MGLMapView_Private.h>
#include "locations.hpp"
#include <chrono>
@interface MBXBenchViewController () <MGLMapViewDelegate>
@property (nonatomic) MGLMapView *mapView;
@end
@implementation MBXBenchViewController
#pragma mark - Setup
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL* url = [[NSURL alloc] initWithString:@"asset://styles/mapbox-streets-v7.json"];
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:nil styleURL:url];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.delegate = self;
self.mapView.zoomEnabled = NO;
self.mapView.scrollEnabled = NO;
self.mapView.rotateEnabled = NO;
self.mapView.userInteractionEnabled = YES;
[self.mapView setDebugActive:NO];
[self startBenchmarkIteration];
[self.view addSubview:self.mapView];
}
using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;
template <typename Duration>
inline int64_t Microseconds(Duration d) {
return std::chrono::duration_cast<std::chrono::microseconds>(d).count();
}
size_t idx = 0;
enum class State { None, WaitingForAssets, WarmingUp, Benchmarking } state = State::None;
int frames = 0;
TimePoint started;
std::vector<std::pair<std::string, double>> result;
static const int warmupDuration = 20; // frames
static const int benchmarkDuration = 200; // frames
- (void)startBenchmarkIteration
{
if (mbgl::bench::locations.size() > idx) {
const auto& location = mbgl::bench::locations[idx];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(location.latitude, location.longitude) zoomLevel:location.zoom animated:NO];
self.mapView.direction = location.bearing;
state = State::WaitingForAssets;
NSLog(@"Benchmarking \"%s\"", location.name.c_str());
NSLog(@"- Loading assets...");
} else {
// Do nothing. The benchmark is completed.
NSLog(@"Benchmark completed.");
NSLog(@"Result:");
size_t colWidth = 0;
for (const auto& row : result) {
colWidth = std::max(row.first.size(), colWidth);
}
for (const auto& row : result) {
NSLog(@"| %-*s | %4.1f fps |", int(colWidth), row.first.c_str(), row.second);
}
exit(0);
}
}
- (void)mapViewDidFinishRenderingMap:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered
{
(void)mapView;
(void)fullyRendered;
if (state == State::Benchmarking)
{
frames++;
if (frames >= benchmarkDuration)
{
state = State::None;
// Report FPS
const auto duration = Microseconds(Clock::now() - started);
const auto fps = double(frames * 1e6) / duration;
result.emplace_back(mbgl::bench::locations[idx].name, fps);
NSLog(@"- FPS: %.1f", fps);
// Start benchmarking the next location.
idx++;
[self startBenchmarkIteration];
} else {
[mapView invalidate];
}
return;
}
else if (state == State::WarmingUp)
{
frames++;
if (frames >= warmupDuration)
{
frames = 0;
state = State::Benchmarking;
started = Clock::now();
NSLog(@"- Benchmarking for %d frames...", benchmarkDuration);
}
[mapView invalidate];
return;
}
else if (state == State::WaitingForAssets)
{
if ([mapView isFullyLoaded])
{
// Start the benchmarking timer.
state = State::WarmingUp;
[self.mapView emptyMemoryCache];
NSLog(@"- Warming up for %d frames...", warmupDuration);
[mapView invalidate];
}
return;
}
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
@end

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.mapbox.GL.benchmark</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.2</string>
<key>CFBundleSignature</key>
<string>MBGL</string>
<key>CFBundleVersion</key>
<string>0.0.3</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>(c) 2015 Mapbox</string>
<key>UIApplicationExitsOnSuspend</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>Default</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -u
LIST=(
"DIN%20Offc%20Pro%20Regular%2c%20Arial%20Unicode%20MS%20Regular/0-255.pbf"
"DIN%20Offc%20Pro%20Medium%2c%20Arial%20Unicode%20MS%20Bold/0-255.pbf"
"DIN%20Offc%20Pro%20Medium%2c%20Arial%20Unicode%20MS%20Regular/0-255.pbf"
"DIN%20Offc%20Pro%20Medium%2c%20Arial%20Unicode%20MS%20Regular/8192-8447.pbf"
"DIN%20Offc%20Pro%20Bold%2c%20Arial%20Unicode%20MS%20Regular/0-255.pbf"
"DIN%20Offc%20Pro%20Regular%2c%20Arial%20Unicode%20MS%20Regular/256-511.pbf"
"DIN%20Offc%20Pro%20Regular%2c%20Arial%20Unicode%20MS%20Regular/8192-8447.pbf"
"DIN%20Offc%20Pro%20Italic%2c%20Arial%20Unicode%20MS%20Regular/0-255.pbf"
"DIN%20Offc%20Pro%20Medium%2c%20Arial%20Unicode%20MS%20Regular/256-511.pbf"
)
# from https://gist.github.com/cdown/1163649
urldecode() {
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\x}"
}
for i in ${LIST[@]} ; do
OUTPUT=`urldecode "$i"`
if [ ! -f "${OUTPUT}" ] ; then
mkdir -p "`dirname "${OUTPUT}"`"
echo "Downloading glyph '${OUTPUT}'"
curl -# "https://api.tiles.mapbox.com/v4/fontstack/${i}?access_token=${MAPBOX_ACCESS_TOKEN}" | gunzip > "${OUTPUT}"
fi
done

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,175 @@
#!/usr/bin/env bash
set -u
LIST=(
# paris
"mapbox.mapbox-streets-v6/11/1037/704.vector.pbf"
"mapbox.mapbox-streets-v6/11/1037/705.vector.pbf"
"mapbox.mapbox-streets-v6/11/1038/704.vector.pbf"
"mapbox.mapbox-streets-v6/11/1038/705.vector.pbf"
"mapbox.mapbox-streets-v6/11/1036/704.vector.pbf"
"mapbox.mapbox-streets-v6/11/1037/703.vector.pbf"
"mapbox.mapbox-streets-v6/11/1036/705.vector.pbf"
"mapbox.mapbox-streets-v6/11/1038/703.vector.pbf"
"mapbox.mapbox-streets-v6/11/1036/703.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1037/704.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1037/705.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1038/704.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1038/705.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1036/704.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1037/703.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1036/705.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1038/703.vector.pbf"
"mapbox.mapbox-terrain-v2/11/1036/703.vector.pbf"
# paris2
"mapbox.mapbox-streets-v6/13/4150/2819.vector.pbf"
"mapbox.mapbox-streets-v6/13/4149/2819.vector.pbf"
"mapbox.mapbox-streets-v6/13/4150/2818.vector.pbf"
"mapbox.mapbox-streets-v6/13/4149/2820.vector.pbf"
"mapbox.mapbox-streets-v6/13/4148/2819.vector.pbf"
"mapbox.mapbox-streets-v6/13/4149/2818.vector.pbf"
"mapbox.mapbox-streets-v6/13/4150/2817.vector.pbf"
"mapbox.mapbox-streets-v6/13/4148/2820.vector.pbf"
"mapbox.mapbox-streets-v6/13/4148/2818.vector.pbf"
"mapbox.mapbox-streets-v6/13/4149/2817.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4150/2819.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4149/2819.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4150/2818.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4149/2820.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4148/2819.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4149/2818.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4150/2817.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4148/2820.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4148/2818.vector.pbf"
"mapbox.mapbox-terrain-v2/13/4149/2817.vector.pbf"
# alps
"mapbox.mapbox-streets-v6/6/34/23.vector.pbf"
"mapbox.mapbox-streets-v6/6/34/22.vector.pbf"
"mapbox.mapbox-streets-v6/6/33/23.vector.pbf"
"mapbox.mapbox-streets-v6/6/33/22.vector.pbf"
"mapbox.mapbox-streets-v6/6/34/21.vector.pbf"
"mapbox.mapbox-streets-v6/6/32/23.vector.pbf"
"mapbox.mapbox-streets-v6/6/32/22.vector.pbf"
"mapbox.mapbox-streets-v6/6/33/21.vector.pbf"
"mapbox.mapbox-streets-v6/6/32/21.vector.pbf"
"mapbox.mapbox-terrain-v2/6/34/23.vector.pbf"
"mapbox.mapbox-terrain-v2/6/34/22.vector.pbf"
"mapbox.mapbox-terrain-v2/6/33/23.vector.pbf"
"mapbox.mapbox-terrain-v2/6/33/22.vector.pbf"
"mapbox.mapbox-terrain-v2/6/34/21.vector.pbf"
"mapbox.mapbox-terrain-v2/6/32/23.vector.pbf"
"mapbox.mapbox-terrain-v2/6/32/22.vector.pbf"
"mapbox.mapbox-terrain-v2/6/33/21.vector.pbf"
"mapbox.mapbox-terrain-v2/6/32/21.vector.pbf"
# us east
"mapbox.mapbox-streets-v6/5/9/12.vector.pbf"
"mapbox.mapbox-streets-v6/5/8/12.vector.pbf"
"mapbox.mapbox-streets-v6/5/9/13.vector.pbf"
"mapbox.mapbox-streets-v6/5/8/13.vector.pbf"
"mapbox.mapbox-streets-v6/5/9/11.vector.pbf"
"mapbox.mapbox-streets-v6/5/7/12.vector.pbf"
"mapbox.mapbox-streets-v6/5/8/11.vector.pbf"
"mapbox.mapbox-streets-v6/5/7/13.vector.pbf"
"mapbox.mapbox-streets-v6/5/7/11.vector.pbf"
"mapbox.mapbox-terrain-v2/5/9/12.vector.pbf"
"mapbox.mapbox-terrain-v2/5/8/12.vector.pbf"
"mapbox.mapbox-terrain-v2/5/9/13.vector.pbf"
"mapbox.mapbox-terrain-v2/5/8/13.vector.pbf"
"mapbox.mapbox-terrain-v2/5/9/11.vector.pbf"
"mapbox.mapbox-terrain-v2/5/7/12.vector.pbf"
"mapbox.mapbox-terrain-v2/5/8/11.vector.pbf"
"mapbox.mapbox-terrain-v2/5/7/13.vector.pbf"
"mapbox.mapbox-terrain-v2/5/7/11.vector.pbf"
# greater la
"mapbox.mapbox-streets-v6/9/88/204.vector.pbf"
"mapbox.mapbox-streets-v6/9/88/205.vector.pbf"
"mapbox.mapbox-streets-v6/9/89/204.vector.pbf"
"mapbox.mapbox-streets-v6/9/89/205.vector.pbf"
"mapbox.mapbox-streets-v6/9/87/204.vector.pbf"
"mapbox.mapbox-streets-v6/9/88/203.vector.pbf"
"mapbox.mapbox-streets-v6/9/87/205.vector.pbf"
"mapbox.mapbox-streets-v6/9/89/203.vector.pbf"
"mapbox.mapbox-streets-v6/9/87/203.vector.pbf"
"mapbox.mapbox-terrain-v2/9/88/204.vector.pbf"
"mapbox.mapbox-terrain-v2/9/88/205.vector.pbf"
"mapbox.mapbox-terrain-v2/9/89/204.vector.pbf"
"mapbox.mapbox-terrain-v2/9/89/205.vector.pbf"
"mapbox.mapbox-terrain-v2/9/87/204.vector.pbf"
"mapbox.mapbox-terrain-v2/9/88/203.vector.pbf"
"mapbox.mapbox-terrain-v2/9/87/205.vector.pbf"
"mapbox.mapbox-terrain-v2/9/89/203.vector.pbf"
"mapbox.mapbox-terrain-v2/9/87/203.vector.pbf"
# sf
"mapbox.mapbox-streets-v6/14/2621/6333.vector.pbf"
"mapbox.mapbox-streets-v6/14/2620/6333.vector.pbf"
"mapbox.mapbox-streets-v6/14/2621/6334.vector.pbf"
"mapbox.mapbox-streets-v6/14/2620/6334.vector.pbf"
"mapbox.mapbox-streets-v6/14/2621/6332.vector.pbf"
"mapbox.mapbox-streets-v6/14/2619/6333.vector.pbf"
"mapbox.mapbox-streets-v6/14/2620/6332.vector.pbf"
"mapbox.mapbox-streets-v6/14/2619/6334.vector.pbf"
"mapbox.mapbox-streets-v6/14/2619/6332.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2621/6333.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2620/6333.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2621/6334.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2620/6334.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2621/6332.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2619/6333.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2620/6332.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2619/6334.vector.pbf"
"mapbox.mapbox-terrain-v2/14/2619/6332.vector.pbf"
# oakland
"mapbox.mapbox-streets-v6/12/657/1582.vector.pbf"
"mapbox.mapbox-streets-v6/12/657/1583.vector.pbf"
"mapbox.mapbox-streets-v6/12/658/1582.vector.pbf"
"mapbox.mapbox-streets-v6/12/658/1583.vector.pbf"
"mapbox.mapbox-streets-v6/12/656/1582.vector.pbf"
"mapbox.mapbox-streets-v6/12/657/1581.vector.pbf"
"mapbox.mapbox-streets-v6/12/656/1583.vector.pbf"
"mapbox.mapbox-streets-v6/12/658/1581.vector.pbf"
"mapbox.mapbox-streets-v6/12/656/1581.vector.pbf"
"mapbox.mapbox-terrain-v2/12/657/1582.vector.pbf"
"mapbox.mapbox-terrain-v2/12/657/1583.vector.pbf"
"mapbox.mapbox-terrain-v2/12/658/1582.vector.pbf"
"mapbox.mapbox-terrain-v2/12/658/1583.vector.pbf"
"mapbox.mapbox-terrain-v2/12/656/1582.vector.pbf"
"mapbox.mapbox-terrain-v2/12/657/1581.vector.pbf"
"mapbox.mapbox-terrain-v2/12/656/1583.vector.pbf"
"mapbox.mapbox-terrain-v2/12/658/1581.vector.pbf"
"mapbox.mapbox-terrain-v2/12/656/1581.vector.pbf"
# germany
"mapbox.mapbox-streets-v6/6/34/21.vector.pbf"
"mapbox.mapbox-streets-v6/6/34/22.vector.pbf"
"mapbox.mapbox-streets-v6/6/33/21.vector.pbf"
"mapbox.mapbox-streets-v6/6/33/22.vector.pbf"
"mapbox.mapbox-streets-v6/6/34/20.vector.pbf"
"mapbox.mapbox-streets-v6/6/32/21.vector.pbf"
"mapbox.mapbox-streets-v6/6/33/20.vector.pbf"
"mapbox.mapbox-streets-v6/6/32/22.vector.pbf"
"mapbox.mapbox-streets-v6/6/32/20.vector.pbf"
"mapbox.mapbox-terrain-v2/6/34/21.vector.pbf"
"mapbox.mapbox-terrain-v2/6/34/22.vector.pbf"
"mapbox.mapbox-terrain-v2/6/33/21.vector.pbf"
"mapbox.mapbox-terrain-v2/6/33/22.vector.pbf"
"mapbox.mapbox-terrain-v2/6/34/20.vector.pbf"
"mapbox.mapbox-terrain-v2/6/32/21.vector.pbf"
"mapbox.mapbox-terrain-v2/6/33/20.vector.pbf"
"mapbox.mapbox-terrain-v2/6/32/22.vector.pbf"
"mapbox.mapbox-terrain-v2/6/32/20.vector.pbf"
)
for OUTPUT in ${LIST[@]} ; do
if [ ! -f "${OUTPUT}" ] ; then
mkdir -p "`dirname "${OUTPUT}"`"
echo "Downloading tile '${OUTPUT}'"
curl -# "https://a.tiles.mapbox.com/v4/${OUTPUT}?access_token=${MAPBOX_ACCESS_TOKEN}" | gunzip > "${OUTPUT}"
fi
done

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"attribution":"<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox &copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://www.mapbox.com/map-feedback/\" target=\"_blank\">Improve this map</a>","bounds":[-180,-85.0511,180,85.0511],"center":[0,0,3],"description":"","filesize":0,"format":"pbf","id":"mapbox.mapbox-terrain-v2","maskLevel":9,"maxzoom":14,"minzoom":0,"name":"Mapbox Terrain V2","private":true,"scheme":"xyz","tilejson":"2.0.0","tiles":["asset://tiles/mapbox.mapbox-terrain-v2/{z}/{x}/{y}.vector.pbf"],"vector_layers":[{"description":"Generalized landcover classification","fields":{"class":"One of: wood, scrub, grass, crop, snow"},"id":"landcover","maxzoom":22,"minzoom":0},{"description":"","fields":{"class":"One of: shadow, highlight","level":"Brightness %. One of: 94, 90, 89, 78, 67, 56"},"id":"hillshade","maxzoom":22,"minzoom":0},{"description":"Elevation contour polygons","fields":{"ele":"Integer. The elevation of the contour in meters.","index":"Indicator for every 2nd, 5th, or 10th contour. Coastlines are given -1. One of: 2, 5, 10, -1, null"},"id":"contour","maxzoom":22,"minzoom":0}]}

View File

@@ -0,0 +1,63 @@
{
'includes': [
'../../gyp/common.gypi',
],
'targets': [
{ 'target_name': 'ios-bench',
'product_name': 'Bench GL',
'type': 'executable',
'product_extension': 'app',
'mac_bundle': 1,
'mac_bundle_resources': [
'<!@(find ../ios/benchmark/img -type f)',
'assets/glyphs',
'assets/sprites',
'assets/styles',
'assets/tiles',
],
'dependencies': [
'../mbgl.gyp:core',
'../mbgl.gyp:platform-<(platform_lib)',
'../mbgl.gyp:http-<(http_lib)',
'../mbgl.gyp:asset-<(asset_lib)',
'../mbgl.gyp:cache-<(cache_lib)',
],
'sources': [
'./main.m',
'./MBXBenchAppDelegate.h',
'./MBXBenchAppDelegate.m',
'./MBXBenchViewController.h',
'./MBXBenchViewController.mm',
'./locations.hpp',
'./locations.cpp',
],
'xcode_settings': {
'SDKROOT': 'iphoneos',
'SUPPORTED_PLATFORMS': 'iphoneos',
'IPHONEOS_DEPLOYMENT_TARGET': '7.0',
'INFOPLIST_FILE': '../ios/benchmark/app-info.plist',
'TARGETED_DEVICE_FAMILY': '1,2',
'COMBINE_HIDPI_IMAGES': 'NO', # don't merge @2x.png images into .tiff files
'CLANG_ENABLE_OBJC_ARC': 'YES',
'CLANG_ENABLE_MODULES': 'YES',
},
'configurations': {
'Debug': {
'xcode_settings': {
'CODE_SIGN_IDENTITY': 'iPhone Developer',
},
},
'Release': {
'xcode_settings': {
'CODE_SIGN_IDENTITY': 'iPhone Distribution',
'ARCHS': [ "arm64" ],
},
},
},
}
]
}

View File

@@ -0,0 +1,140 @@
#import "MBXBenchViewController.h"
#import <mbgl/ios/MGLMapView.h>
#import <mbgl/ios/MGLMapView_private.h>
#include "locations.hpp"
#include <chrono>
@interface MBXBenchViewController () <MGLMapViewDelegate>
@property (nonatomic) MGLMapView *mapView;
@end
@implementation MBXBenchViewController
#pragma mark - Setup
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL* url = [[NSURL alloc] initWithString:@"asset://styles/mapbox-streets-v7.json"];
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:nil styleURL:url];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.delegate = self;
self.mapView.zoomEnabled = NO;
self.mapView.scrollEnabled = NO;
self.mapView.rotateEnabled = NO;
self.mapView.userInteractionEnabled = YES;
[self.mapView setDebugActive:NO];
[self startBenchmarkIteration];
[self.view addSubview:self.mapView];
}
using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;
template <typename Duration>
inline int64_t Microseconds(Duration d) {
return std::chrono::duration_cast<std::chrono::microseconds>(d).count();
}
size_t idx = 0;
enum class State { None, WaitingForAssets, WarmingUp, Benchmarking } state = State::None;
int frames = 0;
TimePoint started;
std::vector<std::pair<std::string, double>> result;
static const int warmupDuration = 20; // frames
static const int benchmarkDuration = 200; // frames
- (void)startBenchmarkIteration
{
if (mbgl::bench::locations.size() > idx) {
const auto& location = mbgl::bench::locations[idx];
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(location.latitude, location.longitude) zoomLevel:location.zoom animated:NO];
self.mapView.direction = location.bearing;
state = State::WaitingForAssets;
NSLog(@"Benchmarking \"%s\"", location.name.c_str());
NSLog(@"- Loading assets...");
} else {
// Do nothing. The benchmark is completed.
NSLog(@"Benchmark completed.");
NSLog(@"Result:");
size_t colWidth = 0;
for (const auto& row : result) {
colWidth = std::max(row.first.size(), colWidth);
}
for (const auto& row : result) {
NSLog(@"| %-*s | %4.1f fps |", int(colWidth), row.first.c_str(), row.second);
}
exit(0);
}
}
- (void)mapViewDidFinishRenderingMap:(MGLMapView *)mapView fullyRendered:(BOOL)fullyRendered
{
(void)mapView;
(void)fullyRendered;
if (state == State::Benchmarking)
{
frames++;
if (frames >= benchmarkDuration)
{
state = State::None;
// Report FPS
const auto duration = Microseconds(Clock::now() - started);
const auto fps = double(frames * 1e6) / duration;
result.emplace_back(mbgl::bench::locations[idx].name, fps);
NSLog(@"- FPS: %.1f", fps);
// Start benchmarking the next location.
idx++;
[self startBenchmarkIteration];
} else {
[mapView invalidate];
}
return;
}
else if (state == State::WarmingUp)
{
frames++;
if (frames >= warmupDuration)
{
frames = 0;
state = State::Benchmarking;
started = Clock::now();
NSLog(@"- Benchmarking for %d frames...", benchmarkDuration);
}
[mapView invalidate];
return;
}
else if (state == State::WaitingForAssets)
{
if ([mapView isFullyLoaded])
{
// Start the benchmarking timer.
state = State::WarmingUp;
[self.mapView emptyMemoryCache];
NSLog(@"- Warming up for %d frames...", warmupDuration);
[mapView invalidate];
}
return;
}
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
@end

View File

@@ -0,0 +1,64 @@
{
'includes': [
'../../gyp/common.gypi',
],
'targets': [
{ 'target_name': 'ios-bench',
'product_name': 'Bench GL',
'type': 'executable',
'product_extension': 'app',
'mac_bundle': 1,
'mac_bundle_resources': [
'<!@(find ../ios/benchmark/img -type f)',
'assets/glyphs',
'assets/sprites',
'assets/styles',
'assets/tiles',
],
'dependencies': [
'../mbgl.gyp:core',
'../mbgl.gyp:platform-<(platform_lib)',
'../mbgl.gyp:http-<(http_lib)',
'../mbgl.gyp:asset-<(asset_lib)',
'../mbgl.gyp:cache-<(cache_lib)',
],
'sources': [
'./main.m',
'../../include/mbgl/ios/MGLMapView_private.h',
'./MBXBenchAppDelegate.h',
'./MBXBenchAppDelegate.m',
'./MBXBenchViewController.h',
'./MBXBenchViewController.mm',
'./locations.hpp',
'./locations.cpp',
],
'xcode_settings': {
'SDKROOT': 'iphoneos',
'SUPPORTED_PLATFORMS': 'iphoneos',
'IPHONEOS_DEPLOYMENT_TARGET': '7.0',
'INFOPLIST_FILE': '../ios/benchmark/app-info.plist',
'TARGETED_DEVICE_FAMILY': '1,2',
'COMBINE_HIDPI_IMAGES': 'NO', # don't merge @2x.png images into .tiff files
'CLANG_ENABLE_OBJC_ARC': 'YES',
'CLANG_ENABLE_MODULES': 'YES',
},
'configurations': {
'Debug': {
'xcode_settings': {
'CODE_SIGN_IDENTITY': 'iPhone Developer',
},
},
'Release': {
'xcode_settings': {
'CODE_SIGN_IDENTITY': 'iPhone Distribution',
'ARCHS': [ "arm64" ],
},
},
},
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
ios/benchmark/img/Icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 15 15" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-miterlimit:1.41421;">
<image x="0" y="0" width="15px" height="15px" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAQ0lEQVQokcXP2wkAIAxD0Sidvqu5jhTxVXdIPsz/4ZLi3hLkKgsBwOjsX3zBcztKeSvllQKeSlnCQ8GhfA5cHvfk8QNc8hvDN5gIKwAAAABJRU5ErkJggg=="/>
<path id="path7143" d="M9.48355,2.89095C8.18827,3.22425 6.67888,4.56018 5.90484,6.38831L4.93731,6.63727C4.23814,6.81719 3.97174,7.44212 3.83781,8.06502L3.65856,8.89868L5.40366,8.44963L7.68238,9.79563L8.13143,11.5407L8.77503,10.9814C9.25592,10.5634 9.67465,10.0284 9.49474,9.32928L9.24577,8.36174C10.4732,6.80143 10.9147,4.8347 10.5814,3.53941L10.3567,2.66627L9.48355,2.89095ZM8.40657,5.10044C8.73798,5.01516 9.08086,5.2177 9.16614,5.54911C9.25142,5.88052 9.04888,6.2234 8.71747,6.30868C8.38606,6.39396 8.04318,6.19142 7.9579,5.86001C7.87262,5.5286 8.07516,5.18572 8.40657,5.10044L8.40657,5.10044ZM5.41251,9.7356L5.18818,10.1154C4.86414,10.664 4.97269,11.7811 4.97269,11.7811C4.97269,11.7811 5.9677,11.3976 6.32753,10.7884L6.55187,10.4086L5.41251,9.7356Z" style="fill:white;fill-rule:nonzero;stroke-width:0.62px;stroke:white;"/>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 KiB

View File

@@ -0,0 +1,18 @@
#include "locations.hpp"
namespace mbgl {
namespace bench {
const std::vector<Location> locations = {
{ "paris", 2.3411, 48.8664, 11, 0.0 },
{ "paris2", 2.3516, 48.8356, 13, 273.8 },
{ "alps", 10.6107, 46.9599, 6, 0.0 },
{ "us east", -84.3395, 36.9400, 5, 0.0 },
{ "greater la", -117.9529, 34.0259, 9, 0.0 },
{ "sf", -122.4202, 37.7625, 14, 0.0 },
{ "oakland", -122.2328, 37.8267, 12, 0.0 },
{ "germany", 9.2280, 50.9262, 6, 0.0 },
};
}
}

View File

@@ -0,0 +1,23 @@
#ifndef MBGL_BENCH_LOCATIONS
#define MBGL_BENCH_LOCATIONS
#include <vector>
#include <string>
namespace mbgl {
namespace bench {
struct Location {
const std::string name;
const double longitude;
const double latitude;
const double zoom;
const double bearing;
};
extern const std::vector<Location> locations;
}
}
#endif

10
ios/benchmark/main.m Normal file
View File

@@ -0,0 +1,10 @@
#import <UIKit/UIKit.h>
#import "MBXBenchAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MBXBenchAppDelegate class]));
}
}

View File

@@ -5,13 +5,15 @@ if [ -z `which appledoc` ]; then
exit 1
fi
VERSION=$( git tag | grep ^[0-9] | sort -r | sed -n '1p' )
OUTPUT="/tmp/`uuidgen`"
VERSION=$( git tag -l ios\* --sort -v:refname | sed -n '1p' | sed 's/ios-v//' )
echo "Creating new docs for $VERSION..."
echo
appledoc \
--output /tmp/`uuidgen` \
--project-name "Mapbox GL $VERSION" \
--output $OUTPUT \
--project-name "Mapbox GL for iOS $VERSION" \
--project-company Mapbox \
--create-docset \
--company-id com.mapbox \

View File

@@ -90,7 +90,7 @@ int main(int argc, char *argv[]) {
map.setStyleURL(style);
int ret = view->run();
view->run();
// Save settings
mbgl::LatLng latLng = map.getLatLng();
@@ -101,5 +101,5 @@ int main(int argc, char *argv[]) {
settings.debug = map.getDebug();
settings.save();
return ret;
return 0;
}

View File

@@ -133,7 +133,7 @@ int main() {
// Load style
map.setStyleURL("asset://styles/bright-v7.json");
int ret = view.run();
view.run();
[reachability stopNotifier];
@@ -146,5 +146,5 @@ int main() {
settings.debug = map.getDebug();
settings.save();
return ret;
return 0;
}

View File

@@ -1,8 +1,8 @@
#include <mbgl/storage/http_request.hpp>
#include <mbgl/storage/http_context.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/uv.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/time.hpp>
#include <mbgl/util/parsedate.h>
@@ -45,32 +45,33 @@ enum class ResponseStatus : uint8_t {
class HTTPNSURLContext;
class HTTPRequestImpl {
class HTTPRequest : public RequestBase {
public:
HTTPRequestImpl(HTTPRequest *request, uv_loop_t *loop, std::shared_ptr<const Response> response);
~HTTPRequestImpl();
HTTPRequest(HTTPNSURLContext*,
const Resource&,
Callback,
uv_loop_t*,
std::shared_ptr<const Response>);
~HTTPRequest();
void cancel();
void cancelTimer();
void cancel() override;
void retry() override;
private:
void start();
void handleResult(NSData *data, NSURLResponse *res, NSError *error);
void handleResponse();
void retry(uint64_t timeout);
void retryImmediately();
static void restart(uv_timer_t *timer, int);
private:
HTTPNSURLContext *context = nullptr;
HTTPRequest *request = nullptr;
bool cancelled = false;
NSURLSessionDataTask *task = nullptr;
std::unique_ptr<Response> response;
const std::shared_ptr<const Response> existingResponse;
ResponseStatus status = ResponseStatus::PermanentError;
uv_async_t *async = nullptr;
uv::async async;
uv::timer timer;
int attempts = 0;
uv_timer_t *timer = nullptr;
enum : bool { PreemptImmediately, ExponentialBackoff } strategy = PreemptImmediately;
static const int maxAttempts = 4;
@@ -78,18 +79,20 @@ private:
// -------------------------------------------------------------------------------------------------
class HTTPNSURLContext : public HTTPContext<HTTPNSURLContext> {
class HTTPNSURLContext : public HTTPContext {
public:
HTTPNSURLContext(uv_loop_t *loop);
~HTTPNSURLContext();
RequestBase* createRequest(const Resource&,
RequestBase::Callback,
uv_loop_t*,
std::shared_ptr<const Response>) override;
NSURLSession *session = nil;
NSString *userAgent = nil;
};
template<> pthread_key_t ThreadContext<HTTPNSURLContext>::key{};
template<> pthread_once_t ThreadContext<HTTPNSURLContext>::once = PTHREAD_ONCE_INIT;
HTTPNSURLContext::HTTPNSURLContext(uv_loop_t *loop_) : HTTPContext(loop_) {
@autoreleasepool {
NSURLSessionConfiguration *sessionConfig =
@@ -115,34 +118,42 @@ HTTPNSURLContext::~HTTPNSURLContext() {
userAgent = nullptr;
}
RequestBase* HTTPNSURLContext::createRequest(const Resource& resource,
RequestBase::Callback callback,
uv_loop_t* loop,
std::shared_ptr<const Response> response) {
return new HTTPRequest(this, resource, callback, loop, response);
}
// -------------------------------------------------------------------------------------------------
HTTPRequestImpl::HTTPRequestImpl(HTTPRequest *request_, uv_loop_t *loop,
std::shared_ptr<const Response> existingResponse_)
: context(HTTPNSURLContext::Get(loop)),
request(request_),
HTTPRequest::HTTPRequest(HTTPNSURLContext* context_, const Resource& resource_, Callback callback_, uv_loop_t *loop, std::shared_ptr<const Response> existingResponse_)
: RequestBase(resource_, callback_),
context(context_),
existingResponse(existingResponse_),
async(new uv_async_t) {
assert(request);
context->addRequest(request);
async->data = this;
uv_async_init(loop, async, [](uv_async_t *as, int) {
auto impl = reinterpret_cast<HTTPRequestImpl *>(as->data);
impl->handleResponse();
});
async(loop, [this] { handleResponse(); }),
timer(loop) {
context->addRequest(this);
start();
}
void HTTPRequestImpl::start() {
HTTPRequest::~HTTPRequest() {
assert(!task);
// Stop the backoff timer to avoid re-triggering this request.
timer.stop();
context->removeRequest(this);
}
void HTTPRequest::start() {
assert(!task);
attempts++;
@autoreleasepool {
NSMutableString *url = [[NSMutableString alloc] initWithString:@(request->resource.url.c_str())];
NSMutableString *url = [[NSMutableString alloc] initWithString:@(resource.url.c_str())];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"mapbox_metrics_disabled"] == nil) {
if ([url rangeOfString:@"?"].location == NSNotFound) {
[url appendString:@"?"];
@@ -174,13 +185,13 @@ void HTTPRequestImpl::start() {
}
}
void HTTPRequestImpl::handleResponse() {
void HTTPRequest::handleResponse() {
if (task) {
[task release];
task = nullptr;
}
if (request) {
if (!cancelled) {
if (status == ResponseStatus::TemporaryError && attempts < maxAttempts) {
strategy = ExponentialBackoff;
return retry((1 << (attempts - 1)) * 1000);
@@ -193,26 +204,21 @@ void HTTPRequestImpl::handleResponse() {
// Actually return the response.
if (status == ResponseStatus::NotModified) {
request->notify(std::move(response), FileCache::Hint::Refresh);
notify(std::move(response), FileCache::Hint::Refresh);
} else {
request->notify(std::move(response), FileCache::Hint::Full);
notify(std::move(response), FileCache::Hint::Full);
}
context->removeRequest(request);
request->ptr = nullptr;
delete request;
request = nullptr;
}
delete this;
}
void HTTPRequestImpl::cancel() {
context->removeRequest(request);
request = nullptr;
void HTTPRequest::cancel() {
context->removeRequest(this);
cancelled = true;
// Stop the backoff timer to avoid re-triggering this request.
cancelTimer();
timer.stop();
if (task) {
[task cancel];
@@ -223,29 +229,6 @@ void HTTPRequestImpl::cancel() {
}
}
void HTTPRequestImpl::cancelTimer() {
if (timer) {
uv_timer_stop(timer);
uv::close(timer);
timer = nullptr;
}
}
HTTPRequestImpl::~HTTPRequestImpl() {
assert(!task);
assert(async);
// Stop the backoff timer to avoid re-triggering this request.
cancelTimer();
uv::close(async);
if (request) {
context->removeRequest(request);
request->ptr = nullptr;
}
}
int64_t parseCacheControl(const char *value) {
if (value) {
unsigned long long seconds = 0;
@@ -261,7 +244,7 @@ int64_t parseCacheControl(const char *value) {
return 0;
}
void HTTPRequestImpl::handleResult(NSData *data, NSURLResponse *res, NSError *error) {
void HTTPRequest::handleResult(NSData *data, NSURLResponse *res, NSError *error) {
if (error) {
if ([error code] == NSURLErrorCancelled) {
status = ResponseStatus::Canceled;
@@ -361,73 +344,28 @@ void HTTPRequestImpl::handleResult(NSData *data, NSURLResponse *res, NSError *er
response->message = "response class is not NSHTTPURLResponse";
}
uv_async_send(async);
async.send();
}
void HTTPRequestImpl::retry(uint64_t timeout) {
void HTTPRequest::retry(uint64_t timeout) {
response.reset();
assert(!timer);
timer = new uv_timer_t;
timer->data = this;
uv_timer_init(async->loop, timer);
uv_timer_start(timer, restart, timeout, 0);
timer.stop();
timer.start(timeout, 0, [this] { start(); });
}
void HTTPRequestImpl::retryImmediately() {
void HTTPRequest::retry() {
// All batons get notified when the network status changed, but some of them
// might not actually wait for the network to become available again.
if (timer && strategy == PreemptImmediately) {
if (strategy == PreemptImmediately) {
// Triggers the timer upon the next event loop iteration.
uv_timer_stop(timer);
uv_timer_start(timer, restart, 0, 0);
timer.stop();
timer.start(0, 0, [this] { start(); });
}
}
void HTTPRequestImpl::restart(uv_timer_t *timer, int) {
// Restart the request.
auto impl = reinterpret_cast<HTTPRequestImpl *>(timer->data);
// Get rid of the timer.
impl->timer = nullptr;
uv::close(timer);
impl->start();
}
// -------------------------------------------------------------------------------------------------
HTTPRequest::HTTPRequest(DefaultFileSource::Impl *source, const Resource &resource)
: SharedRequestBase(source, resource) {
}
HTTPRequest::~HTTPRequest() {
MBGL_VERIFY_THREAD(tid);
if (ptr) {
reinterpret_cast<HTTPRequestImpl *>(ptr)->cancel();
}
}
void HTTPRequest::start(uv_loop_t *loop, std::shared_ptr<const Response> response) {
MBGL_VERIFY_THREAD(tid);
assert(!ptr);
ptr = new HTTPRequestImpl(this, loop, response);
}
void HTTPRequest::retryImmediately() {
MBGL_VERIFY_THREAD(tid);
if (ptr) {
reinterpret_cast<HTTPRequestImpl *>(ptr)->retryImmediately();
}
}
void HTTPRequest::cancel() {
MBGL_VERIFY_THREAD(tid);
delete this;
std::unique_ptr<HTTPContext> HTTPContext::createContext(uv_loop_t* loop) {
return util::make_unique<HTTPNSURLContext>(loop);
}
}

View File

@@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>
#include <mbgl/platform/platform.hpp>
namespace mbgl {
namespace platform {
void makeThreadLowPriority() {
[[NSThread currentThread] setThreadPriority:0.0];
}
}
}

View File

@@ -1,32 +1,26 @@
#include <mbgl/storage/asset_request.hpp>
#include <mbgl/storage/asset_context.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/util.hpp>
#include <mbgl/util/url.hpp>
#include <mbgl/util/uv.hpp>
#include <uv.h>
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#include <boost/algorithm/string.hpp>
#pragma GCC diagnostic pop
#include <cassert>
namespace algo = boost::algorithm;
#include <limits>
namespace mbgl {
class AssetRequestImpl {
class AssetRequest : public RequestBase {
MBGL_STORE_THREAD(tid)
public:
AssetRequestImpl(AssetRequest *request, uv_loop_t *loop);
~AssetRequestImpl();
AssetRequest(const Resource&, Callback, uv_loop_t*, const std::string& assetRoot);
~AssetRequest();
void cancel() override;
static void fileOpened(uv_fs_t *req);
static void fileStated(uv_fs_t *req);
@@ -35,8 +29,7 @@ public:
static void notifyError(uv_fs_t *req);
static void cleanup(uv_fs_t *req);
AssetRequest *request = nullptr;
std::string assetRoot;
bool canceled = false;
uv_fs_t req;
uv_file fd = -1;
@@ -44,33 +37,40 @@ public:
std::unique_ptr<Response> response;
};
AssetRequestImpl::~AssetRequestImpl() {
MBGL_VERIFY_THREAD(tid);
if (request) {
request->ptr = nullptr;
class AssetFSContext : public AssetContext {
RequestBase* createRequest(const Resource& resource,
RequestBase::Callback callback,
uv_loop_t* loop,
const std::string& assetRoot) override {
return new AssetRequest(resource, callback, loop, assetRoot);
}
};
AssetRequest::~AssetRequest() {
MBGL_VERIFY_THREAD(tid);
}
AssetRequestImpl::AssetRequestImpl(AssetRequest *request_, uv_loop_t *loop) : request(request_) {
AssetRequest::AssetRequest(const Resource& resource_, Callback callback_, uv_loop_t* loop, const std::string& assetRoot_)
: RequestBase(resource_, callback_),
assetRoot(assetRoot_) {
req.data = this;
const auto &url = request->resource.url;
const auto &url = resource.url;
std::string path;
if (url.size() <= 8 || url[8] == '/') {
// This is an empty or absolute path.
path = url.substr(8);
path = mbgl::util::percentDecode(url.substr(8));
} else {
// This is a relative path. Prefix with the application root.
path = request->source->assetRoot + "/" + url.substr(8);
path = assetRoot + "/" + mbgl::util::percentDecode(url.substr(8));
}
uv_fs_open(loop, &req, path.c_str(), O_RDONLY, S_IRUSR, fileOpened);
}
void AssetRequestImpl::fileOpened(uv_fs_t *req) {
void AssetRequest::fileOpened(uv_fs_t *req) {
assert(req->data);
auto self = reinterpret_cast<AssetRequestImpl *>(req->data);
auto self = reinterpret_cast<AssetRequest *>(req->data);
MBGL_VERIFY_THREAD(self->tid);
if (req->result < 0) {
@@ -93,9 +93,9 @@ void AssetRequestImpl::fileOpened(uv_fs_t *req) {
}
}
void AssetRequestImpl::fileStated(uv_fs_t *req) {
void AssetRequest::fileStated(uv_fs_t *req) {
assert(req->data);
auto self = reinterpret_cast<AssetRequestImpl *>(req->data);
auto self = reinterpret_cast<AssetRequest *>(req->data);
MBGL_VERIFY_THREAD(self->tid);
if (req->result != 0 || self->canceled) {
@@ -121,9 +121,7 @@ void AssetRequestImpl::fileStated(uv_fs_t *req) {
#else
response->message = uv_strerror(UV_EFBIG);
#endif
assert(self->request);
self->request->notify(std::move(response), FileCache::Hint::No);
delete self->request;
self->notify(std::move(response), FileCache::Hint::No);
uv_fs_req_cleanup(req);
uv_fs_close(req->loop, req, self->fd, fileClosed);
@@ -148,9 +146,9 @@ void AssetRequestImpl::fileStated(uv_fs_t *req) {
}
}
void AssetRequestImpl::fileRead(uv_fs_t *req) {
void AssetRequest::fileRead(uv_fs_t *req) {
assert(req->data);
auto self = reinterpret_cast<AssetRequestImpl *>(req->data);
auto self = reinterpret_cast<AssetRequest *>(req->data);
MBGL_VERIFY_THREAD(self->tid);
if (req->result < 0 || self->canceled) {
@@ -160,18 +158,16 @@ void AssetRequestImpl::fileRead(uv_fs_t *req) {
} else {
// File was successfully read.
self->response->status = Response::Successful;
assert(self->request);
self->request->notify(std::move(self->response), FileCache::Hint::No);
delete self->request;
self->notify(std::move(self->response), FileCache::Hint::No);
}
uv_fs_req_cleanup(req);
uv_fs_close(req->loop, req, self->fd, fileClosed);
}
void AssetRequestImpl::fileClosed(uv_fs_t *req) {
void AssetRequest::fileClosed(uv_fs_t *req) {
assert(req->data);
auto self = reinterpret_cast<AssetRequestImpl *>(req->data);
auto self = reinterpret_cast<AssetRequest *>(req->data);
MBGL_VERIFY_THREAD(self->tid);
(void(self)); // Silence unused variable error in Release mode
@@ -182,70 +178,37 @@ void AssetRequestImpl::fileClosed(uv_fs_t *req) {
cleanup(req);
}
void AssetRequestImpl::notifyError(uv_fs_t *req) {
void AssetRequest::notifyError(uv_fs_t *req) {
assert(req->data);
auto self = reinterpret_cast<AssetRequestImpl *>(req->data);
auto self = reinterpret_cast<AssetRequest *>(req->data);
MBGL_VERIFY_THREAD(self->tid);
if (req->result < 0 && !self->canceled && req->result != UV_ECANCELED) {
auto response = util::make_unique<Response>();
response->status = Response::Error;
response->message = uv::getFileRequestError(req);
assert(self->request);
self->request->notify(std::move(response), FileCache::Hint::No);
delete self->request;
self->notify(std::move(response), FileCache::Hint::No);
}
}
void AssetRequestImpl::cleanup(uv_fs_t *req) {
void AssetRequest::cleanup(uv_fs_t *req) {
assert(req->data);
auto self = reinterpret_cast<AssetRequestImpl *>(req->data);
auto self = reinterpret_cast<AssetRequest *>(req->data);
MBGL_VERIFY_THREAD(self->tid);
uv_fs_req_cleanup(req);
delete self;
}
// -------------------------------------------------------------------------------------------------
AssetRequest::AssetRequest(DefaultFileSource::Impl *source_, const Resource &resource_)
: SharedRequestBase(source_, resource_) {
assert(algo::starts_with(resource.url, "asset://"));
}
AssetRequest::~AssetRequest() {
MBGL_VERIFY_THREAD(tid);
if (ptr) {
reinterpret_cast<AssetRequestImpl *>(ptr)->request = nullptr;
}
}
void AssetRequest::start(uv_loop_t *loop, std::shared_ptr<const Response> response) {
MBGL_VERIFY_THREAD(tid);
// We're ignoring the existing response if any.
(void(response));
assert(!ptr);
ptr = new AssetRequestImpl(this, loop);
// Note: the AssetRequestImpl deletes itself.
}
void AssetRequest::cancel() {
MBGL_VERIFY_THREAD(tid);
canceled = true;
// uv_cancel fails frequently when the request has already been started.
// In that case, we have to let it complete and check the canceled bool
// instead. The cancelation callback will delete the AssetRequest object.
uv_cancel((uv_req_t *)&req);
}
if (ptr) {
reinterpret_cast<AssetRequestImpl *>(ptr)->canceled = true;
// uv_cancel fails frequently when the request has already been started.
// In that case, we have to let it complete and check the canceled bool
// instead. The cancelation callback will delete the AssetRequest object.
uv_cancel((uv_req_t *)&reinterpret_cast<AssetRequestImpl *>(ptr)->req);
} else {
// This request is canceled before we called start. We're safe to delete
// ourselves now.
delete this;
}
std::unique_ptr<AssetContext> AssetContext::createContext(uv_loop_t*) {
return util::make_unique<AssetFSContext>();
}
}

Some files were not shown because too many files have changed in this diff Show More