diff --git a/yg/resource_style_cache.cpp b/yg/resource_style_cache.cpp index e150655ebf..33c260418b 100644 --- a/yg/resource_style_cache.cpp +++ b/yg/resource_style_cache.cpp @@ -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 TPenInfoSet; + TPenInfoSet m_penInfoSet; + + typedef set TCircleInfoSet; + TCircleInfoSet m_circleInfoSet; + + typedef set TColorSet; + TColorSet m_colorSet; + + typedef set 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 const & rm, - int glyphCacheID, - yg::gl::PacketsQueue * glQueue) + int glyphCacheID, + yg::gl::PacketsQueue * glQueue) : m_rm(rm), m_glQueue(glQueue) { diff --git a/yg/resource_style_cache.hpp b/yg/resource_style_cache.hpp index 3d59109e38..b4a3f2263f 100644 --- a/yg/resource_style_cache.hpp +++ b/yg/resource_style_cache.hpp @@ -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 const & rm, int glyphCacheID, yg::gl::PacketsQueue * glQueue);