User marks invalidation.

This commit is contained in:
Daria Volvenkova 2017-07-14 16:58:43 +03:00 committed by Roman Kuznetsov
parent 8878f80d8d
commit ebcb0b59e2
12 changed files with 96 additions and 35 deletions

View file

@ -113,9 +113,10 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
ScreenBase screen;
bool have3dBuildings;
bool forceRequest;
m_requestedTiles->GetParams(screen, have3dBuildings, forceRequest);
m_readManager->UpdateCoverage(screen, have3dBuildings, forceRequest, tiles, m_texMng,
make_ref(m_metalineManager));
bool forceUserMarksRequest;
m_requestedTiles->GetParams(screen, have3dBuildings, forceRequest, forceUserMarksRequest);
m_readManager->UpdateCoverage(screen, have3dBuildings, forceRequest, forceUserMarksRequest,
tiles, m_texMng, make_ref(m_metalineManager));
m_updateCurrentCountryFn(screen.ClipRect().Center(), (*tiles.begin()).m_zoomLevel);
}
break;
@ -175,8 +176,14 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::FinishTileRead:
{
ref_ptr<FinishTileReadMessage> msg = message;
if (msg->NeedForceUpdateUserMarks())
{
for (auto const & tileKey : msg->GetTiles())
m_userMarkGenerator->GenerateUserMarksGeometry(tileKey, m_texMng);
}
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<FinishTileReadMessage>(msg->MoveTiles()),
make_unique_dp<FinishTileReadMessage>(msg->MoveTiles(),
msg->NeedForceUpdateUserMarks()),
MessagePriority::Normal);
break;
}

View file

