summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-10-22 15:14:21 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-10-22 15:14:21 +0200
commit905c4294be495d15591885a2438ca0b8abc8decf (patch)
tree851a94849eb7a1f3269b91de6054846cfbda722b /src
parentc6e4cf2f80216c7139b6587dcd6d919080aef20d (diff)
parent8954b3971f5cb90dc4b18e61b58ea6e41c54fffe (diff)
downloadqtlocation-mapboxgl-905c4294be495d15591885a2438ca0b8abc8decf.tar.gz
Merge branch 'libuv-0.10-headless-display' into mason
Conflicts: common/http_request_baton_curl.cpp include/mbgl/map/map.hpp include/mbgl/util/uv_detail.hpp scripts/travis_before_install.sh setup-libraries.sh src/map/map.cpp src/storage/file_request_baton.cpp src/storage/http_request.cpp src/util/uv-messenger.c
Diffstat (limited to 'src')
-rw-r--r--src/map/map.cpp14
-rw-r--r--src/renderer/painter.cpp20
-rw-r--r--src/storage/file_request_baton.cpp4
-rw-r--r--src/style/class_dictionary.cpp34
-rw-r--r--src/style/style_layer.cpp2
-rw-r--r--src/style/style_parser.cpp2
-rw-r--r--src/util/uv-messenger.c1
-rw-r--r--src/util/uv.cpp2
8 files changed, 62 insertions, 17 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp
index f255c3ff65..451385d3d5 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -163,7 +163,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;
@@ -206,10 +205,13 @@ 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) {
@@ -271,8 +273,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 +607,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,6 +651,8 @@ void Map::prepare() {
}
void Map::render() {
+ view.make_active();
+
#if defined(DEBUG)
std::vector<std::string> debug;
#endif
@@ -685,6 +687,8 @@ void Map::render() {
}
glFlush();
+
+ view.make_inactive();
}
void Map::renderLayers(util::ptr<StyleLayerGroup> group) {
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp
index 9643fb1561..8988112585 100644
--- a/src/renderer/painter.cpp
+++ b/src/renderer/painter.cpp
@@ -82,9 +82,29 @@ void Painter::setupShaders() {
if (!gaussianShader) gaussianShader = std::make_unique<GaussianShader>();
}
+void Painter::deleteShaders() {
+ plainShader = nullptr;
+ outlineShader = nullptr;
+ lineShader = nullptr;
+ linejoinShader = nullptr;
+ linepatternShader = nullptr;
+ patternShader = nullptr;
+ iconShader = nullptr;
+ rasterShader = nullptr;
+ sdfGlyphShader = nullptr;
+ sdfIconShader = nullptr;
+ dotShader = nullptr;
+ gaussianShader = nullptr;
+}
+
void Painter::cleanup() {
}
+void Painter::terminate() {
+ cleanup();
+ deleteShaders();
+}
+
void Painter::resize() {
const TransformState &state = map.getState();
if (gl_viewport != state.getFramebufferDimensions()) {
diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp
index 64c6c13b12..e54b743c43 100644
--- a/src/storage/file_request_baton.cpp
+++ b/src/storage/file_request_baton.cpp
@@ -83,6 +83,7 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
if (stat->st_size > std::numeric_limits<int>::max()) {
// File is too large for us to open this way because uv_buf's only support unsigned
// ints as maximum size.
+ const uv_err_t error = {UV_EFBIG, 0};
if (ptr->request) {
ptr->request->response = std::unique_ptr<Response>(new Response);
ptr->request->response->code = UV_EFBIG;
@@ -97,8 +98,7 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
uv_fs_req_cleanup(req);
uv_fs_close(req->loop, req, ptr->fd, file_closed);
} else {
- const unsigned int size =
- (unsigned int)(stat->st_size);
+ const unsigned int size = (unsigned int)(stat->st_size);
ptr->body.resize(size);
ptr->buffer = uv_buf_init(const_cast<char *>(ptr->body.data()), size);
uv_fs_req_cleanup(req);
diff --git a/src/style/class_dictionary.cpp b/src/style/class_dictionary.cpp
index 6e1eb5a879..ba7c0d55be 100644
--- a/src/style/class_dictionary.cpp
+++ b/src/style/class_dictionary.cpp
@@ -1,8 +1,34 @@
#include <mbgl/style/class_dictionary.hpp>
+#include <uv.h>
+
namespace mbgl {
-ClassID ClassDictionary::Lookup(const std::string &class_name) {
+ClassDictionary::ClassDictionary() {}
+
+ClassDictionary &ClassDictionary::Get() {
+ // Note: We should eventually switch to uv_key_* functions, but libuv 0.10 doesn't have these
+ // yet. Instead, we're using the pthread functions directly for now.
+ static pthread_once_t store_once = PTHREAD_ONCE_INIT;
+ static pthread_key_t store_key;
+
+ // Create the key.
+ pthread_once(&store_once, []() {
+ pthread_key_create(&store_key, [](void *ptr) {
+ delete reinterpret_cast<ClassDictionary *>(ptr);
+ });
+ });
+
+ ClassDictionary *ptr = reinterpret_cast<ClassDictionary *>(pthread_getspecific(store_key));
+ if (ptr == nullptr) {
+ ptr = new ClassDictionary();
+ pthread_setspecific(store_key, ptr);
+ }
+
+ return *ptr;
+}
+
+ClassID ClassDictionary::lookup(const std::string &class_name) {
auto it = store.find(class_name);
if (it == store.end()) {
// Insert the class name into the store.
@@ -14,7 +40,7 @@ ClassID ClassDictionary::Lookup(const std::string &class_name) {
}
}
-ClassID ClassDictionary::Normalize(ClassID id) {
+ClassID ClassDictionary::normalize(ClassID id) {
if (id >= ClassID::Named) {
return ClassID::Named;
} else {
@@ -22,8 +48,4 @@ ClassID ClassDictionary::Normalize(ClassID id) {
}
}
-
-std::unordered_map<std::string, ClassID> ClassDictionary::store = { { "", ClassID::Default } };
-uint32_t ClassDictionary::offset = 0;
-
}
diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp
index 4f758fe723..b1b878cc8d 100644
--- a/src/style/style_layer.cpp
+++ b/src/style/style_layer.cpp
@@ -23,7 +23,7 @@ void StyleLayer::setClasses(const std::vector<std::string> &class_names, const t
for (auto it = class_names.rbegin(); it != class_names.rend(); it++) {
const std::string &class_name = *it;
// From here on, we're only dealing with IDs to avoid comparing strings all the time.
- const ClassID class_id = ClassDictionary::Lookup(class_name);
+ const ClassID class_id = ClassDictionary::Get().lookup(class_name);
applyClassProperties(class_id, already_applied, now, defaultTransition);
}
diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp
index c2247d51b2..2a64ab38f8 100644
--- a/src/style/style_parser.cpp
+++ b/src/style/style_parser.cpp
@@ -554,7 +554,7 @@ void StyleParser::parseStyles(JSVal value, std::map<ClassID, ClassProperties> &s
if (name == "style") {
parseStyle(replaceConstant(itr->value), styles[ClassID::Default]);
} else if (name.compare(0, 6, "style.") == 0 && name.length() > 6) {
- const ClassID class_id = ClassDictionary::Lookup(name.substr(6));
+ const ClassID class_id = ClassDictionary::Get().lookup(name.substr(6));
parseStyle(replaceConstant(itr->value), styles[class_id]);
}
}
diff --git a/src/util/uv-messenger.c b/src/util/uv-messenger.c
index 82df1cae75..bfa1565768 100644
--- a/src/util/uv-messenger.c
+++ b/src/util/uv-messenger.c
@@ -8,7 +8,6 @@ typedef struct {
void *queue[2];
} uv__messenger_item_t;
-
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
diff --git a/src/util/uv.cpp b/src/util/uv.cpp
index 03a885d308..1e51d3dbb6 100644
--- a/src/util/uv.cpp
+++ b/src/util/uv.cpp
@@ -15,7 +15,7 @@ std::string cwd() {
do {
max += 256;
dir.resize(max);
- uv_cwd(const_cast<char *>(dir.data()), &max);
+ uv_cwd(const_cast<char *>(dir.data()), max);
} while (max == dir.size());
dir.resize(max - 1);
return dir;