diff --git a/map/framework.hpp b/map/framework.hpp index af64047ab4..7d26f1350e 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -19,6 +19,7 @@ #include "../yg/color.hpp" #include "../yg/render_state.hpp" #include "../yg/skin.hpp" +#include "../yg/resource_manager.hpp" #include "../coding/file_reader.hpp" #include "../coding/file_writer.hpp" @@ -104,6 +105,7 @@ class FrameWork unsigned m_currentBenchmark; RenderQueue m_renderQueue; + shared_ptr m_resourceManager; InformationDisplay m_informationDisplay; /// is AddRedrawCommand enabled? @@ -213,7 +215,8 @@ public: void initializeGL(shared_ptr const & primaryContext, shared_ptr const & resourceManager) { - m_renderQueue.initializeGL(primaryContext, resourceManager, GetPlatform().VisualScale()); + m_resourceManager = resourceManager; + m_renderQueue.initializeGL(primaryContext, m_resourceManager, GetPlatform().VisualScale()); } model_t & get_model() { return m_model; } @@ -446,6 +449,35 @@ public: void MemoryWarning() { m_informationDisplay.memoryWarning(); + m_renderQueue.memoryWarning(); + + if (m_windowHandle) + m_windowHandle->drawer()->screen()->memoryWarning(); + + if (m_resourceManager) + m_resourceManager->memoryWarning(); + } + + void EnterBackground() + { + m_renderQueue.enterBackground(); + + if (m_windowHandle) + m_windowHandle->drawer()->screen()->enterBackground(); + + if (m_resourceManager) + m_resourceManager->enterBackground(); + } + + void EnterForeground() + { + if (m_resourceManager) + m_resourceManager->enterForeground(); + + if (m_windowHandle) + m_windowHandle->drawer()->screen()->enterForeground(); + + m_renderQueue.enterForeground(); } void CenterViewport() diff --git a/map/render_queue.cpp b/map/render_queue.cpp index 48ca6ded98..cbf5bb3bc1 100644 --- a/map/render_queue.cpp +++ b/map/render_queue.cpp @@ -81,6 +81,19 @@ yg::gl::RenderState const & RenderQueue::renderState() const return *m_renderState.get(); } - +void RenderQueue::memoryWarning() +{ + m_routine->memoryWarning(); +} + +void RenderQueue::enterBackground() +{ + m_routine->enterBackground(); +} + +void RenderQueue::enterForeground() +{ + m_routine->enterForeground(); +} diff --git a/map/render_queue.hpp b/map/render_queue.hpp index f409c4bbb1..8a4dcbf83b 100644 --- a/map/render_queue.hpp +++ b/map/render_queue.hpp @@ -58,4 +58,12 @@ public: yg::gl::RenderState const CopyState() const; yg::gl::RenderState const & renderState() const; + + /// free all possible memory caches + void memoryWarning(); + /// free all possible memory caches, opengl resources, + /// and make sure no opengl call will be made in background + void enterBackground(); + /// load all necessary memory caches and opengl resources. + void enterForeground(); }; diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index ca28218883..00e8a66d2a 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -444,3 +444,18 @@ void RenderQueueRoutine::initializeGL(shared_ptr const & m_threadRenderer.init(renderContext->createShared(), m_renderState); } +void RenderQueueRoutine::memoryWarning() +{ + m_threadDrawer->screen()->memoryWarning(); +} + +void RenderQueueRoutine::enterBackground() +{ + m_threadDrawer->screen()->enterBackground(); +} + +void RenderQueueRoutine::enterForeground() +{ + m_threadDrawer->screen()->enterForeground(); +} + diff --git a/map/render_queue_routine.hpp b/map/render_queue_routine.hpp index f46445213f..d44a710322 100644 --- a/map/render_queue_routine.hpp +++ b/map/render_queue_routine.hpp @@ -112,4 +112,10 @@ public: void addBenchmarkCommand(render_fn_t const & fn, ScreenBase const & frameScreen); /// set the resolution scale factor to the main thread drawer; void setVisualScale(double visualScale); + /// free all available memory + void memoryWarning(); + /// free all easily recreatable opengl resources and make sure that no opengl call will be made. + void enterBackground(); + /// recreate all necessary opengl resources and prepare to run in foreground. + void enterForeground(); }; diff --git a/yg/geometry_batcher.cpp b/yg/geometry_batcher.cpp index 4b6f288a37..648fb69a6f 100644 --- a/yg/geometry_batcher.cpp +++ b/yg/geometry_batcher.cpp @@ -412,6 +412,22 @@ namespace yg return m_aaShift; } + void GeometryBatcher::memoryWarning() + { + if (m_skin) + m_skin->memoryWarning(); + } + void GeometryBatcher::enterBackground() + { + if (m_skin) + m_skin->enterBackground(); + } + + void GeometryBatcher::enterForeground() + { + if (m_skin) + m_skin->enterForeground(); + } } // namespace gl } // namespace yg diff --git a/yg/geometry_batcher.hpp b/yg/geometry_batcher.hpp index 0fc638964d..3edfca75b2 100644 --- a/yg/geometry_batcher.hpp +++ b/yg/geometry_batcher.hpp @@ -163,6 +163,10 @@ namespace yg float x0, float y0, float x1, float y1, double depth, int pageID); + + void memoryWarning(); + void enterBackground(); + void enterForeground(); }; } } diff --git a/yg/render_state_updater.cpp b/yg/render_state_updater.cpp index 880a8104b7..4411fd5f44 100644 --- a/yg/render_state_updater.cpp +++ b/yg/render_state_updater.cpp @@ -20,7 +20,6 @@ namespace yg m_doPeriodicalUpdate(params.m_doPeriodicalUpdate), m_updateInterval(params.m_updateInterval) { - LOG(LINFO, ("UpdateInterval: ", m_updateInterval)); } shared_ptr const & RenderStateUpdater::renderState() const diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index 85df6bd705..0a259fbe99 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -175,4 +175,17 @@ namespace yg { m_glyphCache.addFonts(fontNames); } + + void ResourceManager::memoryWarning() + { + } + + void ResourceManager::enterBackground() + { + } + + void ResourceManager::enterForeground() + { + } + } diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index 7dda79d723..e8ec3499fa 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -69,6 +69,10 @@ namespace yg GlyphMetrics const getGlyphMetrics(GlyphKey const & key); void addFonts(vector const & fontNames); + + void memoryWarning(); + void enterBackground(); + void enterForeground(); }; Skin * loadSkin(shared_ptr const & resourceManager, diff --git a/yg/skin.cpp b/yg/skin.cpp index 5c306caec9..077b12cecc 100644 --- a/yg/skin.cpp +++ b/yg/skin.cpp @@ -241,9 +241,9 @@ namespace yg m_pages[pageID]->clearHandles(); } - /// Called from the skin page on handles overflow. - /// Never called on texture overflow, as this situation - /// are explicitly checked in the mapXXX() functions. + /// This function is set to perform as a callback on texture or handles overflow + /// BUT! Never called on texture overflow, as this situation + /// is explicitly checked in the mapXXX() functions. void Skin::onDynamicOverflow(uint8_t pageID) { LOG(LINFO, ("DynamicPage switching, pageID=", (uint32_t)pageID)); @@ -296,4 +296,16 @@ namespace yg { return 0x00FFFFFF; } + + void Skin::memoryWarning() + { + } + + void Skin::enterBackground() + { + } + + void Skin::enterForeground() + { + } } diff --git a/yg/skin.hpp b/yg/skin.hpp index 4888c5d02c..09c76c567a 100644 --- a/yg/skin.hpp +++ b/yg/skin.hpp @@ -140,5 +140,9 @@ namespace yg uint32_t invalidHandle() const; uint32_t invalidPageHandle() const; + + void memoryWarning(); + void enterBackground(); + void enterForeground(); }; }