refactored ResourceManager to support better resource usage scaling for different instantiations of the same RenderPolicy.

This commit is contained in:
rachytski 2011-11-14 19:56:57 +04:00 committed by Alex Zolotarev
parent 376f7c8748
commit c08a73a884
30 changed files with 744 additions and 414 deletions

View file

@ -6,8 +6,9 @@
BenchmarkRenderPolicyMT::BenchmarkRenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicyMT(videoTimer, params, primaryRC)
: RenderPolicyMT(videoTimer, params, rmParams, primaryRC)
{}
void BenchmarkRenderPolicyMT::DrawFrame(shared_ptr<PaintEvent> const & e,

View file

@ -7,6 +7,7 @@ class BenchmarkRenderPolicyMT : public RenderPolicyMT
public:
BenchmarkRenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);

View file

@ -4,8 +4,9 @@
BenchmarkTilingRenderPolicyMT::BenchmarkTilingRenderPolicyMT(
VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: TilingRenderPolicyMT(videoTimer, params, primaryRC)
: TilingRenderPolicyMT(videoTimer, params, rmParams, primaryRC)
{}
void BenchmarkTilingRenderPolicyMT::DrawFrame(shared_ptr<PaintEvent> const & e,

View file

@ -8,6 +8,7 @@ public:
BenchmarkTilingRenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);

View file

@ -15,34 +15,48 @@
PartialRenderPolicy::PartialRenderPolicy(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false),
m_DoAddCommand(true)
{
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
15,
2000 * sizeof(yg::gl::Vertex),
4000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
512, 256,
10,
512, 256,
5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
3,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
true));
yg::ResourceManager::Params rmp = rmParams;
m_resourceManager->initTinyStorage(300 * sizeof(yg::gl::Vertex), 600 * sizeof(unsigned short), 20);
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
15,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(2000 * sizeof(yg::gl::Vertex),
4000 * sizeof(unsigned short),
100,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
true);
rmp.m_tinyStoragesParams = yg::ResourceManager::StoragePoolParams(300 * sizeof(yg::gl::Vertex),
600 * sizeof(unsigned short),
20,
true);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 10, rmp.m_rtFormat, true);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 5, rmp.m_rtFormat, true);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
2,
1);
rmp.m_isMergeable = true;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
@ -110,7 +124,10 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
yg::gl::Screen * screen = e->drawer()->screen().get();
if (!m_state)
{
m_state = screen->createState();
m_state->m_isDebugging = true;
}
screen->getState(m_state.get());
@ -143,7 +160,10 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
LOG(LINFO, ("will continue on the next frame(", cmdProcessed, ")"));
}
else
LOG(LINFO, ("finished sequence of commands(", cmdProcessed, ")"));
{
if (cmdProcessed != 0)
LOG(LINFO, ("finished sequence of commands(", cmdProcessed, ")"));
}
{
threads::ConditionGuard guard(m_glCondition);
@ -185,6 +205,7 @@ void PartialRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e,
void PartialRenderPolicy::BeginFrame(shared_ptr<PaintEvent> const & paintEvent,
ScreenBase const & screenBase)
{
LOG(LINFO, ("-------BeginFrame-------"));
}
void PartialRenderPolicy::EndFrame(shared_ptr<PaintEvent> const & paintEvent,

View file

@ -31,6 +31,7 @@ public:
PartialRenderPolicy(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void BeginFrame(shared_ptr<PaintEvent> const & paintEvent,

View file

@ -111,6 +111,7 @@ void RenderPolicy::SetRenderFn(TRenderFn renderFn)
RenderPolicy * CreateRenderPolicy(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
{
bool benchmarkingEnabled = false;
@ -122,20 +123,20 @@ RenderPolicy * CreateRenderPolicy(VideoTimer * videoTimer,
Settings::Get("IsBenchmarkingMT", isBenchmarkingMT);
if (isBenchmarkingMT)
return new BenchmarkTilingRenderPolicyMT(videoTimer, params, primaryRC);
return new BenchmarkTilingRenderPolicyMT(videoTimer, params, rmParams, primaryRC);
else
return new BenchmarkRenderPolicyMT(videoTimer, params, primaryRC);
return new BenchmarkRenderPolicyMT(videoTimer, params, rmParams, primaryRC);
}
else
{
#ifdef OMIM_OS_ANDROID
return new PartialRenderPolicy(videoTimer, params, primaryRC);
return new PartialRenderPolicy(videoTimer, params, rmParams, primaryRC);
#endif
#ifdef OMIM_OS_IPHONE
return new RenderPolicyMT(videoTimer, params, primaryRC);
return new RenderPolicyMT(videoTimer, params, rmParams, primaryRC);
#endif
#ifdef OMIM_OS_DESKTOP
return new RenderPolicyMT(videoTimer, params, primaryRC);
return new RenderPolicyMT(videoTimer, params, rmParams, primaryRC);
#endif
}
}

View file

@ -89,5 +89,6 @@ public:
RenderPolicy * CreateRenderPolicy(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);

View file

@ -15,35 +15,51 @@
RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false),
m_DoAddCommand(true),
m_DoSynchronize(true)
{
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
50000 * sizeof(yg::gl::Vertex),
100000 * sizeof(unsigned short),
15,
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
512, 256,
10,
512, 256,
5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
false));
yg::ResourceManager::Params rmp = rmParams;
m_resourceManager->initTinyStorage(300 * sizeof(yg::gl::Vertex), 600 * sizeof(unsigned short), 20);
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
100 * sizeof(unsigned short),
15,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(50 * sizeof(yg::gl::Vertex),
10 * sizeof(unsigned short),
100,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
true);
rmp.m_tinyStoragesParams = yg::ResourceManager::StoragePoolParams(300 * sizeof(yg::gl::Vertex),
600 * sizeof(unsigned short),
20,
true);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 10, rmp.m_rtFormat, true);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 5, rmp.m_rtFormat, true);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
3,
1);
rmp.m_isMergeable = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
rmp.fitIntoLimits();
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);

View file

@ -22,6 +22,7 @@ public:
RenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void BeginFrame(shared_ptr<PaintEvent> const & e,

View file

@ -14,31 +14,43 @@
RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, false)
{
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
50000 * sizeof(yg::gl::Vertex),
100000 * sizeof(unsigned short),
15,
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
512, 256,
10,
512, 256,
5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
1,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
false));
yg::ResourceManager::Params rmp = rmParams;
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(50000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
15,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
true);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 10, rmp.m_rtFormat, true);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 5, rmp.m_rtFormat, true);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
1,
GetPlatform().CpuCores());
rmp.m_isMergeable = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);

View file

