From f18c5e9a259c88f7bc3bbc9cf8afcf805ba00a60 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 13 Mar 2021 19:59:41 +0200 Subject: Text: Separate glyph caching procedure Previously glyph caching was done during text rendering, but that would mean lots of swapping between rendering stuff to the cache and then immediately afterward rendering to the display. There would be a swap per each new glyph. Now the entire document's glyphs are precached at once when a request is finished. Glyphs are also cached in larger batches when new text needs to be drawn. --- src/ui/documentwidget.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/ui/documentwidget.c') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index a7666865..9111b546 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1004,6 +1004,17 @@ static void parseUser_DocumentWidget_(iDocumentWidget *d) { setRange_String(d->titleUser, urlUser_String(d->mod.url)); } +static void cacheRunGlyphs_(void *data, const iGmRun *run) { + iUnused(data); + if (!isEmpty_Range(&run->text)) { + cache_Text(run->font, run->text); + } +} + +static void cacheDocumentGlyphs_DocumentWidget_(const iDocumentWidget *d) { + render_GmDocument(d->doc, (iRangei){ 0, size_GmDocument(d->doc).y }, cacheRunGlyphs_, NULL); +} + static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { const iRecentUrl *recent = findUrl_History(d->mod.history, d->mod.url); if (recent && recent->cachedResponse) { @@ -1026,6 +1037,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { updateSideOpacity_DocumentWidget_(d, iFalse); updateSideIconBuf_DocumentWidget_(d); updateVisible_DocumentWidget_(d); + cacheDocumentGlyphs_DocumentWidget_(d); postCommandf_App("document.changed doc:%p url:%s", d, cstr_String(d->mod.url)); return iTrue; } @@ -1762,6 +1774,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) scrollToHeading_DocumentWidget_(d, cstr_String(&d->pendingGotoHeading)); clear_String(&d->pendingGotoHeading); } + cacheDocumentGlyphs_DocumentWidget_(d); return iFalse; } else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { -- cgit v1.2.3