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