From a9023914918ddc85772265c910bc6d7f7fe17c74 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 12 Aug 2014 18:53:32 -0400 Subject: [PATCH 01/87] clone libuv010 branch of mapnik-packaging --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 3e5e897a7..211a65316 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -44,7 +44,7 @@ NODE=`which node` NPM=`which npm` if [ ! -d 'mapnik-packaging/.git' ]; then - git clone --depth=1 https://github.com/mapnik/mapnik-packaging.git + git clone --depth=1 -b libuv010 https://github.com/mapnik/mapnik-packaging.git fi cd mapnik-packaging/osx/ From 6408e40a60be97555fe98a430f1ae81bd128f4f3 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 13 Aug 2014 16:04:10 -0400 Subject: [PATCH 02/87] revert https://github.com/mapbox/mapbox-gl-native/commit/992815cc3da3a440dbc56c61925a4e5443b58073 --- include/mbgl/util/uv_detail.hpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index c65c247ba..b3fdbb371 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -31,18 +31,13 @@ private: class loop { public: - inline loop() { - if (uv_loop_init(&l) != 0) { - throw std::runtime_error("failed to initialize loop"); - } - } + inline loop() : l(uv_loop_new()) {} + inline ~loop() { uv_loop_delete(l); } - inline ~loop() { uv_loop_close(&l); } - - inline uv_loop_t *operator*() { return &l; } + inline uv_loop_t *operator*() { return l; } private: - uv_loop_t l; + uv_loop_t *l; }; class mutex { From a57aefbd5d2ca494d0a4e7df438cef5fbfdfb65b Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 14 Aug 2014 17:19:40 -0400 Subject: [PATCH 03/87] override LIBUV_VERSION --- setup-libraries.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 211a65316..c8a9bc1c2 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -44,7 +44,7 @@ NODE=`which node` NPM=`which npm` if [ ! -d 'mapnik-packaging/.git' ]; then - git clone --depth=1 -b libuv010 https://github.com/mapnik/mapnik-packaging.git + git clone --depth=1 https://github.com/mapnik/mapnik-packaging.git fi cd mapnik-packaging/osx/ @@ -54,21 +54,25 @@ export CXX11=true if [ ${UNAME} = 'Darwin' ]; then source iPhoneOS.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libcpp-armv7-iphoneos/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libcpp-armv7-iphoneos/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' source iPhoneOSs.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libcpp-armv7s-iphoneos/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libcpp-armv7s-iphoneos/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' source iPhoneOS64.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libcpp-arm64-iphoneos/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libcpp-arm64-iphoneos/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' source iPhoneSimulator.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libcpp-i386-iphonesimulator/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libcpp-i386-iphonesimulator/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' @@ -81,6 +85,7 @@ source iPhoneSimulator.sh # echo ' ...done' source MacOSX.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libcpp-x86_64-macosx/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libcpp-x86_64-macosx/lib/libglfw3.a ] ; then ./scripts/build_glfw.sh ; fi if [ ! -f out/build-cpp11-libcpp-x86_64-macosx/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi @@ -108,6 +113,7 @@ if [ ! -z "${TRAVIS:-}" ]; then fi source Linux.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libglfw3.a ] ; then ./scripts/build_glfw.sh ; fi if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi From 40ee0dfb5f9fd0b17cf0c302776fba0be8bc0790 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 20 Aug 2014 16:54:43 -0400 Subject: [PATCH 04/87] add AWS_S3_BUCKET env var to .travis.yml --- .travis.yml | 1 + setup-libraries.sh | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b641c1158..d2d77a43b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - secure: "bG4YYWMfl9API0MSRgmOaJrlGLv06tRg9KJNawBieZvBJbITPpxVGJZT3/l/SEJ+Rl15e2dRex4k+MGQlmT2SqPQxTEYWv1qxNigKPPcla7IWeNmWWqW8uVvFjdglojgBOK2k/xErVQtA4zDfi3mwSXH4DKwquXWsoEKmX2SV7M=" - secure: "Cbvap9ubVKgjPe3hUhI6JGeDZzBXHpOG9RaYKh+SdoIPhKnlJiNOYm1egomi+e4uqJInlFKuVHTw7Ng9Cun6Zm0jIxpkSchv1GpsR7hmB3UGnGed19Dw8121FwuUaktN+4YnbVlsyd+u8EHD3+h58t4eELrLrZolM4rS7DL6caA=" - secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I=" + - AWS_S3_BUCKET=mapbox-gl-testing before_install: - source ./scripts/flags.sh diff --git a/setup-libraries.sh b/setup-libraries.sh index 9c83595a3..92ff675e9 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -66,7 +66,7 @@ export CXX11=true if [ ${UNAME} = 'Darwin' ]; then if [ ! -z "${TRAVIS:-}" ]; then - if aws s3 cp s3://mapbox-gl-testing/dependencies/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz ./out/ ; then + if aws s3 cp s3://${AWS_S3_BUCKET}/dependencies/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz ./out/ ; then rm -rf out/build-cpp11-libcpp-universal tar -xzf out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz fi @@ -114,7 +114,7 @@ source MacOSX.sh if [ ! -z "${TRAVIS:-}" ]; then tar -zcf out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz out/build-cpp11-libcpp-universal - aws s3 cp out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz s3://mapbox-gl-testing/dependencies/ + aws s3 cp out/build-cpp11-libcpp-universal_${MP_HASH}.tar.gz s3://${AWS_S3_BUCKET}/dependencies/ fi fi @@ -129,7 +129,7 @@ cd ../../ elif [ ${UNAME} = 'Linux' ]; then if [ ! -z "${TRAVIS:-}" ]; then - if aws s3 cp s3://mapbox-gl-testing/dependencies/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ./out/ ; then + if aws s3 cp s3://${AWS_S3_BUCKET}/dependencies/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ./out/ ; then rm -rf out/build-cpp11-libstdcpp-gcc-x86_64-linux tar -xzf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz fi @@ -146,7 +146,7 @@ source Linux.sh if [ ! -z "${TRAVIS:-}" ]; then if ! tar --compare -zf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ; then tar -zcf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz out/build-cpp11-libstdcpp-gcc-x86_64-linux - aws s3 cp out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz s3://mapbox-gl-testing/dependencies/ + aws s3 cp out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz s3://${AWS_S3_BUCKET}/dependencies/ fi fi From 33562623c8a6939df39316020439189ae9d54eed Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 20 Aug 2014 18:53:56 -0400 Subject: [PATCH 05/87] pin mapnik-packaging to new hash to generate pkg-config .pc file for libuv --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 1884ebe12..3708c606c 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="6d7e83e8042" +MP_HASH="762527d980" if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git fi From 1ff71a78e05e0c12fca26fea2c7bda14b237631a Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 20 Aug 2014 19:10:36 -0400 Subject: [PATCH 06/87] update mapnik-packaging --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 3708c606c..5ad69fb14 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="762527d980" +MP_HASH="9d134bf" if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git fi From 3466f364121b3a0a157ce62c417c94802484351a Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 20 Aug 2014 19:43:29 -0400 Subject: [PATCH 07/87] bump mapnik-packaging, conform to libuv 0.10 api --- include/mbgl/map/map.hpp | 8 ++++---- include/mbgl/platform/request.hpp | 2 +- setup-libraries.sh | 2 +- src/map/map.cpp | 8 ++++---- src/platform/request.cpp | 2 +- src/util/uv.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index fba38879e..4c5952a2c 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -129,10 +129,10 @@ public: private: // uv async callbacks - static void render(uv_async_t *async); - static void terminate(uv_async_t *async); - static void cleanup(uv_async_t *async); - static void delete_async(uv_handle_t *handle); + static void render(uv_async_t *async, int status); + static void terminate(uv_async_t *async, int status); + static void cleanup(uv_async_t *async, int status); + static void delete_async(uv_handle_t *handle, int status); // Setup void setup(); diff --git a/include/mbgl/platform/request.hpp b/include/mbgl/platform/request.hpp index 0cbacf645..2a231769c 100644 --- a/include/mbgl/platform/request.hpp +++ b/include/mbgl/platform/request.hpp @@ -24,7 +24,7 @@ public: void complete(); private: - static void complete(uv_async_t *async); + static void complete(uv_async_t *async, int status); public: const std::string url; diff --git a/setup-libraries.sh b/setup-libraries.sh index 5ad69fb14..bcf318ae8 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="9d134bf" +MP_HASH="c07b197" if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git fi diff --git a/src/map/map.cpp b/src/map/map.cpp index 6aa9071a4..8caea4c79 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -98,7 +98,7 @@ void Map::stop() { async = false; } -void Map::delete_async(uv_handle_t *handle) { +void Map::delete_async(uv_handle_t *handle, int status) { delete (uv_async_t *)handle; } @@ -143,14 +143,14 @@ void Map::cleanup() { } } -void Map::cleanup(uv_async_t *async) { +void Map::cleanup(uv_async_t *async, int status) { Map *map = static_cast(async->data); map->view.make_active(); map->painter.cleanup(); } -void Map::render(uv_async_t *async) { +void Map::render(uv_async_t *async, int status) { Map *map = static_cast(async->data); @@ -170,7 +170,7 @@ void Map::render(uv_async_t *async) { } } -void Map::terminate(uv_async_t *async) { +void Map::terminate(uv_async_t *async, int status) { // Closes all open handles on the loop. This means that the loop will automatically terminate. uv_loop_t *loop = static_cast(async->data); uv_walk(loop, [](uv_handle_t *handle, void */*arg*/) { diff --git a/src/platform/request.cpp b/src/platform/request.cpp index efd17895d..b028d8322 100644 --- a/src/platform/request.cpp +++ b/src/platform/request.cpp @@ -41,7 +41,7 @@ void Request::complete() { } } -void Request::complete(uv_async_t *async) { +void Request::complete(uv_async_t *async, int status) { Response *res = static_cast *>(async->data)->get(); res->callback(res); diff --git a/src/util/uv.cpp b/src/util/uv.cpp index 65c790b9c..94f074bfa 100644 --- a/src/util/uv.cpp +++ b/src/util/uv.cpp @@ -10,7 +10,7 @@ std::string cwd() { do { max += 256; dir.resize(max); - uv_cwd(const_cast(dir.data()), &max); + uv_cwd(const_cast(dir.data()), max); } while (max == dir.size()); dir.resize(max - 1); return dir; From 2233f981fb49f6cd000979bea01a483f1abd25bf Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 26 Aug 2014 17:09:32 -0400 Subject: [PATCH 08/87] port curl_request to libuv 0.10.x --- common/curl_request.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/common/curl_request.cpp b/common/curl_request.cpp index 416ed90cd..3370c0a85 100644 --- a/common/curl_request.cpp +++ b/common/curl_request.cpp @@ -216,7 +216,7 @@ int handle_socket(CURL * /*easy*/, curl_socket_t s, int action, void * /*userp*/ return 0; } -void on_timeout(uv_timer_t * /*req*/) { +void on_timeout(uv_timer_t *, int status /*req*/) { int running_handles; CURLMcode error = curl_multi_socket_action(curl_multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); @@ -227,9 +227,9 @@ void on_timeout(uv_timer_t * /*req*/) { void start_timeout(CURLM * /*multi*/, long timeout_ms, void * /*userp*/) { if (timeout_ms <= 0) { - on_timeout(&timeout); + on_timeout(&timeout, -1); } else { - uv_timer_start(&timeout, on_timeout, timeout_ms, 0); + uv_timer_start(&timeout, &on_timeout, timeout_ms, 0); } } @@ -289,7 +289,7 @@ size_t curl_write_cb(void *contents, size_t size, size_t nmemb, void *userp) { // This callback is called in the request event loop (on the request thread). // It initializes newly queued up download requests and adds them to the CURL // multi handle. -void async_add_cb(uv_async_t * /*async*/) { +void async_add_cb(uv_async_t *, int status /*async*/) { std::shared_ptr *req = nullptr; while (add_queue.pop(req)) { // Make sure that we're not starting requests that have been cancelled @@ -321,7 +321,7 @@ void async_add_cb(uv_async_t * /*async*/) { } } -void async_cancel_cb(uv_async_t * /*async*/) { +void async_cancel_cb(uv_async_t *, int status /*async*/) { std::shared_ptr *req = nullptr; while (cancel_queue.pop(req)) { // It is possible that the request has not yet been started, but that it already has been @@ -343,8 +343,8 @@ void thread_init_cb() { curl_global_init(CURL_GLOBAL_ALL); loop = uv_loop_new(); - uv_async_init(loop, &async_add, async_add_cb); - uv_async_init(loop, &async_cancel, async_cancel_cb); + uv_async_init(loop, &async_add, &async_add_cb); + uv_async_init(loop, &async_cancel, &async_cancel_cb); uv_thread_create(&thread, thread_init, nullptr); } } // end namespace request From 1882884c9e3352256722487df3f7e96260c2a858 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 26 Aug 2014 17:38:34 -0400 Subject: [PATCH 09/87] fix uv_cwd call --- src/util/uv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/uv.cpp b/src/util/uv.cpp index 94f074bfa..65c790b9c 100644 --- a/src/util/uv.cpp +++ b/src/util/uv.cpp @@ -10,7 +10,7 @@ std::string cwd() { do { max += 256; dir.resize(max); - uv_cwd(const_cast(dir.data()), max); + uv_cwd(const_cast(dir.data()), &max); } while (max == dir.size()); dir.resize(max - 1); return dir; From 5833f8af25842daf8079014cbae01d9df1ad4eff Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 26 Aug 2014 18:45:42 -0400 Subject: [PATCH 10/87] Revert "fix uv_cwd call" This reverts commit 1882884c9e3352256722487df3f7e96260c2a858. --- src/util/uv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/uv.cpp b/src/util/uv.cpp index 65c790b9c..94f074bfa 100644 --- a/src/util/uv.cpp +++ b/src/util/uv.cpp @@ -10,7 +10,7 @@ std::string cwd() { do { max += 256; dir.resize(max); - uv_cwd(const_cast(dir.data()), &max); + uv_cwd(const_cast(dir.data()), max); } while (max == dir.size()); dir.resize(max - 1); return dir; From d85f03e1103b667285b4444b5e0aaccbf0bea8ed Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 27 Aug 2014 11:57:52 -0400 Subject: [PATCH 11/87] switch mapnik-packaging back to libuv-pkgconfig branch --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index e442333f4..cbc89a102 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="e741a075d28812e5d16b581e1540248fe19c52ce" +MP_HASH="bc0e0b4e02979e56dc9bbc2a601e98583f6e6e6e" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From fa85352612be82c6add5dd53c66211fe500b29b2 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 27 Aug 2014 15:25:16 -0400 Subject: [PATCH 12/87] switch uv_cwd back to &max --- src/util/uv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/uv.cpp b/src/util/uv.cpp index 94f074bfa..65c790b9c 100644 --- a/src/util/uv.cpp +++ b/src/util/uv.cpp @@ -10,7 +10,7 @@ std::string cwd() { do { max += 256; dir.resize(max); - uv_cwd(const_cast(dir.data()), max); + uv_cwd(const_cast(dir.data()), &max); } while (max == dir.size()); dir.resize(max - 1); return dir; From 0c5ba67ac6a5a6dd61065c902241c723a9bf7e56 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 27 Aug 2014 15:57:28 -0400 Subject: [PATCH 13/87] roll back to boost 1.55 --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 3db28a0d2..e27fb33b9 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="bc0e0b4e02979e56dc9bbc2a601e98583f6e6e6e" +MP_HASH="7280b1ab4301d9102b2764a8f16c225c33ccc603" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From 81c9615122ed2c7a8502e25008ccb9c5038427f7 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 27 Aug 2014 15:58:06 -0400 Subject: [PATCH 14/87] more fixes for libuv v0.10 --- src/util/uv.cpp | 2 +- test/fixtures/fixture_request.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/util/uv.cpp b/src/util/uv.cpp index 65c790b9c..94f074bfa 100644 --- a/src/util/uv.cpp +++ b/src/util/uv.cpp @@ -10,7 +10,7 @@ std::string cwd() { do { max += 256; dir.resize(max); - uv_cwd(const_cast(dir.data()), &max); + uv_cwd(const_cast(dir.data()), max); } while (max == dir.size()); dir.resize(max - 1); return dir; diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp index 7e351ecfa..11b308fce 100644 --- a/test/fixtures/fixture_request.cpp +++ b/test/fixtures/fixture_request.cpp @@ -40,8 +40,8 @@ platform::request_http(const std::string &url, uv_fs_req_cleanup(&open_req); if (err < 0) { req->res->code = err; - req->res->error_message = uv_strerror(err); - Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(err)); + req->res->error_message = uv_strerror(uv_last_error(l)); + Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l))); req->complete(); return req; } @@ -53,13 +53,13 @@ platform::request_http(const std::string &url, err = uv_fs_fstat(l, &stat_req, fd, nullptr); if (err < 0) { req->res->code = err; - req->res->error_message = uv_strerror(err); - Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(err)); + req->res->error_message = uv_strerror(uv_last_error(l)); + Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l))); req->complete(); return req; } - const uint64_t size = static_cast(stat_req.ptr)->st_size; + const uint64_t size = static_cast(stat_req.ptr)->st_size; std::string body; @@ -71,8 +71,8 @@ platform::request_http(const std::string &url, uv_fs_req_cleanup(&read_req); if (err < 0) { req->res->code = err; - req->res->error_message = uv_strerror(err); - Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(err)); + req->res->error_message = uv_strerror(uv_last_error(l)); + Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l))); req->complete(); return req; } @@ -83,8 +83,8 @@ platform::request_http(const std::string &url, uv_fs_req_cleanup(&close_req); if (err < 0) { req->res->code = err; - req->res->error_message = uv_strerror(err); - Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(err)); + req->res->error_message = uv_strerror(uv_last_error(l)); + Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l))); req->complete(); return req; } From 0c803a78fa293b8103bbcff9fe679de9ebccba02 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 27 Aug 2014 19:34:37 -0400 Subject: [PATCH 15/87] copy libuv.a to build directory --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index e27fb33b9..6452b1fba 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="7280b1ab4301d9102b2764a8f16c225c33ccc603" +MP_HASH="6c52203e39ae5a8e1b921a66bb170b6fffc12248" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From cffd68f9cabb69491ff8f2c43c680f6b345b25be Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 28 Aug 2014 12:32:57 -0400 Subject: [PATCH 16/87] pull in cleaned up mapnik-packaging with libuv v0.10 fixes --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 6452b1fba..e9041cc93 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="6c52203e39ae5a8e1b921a66bb170b6fffc12248" +MP_HASH="fab18042260ce8aff361bd62cf77edfa914413c0" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From b18cf767c04e57f707c9a5dcc27706e6ec72e9e3 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 2 Sep 2014 17:30:35 -0400 Subject: [PATCH 17/87] use std::fopen/std::fread instead of libuv, thanks @springmeyer --- test/fixtures/fixture_request.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp index 11b308fce..865859238 100644 --- a/test/fixtures/fixture_request.cpp +++ b/test/fixtures/fixture_request.cpp @@ -3,6 +3,7 @@ #include #include #include +#include const std::string base_directory = []{ std::string fn = __FILE__; @@ -35,6 +36,20 @@ platform::request_http(const std::string &url, int err; + std::string body; + FILE *file = std::fopen(clean_url.c_str(),"rb"); + + if (file != NULL) + { + std::fseek(file, 0, SEEK_END); + std::size_t file_size = std::ftell(file); + std::fseek(file, 0, SEEK_SET); + body.resize(file_size); + std::fread(&body[0], file_size, 1, file); + std::fclose(file); + } + + /* uv_fs_t open_req; err = uv_fs_open(l, &open_req, clean_url.c_str(), O_RDONLY, S_IRUSR, nullptr); uv_fs_req_cleanup(&open_req); @@ -67,9 +82,12 @@ platform::request_http(const std::string &url, uv_buf_t uvbuf = uv_buf_init(const_cast(body.data()), body.size()); uv_fs_t read_req; + std::cerr << "fd: " << fd << '\n'; + std::cerr << "uvbuf.len: " << uvbuf.len << '\n'; err = uv_fs_read(l, &read_req, fd, &uvbuf, 1, 0, nullptr); uv_fs_req_cleanup(&read_req); if (err < 0) { + std::cerr << "err: " << read_req.errorno << '\n'; req->res->code = err; req->res->error_message = uv_strerror(uv_last_error(l)); Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l))); @@ -88,6 +106,7 @@ platform::request_http(const std::string &url, req->complete(); return req; } + */ req->res->body.swap(body); req->res->code = 200; From 6b23d05a234710c2d34064289c06362788af0e1b Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 2 Sep 2014 17:48:34 -0400 Subject: [PATCH 18/87] remove debugging --- test/fixtures/fixture_request.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp index 865859238..417958a33 100644 --- a/test/fixtures/fixture_request.cpp +++ b/test/fixtures/fixture_request.cpp @@ -82,12 +82,9 @@ platform::request_http(const std::string &url, uv_buf_t uvbuf = uv_buf_init(const_cast(body.data()), body.size()); uv_fs_t read_req; - std::cerr << "fd: " << fd << '\n'; - std::cerr << "uvbuf.len: " << uvbuf.len << '\n'; err = uv_fs_read(l, &read_req, fd, &uvbuf, 1, 0, nullptr); uv_fs_req_cleanup(&read_req); if (err < 0) { - std::cerr << "err: " << read_req.errorno << '\n'; req->res->code = err; req->res->error_message = uv_strerror(uv_last_error(l)); Log::Warning(Event::HttpRequest, err, url + ": " + uv_strerror(uv_last_error(l))); From 6e5308a61b455ea9e87ca20bc18d6964e6313b74 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 3 Sep 2014 15:13:59 -0400 Subject: [PATCH 19/87] uv_async_init &complete --- src/platform/request.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/request.cpp b/src/platform/request.cpp index b028d8322..82e80b9a7 100644 --- a/src/platform/request.cpp +++ b/src/platform/request.cpp @@ -20,7 +20,7 @@ Request::Request(const std::string &url, // create an actual work request that is attached to the default loop. async = new uv_async_t(); async->data = new std::unique_ptr(); - uv_async_init(**loop, async, complete); + uv_async_init(**loop, async, &complete); } } From 88ef2f23e5061e744fefbb04f9bd908457690018 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 3 Sep 2014 17:20:48 -0400 Subject: [PATCH 20/87] cache linux deps builds on MP_HASH, DIR_HASH --- setup-libraries.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index e9041cc93..00df8795d 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -135,9 +135,9 @@ cd ../../ elif [ ${UNAME} = 'Linux' ]; then if [ ! -z "${TRAVIS:-}" ]; then - if aws s3 cp s3://${AWS_S3_BUCKET}/dependencies/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ./out/ ; then + if aws s3 cp s3://${AWS_S3_BUCKET}/dependencies/build-cpp11-libstdcpp-gcc-x86_64-linux_${MP_HASH}_${DIR_HASH}.tar.gz ./out/ ; then rm -rf out/build-cpp11-libstdcpp-gcc-x86_64-linux - tar -xzf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz + tar -xzf out/build-cpp11-libstdcpp-gcc-x86_64-linux_${MP_HASH}_${DIR_HASH}.tar.gz fi fi @@ -152,8 +152,8 @@ export LIBUV_VERSION=0.10.28 if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then if ! tar --compare -zf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ; then - tar -zcf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz out/build-cpp11-libstdcpp-gcc-x86_64-linux - aws s3 cp --acl public-read out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz s3://${AWS_S3_BUCKET}/dependencies/ + tar -zcf out/build-cpp11-libstdcpp-gcc-x86_64-linux_${MP_HASH}_${DIR_HASH}.tar.gz out/build-cpp11-libstdcpp-gcc-x86_64-linux + aws s3 cp --acl public-read out/build-cpp11-libstdcpp-gcc-x86_64-linux_${MP_HASH}_${DIR_HASH}.tar.gz s3://${AWS_S3_BUCKET}/dependencies/ fi fi From 74c4f976d1437e81e9bd57ee98fde05fba8c6e80 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 3 Sep 2014 19:05:07 -0400 Subject: [PATCH 21/87] fix ios builds? --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 00df8795d..6e9c8393b 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="fab18042260ce8aff361bd62cf77edfa914413c0" +MP_HASH="fd05efbb95003e81257b8af071eceaa62a998c16" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From 2e2c7befac062505d3120c2f40f299dcd97771af Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 9 Sep 2014 17:09:03 -0400 Subject: [PATCH 22/87] bump MP_HASH --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 6e9c8393b..e95530498 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="fd05efbb95003e81257b8af071eceaa62a998c16" +MP_HASH="d58d6f18b99e5283b43940882da9ea18deea1227" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From 4316d2c40585e3d0dcdb25fa6f2341531025e20e Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 10 Sep 2014 14:24:29 -0400 Subject: [PATCH 23/87] make context active before clearing buffers --- common/headless_view.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index f790d90ce..0fce22398 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -113,6 +113,8 @@ void HeadlessView::resize(int width, int height) { } void HeadlessView::clear_buffers() { + make_active(); + #if MBGL_USE_CGL glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); From c004c036964e9012b08aa4a2f8b16094630d62be Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 24 Jun 2014 00:25:20 +1000 Subject: [PATCH 24/87] Add View::make_inactive() to remove context from rendering thread View::make_inactive() is called just before termination of the rendering thread. The implementation must clear the thread's GL context. This ensures there is no context still bound to a thread during GL shutdown. This is needed as GL will not actually delete a context until it is not active on any thread. Fixes mapbox/mapbox-gl-native#340 Conflicts: common/glfw_view.hpp include/llmr/map/view.hpp test/headless.cpp --- common/glfw_view.cpp | 4 ++++ common/glfw_view.hpp | 1 + common/headless_view.cpp | 13 +++++++++++++ common/headless_view.hpp | 1 + include/mbgl/map/view.hpp | 4 ++++ src/map/map.cpp | 2 ++ 6 files changed, 25 insertions(+) diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index f53090a00..724b8bf18 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -192,6 +192,10 @@ void GLFWView::make_active() { glfwMakeContextCurrent(window); } +void GLFWView::make_inactive() { + glfwMakeContextCurrent(nullptr); +} + void GLFWView::swap() { glfwPostEmptyEvent(); diff --git a/common/glfw_view.hpp b/common/glfw_view.hpp index d2f6872fc..04085f775 100644 --- a/common/glfw_view.hpp +++ b/common/glfw_view.hpp @@ -17,6 +17,7 @@ public: void initialize(mbgl::Map *map); void swap(); void make_active(); + void make_inactive(); void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0); static void key(GLFWwindow *window, int key, int scancode, int action, int mods); diff --git a/common/headless_view.cpp b/common/headless_view.cpp index f790d90ce..34326ae29 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -179,6 +179,19 @@ void HeadlessView::make_active() { #endif } +void HeadlessView::make_inactive() { +#if MBGL_USE_CGL + CGLError error = CGLSetCurrentContext(nullptr); + if (error) { + fprintf(stderr, "Removing OpenGL context failed\n"); + } +#endif + +#if MBGL_USE_GLX + // no-op +#endif +} + void HeadlessView::swap() {} unsigned int HeadlessView::root_fbo() { diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 0b255b4a3..a4432bbae 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -23,6 +23,7 @@ public: void notify_map_change(MapChange change, timestamp delay = 0); void make_active(); + void make_inactive(); void swap(); unsigned int root_fbo(); diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 92d60d4d0..3e2f1a4b5 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -35,6 +35,10 @@ public: // renderer setup since the render thread doesn't switch the contexts. virtual void make_active() = 0; + // Called from the render thread. Makes the GL context inactive in the current + // thread. This is called once just before the rendering thread terminates. + virtual void make_inactive() = 0; + // Returns the base framebuffer object, if any, and 0 if using the system // provided framebuffer. virtual unsigned int root_fbo() { diff --git a/src/map/map.cpp b/src/map/map.cpp index 9984f1b18..de7a7032d 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -114,6 +114,8 @@ void Map::run() { prepare(); render(); } + + view.make_inactive(); } void Map::rerender() { From 71549e7b93b6b44ed38e8915d8735c136889c3f1 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 24 Jun 2014 00:41:28 +1000 Subject: [PATCH 25/87] Adds the function Map::terminate() to allow all GL resources held by the map to be released immediately. Map::terminate() will call any GL functions on the current thread without blocking or defering to the rendering thread. This function allows a GL context to be destroyed and recreated safely without having to delete the Map object. Fixes mapbox/mapbox-gl-native#341 Conflicts: include/llmr/renderer/painter.hpp test/headless.cpp --- common/glfw_view.cpp | 5 ++++- include/mbgl/map/map.hpp | 3 +++ include/mbgl/renderer/painter.hpp | 2 ++ src/map/map.cpp | 6 ++++++ src/renderer/painter.cpp | 19 +++++++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp index 724b8bf18..0908786bb 100644 --- a/common/glfw_view.cpp +++ b/common/glfw_view.cpp @@ -8,7 +8,10 @@ GLFWView::GLFWView(bool fullscreen) : fullscreen(fullscreen) { #endif } -GLFWView::~GLFWView() { glfwTerminate(); } +GLFWView::~GLFWView() { + map->terminate(); + glfwTerminate(); +} void GLFWView::initialize(mbgl::Map *map) { View::initialize(map); diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index fba38879e..0d2926d04 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -53,6 +53,9 @@ public: // Triggers a cleanup that releases resources. void cleanup(); + // Releases resources immediately + void terminate(); + // Controls buffer swapping. bool needsSwap(); void swapped(); diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 75529d113..15331b9b6 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -63,6 +63,7 @@ public: // lazy initialization) in case rendering continues. void cleanup(); + void terminate(); // Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any // tiles whatsoever. @@ -123,6 +124,7 @@ public: private: void setupShaders(); + void deleteShaders(); mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const Tile::ID &id, TranslateAnchorType anchor); void prepareTile(const Tile& tile); diff --git a/src/map/map.cpp b/src/map/map.cpp index de7a7032d..00f0ac91c 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -153,6 +153,12 @@ void Map::cleanup(uv_async_t *async) { map->painter.cleanup(); } +void Map::terminate() { + view.make_active(); + painter.terminate(); + view.make_inactive(); +} + void Map::render(uv_async_t *async) { Map *map = static_cast(async->data); diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index c1705cd7c..b1522a56b 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -82,9 +82,28 @@ void Painter::setupShaders() { if (!gaussianShader) gaussianShader = std::make_unique(); } +void Painter::deleteShaders() { + plainShader = nullptr; + outlineShader = nullptr; + lineShader = nullptr; + linejoinShader = nullptr; + patternShader = nullptr; + iconShader = nullptr; + rasterShader = nullptr; + textShader = nullptr; + dotShader = nullptr; + compositeShader = nullptr; + gaussianShader = nullptr; +} + void Painter::cleanup() { } +void Painter::terminate() { + cleanup(); + deleteShaders(); +} + void Painter::resize() { const TransformState &state = map.getState(); if (gl_viewport != state.getFramebufferDimensions()) { From 7a4c914d05cab81ca55ac3cde478997c6d32477e Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 24 Jun 2014 16:19:47 +1000 Subject: [PATCH 26/87] Move notify_map_change() from a global callback, to a callback in View. This allows for their to me more than one Map object alive at a time. Fixes mapbox/mapbox-gl-native#346 Conflicts: common/glfw_view.hpp include/llmr/map/view.hpp include/mbgl/map/transform.hpp src/map/map.cpp src/map/transform.cpp test/headless.cpp --- src/map/map.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index 00f0ac91c..e6c4e9d03 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -156,7 +156,6 @@ void Map::cleanup(uv_async_t *async) { void Map::terminate() { view.make_active(); painter.terminate(); - view.make_inactive(); } void Map::render(uv_async_t *async) { From 89f54e8789d799d3e7db24ef6ae281ca22fb715b Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 10 Sep 2014 19:00:28 -0400 Subject: [PATCH 27/87] update Painter::deleteShaders --- src/renderer/painter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index b1522a56b..0d01fd166 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -87,12 +87,13 @@ void Painter::deleteShaders() { outlineShader = nullptr; lineShader = nullptr; linejoinShader = nullptr; + linepatternShader = nullptr; patternShader = nullptr; iconShader = nullptr; rasterShader = nullptr; - textShader = nullptr; + sdfGlyphShader = nullptr; + sdfIconShader = nullptr; dotShader = nullptr; - compositeShader = nullptr; gaussianShader = nullptr; } From c03beb070b205ef0d5dbceaa5fa3d8dd340ad1fd Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 10 Sep 2014 19:15:03 -0400 Subject: [PATCH 28/87] fix Map::terminate? --- src/map/map.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index 6da514d16..baa82e6c5 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -115,7 +115,7 @@ void Map::run() { render(); } - view.make_inactive(); + terminate(); } void Map::rerender() { @@ -156,6 +156,7 @@ void Map::cleanup(uv_async_t *async, int status) { void Map::terminate() { view.make_active(); painter.terminate(); + view.make_inactive(); } void Map::render(uv_async_t *async, int status) { From 57fb4b984d681fd56c58edc1840cc95c0582f503 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 10 Sep 2014 19:23:40 -0400 Subject: [PATCH 29/87] don't terminate after Map::run --- src/map/map.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index baa82e6c5..10310ee16 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -114,8 +114,6 @@ void Map::run() { prepare(); render(); } - - terminate(); } void Map::rerender() { From d9ccc501c3d61f928479faf78ee21eb81b8cbdf3 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 10 Sep 2014 19:42:06 -0400 Subject: [PATCH 30/87] add GLX support to HeadlessView::make_inactive --- common/headless_view.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 0b4d7ce64..9fa75700a 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -190,7 +190,9 @@ void HeadlessView::make_inactive() { #endif #if MBGL_USE_GLX - // no-op + if (!glXMakeCurrent(x_display, None, nullptr)) { + fprintf(stderr, "Removing OpenGL context failed\n"); + } #endif } From f93a230e977522eba42046a2f6511cb776861aa7 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 11 Sep 2014 09:48:12 -0400 Subject: [PATCH 31/87] drop clear_buffers and glx make_inactive from descrtuctor --- common/headless_view.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 9fa75700a..ff903939b 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -148,14 +148,11 @@ void HeadlessView::clear_buffers() { } HeadlessView::~HeadlessView() { - clear_buffers(); - #if MBGL_USE_CGL CGLDestroyContext(gl_context); #endif #if MBGL_USE_GLX - glXMakeCurrent(x_display, None, NULL); glXDestroyContext(x_display, gl_context); XFree(x_info); XCloseDisplay(x_display); From 1f7c591bc45d95f9bdecc109fd4a3ddf6592e42d Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 11 Sep 2014 09:59:08 -0400 Subject: [PATCH 32/87] clear_buffers in make_inactive, call make_inactive in destructor --- common/headless_view.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index ff903939b..563fd8f24 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -148,6 +148,8 @@ void HeadlessView::clear_buffers() { } HeadlessView::~HeadlessView() { + make_inactive(); + #if MBGL_USE_CGL CGLDestroyContext(gl_context); #endif @@ -179,6 +181,8 @@ void HeadlessView::make_active() { } void HeadlessView::make_inactive() { + clear_buffers(); + #if MBGL_USE_CGL CGLError error = CGLSetCurrentContext(nullptr); if (error) { From 70aaf8d343ab0dc80993038bd13148b20de0b83e Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 11 Sep 2014 10:09:30 -0400 Subject: [PATCH 33/87] pass NULL instead of nullptr to glXMakdeCurrent --- common/headless_view.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 563fd8f24..355206a3e 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -191,7 +191,7 @@ void HeadlessView::make_inactive() { #endif #if MBGL_USE_GLX - if (!glXMakeCurrent(x_display, None, nullptr)) { + if (!glXMakeCurrent(x_display, None, NULL)) { fprintf(stderr, "Removing OpenGL context failed\n"); } #endif From 9d369ec742f00e35fea97fe24415ecaaaad1f01a Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 16 Sep 2014 18:00:52 -0400 Subject: [PATCH 34/87] dont make_active when clearing buffers, call make_inactive at end of Map::prepare() --- common/headless_view.cpp | 4 ---- src/map/map.cpp | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 355206a3e..c2e402c0b 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -113,8 +113,6 @@ void HeadlessView::resize(int width, int height) { } void HeadlessView::clear_buffers() { - make_active(); - #if MBGL_USE_CGL glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -181,8 +179,6 @@ void HeadlessView::make_active() { } void HeadlessView::make_inactive() { - clear_buffers(); - #if MBGL_USE_CGL CGLError error = CGLSetCurrentContext(nullptr); if (error) { diff --git a/src/map/map.cpp b/src/map/map.cpp index 10310ee16..64940af9e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -154,7 +154,6 @@ void Map::cleanup(uv_async_t *async, int status) { void Map::terminate() { view.make_active(); painter.terminate(); - view.make_inactive(); } void Map::render(uv_async_t *async, int status) { @@ -545,6 +544,8 @@ void Map::prepare() { spriteAtlas->update(*getSprite()); updateTiles(); + + view.make_inactive(); } void Map::render() { From d48e5e72213851e4ffb443eae1b6243f491682c3 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 16 Sep 2014 18:06:24 -0400 Subject: [PATCH 35/87] make_active only for CGL in clear_buffers --- common/headless_view.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index c2e402c0b..8ea1b1370 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -114,6 +114,8 @@ void HeadlessView::resize(int width, int height) { void HeadlessView::clear_buffers() { #if MBGL_USE_CGL + make_active(); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); if (fbo) { From 65df83ce4c0ccb410f3d6a9841aeea621483f0be Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 19 Sep 2014 16:16:44 -0400 Subject: [PATCH 36/87] bump mapnik-packaging, remove unnecessary view.make_active calls --- common/headless_view.cpp | 5 ++--- setup-libraries.sh | 2 +- src/map/map.cpp | 13 ++++--------- test/headless.cpp | 2 ++ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 8ea1b1370..4ad22da9a 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -106,10 +106,7 @@ void HeadlessView::resize(int width, int height) { #if MBGL_USE_GLX x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), width, height, 32); glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap); - - make_active(); #endif - } void HeadlessView::clear_buffers() { @@ -132,6 +129,8 @@ void HeadlessView::clear_buffers() { glDeleteRenderbuffersEXT(1, &fbo_depth_stencil); fbo_depth_stencil = 0; } + + make_inactive(); #endif #if MBGL_USE_GLX diff --git a/setup-libraries.sh b/setup-libraries.sh index e95530498..7d205ac4e 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="d58d6f18b99e5283b43940882da9ea18deea1227" +MP_HASH="8239a894fecdfc001016a4669bc5ca289763048f" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git diff --git a/src/map/map.cpp b/src/map/map.cpp index 64940af9e..6db6fa280 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -111,7 +111,6 @@ void Map::run() { // If the map rendering wasn't started asynchronously, we perform one render // *after* all events have been processed. if (!async) { - prepare(); render(); } } @@ -147,12 +146,10 @@ void Map::cleanup() { void Map::cleanup(uv_async_t *async, int status) { Map *map = static_cast(async->data); - map->view.make_active(); map->painter.cleanup(); } void Map::terminate() { - view.make_active(); painter.terminate(); } @@ -189,8 +186,6 @@ void Map::terminate(uv_async_t *async, int status) { #pragma mark - Setup void Map::setup() { - view.make_active(); - painter.setup(); } @@ -525,8 +520,6 @@ void Map::updateRenderState() { } void Map::prepare() { - view.make_active(); - // Update transform transitions. animationTime = util::now(); if (transform.needsTransition()) { @@ -544,11 +537,11 @@ void Map::prepare() { spriteAtlas->update(*getSprite()); updateTiles(); - - view.make_inactive(); } void Map::render() { + view.make_active(); + #if defined(DEBUG) std::vector debug; #endif @@ -583,6 +576,8 @@ void Map::render() { } glFlush(); + + view.make_inactive(); } void Map::renderLayers(std::shared_ptr group) { diff --git a/test/headless.cpp b/test/headless.cpp index 4299fd79b..9a4857dd1 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -91,7 +91,9 @@ TEST_P(HeadlessTest, render) { map.run(); const std::unique_ptr pixels(new uint32_t[width * height]); + map.view.make_active(); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); + map.view.make_inactive(); const std::string image = util::compress_png(width, height, pixels.get(), true); util::write_file(actual_image, image); From 8e1bbae81f61d7a5a86c959b0880a2a18842264b Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 22 Sep 2014 18:06:24 -0400 Subject: [PATCH 37/87] bump mapnik-packaging --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index a605241da..7947efe49 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="d58d6f18b99e5283b43940882da9ea18deea1227" +MP_HASH="c0fc970e52950a6f16e3172f1114e5a4ae1e0aa9" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From 0cdaf58027b758650f4bb7ca7a006cb8568c080c Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 14:40:49 -0400 Subject: [PATCH 38/87] add debugging --- common/headless_view.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 0fce22398..d38a45007 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace mbgl { @@ -155,6 +156,10 @@ HeadlessView::~HeadlessView() { #endif #if MBGL_USE_GLX + std::cerr << "~HeadlessView()" << '\n'; + std::cerr << "x_display: " << x_display << '\n'; + std::cerr << "glx_pixmap: " << glx_pixmap << '\n'; + std::cerr << "gl_context: " << gl_context << '\n'; glXMakeCurrent(x_display, None, NULL); glXDestroyContext(x_display, gl_context); XFree(x_info); @@ -175,6 +180,10 @@ void HeadlessView::make_active() { #endif #if MBGL_USE_GLX + std::cerr << "make_active()" << '\n'; + std::cerr << "x_display: " << x_display << '\n'; + std::cerr << "glx_pixmap: " << glx_pixmap << '\n'; + std::cerr << "gl_context: " << gl_context << '\n'; if (!glXMakeCurrent(x_display, glx_pixmap, gl_context)) { fprintf(stderr, "Switching OpenGL context failed\n"); } From c5a7738dd640604a523e6e069cba92940d502614 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 15:17:42 -0400 Subject: [PATCH 39/87] move make_active call into MBGL_USE_CGL block --- common/headless_view.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index d38a45007..6ab005b6c 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -114,9 +114,9 @@ void HeadlessView::resize(int width, int height) { } void HeadlessView::clear_buffers() { +#if MBGL_USE_CGL make_active(); -#if MBGL_USE_CGL glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); if (fbo) { From 47c6bb5bd49b1535208a7d20e2646c21ab9687ff Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 16:10:36 -0400 Subject: [PATCH 40/87] update MP_HASH --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 7947efe49..a4fc59b93 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="c0fc970e52950a6f16e3172f1114e5a4ae1e0aa9" +MP_HASH="573abb5e0bfb87798172f6f9b90094e9efc58ad9" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From 86b7367994c933c1b91d571d348ec57620c7d26c Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 16:30:01 -0400 Subject: [PATCH 41/87] Revert "add debugging" This reverts commit 0cdaf58027b758650f4bb7ca7a006cb8568c080c. --- common/headless_view.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 94a6cd03b..42d595310 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -2,7 +2,6 @@ #include #include -#include namespace mbgl { @@ -159,10 +158,6 @@ HeadlessView::~HeadlessView() { #endif #if MBGL_USE_GLX - std::cerr << "~HeadlessView()" << '\n'; - std::cerr << "x_display: " << x_display << '\n'; - std::cerr << "glx_pixmap: " << glx_pixmap << '\n'; - std::cerr << "gl_context: " << gl_context << '\n'; glXMakeCurrent(x_display, None, NULL); glXDestroyContext(x_display, gl_context); XFree(x_info); @@ -183,10 +178,6 @@ void HeadlessView::make_active() { #endif #if MBGL_USE_GLX - std::cerr << "make_active()" << '\n'; - std::cerr << "x_display: " << x_display << '\n'; - std::cerr << "glx_pixmap: " << glx_pixmap << '\n'; - std::cerr << "gl_context: " << gl_context << '\n'; if (!glXMakeCurrent(x_display, glx_pixmap, gl_context)) { fprintf(stderr, "Switching OpenGL context failed\n"); } From 735d2456974f7a7c870c2c15c1cfaf0d7ad07c3b Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 16:40:10 -0400 Subject: [PATCH 42/87] fix ios builds? --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index a4fc59b93..b110390a2 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="573abb5e0bfb87798172f6f9b90094e9efc58ad9" +MP_HASH="e2beefa4b52ab81dd8578f0d1a822e4a6e434d99" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From 768e23069c191dd73dd99985d0a620c581b0036d Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 17:11:18 -0400 Subject: [PATCH 43/87] build iPhoneSimulator64 against libuv 0.10.28 --- setup-libraries.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/setup-libraries.sh b/setup-libraries.sh index b110390a2..20fa5568b 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -104,6 +104,7 @@ export LIBUV_VERSION=0.10.28 echo ' ...done' source iPhoneSimulator64.sh +export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libcpp-x86_64-iphonesimulator/lib/libpng.a ] ; then ./scripts/build_png.sh ; fi if [ ! -f out/build-cpp11-libcpp-x86_64-iphonesimulator/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi echo ' ...done' From 92d00347a87eee10b961d4a1836c1dd6e1df6ba7 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 18:51:52 -0400 Subject: [PATCH 44/87] remove travis conditional in darwin_configure.sh --- setup-libraries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 20fa5568b..791db81a8 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -51,7 +51,7 @@ set -u NODE=$(which node) NPM=$(which npm) -MP_HASH="e2beefa4b52ab81dd8578f0d1a822e4a6e434d99" +MP_HASH="e82e6c00ea5a0cda147e4c121a3c7751cae69ff8" DIR_HASH=$(echo `pwd` | git hash-object --stdin) if [ ! -d 'mapnik-packaging/' ]; then git clone https://github.com/mapnik/mapnik-packaging.git From dffeaa07877c59a6a586545e45c4f6339b789a6d Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 24 Sep 2014 23:03:50 -0400 Subject: [PATCH 45/87] make active after resize --- common/headless_view.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 37982e689..9dee14b39 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -109,6 +109,8 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { #if MBGL_USE_GLX x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), width, height, 32); glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap); + + make_active(); #endif } From 40562594083e4e7bbe78a673d2f656dc9baee65a Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 25 Sep 2014 12:17:26 -0400 Subject: [PATCH 46/87] implement make_inactive in mapbox-gl-cocoa --- ios/mapbox-gl-cocoa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 461024ae4..1aa3db196 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 461024ae406fd98b7a27d3297298cf68284e32ad +Subproject commit 1aa3db196b210c6880df6b2aff5e0d924aa78764 From 8e6967669a64d9bc38428fe59fae171a9ac02919 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 25 Sep 2014 18:06:55 -0400 Subject: [PATCH 47/87] make inactive at end of clear_buffers() --- common/headless_view.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 9dee14b39..3fc3816f0 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -148,11 +148,13 @@ void HeadlessView::clear_buffers() { XFreePixmap(x_display, x_pixmap); x_pixmap = 0; } + + make_inactive(); #endif } HeadlessView::~HeadlessView() { - make_inactive(); + clear_buffers(); #if MBGL_USE_CGL CGLDestroyContext(gl_context); From 8ebe1bc36033cfbfe9cad5a2a9ef6b5cc803c38e Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 29 Sep 2014 16:33:26 -0400 Subject: [PATCH 48/87] add more possible errors returned by glCheckFramebufferStatusEXT from https://www.opengl.org/registry/specs/EXT/framebuffer_object.txt --- common/headless_view.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 3fc3816f0..e52bbf8b9 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -98,7 +98,10 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { switch (status) { case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: fprintf(stderr, "incomplete attachment\n"); break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: fprintf(stderr, "incomplete missing attachment\n"); break; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: fprintf(stderr, "incomplete dimensions\n"); break; + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: fprintf(stderr, "incomplete formats\n"); break; case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: fprintf(stderr, "incomplete draw buffer\n"); break; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: fprintf(stderr, "incomplete read buffer\n"); break; case GL_FRAMEBUFFER_UNSUPPORTED: fprintf(stderr, "unsupported\n"); break; default: fprintf(stderr, "other\n"); break; } From 848dccbcae8eb3ddf61b0d9344e150b721a8cf75 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 30 Sep 2014 12:06:51 -0400 Subject: [PATCH 49/87] make view active/inactive around Map::setup, don't leave active after view.resize() --- common/headless_view.cpp | 4 ++-- src/map/map.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index e52bbf8b9..61531bfd6 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -107,13 +107,13 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { } return; } + + make_inactive(); #endif #if MBGL_USE_GLX x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), width, height, 32); glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap); - - make_active(); #endif } diff --git a/src/map/map.cpp b/src/map/map.cpp index 6db6fa280..ad8749ff0 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -186,7 +186,9 @@ void Map::terminate(uv_async_t *async, int status) { #pragma mark - Setup void Map::setup() { + view.make_active(); painter.setup(); + view.make_inactive(); } void Map::setStyleURL(const std::string &url) { From c4c4b3318a89c0a7548040f7182fb043704e230f Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 30 Sep 2014 17:42:27 -0400 Subject: [PATCH 50/87] log CGLErrorString for CGLChoosePixelFormat, enable OpenGL multithreading https://developer.apple.com/library/mac/technotes/tn2085/_index.html --- common/headless_view.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 61531bfd6..10888f7a7 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -20,7 +20,7 @@ HeadlessView::HeadlessView() { GLint num; CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num); if (error) { - fprintf(stderr, "Error pixel format\n"); + fprintf(stderr, "Error pixel format: %s\n", CGLErrorString(error)); return; } @@ -30,6 +30,12 @@ HeadlessView::HeadlessView() { fprintf(stderr, "Error creating GL context object\n"); return; } + + error = CGLEnable(gl_context, kCGLCEMPEngine); + if (error != kCGLNoError ) { + fprintf(stderr, "Error enabling OpenGL multithreading\n"); + return; + } #endif #if MBGL_USE_GLX From 0f1d33f5ee29adf9b62c912339935fdde44b0b98 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 3 Oct 2014 18:31:38 -0400 Subject: [PATCH 51/87] break out HeadlessDisplay from HeadlessView, ref #478 --- common/headless_display.cpp | 65 +++++++++++++++++++++++++++++++++++++ common/headless_display.hpp | 32 ++++++++++++++++++ common/headless_view.cpp | 60 ++++++++-------------------------- common/headless_view.hpp | 22 ++++++------- test/test.gyp | 2 ++ 5 files changed, 122 insertions(+), 59 deletions(-) create mode 100644 common/headless_display.cpp create mode 100644 common/headless_display.hpp diff --git a/common/headless_display.cpp b/common/headless_display.cpp new file mode 100644 index 000000000..580d3ef58 --- /dev/null +++ b/common/headless_display.cpp @@ -0,0 +1,65 @@ +#include "headless_view.hpp" + +#include + +namespace mbgl { + +HeadlessDisplay::HeadlessDisplay() { +#if MBGL_USE_CGL + // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported + // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension. + CGLPixelFormatAttribute attributes[] = { + kCGLPFAOpenGLProfile, + (CGLPixelFormatAttribute) kCGLOGLPVersion_Legacy, + kCGLPFAAccelerated, + (CGLPixelFormatAttribute) 0 + }; + + GLint num; + CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num); + if (error) { + fprintf(stderr, "Error pixel format: %s\n", CGLErrorString(error)); + return; + } +#endif + +#if MBGL_USE_GLX + x_display = XOpenDisplay(0); + + if (x_display == nullptr) { + throw std::runtime_error("Failed to open X display"); + } + + static int pixelFormat[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_STENCIL_SIZE, 8, + None + }; + + x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat); + + if (x_info == nullptr) { + throw std::runtime_error("Error pixel format"); + } +#endif +} + +HeadlessDisplay::~HeadlessDisplay() { +#if MBGL_USE_CGL + CGLDestroyPixelFormat(pixelFormat); +#endif + +#if MBGL_USE_GLX + XFree(x_info); + XCloseDisplay(x_display); +#endif +} + +} + diff --git a/common/headless_display.hpp b/common/headless_display.hpp new file mode 100644 index 000000000..4fc03da08 --- /dev/null +++ b/common/headless_display.hpp @@ -0,0 +1,32 @@ +#ifndef MBGL_COMMON_HEADLESS_DISPLAY +#define MBGL_COMMON_HEADLESS_DISPLAY + +#ifdef __APPLE__ +#define MBGL_USE_CGL 1 +#else +#include +#define MBGL_USE_GLX 1 +#endif + +#include + +namespace mbgl { + +class HeadlessDisplay { +public: + HeadlessDisplay(); + ~HeadlessDisplay(); + +#if MBGL_USE_CGL + CGLPixelFormatObj pixelFormat; +#endif + +#if MBGL_USE_GLX + Display *x_display = nullptr; + XVisualInfo *x_info = nullptr; +#endif +}; + +} + +#endif diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 10888f7a7..47cf3bd66 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -1,31 +1,21 @@ #include "headless_view.hpp" -#include #include namespace mbgl { -HeadlessView::HeadlessView() { +HeadlessView::HeadlessView() : display_(new HeadlessDisplay()) { + createContext(); +} + +HeadlessView::HeadlessView(HeadlessDisplay *display) + : display_(display) { + createContext(); +} + +void HeadlessView::createContext() { #if MBGL_USE_CGL - // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported - // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension. - CGLPixelFormatAttribute attributes[] = { - kCGLPFAOpenGLProfile, - (CGLPixelFormatAttribute) kCGLOGLPVersion_Legacy, - kCGLPFAAccelerated, - (CGLPixelFormatAttribute) 0 - }; - - CGLPixelFormatObj pixelFormat; - GLint num; - CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num); - if (error) { - fprintf(stderr, "Error pixel format: %s\n", CGLErrorString(error)); - return; - } - - error = CGLCreateContext(pixelFormat, NULL, &gl_context); - CGLDestroyPixelFormat(pixelFormat); + CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context); if (error) { fprintf(stderr, "Error creating GL context object\n"); return; @@ -39,29 +29,8 @@ HeadlessView::HeadlessView() { #endif #if MBGL_USE_GLX - x_display = XOpenDisplay(0); - - if (x_display == nullptr) { - throw std::runtime_error("Failed to open X display"); - } - - static int pixelFormat[] = { - GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_ALPHA_SIZE, 8, - GLX_DEPTH_SIZE, 24, - GLX_STENCIL_SIZE, 8, - None - }; - - x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat); - - if (x_info == nullptr) { - throw std::runtime_error("Error pixel format"); - } + x_display = display_->x_display; + x_info = display_->x_info; gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE); if (gl_context == nullptr) { @@ -70,7 +39,6 @@ HeadlessView::HeadlessView() { #endif } - void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { clear_buffers(); @@ -171,8 +139,6 @@ HeadlessView::~HeadlessView() { #if MBGL_USE_GLX glXDestroyContext(x_display, gl_context); - XFree(x_info); - XCloseDisplay(x_display); #endif } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index c8475a251..d1b09ce70 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -1,24 +1,20 @@ -#ifndef MBGL_COMMON_HEADLESS_CGL -#define MBGL_COMMON_HEADLESS_CGL +#ifndef MBGL_COMMON_HEADLESS_VIEW +#define MBGL_COMMON_HEADLESS_VIEW -#ifdef __APPLE__ -#define MBGL_USE_CGL 1 -#else -#include -#define MBGL_USE_GLX 1 -#endif +#include "headless_display.hpp" #include -#include -#include namespace mbgl { class HeadlessView : public View { public: HeadlessView(); + HeadlessView(HeadlessDisplay *display); ~HeadlessView(); + void createContext(); + void resize(uint16_t width, uint16_t height, float pixelRatio); void notify_map_change(MapChange change, timestamp delay = 0); @@ -32,6 +28,8 @@ private: private: + HeadlessDisplay *display_; + #if MBGL_USE_CGL CGLContextObj gl_context; GLuint fbo = 0; @@ -40,9 +38,9 @@ private: #endif #if MBGL_USE_GLX - GLXContext gl_context = nullptr; - XVisualInfo *x_info = nullptr; Display *x_display = nullptr; + XVisualInfo *x_info = nullptr; + GLXContext gl_context = nullptr; Pixmap x_pixmap = 0; GLXPixmap glx_pixmap = 0; #endif diff --git a/test/test.gyp b/test/test.gyp index fd7725bb0..1ebaf6cc1 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -201,6 +201,8 @@ "./headless.cpp", "../common/headless_view.hpp", "../common/headless_view.cpp", + "../common/headless_display.hpp", + "../common/headless_display.cpp", "../common/platform_default.cpp", "./fixtures/fixture_request.cpp", "./fixtures/fixture_log.hpp", From 170ce422ceb20126cd7dc7b184b5edbc0685c7e7 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 6 Oct 2014 15:45:14 -0400 Subject: [PATCH 52/87] forward declare HeadlessDisplay in headless_view.hpp --- common/headless_display.cpp | 2 +- common/headless_display.hpp | 9 +-------- common/headless_view.cpp | 1 + common/headless_view.hpp | 10 +++++++++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/headless_display.cpp b/common/headless_display.cpp index 580d3ef58..38d123034 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -1,4 +1,4 @@ -#include "headless_view.hpp" +#include "headless_display.hpp" #include diff --git a/common/headless_display.hpp b/common/headless_display.hpp index 4fc03da08..0eb41911e 100644 --- a/common/headless_display.hpp +++ b/common/headless_display.hpp @@ -1,14 +1,7 @@ #ifndef MBGL_COMMON_HEADLESS_DISPLAY #define MBGL_COMMON_HEADLESS_DISPLAY -#ifdef __APPLE__ -#define MBGL_USE_CGL 1 -#else -#include -#define MBGL_USE_GLX 1 -#endif - -#include +#include "headless_view.hpp" namespace mbgl { diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 47cf3bd66..86fa445fc 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -1,4 +1,5 @@ #include "headless_view.hpp" +#include "headless_display.hpp" #include diff --git a/common/headless_view.hpp b/common/headless_view.hpp index d1b09ce70..381988ae9 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -1,12 +1,20 @@ #ifndef MBGL_COMMON_HEADLESS_VIEW #define MBGL_COMMON_HEADLESS_VIEW -#include "headless_display.hpp" +#ifdef __APPLE__ +#define MBGL_USE_CGL 1 +#else +#include +#define MBGL_USE_GLX 1 +#endif #include +#include namespace mbgl { +class HeadlessDisplay; + class HeadlessView : public View { public: HeadlessView(); From 8b06b65f35445a1dc8490ede523a23fab46529fa Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 6 Oct 2014 16:53:57 -0400 Subject: [PATCH 53/87] wrap GL/glx.h with undef None, use 0 instead, h/t @jfirebaugh --- common/glx.h | 2 ++ common/headless_display.cpp | 2 +- common/headless_view.cpp | 2 +- common/headless_view.hpp | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 common/glx.h diff --git a/common/glx.h b/common/glx.h new file mode 100644 index 000000000..6b7d9a3df --- /dev/null +++ b/common/glx.h @@ -0,0 +1,2 @@ +#include +#undef None diff --git a/common/headless_display.cpp b/common/headless_display.cpp index 38d123034..b183b0a50 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -39,7 +39,7 @@ HeadlessDisplay::HeadlessDisplay() { GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, - None + 0 }; x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat); diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 86fa445fc..cd8ee685d 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -171,7 +171,7 @@ void HeadlessView::make_inactive() { #endif #if MBGL_USE_GLX - if (!glXMakeCurrent(x_display, None, NULL)) { + if (!glXMakeCurrent(x_display, 0, NULL)) { fprintf(stderr, "Removing OpenGL context failed\n"); } #endif diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 381988ae9..cef4213e9 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -4,7 +4,7 @@ #ifdef __APPLE__ #define MBGL_USE_CGL 1 #else -#include +#include "glx.h" #define MBGL_USE_GLX 1 #endif From 41dac96408a08e3ad2fca7bbe1e7572db85acd13 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 6 Oct 2014 18:05:10 -0400 Subject: [PATCH 54/87] use shared_ptr for HeadlessDisplay in HeadlessView --- common/headless_view.cpp | 12 ++++++------ common/headless_view.hpp | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index cd8ee685d..5e8770b7a 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -5,18 +5,18 @@ namespace mbgl { -HeadlessView::HeadlessView() : display_(new HeadlessDisplay()) { +HeadlessView::HeadlessView() : display_ptr(std::make_shared()) { createContext(); } -HeadlessView::HeadlessView(HeadlessDisplay *display) - : display_(display) { +HeadlessView::HeadlessView(HeadlessDisplay &display) + : display_ptr(std::make_shared(display)) { createContext(); } void HeadlessView::createContext() { #if MBGL_USE_CGL - CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context); + CGLError error = CGLCreateContext(display_ptr->pixelFormat, NULL, &gl_context); if (error) { fprintf(stderr, "Error creating GL context object\n"); return; @@ -30,8 +30,8 @@ void HeadlessView::createContext() { #endif #if MBGL_USE_GLX - x_display = display_->x_display; - x_info = display_->x_info; + x_display = display_ptr->x_display; + x_info = display_ptr->x_info; gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE); if (gl_context == nullptr) { diff --git a/common/headless_view.hpp b/common/headless_view.hpp index cef4213e9..5303f2c10 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -11,6 +11,8 @@ #include #include +#include + namespace mbgl { class HeadlessDisplay; @@ -18,7 +20,7 @@ class HeadlessDisplay; class HeadlessView : public View { public: HeadlessView(); - HeadlessView(HeadlessDisplay *display); + HeadlessView(HeadlessDisplay &display); ~HeadlessView(); void createContext(); @@ -36,7 +38,7 @@ private: private: - HeadlessDisplay *display_; + std::shared_ptr display_ptr; #if MBGL_USE_CGL CGLContextObj gl_context; From 5cc6b26229597ef78bd87d21367b75f2051b7314 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 6 Oct 2014 18:24:01 -0400 Subject: [PATCH 55/87] clean up shared_ptr usage --- common/headless_view.cpp | 12 ++++++------ common/headless_view.hpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 5e8770b7a..b8a2fa360 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -5,18 +5,18 @@ namespace mbgl { -HeadlessView::HeadlessView() : display_ptr(std::make_shared()) { +HeadlessView::HeadlessView() : display_ptr_(std::make_shared()) { createContext(); } -HeadlessView::HeadlessView(HeadlessDisplay &display) - : display_ptr(std::make_shared(display)) { +HeadlessView::HeadlessView(std::shared_ptr display_ptr) + : display_ptr_(display_ptr) { createContext(); } void HeadlessView::createContext() { #if MBGL_USE_CGL - CGLError error = CGLCreateContext(display_ptr->pixelFormat, NULL, &gl_context); + CGLError error = CGLCreateContext(display_ptr_->pixelFormat, NULL, &gl_context); if (error) { fprintf(stderr, "Error creating GL context object\n"); return; @@ -30,8 +30,8 @@ void HeadlessView::createContext() { #endif #if MBGL_USE_GLX - x_display = display_ptr->x_display; - x_info = display_ptr->x_info; + x_display = display_ptr_->x_display; + x_info = display_ptr_->x_info; gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE); if (gl_context == nullptr) { diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 5303f2c10..3ad5a669a 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -20,7 +20,7 @@ class HeadlessDisplay; class HeadlessView : public View { public: HeadlessView(); - HeadlessView(HeadlessDisplay &display); + HeadlessView(std::shared_ptr display_ptr); ~HeadlessView(); void createContext(); @@ -38,7 +38,7 @@ private: private: - std::shared_ptr display_ptr; + std::shared_ptr display_ptr_; #if MBGL_USE_CGL CGLContextObj gl_context; From 36b7bb0c0991b3c5c3a7d001139b120bee854484 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 7 Oct 2014 16:26:21 -0400 Subject: [PATCH 56/87] clean up shared_ptr usage in HeadlessView --- common/headless_view.cpp | 12 ++++++------ common/headless_view.hpp | 4 ++-- test/headless.cpp | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index b8a2fa360..d11f63dbd 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -5,18 +5,18 @@ namespace mbgl { -HeadlessView::HeadlessView() : display_ptr_(std::make_shared()) { +HeadlessView::HeadlessView() : display_(std::make_shared()) { createContext(); } -HeadlessView::HeadlessView(std::shared_ptr display_ptr) - : display_ptr_(display_ptr) { +HeadlessView::HeadlessView(std::shared_ptr display) + : display_(display) { createContext(); } void HeadlessView::createContext() { #if MBGL_USE_CGL - CGLError error = CGLCreateContext(display_ptr_->pixelFormat, NULL, &gl_context); + CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context); if (error) { fprintf(stderr, "Error creating GL context object\n"); return; @@ -30,8 +30,8 @@ void HeadlessView::createContext() { #endif #if MBGL_USE_GLX - x_display = display_ptr_->x_display; - x_info = display_ptr_->x_info; + x_display = display_->x_display; + x_info = display_->x_info; gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE); if (gl_context == nullptr) { diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 3ad5a669a..13a5b0109 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -20,7 +20,7 @@ class HeadlessDisplay; class HeadlessView : public View { public: HeadlessView(); - HeadlessView(std::shared_ptr display_ptr); + HeadlessView(std::shared_ptr display); ~HeadlessView(); void createContext(); @@ -38,7 +38,7 @@ private: private: - std::shared_ptr display_ptr_; + std::shared_ptr display_; #if MBGL_USE_CGL CGLContextObj gl_context; diff --git a/test/headless.cpp b/test/headless.cpp index d4c4d6036..981a9dcd5 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -10,6 +10,7 @@ #include #include "../common/headless_view.hpp" +#include "../common/headless_display.hpp" #include "./fixtures/fixture_log.hpp" @@ -22,6 +23,8 @@ const std::string base_directory = []{ return fn + "/node_modules/mapbox-gl-test-suite/"; }(); +auto display_ = std::make_shared(); + class HeadlessTest : public ::testing::TestWithParam {}; TEST_P(HeadlessTest, render) { @@ -78,7 +81,7 @@ TEST_P(HeadlessTest, render) { } } - HeadlessView view; + HeadlessView view(display_); Map map(view); map.setStyleJSON(style, base_directory); From 91f40daa6911f57f3dca534080241b46844c71b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 8 Oct 2014 15:27:33 +0200 Subject: [PATCH 57/87] don't do concurrent access to a static member variable in situations where the renderer is used from multiple threads, this causes memory corruption. fixes mapbox/node-mapbox-gl-native#7 --- include/mbgl/style/class_dictionary.hpp | 13 +++++++--- src/style/class_dictionary.cpp | 34 ++++++++++++++++++++----- src/style/style_layer.cpp | 2 +- src/style/style_parser.cpp | 2 +- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/include/mbgl/style/class_dictionary.hpp b/include/mbgl/style/class_dictionary.hpp index c7f9c6a28..ecf80be3e 100644 --- a/include/mbgl/style/class_dictionary.hpp +++ b/include/mbgl/style/class_dictionary.hpp @@ -14,17 +14,22 @@ enum class ClassID : uint32_t { }; class ClassDictionary { +private: + ClassDictionary(); + public: + static ClassDictionary &Get(); + // Returns an ID for a class name. If the class name does not yet have an ID, one is // auto-generated and stored for future reference. - static ClassID Lookup(const std::string &class_name); + ClassID lookup(const std::string &class_name); // Returns either Fallback, Default or Named, depending on the type of the class id. - static ClassID Normalize(ClassID id); + ClassID normalize(ClassID id); private: - static std::unordered_map store; - static uint32_t offset; + std::unordered_map store = { { "", ClassID::Default } }; + uint32_t offset = 0; }; } diff --git a/src/style/class_dictionary.cpp b/src/style/class_dictionary.cpp index 6e1eb5a87..ba7c0d55b 100644 --- a/src/style/class_dictionary.cpp +++ b/src/style/class_dictionary.cpp @@ -1,8 +1,34 @@ #include +#include + namespace mbgl { -ClassID ClassDictionary::Lookup(const std::string &class_name) { +ClassDictionary::ClassDictionary() {} + +ClassDictionary &ClassDictionary::Get() { + // Note: We should eventually switch to uv_key_* functions, but libuv 0.10 doesn't have these + // yet. Instead, we're using the pthread functions directly for now. + static pthread_once_t store_once = PTHREAD_ONCE_INIT; + static pthread_key_t store_key; + + // Create the key. + pthread_once(&store_once, []() { + pthread_key_create(&store_key, [](void *ptr) { + delete reinterpret_cast(ptr); + }); + }); + + ClassDictionary *ptr = reinterpret_cast(pthread_getspecific(store_key)); + if (ptr == nullptr) { + ptr = new ClassDictionary(); + pthread_setspecific(store_key, ptr); + } + + return *ptr; +} + +ClassID ClassDictionary::lookup(const std::string &class_name) { auto it = store.find(class_name); if (it == store.end()) { // Insert the class name into the store. @@ -14,7 +40,7 @@ ClassID ClassDictionary::Lookup(const std::string &class_name) { } } -ClassID ClassDictionary::Normalize(ClassID id) { +ClassID ClassDictionary::normalize(ClassID id) { if (id >= ClassID::Named) { return ClassID::Named; } else { @@ -22,8 +48,4 @@ ClassID ClassDictionary::Normalize(ClassID id) { } } - -std::unordered_map ClassDictionary::store = { { "", ClassID::Default } }; -uint32_t ClassDictionary::offset = 0; - } diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 4f758fe72..b1b878cc8 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -23,7 +23,7 @@ void StyleLayer::setClasses(const std::vector &class_names, const t for (auto it = class_names.rbegin(); it != class_names.rend(); it++) { const std::string &class_name = *it; // From here on, we're only dealing with IDs to avoid comparing strings all the time. - const ClassID class_id = ClassDictionary::Lookup(class_name); + const ClassID class_id = ClassDictionary::Get().lookup(class_name); applyClassProperties(class_id, already_applied, now, defaultTransition); } diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 7e695e71c..ad7694d9a 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -554,7 +554,7 @@ void StyleParser::parseStyles(JSVal value, std::map &s if (name == "style") { parseStyle(replaceConstant(itr->value), styles[ClassID::Default]); } else if (name.compare(0, 6, "style.") == 0 && name.length() > 6) { - const ClassID class_id = ClassDictionary::Lookup(name.substr(6)); + const ClassID class_id = ClassDictionary::Get().lookup(name.substr(6)); parseStyle(replaceConstant(itr->value), styles[class_id]); } } From 7aea160760a0ad8338d0b3e15419332c1794848c Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 8 Oct 2014 14:47:41 -0400 Subject: [PATCH 58/87] throw std::runtime_error instead of fprintf in HeadlessView, closes #481 --- common/headless_view.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index d11f63dbd..d19db5748 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -2,6 +2,8 @@ #include "headless_display.hpp" #include +#include +#include namespace mbgl { @@ -18,14 +20,12 @@ void HeadlessView::createContext() { #if MBGL_USE_CGL CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context); if (error) { - fprintf(stderr, "Error creating GL context object\n"); - return; + throw std::runtime_error("Error creating GL context object\n"); } error = CGLEnable(gl_context, kCGLCEMPEngine); if (error != kCGLNoError ) { - fprintf(stderr, "Error enabling OpenGL multithreading\n"); - return; + throw std::runtime_error("Error enabling OpenGL multithreading\n"); } #endif @@ -69,18 +69,18 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - fprintf(stderr, "Couldn't create framebuffer: "); + std::stringstream error("Couldn't create framebuffer: "); switch (status) { - case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: fprintf(stderr, "incomplete attachment\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: fprintf(stderr, "incomplete missing attachment\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: fprintf(stderr, "incomplete dimensions\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: fprintf(stderr, "incomplete formats\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: fprintf(stderr, "incomplete draw buffer\n"); break; - case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: fprintf(stderr, "incomplete read buffer\n"); break; - case GL_FRAMEBUFFER_UNSUPPORTED: fprintf(stderr, "unsupported\n"); break; - default: fprintf(stderr, "other\n"); break; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: (error << "incomplete attachment\n"); break; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: error << "incomplete missing attachment\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: error << "incomplete dimensions\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: error << "incomplete formats\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: error << "incomplete draw buffer\n"; break; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: error << "incomplete read buffer\n"; break; + case GL_FRAMEBUFFER_UNSUPPORTED: error << "unsupported\n"; break; + default: error << "other\n"; break; } - return; + throw std::runtime_error(error.str()); } make_inactive(); @@ -151,13 +151,13 @@ void HeadlessView::make_active() { #if MBGL_USE_CGL CGLError error = CGLSetCurrentContext(gl_context); if (error) { - fprintf(stderr, "Switching OpenGL context failed\n"); + throw std::runtime_error("Switching OpenGL context failed\n"); } #endif #if MBGL_USE_GLX if (!glXMakeCurrent(x_display, glx_pixmap, gl_context)) { - fprintf(stderr, "Switching OpenGL context failed\n"); + throw std::runtime_error("Switching OpenGL context failed\n"); } #endif } @@ -166,13 +166,13 @@ void HeadlessView::make_inactive() { #if MBGL_USE_CGL CGLError error = CGLSetCurrentContext(nullptr); if (error) { - fprintf(stderr, "Removing OpenGL context failed\n"); + throw std::runtime_error("Removing OpenGL context failed\n"); } #endif #if MBGL_USE_GLX if (!glXMakeCurrent(x_display, 0, NULL)) { - fprintf(stderr, "Removing OpenGL context failed\n"); + throw std::runtime_error("Removing OpenGL context failed\n"); } #endif } From a1bc8c766d6e204a44e2c7171a80330e123b582b Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 8 Oct 2014 15:31:41 -0400 Subject: [PATCH 59/87] add HeadlessView::readPixels, fixes #480 --- common/headless_view.cpp | 30 ++++++++++++++++++++++++------ common/headless_view.hpp | 5 ++++- test/headless.cpp | 8 +------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index d19db5748..9775da1d5 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -7,7 +7,8 @@ namespace mbgl { -HeadlessView::HeadlessView() : display_(std::make_shared()) { +HeadlessView::HeadlessView() + : display_(std::make_shared()) { createContext(); } @@ -43,8 +44,12 @@ void HeadlessView::createContext() { void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { clear_buffers(); - width *= pixelRatio; - height *= pixelRatio; + width_ = width; + height_ = height; + pixelRatio_ = pixelRatio; + + const unsigned int w = width_ * pixelRatio_; + const unsigned int h = height_ * pixelRatio_; #if MBGL_USE_CGL make_active(); @@ -52,12 +57,12 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { // Create depth/stencil buffer glGenRenderbuffersEXT(1, &fbo_depth_stencil); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depth_stencil); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, width, height); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); glGenRenderbuffersEXT(1, &fbo_color); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_color); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); glGenFramebuffersEXT(1, &fbo); @@ -87,11 +92,24 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { #endif #if MBGL_USE_GLX - x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), width, height, 32); + x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), w, h, 32); glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap); #endif } +const std::unique_ptr* HeadlessView::readPixels() { + const unsigned int w = width_ * pixelRatio_; + const unsigned int h = height_ * pixelRatio_; + + const std::unique_ptr pixels(new uint32_t[w * h]); + + make_active(); + glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); + make_inactive(); + + return &pixels; +} + void HeadlessView::clear_buffers() { #if MBGL_USE_CGL make_active(); diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 13a5b0109..b59366349 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -26,6 +26,7 @@ public: void createContext(); void resize(uint16_t width, uint16_t height, float pixelRatio); + const std::unique_ptr* readPixels(); void notify_map_change(MapChange change, timestamp delay = 0); void make_active(); @@ -36,9 +37,11 @@ public: private: void clear_buffers(); - private: std::shared_ptr display_; + uint16_t width_; + uint16_t height_; + float pixelRatio_; #if MBGL_USE_CGL CGLContextObj gl_context; diff --git a/test/headless.cpp b/test/headless.cpp index 981a9dcd5..439a6dcab 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -98,13 +98,7 @@ TEST_P(HeadlessTest, render) { const unsigned int w = width * pixelRatio; const unsigned int h = height * pixelRatio; - const std::unique_ptr pixels(new uint32_t[w * h]); - - map.view.make_active(); - glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); - map.view.make_inactive(); - - const std::string image = util::compress_png(w, h, pixels.get(), true); + const std::string image = util::compress_png(w, h, view.readPixels()->get(), true); util::write_file(actual_image, image); } } From dfb81fe9ce796c06263c4b531cdba4d0e8571808 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 8 Oct 2014 16:04:13 -0400 Subject: [PATCH 60/87] fix HeadlessView::readPixels return value, ref #480 --- common/headless_view.cpp | 6 +++--- common/headless_view.hpp | 2 +- test/headless.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 9775da1d5..3f945ee6a 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -97,17 +97,17 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { #endif } -const std::unique_ptr* HeadlessView::readPixels() { +const std::unique_ptr HeadlessView::readPixels() { const unsigned int w = width_ * pixelRatio_; const unsigned int h = height_ * pixelRatio_; - const std::unique_ptr pixels(new uint32_t[w * h]); + std::unique_ptr pixels(new uint32_t[w * h]); make_active(); glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); make_inactive(); - return &pixels; + return pixels; } void HeadlessView::clear_buffers() { diff --git a/common/headless_view.hpp b/common/headless_view.hpp index b59366349..600e9d51f 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -26,7 +26,7 @@ public: void createContext(); void resize(uint16_t width, uint16_t height, float pixelRatio); - const std::unique_ptr* readPixels(); + const std::unique_ptr readPixels(); void notify_map_change(MapChange change, timestamp delay = 0); void make_active(); diff --git a/test/headless.cpp b/test/headless.cpp index 439a6dcab..91533bb36 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -98,7 +98,7 @@ TEST_P(HeadlessTest, render) { const unsigned int w = width * pixelRatio; const unsigned int h = height * pixelRatio; - const std::string image = util::compress_png(w, h, view.readPixels()->get(), true); + const std::string image = util::compress_png(w, h, view.readPixels().get(), true); util::write_file(actual_image, image); } } From 356cf956f413bbf4c4e69a849350f8fc0194356a Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 9 Oct 2014 15:16:01 -0400 Subject: [PATCH 61/87] XInitThreads --- common/headless_display.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/headless_display.cpp b/common/headless_display.cpp index b183b0a50..bbb1c10f5 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -24,6 +24,10 @@ HeadlessDisplay::HeadlessDisplay() { #endif #if MBGL_USE_GLX + if (!XInitThreads()) { + throw std::runtime_error("Failed to XInitThreads"); + } + x_display = XOpenDisplay(0); if (x_display == nullptr) { From 8f6e8eead12c6b2c2de0ce76fa7df39ca2445006 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 10 Oct 2014 11:40:03 -0400 Subject: [PATCH 62/87] only upload binaries on travis --- setup-libraries.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup-libraries.sh b/setup-libraries.sh index 791db81a8..ce0a230bc 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -122,7 +122,7 @@ export LIBUV_VERSION=0.10.28 # setup iOS universal libs ./scripts/make_universal.sh -if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then +if [ ! -z "${TRAVIS:-}" ] && [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then tar -zcf out/build-cpp11-libcpp-ios_${MP_HASH}_${DIR_HASH}.tar.gz out/build-cpp11-libcpp-universal aws s3 cp --acl public-read out/build-cpp11-libcpp-ios_${MP_HASH}_${DIR_HASH}.tar.gz s3://${AWS_S3_BUCKET}/dependencies/ tar -zcf out/build-cpp11-libcpp-osx_${MP_HASH}_${DIR_HASH}.tar.gz out/build-cpp11-libcpp-x86_64-macosx @@ -154,7 +154,7 @@ export LIBUV_VERSION=0.10.28 if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libcurl.a ] ; then ./scripts/build_curl.sh ; fi if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/libboost_regex.a ] ; then ./scripts/build_boost.sh --with-regex ; fi -if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then +if [ ! -z "${TRAVIS:-}" ] && [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then if ! tar --compare -zf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz ; then tar -zcf out/build-cpp11-libstdcpp-gcc-x86_64-linux_${MP_HASH}_${DIR_HASH}.tar.gz out/build-cpp11-libstdcpp-gcc-x86_64-linux aws s3 cp --acl public-read out/build-cpp11-libstdcpp-gcc-x86_64-linux_${MP_HASH}_${DIR_HASH}.tar.gz s3://${AWS_S3_BUCKET}/dependencies/ From c458f246fa965407dd4cde44444f6017eac20171 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 10 Oct 2014 12:52:24 -0400 Subject: [PATCH 63/87] bump mapbox-gl-cocoa to match master --- ios/mapbox-gl-cocoa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 1aa3db196..bc2c5fe69 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 1aa3db196b210c6880df6b2aff5e0d924aa78764 +Subproject commit bc2c5fe6974fa99ea4816e9e793757cc17066594 From ee68c091a858d70b8c66277cb4d3d9cbec1a9b14 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 10 Oct 2014 13:25:26 -0400 Subject: [PATCH 64/87] adjust file_request_baton and http_request for libuv 0.10 api --- src/storage/file_request_baton.cpp | 11 ++++++----- src/storage/http_request.cpp | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp index 127c78f3e..af4497689 100644 --- a/src/storage/file_request_baton.cpp +++ b/src/storage/file_request_baton.cpp @@ -29,7 +29,7 @@ void FileRequestBaton::notify_error(uv_fs_t *req) { if (ptr->request && req->result < 0 && !ptr->canceled && req->result != UV_ECANCELED) { ptr->request->response = std::unique_ptr(new Response); ptr->request->response->code = req->result == UV_ENOENT ? 404 : 500; - ptr->request->response->message = uv_strerror(int(req->result)); + ptr->request->response->message = uv_strerror(uv_last_error(req->loop)); ptr->request->notify(); } } @@ -71,13 +71,14 @@ void FileRequestBaton::file_stated(uv_fs_t *req) { uv_fs_req_cleanup(req); uv_fs_close(req->loop, req, ptr->fd, file_closed); } else { - if (static_cast(req->ptr)->st_size > std::numeric_limits::max()) { + if (static_cast(req->ptr)->st_size > std::numeric_limits::max()) { // File is too large for us to open this way because uv_buf's only support unsigned // ints as maximum size. + const uv_err_t error = {UV_EFBIG, 0}; if (ptr->request) { ptr->request->response = std::unique_ptr(new Response); - ptr->request->response->code = UV_EFBIG; - ptr->request->response->message = uv_strerror(UV_EFBIG); + ptr->request->response->code = error.code; + ptr->request->response->message = uv_strerror(error); ptr->request->notify(); } @@ -85,7 +86,7 @@ void FileRequestBaton::file_stated(uv_fs_t *req) { uv_fs_close(req->loop, req, ptr->fd, file_closed); } else { const unsigned int size = - (unsigned int)(static_cast(req->ptr)->st_size); + (unsigned int)(static_cast(req->ptr)->st_size); ptr->body.resize(size); ptr->buffer = uv_buf_init(const_cast(ptr->body.data()), size); uv_fs_req_cleanup(req); diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp index 1b799d489..4dcb12604 100644 --- a/src/storage/http_request.cpp +++ b/src/storage/http_request.cpp @@ -77,7 +77,7 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { http_baton->response = std::move(res); http_baton->async->data = new util::ptr(http_baton); - uv_async_init(loop, http_baton->async, [](uv_async_t *async) { + uv_async_init(loop, http_baton->async, [](uv_async_t *async, int status) { util::ptr &http_baton = *(util::ptr *)async->data; if (http_baton->request) { @@ -193,7 +193,7 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr &&res, uint64_t tim backoff_timer = new uv_timer_t(); uv_timer_init(loop, backoff_timer); backoff_timer->data = new RetryBaton(this, std::move(res)); - uv_timer_start(backoff_timer, [](uv_timer_t *timer) { + uv_timer_start(backoff_timer, [](uv_timer_t *timer, int status) { std::unique_ptr pair { static_cast(timer->data) }; pair->first->startHTTPRequest(std::move(pair->second)); pair->first->backoff_timer = nullptr; From 35f2c7fe23fd9265e22897bbcb6bcef66e9e7032 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 10 Oct 2014 14:37:10 -0400 Subject: [PATCH 65/87] switch http_request_baton_curl to libuv 0.10 api --- common/http_request_baton_curl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/http_request_baton_curl.cpp b/common/http_request_baton_curl.cpp index 772aeb86e..726198d1d 100644 --- a/common/http_request_baton_curl.cpp +++ b/common/http_request_baton_curl.cpp @@ -253,7 +253,7 @@ int handle_socket(CURL *handle, curl_socket_t sockfd, int action, void *, void * return 0; } -void on_timeout(uv_timer_t *) { +void on_timeout(uv_timer_t *, int status) { int running_handles; CURLMcode error = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); if (error != CURLM_OK) { @@ -442,7 +442,6 @@ void stop_request(void *const ptr) { void create_thread() { uv_mutex_init(&share_mutex); - uv_loop_init(&loop); uv_messenger_init(&loop, &start_messenger, start_request); uv_messenger_init(&loop, &stop_messenger, stop_request); uv_thread_create(&thread, thread_init, nullptr); From 6e8e50e371b519e86955f004f53ce622923c5aa6 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 10 Oct 2014 14:47:33 -0400 Subject: [PATCH 66/87] call on_timeout with status 0 (success) --- common/http_request_baton_curl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/http_request_baton_curl.cpp b/common/http_request_baton_curl.cpp index 726198d1d..3419dcc16 100644 --- a/common/http_request_baton_curl.cpp +++ b/common/http_request_baton_curl.cpp @@ -263,7 +263,7 @@ void on_timeout(uv_timer_t *, int status) { void start_timeout(CURLM *, long timeout_ms, void *) { if (timeout_ms <= 0) { - on_timeout(&timeout); + on_timeout(&timeout, 0); } else { uv_timer_start(&timeout, on_timeout, timeout_ms, 0); } From b3d064d1bbdfce42f394e96c63371b7f313b60d0 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Fri, 10 Oct 2014 18:34:15 -0400 Subject: [PATCH 67/87] use node-mapbox-gl-native AWS bucket for travis caching --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a2bf164c6..b50a63eaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ env: - secure: "bG4YYWMfl9API0MSRgmOaJrlGLv06tRg9KJNawBieZvBJbITPpxVGJZT3/l/SEJ+Rl15e2dRex4k+MGQlmT2SqPQxTEYWv1qxNigKPPcla7IWeNmWWqW8uVvFjdglojgBOK2k/xErVQtA4zDfi3mwSXH4DKwquXWsoEKmX2SV7M=" - secure: "Cbvap9ubVKgjPe3hUhI6JGeDZzBXHpOG9RaYKh+SdoIPhKnlJiNOYm1egomi+e4uqJInlFKuVHTw7Ng9Cun6Zm0jIxpkSchv1GpsR7hmB3UGnGed19Dw8121FwuUaktN+4YnbVlsyd+u8EHD3+h58t4eELrLrZolM4rS7DL6caA=" - secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I=" - - AWS_S3_BUCKET=mapbox-gl-testing + - AWS_S3_BUCKET: 'node-mapbox-gl-native' before_install: - source ./scripts/flags.sh From 5d46caaf87e315a4c221e8c5f0ed10236b244b43 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Sat, 11 Oct 2014 12:48:34 -0400 Subject: [PATCH 68/87] use node-mapbox-gl-native AWS keys --- .travis.yml | 4 ++-- travis/travis-resources.template | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b50a63eaa..79922f955 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ matrix: env: global: - - secure: "bG4YYWMfl9API0MSRgmOaJrlGLv06tRg9KJNawBieZvBJbITPpxVGJZT3/l/SEJ+Rl15e2dRex4k+MGQlmT2SqPQxTEYWv1qxNigKPPcla7IWeNmWWqW8uVvFjdglojgBOK2k/xErVQtA4zDfi3mwSXH4DKwquXWsoEKmX2SV7M=" - - secure: "Cbvap9ubVKgjPe3hUhI6JGeDZzBXHpOG9RaYKh+SdoIPhKnlJiNOYm1egomi+e4uqJInlFKuVHTw7Ng9Cun6Zm0jIxpkSchv1GpsR7hmB3UGnGed19Dw8121FwuUaktN+4YnbVlsyd+u8EHD3+h58t4eELrLrZolM4rS7DL6caA=" + - secure: "2ie/lwLSSUpx9q98geDlT/BxKYExK18i3PIgaPpgojnWPOOYr1S9TQfwggxd4FdU3eUwgq8dxuW9NuH2qmEBYvnB9BTcGSoNhrnpDZ0lrA/dFOArDHEheyLz8XirTauzciq+r1pbF0dld5uVaxZfNzbI6labDZPjf/jjSDgVc4c=" + - secure: "RsEbBA2yhdg2MYvMucJ1mmfm99UjEaC47NcYimy0Fsvzjfoe1vYrSJlYzyb9SIOj2URo8v4sAFWUbD+RTX/5pBgXCzSzEKh6ZZ1Sd7O05sx5dz8M3kRzo4asm9di8kAI842eCW/n6EhlykQBvtgA00os3ivG0Gh6KS/WebMsXsM=" - secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I=" - AWS_S3_BUCKET: 'node-mapbox-gl-native' diff --git a/travis/travis-resources.template b/travis/travis-resources.template index afe0478e3..0145e69ea 100644 --- a/travis/travis-resources.template +++ b/travis/travis-resources.template @@ -1,7 +1,7 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "mapbox-gl-native travis resources", + "Description": "node-mapbox-gl-native travis resources", "Resources": { "BuildUser": { "Type": "AWS::IAM::User", @@ -17,7 +17,7 @@ ], "Effect": "Allow", "Resource": [ - "arn:aws:s3:::mapbox-gl-testing" + "arn:aws:s3:::node-mapbox-gl-native" ] } ] @@ -37,7 +37,7 @@ ], "Effect": "Allow", "Resource": [ - "arn:aws:s3:::mapbox-gl-testing/*" + "arn:aws:s3:::node-mapbox-gl-native/*" ] } ] From 38023928ad44ef86e84c045c77c571ce252306dc Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Sat, 11 Oct 2014 13:47:57 -0400 Subject: [PATCH 69/87] fix node-mapbox-gl-native AWS keys --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79922f955..5a3345971 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,8 @@ matrix: env: global: - - secure: "2ie/lwLSSUpx9q98geDlT/BxKYExK18i3PIgaPpgojnWPOOYr1S9TQfwggxd4FdU3eUwgq8dxuW9NuH2qmEBYvnB9BTcGSoNhrnpDZ0lrA/dFOArDHEheyLz8XirTauzciq+r1pbF0dld5uVaxZfNzbI6labDZPjf/jjSDgVc4c=" - - secure: "RsEbBA2yhdg2MYvMucJ1mmfm99UjEaC47NcYimy0Fsvzjfoe1vYrSJlYzyb9SIOj2URo8v4sAFWUbD+RTX/5pBgXCzSzEKh6ZZ1Sd7O05sx5dz8M3kRzo4asm9di8kAI842eCW/n6EhlykQBvtgA00os3ivG0Gh6KS/WebMsXsM=" + - secure: "HPlPuLk531F7bCyADMcxQ+I1CfGhJlhX9A3q3auNCdLsjqaZbktaCIGuq4R1IPZz0UTtO8RfrTfVaoktyZdq2QyU3iD8oj6BeZ/Jypr4TCBJxI5IeyU3gyPMFHqUYIJuHL9k40Xu7Dhf4HT123zr8KoeVqCHauZP1/TumA0nezg=" + - secure: "R/+uOeccl7GqjJbknailAV7VtjAtGwHHM9xToVnhfPVUXp9fzJs+oNk3IWcs3Eg4sw4WsYxXRfbCQG9bA3MnPlTOsxETGRioO9CAuXap6mwcwNAzeWuq7ePFki2u01pJGQD5b6WFqBCdnAQ4o2SgHgGzhs0TJzYd9tONQxSmkCI=" - secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I=" - AWS_S3_BUCKET: 'node-mapbox-gl-native' From ed93d750ad69af642bbf87685f55c21c7dcd4271 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 13 Oct 2014 16:00:31 -0400 Subject: [PATCH 70/87] add policies for mapbox-gl-testing bucket --- travis/travis-resources.template | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/travis/travis-resources.template b/travis/travis-resources.template index 0145e69ea..2891fcf59 100644 --- a/travis/travis-resources.template +++ b/travis/travis-resources.template @@ -42,6 +42,42 @@ } ] } + }, + { + "PolicyName": "list testing", + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "s3:ListBucket" + ], + "Effect": "Allow", + "Resource": [ + "arn:aws:s3:::mapbox-gl-testing" + ] + } + ] + } + }, + { + "PolicyName": "build testing", + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "s3:DeleteObject", + "s3:GetObject", + "s3:GetObjectAcl", + "s3:PutObject", + "s3:PutObjectAcl" + ], + "Effect": "Allow", + "Resource": [ + "arn:aws:s3:::mapbox-gl-testing/*" + ] + } + ] + } } ] } From 21f642015197f2bb7f406f191a71cb0e875ede05 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 13 Oct 2014 16:05:20 -0400 Subject: [PATCH 71/87] fix policy names --- travis/travis-resources.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/travis/travis-resources.template b/travis/travis-resources.template index 2891fcf59..e1b0cff8c 100644 --- a/travis/travis-resources.template +++ b/travis/travis-resources.template @@ -44,7 +44,7 @@ } }, { - "PolicyName": "list testing", + "PolicyName": "list-testing", "PolicyDocument": { "Statement": [ { @@ -60,7 +60,7 @@ } }, { - "PolicyName": "build testing", + "PolicyName": "build-testing", "PolicyDocument": { "Statement": [ { From aa4828762c2876c1842ee7a9d6be9dfa8173a31e Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 13 Oct 2014 16:10:47 -0400 Subject: [PATCH 72/87] add int status arg to uv_messenger_callback --- src/util/uv-messenger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/uv-messenger.c b/src/util/uv-messenger.c index a25c84dc5..01c37dfd3 100644 --- a/src/util/uv-messenger.c +++ b/src/util/uv-messenger.c @@ -8,7 +8,7 @@ typedef struct { void *queue[2]; } uv__messenger_item_t; -void uv__messenger_callback(uv_async_t *async) { +void uv__messenger_callback(uv_async_t *async, int status) { uv_messenger_t *msgr = (uv_messenger_t *)async->data; uv__messenger_item_t *item; From c1e4d8554fac803304361550357e90d78d5acd46 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 13 Oct 2014 16:37:32 -0400 Subject: [PATCH 73/87] bump mapbox-gl-cocoa submodule with make_inactive fix --- ios/mapbox-gl-cocoa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index bc2c5fe69..dd4f4cac2 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit bc2c5fe6974fa99ea4816e9e793757cc17066594 +Subproject commit dd4f4cac252e0e9af5fbf73980370fc1528079ad From 9ff1d9e3bdc05817d9f9de820e1d07dd17a699cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 15 Oct 2014 16:08:36 +0200 Subject: [PATCH 74/87] experimental pbuffer support [skip ci] --- common/headless_display.cpp | 32 +++++++++++++++------- common/headless_display.hpp | 2 +- common/headless_view.cpp | 54 +++++++++++++++++++++++++------------ common/headless_view.hpp | 5 ++-- 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/common/headless_display.cpp b/common/headless_display.cpp index bbb1c10f5..a93834752 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -27,30 +27,42 @@ HeadlessDisplay::HeadlessDisplay() { if (!XInitThreads()) { throw std::runtime_error("Failed to XInitThreads"); } - - x_display = XOpenDisplay(0); + x_display = XOpenDisplay(nullptr); if (x_display == nullptr) { throw std::runtime_error("Failed to open X display"); } + const char *extensions = (char *)glXQueryServerString(x_display, DefaultScreen(x_display), GLX_EXTENSIONS); + if (!extensions) { + throw std::runtime_error("Cannot read GLX extensions"); + } + if (!strstr(extensions,"GLX_SGIX_fbconfig")) { + throw std::runtime_error("Extension GLX_SGIX_fbconfig was not found"); + } + if (!strstr(extensions, "GLX_SGIX_pbuffer")) { + throw std::runtime_error("Cannot find glXCreateContextAttribsARB"); + } + + static int pixelFormat[] = { - GLX_RGBA, - GLX_DOUBLEBUFFER, + GLX_DOUBLEBUFFER, False, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, - 0 + None }; - x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat); - - if (x_info == nullptr) { - throw std::runtime_error("Error pixel format"); + int configs = 0; + fb_configs = glXChooseFBConfig(x_display, DefaultScreen(x_display), pixelFormat, &configs); + if (configs <= 0) { + throw std::runtime_error("No Framebuffer configurations"); } + + XSync(x_display, False); #endif } @@ -60,7 +72,7 @@ HeadlessDisplay::~HeadlessDisplay() { #endif #if MBGL_USE_GLX - XFree(x_info); + XFree(fb_configs); XCloseDisplay(x_display); #endif } diff --git a/common/headless_display.hpp b/common/headless_display.hpp index 0eb41911e..5b33fd699 100644 --- a/common/headless_display.hpp +++ b/common/headless_display.hpp @@ -16,7 +16,7 @@ public: #if MBGL_USE_GLX Display *x_display = nullptr; - XVisualInfo *x_info = nullptr; + GLXFBConfig *fb_configs = nullptr; #endif }; diff --git a/common/headless_view.cpp b/common/headless_view.cpp index c2084ac90..dd62d9d23 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -5,6 +5,11 @@ #include #include +#if MBGL_USE_GLX +typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, Bool, const int *); +static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = nullptr; +#endif + namespace mbgl { HeadlessView::HeadlessView() @@ -31,13 +36,29 @@ void HeadlessView::createContext() { #endif #if MBGL_USE_GLX - x_display = display_->x_display; - x_info = display_->x_info; + if (glXCreateContextAttribsARB == nullptr) { + glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB"); + } + if (glXCreateContextAttribsARB == nullptr) { + throw std::runtime_error("Cannot find glXCreateContextAttribsARB"); + } - gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE); + x_display = display_->x_display; + fb_configs = display_->fb_configs; + + + int attributes[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, 2, + GLX_CONTEXT_MINOR_VERSION_ARB, 1, + GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, + None + }; + gl_context = glXCreateContextAttribsARB(x_display, fb_configs[0], 0, True, attributes); if (gl_context == nullptr) { throw std::runtime_error("Error creating GL context object"); } + #endif } @@ -92,8 +113,12 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { #endif #if MBGL_USE_GLX - x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), w, h, 32); - glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap); + int attributes[] = { + GLX_PBUFFER_WIDTH, w, + GLX_PBUFFER_HEIGHT, h, + None + }; + GLXPbuffer pbuffer = glXCreatePbuffer(x_display, fg_configs[0], attributes); #endif } @@ -135,17 +160,12 @@ void HeadlessView::clear_buffers() { #endif #if MBGL_USE_GLX - if (glx_pixmap) { - glXDestroyGLXPixmap(x_display, glx_pixmap); - glx_pixmap = 0; - } - - if (x_pixmap) { - XFreePixmap(x_display, x_pixmap); - x_pixmap = 0; - } - make_inactive(); + + if (glx_pbuffer) { + glXDestroyPbuffer(x_display, glx_pbuffer); + glx_pbuffer = 0; + } #endif } @@ -178,7 +198,7 @@ void HeadlessView::make_active() { #endif #if MBGL_USE_GLX - if (!glXMakeCurrent(x_display, glx_pixmap, gl_context)) { + if (!glXMakeContextCurrent(x_display, glx_pbuffer, glx_pbuffer, gl_context)) { throw std::runtime_error("Switching OpenGL context failed\n"); } #endif @@ -193,7 +213,7 @@ void HeadlessView::make_inactive() { #endif #if MBGL_USE_GLX - if (!glXMakeCurrent(x_display, 0, NULL)) { + if (!glXMakeContextCurrent(x_display, 0, 0, nullptr)) { throw std::runtime_error("Removing OpenGL context failed\n"); } #endif diff --git a/common/headless_view.hpp b/common/headless_view.hpp index d2fe75382..9ba25c73f 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -53,10 +53,9 @@ private: #if MBGL_USE_GLX Display *x_display = nullptr; - XVisualInfo *x_info = nullptr; + GLXFBConfig *fb_configs = nullptr; GLXContext gl_context = nullptr; - Pixmap x_pixmap = 0; - GLXPixmap glx_pixmap = 0; + GLXPBuffer glx_pbuffer = 0; #endif }; From 8eda68dd8a24ee5025db82d02f952fdd5921eea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 15 Oct 2014 14:20:28 +0000 Subject: [PATCH 75/87] fix errors that prevented compilation/running --- common/headless_display.cpp | 1 + common/headless_view.cpp | 2 +- common/headless_view.hpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/headless_display.cpp b/common/headless_display.cpp index a93834752..3e30d6274 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -1,5 +1,6 @@ #include "headless_display.hpp" +#include #include namespace mbgl { diff --git a/common/headless_view.cpp b/common/headless_view.cpp index dd62d9d23..51196faed 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -118,7 +118,7 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { GLX_PBUFFER_HEIGHT, h, None }; - GLXPbuffer pbuffer = glXCreatePbuffer(x_display, fg_configs[0], attributes); + glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], attributes); #endif } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 9ba25c73f..ec76f1a07 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -4,7 +4,7 @@ #ifdef __APPLE__ #define MBGL_USE_CGL 1 #else -#include "glx.h" +#include #define MBGL_USE_GLX 1 #endif @@ -55,7 +55,7 @@ private: Display *x_display = nullptr; GLXFBConfig *fb_configs = nullptr; GLXContext gl_context = nullptr; - GLXPBuffer glx_pbuffer = 0; + GLXPbuffer glx_pbuffer = 0; #endif }; From 5f40d27256b5da164bfdd19253ca4c2078b1800a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 15 Oct 2014 14:31:19 +0000 Subject: [PATCH 76/87] cast to correct int type --- common/headless_view.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 51196faed..c482bbd8b 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -114,8 +114,8 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { #if MBGL_USE_GLX int attributes[] = { - GLX_PBUFFER_WIDTH, w, - GLX_PBUFFER_HEIGHT, h, + GLX_PBUFFER_WIDTH, static_cast(w), + GLX_PBUFFER_HEIGHT, static_cast(h), None }; glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], attributes); From ee54220c7df2863dbbda191ad666416a6c84531b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 15 Oct 2014 09:56:57 -0700 Subject: [PATCH 77/87] lower our expectations towards the pbuffer and use framebuffers instead --- common/headless_display.cpp | 12 ++---------- common/headless_view.cpp | 38 ++++++++++++++----------------------- common/headless_view.hpp | 8 +++++--- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/common/headless_display.cpp b/common/headless_display.cpp index 3e30d6274..3aaf2020b 100644 --- a/common/headless_display.cpp +++ b/common/headless_display.cpp @@ -45,15 +45,9 @@ HeadlessDisplay::HeadlessDisplay() { throw std::runtime_error("Cannot find glXCreateContextAttribsARB"); } - + // We're creating a dummy pbuffer anyway that we're not using. static int pixelFormat[] = { - GLX_DOUBLEBUFFER, False, - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_ALPHA_SIZE, 8, - GLX_DEPTH_SIZE, 24, - GLX_STENCIL_SIZE, 8, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, None }; @@ -62,8 +56,6 @@ HeadlessDisplay::HeadlessDisplay() { if (configs <= 0) { throw std::runtime_error("No Framebuffer configurations"); } - - XSync(x_display, False); #endif } diff --git a/common/headless_view.cpp b/common/headless_view.cpp index c482bbd8b..7b739e1d6 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -47,18 +47,25 @@ void HeadlessView::createContext() { fb_configs = display_->fb_configs; - int attributes[] = { + int context_attributes[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 1, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, None }; - gl_context = glXCreateContextAttribsARB(x_display, fb_configs[0], 0, True, attributes); + gl_context = glXCreateContextAttribsARB(x_display, fb_configs[0], 0, True, context_attributes); if (gl_context == nullptr) { throw std::runtime_error("Error creating GL context object"); } + int pbuffer_attributes[] = { + GLX_PBUFFER_WIDTH, 32, + GLX_PBUFFER_HEIGHT, 32, + None + }; + glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes); + #endif } @@ -72,7 +79,6 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { const unsigned int w = width_ * pixelRatio_; const unsigned int h = height_ * pixelRatio_; -#if MBGL_USE_CGL make_active(); // Create depth/stencil buffer @@ -110,16 +116,6 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { } make_inactive(); -#endif - -#if MBGL_USE_GLX - int attributes[] = { - GLX_PBUFFER_WIDTH, static_cast(w), - GLX_PBUFFER_HEIGHT, static_cast(h), - None - }; - glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], attributes); -#endif } const std::unique_ptr HeadlessView::readPixels() { @@ -136,7 +132,6 @@ const std::unique_ptr HeadlessView::readPixels() { } void HeadlessView::clear_buffers() { -#if MBGL_USE_CGL make_active(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); @@ -157,16 +152,6 @@ void HeadlessView::clear_buffers() { } make_inactive(); -#endif - -#if MBGL_USE_GLX - make_inactive(); - - if (glx_pbuffer) { - glXDestroyPbuffer(x_display, glx_pbuffer); - glx_pbuffer = 0; - } -#endif } HeadlessView::~HeadlessView() { @@ -177,6 +162,11 @@ HeadlessView::~HeadlessView() { #endif #if MBGL_USE_GLX + if (glx_pbuffer) { + glXDestroyPbuffer(x_display, glx_pbuffer); + glx_pbuffer = 0; + } + glXDestroyContext(x_display, gl_context); #endif } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index ec76f1a07..195364db6 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -4,6 +4,7 @@ #ifdef __APPLE__ #define MBGL_USE_CGL 1 #else +#define GL_GLEXT_PROTOTYPES #include #define MBGL_USE_GLX 1 #endif @@ -46,9 +47,6 @@ private: #if MBGL_USE_CGL CGLContextObj gl_context; - GLuint fbo = 0; - GLuint fbo_depth_stencil = 0; - GLuint fbo_color = 0; #endif #if MBGL_USE_GLX @@ -57,6 +55,10 @@ private: GLXContext gl_context = nullptr; GLXPbuffer glx_pbuffer = 0; #endif + + GLuint fbo = 0; + GLuint fbo_depth_stencil = 0; + GLuint fbo_color = 0; }; } From 8b08772d33ae37f05cf0ed4c5ce5c884cb8fab2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 03:49:29 -0700 Subject: [PATCH 78/87] first attempt to create an opengl core profile version before falling back to legacy opengl contexts --- common/headless_view.cpp | 99 ++++++++++++++++++++++++++++++++-------- common/headless_view.hpp | 2 +- 2 files changed, 82 insertions(+), 19 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 7b739e1d6..f746d97c3 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -6,8 +6,9 @@ #include #if MBGL_USE_GLX -typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, Bool, const int *); -static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = nullptr; +#ifdef GLX_ARB_create_context +static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = nullptr; +#endif #endif namespace mbgl { @@ -22,6 +23,59 @@ HeadlessView::HeadlessView(std::shared_ptr display) createContext(); } + +#if MBGL_USE_GLX +#ifdef GLX_ARB_create_context + +// These are all of the OpenGL Core profile version that we know about. +struct core_profile_version { int major, minor; }; +static const core_profile_version core_profile_versions[] = { + {4, 5}, + {4, 4}, + {4, 3}, + {4, 2}, + {4, 1}, + {4, 0}, + {3, 3}, + {3, 2}, + {3, 1}, + {3, 0}, + {0, 0}, +}; + +GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) { + static bool context_creation_failed = false; + GLXContext ctx = 0; + + // Set the Error Handler to avoid crashing the program when the context creation fails. + // It is expected that some context creation attempts fail, e.g. because the OpenGL + // implementation does not support the version we're requesting. + int (*previous_error_handler)(Display *, XErrorEvent *) = XSetErrorHandler([](Display *, XErrorEvent *) { + context_creation_failed = true; + return 0; + }); + + // Try to create core profiles from the highest known version on down. + for (int i = 0; !ctx && core_profile_versions[i].major; i++) { + context_creation_failed = false; + const int context_flags[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, core_profile_versions[i].major, + GLX_CONTEXT_MINOR_VERSION_ARB, core_profile_versions[i].minor, + None + }; + ctx = glXCreateContextAttribsARB(dpy, fbconfig, 0, True, context_flags); + if (context_creation_failed) { + ctx = 0; + } + } + + // Restore the old error handler. + XSetErrorHandler(previous_error_handler); + return ctx; +} +#endif +#endif + void HeadlessView::createContext() { #if MBGL_USE_CGL CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context); @@ -36,36 +90,45 @@ void HeadlessView::createContext() { #endif #if MBGL_USE_GLX +#ifdef GLX_ARB_create_context if (glXCreateContextAttribsARB == nullptr) { - glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB"); - } - if (glXCreateContextAttribsARB == nullptr) { - throw std::runtime_error("Cannot find glXCreateContextAttribsARB"); + glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB"); } +#endif x_display = display_->x_display; fb_configs = display_->fb_configs; +#ifdef GLX_ARB_create_context + if (glXCreateContextAttribsARB) { + // Try to create a core profile context. + gl_context = createCoreProfile(x_display, fb_configs[0]); + } +#endif - int context_attributes[] = { - GLX_CONTEXT_MAJOR_VERSION_ARB, 2, - GLX_CONTEXT_MINOR_VERSION_ARB, 1, - GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, - None - }; - gl_context = glXCreateContextAttribsARB(x_display, fb_configs[0], 0, True, context_attributes); - if (gl_context == nullptr) { + if (!gl_context) { + // Try to create a legacy context + gl_context = glXCreateNewContext(x_display, fb_configs[0], GLX_RGBA_TYPE, 0, True); + if (gl_context) { + if (!glXIsDirect(x_display, gl_context)) { + glXDestroyContext(x_display, gl_context); + gl_context = 0; + } + } + } + + if (gl_context == 0) { throw std::runtime_error("Error creating GL context object"); } + // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to + // activate the context. int pbuffer_attributes[] = { - GLX_PBUFFER_WIDTH, 32, - GLX_PBUFFER_HEIGHT, 32, + GLX_PBUFFER_WIDTH, 8, + GLX_PBUFFER_HEIGHT, 8, None }; glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes); - #endif } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 195364db6..6e4ddcd9e 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -52,7 +52,7 @@ private: #if MBGL_USE_GLX Display *x_display = nullptr; GLXFBConfig *fb_configs = nullptr; - GLXContext gl_context = nullptr; + GLXContext gl_context = 0; GLXPbuffer glx_pbuffer = 0; #endif From 4bc56eac24d399e5c58a7f9a936fe85a71180915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 04:26:50 -0700 Subject: [PATCH 79/87] we now always use the fbo [skip ci] --- common/headless_view.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index f746d97c3..6a5a2dc00 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -275,11 +275,7 @@ void HeadlessView::make_inactive() { void HeadlessView::swap() {} unsigned int HeadlessView::root_fbo() { -#if MBGL_USE_CGL return fbo; -#endif - - return 0; } } From 97986f603f5af6b12deb4cdb4e91cd5035457c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 04:27:30 -0700 Subject: [PATCH 80/87] we don't need a root_fbo function anymore [skip ci] --- common/headless_view.cpp | 4 ---- common/headless_view.hpp | 1 - include/mbgl/map/view.hpp | 6 ------ 3 files changed, 11 deletions(-) diff --git a/common/headless_view.cpp b/common/headless_view.cpp index 6a5a2dc00..d1d13db5f 100644 --- a/common/headless_view.cpp +++ b/common/headless_view.cpp @@ -274,9 +274,5 @@ void HeadlessView::make_inactive() { void HeadlessView::swap() {} -unsigned int HeadlessView::root_fbo() { - return fbo; -} - } diff --git a/common/headless_view.hpp b/common/headless_view.hpp index 6e4ddcd9e..c0baddb88 100644 --- a/common/headless_view.hpp +++ b/common/headless_view.hpp @@ -34,7 +34,6 @@ public: void make_active(); void make_inactive(); void swap(); - unsigned int root_fbo(); private: void clear_buffers(); diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 395a05d43..b567cd424 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -39,12 +39,6 @@ public: // thread. This is called once just before the rendering thread terminates. virtual void make_inactive() = 0; - // Returns the base framebuffer object, if any, and 0 if using the system - // provided framebuffer. - virtual unsigned int root_fbo() { - return 0; - } - virtual void notify() = 0; // Notifies a watcher of map x/y/scale/rotation changes. From e211ee620d2cd64840019d682f61800e26dba7d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 05:44:26 -0700 Subject: [PATCH 81/87] add more instrumentation and code folding to travis builds --- scripts/flags.sh | 11 +++++++++++ scripts/travis_before_install.sh | 13 +++++++++++++ scripts/travis_install.sh | 1 + scripts/travis_script.sh | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/scripts/flags.sh b/scripts/flags.sh index 58aee18a0..21313b24c 100755 --- a/scripts/flags.sh +++ b/scripts/flags.sh @@ -1,7 +1,18 @@ #!/usr/bin/env bash +function mapbox_time { + local NAME=$1 ; shift + travis_fold start "${NAME}" + travis_time_start + "$@" + travis_time_finish + travis_fold end "${NAME}" +} + if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then export DISPLAY=:99.0 + + mapbox_time "start xvfb" \ sh -e /etc/init.d/xvfb start # use g++ that supports c++11 diff --git a/scripts/travis_before_install.sh b/scripts/travis_before_install.sh index e9b3384de..ab955f6aa 100755 --- a/scripts/travis_before_install.sh +++ b/scripts/travis_before_install.sh @@ -10,18 +10,31 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then if [[ `lsb_release -r` =~ "12.04" ]]; then sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test fi + + mapbox_time "apt update" \ sudo apt-get update -y + + mapbox_time "install gcc" \ sudo apt-get -y install gcc-4.8 g++-4.8 + + mapbox_time "install build tools" \ sudo apt-get -y install git build-essential zlib1g-dev automake \ libtool xutils-dev make cmake pkg-config python-pip + + mapbox_time "install opengl" \ sudo apt-get -y install libxi-dev libglu1-mesa-dev x11proto-randr-dev \ x11proto-xext-dev libxrandr-dev \ x11proto-xf86vidmode-dev libxxf86vm-dev libxcursor-dev + + mapbox_time "install awscli" \ sudo pip install awscli elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # install OS X dependencies # + mapbox_time "install build tools" \ brew install autoconf automake libtool makedepend cmake pkg-config node git + + mapbox_time "install awscli" \ sudo pip install awscli fi diff --git a/scripts/travis_install.sh b/scripts/travis_install.sh index eca24e719..d0539946b 100755 --- a/scripts/travis_install.sh +++ b/scripts/travis_install.sh @@ -4,5 +4,6 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # we'll need the test suite on Linux # + mapbox_time "install test suite" \ npm install git+https://github.com/mapbox/mapbox-gl-test-suite.git fi diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index f1cad6b9d..1c61dfa9d 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -7,12 +7,20 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # build & test Linux # + mapbox_time "compile program" \ make linux -j4 BUILDTYPE=${BUILDTYPE} + + mapbox_time "install tests" \ make test -j4 BUILDTYPE=${BUILDTYPE} + + mapbox_time "run tests" \ ./scripts/run_tests.sh + + mapbox_time "compare results" \ (cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true)) if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then + mapbox_time "deploy results" \ (cd ./node_modules/mapbox-gl-test-suite/ && ./bin/deploy_results.sh) fi @@ -20,13 +28,23 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # build OS X # + mapbox_time "create osx project" \ make xproj-cli + + mapbox_time "build osx" \ xcodebuild -project ./build/macosx/mapboxgl-app.xcodeproj -jobs 4 + # # build iOS # git submodule init + + mapbox_time "load submodules" \ git submodule update + + mapbox_time "create ios project" \ make iproj-cli + + mapbox_time "build ios" \ xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -jobs 4 fi From 3d6304e8c3d9433199ae1b928fcf935ce1a43bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 05:50:10 -0700 Subject: [PATCH 82/87] remove spaces from fold command and put in separate file --- scripts/flags.sh | 9 +-------- scripts/travis_before_install.sh | 16 +++++++++------- scripts/travis_helper.sh | 10 ++++++++++ scripts/travis_install.sh | 4 +++- scripts/travis_script.sh | 22 ++++++++++++---------- 5 files changed, 35 insertions(+), 26 deletions(-) create mode 100755 scripts/travis_helper.sh diff --git a/scripts/flags.sh b/scripts/flags.sh index 21313b24c..83a413821 100755 --- a/scripts/flags.sh +++ b/scripts/flags.sh @@ -1,13 +1,6 @@ #!/usr/bin/env bash -function mapbox_time { - local NAME=$1 ; shift - travis_fold start "${NAME}" - travis_time_start - "$@" - travis_time_finish - travis_fold end "${NAME}" -} +. ./scripts/travis_helper.sh if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then export DISPLAY=:99.0 diff --git a/scripts/travis_before_install.sh b/scripts/travis_before_install.sh index ab955f6aa..654c9dcc6 100755 --- a/scripts/travis_before_install.sh +++ b/scripts/travis_before_install.sh @@ -3,6 +3,8 @@ set -e set -o pipefail +. ./scripts/travis_helper.sh + if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # install Linux dependencies @@ -11,30 +13,30 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test fi - mapbox_time "apt update" \ + mapbox_time "apt_update" \ sudo apt-get update -y - mapbox_time "install gcc" \ + mapbox_time "install_gcc" \ sudo apt-get -y install gcc-4.8 g++-4.8 - mapbox_time "install build tools" \ + mapbox_time "install_build_tools" \ sudo apt-get -y install git build-essential zlib1g-dev automake \ libtool xutils-dev make cmake pkg-config python-pip - mapbox_time "install opengl" \ + mapbox_time "install_opengl" \ sudo apt-get -y install libxi-dev libglu1-mesa-dev x11proto-randr-dev \ x11proto-xext-dev libxrandr-dev \ x11proto-xf86vidmode-dev libxxf86vm-dev libxcursor-dev - mapbox_time "install awscli" \ + mapbox_time "install_awscli" \ sudo pip install awscli elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # install OS X dependencies # - mapbox_time "install build tools" \ + mapbox_time "install_build_tools" \ brew install autoconf automake libtool makedepend cmake pkg-config node git - mapbox_time "install awscli" \ + mapbox_time "install_awscli" \ sudo pip install awscli fi diff --git a/scripts/travis_helper.sh b/scripts/travis_helper.sh new file mode 100755 index 000000000..0a2aab663 --- /dev/null +++ b/scripts/travis_helper.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +function mapbox_time { + local NAME=$1 ; shift + travis_fold start "${NAME}" + travis_time_start + "$@" + travis_time_finish + travis_fold end "${NAME}" +} diff --git a/scripts/travis_install.sh b/scripts/travis_install.sh index d0539946b..9d17fee7f 100755 --- a/scripts/travis_install.sh +++ b/scripts/travis_install.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash +. ./scripts/travis_helper.sh + if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # we'll need the test suite on Linux # - mapbox_time "install test suite" \ + mapbox_time "install_test_suite" \ npm install git+https://github.com/mapbox/mapbox-gl-test-suite.git fi diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index 1c61dfa9d..d4ebeb12d 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -3,24 +3,26 @@ set -e set -o pipefail +. ./scripts/travis_helper.sh + if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # build & test Linux # - mapbox_time "compile program" \ + mapbox_time "compile_program" \ make linux -j4 BUILDTYPE=${BUILDTYPE} - mapbox_time "install tests" \ + mapbox_time "install_tests" \ make test -j4 BUILDTYPE=${BUILDTYPE} - mapbox_time "run tests" \ + mapbox_time "run_tests" \ ./scripts/run_tests.sh - mapbox_time "compare results" \ + mapbox_time "compare_results" \ (cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true)) if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then - mapbox_time "deploy results" \ + mapbox_time "deploy_results" \ (cd ./node_modules/mapbox-gl-test-suite/ && ./bin/deploy_results.sh) fi @@ -28,10 +30,10 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # # build OS X # - mapbox_time "create osx project" \ + mapbox_time "create_osx_project" \ make xproj-cli - mapbox_time "build osx" \ + mapbox_time "build_osx" \ xcodebuild -project ./build/macosx/mapboxgl-app.xcodeproj -jobs 4 # @@ -39,12 +41,12 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # git submodule init - mapbox_time "load submodules" \ + mapbox_time "load_submodules" \ git submodule update - mapbox_time "create ios project" \ + mapbox_time "create_ios_project" \ make iproj-cli - mapbox_time "build ios" \ + mapbox_time "build_ios" \ xcodebuild -project ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -jobs 4 fi From 0d213283c0cc7bf7ebd06210b42577c9b8dece43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 05:56:18 -0700 Subject: [PATCH 83/87] export function to subshells --- .travis.yml | 1 + scripts/flags.sh | 2 -- scripts/travis_before_install.sh | 2 -- scripts/travis_helper.sh | 2 ++ scripts/travis_install.sh | 2 -- scripts/travis_script.sh | 2 -- 6 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a3345971..78b2754a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ env: - AWS_S3_BUCKET: 'node-mapbox-gl-native' before_install: +- source ./scripts/travis_helper.sh - source ./scripts/flags.sh - ./scripts/travis_before_install.sh diff --git a/scripts/flags.sh b/scripts/flags.sh index 83a413821..1cb8b766e 100755 --- a/scripts/flags.sh +++ b/scripts/flags.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -. ./scripts/travis_helper.sh - if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then export DISPLAY=:99.0 diff --git a/scripts/travis_before_install.sh b/scripts/travis_before_install.sh index 654c9dcc6..d3add138c 100755 --- a/scripts/travis_before_install.sh +++ b/scripts/travis_before_install.sh @@ -3,8 +3,6 @@ set -e set -o pipefail -. ./scripts/travis_helper.sh - if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # install Linux dependencies diff --git a/scripts/travis_helper.sh b/scripts/travis_helper.sh index 0a2aab663..0c54e3dd0 100755 --- a/scripts/travis_helper.sh +++ b/scripts/travis_helper.sh @@ -8,3 +8,5 @@ function mapbox_time { travis_time_finish travis_fold end "${NAME}" } + +export -f mapbox_time diff --git a/scripts/travis_install.sh b/scripts/travis_install.sh index 9d17fee7f..cb2422d70 100755 --- a/scripts/travis_install.sh +++ b/scripts/travis_install.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -. ./scripts/travis_helper.sh - if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # we'll need the test suite on Linux diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index d4ebeb12d..a9c26f34f 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -3,8 +3,6 @@ set -e set -o pipefail -. ./scripts/travis_helper.sh - if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then # # build & test Linux From 42b54b11d8f90aeeb7fd37309a06de91553caa6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 05:59:47 -0700 Subject: [PATCH 84/87] export all required functions --- scripts/travis_helper.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/travis_helper.sh b/scripts/travis_helper.sh index 0c54e3dd0..ebe1e965b 100755 --- a/scripts/travis_helper.sh +++ b/scripts/travis_helper.sh @@ -9,4 +9,9 @@ function mapbox_time { travis_fold end "${NAME}" } +export -f travis_fold +export -f travis_time_start +export -f travis_time_finish +export -f travis_nanoseconds +export ANSI_CLEAR export -f mapbox_time From 21b97d490625b016243aea4d2d627040de8879c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 06:54:36 -0700 Subject: [PATCH 85/87] better timing functions --- scripts/travis_helper.sh | 46 ++++++++++++++++++++++++++++++---------- scripts/travis_script.sh | 6 ++++-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/scripts/travis_helper.sh b/scripts/travis_helper.sh index ebe1e965b..040ef2944 100755 --- a/scripts/travis_helper.sh +++ b/scripts/travis_helper.sh @@ -1,17 +1,41 @@ #!/usr/bin/env bash -function mapbox_time { - local NAME=$1 ; shift - travis_fold start "${NAME}" - travis_time_start - "$@" - travis_time_finish - travis_fold end "${NAME}" +function mapbox_time_start { + local name=$1 + mapbox_timer_name=$name + + travis_fold start $name + + mapbox_timer_id=$(printf %08x $(( RANDOM * RANDOM ))) + eval "mapbox_start_time_$mapbox_timer_id=$(travis_nanoseconds)" + echo -en "travis_time:start:$mapbox_timer_id\n" } -export -f travis_fold -export -f travis_time_start -export -f travis_time_finish -export -f travis_nanoseconds +function mapbox_time_finish { + local name=${1:-$mapbox_timer_name} + local timer_id=${2:-$mapbox_timer_id} + local timer_start="mapbox_start_time_$timer_id" + eval local start_time=\${$timer_start} + local end_time=$(travis_nanoseconds) + local duration=$(($end_time-$start_time)) + echo -en "travis_time:end:$timer_id:start=$start_time,finish=$end_time,duration=$duration\n" + + travis_fold end $name +} + +function mapbox_time { + local name=$1 ; shift + mapbox_time_start $name + local timer_id=$mapbox_timer_id + echo "\$ $@" + $@ + mapbox_time_finish $name $timer_id +} + + export ANSI_CLEAR +export -f travis_fold +export -f travis_nanoseconds export -f mapbox_time +export -f mapbox_time_start +export -f mapbox_time_finish diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index a9c26f34f..ae26467a0 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -16,12 +16,14 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then mapbox_time "run_tests" \ ./scripts/run_tests.sh - mapbox_time "compare_results" \ + mapbox_time_start "compare_results" (cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true)) + mapbox_time_end if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then - mapbox_time "deploy_results" \ + mapbox_time_start "deploy_results" (cd ./node_modules/mapbox-gl-test-suite/ && ./bin/deploy_results.sh) + mapbox_time_end fi elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then From 2c6d9374a4f30dde2585ef7f18344643df3c823c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 07:00:04 -0700 Subject: [PATCH 86/87] fix misnamed function --- scripts/travis_script.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/travis_script.sh b/scripts/travis_script.sh index ae26467a0..f306dbcb7 100755 --- a/scripts/travis_script.sh +++ b/scripts/travis_script.sh @@ -10,7 +10,7 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then mapbox_time "compile_program" \ make linux -j4 BUILDTYPE=${BUILDTYPE} - mapbox_time "install_tests" \ + mapbox_time "compile_tests" \ make test -j4 BUILDTYPE=${BUILDTYPE} mapbox_time "run_tests" \ @@ -18,12 +18,12 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then mapbox_time_start "compare_results" (cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true)) - mapbox_time_end + mapbox_time_finish if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then mapbox_time_start "deploy_results" (cd ./node_modules/mapbox-gl-test-suite/ && ./bin/deploy_results.sh) - mapbox_time_end + mapbox_time_finish fi elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then From 8954b3971f5cb90dc4b18e61b58ea6e41c54fffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Oct 2014 07:07:05 -0700 Subject: [PATCH 87/87] don't time xvfb startup --- scripts/flags.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/flags.sh b/scripts/flags.sh index 1cb8b766e..9c7e1cff9 100755 --- a/scripts/flags.sh +++ b/scripts/flags.sh @@ -3,7 +3,6 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then export DISPLAY=:99.0 - mapbox_time "start xvfb" \ sh -e /etc/init.d/xvfb start # use g++ that supports c++11