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 a52d32a5dea..cb9f3855e9e 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 @@ -129,7 +129,6 @@ MTLTR_InitGlyphCache(MTLContext *mtlc, jboolean lcdCache) { J2dTraceLn(J2D_TRACE_INFO, "MTLTR_InitGlyphCache"); - // TODO : Need to verify RGB order in case of LCD MTLPixelFormat pixelFormat = lcdCache ? MTLPixelFormatBGRA8Unorm : MTLPixelFormatA8Unorm; @@ -232,10 +231,19 @@ int srcIndex = 0; int dstIndex = 0; for (int i = 0; i < (w * h); i++) { - imageData[dstIndex++] = glyph->image[srcIndex++]; - imageData[dstIndex++] = glyph->image[srcIndex++]; - imageData[dstIndex++] = glyph->image[srcIndex++]; - imageData[dstIndex++] = 0xFF; + if (!lastRGBOrder) { + imageData[dstIndex++] = glyph->image[srcIndex++]; + imageData[dstIndex++] = glyph->image[srcIndex++]; + imageData[dstIndex++] = glyph->image[srcIndex++]; + imageData[dstIndex++] = 0xFF; + } else { + // store RGB data into BGR texture + imageData[dstIndex + 2] = glyph->image[srcIndex++]; + imageData[dstIndex + 1] = glyph->image[srcIndex++]; + imageData[dstIndex] = glyph->image[srcIndex++]; + imageData[dstIndex + 3] = 0xFF; + dstIndex += 4; + } } NSUInteger bytesPerRow = 4 * w; @@ -411,9 +419,9 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { lcdCacheEncoder = [mtlc.encoderManager getLCDEncoder:dstOps->pTexture isSrcOpaque:YES isDstOpaque:YES]; } if (rgbOrder != lastRGBOrder) { - // need to invalidate the cache in this case; see comments - // for lastRGBOrder above - MTLGlyphCache_Invalidate(glyphCacheLCD); + // no need to invalidate cache in case of metal pipeline + // because we read and store individual samples and we can + // reorder it in MTLTR_AddToGlyphCache() lastRGBOrder = rgbOrder; } @@ -422,7 +430,6 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { if (ginfo->cellInfo == NULL) { // attempt to add glyph to accelerated glyph cache - // TODO : Handle RGB order MTLTR_AddToGlyphCache(ginfo, mtlc, JNI_TRUE); if (ginfo->cellInfo == NULL) { @@ -521,7 +528,7 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { id encoder = nil; MTLTextureDescriptor *textureDescriptor = - [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm + [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:w height:h mipmapped:NO]; @@ -558,10 +565,19 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { int srcIndex = 0; int dstIndex = 0; for (int i = 0; i < (w * h); i++) { - imageData[dstIndex++] = ginfo->image[srcIndex++ + rowBytesOffset]; - imageData[dstIndex++] = ginfo->image[srcIndex++ + rowBytesOffset]; - imageData[dstIndex++] = ginfo->image[srcIndex++ + rowBytesOffset]; - imageData[dstIndex++] = 0xFF; + if (rgbOrder) { + imageData[dstIndex++] = ginfo->image[srcIndex++ + rowBytesOffset]; + imageData[dstIndex++] = ginfo->image[srcIndex++ + rowBytesOffset]; + imageData[dstIndex++] = ginfo->image[srcIndex++ + rowBytesOffset]; + imageData[dstIndex++] = 0xFF; + } else { + //store BGR data in to RGB texture + imageData[dstIndex + 2] = ginfo->image[srcIndex++ + rowBytesOffset]; + imageData[dstIndex + 1] = ginfo->image[srcIndex++ + rowBytesOffset]; + imageData[dstIndex] = ginfo->image[srcIndex++ + rowBytesOffset]; + imageData[dstIndex + 3] = 0xFF; + dstIndex += 4; + } } // copy LCD mask into glyph texture tile