Merge remote-tracking branch 'origin/master' into claude/issue-123
# Conflicts: # implementations/Crafter.Graphics-UI-Shared.cpp # interfaces/Crafter.Graphics-UI.cppm
This commit is contained in:
commit
88541bf44e
5 changed files with 99 additions and 30 deletions
|
|
@ -75,8 +75,11 @@ std::uint32_t UIRenderer::ShapeText(Font& font, float pxSize,
|
|||
// the pen starting at x=0, baseline=0 so a cache hit only needs the
|
||||
// translate below. The whole string is shaped (no outCapacity limit) so
|
||||
// a later call with a larger buffer still gets the full run.
|
||||
ShapedRunKey key{&font, pxSize, color, std::string(utf8)};
|
||||
auto it = shapedRuns_.find(key);
|
||||
// Probe with a borrowing view key (text is a string_view onto utf8) so a
|
||||
// cache hit copies and hashes no string. The owning std::string is only
|
||||
// built on a miss, below, for the emplace.
|
||||
ShapedRunViewKey viewKey{&font, pxSize, color, utf8};
|
||||
auto it = shapedRuns_.find(viewKey);
|
||||
if (it == shapedRuns_.end()) {
|
||||
// Miss: shape from scratch. Ensure() each glyph so brand-new ones
|
||||
// rasterise into the atlas and mark it dirty for the next upload —
|
||||
|
|
@ -119,6 +122,9 @@ std::uint32_t UIRenderer::ShapeText(Font& font, float pxSize,
|
|||
shapedRunsLru_.pop_back();
|
||||
shapedRuns_.erase(*victim);
|
||||
}
|
||||
// Materialise the owning key (the probe above borrowed utf8) only now,
|
||||
// on the miss path, for the emplace.
|
||||
ShapedRunKey key{&font, pxSize, color, std::string(utf8)};
|
||||
it = shapedRuns_.emplace(std::move(key), std::move(run)).first;
|
||||
it->second.lruIt = shapedRunsLru_.insert(shapedRunsLru_.begin(), &it->first);
|
||||
} else {
|
||||
|
|
@ -164,6 +170,6 @@ void UIRenderer::InvalidateFont(const Font& font) noexcept {
|
|||
bool UIRenderer::IsShapedRunCached(const Font& font, float pxSize,
|
||||
std::array<float,4> color,
|
||||
std::string_view utf8) const {
|
||||
return shapedRuns_.find(ShapedRunKey{&font, pxSize, color, std::string(utf8)})
|
||||
return shapedRuns_.find(ShapedRunViewKey{&font, pxSize, color, utf8})
|
||||
!= shapedRuns_.end();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue