Merge branch 'master' of github.com:mapbox/mapbox-gl-native

This commit is contained in:
Justin R. Miller
2014-10-27 17:02:24 -04:00
135 changed files with 1796 additions and 1213 deletions

View File

@@ -24,6 +24,7 @@ env:
- secure: "RiBIBfVhhaMjU5ksuwJO3shdvG9FpinBjdSv4co9jg9171SR8edNriedHjVKSIeBhSGNmZmX+twS3dJS/By6tl/LKh9sTynA+ZAYYljkE7jn881B/gMrlYvdAA6og5KvkhV1/0iJWlhuZrMTkhpDR200iLgg3EWBhWjltzmDW/I="
before_install:
- source ./scripts/travis_helper.sh
- source ./scripts/flags.sh
- (git clone https://github.com/mapbox/mason.git ~/.mason ; sudo ln -s ~/.mason/mason /usr/local/bin/mason)
- ./scripts/travis_before_install.sh
@@ -31,6 +32,11 @@ before_install:
install:
- make config.gypi
- ./scripts/travis_install_test_suite.sh
- ulimit -c
before_script:
# Set the core file limit to unlimited so a core file is generated upon crash
- ulimit -c unlimited -S
script:
- ./scripts/travis_script.sh

View File

@@ -1,6 +1,13 @@
BUILDTYPE ?= Release
PYTHON ?= python
V ?= 1
PREFIX ?= /usr/local
ifeq ($(shell uname -s), Darwin)
PLATFORM ?= osx
endif
PLATFORM ?= linux
all: mbgl
@@ -12,13 +19,17 @@ config-ios.gypi: configure
# Builds the regular library
mbgl: config.gypi mapboxgl.gyp
deps/run_gyp mapboxgl.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/mbgl -f make
$(MAKE) -C build/mbgl BUILDTYPE=$(BUILDTYPE) V=$(V) mapboxgl
deps/run_gyp mapboxgl.gyp -Iconfig.gypi -Dplatform=$(PLATFORM) --depth=. -Goutput_dir=.. --generator-output=./build/mbgl -f make
$(MAKE) -C build/mbgl BUILDTYPE=$(BUILDTYPE) V=$(V) mbgl
install: config.gypi mapboxgl.gyp
deps/run_gyp mapboxgl.gyp -Iconfig.gypi -Dplatform=$(PLATFORM) -Dinstall_prefix=$(PREFIX) --depth=. -Goutput_dir=.. --generator-output=./build/mbgl -f make
$(MAKE) -C build/mbgl BUILDTYPE=$(BUILDTYPE) V=$(V) install
##### Test cases ###############################################################
build/test/Makefile: src common config.gypi test/test.gyp
deps/run_gyp test/test.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/test -f make
deps/run_gyp test/test.gyp -Iconfig.gypi -Dplatform=$(PLATFORM) --depth=. -Goutput_dir=.. --generator-output=./build/test -f make
test: build/test/Makefile
$(MAKE) -C build/test BUILDTYPE=$(BUILDTYPE) V=$(V) test
@@ -29,7 +40,7 @@ test_%: build/test/Makefile
# build Mac OS X project for Xcode
xtest: config.gypi clear_xcode_cache
deps/run_gyp test/test.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build -f xcode
deps/run_gyp test/test.gyp -Iconfig.gypi -Dplatform=osx --depth=. -Goutput_dir=.. --generator-output=./build -f xcode
open ./build/test/test.xcodeproj
##### Makefile builds ##########################################################
@@ -37,7 +48,7 @@ xtest: config.gypi clear_xcode_cache
# Builds the linux app with make.
linux: config.gypi linux/mapboxgl-app.gyp
deps/run_gyp linux/mapboxgl-app.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/linux -f make
deps/run_gyp linux/mapboxgl-app.gyp -Iconfig.gypi -Dplatform=linux --depth=. -Goutput_dir=.. --generator-output=./build/linux -f make
$(MAKE) -C build/linux BUILDTYPE=$(BUILDTYPE) V=$(V) linuxapp
# Executes the Linux binary
@@ -48,7 +59,7 @@ run-linux: linux
# Builds the OS X app with make.
osx: config.gypi macosx/mapboxgl-app.gyp
deps/run_gyp macosx/mapboxgl-app.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/macosx -f make
deps/run_gyp macosx/mapboxgl-app.gyp -Iconfig.gypi -Dplatform=osx --depth=. -Goutput_dir=.. --generator-output=./build/macosx -f make
$(MAKE) -C build/macosx BUILDTYPE=$(BUILDTYPE) V=$(V) osxapp
# Executes the OS X binary
@@ -70,21 +81,21 @@ clear_xcode_cache:
# build Mac OS X project for Xcode
xproj-cli: config.gypi macosx/mapboxgl-app.gyp clear_xcode_cache
deps/run_gyp macosx/mapboxgl-app.gyp -Iconfig.gypi --depth=. --generator-output=./build -f xcode
deps/run_gyp macosx/mapboxgl-app.gyp -Iconfig.gypi -Dplatform=osx --depth=. --generator-output=./build -f xcode
xproj: xproj-cli
open ./build/macosx/mapboxgl-app.xcodeproj
# build iOS project for Xcode
iproj-cli: config-ios.gypi ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp clear_xcode_cache
deps/run_gyp ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp -Iconfig-ios.gypi --depth=. --generator-output=./build -f xcode
deps/run_gyp ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp -Iconfig-ios.gypi -Dplatform=ios --depth=. --generator-output=./build -f xcode
iproj: iproj-cli
open ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj
# build Linux project for Xcode (Runs on Mac OS X too, but without platform-specific code)
lproj: config.gypi linux/mapboxgl-app.gyp clear_xcode_cache
deps/run_gyp linux/mapboxgl-app.gyp -Iconfig.gypi --depth=. --generator-output=./build -f xcode
deps/run_gyp linux/mapboxgl-app.gyp -Iconfig.gypi -Dplatform=linux --depth=. --generator-output=./build -f xcode
open ./build/linux/mapboxgl-app.xcodeproj
@@ -98,5 +109,5 @@ clean: clear_xcode_cache
distclean: clean
-rm -rf ./mason_packages
.PHONY: mbgl test linux build/test/Makefile
.PHONY: mbgl install test linux clear_xcode_cache build/test/Makefile clean distclean
# DO NOT DELETE

View File

@@ -1,39 +0,0 @@
{
'target_defaults': {
'default_configuration': 'Release',
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI':'YES',
'OTHER_CPLUSPLUSFLAGS': [ '-Wall', '-Wextra', '-Wno-variadic-macros' ],
'GCC_WARN_PEDANTIC': 'YES',
'GCC_WARN_UNINITIALIZED_AUTOS': 'YES_AGGRESSIVE'
},
'cflags_cc': ['-std=c++11', '-Wall', '-Wextra'],
'configurations': {
'Debug': {
'cflags_cc': [ '-g', '-O0', '-fno-omit-frame-pointer','-fwrapv', '-fstack-protector-all', '-fno-common' ],
'defines': [ 'DEBUG' ],
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '0',
'GCC_GENERATE_DEBUGGING_SYMBOLS': 'YES',
'DEAD_CODE_STRIPPING': 'NO',
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'NO',
'OTHER_CPLUSPLUSFLAGS': [ '-fno-omit-frame-pointer','-fwrapv', '-fstack-protector-all', '-fno-common']
}
},
'Release': {
'cflags_cc': [ '-O3' ],
'defines': [ 'NDEBUG' ],
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '3',
'GCC_GENERATE_DEBUGGING_SYMBOLS': 'NO',
'DEAD_CODE_STRIPPING': 'YES',
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES'
}
},
}
}
}

View File

@@ -1,200 +0,0 @@
#include "headless_view.hpp"
#include <mbgl/util/timer.hpp>
#include <stdexcept>
namespace mbgl {
HeadlessView::HeadlessView() {
#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\n");
return;
}
error = CGLCreateContext(pixelFormat, NULL, &gl_context);
CGLDestroyPixelFormat(pixelFormat);
if (error) {
fprintf(stderr, "Error creating GL context object\n");
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");
}
gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE);
if (gl_context == nullptr) {
throw std::runtime_error("Error creating GL context object");
}
#endif
}
void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
clear_buffers();
width *= pixelRatio;
height *= pixelRatio;
#if MBGL_USE_CGL
make_active();
// 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);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glGenRenderbuffersEXT(1, &fbo_color);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_color);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fbo_color);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fbo_depth_stencil);
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
fprintf(stderr, "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_DRAW_BUFFER_EXT: fprintf(stderr, "incomplete draw buffer\n"); break;
case GL_FRAMEBUFFER_UNSUPPORTED: fprintf(stderr, "unsupported\n"); break;
default: fprintf(stderr, "other\n"); break;
}
return;
}
#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
}
void HeadlessView::clear_buffers() {
#if MBGL_USE_CGL
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
if (fbo) {
glDeleteFramebuffersEXT(1, &fbo);
fbo = 0;
}
if (fbo_color) {
glDeleteTextures(1, &fbo_color);
fbo_color = 0;
}
if (fbo_depth_stencil) {
glDeleteRenderbuffersEXT(1, &fbo_depth_stencil);
fbo_depth_stencil = 0;
}
#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;
}
#endif
}
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);
#endif
}
void HeadlessView::notify() {
// no-op
}
void HeadlessView::notify_map_change(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
// no-op
}
void HeadlessView::make_active() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(gl_context);
if (error) {
fprintf(stderr, "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");
}
#endif
}
void HeadlessView::swap() {}
unsigned int HeadlessView::root_fbo() {
#if MBGL_USE_CGL
return fbo;
#endif
return 0;
}
}

12
gyp/certificates.gypi Normal file
View File

@@ -0,0 +1,12 @@
{
'targets': [
{ 'target_name': 'copy_certificate_bundle',
'type': 'none',
'hard_dependency': 1,
'copies': [{
'files': [ '../common/ca-bundle.crt' ],
'destination': '<(PRODUCT_DIR)'
}],
},
]
}

52
gyp/common.gypi Normal file
View File

@@ -0,0 +1,52 @@
{
'variables': {
'install_prefix%': '',
},
'target_defaults': {
'default_configuration': 'Release',
'conditions': [
['OS=="mac"', {
'xcode_settings': {
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI':'YES',
'OTHER_CPLUSPLUSFLAGS': [ '-Wall', '-Wextra', '-Wshadow', '-Wno-variadic-macros', '-frtti', '-fexceptions' ],
'GCC_WARN_PEDANTIC': 'YES',
'GCC_WARN_UNINITIALIZED_AUTOS': 'YES_AGGRESSIVE',
},
}],
['OS=="linux"', {
'cflags_cc': [
'-Wno-unknown-pragmas', # We are using '#pragma mark', but it is only available on Darwin.
'-Wno-literal-suffix', # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653
],
}],
],
'cflags_cc': [ '-std=c++11', '-Werror', '-Wall', '-Wextra', '-Wshadow', '-frtti', '-fexceptions' ],
'configurations': {
'Debug': {
'cflags_cc': [ '-g', '-O0', '-fno-omit-frame-pointer','-fwrapv', '-fstack-protector-all', '-fno-common' ],
'defines': [ 'DEBUG' ],
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '0',
'GCC_GENERATE_DEBUGGING_SYMBOLS': 'YES',
'DEAD_CODE_STRIPPING': 'NO',
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'NO',
'OTHER_CPLUSPLUSFLAGS': [ '-fno-omit-frame-pointer','-fwrapv', '-fstack-protector-all', '-fno-common']
}
},
'Release': {
'cflags_cc': [ '-O3' ],
'defines': [ 'NDEBUG' ],
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '3',
'GCC_GENERATE_DEBUGGING_SYMBOLS': 'NO',
'DEAD_CODE_STRIPPING': 'YES',
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'NO'
}
},
},
}
}

