Merge branch 'master' into access_token

Conflicts:
	.gitignore
This commit is contained in:
Justin R. Miller
2014-07-09 15:12:15 -07:00
69 changed files with 386 additions and 504 deletions

3
.gitignore vendored
View File

@@ -1,6 +1,8 @@
.DS_Store
*.xcodeproj
*.o
*.actual.png
/node_modules
/mapnik-packaging
/macosx/build
/ios/build
@@ -14,3 +16,4 @@
/src/shader/shaders_gles2.cpp
/bin/style.bin.js
access_token.hpp
/test/fixtures/styles/index.html

View File

@@ -11,9 +11,13 @@ env:
matrix:
- BUILDTYPE=Release
- BUILDTYPE=Debug
global:
- secure: "bG4YYWMfl9API0MSRgmOaJrlGLv06tRg9KJNawBieZvBJbITPpxVGJZT3/l/SEJ+Rl15e2dRex4k+MGQlmT2SqPQxTEYWv1qxNigKPPcla7IWeNmWWqW8uVvFjdglojgBOK2k/xErVQtA4zDfi3mwSXH4DKwquXWsoEKmX2SV7M="
- secure: "Cbvap9ubVKgjPe3hUhI6JGeDZzBXHpOG9RaYKh+SdoIPhKnlJiNOYm1egomi+e4uqJInlFKuVHTw7Ng9Cun6Zm0jIxpkSchv1GpsR7hmB3UGnGed19Dw8121FwuUaktN+4YnbVlsyd+u8EHD3+h58t4eELrLrZolM4rS7DL6caA="
before_install:
- source ./scripts/setup_travis.sh
- ./scripts/setup_travis.sh
- source ./scripts/flags.sh
install:
- make setup
@@ -22,8 +26,12 @@ before_script:
- rm -rf mapnik-packaging/out/packages
script:
- make linux BUILDTYPE=${BUILDTYPE}
- make run-tests BUILDTYPE=${BUILDTYPE}
- make linux -j4 BUILDTYPE=${BUILDTYPE}
- make test -j4 BUILDTYPE=${BUILDTYPE}
- ./scripts/run_tests.sh
after_script:
- ./scripts/deploy_results.sh
notifications:
hipchat:

View File

@@ -27,10 +27,6 @@ build/test/Makefile: src common config.gypi test/test.gyp
test: build/test/Makefile
$(MAKE) -C build/test BUILDTYPE=$(BUILDTYPE) V=$(V) test
# Runs all test cases
run-tests: test
(cd build/${BUILDTYPE} && exec find . -maxdepth 1 -name "test_*" -exec {} \;)
test/%: build/test/Makefile
$(MAKE) -C build/test BUILDTYPE=$(BUILDTYPE) V=$(V) $*
(cd build/$(BUILDTYPE) && exec ./test_$*)
@@ -82,9 +78,9 @@ xproj: config.gypi macosx/llmr-app.gyp clear_xcode_cache node
open ./build/macosx/llmr-app.xcodeproj
# build iOS project for Xcode
iproj: config.gypi ios/llmr-app.gyp clear_xcode_cache node
deps/run_gyp ios/llmr-app.gyp --depth=. --generator-output=./build -f xcode
open ./build/ios/llmr-app.xcodeproj
iproj: config.gypi ios/mapbox-gl-cocoa/app/llmr-app.gyp clear_xcode_cache node
deps/run_gyp ios/mapbox-gl-cocoa/app/llmr-app.gyp --depth=. --generator-output=./build -f xcode
open ./build/ios/mapbox-gl-cocoa/app/llmr-app.xcodeproj
# build Linux project for Xcode (Runs on Mac OS X too, but without platform-specific code)
lproj: config.gypi linux/llmr-app.gyp clear_xcode_cache node

View File