@ -130,11 +130,13 @@ FrontendRenderer::FrontendRenderer(Params && params)
, m_userPositionChangedFn(params.m_positionChangedFn)
, m_requestedTiles(params.m_requestedTiles)
, m_maxGeneration(0)
, m_maxUserMarksGeneration(0)
, m_needRestoreSize(false)
, m_trafficEnabled(params.m_trafficEnabled)
, m_overlaysTracker(new OverlaysTracker())
, m_overlaysShowStatsCallback(std::move(params.m_overlaysShowStatsCallback))
, m_forceUpdateScene(false)
, m_forceUpdateUserMarks(false)
, m_postprocessRenderer(new PostprocessRenderer())
#ifdef SCENARIO_ENABLE
, m_scenarioManager(new ScenarioManager(this))
@ -750,12 +752,21 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::SetSimplifiedTrafficColors:
case Message::SetDisplacementMode:
case Message::UpdateMetalines:
case Message::InvalidateUserMarks:
{
m_forceUpdateScene = true;
break;
}
case Message::InvalidateUserMarks:
{
auto removePredicate = [](drape_ptr<RenderGroup> const & group)
{
RenderLayer::RenderLayerID id = RenderLayer::GetLayerID(group->GetState());
return id == RenderLayer::UserLineID || id == RenderLayer::UserMarkID;
};
RemoveRenderGroupsLater(removePredicate);
m_forceUpdateUserMarks = true;
break;
}
case Message::FlushTrafficData:
{
if (!m_trafficEnabled)
@ -851,7 +862,8 @@ void FrontendRenderer::UpdateGLResources()
ScreenBase screen = m_userEventStream.GetCurrentScreen();
m_lastReadedModelView = screen;
m_requestedTiles->Set(screen, m_isIsometry || screen.isPerspective(),
m_forceUpdateScene, ResolveTileKeys(screen));
m_forceUpdateScene, m_forceUpdateUserMarks,
ResolveTileKeys(screen));
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<UpdateReadManagerMessage>(),
MessagePriority::UberHighSingleton);
@ -916,7 +928,8 @@ void FrontendRenderer::InvalidateRect(m2::RectD const & gRect)
// Request new tiles.
m_lastReadedModelView = screen;
m_requestedTiles->Set(screen, m_isIsometry || screen.isPerspective(), m_forceUpdateScene,
m_requestedTiles->Set(screen, m_isIsometry || screen.isPerspective(),
m_forceUpdateScene, m_forceUpdateUserMarks,
ResolveTileKeys(screen));
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<UpdateReadManagerMessage>(),
@ -1000,6 +1013,9 @@ bool FrontendRenderer::CheckTileGenerations(TileKey const & tileKey)
if (tileKey.m_generation > m_maxGeneration)
m_maxGeneration = tileKey.m_generation;
if (tileKey.m_userMarksGeneration > m_maxUserMarksGeneration)
m_maxUserMarksGeneration = tileKey.m_userMarksGeneration;
auto removePredicate = [&tileKey](drape_ptr<RenderGroup> const & group)
{
return group->GetTileKey() == tileKey && group->GetTileKey().m_generation < tileKey.m_generation;
@ -1833,7 +1849,7 @@ void FrontendRenderer::Routine::Do()
m_renderer.RenderScene(modelView);
if (modelViewChanged || m_renderer.m_forceUpdateScene)
if (modelViewChanged || m_renderer.m_forceUpdateScene || m_renderer.m_forceUpdateUserMarks)
m_renderer.UpdateScene(modelView);
isActiveFrame |= InterpolationHolder::Instance().Advance(frameTime);
@ -1991,22 +2007,27 @@ void FrontendRenderer::UpdateScene(ScreenBase const & modelView)
{
uint32_t const kMaxGenerationRange = 5;
TileKey const & key = group->GetTileKey();
return (group->IsOverlay() && key.m_zoomLevel > m_currentZoomLevel) ||
(m_maxGeneration - key.m_generation > kMaxGenerationRange);
(m_maxGeneration - key.m_generation > kMaxGenerationRange) ||
(group->IsUserMark() &&
(m_maxUserMarksGeneration - key.m_userMarksGeneration > kMaxGenerationRange));
};
for (RenderLayer & layer : m_layers)
layer.m_isDirty |= RemoveGroups(removePredicate, layer.m_renderGroups, make_ref(m_overlayTree));
if (m_forceUpdateScene || m_lastReadedModelView != modelView)
if (m_forceUpdateScene || m_forceUpdateUserMarks || m_lastReadedModelView != modelView)
{
EmitModelViewChanged(modelView);
m_lastReadedModelView = modelView;
m_requestedTiles->Set(modelView, m_isIsometry || modelView.isPerspective(), m_forceUpdateScene,
m_requestedTiles->Set(modelView, m_isIsometry || modelView.isPerspective(),
m_forceUpdateScene, m_forceUpdateUserMarks,
ResolveTileKeys(modelView));
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<UpdateReadManagerMessage>(),
MessagePriority::UberHighSingleton);
m_forceUpdateScene = false;
m_forceUpdateUserMarks = false;
}
}

View file

@ -293,6 +293,7 @@ private:
ref_ptr<RequestedTiles> m_requestedTiles;
uint64_t m_maxGeneration;
uint64_t m_maxUserMarksGeneration;
int m_mergeBucketsCounter = 0;
int m_lastRecacheRouteId = 0;
@ -324,6 +325,7 @@ private:
OverlaysShowStatsCallback m_overlaysShowStatsCallback;
bool m_forceUpdateScene;
bool m_forceUpdateUserMarks;
drape_ptr<PostprocessRenderer> m_postprocessRenderer;

View file

@ -104,17 +104,20 @@ public:
class FinishTileReadMessage : public Message
{
public:
template<typename T> FinishTileReadMessage(T && tiles)
template<typename T> FinishTileReadMessage(T && tiles, bool forceUpdateUserMarks)
: m_tiles(forward<T>(tiles))
, m_forceUpdateUserMarks(forceUpdateUserMarks)
{}
Type GetType() const override { return Message::FinishTileRead; }
TTilesCollection const & GetTiles() const { return m_tiles; }
TTilesCollection && MoveTiles() { return move(m_tiles); }
bool NeedForceUpdateUserMarks() const { return m_forceUpdateUserMarks; }
private:
TTilesCollection m_tiles;
bool m_forceUpdateUserMarks;
};
class FlushRenderBucketMessage : public BaseTileMessage

View file

@ -55,6 +55,7 @@ ReadManager::ReadManager(ref_ptr<ThreadsCommutator> commutator, MapDataProvider
, m_tasksPool(64, ReadMWMTaskFactory(m_model))
, m_counter(0)
, m_generationCounter(0)
, m_userMarksGenerationCounter(0)
{
Start();
}
@ -103,7 +104,8 @@ void ReadManager::OnTaskFinished(threads::IRoutine * task)
TTilesCollection tiles;
tiles.emplace(t->GetTileKey());
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<FinishTileReadMessage>(std::move(tiles)),
make_unique_dp<FinishTileReadMessage>(std::move(tiles),
false /* forceUpdateUserMarks */),
MessagePriority::Normal);
}
}
@ -112,8 +114,8 @@ void ReadManager::OnTaskFinished(threads::IRoutine * task)
m_tasksPool.Return(t);
}
void ReadManager::UpdateCoverage(ScreenBase const & screen,
bool have3dBuildings, bool forceUpdate,
void ReadManager::UpdateCoverage(ScreenBase const & screen, bool have3dBuildings,
bool forceUpdate, bool forceUpdateUserMarks,
TTilesCollection const & tiles,
ref_ptr<dp::TextureManager> texMng,
ref_ptr<MetalineManager> metalineMng)
@ -130,7 +132,8 @@ void ReadManager::UpdateCoverage(ScreenBase const & screen,
m_tileInfos.clear();
IncreaseCounter(static_cast<int>(tiles.size()));
m_generationCounter++;
++m_generationCounter;
++m_userMarksGenerationCounter;
for (auto const & tileKey : tiles)
PushTaskBackForTileKey(tileKey, texMng, metalineMng);
@ -159,7 +162,9 @@ void ReadManager::UpdateCoverage(ScreenBase const & screen,
std::back_inserter(readyTiles), LessCoverageCell());
IncreaseCounter(static_cast<int>(newTiles.size()));
CheckFinishedTiles(readyTiles);
if (forceUpdateUserMarks)
++m_userMarksGenerationCounter;
CheckFinishedTiles(readyTiles, forceUpdateUserMarks);
for (auto const & tileKey : newTiles)
PushTaskBackForTileKey(tileKey, texMng, metalineMng);
}
@ -214,7 +219,7 @@ void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey,
ref_ptr<MetalineManager> metalineMng)
{
ASSERT(m_pool != nullptr, ());
auto context = make_unique_dp<EngineContext>(TileKey(tileKey, m_generationCounter),
auto context = make_unique_dp<EngineContext>(TileKey(tileKey, m_generationCounter, m_userMarksGenerationCounter),
m_commutator, texMng, metalineMng,
m_customSymbolsContext,
m_have3dBuildings && m_allow3dBuildings,
@ -231,7 +236,7 @@ void ReadManager::PushTaskBackForTileKey(TileKey const & tileKey,
m_pool->PushBack(task);
}
void ReadManager::CheckFinishedTiles(TTileInfoCollection const & requestedTiles)
void ReadManager::CheckFinishedTiles(TTileInfoCollection const & requestedTiles, bool forceUpdateUserMarks)
{
if (requestedTiles.empty())
return;
@ -243,13 +248,14 @@ void ReadManager::CheckFinishedTiles(TTileInfoCollection const & requestedTiles)
for (auto const & tile : requestedTiles)
{
if (m_activeTiles.find(tile->GetTileKey()) == m_activeTiles.end())
finishedTiles.emplace(tile->GetTileKey());
finishedTiles.emplace(tile->GetTileKey(), m_generationCounter, m_userMarksGenerationCounter);
}
if (!finishedTiles.empty())
{
m_commutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
make_unique_dp<FinishTileReadMessage>(std::move(finishedTiles)),
make_unique_dp<FinishTileReadMessage>(std::move(finishedTiles),
forceUpdateUserMarks),
MessagePriority::Normal);
}
}

View file

@ -40,7 +40,8 @@ public:
void Start();
void Stop();
void UpdateCoverage(ScreenBase const & screen, bool have3dBuildings, bool forceUpdate,
void UpdateCoverage(ScreenBase const & screen, bool have3dBuildings,
bool forceUpdate, bool forceUpdateUserMarks,
TTilesCollection const & tiles, ref_ptr<dp::TextureManager> texMng,
ref_ptr<MetalineManager> metalineMng);
void Invalidate(TTilesCollection const & keyStorage);
@ -93,6 +94,7 @@ private:
int m_counter;
std::mutex m_finishedTilesMutex;
uint64_t m_generationCounter;
uint64_t m_userMarksGenerationCounter;
using TTileInfoCollection = buffer_vector<std::shared_ptr<TileInfo>, 8>;
TTilesCollection m_activeTiles;
@ -102,6 +104,6 @@ private:
void CancelTileInfo(std::shared_ptr<TileInfo> const & tileToCancel);
void ClearTileInfo(std::shared_ptr<TileInfo> const & tileToClear);
void IncreaseCounter(int value);
void CheckFinishedTiles(TTileInfoCollection const & requestedTiles);
void CheckFinishedTiles(TTileInfoCollection const & requestedTiles, bool forceUpdateUserMarks);
};
} // namespace df

View file

@ -158,6 +158,12 @@ bool RenderGroup::IsOverlay() const
(m_state.GetDepthLayer() == dp::GLState::NavigationLayer && HasOverlayHandles());
}
bool RenderGroup::IsUserMark() const
{
return m_state.GetDepthLayer() == dp::GLState::UserLineLayer ||
m_state.GetDepthLayer() == dp::GLState::UserMarkLayer;
}
bool RenderGroup::UpdateCanBeDeletedStatus(bool canBeDeleted, int currentZoom, ref_ptr<dp::OverlayTree> tree)
{
if (!IsPendingOnDelete())

View file

@ -74,6 +74,7 @@ public:
bool UpdateCanBeDeletedStatus(bool canBeDeleted, int currentZoom, ref_ptr<dp::OverlayTree> tree);
bool IsOverlay() const;
bool IsUserMark() const;
private:
std::vector<drape_ptr<dp::RenderBucket>> m_renderBuckets;

View file

@ -4,13 +4,14 @@ namespace df
{
void RequestedTiles::Set(ScreenBase const & screen, bool have3dBuildings, bool forceRequest,
TTilesCollection && tiles)
bool forceUserMarksRequest, TTilesCollection && tiles)
{
lock_guard<mutex> lock(m_mutex);
m_tiles = move(tiles);
m_screen = screen;
m_have3dBuildings = have3dBuildings;
m_forceRequest = forceRequest;
m_forceUserMarksRequest = forceUserMarksRequest;
}
TTilesCollection RequestedTiles::GetTiles()
@ -23,12 +24,14 @@ TTilesCollection RequestedTiles::GetTiles()
return tiles;
}
void RequestedTiles::GetParams(ScreenBase & screen, bool & have3dBuildings, bool & forceRequest)
void RequestedTiles::GetParams(ScreenBase & screen, bool & have3dBuildings,
bool & forceRequest, bool & forceUserMarksRequest)
{
lock_guard<mutex> lock(m_mutex);
screen = m_screen;
have3dBuildings = m_have3dBuildings;
forceRequest = m_forceRequest;
forceUserMarksRequest = m_forceUserMarksRequest;
}
bool RequestedTiles::CheckTileKey(TileKey const & tileKey) const

