#pragma once #include "drape_frontend/message_acceptor.hpp" #include "drape_frontend/threads_commutator.hpp" #include "drape_frontend/tile_utils.hpp" #include "drape/oglcontextfactory.hpp" #include "drape/texture_manager.hpp" #include "base/thread.hpp" #include "std/atomic.hpp" #include "std/condition_variable.hpp" #include "std/function.hpp" #include "std/mutex.hpp" namespace df { class BaseRenderer : public MessageAcceptor { public: struct Params { Params(ref_ptr commutator, ref_ptr factory, ref_ptr texMng) : m_commutator(commutator) , m_oglContextFactory(factory) , m_texMng(texMng) { } ref_ptr m_commutator; ref_ptr m_oglContextFactory; ref_ptr m_texMng; }; BaseRenderer(ThreadsCommutator::ThreadName name, Params const & params); bool CanReceiveMessages(); void SetRenderingEnabled(ref_ptr contextFactory); void SetRenderingDisabled(bool const destroyContext); bool IsRenderingEnabled() const; protected: ref_ptr m_commutator; ref_ptr m_contextFactory; ref_ptr m_texMng; void StartThread(); void StopThread(); void CheckRenderingEnabled(); virtual unique_ptr CreateRoutine() = 0; virtual void OnContextCreate() = 0; virtual void OnContextDestroy() = 0; private: using TCompletionHandler = function; threads::Thread m_selfThread; ThreadsCommutator::ThreadName m_threadName; mutex m_renderingEnablingMutex; condition_variable m_renderingEnablingCondition; atomic m_isEnabled; TCompletionHandler m_renderingEnablingCompletionHandler; bool m_wasNotified; atomic m_wasContextReset; bool FilterGLContextDependentMessage(ref_ptr msg); void SetRenderingEnabled(bool const isEnabled); void Notify(); void WakeUp(); }; } // namespace df