@@ -117,12 +117,14 @@ module.exports = function(shader_type, prefix, suffix) {
code += '\n};\n';
code += suffix + '\n';
var file_path = path.join(process.argv[2], 'include/llmr/shader/shaders.hpp');
mkdirp.sync(path.dirname(file_path));
fs.writeFileSync(file_path, header);
var header_path = path.join(process.argv[2], 'src/shader/shaders_' + shader_type + '.cpp');
var header_path = path.join(process.argv[2], 'include/llmr/shader/shaders.hpp');
mkdirp.sync(path.dirname(header_path));
fs.writeFileSync(header_path, code);
fs.writeFileSync(header_path, header);
console.warn('wrote file ' + header_path);
var file_path = path.join(process.argv[2], 'src/shader/shaders_' + shader_type + '.cpp');
mkdirp.sync(path.dirname(file_path));
fs.writeFileSync(file_path, code);
console.warn('wrote file ' + file_path);
};

View File

@@ -29,14 +29,14 @@ private:
private:
#ifdef LLMR_USE_CGL
#if LLMR_USE_CGL
CGLContextObj gl_context;
GLuint fbo = 0;
GLuint fbo_depth_stencil = 0;
GLuint fbo_color = 0;
#endif
#ifdef LLMR_USE_GLX
#if LLMR_USE_GLX
GLXContext gl_context = nullptr;
XVisualInfo *x_info = nullptr;
Display *x_display = nullptr;

View File

@@ -0,0 +1,20 @@
#ifndef LLMR_UTIL_ERROR
#define LLMR_UTIL_ERROR
#include <stdexcept>
#include <string>
namespace llmr {
namespace error {
struct style_parse : std::exception {
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;
};
}
}
#endif

View File

@@ -7,6 +7,7 @@ namespace llmr {
namespace util {
void write_file(const std::string &filename, const std::string &data);
std::string read_file(const std::string &filename);
}
}

View File

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

View File

@@ -1,15 +0,0 @@
//
// MBXAppDelegate.h
// ios
//
// Created by Justin R. Miller on 1/27/14.
//
//
#import <UIKit/UIKit.h>
@interface MBXAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -1,24 +0,0 @@
//
// MBXAppDelegate.m
// ios
//
// Created by Justin R. Miller on 1/27/14.
//
//
#import "MBXAppDelegate.h"
#import "MBXViewController.h"
@implementation MBXAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [MBXViewController new];
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

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

View File

