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
path: root/gui
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2013-03-30 00:18:06 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:52:37 +0300
commit2807f21e5f2b8534b2dd99ac3bb3140184532365 (patch)
treeb0eaf6260a14438eafa88036116641e1c1899250 /gui
parent8a0e351f2fad2004df7e6d28f976a0820fe005c5 (diff)
added DisplayListCache to cache single glyphs as a DisplayLists
Diffstat (limited to 'gui')
-rw-r--r--gui/display_list_cache.cpp51
-rw-r--r--gui/display_list_cache.hpp34
2 files changed, 85 insertions, 0 deletions
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<graphics::DisplayList> 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<graphics::DisplayList> & 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<graphics::Glyph const *>(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<graphics::GlyphKey, shared_ptr<graphics::DisplayList> > 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<graphics::DisplayList> const & FindGlyph(graphics::GlyphKey const & key);
+ /// Check, whether the glyph is present in cache.
+ bool HasGlyph(graphics::GlyphKey const & key);
+ };
+}