@ -10,6 +10,7 @@ class RenderPolicyST : public RenderPolicy
public:
RenderPolicyST(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void DrawFrame(shared_ptr<PaintEvent> const & paintEvent,

View file

@ -29,7 +29,7 @@ public:
static void Evict(Entry & val)
{
if (val.m_rm)
val.m_rm->renderTargets()->Free(val.m_tile.m_renderTarget);
val.m_rm->renderTargetTextures()->Free(val.m_tile.m_renderTarget);
}
};

View file

@ -35,8 +35,8 @@ TileRenderer::TileRenderer(
LOG(LINFO, ("initializing ", m_queue.ExecutorsCount(), " rendering threads"));
int tileWidth = m_resourceManager->tileTextureWidth();
int tileHeight = m_resourceManager->tileTextureHeight();
int tileWidth = m_resourceManager->params().m_renderTargetTexturesParams.m_texWidth;
int tileHeight = m_resourceManager->params().m_renderTargetTexturesParams.m_texHeight;
for (unsigned i = 0; i < m_queue.ExecutorsCount(); ++i)
{
@ -76,7 +76,7 @@ TileRenderer::~TileRenderer()
void TileRenderer::CancelThread(core::CommandsQueue::Environment const & /*env*/)
{
m_resourceManager->renderTargets()->Cancel();
m_resourceManager->renderTargetTextures()->Cancel();
}
void TileRenderer::InitializeThreadGL(core::CommandsQueue::Environment const & env)
@ -114,8 +114,8 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env,
ScreenBase frameScreen;
unsigned tileWidth = m_resourceManager->tileTextureWidth();
unsigned tileHeight = m_resourceManager->tileTextureHeight();
unsigned tileWidth = m_resourceManager->params().m_renderTargetTexturesParams.m_texWidth;
unsigned tileHeight = m_resourceManager->params().m_renderTargetTexturesParams.m_texHeight;
m2::RectI renderRect(1, 1, tileWidth - 1, tileHeight - 1);
@ -125,9 +125,9 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env,
my::Timer timer;
shared_ptr<yg::gl::BaseTexture> tileTarget = m_resourceManager->renderTargets()->Reserve();
shared_ptr<yg::gl::BaseTexture> tileTarget = m_resourceManager->renderTargetTextures()->Reserve();
if (m_resourceManager->renderTargets()->IsCancelled())
if (m_resourceManager->renderTargetTextures()->IsCancelled())
return;
drawer->screen()->setRenderTarget(tileTarget);
@ -172,7 +172,7 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env,
double duration = timer.ElapsedSeconds();
if (env.IsCancelled())
m_resourceManager->renderTargets()->Free(tileTarget);
m_resourceManager->renderTargetTextures()->Free(tileTarget);
else
AddTile(rectInfo, Tile(tileTarget, tileInfoLayer, frameScreen, rectInfo, duration));
}
@ -226,7 +226,7 @@ void TileRenderer::AddTile(Tiler::RectInfo const & rectInfo, Tile const & tile)
m_tileCache.writeLock();
if (m_tileCache.hasTile(rectInfo))
{
m_resourceManager->renderTargets()->Free(tile.m_renderTarget);
m_resourceManager->renderTargetTextures()->Free(tile.m_renderTarget);
m_tileCache.touchTile(rectInfo);
}
else

View file

@ -16,36 +16,64 @@
TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, true)
{
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
50000 * sizeof(yg::gl::Vertex),
100000 * sizeof(unsigned short),
15,
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
512, 256,
10,
512, 256,
5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
false));
yg::ResourceManager::Params rmp = rmParams;
m_resourceManager->initMultiBlitStorage(500 * sizeof(yg::gl::AuxVertex), 500 * sizeof(unsigned short), 10);
m_resourceManager->initRenderTargets(GetPlatform().TileSize(), GetPlatform().TileSize(), GetPlatform().MaxTilesCount());
m_resourceManager->initStyleCacheTextures(m_resourceManager->fontTextureWidth(), m_resourceManager->fontTextureHeight() * 2, 2);
m_resourceManager->initTinyStorage(300 * sizeof(yg::gl::Vertex), 600 * sizeof(unsigned short), 50);
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(50000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
15,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
true);
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::AuxVertex),
500 * sizeof(unsigned short),
10,
true);
rmp.m_tinyStoragesParams = yg::ResourceManager::StoragePoolParams(300 * sizeof(yg::gl::Vertex),
600 * sizeof(unsigned short),
20,
true);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 10, rmp.m_rtFormat, true);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 5, rmp.m_rtFormat, true);
rmp.m_renderTargetTexturesParams = yg::ResourceManager::TexturePoolParams(GetPlatform().TileSize(),
GetPlatform().TileSize(),
GetPlatform().MaxTilesCount(),
rmp.m_rtFormat,
true);
rmp.m_styleCacheTexturesParams = yg::ResourceManager::TexturePoolParams(rmp.m_fontTexturesParams.m_texWidth,
rmp.m_fontTexturesParams.m_texHeight,
2,
rmp.m_rtFormat,
true);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
GetPlatform().CpuCores());
rmp.m_isMergeable = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);

View file

