summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-05-22 12:12:19 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-05-22 12:12:19 +0200
commitbb2cda34a7a185a034f8a42c6426aea6fc3a1a52 (patch)
tree49d471a29e78276f0311266e3c2491c79282fe3a
parentab4bc4ae3067aa038cdb20e4fff0542addaac564 (diff)
downloadqtlocation-mapboxgl-bb2cda34a7a185a034f8a42c6426aea6fc3a1a52.tar.gz
make sure we're not calling functions that aren't threadsafe
-rw-r--r--include/llmr/map/transform_state.hpp2
-rw-r--r--src/map/map.cpp62
2 files changed, 47 insertions, 17 deletions
diff --git a/include/llmr/map/transform_state.hpp b/include/llmr/map/transform_state.hpp
index 6c360b3f3e..a6c69cae3c 100644
--- a/include/llmr/map/transform_state.hpp
+++ b/include/llmr/map/transform_state.hpp
@@ -60,7 +60,7 @@ private:
// map position
double x = 0, y = 0;
double angle = 0;
- double scale = 1;
+ double scale = std::numeric_limits<double>::infinity();
};
}
diff --git a/src/map/map.cpp b/src/map/map.cpp
index cb2d27dfba..8317735a3a 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -173,32 +173,21 @@ void Map::loadStyle(const uint8_t *const data, uint32_t bytes) {
#pragma mark - Size
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::resize(uint16_t width, uint16_t height, float ratio) {
resize(width, height, ratio, width * ratio, height * ratio);
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height) {
- bool changed = false;
-
if (transform.resize(width, height, ratio, fb_width, fb_height)) {
- changed = true;
- }
-
- // TODO: Make sure we're not currently rendering anything
- if (spriteAtlas.resize(ratio)) {
- changed = true;
- }
-
- // TODO: Make sure we're not currently rendering anything
- painter.clearFramebuffers();
-
- if (changed) {
update();
}
}
#pragma mark - Transitions
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::cancelTransitions() {
transform.cancelTransitions();
@@ -208,30 +197,36 @@ void Map::cancelTransitions() {
#pragma mark - Position
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::moveBy(double dx, double dy, double duration) {
transform.moveBy(dx, dy, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::setLonLat(double lon, double lat, double duration) {
transform.setLonLat(lon, lat, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::getLonLat(double& lon, double& lat) const {
transform.getLonLat(lon, lat);
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::startPanning() {
transform.startPanning();
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::stopPanning() {
transform.stopPanning();
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::resetPosition() {
transform.setAngle(0);
transform.setLonLat(0, 0);
@@ -242,47 +237,57 @@ void Map::resetPosition() {
#pragma mark - Scale
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::scaleBy(double ds, double cx, double cy, double duration) {
transform.scaleBy(ds, cx, cy, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::setScale(double scale, double cx, double cy, double duration) {
transform.setScale(scale, cx, cy, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
double Map::getScale() const {
return transform.getScale();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::setZoom(double zoom, double duration) {
transform.setZoom(zoom, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
double Map::getZoom() const {
return transform.getZoom();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::setLonLatZoom(double lon, double lat, double zoom, double duration) {
transform.setLonLatZoom(lon, lat, zoom, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::getLonLatZoom(double& lon, double& lat, double& zoom) const {
transform.getLonLatZoom(lon, lat, zoom);
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::resetZoom() {
setZoom(0);
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::startScaling() {
transform.startScaling();
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::stopScaling() {
transform.stopScaling();
update();
@@ -291,35 +296,42 @@ void Map::stopScaling() {
#pragma mark - Rotation
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::rotateBy(double sx, double sy, double ex, double ey, double duration) {
transform.rotateBy(sx, sy, ex, ey, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::setAngle(double angle, double duration) {
transform.setAngle(angle, duration * 1_second);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::setAngle(double angle, double cx, double cy) {
transform.setAngle(angle, cx, cy);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
double Map::getAngle() const {
return transform.getAngle();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::resetNorth() {
transform.setAngle(0, 500_milliseconds);
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::startRotating() {
transform.startRotating();
update();
}
+// Note: This function is called from another thread. Make sure you only call threadsafe functions!
void Map::stopRotating() {
transform.stopRotating();
update();
@@ -402,11 +414,29 @@ void Map::prepare() {
transform.updateTransitions(animationTime);
}
+
+ const TransformState oldState = state;
state = transform.currentState();
- style.cascade(state.getNormalizedZoom());
- if (!style.sprite || style.sprite->pixelRatio != state.getPixelRatio()) {
+
+ bool pixelRatioChanged = oldState.getPixelRatio() != state.getPixelRatio();
+ bool dimensionsChanged = oldState.getFramebufferWidth() != state.getFramebufferWidth() ||
+ oldState.getFramebufferHeight() != state.getFramebufferHeight();
+ bool zoomChanged = oldState.getNormalizedZoom() != state.getNormalizedZoom();
+
+ if (pixelRatioChanged) {
+ // We have a pixelratio change
style.sprite = std::make_shared<Sprite>(*this, state.getPixelRatio());
style.sprite->load(kSpriteURL);
+
+ spriteAtlas.resize(state.getPixelRatio());
+ }
+
+ if (pixelRatioChanged || dimensionsChanged) {
+ painter.clearFramebuffers();
+ }
+
+ if (zoomChanged) {
+ style.cascade(state.getNormalizedZoom());
}
// Allow the sprite atlas to potentially pull new sprite images if needed.