diff --git a/drape/oglcontextfactory.cpp b/drape/oglcontextfactory.cpp index 4408c4e01b..4d2d17d0b9 100644 --- a/drape/oglcontextfactory.cpp +++ b/drape/oglcontextfactory.cpp @@ -41,4 +41,9 @@ OGLContext * ThreadSafeFactory::CreateContext(TCreateCtxFn const & createFn, TIs return ctx; } +void ThreadSafeFactory::waitForInitialization() +{ + m_factory->waitForInitialization(); +} + } // namespace dp diff --git a/drape/oglcontextfactory.hpp b/drape/oglcontextfactory.hpp index c015781843..f3cb2fe366 100644 --- a/drape/oglcontextfactory.hpp +++ b/drape/oglcontextfactory.hpp @@ -18,6 +18,7 @@ public: virtual OGLContext * getResourcesUploadContext() = 0; virtual bool isDrawContextCreated() const { return false; } virtual bool isUploadContextCreated() const { return false; } + virtual void waitForInitialization() {} }; class ThreadSafeFactory : public OGLContextFactory @@ -25,8 +26,8 @@ class ThreadSafeFactory : public OGLContextFactory public: ThreadSafeFactory(OGLContextFactory * factory, bool enableSharing = true); ~ThreadSafeFactory(); - virtual OGLContext * getDrawContext(); - virtual OGLContext * getResourcesUploadContext(); + OGLContext * getDrawContext() override; + OGLContext * getResourcesUploadContext() override; template T * CastFactory() @@ -35,6 +36,8 @@ public: return static_cast(m_factory); } + void waitForInitialization() override; + protected: typedef function TCreateCtxFn; typedef function TIsSeparateCreatedFn; diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index ccc0dff5a4..170452642c 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -255,11 +255,6 @@ void BackendRenderer::AcceptMessage(ref_ptr message) MessagePriority::Normal); break; } - case Message::StopRendering: - { - ProcessStopRenderingMessage(); - break; - } case Message::Allow3dBuildings: { ref_ptr msg = message; @@ -288,6 +283,8 @@ BackendRenderer::Routine::Routine(BackendRenderer & renderer) : m_renderer(rende void BackendRenderer::Routine::Do() { + m_renderer.m_contextFactory->waitForInitialization(); + m_renderer.m_contextFactory->getResourcesUploadContext()->makeCurrent(); GLFunctions::Init(); diff --git a/drape_frontend/base_renderer.cpp b/drape_frontend/base_renderer.cpp index 1b363b43dc..8cc083b2ca 100644 --- a/drape_frontend/base_renderer.cpp +++ b/drape_frontend/base_renderer.cpp @@ -25,10 +25,9 @@ void BaseRenderer::StartThread() void BaseRenderer::StopThread() { - // send message to stop rendering in render thread - m_commutator->PostMessage(m_threadName, - make_unique_dp(), - MessagePriority::High); + // stop rendering and close queue + m_selfThread.GetRoutine()->Cancel(); + CloseQueue(); // wake up render thread if necessary if (!m_isEnabled) @@ -134,12 +133,6 @@ void BaseRenderer::WakeUp() m_renderingEnablingCondition.notify_one(); } -void BaseRenderer::ProcessStopRenderingMessage() -{ - m_selfThread.GetRoutine()->Cancel(); - CloseQueue(); -} - bool BaseRenderer::CanReceiveMessages() { threads::IRoutine * routine = m_selfThread.GetRoutine(); diff --git a/drape_frontend/base_renderer.hpp b/drape_frontend/base_renderer.hpp index 58afbdd0a8..14d4da18b4 100644 --- a/drape_frontend/base_renderer.hpp +++ b/drape_frontend/base_renderer.hpp @@ -52,7 +52,6 @@ protected: void StopThread(); void CheckRenderingEnabled(); - void ProcessStopRenderingMessage(); virtual unique_ptr CreateRoutine() = 0; diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 2d102ce52c..a6bfabb233 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -356,12 +356,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) break; } - case Message::StopRendering: - { - ProcessStopRenderingMessage(); - break; - } - case Message::MyPositionShape: { ref_ptr msg = message; @@ -1388,6 +1382,8 @@ FrontendRenderer::Routine::Routine(FrontendRenderer & renderer) : m_renderer(ren void FrontendRenderer::Routine::Do() { + m_renderer.m_contextFactory->waitForInitialization(); + gui::DrapeGui::Instance().ConnectOnCompassTappedHandler(bind(&FrontendRenderer::OnCompassTapped, &m_renderer)); m_renderer.m_myPositionController->SetListener(ref_ptr(&m_renderer)); m_renderer.m_userEventStream.SetListener(ref_ptr(&m_renderer)); diff --git a/drape_frontend/message.hpp b/drape_frontend/message.hpp index 388b7de068..33381d61df 100644 --- a/drape_frontend/message.hpp +++ b/drape_frontend/message.hpp @@ -27,7 +27,6 @@ public: GuiRecache, GuiLayerLayout, MyPositionShape, - StopRendering, ChangeMyPostitionMode, CompassInfo, GpsInfo, diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 42cf44d84a..cdd04dcc7c 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -366,13 +366,6 @@ private: drape_ptr m_selection; }; -class StopRenderingMessage : public Message -{ -public: - StopRenderingMessage(){} - Type GetType() const override { return Message::StopRendering; } -}; - class ChangeMyPositionModeMessage : public Message { public: diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index a3af7e0c93..01cd45add5 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -89,7 +89,7 @@ double getExactDPI(double contentScaleFactor) - (void)createDrapeEngineWithWidth:(int)width height:(int)height { - NSLog(@"EAGLView createDrapeEngine Started"); + LOG(LINFO, ("EAGLView createDrapeEngine Started")); if (MapsAppDelegate.theApp.isDaemonMode) return; @@ -103,7 +103,7 @@ double getExactDPI(double contentScaleFactor) _drapeEngineCreated = YES; - NSLog(@"EAGLView createDrapeEngine Ended"); + LOG(LINFO, ("EAGLView createDrapeEngine Ended")); } - (void)addSubview:(UIView *)view diff --git a/iphone/Maps/Platform/opengl/iosOGLContextFactory.h b/iphone/Maps/Platform/opengl/iosOGLContextFactory.h index bcec895726..ee997e07cf 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContextFactory.h +++ b/iphone/Maps/Platform/opengl/iosOGLContextFactory.h @@ -3,17 +3,22 @@ #import "iosOGLContext.h" #import "../../../../drape/oglcontextfactory.hpp" +#include "std/condition_variable.hpp" +#include "std/mutex.hpp" + class iosOGLContextFactory: public dp::OGLContextFactory { public: iosOGLContextFactory(CAEAGLLayer * layer); ~iosOGLContextFactory(); - virtual dp::OGLContext * getDrawContext(); - virtual dp::OGLContext * getResourcesUploadContext(); + dp::OGLContext * getDrawContext() override; + dp::OGLContext * getResourcesUploadContext() override; - virtual bool isDrawContextCreated() const; - virtual bool isUploadContextCreated() const; + bool isDrawContextCreated() const override; + bool isUploadContextCreated() const override; + + void waitForInitialization() override; void setPresentAvailable(bool available); @@ -21,4 +26,8 @@ private: CAEAGLLayer * m_layer; iosOGLContext * m_drawContext; iosOGLContext * m_uploadContext; -}; \ No newline at end of file + + bool m_isInitialized; + condition_variable m_initializationCondition; + mutex m_initializationMutex; +}; diff --git a/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm b/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm index 60751ff34c..b4f07887ae 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm +++ b/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm @@ -2,8 +2,9 @@ iosOGLContextFactory::iosOGLContextFactory(CAEAGLLayer * layer) : m_layer(layer) - , m_drawContext(NULL) - , m_uploadContext(NULL) + , m_drawContext(nullptr) + , m_uploadContext(nullptr) + , m_isInitialized(false) {} iosOGLContextFactory::~iosOGLContextFactory() @@ -14,14 +15,14 @@ iosOGLContextFactory::~iosOGLContextFactory() dp::OGLContext * iosOGLContextFactory::getDrawContext() { - if (m_drawContext == NULL) + if (m_drawContext == nullptr) m_drawContext = new iosOGLContext(m_layer, m_uploadContext, true); return m_drawContext; } dp::OGLContext * iosOGLContextFactory::getResourcesUploadContext() { - if (m_uploadContext == NULL) + if (m_uploadContext == nullptr) m_uploadContext = new iosOGLContext(m_layer, m_drawContext, false); return m_uploadContext; } @@ -38,6 +39,20 @@ bool iosOGLContextFactory::isUploadContextCreated() const void iosOGLContextFactory::setPresentAvailable(bool available) { + { + lock_guard lock(m_initializationMutex); + if (!m_isInitialized && available) + { + m_isInitialized = true; + m_initializationCondition.notify_one(); + } + } if (m_drawContext != nullptr) m_drawContext->setPresentAvailable(available); } + +void iosOGLContextFactory::waitForInitialization() +{ + unique_lock lock(m_initializationMutex); + m_initializationCondition.wait(lock, [this] { return m_isInitialized; }); +}