diff --git a/gui/display_list_cache.cpp b/gui/display_list_cache.cpp new file mode 100644 index 0000000000..c3da094cc0 --- /dev/null +++ b/gui/display_list_cache.cpp @@ -0,0 +1,51 @@ +#include "display_list_cache.hpp" + +#include "../graphics/display_list.hpp" +#include "../graphics/glyph.hpp" + +namespace gui +{ + DisplayListCache::DisplayListCache(graphics::Screen * CacheScreen, + graphics::GlyphCache * GlyphCache) + : m_CacheScreen(CacheScreen), + m_GlyphCache(GlyphCache) + {} + + shared_ptr const & DisplayListCache::FindGlyph(graphics::GlyphKey const & key) + { + TGlyphs::const_iterator it = m_Glyphs.find(key); + + if (it != m_Glyphs.end()) + return it->second; + + shared_ptr & dl = m_Glyphs[key]; + + dl.reset(m_CacheScreen->createDisplayList()); + + m_CacheScreen->beginFrame(); + m_CacheScreen->setDisplayList(dl.get()); + + uint32_t resID = m_CacheScreen->mapInfo(graphics::Glyph::Info(key, m_GlyphCache)); + graphics::Resource const * res = m_CacheScreen->fromID(resID); + + ASSERT(res->m_cat == graphics::Resource::EGlyph, ()); + graphics::Glyph const * glyph = static_cast(res); + + m_CacheScreen->drawGlyph(m2::PointD(0, 0), m2::PointD(0, 0), ang::AngleD(0), 0, glyph, graphics::maxDepth - 10); + + m_CacheScreen->setDisplayList(0); + m_CacheScreen->endFrame(); + + return dl; + } + + void DisplayListCache::TouchGlyph(graphics::GlyphKey const & key) + { + FindGlyph(key); + } + + bool DisplayListCache::HasGlyph(graphics::GlyphKey const & key) + { + return m_Glyphs.find(key) != m_Glyphs.end(); + } +} diff --git a/gui/display_list_cache.hpp b/gui/display_list_cache.hpp new file mode 100644 index 0000000000..c48f5b3868 --- /dev/null +++ b/gui/display_list_cache.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "../std/shared_ptr.hpp" + +#include "../graphics/screen.hpp" + +namespace gui +{ + class DisplayListCache + { + private: + + /// Screen, which should be used for caching + graphics::Screen * m_CacheScreen; + /// GlyphCache, which should be used for caching + graphics::GlyphCache * m_GlyphCache; + /// Actual cache of glyphs as a display lists + typedef map > TGlyphs; + + TGlyphs m_Glyphs; + + public: + + DisplayListCache(graphics::Screen * CacheScreen, + graphics::GlyphCache * GlyphCache); + + /// Add element to cache if need be + void TouchGlyph(graphics::GlyphKey const & key); + /// Find glyph in cache, caching if needed. + shared_ptr const & FindGlyph(graphics::GlyphKey const & key); + /// Check, whether the glyph is present in cache. + bool HasGlyph(graphics::GlyphKey const & key); + }; +}