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
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2013-01-12 19:22:56 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:48:50 +0300
commitbb19a489f0e02a37bcf9707aa59ac8d0215ec132 (patch)
tree543715062157cfdaf567ff88b4309d3b517d1c75
parent9132a8191c5961482ad2cd06e4184e41bdc5e255 (diff)
added ability to use cacheKey's in Resource::Info.
-rw-r--r--graphics/brush.cpp5
-rw-r--r--graphics/brush.hpp1
-rw-r--r--graphics/circle.cpp5
-rw-r--r--graphics/circle.hpp1
-rw-r--r--graphics/geometry_batcher.cpp13
-rw-r--r--graphics/glyph.cpp5
-rw-r--r--graphics/glyph.hpp1
-rw-r--r--graphics/icon.cpp5
-rw-r--r--graphics/icon.hpp1
-rw-r--r--graphics/image.cpp5
-rw-r--r--graphics/image.hpp1
-rw-r--r--graphics/path_renderer.cpp2
-rw-r--r--graphics/pen.cpp19
-rw-r--r--graphics/pen.hpp4
-rw-r--r--graphics/resource.cpp8
-rw-r--r--graphics/resource.hpp6
-rw-r--r--graphics/resource_cache.cpp27
-rw-r--r--graphics/resource_cache.hpp3
-rw-r--r--map/proto_to_styles.cpp2
19 files changed, 90 insertions, 24 deletions
diff --git a/graphics/brush.cpp b/graphics/brush.cpp
index 085e30969c..c5deb829cb 100644
--- a/graphics/brush.cpp
+++ b/graphics/brush.cpp
@@ -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);
diff --git a/graphics/brush.hpp b/graphics/brush.hpp
index f4a0bc8a67..96f1abc5bb 100644
--- a/graphics/brush.hpp
+++ b/graphics/brush.hpp
@@ -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;
diff --git a/graphics/circle.cpp b/graphics/circle.cpp
index 73b7dff954..c387d43ec5 100644
--- a/graphics/circle.cpp
+++ b/graphics/circle.cpp
@@ -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;
diff --git a/graphics/circle.hpp b/graphics/circle.hpp
index 5634a36a9d..6d5a9e0b83 100644
--- a/graphics/circle.hpp
+++ b/graphics/circle.hpp
@@ -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;
diff --git a/graphics/geometry_batcher.cpp b/graphics/geometry_batcher.cpp
index 23ef749578..574abdd010 100644
--- a/graphics/geometry_batcher.cpp
+++ b/graphics/geometry_batcher.cpp
@@ -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))
diff --git a/graphics/glyph.cpp b/graphics/glyph.cpp
index 08b5c298fc..29e238dbe3 100644
--- a/graphics/glyph.cpp
+++ b/graphics/glyph.cpp
@@ -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,
diff --git a/graphics/glyph.hpp b/graphics/glyph.hpp
index f9882bcbe3..6cc6416725 100644
--- a/graphics/glyph.hpp
+++ b/graphics/glyph.hpp
@@ -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;
diff --git a/graphics/icon.cpp b/graphics/icon.cpp
index eccbc48e09..ed6d08e5fa 100644
--- a/graphics/icon.cpp
+++ b/graphics/icon.cpp
@@ -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);
diff --git a/graphics/icon.hpp b/graphics/icon.hpp
index ef2024e65f..a9279ca1e4 100644
--- a/graphics/icon.hpp
+++ b/graphics/icon.hpp
@@ -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;
diff --git a/graphics/image.cpp b/graphics/image.cpp
index 5d505ba697..03ed929799 100644
--- a/graphics/image.cpp
+++ b/graphics/image.cpp
@@ -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);
diff --git a/graphics/image.hpp b/graphics/image.hpp
index 4aaaec3117..c7a5f9a968 100644
--- a/graphics/image.hpp
+++ b/graphics/image.hpp
@@ -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;
diff --git a/graphics/path_renderer.cpp b/graphics/path_renderer.cpp
index 36fd827169..55300b66b6 100644
--- a/graphics/path_renderer.cpp
+++ b/graphics/path_renderer.cpp
@@ -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)
diff --git a/graphics/pen.cpp b/graphics/pen.cpp
index 531884be82..c004ace62a 100644
--- a/graphics/pen.cpp
+++ b/graphics/pen.cpp
@@ -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;
diff --git a/graphics/pen.hpp b/graphics/pen.hpp
index bd43783d52..2c46ee3b5e 100644
--- a/graphics/pen.hpp
+++ b/graphics/pen.hpp
@@ -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;
diff --git a/graphics/resource.cpp b/graphics/resource.cpp
index 4feaeead43..9ea7d9b297 100644
--- a/graphics/resource.cpp
+++ b/graphics/resource.cpp
@@ -9,14 +9,6 @@ namespace graphics
{}
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,
int pipelineID)
diff --git a/graphics/resource.hpp b/graphics/resource.hpp
index e3c965d356..a1e89b66e0 100644
--- a/graphics/resource.hpp
+++ b/graphics/resource.hpp
@@ -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.
diff --git a/graphics/resource_cache.cpp b/graphics/resource_cache.cpp
index 5f6b991625..aaaf15cfdf 100644
--- a/graphics/resource_cache.cpp
+++ b/graphics/resource_cache.cpp
@@ -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
diff --git a/graphics/resource_cache.hpp b/graphics/resource_cache.hpp
index 2b900d3e54..0f498b4a16 100644
--- a/graphics/resource_cache.hpp
+++ b/graphics/resource_cache.hpp
@@ -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;
diff --git a/map/proto_to_styles.cpp b/map/proto_to_styles.cpp
index 482a047196..315f2e12c5 100644
--- a/map/proto_to_styles.cpp
+++ b/map/proto_to_styles.cpp
@@ -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();
}