This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Unify update and render into a single step #7574
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,8 +63,8 @@ class Map::Impl : public style::Observer { | |
void onStyleError() override; | ||
void onResourceError(std::exception_ptr) override; | ||
|
||
void update(); | ||
void render(View&); | ||
void renderStill(); | ||
|
||
void loadStyleJSON(const std::string&); | ||
|
||
|
@@ -83,7 +83,6 @@ class Map::Impl : public style::Observer { | |
MapDebugOptions debugOptions { MapDebugOptions::NoDebug }; | ||
|
||
Update updateFlags = Update::Nothing; | ||
util::AsyncTask asyncUpdate; | ||
|
||
std::unique_ptr<AnnotationManager> annotationManager; | ||
std::unique_ptr<Painter> painter; | ||
|
@@ -96,10 +95,11 @@ class Map::Impl : public style::Observer { | |
|
||
std::unique_ptr<AsyncRequest> styleRequest; | ||
|
||
std::unique_ptr<StillImageRequest> stillImageRequest; | ||
size_t sourceCacheSize; | ||
TimePoint timePoint; | ||
bool loading = false; | ||
|
||
util::AsyncTask asyncInvalidate; | ||
std::unique_ptr<StillImageRequest> stillImageRequest; | ||
}; | ||
|
||
Map::Map(Backend& backend, | ||
|
@@ -142,8 +142,14 @@ Map::Impl::Impl(Map& map_, | |
mode(mode_), | ||
contextMode(contextMode_), | ||
pixelRatio(pixelRatio_), | ||
asyncUpdate([this] { update(); }), | ||
annotationManager(std::make_unique<AnnotationManager>(pixelRatio)) { | ||
annotationManager(std::make_unique<AnnotationManager>(pixelRatio)), | ||
asyncInvalidate([this] { | ||
if (mode == MapMode::Continuous) { | ||
backend.invalidate(); | ||
} else { | ||
renderStill(); | ||
} | ||
}) { | ||
} | ||
|
||
Map::~Map() { | ||
|
@@ -185,64 +191,37 @@ void Map::renderStill(View& view, StillImageCallback callback) { | |
} | ||
|
||
impl->stillImageRequest = std::make_unique<StillImageRequest>(view, std::move(callback)); | ||
impl->updateFlags |= Update::RenderStill; | ||
impl->asyncUpdate.send(); | ||
impl->onUpdate(Update::Repaint); | ||
} | ||
|
||
void Map::render(View& view) { | ||
if (!impl->style) { | ||
void Map::Impl::renderStill() { | ||
if (!stillImageRequest) { | ||
return; | ||
} | ||
|
||
if (impl->renderState == RenderState::Never) { | ||
impl->backend.notifyMapChange(MapChangeWillStartRenderingMap); | ||
} | ||
|
||
impl->backend.notifyMapChange(MapChangeWillStartRenderingFrame); | ||
|
||
const Update flags = impl->transform.updateTransitions(Clock::now()); | ||
|
||
impl->render(view); | ||
|
||
impl->backend.notifyMapChange(isFullyLoaded() ? | ||
MapChangeDidFinishRenderingFrameFullyRendered : | ||
MapChangeDidFinishRenderingFrame); | ||
|
||
if (!isFullyLoaded()) { | ||
impl->renderState = RenderState::Partial; | ||
} else if (impl->renderState != RenderState::Fully) { | ||
impl->renderState = RenderState::Fully; | ||
impl->backend.notifyMapChange(MapChangeDidFinishRenderingMapFullyRendered); | ||
if (impl->loading) { | ||
impl->loading = false; | ||
impl->backend.notifyMapChange(MapChangeDidFinishLoadingMap); | ||
} | ||
} | ||
|
||
// Triggers an asynchronous update, that eventually triggers a view | ||
// invalidation, causing renderSync to be called again if in transition. | ||
if (flags != Update::Nothing) { | ||
impl->onUpdate(flags); | ||
} | ||
// TODO: determine whether we need activate/deactivate | ||
BackendScope guard(backend); | ||
render(stillImageRequest->view); | ||
} | ||
|
||
void Map::triggerRepaint() { | ||
impl->backend.invalidate(); | ||
} | ||
|
||
void Map::Impl::update() { | ||
if (!style) { | ||
updateFlags = Update::Nothing; | ||
} | ||
void Map::render(View& view) { | ||
impl->render(view); | ||
} | ||
|
||
if (updateFlags == Update::Nothing || (mode == MapMode::Still && !stillImageRequest)) { | ||
void Map::Impl::render(View& view) { | ||
if (!style) { | ||
return; | ||
} | ||
|
||
// This time point is used to: | ||
// - Calculate style property transitions; | ||
// - Hint style sources to notify when all its tiles are loaded; | ||
timePoint = Clock::now(); | ||
TimePoint timePoint = Clock::now(); | ||
|
||
auto flags = transform.updateTransitions(timePoint); | ||
|
||
updateFlags |= flags; | ||
|
||
if (style->loaded && updateFlags & Update::AnnotationStyle) { | ||
annotationManager->updateStyle(*style); | ||
|
@@ -276,46 +255,74 @@ void Map::Impl::update() { | |
|
||
style->updateTiles(parameters); | ||
|
||
if (mode == MapMode::Continuous) { | ||
backend.invalidate(); | ||
} else if (stillImageRequest && style->isLoaded()) { | ||
// TODO: determine whether we need activate/deactivate | ||
BackendScope guard(backend); | ||
render(stillImageRequest->view); | ||
} | ||
|
||
updateFlags = Update::Nothing; | ||
} | ||
|
||
void Map::Impl::render(View& view) { | ||
if (!painter) { | ||
painter = std::make_unique<Painter>(backend.getContext(), transform.getState(), pixelRatio); | ||
} | ||
|
||
FrameData frameData { timePoint, | ||
pixelRatio, | ||
mode, | ||
contextMode, | ||
debugOptions }; | ||
if (mode == MapMode::Continuous) { | ||
if (renderState == RenderState::Never) { | ||
backend.notifyMapChange(MapChangeWillStartRenderingMap); | ||
} | ||
|
||
backend.notifyMapChange(MapChangeWillStartRenderingFrame); | ||
|
||
FrameData frameData { timePoint, | ||
pixelRatio, | ||
mode, | ||
contextMode, | ||
debugOptions }; | ||
|
||
painter->render(*style, | ||
frameData, | ||
view, | ||
annotationManager->getSpriteAtlas()); | ||
|
||
painter->cleanup(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the static rendering case, we're calling |
||
|
||
backend.notifyMapChange(style->isLoaded() ? | ||
MapChangeDidFinishRenderingFrameFullyRendered : | ||
MapChangeDidFinishRenderingFrame); | ||
|
||
if (!style->isLoaded()) { | ||
renderState = RenderState::Partial; | ||
} else if (renderState != RenderState::Fully) { | ||
renderState = RenderState::Fully; | ||
backend.notifyMapChange(MapChangeDidFinishRenderingMapFullyRendered); | ||
if (loading) { | ||
loading = false; | ||
backend.notifyMapChange(MapChangeDidFinishLoadingMap); | ||
} | ||
} | ||
|
||
painter->render(*style, | ||
frameData, | ||
view, | ||
annotationManager->getSpriteAtlas()); | ||
if (style->hasTransitions()) { | ||
flags |= Update::RecalculateStyle; | ||
} else if (painter->needsAnimation()) { | ||
flags |= Update::Repaint; | ||
} | ||
|
||
// Only schedule an update if we need to paint another frame due to transitions or | ||
// animations that are still in progress | ||
if (flags != Update::Nothing) { | ||
onUpdate(flags); | ||
} | ||
} else if (stillImageRequest && style->isLoaded()) { | ||
FrameData frameData { timePoint, | ||
pixelRatio, | ||
mode, | ||
contextMode, | ||
debugOptions }; | ||
|
||
painter->render(*style, | ||
frameData, | ||
view, | ||
annotationManager->getSpriteAtlas()); | ||
|
||
if (mode == MapMode::Still) { | ||
auto request = std::move(stillImageRequest); | ||
request->callback(nullptr); | ||
} | ||
|
||
painter->cleanup(); | ||
|
||
if (style->hasTransitions()) { | ||
updateFlags |= Update::RecalculateStyle; | ||
asyncUpdate.send(); | ||
} else if (painter->needsAnimation()) { | ||
updateFlags |= Update::Repaint; | ||
asyncUpdate.send(); | ||
painter->cleanup(); | ||
} | ||
} | ||
|
||
|
@@ -399,8 +406,7 @@ void Map::Impl::loadStyleJSON(const std::string& json) { | |
map.setPitch(map.getDefaultPitch()); | ||
} | ||
|
||
updateFlags |= Update::Classes | Update::RecalculateStyle | Update::AnnotationStyle; | ||
asyncUpdate.send(); | ||
onUpdate(Update::Classes | Update::RecalculateStyle | Update::AnnotationStyle); | ||
} | ||
|
||
std::string Map::getStyleURL() const { | ||
|
@@ -1075,9 +1081,9 @@ void Map::Impl::onSourceAttributionChanged(style::Source&, const std::string&) { | |
|
||
void Map::Impl::onUpdate(Update flags) { | ||
updateFlags |= flags; | ||
asyncUpdate.send(); | ||
asyncInvalidate.send(); | ||
} | ||
|
||
void Map::Impl::onStyleLoaded() { | ||
backend.notifyMapChange(MapChangeDidFinishLoadingStyle); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the invalidation call back to happen after the async. The change to master is now that before, we had a
render() => asyncUpdate() => update() => invalidate() => render()
flow. It's now shortened torender() => asyncInvalidate() => invalidate() => update+render()