Skip to content

Commit bac12d4

Browse files
committed
JBR-1517 Update font layout speedup code to match the variant submitted to OpenJDK (JDK-8220231)
revert original implementation of font layout speedup
1 parent 2bbfe3b commit bac12d4

File tree

8 files changed

+92
-149
lines changed

8 files changed

+92
-149
lines changed

src/java.desktop/macosx/classes/sun/font/CFont.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,12 @@
3131
import java.awt.geom.GeneralPath;
3232
import java.awt.geom.Point2D;
3333
import java.awt.geom.Rectangle2D;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedAction;
3634

3735
// Right now this class is final to avoid a problem with native code.
3836
// For some reason the JNI IsInstanceOf was not working correctly
3937
// so we are checking the class specifically. If we subclass this
4038
// we need to modify the native code in CFontWrapper.m
4139
public final class CFont extends PhysicalFont implements FontSubstitution {
42-
private static final boolean useCoreTextLayout;
43-
44-
static {
45-
useCoreTextLayout = AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
46-
Boolean.getBoolean("sun.font.use.coretext.layout"));
47-
}
4840

4941
/* CFontStrike doesn't call these methods so they are unimplemented.
5042
* They are here to meet the requirements of PhysicalFont, needed
@@ -254,13 +246,6 @@ String getNativeFontName() {
254246
return nativeFontName;
255247
}
256248

257-
@Override
258-
protected boolean isAAT() {
259-
// CoreText layout code ignores fractional metrics font attribute
260-
// also, using CoreText layout in Harfbuzz code leads to wrong advances for emoji glyphs
261-
return useCoreTextLayout && !"AppleColorEmoji".equals(nativeFontName) && super.isAAT();
262-
}
263-
264249
// <rdar://problem/5321707> sun.font.Font2D caches the last used strike,
265250
// but does not check if the properties of the strike match the properties
266251
// of the incoming java.awt.Font object (size, style, etc).

src/java.desktop/share/classes/sun/font/Font2D.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525

2626
package sun.font;
2727

28-
import sun.java2d.Disposer;
29-
import sun.java2d.DisposerRecord;
30-
3128
import java.awt.Font;
3229
import java.awt.font.FontRenderContext;
3330
import java.awt.geom.AffineTransform;
@@ -80,8 +77,6 @@ public abstract class Font2D {
8077
protected FontFamily family;
8178
protected int fontRank = DEFAULT_RANK;
8279

83-
private HarfbuzzFaceRef harfbuzzFaceRef;
84-
8580
/*
8681
* A mapper can be independent of the strike.
8782
* Perhaps the reference to the mapper ought to be held on the
@@ -485,23 +480,6 @@ protected long getPlatformNativeFontPtr() {
485480
return 0L;
486481
}
487482

488-
protected boolean isAAT() {
489-
return false;
490-
}
491-
492-
synchronized long getHarfbuzzFacePtr() {
493-
if (harfbuzzFaceRef == null) {
494-
long harfbuzzFaceNativePtr = createHarfbuzzFace(isAAT(), getPlatformNativeFontPtr());
495-
if (harfbuzzFaceNativePtr == 0) return 0;
496-
harfbuzzFaceRef = new HarfbuzzFaceRef(harfbuzzFaceNativePtr);
497-
Disposer.addObjectRecord(this, harfbuzzFaceRef);
498-
}
499-
return harfbuzzFaceRef.harfbuzzFaceNativePtr;
500-
}
501-
502-
private native long createHarfbuzzFace(boolean aat, long platformNativeFontPtr);
503-
private static native void disposeHarfbuzzFace(long harfbuzzFaceNativePtr);
504-
505483
/* for layout code */
506484
protected long getUnitsPerEm() {
507485
return 2048;
@@ -587,17 +565,4 @@ public float getItalicAngle(Font font, AffineTransform at,
587565
}
588566
}
589567

590-
591-
private static class HarfbuzzFaceRef implements DisposerRecord {
592-
private final long harfbuzzFaceNativePtr;
593-
594-
private HarfbuzzFaceRef(long harfbuzzFaceNativePtr) {
595-
this.harfbuzzFaceNativePtr = harfbuzzFaceNativePtr;
596-
}
597-
598-
@Override
599-
public void dispose() {
600-
disposeHarfbuzzFace(harfbuzzFaceNativePtr);
601-
}
602-
}
603568
}

src/java.desktop/share/classes/sun/font/PhysicalFont.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ Point2D.Float getGlyphPoint(long pScalerContext,
7979
return new Point2D.Float();
8080
}
8181

82-
@Override
83-
protected boolean isAAT() {
84-
return getTableBytes(TrueTypeFont.morxTag) != null ||
85-
getTableBytes(TrueTypeFont.mortTag) != null;
86-
}
87-
8882
/* These 3 metrics methods should be implemented to return
8983
* values in user space.
9084
*/

