From ec3e10e3f7780dc3921ff0745584984df13b46f8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 27 Apr 2021 01:58:28 +0900 Subject: [PATCH] text: Improve the comment --- text/text.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/text/text.go b/text/text.go index df8de9ddd..0bb4678be 100644 --- a/text/text.go +++ b/text/text.go @@ -157,6 +157,13 @@ var textM sync.Mutex // // Glyphs used for rendering are cached in least-recently-used way. // It is OK to call Draw with a same text and a same face at every frame in terms of performance. +// The cache is shared with CacheGlyphs. +// +// The two functions are implemented like this: +// +// Draw = Create glyphs by `ReplacePixels` and put them into the cache if necessary +// + Draw them onto the destination by `DrawImage` +// CacheGlyphs = Create glyphs by `ReplacePixels` and put them into the cache if necessary // // Be careful that the passed font face is held by this package and is never released. // This is a known issue (#498). @@ -271,12 +278,20 @@ func BoundString(face font.Face, text string) image.Rectangle { } // CacheGlyphs precaches the glyphs for the given text and the given font face into the cache. +// The cache is shared with Draw. // // Draw automatically creates and caches necessary glyphs, so usually you don't have to call CacheGlyphs // explicitly. However, for example, when you call Draw for each rune of one big text, Draw tries to create the glyph // cache and render it for each rune. This is very inefficient because creating a glyph image and rendering it are -// different operations and can never be merged as one draw call. CacheGlyphs creates necessary glyphs without -// rendering them so that these operations are likely merged into one draw call. +// different operations (ReplacePixels and DrawImage) and can never be merged as one draw call. +// CacheGlyphs creates necessary glyphs without rendering them so that these operations are likely merged into one +// draw call regardless of the size of the text. +// +// The two functions are implemented like this: +// +// Draw = Create glyphs by `ReplacePixels` and put them into the cache if necessary +// + Draw them onto the destination by `DrawImage` +// CacheGlyphs = Create glyphs by `ReplacePixels` and put them into the cache if necessary // // If a rune's glyph is already cached, CacheGlyphs does nothing for the rune. func CacheGlyphs(face font.Face, text string) {