@ -42,6 +42,7 @@ public:
TilingRenderPolicyMT(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void BeginFrame(shared_ptr<PaintEvent> const & ev, ScreenBase const & s);

View file

@ -16,36 +16,56 @@
TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC)
: RenderPolicy(primaryRC, true),
m_tileCache(GetPlatform().MaxTilesCount() - 1),
m_tiler(GetPlatform().TileSize(), GetPlatform().ScaleEtalonSize())
{
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
50000 * sizeof(yg::gl::Vertex),
100000 * sizeof(unsigned short),
15,
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
512, 256,
10,
512, 256,
5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
false));
yg::ResourceManager::Params rmp = rmParams;
m_resourceManager->initMultiBlitStorage(500 * sizeof(yg::gl::AuxVertex), 500 * sizeof(unsigned short), 10);
m_resourceManager->initRenderTargets(GetPlatform().TileSize(), GetPlatform().TileSize(), GetPlatform().MaxTilesCount());
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(50000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
15,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
true);
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::AuxVertex),
500 * sizeof(unsigned short),
10,
true);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 10, rmp.m_rtFormat, true);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 5, rmp.m_rtFormat, true);
rmp.m_renderTargetTexturesParams = yg::ResourceManager::TexturePoolParams(GetPlatform().TileSize(),
GetPlatform().TileSize(),
GetPlatform().MaxTilesCount(),
rmp.m_rtFormat,
true);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
GetPlatform().CpuCores());
rmp.m_isMergeable = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);
@ -72,8 +92,8 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
/// render single tile on the same thread
shared_ptr<yg::gl::FrameBuffer> frameBuffer(new yg::gl::FrameBuffer());
unsigned tileWidth = m_resourceManager->tileTextureWidth();
unsigned tileHeight = m_resourceManager->tileTextureHeight();
unsigned tileWidth = m_resourceManager->params().m_renderTargetTexturesParams.m_texWidth;
unsigned tileHeight = m_resourceManager->params().m_renderTargetTexturesParams.m_texHeight;
shared_ptr<yg::gl::RenderBuffer> depthBuffer(new yg::gl::RenderBuffer(tileWidth, tileHeight, true));
frameBuffer->setDepthBuffer(depthBuffer);
@ -134,7 +154,7 @@ void TilingRenderPolicyST::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBas
{
m_tileCache.readUnlock();
shared_ptr<PaintEvent> paintEvent(new PaintEvent(m_tileDrawer.get()));
shared_ptr<yg::gl::BaseTexture> tileTarget = m_resourceManager->renderTargets()->Reserve();
shared_ptr<yg::gl::BaseTexture> tileTarget = m_resourceManager->renderTargetTextures()->Reserve();
shared_ptr<yg::InfoLayer> tileInfoLayer(new yg::InfoLayer());
@ -146,7 +166,11 @@ void TilingRenderPolicyST::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBas
yg::Color c = m_bgColor;
m_tileDrawer->clear(yg::Color(c.r, c.g, c.b, 0));
m2::RectI renderRect(1, 1, m_resourceManager->tileTextureWidth() - 1, m_resourceManager->tileTextureHeight() - 1);
unsigned tileWidth = m_resourceManager->params().m_renderTargetTexturesParams.m_texWidth;
unsigned tileHeight = m_resourceManager->params().m_renderTargetTexturesParams.m_texHeight;
m2::RectI renderRect(1, 1, tileWidth - 1, tileHeight - 1);
m_tileDrawer->screen()->setClipRect(renderRect);
m_tileDrawer->clear(c);
@ -179,9 +203,6 @@ void TilingRenderPolicyST::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBas
tile = m_tileCache.getTile(ri);
m_tileCache.readUnlock();
size_t tileWidth = tile.m_renderTarget->width();
size_t tileHeight = tile.m_renderTarget->height();
pDrawer->screen()->blit(tile.m_renderTarget, tile.m_tileScreen, currentScreen, true,
yg::Color(),
m2::RectI(0, 0, tileWidth - 2, tileHeight - 2),

View file

@ -38,6 +38,7 @@ public:
TilingRenderPolicyST(VideoTimer * videoTimer,
DrawerYG::Params const & params,
yg::ResourceManager::Params const & rmParams,
shared_ptr<yg::gl::RenderContext> const & primaryRC);
void DrawFrame(shared_ptr<PaintEvent> const & paintEvent, ScreenBase const & screenBase);

View file

@ -208,7 +208,11 @@ namespace qt
shared_ptr<qt::gl::RenderContext> primaryRC(new qt::gl::RenderContext(this));
m_framework->SetRenderPolicy(CreateRenderPolicy(m_videoTimer.get(), params, primaryRC));
yg::ResourceManager::Params rmParams;
rmParams.m_rtFormat = yg::Rt8Bpp;
rmParams.m_videoMemoryLimit = 30 * 1024 * 1024;
m_framework->SetRenderPolicy(CreateRenderPolicy(m_videoTimer.get(), params, rmParams, primaryRC));
m_isInitialized = true;
}

View file

@ -36,65 +36,6 @@ namespace qt
void GLDrawWidget::initializeGL()
{
/// we'll perform swap by ourselves, see issue #333
setAutoBufferSwap(false);
if (m_p == 0)
{
#ifdef OMIM_OS_WINDOWS
win32::InitOpenGL();
#endif
if (!yg::gl::CheckExtensionSupport())
{
/// TODO: Show "Please Update Drivers" dialog and close the program.
}
Platform & pl = GetPlatform();
m_renderContext = shared_ptr<yg::gl::RenderContext>(new qt::gl::RenderContext(this));
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
50000 * sizeof(yg::gl::Vertex),
100000 * sizeof(unsigned short),
15,
5000 * sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
50,
512, 256,
10,
512, 256,
5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
false));
m_resourceManager->initMultiBlitStorage(500 * sizeof(yg::gl::AuxVertex), 500 * sizeof(unsigned short), 10);
Platform::FilesList fonts;
pl.GetFontNames(fonts);
m_resourceManager->addFonts(fonts);
DrawerYG::params_t p;
p.m_resourceManager = m_resourceManager;
p.m_frameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(true));
p.m_dynamicPagesCount = 2;
p.m_textPagesCount = 2;
p.m_glyphCacheID = m_resourceManager->guiThreadGlyphCacheID();
p.m_skinName = GetPlatform().SkinName();
p.m_visualScale = GetPlatform().VisualScale();
p.m_isSynchronized = true;
m_p = shared_ptr<DrawerYG>(new DrawerYG(p));
}
}
shared_ptr<yg::gl::RenderContext> const & GLDrawWidget::renderContext()

View file

@ -42,28 +42,45 @@ void GLDrawWidget::initializeGL()
m_primaryContext = make_shared_ptr(new qt::gl::RenderContext(this));
m_resourceManager = make_shared_ptr(new yg::ResourceManager(
30000 * sizeof(yg::gl::Vertex),
50000 * sizeof(unsigned short),
20,
3000 * sizeof(yg::gl::Vertex),
5000 * sizeof(unsigned short),
100,
10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
30,
512, 256, 10,
512, 256, 5,
"unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
GetPlatform().CpuCores() + 2,
yg::Rt8Bpp,
!yg::gl::g_isBufferObjectsSupported,
false));
yg::ResourceManager::Params rmp;
m_resourceManager->initMultiBlitStorage(500 * sizeof(yg::gl::AuxVertex), 500 * sizeof(unsigned short), 10);
rmp.m_videoMemoryLimit = 20 * 1024 * 1024;
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(30000 * sizeof(yg::gl::Vertex),
50000 * sizeof(unsigned short),
20,
false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(3000 * sizeof(yg::gl::Vertex),
5000 * sizeof(unsigned short),
100,
false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::AuxVertex),
10 * sizeof(unsigned short),
30,
true);
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::AuxVertex),
500 * sizeof(unsigned short),
10,
true);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 10, rmp.m_rtFormat, true);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512, 256, 5, rmp.m_rtFormat, true);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
"fonts_blacklist.txt",
2 * 1024 * 1024,
1,
0);
rmp.m_isMergeable = false;
rmp.m_useVA = !yg::gl::g_isBufferObjectsSupported;
rmp.m_rtFormat = yg::Rt8Bpp;
m_resourceManager.reset(new yg::ResourceManager(rmp));
Platform::FilesList fonts;
GetPlatform().GetFontNames(fonts);

View file

@ -63,7 +63,7 @@ namespace yg
if (m_useTinyStorage)
m_storage = resourceManager->tinyStorages()->Reserve();
else
m_storage = m_usage != SkinPage::EStaticUsage ? resourceManager->storages()->Reserve()
m_storage = m_usage != SkinPage::EStaticUsage ? resourceManager->primaryStorages()->Reserve()
: resourceManager->smallStorages()->Reserve();
m_maxVertices = m_storage.m_vertices->size() / sizeof(Vertex);
@ -102,7 +102,7 @@ namespace yg
freeStorage->m_storagePool = resourceManager()->tinyStorages();
else
if (pipeline.m_usage != SkinPage::EStaticUsage)
freeStorage->m_storagePool = resourceManager()->storages();
freeStorage->m_storagePool = resourceManager()->primaryStorages();
else
freeStorage->m_storagePool = resourceManager()->smallStorages();
@ -299,7 +299,7 @@ namespace yg
switch (m_skin->getPage(pipelineID)->usage())
{
case SkinPage::EDynamicUsage:
freeTexCmd->m_texturePool = resourceManager()->dynamicTextures();
freeTexCmd->m_texturePool = resourceManager()->primaryTextures();
break;
case SkinPage::EFontsUsage:
freeTexCmd->m_texturePool = resourceManager()->fontTextures();

View file

@ -88,7 +88,7 @@ namespace yg
}
};
GlyphCache::Params::Params(char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxSize)
GlyphCache::Params::Params(string const & blocksFile, string const & whiteListFile, string const & blackListFile, size_t maxSize)
: m_blocksFile(blocksFile), m_whiteListFile(whiteListFile), m_blackListFile(blackListFile), m_maxSize(maxSize)
{}

View file

@ -76,7 +76,7 @@ namespace yg
string m_whiteListFile;
string m_blackListFile;
size_t m_maxSize;
Params(char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxSize);
Params(string const & blocksFile, string const & whiteListFile, string const & blackListFile, size_t maxSize);
};
GlyphCache();

View file