src/java.desktop/share/classes/sun/font/SunLayoutEngine.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public LayoutEngine getEngine(LayoutEngineKey key) {
144144
private SoftReference<ConcurrentHashMap<LayoutEngineKey, LayoutEngine>> cacheref =
145145
new SoftReference<>(null);
146146

147+
private boolean isAAT(Font2D font) {
148+
// CoreText layout code ignores fractional metrics font attribute
149+
// also, using CoreText layout in Harfbuzz code leads to wrong advances for emoji glyphs
150+
return false;
151+
}
152+
147153
private SunLayoutEngine(LayoutEngineKey key) {
148154
this.key = key;
149155
}
@@ -153,8 +159,15 @@ public void layout(FontStrikeDesc desc, float[] mat, float ptSize, int gmask,
153159
Point2D.Float pt, GVData data) {
154160
Font2D font = key.font();
155161
FontStrike strike = font.getStrike(desc);
156-
shape(font, strike, ptSize, mat,
157-
font.getHarfbuzzFacePtr(), font.getPlatformNativeFontPtr(), font.isAAT(),
162+
long layoutTables = font.getLayoutTableCache();
163+
long pNativeFont = font.getPlatformNativeFontPtr(); // used on OSX
164+
// pScaler probably not needed long term.
165+
long pScaler = 0L;
166+
if (font instanceof FileFont) {
167+
pScaler = ((FileFont)font).getScaler().nativeScaler;
168+
}
169+
shape(font, strike, ptSize, mat, pScaler, pNativeFont,
170+
layoutTables, isAAT(font),
158171
tr.text, data, key.script(),
159172
tr.start, tr.limit, baseIndex, pt,
160173
typo_flags, gmask);
@@ -163,7 +176,7 @@ public void layout(FontStrikeDesc desc, float[] mat, float ptSize, int gmask,
163176
/* Native method to invoke harfbuzz layout engine */
164177
private static native boolean
165178
shape(Font2D font, FontStrike strike, float ptSize, float[] mat,
166-
long pscaler, long pNativeFont, boolean aat,
179+
long pscaler, long pNativeFont, long layoutTables, boolean aat,
167180
char[] chars, GVData data,
168181
int script, int offset, int limit,
169182
int baseIndex, Point2D.Float pt, int typo_flags, int slot);

src/java.desktop/share/classes/sun/font/TrueTypeFont.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,6 @@ public int getWeight() {
999999
return (fontWeight > 0) ? fontWeight : super.getWeight();
10001000
}
10011001

1002-
@Override
1003-
protected boolean isAAT() {
1004-
return getDirectoryEntry(TrueTypeFont.morxTag) != null ||
1005-
getDirectoryEntry(TrueTypeFont.mortTag) != null;
1006-
}
1007-
10081002
/* TrueTypeFont can use the fsSelection fields of OS/2 table
10091003
* to determine the style. In the unlikely case that doesn't exist,
10101004
* can use macStyle in the 'head' table but simpler to

src/java.desktop/share/native/libfontmanager/HBShaper.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ JDKFontInfo*
201201
jobject font2D,
202202
jobject fontStrike,
203203
jfloat ptSize,
204+
jlong pScaler,
204205
jlong pNativeFont,
206+
jlong layoutTables,
205207
jfloatArray matrix,
206208
jboolean aat) {
207209

@@ -214,6 +216,7 @@ JDKFontInfo*
214216
fi->font2D = font2D;
215217
fi->fontStrike = fontStrike;
216218
fi->nativeFont = pNativeFont;
219+
fi->layoutTables = (TTLayoutTableCache*)layoutTables;
217220
fi->aat = aat;
218221
(*env)->GetFloatArrayRegion(env, matrix, 0, 4, fi->matrix);
219222
fi->ptSize = ptSize;
@@ -238,8 +241,9 @@ JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape
238241
jobject fontStrike,
239242
jfloat ptSize,
240243
jfloatArray matrix,
241-
jlong pFace,
244+
jlong pScaler,
242245
jlong pNativeFont,
246+
jlong layoutTables,
243247
jboolean aat,
244248
jcharArray text,
245249
jobject gvdata,
@@ -252,7 +256,6 @@ JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape
252256
jint slot) {
253257

254258
hb_buffer_t *buffer;
255-
hb_face_t* hbface;
256259
hb_font_t* hbfont;
257260
jchar *chars;
258261
jsize len;
@@ -269,16 +272,15 @@ JNIEXPORT jboolean JNICALL Java_sun_font_SunLayoutEngine_shape
269272

270273
JDKFontInfo *jdkFontInfo =
271274
createJDKFontInfo(env, font2D, fontStrike, ptSize,
272-
pNativeFont, matrix, aat);
275+
pScaler, pNativeFont, layoutTables, matrix, aat);
273276
if (!jdkFontInfo) {
274277
return JNI_FALSE;
275278
}
276279
jdkFontInfo->env = env; // this is valid only for the life of this JNI call.
277280
jdkFontInfo->font2D = font2D;
278281
jdkFontInfo->fontStrike = fontStrike;
279282

280-
hbface = (hb_face_t*) jlong_to_ptr(pFace);
281-
hbfont = hb_jdk_font_create(hbface, jdkFontInfo, NULL);
283+
hbfont = hb_jdk_font_create(jdkFontInfo, NULL);
282284

283285
buffer = hb_buffer_create();
284286
hb_buffer_set_script(buffer, getHBScriptCode(script));

0 commit comments

Comments
 (0)