summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-03-24 18:00:03 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-03-24 18:00:03 +0100
commitafe27ed74c00d104c89ea1391b81f21be0d3112d (patch)
tree1f76d5a6bfe78da2ace3fa458813a0eeded11e95 /src
parentb4a67a959c8aecab6533880a7eb453309b927b5f (diff)
downloadqtlocation-mapboxgl-afe27ed74c00d104c89ea1391b81f21be0d3112d.tar.gz
only animate when we need to fade the text
Diffstat (limited to 'src')
-rw-r--r--src/map/map.cpp2
-rw-r--r--src/renderer/frame_history.cpp31
-rw-r--r--src/renderer/painter.cpp4
3 files changed, 36 insertions, 1 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 078fe01b92..75bfdb2c9e 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -483,5 +483,5 @@ bool Map::render() {
painter.renderMatte();
- return changed || transform.needsAnimation();
+ return changed || transform.needsAnimation() || painter.needsAnimation();
}
diff --git a/src/renderer/frame_history.cpp b/src/renderer/frame_history.cpp
index de65c1ad4a..ba0cf56c70 100644
--- a/src/renderer/frame_history.cpp
+++ b/src/renderer/frame_history.cpp
@@ -14,3 +14,34 @@ void FrameHistory::record(float zoom) {
history.emplace_back(FrameSnapshot{static_cast<float>(platform::time() * 1000), zoom});
}
}
+
+bool FrameHistory::needsAnimation(const float duration) const {
+ if (!history.size()) return true;
+
+ // If we have a value that is older than duration and whose z value is the
+ // same as the most current z value, and if all values inbetween have the
+ // same z value, we don't need animation, otherwise we probably do.
+ const FrameSnapshot &pivot = history.back();
+
+ int i = -1;
+ while (history.size() > i + 1 &&
+ history[i + 1].time + duration < pivot.time) {
+ i++;
+ }
+
+ if (i < 0) {
+ // There is no frame that is older than the duration time, so we need to
+ // check all frames.
+ i = 0;
+ }
+
+ // Make sure that all subsequent snapshots have the same zoom as the last
+ // pivot element.
+ for (; history.size() > i; i++) {
+ if (history[i].z != pivot.z) {
+ return true;
+ }
+ }
+
+ return false;
+} \ No newline at end of file
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp
index 95017465c3..9a52cb36d3 100644
--- a/src/renderer/painter.cpp
+++ b/src/renderer/painter.cpp
@@ -29,6 +29,10 @@ Painter::Painter(Transform& transform, Settings& settings, Style& style, GlyphAt
glyphAtlas(glyphAtlas) {
}
+bool Painter::needsAnimation() const {
+ return frameHistory.needsAnimation(300);
+}
+
void Painter::setup() {
setupShaders();