diff options
author | Constantin Shalnev <c.shalnev@corp.mail.ru> | 2015-08-19 13:48:15 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:01:54 +0300 |
commit | 487a28e33e7f2f4f4f26aeaffcdac379bfd0078b (patch) | |
tree | 32718246cf87e07ccdd76a58783035d0c8f6d39d | |
parent | 60952b43503ec79bb5e51e9a7cae8151bd84a162 (diff) |
Use natural-land as background color for specified scales
-rw-r--r-- | indexer/drawing_rules.cpp | 73 | ||||
-rw-r--r-- | indexer/drawing_rules.hpp | 9 | ||||
-rw-r--r-- | render/basic_tiling_render_policy.cpp | 7 | ||||
-rw-r--r-- | render/render_policy.cpp | 12 | ||||
-rw-r--r-- | render/render_policy.hpp | 5 | ||||
-rw-r--r-- | render/simple_render_policy.cpp | 2 | ||||
-rw-r--r-- | render/tile_renderer.cpp | 13 | ||||
-rw-r--r-- | render/tile_renderer.hpp | 4 | ||||
-rw-r--r-- | render/tiling_render_policy_mt.cpp | 2 | ||||
-rw-r--r-- | render/tiling_render_policy_st.cpp | 2 | ||||
-rw-r--r-- | render/yopme_render_policy.cpp | 11 | ||||
-rw-r--r-- | std/algorithm.hpp | 1 |
12 files changed, 87 insertions, 54 deletions
diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp index 35ad7de737..fa78019104 100644 --- a/indexer/drawing_rules.cpp +++ b/indexer/drawing_rules.cpp @@ -12,6 +12,7 @@ #include "std/bind.hpp" #include "std/iterator_facade.hpp" +#include "std/unordered_map.hpp" #include <google/protobuf/text_format.h> @@ -84,7 +85,7 @@ CircleRuleProto const * BaseRule::GetCircle() const } RulesHolder::RulesHolder() - : m_bgColor(DEFAULT_BG_COLOR) + : m_bgColors(scales::UPPER_STYLE_SCALE+1, DEFAULT_BG_COLOR) {} RulesHolder::~RulesHolder() @@ -135,9 +136,11 @@ BaseRule const * RulesHolder::Find(Key const & k) const return 0; } -uint32_t RulesHolder::GetBgColor() const +uint32_t RulesHolder::GetBgColor(int scale) const { - return m_bgColor; + ASSERT_LESS(scale, m_bgColors.size(), ()); + ASSERT_GREATER_OR_EQUAL(scale, 0, ()); + return m_bgColors[scale]; } void RulesHolder::ClearCaches() @@ -355,42 +358,56 @@ namespace m_names.pop_back(); } }; +} - uint32_t GetBackgroundColor(ContainerProto const & cont) - { - // WARNING! - // Background color is not specified in current format. - // Therefore, we use color of "natural-land" area element as background color. - // If such element is not present or if the element is not area then we use default background color +void RulesHolder::InitBackgroundColors(ContainerProto const & cont) +{ + // WARNING! + // Background color is not specified in current format. + // Therefore, we use color of "natural-land" area element as background color. + // If such element is not present or if the element is not area then we use default background color - uint32_t backgroundColor = DEFAULT_BG_COLOR; + // Default background color is any found color, it is used if color is not specified for scale + uint32_t bgColorDefault = DEFAULT_BG_COLOR; - // Find the "natural-land" classification element - for (int i = 0; i < cont.cont_size(); ++i) + // Background colors specified for scales + unordered_map<int, uint32_t> bgColorForScale; + + // Find the "natural-land" classification element + for (int i = 0; i < cont.cont_size(); ++i) + { + ClassifElementProto const & ce = cont.cont(i); + if (ce.name() == "natural-land") { - ClassifElementProto const & ce = cont.cont(i); - if (ce.name() == "natural-land") + // Take any area draw element + for (int j = 0; j < ce.element_size(); ++j) { - // Take any area draw element - for (int j = 0; j < ce.element_size(); ++j) + DrawElementProto const & de = ce.element(j); + if (de.has_area()) { - DrawElementProto const & de = ce.element(j); - if (de.has_area()) + // Take the color of the draw element + AreaRuleProto const & rule = de.area(); + if (rule.has_color()) { - // Take the color of the draw element - AreaRuleProto const & rule = de.area(); - if (rule.has_color()) - { - backgroundColor = rule.color(); - break; - } + bgColorDefault = rule.color(); + + if (de.has_scale()) + bgColorForScale.insert(make_pair(de.scale(), rule.color())); } } - break; } + break; } + } - return backgroundColor; + ASSERT_EQUAL(m_bgColors.size(), scales::UPPER_STYLE_SCALE+1, ()); + for (int scale = 0; scale <= scales::UPPER_STYLE_SCALE; ++scale) + { + auto const i = bgColorForScale.find(scale); + if (bgColorForScale.end() != i) + m_bgColors[scale] = i->second; + else + m_bgColors[scale] = bgColorDefault; } } @@ -404,7 +421,7 @@ void RulesHolder::LoadFromBinaryProto(string const & s) classif().GetMutableRoot()->ForEachObject(ref(doSet)); - m_bgColor = GetBackgroundColor(doSet.m_cont); + InitBackgroundColors(doSet.m_cont); } void LoadRules() diff --git a/indexer/drawing_rules.hpp b/indexer/drawing_rules.hpp index 57b0aa0e6e..a72b764f99 100644 --- a/indexer/drawing_rules.hpp +++ b/indexer/drawing_rules.hpp @@ -17,6 +17,7 @@ class AreaRuleProto; class SymbolRuleProto; class CaptionDefProto; class CircleRuleProto; +class ContainerProto; namespace drule @@ -60,7 +61,8 @@ namespace drule typedef map<int32_t, array<vector<uint32_t>, count_of_rules> > rules_map_t; rules_map_t m_rules; - uint32_t m_bgColor; + /// background color for scales in range [0...scales::UPPER_STYLE_SCALE] + vector<uint32_t> m_bgColors; public: RulesHolder(); @@ -75,7 +77,7 @@ namespace drule BaseRule const * Find(Key const & k) const; - uint32_t GetBgColor() const; + uint32_t GetBgColor(int scale = 0) const; #ifdef OMIM_OS_DESKTOP void LoadFromTextProto(string const & buffer); @@ -99,6 +101,9 @@ namespace drule } } } + + private: + void InitBackgroundColors(ContainerProto const & cp); }; RulesHolder & rules(); diff --git a/render/basic_tiling_render_policy.cpp b/render/basic_tiling_render_policy.cpp index 9b8d87bcff..e43963df11 100644 --- a/render/basic_tiling_render_policy.cpp +++ b/render/basic_tiling_render_policy.cpp @@ -82,8 +82,13 @@ void BasicTilingRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e, Screen graphics::Screen * pScreen = GPUDrawer::GetScreen(e->drawer()); + ScalesProcessor scales; + scales.SetParams(VisualScale(), m_TileSize); + int const drawingScale = scales.GetDrawTileScale(s); + ASSERT(0 <= drawingScale && drawingScale < m_bgColors.size(), ()); + pScreen->beginFrame(); - pScreen->clear(m_bgColor); + pScreen->clear(m_bgColors[drawingScale]); FrameLock(); diff --git a/render/render_policy.cpp b/render/render_policy.cpp index 1b715705ea..1dacc016da 100644 --- a/render/render_policy.cpp +++ b/render/render_policy.cpp @@ -31,13 +31,16 @@ RenderPolicy::~RenderPolicy() RenderPolicy::RenderPolicy(Params const & p, size_t idCacheSize) - : m_bgColor(ConvertColor(drule::rules().GetBgColor())), - m_primaryRC(p.m_primaryRC), + : m_primaryRC(p.m_primaryRC), m_doForceUpdate(false), m_density(p.m_density), m_visualScale(graphics::visualScale(p.m_density)), m_skinName(p.m_skinName) { + m_bgColors.resize(scales::UPPER_STYLE_SCALE+1); + for (int scale = 0; scale <= scales::UPPER_STYLE_SCALE; ++scale) + m_bgColors[scale] = ConvertColor(drule::rules().GetBgColor(scale)); + LOG(LDEBUG, ("each BaseRule will hold up to", idCacheSize, "cached values")); drule::rules().ResizeCaches(idCacheSize); @@ -235,11 +238,6 @@ graphics::Overlay * RenderPolicy::FrameOverlay() const return NULL; } -graphics::Color const RenderPolicy::GetBgColor() const -{ - return m_bgColor; -} - shared_ptr<graphics::Screen> const & RenderPolicy::GetCacheScreen() const { return m_cacheScreen; diff --git a/render/render_policy.hpp b/render/render_policy.hpp index 291b93c6dd..53748228d9 100644 --- a/render/render_policy.hpp +++ b/render/render_policy.hpp @@ -10,6 +10,7 @@ #include "std/function.hpp" #include "std/shared_ptr.hpp" +#include "std/vector.hpp" class PaintEvent; @@ -50,7 +51,7 @@ public: protected: - graphics::Color m_bgColor; + vector<graphics::Color> m_bgColors; shared_ptr<graphics::ResourceManager> m_resourceManager; shared_ptr<graphics::Skin> m_skin; shared_ptr<graphics::Screen> m_cacheScreen; @@ -157,8 +158,6 @@ public: virtual int InsertBenchmarkFence(); virtual void JoinBenchmarkFence(int fenceID); - graphics::Color const GetBgColor() const; - shared_ptr<graphics::Screen> const & GetCacheScreen() const; shared_ptr<graphics::ResourceManager> const & GetResourceManager() const { return m_resourceManager; } shared_ptr<graphics::RenderContext> const & GetRenderContext() const { return m_primaryRC; } diff --git a/render/simple_render_policy.cpp b/render/simple_render_policy.cpp index fc10dd3366..44beb2add0 100644 --- a/render/simple_render_policy.cpp +++ b/render/simple_render_policy.cpp @@ -66,7 +66,7 @@ void SimpleRenderPolicy::DrawFrame(shared_ptr<PaintEvent> const & e, pScreen->setOverlay(storage); pScreen->beginFrame(); - pScreen->clear(m_bgColor); + pScreen->clear(m_bgColors[0]); m_renderFn(e, s, s.PixelRect(), ScalesProcessor().GetTileScaleBase(s)); diff --git a/render/tile_renderer.cpp b/render/tile_renderer.cpp index b516a02ead..338fcad612 100644 --- a/render/tile_renderer.cpp +++ b/render/tile_renderer.cpp @@ -1,5 +1,6 @@ #include "tile_renderer.hpp" #include "window_handle.hpp" +#include "scales_processor.hpp" #include "graphics/opengl/opengl.hpp" #include "graphics/opengl/gl_render_context.hpp" @@ -50,7 +51,7 @@ TileRenderer::TileSizeT TileRenderer::GetTileSizes() const TileRenderer::TileRenderer( size_t tileSize, unsigned executorsCount, - graphics::Color const & bgColor, + vector<graphics::Color> const & bgColors, RenderPolicy::TRenderFn const & renderFn, shared_ptr<graphics::RenderContext> const & primaryRC, shared_ptr<graphics::ResourceManager> const & rm, @@ -59,7 +60,7 @@ TileRenderer::TileRenderer( : m_queue(executorsCount) , m_tileSize(tileSize) , m_renderFn(renderFn) - , m_bgColor(bgColor) + , m_bgColors(bgColors) , m_sequenceID(0) , m_isPaused(false) { @@ -168,6 +169,7 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env, ScreenBase frameScreen; TileSizeT const tileSz = GetTileSizes(); + ASSERT_EQUAL(tileSz.first, tileSz.second, ()); m2::RectI renderRect(1, 1, tileSz.first - 1, tileSz.second - 1); @@ -186,10 +188,15 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env, graphics::Screen * pScreen = drawer->Screen(); + ScalesProcessor scales; + scales.SetParams(drawer->VisualScale(), tileSz.first); + int const drawingScale = scales.GetDrawTileScale(rectInfo.m_tileScale); + ASSERT(0 <= drawingScale && drawingScale < m_bgColors.size(), ()); + pScreen->setOverlay(tileOverlay); pScreen->beginFrame(); pScreen->setClipRect(renderRect); - pScreen->clear(m_bgColor); + pScreen->clear(m_bgColors[drawingScale]); frameScreen.SetFromRect(m2::AnyRectD(rectInfo.m_rect)); diff --git a/render/tile_renderer.hpp b/render/tile_renderer.hpp index c467140053..2e689e1c42 100644 --- a/render/tile_renderer.hpp +++ b/render/tile_renderer.hpp @@ -61,7 +61,7 @@ protected: TileSizeT GetTileSizes() const; RenderPolicy::TRenderFn m_renderFn; - graphics::Color m_bgColor; + vector<graphics::Color> m_bgColors; int m_sequenceID; bool m_isPaused; @@ -83,7 +83,7 @@ public: /// constructor. TileRenderer(size_t tileSize, unsigned tasksCount, - graphics::Color const & bgColor, + vector<graphics::Color> const & bgColors, RenderPolicy::TRenderFn const & renderFn, shared_ptr<graphics::RenderContext> const & primaryRC, shared_ptr<graphics::ResourceManager> const & rm, diff --git a/render/tiling_render_policy_mt.cpp b/render/tiling_render_policy_mt.cpp index b1200e4c0a..615579389f 100644 --- a/render/tiling_render_policy_mt.cpp +++ b/render/tiling_render_policy_mt.cpp @@ -67,7 +67,7 @@ void TilingRenderPolicyMT::SetRenderFn(TRenderFn const & renderFn) { m_TileRenderer.reset(new TileRenderer(TileSize(), GetPlatform().CpuCores(), - m_bgColor, + m_bgColors, renderFn, m_primaryRC, m_resourceManager, diff --git a/render/tiling_render_policy_st.cpp b/render/tiling_render_policy_st.cpp index d70482aeb0..e88134c8cf 100644 --- a/render/tiling_render_policy_st.cpp +++ b/render/tiling_render_policy_st.cpp @@ -97,7 +97,7 @@ void TilingRenderPolicyST::SetRenderFn(TRenderFn const & renderFn) m_TileRenderer.reset(new TileRenderer(TileSize(), cpuCores, - m_bgColor, + m_bgColors, renderFn, m_primaryRC, m_resourceManager, diff --git a/render/yopme_render_policy.cpp b/render/yopme_render_policy.cpp index 2ea62e5948..e91a1d6b74 100644 --- a/render/yopme_render_policy.cpp +++ b/render/yopme_render_policy.cpp @@ -14,6 +14,7 @@ #include "base/matrix.hpp" +#include "std/algorithm.hpp" #include "std/vector.hpp" @@ -86,7 +87,7 @@ YopmeRP::YopmeRP(RenderPolicy::Params const & p) , m_drawMyPosition(false) { LOG(LDEBUG, ("Yopme render policy created")); - m_bgColor = graphics::Color(0xFF, 0xFF, 0xFF, 0xFF); + fill(m_bgColors.begin(), m_bgColors.end(), graphics::Color(0xFF, 0xFF, 0xFF, 0xFF)); ResourceManager::Params rmp = p.m_rmParams; @@ -203,7 +204,7 @@ void YopmeRP::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s) pScreen->setOverlay(overlay); pScreen->beginFrame(); pScreen->setClipRect(renderRect); - pScreen->clear(m_bgColor); + pScreen->clear(m_bgColors[0]); shared_ptr<PaintEvent> paintEvent(new PaintEvent(m_offscreenDrawer.get())); m_renderFn(paintEvent, s, m2::RectD(renderRect), ScalesProcessor().GetTileScaleBase(s)); @@ -217,7 +218,7 @@ void YopmeRP::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s) drawOverlay->merge(overlay); pScreen->applySharpStates(); - pScreen->clear(m_bgColor, false); + pScreen->clear(m_bgColors[0], false); math::Matrix<double, 3, 3> const m = math::Identity<double, 3>(); drawOverlay->forEach([&pScreen, &m](shared_ptr<OverlayElement> const & e) @@ -240,12 +241,12 @@ void YopmeRP::DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s) info.m_depth = minDepth; pScreen->beginFrame(); - pScreen->clear(m_bgColor); + pScreen->clear(m_bgColors[0]); pScreen->applyBlitStates(); pScreen->blit(&info, 1, true); - pScreen->clear(m_bgColor, false); + pScreen->clear(m_bgColors[0], false); if (m_drawMyPosition) DrawCircle(pScreen, m_myPositionPoint); diff --git a/std/algorithm.hpp b/std/algorithm.hpp index 913e1c0482..b77cd4ff4c 100644 --- a/std/algorithm.hpp +++ b/std/algorithm.hpp @@ -9,6 +9,7 @@ using std::all_of; using std::binary_search; using std::equal; +using std::fill; using std::find; using std::find_if; using std::find_first_of; |