< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m

Print this page
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


  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #import "QuartzSurfaceData.h"
  27 
  28 #import "java_awt_BasicStroke.h"
  29 #import "java_awt_AlphaComposite.h"
  30 #import "java_awt_geom_PathIterator.h"
  31 #import "java_awt_image_BufferedImage.h"
  32 #import "sun_awt_SunHints.h"
  33 #import "sun_java2d_CRenderer.h"
  34 #import "sun_java2d_OSXSurfaceData.h"
  35 #import "sun_lwawt_macosx_CPrinterSurfaceData.h"
  36 #import "ImageSurfaceData.h"
  37 
  38 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  39 
  40 #import <AppKit/AppKit.h>
  41 #import "ThreadUtilities.h"
  42 
  43 //#define DEBUG
  44 #if defined DEBUG
  45     #define PRINT(msg) {fprintf(stderr, "%s\n", msg);}
  46 #else
  47     #define PRINT(msg) {}
  48 #endif
  49 
  50 #define kOffset (0.5f)
  51 






  52 BOOL gAdjustForJavaDrawing;
  53 
  54 #pragma mark
  55 #pragma mark --- Color Cache ---
  56 
  57 // Creating and deleting CGColorRefs can be expensive, therefore we have a color cache.
  58 // The color cache was first introduced with <rdar://problem/3923927>
  59 // With <rdar://problem/4280514>, the hashing function was improved
  60 // With <rdar://problem/4012223>, the color cache became global (per process) instead of per surface.
  61 
  62 // Must be power of 2. 1024 is the least power of 2 number that makes SwingSet2 run without any non-empty cache misses
  63 #define gColorCacheSize 1024
  64 struct _ColorCacheInfo
  65 {
  66     UInt32        keys[gColorCacheSize];
  67     CGColorRef    values[gColorCacheSize];
  68 };
  69 static struct _ColorCacheInfo colorCacheInfo;
  70 
  71 static pthread_mutex_t gColorCacheLock = PTHREAD_MUTEX_INITIALIZER;


 897     {
 898         // rdar://problem/5214320
 899         // Gradient fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
 900         // Notice the side effect of the stmt after this if-block.
 901         if (renderType == SD_EOFill) {
 902             qsdo->isEvenOddFill = YES;
 903         }
 904 
 905         renderType = SetUpPaint(env, qsdo, renderType);
 906     }
 907 
 908     qsdo->renderType = renderType;
 909 }
 910 
 911 void setupGradient(JNIEnv *env, QuartzSDOps* qsdo, jfloat* javaFloatGraphicsStates)
 912 {
 913     static const CGFloat kColorConversionMultiplier = 1.0f/255.0f;
 914     qsdo->gradientInfo = (StateGradientInfo*)malloc(sizeof(StateGradientInfo));
 915     if (qsdo->gradientInfo == NULL)
 916     {
 917         [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for gradient paint"];
 918     }
 919 
 920     qsdo->graphicsStateInfo.simpleStroke = NO;
 921     qsdo->graphicsStateInfo.simpleColor = NO;
 922 
 923     qsdo->gradientInfo->start.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx1Index];
 924     qsdo->gradientInfo->start.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory1Index];
 925     qsdo->gradientInfo->end.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx2Index];
 926     qsdo->gradientInfo->end.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory2Index];
 927 
 928     jobject colorArray  = ((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kColorArrayIndex));
 929     if (colorArray != NULL)
 930     {
 931         jint length = (*env)->GetArrayLength(env, colorArray);
 932 
 933         jint* jcolorData = (jint*)(*env)->GetPrimitiveArrayCritical(env, colorArray, NULL);
 934         qsdo->gradientInfo->colordata = (CGFloat*)malloc(sizeof(CGFloat)*4*length);
 935         memset(qsdo->gradientInfo->colordata, 0, sizeof(CGFloat)*4*length);
 936         if (jcolorData != NULL)
 937         {


 998         case sun_java2d_OSXSurfaceData_kColorSystem:
 999         {
1000             qsdo->graphicsStateInfo.simpleStroke = NO;
1001             // All our custom Colors are NSPatternColorSpace so we are complex colors!
1002             qsdo->graphicsStateInfo.simpleColor = NO;
1003 
1004             NSColor *color = nil;
1005             /* TODO:BG
1006             {
1007                 color = getColor(javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorIndexValueIndex]);
1008             }
1009             */
1010             [color set];
1011             break;
1012         }
1013         case sun_java2d_OSXSurfaceData_kColorGradient:
1014         {
1015             qsdo->shadingInfo = (StateShadingInfo*)malloc(sizeof(StateShadingInfo));
1016             if (qsdo->shadingInfo == NULL)
1017             {
1018                 [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for gradient paint"];
1019             }
1020 
1021             qsdo->graphicsStateInfo.simpleStroke = NO;
1022             qsdo->graphicsStateInfo.simpleColor = NO;
1023 
1024             renderType = SD_Shade;
1025 
1026             qsdo->shadingInfo->start.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx1Index];
1027             qsdo->shadingInfo->start.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory1Index];
1028             qsdo->shadingInfo->end.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx2Index];
1029             qsdo->shadingInfo->end.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory2Index];
1030             jint c1 = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValue1Index];
1031             qsdo->shadingInfo->colors[0] = ((c1>>16)&0xff)*kColorConversionMultiplier;
1032             qsdo->shadingInfo->colors[1] = ((c1>>8)&0xff)*kColorConversionMultiplier;
1033             qsdo->shadingInfo->colors[2] = ((c1>>0)&0xff)*kColorConversionMultiplier;
1034             qsdo->shadingInfo->colors[3] = ((c1>>24)&0xff)*kColorConversionMultiplier;
1035             jint c2 = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValue2Index];
1036             qsdo->shadingInfo->colors[4] = ((c2>>16)&0xff)*kColorConversionMultiplier;
1037             qsdo->shadingInfo->colors[5] = ((c2>>8)&0xff)*kColorConversionMultiplier;
1038             qsdo->shadingInfo->colors[6] = ((c2>>0)&0xff)*kColorConversionMultiplier;


