From 63fbe9f8a88ce95250f9999850f27ea8cb89cf6c Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 31 Jan 2012 21:55:27 +0400 Subject: [PATCH] doesn't cancel already rendering first tile in new coverage. --- map/screen_coverage.cpp | 6 ++++-- map/tile_renderer.cpp | 38 ++++++++++++++++++++++++++++++++++++++ map/tile_renderer.hpp | 10 ++++++++++ map/tiler.cpp | 9 +++++++++ map/tiler.hpp | 1 + 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp index 7c769b5520..9490b3314b 100644 --- a/map/screen_coverage.cpp +++ b/map/screen_coverage.cpp @@ -244,8 +244,10 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) m_tileRenderer->ClearCommands(); /// setting new sequenceID m_tileRenderer->SetSequenceID(m_tiler.sequenceID()); - /// cancelling commands in progress - m_tileRenderer->CancelCommands(); + + /// checking, whether we should cancel tile that is currently rendering + m_tileRenderer->CheckCurrentTiles(newRects); + /// adding commands for tiles which aren't in cache for (size_t i = 0; i < newRects.size(); ++i) m_tileRenderer->AddCommand(newRects[i], m_tiler.sequenceID(), diff --git a/map/tile_renderer.cpp b/map/tile_renderer.cpp index 948c184a93..d23ba690f8 100644 --- a/map/tile_renderer.cpp +++ b/map/tile_renderer.cpp @@ -145,6 +145,8 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env, if (m_resourceManager->renderTargetTextures()->IsCancelled()) return; + StartTile(rectInfo); + drawer->screen()->setRenderTarget(tileTarget); shared_ptr tileInfoLayer(new yg::InfoLayer()); @@ -212,6 +214,8 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env, } } + FinishTile(rectInfo); + double duration = timer.ElapsedSeconds(); if (env.isCancelled()) @@ -285,4 +289,38 @@ void TileRenderer::AddTile(Tiler::RectInfo const & rectInfo, Tile const & tile) m_tileCache.writeUnlock(); } +void TileRenderer::StartTile(Tiler::RectInfo const & rectInfo) +{ + threads::MutexGuard g(m_tilesInProgressMutex); + m_tilesInProgress.insert(rectInfo); +} + +void TileRenderer::FinishTile(Tiler::RectInfo const & rectInfo) +{ + threads::MutexGuard g(m_tilesInProgressMutex); + m_tilesInProgress.erase(rectInfo); +} + +void TileRenderer::CheckCurrentTiles(vector & v) +{ + bool shouldCancel = true; + + { + threads::MutexGuard g(m_tilesInProgressMutex); + + for (set::const_iterator it = m_tilesInProgress.begin(); + it != m_tilesInProgress.end(); + ++it) + { + /// if the first non-drawn tile in new coverage is + /// already rendering do not cancell it. + if (!v.empty() && v[0] == *it) + shouldCancel = false; + } + } + + if (shouldCancel) + CancelCommands(); +} + diff --git a/map/tile_renderer.hpp b/map/tile_renderer.hpp index d44b8183fe..387a449a11 100644 --- a/map/tile_renderer.hpp +++ b/map/tile_renderer.hpp @@ -57,6 +57,9 @@ protected: int m_sequenceID; bool m_isExiting; + threads::Mutex m_tilesInProgressMutex; + set m_tilesInProgress; + void InitializeThreadGL(core::CommandsQueue::Environment const & env); void FinalizeThreadGL(core::CommandsQueue::Environment const & env); void CancelThread(core::CommandsQueue::Environment const & env); @@ -98,4 +101,11 @@ public: bool HasTile(Tiler::RectInfo const & rectInfo); void AddTile(Tiler::RectInfo const & rectInfo, Tile const & tile); + + void StartTile(Tiler::RectInfo const & rectInfo); + void FinishTile(Tiler::RectInfo const & rectInfo); + + /// checking, whether we should cancell currently rendering tiles, + /// or continue with theirs rendering. + void CheckCurrentTiles(vector & v); }; diff --git a/map/tiler.cpp b/map/tiler.cpp index db4cca7a62..a7090148e8 100644 --- a/map/tiler.cpp +++ b/map/tiler.cpp @@ -50,6 +50,15 @@ bool operator<(Tiler::RectInfo const & l, Tiler::RectInfo const & r) return false; } +bool operator==(Tiler::RectInfo const & l, Tiler::RectInfo const & r) +{ + return (l.m_y == r.m_y) + && (l.m_x == r.m_x) + && (l.m_drawScale == r.m_drawScale) + && (l.m_tileScale == r.m_tileScale); +} + + int Tiler::drawScale(ScreenBase const & s) const { ScreenBase tmpS = s; diff --git a/map/tiler.hpp b/map/tiler.hpp index f8d89bc70f..ad11f36008 100644 --- a/map/tiler.hpp +++ b/map/tiler.hpp @@ -60,3 +60,4 @@ struct LessByDistance }; bool operator<(Tiler::RectInfo const & l, Tiler::RectInfo const & r); +bool operator==(Tiler::RectInfo const & l, Tiler::RectInfo const & r);