src/macosx/native/sun/awt/ImageSurfaceData.m

Print this page




  36 #import "BufImgSurfaceData.h"
  37 #import "ThreadUtilities.h"
  38 
  39 
  40 
  41 //#define DEBUG 1
  42 #if defined DEBUG
  43     #define IMAGE_SURFACE_INLINE
  44     #define PRINT(msg) {fprintf(stderr, "%s\n", msg);fflush(stderr);}
  45 #else
  46     #define IMAGE_SURFACE_INLINE static inline
  47     #define PRINT(msg) {}
  48 #endif
  49 
  50 // same value as defined in Sun's own code
  51 #define XOR_ALPHA_CUTOFF 128
  52 
  53 // for vImage framework headers
  54 #include <Accelerate/Accelerate.h>
  55 
  56 
  57 // private Quartz routines needed here
  58 CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx);
  59 
  60 static ContextInfo sDefaultContextInfo[sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB+1] =
  61 {
  62     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_CUSTOM            // special case
  63     {YES,    YES,    8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_RGB
  64     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB
  65     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB_PRE
  66     {YES,    YES,    8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_BGR
  67     {YES,    NO,        8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_3BYTE_BGR        // use the default ARGB_PRE context synce we have to sync by hand anyway
  68     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR
  69     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR_PRE
  70 #ifdef __LITTLE_ENDIAN__
  71     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_565_RGB
  72     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_555_RGB
  73 #else
  74     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_565_RGB
  75     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_555_RGB
  76 #endif
  77     {YES,    YES,    8,        1,        0,        kCGImageAlphaNone,                                            NULL},    // TYPE_BYTE_GRAY
  78     {YES,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_USHORT_GRAY        // use the default ARGB_PRE context synce we have to sync by hand anyway
  79     {NO,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_BYTE_BINARY        mapped to TYPE_CUSTOM


 925         if (isdo->nativePixels == NULL)
 926         {
 927             fprintf(stderr, "malloc failed for size %d bytes in ImageSurfaceData.createContext()\n", (int) size);
 928         }
 929 
 930 //fprintf(stderr, "isdo=%p isdo->type=%d, bitsPerComponent=%d, bytesPerRow=%d, colorSpace=%p, alphaInfo=%d, width=%d, height=%d, size=%d\n", isdo, type, (jint)bitsPerComponent, (jint)bytesPerRow, colorSpace, (jint)alphaInfo, (jint) isdo->width, (jint) isdo->height, (jint) size);
 931 
 932         qsdo->cgRef = CGBitmapContextCreate(isdo->nativePixels, isdo->width, isdo->height, bitsPerComponent, bytesPerRow, colorSpace, alphaInfo);
 933         isdo->dataProvider = CGDataProviderCreateWithData(NULL, isdo->nativePixels, size, releaseDataFromProvider);
 934     }
 935 
 936 //fprintf(stderr, "cgRef=%p\n", qsdo->cgRef);
 937     if (qsdo->cgRef == NULL)
 938     {
 939         fprintf(stderr, "ERROR: (qsdo->cgRef == NULL) in createContext!\n");
 940     }
 941 
 942     // intitalize the context to match the Java coordinate system
 943 
 944     // BG, since the context is created above, we can just concat
 945     //CGContextSetCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height));
 946     CGContextConcatCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height));
 947 
 948     CGContextSaveGState(qsdo->cgRef); // this will make sure we don't go pass device context settings
 949     CGContextSaveGState(qsdo->cgRef); // this will put user settings on top, used by LazyStateManagement code
 950     qsdo->newContext = YES;
 951 }
 952 
 953 IMAGE_SURFACE_INLINE void holdJavaPixels(JNIEnv* env, ImageSDOps* isdo)
 954 {
 955 PRINT("holdJavaPixels")
 956 
 957     if (isdo->type != java_awt_image_BufferedImage_TYPE_CUSTOM)
 958     {
 959         Pixel8bit* pixels = NULL;
 960         if (isdo->nrOfPixelsOwners == 0)
 961         {
 962             pixels = (Pixel8bit*)((*env)->GetPrimitiveArrayCritical(env, isdo->array, NULL));
 963             if (pixels != NULL)
 964             {
 965                 isdo->pixelsLocked = pixels;


1097             CGDataProviderRelease(provider);
1098 
1099             if (javaImg != NULL)
1100             {
1101                 QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
1102 
1103                 if (isdo->imgRef != NULL)
1104                 {
1105                     CGImageRelease(isdo->imgRef);
1106                     isdo->imgRef = NULL;
1107                 }
1108 
1109                 if (qsdo->cgRef == NULL)
1110                 {
1111                     createContext(env, isdo);
1112                 }
1113 
1114                 if (qsdo->cgRef != NULL)
1115                 {
1116                     CGContextSaveGState(qsdo->cgRef);
1117                     CGContextSetCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, 1, 0, 0));
1118                     CGContextSetBlendMode(qsdo->cgRef, kCGBlendModeCopy);
1119                     CGContextSetAlpha(qsdo->cgRef, 1.0f);
1120                     CGContextDrawImage(qsdo->cgRef, CGRectMake(0, 0, width, height), javaImg);
1121                     CGContextFlush(qsdo->cgRef);
1122                     CGContextRestoreGState(qsdo->cgRef);
1123                     CGImageRelease(javaImg);
1124                 }
1125                 else
1126                 {
1127                     fprintf(stderr, "ERROR: (cgRef == NULL) in syncFromJavaPixels!\n");
1128                 }
1129             }
1130             else
1131             {
1132 //fprintf(stderr, "isdo->type=%d, isdo->width=%d, isdo->height=%d, isdo->imageInfo.bitsPerComponent=%d, isdo->imageInfo.bytesPerPixel=%d, isdo->imageInfo.bitsPerPixel=%d, isdo->imageInfo.bytesPerRow=%d, isdo->imageInfo.colorSpace=%p, isdo->imageInfo.alphaInfo=%d\n",
1133 //(jint)isdo->type, (jint)isdo->width, (jint)isdo->height, (jint)isdo->imageInfo.bitsPerComponent, (jint)isdo->imageInfo.bytesPerPixel, (jint)isdo->imageInfo.bitsPerPixel, (jint)isdo->imageInfo.bytesPerRow, isdo->imageInfo.colorSpace, (jint)isdo->imageInfo.alphaInfo);
1134                 fprintf(stderr, "ERROR: (javaImg == NULL) in syncFromJavaPixels!\n");
1135             }
1136         }
1137 




  36 #import "BufImgSurfaceData.h"
  37 #import "ThreadUtilities.h"
  38 
  39 
  40 
  41 //#define DEBUG 1
  42 #if defined DEBUG
  43     #define IMAGE_SURFACE_INLINE
  44     #define PRINT(msg) {fprintf(stderr, "%s\n", msg);fflush(stderr);}
  45 #else
  46     #define IMAGE_SURFACE_INLINE static inline
  47     #define PRINT(msg) {}
  48 #endif
  49 
  50 // same value as defined in Sun's own code
  51 #define XOR_ALPHA_CUTOFF 128
  52 
  53 // for vImage framework headers
  54 #include <Accelerate/Accelerate.h>
  55 




  56 static ContextInfo sDefaultContextInfo[sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB+1] =
  57 {
  58     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_CUSTOM            // special case
  59     {YES,    YES,    8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_RGB
  60     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB
  61     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_INT_ARGB_PRE
  62     {YES,    YES,    8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_INT_BGR
  63     {YES,    NO,        8,        4,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host,        NULL},    // TYPE_3BYTE_BGR        // use the default ARGB_PRE context synce we have to sync by hand anyway
  64     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR
  65     {YES,    YES,    8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_4BYTE_ABGR_PRE
  66 #ifdef __LITTLE_ENDIAN__
  67     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_565_RGB
  68     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host,        NULL},    // TYPE_USHORT_555_RGB
  69 #else
  70     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_565_RGB
  71     {YES,    YES,    5,        2,        0,        kCGImageAlphaNoneSkipFirst,                                    NULL},    // TYPE_USHORT_555_RGB
  72 #endif
  73     {YES,    YES,    8,        1,        0,        kCGImageAlphaNone,                                            NULL},    // TYPE_BYTE_GRAY
  74     {YES,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_USHORT_GRAY        // use the default ARGB_PRE context synce we have to sync by hand anyway
  75     {NO,    NO,        8,        4,        0,        kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,    NULL},    // TYPE_BYTE_BINARY        mapped to TYPE_CUSTOM


 921         if (isdo->nativePixels == NULL)
 922         {
 923             fprintf(stderr, "malloc failed for size %d bytes in ImageSurfaceData.createContext()\n", (int) size);
 924         }
 925 
 926 //fprintf(stderr, "isdo=%p isdo->type=%d, bitsPerComponent=%d, bytesPerRow=%d, colorSpace=%p, alphaInfo=%d, width=%d, height=%d, size=%d\n", isdo, type, (jint)bitsPerComponent, (jint)bytesPerRow, colorSpace, (jint)alphaInfo, (jint) isdo->width, (jint) isdo->height, (jint) size);
 927 
 928         qsdo->cgRef = CGBitmapContextCreate(isdo->nativePixels, isdo->width, isdo->height, bitsPerComponent, bytesPerRow, colorSpace, alphaInfo);
 929         isdo->dataProvider = CGDataProviderCreateWithData(NULL, isdo->nativePixels, size, releaseDataFromProvider);
 930     }
 931 
 932 //fprintf(stderr, "cgRef=%p\n", qsdo->cgRef);
 933     if (qsdo->cgRef == NULL)
 934     {
 935         fprintf(stderr, "ERROR: (qsdo->cgRef == NULL) in createContext!\n");
 936     }
 937 
 938     // intitalize the context to match the Java coordinate system
 939 
 940     // BG, since the context is created above, we can just concat

 941     CGContextConcatCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height));
 942 
 943     CGContextSaveGState(qsdo->cgRef); // this will make sure we don't go pass device context settings
 944     CGContextSaveGState(qsdo->cgRef); // this will put user settings on top, used by LazyStateManagement code
 945     qsdo->newContext = YES;
 946 }
 947 
 948 IMAGE_SURFACE_INLINE void holdJavaPixels(JNIEnv* env, ImageSDOps* isdo)
 949 {
 950 PRINT("holdJavaPixels")
 951 
 952     if (isdo->type != java_awt_image_BufferedImage_TYPE_CUSTOM)
 953     {
 954         Pixel8bit* pixels = NULL;
 955         if (isdo->nrOfPixelsOwners == 0)
 956         {
 957             pixels = (Pixel8bit*)((*env)->GetPrimitiveArrayCritical(env, isdo->array, NULL));
 958             if (pixels != NULL)
 959             {
 960                 isdo->pixelsLocked = pixels;


1092             CGDataProviderRelease(provider);
1093 
1094             if (javaImg != NULL)
1095             {
1096                 QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
1097 
1098                 if (isdo->imgRef != NULL)
1099                 {
1100                     CGImageRelease(isdo->imgRef);
1101                     isdo->imgRef = NULL;
1102                 }
1103 
1104                 if (qsdo->cgRef == NULL)
1105                 {
1106                     createContext(env, isdo);
1107                 }
1108 
1109                 if (qsdo->cgRef != NULL)
1110                 {
1111                     CGContextSaveGState(qsdo->cgRef);
1112                     CGContextConcatCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, 1, 0, 0));
1113                     CGContextSetBlendMode(qsdo->cgRef, kCGBlendModeCopy);
1114                     CGContextSetAlpha(qsdo->cgRef, 1.0f);
1115                     CGContextDrawImage(qsdo->cgRef, CGRectMake(0, 0, width, height), javaImg);
1116                     CGContextFlush(qsdo->cgRef);
1117                     CGContextRestoreGState(qsdo->cgRef);
1118                     CGImageRelease(javaImg);
1119                 }
1120                 else
1121                 {
1122                     fprintf(stderr, "ERROR: (cgRef == NULL) in syncFromJavaPixels!\n");
1123                 }
1124             }
1125             else
1126             {
1127 //fprintf(stderr, "isdo->type=%d, isdo->width=%d, isdo->height=%d, isdo->imageInfo.bitsPerComponent=%d, isdo->imageInfo.bytesPerPixel=%d, isdo->imageInfo.bitsPerPixel=%d, isdo->imageInfo.bytesPerRow=%d, isdo->imageInfo.colorSpace=%p, isdo->imageInfo.alphaInfo=%d\n",
1128 //(jint)isdo->type, (jint)isdo->width, (jint)isdo->height, (jint)isdo->imageInfo.bitsPerComponent, (jint)isdo->imageInfo.bytesPerPixel, (jint)isdo->imageInfo.bitsPerPixel, (jint)isdo->imageInfo.bytesPerRow, isdo->imageInfo.colorSpace, (jint)isdo->imageInfo.alphaInfo);
1129                 fprintf(stderr, "ERROR: (javaImg == NULL) in syncFromJavaPixels!\n");
1130             }
1131         }
1132