From c4ab0f5fd4f6772560c2390a54a8a3f23c7889df Mon Sep 17 00:00:00 2001 From: Nikita Gubarkov Date: Wed, 24 Apr 2024 01:50:44 +0200 Subject: [PATCH] JBR-7046 Tolerate subpixelResolution=0 in Metal and OGL --- .../java2d/metal/MTLTextRenderer.m | 28 +++++++------------ .../common/java2d/opengl/OGLTextRenderer.c | 28 +++++++------------ 2 files changed, 20 insertions(+), 36 deletions(-) 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..b5e3b416800f 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 @@ -660,19 +660,17 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { int ry = ginfo->subpixelResolutionY; ADJUST_SUBPIXEL_GLYPH_POSITION(glyphx, rx); ADJUST_SUBPIXEL_GLYPH_POSITION(glyphy, ry); - int subx = 0, suby = 0; - // see DrawGlyphList.c FLOOR_ASSIGN & getSubpixelGlyphImage - if (glyphx >= 0.0f && glyphy >= 0.0f) { - x = (int) glyphx; - y = (int) glyphy; - subx = ((int) (glyphx * (float) rx)) % rx; - suby = ((int) (glyphy * (float) ry)) % ry; + float fx = floor(glyphx); + float fy = floor(glyphy); + x = (int) fx; + y = (int) fy; + int subimage; + if ((rx == 1 && ry == 1) || rx <= 0 || ry <= 0) { + subimage = 0; } else { - float fx = floor(glyphx), fy = floor(glyphy); - x = (int) fx; - y = (int) fy; - subx = (int) ((glyphx - fx) * (float) rx); - suby = (int) ((glyphy - fy) * (float) ry); + int subx = (int) ((glyphx - fx) * (float) rx); + int suby = (int) ((glyphy - fy) * (float) ry); + subimage = subx + suby * rx; } if (ginfo->image == NULL) { @@ -684,12 +682,6 @@ static void DisableColorGlyphPainting(MTLContext *mtlc) { J2dTraceLn1(J2D_TRACE_INFO, "rowBytes = %d", ginfo->rowBytes); if (ginfo->format == sun_font_StrikeCache_PIXEL_FORMAT_GREYSCALE) { // grayscale or monochrome glyph data - int subimage; - if ((rx == 1 && ry == 1) || rx <= 0 || ry <= 0) { - subimage = 0; - } else { - subimage = subx + suby * rx; - } if (ginfo->width <= MTLTR_CACHE_CELL_WIDTH && ginfo->height <= MTLTR_CACHE_CELL_HEIGHT) { diff --git a/src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c b/src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c index 9e907c553dd6..0cf7db85b56c 100644 --- a/src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c +++ b/src/java.desktop/share/native/common/java2d/opengl/OGLTextRenderer.c @@ -1297,19 +1297,17 @@ OGLTR_DrawGlyphList(JNIEnv *env, OGLContext *oglc, OGLSDOps *dstOps, int ry = ginfo->subpixelResolutionY; ADJUST_SUBPIXEL_GLYPH_POSITION(glyphx, rx); ADJUST_SUBPIXEL_GLYPH_POSITION(glyphy, ry); - int subx = 0, suby = 0; - // see DrawGlyphList.c FLOOR_ASSIGN & getSubpixelGlyphImage - if (glyphx >= 0.0f && glyphy >= 0.0f) { - x = (int) glyphx; - y = (int) glyphy; - subx = ((int) (glyphx * (float) rx)) % rx; - suby = ((int) (glyphy * (float) ry)) % ry; + float fx = floor(glyphx); + float fy = floor(glyphy); + x = (int) fx; + y = (int) fy; + int subimage; + if ((rx == 1 && ry == 1) || rx <= 0 || ry <= 0) { + subimage = 0; } else { - float fx = floor(glyphx), fy = floor(glyphy); - x = (int) fx; - y = (int) fy; - subx = (int) ((glyphx - fx) * (float) rx); - suby = (int) ((glyphy - fy) * (float) ry); + int subx = (int) ((glyphx - fx) * (float) rx); + int suby = (int) ((glyphy - fy) * (float) ry); + subimage = subx + suby * rx; } if (ginfo->image == NULL) { @@ -1321,12 +1319,6 @@ OGLTR_DrawGlyphList(JNIEnv *env, OGLContext *oglc, OGLSDOps *dstOps, OGLContext_InitGrayRenderHints(env, oglc); } // grayscale or monochrome glyph data - int subimage; - if ((rx == 1 && ry == 1) || rx <= 0 || ry <= 0) { - subimage = 0; - } else { - subimage = subx + suby * rx; - } if (ginfo->width <= OGLTR_CACHE_CELL_WIDTH && ginfo->height <= OGLTR_CACHE_CELL_HEIGHT) {