[drape] nits

Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
This commit is contained in:
x7z4w
2025-11-24 17:34:56 +00:00
parent 298518ae72
commit 7e561d09d3
17 changed files with 51 additions and 112 deletions

View File

@@ -4,14 +4,15 @@
#include "base/math.hpp"
#include "base/stl_helpers.hpp"
#include <boost/algorithm/string/trim.hpp>
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <iomanip>
#include <string>
#include <fast_double_parser.h>
#include <boost/algorithm/string/trim.hpp>
#include <string>
namespace strings
{
@@ -271,17 +272,15 @@ bool Truncate(std::string & utf8, size_t const maxTextLengthPlus1)
{
if ((utf8[i] & 0xC0) != 0x80)
{
++codePoints;
if (codePoints == maxTextLengthPlus1)
if (++codePoints == maxTextLengthPlus1)
{
--i;
unsigned char byte = utf8[i];
auto const & byte = utf8[i];
uint8_t bytesInCodepoint = 1;
if ((byte & 0x80) == 0x00)
bytesInCodepoint = 1;
{}
else if ((byte & 0xE0) == 0xC0)
bytesInCodepoint = 2;
else if ((byte & 0xF0) == 0xE0)

View File

@@ -1,11 +1,9 @@
#include "drape/batcher.hpp"
#include "drape/batcher_helpers.hpp"
#include "drape/cpu_buffer.hpp"
#include "drape/index_storage.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "base/assert.hpp"
#include "base/stl_helpers.hpp"
#include <utility>
@@ -190,14 +188,6 @@ void Batcher::ResetSession()
m_buckets.clear();
}
void Batcher::SetFeatureMinZoom(int minZoom)
{
m_featureMinZoom = minZoom;
for (auto const & bucket : m_buckets)
bucket.second->SetFeatureMinZoom(m_featureMinZoom);
}
void Batcher::SetBatcherHash(uint64_t batcherHash)
{
m_batcherHash = batcherHash;

View File

@@ -68,7 +68,13 @@ public:
void SetBatcherHash(uint64_t batcherHash);
void SetFeatureMinZoom(int minZoom);
inline void SetFeatureMinZoom(int minZoom)
{
m_featureMinZoom = minZoom;
for (auto const & bucket : m_buckets)
bucket.second->SetFeatureMinZoom(m_featureMinZoom);
}
private:
template <typename TBatcher, typename... TArgs>

View File

@@ -5,8 +5,6 @@
#include "base/logging.hpp"
#include <algorithm>
#include <functional>
#include <iterator>
#include "font_constants.hpp"

View File

@@ -1,7 +1,6 @@
#include "drape/gl_gpu_program.hpp"
#include "drape/gl_functions.hpp"
#include "drape/render_state.hpp"
#include "drape/support_manager.hpp"
#include "base/logging.hpp"

View File

@@ -5,9 +5,8 @@
#include "drape/pointers.hpp"
#include "drape/shader.hpp"
#include <map>
#include <unordered_map>
#include <string>
#include <vector>
namespace dp
{
@@ -30,7 +29,7 @@ public:
glConst m_type = gl_const::GLFloatType;
};
using UniformsInfo = std::map<std::string, UniformInfo>;
using UniformsInfo = std::unordered_map<std::string, UniformInfo>;
UniformsInfo const & GetUniformsInfo() const;
uint32_t GetNumericUniformsCount() const { return m_numericUniformsCount; }

View File

@@ -205,9 +205,9 @@ FreetypeError constexpr g_FT_Errors[] =
static void Close(FT_Stream) {}
void MarkGlyphReady(uint16_t glyphId) { m_readyGlyphs.emplace(glyphId); }
inline void MarkGlyphReady(uint16_t glyphId) { m_readyGlyphs.emplace(glyphId); }
bool IsGlyphReady(uint16_t glyphId) const { return m_readyGlyphs.find(glyphId) != m_readyGlyphs.end(); }
inline bool IsGlyphReady(uint16_t glyphId) const { return m_readyGlyphs.find(glyphId) != m_readyGlyphs.end(); }
std::string GetName() const { return std::string(m_fontFace->family_name) + ':' + m_fontFace->style_name; }
@@ -257,7 +257,7 @@ FreetypeError constexpr g_FT_Errors[] =
FT_StreamRec_ m_stream;
FT_Face m_fontFace;
std::set<uint16_t> m_readyGlyphs;
std::unordered_set<uint16_t> m_readyGlyphs;
hb_font_t * m_harfbuzzFont{nullptr};
};
@@ -334,7 +334,6 @@ FreetypeError constexpr g_FT_Errors[] =
using is_transparent = void;
};
// TODO(AB): Compare performance with std::map.
std::unordered_map<std::string, text::TextMetrics, StringHash, std::equal_to<>> m_textMetricsCache;
hb_buffer_t * m_harfbuzzBuffer;
};

View File

@@ -6,8 +6,6 @@
#include "drape/overlay_tree.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "base/stl_helpers.hpp"
namespace dp
{
RenderBucket::RenderBucket(drape_ptr<VertexArrayBuffer> && buffer) : m_buffer(std::move(buffer)) {}
@@ -59,9 +57,11 @@ void RenderBucket::Update(ScreenBase const & modelView)
{
BeforeUpdate();
for (auto & overlayHandle : m_overlay)
{
if (overlayHandle->IsVisible())
overlayHandle->Update(modelView);
}
}
void RenderBucket::CollectOverlayHandles(ref_ptr<OverlayTree> tree)
{
@@ -129,7 +129,7 @@ void RenderBucket::SetFeatureMinZoom(int minZoom)
void RenderBucket::RenderDebug(ref_ptr<GraphicsContext> context, ScreenBase const & screen,
ref_ptr<DebugRenderer> debugRectRenderer) const
{
if (!debugRectRenderer || !debugRectRenderer->IsEnabled() || m_overlay.empty())
if (m_overlay.empty())
return;
for (auto const & handle : m_overlay)

View File

@@ -264,39 +264,4 @@ void SymbolsTexture::Fail(ref_ptr<dp::GraphicsContext> context)
Create(context, p, make_ref(&alphaTexture));
}
bool SymbolsTexture::IsSymbolContained(std::string const & symbolName) const
{
return m_definition.find(symbolName) != m_definition.end();
}
bool SymbolsTexture::DecodeToMemory(std::string const & skinPathName, std::string const & textureName,
std::vector<uint8_t> & symbolsSkin, std::map<std::string, m2::RectU> & symbolsIndex,
uint32_t & skinWidth, uint32_t & skinHeight)
{
auto definitionInserter = [&symbolsIndex](std::string const & name, m2::RectF const & rect)
{ symbolsIndex.insert(make_pair(name, m2::RectU(rect))); };
bool result = true;
auto completionHandler =
[&result, &symbolsSkin, &skinWidth, &skinHeight](unsigned char * data, uint32_t width, uint32_t height)
{
size_t size = 4 * width * height;
symbolsSkin.resize(size);
memcpy(symbolsSkin.data(), data, size);
skinWidth = width;
skinHeight = height;
result = true;
};
auto failureHandler = [&result](std::string const & reason)
{
LOG(LERROR, (reason));
result = false;
};
LoadSymbols(skinPathName, textureName, false /* convertToUV */, definitionInserter, completionHandler,
failureHandler);
return result;
}
} // namespace dp

View File

@@ -2,7 +2,7 @@
#include "drape/texture.hpp"
#include <map>
#include <unordered_map>
#include <string>
#include <vector>
@@ -39,19 +39,17 @@ public:
void Invalidate(ref_ptr<dp::GraphicsContext> context, std::string const & skinPathName,
ref_ptr<HWTextureAllocator> allocator, std::vector<drape_ptr<HWTexture>> & internalTextures);
bool IsSymbolContained(std::string const & symbolName) const;
static bool DecodeToMemory(std::string const & skinPathName, std::string const & textureName,
std::vector<uint8_t> & symbolsSkin, std::map<std::string, m2::RectU> & symbolsIndex,
uint32_t & skinWidth, uint32_t & skinHeight);
inline bool IsSymbolContained(std::string const & symbolName) const
{
return m_definition.find(symbolName) != m_definition.end();
}
private:
void Fail(ref_ptr<dp::GraphicsContext> context);
void Load(ref_ptr<dp::GraphicsContext> context, std::string const & skinPathName,
ref_ptr<HWTextureAllocator> allocator);
using TSymDefinition = std::map<std::string, SymbolInfo>;
std::string m_name;
mutable TSymDefinition m_definition;
mutable std::unordered_map<std::string, SymbolInfo> m_definition;
};
} // namespace dp

View File

@@ -539,12 +539,6 @@ GlyphFontAndId TextureManager::GetSpaceGlyph() const
return m_spaceGlyph;
}
bool TextureManager::AreGlyphsReady(TGlyphs const & glyphs) const
{
CHECK(m_isInitialized, ());
return m_glyphManager->AreGlyphsReady(glyphs);
}
ref_ptr<Texture> TextureManager::GetSymbolsTexture() const
{
CHECK(m_isInitialized, ());

View File

@@ -95,7 +95,11 @@ public:
TMultilineGlyphsBuffer & multilineGlyphRegions);
// This method must be called only on Frontend renderer's thread.
bool AreGlyphsReady(TGlyphs const & glyphs) const;
inline bool AreGlyphsReady(TGlyphs const & glyphs) const
{
CHECK(m_isInitialized, ());
return m_glyphManager->AreGlyphsReady(glyphs);
}
GlyphFontAndId GetSpaceGlyph() const;

View File

@@ -3,16 +3,15 @@
#include "drape/vulkan/vulkan_base_context.hpp"
#include "drape/vulkan/vulkan_gpu_buffer_impl.hpp"
#include "drape/vulkan/vulkan_param_descriptor.hpp"
#include "drape/vulkan/vulkan_utils.hpp"
#include "base/assert.hpp"
#include "base/macros.hpp"
#include "drape/vulkan/vulkan_staging_buffer.hpp"
#include <array>
#include <cstdint>
#include <cstring>
#include <utility>
#include <vector>
namespace dp
{
@@ -44,11 +43,11 @@ public:
void RenderRange(ref_ptr<GraphicsContext> context, bool drawAsLine, IndicesRange const & range) override
{
CHECK(m_vertexArrayBuffer->HasBuffers(), ());
ASSERT(m_vertexArrayBuffer->HasBuffers(), ());
ref_ptr<dp::vulkan::VulkanBaseContext> vulkanContext = context;
VkCommandBuffer commandBuffer = vulkanContext->GetCurrentRenderingCommandBuffer();
CHECK(commandBuffer != nullptr, ());
ASSERT(commandBuffer != nullptr, ());
vulkanContext->SetPrimitiveTopology(drawAsLine ? VK_PRIMITIVE_TOPOLOGY_LINE_LIST
: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
@@ -71,23 +70,22 @@ public:
for (auto & buffer : m_vertexArrayBuffer->m_staticBuffers)
{
ref_ptr<VulkanGpuBufferImpl> b = buffer.second->GetBuffer();
CHECK_LESS(bufferIndex, kMaxBuffersCount, ());
ASSERT_LESS(bufferIndex, kMaxBuffersCount, ());
buffers[bufferIndex++] = b->GetVulkanBuffer();
}
for (auto & buffer : m_vertexArrayBuffer->m_dynamicBuffers)
{
ref_ptr<VulkanGpuBufferImpl> b = buffer.second->GetBuffer();
CHECK_LESS(bufferIndex, kMaxBuffersCount, ());
ASSERT_LESS(bufferIndex, kMaxBuffersCount, ());
buffers[bufferIndex++] = b->GetVulkanBuffer();
}
vkCmdBindVertexBuffers(commandBuffer, 0, bufferIndex, buffers.data(), offsets.data());
ref_ptr<VulkanGpuBufferImpl> ib = m_vertexArrayBuffer->m_indexBuffer->GetBuffer();
VkBuffer vulkanIndexBuffer = ib->GetVulkanBuffer();
auto const indexType = dp::IndexStorage::IsSupported32bit() ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16;
vkCmdBindIndexBuffer(commandBuffer, vulkanIndexBuffer, 0, indexType);
vkCmdBindIndexBuffer(
commandBuffer, ref_ptr<VulkanGpuBufferImpl>(m_vertexArrayBuffer->m_indexBuffer->GetBuffer())->GetVulkanBuffer(),
0, m_indexType);
CHECK_LESS_OR_EQUAL(range.m_idxStart + range.m_idxCount,
ASSERT_LESS_OR_EQUAL(range.m_idxStart + range.m_idxCount,
m_objectManager->GetMemoryManager().GetDeviceLimits().maxDrawIndexedIndexValue, ());
vkCmdDrawIndexed(commandBuffer, range.m_idxCount, 1, range.m_idxStart, 0, 0);
@@ -99,6 +97,7 @@ private:
BindingInfoArray m_bindingInfo;
uint8_t m_bindingInfoCount = 0;
ParamDescriptorUpdater m_descriptorUpdater;
VkIndexType const m_indexType = dp::IndexStorage::IsSupported32bit() ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16;
};
} // namespace vulkan

View File

@@ -37,14 +37,7 @@
#include "std/target_os.hpp"
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <functional>
#include <limits>
#include <memory>
#include <thread>
#include <utility>
namespace df
{
@@ -1827,6 +1820,7 @@ void FrontendRenderer::BuildOverlayTree(ScreenBase const & modelView)
return;
BeginUpdateOverlayTree(modelView);
for (auto const layerId :
{DepthLayer::OverlayUnderBuildingLayer, DepthLayer::OverlayLayer, DepthLayer::RoutingBottomMarkLayer, DepthLayer::RoutingMarkLayer})
{

View File

@@ -122,11 +122,6 @@ ref_ptr<PathTextLayout> const PathTextContext::GetLayout() const
return make_ref(m_layout);
}
void PathTextContext::BeforeUpdate()
{
m_updated = false;
}
std::vector<double> const & PathTextContext::GetOffsets() const
{
return m_globalOffsets;

View File

@@ -21,7 +21,8 @@ public:
bool GetPivot(size_t textIndex, m2::PointD & pivot, m2::Spline::iterator & centerPointIter) const;
void BeforeUpdate();
// TODO: these are unused?
inline void BeforeUpdate() { m_updated = false; }
void Update(ScreenBase const & screen);
std::vector<double> const & GetOffsets() const;

View File

@@ -8,8 +8,6 @@
#include "geometry/screenbase.hpp"
#include "base/stl_helpers.hpp"
#include <algorithm>
#include <sstream>
#include <utility>
@@ -115,6 +113,7 @@ void RenderGroup::Render(ref_ptr<dp::GraphicsContext> context, ref_ptr<gpu::Prog
for (auto & renderBucket : m_renderBuckets)
renderBucket->Render(context, m_state.GetDrawAsLine());
if (debugRectRenderer && debugRectRenderer->IsEnabled())
for (auto const & renderBucket : m_renderBuckets)
renderBucket->RenderDebug(context, screen, debugRectRenderer);
}