@ -371,8 +371,8 @@ namespace yg
void Renderer::processCommand(shared_ptr<Command> const & command)
{
command->m_isDebugging = false;
// command->m_isDebugging = renderQueue();
// command->m_isDebugging = false;
command->m_isDebugging = renderQueue();
if (renderQueue())
{

View file

@ -68,89 +68,329 @@ namespace yg
}
}
ResourceManager::ResourceManager(size_t vbSize, size_t ibSize, size_t storagesCount,
size_t smallVBSize, size_t smallIBSize, size_t smallStoragesCount,
size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount,
size_t dynamicTexWidth, size_t dynamicTexHeight, size_t dynamicTexCount,
size_t fontTexWidth, size_t fontTexHeight, size_t fontTexCount,
char const * blocksFile, char const * whiteListFile, char const * blackListFile,
size_t glyphCacheSize,
size_t glyphCacheCount,
RtFormat fmt,
bool useVA,
bool isMergeable)
: m_dynamicTextureWidth(dynamicTexWidth), m_dynamicTextureHeight(dynamicTexHeight),
m_fontTextureWidth(fontTexWidth), m_fontTextureHeight(fontTexHeight),
m_vbSize(vbSize), m_ibSize(ibSize),
m_smallVBSize(smallVBSize), m_smallIBSize(smallIBSize),
m_blitVBSize(blitVBSize), m_blitIBSize(blitIBSize),
m_format(fmt),
m_useVA(useVA),
m_isMergeable(isMergeable)
ResourceManager::StoragePoolParams::StoragePoolParams()
: m_vbSize(0), m_ibSize(0), m_storagesCount(0), m_isFixed(true)
{}
ResourceManager::StoragePoolParams::StoragePoolParams(size_t vbSize, size_t ibSize, size_t storagesCount, bool isFixed)
: m_vbSize(vbSize), m_ibSize(ibSize), m_storagesCount(storagesCount), m_isFixed(isFixed)
{}
bool ResourceManager::StoragePoolParams::isValid() const
{
LOG(LDEBUG, ("allocating ", glyphCacheCount, " glyphCaches, ", glyphCacheSize, " bytes total."));
return m_vbSize && m_ibSize && m_storagesCount;
}
for (size_t i = 0; i < glyphCacheCount; ++i)
m_glyphCaches.push_back(GlyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, glyphCacheSize / glyphCacheCount)));
size_t ResourceManager::StoragePoolParams::memoryUsage() const
{
return (m_vbSize + m_ibSize) * m_storagesCount;
}
if (useVA)
void ResourceManager::StoragePoolParams::scaleMemoryUsage(double k)
{
m_vbSize *= k;
m_ibSize *= k;
}
ResourceManager::TexturePoolParams::TexturePoolParams()
: m_texWidth(0), m_texHeight(0), m_texCount(0), m_rtFormat(yg::Rt8Bpp), m_isFixed(true)
{}
ResourceManager::TexturePoolParams::TexturePoolParams(size_t texWidth, size_t texHeight, size_t texCount, yg::RtFormat rtFormat, bool isFixed)
: m_texWidth(texWidth), m_texHeight(texHeight), m_texCount(texCount), m_rtFormat(rtFormat), m_isFixed(isFixed)
{}
bool ResourceManager::TexturePoolParams::isValid() const
{
return m_texWidth && m_texHeight && m_texCount;
}
size_t ResourceManager::TexturePoolParams::memoryUsage() const
{
size_t pixelSize = 0;
switch (m_rtFormat)
{
case yg::Rt4Bpp:
pixelSize = 2;
break;
case yg::Rt8Bpp:
pixelSize = 4;
break;
}
return m_texWidth * m_texHeight * pixelSize * m_texCount;
}
void ResourceManager::TexturePoolParams::scaleMemoryUsage(double k)
{
if (k > 1)
{
while (k > 2)
{
if (k > 2)
{
m_texWidth *= 2;
k /= 2;
}
if (k > 2)
{
m_texHeight *= 2;
k /= 2;
}
}
}
else
{
if (k < 1)
{
while (k < 1)
{
if (k < 0.5)
{
m_texHeight /= 2;
k *= 2;
}
if (k < 0.5)
{
m_texWidth /= 2;
k *= 2;
}
}
}
}
m_texCount *= k;
}
ResourceManager::GlyphCacheParams::GlyphCacheParams()
: m_glyphCacheMemoryLimit(0),
m_glyphCacheCount(0),
m_renderThreadCount(0)
{}
ResourceManager::GlyphCacheParams::GlyphCacheParams(string const & unicodeBlockFile,
string const & whiteListFile,
string const & blackListFile,
size_t glyphCacheMemoryLimit,
size_t glyphCacheCount,
size_t renderThreadCount)
: m_unicodeBlockFile(unicodeBlockFile),
m_whiteListFile(whiteListFile),
m_blackListFile(blackListFile),
m_glyphCacheMemoryLimit(glyphCacheMemoryLimit),
m_glyphCacheCount(glyphCacheCount),
m_renderThreadCount(renderThreadCount)
{}
ResourceManager::Params::Params()
: m_rtFormat(yg::Rt8Bpp),
m_isMergeable(false),
m_useVA(true),
m_videoMemoryLimit(0)
{}
void ResourceManager::Params::fitIntoLimits()
{
size_t storageMemoryUsage = m_primaryStoragesParams.memoryUsage()
+ m_smallStoragesParams.memoryUsage()
+ m_blitStoragesParams.memoryUsage()
+ m_multiBlitStoragesParams.memoryUsage()
+ m_tinyStoragesParams.memoryUsage();
size_t fixedStorageMemoryUsage = (m_primaryStoragesParams.m_isFixed ? m_primaryStoragesParams.memoryUsage() : 0)
+ (m_smallStoragesParams.m_isFixed ? m_smallStoragesParams.memoryUsage() : 0)
+ (m_blitStoragesParams.m_isFixed ? m_blitStoragesParams.memoryUsage() : 0)
+ (m_multiBlitStoragesParams.m_isFixed ? m_multiBlitStoragesParams.memoryUsage() : 0)
+ (m_tinyStoragesParams.m_isFixed ? m_tinyStoragesParams.memoryUsage() : 0);
size_t textureMemoryUsage = m_primaryTexturesParams.memoryUsage()
+ m_fontTexturesParams.memoryUsage()
+ m_renderTargetTexturesParams.memoryUsage()
+ m_styleCacheTexturesParams.memoryUsage();
size_t fixedTextureMemoryUsage = (m_primaryTexturesParams.m_isFixed ? m_primaryTexturesParams.memoryUsage() : 0)
+ (m_fontTexturesParams.m_isFixed ? m_fontTexturesParams.memoryUsage() : 0)
+ (m_renderTargetTexturesParams.m_isFixed ? m_renderTargetTexturesParams.memoryUsage() : 0)
+ (m_styleCacheTexturesParams.m_isFixed ? m_styleCacheTexturesParams.memoryUsage() : 0);
size_t videoMemoryLimit = m_videoMemoryLimit;
if (videoMemoryLimit == 0)
videoMemoryLimit = storageMemoryUsage + textureMemoryUsage;
double k = ((int)videoMemoryLimit - (int)fixedStorageMemoryUsage - (int)fixedTextureMemoryUsage)* 1.0 / ((int)storageMemoryUsage + (int)textureMemoryUsage - (int)fixedStorageMemoryUsage - (int)fixedTextureMemoryUsage);
if (k < 0)
k = 1;
scaleMemoryUsage(k);
storageMemoryUsage = m_primaryStoragesParams.memoryUsage()
+ m_smallStoragesParams.memoryUsage()
+ m_blitStoragesParams.memoryUsage()
+ m_multiBlitStoragesParams.memoryUsage()
+ m_tinyStoragesParams.memoryUsage();
textureMemoryUsage = m_primaryTexturesParams.memoryUsage()
+ m_fontTexturesParams.memoryUsage()
+ m_renderTargetTexturesParams.memoryUsage()
+ m_styleCacheTexturesParams.memoryUsage();
LOG(LINFO, ("allocating ", storageMemoryUsage + textureMemoryUsage, " bytes of videoMemory, with initial limit ", m_videoMemoryLimit));
}
void ResourceManager::Params::scaleMemoryUsage(double k)
{
if (!m_primaryStoragesParams.m_isFixed)
m_primaryStoragesParams.scaleMemoryUsage(k);
if (!m_smallStoragesParams.m_isFixed)
m_smallStoragesParams.scaleMemoryUsage(k);
if (!m_blitStoragesParams.m_isFixed)
m_blitStoragesParams.scaleMemoryUsage(k);
if (!m_multiBlitStoragesParams.m_isFixed)
m_multiBlitStoragesParams.scaleMemoryUsage(k);
if (!m_tinyStoragesParams.m_isFixed)
m_tinyStoragesParams.scaleMemoryUsage(k);
if (!m_primaryTexturesParams.m_isFixed)
m_primaryTexturesParams.scaleMemoryUsage(k);
if (!m_fontTexturesParams.m_isFixed)
m_fontTexturesParams.scaleMemoryUsage(k);
if (!m_renderTargetTexturesParams.m_isFixed)
m_renderTargetTexturesParams.scaleMemoryUsage(k);
if (!m_styleCacheTexturesParams.m_isFixed)
m_styleCacheTexturesParams.scaleMemoryUsage(k);
}
ResourceManager::ResourceManager(Params const & p)
: m_params(p)
{
initGlyphCaches(p.m_glyphCacheParams);
initPrimaryStorage(p.m_primaryStoragesParams);
initSmallStorage(p.m_smallStoragesParams);
initBlitStorage(p.m_blitStoragesParams);
initMultiBlitStorage(p.m_multiBlitStoragesParams);
initTinyStorage(p.m_tinyStoragesParams);
initPrimaryTextures(p.m_primaryTexturesParams);
initFontTextures(p.m_fontTexturesParams);
initRenderTargetTextures(p.m_renderTargetTexturesParams);
initStyleCacheTextures(p.m_styleCacheTexturesParams);
if (p.m_useVA)
LOG(LINFO, ("buffer objects are unsupported. using client vertex array instead."));
if (m_isMergeable)
m_storages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(vbSize, ibSize, useVA, m_isMergeable, "primaryStorage"), storagesCount)));
else
m_storages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(vbSize, ibSize, useVA, m_isMergeable, "primaryStorage"), storagesCount)));
if (m_isMergeable)
m_smallStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(smallVBSize, smallIBSize, useVA, m_isMergeable, "smallStorage"), smallStoragesCount)));
else
m_smallStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(smallVBSize, smallIBSize, useVA, m_isMergeable, "smallStorage"), smallStoragesCount)));
if (m_isMergeable)
m_blitStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(blitVBSize, blitIBSize, useVA, m_isMergeable, "blitStorage"), blitStoragesCount)));
else
m_blitStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(blitVBSize, blitIBSize, useVA, m_isMergeable, "blitStorage"), blitStoragesCount)));
m_dynamicTextures.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(dynamicTexWidth, dynamicTexHeight, "dynamicTexture"), dynamicTexCount)));
m_fontTextures.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(fontTexWidth, fontTexHeight, "fontTexture"), fontTexCount)));
}
void ResourceManager::initMultiBlitStorage(size_t multiBlitVBSize, size_t multiBlitIBSize, size_t multiBlitStoragesCount)
void ResourceManager::initGlyphCaches(GlyphCacheParams const & p)
{
m_multiBlitVBSize = multiBlitVBSize;
m_multiBlitIBSize = multiBlitIBSize;
if (p.m_glyphCacheMemoryLimit && p.m_glyphCacheCount)
{
LOG(LDEBUG, ("allocating ", p.m_glyphCacheCount, " glyphCaches, ", p.m_glyphCacheMemoryLimit, " bytes total."));
if (m_isMergeable)
m_multiBlitStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(multiBlitVBSize, multiBlitIBSize, m_useVA, m_isMergeable, "multiBlitStorage"), multiBlitStoragesCount)));
for (size_t i = 0; i < p.m_glyphCacheCount; ++i)
m_glyphCaches.push_back(GlyphCache(GlyphCache::Params(p.m_unicodeBlockFile, p.m_whiteListFile, p.m_blackListFile, p.m_glyphCacheMemoryLimit / p.m_glyphCacheCount)));
}
else
m_multiBlitStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(multiBlitVBSize, multiBlitIBSize, m_useVA, m_isMergeable, "multiBlitStorage"), multiBlitStoragesCount)));
LOG(LERROR, ("no params to init glyph caches."));
}
void ResourceManager::initTinyStorage(size_t tinyVBSize, size_t tinyIBSize, size_t tinyStoragesCount)
void ResourceManager::initPrimaryStorage(StoragePoolParams const & p)
{
m_tinyVBSize = tinyVBSize;
m_tinyIBSize = tinyIBSize;
if (m_isMergeable)
m_tinyStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(tinyVBSize, tinyIBSize, m_useVA, m_isMergeable, "tinyStorage"), tinyStoragesCount)));
if (p.isValid())
{
if (m_params.m_isMergeable)
m_primaryStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "primaryStorage"), p.m_storagesCount)));
else
m_primaryStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "primaryStorage"), p.m_storagesCount)));
}
else
m_tinyStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(tinyVBSize, tinyIBSize, m_useVA, m_isMergeable, "tinyStorage"), tinyStoragesCount)));
LOG(LINFO, ("no primary storages"));
}
void ResourceManager::initRenderTargets(size_t renderTargetWidth, size_t renderTargetHeight, size_t renderTargetsCount)
void ResourceManager::initSmallStorage(StoragePoolParams const & p)
{
m_renderTargetWidth = renderTargetWidth;
m_renderTargetHeight = renderTargetHeight;
m_renderTargets.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(renderTargetWidth, renderTargetHeight, "renderTargets"), renderTargetsCount)));
if (p.isValid())
{
if (m_params.m_isMergeable)
m_smallStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "smallStorage"), p.m_storagesCount)));
else
m_smallStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "smallStorage"), p.m_storagesCount)));
}
else
LOG(LINFO, ("no small storages"));
}
void ResourceManager::initStyleCacheTextures(size_t styleCacheTextureWidth, size_t styleCacheTextureHeight, size_t styleCacheTexturesCount)
void ResourceManager::initBlitStorage(StoragePoolParams const & p)
{
m_styleCacheTextureWidth = styleCacheTextureWidth;
m_styleCacheTextureHeight = styleCacheTextureHeight;
if (p.isValid())
{
if (m_params.m_isMergeable)
m_blitStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "blitStorage"), p.m_storagesCount)));
else
m_blitStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "blitStorage"), p.m_storagesCount)));
}
else
LOG(LINFO, ("no blit storages"));
}
m_styleCacheTextures.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(styleCacheTextureWidth, styleCacheTextureHeight, "styleCacheTextures"), styleCacheTexturesCount)));
void ResourceManager::initMultiBlitStorage(StoragePoolParams const & p)
{
if (p.isValid())
{
if (m_params.m_isMergeable)
m_multiBlitStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "multiBlitStorage"), p.m_storagesCount)));
else
m_multiBlitStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "multiBlitStorage"), p.m_storagesCount)));
}
else
LOG(LINFO, ("no multiBlit storages"));
}
void ResourceManager::initTinyStorage(StoragePoolParams const & p)
{
if (p.isValid())
{
if (m_params.m_isMergeable)
m_tinyStorages.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "tinyStorage"), p.m_storagesCount)));
else
m_tinyStorages.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_isMergeable, "tinyStorage"), p.m_storagesCount)));
}
else
LOG(LINFO, ("no tiny storages"));
}
void ResourceManager::initPrimaryTextures(TexturePoolParams const & p)
{
if (p.isValid())
m_primaryTextures.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(p.m_texWidth, p.m_texHeight, "primaryTextures"), p.m_texCount)));
else
LOG(LINFO, ("no primary textures"));
}
void ResourceManager::initFontTextures(TexturePoolParams const & p)
{
if (p.isValid())
m_fontTextures.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(p.m_texWidth, p.m_texHeight, "fontTextures"), p.m_texCount)));
else
LOG(LINFO, ("no font textures"));
}
void ResourceManager::initRenderTargetTextures(TexturePoolParams const & p)
{
if (p.isValid())
m_renderTargets.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(p.m_texWidth, p.m_texHeight, "renderTargets"), p.m_texCount)));
else
LOG(LINFO, ("no renderTarget textures"));
}
void ResourceManager::initStyleCacheTextures(TexturePoolParams const & p)
{
if (p.isValid())
m_styleCacheTextures.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(p.m_texWidth, p.m_texHeight, "styleCacheTextures"), p.m_texCount)));
else
LOG(LINFO, ("no styleCache textures"));
}
shared_ptr<gl::BaseTexture> const & ResourceManager::getTexture(string const & fileName)
@ -190,34 +430,9 @@ namespace yg
return loader.skin();
}
size_t ResourceManager::dynamicTextureWidth() const
ResourceManager::Params const & ResourceManager::params() const
{
return m_dynamicTextureWidth;
}
size_t ResourceManager::dynamicTextureHeight() const
{
return m_dynamicTextureHeight;
}
size_t ResourceManager::fontTextureWidth() const
{
return m_fontTextureWidth;
}
size_t ResourceManager::fontTextureHeight() const
{
return m_fontTextureHeight;
}
size_t ResourceManager::tileTextureWidth() const
{
return m_renderTargetWidth;
}
size_t ResourceManager::tileTextureHeight() const
{
return m_renderTargetHeight;
return m_params;
}
GlyphCache * ResourceManager::glyphCache(int glyphCacheID)
@ -239,8 +454,8 @@ namespace yg
{
threads::MutexGuard guard(m_mutex);
if (m_storages.get())
m_storages->EnterBackground();
if (m_primaryStorages.get())
m_primaryStorages->EnterBackground();
if (m_smallStorages.get())
m_smallStorages->EnterBackground();
@ -254,8 +469,8 @@ namespace yg
if (m_tinyStorages.get())
m_tinyStorages->EnterBackground();
if (m_dynamicTextures.get())
m_dynamicTextures->EnterBackground();
if (m_primaryTextures.get())
m_primaryTextures->EnterBackground();
if (m_fontTextures.get())
m_fontTextures->EnterBackground();
@ -271,8 +486,8 @@ namespace yg
{
threads::MutexGuard guard(m_mutex);
if (m_storages.get())
m_storages->EnterForeground();
if (m_primaryStorages.get())
m_primaryStorages->EnterForeground();
if (m_smallStorages.get())
m_smallStorages->EnterForeground();
@ -286,8 +501,8 @@ namespace yg
if (m_tinyStorages.get())
m_tinyStorages->EnterForeground();
if (m_dynamicTextures.get())
m_dynamicTextures->EnterForeground();
if (m_primaryTextures.get())
m_primaryTextures->EnterForeground();
if (m_fontTextures.get())
m_fontTextures->EnterForeground();
@ -301,7 +516,7 @@ namespace yg
shared_ptr<yg::gl::BaseTexture> ResourceManager::createRenderTarget(unsigned w, unsigned h)
{
switch (m_format)
switch (m_params.m_rtFormat)
{
case Rt8Bpp:
return make_shared_ptr(new gl::Texture<RGBA8Traits, false>(w, h));
@ -314,7 +529,8 @@ namespace yg
int ResourceManager::renderThreadGlyphCacheID(int threadNum) const
{
return 2 + threadNum;
ASSERT(threadNum < m_params.m_glyphCacheParams.m_renderThreadCount, ());
return 1 + threadNum;
}
int ResourceManager::guiThreadGlyphCacheID() const
@ -324,12 +540,12 @@ namespace yg
int ResourceManager::cacheThreadGlyphCacheID() const
{
return 1;
return 1 + m_params.m_glyphCacheParams.m_renderThreadCount;
}
ResourceManager::TStoragePool * ResourceManager::storages()
ResourceManager::TStoragePool * ResourceManager::primaryStorages()
{
return m_storages.get();
return m_primaryStorages.get();
}
ResourceManager::TStoragePool * ResourceManager::smallStorages()
@ -337,6 +553,11 @@ namespace yg
return m_smallStorages.get();
}
ResourceManager::TStoragePool * ResourceManager::tinyStorages()
{
return m_tinyStorages.get();
}
ResourceManager::TStoragePool * ResourceManager::blitStorages()
{
return m_blitStorages.get();
@ -347,14 +568,9 @@ namespace yg
return m_multiBlitStorages.get();
}
ResourceManager::TStoragePool * ResourceManager::tinyStorages()
ResourceManager::TTexturePool * ResourceManager::primaryTextures()
{
return m_tinyStorages.get();
}
ResourceManager::TTexturePool * ResourceManager::dynamicTextures()
{
return m_dynamicTextures.get();
return m_primaryTextures.get();
}
ResourceManager::TTexturePool * ResourceManager::fontTextures()
@ -362,7 +578,7 @@ namespace yg
return m_fontTextures.get();
}
ResourceManager::TTexturePool * ResourceManager::renderTargets()
ResourceManager::TTexturePool * ResourceManager::renderTargetTextures()
{
return m_renderTargets.get();
}
@ -376,8 +592,8 @@ namespace yg
{
if (m_tinyStorages.get())
m_tinyStorages->Merge();
if (m_storages.get())
m_storages->Merge();
if (m_primaryStorages.get())
m_primaryStorages->Merge();
if (m_smallStorages.get())
m_smallStorages->Merge();
if (m_blitStorages.get())

View file

@ -70,6 +70,91 @@ namespace yg
typedef ResourcePool<gl::Storage> TStoragePool;
public:
struct StoragePoolParams
{
size_t m_vbSize;
size_t m_ibSize;
size_t m_storagesCount;
bool m_isFixed; //< should this params be scaled while fitting into videoMemoryLimit
StoragePoolParams(size_t vbSize, size_t ibSize, size_t storagesCount, bool isFixed);
StoragePoolParams();
bool isValid() const;
void scaleMemoryUsage(double k);
size_t memoryUsage() const;
};
struct TexturePoolParams
{
size_t m_texWidth;
size_t m_texHeight;
size_t m_texCount;
yg::RtFormat m_rtFormat;
bool m_isFixed; //< should this params be scaled while fitting into videoMemoryLimit
TexturePoolParams(size_t texWidth, size_t texHeight, size_t texCount, yg::RtFormat rtFormat, bool isFixed);
TexturePoolParams();
bool isValid() const;
void scaleMemoryUsage(double k);
size_t memoryUsage() const;
};
struct GlyphCacheParams
{
string m_unicodeBlockFile;
string m_whiteListFile;
string m_blackListFile;
size_t m_glyphCacheMemoryLimit;
size_t m_glyphCacheCount;
size_t m_renderThreadCount;
GlyphCacheParams();
GlyphCacheParams(string const & unicodeBlockFile,
string const & whiteListFile,
string const & blackListFile,
size_t glyphCacheMemoryLimit,
size_t glyphCacheCount,
size_t renderThreadCount);
};
struct Params
{
RtFormat m_rtFormat;
bool m_isMergeable;
bool m_useVA;
size_t m_videoMemoryLimit;
/// storages params
StoragePoolParams m_primaryStoragesParams;
StoragePoolParams m_smallStoragesParams;
StoragePoolParams m_blitStoragesParams;
StoragePoolParams m_multiBlitStoragesParams;
StoragePoolParams m_tinyStoragesParams;
/// textures params
TexturePoolParams m_primaryTexturesParams;
TexturePoolParams m_fontTexturesParams;
TexturePoolParams m_renderTargetTexturesParams;
TexturePoolParams m_styleCacheTexturesParams;
/// glyph caches params
GlyphCacheParams m_glyphCacheParams;
Params();
void scaleMemoryUsage(double k);
void fitIntoLimits();
};
private:
typedef map<string, shared_ptr<gl::BaseTexture> > TStaticTextures;
@ -78,42 +163,12 @@ namespace yg
threads::Mutex m_mutex;
size_t m_dynamicTextureWidth;
size_t m_dynamicTextureHeight;
auto_ptr<TTexturePool> m_dynamicTextures;
size_t m_fontTextureWidth;
size_t m_fontTextureHeight;
auto_ptr<TTexturePool> m_primaryTextures;
auto_ptr<TTexturePool> m_fontTextures;
size_t m_styleCacheTextureWidth;
size_t m_styleCacheTextureHeight;
auto_ptr<TTexturePool> m_styleCacheTextures;
size_t m_renderTargetWidth;
size_t m_renderTargetHeight;
auto_ptr<TTexturePool> m_renderTargets;
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_multiBlitVBSize;
size_t m_multiBlitIBSize;
size_t m_tinyVBSize;
size_t m_tinyIBSize;
auto_ptr<TStoragePool> m_storages;
auto_ptr<TStoragePool> m_primaryStorages;
auto_ptr<TStoragePool> m_smallStorages;
auto_ptr<TStoragePool> m_blitStorages;
auto_ptr<TStoragePool> m_multiBlitStorages;
@ -121,51 +176,39 @@ namespace yg
vector<GlyphCache> m_glyphCaches;
RtFormat m_format;
bool m_useVA;
bool m_isMergeable;
Params m_params;
public:
ResourceManager(size_t vbSize, size_t ibSize, size_t storagesCount,
size_t smallVBSize, size_t smallIBSize, size_t smallStoragesCount,
size_t blitVBSize, size_t blitIBSize, size_t blitStoragesCount,
size_t texWidth, size_t texHeight, size_t texCount,
size_t fontTexWidth, size_t fontTexHeight, size_t fontTexCount,
char const * blocksFile, char const * whileListFile, char const * blackListFile,
size_t glyphCacheSize,
size_t glyphCacheCount,
RtFormat fmt,
bool useVA,
bool isMergeable);
ResourceManager(Params const & p);
void initMultiBlitStorage(size_t multiBlitVBSize, size_t multiBlitIBSize, size_t multiBlitStoragesCount);
void initRenderTargets(size_t renderTargetWidth, size_t renderTargetHeight, size_t renderTargetCount);
void initTinyStorage(size_t tinyVBSize, size_t tinyIBSize, size_t tinyStoragesCount);
void initStyleCacheTextures(size_t styleCacheTextureWidth, size_t styleCacheTextureHeight, size_t styleCacheTexturesCount);
void initGlyphCaches(GlyphCacheParams const & p);
shared_ptr<gl::BaseTexture> const & getTexture(string const & fileName);
void initPrimaryStorage(StoragePoolParams const & p);
void initSmallStorage(StoragePoolParams const & p);
void initBlitStorage(StoragePoolParams const & p);
void initMultiBlitStorage(StoragePoolParams const & p);
void initTinyStorage(StoragePoolParams const & p);
TStoragePool * storages();
TStoragePool * primaryStorages();
TStoragePool * smallStorages();
TStoragePool * blitStorages();
TStoragePool * multiBlitStorages();
TStoragePool * tinyStorages();
TTexturePool * dynamicTextures();
void initPrimaryTextures(TexturePoolParams const & p);
void initFontTextures(TexturePoolParams const & p);
void initRenderTargetTextures(TexturePoolParams const & p);
void initStyleCacheTextures(TexturePoolParams const & p);
TTexturePool * primaryTextures();
TTexturePool * fontTextures();
TTexturePool * renderTargets();
TTexturePool * renderTargetTextures();
TTexturePool * styleCacheTextures();
size_t dynamicTextureWidth() const;
size_t dynamicTextureHeight() const;
shared_ptr<gl::BaseTexture> const & getTexture(string const & fileName);
size_t fontTextureWidth() const;
size_t fontTextureHeight() const;
size_t tileTextureWidth() const;
size_t tileTextureHeight() const;
Params const & params() const;
shared_ptr<GlyphInfo> const getGlyphInfo(GlyphKey const & key);
GlyphMetrics const getGlyphMetrics(GlyphKey const & key);

View file

@ -384,7 +384,7 @@ namespace yg
switch (m_usage)
{
case EDynamicUsage:
m_resourceManager->dynamicTextures()->Free(m_texture);
m_resourceManager->primaryTextures()->Free(m_texture);
break;
case EFontsUsage:
m_resourceManager->fontTextures()->Free(m_texture);
@ -402,7 +402,7 @@ namespace yg
switch (m_usage)
{
case EDynamicUsage:
m_texture = m_resourceManager->dynamicTextures()->Reserve();
m_texture = m_resourceManager->primaryTextures()->Reserve();
break;
case EFontsUsage:
m_texture = m_resourceManager->fontTextures()->Reserve();
@ -417,13 +417,13 @@ namespace yg
switch (m_usage)
{
case EDynamicUsage:
m_packer = m2::Packer(m_resourceManager->dynamicTextureWidth(),
m_resourceManager->dynamicTextureHeight(),
m_packer = m2::Packer(m_resourceManager->params().m_primaryTexturesParams.m_texWidth,
m_resourceManager->params().m_primaryTexturesParams.m_texHeight,
0x00FFFFFF - 1);
break;
case EFontsUsage:
m_packer = m2::Packer(m_resourceManager->fontTextureWidth(),
m_resourceManager->fontTextureHeight(),
m_packer = m2::Packer(m_resourceManager->params().m_fontTexturesParams.m_texWidth,
m_resourceManager->params().m_fontTexturesParams.m_texHeight,
0x00FFFFFF - 1);
break;
default:

View file

@ -8,6 +8,6 @@
UNIT_TEST(SkinLoaderTest_Main)
{
GL_TEST_START;
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(1000, 1000, 2, 1000, 1000, 2, 1000, 1000, 2, 128, 128, 15, 256, 256, 5, "unicode_blocks.txt", "fonts_whitelist.txt", "fonts_blacklist.txt", 2 * 1024 * 1024, 3, yg::Rt8Bpp, false, false));
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(yg::ResourceManager::Params()));
loadSkin(rm, "basic.skn", 2, 2);
};

View file

@ -10,7 +10,7 @@ UNIT_TEST(SkinTest_Main)
{
GL_TEST_START;
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(100, 100, 1, 100, 100, 1, 100, 100, 1, 128, 128, 15, 256, 256, 5, "unicode_blocks.txt", "fonts_whitelist.txt", "fonts_blacklist.txt", 2 * 1024 * 1024, 3, yg::Rt8Bpp, false, false));
shared_ptr<yg::ResourceManager> rm(new yg::ResourceManager(yg::ResourceManager::Params()));
yg::Skin * skin = loadSkin(rm, "basic.skn", 2, 2);
double p0 [] = {1, 1};