View file

@ -14,9 +14,10 @@ class RequestedTiles
public:
RequestedTiles() = default;
void Set(ScreenBase const & screen, bool have3dBuildings, bool forceRequest,
TTilesCollection && tiles);
bool forceUserMarksRequest, TTilesCollection && tiles);
TTilesCollection GetTiles();
void GetParams(ScreenBase & screen, bool & have3dBuildings, bool & forceRequest);
void GetParams(ScreenBase & screen, bool & have3dBuildings,
bool & forceRequest, bool & forceUserMarksRequest);
bool CheckTileKey(TileKey const & tileKey) const;
private:
@ -24,6 +25,7 @@ private:
ScreenBase m_screen;
bool m_have3dBuildings = false;
bool m_forceRequest = false;
bool m_forceUserMarksRequest = false;
mutable mutex m_mutex;
};

View file

@ -23,10 +23,12 @@ TileKey::TileKey(int x, int y, int zoomLevel)
m_generation(0)
{}
TileKey::TileKey(TileKey const & key, uint64_t generation)
: m_x(key.m_x), m_y(key.m_y),
m_zoomLevel(key.m_zoomLevel),
m_generation(generation)
TileKey::TileKey(TileKey const & key, uint64_t generation, uint64_t userMarksGeneration)
: m_x(key.m_x)
, m_y(key.m_y)
, m_zoomLevel(key.m_zoomLevel)
, m_generation(generation)
, m_userMarksGeneration(userMarksGeneration)
{}
bool TileKey::operator <(TileKey const & other) const
@ -49,6 +51,9 @@ bool TileKey::operator ==(TileKey const & other) const
bool TileKey::LessStrict(TileKey const & other) const
{
if (m_userMarksGeneration != other.m_userMarksGeneration)
return m_userMarksGeneration < other.m_userMarksGeneration;
if (m_generation != other.m_generation)
return m_generation < other.m_generation;
@ -66,7 +71,8 @@ bool TileKey::EqualStrict(TileKey const & other) const
return m_x == other.m_x &&
m_y == other.m_y &&
m_zoomLevel == other.m_zoomLevel &&
m_generation == other.m_generation;
m_generation == other.m_generation &&
m_userMarksGeneration == other.m_userMarksGeneration;
}
m2::RectD TileKey::GetGlobalRect(bool clipByDataMaxZoom) const
@ -97,7 +103,8 @@ std::string DebugPrint(TileKey const & key)
{
std::ostringstream out;
out << "[x = " << key.m_x << ", y = " << key.m_y << ", zoomLevel = "
<< key.m_zoomLevel << ", gen = " << key.m_generation << "]";
<< key.m_zoomLevel << ", gen = " << key.m_generation
<< ", user marks gen = " << key.m_userMarksGeneration << "]";
return out.str();
}
} // namespace df

View file

@ -13,7 +13,7 @@ struct TileKey
{
TileKey();
TileKey(int x, int y, int zoomLevel);
TileKey(TileKey const & key, uint64_t generation);
TileKey(TileKey const & key, uint64_t generation, uint64_t userMarksGeneration);
// Operators < and == do not consider parameter m_generation.
// m_generation is used to determine a generation of geometry for this tile key.
@ -37,6 +37,7 @@ struct TileKey
int m_zoomLevel;
uint64_t m_generation;
uint64_t m_userMarksGeneration;
};
struct TileKeyStrictComparator