Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] always commit placement to fix #11795
Browse files Browse the repository at this point in the history
Since placements will be committed even if they do not need the full
fade duration to fade features in, we need the new `fadeStartTime` to
keep track of how long we still need to fade. This is important because
if we fade too long we will trigger another placement and never stop
rendering.
  • Loading branch information
ansis committed Jun 7, 2018
1 parent 0a15be0 commit 58b6c42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
10 changes: 4 additions & 6 deletions src/mbgl/renderer/renderer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {

bool placementChanged = false;
if (!placement->stillRecent(parameters.timePoint)) {
placementChanged = true;

auto newPlacement = std::make_unique<Placement>(parameters.state, parameters.mapMode);
std::set<std::string> usedSymbolLayers;
for (auto it = order.rbegin(); it != order.rend(); ++it) {
Expand All @@ -396,13 +398,9 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
}
}

placementChanged = newPlacement->commit(*placement, parameters.timePoint);
newPlacement->commit(*placement, parameters.timePoint);
crossTileSymbolIndex.pruneUnusedLayers(usedSymbolLayers);
if (placementChanged || symbolBucketsChanged) {
placement = std::move(newPlacement);
}

placement->setRecent(parameters.timePoint);
placement = std::move(newPlacement);

updateFadingTiles();
} else {
Expand Down
20 changes: 8 additions & 12 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Placement::Placement(const TransformState& state_, MapMode mapMode_)
: collisionIndex(state_)
, state(state_)
, mapMode(mapMode_)
, recentUntil(TimePoint::min())
{}

void Placement::placeLayer(RenderSymbolLayer& symbolLayer, const mat4& projMatrix, bool showCollisionBoxes) {
Expand Down Expand Up @@ -188,7 +187,7 @@ void Placement::placeLayerBucket(
bucket.justReloaded = false;
}

bool Placement::commit(const Placement& prevPlacement, TimePoint now) {
void Placement::commit(const Placement& prevPlacement, TimePoint now) {
commitTime = now;

bool placementChanged = false;
Expand Down Expand Up @@ -222,7 +221,7 @@ bool Placement::commit(const Placement& prevPlacement, TimePoint now) {
}
}

return placementChanged;
fadeStartTime = placementChanged ? commitTime : prevPlacement.fadeStartTime;
}

void Placement::updateLayerOpacities(RenderSymbolLayer& symbolLayer) {
Expand Down Expand Up @@ -339,18 +338,15 @@ float Placement::symbolFadeChange(TimePoint now) const {
}

bool Placement::hasTransitions(TimePoint now) const {
return symbolFadeChange(now) < 1.0 || stale;
if (mapMode == MapMode::Continuous) {
return stale || std::chrono::duration<float>(now - fadeStartTime) < Duration(std::chrono::milliseconds(300));
} else {
return false;
}
}

bool Placement::stillRecent(TimePoint now) const {
return mapMode == MapMode::Continuous && recentUntil > now;
}
void Placement::setRecent(TimePoint now) {
stale = false;
if (mapMode == MapMode::Continuous) {
// Only set in continuous mode because "now" isn't defined in still mode
recentUntil = now + Duration(std::chrono::milliseconds(300));
}
return mapMode == MapMode::Continuous && commitTime + Duration(std::chrono::milliseconds(300)) > now;
}

void Placement::setStale() {
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/text/placement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Placement {
public:
Placement(const TransformState&, MapMode mapMode);
void placeLayer(RenderSymbolLayer&, const mat4&, bool showCollisionBoxes);
bool commit(const Placement& prevPlacement, TimePoint);
void commit(const Placement& prevPlacement, TimePoint);
void updateLayerOpacities(RenderSymbolLayer&);
float symbolFadeChange(TimePoint now) const;
bool hasTransitions(TimePoint now) const;
Expand Down Expand Up @@ -94,12 +94,12 @@ class Placement {

TransformState state;
MapMode mapMode;
TimePoint fadeStartTime;
TimePoint commitTime;

std::unordered_map<uint32_t, JointPlacement> placements;
std::unordered_map<uint32_t, JointOpacityState> opacities;

TimePoint recentUntil;
bool stale = false;

std::unordered_map<uint32_t, RetainedQueryData> retainedQueryData;
Expand Down

0 comments on commit 58b6c42

Please sign in to comment.