author | prr |
Thu, 07 Mar 2013 10:02:20 -0800 | |
changeset 16891 | 91e99bed64ae |
parent 12392 | af6c2083c5d7 |
child 19356 | 6f8b216b81bd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include "stdlib.h" |
|
27 |
#include "string.h" |
|
28 |
#include "gdefs.h" |
|
29 |
#include "jlong.h" |
|
30 |
#include "sunfontids.h" |
|
31 |
#include "fontscalerdefs.h" |
|
12392
af6c2083c5d7
7159136: JDK 7 font manager refactoring left JNI header generation and inclusion out of sync
prr
parents:
12047
diff
changeset
|
32 |
#include "sun_font_SunFontManager.h" |
2 | 33 |
#include "sun_font_NullFontScaler.h" |
34 |
#include "sun_font_StrikeCache.h" |
|
35 |
||
36 |
static void *theNullScalerContext = NULL; |
|
887 | 37 |
extern void AccelGlyphCache_RemoveAllCellInfos(GlyphInfo *glyph); |
38 |
||
2 | 39 |
|
40 |
JNIEXPORT jlong JNICALL |
|
41 |
Java_sun_font_NullFontScaler_getNullScalerContext |
|
42 |
(JNIEnv *env, jclass scalerClass) { |
|
43 |
||
44 |
if (theNullScalerContext == NULL) { |
|
45 |
theNullScalerContext = malloc(1); |
|
46 |
} |
|
47 |
return ptr_to_jlong(theNullScalerContext); |
|
48 |
} |
|
49 |
||
50 |
int isNullScalerContext(void *context) { |
|
51 |
return theNullScalerContext == context; |
|
52 |
} |
|
53 |
||
54 |
/* Eventually we may rework it to be a singleton. |
|
55 |
* This will require additional checks in freeLongMemory/freeIntMemory |
|
56 |
* and on other hand malformed fonts (main source of null glyph images) |
|
57 |
* are supposed to be collected fast. |
|
58 |
* But perhaps it is still right thing to do. |
|
59 |
* Even better is to eliminate the need to have this native method |
|
60 |
* but for this it is necessary to rework Strike and drawing logic |
|
61 |
* to be able to live with NULL pointers without performance hit. |
|
62 |
*/ |
|
63 |
JNIEXPORT jlong JNICALL Java_sun_font_NullFontScaler_getGlyphImage |
|
64 |
(JNIEnv *env, jobject scaler, jlong pContext, jint glyphCode) { |
|
65 |
void *nullscaler = calloc(sizeof(GlyphInfo), 1); |
|
66 |
return ptr_to_jlong(nullscaler); |
|
67 |
} |
|
68 |
||
69 |
||
70 |
||
71 |
void initLCDGammaTables(); |
|
72 |
||
73 |
/* placeholder for extern variable */ |
|
74 |
FontManagerNativeIDs sunFontIDs; |
|
75 |
||
76 |
JNIEXPORT void JNICALL |
|
3928 | 77 |
Java_sun_font_SunFontManager_initIDs |
2 | 78 |
(JNIEnv *env, jclass cls) { |
79 |
||
3928 | 80 |
jclass tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont"); |
2 | 81 |
sunFontIDs.ttReadBlockMID = |
82 |
(*env)->GetMethodID(env, tmpClass, "readBlock", |
|
83 |
"(Ljava/nio/ByteBuffer;II)I"); |
|
84 |
sunFontIDs.ttReadBytesMID = |
|
85 |
(*env)->GetMethodID(env, tmpClass, "readBytes", "(II)[B"); |
|
86 |
||
87 |
tmpClass = (*env)->FindClass(env, "sun/font/Type1Font"); |
|
88 |
sunFontIDs.readFileMID = |
|
89 |
(*env)->GetMethodID(env, tmpClass, |
|
90 |
"readFile", "(Ljava/nio/ByteBuffer;)V"); |
|
91 |
||
92 |
tmpClass = (*env)->FindClass(env, "java/awt/geom/Point2D$Float"); |
|
93 |
sunFontIDs.pt2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass); |
|
94 |
sunFontIDs.pt2DFloatCtr = |
|
95 |
(*env)->GetMethodID(env, sunFontIDs.pt2DFloatClass, "<init>","(FF)V"); |
|
96 |
||
97 |
sunFontIDs.xFID = |
|
98 |
(*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "x", "F"); |
|
99 |
sunFontIDs.yFID = |
|
100 |
(*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "y", "F"); |
|
101 |
||
102 |
tmpClass = (*env)->FindClass(env, "sun/font/StrikeMetrics"); |
|
103 |
sunFontIDs.strikeMetricsClass=(jclass)(*env)->NewGlobalRef(env, tmpClass); |
|
104 |
||
105 |
sunFontIDs.strikeMetricsCtr = |
|
106 |
(*env)->GetMethodID(env, sunFontIDs.strikeMetricsClass, |
|
107 |
"<init>", "(FFFFFFFFFF)V"); |
|
108 |
||
109 |
tmpClass = (*env)->FindClass(env, "java/awt/geom/Rectangle2D$Float"); |
|
110 |
sunFontIDs.rect2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass); |
|
111 |
sunFontIDs.rect2DFloatCtr = |
|
112 |
(*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass, "<init>", "()V"); |
|
113 |
sunFontIDs.rect2DFloatCtr4 = |
|
114 |
(*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass, |
|
115 |
"<init>", "(FFFF)V"); |
|
116 |
sunFontIDs.rectF2DX = |
|
117 |
(*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "x", "F"); |
|
118 |
sunFontIDs.rectF2DY = |
|
119 |
(*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "y", "F"); |
|
120 |
sunFontIDs.rectF2DWidth = |
|
121 |
(*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "width", "F"); |
|
122 |
sunFontIDs.rectF2DHeight = |
|
123 |
(*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "height", "F"); |
|
124 |
||
125 |
tmpClass = (*env)->FindClass(env, "java/awt/geom/GeneralPath"); |
|
126 |
sunFontIDs.gpClass = (jclass)(*env)->NewGlobalRef(env, tmpClass); |
|
127 |
sunFontIDs.gpCtr = |
|
128 |
(*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "(I[BI[FI)V"); |
|
129 |
sunFontIDs.gpCtrEmpty = |
|
130 |
(*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "()V"); |
|
131 |
||
132 |
tmpClass = (*env)->FindClass(env, "sun/font/Font2D"); |
|
133 |
sunFontIDs.f2dCharToGlyphMID = |
|
134 |
(*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I"); |
|
135 |
sunFontIDs.getMapperMID = |
|
136 |
(*env)->GetMethodID(env, tmpClass, "getMapper", |
|
137 |
"()Lsun/font/CharToGlyphMapper;"); |
|
138 |
sunFontIDs.getTableBytesMID = |
|
139 |
(*env)->GetMethodID(env, tmpClass, "getTableBytes", "(I)[B"); |
|
140 |
sunFontIDs.canDisplayMID = |
|
141 |
(*env)->GetMethodID(env, tmpClass, "canDisplay", "(C)Z"); |
|
142 |
||
143 |
tmpClass = (*env)->FindClass(env, "sun/font/CharToGlyphMapper"); |
|
144 |
sunFontIDs.charToGlyphMID = |
|
145 |
(*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I"); |
|
146 |
||
147 |
tmpClass = (*env)->FindClass(env, "sun/font/PhysicalStrike"); |
|
148 |
sunFontIDs.getGlyphMetricsMID = |
|
149 |
(*env)->GetMethodID(env, tmpClass, "getGlyphMetrics", |
|
150 |
"(I)Ljava/awt/geom/Point2D$Float;"); |
|
151 |
sunFontIDs.getGlyphPointMID = |
|
152 |
(*env)->GetMethodID(env, tmpClass, "getGlyphPoint", |
|
153 |
"(II)Ljava/awt/geom/Point2D$Float;"); |
|
154 |
sunFontIDs.adjustPointMID = |
|
155 |
(*env)->GetMethodID(env, tmpClass, "adjustPoint", |
|
156 |
"(Ljava/awt/geom/Point2D$Float;)V"); |
|
157 |
sunFontIDs.pScalerContextFID = |
|
158 |
(*env)->GetFieldID(env, tmpClass, "pScalerContext", "J"); |
|
159 |
||
160 |
tmpClass = (*env)->FindClass(env, "sun/font/GlyphList"); |
|
161 |
sunFontIDs.glyphListX = (*env)->GetFieldID(env, tmpClass, "x", "F"); |
|
162 |
sunFontIDs.glyphListY = (*env)->GetFieldID(env, tmpClass, "y", "F"); |
|
163 |
sunFontIDs.glyphListLen = (*env)->GetFieldID(env, tmpClass, "len", "I"); |
|
164 |
sunFontIDs.glyphImages = |
|
165 |
(*env)->GetFieldID(env, tmpClass, "images", "[J"); |
|
166 |
sunFontIDs.glyphListUsePos = |
|
167 |
(*env)->GetFieldID(env, tmpClass, "usePositions", "Z"); |
|
168 |
sunFontIDs.glyphListPos = |
|
169 |
(*env)->GetFieldID(env, tmpClass, "positions", "[F"); |
|
170 |
sunFontIDs.lcdRGBOrder = |
|
171 |
(*env)->GetFieldID(env, tmpClass, "lcdRGBOrder", "Z"); |
|
172 |
sunFontIDs.lcdSubPixPos = |
|
173 |
(*env)->GetFieldID(env, tmpClass, "lcdSubPixPos", "Z"); |
|
174 |
||
175 |
initLCDGammaTables(); |
|
176 |
} |
|
177 |
||
178 |
JNIEXPORT FontManagerNativeIDs getSunFontIDs() { |
|
179 |
return sunFontIDs; |
|
180 |
} |
|
181 |
||
182 |
/* |
|
183 |
* Class: sun_font_StrikeCache |
|
184 |
* Method: freeIntPointer |
|
185 |
* Signature: (I)V |
|
186 |
*/ |
|
187 |
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntPointer |
|
188 |
(JNIEnv *env, jclass cacheClass, jint ptr) { |
|
189 |
||
190 |
/* Note this is used for freeing a glyph which was allocated |
|
191 |
* but never placed into the glyph cache. The caller holds the |
|
192 |
* only reference, therefore it is unnecessary to invalidate any |
|
193 |
* accelerated glyph cache cells as we do in freeInt/LongMemory(). |
|
194 |
*/ |
|
195 |
if (ptr != 0) { |
|
196 |
free((void*)ptr); |
|
197 |
} |
|
198 |
} |
|
199 |
||
200 |
/* |
|
201 |
* Class: sun_font_StrikeCache |
|
202 |
* Method: freeLongPointer |
|
203 |
* Signature: (J)V |
|
204 |
*/ |
|
205 |
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeLongPointer |
|
206 |
(JNIEnv *env, jclass cacheClass, jlong ptr) { |
|
207 |
||
208 |
/* Note this is used for freeing a glyph which was allocated |
|
209 |
* but never placed into the glyph cache. The caller holds the |
|
210 |
* only reference, therefore it is unnecessary to invalidate any |
|
211 |
* accelerated glyph cache cells as we do in freeInt/LongMemory(). |
|
212 |
*/ |
|
213 |
if (ptr != 0L) { |
|
214 |
free(jlong_to_ptr(ptr)); |
|
215 |
} |
|
216 |
} |
|
217 |
||
218 |
/* |
|
219 |
* Class: sun_font_StrikeCache |
|
220 |
* Method: freeIntMemory |
|
221 |
* Signature: ([I)V |
|
222 |
*/ |
|
223 |
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntMemory |
|
224 |
(JNIEnv *env, jclass cacheClass, jintArray jmemArray, jlong pContext) { |
|
225 |
||
226 |
int len = (*env)->GetArrayLength(env, jmemArray); |
|
227 |
jint* ptrs = |
|
228 |
(jint*)(*env)->GetPrimitiveArrayCritical(env, jmemArray, NULL); |
|
229 |
int i; |
|
230 |
||
231 |
if (ptrs) { |
|
232 |
for (i=0; i< len; i++) { |
|
233 |
if (ptrs[i] != 0) { |
|
234 |
GlyphInfo *ginfo = (GlyphInfo *)ptrs[i]; |
|
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
235 |
if (ginfo->cellInfo != NULL && |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
236 |
ginfo->managed == MANAGED_GLYPH) { |
2 | 237 |
// invalidate this glyph's accelerated cache cell |
887 | 238 |
AccelGlyphCache_RemoveAllCellInfos(ginfo); |
2 | 239 |
} |
240 |
free((void*)ginfo); |
|
241 |
} |
|
242 |
} |
|
243 |
(*env)->ReleasePrimitiveArrayCritical(env, jmemArray, ptrs, JNI_ABORT); |
|
244 |
} |
|
245 |
if (!isNullScalerContext(jlong_to_ptr(pContext))) { |
|
246 |
free(jlong_to_ptr(pContext)); |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
/* |
|
251 |
* Class: sun_font_StrikeCache |
|
252 |
* Method: freeLongMemory |
|
253 |
* Signature: ([J)V |
|
254 |
*/ |
|
255 |
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeLongMemory |
|
256 |
(JNIEnv *env, jclass cacheClass, jlongArray jmemArray, jlong pContext) { |
|
257 |
||
258 |
int len = (*env)->GetArrayLength(env, jmemArray); |
|
259 |
jlong* ptrs = |
|
260 |
(jlong*)(*env)->GetPrimitiveArrayCritical(env, jmemArray, NULL); |
|
261 |
int i; |
|
262 |
||
263 |
if (ptrs) { |
|
264 |
for (i=0; i< len; i++) { |
|
265 |
if (ptrs[i] != 0L) { |
|
266 |
GlyphInfo *ginfo = (GlyphInfo *) jlong_to_ptr(ptrs[i]); |
|
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
267 |
if (ginfo->cellInfo != NULL && |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
268 |
ginfo->managed == MANAGED_GLYPH) { |
887 | 269 |
AccelGlyphCache_RemoveAllCellInfos(ginfo); |
2 | 270 |
} |
271 |
free((void*)ginfo); |
|
272 |
} |
|
273 |
} |
|
274 |
(*env)->ReleasePrimitiveArrayCritical(env, jmemArray, ptrs, JNI_ABORT); |
|
275 |
} |
|
276 |
if (!isNullScalerContext(jlong_to_ptr(pContext))) { |
|
277 |
free(jlong_to_ptr(pContext)); |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
JNIEXPORT void JNICALL |
|
282 |
Java_sun_font_StrikeCache_getGlyphCacheDescription |
|
283 |
(JNIEnv *env, jclass cls, jlongArray results) { |
|
284 |
||
285 |
jlong* nresults; |
|
286 |
GlyphInfo *info; |
|
287 |
size_t baseAddr; |
|
288 |
||
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
289 |
if ((*env)->GetArrayLength(env, results) < 13) { |
2 | 290 |
return; |
291 |
} |
|
292 |
||
293 |
nresults = (jlong*)(*env)->GetPrimitiveArrayCritical(env, results, NULL); |
|
294 |
if (nresults == NULL) { |
|
295 |
return; |
|
296 |
} |
|
297 |
info = (GlyphInfo*) calloc(1, sizeof(GlyphInfo)); |
|
298 |
if (info == NULL) { |
|
299 |
(*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0); |
|
300 |
return; |
|
301 |
} |
|
302 |
baseAddr = (size_t)info; |
|
303 |
nresults[0] = sizeof(void*); |
|
304 |
nresults[1] = sizeof(GlyphInfo); |
|
305 |
nresults[2] = 0; |
|
306 |
nresults[3] = (size_t)&(info->advanceY)-baseAddr; |
|
307 |
nresults[4] = (size_t)&(info->width)-baseAddr; |
|
308 |
nresults[5] = (size_t)&(info->height)-baseAddr; |
|
309 |
nresults[6] = (size_t)&(info->rowBytes)-baseAddr; |
|
310 |
nresults[7] = (size_t)&(info->topLeftX)-baseAddr; |
|
311 |
nresults[8] = (size_t)&(info->topLeftY)-baseAddr; |
|
312 |
nresults[9] = (size_t)&(info->image)-baseAddr; |
|
313 |
nresults[10] = (jlong)(uintptr_t)info; /* invisible glyph */ |
|
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
314 |
nresults[11] = (size_t)&(info->cellInfo)-baseAddr; |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
315 |
nresults[12] = (size_t)&(info->managed)-baseAddr; |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
3928
diff
changeset
|
316 |
|
2 | 317 |
(*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0); |
318 |
} |
|
319 |
||
320 |
JNIEXPORT TTLayoutTableCache* newLayoutTableCache() { |
|
321 |
TTLayoutTableCache* ltc = calloc(1, sizeof(TTLayoutTableCache)); |
|
322 |
if (ltc) { |
|
16891 | 323 |
int i; |
324 |
for(i=0;i<LAYOUTCACHE_ENTRIES;i++) { |
|
325 |
ltc->entries[i].len = -1; |
|
326 |
} |
|
2 | 327 |
} |
328 |
return ltc; |
|
329 |
} |
|
330 |
||
331 |
JNIEXPORT void freeLayoutTableCache(TTLayoutTableCache* ltc) { |
|
332 |
if (ltc) { |
|
16891 | 333 |
int i; |
334 |
for(i=0;i<LAYOUTCACHE_ENTRIES;i++) { |
|
335 |
if(ltc->entries[i].ptr) free (ltc->entries[i].ptr); |
|
336 |
} |
|
2 | 337 |
if (ltc->kernPairs) free(ltc->kernPairs); |
338 |
free(ltc); |
|
339 |
} |
|
340 |
} |