diff --git a/drape/overlay_handle.cpp b/drape/overlay_handle.cpp index 838dd9e300..4d622ea5b6 100644 --- a/drape/overlay_handle.cpp +++ b/drape/overlay_handle.cpp @@ -88,11 +88,10 @@ void OverlayHandle::GetElementIndexes(ref_ptr mutator) const } void OverlayHandle::GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen, bool isVisible) const + ScreenBase const & screen) const { UNUSED_VALUE(mutator); UNUSED_VALUE(screen); - UNUSED_VALUE(isVisible); } bool OverlayHandle::HasDynamicAttributes() const diff --git a/drape/overlay_handle.hpp b/drape/overlay_handle.hpp index a02500c77a..cd38cc01f6 100644 --- a/drape/overlay_handle.hpp +++ b/drape/overlay_handle.hpp @@ -46,7 +46,7 @@ public: void * IndexStorage(uint32_t size); void GetElementIndexes(ref_ptr mutator) const; virtual void GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen, bool isVisible) const; + ScreenBase const & screen) const; bool HasDynamicAttributes() const; void AddDynamicAttribute(BindingInfo const & binding, uint32_t offset, uint32_t count); diff --git a/drape/render_bucket.cpp b/drape/render_bucket.cpp index 1c4243a9cd..b4d0fb0dce 100644 --- a/drape/render_bucket.cpp +++ b/drape/render_bucket.cpp @@ -94,7 +94,7 @@ void RenderBucket::Render(ScreenBase const & screen) } if (handle->HasDynamicAttributes()) - handle->GetAttributeMutation(rfpAttrib, screen, handle->IsVisible()); + handle->GetAttributeMutation(rfpAttrib, screen); } } diff --git a/drape_frontend/gui/gui_text.cpp b/drape_frontend/gui/gui_text.cpp index 79d7382f4b..c8c7d915cc 100644 --- a/drape_frontend/gui/gui_text.cpp +++ b/drape_frontend/gui/gui_text.cpp @@ -444,10 +444,9 @@ MutableLabelHandle::MutableLabelHandle(dp::Anchor anchor, m2::PointF const & piv } void MutableLabelHandle::GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen, bool isVisible) const + ScreenBase const & screen) const { UNUSED_VALUE(screen); - UNUSED_VALUE(isVisible); if (!m_isContentDirty) return; diff --git a/drape_frontend/gui/gui_text.hpp b/drape_frontend/gui/gui_text.hpp index bd8d6eab91..5cc8c42468 100644 --- a/drape_frontend/gui/gui_text.hpp +++ b/drape_frontend/gui/gui_text.hpp @@ -144,7 +144,7 @@ public: MutableLabelHandle(dp::Anchor anchor, m2::PointF const & pivot); void GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen, bool isVisible) const override; + ScreenBase const & screen) const override; ref_ptr GetTextView(); void UpdateSize(m2::PointF const & size); diff --git a/drape_frontend/gui/shape.cpp b/drape_frontend/gui/shape.cpp index 8b56676d07..b61f0be337 100644 --- a/drape_frontend/gui/shape.cpp +++ b/drape_frontend/gui/shape.cpp @@ -101,7 +101,7 @@ void ShapeRenderer::Render(ScreenBase const & screen, ref_ptr mutatorRef = make_ref(&mutator); - info.m_handle->GetAttributeMutation(mutatorRef, screen, true /* isVisible */); + info.m_handle->GetAttributeMutation(mutatorRef, screen); info.m_buffer->ApplyMutation(nullptr, mutatorRef); } diff --git a/drape_frontend/path_text_shape.cpp b/drape_frontend/path_text_shape.cpp index eb437c2d86..c1d5a0dae6 100644 --- a/drape_frontend/path_text_shape.cpp +++ b/drape_frontend/path_text_shape.cpp @@ -42,7 +42,7 @@ public: m_normals.resize(4 * m_layout->GetGlyphCount()); } - void Update(ScreenBase const & screen) + void Update(ScreenBase const & screen) override { if (m_layout->CacheDynamicGeometry(m_centerPointIter, screen, m_normals)) { @@ -53,11 +53,11 @@ public: SetIsValid(false); } - m2::RectD GetPixelRect(ScreenBase const & screen) const + m2::RectD GetPixelRect(ScreenBase const & screen) const override { ASSERT(IsValid(), ()); - m2::PointD pixelPivot(screen.GtoP(m_centerPointIter.m_pos)); + m2::PointD const pixelPivot(screen.GtoP(m_centerPointIter.m_pos)); m2::RectD result; for (gpu::TextDynamicVertex const & v : m_normals) result.Add(pixelPivot + glsl::ToPoint(v.m_normal)); @@ -65,11 +65,11 @@ public: return result; } - void GetPixelShape(ScreenBase const & screen, Rects & rects) const + void GetPixelShape(ScreenBase const & screen, Rects & rects) const override { ASSERT(IsValid(), ()); - m2::PointD pixelPivot(screen.GtoP(m_centerPointIter.m_pos)); + m2::PointD const pixelPivot(screen.GtoP(m_centerPointIter.m_pos)); for (size_t quadIndex = 0; quadIndex < m_normals.size(); quadIndex += 4) { m2::RectF r; @@ -81,6 +81,14 @@ public: } } + void GetAttributeMutation(ref_ptr mutator, + ScreenBase const & screen) const override + { + // for visible text paths we always update normals + SetForceUpdateNormals(IsVisible()); + TextHandle::GetAttributeMutation(mutator, screen); + } + private: m2::SharedSpline m_spline; m2::Spline::iterator m_centerPointIter; diff --git a/drape_frontend/text_handle.cpp b/drape_frontend/text_handle.cpp index 53c05087cb..549e559d21 100644 --- a/drape_frontend/text_handle.cpp +++ b/drape_frontend/text_handle.cpp @@ -3,12 +3,30 @@ namespace df { +TextHandle::TextHandle(FeatureID const & id, dp::Anchor anchor, double priority) + : OverlayHandle(id, anchor, priority) + , m_forceUpdateNormals(false) + , m_isLastVisible(false) +{} + +TextHandle::TextHandle(FeatureID const & id, dp::Anchor anchor, double priority, + gpu::TTextDynamicVertexBuffer && normals) + : OverlayHandle(id, anchor, priority) + , m_normals(move(normals)) + , m_forceUpdateNormals(false) + , m_isLastVisible(false) +{} + void TextHandle::GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen, bool isVisible) const + ScreenBase const & screen) const { ASSERT(IsValid(), ()); UNUSED_VALUE(screen); + bool const isVisible = IsVisible(); + if (!m_forceUpdateNormals && m_isLastVisible == isVisible) + return; + TOffsetNode const & node = GetOffsetNode(gpu::TextDynamicVertex::GetDynamicStreamID()); ASSERT(node.first.GetElementSize() == sizeof(gpu::TextDynamicVertex), ()); ASSERT(node.second.m_count == m_normals.size(), ()); @@ -24,6 +42,8 @@ void TextHandle::GetAttributeMutation(ref_ptr mutato mutateNode.m_region = node.second; mutateNode.m_data = make_ref(buffer); mutator->AddMutation(node.first, mutateNode); + + m_isLastVisible = isVisible; } bool TextHandle::IndexesRequired() const @@ -31,4 +51,9 @@ bool TextHandle::IndexesRequired() const return false; } +void TextHandle::SetForceUpdateNormals(bool forceUpdate) const +{ + m_forceUpdateNormals = forceUpdate; +} + } // namespace df diff --git a/drape_frontend/text_handle.hpp b/drape_frontend/text_handle.hpp index 523492ef69..55d3e8a8d5 100644 --- a/drape_frontend/text_handle.hpp +++ b/drape_frontend/text_handle.hpp @@ -9,23 +9,24 @@ namespace df class TextHandle : public dp::OverlayHandle { public: - TextHandle(FeatureID const & id, dp::Anchor anchor, double priority) - : OverlayHandle(id, anchor, priority) - {} + TextHandle(FeatureID const & id, dp::Anchor anchor, double priority); TextHandle(FeatureID const & id, dp::Anchor anchor, double priority, - gpu::TTextDynamicVertexBuffer && normals) - : OverlayHandle(id, anchor, priority) - , m_normals(move(normals)) - {} + gpu::TTextDynamicVertexBuffer && normals); void GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen, bool isVisible) const override; + ScreenBase const & screen) const override; bool IndexesRequired() const override; + void SetForceUpdateNormals(bool forceUpdate) const; + protected: gpu::TTextDynamicVertexBuffer m_normals; + mutable bool m_forceUpdateNormals; + +private: + mutable bool m_isLastVisible; }; diff --git a/drape_frontend/text_shape.cpp b/drape_frontend/text_shape.cpp index 0d2485eda6..2fb0f8e79c 100644 --- a/drape_frontend/text_shape.cpp +++ b/drape_frontend/text_shape.cpp @@ -137,8 +137,7 @@ void TextShape::DrawSubString(StraightTextLayout const & layout, state.SetColorTexture(color.GetTexture()); state.SetMaskTexture(layout.GetMaskTexture()); - gpu::TTextDynamicVertexBuffer initialDynBuffer; - initialDynBuffer.resize(dynamicBuffer.size(), gpu::TextDynamicVertex(glsl::vec2(0.0, 0.0))); + gpu::TTextDynamicVertexBuffer initialDynBuffer(dynamicBuffer.size()); m2::PointU const & pixelSize = layout.GetPixelSize(); drape_ptr handle = make_unique_dp(m_params.m_featureID,