From a2d480a4788176673f8fe828a8daf95ec874a003 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Mon, 29 Jun 2015 16:21:49 +0300 Subject: [PATCH] Disabled IB mutation in text rendering --- drape/overlay_handle.cpp | 4 +- drape/overlay_handle.hpp | 3 +- drape/render_bucket.cpp | 14 +++- drape_frontend/drape_frontend.pro | 2 + drape_frontend/gui/gui_text.cpp | 3 +- drape_frontend/gui/gui_text.hpp | 2 +- drape_frontend/gui/shape.cpp | 2 +- drape_frontend/path_text_shape.cpp | 125 +++++++++++++---------------- drape_frontend/text_handle.cpp | 34 ++++++++ drape_frontend/text_handle.hpp | 32 ++++++++ drape_frontend/text_shape.cpp | 23 +++--- 11 files changed, 155 insertions(+), 89 deletions(-) create mode 100644 drape_frontend/text_handle.cpp create mode 100644 drape_frontend/text_handle.hpp diff --git a/drape/overlay_handle.cpp b/drape/overlay_handle.cpp index 2d9c436869..838dd9e300 100644 --- a/drape/overlay_handle.cpp +++ b/drape/overlay_handle.cpp @@ -87,10 +87,12 @@ void OverlayHandle::GetElementIndexes(ref_ptr mutator) const mutator->AppendIndexes(m_indexes.GetRawConst(), m_indexes.Size()); } -void OverlayHandle::GetAttributeMutation(ref_ptr mutator, ScreenBase const & screen) const +void OverlayHandle::GetAttributeMutation(ref_ptr mutator, + ScreenBase const & screen, bool isVisible) 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 83a9707745..a02500c77a 100644 --- a/drape/overlay_handle.hpp +++ b/drape/overlay_handle.hpp @@ -45,7 +45,8 @@ public: virtual bool IndexesRequired() const { return true; } void * IndexStorage(uint32_t size); void GetElementIndexes(ref_ptr mutator) const; - virtual void GetAttributeMutation(ref_ptr mutator, ScreenBase const & screen) const; + virtual void GetAttributeMutation(ref_ptr mutator, + ScreenBase const & screen, bool isVisible) 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 2647014be9..1c4243a9cd 100644 --- a/drape/render_bucket.cpp +++ b/drape/render_bucket.cpp @@ -82,17 +82,23 @@ void RenderBucket::Render(ScreenBase const & screen) ref_ptr rfpIndex = make_ref(&indexMutator); ref_ptr rfpAttrib = make_ref(&attributeMutator); + bool hasIndexMutation = false; for (drape_ptr const & handle : m_overlay) { - if (handle->IsValid() && handle->IsVisible()) + if (handle->IsValid()) { - handle->GetElementIndexes(rfpIndex); + if (handle->IndexesRequired() && handle->IsVisible()) + { + handle->GetElementIndexes(rfpIndex); + hasIndexMutation = true; + } + if (handle->HasDynamicAttributes()) - handle->GetAttributeMutation(rfpAttrib, screen); + handle->GetAttributeMutation(rfpAttrib, screen, handle->IsVisible()); } } - m_buffer->ApplyMutation(rfpIndex, rfpAttrib); + m_buffer->ApplyMutation(hasIndexMutation ? rfpIndex : nullptr, rfpAttrib); } m_buffer->Render(); } diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index 64ac5539ad..55357dcb76 100755 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -59,6 +59,7 @@ SOURCES += \ rule_drawer.cpp \ selection_shape.cpp \ stylist.cpp \ + text_handle.cpp \ text_layout.cpp \ text_shape.cpp \ threads_commutator.cpp \ @@ -129,6 +130,7 @@ HEADERS += \ selection_shape.hpp \ shape_view_params.hpp \ stylist.hpp \ + text_handle.hpp \ text_layout.hpp \ text_shape.hpp \ threads_commutator.hpp \ diff --git a/drape_frontend/gui/gui_text.cpp b/drape_frontend/gui/gui_text.cpp index c8c7d915cc..79d7382f4b 100644 --- a/drape_frontend/gui/gui_text.cpp +++ b/drape_frontend/gui/gui_text.cpp @@ -444,9 +444,10 @@ MutableLabelHandle::MutableLabelHandle(dp::Anchor anchor, m2::PointF const & piv } void MutableLabelHandle::GetAttributeMutation(ref_ptr mutator, - ScreenBase const & screen) const + ScreenBase const & screen, bool isVisible) 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 5cc8c42468..bd8d6eab91 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) const override; + ScreenBase const & screen, bool isVisible) 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 b61f0be337..8b56676d07 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); + info.m_handle->GetAttributeMutation(mutatorRef, screen, true /* isVisible */); info.m_buffer->ApplyMutation(nullptr, mutatorRef); } diff --git a/drape_frontend/path_text_shape.cpp b/drape_frontend/path_text_shape.cpp index 6a74d349c4..eb437c2d86 100644 --- a/drape_frontend/path_text_shape.cpp +++ b/drape_frontend/path_text_shape.cpp @@ -1,4 +1,5 @@ #include "drape_frontend/path_text_shape.hpp" +#include "drape_frontend/text_handle.hpp" #include "drape_frontend/text_layout.hpp" #include "drape_frontend/visual_params.hpp" #include "drape_frontend/intrusive_vector.hpp" @@ -24,85 +25,69 @@ using m2::Spline; namespace { - class PathTextHandle : public dp::OverlayHandle + +class PathTextHandle : public df::TextHandle +{ +public: + PathTextHandle(m2::SharedSpline const & spl, + df::SharedTextLayout const & layout, + float const mercatorOffset, + float const depth) + : TextHandle(FeatureID(), dp::Center, depth) + , m_spline(spl) + , m_layout(layout) { - public: - PathTextHandle(m2::SharedSpline const & spl, - df::SharedTextLayout const & layout, - float const mercatorOffset, - float const depth) - : OverlayHandle(FeatureID(), dp::Center, depth) - , m_spline(spl) - , m_layout(layout) + m_centerPointIter = m_spline.CreateIterator(); + m_centerPointIter.Advance(mercatorOffset); + m_normals.resize(4 * m_layout->GetGlyphCount()); + } + + void Update(ScreenBase const & screen) + { + if (m_layout->CacheDynamicGeometry(m_centerPointIter, screen, m_normals)) { - m_centerPointIter = m_spline.CreateIterator(); - m_centerPointIter.Advance(mercatorOffset); - m_normals.resize(4 * m_layout->GetGlyphCount()); + SetIsValid(true); + return; } - void Update(ScreenBase const & screen) + SetIsValid(false); + } + + m2::RectD GetPixelRect(ScreenBase const & screen) const + { + ASSERT(IsValid(), ()); + + m2::PointD 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)); + + return result; + } + + void GetPixelShape(ScreenBase const & screen, Rects & rects) const + { + ASSERT(IsValid(), ()); + + m2::PointD pixelPivot(screen.GtoP(m_centerPointIter.m_pos)); + for (size_t quadIndex = 0; quadIndex < m_normals.size(); quadIndex += 4) { - if (m_layout->CacheDynamicGeometry(m_centerPointIter, screen, m_normals)) - { - SetIsValid(true); - return; - } - - SetIsValid(false); + m2::RectF r; + r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex].m_normal)); + r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex + 1].m_normal)); + r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex + 2].m_normal)); + r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex + 3].m_normal)); + rects.push_back(r); } + } - m2::RectD GetPixelRect(ScreenBase const & screen) const - { - ASSERT(IsValid(), ()); +private: + m2::SharedSpline m_spline; + m2::Spline::iterator m_centerPointIter; - m2::PointD 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)); + df::SharedTextLayout m_layout; +}; - return result; - } - - void GetPixelShape(ScreenBase const & screen, Rects & rects) const - { - ASSERT(IsValid(), ()); - - m2::PointD pixelPivot(screen.GtoP(m_centerPointIter.m_pos)); - for (size_t quadIndex = 0; quadIndex < m_normals.size(); quadIndex += 4) - { - m2::RectF r; - r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex].m_normal)); - r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex + 1].m_normal)); - r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex + 2].m_normal)); - r.Add(pixelPivot + glsl::ToPoint(m_normals[quadIndex + 3].m_normal)); - rects.push_back(r); - } - } - - void GetAttributeMutation(ref_ptr mutator, ScreenBase const & screen) const - { - ASSERT(IsValid(), ()); - - TOffsetNode const & node = GetOffsetNode(gpu::TextDynamicVertex::GetDynamicStreamID()); - ASSERT(node.first.GetElementSize() == sizeof(gpu::TextDynamicVertex), ()); - ASSERT(node.second.m_count == m_normals.size(), ()); - - uint32_t byteCount = m_normals.size() * sizeof(gpu::TextDynamicVertex); - void * buffer = mutator->AllocateMutationBuffer(byteCount); - memcpy(buffer, m_normals.data(), byteCount); - dp::MutateNode mutateNode; - mutateNode.m_region = node.second; - mutateNode.m_data = make_ref(buffer); - mutator->AddMutation(node.first, mutateNode); - } - - private: - m2::SharedSpline m_spline; - m2::Spline::iterator m_centerPointIter; - gpu::TTextDynamicVertexBuffer m_normals; - - df::SharedTextLayout m_layout; - }; } namespace df diff --git a/drape_frontend/text_handle.cpp b/drape_frontend/text_handle.cpp new file mode 100644 index 0000000000..53c05087cb --- /dev/null +++ b/drape_frontend/text_handle.cpp @@ -0,0 +1,34 @@ +#include "drape_frontend/text_handle.hpp" + +namespace df +{ + +void TextHandle::GetAttributeMutation(ref_ptr mutator, + ScreenBase const & screen, bool isVisible) const +{ + ASSERT(IsValid(), ()); + UNUSED_VALUE(screen); + + TOffsetNode const & node = GetOffsetNode(gpu::TextDynamicVertex::GetDynamicStreamID()); + ASSERT(node.first.GetElementSize() == sizeof(gpu::TextDynamicVertex), ()); + ASSERT(node.second.m_count == m_normals.size(), ()); + + uint32_t byteCount = m_normals.size() * sizeof(gpu::TextDynamicVertex); + void * buffer = mutator->AllocateMutationBuffer(byteCount); + if (isVisible) + memcpy(buffer, m_normals.data(), byteCount); + else + memset(buffer, 0, byteCount); + + dp::MutateNode mutateNode; + mutateNode.m_region = node.second; + mutateNode.m_data = make_ref(buffer); + mutator->AddMutation(node.first, mutateNode); +} + +bool TextHandle::IndexesRequired() const +{ + return false; +} + +} // namespace df diff --git a/drape_frontend/text_handle.hpp b/drape_frontend/text_handle.hpp new file mode 100644 index 0000000000..523492ef69 --- /dev/null +++ b/drape_frontend/text_handle.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "drape/overlay_handle.hpp" +#include "drape/utils/vertex_decl.hpp" + +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, + gpu::TTextDynamicVertexBuffer && normals) + : OverlayHandle(id, anchor, priority) + , m_normals(move(normals)) + {} + + void GetAttributeMutation(ref_ptr mutator, + ScreenBase const & screen, bool isVisible) const override; + + bool IndexesRequired() const override; + +protected: + gpu::TTextDynamicVertexBuffer m_normals; +}; + + +} // namespace df diff --git a/drape_frontend/text_shape.cpp b/drape_frontend/text_shape.cpp index 199ab27158..0d2485eda6 100644 --- a/drape_frontend/text_shape.cpp +++ b/drape_frontend/text_shape.cpp @@ -1,4 +1,5 @@ #include "drape_frontend/text_shape.hpp" +#include "drape_frontend/text_handle.hpp" #include "drape_frontend/text_layout.hpp" #include "drape/utils/vertex_decl.hpp" @@ -18,20 +19,19 @@ namespace df namespace { -class StraightTextHandle : public dp::OverlayHandle +class StraightTextHandle : public TextHandle { public: StraightTextHandle(FeatureID const & id, dp::Anchor anchor, glsl::vec2 const & pivot, glsl::vec2 const & pxSize, glsl::vec2 const & offset, - double priority) - : OverlayHandle(id, anchor, priority) + double priority, gpu::TTextDynamicVertexBuffer && normals) + : TextHandle(id, anchor, priority, move(normals)) , m_pivot(glsl::ToPoint(pivot)) , m_offset(glsl::ToPoint(offset)) , m_size(glsl::ToPoint(pxSize)) - { - } + {} - m2::RectD GetPixelRect(ScreenBase const & screen) const + m2::RectD GetPixelRect(ScreenBase const & screen) const override { m2::PointD pivot = screen.GtoP(m_pivot) + m_offset; double x = pivot.x; @@ -62,7 +62,7 @@ public: max(x, pivot.x), max(y, pivot.y)); } - void GetPixelShape(ScreenBase const & screen, Rects & rects) const + void GetPixelShape(ScreenBase const & screen, Rects & rects) const override { rects.push_back(m2::RectF(GetPixelRect(screen))); } @@ -137,17 +137,20 @@ 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))); + m2::PointU const & pixelSize = layout.GetPixelSize(); drape_ptr handle = make_unique_dp(m_params.m_featureID, m_params.m_anchor, glsl::ToVec2(m_basePoint), glsl::vec2(pixelSize.x, pixelSize.y), - baseOffset, - m_params.m_depth); + baseOffset, m_params.m_depth, + move(dynamicBuffer)); dp::AttributeProvider provider(2, staticBuffer.size()); provider.InitStream(0, gpu::TextStaticVertex::GetBindingInfo(), make_ref(staticBuffer.data())); - provider.InitStream(1, gpu::TextDynamicVertex::GetBindingInfo(), make_ref(dynamicBuffer.data())); + provider.InitStream(1, gpu::TextDynamicVertex::GetBindingInfo(), make_ref(initialDynBuffer.data())); batcher->InsertListOfStrip(state, make_ref(&provider), move(handle), 4); }