From dc071052184ccb1e07e2ae8217661f6b1eda84ce Mon Sep 17 00:00:00 2001 From: skovatch Date: Wed, 5 Sep 2012 09:34:19 -0700 Subject: [PATCH] 7187834: [macosx] Usage of private API in macosx 2D implementation causes Apple Store rejection Reviewed-by: prr, igor --- src/macosx/native/sun/awt/ImageSurfaceData.h | 10 ++++------ src/macosx/native/sun/awt/ImageSurfaceData.m | 10 ++++------ src/macosx/native/sun/awt/QuartzRenderer.m | 7 ++----- src/macosx/native/sun/awt/QuartzSurfaceData.m | 9 ++------- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/macosx/native/sun/awt/ImageSurfaceData.h b/src/macosx/native/sun/awt/ImageSurfaceData.h index 0e4d306f2..970940288 100644 --- a/src/macosx/native/sun/awt/ImageSurfaceData.h +++ b/src/macosx/native/sun/awt/ImageSurfaceData.h @@ -41,7 +41,7 @@ void UnlockImagePixels(JNIEnv* env, ImageSDOps* isdo); // If there is an image present, this is a no-op void makeSureImageIsCreated(ImageSDOps* isdo); -struct _ContextInfo +typedef struct _ContextInfo { BOOL useWindowContextReference; BOOL canUseJavaPixelsAsContext; @@ -50,10 +50,9 @@ struct _ContextInfo size_t bytesPerRow; CGImageAlphaInfo alphaInfo; CGColorSpaceRef colorSpace; -} -typedef ContextInfo; +} ContextInfo; -struct _ImageInfo +typedef struct _ImageInfo { size_t bitsPerComponent; size_t bitsPerPixel; @@ -61,8 +60,7 @@ struct _ImageInfo size_t bytesPerRow; CGImageAlphaInfo alphaInfo; CGColorSpaceRef colorSpace; -} -typedef ImageInfo; +} ImageInfo; struct _ImageSDOps { diff --git a/src/macosx/native/sun/awt/ImageSurfaceData.m b/src/macosx/native/sun/awt/ImageSurfaceData.m index f2ebd2843..af7ce4ba3 100644 --- a/src/macosx/native/sun/awt/ImageSurfaceData.m +++ b/src/macosx/native/sun/awt/ImageSurfaceData.m @@ -53,10 +53,6 @@ // for vImage framework headers #include - -// private Quartz routines needed here -CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx); - static ContextInfo sDefaultContextInfo[sun_java2d_OSXOffScreenSurfaceData_TYPE_3BYTE_RGB+1] = { {YES, YES, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_CUSTOM // special case @@ -942,7 +938,6 @@ PRINT("createContext") // intitalize the context to match the Java coordinate system // BG, since the context is created above, we can just concat - //CGContextSetCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height)); CGContextConcatCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, -1, 0, isdo->height)); CGContextSaveGState(qsdo->cgRef); // this will make sure we don't go pass device context settings @@ -1114,7 +1109,10 @@ PRINT("syncFromJavaPixels") if (qsdo->cgRef != NULL) { CGContextSaveGState(qsdo->cgRef); - CGContextSetCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, 1, 0, 0)); + CGAffineTransform currCTM = CGContextGetCTM(qsdo->cgRef); + CGAffineTransform inverse = CGAffineTransformInvert(currCTM); + CGContextConcatCTM(qsdo->cgRef, inverse); + CGContextConcatCTM(qsdo->cgRef, CGAffineTransformMake(1, 0, 0, 1, 0, 0)); CGContextSetBlendMode(qsdo->cgRef, kCGBlendModeCopy); CGContextSetAlpha(qsdo->cgRef, 1.0f); CGContextDrawImage(qsdo->cgRef, CGRectMake(0, 0, width, height), javaImg); diff --git a/src/macosx/native/sun/awt/QuartzRenderer.m b/src/macosx/native/sun/awt/QuartzRenderer.m index e5784f691..755090409 100644 --- a/src/macosx/native/sun/awt/QuartzRenderer.m +++ b/src/macosx/native/sun/awt/QuartzRenderer.m @@ -50,9 +50,6 @@ // same value as defined in Sun's own code #define XOR_ALPHA_CUTOFF 128 -// private Quartz routines needed here -CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx); - static CGFloat gRoundRectCtrlpts[10][12] = { @@ -536,7 +533,7 @@ QUARTZ_RENDERER_INLINE void doImageCG(JNIEnv *env, CGContextRef cgRef, jobject i makeSureImageIsCreated(isdo); - CGAffineTransform ctm = CGContextGetCTM(cgRef); + CGContextSaveGState(cgRef); CGContextConcatCTM(cgRef, CGAffineTransformMake(a, b, c, d, tx, ty)); jint alphaInfo = isdo->contextInfo.alphaInfo & kCGBitmapAlphaInfoMask; @@ -551,7 +548,7 @@ QUARTZ_RENDERER_INLINE void doImageCG(JNIEnv *env, CGContextRef cgRef, jobject i CGImageRelease(subImg); } - CGContextSetCTM(cgRef, ctm); + CGContextRestoreGState(cgRef); UnlockImage(env, isdo); } diff --git a/src/macosx/native/sun/awt/QuartzSurfaceData.m b/src/macosx/native/sun/awt/QuartzSurfaceData.m index 8d3784cf2..3a0eea126 100644 --- a/src/macosx/native/sun/awt/QuartzSurfaceData.m +++ b/src/macosx/native/sun/awt/QuartzSurfaceData.m @@ -40,9 +40,6 @@ #import #import "ThreadUtilities.h" -// private Quartz routines needed here -CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx); - //#define DEBUG #if defined DEBUG #define PRINT(msg) {fprintf(stderr, "%s\n", msg);} @@ -50,9 +47,6 @@ CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx); #define PRINT(msg) {} #endif -// from CGAffineTransformPrivate.h -extern CGPoint CGPointApplyInverseAffineTransform(CGPoint point, CGAffineTransform t); - #define kOffset (0.5f) BOOL gAdjustForJavaDrawing; @@ -608,7 +602,8 @@ PRINT(" SetUpCGContext") // We need to flip both y coefficeints to flip the offset point into the java coordinate system. ctm.b = -ctm.b; ctm.d = -ctm.d; ctm.tx = 0.0f; ctm.ty = 0.0f; CGPoint offsets = {kOffset, kOffset}; - offsets = CGPointApplyInverseAffineTransform(offsets, ctm); + CGAffineTransform inverse = CGAffineTransformInvert(ctm); + offsets = CGPointApplyAffineTransform(offsets, inverse); qsdo->graphicsStateInfo.offsetX = offsets.x; qsdo->graphicsStateInfo.offsetY = offsets.y; } -- GitLab