forked from organicmaps/organicmaps
added ability to use cacheKey's in Resource::Info.
This commit is contained in:
parent
9132a8191c
commit
bb19a489f0
19 changed files with 90 additions and 24 deletions
|
@ -12,6 +12,11 @@ namespace graphics
|
|||
m_color(color)
|
||||
{}
|
||||
|
||||
Resource::Info const & Brush::Info::cacheKey() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
m2::PointU const Brush::Info::resourceSize() const
|
||||
{
|
||||
return m2::PointU(2, 2);
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace graphics
|
|||
Info();
|
||||
explicit Info(Color const & color);
|
||||
|
||||
Resource::Info const & cacheKey() const;
|
||||
m2::PointU const resourceSize() const;
|
||||
Resource * createResource(m2::RectU const & texRect,
|
||||
uint8_t pipelineID) const;
|
||||
|
|
|
@ -52,6 +52,11 @@ namespace graphics
|
|||
return false;
|
||||
}
|
||||
|
||||
Resource::Info const & Circle::Info::cacheKey() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
m2::PointU const Circle::Info::resourceSize() const
|
||||
{
|
||||
unsigned r = m_isOutlined ? m_radius + m_outlineWidth : m_radius;
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace graphics
|
|||
double outlineWidth = 1,
|
||||
Color const & outlineColor = Color(255, 255, 255, 255));
|
||||
|
||||
Resource::Info const & cacheKey() const;
|
||||
m2::PointU const resourceSize() const;
|
||||
Resource * createResource(m2::RectU const & texRect,
|
||||
uint8_t pipelineID) const;
|
||||
|
|
|
@ -729,9 +729,20 @@ namespace graphics
|
|||
|
||||
for (uint8_t i = 0; i < pipelinesCount(); ++i)
|
||||
{
|
||||
res = pipeline(i).cache()->findInfo(info);
|
||||
ResourceCache * cache = pipeline(i).cache().get();
|
||||
res = cache->findInfo(info);
|
||||
if (res != invalidPageHandle())
|
||||
return packID(i, res);
|
||||
else
|
||||
{
|
||||
/// trying to find cacheKey
|
||||
res = cache->findInfo(info.cacheKey());
|
||||
if (res != invalidPageHandle())
|
||||
{
|
||||
cache->addParentInfo(info);
|
||||
return packID(i, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pipeline(m_dynamicPage).cache()->hasRoom(info))
|
||||
|
|
|
@ -19,6 +19,11 @@ namespace graphics
|
|||
m_metrics = m_cache->getGlyphMetrics(m_key);
|
||||
}
|
||||
|
||||
Resource::Info const & Glyph::Info::cacheKey() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
m2::PointU const Glyph::Info::resourceSize() const
|
||||
{
|
||||
return m2::PointU(m_metrics.m_width + 4,
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace graphics
|
|||
Info(GlyphKey const & key,
|
||||
GlyphCache * cache);
|
||||
|
||||
Resource::Info const & cacheKey() const;
|
||||
m2::PointU const resourceSize() const;
|
||||
Resource * createResource(m2::RectU const & texRect,
|
||||
uint8_t pipelineID) const;
|
||||
|
|
|
@ -11,6 +11,11 @@ namespace graphics
|
|||
m_name(name)
|
||||
{}
|
||||
|
||||
Resource::Info const & Icon::Info::cacheKey() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
m2::PointU const Icon::Info::resourceSize() const
|
||||
{
|
||||
return m2::PointU(0, 0);
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace graphics
|
|||
Info();
|
||||
Info(string const & name);
|
||||
|
||||
Resource::Info const & cacheKey() const;
|
||||
m2::PointU const resourceSize() const;
|
||||
Resource * createResource(m2::RectU const & texRect,
|
||||
uint8_t pipelineID) const;
|
||||
|
|
|
@ -65,6 +65,11 @@ namespace graphics
|
|||
return false;
|
||||
}
|
||||
|
||||
Resource::Info const & Image::Info::cacheKey() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
m2::PointU const Image::Info::resourceSize() const
|
||||
{
|
||||
return m2::PointU(m_size.x + 4, m_size.y + 4);
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace graphics
|
|||
unsigned height() const;
|
||||
unsigned char const * data() const;
|
||||
|
||||
Resource::Info const & cacheKey() const;
|
||||
m2::PointU const resourceSize() const;
|
||||
Resource * createResource(m2::RectU const & texRect,
|
||||
uint8_t pipelineID) const;
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace graphics
|
|||
|
||||
Pen const * pen = static_cast<Pen const *>(res);
|
||||
|
||||
if (!pen->m_info.m_symbol.empty())
|
||||
if (!pen->m_info.m_icon.m_name.empty())
|
||||
drawSymbolPath(pts, ptsCount, offset, pen, depth);
|
||||
else
|
||||
if (m_fastSolidPath && pen->m_isSolid)
|
||||
|
|
|
@ -30,12 +30,12 @@ namespace graphics
|
|||
m_isSolid(false)
|
||||
{
|
||||
if (symbol != 0)
|
||||
m_symbol = string(symbol);
|
||||
m_icon = Icon::Info(symbol);
|
||||
|
||||
if (m_w < 1.0)
|
||||
m_w = 1.0;
|
||||
|
||||
if (!m_symbol.empty())
|
||||
if (!m_icon.m_name.empty())
|
||||
{
|
||||
m_isSolid = false;
|
||||
}
|
||||
|
@ -130,8 +130,19 @@ namespace graphics
|
|||
return false;
|
||||
}
|
||||
|
||||
Resource::Info const & Pen::Info::cacheKey() const
|
||||
{
|
||||
if (!m_icon.m_name.empty())
|
||||
return m_icon;
|
||||
else
|
||||
return *this;
|
||||
}
|
||||
|
||||
m2::PointU const Pen::Info::resourceSize() const
|
||||
{
|
||||
if (!m_icon.m_name.empty())
|
||||
return m_icon.resourceSize();
|
||||
|
||||
if (m_isSolid)
|
||||
return m2::PointU(static_cast<uint32_t>(ceil(m_w / 2)) * 2 + 4,
|
||||
static_cast<uint32_t>(ceil(m_w / 2)) * 2 + 4);
|
||||
|
@ -175,8 +186,8 @@ namespace graphics
|
|||
return m_join < rp->m_join;
|
||||
if (m_cap != rp->m_cap)
|
||||
return m_cap < rp->m_cap;
|
||||
if (m_symbol != rp->m_symbol)
|
||||
return m_symbol < rp->m_symbol;
|
||||
if (m_icon.m_name != rp->m_icon.m_name)
|
||||
return m_icon.m_name < rp->m_icon.m_name;
|
||||
if (m_step != rp->m_step)
|
||||
return m_step < rp->m_step;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "resource.hpp"
|
||||
#include "icon.hpp"
|
||||
#include "color.hpp"
|
||||
|
||||
#include "../geometry/point2d.hpp"
|
||||
|
@ -34,7 +35,7 @@ namespace graphics
|
|||
double m_w;
|
||||
TPattern m_pat;
|
||||
double m_offset;
|
||||
string m_symbol;
|
||||
Icon::Info m_icon;
|
||||
double m_step;
|
||||
ELineJoin m_join;
|
||||
ELineCap m_cap;
|
||||
|
@ -54,6 +55,7 @@ namespace graphics
|
|||
double firstDashOffset() const;
|
||||
bool atDashOffset(double offset) const;
|
||||
|
||||
Resource::Info const & cacheKey() const;
|
||||
m2::PointU const resourceSize() const;
|
||||
Resource * createResource(m2::RectU const & texRect,
|
||||
uint8_t pipelineID) const;
|
||||
|
|
|
@ -8,14 +8,6 @@ namespace graphics
|
|||
: m_category(cat)
|
||||
{}
|
||||
|
||||
Resource::Resource(
|
||||
m2::RectU const & texRect,
|
||||
int pipelineID
|
||||
) : m_cat(EUnknown),
|
||||
m_texRect(texRect),
|
||||
m_pipelineID(pipelineID)
|
||||
{}
|
||||
|
||||
Resource::Resource(
|
||||
Category cat,
|
||||
m2::RectU const & texRect,
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace graphics
|
|||
Category m_category;
|
||||
|
||||
Info(Category cat);
|
||||
|
||||
virtual Info const & cacheKey() const = 0;
|
||||
/// returns the size of this resource info which will
|
||||
/// be occupied in texture cache.
|
||||
virtual m2::PointU const resourceSize() const = 0;
|
||||
|
@ -39,10 +41,6 @@ namespace graphics
|
|||
m2::RectU m_texRect;
|
||||
int m_pipelineID;
|
||||
|
||||
Resource();
|
||||
Resource(m2::RectU const & texRect,
|
||||
int pipelineID);
|
||||
|
||||
virtual ~Resource();
|
||||
virtual void render(void * dst) = 0;
|
||||
/// get key for ResourceCache.
|
||||
|
|
|
@ -106,6 +106,18 @@ namespace graphics
|
|||
return h;
|
||||
}
|
||||
|
||||
void ResourceCache::addParentInfo(Resource::Info const & fullInfo)
|
||||
{
|
||||
uint32_t id = findInfo(fullInfo.cacheKey());
|
||||
|
||||
Resource * r = fromID(id);
|
||||
|
||||
shared_ptr<Resource> resource(fullInfo.createResource(r->m_texRect, r->m_pipelineID));
|
||||
|
||||
m_parentResources[id] = resource;
|
||||
m_infos[resource->info()] = id;
|
||||
}
|
||||
|
||||
bool ResourceCache::hasRoom(Resource::Info const & info) const
|
||||
{
|
||||
m2::PointU sz = info.resourceSize();
|
||||
|
@ -157,12 +169,19 @@ namespace graphics
|
|||
|
||||
Resource * ResourceCache::fromID(uint32_t idx) const
|
||||
{
|
||||
TResources::const_iterator it = m_resources.find(idx);
|
||||
TResources::const_iterator it = m_parentResources.find(idx);
|
||||
|
||||
if (it == m_resources.end())
|
||||
return 0;
|
||||
else
|
||||
it = m_parentResources.find(idx);
|
||||
|
||||
if (it != m_parentResources.end())
|
||||
return it->second.get();
|
||||
|
||||
it = m_resources.find(idx);
|
||||
|
||||
if (it != m_resources.end())
|
||||
return it->second.get();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
shared_ptr<gl::BaseTexture> const & ResourceCache::texture() const
|
||||
|
|
|
@ -31,7 +31,9 @@ namespace graphics
|
|||
private:
|
||||
|
||||
typedef map<uint32_t, shared_ptr<Resource> > TResources;
|
||||
|
||||
TResources m_resources;
|
||||
TResources m_parentResources;
|
||||
|
||||
struct LessThan
|
||||
{
|
||||
|
@ -95,6 +97,7 @@ namespace graphics
|
|||
|
||||
uint32_t findInfo(Resource::Info const & info) const;
|
||||
uint32_t mapInfo(Resource::Info const & info);
|
||||
void addParentInfo(Resource::Info const & fullInfo);
|
||||
bool hasRoom(Resource::Info const & info) const;
|
||||
|
||||
Resource * fromID(uint32_t idx) const;
|
||||
|
|
|
@ -51,7 +51,7 @@ void ConvertStyle(LineDefProto const * pSrc, double scale, graphics::Pen::Info &
|
|||
PathSymProto const & ps = pSrc->pathsym();
|
||||
|
||||
dest.m_step = ps.step();
|
||||
dest.m_symbol = ps.name();
|
||||
dest.m_icon.m_name = ps.name();
|
||||
dest.m_offset = ps.offset();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue