forked from organicmaps/organicmaps
enterBackground/enterForeground/memoryWarning infrastructure.
This commit is contained in:
parent
9708733e91
commit
2c6b2bcc36
12 changed files with 132 additions and 6 deletions
|
@ -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<yg::ResourceManager> m_resourceManager;
|
||||
InformationDisplay m_informationDisplay;
|
||||
|
||||
/// is AddRedrawCommand enabled?
|
||||
|
@ -213,7 +215,8 @@ public:
|
|||
void initializeGL(shared_ptr<yg::gl::RenderContext> const & primaryContext,
|
||||
shared_ptr<yg::ResourceManager> 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()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -444,3 +444,18 @@ void RenderQueueRoutine::initializeGL(shared_ptr<yg::gl::RenderContext> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -163,6 +163,10 @@ namespace yg
|
|||
float x0, float y0, float x1, float y1,
|
||||
double depth,
|
||||
int pageID);
|
||||
|
||||
void memoryWarning();
|
||||
void enterBackground();
|
||||
void enterForeground();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace yg
|
|||
m_doPeriodicalUpdate(params.m_doPeriodicalUpdate),
|
||||
m_updateInterval(params.m_updateInterval)
|
||||
{
|
||||
LOG(LINFO, ("UpdateInterval: ", m_updateInterval));
|
||||
}
|
||||
|
||||
shared_ptr<RenderState> const & RenderStateUpdater::renderState() const
|
||||
|
|
|
@ -175,4 +175,17 @@ namespace yg
|
|||
{
|
||||
m_glyphCache.addFonts(fontNames);
|
||||
}
|
||||
|
||||
void ResourceManager::memoryWarning()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceManager::enterBackground()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceManager::enterForeground()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,6 +69,10 @@ namespace yg
|
|||
GlyphMetrics const getGlyphMetrics(GlyphKey const & key);
|
||||
|
||||
void addFonts(vector<string> const & fontNames);
|
||||
|
||||
void memoryWarning();
|
||||
void enterBackground();
|
||||
void enterForeground();
|
||||
};
|
||||
|
||||
Skin * loadSkin(shared_ptr<ResourceManager> const & resourceManager,
|
||||
|
|
18
yg/skin.cpp
18
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,5 +140,9 @@ namespace yg
|
|||
|
||||
uint32_t invalidHandle() const;
|
||||
uint32_t invalidPageHandle() const;
|
||||
|
||||
void memoryWarning();
|
||||
void enterBackground();
|
||||
void enterForeground();
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue