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
path: root/map
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2013-01-03 18:43:36 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:48:18 +0300
commit29d56aa987f553be32124b3f97dc04cce86626d1 (patch)
tree549551f832b292c7c587121b178c59d3de666201 /map
parent182f784678230bbd3238ed4d7d4e19ad9623ed6c (diff)
fixed race conditions on current graphics::Overlay object.
Diffstat (limited to 'map')
-rw-r--r--map/basic_tiling_render_policy.cpp17
-rw-r--r--map/basic_tiling_render_policy.hpp4
-rw-r--r--map/framework.cpp17
-rw-r--r--map/render_policy.cpp14
-rw-r--r--map/render_policy.hpp18
5 files changed, 55 insertions, 15 deletions
diff --git a/map/basic_tiling_render_policy.cpp b/map/basic_tiling_render_policy.cpp
index f3c448089a..f8a8a23cb2 100644
--- a/map/basic_tiling_render_policy.cpp
+++ b/map/basic_tiling_render_policy.cpp
@@ -118,8 +118,6 @@ void BasicTilingRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e, Screen
if (curCvg)
{
- SetOverlay(curCvg->GetOverlay());
-
curCvg->Draw(pDrawer->screen().get(), s);
m_DrawScale = curCvg->GetDrawScale();
@@ -255,6 +253,21 @@ size_t BasicTilingRenderPolicy::TileSize() const
return m_TileSize;
}
+void BasicTilingRenderPolicy::FrameLock()
+{
+ m_CoverageGenerator->Mutex().Lock();
+}
+
+void BasicTilingRenderPolicy::FrameUnlock()
+{
+ m_CoverageGenerator->Mutex().Unlock();
+}
+
+shared_ptr<graphics::Overlay> const BasicTilingRenderPolicy::FrameOverlay() const
+{
+ return m_CoverageGenerator->CurrentCoverage()->GetOverlay();
+}
+
int BasicTilingRenderPolicy::InsertBenchmarkFence()
{
return m_CoverageGenerator->InsertBenchmarkFence();
diff --git a/map/basic_tiling_render_policy.hpp b/map/basic_tiling_render_policy.hpp
index c447a71630..dd0f35be71 100644
--- a/map/basic_tiling_render_policy.hpp
+++ b/map/basic_tiling_render_policy.hpp
@@ -79,6 +79,10 @@ public:
size_t ScaleEtalonSize() const;
size_t TileSize() const;
+ void FrameLock();
+ void FrameUnlock();
+ shared_ptr<graphics::Overlay> const FrameOverlay() const;
+
/// benchmarking protocol
int InsertBenchmarkFence();
void JoinBenchmarkFence(int fenceID);
diff --git a/map/framework.cpp b/map/framework.cpp
index 570a451e6d..c7f78596bf 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -1411,6 +1411,8 @@ shared_ptr<graphics::OverlayElement> const GetClosestToPivot(list<shared_ptr<gra
bool Framework::GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot, AddressInfo & info) const
{
+ m_renderPolicy->FrameLock();
+
m2::PointD const pt = m_navigator.ShiftPoint(pxPoint);
double const halfSize = TOUCH_PIXEL_RADIUS * GetVisualScale();
@@ -1419,12 +1421,14 @@ bool Framework::GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot,
list<shared_ptr<ElementT> > candidates;
m2::RectD rect(pt.x - halfSize, pt.y - halfSize,
pt.x + halfSize, pt.y + halfSize);
- m_renderPolicy->GetOverlay()->selectOverlayElements(rect, candidates);
+ m_renderPolicy->FrameOverlay()->selectOverlayElements(rect, candidates);
+
+ bool res = false;
- shared_ptr<ElementT> res = GetClosestToPivot(candidates, pt);
- if (res)
+ shared_ptr<ElementT> elem = GetClosestToPivot(candidates, pt);
+ if (elem)
{
- ElementT::UserInfo const & ui = res->userInfo();
+ ElementT::UserInfo const & ui = elem->userInfo();
if (ui.IsValid())
{
Index::FeaturesLoaderGuard guard(m_model.GetIndex(), ui.m_mwmID);
@@ -1439,11 +1443,12 @@ bool Framework::GetVisiblePOI(m2::PointD const & pxPoint, m2::PointD & pxPivot,
GetAddressInfo(ft, center, info);
pxPivot = GtoP(center);
- return true;
+ res = true;
}
}
- return false;
+ m_renderPolicy->FrameUnlock();
+ return res;
}
Animator & Framework::GetAnimator()
diff --git a/map/render_policy.cpp b/map/render_policy.cpp
index 0cae75de76..29133edf6d 100644
--- a/map/render_policy.cpp
+++ b/map/render_policy.cpp
@@ -239,14 +239,20 @@ void RenderPolicy::SetAnimController(anim::Controller * controller)
m_controller = controller;
}
-void RenderPolicy::SetOverlay(shared_ptr<graphics::Overlay> const & overlay)
+void RenderPolicy::FrameLock()
{
- m_overlay = overlay;
+ LOG(LWARNING, ("unimplemented method called."));
}
-shared_ptr<graphics::Overlay> const RenderPolicy::GetOverlay() const
+void RenderPolicy::FrameUnlock()
{
- return m_overlay;
+ LOG(LWARNING, ("unimplemented method called"));
+}
+
+shared_ptr<graphics::Overlay> const RenderPolicy::FrameOverlay() const
+{
+ LOG(LWARNING, ("unimplemented method called"));
+ return shared_ptr<graphics::Overlay>();
}
graphics::Color const RenderPolicy::GetBgColor() const
diff --git a/map/render_policy.hpp b/map/render_policy.hpp
index 8038794259..fc98db5ac7 100644
--- a/map/render_policy.hpp
+++ b/map/render_policy.hpp
@@ -71,8 +71,6 @@ protected:
anim::Controller * m_controller;
shared_ptr<graphics::Overlay> m_overlay;
- void SetOverlay(shared_ptr<graphics::Overlay> const & overlay);
-
void InitCacheScreen();
public:
@@ -149,11 +147,25 @@ public:
double VisualScale() const;
string const & SkinName() const;
+ /// This function is used when we need to prevent race
+ /// conditions on some resources, which could be modified
+ /// from another threads.
+ /// One example of such resource is a current graphics::Overlay
+ /// object
+ /// @{
+ virtual void FrameLock();
+ virtual void FrameUnlock();
+ /// @}
+
+ /// Get current graphics::Overlay object.
+ /// Access to this resource should be synchronized using
+ /// FrameLock/FrameUnlock methods
+ virtual shared_ptr<graphics::Overlay> const FrameOverlay() const;
+
/// Benchmarking protocol
virtual int InsertBenchmarkFence();
virtual void JoinBenchmarkFence(int fenceID);
- virtual shared_ptr<graphics::Overlay> const GetOverlay() const;
graphics::Color const GetBgColor() const;
shared_ptr<graphics::Screen> const & GetCacheScreen() const;