[core] Get rid of MapData::{get,set}animationTime
This commit is contained in:
@@ -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 :
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace gl { class TexturePool; }
|
||||
|
||||
struct FrameData {
|
||||
std::array<uint16_t, 2> framebufferSize;
|
||||
TimePoint timePoint;
|
||||
};
|
||||
|
||||
class MapContext : public Style::Observer {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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++; }
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user