1044         case sun_java2d_OSXSurfaceData_kColorLinearGradient:
1045         {
1046             renderType = SD_LinearGradient;
1047             setupGradient(env, qsdo, javaFloatGraphicsStates);
1048             break;
1049         }
1050 
1051         case sun_java2d_OSXSurfaceData_kColorRadialGradient:
1052         {
1053             renderType = SD_RadialGradient;
1054             setupGradient(env, qsdo, javaFloatGraphicsStates);
1055             qsdo->gradientInfo->radius = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kRadiusIndex];
1056             break;
1057         }
1058 
1059         case sun_java2d_OSXSurfaceData_kColorTexture:
1060         {
1061             qsdo->patternInfo = (StatePatternInfo*)malloc(sizeof(StatePatternInfo));
1062             if (qsdo->patternInfo == NULL)
1063             {
1064                 [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for texture paint"];
1065             }
1066 
1067             qsdo->graphicsStateInfo.simpleStroke = NO;
1068             qsdo->graphicsStateInfo.simpleColor = NO;
1069 
1070             renderType = SD_Pattern;
1071 
1072             qsdo->patternInfo->tx        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColortxIndex];
1073             qsdo->patternInfo->ty        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColortyIndex];
1074             qsdo->patternInfo->sx        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorsxIndex];
1075             if (qsdo->patternInfo->sx == 0.0f)
1076             {
1077                 return SD_Fill; // 0 is an invalid value, fill argb rect
1078             }
1079             qsdo->patternInfo->sy        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorsyIndex];
1080             if (qsdo->patternInfo->sy == 0.0f)
1081             {
1082                 return SD_Fill; // 0 is an invalid value, fill argb rect
1083             }
1084             qsdo->patternInfo->width    = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorWidthIndex];




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #import "QuartzSurfaceData.h"
  27 
  28 #import "java_awt_BasicStroke.h"
  29 #import "java_awt_AlphaComposite.h"
  30 #import "java_awt_geom_PathIterator.h"
  31 #import "java_awt_image_BufferedImage.h"
  32 #import "sun_awt_SunHints.h"
  33 #import "sun_java2d_CRenderer.h"
  34 #import "sun_java2d_OSXSurfaceData.h"
  35 #import "sun_lwawt_macosx_CPrinterSurfaceData.h"
  36 #import "ImageSurfaceData.h"
  37 


  38 #import <AppKit/AppKit.h>
  39 #import "ThreadUtilities.h"
  40 
  41 //#define DEBUG
  42 #if defined DEBUG
  43     #define PRINT(msg) {fprintf(stderr, "%s\n", msg);}
  44 #else
  45     #define PRINT(msg) {}
  46 #endif
  47 
  48 #define kOffset (0.5f)
  49 
  50 #define JNI_COCOA_THROW_OOME(env, msg) \
  51     if ([NSThread isMainThread] == NO) { \
  52          JNU_ThrowOutOfMemoryError(env, msg); \
  53     } \
  54     [NSException raise:@"Java Exception" reason:@"Java OutOfMemoryException" userInfo:nil]
  55 
  56 BOOL gAdjustForJavaDrawing;
  57 
  58 #pragma mark
  59 #pragma mark --- Color Cache ---
  60 
  61 // Creating and deleting CGColorRefs can be expensive, therefore we have a color cache.
  62 // The color cache was first introduced with <rdar://problem/3923927>
  63 // With <rdar://problem/4280514>, the hashing function was improved
  64 // With <rdar://problem/4012223>, the color cache became global (per process) instead of per surface.
  65 
  66 // Must be power of 2. 1024 is the least power of 2 number that makes SwingSet2 run without any non-empty cache misses
  67 #define gColorCacheSize 1024
  68 struct _ColorCacheInfo
  69 {
  70     UInt32        keys[gColorCacheSize];
  71     CGColorRef    values[gColorCacheSize];
  72 };
  73 static struct _ColorCacheInfo colorCacheInfo;
  74 
  75 static pthread_mutex_t gColorCacheLock = PTHREAD_MUTEX_INITIALIZER;


 901     {
 902         // rdar://problem/5214320
 903         // Gradient fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
 904         // Notice the side effect of the stmt after this if-block.
 905         if (renderType == SD_EOFill) {
 906             qsdo->isEvenOddFill = YES;
 907         }
 908 
 909         renderType = SetUpPaint(env, qsdo, renderType);
 910     }
 911 
 912     qsdo->renderType = renderType;
 913 }
 914 
 915 void setupGradient(JNIEnv *env, QuartzSDOps* qsdo, jfloat* javaFloatGraphicsStates)
 916 {
 917     static const CGFloat kColorConversionMultiplier = 1.0f/255.0f;
 918     qsdo->gradientInfo = (StateGradientInfo*)malloc(sizeof(StateGradientInfo));
 919     if (qsdo->gradientInfo == NULL)
 920     {
 921         JNI_COCOA_THROW_OOME(env, "Failed to malloc memory for gradient paint");
 922     }
 923 
 924     qsdo->graphicsStateInfo.simpleStroke = NO;
 925     qsdo->graphicsStateInfo.simpleColor = NO;
 926 
 927     qsdo->gradientInfo->start.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx1Index];
 928     qsdo->gradientInfo->start.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory1Index];
 929     qsdo->gradientInfo->end.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx2Index];
 930     qsdo->gradientInfo->end.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory2Index];
 931 
 932     jobject colorArray  = ((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kColorArrayIndex));
 933     if (colorArray != NULL)
 934     {
 935         jint length = (*env)->GetArrayLength(env, colorArray);
 936 
 937         jint* jcolorData = (jint*)(*env)->GetPrimitiveArrayCritical(env, colorArray, NULL);
 938         qsdo->gradientInfo->colordata = (CGFloat*)malloc(sizeof(CGFloat)*4*length);
 939         memset(qsdo->gradientInfo->colordata, 0, sizeof(CGFloat)*4*length);
 940         if (jcolorData != NULL)
 941         {


1002         case sun_java2d_OSXSurfaceData_kColorSystem:
1003         {
1004             qsdo->graphicsStateInfo.simpleStroke = NO;
1005             // All our custom Colors are NSPatternColorSpace so we are complex colors!
1006             qsdo->graphicsStateInfo.simpleColor = NO;
1007 
1008             NSColor *color = nil;
1009             /* TODO:BG
1010             {
1011                 color = getColor(javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorIndexValueIndex]);
1012             }
1013             */
1014             [color set];
1015             break;
1016         }
1017         case sun_java2d_OSXSurfaceData_kColorGradient:
1018         {
1019             qsdo->shadingInfo = (StateShadingInfo*)malloc(sizeof(StateShadingInfo));
1020             if (qsdo->shadingInfo == NULL)
1021             {
1022                 JNI_COCOA_THROW_OOME(env, "Failed to malloc memory for gradient paint");
1023             }
1024 
1025             qsdo->graphicsStateInfo.simpleStroke = NO;
1026             qsdo->graphicsStateInfo.simpleColor = NO;
1027 
1028             renderType = SD_Shade;
1029 
1030             qsdo->shadingInfo->start.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx1Index];
1031             qsdo->shadingInfo->start.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory1Index];
1032             qsdo->shadingInfo->end.x    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorx2Index];
1033             qsdo->shadingInfo->end.y    = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColory2Index];
1034             jint c1 = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValue1Index];
1035             qsdo->shadingInfo->colors[0] = ((c1>>16)&0xff)*kColorConversionMultiplier;
1036             qsdo->shadingInfo->colors[1] = ((c1>>8)&0xff)*kColorConversionMultiplier;
1037             qsdo->shadingInfo->colors[2] = ((c1>>0)&0xff)*kColorConversionMultiplier;
1038             qsdo->shadingInfo->colors[3] = ((c1>>24)&0xff)*kColorConversionMultiplier;
1039             jint c2 = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorRGBValue2Index];
1040             qsdo->shadingInfo->colors[4] = ((c2>>16)&0xff)*kColorConversionMultiplier;
1041             qsdo->shadingInfo->colors[5] = ((c2>>8)&0xff)*kColorConversionMultiplier;
1042             qsdo->shadingInfo->colors[6] = ((c2>>0)&0xff)*kColorConversionMultiplier;


1048         case sun_java2d_OSXSurfaceData_kColorLinearGradient:
1049         {
1050             renderType = SD_LinearGradient;
1051             setupGradient(env, qsdo, javaFloatGraphicsStates);
1052             break;
1053         }
1054 
1055         case sun_java2d_OSXSurfaceData_kColorRadialGradient:
1056         {
1057             renderType = SD_RadialGradient;
1058             setupGradient(env, qsdo, javaFloatGraphicsStates);
1059             qsdo->gradientInfo->radius = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kRadiusIndex];
1060             break;
1061         }
1062 
1063         case sun_java2d_OSXSurfaceData_kColorTexture:
1064         {
1065             qsdo->patternInfo = (StatePatternInfo*)malloc(sizeof(StatePatternInfo));
1066             if (qsdo->patternInfo == NULL)
1067             {
1068                 JNI_COCOA_THROW_OOME(env, "Failed to malloc memory for texture paint");
1069             }
1070 
1071             qsdo->graphicsStateInfo.simpleStroke = NO;
1072             qsdo->graphicsStateInfo.simpleColor = NO;
1073 
1074             renderType = SD_Pattern;
1075 
1076             qsdo->patternInfo->tx        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColortxIndex];
1077             qsdo->patternInfo->ty        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColortyIndex];
1078             qsdo->patternInfo->sx        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorsxIndex];
1079             if (qsdo->patternInfo->sx == 0.0f)
1080             {
1081                 return SD_Fill; // 0 is an invalid value, fill argb rect
1082             }
1083             qsdo->patternInfo->sy        = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kColorsyIndex];
1084             if (qsdo->patternInfo->sy == 0.0f)
1085             {
1086                 return SD_Fill; // 0 is an invalid value, fill argb rect
1087             }
1088             qsdo->patternInfo->width    = javaGraphicsStates[sun_java2d_OSXSurfaceData_kColorWidthIndex];


< prev index next >