1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 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 "SurfaceData.h" 27 #import "BufImgSurfaceData.h" 28 #import "AWTFont.h" 29 #import <Cocoa/Cocoa.h> 30 31 // these flags are not defined on Tiger on PPC, so we need to make them a no-op 32 #if !defined(kCGBitmapByteOrder32Host) 33 #define kCGBitmapByteOrder32Host 0 34 #endif 35 #if !defined(kCGBitmapByteOrder16Host) 36 #define kCGBitmapByteOrder16Host 0 37 #endif 38 39 // NOTE : Modify the printSurfaceDataDiagnostics API if you change this enum 40 enum SDRenderType 41 { 42 SD_Nothing, 43 SD_Stroke, 44 SD_Fill, 45 SD_EOFill, 46 SD_Shade, 47 SD_LinearGradient, 48 SD_RadialGradient, 49 SD_Pattern, 50 SD_Image, 51 SD_Text, 52 SD_CopyArea, 53 SD_Queue, 54 SD_External 55 }; 56 typedef enum SDRenderType SDRenderType; 57 58 struct _stateShadingInfo 59 { 60 CGPoint start; 61 CGPoint end; 62 CGFloat colors[8]; 63 BOOL cyclic; 64 CGFloat length; // of the total segment (used by the cyclic gradient) 65 CGFloat period; // of the cycle (used by the cyclic gradient) 66 CGFloat offset; // of the cycle from the start (used by the cyclic gradient) 67 }; 68 typedef struct _stateShadingInfo StateShadingInfo; 69 70 struct _stateGradientInfo 71 { 72 CGPoint start; 73 CGPoint end; 74 CGFloat radius; 75 CGFloat* colordata; 76 CGFloat* fractionsdata; 77 jint fractionsLength; 78 }; 79 typedef struct _stateGradientInfo StateGradientInfo; 80 81 struct _statePatternInfo 82 { 83 CGFloat tx; 84 CGFloat ty; 85 CGFloat sx; 86 CGFloat sy; 87 jint width; 88 jint height; 89 jobject sdata; 90 }; 91 typedef struct _statePatternInfo StatePatternInfo; 92 93 struct _stateGraphicsInfo 94 { 95 BOOL adjustedLineWidth; 96 BOOL adjustedAntialias; 97 BOOL antialiased; 98 jint interpolation; 99 BOOL simpleColor; 100 BOOL simpleStroke; 101 CGAffineTransform ctm; 102 CGFloat offsetX; 103 CGFloat offsetY; 104 struct CGPoint* batchedLines; 105 UInt32 batchedLinesCount; 106 }; 107 typedef struct _stateGraphicsInfo StateGraphicsInfo; 108 109 typedef struct _QuartzSDOps QuartzSDOps; 110 typedef void BeginContextFunc(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType); 111 typedef void FinishContextFunc(JNIEnv *env, QuartzSDOps *qsdo); 112 struct _QuartzSDOps 113 { 114 BufImgSDOps sdo; // must be the first entry! 115 116 BeginContextFunc* BeginSurface; // used to set graphics states (clip, color, stroke, etc...) 117 FinishContextFunc* FinishSurface; // used to finish drawing primitives 118 BOOL newContext; 119 CGContextRef cgRef; 120 121 jint* javaGraphicsStates; 122 jobject javaGraphicsStatesObjects; 123 124 SDRenderType renderType; 125 126 // rdar://problem/5214320 127 // Gradient/Texture fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline). 128 BOOL isEvenOddFill; // Tracks whether the original render type passed into 129 // SetUpCGContext(...) is SD_EOFILL. 130 // The reason for this field is because SetUpCGContext(...) can 131 // change the render type after calling SetUpPaint(...), and right 132 // after that, the possibly new render type is then assigned into 133 // qsdo->renderType. Sigh!!! 134 // This field is potentially used within CompleteCGContext(...) or 135 // its callees. 136 137 StateShadingInfo* shadingInfo; // tracks shading and its parameters 138 StateGradientInfo* gradientInfo; // tracks gradient and its parameters 139 StatePatternInfo* patternInfo; // tracks pattern and its parameters 140 StateGraphicsInfo graphicsStateInfo; // tracks other graphics state 141 142 BOOL syncContentsToLayer; // should changed pixels be synced to a CALayer 143 CGRect updateRect; // used by the layer synchronization code to track update rects. 144 }; 145 146 void SetUpCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType); 147 SDRenderType DoShapeUsingCG(CGContextRef cgRef, jint *types, jfloat *coords, jint numtypes, BOOL fill, CGFloat offsetX, CGFloat offsetY); 148 SDRenderType SetUpPaint(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType); 149 void CompleteCGContext(JNIEnv *env, QuartzSDOps *qsdo); 150 151 NSColor* ByteParametersToNSColor(JNIEnv* env, jint *javaGraphicsStates, NSColor* defColor); 152 153 #define JNF_COCOA_RENDERER_EXIT(env) \ 154 } @catch(NSException *localException) { \ 155 qsdo->FinishSurface(env, qsdo); \ 156 [JNFException throwToJava:env exception:localException]; \ 157 } \ 158 if (_token) JNFNativeMethodExit(_token); \ 159 }