jdk/src/share/native/sun/font/sunFont.c
author rkennke
Fri, 07 Aug 2009 18:31:11 +0200
changeset 3928 be186a33df9b
parent 887 0aab8d3fa11a
child 5506 202f599c92aa
child 5579 1a5e995a710b
permissions -rw-r--r--
6795908: Refactor FontManager Reviewed-by: prr, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
     2
 * Copyright 2007-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 "malloc.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "string.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "gdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "sunfontids.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "fontscalerdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "sun_font_FontManager.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "sun_font_NullFontScaler.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "sun_font_StrikeCache.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
static void *theNullScalerContext = NULL;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    38
extern void AccelGlyphCache_RemoveAllCellInfos(GlyphInfo *glyph);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    39
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
Java_sun_font_NullFontScaler_getNullScalerContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    (JNIEnv *env, jclass scalerClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    if (theNullScalerContext == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        theNullScalerContext = malloc(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    return ptr_to_jlong(theNullScalerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
int isNullScalerContext(void *context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    return theNullScalerContext == context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* Eventually we may rework it to be a singleton.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This will require additional checks in freeLongMemory/freeIntMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * and on other hand malformed fonts (main source of null glyph images)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * are supposed to be collected fast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * But perhaps it is still right thing to do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Even better is to eliminate the need to have this native method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * but for this it is necessary to rework Strike and drawing logic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * to be able to live with NULL pointers without performance hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
JNIEXPORT jlong JNICALL Java_sun_font_NullFontScaler_getGlyphImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  (JNIEnv *env, jobject scaler, jlong pContext, jint glyphCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    void *nullscaler = calloc(sizeof(GlyphInfo), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    return ptr_to_jlong(nullscaler);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
void initLCDGammaTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/* placeholder for extern variable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
FontManagerNativeIDs sunFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
JNIEXPORT void JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 887
diff changeset
    78
Java_sun_font_SunFontManager_initIDs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    (JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 887
diff changeset
    81
     jclass tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     sunFontIDs.ttReadBlockMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         (*env)->GetMethodID(env, tmpClass, "readBlock",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                             "(Ljava/nio/ByteBuffer;II)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     sunFontIDs.ttReadBytesMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         (*env)->GetMethodID(env, tmpClass, "readBytes", "(II)[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     tmpClass = (*env)->FindClass(env, "sun/font/Type1Font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     sunFontIDs.readFileMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         (*env)->GetMethodID(env, tmpClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                             "readFile", "(Ljava/nio/ByteBuffer;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     tmpClass = (*env)->FindClass(env, "java/awt/geom/Point2D$Float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     sunFontIDs.pt2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     sunFontIDs.pt2DFloatCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         (*env)->GetMethodID(env, sunFontIDs.pt2DFloatClass, "<init>","(FF)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     sunFontIDs.xFID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         (*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "x", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     sunFontIDs.yFID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         (*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "y", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     tmpClass = (*env)->FindClass(env, "sun/font/StrikeMetrics");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     sunFontIDs.strikeMetricsClass=(jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     sunFontIDs.strikeMetricsCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         (*env)->GetMethodID(env, sunFontIDs.strikeMetricsClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                             "<init>", "(FFFFFFFFFF)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     tmpClass = (*env)->FindClass(env, "java/awt/geom/Rectangle2D$Float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     sunFontIDs.rect2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     sunFontIDs.rect2DFloatCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
       (*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     sunFontIDs.rect2DFloatCtr4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
       (*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                           "<init>", "(FFFF)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     sunFontIDs.rectF2DX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "x", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     sunFontIDs.rectF2DY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "y", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     sunFontIDs.rectF2DWidth =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "width", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     sunFontIDs.rectF2DHeight =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "height", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     tmpClass = (*env)->FindClass(env, "java/awt/geom/GeneralPath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     sunFontIDs.gpClass = (jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     sunFontIDs.gpCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
       (*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "(I[BI[FI)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     sunFontIDs.gpCtrEmpty =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
       (*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     tmpClass = (*env)->FindClass(env, "sun/font/Font2D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     sunFontIDs.f2dCharToGlyphMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     sunFontIDs.getMapperMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         (*env)->GetMethodID(env, tmpClass, "getMapper",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                             "()Lsun/font/CharToGlyphMapper;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     sunFontIDs.getTableBytesMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         (*env)->GetMethodID(env, tmpClass, "getTableBytes", "(I)[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     sunFontIDs.canDisplayMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         (*env)->GetMethodID(env, tmpClass, "canDisplay", "(C)Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     tmpClass = (*env)->FindClass(env, "sun/font/CharToGlyphMapper");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     sunFontIDs.charToGlyphMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     tmpClass = (*env)->FindClass(env, "sun/font/PhysicalStrike");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     sunFontIDs.getGlyphMetricsMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         (*env)->GetMethodID(env, tmpClass, "getGlyphMetrics",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                             "(I)Ljava/awt/geom/Point2D$Float;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     sunFontIDs.getGlyphPointMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         (*env)->GetMethodID(env, tmpClass, "getGlyphPoint",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                             "(II)Ljava/awt/geom/Point2D$Float;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     sunFontIDs.adjustPointMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         (*env)->GetMethodID(env, tmpClass, "adjustPoint",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                             "(Ljava/awt/geom/Point2D$Float;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     sunFontIDs.pScalerContextFID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         (*env)->GetFieldID(env, tmpClass, "pScalerContext", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     tmpClass = (*env)->FindClass(env, "sun/font/GlyphList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     sunFontIDs.glyphListX = (*env)->GetFieldID(env, tmpClass, "x", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     sunFontIDs.glyphListY = (*env)->GetFieldID(env, tmpClass, "y", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     sunFontIDs.glyphListLen = (*env)->GetFieldID(env, tmpClass, "len", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     sunFontIDs.glyphImages =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         (*env)->GetFieldID(env, tmpClass, "images", "[J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     sunFontIDs.glyphListUsePos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         (*env)->GetFieldID(env, tmpClass, "usePositions", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     sunFontIDs.glyphListPos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         (*env)->GetFieldID(env, tmpClass, "positions", "[F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     sunFontIDs.lcdRGBOrder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         (*env)->GetFieldID(env, tmpClass, "lcdRGBOrder", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     sunFontIDs.lcdSubPixPos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         (*env)->GetFieldID(env, tmpClass, "lcdSubPixPos", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     initLCDGammaTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
JNIEXPORT FontManagerNativeIDs getSunFontIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    return sunFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * Method:    freeIntPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * Signature: (I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    (JNIEnv *env, jclass cacheClass, jint ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /* Note this is used for freeing a glyph which was allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * but never placed into the glyph cache. The caller holds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * only reference, therefore it is unnecessary to invalidate any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * accelerated glyph cache cells as we do in freeInt/LongMemory().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    if (ptr != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        free((void*)ptr);
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * Method:    freeLongPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeLongPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    (JNIEnv *env, jclass cacheClass, jlong ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /* Note this is used for freeing a glyph which was allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * but never placed into the glyph cache. The caller holds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * only reference, therefore it is unnecessary to invalidate any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * accelerated glyph cache cells as we do in freeInt/LongMemory().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    if (ptr != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        free(jlong_to_ptr(ptr));
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * Method:    freeIntMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    (JNIEnv *env, jclass cacheClass, jintArray jmemArray, jlong pContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    int len = (*env)->GetArrayLength(env, jmemArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    jint* ptrs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        (jint*)(*env)->GetPrimitiveArrayCritical(env, jmemArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        for (i=0; i< len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (ptrs[i] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                GlyphInfo *ginfo = (GlyphInfo *)ptrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (ginfo->cellInfo != NULL) {
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]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                if (ginfo->cellInfo != NULL) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   268
                    AccelGlyphCache_RemoveAllCellInfos(ginfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                free((void*)ginfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        (*env)->ReleasePrimitiveArrayCritical(env, jmemArray, ptrs, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if (!isNullScalerContext(jlong_to_ptr(pContext))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        free(jlong_to_ptr(pContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
Java_sun_font_StrikeCache_getGlyphCacheDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  (JNIEnv *env, jclass cls, jlongArray results) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    jlong* nresults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    GlyphInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    size_t baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if ((*env)->GetArrayLength(env, results) < 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    nresults = (jlong*)(*env)->GetPrimitiveArrayCritical(env, results, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    if (nresults == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    info = (GlyphInfo*) calloc(1, sizeof(GlyphInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    if (info == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        (*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    baseAddr = (size_t)info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    nresults[0] = sizeof(void*);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    nresults[1] = sizeof(GlyphInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    nresults[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    nresults[3] = (size_t)&(info->advanceY)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    nresults[4] = (size_t)&(info->width)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    nresults[5] = (size_t)&(info->height)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    nresults[6] = (size_t)&(info->rowBytes)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    nresults[7] = (size_t)&(info->topLeftX)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    nresults[8] = (size_t)&(info->topLeftY)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    nresults[9] = (size_t)&(info->image)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    nresults[10] = (jlong)(uintptr_t)info; /* invisible glyph */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    (*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
JNIEXPORT TTLayoutTableCache* newLayoutTableCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  TTLayoutTableCache* ltc = calloc(1, sizeof(TTLayoutTableCache));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
  if (ltc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    ltc->gsub_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    ltc->gpos_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    ltc->gdef_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    ltc->mort_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    ltc->kern_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
  return ltc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
JNIEXPORT void freeLayoutTableCache(TTLayoutTableCache* ltc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  if (ltc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (ltc->gsub) free(ltc->gsub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    if (ltc->gpos) free(ltc->gpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    if (ltc->gdef) free(ltc->gdef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    if (ltc->mort) free(ltc->mort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    if (ltc->kern) free(ltc->kern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    if (ltc->kernPairs) free(ltc->kernPairs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    free(ltc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
}