Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drape_frontend/CMakeLists.txt1
-rw-r--r--drape_frontend/drape_api.cpp76
-rw-r--r--drape_frontend/drape_api.hpp31
-rw-r--r--drape_frontend/drape_engine.hpp3
-rw-r--r--drape_frontend/drape_engine_safe_ptr.hpp75
-rwxr-xr-xdrape_frontend/drape_frontend.pro1
-rw-r--r--map/framework.cpp8
-rw-r--r--map/local_ads_manager.cpp25
-rw-r--r--map/local_ads_manager.hpp10
-rw-r--r--map/routing_manager.cpp120
-rw-r--r--map/routing_manager.hpp14
-rw-r--r--map/traffic_manager.cpp24
-rw-r--r--map/traffic_manager.hpp9
-rw-r--r--xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj4
14 files changed, 226 insertions, 175 deletions
diff --git a/drape_frontend/CMakeLists.txt b/drape_frontend/CMakeLists.txt
index 0ab7df5fb5..a3c00e0a12 100644
--- a/drape_frontend/CMakeLists.txt
+++ b/drape_frontend/CMakeLists.txt
@@ -80,6 +80,7 @@ set(
drape_api_renderer.hpp
drape_engine.cpp
drape_engine.hpp
+ drape_engine_safe_ptr.hpp
drape_hints.hpp
drape_measurer.cpp
drape_measurer.hpp
diff --git a/drape_frontend/drape_api.cpp b/drape_frontend/drape_api.cpp
index 8e00a22b8f..f8bcad6f65 100644
--- a/drape_frontend/drape_api.cpp
+++ b/drape_frontend/drape_api.cpp
@@ -4,76 +4,74 @@
namespace df
{
-
-void DrapeApi::SetEngine(ref_ptr<DrapeEngine> engine)
+void DrapeApi::SetDrapeEngine(ref_ptr<DrapeEngine> engine)
{
- m_engine = engine;
+ m_engine.Set(engine);
}
-void DrapeApi::AddLine(string const & id, DrapeApiLineData const & data)
+void DrapeApi::AddLine(std::string const & id, DrapeApiLineData const & data)
{
- lock_guard<mutex> lock(m_mutex);
-
- if (m_engine == nullptr)
+ DrapeEngineLockGuard lock(m_engine);
+ if (!lock)
return;
- auto it = m_lines.find(id);
+ auto & threadCommutator = lock.Get()->m_threadCommutator;
+ auto const it = m_lines.find(id);
if (it != m_lines.end())
{
- m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
- make_unique_dp<DrapeApiRemoveMessage>(id),
- MessagePriority::Normal);
+ threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
+ make_unique_dp<DrapeApiRemoveMessage>(id),
+ MessagePriority::Normal);
}
m_lines[id] = data;
TLines lines;
- lines.insert(make_pair(id, data));
- m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
- make_unique_dp<DrapeApiAddLinesMessage>(lines),
- MessagePriority::Normal);
+ lines.insert(std::make_pair(id, data));
+ threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
+ make_unique_dp<DrapeApiAddLinesMessage>(lines),
+ MessagePriority::Normal);
}
-void DrapeApi::RemoveLine(string const & id)
+void DrapeApi::RemoveLine(std::string const & id)
{
- lock_guard<mutex> lock(m_mutex);
-
- if (m_engine == nullptr)
+ DrapeEngineLockGuard lock(m_engine);
+ if (!lock)
return;
+ auto & threadCommutator = lock.Get()->m_threadCommutator;
m_lines.erase(id);
- m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
- make_unique_dp<DrapeApiRemoveMessage>(id),
- MessagePriority::Normal);
+ threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
+ make_unique_dp<DrapeApiRemoveMessage>(id),
+ MessagePriority::Normal);
}
void DrapeApi::Clear()
{
- lock_guard<mutex> lock(m_mutex);
-
- if (m_engine == nullptr)
+ DrapeEngineLockGuard lock(m_engine);
+ if (!lock)
return;
+ auto & threadCommutator = lock.Get()->m_threadCommutator;
m_lines.clear();
- m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
- make_unique_dp<DrapeApiRemoveMessage>("", true /* remove all */),
- MessagePriority::Normal);
+ threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
+ make_unique_dp<DrapeApiRemoveMessage>("", true /* remove all */),
+ MessagePriority::Normal);
}
void DrapeApi::Invalidate()
{
- lock_guard<mutex> lock(m_mutex);
-
- if (m_engine == nullptr)
+ DrapeEngineLockGuard lock(m_engine);
+ if (!lock)
return;
- m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
- make_unique_dp<DrapeApiRemoveMessage>("", true /* remove all */),
- MessagePriority::Normal);
+ auto & threadCommutator = lock.Get()->m_threadCommutator;
+ threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
+ make_unique_dp<DrapeApiRemoveMessage>("", true /* remove all */),
+ MessagePriority::Normal);
- m_engine->m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
- make_unique_dp<DrapeApiAddLinesMessage>(m_lines),
- MessagePriority::Normal);
+ threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
+ make_unique_dp<DrapeApiAddLinesMessage>(m_lines),
+ MessagePriority::Normal);
}
-
-} // namespace df
+} // namespace df
diff --git a/drape_frontend/drape_api.hpp b/drape_frontend/drape_api.hpp
index 4d3b63fcf0..769c7016e3 100644
--- a/drape_frontend/drape_api.hpp
+++ b/drape_frontend/drape_api.hpp
@@ -1,24 +1,25 @@
#pragma once
+#include "drape_frontend/drape_engine_safe_ptr.hpp"
+
#include "drape/color.hpp"
#include "drape/pointers.hpp"
#include "geometry/point2d.hpp"
-#include "std/mutex.hpp"
-#include "std/unordered_map.hpp"
-#include "std/vector.hpp"
+#include <mutex>
+#include <string>
+#include <unordered_map>
+#include <vector>
namespace df
{
-
-class DrapeEngine;
-
struct DrapeApiLineData
{
DrapeApiLineData() = default;
- DrapeApiLineData(vector<m2::PointD> const & points, dp::Color const & color)
+ DrapeApiLineData(std::vector<m2::PointD> const & points,
+ dp::Color const & color)
: m_points(points)
, m_color(color)
{}
@@ -42,7 +43,7 @@ struct DrapeApiLineData
return *this;
}
- vector<m2::PointD> m_points;
+ std::vector<m2::PointD> m_points;
float m_width = 1.0f;
dp::Color m_color;
@@ -54,21 +55,19 @@ struct DrapeApiLineData
class DrapeApi
{
public:
- using TLines = unordered_map<string, DrapeApiLineData>;
+ using TLines = std::unordered_map<std::string, DrapeApiLineData>;
DrapeApi() = default;
- void SetEngine(ref_ptr<DrapeEngine> engine);
+ void SetDrapeEngine(ref_ptr<DrapeEngine> engine);
- void AddLine(string const & id, DrapeApiLineData const & data);
- void RemoveLine(string const & id);
+ void AddLine(std::string const & id, DrapeApiLineData const & data);
+ void RemoveLine(std::string const & id);
void Clear();
void Invalidate();
private:
- ref_ptr<DrapeEngine> m_engine;
+ DrapeEngineSafePtr m_engine;
TLines m_lines;
- mutex m_mutex;
};
-
-} // namespace df
+} // namespace df
diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp
index 08918f68e1..dbd2a8d134 100644
--- a/drape_frontend/drape_engine.hpp
+++ b/drape_frontend/drape_engine.hpp
@@ -252,5 +252,4 @@ private:
friend class DrapeApi;
};
-
-} // namespace df
+} // namespace df
diff --git a/drape_frontend/drape_engine_safe_ptr.hpp b/drape_frontend/drape_engine_safe_ptr.hpp
new file mode 100644
index 0000000000..a1a1366391
--- /dev/null
+++ b/drape_frontend/drape_engine_safe_ptr.hpp
@@ -0,0 +1,75 @@
+#pragma once
+
+#include "base/macros.hpp"
+
+#include "drape/drape_global.hpp"
+#include "drape/pointers.hpp"
+
+#include <mutex>
+
+namespace df
+{
+class DrapeEngine;
+
+class DrapeEngineSafePtr
+{
+public:
+ void Set(ref_ptr<DrapeEngine> engine)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ m_engine = engine;
+ }
+
+ explicit operator bool()
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ return m_engine != nullptr;
+ }
+
+ template <typename Function, typename ... Args>
+ void SafeCall(Function && f, Args && ... functionArgs)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_engine != nullptr)
+ (m_engine.get()->*f)(std::forward<Args>(functionArgs)...);
+ }
+
+ template <typename Function, typename ... Args>
+ dp::DrapeID SafeCallWithResult(Function && f, Args && ... functionArgs)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_engine != nullptr)
+ return (m_engine.get()->*f)(std::forward<Args>(functionArgs)...);
+ return dp::DrapeID();
+ }
+
+private:
+ ref_ptr<DrapeEngine> m_engine;
+ std::mutex m_mutex;
+
+ friend class DrapeEngineLockGuard;
+};
+
+class DrapeEngineLockGuard
+{
+public:
+ explicit DrapeEngineLockGuard(DrapeEngineSafePtr & enginePtr)
+ : m_ptr(enginePtr)
+ {
+ m_ptr.m_mutex.lock();
+ }
+
+ ~DrapeEngineLockGuard()
+ {
+ m_ptr.m_mutex.unlock();
+ }
+
+ explicit operator bool() { return m_ptr.m_engine != nullptr; }
+
+ ref_ptr<DrapeEngine> Get() { return m_ptr.m_engine; }
+
+private:
+ DrapeEngineSafePtr & m_ptr;
+ DISALLOW_COPY_AND_MOVE(DrapeEngineLockGuard);
+};
+} // namespace df
diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro
index 65ed3c70b5..346ac69d1c 100755
--- a/drape_frontend/drape_frontend.pro
+++ b/drape_frontend/drape_frontend.pro
@@ -151,6 +151,7 @@ HEADERS += \
drape_api_builder.hpp \
drape_api_renderer.hpp \
drape_engine.hpp \
+ drape_engine_safe_ptr.hpp \
drape_hints.hpp \
drape_measurer.hpp \
engine_context.hpp \
diff --git a/map/framework.cpp b/map/framework.cpp
index 5b2c128fcb..828cc4f064 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -1984,7 +1984,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
GetPlatform().RunOnGuiThread([this, sizes](){ m_searchMarksSizes = sizes; });
});
- m_drapeApi.SetEngine(make_ref(m_drapeEngine));
+ m_drapeApi.SetDrapeEngine(make_ref(m_drapeEngine));
m_routingManager.SetDrapeEngine(make_ref(m_drapeEngine), allow3d);
m_trafficManager.SetDrapeEngine(make_ref(m_drapeEngine));
m_localAdsManager.SetDrapeEngine(make_ref(m_drapeEngine));
@@ -2023,7 +2023,11 @@ void Framework::DestroyDrapeEngine()
{
if (m_drapeEngine != nullptr)
{
- m_drapeApi.SetEngine(nullptr);
+ m_drapeApi.SetDrapeEngine(nullptr);
+ m_routingManager.SetDrapeEngine(nullptr, false);
+ m_trafficManager.SetDrapeEngine(nullptr);
+ m_localAdsManager.SetDrapeEngine(nullptr);
+
m_trafficManager.Teardown();
m_localAdsManager.Teardown();
GpsTracker::Instance().Disconnect();
diff --git a/map/local_ads_manager.cpp b/map/local_ads_manager.cpp
index a1cf387d0a..e0b7ba3c40 100644
--- a/map/local_ads_manager.cpp
+++ b/map/local_ads_manager.cpp
@@ -316,10 +316,7 @@ void LocalAdsManager::SetBookmarkManager(BookmarkManager * bmManager)
void LocalAdsManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
{
- {
- std::lock_guard<std::mutex> lock(m_drapeEngineMutex);
- m_drapeEngine = engine;
- }
+ m_drapeEngine.Set(engine);
UpdateFeaturesCache({});
}
@@ -571,11 +568,7 @@ void LocalAdsManager::WriteCampaignFile(std::string const & campaignFile)
void LocalAdsManager::Invalidate()
{
DeleteAllLocalAdsMarks(m_bmManager);
- {
- std::lock_guard<std::mutex> lock(m_drapeEngineMutex);
- if (m_drapeEngine != nullptr)
- m_drapeEngine->RemoveAllCustomFeatures();
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::RemoveAllCustomFeatures);
CampaignData campaignData;
{
@@ -600,14 +593,10 @@ void LocalAdsManager::UpdateFeaturesCache(std::set<FeatureID> && ids)
m_featuresCache.insert(ids.begin(), ids.end());
featuresCache = m_featuresCache;
}
- {
- std::lock_guard<std::mutex> lock(m_drapeEngineMutex);
- if (m_drapeEngine != nullptr)
- m_drapeEngine->SetCustomFeatures(std::move(featuresCache));
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::SetCustomFeatures, std::move(featuresCache));
}
-void LocalAdsManager::ClearLocalAdsForMwm(MwmSet::MwmId const &mwmId)
+void LocalAdsManager::ClearLocalAdsForMwm(MwmSet::MwmId const & mwmId)
{
// Clear feature cache.
{
@@ -622,11 +611,7 @@ void LocalAdsManager::ClearLocalAdsForMwm(MwmSet::MwmId const &mwmId)
}
// Remove custom features in graphics engine.
- {
- std::lock_guard<std::mutex> lock(m_drapeEngineMutex);
- if (m_drapeEngine != nullptr)
- m_drapeEngine->RemoveCustomFeatures(mwmId);
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::RemoveCustomFeatures, mwmId);
// Delete marks.
DeleteLocalAdsMarks(m_bmManager, mwmId);
diff --git a/map/local_ads_manager.hpp b/map/local_ads_manager.hpp
index 147e81c43e..d3a99ccd59 100644
--- a/map/local_ads_manager.hpp
+++ b/map/local_ads_manager.hpp
@@ -2,6 +2,8 @@
#include "local_ads/statistics.hpp"
+#include "drape_frontend/drape_engine_safe_ptr.hpp"
+
#include "drape/pointers.hpp"
#include "geometry/rect2d.hpp"
@@ -22,11 +24,6 @@
#include <string>
#include <vector>
-namespace df
-{
-class DrapeEngine;
-}
-
namespace feature
{
class TypesHolder;
@@ -98,8 +95,7 @@ private:
std::atomic<BookmarkManager *> m_bmManager;
- ref_ptr<df::DrapeEngine> m_drapeEngine;
- std::mutex m_drapeEngineMutex;
+ df::DrapeEngineSafePtr m_drapeEngine;
std::map<std::string, bool> m_campaigns;
struct CampaignInfo
diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp
index fa2ba3ff4f..d76e6ed519 100644
--- a/map/routing_manager.cpp
+++ b/map/routing_manager.cpp
@@ -284,8 +284,7 @@ void RoutingManager::OnBuildRouteReady(Route const & route, IRouter::ResultCode
if (code == IRouter::NoError)
{
InsertRoute(route);
- if (m_drapeEngine != nullptr)
- m_drapeEngine->StopLocationFollow();
+ m_drapeEngine.SafeCall(&df::DrapeEngine::StopLocationFollow);
// Validate route (in case of bicycle routing it can be invalid).
ASSERT(route.IsValid(), ());
@@ -293,11 +292,8 @@ void RoutingManager::OnBuildRouteReady(Route const & route, IRouter::ResultCode
{
m2::RectD routeRect = route.GetPoly().GetLimitRect();
routeRect.Scale(kRouteScaleMultiplier);
- if (m_drapeEngine != nullptr)
- {
- m_drapeEngine->SetModelViewRect(routeRect, true /* applyRotation */, -1 /* zoom */,
- true /* isAnim */);
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::SetModelViewRect, routeRect,
+ true /* applyRotation */, -1 /* zoom */, true /* isAnim */);
}
}
else
@@ -401,35 +397,40 @@ void RoutingManager::SetRouterImpl(RouterType type)
void RoutingManager::RemoveRoute(bool deactivateFollowing)
{
- if (m_drapeEngine == nullptr)
- return;
-
if (deactivateFollowing)
SetPointsFollowingMode(false /* enabled */);
- lock_guard<mutex> lock(m_drapeSubroutesMutex);
if (deactivateFollowing)
{
// Remove all subroutes.
- m_drapeEngine->RemoveSubroute(dp::DrapeID(), true /* deactivateFollowing */);
+ m_drapeEngine.SafeCall(&df::DrapeEngine::RemoveSubroute,
+ dp::DrapeID(), true /* deactivateFollowing */);
}
else
{
- for (auto const & subrouteId : m_drapeSubroutes)
- m_drapeEngine->RemoveSubroute(subrouteId, false /* deactivateFollowing */);
+ auto const subroutes = GetSubrouteIds();
+ df::DrapeEngineLockGuard lock(m_drapeEngine);
+ if (lock)
+ {
+ for (auto const & subrouteId : subroutes)
+ lock.Get()->RemoveSubroute(subrouteId, false /* deactivateFollowing */);
+ }
+ }
+
+ {
+ lock_guard<mutex> lock(m_drapeSubroutesMutex);
+ m_drapeSubroutes.clear();
}
- m_drapeSubroutes.clear();
}
void RoutingManager::InsertRoute(Route const & route)
{
- if (m_drapeEngine == nullptr)
+ if (!m_drapeEngine)
return;
// TODO: Now we always update whole route, so we need to remove previous one.
RemoveRoute(false /* deactivateFollowing */);
- lock_guard<mutex> lock(m_drapeSubroutesMutex);
vector<RouteSegment> segments;
vector<m2::PointD> points;
double distance = 0.0;
@@ -487,18 +488,19 @@ void RoutingManager::InsertRoute(Route const & route)
default: ASSERT(false, ("Unknown router type"));
}
- auto const subrouteId = m_drapeEngine->AddSubroute(df::SubrouteConstPtr(subroute.release()));
- m_drapeSubroutes.push_back(subrouteId);
+ auto const subrouteId = m_drapeEngine.SafeCallWithResult(&df::DrapeEngine::AddSubroute,
+ df::SubrouteConstPtr(subroute.release()));
// TODO: we will send subrouteId to routing subsystem when we can partly update route.
//route.SetSubrouteUid(subrouteIndex, static_cast<SubrouteUid>(subrouteId));
+
+ lock_guard<mutex> lock(m_drapeSubroutesMutex);
+ m_drapeSubroutes.push_back(subrouteId);
}
}
void RoutingManager::FollowRoute()
{
- ASSERT(m_drapeEngine != nullptr, ());
-
if (!m_routingSession.EnableFollowMode())
return;
@@ -721,7 +723,6 @@ void RoutingManager::GenerateTurnNotifications(vector<string> & turnNotification
void RoutingManager::BuildRoute(uint32_t timeoutSec)
{
ASSERT_THREAD_CHECKER(m_threadChecker, ("BuildRoute"));
- ASSERT(m_drapeEngine != nullptr, ());
auto routePoints = GetRoutePoints();
if (routePoints.size() < 2)
@@ -790,13 +791,10 @@ void RoutingManager::BuildRoute(uint32_t timeoutSec)
CloseRouting(false /* remove route points */);
// Show preview.
- if (m_drapeEngine != nullptr)
- {
- m2::RectD rect = ShowPreviewSegments(routePoints);
- rect.Scale(kRouteScaleMultiplier);
- m_drapeEngine->SetModelViewRect(rect, true /* applyRotation */, -1 /* zoom */,
- true /* isAnim */);
- }
+ m2::RectD rect = ShowPreviewSegments(routePoints);
+ rect.Scale(kRouteScaleMultiplier);
+ m_drapeEngine.SafeCall(&df::DrapeEngine::SetModelViewRect, rect, true /* applyRotation */,
+ -1 /* zoom */, true /* isAnim */);
m_routingSession.SetUserCurrentPosition(routePoints.front().m_position);
@@ -830,8 +828,8 @@ void RoutingManager::SetUserCurrentPosition(m2::PointD const & position)
bool RoutingManager::DisableFollowMode()
{
bool const disabled = m_routingSession.DisableFollowMode();
- if (disabled && m_drapeEngine != nullptr)
- m_drapeEngine->DeactivateRouteFollowing();
+ if (disabled)
+ m_drapeEngine.SafeCall(&df::DrapeEngine::DeactivateRouteFollowing);
return disabled;
}
@@ -872,13 +870,12 @@ void RoutingManager::MatchLocationToRoute(location::GpsInfo & location,
void RoutingManager::OnLocationUpdate(location::GpsInfo & info)
{
- if (m_drapeEngine == nullptr)
+ if (!m_drapeEngine)
m_gpsInfoCache = my::make_unique<location::GpsInfo>(info);
auto routeMatchingInfo = GetRouteMatchingInfo(info);
-
- if (m_drapeEngine != nullptr)
- m_drapeEngine->SetGpsInfo(info, m_routingSession.IsNavigable(), routeMatchingInfo);
+ m_drapeEngine.SafeCall(&df::DrapeEngine::SetGpsInfo, info,
+ m_routingSession.IsNavigable(), routeMatchingInfo);
if (IsTrackingReporterEnabled())
m_trackingReporter.AddLocation(info, m_routingSession.MatchTraffic(routeMatchingInfo));
@@ -894,13 +891,16 @@ location::RouteMatchingInfo RoutingManager::GetRouteMatchingInfo(location::GpsIn
void RoutingManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine, bool is3dAllowed)
{
- m_drapeEngine = engine;
+ m_drapeEngine.Set(engine);
+ if (engine == nullptr)
+ return;
// Apply gps info which was set before drape engine creation.
if (m_gpsInfoCache != nullptr)
{
auto routeMatchingInfo = GetRouteMatchingInfo(*m_gpsInfoCache);
- m_drapeEngine->SetGpsInfo(*m_gpsInfoCache, m_routingSession.IsNavigable(), routeMatchingInfo);
+ m_drapeEngine.SafeCall(&df::DrapeEngine::SetGpsInfo, *m_gpsInfoCache,
+ m_routingSession.IsNavigable(), routeMatchingInfo);
m_gpsInfoCache.reset();
}
@@ -909,7 +909,7 @@ void RoutingManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine, bool is3dAl
{
InsertRoute(*m_routingSession.GetRoute());
if (is3dAllowed && m_routingSession.IsFollowing())
- m_drapeEngine->EnablePerspective();
+ m_drapeEngine.SafeCall(&df::DrapeEngine::EnablePerspective);
}
}
@@ -1134,32 +1134,21 @@ void RoutingManager::DeleteSavedRoutePoints()
void RoutingManager::UpdatePreviewMode()
{
- // Hide all subroutes.
- {
- lock_guard<mutex> lock(m_drapeSubroutesMutex);
- for (auto const & subrouteId : m_drapeSubroutes)
- m_drapeEngine->SetSubrouteVisibility(subrouteId, false /* isVisible */);
- }
-
+ SetSubroutesVisibility(false /* visible */);
HidePreviewSegments();
ShowPreviewSegments(GetRoutePoints());
}
void RoutingManager::CancelPreviewMode()
{
- // Show all subroutes.
- {
- lock_guard<mutex> lock(m_drapeSubroutesMutex);
- for (auto const & subrouteId : m_drapeSubroutes)
- m_drapeEngine->SetSubrouteVisibility(subrouteId, true /* isVisible */);
- }
-
+ SetSubroutesVisibility(true /* visible */);
HidePreviewSegments();
}
m2::RectD RoutingManager::ShowPreviewSegments(vector<RouteMarkData> const & routePoints)
{
- if (m_drapeEngine == nullptr)
+ df::DrapeEngineLockGuard lock(m_drapeEngine);
+ if (!lock)
return MercatorBounds::FullRect();
m2::RectD rect;
@@ -1167,16 +1156,15 @@ m2::RectD RoutingManager::ShowPreviewSegments(vector<RouteMarkData> const & rout
{
rect.Add(routePoints[pointIndex].m_position);
rect.Add(routePoints[pointIndex + 1].m_position);
- m_drapeEngine->AddRoutePreviewSegment(routePoints[pointIndex].m_position,
- routePoints[pointIndex + 1].m_position);
+ lock.Get()->AddRoutePreviewSegment(routePoints[pointIndex].m_position,
+ routePoints[pointIndex + 1].m_position);
}
return rect;
}
void RoutingManager::HidePreviewSegments()
{
- if (m_drapeEngine != nullptr)
- m_drapeEngine->RemoveAllRoutePreviewSegments();
+ m_drapeEngine.SafeCall(&df::DrapeEngine::RemoveAllRoutePreviewSegments);
}
void RoutingManager::CancelRecommendation(Recommendation recommendation)
@@ -1184,3 +1172,21 @@ void RoutingManager::CancelRecommendation(Recommendation recommendation)
if (recommendation == Recommendation::RebuildAfterPointsLoading)
m_loadRoutePointsTimestamp = chrono::steady_clock::time_point();
}
+
+std::vector<dp::DrapeID> RoutingManager::GetSubrouteIds() const
+{
+ lock_guard<mutex> lock(m_drapeSubroutesMutex);
+ return m_drapeSubroutes;
+}
+
+void RoutingManager::SetSubroutesVisibility(bool visible)
+{
+ auto const subroutes = GetSubrouteIds();
+
+ df::DrapeEngineLockGuard lock(m_drapeEngine);
+ if (!lock)
+ return;
+
+ for (auto const & subrouteId : subroutes)
+ lock.Get()->SetSubrouteVisibility(subrouteId, visible);
+}
diff --git a/map/routing_manager.hpp b/map/routing_manager.hpp
index 2a1a171fd4..9b7bf3e21b 100644
--- a/map/routing_manager.hpp
+++ b/map/routing_manager.hpp
@@ -8,6 +8,8 @@
#include "storage/index.hpp"
+#include "drape_frontend/drape_engine_safe_ptr.hpp"
+
#include "drape/pointers.hpp"
#include "tracking/reporter.hpp"
@@ -25,11 +27,6 @@
#include <utility>
#include <vector>
-namespace df
-{
-class DrapeEngine;
-}
-
namespace storage
{
class CountryInfoGetter;
@@ -272,12 +269,15 @@ private:
m2::RectD ShowPreviewSegments(std::vector<RouteMarkData> const & routePoints);
void HidePreviewSegments();
+ std::vector<dp::DrapeID> GetSubrouteIds() const;
+ void SetSubroutesVisibility(bool visible);
+
void CancelRecommendation(Recommendation recommendation);
RouteBuildingCallback m_routingCallback = nullptr;
RouteRecommendCallback m_routeRecommendCallback = nullptr;
Callbacks m_callbacks;
- ref_ptr<df::DrapeEngine> m_drapeEngine = nullptr;
+ df::DrapeEngineSafePtr m_drapeEngine;
routing::RouterType m_currentRouterType = routing::RouterType::Count;
routing::RoutingSession m_routingSession;
Delegate & m_delegate;
@@ -285,7 +285,7 @@ private:
BookmarkManager * m_bmManager = nullptr;
std::vector<dp::DrapeID> m_drapeSubroutes;
- std::mutex m_drapeSubroutesMutex;
+ mutable std::mutex m_drapeSubroutesMutex;
std::unique_ptr<location::GpsInfo> m_gpsInfoCache;
diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp
index 772885cff8..7a67d36b88 100644
--- a/map/traffic_manager.cpp
+++ b/map/traffic_manager.cpp
@@ -102,11 +102,7 @@ void TrafficManager::SetEnabled(bool enabled)
ChangeState(enabled ? TrafficState::Enabled : TrafficState::Disabled);
}
- {
- lock_guard<mutex> lock(m_drapeEngineMutex);
- if (m_drapeEngine != nullptr)
- m_drapeEngine->EnableTraffic(enabled);
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::EnableTraffic, enabled);
if (enabled)
{
@@ -136,8 +132,7 @@ void TrafficManager::Clear()
void TrafficManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
{
- lock_guard<mutex> lock(m_drapeEngineMutex);
- m_drapeEngine = engine;
+ m_drapeEngine.Set(engine);
}
void TrafficManager::SetCurrentDataVersion(int64_t dataVersion)
@@ -396,10 +391,8 @@ void TrafficManager::OnTrafficDataResponse(traffic::TrafficInfo && info)
if (!info.GetColoring().empty())
{
- {
- lock_guard<mutex> lock(m_drapeEngineMutex);
- m_drapeEngine->UpdateTraffic(info);
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::UpdateTraffic,
+ static_cast<traffic::TrafficInfo const &>(info));
// Update traffic colors for routing.
m_observer.OnTrafficInfoAdded(move(info));
@@ -445,10 +438,7 @@ void TrafficManager::ClearCache(MwmSet::MwmId const & mwmId)
ASSERT_GREATER_OR_EQUAL(m_currentCacheSizeBytes, it->second.m_dataSize, ());
m_currentCacheSizeBytes -= it->second.m_dataSize;
- {
- lock_guard<mutex> lock(m_drapeEngineMutex);
- m_drapeEngine->ClearTrafficCache(mwmId);
- }
+ m_drapeEngine.SafeCall(&df::DrapeEngine::ClearTrafficCache, mwmId);
GetPlatform().RunOnGuiThread([this, mwmId]()
{
@@ -570,9 +560,7 @@ void TrafficManager::Resume()
void TrafficManager::SetSimplifiedColorScheme(bool simplified)
{
- lock_guard<mutex> lock(m_drapeEngineMutex);
- if (m_drapeEngine != nullptr)
- m_drapeEngine->SetSimplifiedTrafficColors(simplified);
+ m_drapeEngine.SafeCall(&df::DrapeEngine::SetSimplifiedTrafficColors, simplified);
}
string DebugPrint(TrafficManager::TrafficState state)
diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp
index 8b0c5abea2..47eb5ba91a 100644
--- a/map/traffic_manager.hpp
+++ b/map/traffic_manager.hpp
@@ -2,6 +2,7 @@
#include "traffic/traffic_info.hpp"
+#include "drape_frontend/drape_engine_safe_ptr.hpp"
#include "drape_frontend/traffic_generator.hpp"
#include "drape/pointers.hpp"
@@ -24,11 +25,6 @@
#include "std/string.hpp"
#include "std/vector.hpp"
-namespace df
-{
-class DrapeEngine;
-} // namespace df
-
class TrafficManager final
{
public:
@@ -149,8 +145,7 @@ private:
GetMwmsByRectFn m_getMwmsByRectFn;
traffic::TrafficObserver & m_observer;
- ref_ptr<df::DrapeEngine> m_drapeEngine;
- mutex m_drapeEngineMutex;
+ df::DrapeEngineSafePtr m_drapeEngine;
atomic<int64_t> m_currentDataVersion;
// These fields have a flag of their initialization.
diff --git a/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj b/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj
index b031b3558f..6ffea2b66a 100644
--- a/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj
+++ b/xcode/drape_frontend/drape_frontend.xcodeproj/project.pbxproj
@@ -44,6 +44,7 @@
453EEA6E1E3A28F400505E09 /* colored_symbol_shape.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 453EEA6C1E3A28F400505E09 /* colored_symbol_shape.hpp */; };
453FEDAC1F34C257005C1BB4 /* render_state.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 453FEDAA1F34C257005C1BB4 /* render_state.cpp */; };
453FEDAD1F34C257005C1BB4 /* render_state.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 453FEDAB1F34C257005C1BB4 /* render_state.hpp */; };
+ 454B9A3A1F4591AD003FAE7A /* drape_engine_safe_ptr.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 454B9A391F4591AC003FAE7A /* drape_engine_safe_ptr.hpp */; };
454C19BB1CCE3EC0002A2C86 /* animation_constants.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 454C19B81CCE3EC0002A2C86 /* animation_constants.hpp */; };
454C19BC1CCE3EC0002A2C86 /* animation_system.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 454C19B91CCE3EC0002A2C86 /* animation_system.cpp */; };
454C19BD1CCE3EC0002A2C86 /* animation_system.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 454C19BA1CCE3EC0002A2C86 /* animation_system.hpp */; };
@@ -243,6 +244,7 @@
453EEA6C1E3A28F400505E09 /* colored_symbol_shape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = colored_symbol_shape.hpp; sourceTree = "<group>"; };
453FEDAA1F34C257005C1BB4 /* render_state.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = render_state.cpp; sourceTree = "<group>"; };
453FEDAB1F34C257005C1BB4 /* render_state.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = render_state.hpp; sourceTree = "<group>"; };
+ 454B9A391F4591AC003FAE7A /* drape_engine_safe_ptr.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = drape_engine_safe_ptr.hpp; sourceTree = "<group>"; };
454C19B81CCE3EC0002A2C86 /* animation_constants.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = animation_constants.hpp; sourceTree = "<group>"; };
454C19B91CCE3EC0002A2C86 /* animation_system.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = animation_system.cpp; sourceTree = "<group>"; };
454C19BA1CCE3EC0002A2C86 /* animation_system.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = animation_system.hpp; sourceTree = "<group>"; };
@@ -569,6 +571,7 @@
670947411BDF9B99005014C0 /* drape_frontend */ = {
isa = PBXGroup;
children = (
+ 454B9A391F4591AC003FAE7A /* drape_engine_safe_ptr.hpp */,
453FEDAA1F34C257005C1BB4 /* render_state.cpp */,
453FEDAB1F34C257005C1BB4 /* render_state.hpp */,
EB2B78011EEDD439002697B6 /* read_metaline_task.cpp */,
@@ -823,6 +826,7 @@
F6B283101C1B04680081957A /* gps_track_point.hpp in Headers */,
670947B61BDF9BE1005014C0 /* render_node.hpp in Headers */,
6709484C1BDF9C48005014C0 /* ruler.hpp in Headers */,
+ 454B9A3A1F4591AD003FAE7A /* drape_engine_safe_ptr.hpp in Headers */,
670947AE1BDF9BE1005014C0 /* poi_symbol_shape.hpp in Headers */,
670947AA1BDF9BE1005014C0 /* path_symbol_shape.hpp in Headers */,
6709483E1BDF9C48005014C0 /* copyright_label.hpp in Headers */,