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

Conflicts:
	.gitignore
	gyp/mbgl-ios.gypi
	gyp/mbgl-linux.gypi
	gyp/mbgl-osx.gypi
	include/mbgl/map/map.hpp
	src/mbgl/map/map.cpp
	src/mbgl/storage/caching_http_file_source.cpp
This commit is contained in:
Leith Bade
2014-12-05 23:16:49 +11:00
273 changed files with 347 additions and 327 deletions

1
.gitignore vendored
View File

@@ -7,7 +7,6 @@
/config.gypi
/config-ios.gypi
/config-android.gypi
/config/constants_local.cpp
/build
/include/mbgl/shader/shaders.hpp
/src/shader/shaders_gl.cpp

View File

@@ -21,7 +21,6 @@
},
'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")',
@@ -31,6 +30,7 @@
],
'include_dirs': [
'../include',
'../src',
],
'conditions': [
['OS == "mac"', {

View File

@@ -29,7 +29,6 @@
'sources': [
'../platform/default/headless_view.cpp',
'../platform/default/headless_display.cpp',
'../platform/default/caching_http_file_source.cpp',
],
},
],

View File

@@ -36,7 +36,6 @@
'../platform/darwin/string_nsstring.mm',
'../platform/darwin/http_request_baton_cocoa.mm',
'../platform/darwin/image.mm',
'../platform/default/caching_http_file_source.cpp',
'../platform/default/asset_request_baton_noop.cpp',
],
'include_dirs': [

View File

@@ -35,7 +35,6 @@
'../platform/default/image_reader.cpp',
'../platform/default/png_reader.cpp',
'../platform/default/jpeg_reader.cpp',
'../platform/default/caching_http_file_source.cpp',
'../platform/default/asset_request_baton_noop.cpp',
],
'include_dirs': [

View File

@@ -11,7 +11,6 @@
'../platform/darwin/string_nsstring.mm',
'../platform/darwin/http_request_baton_cocoa.mm',
'../platform/darwin/image.mm',
'../platform/default/caching_http_file_source.cpp',
'../platform/default/asset_request_baton_noop.cpp',
],
'include_dirs': [

View File

@@ -1,25 +0,0 @@
** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
** Copyright (C) [dates of first publication] Silicon Graphics, Inc.
** All Rights Reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
** of the Software, and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions:
**
** The above copyright notice including the dates of first publication and either this
** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC.
** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
** OR OTHER DEALINGS IN THE SOFTWARE.
**
** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not
** be used in advertising or otherwise to promote the sale, use or other dealings in
** this Software without prior written authorization from Silicon Graphics, Inc.

View File

@@ -2,9 +2,6 @@
#define MBGL_MAP_MAP
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/geometry/sprite_atlas.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/time.hpp>
#include <mbgl/util/uv.hpp>
@@ -18,9 +15,11 @@
#include <vector>
#include <mutex>
#include <condition_variable>
#include <functional>
namespace mbgl {
class Painter;
class GlyphStore;
class LayerDescription;
class Sprite;
@@ -31,10 +30,10 @@ class StyleSource;
class TexturePool;
class FileSource;
class View;
class GlyphAtlas;
class SpriteAtlas;
class Map : private util::noncopyable {
typedef void (*stop_callback)(void *);
public:
explicit Map(View&, FileSource&);
~Map();
@@ -45,9 +44,8 @@ public:
// Stop the map render thread. This call will block until the map rendering thread stopped.
// The optional callback function will be invoked repeatedly until the map thread is stopped.
// The callback function should wait until it is woken up again by view.notify(), otherwise
// this will be a busy waiting loop. The optional data parameter will be passed to the callback
// function.
void stop(stop_callback cb = nullptr, void *data = nullptr);
// this will be a busy waiting loop.
void stop(std::function<void ()> callback = std::function<void ()>());
// Pauses the render thread. The render thread will stop running but will not be terminated and will not lose state until resumed.
void pause(bool waitForPause = false);
@@ -89,8 +87,6 @@ public:
void setStyleURL(const std::string &url);
void setStyleJSON(std::string newStyleJSON, const std::string &base = "");
std::string getStyleJSON() const;
void setAccessToken(std::string accessToken);
std::string getAccessToken() const;
// Transition
void cancelTransitions();
@@ -131,9 +127,6 @@ public:
void toggleDebug();
bool getDebug() const;
// Call this when the network reachability changed.
void setReachability(bool status);
inline const TransformState &getState() const { return state; }
inline timestamp getTime() const { return animationTime; }
@@ -202,17 +195,16 @@ private:
FileSource& fileSource;
util::ptr<Style> style;
GlyphAtlas glyphAtlas;
const std::unique_ptr<GlyphAtlas> glyphAtlas;
util::ptr<GlyphStore> glyphStore;
SpriteAtlas spriteAtlas;
const std::unique_ptr<SpriteAtlas> spriteAtlas;
util::ptr<Sprite> sprite;
util::ptr<TexturePool> texturePool;
Painter painter;
const std::unique_ptr<Painter> painter;
std::string styleURL;
std::string styleJSON = "";
std::string accessToken = "";
std::atomic_uint_fast64_t defaultTransitionDuration;

View File

@@ -44,10 +44,6 @@ public:
return ((std::pow(2, z) * y + x) * 32) + z;
}
inline operator std::string() const {
return std::to_string(z) + "/" + std::to_string(x) + "/" + std::to_string(y);
}
inline bool operator==(const ID& rhs) const {
return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y;
}
@@ -67,6 +63,7 @@ public:
ID normalized() const;
std::forward_list<ID> children(int32_t z) const;
bool isChildOf(const Tile::ID &id) const;
operator std::string() const;
};
static std::forward_list<Tile::ID> cover(int8_t z, const box& bounds);

View File

@@ -4,7 +4,6 @@
#include <mbgl/map/tile.hpp>
#include <mbgl/util/mat4.hpp>
#include <mbgl/util/vec.hpp>
#include <cstdint>
#include <array>

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_COMMON_HEADLESS_DISPLAY
#define MBGL_COMMON_HEADLESS_DISPLAY
#include "headless_view.hpp"
#include <mbgl/platform/default/headless_view.hpp>
namespace mbgl {

View File

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

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_PLATFORM_LOG
#define MBGL_PLATFORM_LOG
#include "event.hpp"
#include <mbgl/platform/event.hpp>
#include <mbgl/util/std.hpp>

View File

@@ -16,25 +16,32 @@ class SQLiteStore;
class CachingHTTPFileSource : public FileSource {
public:
CachingHTTPFileSource(const std::string &path_);
~CachingHTTPFileSource();
virtual ~CachingHTTPFileSource();
// Stores and checks the libuv loop for requests
void setLoop(uv_loop_t*);
bool hasLoop();
void clearLoop();
// Stores and retrieves the base path/URL for relative requests
void setBase(const std::string &value);
const std::string &getBase() const;
// Set the base path/URL for relative requests
void setBase(std::string);
// Set the Mapbox API access token
void setAccessToken(std::string);
std::unique_ptr<Request> request(ResourceType type, const std::string &url);
void prepare(std::function<void()> fn);
void retryAllPending();
// Call this when the network status reachability changed.
void setReachability(bool reachable);
private:
std::thread::id threadId;
// Mapbox API access token.
std::string accessToken;
// Path to the cache database.
std::string path;

View File

@@ -10,16 +10,20 @@
typedef struct uv_loop_s uv_loop_t;
namespace mbgl {
class FileSource : public util::noncopyable {
public:
virtual ~FileSource() = default;
virtual void setLoop(uv_loop_t*) = 0;
virtual bool hasLoop() = 0;
virtual void setBase(const std::string &value) = 0;
virtual void clearLoop() = 0;
virtual void setBase(std::string) = 0;
virtual std::unique_ptr<Request> request(ResourceType type, const std::string &url) = 0;
virtual void prepare(std::function<void()> fn) = 0;
virtual void retryAllPending() = 0;
};
}

View File

@@ -3,6 +3,7 @@
#include <mbgl/storage/request_callback.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/util/ptr.hpp>
#include <thread>

View File

@@ -4,7 +4,7 @@
#include <cmath>
#include <array>
#include "vec.hpp"
#include <mbgl/util/vec.hpp>
namespace mbgl {
namespace util {

View File

@@ -3,9 +3,27 @@
#include <string>
#pragma GCC diagnostic push
#ifndef __clang__
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic pop
namespace mbgl {
namespace util {
template <typename... Args>
inline std::string toString(Args&&... args) {
return boost::lexical_cast<std::string>(::std::forward<Args>(args)...);
}
// boost::lexical_cast() treats this as a character, but we are using it as number types.
inline std::string toString(int8_t num) {
return boost::lexical_cast<std::string>(int(num));
}
template<size_t max, typename... Args>
inline std::string sprintf(const char *msg, Args... args) {
char res[max];

View File

@@ -10,7 +10,7 @@
#include <iosfwd>
#include <string>
#include "recursive_wrapper.hpp"
#include <mbgl/util/recursive_wrapper.hpp>
#ifdef _MSC_VER
// http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx

View File

@@ -105,11 +105,6 @@ struct vec4 {
};
struct box {
vec2<double> tl, tr, bl, br;
vec2<double> center;
};
typedef vec2<int16_t> Coordinate;
}

View File

@@ -4,7 +4,7 @@
#include <mbgl/platform/default/settings_json.hpp>
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/platform/default/log_stderr.hpp>
#include <mbgl/platform/default/caching_http_file_source.hpp>
#include <mbgl/storage/caching_http_file_source.hpp>
#include <signal.h>
#include <getopt.h>
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
if (token == nullptr) {
mbgl::Log::Warning(mbgl::Event::Setup, "no access token set. mapbox.com tiles won't work.");
} else {
map.setAccessToken(std::string(token));
fileSource.setAccessToken(std::string(token));
}
// Load style

View File

@@ -1,8 +1,9 @@
#include <mbgl/platform/platform.hpp>
#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>
#include <mbgl/platform/default/caching_http_file_source.hpp>
#include <mbgl/storage/caching_http_file_source.hpp>
#import <Foundation/Foundation.h>
@@ -75,7 +76,7 @@ int main() {
GLFWView view;
mbgl::CachingHTTPFileSource fileSource(mbgl::platform::defaultCacheDatabase());
mbgl::Map map(view, fileSource);
mbgl::Map *map_ptr = &map;
mbgl::CachingHTTPFileSource *fileSourcePtr = &fileSource;
URLHandler *handler = [[URLHandler alloc] init];
[handler setMap:&map];
@@ -85,7 +86,7 @@ int main() {
// Notify map object when network reachability status changes.
Reachability* reachability = [Reachability reachabilityForInternetConnection];
reachability.reachableBlock = ^(Reachability *) {
map_ptr->setReachability(true);
fileSourcePtr->setReachability(true);
};
[reachability startNotifier];
@@ -95,11 +96,10 @@ int main() {
map.setBearing(settings.bearing);
map.setDebug(settings.debug);
// Set access token if present
NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"];
if ( ! accessToken) mbgl::Log::Warning(mbgl::Event::Setup, "No access token set. Mapbox vector tiles won't work.");
if (accessToken) map.setAccessToken([accessToken cStringUsingEncoding:[NSString defaultCStringEncoding]]);
if (!accessToken) mbgl::Log::Warning(mbgl::Event::Setup, "No access token set. Mapbox vector tiles won't work.");
if (accessToken) fileSource.setAccessToken([accessToken cStringUsingEncoding:[NSString defaultCStringEncoding]]);
// Load style
const std::string path([[[NSBundle mainBundle] pathForResource:@"bright-v6" ofType:@"json" inDirectory:@"styles/"] UTF8String]);

View File

@@ -1,119 +0,0 @@
#include <mbgl/platform/default/caching_http_file_source.hpp>
#include <mbgl/storage/file_request.hpp>
#include <mbgl/storage/http_request.hpp>
#include <mbgl/storage/sqlite_store.hpp>
#include <mbgl/storage/asset_request.hpp>
#include <mbgl/util/uv-messenger.h>
#include <mbgl/util/std.hpp>
#include <uv.h>
namespace mbgl {
CachingHTTPFileSource::CachingHTTPFileSource(const std::string &path_)
: path(path_) {}
CachingHTTPFileSource::~CachingHTTPFileSource() {
if (hasLoop()) {
// FIXME temp fix for #608 crash
// assert(thread_id == std::this_thread::get_id());
uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
delete msgr;
});
util::ptr<BaseRequest> req;
// Send a cancel() message to all requests that we are still holding.
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
if ((req = pair.second.lock())) {
req->cancel();
}
}
}
}
void CachingHTTPFileSource::setLoop(uv_loop_t* loop_) {
threadId = std::this_thread::get_id();
store = !path.empty() ? util::ptr<SQLiteStore>(new SQLiteStore(loop_, path)) : nullptr;
loop = loop_;
queue = new uv_messenger_t;
uv_messenger_init(loop, queue, [](void *ptr) {
std::unique_ptr<std::function<void()>> fn { reinterpret_cast<std::function<void()> *>(ptr) };
(*fn)();
});
uv_unref((uv_handle_t *)&queue->async);
}
bool CachingHTTPFileSource::hasLoop() {
return loop;
}
void CachingHTTPFileSource::setBase(const std::string &value) {
assert(std::this_thread::get_id() == threadId);
base = value;
}
const std::string &CachingHTTPFileSource::getBase() const {
assert(std::this_thread::get_id() == threadId);
return base;
}
std::unique_ptr<Request> CachingHTTPFileSource::request(ResourceType type, const std::string &url) {
assert(std::this_thread::get_id() == threadId);
// Make URL absolute.
const std::string absoluteURL = [&]() -> std::string {
const size_t separator = url.find("://");
if (separator == std::string::npos) {
// Relative URL.
return base + url;
} else {
return url;
}
}();
util::ptr<BaseRequest> req;
// First, try to find an existing Request object.
auto it = pending.find(absoluteURL);
if (it != pending.end()) {
req = it->second.lock();
}
if (!req) {
if (absoluteURL.substr(0, 7) == "file://") {
req = std::make_shared<FileRequest>(absoluteURL.substr(7), loop);
} else if (absoluteURL.substr(0, 8) == "asset://") {
req = std::make_shared<AssetRequest>(absoluteURL.substr(8), loop);
} else {
req = std::make_shared<HTTPRequest>(type, absoluteURL, loop, store);
}
pending.emplace(absoluteURL, req);
}
return util::make_unique<Request>(req);
}
void CachingHTTPFileSource::prepare(std::function<void()> fn) {
if (std::this_thread::get_id() == threadId) {
fn();
} else {
uv_messenger_send(queue, new std::function<void()>(std::move(fn)));
}
}
void CachingHTTPFileSource::retryAllPending() {
assert(std::this_thread::get_id() == threadId);
util::ptr<BaseRequest> req;
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
if ((req = pair.second.lock())) {
req->retryImmediately();
}
}
}
}

View File

@@ -1,8 +1,6 @@
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/util/string.hpp>
GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
#ifdef NVIDIA
glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXTPROC)glfwGetProcAddress("glDiscardFramebufferEXT");
@@ -10,7 +8,6 @@ GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
}
GLFWView::~GLFWView() {
map->terminate();
glfwTerminate();
}
@@ -242,7 +239,7 @@ int GLFWView::run() {
glfwWaitEvents();
}
map->stop([](void *) {
map->stop([]() {
glfwWaitEvents();
});

View File

@@ -1,40 +1,30 @@
#include <mbgl/platform/default/settings_json.hpp>
#include <rapidjson/prettywriter.h>
#include <rapidjson/filestream.h>
#include <rapidjson/document.h>
#include <stdio.h>
#include <fstream>
using namespace mbgl;
Settings_JSON::Settings_JSON() { load(); }
void Settings_JSON::load() {
FILE *settingsFile = fopen("/tmp/mbgl-native.json", "r");
if (settingsFile != NULL) {
rapidjson::FileStream is(settingsFile);
rapidjson::Document document;
document.ParseStream<0>(is);
if (document.IsArray()) {
longitude = document[rapidjson::SizeType(0)].GetDouble();
latitude = document[1].GetDouble();
zoom = document[2].GetDouble();
bearing = document[3].GetDouble();
debug = document[4].GetBool();
}
std::ifstream file("/tmp/mbgl-native.cfg");
if (file) {
file >> longitude;
file >> latitude;
file >> zoom;
file >> bearing;
file >> debug;
}
}
void Settings_JSON::save() {
rapidjson::FileStream s(fopen("/tmp/mbgl-native.json", "w"));
rapidjson::PrettyWriter<rapidjson::FileStream> writer(s);
writer.StartArray();
writer.Double(longitude);
writer.Double(latitude);
writer.Double(zoom);
writer.Double(bearing);
writer.Bool(debug);
writer.EndArray();
std::ofstream file("/tmp/mbgl-native.cfg");
if (file) {
file << longitude << std::endl;
file << latitude << std::endl;
file << zoom << std::endl;
file << bearing << std::endl;
file << debug << std::endl;
}
}
void Settings_JSON::clear() {

View File

@@ -38,7 +38,7 @@
* *
*******************************************************************************/
#include <clipper/clipper.hpp>
#include "clipper.hpp"
#include <cmath>
#include <vector>
#include <algorithm>

View File

@@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#include <csscolorparser/csscolorparser.hpp>
#include "csscolorparser.hpp"
#include <cstdint>
#include <vector>

View File

@@ -35,7 +35,7 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <libtess2/tesselator.h>
#include "tesselator.h"
//#define CHECK_BOUNDS

View File

@@ -36,7 +36,7 @@
extern "C" {
#endif
#include <libtess2/tesselator.h>
#include "tesselator.h"
struct BucketAlloc *createBucketAlloc( TESSalloc* alloc, const char *name,
unsigned int itemSize, unsigned int bucketSize );

View File

@@ -30,7 +30,7 @@
*/
#include <stddef.h>
#include <libtess2/tesselator.h>
#include "tesselator.h"
#include "bucketalloc.h"
#include "dict.h"

View File

@@ -32,7 +32,7 @@
#ifndef MESH_H
#define MESH_H
#include <libtess2/tesselator.h>
#include "tesselator.h"
typedef struct TESSmesh TESSmesh;
typedef struct TESSvertex TESSvertex;

View File

@@ -32,7 +32,7 @@
//#include "tesos.h"
#include <stddef.h>
#include <assert.h>
#include <libtess2/tesselator.h>
#include "tesselator.h"
#include "priorityq.h"

View File

@@ -37,7 +37,7 @@
#include "mesh.h"
#include "dict.h"
#include "priorityq.h"
#include <libtess2/tesselator.h>
#include "tesselator.h"
#ifdef __cplusplus
extern "C" {

View File

@@ -1,10 +1,10 @@
#include <mbgl/geometry/debug_font_buffer.hpp>
#include <mbgl/geometry/debug_font_data.hpp>
#include <mbgl/platform/gl.hpp>
#include <cmath>
#include <cstring>
#include "debug_font_data.hpp"
using namespace mbgl;
void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) {

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_GEOMETRY_DEBUG_FONT_BUFFER
#define MBGL_GEOMETRY_DEBUG_FONT_BUFFER
#include "buffer.hpp"
#include <mbgl/geometry/buffer.hpp>
namespace mbgl {

View File

@@ -3,6 +3,7 @@
#include <mbgl/geometry/buffer.hpp>
#include <mbgl/geometry/vao.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <array>

View File

@@ -1,4 +1,5 @@
#include <mbgl/geometry/fill_buffer.hpp>
#include <mbgl/platform/gl.hpp>
#include <climits>

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_GEOMETRY_FILL_BUFFER
#define MBGL_GEOMETRY_FILL_BUFFER
#include "buffer.hpp"
#include <mbgl/geometry/buffer.hpp>
#include <vector>
#include <cstdint>

View File

@@ -1,5 +1,6 @@
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/map/vector_tile.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/platform/platform.hpp>

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_GEOMETRY_ICON_BUFFER
#define MBGL_GEOMETRY_ICON_BUFFER
#include "buffer.hpp"
#include <mbgl/geometry/buffer.hpp>
#include <array>

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_GEOMETRY_LINE_BUFFER
#define MBGL_GEOMETRY_LINE_BUFFER
#include "buffer.hpp"
#include <mbgl/geometry/buffer.hpp>
namespace mbgl {

View File

@@ -2,6 +2,7 @@
#define MBGL_GEOMETRY_SPRITE_ATLAS
#include <mbgl/geometry/binpack.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>

View File

@@ -1,7 +1,7 @@
#ifndef MBGL_GEOMETRY_TEXT_BUFFER
#define MBGL_GEOMETRY_TEXT_BUFFER
#include "buffer.hpp"
#include <mbgl/geometry/buffer.hpp>
#include <array>
namespace mbgl {

View File

@@ -1,5 +1,6 @@
#include <mbgl/geometry/vao.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>
namespace mbgl {
@@ -31,8 +32,8 @@ void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuin
char *offset) {
if (bound_shader != shader.getID()) {
throw std::runtime_error(std::string("trying to rebind VAO to another shader from " +
std::to_string(bound_shader) + "(" + bound_shader_name + ") to " +
std::to_string(shader.getID()) + "(" + shader.name + ")" ));
util::toString(bound_shader) + "(" + bound_shader_name + ") to " +
util::toString(shader.getID()) + "(" + shader.name + ")" ));
} else if (bound_offset != offset) {
throw std::runtime_error("trying to bind VAO to another offset");
} else if (bound_vertex_buffer != vertexBuffer) {

View File

@@ -1,7 +1,8 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/map/sprite.hpp>
#include <mbgl/util/transition.hpp>
#include <mbgl/util/time.hpp>
@@ -11,10 +12,10 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/uv_detail.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/text/glyph_store.hpp>
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/style/style_layer_group.hpp>
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/util/texture_pool.hpp>
@@ -98,10 +99,11 @@ Map::Map(View& view_, FileSource& fileSource_)
#endif
transform(view_),
fileSource(fileSource_),
glyphAtlas(1024, 1024),
spriteAtlas(512, 512),
glyphAtlas(util::make_unique<GlyphAtlas>(1024, 1024)),
glyphStore(std::make_shared<GlyphStore>(fileSource)),
spriteAtlas(util::make_unique<SpriteAtlas>(512, 512)),
texturePool(std::make_shared<TexturePool>()),
painter(spriteAtlas, glyphAtlas)
painter(util::make_unique<Painter>(*spriteAtlas, *glyphAtlas))
{
view.initialize(this);
// Make sure that we're doing an initial drawing in all cases.
@@ -149,11 +151,12 @@ void Map::start(bool startPaused) {
assert(std::this_thread::get_id() == mapThread);
// Remove all of these to make sure they are destructed in the correct thread.
glyphStore.reset();
style.reset();
workers.reset();
activeSources.clear();
fileSource.clearLoop();
terminating = true;
// Closes all open handles on the loop. This means that the loop will automatically terminate.
@@ -182,7 +185,8 @@ void Map::start(bool startPaused) {
});
asyncCleanup = util::make_unique<uv::async>(**loop, [this]() {
painter.cleanup();
assert(painter);
painter->cleanup();
});
// Do we need to pause first?
@@ -211,7 +215,7 @@ void Map::start(bool startPaused) {
});
}
void Map::stop(stop_callback cb, void *data) {
void Map::stop(std::function<void ()> callback) {
assert(std::this_thread::get_id() == mainThread);
assert(mainThread != mapThread);
assert(async);
@@ -220,7 +224,7 @@ void Map::stop(stop_callback cb, void *data) {
resume();
if (cb) {
if (callback) {
// Wait until the render thread stopped. We are using this construct instead of plainly
// relying on the thread_join because the system might need to run things in the current
// thread that is required for the render thread to terminate correctly. This is for example
@@ -228,7 +232,7 @@ void Map::stop(stop_callback cb, void *data) {
// thread (== main thread) is blocked. The callback function should use an efficient waiting
// function to avoid a busy waiting loop.
while (!isStopped) {
cb(data);
callback();
}
}
@@ -364,24 +368,17 @@ void Map::cleanup() {
}
void Map::terminate() {
painter.terminate();
}
void Map::setReachability(bool reachable) {
// Note: This function may be called from *any* thread.
if (reachable) {
fileSource.prepare([&]() {
fileSource.retryAllPending();
});
}
assert(painter);
painter->terminate();
}
#pragma mark - Setup
void Map::setup() {
assert(std::this_thread::get_id() == mapThread);
assert(painter);
view.make_active();
painter.setup();
painter->setup();
}
void Map::setStyleURL(const std::string &url) {
@@ -404,12 +401,8 @@ void Map::setStyleJSON(std::string newStyleJSON, const std::string &base) {
}
style->loadJSON((const uint8_t *)styleJSON.c_str());
if (!fileSource.hasLoop()) {
fileSource.setLoop(**loop);
glyphStore = std::make_shared<GlyphStore>(fileSource);
}
fileSource.setBase(base);
glyphStore->setURL(util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken()));
glyphStore->setURL(style->glyph_url);
style->setDefaultTransitionDuration(defaultTransitionDuration);
@@ -431,15 +424,6 @@ std::string Map::getStyleJSON() const {
return styleJSON;
}
void Map::setAccessToken(std::string accessToken_) {
// TODO: Make threadsafe.
accessToken.swap(accessToken_);
}
std::string Map::getAccessToken() const {
return accessToken;
}
util::ptr<Sprite> Map::getSprite() {
const float pixelRatio = state.getPixelRatio();
const std::string &sprite_url = style->getSpriteURL();
@@ -604,7 +588,8 @@ void Map::stopRotating() {
void Map::setDebug(bool value) {
debug = value;
painter.setDebug(debug);
assert(painter);
painter->setDebug(debug);
update();
}
@@ -700,8 +685,8 @@ void Map::updateSources(const util::ptr<StyleLayerGroup> &group) {
void Map::updateTiles() {
for (const auto& source : activeSources) {
source->source->update(*this, getWorker(),
style, glyphAtlas, *glyphStore,
spriteAtlas, getSprite(),
style, *glyphAtlas, *glyphStore,
*spriteAtlas, getSprite(),
*texturePool, fileSource, [this](){ update(); });
}
}
@@ -709,7 +694,6 @@ void Map::updateTiles() {
void Map::prepare() {
if (!fileSource.hasLoop()) {
fileSource.setLoop(**loop);
glyphStore = std::make_shared<GlyphStore>(fileSource);
}
if (!style) {
@@ -744,14 +728,15 @@ void Map::prepare() {
style->updateProperties(state.getNormalizedZoom(), animationTime);
// Allow the sprite atlas to potentially pull new sprite images if needed.
spriteAtlas.resize(state.getPixelRatio());
spriteAtlas.setSprite(getSprite());
spriteAtlas->resize(state.getPixelRatio());
spriteAtlas->setSprite(getSprite());
updateTiles();
}
void Map::render() {
painter.render(*style, activeSources,
assert(painter);
painter->render(*style, activeSources,
state, animationTime);
// Schedule another rerender when we definitely need a next frame.
if (transform.needsTransition() || style->hasTransitions()) {

View File

@@ -10,6 +10,7 @@
#include <mbgl/util/vec.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/box.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/style/style_layer.hpp>
@@ -36,10 +37,9 @@ void Source::load(Map& map, FileSource& fileSource) {
return;
}
std::string url = util::mapbox::normalizeSourceURL(info.url, map.getAccessToken());
util::ptr<Source> source = shared_from_this();
fileSource.request(ResourceType::JSON, url)->onload([source, &map](const Response &res) {
fileSource.request(ResourceType::JSON, info.url)->onload([source, &map](const Response &res) {
if (res.code != 200) {
Log::Warning(Event::General, "failed to load source TileJSON");
return;
@@ -88,13 +88,13 @@ size_t Source::getTileCount() const {
void Source::drawClippingMasks(Painter &painter) {
for (std::pair<const Tile::ID, std::unique_ptr<Tile>> &pair : tiles) {
Tile &tile = *pair.second;
gl::group group(util::sprintf<32>("mask %d/%d/%d", tile.id.z, tile.id.y, tile.id.z));
gl::group group(std::string { "mask: " } + std::string(tile.id));
painter.drawClippingMask(tile.matrix, tile.clip);
}
}
void Source::render(Painter &painter, util::ptr<StyleLayer> layer_desc) {
gl::group group(std::string("layer: ") + layer_desc->id);
gl::group group(std::string { "layer: " } + layer_desc->id);
for (const std::pair<const Tile::ID, std::unique_ptr<Tile>> &pair : tiles) {
Tile &tile = *pair.second;
if (tile.data && tile.data->state == TileData::State::parsed) {

View File

@@ -1,5 +1,8 @@
#include <mbgl/map/tile.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/box.hpp>
#include <cassert>
@@ -52,6 +55,11 @@ bool Tile::ID::isChildOf(const Tile::ID &parent_id) const {
}
Tile::ID::operator std::string() const {
return util::toString(z) + "/" + util::toString(x) + "/" + util::toString(y);
}
// Taken from polymaps src/Layer.js
// https://github.com/simplegeo/polymaps/blob/master/src/Layer.js#L333-L383

View File

@@ -11,12 +11,12 @@ using namespace mbgl;
TileData::TileData(Tile::ID const& id_, const SourceInfo& source_)
: id(id_),
name(id),
state(State::initial),
source(source_),
debugBucket(debugFontBuffer) {
// Initialize tile debug coordinates
const std::string str = util::sprintf<32>("%d/%d/%d", id_.z, id_.x, id_.y);
debugFontBuffer.addText(str.c_str(), 50, 200, 5);
debugFontBuffer.addText(name.c_str(), 50, 200, 5);
}
TileData::~TileData() {
@@ -24,7 +24,7 @@ TileData::~TileData() {
}
const std::string TileData::toString() const {
return util::sprintf<32>("[tile %d/%d/%d]", id.z, id.x, id.y);
return std::string { "[tile " } + name + "]";
}
void TileData::request(uv::worker& worker, FileSource& fileSource,
@@ -34,9 +34,9 @@ void TileData::request(uv::worker& worker, FileSource& fileSource,
std::string url = source.tiles[(id.x + id.y) % source.tiles.size()];
url = util::replaceTokens(url, [&](const std::string &token) -> std::string {
if (token == "z") return std::to_string(id.z);
if (token == "x") return std::to_string(id.x);
if (token == "y") return std::to_string(id.y);
if (token == "z") return util::toString(id.z);
if (token == "x") return util::toString(id.x);
if (token == "y") return util::toString(id.y);
if (token == "prefix") {
std::string prefix { 2 };
prefix[0] = "0123456789abcdef"[id.x % 16];

View File

@@ -66,6 +66,7 @@ public:
public:
const Tile::ID id;
const std::string name;
std::atomic<State> state;
public:

View File

@@ -1,5 +1,4 @@
#include <mbgl/map/tile_parser.hpp>
#include <mbgl/map/vector_tile_data.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/style_layer.hpp>

View File

@@ -1,5 +1,6 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/box.hpp>
using namespace mbgl;

View File

@@ -1,5 +1,4 @@
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/platform/gl.hpp>

View File

@@ -370,7 +370,7 @@ void Painter::renderLayer(util::ptr<StyleLayer> layer_desc, const Tile::ID* id,
void Painter::renderTileLayer(const Tile& tile, util::ptr<StyleLayer> layer_desc, const mat4 &matrix) {
assert(tile.data);
if (tile.data->hasData(*layer_desc) || layer_desc->type == StyleLayerType::Raster) {
gl::group group(util::sprintf<32>("render %d/%d/%d\n", tile.id.z, tile.id.y, tile.id.z));
gl::group group(std::string { "render " } + tile.data->name);
prepareTile(tile);
tile.data->render(*this, layer_desc, matrix);
}

View File

@@ -6,7 +6,7 @@
using namespace mbgl;
void Painter::renderTileDebug(const Tile& tile) {
gl::group group(util::sprintf<32>("debug %d/%d/%d", tile.id.z, tile.id.y, tile.id.z));
gl::group group(std::string { "debug " } + std::string(tile.id));
assert(tile.data);
if (debug) {
prepareTile(tile);

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