WIP: Re-enable bucket discard optimization #5921

Draft
pastk wants to merge 2 commits from pastk-drape-bucket-discard-optimization into master
7 changed files with 30 additions and 3 deletions

View file

@ -240,6 +240,7 @@ uint64_t CalculateOverlayPriority(int minZoomLevel, uint8_t rank, float depth)
// Even if minZoomLevel < 0 (-1 is not visible), we will get more consistent |minZoom| value (less is worse).
ASSERT_GREATER_OR_EQUAL(minZoomLevel, 0, ());
minZoomLevel = 0; // TMP make sure its not affecting overlays displacement
uint8_t const minZoom = 0xFF - static_cast<uint8_t>(minZoomLevel);
// Pack into uint64_t priority value (bigger is better).

View file

@ -153,6 +153,10 @@ bool RenderGroup::UpdateCanBeDeletedStatus(bool canBeDeleted, int currentZoom, r
bool visibleBucket = !canBeDeleted && (m_renderBuckets[i]->GetMinZoom() <= currentZoom);
if (!visibleBucket)
{
// TMP DEBUG output
if (m_renderBuckets[i]->GetMinZoom() > currentZoom)
LOG(LINFO, ("Removing not visible bucket", m_renderBuckets[i]->GetMinZoom(), currentZoom, GetDepthLayer(m_state), m_renderBuckets.size()));
m_renderBuckets[i]->RemoveOverlayHandles(tree);
std::swap(m_renderBuckets[i], m_renderBuckets.back());
m_renderBuckets.pop_back();

View file

@ -303,6 +303,12 @@ void RuleDrawer::ProcessAreaStyle(FeatureType & f, Stylist const & s,
applyPointStyle = m_globalRect.IsPointInside(featureCenter);
}
if (applyPointStyle || is3dBuilding)
{
// At this point a proper geometry is loaded already.
minVisibleScale = feature::GetMinDrawableScale(f); // Doesn't get passed to insertShape().
}
ApplyAreaFeature apply(m_context->GetTileKey(), insertShape, f.GetID(),
m_currentScaleGtoP, isBuilding,
m_context->Is3dBuildingsEnabled() && isBuildingOutline,
@ -446,6 +452,7 @@ void RuleDrawer::ProcessPointStyle(FeatureType & f, Stylist const & s,
if (isSpeedCamera)
depthLayer = DepthLayer::NavigationLayer;
minVisibleScale = feature::GetMinDrawableScale(f); // Doesn't get passed to insertShape().
ApplyPointFeature apply(m_context->GetTileKey(), insertShape, f.GetID(), minVisibleScale, f.GetRank(),
s.GetCaptionDescription(), 0.0f /* posZ */, depthLayer);
f.ForEachPoint([&apply](m2::PointD const & pt) { apply(pt, false /* hasArea */); }, zoomLevel);
@ -492,13 +499,14 @@ void RuleDrawer::operator()(FeatureType & f)
}
#endif
/// @todo Remove passing of minVisibleScale arg everywhere.
int minVisibleScale = 0;
auto insertShape = [this, &minVisibleScale](drape_ptr<MapShape> && shape)
//int const minVisibleScale = feature::GetMinDrawableScale(f); // original version
int const minVisibleScale = s.m_minOverlaysZoom; // lighter weight version
auto insertShape = [this, minVisibleScale](drape_ptr<MapShape> && shape)
{
size_t const index = shape->GetType();
ASSERT_LESS(index, m_mapShapes.size(), ());
// MinZoom is used for optimization in RenderGroup::UpdateCanBeDeletedStatus().
shape->SetFeatureMinZoom(minVisibleScale);
m_mapShapes[index].push_back(std::move(shape));
};

View file

@ -403,6 +403,9 @@ bool InitStylist(FeatureType & f, int8_t deviceLang, int const zoomLevel, bool b
}
}
if (mainOverlayType != 0)
s.m_minOverlaysZoom = cl.GetObject(mainOverlayType)->GetMinOverlaysZoom();
feature::FilterRulesByRuntimeSelector(f, zoomLevel, keys);
if (keys.empty())

View file

@ -55,6 +55,7 @@ public:
bool m_areaStyleExists = false;
bool m_lineStyleExists = false;
bool m_pointStyleExists = false;
int m_minOverlaysZoom = 0;
public:
CaptionDescription const & GetCaptionDescription() const;

View file

@ -54,6 +54,11 @@ void ClassifObject::AddDrawRule(drule::Key const & k)
if (k == *i)
return; // already exists
m_drawRules.insert(i, k);
if ((k.m_scale < m_minOverlaysZoom || m_minOverlaysZoom == 0) &&
(k.m_type == drule::symbol || k.m_type == drule::caption ||
k.m_type == drule::shield || k.m_type == drule::pathtext))
m_minOverlaysZoom = k.m_scale;
}
ClassifObjectPtr ClassifObject::BinaryFind(std::string_view const s) const

View file

@ -90,6 +90,9 @@ public:
std::vector<drule::Key> const & GetDrawRules() const { return m_drawRules; }
void GetSuitable(int scale, feature::GeomType gt, drule::KeysT & keys) const;
// Returns 0 if there are no overlay drules.
uint8_t GetMinOverlaysZoom() const { return m_minOverlaysZoom; }
bool IsDrawable(int scale) const;
bool IsDrawableAny() const;
bool IsDrawableLike(feature::GeomType gt, bool emptyName = false) const;
@ -161,6 +164,8 @@ private:
std::vector<drule::Key> m_drawRules;
std::vector<ClassifObject> m_objs;
VisibleMask m_visibility;
uint8_t m_minOverlaysZoom = 0;
};
inline void swap(ClassifObject & r1, ClassifObject & r2)