@@ -1,214 +0,0 @@
#import "MBXViewController.h"
#import "MGLMapView.h"
#import "../common/settings_nsuserdefaults.hpp"
#import <CoreLocation/CoreLocation.h>
@interface MBXViewController () <CLLocationManagerDelegate>
@property (nonatomic) MGLMapView *mapView;
@property (nonatomic) BOOL debug;
@property (nonatomic) UIView *palette;
@property (nonatomic) CLLocationManager *locationManager;
@end
@implementation MBXViewController
llmr::Settings_NSUserDefaults *settings = nullptr;
#pragma mark - Setup
- (id)init
{
self = [super init];
if (self)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.mapView];
self.mapView.viewControllerForLayoutGuides = self;
settings = new llmr::Settings_NSUserDefaults();
[self restoreState:nil];
[self setupDebugUI];
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
- (void)saveState:(NSNotification *)notification
{
if (self.mapView && settings)
{
settings->longitude = self.mapView.centerCoordinate.longitude;
settings->latitude = self.mapView.centerCoordinate.latitude;
settings->zoom = self.mapView.zoomLevel;
settings->angle = self.mapView.direction;
settings->debug = self.mapView.isDebugActive;
settings->save();
}
}
- (void)restoreState:(NSNotification *)notification
{
if (self.mapView && settings) {
settings->load();
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(settings->latitude, settings->longitude) zoomLevel:settings->zoom animated:NO];
self.mapView.direction = settings->angle;
[self.mapView setDebugActive:settings->debug];
}
}
#pragma clang diagnostic pop
- (void)setupDebugUI
{
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
singleTap.numberOfTapsRequired = 1;
[self.mapView addGestureRecognizer:singleTap];
NSArray *selectorNames = @[ @"unrotate", @"resetPosition", @"toggleDebug", @"toggleStyle", @"locateUser" ];
CGFloat buttonSize = 40;
CGFloat bufferSize = 20;
CGFloat alpha = 0.75;
CGFloat paletteWidth = buttonSize + (2 * bufferSize);
CGFloat paletteHeight = [selectorNames count] * (buttonSize + bufferSize) + bufferSize;
self.palette = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - paletteWidth,
(self.view.bounds.size.height - paletteHeight) / 2,
paletteWidth,
paletteHeight)];
self.palette.backgroundColor = [UIColor colorWithWhite:0 alpha:alpha];
self.palette.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
self.palette.layer.cornerRadius = bufferSize;
[self.view addSubview:self.palette];
for (NSString *selectorName in selectorNames)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(bufferSize,
([selectorNames indexOfObject:selectorName] * (buttonSize + bufferSize)) + bufferSize,
buttonSize,
buttonSize);
[button setImage:[UIImage imageNamed:[selectorName stringByAppendingString:@".png"]] forState:UIControlStateNormal];
[button addTarget:self action:NSSelectorFromString(selectorName) forControlEvents:UIControlEventTouchUpInside];
[self.palette addSubview:button];
}
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
#pragma mark - Debugging UI
- (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap
{
if (singleTap.state == UIGestureRecognizerStateEnded)
{
[self togglePalette];
}
}
- (void)togglePalette
{
if (self.palette.alpha < 1)
{
self.palette.userInteractionEnabled = YES;
[UIView animateWithDuration:0.25 animations:^(void)
{
self.palette.alpha = 1;
}];
}
else
{
self.palette.userInteractionEnabled = NO;
[UIView animateWithDuration:0.25 animations:^(void)
{
self.palette.alpha = 0;
}];
}
}
- (void)unrotate
{
[self.mapView resetNorth];
}
- (void)resetPosition
{
[self.mapView resetPosition];
}
- (void)toggleDebug
{
[self.mapView toggleDebug];
self.debug = ! self.debug;
}
- (void)toggleStyle
{
[self.mapView toggleStyle];
}
- (void)locateUser
{
[self.locationManager startUpdatingLocation];
}
#pragma mark - Destruction
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (settings)
{
[self saveState:nil];
delete settings;
settings = nullptr;
}
}
#pragma mark - User location
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *latestLocation = locations.lastObject;
if ([latestLocation distanceFromLocation:[[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude]] > 100)
{
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(latestLocation.coordinate.latitude, latestLocation.coordinate.longitude) zoomLevel:17 animated:YES];
}
[self.locationManager stopUpdatingLocation];
}
#pragma clang diagnostic pop
@end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 646 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

View File

@@ -1,70 +0,0 @@
{
'includes': [
'../common.gypi',
'../config.gypi'
],
'targets': [
{
"target_name": "iosapp",
"product_name": "Mapbox GL",
"type": "executable",
"sources": [
"./main.m",
"./MBXAppDelegate.h",
"./MBXAppDelegate.m",
"./MBXViewController.h",
"./MBXViewController.mm",
'<!@(find mapbox-gl-cocoa/mapbox-gl-cocoa -type f -name "*.h")',
'<!@(find mapbox-gl-cocoa/mapbox-gl-cocoa -type f -name "*.m")',
'<!@(find mapbox-gl-cocoa/mapbox-gl-cocoa -type f -name "*.mm")',
"../common/settings_nsuserdefaults.hpp",
"../common/settings_nsuserdefaults.mm",
"../common/foundation_request.h",
"../common/foundation_request.mm",
],
'product_extension': 'app',
'mac_bundle': 1,
'mac_bundle_resources': [
'<!@(find img -type f)',
'<!@(find mapbox-gl-cocoa/mapbox-gl-cocoa/Resources -type f)',
'<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js'
],
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/UIKit.framework',
'$(SDKROOT)/System/Library/Frameworks/OpenGLES.framework',
'$(SDKROOT)/System/Library/Frameworks/GLKit.framework',
'$(SDKROOT)/System/Library/Frameworks/CoreLocation.framework',
'$(SDKROOT)/System/Library/Frameworks/CoreGraphics.framework'
],
},
'xcode_settings': {
'SDKROOT': 'iphoneos',
'SUPPORTED_PLATFORMS':['iphonesimulator','iphoneos'],
'ARCHS': [ "armv7", "armv7s", "arm64", "i386" ],
'INFOPLIST_FILE': 'Info.plist',
'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'
},
'configurations': {
'Debug': {
'xcode_settings': {
'CODE_SIGN_IDENTITY': 'iPhone Developer',
}
},
'Release': {
'xcode_settings': {
'CODE_SIGN_IDENTITY': 'iPhone Distribution',
}
}
},
"dependencies": [
"../llmr.gyp:llmr-ios"
]
}
]
}

