forked from organicmaps/organicmaps
added DisplayListCache to cache single glyphs as a DisplayLists
This commit is contained in:
parent
8a0e351f2f
commit
2807f21e5f
2 changed files with 85 additions and 0 deletions
51
gui/display_list_cache.cpp
Normal file
51
gui/display_list_cache.cpp
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
34
gui/display_list_cache.hpp
Normal file
34
gui/display_list_cache.hpp
Normal file
|
@ -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);
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue