< prev index next >
src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m
Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion
*** 28,42 ****
#import "sun_awt_SunHints.h"
#import "sun_lwawt_macosx_CTextPipe.h"
#import "sun_java2d_OSXSurfaceData.h"
- #import <JavaNativeFoundation/JavaNativeFoundation.h>
-
#import "CoreTextSupport.h"
#import "QuartzSurfaceData.h"
#include "AWTStrike.h"
static const CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
#pragma mark --- CoreText Support ---
--- 28,41 ----
#import "sun_awt_SunHints.h"
#import "sun_lwawt_macosx_CTextPipe.h"
#import "sun_java2d_OSXSurfaceData.h"
#import "CoreTextSupport.h"
#import "QuartzSurfaceData.h"
#include "AWTStrike.h"
+ #import "JNIUtilities.h"
static const CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 };
#pragma mark --- CoreText Support ---
*** 320,339 ****
acquired at a given stage, must be released in that stage. Any error that occurs (like a failed malloc)
is to be handled in the stage it occurs in, and is to return immediatly after freeing it's resources.
-----------------------------------*/
! static JNF_CLASS_CACHE(jc_StandardGlyphVector, "sun/font/StandardGlyphVector");
// Checks the GlyphVector Java object for any transforms that were applied to individual characters. If none are present,
// strike the glyphs immediately in Core Graphics. Otherwise, obtain the arrays, and defer to above.
static inline void doDrawGlyphsPipe_checkForPerGlyphTransforms
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, BOOL useSubstituion, int *uniChars, CGGlyph *glyphs, CGSize *advances, size_t length)
{
// if we have no character substitution, and no per-glyph transformations - strike now!
! static JNF_MEMBER_CACHE(jm_StandardGlyphVector_gti, jc_StandardGlyphVector, "gti", "Lsun/font/StandardGlyphVector$GlyphTransformInfo;");
! jobject gti = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_gti);
if (gti == 0)
{
if (useSubstituion)
{
// quasi-simple case, substitution, but no per-glyph transforms
--- 319,340 ----
acquired at a given stage, must be released in that stage. Any error that occurs (like a failed malloc)
is to be handled in the stage it occurs in, and is to return immediatly after freeing it's resources.
-----------------------------------*/
! static jclass jc_StandardGlyphVector = NULL;
! #define GET_SGV_CLASS() GET_CLASS(jc_StandardGlyphVector, "sun/font/StandardGlyphVector");
// Checks the GlyphVector Java object for any transforms that were applied to individual characters. If none are present,
// strike the glyphs immediately in Core Graphics. Otherwise, obtain the arrays, and defer to above.
static inline void doDrawGlyphsPipe_checkForPerGlyphTransforms
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, BOOL useSubstituion, int *uniChars, CGGlyph *glyphs, CGSize *advances, size_t length)
{
// if we have no character substitution, and no per-glyph transformations - strike now!
! GET_SGV_CLASS();
! DECLARE_FIELD(jm_StandardGlyphVector_gti, jc_StandardGlyphVector, "gti", "Lsun/font/StandardGlyphVector$GlyphTransformInfo;");
! jobject gti = (*env)->GetObjectField(env, gVector, jm_StandardGlyphVector_gti);
if (gti == 0)
{
if (useSubstituion)
{
// quasi-simple case, substitution, but no per-glyph transforms
*** 345,368 ****
CGContextShowGlyphsWithAdvances(qsdo->cgRef, glyphs, advances, length);
}
return;
}
! static JNF_CLASS_CACHE(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo");
! static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D");
! jdoubleArray g_gtiTransformsArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms);
if (g_gtiTransformsArray == NULL) {
return;
}
jdouble *g_gvTransformsAsDoubles = (*env)->GetPrimitiveArrayCritical(env, g_gtiTransformsArray, NULL);
if (g_gvTransformsAsDoubles == NULL) {
(*env)->DeleteLocalRef(env, g_gtiTransformsArray);
return;
}
! static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I");
! jintArray g_gtiTXIndicesArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices);
jint *g_gvTXIndicesAsInts = (*env)->GetPrimitiveArrayCritical(env, g_gtiTXIndicesArray, NULL);
if (g_gvTXIndicesAsInts == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT);
(*env)->DeleteLocalRef(env, g_gtiTransformsArray);
(*env)->DeleteLocalRef(env, g_gtiTXIndicesArray);
--- 346,369 ----
CGContextShowGlyphsWithAdvances(qsdo->cgRef, glyphs, advances, length);
}
return;
}
! DECLARE_CLASS(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo");
! DECLARE_FIELD(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D");
! jdoubleArray g_gtiTransformsArray = (*env)->GetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms);
if (g_gtiTransformsArray == NULL) {
return;
}
jdouble *g_gvTransformsAsDoubles = (*env)->GetPrimitiveArrayCritical(env, g_gtiTransformsArray, NULL);
if (g_gvTransformsAsDoubles == NULL) {
(*env)->DeleteLocalRef(env, g_gtiTransformsArray);
return;
}
! DECLARE_FIELD(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I");
! jintArray g_gtiTXIndicesArray = (*env)->GetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices);
jint *g_gvTXIndicesAsInts = (*env)->GetPrimitiveArrayCritical(env, g_gtiTXIndicesArray, NULL);
if (g_gvTXIndicesAsInts == NULL) {
(*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT);
(*env)->DeleteLocalRef(env, g_gtiTransformsArray);
(*env)->DeleteLocalRef(env, g_gtiTXIndicesArray);
*** 435,446 ****
}
(*env)->ReleasePrimitiveArrayCritical(env, glyphsArray, glyphsAsInts, JNI_ABORT);
// fill the advance buffer
! static JNF_MEMBER_CACHE(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F");
! jfloatArray posArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_positions);
jfloat *positions = NULL;
if (posArray != NULL) {
// in this case, the positions have already been pre-calculated for us on the Java side
positions = (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
if (positions == NULL) {
--- 436,448 ----
}
(*env)->ReleasePrimitiveArrayCritical(env, glyphsArray, glyphsAsInts, JNI_ABORT);
// fill the advance buffer
! GET_SGV_CLASS();
! DECLARE_FIELD(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F");
! jfloatArray posArray = (*env)->GetObjectField(env, gVector, jm_StandardGlyphVector_positions);
jfloat *positions = NULL;
if (posArray != NULL) {
// in this case, the positions have already been pre-calculated for us on the Java side
positions = (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
if (positions == NULL) {
*** 495,506 ****
// Obtains the glyph array to determine the number of glyphs we are dealing with. If we are dealing a large number of glyphs,
// we malloc a buffer to hold the glyphs and their advances, otherwise we use stack allocated buffers.
static inline void doDrawGlyphsPipe_getGlyphVectorLengthAndAlloc
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector)
{
! static JNF_MEMBER_CACHE(jm_StandardGlyphVector_glyphs, jc_StandardGlyphVector, "glyphs", "[I");
! jintArray glyphsArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_glyphs);
jsize length = (*env)->GetArrayLength(env, glyphsArray);
if (length == 0)
{
// nothing to draw
--- 497,509 ----
// Obtains the glyph array to determine the number of glyphs we are dealing with. If we are dealing a large number of glyphs,
// we malloc a buffer to hold the glyphs and their advances, otherwise we use stack allocated buffers.
static inline void doDrawGlyphsPipe_getGlyphVectorLengthAndAlloc
(JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector)
{
! GET_SGV_CLASS();
! DECLARE_FIELD(jm_StandardGlyphVector_glyphs, jc_StandardGlyphVector, "glyphs", "[I");
! jintArray glyphsArray = (*env)->GetObjectField(env, gVector, jm_StandardGlyphVector_glyphs);
jsize length = (*env)->GetArrayLength(env, glyphsArray);
if (length == 0)
{
// nothing to draw
*** 579,616 ****
* Signature: (Lsun/java2d/SurfaceData;JLjava/lang/String;DD)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doDrawString
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jstring str, jdouble x, jdouble y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNF_COCOA_ENTER(env);
jsize len = (*env)->GetStringLength(env, str);
if (len < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation <rdar://problem/4285041>
{
jchar unichars[len];
(*env)->GetStringRegion(env, str, 0, len, unichars);
! JNF_CHECK_AND_RETHROW_EXCEPTION(env);
// Draw the text context
DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y);
}
else
{
// Get string to draw and the length
! const jchar *unichars = JNFGetStringUTF16UniChars(env, str);
// Draw the text context
DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y);
! JNFReleaseStringUTF16UniChars(env, str, unichars);
}
! JNF_COCOA_RENDERER_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CTextPipe
--- 582,626 ----
* Signature: (Lsun/java2d/SurfaceData;JLjava/lang/String;DD)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doDrawString
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jstring str, jdouble x, jdouble y)
{
+ if (str == NULL) {
+ return;
+ }
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNI_COCOA_ENTER(env);
jsize len = (*env)->GetStringLength(env, str);
if (len < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation <rdar://problem/4285041>
{
jchar unichars[len];
(*env)->GetStringRegion(env, str, 0, len, unichars);
! CHECK_EXCEPTION();
// Draw the text context
DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y);
}
else
{
// Get string to draw and the length
! const jchar *unichars = (*env)->GetStringChars(env, str, NULL);
! if (unichars == NULL) {
! JNU_ThrowOutOfMemoryError(env, "Could not get string chars");
! return;
! }
// Draw the text context
DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y);
! (*env)->ReleaseStringChars(env, str, unichars);
}
! JNI_COCOA_RENDERER_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CTextPipe
*** 621,657 ****
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jcharArray unicodes, jint offset, jint length, jfloat x, jfloat y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNF_COCOA_ENTER(env);
// Setup the text context
if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation
{
jchar copyUnichars[length];
(*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars);
! JNF_CHECK_AND_RETHROW_EXCEPTION(env);
DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y);
}
else
{
jchar *copyUnichars = malloc(length * sizeof(jchar));
if (!copyUnichars) {
! [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory to create the glyphs for string drawing"];
}
@try {
(*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars);
! JNF_CHECK_AND_RETHROW_EXCEPTION(env);
DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y);
} @finally {
free(copyUnichars);
}
}
! JNF_COCOA_RENDERER_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doOneUnicode
--- 631,668 ----
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jcharArray unicodes, jint offset, jint length, jfloat x, jfloat y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNI_COCOA_ENTER(env);
// Setup the text context
if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation
{
jchar copyUnichars[length];
(*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars);
! CHECK_EXCEPTION();
DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y);
}
else
{
jchar *copyUnichars = malloc(length * sizeof(jchar));
if (!copyUnichars) {
! JNU_ThrowOutOfMemoryError(env, "Failed to malloc memory to create the glyphs for string drawing");
! return;
}
@try {
(*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars);
! CHECK_EXCEPTION();
DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y);
} @finally {
free(copyUnichars);
}
}
! JNI_COCOA_RENDERER_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doOneUnicode
*** 661,675 ****
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jchar aUnicode, jfloat x, jfloat y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNF_COCOA_ENTER(env);
DrawTextContext(env, qsdo, awtStrike, &aUnicode, 1, x, y);
! JNF_COCOA_RENDERER_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doDrawGlyphs
--- 672,686 ----
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jchar aUnicode, jfloat x, jfloat y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNI_COCOA_ENTER(env);
DrawTextContext(env, qsdo, awtStrike, &aUnicode, 1, x, y);
! JNI_COCOA_RENDERER_EXIT(env);
}
/*
* Class: sun_lwawt_macosx_CTextPipe
* Method: doDrawGlyphs
*** 679,689 ****
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jobject gVector, jfloat x, jfloat y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNF_COCOA_ENTER(env);
qsdo->BeginSurface(env, qsdo, SD_Text);
if (qsdo->cgRef == NULL)
{
qsdo->FinishSurface(env, qsdo);
--- 690,700 ----
(JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jobject gVector, jfloat x, jfloat y)
{
QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata);
AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr);
! JNI_COCOA_ENTER(env);
qsdo->BeginSurface(env, qsdo, SD_Text);
if (qsdo->cgRef == NULL)
{
qsdo->FinishSurface(env, qsdo);
*** 697,703 ****
CGContextRestoreGState(qsdo->cgRef);
qsdo->FinishSurface(env, qsdo);
! JNF_COCOA_RENDERER_EXIT(env);
}
--- 708,714 ----
CGContextRestoreGState(qsdo->cgRef);
qsdo->FinishSurface(env, qsdo);
! JNI_COCOA_RENDERER_EXIT(env);
}
< prev index next >