From 3403f485dd0faec27ee29a26a5471b67253ab5de Mon Sep 17 00:00:00 2001 From: Nikita Gubarkov Date: Tue, 23 Apr 2024 15:51:23 +0200 Subject: [PATCH] JBR-7020 Reorder LCD glyph cache freeing and validation 1. As we started committing the command buffer on glyph cache flush, this invalidates the current encoder. We need to `MTLTR_ValidateGlyphCache` after the flush, not before. 2. There's no reason to maintain separate glyph cache invalidation logic for this singe case (which is a no-op in reality), so just free the cache instead. --- .../libawt_lwawt/java2d/metal/MTLGlyphCache.m | 31 ------------------- .../java2d/metal/MTLTextRenderer.m | 10 +++--- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGlyphCache.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGlyphCache.m index 7ff7410fabb7..4808092dbd46 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGlyphCache.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGlyphCache.m @@ -215,37 +215,6 @@ - (BOOL) isCacheFull:(GlyphInfo*) glyph } return JNI_FALSE; } -/** - * Invalidates all cells in the cache. Note that this method does not - * attempt to compact the cache in any way; it just invalidates any cells - * that already exist. - */ -- (void) invalidate -{ - MTLCacheCellInfo *cellinfo; - - J2dTraceLn(J2D_TRACE_INFO, "MTLGlyphCache.invalidate"); - - if (_cacheInfo == NULL) { - return; - } - - // flush any pending vertices that may be depending on the current - // glyph cache layout - if (_cacheInfo->Flush != NULL) { - _cacheInfo->Flush(_cacheInfo->mtlc); - } - - cellinfo = _cacheInfo->head; - while (cellinfo != NULL) { - if (cellinfo->glyphInfo != NULL) { - // if the cell is occupied, notify the base glyph that its - // cached version for this cache is about to be invalidated - MTLGlyphCache_RemoveCellInfo(cellinfo->glyphInfo, cellinfo); - } - cellinfo = cellinfo->next; - } -} /** * Invalidates and frees all cells and the cache itself. The "cache" pointer diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m index 3e78ed5a9c94..1aa57e25b89e 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m @@ -372,17 +372,17 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { DisableColorGlyphPainting(mtlc); } - if (!MTLTR_ValidateGlyphCache(mtlc, dstOps, JNI_TRUE)) { - return JNI_FALSE; - } - if (rgbOrder != lastRGBOrder) { // need to invalidate the cache in this case; see comments // for lastRGBOrder above - [mtlc.glyphCacheLCD invalidate]; + [mtlc.glyphCacheLCD free]; lastRGBOrder = rgbOrder; } + if (!MTLTR_ValidateGlyphCache(mtlc, dstOps, JNI_TRUE)) { + return JNI_FALSE; + } + glyphMode = MODE_USE_CACHE_LCD; }