lazy allocation of SkinPage::m_texture to improve resource usage.

This commit is contained in:
rachytski 2011-03-13 20:14:30 +02:00 committed by Alex Zolotarev
parent 2a08e0287a
commit c0edea9082
5 changed files with 65 additions and 11 deletions

View file

@ -240,7 +240,7 @@ namespace yg
void GeometryBatcher::switchTextures(int pageID)
{
m_skin->pages()[pageID]->freeTexture();
m_skin->pages()[pageID]->reserveTexture();
// m_skin->pages()[pageID]->reserveTexture();
}
void GeometryBatcher::drawTexturedPolygon(

View file

@ -21,7 +21,11 @@ namespace yg
size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount,
size_t texWidth, size_t texHeight, size_t texCount,
char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxGlyphCacheSize)
: m_glyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize))
: m_vbSize(vbSize), m_ibSize(ibSize),
m_smallVBSize(smallVBSize), m_smallIBSize(smallIBSize),
m_blitVBSize(blitVBSize), m_blitIBSize(blitIBSize),
m_textureWidth(texWidth), m_textureHeight(texHeight),
m_glyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize))
{
for (size_t i = 0; i < storagesCount; ++i)
m_storages.push_back(gl::Storage(vbSize, ibSize));
@ -147,6 +151,16 @@ namespace yg
return res;
}
size_t ResourceManager::textureWidth() const
{
return m_textureWidth;
}
size_t ResourceManager::textureHeight() const
{
return m_textureHeight;
}
void ResourceManager::freeTexture(shared_ptr<gl::BaseTexture> const & texture, bool doSignal)
{
threads::MutexGuard guard(m_mutex);

View file

@ -34,6 +34,18 @@ namespace yg
list<shared_ptr<gl::BaseTexture> > m_dynamicTextures;
size_t m_vbSize;
size_t m_ibSize;
size_t m_smallVBSize;
size_t m_smallIBSize;
size_t m_blitVBSize;
size_t m_blitIBSize;
size_t m_textureWidth;
size_t m_textureHeight;
list<gl::Storage> m_storages;
list<gl::Storage> m_smallStorages;
list<gl::Storage> m_blitStorages;
@ -65,6 +77,9 @@ namespace yg
shared_ptr<gl::BaseTexture> const reserveTexture(bool doWait = false);
void freeTexture(shared_ptr<gl::BaseTexture> const & texture, bool doSignal = false);
size_t textureWidth() const;
size_t textureHeight() const;
shared_ptr<GlyphInfo> const getGlyph(GlyphKey const & key);
GlyphMetrics const getGlyphMetrics(GlyphKey const & key);

View file

@ -110,12 +110,13 @@ namespace yg
SkinPage::SkinPage(shared_ptr<ResourceManager> const & resourceManager,
uint8_t pageID)
: m_texture(resourceManager->reserveTexture()),
m_resourceManager(resourceManager),
: m_resourceManager(resourceManager),
m_isDynamic(true),
m_pageID(pageID)
{
m_packer = m2::Packer(m_texture->width(), m_texture->height(), 0x00FFFFFF - 1),
m_packer = m2::Packer(m_resourceManager->textureWidth(),
m_resourceManager->textureHeight(),
0x00FFFFFF - 1);
/// clear handles will be called only upon handles overflow,
/// as the texture overflow is processed separately
m_packer.addOverflowFn(bind(&SkinPage::clearHandles, this), 0);
@ -736,10 +737,25 @@ namespace yg
m_colorUploadCommands.clear();
}
bool SkinPage::hasData()
{
return ((!m_colorUploadCommands.empty())
|| (!m_penUploadCommands.empty())
|| (!m_glyphUploadCommands.empty())
|| (!m_circleUploadCommands.empty()));
}
void SkinPage::checkTexture() const
{
if ((m_isDynamic) && (m_texture == 0))
reserveTexture();
}
void SkinPage::uploadData()
{
if (m_isDynamic)
if ((m_isDynamic) && (hasData()))
{
checkTexture();
static_cast<gl::ManagedTexture*>(m_texture.get())->lock();
uploadColors();
uploadPenInfo();
@ -766,15 +782,18 @@ namespace yg
shared_ptr<gl::BaseTexture> const & SkinPage::texture() const
{
checkTexture();
return m_texture;
}
void SkinPage::freeTexture()
{
m_resourceManager->freeTexture(m_texture);
if (m_texture)
m_resourceManager->freeTexture(m_texture);
m_texture.reset();
}
void SkinPage::reserveTexture()
void SkinPage::reserveTexture() const
{
m_texture = m_resourceManager->reserveTexture();
}

View file

@ -95,8 +95,11 @@ namespace yg
TGlyphMap m_glyphMap;
m2::Packer m_packer;
shared_ptr<gl::BaseTexture> m_texture;
shared_ptr<ResourceManager> m_resourceManager;
/// made mutable to implement lazy reservation of texture
/// @{
mutable shared_ptr<gl::BaseTexture> m_texture;
mutable shared_ptr<ResourceManager> m_resourceManager;
/// @}
vector<ColorUploadCmd> m_colorUploadCommands;
vector<PenUploadCmd> m_penUploadCommands;
@ -129,8 +132,11 @@ namespace yg
void clearHandles();
bool hasData();
void uploadData();
void checkTexture() const;
SkinPage();
/// creation of a static page
@ -142,7 +148,7 @@ namespace yg
SkinPage(shared_ptr<ResourceManager> const & resourceManager,
uint8_t pageID);
void reserveTexture();
void reserveTexture() const;
void freeTexture();
uint32_t findColor(Color const & c) const;