diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2019-05-14 16:39:11 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2019-05-17 18:45:59 +0300 |
commit | a3007501b4c097ae916932ee1b019a456695a48e (patch) | |
tree | 1b86c1912778b102d4fb1ab3022fdb128b90a5c9 /drape_frontend | |
parent | 4695b23cdbfd0fbae4b1d3f47bd4d3ff1ac390d1 (diff) |
[drape] Fixed rendering initialization notification
Diffstat (limited to 'drape_frontend')
-rw-r--r-- | drape_frontend/backend_renderer.cpp | 2 | ||||
-rw-r--r-- | drape_frontend/backend_renderer.hpp | 5 | ||||
-rw-r--r-- | drape_frontend/base_renderer.cpp | 18 | ||||
-rw-r--r-- | drape_frontend/base_renderer.hpp | 15 | ||||
-rw-r--r-- | drape_frontend/drape_engine.cpp | 6 | ||||
-rw-r--r-- | drape_frontend/drape_engine.hpp | 5 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.cpp | 2 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.hpp | 5 |
8 files changed, 45 insertions, 13 deletions
diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index f48ee3c9f1..11023365af 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -671,7 +671,7 @@ BackendRenderer::Routine::Routine(BackendRenderer & renderer) : m_renderer(rende void BackendRenderer::Routine::Do() { LOG(LINFO, ("Start routine.")); - m_renderer.OnContextCreate(); + m_renderer.CreateContext(); while (!IsCancelled()) { RENDER_FRAME(m_renderer.RenderFrame()); diff --git a/drape_frontend/backend_renderer.hpp b/drape_frontend/backend_renderer.hpp index e47755a641..44d3003488 100644 --- a/drape_frontend/backend_renderer.hpp +++ b/drape_frontend/backend_renderer.hpp @@ -44,8 +44,9 @@ public: ref_ptr<dp::GraphicsContextFactory> factory, ref_ptr<dp::TextureManager> texMng, MapDataProvider const & model, TUpdateCurrentCountryFn const & updateCurrentCountryFn, ref_ptr<RequestedTiles> requestedTiles, bool allow3dBuildings, bool trafficEnabled, - bool simplifiedTrafficColors, TIsUGCFn && isUGCFn) - : BaseRenderer::Params(apiVersion, commutator, factory, texMng) + bool simplifiedTrafficColors, TIsUGCFn && isUGCFn, + OnGraphicsContextInitialized const & onGraphicsContextInitialized) + : BaseRenderer::Params(apiVersion, commutator, factory, texMng, onGraphicsContextInitialized) , m_model(model) , m_updateCurrentCountryFn(updateCurrentCountryFn) , m_requestedTiles(requestedTiles) diff --git a/drape_frontend/base_renderer.cpp b/drape_frontend/base_renderer.cpp index 8889a2e895..f7a357ffc4 100644 --- a/drape_frontend/base_renderer.cpp +++ b/drape_frontend/base_renderer.cpp @@ -5,6 +5,9 @@ namespace df { +// static +std::atomic<uint8_t> BaseRenderer::m_contextCounter(0); + BaseRenderer::BaseRenderer(ThreadsCommutator::ThreadName name, Params const & params) : m_apiVersion(params.m_apiVersion) , m_commutator(params.m_commutator) @@ -15,6 +18,7 @@ BaseRenderer::BaseRenderer(ThreadsCommutator::ThreadName name, Params const & pa , m_renderingEnablingCompletionHandler(nullptr) , m_wasNotified(false) , m_wasContextReset(false) + , m_onGraphicsContextInitialized(params.m_onGraphicsContextInitialized) { m_commutator->RegisterThread(m_threadName, this); } @@ -103,6 +107,16 @@ bool BaseRenderer::FilterContextDependentMessage(ref_ptr<Message> msg) return msg->IsGraphicsContextDependent(); } +void BaseRenderer::CreateContext() +{ + OnContextCreate(); + + m_contextCounter++; + uint8_t constexpr kContextCount = 2; + if (m_contextCounter == kContextCount && m_onGraphicsContextInitialized) + m_onGraphicsContextInitialized(); +} + void BaseRenderer::CheckRenderingEnabled() { if (!m_isEnabled) @@ -114,6 +128,8 @@ void BaseRenderer::CheckRenderingEnabled() using namespace std::placeholders; EnableMessageFiltering(std::bind(&BaseRenderer::FilterContextDependentMessage, this, _1)); OnContextDestroy(); + CHECK(m_contextCounter > 0, ()); + m_contextCounter--; } else { @@ -161,7 +177,7 @@ void BaseRenderer::CheckRenderingEnabled() OnRenderingEnabled(); if (needCreateContext) - OnContextCreate(); + CreateContext(); } } diff --git a/drape_frontend/base_renderer.hpp b/drape_frontend/base_renderer.hpp index d426e6baf3..8cbf641dcb 100644 --- a/drape_frontend/base_renderer.hpp +++ b/drape_frontend/base_renderer.hpp @@ -27,24 +27,28 @@ extern void RenderFrameMediator(std::function<void()> && renderFrameFunction); namespace df { +using OnGraphicsContextInitialized = std::function<void()>; + class BaseRenderer : public MessageAcceptor { public: struct Params { Params(dp::ApiVersion apiVersion, ref_ptr<ThreadsCommutator> commutator, - ref_ptr<dp::GraphicsContextFactory> factory, ref_ptr<dp::TextureManager> texMng) + ref_ptr<dp::GraphicsContextFactory> factory, ref_ptr<dp::TextureManager> texMng, + OnGraphicsContextInitialized const & onGraphicsContextInitialized) : m_apiVersion(apiVersion) , m_commutator(commutator) , m_oglContextFactory(factory) , m_texMng(texMng) - { - } + , m_onGraphicsContextInitialized(onGraphicsContextInitialized) + {} dp::ApiVersion m_apiVersion; ref_ptr<ThreadsCommutator> m_commutator; ref_ptr<dp::GraphicsContextFactory> m_oglContextFactory; ref_ptr<dp::TextureManager> m_texMng; + OnGraphicsContextInitialized m_onGraphicsContextInitialized; }; BaseRenderer(ThreadsCommutator::ThreadName name, Params const & params); @@ -66,6 +70,8 @@ protected: void StartThread(); void StopThread(); + void CreateContext(); + void CheckRenderingEnabled(); virtual std::unique_ptr<threads::IRoutine> CreateRoutine() = 0; @@ -90,6 +96,9 @@ private: bool m_wasNotified; std::atomic<bool> m_wasContextReset; + OnGraphicsContextInitialized m_onGraphicsContextInitialized; + static std::atomic<uint8_t> m_contextCounter; + bool FilterContextDependentMessage(ref_ptr<Message> msg); void SetRenderingEnabled(bool const isEnabled); void Notify(); diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index d17a2e2b30..b3a50d9bcc 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -85,7 +85,8 @@ DrapeEngine::DrapeEngine(Params && params) params.m_allow3dBuildings, params.m_trafficEnabled, params.m_blockTapEvents, - std::move(effects)); + std::move(effects), + params.m_onGraphicsContextInitialized); m_frontend = make_unique_dp<FrontendRenderer>(std::move(frParams)); @@ -99,7 +100,8 @@ DrapeEngine::DrapeEngine(Params && params) params.m_allow3dBuildings, params.m_trafficEnabled, params.m_simplifiedTrafficColors, - std::move(params.m_isUGCFn)); + std::move(params.m_isUGCFn), + params.m_onGraphicsContextInitialized); m_backend = make_unique_dp<BackendRenderer>(std::move(brParams)); diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 08ffa9986a..380b3a9cb3 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -70,7 +70,8 @@ public: bool isAutozoomEnabled, bool simplifiedTrafficColors, OverlaysShowStatsCallback && overlaysShowStatsCallback, - TIsUGCFn && isUGCFn) + TIsUGCFn && isUGCFn, + OnGraphicsContextInitialized && onGraphicsContextInitialized) : m_apiVersion(apiVersion) , m_factory(factory) , m_viewport(viewport) @@ -91,6 +92,7 @@ public: , m_simplifiedTrafficColors(simplifiedTrafficColors) , m_overlaysShowStatsCallback(std::move(overlaysShowStatsCallback)) , m_isUGCFn(std::move(isUGCFn)) + , m_onGraphicsContextInitialized(std::move(onGraphicsContextInitialized)) {} dp::ApiVersion m_apiVersion; @@ -113,6 +115,7 @@ public: bool m_simplifiedTrafficColors; OverlaysShowStatsCallback m_overlaysShowStatsCallback; TIsUGCFn m_isUGCFn; + OnGraphicsContextInitialized m_onGraphicsContextInitialized; }; DrapeEngine(Params && params); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 078fa01c12..30eec74b99 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -2339,7 +2339,7 @@ void FrontendRenderer::Routine::Do() m_renderer.m_myPositionController->SetListener(ref_ptr<MyPositionController::Listener>(&m_renderer)); m_renderer.m_userEventStream.SetListener(ref_ptr<UserEventStream::Listener>(&m_renderer)); - m_renderer.OnContextCreate(); + m_renderer.CreateContext(); #if defined(DEBUG) || defined(DEBUG_DRAPE_XCODE) || defined(SCENARIO_ENABLE) gui::DrapeGui::Instance().GetScaleFpsHelper().SetVisible(true); diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index d08bbd305e..d2a2a31171 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -89,8 +89,9 @@ public: TUserPositionChangedFn const & positionChangedFn, ref_ptr<RequestedTiles> requestedTiles, OverlaysShowStatsCallback && overlaysShowStatsCallback, bool allow3dBuildings, bool trafficEnabled, bool blockTapEvents, - std::vector<PostprocessRenderer::Effect> && enabledEffects) - : BaseRenderer::Params(apiVersion, commutator, factory, texMng) + std::vector<PostprocessRenderer::Effect> && enabledEffects, + OnGraphicsContextInitialized const & onGraphicsContextInitialized) + : BaseRenderer::Params(apiVersion, commutator, factory, texMng, onGraphicsContextInitialized) , m_myPositionParams(std::move(myPositionParams)) , m_viewport(viewport) , m_modelViewChangedFn(modelViewChangedFn) |