17
gyp/fixtures.gypi Normal file
View File

@@ -0,0 +1,17 @@
{
'targets': [
{ 'target_name': 'copy_fixtures',
'type': 'none',
'hard_dependency': 1,
'dependencies': [
'bundle_styles'
],
'copies': [
{
'files': [ '../styles' ],
'destination': '../test/fixtures/style_parser'
}
]
},
]
}

23
gyp/install.gypi Normal file
View File

@@ -0,0 +1,23 @@
{
'conditions': [
['install_prefix != ""', {
'targets': [
{ 'target_name': 'install',
'type': 'none',
'hard_dependency': 1,
'dependencies': [
'mbgl',
'mbgl-headless',
'mbgl-<(platform)',
],
'copies': [
{ 'files': [ '<(PRODUCT_DIR)/libmbgl.a' ], 'destination': '<(install_prefix)/lib' },
{ 'files': [ '<(PRODUCT_DIR)/libmbgl-headless.a' ], 'destination': '<(install_prefix)/lib' },
{ 'files': [ '<(PRODUCT_DIR)/libmbgl-<(platform).a' ], 'destination': '<(install_prefix)/lib' },
{ 'files': [ '../include/mbgl' ], 'destination': '<(install_prefix)/include' }
],
},
]
}],
],
}

16
gyp/mbgl-headless.gypi Normal file
View File

@@ -0,0 +1,16 @@
{
'targets': [
{ 'target_name': 'mbgl-headless',
'product_name': 'mbgl-headless',
'type': 'static_library',
'standalone_static_library': 1,
'include_dirs': [
'../include',
],
'sources': [
'../platform/default/headless_view.cpp',
'../platform/default/headless_display.cpp',
],
},
]
}

59
gyp/mbgl-ios.gypi Normal file
View File

@@ -0,0 +1,59 @@
{
'target_defaults': {
'target_conditions': [
['_type == "static_library"', {
'xcode_settings': {
'SDKROOT': 'iphoneos',
'SUPPORTED_PLATFORMS': 'iphonesimulator iphoneos',
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
'IPHONEOS_DEPLOYMENT_TARGET':'7.0',
'TARGETED_DEVICE_FAMILY': '1,2',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'CLANG_ENABLE_OBJC_ARC': 'YES',
'CODE_SIGN_IDENTITY': 'iPhone Developer',
'PUBLIC_HEADERS_FOLDER_PATH': 'include',
},
'configurations': {
'Release': {
'xcode_settings': {
'ARCHS': [ "armv7", "armv7s", "arm64", "i386", "x86_64" ],
},
},
},
}],
],
},
'targets': [
{ 'target_name': 'mbgl-ios',
'product_name': 'mbgl-ios',
'type': 'static_library',
'standalone_static_library': 1,
'hard_dependency': 1,
'include_dirs': [
'../include',
],
'sources': [
'../platform/ios/cache_database_library.mm',
'../platform/darwin/log_nslog.mm',
'../platform/darwin/string_nsstring.mm',
'../platform/darwin/http_request_baton_cocoa.mm',
],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [
'<@(uv_cflags)',
],
},
'direct_dependent_settings': {
'include_dirs': [
'../include',
],
'xcode_settings': {
'OTHER_LDFLAGS': [
'<@(uv_libraries)',
],
},
},
},
],
}

55
gyp/mbgl-linux.gypi Normal file
View File

@@ -0,0 +1,55 @@
{
'targets': [
{ 'target_name': 'mbgl-linux',
'product_name': 'mbgl-linux',
'type': 'static_library',
'standalone_static_library': 1,
'hard_dependency': 1,
'include_dirs': [
'../include'
],
'sources': [
'../platform/default/cache_database_tmp.cpp',
'../platform/default/log_stderr.cpp',
'../platform/default/string_stdlib.cpp',
'../platform/default/http_request_baton_curl.cpp',
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [
'<@(uv_cflags)',
'<@(curl_cflags)',
],
}
}, {
'cflags': [
'<@(uv_cflags)',
'<@(curl_cflags)',
],
}]
],
'direct_dependent_settings': {
'include_dirs': [
'../include',
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'OTHER_LDFLAGS': [
'<@(uv_libraries)',
'<@(curl_libraries)',
]
}
}, {
'libraries': [
'<@(uv_libraries)',
'<@(curl_libraries)',
'-lboost_regex',
]
}]
]
}
},
]
}

34
gyp/mbgl-osx.gypi Normal file
View File

@@ -0,0 +1,34 @@
{
'targets': [
{ 'target_name': 'mbgl-osx',
'product_name': 'mbgl-osx',
'type': 'static_library',
'standalone_static_library': 1,
'hard_dependency': 1,
'include_dirs': [
'../include',
],
'sources': [
'../platform/osx/cache_database_application_support.mm',
'../platform/darwin/log_nslog.mm',
'../platform/darwin/string_nsstring.mm',
'../platform/darwin/http_request_baton_cocoa.mm',
],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [
'<@(uv_cflags)',
],
},
'direct_dependent_settings': {
'include_dirs': [
'../include',
],
'xcode_settings': {
'OTHER_LDFLAGS': [
'<@(uv_libraries)',
],
},
},
},
],
}

16
gyp/mbgl-platform.gypi Normal file
View File

@@ -0,0 +1,16 @@
{
'conditions': [
['platform == "osx"', {
'includes': ['mbgl-osx.gypi'],
'variables': { 'platform_library': 'mbgl-osx' },
}],
['platform == "ios"', {
'includes': ['mbgl-ios.gypi'],
'variables': { 'platform_library': 'mbgl-ios' },
}],
['platform == "linux"', {
'includes': ['mbgl-linux.gypi'],
'variables': { 'platform_library': 'mbgl-linux' },
}],
],
}

75
gyp/mbgl.gypi Normal file
View File

@@ -0,0 +1,75 @@
{
'targets': [
{ 'target_name': 'mbgl',
'product_name': 'mbgl',
'type': 'static_library',
'standalone_static_library': 1,
'hard_dependency': 1,
'dependencies': [
'shaders',
],
'sources': [
'<!@(find src -name "*.cpp")',
'<!@(test -f "config/constants_local.cpp" && echo "config/constants_local.cpp" || echo "config/constants.cpp")',
'<!@(find src -name "*.c")',
'<!@(find src -name "*.h")',
'<!@(find include -name "*.hpp")',
'<!@(find include -name "*.h")',
'<!@(find src -name "*.glsl")',
'bin/style.json'
],
'include_dirs': [
'../include'
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'PUBLIC_HEADERS_FOLDER_PATH': 'include',
'OTHER_CPLUSPLUSFLAGS': [
'<@(png_cflags)',
'<@(uv_cflags)',
'<@(sqlite3_cflags)',
'<@(zlib_cflags)',
'-I<(boost_root)/include',
],
'OTHER_CFLAGS': [
'<@(uv_cflags)',
],
},
}, {
'cflags': [
'<@(png_cflags)',
'<@(uv_cflags)',
'<@(sqlite3_cflags)',
'<@(zlib_cflags)',
'-I<(boost_root)/include',
],
}]
],
'direct_dependent_settings': {
'include_dirs': [
'../include',
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'OTHER_LDFLAGS': [
'<@(png_libraries)',
'<@(uv_libraries)',
'<@(sqlite3_libraries)',
'<@(zlib_libraries)',
]
}
}, {
'libraries': [
'<@(png_libraries)',
'<@(uv_libraries)',
'<@(sqlite3_libraries)',
'<@(zlib_libraries)',
]
}]
]
}
}
]
}

20
gyp/npm_install.gypi Normal file
View File

@@ -0,0 +1,20 @@
{
'targets': [
{ 'target_name': 'npm_install',
'type': 'none',
'hard_dependency': 1,
'actions': [
{
'action_name': 'npm install',
'inputs': [
'../bin/package.json',
],
'outputs': [
'../bin/node_modules',
],
'action': ['./scripts/npm_install.sh', '<@(npm)']
}
],
},
]
}

36
gyp/shaders.gypi Normal file
View File

@@ -0,0 +1,36 @@
{
'targets': [
{
'target_name': 'shaders',
'type': 'none',
'hard_dependency': 1,
'dependencies': [
'npm_install'
],
'actions': [
{
'action_name': 'Build Shaders',
'inputs': [
'<!@(find src -name "*.glsl")'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/include/mbgl/shader/shaders.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp',
],
'action': ['<@(node)', 'bin/build-shaders.js', '<(SHARED_INTERMEDIATE_DIR)'],
}
],
'direct_dependent_settings': {
'sources': [
'<(SHARED_INTERMEDIATE_DIR)/include/mbgl/shader/shaders.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp'
],
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)/include/',
]
}
},
]
}

36
gyp/styles.gypi Normal file
View File

@@ -0,0 +1,36 @@
{
'targets': [
{
'target_name': 'touch_styles',
'type': 'none',
'hard_dependency': 1,
'actions': [
{
'action_name': 'Touch Stylesheet Directory',
'inputs': ['../styles'],
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/'], # need to specify a distinct directory
'action': ['touch', '../styles'],
}
],
},
{
'target_name': 'bundle_styles',
'type': 'none',
'hard_dependency': 1,
'dependencies': [ 'touch_styles' ], # required for xcode http://openradar.appspot.com/7232149
'direct_dependent_settings': {
'mac_bundle_resources': [ '../styles' ],
}
},
{
'target_name': 'copy_styles',
'type': 'none',
'hard_dependency': 1,
'dependencies': [ 'touch_styles' ], # required for xcode http://openradar.appspot.com/7232149
'copies': [{
'files': [ '../styles' ],
'destination': '<(PRODUCT_DIR)'
}],
},
]
}

View File