View File

@@ -1,18 +0,0 @@
//
// main.m
// ios
//
// Created by Justin R. Miller on 1/27/14.
//
//
#import <UIKit/UIKit.h>
#import "MBXAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MBXAppDelegate class]));
}
}

View File

@@ -15,9 +15,9 @@
'<!@(find src -name "*.glsl")'
],
'outputs': [
'include/llmr/shader/shaders.hpp',
'src/shader/shaders_gl.cpp',
'src/shader/shaders_gles2.cpp',
'<(SHARED_INTERMEDIATE_DIR)/include/llmr/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)'],
}
@@ -84,6 +84,7 @@
'target_name': 'llmr-x86',
'product_name': 'llmr-x86',
'type': 'static_library',
'hard_dependency': 1,
'dependencies': [
'build_stylesheet',
'shaders',
@@ -151,6 +152,7 @@
'target_name': 'llmr-ios',
'product_name': 'llmr-ios',
'type': 'static_library',
'hard_dependency': 1,
'dependencies': [
'build_stylesheet',
'shaders',

View File

@@ -1 +0,0 @@
Icon from http://dryicons.com/icon/architecture-blueprint-icons-set/map/

View File

@@ -0,0 +1,42 @@
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var html =
'<style>body { font-family: Helvetica; }</style>\n' +
'<table>\n' +
'<tr>\n' +
' <th>Actual</th>\n' +
' <th>Expected</th>\n' +
' <th>Info</th>\n' +
'</tr>\n';
var dir = fs.readdirSync('./test/fixtures/styles').filter(function(name) {
return name.match(/\.info\.json$/);
}).forEach(function(name) {
var info = require(path.join(path.resolve('.'), './test/fixtures/styles', name));
var base = path.basename(name, '.info.json');
html +=
'<tr>\n' +
' <td><img src="' + base + '.actual.png"></td>\n' +
' <td><img src="https://raw.githubusercontent.com/mapbox/mapbox-gl-native/' + process.env.TRAVIS_COMMIT + '/test/fixtures/styles/' + base + '.expected.png"></td>\n' +
' <td>\n' +
' <h2 style="text-align:center"><a href="https://raw.githubusercontent.com/mapbox/mapbox-gl-native/' + process.env.TRAVIS_COMMIT + '/test/fixtures/styles/' + base + '.style.json">' + base + '</a></h2>\n' +
' <ul>\n' +
' <li>zoom: <strong>' + (info.zoom || 0) + '</strong></li>\n' +
' <li>latitude: <strong>' + (info.latitude || 0) + '</strong></li>\n' +
' <li>longitude: <strong>' + (info.longitude || 0) + '</strong></li>\n' +
' <li>angle: <strong>' + (info.angle || 0) + '</strong></li>\n' +
' <li>width: <strong>' + (info.width || 0) + '</strong></li>\n' +
' <li>height: <strong>' + (info.height || 0) + '</strong></li>\n' +
' </ul>\n' +
' </td>\n' +
'</tr>\n'
;
});
html += "</table\n";
fs.writeFileSync('./test/fixtures/styles/index.html', html);

11
scripts/deploy_results.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
set -o pipefail
node scripts/create_result_table.js
aws s3 cp test/fixtures/styles/ s3://mapbox-gl-testing/headless/$TRAVIS_BUILD_NUMBER/$TRAVIS_JOB_NUMBER/ --acl public-read --recursive --exclude "*" --include "*.actual.png" --include "*.html"
echo http://mapbox-gl-testing.s3.amazonaws.com/headless/$TRAVIS_BUILD_NUMBER/$TRAVIS_JOB_NUMBER/index.html

31
scripts/flags.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start
# use g++ that supports c++11
if [[ ${CXX} == "g++" ]]; then
export CXX="g++-4.8" ;
fi
# If building in debug then turn on sanitizers.
# They should both work with latest g++/clang++
# 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 ${CXXFLAGS}"
export CFLAGS="-fsanitize=address ${CFLAGS}"
export LDFLAGS="-fsanitize=address ${LDFLAGS}"
elif [[ ${CXX} == "clang++" ]]; then
export CXXFLAGS="-fsanitize=thread -fPIC ${CXXFLAGS}"
export CFLAGS="-fsanitize=thread ${CFLAGS}"
export LDFLAGS="-fsanitize=thread -pie ${LDFLAGS}"
fi
fi
fi
# turn off a few warnings
export CXXFLAGS="-Wno-unknown-warning-option -Wno-unused-local-typedefs -Wno-unknown-pragmas ${CXXFLAGS}";

12
scripts/run_tests.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
set -o pipefail
BUILDTYPE="${BUILDTYPE:-Release}"
cd build/${BUILDTYPE}
for TEST in ./test_* ; do
${TEST}
done

View File

@@ -3,15 +3,6 @@
set -e
set -o pipefail
# enable testing locally (not on travis)
if [[ "${TRAVIS_OS_NAME:-false}" == false ]]; then
if [[ $(uname -s) == "Darwin" ]]; then
TRAVIS_OS_NAME="osx"
elif [[ $(uname -s) == "Linux" ]]; then
TRAVIS_OS_NAME="linux"
fi
fi
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
if [[ `lsb_release -r` =~ "12.04" ]]; then
@@ -19,36 +10,10 @@ if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
fi
sudo apt-get update -y
sudo apt-get -y install gcc-4.8 g++-4.8
sudo apt-get -y install git build-essential zlib1g-dev automake libtool xutils-dev make cmake pkg-config
sudo apt-get -y install git build-essential zlib1g-dev automake libtool xutils-dev make cmake pkg-config python-pip
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
export DISPLAY=:99.0
sh -e /etc/init.d/xvfb start
# use g++ that supports c++11
if [[ ${CXX} == "g++" ]]; then
export CXX="g++-4.8" ;
fi
# If building in debug then turn on sanitizers.
# They should both work with latest g++/clang++
# 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 ${CXXFLAGS}"
export CFLAGS="-fsanitize=address ${CFLAGS}"
export LDFLAGS="-fsanitize=address ${LDFLAGS}"
elif [[ ${CXX} == "clang++" ]]; then
export CXXFLAGS="-fsanitize=thread -fPIC ${CXXFLAGS}"
export CFLAGS="-fsanitize=thread ${CFLAGS}"
export LDFLAGS="-fsanitize=thread -pie ${LDFLAGS}"
fi
fi
sudo pip install awscli
elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then
brew install autoconf automake libtool makedepend cmake pkg-config node git
fi
# turn off a few warnings
export CXXFLAGS="-Wno-unknown-warning-option -Wno-unused-local-typedefs -Wno-unknown-pragmas ${CXXFLAGS}";

View File

@@ -96,6 +96,13 @@ 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
rm -rf out/build-cpp11-libstdcpp-gcc-x86_64-linux
tar -xzf out/build-cpp11-libstdcpp-gcc-x86_64-linux.tar.gz
fi
fi
source Linux.sh
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
@@ -104,6 +111,13 @@ source Linux.sh
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 "${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/
fi
fi
cd ../../
./configure \
--pkg-config-root=`pwd`/mapnik-packaging/osx/out/build-cpp11-libstdcpp-gcc-x86_64-linux/lib/pkgconfig \

View File

@@ -491,15 +491,6 @@ void Map::render() {
painter.drawClippingMasks(style->getActiveSources());
#if defined(DEBUG)
// Generate debug information
size_t source_id = 0;
for (const std::shared_ptr<Source> &source : style->getActiveSources()) {
size_t count = source->getTileCount();
debug.emplace_back(util::sprintf<100>("source %d: %d\n", source_id, count));
source_id++;
}
#endif
// Actually render the layers
if (debug::renderTree) { std::cout << "{" << std::endl; indent++; }
renderLayers(style->layers);
@@ -515,10 +506,6 @@ void Map::render() {
painter.renderMatte();
#if defined(DEBUG)
painter.renderDebugText(debug);
#endif
// Schedule another rerender when we definitely need a next frame.
if (transform.needsTransition() || style->hasTransitions()) {
update();

View File

@@ -4,6 +4,7 @@
#include <llmr/style/style_bucket.hpp>
#include <llmr/util/constants.hpp>
#include <llmr/util/time.hpp>
#include <llmr/util/error.hpp>
#include <csscolorparser/csscolorparser.hpp>
#include <rapidjson/document.h>
@@ -102,6 +103,9 @@ void Style::loadJSON(const uint8_t *const data) {
rapidjson::Document doc;
doc.Parse<0>((const char *const)data);
if (doc.HasParseError()) {
throw error::style_parse(doc.GetErrorOffset(), doc.GetParseError());
}
StyleParser parser;
parser.parse(const_cast<const rapidjson::Document &>(doc));

View File

@@ -1,8 +1,15 @@
#include <llmr/util/io.hpp>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <stdexcept>
void llmr::util::write_file(const std::string &filename, const std::string &data) {
namespace llmr {
namespace util {
void write_file(const std::string &filename, const std::string &data) {
FILE *fd = fopen(filename.c_str(), "wb");
if (fd) {
fwrite(data.data(), sizeof(std::string::value_type), data.size(), fd);
@@ -11,3 +18,17 @@ void llmr::util::write_file(const std::string &filename, const std::string &data
fprintf(stderr, "Failed to open file\n");
}
}
std::string read_file(const std::string &filename) {
std::ifstream file(filename);
if (file.good()) {
std::stringstream data;
data << file.rdbuf();
return data.str();
} else {
throw std::runtime_error("Cannot read file " + filename);
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 KiB

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

BIN
test/fixtures/styles/0.expected.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

8
test/fixtures/styles/0.info.json vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"zoom": 0,
"latitude": 0,
"longitude": 0,
"angle": 0,
"width": 512,
"height": 512
}

34
test/fixtures/styles/0.style.json vendored Normal file
View File

@@ -0,0 +1,34 @@
{
"version": 3,
"sources": {
"mapbox": {
"type": "vector",
"url": "tiles/%d-%d-%d.vector.pbf",
"tileSize": 512,
"maxZoom": 14
}
},
"layers": [
{
"id": "background",
"render": {
"type": "background"
},
"style": {
"background-color": "red"
}
},
{
"id": "water",
"source": "mapbox",
"source-layer": "water",
"render": {
"type": "fill"
},
"style": {
"fill-color": "blue",
"fill-antialias": false
}
}
]
}

BIN
test/fixtures/styles/1.expected.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

8
test/fixtures/styles/1.info.json vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"zoom": 0,
"latitude": 0,
"longitude": 0,
"angle": 0,
"width": 512,
"height": 512
}

33
test/fixtures/styles/1.style.json vendored Normal file
View File

@@ -0,0 +1,33 @@
{
"version": 3,
"sources": {
"mapbox": {
"type": "vector",
"url": "tiles/%d-%d-%d.vector.pbf",
"tileSize": 512,
"maxZoom": 14
}
},
"layers": [
{
"id": "background",
"render": {
"type": "background"
},
"style": {
"background-color": "red"
}
},
{
"id": "water",
"source": "mapbox",
"source-layer": "water",
"render": {
"type": "fill"
},
"style": {
"fill-color": "blue"
}
}
]
}

View File

@@ -3,24 +3,39 @@
#include <llmr/map/map.hpp>
#include <llmr/util/image.hpp>
#include <llmr/util/io.hpp>
#include <llmr/util/timer.hpp>
#include <llmr/util/std.hpp>
#include <rapidjson/document.h>
#include "../common/headless_view.hpp"
#include <iostream>
#include <fstream>
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
return fn;
}();
TEST(Headless, initialize) {
const unsigned int width = 1024;
const unsigned int height = 768;
class HeadlessTest : public ::testing::TestWithParam<const char *> {};
llmr::util::timer timer;
TEST_P(HeadlessTest, render) {
const char *base = GetParam();
const std::string style = llmr::util::read_file(base_directory + "/fixtures/styles/" + base + ".style.json");
const std::string info = llmr::util::read_file(base_directory + "/fixtures/styles/" + base + ".info.json");
const std::string expected_image = base_directory + "/fixtures/styles/" + base + ".expected.png";
const std::string actual_image = base_directory + "/fixtures/styles/" + base + ".actual.png";
// Parse settings.
rapidjson::Document doc;
doc.Parse<0>((const char *const)info.c_str());
ASSERT_EQ(false, doc.HasParseError());
const double zoom = doc.HasMember("zoom") ? doc["zoom"].GetDouble() : 0;
const double angle = doc.HasMember("angle") ? doc["angle"].GetDouble() : 0;
const double longitude = doc.HasMember("longitude") ? doc["longitude"].GetDouble() : 0;
const double latitude = doc.HasMember("latitude") ? doc["latitude"].GetDouble() : 0;
const unsigned int width = doc.HasMember("width") ? doc["width"].GetUint() : 0;
const unsigned int height = doc.HasMember("height") ? doc["height"].GetUint() : 0;
// Setup OpenGL
llmr::HeadlessView view;
@@ -29,42 +44,27 @@ TEST(Headless, initialize) {
view.resize(width, height);
map.resize(width, height);
timer.report("map setup");
map.setStyleJSON(style);
std::ifstream stylefile("./style.min.js");
ASSERT_TRUE(stylefile.good());
std::stringstream stylejson;
stylejson << stylefile.rdbuf();
map.setStyleJSON(stylejson.str());
timer.report("map style");
map.setLonLatZoom(0, 0, 2);
map.setAngle(0);
map.setLonLatZoom(longitude, latitude, zoom);
map.setAngle(angle);
map.setDebug(false);
// Run the loop. It will terminate when we don't have any further listeners.
map.run();
timer.report("map loop");
const std::unique_ptr<uint32_t[]> pixels(new uint32_t[width * height]);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
uint32_t *pixels = new uint32_t[width * height];
const std::string image = llmr::util::compress_png(width, height, pixels.get(), true);
llmr::util::write_file(actual_image, image);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
std::string result = llmr::util::compress_png(width, height, pixels, true);
llmr::util::write_file("out.png", result);
std::ifstream imagefile(base_directory + "/fixtures/result/out.png");
ASSERT_TRUE(imagefile.good());
std::stringstream image;
image << imagefile.rdbuf();
llmr::util::Image reference(image.str(), true);
ASSERT_EQ(reference.getWidth(), width);
ASSERT_EQ(reference.getHeight(), height);
ASSERT_EQ(0, std::memcmp(pixels, reference.getData(), width * height * 4));
delete[] pixels;
const std::string expected_image_data(llmr::util::read_file(expected_image));
const llmr::util::Image expected(expected_image_data, true);
ASSERT_EQ(width, expected.getWidth());
ASSERT_EQ(height, expected.getHeight());
ASSERT_EQ(0, std::memcmp(pixels.get(), expected.getData(), width * height * 4));
}
INSTANTIATE_TEST_CASE_P(Headless, HeadlessTest,
::testing::Values("0", "1"));

View File

@@ -0,0 +1,74 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "mapbox-gl-native travis resources",
"Resources": {
"BuildUser": {
"Type": "AWS::IAM::User",
"Properties": {
"Policies": [
{
"PolicyName": "list",
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::mapbox-gl-testing"
]
}
]
}
},
{
"PolicyName": "build",
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::mapbox-gl-testing/*"
]
}
]
}
}
]
}
},
"BuildUserKey": {
"Type": "AWS::IAM::AccessKey",
"Properties": {
"UserName": {
"Ref": "BuildUser"
}
}
}
},
"Outputs": {
"AccessKeyId": {
"Value": {
"Ref": "BuildUserKey"
}
},
"SecretAccessKey": {
"Value": {
"Fn::GetAtt": [
"BuildUserKey",
"SecretAccessKey"
]
}
}
}
}