jdk/src/share/native/sun/font/sunFont.c
author tdv
Fri, 18 Jul 2008 10:48:44 -0700
changeset 887 0aab8d3fa11a
parent 2 90ce3da70b43
child 3928 be186a33df9b
permissions -rw-r--r--
6725214: D3D: forward-port the new pipeline from 6u10 Summary: Forward port of the new Direct3D 9 rendering pipeline from 6u10. Also includes fixes for 6690659 6689025 6658398 6596234. Reviewed-by: campbell, prr
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Class:     sun_font_FontManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Method:    getPlatformFontVar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
Java_sun_font_FontManager_getPlatformFontVar(JNIEnv *env, jclass cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    char *c = getenv("JAVA2D_USEPLATFORMFONT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    if (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/* placeholder for extern variable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
FontManagerNativeIDs sunFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
Java_sun_font_FontManager_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    (JNIEnv *env, jclass cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     jclass tmpClass = (*env)->FindClass(env, "java/awt/Font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     sunFontIDs.getFont2DMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         (*env)->GetMethodID(env, tmpClass, "getFont2D",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                             "()Lsun/font/Font2D;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     sunFontIDs.font2DHandle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
       (*env)->GetFieldID(env, tmpClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                          "font2DHandle", "Lsun/font/Font2DHandle;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     sunFontIDs.createdFont =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
       (*env)->GetFieldID(env, tmpClass, "createdFont", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     sunFontIDs.ttReadBlockMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         (*env)->GetMethodID(env, tmpClass, "readBlock",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                             "(Ljava/nio/ByteBuffer;II)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     sunFontIDs.ttReadBytesMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         (*env)->GetMethodID(env, tmpClass, "readBytes", "(II)[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     tmpClass = (*env)->FindClass(env, "sun/font/Type1Font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     sunFontIDs.readFileMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         (*env)->GetMethodID(env, tmpClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                             "readFile", "(Ljava/nio/ByteBuffer;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     tmpClass = (*env)->FindClass(env, "java/awt/geom/Point2D$Float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     sunFontIDs.pt2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     sunFontIDs.pt2DFloatCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         (*env)->GetMethodID(env, sunFontIDs.pt2DFloatClass, "<init>","(FF)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     sunFontIDs.xFID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         (*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "x", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     sunFontIDs.yFID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         (*env)->GetFieldID(env, sunFontIDs.pt2DFloatClass, "y", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     tmpClass = (*env)->FindClass(env, "sun/font/StrikeMetrics");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     sunFontIDs.strikeMetricsClass=(jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     sunFontIDs.strikeMetricsCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         (*env)->GetMethodID(env, sunFontIDs.strikeMetricsClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                             "<init>", "(FFFFFFFFFF)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     tmpClass = (*env)->FindClass(env, "java/awt/geom/Rectangle2D$Float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     sunFontIDs.rect2DFloatClass = (jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     sunFontIDs.rect2DFloatCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
       (*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     sunFontIDs.rect2DFloatCtr4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
       (*env)->GetMethodID(env, sunFontIDs.rect2DFloatClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                           "<init>", "(FFFF)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     sunFontIDs.rectF2DX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "x", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     sunFontIDs.rectF2DY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "y", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     sunFontIDs.rectF2DWidth =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "width", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     sunFontIDs.rectF2DHeight =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         (*env)->GetFieldID(env, sunFontIDs.rect2DFloatClass, "height", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     tmpClass = (*env)->FindClass(env, "java/awt/geom/GeneralPath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     sunFontIDs.gpClass = (jclass)(*env)->NewGlobalRef(env, tmpClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     sunFontIDs.gpCtr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
       (*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "(I[BI[FI)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     sunFontIDs.gpCtrEmpty =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
       (*env)->GetMethodID(env, sunFontIDs.gpClass, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     tmpClass = (*env)->FindClass(env, "sun/font/Font2D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     sunFontIDs.f2dCharToGlyphMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     sunFontIDs.getMapperMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         (*env)->GetMethodID(env, tmpClass, "getMapper",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                             "()Lsun/font/CharToGlyphMapper;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     sunFontIDs.getTableBytesMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         (*env)->GetMethodID(env, tmpClass, "getTableBytes", "(I)[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     sunFontIDs.canDisplayMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         (*env)->GetMethodID(env, tmpClass, "canDisplay", "(C)Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     tmpClass = (*env)->FindClass(env, "sun/font/CharToGlyphMapper");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     sunFontIDs.charToGlyphMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        (*env)->GetMethodID(env, tmpClass, "charToGlyph", "(I)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     tmpClass = (*env)->FindClass(env, "sun/font/PhysicalStrike");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     sunFontIDs.getGlyphMetricsMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         (*env)->GetMethodID(env, tmpClass, "getGlyphMetrics",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                             "(I)Ljava/awt/geom/Point2D$Float;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     sunFontIDs.getGlyphPointMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         (*env)->GetMethodID(env, tmpClass, "getGlyphPoint",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                             "(II)Ljava/awt/geom/Point2D$Float;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     sunFontIDs.adjustPointMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         (*env)->GetMethodID(env, tmpClass, "adjustPoint",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                             "(Ljava/awt/geom/Point2D$Float;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     sunFontIDs.pScalerContextFID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         (*env)->GetFieldID(env, tmpClass, "pScalerContext", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     tmpClass = (*env)->FindClass(env, "sun/font/GlyphList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     sunFontIDs.glyphListX = (*env)->GetFieldID(env, tmpClass, "x", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     sunFontIDs.glyphListY = (*env)->GetFieldID(env, tmpClass, "y", "F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     sunFontIDs.glyphListLen = (*env)->GetFieldID(env, tmpClass, "len", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     sunFontIDs.glyphImages =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         (*env)->GetFieldID(env, tmpClass, "images", "[J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     sunFontIDs.glyphListUsePos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         (*env)->GetFieldID(env, tmpClass, "usePositions", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     sunFontIDs.glyphListPos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         (*env)->GetFieldID(env, tmpClass, "positions", "[F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     sunFontIDs.lcdRGBOrder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         (*env)->GetFieldID(env, tmpClass, "lcdRGBOrder", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     sunFontIDs.lcdSubPixPos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         (*env)->GetFieldID(env, tmpClass, "lcdSubPixPos", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     initLCDGammaTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
JNIEXPORT FontManagerNativeIDs getSunFontIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    return sunFontIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
Java_sun_font_FontManager_getFont2D(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
  JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  jclass clsFM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  jobject javaFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    return (*env)->CallObjectMethod(env, javaFont, sunFontIDs.getFont2DMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
Java_sun_font_FontManager_setFont2D(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  jclass clsFM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  jobject javaFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  jobject fontHandle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    (*env)->SetObjectField(env, javaFont, sunFontIDs.font2DHandle, fontHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
Java_sun_font_FontManager_setCreatedFont(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  jclass clsFM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  jobject javaFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    (*env)->SetBooleanField(env, javaFont, sunFontIDs.createdFont, JNI_TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
Java_sun_font_FontManager_isCreatedFont(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  jclass clsFM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  jobject javaFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    return (*env)->GetBooleanField(env, javaFont, sunFontIDs.createdFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * Method:    freeIntPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * Signature: (I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    (JNIEnv *env, jclass cacheClass, jint ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /* Note this is used for freeing a glyph which was allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * but never placed into the glyph cache. The caller holds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * only reference, therefore it is unnecessary to invalidate any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * accelerated glyph cache cells as we do in freeInt/LongMemory().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    if (ptr != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        free((void*)ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * Method:    freeLongPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeLongPointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    (JNIEnv *env, jclass cacheClass, jlong ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /* Note this is used for freeing a glyph which was allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * but never placed into the glyph cache. The caller holds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * only reference, therefore it is unnecessary to invalidate any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * accelerated glyph cache cells as we do in freeInt/LongMemory().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if (ptr != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        free(jlong_to_ptr(ptr));
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * Method:    freeIntMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeIntMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    (JNIEnv *env, jclass cacheClass, jintArray jmemArray, jlong pContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    int len = (*env)->GetArrayLength(env, jmemArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    jint* ptrs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        (jint*)(*env)->GetPrimitiveArrayCritical(env, jmemArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    if (ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        for (i=0; i< len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (ptrs[i] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                GlyphInfo *ginfo = (GlyphInfo *)ptrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                if (ginfo->cellInfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    // invalidate this glyph's accelerated cache cell
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   299
                    AccelGlyphCache_RemoveAllCellInfos(ginfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                free((void*)ginfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        (*env)->ReleasePrimitiveArrayCritical(env, jmemArray, ptrs, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (!isNullScalerContext(jlong_to_ptr(pContext))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        free(jlong_to_ptr(pContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * Class:     sun_font_StrikeCache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 * Method:    freeLongMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 * Signature: ([J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
JNIEXPORT void JNICALL Java_sun_font_StrikeCache_freeLongMemory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    (JNIEnv *env, jclass cacheClass, jlongArray jmemArray, jlong pContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    int len = (*env)->GetArrayLength(env, jmemArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    jlong* ptrs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        (jlong*)(*env)->GetPrimitiveArrayCritical(env, jmemArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    if (ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        for (i=0; i< len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            if (ptrs[i] != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                GlyphInfo *ginfo = (GlyphInfo *) jlong_to_ptr(ptrs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                if (ginfo->cellInfo != NULL) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   329
                    AccelGlyphCache_RemoveAllCellInfos(ginfo);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                free((void*)ginfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        (*env)->ReleasePrimitiveArrayCritical(env, jmemArray, ptrs, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    if (!isNullScalerContext(jlong_to_ptr(pContext))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        free(jlong_to_ptr(pContext));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
Java_sun_font_StrikeCache_getGlyphCacheDescription
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  (JNIEnv *env, jclass cls, jlongArray results) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    jlong* nresults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    GlyphInfo *info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    size_t baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    if ((*env)->GetArrayLength(env, results) < 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    nresults = (jlong*)(*env)->GetPrimitiveArrayCritical(env, results, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    if (nresults == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    info = (GlyphInfo*) calloc(1, sizeof(GlyphInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (info == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        (*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    baseAddr = (size_t)info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    nresults[0] = sizeof(void*);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    nresults[1] = sizeof(GlyphInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    nresults[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    nresults[3] = (size_t)&(info->advanceY)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    nresults[4] = (size_t)&(info->width)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    nresults[5] = (size_t)&(info->height)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    nresults[6] = (size_t)&(info->rowBytes)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    nresults[7] = (size_t)&(info->topLeftX)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    nresults[8] = (size_t)&(info->topLeftY)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    nresults[9] = (size_t)&(info->image)-baseAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    nresults[10] = (jlong)(uintptr_t)info; /* invisible glyph */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    (*env)->ReleasePrimitiveArrayCritical(env, results, nresults, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
JNIEXPORT TTLayoutTableCache* newLayoutTableCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  TTLayoutTableCache* ltc = calloc(1, sizeof(TTLayoutTableCache));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  if (ltc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    ltc->gsub_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    ltc->gpos_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    ltc->gdef_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    ltc->mort_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    ltc->kern_len = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  return ltc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
JNIEXPORT void freeLayoutTableCache(TTLayoutTableCache* ltc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  if (ltc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    if (ltc->gsub) free(ltc->gsub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    if (ltc->gpos) free(ltc->gpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if (ltc->gdef) free(ltc->gdef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    if (ltc->mort) free(ltc->mort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    if (ltc->kern) free(ltc->kern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if (ltc->kernPairs) free(ltc->kernPairs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    free(ltc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
}