summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mbgl/map/map.cpp4
-rw-r--r--src/mbgl/map/map_context.cpp19
-rw-r--r--src/mbgl/map/map_context.hpp1
-rw-r--r--src/mbgl/map/map_data.hpp19
-rw-r--r--src/mbgl/renderer/painter.cpp2
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp2
-rw-r--r--src/mbgl/style/style.cpp14
-rw-r--r--src/mbgl/style/style.hpp6
-rw-r--r--test/style/style.cpp18
9 files changed, 39 insertions, 46 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 495dc06e3b..1d9cb1ac74 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -56,7 +56,7 @@ void Map::resume() {
void Map::renderStill(StillImageCallback callback) {
context->invoke(&MapContext::renderStill, transform->getState(),
- FrameData{ view.getFramebufferSize() }, callback);
+ FrameData { view.getFramebufferSize(), Clock::now() }, callback);
}
void Map::renderSync() {
@@ -68,7 +68,7 @@ void Map::renderSync() {
const Update flags = transform->updateTransitions(Clock::now());
const bool fullyLoaded = context->invokeSync<bool>(
- &MapContext::renderSync, transform->getState(), FrameData { view.getFramebufferSize() });
+ &MapContext::renderSync, transform->getState(), FrameData { view.getFramebufferSize(), Clock::now() });
view.notifyMapChange(fullyLoaded ?
MapChangeDidFinishRenderingFrameFullyRendered :
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index b03218da1f..ecb3503e23 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -144,7 +144,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
styleJSON = json;
// force style cascade, causing all pending transitions to complete.
- style->cascade();
+ style->cascade(Clock::now());
// set loading here so we don't get a false loaded event as soon as map is
// created but before a style is loaded
@@ -164,27 +164,29 @@ void MapContext::update() {
return;
}
- data.setAnimationTime(Clock::now());
-
if (style->loaded && updateFlags & Update::Annotations) {
data.getAnnotationManager()->updateStyle(*style);
updateFlags |= Update::Classes;
}
if (updateFlags & Update::Classes) {
- style->cascade();
+ style->cascade(frameData.timePoint);
}
if (updateFlags & Update::Classes || updateFlags & Update::RecalculateStyle) {
- style->recalculate(transformState.getZoom());
+ style->recalculate(transformState.getZoom(), frameData.timePoint);
}
- style->update(transformState, *texturePool);
+ style->update(transformState, frameData.timePoint, *texturePool);
if (data.mode == MapMode::Continuous) {
asyncInvalidate.send();
- } else if (callback && style->isLoaded()) {
- renderSync(transformState, frameData);
+ } else {
+ // Update time point so style sources can check they are loaded.
+ frameData.timePoint = Clock::now();
+ if (callback && style->isLoaded()) {
+ renderSync(transformState, frameData);
+ }
}
updateFlags = Update::Nothing;
@@ -234,6 +236,7 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame)
view.beforeRender();
transformState = state;
+ frameData = frame;
if (!painter) painter = std::make_unique<Painter>(data, transformState, glObjectStore);
painter->render(*style, frame, data.getAnnotationManager()->getSpriteAtlas());
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index 55278131ad..8570a40935 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -27,6 +27,7 @@ namespace gl { class TexturePool; }
struct FrameData {
std::array<uint16_t, 2> framebufferSize;
+ TimePoint timePoint;
};
class MapContext : public Style::Observer {
diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp
index da41a28035..4cf3140e91 100644
--- a/src/mbgl/map/map_data.hpp
+++ b/src/mbgl/map/map_data.hpp
@@ -1,8 +1,6 @@
#ifndef MBGL_MAP_MAP_DATA
#define MBGL_MAP_MAP_DATA
-#include <mbgl/util/chrono.hpp>
-
#include <mutex>
#include <atomic>
#include <vector>
@@ -23,8 +21,7 @@ public:
: mode(mode_)
, contextMode(contextMode_)
, pixelRatio(pixelRatio_)
- , annotationManager(pixelRatio)
- , animationTime(Duration::zero()) {
+ , annotationManager(pixelRatio) {
assert(pixelRatio > 0);
}
@@ -49,19 +46,6 @@ public:
debugOptions = debugOptions_;
}
- inline TimePoint getAnimationTime() const {
- // We're casting the TimePoint to and from a Duration because libstdc++
- // has a bug that doesn't allow TimePoints to be atomic.
- return mode == MapMode::Continuous ? TimePoint(animationTime) : Clock::now();
- }
- inline void setAnimationTime(const TimePoint& timePoint) {
- if (mode == MapMode::Still) {
- return;
- }
-
- animationTime = timePoint.time_since_epoch();
- };
-
util::exclusive<AnnotationManager> getAnnotationManager() {
return util::exclusive<AnnotationManager>(
&annotationManager,
@@ -78,7 +62,6 @@ private:
AnnotationManager annotationManager;
std::atomic<MapDebugOptions> debugOptions { MapDebugOptions::NoDebug };
- std::atomic<Duration> animationTime;
// TODO: make private
public:
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index ab35d173ae..c6b8bdbc3b 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -155,7 +155,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
drawClippingMasks(generator.getStencils());
}
- frameHistory.record(data.getAnimationTime(), state.getZoom());
+ frameHistory.record(frame.timePoint, state.getZoom());
// Actually render the layers
if (debug::renderTree) { Log::Info(Event::Render, "{"); indent++; }
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index 66f51543ea..ea7a0463d4 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -62,7 +62,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
sdfShader.u_zoom = (state.getZoom() - zoomAdjust) * 10; // current zoom level
if (data.mode == MapMode::Continuous) {
- FadeProperties f = frameHistory.getFadeProperties(data.getAnimationTime(), util::DEFAULT_FADE_DURATION);
+ FadeProperties f = frameHistory.getFadeProperties(frame.timePoint, util::DEFAULT_FADE_DURATION);
sdfShader.u_fadedist = f.fadedist * 10;
sdfShader.u_minfadezoom = std::floor(f.minfadezoom * 10);
sdfShader.u_maxfadezoom = std::floor(f.maxfadezoom * 10);
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 724810a70c..6342dabc45 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -147,12 +147,12 @@ void Style::removeLayer(const std::string& id) {
layers.erase(it);
}
-void Style::update(const TransformState& transform,
+void Style::update(const TransformState& transform, const TimePoint& timePoint,
gl::TexturePool& texturePool) {
bool allTilesUpdated = true;
StyleUpdateParameters parameters(data.pixelRatio,
data.getDebug(),
- data.getAnimationTime(),
+ timePoint,
transform,
workers,
fileSource,
@@ -175,7 +175,7 @@ void Style::update(const TransformState& transform,
}
}
-void Style::cascade() {
+void Style::cascade(const TimePoint& timePoint) {
// When in continuous mode, we can either have user- or style-defined
// transitions. Still mode is always immediate.
static const PropertyTransition immediateTransition;
@@ -189,7 +189,7 @@ void Style::cascade() {
const StyleCascadeParameters parameters {
classIDs,
- data.getAnimationTime(),
+ timePoint,
data.mode == MapMode::Continuous ? transitionProperties.value_or(immediateTransition) : immediateTransition
};
@@ -200,16 +200,16 @@ void Style::cascade() {
}
}
-void Style::recalculate(float z) {
+void Style::recalculate(float z, const TimePoint& timePoint) {
for (const auto& source : sources) {
source->enabled = false;
}
- zoomHistory.update(z, data.getAnimationTime());
+ zoomHistory.update(z, timePoint);
const StyleCalculationParameters parameters {
z,
- data.getAnimationTime(),
+ timePoint,
zoomHistory,
data.mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero()
};
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 6321a04c3f..e4ed7435b0 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -81,10 +81,10 @@ public:
// Fetch the tiles needed by the current viewport and emit a signal when
// a tile is ready so observers can render the tile.
- void update(const TransformState&, gl::TexturePool&);
+ void update(const TransformState&, const TimePoint&, gl::TexturePool&);
- void cascade();
- void recalculate(float z);
+ void cascade(const TimePoint&);
+ void recalculate(float z, const TimePoint&);
bool hasTransitions() const;
diff --git a/test/style/style.cpp b/test/style/style.cpp
index 6fa6a64b18..1d3b3beb47 100644
--- a/test/style/style.cpp
+++ b/test/style/style.cpp
@@ -16,9 +16,11 @@ TEST(Style, UnusedSource) {
StubFileSource fileSource;
Style style { data, fileSource };
+ auto now = Clock::now();
+
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), "");
- style.cascade();
- style.recalculate(0);
+ style.cascade(now);
+ style.recalculate(0, now);
Source *usedSource = style.getSource("usedsource");
EXPECT_TRUE(usedSource);
@@ -42,8 +44,10 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) {
EXPECT_TRUE(style.addClass("visible"));
EXPECT_TRUE(style.hasClass("visible"));
- style.cascade();
- style.recalculate(0);
+ auto now = Clock::now();
+
+ style.cascade(now);
+ style.recalculate(0, now);
Source *unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);
@@ -53,8 +57,10 @@ TEST(Style, UnusedSourceActiveViaClassUpdate) {
style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"), "");
EXPECT_FALSE(style.hasClass("visible"));
- style.cascade();
- style.recalculate(0);
+ now = Clock::now();
+
+ style.cascade(now);
+ style.recalculate(0, now);
unusedSource = style.getSource("unusedsource");
EXPECT_TRUE(unusedSource);