forked from organicmaps/organicmaps
added ResourceStyleCacheContext to avoid caching some ResourceStyles twice.
This commit is contained in:
parent
d09204fdef
commit
ba1fbcd59f
2 changed files with 119 additions and 3 deletions
|
@ -14,9 +14,90 @@
|
|||
|
||||
namespace yg
|
||||
{
|
||||
|
||||
struct ResourceStyleCacheContext::Impl
|
||||
{
|
||||
/// the following sets are used to see, whether
|
||||
/// in the current InfoLayer::cache process we've already
|
||||
/// caching some resource (glyph, color, penInfo, e.t.c.)
|
||||
/// to avoid caching it twice.
|
||||
/// @{
|
||||
|
||||
typedef set<PenInfo> TPenInfoSet;
|
||||
TPenInfoSet m_penInfoSet;
|
||||
|
||||
typedef set<CircleInfo> TCircleInfoSet;
|
||||
TCircleInfoSet m_circleInfoSet;
|
||||
|
||||
typedef set<Color> TColorSet;
|
||||
TColorSet m_colorSet;
|
||||
|
||||
typedef set<GlyphKey> TGlyphSet;
|
||||
TGlyphSet m_glyphSet;
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
ResourceStyleCacheContext::ResourceStyleCacheContext()
|
||||
{
|
||||
m_impl = new Impl();
|
||||
}
|
||||
|
||||
ResourceStyleCacheContext::~ResourceStyleCacheContext()
|
||||
{
|
||||
delete m_impl;
|
||||
}
|
||||
|
||||
bool ResourceStyleCacheContext::hasColor(Color const & c) const
|
||||
{
|
||||
return m_impl->m_colorSet.count(c);
|
||||
}
|
||||
|
||||
void ResourceStyleCacheContext::addColor(Color const & c)
|
||||
{
|
||||
m_impl->m_colorSet.insert(c);
|
||||
}
|
||||
|
||||
bool ResourceStyleCacheContext::hasPenInfo(PenInfo const & pi) const
|
||||
{
|
||||
return m_impl->m_penInfoSet.count(pi);
|
||||
}
|
||||
|
||||
void ResourceStyleCacheContext::addPenInfo(PenInfo const & pi)
|
||||
{
|
||||
m_impl->m_penInfoSet.insert(pi);
|
||||
}
|
||||
|
||||
bool ResourceStyleCacheContext::hasCircleInfo(CircleInfo const & ci) const
|
||||
{
|
||||
return m_impl->m_circleInfoSet.count(ci);
|
||||
}
|
||||
|
||||
void ResourceStyleCacheContext::addCircleInfo(CircleInfo const & ci)
|
||||
{
|
||||
m_impl->m_circleInfoSet.insert(ci);
|
||||
}
|
||||
|
||||
bool ResourceStyleCacheContext::hasGlyph(GlyphKey const & gk) const
|
||||
{
|
||||
return m_impl->m_glyphSet.count(gk);
|
||||
}
|
||||
|
||||
void ResourceStyleCacheContext::addGlyph(GlyphKey const & gk)
|
||||
{
|
||||
m_impl->m_glyphSet.insert(gk);
|
||||
}
|
||||
|
||||
void ResourceStyleCacheContext::clear()
|
||||
{
|
||||
m_impl->m_circleInfoSet.clear();
|
||||
m_impl->m_colorSet.clear();
|
||||
m_impl->m_glyphSet.clear();
|
||||
m_impl->m_penInfoSet.clear();
|
||||
}
|
||||
ResourceStyleCache::ResourceStyleCache(shared_ptr<ResourceManager> const & rm,
|
||||
int glyphCacheID,
|
||||
yg::gl::PacketsQueue * glQueue)
|
||||
int glyphCacheID,
|
||||
yg::gl::PacketsQueue * glQueue)
|
||||
: m_rm(rm),
|
||||
m_glQueue(glQueue)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../std/shared_ptr.hpp"
|
||||
#include "../std/set.hpp"
|
||||
#include "../geometry/point2d.hpp"
|
||||
|
||||
namespace yg
|
||||
|
@ -15,6 +16,41 @@ namespace yg
|
|||
class SkinPage;
|
||||
class GlyphCache;
|
||||
class ResourceManager;
|
||||
struct Color;
|
||||
struct PenInfo;
|
||||
struct CircleInfo;
|
||||
struct GlyphKey;
|
||||
|
||||
class ResourceStyleCacheContext
|
||||
{
|
||||
private:
|
||||
|
||||
struct Impl;
|
||||
Impl * m_impl;
|
||||
|
||||
/// noncopyable
|
||||
ResourceStyleCacheContext(ResourceStyleCacheContext const & src);
|
||||
ResourceStyleCacheContext const & operator=(ResourceStyleCacheContext const & src);
|
||||
|
||||
public:
|
||||
|
||||
ResourceStyleCacheContext();
|
||||
~ResourceStyleCacheContext();
|
||||
|
||||
bool hasColor(Color const & c) const;
|
||||
void addColor(Color const & c);
|
||||
|
||||
bool hasPenInfo(PenInfo const & pi) const;
|
||||
void addPenInfo(PenInfo const & pi);
|
||||
|
||||
bool hasCircleInfo(CircleInfo const & ci) const;
|
||||
void addCircleInfo(CircleInfo const & ci);
|
||||
|
||||
bool hasGlyph(GlyphKey const & gk) const;
|
||||
void addGlyph(GlyphKey const & gk);
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
/// - cache of potentially all yg::ResourceStyle's
|
||||
/// - cache is build on the separate thread (CoverageGenerator thread)
|
||||
|
@ -31,7 +67,6 @@ namespace yg
|
|||
|
||||
public:
|
||||
|
||||
|
||||
ResourceStyleCache(shared_ptr<ResourceManager> const & rm,
|
||||
int glyphCacheID,
|
||||
yg::gl::PacketsQueue * glQueue);
|
||||
|
|
Loading…
Add table
Reference in a new issue