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_Gradient,
  48     SD_Pattern,
  49     SD_Image,
  50     SD_Text,
  51     SD_CopyArea,
  52     SD_Queue,
  53     SD_External
  54 };
  55 typedef enum SDRenderType SDRenderType;
  56 
  57 struct _stateShadingInfo
  58 {
  59     CGPoint    start;
  60     CGPoint    end;
  61     CGFloat    colors[8];
  62     BOOL    cyclic;
  63     CGFloat    length; // of the total segment (used by the cyclic gradient)
  64     CGFloat    period; // of the cycle (used by the cyclic gradient)
  65     CGFloat    offset; // of the cycle from the start (used by the cyclic gradient)
  66 };
  67 typedef struct _stateShadingInfo StateShadingInfo;
  68 
  69 struct _stateGradientInfo
  70 {
  71     CGPoint    start;
  72     CGPoint    end;
  73     CGFloat* colordata;
  74     CGFloat* fractionsdata;
  75     jint     fractionsLength;
  76 };
  77 typedef struct _stateGradientInfo StateGradientInfo;
  78 
  79 struct _statePatternInfo
  80 {
  81     CGFloat    tx;
  82     CGFloat    ty;
  83     CGFloat    sx;
  84     CGFloat    sy;
  85     jint    width;
  86     jint    height;
  87     jobject    sdata;
  88 };
  89 typedef struct _statePatternInfo StatePatternInfo;
  90 
  91 struct _stateGraphicsInfo
  92 {
  93     BOOL                adjustedLineWidth;
  94     BOOL                adjustedAntialias;
  95     BOOL                antialiased;
  96     jint                interpolation;
  97     BOOL                simpleColor;
  98     BOOL                simpleStroke;
  99     CGAffineTransform    ctm;
 100     CGFloat                offsetX;
 101     CGFloat                offsetY;
 102     struct CGPoint*        batchedLines;
 103     UInt32                batchedLinesCount;
 104 };
 105 typedef struct _stateGraphicsInfo StateGraphicsInfo;
 106 
 107 typedef struct _QuartzSDOps QuartzSDOps;
 108 typedef void BeginContextFunc(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType);
 109 typedef void FinishContextFunc(JNIEnv *env, QuartzSDOps *qsdo);
 110 struct _QuartzSDOps
 111 {
 112     BufImgSDOps                sdo; // must be the first entry!
 113 
 114     BeginContextFunc*        BeginSurface;        // used to set graphics states (clip, color, stroke, etc...)
 115     FinishContextFunc*        FinishSurface;        // used to finish drawing primitives
 116     BOOL                    newContext;
 117     CGContextRef            cgRef;
 118 
 119     jint*                    javaGraphicsStates;
 120     jobject                    javaGraphicsStatesObjects;
 121 
 122     SDRenderType            renderType;
 123 
 124     // rdar://problem/5214320
 125     // Gradient/Texture fills of Java GeneralPath don't respect the even odd winding rule (quartz pipeline).
 126     BOOL                    isEvenOddFill;        // Tracks whether the original render type passed into
 127                                                 // SetUpCGContext(...) is SD_EOFILL.
 128                                                 // The reason for this field is because SetUpCGContext(...) can
 129                                                 // change the render type after calling SetUpPaint(...), and right
 130                                                 // after that, the possibly new render type is then assigned into
 131                                                 // qsdo->renderType.  Sigh!!!
 132                                                 // This field is potentially used within CompleteCGContext(...) or
 133                                                 // its callees.
 134 
 135     StateShadingInfo*        shadingInfo;        // tracks shading and its parameters
 136     StateGradientInfo*       gradientInfo;       // tracks gradient and its parameters
 137     StatePatternInfo*        patternInfo;        // tracks pattern and its parameters
 138     StateGraphicsInfo        graphicsStateInfo;    // tracks other graphics state
 139 
 140     BOOL  syncContentsToLayer;    // should changed pixels be synced to a CALayer
 141     CGRect updateRect;     // used by the layer synchronization code to track update rects.
 142 };
 143 
 144 void SetUpCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType);
 145 SDRenderType DoShapeUsingCG(CGContextRef cgRef, jint *types, jfloat *coords, jint numtypes, BOOL fill, CGFloat offsetX, CGFloat offsetY);
 146 SDRenderType SetUpPaint(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType);
 147 void CompleteCGContext(JNIEnv *env, QuartzSDOps *qsdo);
 148 
 149 NSColor* ByteParametersToNSColor(JNIEnv* env, jint *javaGraphicsStates, NSColor* defColor);
 150 
 151 #define JNF_COCOA_RENDERER_EXIT(env) \
 152 } @catch(NSException *localException) { \
 153     qsdo->FinishSurface(env, qsdo); \
 154     [JNFException throwToJava:env exception:localException]; \
 155 } \
 156         if (_token) JNFNativeMethodExit(_token); \
 157 }
--- EOF ---