Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2013-05-29 15:45:32 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:55:34 +0300
commitbe7a21e6ed78e1c3f457d6a801a62f0af632f24d (patch)
treedfb0c2c16d2b58a4bb50a04e4d48aa0378c282ec /graphics
parent3f35306ff163a0e280c0859d79dbfb7d2916c8ce (diff)
Read .skn file and static texture once in main thread.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/geometry_batcher.cpp8
-rw-r--r--graphics/geometry_batcher.hpp3
-rw-r--r--graphics/opengl/texture.hpp3
-rw-r--r--graphics/resource_cache.cpp5
-rw-r--r--graphics/resource_cache.hpp3
-rw-r--r--graphics/resource_manager.cpp72
-rw-r--r--graphics/resource_manager.hpp19
-rw-r--r--graphics/skin_loader.cpp8
-rw-r--r--graphics/skin_loader.hpp5
9 files changed, 61 insertions, 65 deletions
diff --git a/graphics/geometry_batcher.cpp b/graphics/geometry_batcher.cpp
index 303039ece5..d7bcbd7f87 100644
--- a/graphics/geometry_batcher.cpp
+++ b/graphics/geometry_batcher.cpp
@@ -31,8 +31,7 @@ namespace graphics
GeometryBatcher::Params::Params()
: m_storageType(ELargeStorage),
- m_textureType(ELargeTexture),
- m_density(EDensityLDPI)
+ m_textureType(ELargeTexture)
{
CheckPointLayout<float>();
CheckPointLayout<double>();
@@ -40,13 +39,12 @@ namespace graphics
GeometryBatcher::GeometryBatcher(Params const & p)
: base_t(p),
- m_isAntiAliased(true),
- m_density(p.m_density)
+ m_isAntiAliased(true)
{
base_t::applyStates();
vector<shared_ptr<ResourceCache> > caches;
- loadSkin(resourceManager(), p.m_skinName, m_density, caches);
+ ResourceManager::loadSkin(resourceManager(), caches);
m_staticPagesCount = caches.size();
m_startStaticPage = reservePipelines(caches,
diff --git a/graphics/geometry_batcher.hpp b/graphics/geometry_batcher.hpp
index 30e36343e9..d181c192b9 100644
--- a/graphics/geometry_batcher.hpp
+++ b/graphics/geometry_batcher.hpp
@@ -30,7 +30,6 @@ namespace graphics
bool m_isAntiAliased;
int m_aaShift;
- EDensity m_density;
public:
@@ -47,8 +46,6 @@ namespace graphics
{
EStorageType m_storageType;
ETextureType m_textureType;
- string m_skinName;
- EDensity m_density;
Params();
};
diff --git a/graphics/opengl/texture.hpp b/graphics/opengl/texture.hpp
index 610f307263..e860cb5fcf 100644
--- a/graphics/opengl/texture.hpp
+++ b/graphics/opengl/texture.hpp
@@ -189,7 +189,8 @@ namespace graphics
}
template <typename Traits>
- Texture<Traits, true>::Texture(string const & fileName, EDensity density) : ManagedTexture(GetDimensions(fileName, density), sizeof(pixel_t))
+ Texture<Traits, true>::Texture(string const & fileName, EDensity density)
+ : ManagedTexture(GetDimensions(fileName, density), sizeof(pixel_t))
{
lock();
view_t v = view(width(), height());
diff --git a/graphics/resource_cache.cpp b/graphics/resource_cache.cpp
index 8e43d4abff..1f1fd7791b 100644
--- a/graphics/resource_cache.cpp
+++ b/graphics/resource_cache.cpp
@@ -20,10 +20,9 @@ namespace graphics
{}
ResourceCache::ResourceCache(shared_ptr<ResourceManager> const & resourceManager,
- char const * name,
- EDensity density,
+ string const & name,
uint8_t pipelineID)
- : m_texture(resourceManager->getTexture(name, density)),
+ : m_texture(resourceManager->getTexture(name)),
m_packer(m_texture->width(), m_texture->height(), 0x00FFFFFF - 1),
m_textureType(EStaticTexture),
m_pipelineID(pipelineID)
diff --git a/graphics/resource_cache.hpp b/graphics/resource_cache.hpp
index 3e7d7ea511..8f7ae96c3b 100644
--- a/graphics/resource_cache.hpp
+++ b/graphics/resource_cache.hpp
@@ -77,8 +77,7 @@ namespace graphics
/// creation of a static page
ResourceCache(shared_ptr<ResourceManager> const & resourceManager,
- char const * name,
- EDensity density,
+ string const & name,
uint8_t pipelineID);
/// creation of a dynamic page
diff --git a/graphics/resource_manager.cpp b/graphics/resource_manager.cpp
index 995e1179b5..5d2aeb1c1d 100644
--- a/graphics/resource_manager.cpp
+++ b/graphics/resource_manager.cpp
@@ -274,9 +274,37 @@ namespace
LOG(LINFO, ("using ReadPixels instead of glFinish to synchronize"));
}
- ResourceManager::ResourceManager(Params const & p)
+ void ResourceManager::loadSkinInfoAndTexture(string const & skinFileName, EDensity density)
+ {
+ try
+ {
+ ReaderPtr<Reader> reader(GetPlatform().GetReader(resourcePath(skinFileName, density)));
+ reader.ReadAsString(m_skinBuffer);
+
+ size_t i = m_skinBuffer.find("file=\"", 0);
+ if (i == string::npos)
+ MYTHROW(RootException, ("Invalid skin file"));
+ i += strlen("file=\"");
+
+ size_t const j = m_skinBuffer.find('\"', i);
+ if (j == string::npos)
+ MYTHROW(RootException, ("Invalid skin file"));
+
+ string const textureFileName = m_skinBuffer.substr(i, j-i);
+ m_staticTextures[textureFileName] = make_shared_ptr(new TStaticTexture(textureFileName, density));
+ }
+ catch (RootException const & ex)
+ {
+ LOG(LERROR, ("Error reading skin file", skinFileName, ex.Msg()));
+ }
+ }
+
+ ResourceManager::ResourceManager(Params const & p, string const & skinFileName, EDensity density)
: m_params(p)
{
+ // Load skin and texture once before thread's initializing.
+ loadSkinInfoAndTexture(skinFileName, density);
+
initThreadSlots(p);
m_storagePools.resize(EInvalidStorage + 1);
@@ -379,43 +407,21 @@ namespace
return m_texturePools[type].get();
}
- shared_ptr<gl::BaseTexture> const & ResourceManager::getTexture(string const & fileName, EDensity density)
+ shared_ptr<gl::BaseTexture> const & ResourceManager::getTexture(string const & name)
{
- pair<string, EDensity> key(fileName, density);
- TStaticTextures::const_iterator it = m_staticTextures.find(key);
- if (it != m_staticTextures.end())
- return it->second;
-
- shared_ptr<gl::BaseTexture> texture;
-
- texture = make_shared_ptr(new TStaticTexture(fileName, density));
-
- m_staticTextures[key] = texture;
- return m_staticTextures[key];
+ TStaticTextures::const_iterator it = m_staticTextures.find(name);
+ ASSERT ( it != m_staticTextures.end(), () );
+ return it->second;
}
- void loadSkin(shared_ptr<ResourceManager> const & rm,
- string const & fileName,
- EDensity density,
- vector<shared_ptr<ResourceCache> > & caches)
+ void ResourceManager::loadSkin(shared_ptr<ResourceManager> const & rm,
+ vector<shared_ptr<ResourceCache> > & caches)
{
- if (fileName.empty())
- return;
-
- SkinLoader loader(rm, caches, density);
+ SkinLoader loader(rm, caches);
- try
- {
- ReaderPtr<Reader> skinFile(GetPlatform().GetReader(resourcePath(fileName, density)));
- ReaderSource<ReaderPtr<Reader> > source(skinFile);
- if (!ParseXML(source, loader))
- MYTHROW(RootException, ("Error parsing skin file: ", fileName));
- }
- catch (RootException const & e)
- {
- LOG(LERROR, ("Error reading skin file: ", e.what()));
- return;
- }
+ ReaderSource<MemReader> source(MemReader(rm->m_skinBuffer.c_str(), rm->m_skinBuffer.size()));
+ if (!ParseXML(source, loader))
+ LOG(LERROR, ("Error parsing skin"));
}
ResourceManager::Params const & ResourceManager::params() const
diff --git a/graphics/resource_manager.hpp b/graphics/resource_manager.hpp
index 37a21cf4d1..8dec35f946 100644
--- a/graphics/resource_manager.hpp
+++ b/graphics/resource_manager.hpp
@@ -212,9 +212,11 @@ namespace graphics
private:
- typedef map<pair<string, EDensity>, shared_ptr<gl::BaseTexture> > TStaticTextures;
-
+ typedef map<string, shared_ptr<gl::BaseTexture> > TStaticTextures;
TStaticTextures m_staticTextures;
+ string m_skinBuffer;
+
+ void loadSkinInfoAndTexture(string const & skinFileName, EDensity density);
threads::Mutex m_mutex;
@@ -232,8 +234,12 @@ namespace graphics
Params m_params;
public:
+ ResourceManager(Params const & p, string const & skinFileName, EDensity density);
- ResourceManager(Params const & p);
+ /// Use like static function with shared_ptr instead of this.
+ /// @todo Check if we can remove shared_ptrs from this logic.
+ static void loadSkin(shared_ptr<ResourceManager> const & rm,
+ vector<shared_ptr<ResourceCache> > & caches);
void initThreadSlots(Params const & p);
@@ -245,7 +251,7 @@ namespace graphics
TTexturePool * texturePool(ETextureType type);
- shared_ptr<gl::BaseTexture> const & getTexture(string const & fileName, EDensity density);
+ shared_ptr<gl::BaseTexture> const & getTexture(string const & name);
Params const & params() const;
@@ -270,10 +276,5 @@ namespace graphics
shared_ptr<graphics::gl::BaseTexture> createRenderTarget(unsigned w, unsigned h);
gl::ProgramManager * programManager(int threadSlot);
};
-
- void loadSkin(shared_ptr<ResourceManager> const & rm,
- string const & fileName,
- EDensity density,
- vector<shared_ptr<ResourceCache> > & caches);
}
diff --git a/graphics/skin_loader.cpp b/graphics/skin_loader.cpp
index d62257df03..ec5260cb6f 100644
--- a/graphics/skin_loader.cpp
+++ b/graphics/skin_loader.cpp
@@ -9,12 +9,10 @@
namespace graphics
{
SkinLoader::SkinLoader(shared_ptr<ResourceManager> const & resourceManager,
- vector<shared_ptr<ResourceCache> > & caches,
- EDensity density)
- : m_id(-1),
+ vector<shared_ptr<ResourceCache> > & caches)
+ : m_id(-1),
m_texRect(0, 0, 0, 0),
m_fileName(""),
- m_density(density),
m_resourceManager(resourceManager),
m_caches(caches)
{
@@ -50,7 +48,7 @@ namespace graphics
void SkinLoader::popPage()
{
- m_caches.push_back(make_shared_ptr(new ResourceCache(m_resourceManager, m_fileName.c_str(), m_density, m_caches.size())));
+ m_caches.push_back(make_shared_ptr(new ResourceCache(m_resourceManager, m_fileName, m_caches.size())));
TResourceList::iterator prevIt = m_resourceList.end();
diff --git a/graphics/skin_loader.hpp b/graphics/skin_loader.hpp
index 39fe2948e2..f0e9d52d4b 100644
--- a/graphics/skin_loader.hpp
+++ b/graphics/skin_loader.hpp
@@ -64,8 +64,6 @@ namespace graphics
/// skin-page specific parameters
string m_fileName;
- EDensity m_density;
-
shared_ptr<ResourceManager> m_resourceManager;
/// skin-specific parameters
@@ -80,8 +78,7 @@ namespace graphics
public:
SkinLoader(shared_ptr<ResourceManager> const & resourceManager,
- vector<shared_ptr<ResourceCache> > & caches,
- EDensity density);
+ vector<shared_ptr<ResourceCache> > & caches);
bool Push(string const & element);
void Pop(string const & element);