@@ -31,8 +31,8 @@ namespace CSSColorParser {
struct Color {
inline Color() {}
inline Color(unsigned char r, unsigned char g, unsigned char b, float a)
: r(r), g(g), b(b), a(a) {}
inline Color(unsigned char r_, unsigned char g_, unsigned char b_, float a_)
: r(r_), g(g_), b(b_), a(a_) {}
unsigned char r = 0, g = 0, b = 0;
float a = 1.0f;
};

View File

@@ -12,10 +12,10 @@ struct Anchor {
float scale = 0.0f;
int segment = -1;
explicit Anchor(float x, float y, float angle, float scale)
: x(x), y(y), angle(angle), scale(scale) {}
explicit Anchor(float x, float y, float angle, float scale, int segment)
: x(x), y(y), angle(angle), scale(scale), segment(segment) {}
explicit Anchor(float x_, float y_, float angle_, float scale_)
: x(x_), y(y_), angle(angle_), scale(scale_) {}
explicit Anchor(float x_, float y_, float angle_, float scale_, int segment_)
: x(x_), y(y_), angle(angle_), scale(scale_), segment(segment_) {}
};
typedef std::vector<Anchor> Anchors;

View File

@@ -84,15 +84,15 @@ protected:
}
// Get a pointer to the item at a given index.
inline void *getElement(size_t index) {
inline void *getElement(size_t i) {
if (array == nullptr) {
throw std::runtime_error("Buffer was already deleted or doesn't contain elements");
}
if (index * itemSize >= pos) {
if (i * itemSize >= pos) {
throw new std::runtime_error("Can't get element after array bounds");
} else {
return static_cast<char *>(array) + (index * itemSize);
return static_cast<char *>(array) + (i * itemSize);
}
}

View File

@@ -16,9 +16,9 @@ struct ElementGroup : public util::noncopyable {
uint32_t elements_length;
ElementGroup() : vertex_length(0), elements_length(0) {}
ElementGroup(uint32_t vertex_length, uint32_t elements_length)
: vertex_length(vertex_length),
elements_length(elements_length) {
ElementGroup(uint32_t vertex_length_, uint32_t elements_length_)
: vertex_length(vertex_length_),
elements_length(elements_length_) {
}
ElementGroup(ElementGroup &&rhs) noexcept

View File

@@ -30,8 +30,8 @@ private:
int32_t ox, oy;
};
Geometry::Geometry(pbf& data)
: data(data),
Geometry::Geometry(pbf& data_)
: data(data_),
cmd(1),
length(0),
x(0), y(0),

View File

@@ -18,12 +18,14 @@ public:
private:
struct GlyphValue {
GlyphValue(const Rect<uint16_t>& rect, uint64_t id)
: rect(rect), ids({ id }) {}
GlyphValue(const Rect<uint16_t>& rect_, uint64_t id)
: rect(rect_), ids({ id }) {}
Rect<uint16_t> rect;
std::set<uint64_t> ids;
};
Rect<uint16_t> addGlyph_impl(uint64_t tile_id, const std::string& face_name,
const SDFGlyph& glyph);
public:
GlyphAtlas(uint16_t width, uint16_t height);
~GlyphAtlas();
@@ -31,6 +33,8 @@ public:
Rect<uint16_t> addGlyph(uint64_t tile_id, const std::string& face_name,
const SDFGlyph& glyph);
void addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname,
FontStack const& fontStack, GlyphPositions & face);
void removeGlyphs(uint64_t tile_id);
void bind();

View File

@@ -63,6 +63,9 @@ public:
// Triggers a cleanup that releases resources.
void cleanup();
// Releases resources immediately
void terminate();
// Controls buffer swapping.
bool needsSwap();
void swapped();
@@ -143,15 +146,9 @@ public:
private:
// uv async callbacks
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
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);
#else
static void render(uv_async_t *async);
static void terminate(uv_async_t *async);
static void cleanup(uv_async_t *async);
#endif
// Setup
void setup();

View File

@@ -37,8 +37,8 @@ public:
const int8_t z = 0;
const int32_t x = 0, y = 0;
inline explicit ID(int8_t z, int32_t x, int32_t y)
: w((x < 0 ? x - (1 << z) + 1 : x) / (1 << z)), z(z), x(x), y(y) {}
inline explicit ID(int8_t z_, int32_t x_, int32_t y_)
: w((x_ < 0 ? x_ - (1 << z_) + 1 : x_) / (1 << z_)), z(z_), x(x_), y(y_) {}
inline uint64_t to_uint64() const {
return ((std::pow(2, z) * y + x) * 32) + z;

View File

@@ -22,8 +22,8 @@ enum MapChange : uint8_t {
class View {
public:
virtual void initialize(Map *map) {
this->map = map;
virtual void initialize(Map *map_) {
map = map_;
}
// Called from the render (=GL) thread. Signals that the context should
@@ -35,11 +35,9 @@ public:
// renderer setup since the render thread doesn't switch the contexts.
virtual void make_active() = 0;
// Returns the base framebuffer object, if any, and 0 if using the system
// provided framebuffer.
virtual unsigned int root_fbo() {
return 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;
virtual void notify() = 0;

View File

@@ -17,6 +17,7 @@ public:
void initialize(mbgl::Map *map);
void swap();
void make_active();
void make_inactive();
void notify();
void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0);

View File

@@ -0,0 +1,2 @@
#include <GL/glx.h>
#undef None

View File

@@ -0,0 +1,25 @@
#ifndef MBGL_COMMON_HEADLESS_DISPLAY
#define MBGL_COMMON_HEADLESS_DISPLAY
#include "headless_view.hpp"
namespace mbgl {
class HeadlessDisplay {
public:
HeadlessDisplay();
~HeadlessDisplay();
#if MBGL_USE_CGL
CGLPixelFormatObj pixelFormat;
#endif
#if MBGL_USE_GLX
Display *x_display = nullptr;
GLXFBConfig *fb_configs = nullptr;
#endif
};
}
#endif

View File

@@ -1,51 +1,63 @@
#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
#define GL_GLEXT_PROTOTYPES
#include <GL/glx.h>
#define MBGL_USE_GLX 1
#endif
#include <mbgl/map/view.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/util/time.hpp>
#include <memory>
namespace mbgl {
class HeadlessDisplay;
class HeadlessView : public View {
public:
HeadlessView();
HeadlessView(std::shared_ptr<HeadlessDisplay> display);
~HeadlessView();
void createContext();
void resize(uint16_t width, uint16_t height, float pixelRatio);
const std::unique_ptr<uint32_t[]> readPixels();
void notify();
void notify_map_change(MapChange change, timestamp delay = 0);
void make_active();
void make_inactive();
void swap();
unsigned int root_fbo();
private:
void clear_buffers();
private:
std::shared_ptr<HeadlessDisplay> display_;
uint16_t width_;
uint16_t height_;
float pixelRatio_;
#if MBGL_USE_CGL
CGLContextObj gl_context;
GLuint fbo = 0;
GLuint fbo_depth_stencil = 0;
GLuint fbo_color = 0;
#endif
#if MBGL_USE_GLX
GLXContext gl_context = nullptr;
XVisualInfo *x_info = nullptr;
Display *x_display = nullptr;
Pixmap x_pixmap = 0;
GLXPixmap glx_pixmap = 0;
GLXFBConfig *fb_configs = nullptr;
GLXContext gl_context = 0;
GLXPbuffer glx_pbuffer = 0;
#endif
GLuint fbo = 0;
GLuint fbo_depth_stencil = 0;
GLuint fbo_color = 0;
};
}

View File

@@ -11,7 +11,7 @@
namespace mbgl {
struct FrameSnapshot {
explicit inline FrameSnapshot(timestamp t, float z) : t(t), z(z) {}
explicit inline FrameSnapshot(timestamp t_, float z_) : t(t_), z(z_) {}
float t;
float z;
};

View File

@@ -64,6 +64,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.
@@ -124,6 +125,7 @@ public:
private:
void setupShaders();
void deleteShaders();
mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor);
void prepareTile(const Tile& tile);
@@ -152,10 +154,10 @@ public:
// used to composite images and flips the geometry upside down
const mat4 flipMatrix = []{
mat4 flipMatrix;
matrix::ortho(flipMatrix, 0, 4096, -4096, 0, 0, 1);
matrix::translate(flipMatrix, flipMatrix, 0, -4096, 0);
return flipMatrix;
mat4 flip;
matrix::ortho(flip, 0, 4096, -4096, 0, 0, 1);
matrix::translate(flip, flip, 0, -4096, 0);
return flip;
}();
const mat4 identityMatrix = []{

View File

@@ -86,8 +86,8 @@ private:
void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, PlacementRange placementRange);
// Adds glyphs to the glyph atlas so that they have a left/top/width/height coordinates associated to them that we can use for writing to a buffer.
void addGlyphsToAtlas(uint64_t tileid, const std::string stackname, const std::u32string &string,
const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face);
static void addGlyphsToAtlas(uint64_t tileid, const std::string stackname, const std::u32string &string,
const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face);
public:
const StyleBucketSymbol &properties;

View File

@@ -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<std::string, ClassID> store;
static uint32_t offset;
std::unordered_map<std::string, ClassID> store = { { "", ClassID::Default } };
uint32_t offset = 0;
};
}

View File

@@ -12,8 +12,8 @@ namespace mbgl {
class ClassProperties {
public:
inline ClassProperties() {}
inline ClassProperties(ClassProperties &&properties)
: properties(std::move(properties.properties)) {}
inline ClassProperties(ClassProperties &&properties_)
: properties(std::move(properties_.properties)) {}
inline void set(PropertyKey key, const PropertyValue &value) {
properties.emplace(key, value);

View File

@@ -24,8 +24,8 @@ public:
class Instance {
public:
Instance(Operator op, std::vector<Value> &&values)
: op(op), values(values) {}
Instance(Operator op_, std::vector<Value> &&values_)
: op(op_), values(values_) {}
bool compare(const std::vector<Value> &property_values) const;
@@ -37,7 +37,7 @@ public:
};
public:
FilterComparison(const std::string &field) : field(field) {};
FilterComparison(const std::string &field_) : field(field_) {};
const std::string &getField() const;
template <typename Extractor> inline bool compare(const Extractor &extractor) const;

View File

@@ -28,7 +28,7 @@ public:
public:
FilterExpression() = default;
FilterExpression(Operator op) : op(op) {};
FilterExpression(Operator op_) : op(op_) {};
bool empty() const;

View File

@@ -9,7 +9,7 @@ namespace mbgl {
template <typename T>
struct ConstantFunction {
inline ConstantFunction(const T &value) : value(value) {}
inline ConstantFunction(const T &value_) : value(value_) {}
inline T evaluate(float) const { return value; }
private:
@@ -18,7 +18,7 @@ private:
template <typename T>
struct StopsFunction {
inline StopsFunction(const std::vector<std::pair<float, T>> &values, float base) : values(values), base(base) {}
inline StopsFunction(const std::vector<std::pair<float, T>> &values_, float base_) : values(values_), base(base_) {}
T evaluate(float z) const;
private:
@@ -36,7 +36,7 @@ using Function = mapbox::util::variant<
template <typename T>
struct FunctionEvaluator {
typedef T result_type;
inline FunctionEvaluator(float z) : z(z) {}
inline FunctionEvaluator(float z_) : z(z_) {}
inline result_type operator()(const std::false_type &) {
return result_type();

View File

@@ -36,8 +36,8 @@ public:
bool enabled = false;
util::ptr<Source> source;
StyleSource(const util::ptr<SourceInfo> &info)
: info(info)
StyleSource(const util::ptr<SourceInfo> &info_)
: info(info_)
{}
};

View File

@@ -6,6 +6,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wshadow"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wdeprecated-register"
#else

View File

@@ -30,9 +30,9 @@ struct GlyphMetrics {
struct Glyph {
inline explicit Glyph() : rect(0, 0, 0, 0), metrics() {}
inline explicit Glyph(const Rect<uint16_t> &rect,
const GlyphMetrics &metrics)
: rect(rect), metrics(metrics) {}
inline explicit Glyph(const Rect<uint16_t> &rect_,
const GlyphMetrics &metrics_)
: rect(rect_), metrics(metrics_) {}
operator bool() const {
return metrics || rect;
@@ -46,8 +46,8 @@ typedef std::map<uint32_t, Glyph> GlyphPositions;
class PositionedGlyph {
public:
inline explicit PositionedGlyph(uint32_t glyph, float x, float y)
: glyph(glyph), x(x), y(y) {}
inline explicit PositionedGlyph(uint32_t glyph_, float x_, float y_)
: glyph(glyph_), x(x_), y(y_) {}
uint32_t glyph = 0;
float x = 0;

View File

@@ -3,11 +3,10 @@
#include <mbgl/util/vec.hpp>
#include <mbgl/util/rect.hpp>
#include <mbgl/util/optional.hpp>
#include <array>
#include <vector>
#include <boost/optional.hpp>
namespace mbgl {
typedef vec2<float> CollisionPoint;
@@ -29,31 +28,31 @@ struct CollisionRect {
CollisionPoint::Type bx,
CollisionPoint::Type by)
: tl(ax, ay), br(bx, by) {}
inline explicit CollisionRect(const CollisionPoint &tl,
const CollisionPoint &br)
: tl(tl), br(br) {}
inline explicit CollisionRect(const CollisionPoint &tl_,
const CollisionPoint &br_)
: tl(tl_), br(br_) {}
};
// These are the glyph boxes that we want to have placed.
struct GlyphBox {
explicit GlyphBox() {}
explicit GlyphBox(const CollisionRect &box,
const CollisionAnchor &anchor,
float minScale,
float maxScale,
float padding)
: box(box), anchor(anchor), minScale(minScale), maxScale(maxScale), padding(padding) {}
explicit GlyphBox(const CollisionRect &box,
float minScale,
float padding)
: box(box), minScale(minScale), padding(padding) {}
explicit GlyphBox(const CollisionRect &box_,
const CollisionAnchor &anchor_,
float minScale_,
float maxScale_,
float padding_)
: box(box_), anchor(anchor_), minScale(minScale_), maxScale(maxScale_), padding(padding_) {}
explicit GlyphBox(const CollisionRect &box_,
float minScale_,
float padding_)
: box(box_), minScale(minScale_), padding(padding_) {}
CollisionRect box;
CollisionAnchor anchor;
float minScale = 0.0f;
float maxScale = std::numeric_limits<float>::infinity();
float padding = 0.0f;
boost::optional<CollisionRect> hBox;
mapbox::util::optional<CollisionRect> hBox;
};
typedef std::vector<GlyphBox> GlyphBoxes;
@@ -61,19 +60,19 @@ typedef std::vector<GlyphBox> GlyphBoxes;
// TODO: Transform the vec2<float>s to vec2<int16_t> to save bytes
struct PlacedGlyph {
explicit PlacedGlyph(const vec2<float> &tl, const vec2<float> &tr,
const vec2<float> &bl, const vec2<float> &br,
const Rect<uint16_t> &tex, float angle, const vec2<float> &anchor,
float minScale, float maxScale)
: tl(tl),
tr(tr),
bl(bl),
br(br),
tex(tex),
angle(angle),
anchor(anchor),
minScale(minScale),
maxScale(maxScale) {}
explicit PlacedGlyph(const vec2<float> &tl_, const vec2<float> &tr_,
const vec2<float> &bl_, const vec2<float> &br_,
const Rect<uint16_t> &tex_, float angle_, const vec2<float> &anchor_,
float minScale_, float maxScale_)
: tl(tl_),
tr(tr_),
bl(bl_),
br(br_),
tex(tex_),
angle(angle_),
anchor(anchor_),
minScale(minScale_),
maxScale(maxScale_) {}
vec2<float> tl, tr, bl, br;
Rect<uint16_t> tex;
@@ -88,7 +87,7 @@ typedef std::vector<PlacedGlyph> PlacedGlyphs;
struct PlacementBox {
CollisionAnchor anchor;
CollisionRect box;
boost::optional<CollisionRect> hBox;
mapbox::util::optional<CollisionRect> hBox;
PlacementRange placementRange = {{0.0f, 0.0f}};
float placementScale = 0.0f;
float maxScale = std::numeric_limits<float>::infinity();
@@ -97,8 +96,8 @@ struct PlacementBox {
struct PlacementProperty {
explicit PlacementProperty() {}
explicit PlacementProperty(float zoom, const PlacementRange &rotationRange)
: zoom(zoom), rotationRange(rotationRange) {}
explicit PlacementProperty(float zoom_, const PlacementRange &rotationRange_)
: zoom(zoom_), rotationRange(rotationRange_) {}
inline operator bool() const {
return !std::isnan(zoom) && zoom != std::numeric_limits<float>::infinity() &&

View File

@@ -21,11 +21,11 @@ private:
static constexpr inline bool compare(const char *a, const char *b) {
return *a == *b && (*a == '\0' || compare(a + 1, b + 1));
}
static constexpr inline const char *lookup_type(Type e, EnumValue<Type> const * const l, size_t r) {
return r == 0 ? "" : l->value == e ? l->name : lookup_type(e, l + 1, r - 1);
static constexpr inline const char *lookup_type(Type e, EnumValue<Type> const * const list, size_t r) {
return r == 0 ? "" : list->value == e ? list->name : lookup_type(e, list + 1, r - 1);
}
static constexpr inline Type lookup_name(const char *n, EnumValue<Type> const * const l, size_t r) {
return r == 0 ? Type(-1) : compare(l->name, n) ? l->value : lookup_name(n, l + 1, r - 1);
static constexpr inline Type lookup_name(const char *n, EnumValue<Type> const * const list, size_t r) {
return r == 0 ? Type(-1) : compare(list->name, n) ? list->value : lookup_name(n, list + 1, r - 1);
}
public:
inline constexpr Enum(const char *n) : value(lookup_name(n, names, length)) {}

View File

@@ -8,7 +8,7 @@ namespace mbgl {
namespace error {
struct style_parse : std::exception {
inline style_parse(size_t offset, const char *msg) : offset(offset), msg(msg) {}
inline style_parse(size_t offset_, const char *msg_) : offset(offset_), msg(msg_) {}
inline const char* what() const noexcept { return msg.c_str(); }
const size_t offset;
const std::string msg;

View File

@@ -0,0 +1,69 @@
#ifndef MAPBOX_UTIL_OPTIONAL_HPP
#define MAPBOX_UTIL_OPTIONAL_HPP
#include <type_traits>
#include "variant.hpp"
namespace mapbox
{
namespace util
{
template <typename T> class optional
{
static_assert(!std::is_reference<T>::value, "optional doesn't support references");
struct none_type
{
};
variant<none_type, T> variant_;
public:
optional() = default;
optional(optional const &rhs)
{
if (this != &rhs)
{ // protect against invalid self-assignment
variant_ = rhs.variant_;
}
}
optional(T const &v) { variant_ = v; }
explicit operator bool() const noexcept { return variant_.template is<T>(); }
T const &get() const { return variant_.template get<T>(); }
T &get() { return variant_.template get<T>(); }
T const &operator*() const { return this->get(); }
T operator*() { return this->get(); }
optional &operator=(T const &v)
{
variant_ = v;
return *this;
}
optional &operator=(optional const &rhs)
{
if (this != &rhs)
{
variant_ = rhs.variant_;
}
return *this;
}
template <typename... Args> void emplace(Args &&... args)
{
variant_ = T{std::forward<Args>(args)...};
}
void reset() { variant_ = none_type{}; }
};
}
}
#endif

View File

@@ -49,9 +49,9 @@ struct pbf {
uint32_t tag = 0;
};
pbf::pbf(const unsigned char *data, size_t length)
: data(data),
end(data + length),
pbf::pbf(const unsigned char *data_, size_t length)
: data(data_),
end(data_ + length),
value(0),
tag(0) {
}
@@ -132,9 +132,9 @@ double pbf::float64() {
std::string pbf::string() {
uint32_t bytes = static_cast<uint32_t>(varint());
const char *string = reinterpret_cast<const char*>(data);
const char *string_data = reinterpret_cast<const char*>(data);
skipBytes(bytes);
return std::string(string, bytes);
return std::string(string_data, bytes);
}
bool pbf::boolean() {

View File

@@ -6,7 +6,7 @@ namespace mbgl {
template <typename T>
struct Rect {
inline Rect() {}
inline Rect(T x, T y, T w, T h) : x(x), y(y), w(w), h(h) {}
inline Rect(T x_, T y_, T w_, T h_) : x(x_), y(y_), w(w_), h(h_) {}
T x = 0, y = 0;
T w = 0, h = 0;

View File

@@ -15,9 +15,9 @@ public:
complete
};
inline transition(timestamp start, timestamp duration)
: start(start),
duration(duration) {}
inline transition(timestamp start_, timestamp duration_)
: start(start_),
duration(duration_) {}
inline float progress(timestamp now) const {
if (duration == 0) return 1;
@@ -36,11 +36,11 @@ protected:
template <typename T>
class ease_transition : public transition {
public:
ease_transition(T from, T to, T& value, timestamp start, timestamp duration)
: transition(start, duration),
from(from),
to(to),
value(value) {}
ease_transition(T from_, T to_, T& value_, timestamp start_, timestamp duration_)
: transition(start_, duration_),
from(from_),
to(to_),
value(value_) {}
state update(timestamp now) const;
@@ -53,10 +53,10 @@ private:
template <typename T>
class timeout : public transition {
public:
timeout(T final_value, T& value, timestamp start, timestamp duration)
: transition(start, duration),
final_value(final_value),
value(value) {}
timeout(T final_value_, T& value_, timestamp start_, timestamp duration_)
: transition(start_, duration_),
final_value(final_value_),
value(value_) {}
state update(timestamp now) const {
if (progress(now) >= 1) {

View File

@@ -29,7 +29,7 @@ public:
if (l == nullptr) {
#else
l = new uv_loop_t;
if (uv_loop_init(&l) != 0) {
if (uv_loop_init(l) != 0) {
#endif
throw std::runtime_error("failed to initialize loop");
}
@@ -68,7 +68,7 @@ private:
class lock {
public:
lock(mutex &mtx) : mtx(mtx) { mtx.lock(); }
lock(mutex &mtx_) : mtx(mtx_) { mtx.lock(); }
~lock() { mtx.unlock(); }
private:
@@ -94,8 +94,8 @@ private:
class readlock {
public:
inline readlock(rwlock &mtx) : mtx(mtx) { mtx.rdlock(); }
inline readlock(const std::unique_ptr<rwlock> &mtx) : mtx(*mtx) { mtx->rdlock(); }
inline readlock(rwlock &mtx_) : mtx(mtx_) { mtx.rdlock(); }
inline readlock(const std::unique_ptr<rwlock> &mtx_) : mtx(*mtx_) { mtx.rdlock(); }
inline ~readlock() { mtx.rdunlock(); }
private:
@@ -104,8 +104,8 @@ private:
class writelock {
public:
inline writelock(rwlock &mtx) : mtx(mtx) { mtx.wrlock(); }
inline writelock(const std::unique_ptr<rwlock> &mtx) : mtx(*mtx) { mtx->wrlock(); }
inline writelock(rwlock &mtx_) : mtx(mtx_) { mtx.wrlock(); }
inline writelock(const std::unique_ptr<rwlock> &mtx_) : mtx(*mtx_) { mtx.wrlock(); }
inline ~writelock() { mtx.wrunlock(); }
private:
@@ -148,10 +148,10 @@ public:
typedef void (*after_work_callback)(T &object);
template<typename... Args>
work(worker &worker, work_callback work_cb, after_work_callback after_work_cb, Args&&... args)
work(worker &worker, work_callback work_cb_, after_work_callback after_work_cb_, Args&&... args)
: data(std::forward<Args>(args)...),
work_cb(work_cb),
after_work_cb(after_work_cb) {
work_cb(work_cb_),
after_work_cb(after_work_cb_) {
worker.add(this, do_work, after_work);
}

View File

@@ -4,7 +4,6 @@
#include <utility>
#include <typeinfo>
#include <type_traits>
#include <algorithm> // std::move/swap
#include <stdexcept> // runtime_error
#include <new> // operator new
#include <cstddef> // size_t
@@ -515,22 +514,13 @@ public:
VARIANT_INLINE variant(no_init)
: type_index(detail::invalid_value) {}
// http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
template <typename T, class = typename std::enable_if<
detail::is_valid_type<T, Types...>::value>::type>
VARIANT_INLINE explicit variant(T const& val) noexcept
: type_index(detail::value_traits<T, Types...>::index)
{
constexpr std::size_t index = sizeof...(Types) - detail::value_traits<T, Types...>::index - 1;
using target_type = typename detail::select_type<index, Types...>::type;
new (&data) target_type(val);
}
template <typename T, class = typename std::enable_if<
detail::is_valid_type<T, Types...>::value>::type>
detail::is_valid_type<typename std::remove_reference<T>::type, Types...>::value>::type>
VARIANT_INLINE variant(T && val) noexcept
: type_index(detail::value_traits<T, Types...>::index)
: type_index(detail::value_traits<typename std::remove_reference<T>::type, Types...>::index)
{
constexpr std::size_t index = sizeof...(Types) - detail::value_traits<T, Types...>::index - 1;
constexpr std::size_t index = sizeof...(Types) - detail::value_traits<typename std::remove_reference<T>::type, Types...>::index - 1;
using target_type = typename detail::select_type<index, Types...>::type;
new (&data) target_type(std::forward<T>(val)); // nothrow
}
@@ -565,7 +555,7 @@ public:
template <typename T>
VARIANT_INLINE variant<Types...>& operator=(T && rhs) noexcept
{
variant<Types...> temp(std::move(rhs));
variant<Types...> temp(std::forward<T>(rhs));
swap(*this, temp);
return *this;
}

View File

@@ -29,7 +29,7 @@ struct vec2 {
template<typename U>
inline vec2(const U& u) : x(u.x), y(u.y) {}
inline vec2(T x, T y) : x(x), y(y) {}
inline vec2(T x_, T y_) : x(x_), y(y_) {}
inline bool operator==(const vec2& rhs) const {
return x == rhs.x && y == rhs.y;
@@ -86,7 +86,7 @@ struct vec3 {
inline vec3() {}
inline vec3(const vec3& o) : x(o.x), y(o.y), z(o.z) {}
inline vec3(T x, T y, T z) : x(x), y(y), z(z) {}
inline vec3(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
inline bool operator==(const vec3& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z;
}
@@ -98,7 +98,7 @@ struct vec4 {
inline vec4() {}
inline vec4(const vec4& o) : x(o.x), y(o.y), z(o.z), w(o.w) {}
inline vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
inline vec4(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {}
inline bool operator==(const vec4& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
}

View File

@@ -1,15 +1,16 @@
#include <mbgl/mbgl.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/util/uv.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/default/settings_json.hpp>
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/platform/default/log_stderr.hpp>
#include <signal.h>
#include <getopt.h>
#include <fstream>
#include <sstream>
#include "../common/settings_json.hpp"
#include "../common/glfw_view.hpp"
#include "../common/stderr_log.hpp"
GLFWView *view = nullptr;

View File

@@ -1,7 +1,6 @@
{
'includes': [
'../common.gypi',
'../config.gypi',
'../gyp/common.gypi',
],
'targets': [
{
@@ -10,15 +9,9 @@
'type': 'executable',
'sources': [
'./main.cpp',
'../common/settings_json.cpp',
'../common/settings_json.hpp',
'../common/platform_default.cpp',
'../common/glfw_view.hpp',
'../common/glfw_view.cpp',
'../common/http_request_baton_curl.cpp',
'../common/linux.cpp',
'../common/stderr_log.hpp',
'../common/stderr_log.cpp',
'../platform/default/settings_json.cpp',
'../platform/default/glfw_view.cpp',
'../platform/default/log_stderr.cpp',
],
'conditions': [
@@ -29,11 +22,9 @@
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS':[
'<@(glfw3_cflags)',
'<@(curl_cflags)',
],
'OTHER_LDFLAGS': [
'<@(glfw3_libraries)',
'<@(curl_libraries)',
],
}
},
@@ -42,19 +33,19 @@
{
'cflags': [
'<@(glfw3_cflags)',
'<@(curl_cflags)',
],
'link_settings': {
'libraries': [
'<@(glfw3_libraries)',
'<@(curl_libraries)',
'-lboost_regex'
'-L<(boost_root)/lib',
'-lboost_regex',
],
},
}],
],
'dependencies': [
'../mapboxgl.gyp:mapboxgl',
'../mapboxgl.gyp:mbgl',
'../mapboxgl.gyp:mbgl-linux',
'../mapboxgl.gyp:copy_styles',
'../mapboxgl.gyp:copy_certificate_bundle',
],

View File

@@ -1,12 +1,10 @@
#include "../common/settings_nsuserdefaults.hpp"
#include "../common/glfw_view.hpp"
#include "../common/nslog_log.hpp"
#include "../common/Reachability.h"
#include <mbgl/platform/darwin/settings_nsuserdefaults.hpp>
#include <mbgl/platform/darwin/log_nslog.hpp>
#include <mbgl/platform/darwin/Reachability.h>
#include <mbgl/platform/default/glfw_view.hpp>
#import <Foundation/Foundation.h>
#include <uv.h>
@interface URLHandler : NSObject
@property (nonatomic) mbgl::Map *map;
@@ -71,7 +69,6 @@
@end
int main() {
fprintf(stderr, "main thread: 0x%lx\n", uv_thread_self());
mbgl::Log::Set<mbgl::NSLogBackend>();
GLFWView view;

View File

@@ -1,7 +1,6 @@
{
'includes': [
'../common.gypi',
'../config.gypi'
'../gyp/common.gypi',
],
'targets': [
{
@@ -10,17 +9,11 @@
'type': 'executable',
'sources': [
'./main.mm',
'../common/settings_nsuserdefaults.hpp',
'../common/settings_nsuserdefaults.mm',
'../common/platform_nsstring.mm',
'../common/glfw_view.hpp',
'../common/glfw_view.cpp',
'../common/reachability.h',
'../common/reachability.m',
'../common/http_request_baton_cocoa.mm',
'../common/osx.mm',
'../common/nslog_log.hpp',
'../common/nslog_log.mm',
'../platform/darwin/settings_nsuserdefaults.hpp',
'../platform/darwin/settings_nsuserdefaults.mm',
'../platform/darwin/reachability.m',
'../platform/default/glfw_view.hpp',
'../platform/default/glfw_view.cpp',
],
'product_extension': 'app',
'mac_bundle': 1,
@@ -44,7 +37,8 @@
},
'dependencies': [
'../mapboxgl.gyp:bundle_styles',
'../mapboxgl.gyp:mapboxgl',
'../mapboxgl.gyp:mbgl',
'../mapboxgl.gyp:mbgl-osx',
]
}
]

View File

@@ -1,249 +1,14 @@
{
'includes': [
'./common.gypi',
'./gyp/common.gypi',
'./gyp/shaders.gypi',
'./gyp/npm_install.gypi',
'./gyp/styles.gypi',
'./gyp/fixtures.gypi',
'./gyp/certificates.gypi',
'./gyp/mbgl.gypi',
'./gyp/mbgl-platform.gypi',
'./gyp/mbgl-headless.gypi',
'./gyp/install.gypi',
],
'targets': [
{
'target_name': 'shaders',
'type': 'none',
'hard_dependency': 1,
'dependencies': [
'npm_install'
],
'actions': [
{
'action_name': 'Build Shaders',
'inputs': [
'<!@(find src -name "*.glsl")'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/include/mbgl/shader/shaders.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp',
],
'action': ['<@(node)', 'bin/build-shaders.js', '<(SHARED_INTERMEDIATE_DIR)'],
}
],
'direct_dependent_settings': {
'sources': [
'<(SHARED_INTERMEDIATE_DIR)/include/mbgl/shader/shaders.hpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp'
],
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)/include/',
]
}
},
{
'target_name': 'npm_install',
'type': 'none',
'hard_dependency': 1,
'actions': [
{
'action_name': 'npm install',
'inputs': [
'bin/package.json',
],
'outputs': [
'bin/node_modules',
],
'action': ['./scripts/npm_install.sh', '<@(npm)']
}
],
},
{
'target_name': 'touch_styles',
'type': 'none',
'hard_dependency': 1,
'actions': [
{
'action_name': 'Touch Stylesheet Directory',
'inputs': ['styles'],
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/'], # need to specify a distinct directory
'action': ['touch', 'styles'],
}
],
},
{
'target_name': 'bundle_styles',
'type': 'none',
'hard_dependency': 1,
'dependencies': [ 'touch_styles' ], # required for xcode http://openradar.appspot.com/7232149
'direct_dependent_settings': {
'mac_bundle_resources': [ 'styles' ],
}
},
{
'target_name': 'copy_styles',
'type': 'none',
'hard_dependency': 1,
'dependencies': [ 'touch_styles' ], # required for xcode http://openradar.appspot.com/7232149
'copies': [{
'files': [ 'styles' ],
'destination': '<(PRODUCT_DIR)'
}],
},
{
'target_name': 'copy_fixtures',
'type': 'none',
'hard_dependency': 1,
'dependencies': [
'bundle_styles'
],
'copies': [
{
'files': [ 'styles' ],
'destination': 'test/fixtures/style_parser'
}
]
},
{
'target_name': 'copy_certificate_bundle',
'type': 'none',
'hard_dependency': 1,
'copies': [{
'files': [ 'common/ca-bundle.crt' ],
'destination': '<(PRODUCT_DIR)'
}],
},
{
'target_name': 'mapboxgl',
'product_name': 'mapboxgl',
'type': 'static_library',
'hard_dependency': 1,
'dependencies': [
'shaders',
],
'sources': [
'<!@(find src -name "*.cpp")',
'<!@(test -f "config/constants_local.cpp" && echo "config/constants_local.cpp" || echo "config/constants.cpp")',
'<!@(find src -name "*.c")',
'<!@(find src -name "*.h")',
'<!@(find include -name "*.hpp")',
'<!@(find include -name "*.h")',
'<!@(find src -name "*.glsl")',
'bin/style.json'
],
'include_dirs': [
'./include'
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'SDKROOT': 'macosx',
'SUPPORTED_PLATFORMS': ['macosx'],
'MACOSX_DEPLOYMENT_TARGET': '10.9',
'PUBLIC_HEADERS_FOLDER_PATH': 'include',
'OTHER_CPLUSPLUSFLAGS': [
'<@(png_cflags)',
'<@(uv_cflags)',
'<@(sqlite3_cflags)',
'<@(zlib_cflags)',
'-I<(boost_root)/include',
],
'OTHER_CFLAGS': [
'<@(uv_cflags)',
],
},
}, {
'cflags': [
'<@(png_cflags)',
'<@(uv_cflags)',
'<@(sqlite3_cflags)',
'<@(zlib_cflags)',
'-I<(boost_root)/include',
],
}]
],
'direct_dependent_settings': {
'include_dirs': [
'./include',
],
'conditions': [
['OS == "mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [
'<@(uv_cflags)',
],
'OTHER_LDFLAGS': [
'<@(png_libraries)',
'<@(uv_libraries)',
'<@(sqlite3_libraries)',
'<@(zlib_libraries)',
]
}
}, {
'cflags': [
'<@(uv_cflags)',
],
'libraries': [
'<@(png_libraries)',
'<@(uv_libraries)',
'<@(sqlite3_libraries)',
'<@(zlib_libraries)',
]
}]
]
}
},
{
'target_name': 'mapboxgl-ios',
'product_name': 'mapboxgl-ios',
'type': 'static_library',
'hard_dependency': 1,
'dependencies': [
'shaders',
],
'sources': [
'<!@(find src/ \( -name "*.cpp" ! -name shaders.hpp ! -name shaders_gles2.cpp ! -name shaders_gl.cpp \))',
'<!@(test -f "config/constants_local.cpp" && echo "config/constants_local.cpp" || echo "config/constants.cpp")',
'<!@(find src -name "*.c")',
'<!@(find src -name "*.h")',
'<!@(find include -name "*.hpp")',
'<!@(find include -name "*.h")',
'<!@(find src -name "*.glsl")',
'bin/style.json'
],
'xcode_settings': {
'SDKROOT': 'iphoneos',
'SUPPORTED_PLATFORMS': 'iphonesimulator iphoneos',
'ARCHS': [ "armv7", "armv7s", "arm64", "i386", "x86_64" ],
'TARGETED_DEVICE_FAMILY': '1,2',
'CODE_SIGN_IDENTITY': 'iPhone Developer',
'IPHONEOS_DEPLOYMENT_TARGET': '7.0',
'PUBLIC_HEADERS_FOLDER_PATH': 'include',
'GCC_INPUT_FILETYPE': 'sourcecode.cpp.cpp',
'OTHER_CPLUSPLUSFLAGS': [
'<@(png_cflags)',
'<@(uv_cflags)',
'<@(sqlite3_cflags)',
'<@(zlib_cflags)',
'-I<(boost_root)/include',
],
},
'include_dirs': [
'./include'
],
'direct_dependent_settings': {
'include_dirs': [
'./include',
],
'xcode_settings': {
'OTHER_LDFLAGS': [
'<@(png_libraries)',
'<@(uv_libraries)',
'<@(sqlite3_libraries)',
'<@(zlib_libraries)',
],
'OTHER_CPLUSPLUSFLAGS': [
'<@(uv_cflags)',
],
'OTHER_CFLAGS': [
'<@(uv_cflags)',
],
}
}
}
]
}

View File

@@ -1,4 +1,4 @@
#include "nslog_log.hpp"
#include <mbgl/platform/darwin/log_nslog.hpp>
#import <Foundation/Foundation.h>

View File

@@ -25,7 +25,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/
#import "Reachability.h"
#import <mbgl/platform/darwin/reachability.h>
NSString *const kReachabilityChangedNotification = @"kReachabilityChangedNotification";

View File

@@ -1,6 +1,6 @@
#import <Foundation/Foundation.h>
#include "settings_nsuserdefaults.hpp"
#include <mbgl/platform/darwin/settings_nsuserdefaults.hpp>
using namespace mbgl;

View File

@@ -18,4 +18,4 @@ std::string lowercase(const std::string &string) {
}
}
}
}

View File

@@ -1,17 +1,20 @@
#include "glfw_view.hpp"
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/util/string.hpp>
GLFWView::GLFWView(bool fullscreen) : fullscreen(fullscreen) {
GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
#ifdef NVIDIA
glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXTPROC)glfwGetProcAddress("glDiscardFramebufferEXT");
#endif
}
GLFWView::~GLFWView() { glfwTerminate(); }
GLFWView::~GLFWView() {
map->terminate();
glfwTerminate();
}
void GLFWView::initialize(mbgl::Map *map) {
View::initialize(map);
void GLFWView::initialize(mbgl::Map *map_) {
View::initialize(map_);
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize glfw\n");
@@ -194,6 +197,10 @@ void GLFWView::make_active() {
glfwMakeContextCurrent(window);
}
void GLFWView::make_inactive() {
glfwMakeContextCurrent(nullptr);
}
void GLFWView::notify() {
glfwPostEmptyEvent();
}

View File

@@ -0,0 +1,74 @@
#include <mbgl/platform/default/headless_display.hpp>
#include <cstring>
#include <stdexcept>
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
if (!XInitThreads()) {
throw std::runtime_error("Failed to XInitThreads");
}
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");
}
// We're creating a dummy pbuffer anyway that we're not using.
static int pixelFormat[] = {
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
None
};
int configs = 0;
fb_configs = glXChooseFBConfig(x_display, DefaultScreen(x_display), pixelFormat, &configs);
if (configs <= 0) {
throw std::runtime_error("No Framebuffer configurations");
}
#endif
}
HeadlessDisplay::~HeadlessDisplay() {
#if MBGL_USE_CGL
CGLDestroyPixelFormat(pixelFormat);
#endif
#if MBGL_USE_GLX
XFree(fb_configs);
XCloseDisplay(x_display);
#endif
}
}

View File

@@ -0,0 +1,278 @@
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/platform/default/headless_display.hpp>
#include <stdexcept>
#include <sstream>
#include <string>
#if MBGL_USE_GLX
#ifdef GLX_ARB_create_context
static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = nullptr;
#endif
#endif
namespace mbgl {
HeadlessView::HeadlessView()
: display_(std::make_shared<HeadlessDisplay>()) {
createContext();
}
HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
: display_(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);
if (error) {
throw std::runtime_error("Error creating GL context object\n");
}
error = CGLEnable(gl_context, kCGLCEMPEngine);
if (error != kCGLNoError ) {
throw std::runtime_error("Error enabling OpenGL multithreading\n");
}
#endif
#if MBGL_USE_GLX
#ifdef GLX_ARB_create_context
if (glXCreateContextAttribsARB == nullptr) {
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
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, 8,
GLX_PBUFFER_HEIGHT, 8,
None
};
glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes);
#endif
}
void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
clear_buffers();
width_ = width;
height_ = height;
pixelRatio_ = pixelRatio;
const unsigned int w = width_ * pixelRatio_;
const unsigned int h = height_ * pixelRatio_;
make_active();
// Create depth/stencil buffer
glGenRenderbuffersEXT(1, &fbo_depth_stencil);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depth_stencil);
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, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fbo_color);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fbo_depth_stencil);
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
std::stringstream error("Couldn't create framebuffer: ");
switch (status) {
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;
}
throw std::runtime_error(error.str());
}
make_inactive();
}
const std::unique_ptr<uint32_t[]> HeadlessView::readPixels() {
const unsigned int w = width_ * pixelRatio_;
const unsigned int h = height_ * pixelRatio_;
std::unique_ptr<uint32_t[]> 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() {
make_active();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
if (fbo) {
glDeleteFramebuffersEXT(1, &fbo);
fbo = 0;
}
if (fbo_color) {
glDeleteTextures(1, &fbo_color);
fbo_color = 0;
}
if (fbo_depth_stencil) {
glDeleteRenderbuffersEXT(1, &fbo_depth_stencil);
fbo_depth_stencil = 0;
}
make_inactive();
}
HeadlessView::~HeadlessView() {
clear_buffers();
#if MBGL_USE_CGL
CGLDestroyContext(gl_context);
#endif
#if MBGL_USE_GLX
if (glx_pbuffer) {
glXDestroyPbuffer(x_display, glx_pbuffer);
glx_pbuffer = 0;
}
glXDestroyContext(x_display, gl_context);
#endif
}
void HeadlessView::notify() {
// no-op
}
void HeadlessView::notify_map_change(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
// no-op
}
void HeadlessView::make_active() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(gl_context);
if (error) {
throw std::runtime_error("Switching OpenGL context failed\n");
}
#endif
#if MBGL_USE_GLX
if (!glXMakeContextCurrent(x_display, glx_pbuffer, glx_pbuffer, gl_context)) {
throw std::runtime_error("Switching OpenGL context failed\n");
}
#endif
}
void HeadlessView::make_inactive() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(nullptr);
if (error) {
throw std::runtime_error("Removing OpenGL context failed\n");
}
#endif
#if MBGL_USE_GLX
if (!glXMakeContextCurrent(x_display, 0, 0, nullptr)) {
throw std::runtime_error("Removing OpenGL context failed\n");
}
#endif
}
void HeadlessView::swap() {}
}

View File

@@ -154,11 +154,11 @@ void curl_perform(uv_poll_t *req, int, int events) {
while ((message = curl_multi_info_read(multi, &pending))) {
switch (message->msg) {
case CURLMSG_DONE: {
CURLContext *context = nullptr;
curl_easy_getinfo(message->easy_handle, CURLINFO_PRIVATE, (char *)&context);
CURLContext *ctx = nullptr;
curl_easy_getinfo(message->easy_handle, CURLINFO_PRIVATE, (char *)&ctx);
// Make a copy so that the Baton stays around even after we are calling finish_request
util::ptr<HTTPRequestBaton> baton = context->baton;
util::ptr<HTTPRequestBaton> baton = ctx->baton;
// Add human-readable error code
if (message->data.result != CURLE_OK) {
@@ -242,8 +242,8 @@ int handle_socket(CURL *handle, curl_socket_t sockfd, int action, void *, void *
}
if (action == CURL_POLL_REMOVE && socketp) {
uv_poll_stop(context->poll_handle);
uv_close((uv_handle_t *)context->poll_handle, [](uv_handle_t *handle) {
delete (uv_poll_t *)handle;
uv_close((uv_handle_t *)context->poll_handle, [](uv_handle_t *poll_handle) {
delete (uv_poll_t *)poll_handle;
});
context->poll_handle = nullptr;
curl_multi_assign(multi, sockfd, NULL);
@@ -267,7 +267,7 @@ void on_timeout(uv_timer_t *) {
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);
}

View File

@@ -1,4 +1,4 @@
#include "stderr_log.hpp"
#include <mbgl/platform/default/log_stderr.hpp>
#include <iostream>
#include <cstdarg>

View File

@@ -1,4 +1,4 @@
#include "settings_json.hpp"
#include <mbgl/platform/default/settings_json.hpp>
#include <rapidjson/prettywriter.h>
#include <rapidjson/filestream.h>
#include <rapidjson/document.h>

View File

@@ -2,6 +2,7 @@
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start
# use g++ that supports c++11
@@ -15,17 +16,17 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
# but it's not worth a standalone matrix so here
# we just test address->gcc and thread->clang for
# some limited coverage
if [[ ${BUILDTYPE} == "Debug" ]]; then
if [[ ${CXX} == "g++" ]]; then
export CXXFLAGS="-fsanitize=address -g ${CXXFLAGS}"
export CFLAGS="-fsanitize=address -g ${CFLAGS}"
export LDFLAGS="-fsanitize=address ${LDFLAGS}"
elif [[ ${CXX} == "clang++" ]]; then
export CXXFLAGS="-fsanitize=thread -g -fPIC ${CXXFLAGS}"
export CFLAGS="-fsanitize=thread -g ${CFLAGS}"
export LDFLAGS="-fsanitize=thread -pie ${LDFLAGS}"
fi
fi
# if [[ ${BUILDTYPE} == "Debug" ]]; then
# if [[ ${CXX} == "g++" ]]; then
# export CXXFLAGS="-fsanitize=address -g ${CXXFLAGS}"
# export CFLAGS="-fsanitize=address -g ${CFLAGS}"
# export LDFLAGS="-fsanitize=address ${LDFLAGS}"
# elif [[ ${CXX} == "clang++" ]]; then
# export CXXFLAGS="-fsanitize=thread -g -fPIC ${CXXFLAGS}"
# export CFLAGS="-fsanitize=thread -g ${CFLAGS}"
# export LDFLAGS="-fsanitize=thread -pie ${LDFLAGS}"
# fi
# fi
fi
# turn off a few warnings

View File

@@ -6,5 +6,31 @@ set -o pipefail
cd build/${BUILDTYPE:-Release}
for TEST in ./test_* ; do
${TEST}
# allow writing core files
ulimit -c unlimited -S
echo 'ulimit -c: '`ulimit -c`
echo '/proc/sys/kernel/core_pattern: '`cat /proc/sys/kernel/core_pattern`
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
sysctl kernel.core_pattern
fi
RESULT=0
${TEST} || RESULT=$?
if [[ ${RESULT} != 0 ]]; then
echo "The program crashed with exit code ${RESULT}. We're now trying to output the core dump."
fi
# output core dump if we got one
for DUMP in $(find ./ -maxdepth 1 -name 'core*' -print); do
gdb ${TEST} ${DUMP} -ex "thread apply all bt" -ex "set pagination 0" -batch
rm -rf ${DUMP}
done
# now we should present travis with the original
# error code so the run cleanly stops
if [[ ${RESULT} != 0 ]]; then
exit $RESULT
fi
done

View File

@@ -11,21 +11,34 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
fi
sudo add-apt-repository --yes ppa:boost-latest/ppa
mapbox_time "apt_update" \
sudo apt-get update -y
mapbox_time "install_gcc" \
sudo apt-get -y install gcc-4.8 g++-4.8
sudo apt-get -y install git build-essential zlib1g-dev automake \
mapbox_time "install_build_tools" \
sudo apt-get -y install git build-essential zlib1g-dev automake gdb \
libtool xutils-dev make cmake pkg-config python-pip \
libboost1.55-dev libboost-regex1.55-dev libcurl4-openssl-dev \
libpng-dev libsqlite3-dev
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 libxinerama-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 boost
mapbox_time "install_awscli" \
sudo pip install awscli
fi

41
scripts/travis_helper.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env bash
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"
}
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

View File

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

View File

@@ -7,26 +7,46 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
#
# build & test Linux
#
mapbox_time "compile_program" \
make linux -j4 BUILDTYPE=${BUILDTYPE}
mapbox_time "compile_tests" \
make test -j4 BUILDTYPE=${BUILDTYPE}
mapbox_time "run_tests" \
./scripts/run_tests.sh
mapbox_time_start "compare_results"
(cd ./node_modules/mapbox-gl-test-suite/ && (./bin/compare_images.js || true))
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_finish
fi
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

View File

@@ -48,6 +48,8 @@
#include <ostream>
#include <functional>
#pragma GCC diagnostic ignored "-Wshadow"
namespace ClipperLib {
#ifdef use_int32
@@ -3242,7 +3244,7 @@ void Clipper::BuildResult(Paths &polys)
int cnt = PointCount(p);
if (cnt < 2) continue;
pg.reserve(cnt);
for (int i = 0; i < cnt; ++i)
for (int j = 0; j < cnt; ++j)
{
pg.push_back(p->Pt);
p = p->Prev;

View File

@@ -98,10 +98,10 @@ const int8_t simplex_94[] = { 3, 6, 3, 8, 4, 11, 6, 12, 8, 12, 10, 11, 14, 8, 16
struct glyph {
glyph() : width(0), length(0), data(nullptr) { }
glyph(uint8_t width, uint8_t length, const int8_t *data)
: width(width),
length(length),
data(data) {}
glyph(uint8_t width_, uint8_t length_, const int8_t *data_)
: width(width_),
length(length_),
data(data_) {}
uint8_t width;
uint8_t length;
const int8_t *data;

View File

@@ -10,9 +10,9 @@ using namespace mbgl;
void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) {
uint16_t *coords = nullptr;
size_t length = strlen(text);
for (size_t i = 0; i < length; ++i) {
if (text[i] < 32 || text[i] > 127) {
const size_t len = strlen(text);
for (size_t i = 0; i < len; ++i) {
if (text[i] < 32 || (unsigned char)(text[i]) > 127) {
continue;
}

View File

@@ -9,11 +9,11 @@
using namespace mbgl;
GlyphAtlas::GlyphAtlas(uint16_t width, uint16_t height)
: width(width),
height(height),
bin(width, height),
data(new char[width *height]),
GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_)
: width(width_),
height(height_),
bin(width_, height_),
data(new char[width_ *height_]),
dirty(true) {
}
@@ -22,9 +22,15 @@ GlyphAtlas::~GlyphAtlas() {
}
Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_name,
const SDFGlyph& glyph) {
const SDFGlyph& glyph)
{
std::lock_guard<std::mutex> lock(mtx);
return addGlyph_impl(tile_id, face_name, glyph);
}
Rect<uint16_t> GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& face_name,
const SDFGlyph& glyph)
{
// Use constant value for now.
const uint8_t buffer = 3;
@@ -83,6 +89,23 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_na
return rect;
}
void GlyphAtlas::addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname, FontStack const& fontStack, GlyphPositions & face)
{
std::lock_guard<std::mutex> lock(mtx);
std::map<uint32_t, SDFGlyph> const& sdfs = fontStack.getSDFs();
for (uint32_t chr : text)
{
auto sdf_it = sdfs.find(chr);
if (sdf_it != sdfs.end())
{
SDFGlyph const& sdf = sdf_it->second;
Rect<uint16_t> rect = addGlyph_impl(tileid, stackname, sdf);
face.emplace(chr, Glyph{rect, sdf.metrics});
}
}
}
void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
std::lock_guard<std::mutex> lock(mtx);

View File

@@ -14,10 +14,10 @@
using namespace mbgl;
SpriteAtlas::SpriteAtlas(dimension width, dimension height)
: width(width),
height(height),
bin(width, height),
SpriteAtlas::SpriteAtlas(dimension width_, dimension height_)
: width(width_),
height(height_),
bin(width_, height_),
dirty(true) {
}
@@ -53,7 +53,7 @@ bool SpriteAtlas::resize(const float newRatio) {
}
}
free(old_data);
::operator delete(old_data);
dirty = true;
// Mark all sprite images as in need of update
@@ -88,10 +88,10 @@ void copy_bitmap(const uint32_t *src, const int src_stride, const int src_x, con
}
}
Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t width, size_t height) {
Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t pixel_width, size_t pixel_height) {
// We have to allocate a new area in the bin, and store an empty image in it.
// Add a 1px border around every image.
Rect<dimension> rect = bin.allocate(width + 2 * buffer, height + 2 * buffer);
Rect<dimension> rect = bin.allocate(pixel_width + 2 * buffer, pixel_height + 2 * buffer);
if (rect.w == 0) {
return rect;
}
@@ -154,7 +154,8 @@ void SpriteAtlas::allocate() {
if (!data) {
dimension w = static_cast<dimension>(width * pixelRatio);
dimension h = static_cast<dimension>(height * pixelRatio);
data = (uint32_t *)calloc(w * h, sizeof(uint32_t));
data = static_cast<uint32_t*>(::operator new(w * h * sizeof(uint32_t)));
std::fill(data, data + w * h, 0);
}
}
@@ -268,9 +269,5 @@ SpriteAtlas::~SpriteAtlas() {
glDeleteTextures(1, &texture);
texture = 0;
if (data) {
free(data);
data = nullptr;
}
::operator delete(data), data = nullptr;
}

View File

@@ -30,17 +30,17 @@
using namespace mbgl;
Map::Map(View& view)
Map::Map(View& view_)
: loop(std::make_shared<uv::loop>()),
thread(std::make_unique<uv::thread>()),
async_terminate(new uv_async_t()),
async_render(new uv_async_t()),
async_cleanup(new uv_async_t()),
view(view),
view(view_),
#ifndef NDEBUG
main_thread(uv_thread_self()),
#endif
transform(view),
transform(view_),
glyphAtlas(std::make_shared<GlyphAtlas>(1024, 1024)),
spriteAtlas(std::make_shared<SpriteAtlas>(512, 512)),
texturepool(std::make_shared<Texturepool>()),
@@ -91,15 +91,28 @@ void Map::start() {
is_stopped = false;
// Setup async notifications
uv_async_init(**loop, async_terminate.get(), terminate);
// Iron out the differences between libuv 0.10 and 0.11
#ifdef UV_ASYNC_CALLBACK
#error Cannot overwrite UV_ASYNC_CALLBACK
#endif
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
#define UV_ASYNC_CALLBACK(name) [](uv_async_t *a, int) { return Map::name(a); }
#else
#define UV_ASYNC_CALLBACK(name) name
#endif
uv_async_init(**loop, async_terminate.get(), UV_ASYNC_CALLBACK(terminate));
async_terminate->data = this;
uv_async_init(**loop, async_render.get(), render);
uv_async_init(**loop, async_render.get(), UV_ASYNC_CALLBACK(render));
async_render->data = this;
uv_async_init(**loop, async_cleanup.get(), cleanup);
uv_async_init(**loop, async_cleanup.get(), UV_ASYNC_CALLBACK(cleanup));
async_cleanup->data = this;
#undef UV_ASYNC_CALLBACK
uv_thread_create(*thread, [](void *arg) {
Map *map = static_cast<Map *>(arg);
#ifndef NDEBUG
@@ -163,7 +176,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();
#ifndef NDEBUG
map_thread = -1;
@@ -199,17 +211,16 @@ void Map::cleanup() {
}
}
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
void Map::cleanup(uv_async_t *async, int) {
#else
void Map::cleanup(uv_async_t *async) {
#endif
Map *map = static_cast<Map *>(async->data);
map->view.make_active();
map->painter.cleanup();
}
void Map::terminate() {
painter.terminate();
}
void Map::setReachability(bool reachable) {
// Note: This function may be called from *any* thread.
if (reachable) {
@@ -221,11 +232,7 @@ void Map::setReachability(bool reachable) {
}
}
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
void Map::render(uv_async_t *async, int) {
#else
void Map::render(uv_async_t *async) {
#endif
Map *map = static_cast<Map *>(async->data);
assert(uv_thread_self() == map->map_thread);
@@ -245,11 +252,7 @@ void Map::render(uv_async_t *async) {
}
}
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
void Map::terminate(uv_async_t *async, int) {
#else
void Map::terminate(uv_async_t *async) {
#endif
// Closes all open handles on the loop. This means that the loop will automatically terminate.
Map *map = static_cast<Map *>(async->data);
assert(uv_thread_self() == map->map_thread);
@@ -271,8 +274,8 @@ void Map::terminate(uv_async_t *async) {
void Map::setup() {
assert(uv_thread_self() == map_thread);
view.make_active();
painter.setup();
view.make_inactive();
}
void Map::setStyleURL(const std::string &url) {
@@ -605,8 +608,6 @@ void Map::updateRenderState() {
}
void Map::prepare() {
view.make_active();
if (!fileSource) {
fileSource = std::make_shared<FileSource>(**loop, platform::defaultCacheDatabase());
glyphStore = std::make_shared<GlyphStore>(fileSource);
@@ -651,9 +652,8 @@ void Map::prepare() {
}
void Map::render() {
#if defined(DEBUG)
std::vector<std::string> debug;
#endif
view.make_active();
painter.clear();
painter.resize();
@@ -685,6 +685,8 @@ void Map::render() {
}
glFlush();
view.make_inactive();
}
void Map::renderLayers(util::ptr<StyleLayerGroup> group) {

View File

@@ -5,8 +5,8 @@
using namespace mbgl;
RasterTileData::RasterTileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source)
: TileData(id, map, source),
RasterTileData::RasterTileData(Tile::ID id_, Map &map_, const util::ptr<SourceInfo> &source_)
: TileData(id_, map_, source_),
bucket(map.getTexturepool(), properties) {
}

View File

@@ -18,10 +18,12 @@
#include <mbgl/map/vector_tile_data.hpp>
#include <mbgl/map/raster_tile_data.hpp>
#include <algorithm>
namespace mbgl {
Source::Source(const util::ptr<SourceInfo>& info)
: info(info)
Source::Source(const util::ptr<SourceInfo>& info_)
: info(info_)
{
}
@@ -219,15 +221,15 @@ std::forward_list<Tile::ID> Source::coveringTiles(const TransformState& state) c
box points = state.cornersToBox(z);
const vec2<double>& center = points.center;
std::forward_list<Tile::ID> tiles = Tile::cover(z, points);
std::forward_list<Tile::ID> covering_tiles = Tile::cover(z, points);
tiles.sort([&center](const Tile::ID& a, const Tile::ID& b) {
covering_tiles.sort([&center](const Tile::ID& a, const Tile::ID& b) {
// Sorts by distance from the box center
return std::fabs(a.x - center.x) + std::fabs(a.y - center.y) <
std::fabs(b.x - center.x) + std::fabs(b.y - center.y);
});
return tiles;
return covering_tiles;
}
/**

View File

@@ -13,13 +13,13 @@
using namespace mbgl;
SpritePosition::SpritePosition(uint16_t x, uint16_t y, uint16_t width, uint16_t height, float pixelRatio, bool sdf)
: x(x),
y(y),
width(width),
height(height),
pixelRatio(pixelRatio),
sdf(sdf) {
SpritePosition::SpritePosition(uint16_t x_, uint16_t y_, uint16_t width_, uint16_t height_, float pixelRatio_, bool sdf_)
: x(x_),
y(y_),
width(width_),
height(height_),
pixelRatio(pixelRatio_),
sdf(sdf_) {
}
util::ptr<Sprite> Sprite::Create(const std::string& base_url, float pixelRatio, const util::ptr<FileSource> &fileSource) {
@@ -28,11 +28,11 @@ util::ptr<Sprite> Sprite::Create(const std::string& base_url, float pixelRatio,
return sprite;
}
Sprite::Sprite(const Key &, const std::string& base_url, float pixelRatio)
Sprite::Sprite(const Key &, const std::string& base_url, float pixelRatio_)
: valid(base_url.length() > 0),
pixelRatio(pixelRatio),
spriteURL(base_url + (pixelRatio > 1 ? "@2x" : "") + ".png"),
jsonURL(base_url + (pixelRatio > 1 ? "@2x" : "") + ".json"),
pixelRatio(pixelRatio_),
spriteURL(base_url + (pixelRatio_ > 1 ? "@2x" : "") + ".png"),
jsonURL(base_url + (pixelRatio_ > 1 ? "@2x" : "") + ".json"),
raster(),
loadedImage(false),
loadedJSON(false),
@@ -123,16 +123,16 @@ void Sprite::parseJSON() {
uint16_t y = 0;
uint16_t width = 0;
uint16_t height = 0;
float pixelRatio = 1.0f;
float spritePixelRatio = 1.0f;
bool sdf = false;
if (value.HasMember("x")) x = value["x"].GetInt();
if (value.HasMember("y")) y = value["y"].GetInt();
if (value.HasMember("width")) width = value["width"].GetInt();
if (value.HasMember("height")) height = value["height"].GetInt();
if (value.HasMember("pixelRatio")) pixelRatio = value["pixelRatio"].GetInt();
if (value.HasMember("pixelRatio")) spritePixelRatio = value["pixelRatio"].GetInt();
if (value.HasMember("sdf")) sdf = value["sdf"].GetBool();
pos.emplace(name, SpritePosition { x, y, width, height, pixelRatio, sdf });
pos.emplace(name, SpritePosition { x, y, width, height, spritePixelRatio, sdf });
}
}
} else {

View File

@@ -7,8 +7,8 @@ using namespace mbgl;
#include <iostream>
Tile::Tile(const ID& id)
: id(id) {
Tile::Tile(const ID& id_)
: id(id_) {
}
Tile::ID Tile::ID::parent(int8_t parent_z) const {
@@ -25,13 +25,13 @@ std::forward_list<Tile::ID> Tile::ID::children(int32_t child_z) const {
assert(child_z > z);
int32_t factor = std::pow(2, child_z - z);
std::forward_list<ID> children;
std::forward_list<ID> child_ids;
for (int32_t ty = y * factor, y_max = (y + 1) * factor; ty < y_max; ++ty) {
for (int32_t tx = x * factor, x_max = (x + 1) * factor; tx < x_max; ++tx) {
children.emplace_front(child_z, tx, ty);
child_ids.emplace_front(child_z, tx, ty);
}
}
return children;
return child_ids;
}
Tile::ID Tile::ID::normalized() const {
@@ -42,13 +42,13 @@ Tile::ID Tile::ID::normalized() const {
return ID { z, nx, ny };
}
bool Tile::ID::isChildOf(const Tile::ID &parent) const {
if (parent.z >= z || parent.w != w) {
bool Tile::ID::isChildOf(const Tile::ID &parent_id) const {
if (parent_id.z >= z || parent_id.w != w) {
return false;
}
int32_t scale = std::pow(2, z - parent.z);
return parent.x == ((x < 0 ? x - scale + 1 : x) / scale) &&
parent.y == y / scale;
int32_t scale = std::pow(2, z - parent_id.z);
return parent_id.x == ((x < 0 ? x - scale + 1 : x) / scale) &&
parent_id.y == y / scale;
}

View File

@@ -9,14 +9,14 @@
using namespace mbgl;
TileData::TileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source)
: id(id),
TileData::TileData(Tile::ID id_, Map &map_, const util::ptr<SourceInfo> &source_)
: id(id_),
state(State::initial),
map(map),
source(source),
map(map_),
source(source_),
debugBucket(debugFontBuffer) {
// Initialize tile debug coordinates
const std::string str = util::sprintf<32>("%d/%d/%d", id.z, id.x, id.y);
const std::string str = util::sprintf<32>("%d/%d/%d", id_.z, id_.x, id_.y);
debugFontBuffer.addText(str.c_str(), 50, 200, 5);
}

View File

@@ -37,14 +37,14 @@ namespace mbgl {
// its header file.
TileParser::~TileParser() = default;
TileParser::TileParser(const std::string &data, VectorTileData &tile,
TileParser::TileParser(const std::string &data, VectorTileData &tile_,
const util::ptr<const Style> &style_,
const util::ptr<GlyphAtlas> &glyphAtlas_,
const util::ptr<GlyphStore> &glyphStore_,
const util::ptr<SpriteAtlas> &spriteAtlas_,
const util::ptr<Sprite> &sprite_)
: vector_data(pbf((const uint8_t *)data.data(), data.size())),
tile(tile),
tile(tile_),
style(style_),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),

View File

@@ -17,7 +17,7 @@ const double R2D = 180.0 / M_PI;
const double M2PI = 2 * M_PI;
const double MIN_ROTATE_SCALE = 8;
Transform::Transform(View &view) : view(view), mtx(std::make_unique<uv::rwlock>()) {
Transform::Transform(View &view_) : view(view_), mtx(std::make_unique<uv::rwlock>()) {
setScale(current.scale);
setAngle(current.angle);
}

View File

@@ -96,8 +96,8 @@ float TransformState::lngX(float lon) const {
}
float TransformState::latY(float lat) const {
float y = 180 / M_PI * std::log(std::tan(M_PI / 4 + lat * M_PI / 360));
return (180 - y) * worldSize() / 360;
float lat_y = 180 / M_PI * std::log(std::tan(M_PI / 4 + lat * M_PI / 360));
return (180 - lat_y) * worldSize() / 360;
}
std::array<float, 2> TransformState::locationCoordinate(float lon, float lat) const {

View File

@@ -103,9 +103,9 @@ VectorTileLayer::VectorTileLayer(pbf layer) : data(layer) {
}
}
FilteredVectorTileLayer::FilteredVectorTileLayer(const VectorTileLayer& layer, const FilterExpression &filterExpression)
: layer(layer),
filterExpression(filterExpression) {
FilteredVectorTileLayer::FilteredVectorTileLayer(const VectorTileLayer& layer_, const FilterExpression &filterExpression_)
: layer(layer_),
filterExpression(filterExpression_) {
}
FilteredVectorTileLayer::iterator FilteredVectorTileLayer::begin() const {
@@ -116,10 +116,10 @@ FilteredVectorTileLayer::iterator FilteredVectorTileLayer::end() const {
return iterator(*this, pbf(layer.data.end, 0));
}
FilteredVectorTileLayer::iterator::iterator(const FilteredVectorTileLayer& parent, const pbf& data)
: parent(parent),
FilteredVectorTileLayer::iterator::iterator(const FilteredVectorTileLayer& parent_, const pbf& data_)
: parent(parent_),
feature(pbf()),
data(data) {
data(data_) {
operator++();
}

View File

@@ -8,8 +8,8 @@
using namespace mbgl;
VectorTileData::VectorTileData(Tile::ID id, Map &map, const util::ptr<SourceInfo> &source)
: TileData(id, map, source),
VectorTileData::VectorTileData(Tile::ID id_, Map &map_, const util::ptr<SourceInfo> &source_)
: TileData(id_, map_, source_),
depth(id.z >= source->max_zoom ? map.getMaxZoom() - id.z : 1) {
}

View File

@@ -10,8 +10,8 @@ struct geometry_too_long_exception : std::exception {};
using namespace mbgl;
DebugBucket::DebugBucket(DebugFontBuffer& fontBuffer)
: fontBuffer(fontBuffer) {
DebugBucket::DebugBucket(DebugFontBuffer& fontBuffer_)
: fontBuffer(fontBuffer_) {
}
void DebugBucket::render(Painter& painter, util::ptr<StyleLayer> /*layer_desc*/, const Tile::ID& /*id*/, const mat4 &matrix) {

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