Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/OSXSurfaceData.java
41152 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d;2627import java.awt.*;28import java.awt.font.*;29import java.awt.geom.*;30import java.awt.image.*;31import java.nio.*;3233import sun.awt.*;34import sun.awt.image.*;35import sun.java2d.loops.*;36import sun.java2d.pipe.*;37import sun.lwawt.macosx.*;3839import java.lang.annotation.Native;4041/*42* This is the SurfaceData for a CGContextRef.43*/44public abstract class OSXSurfaceData extends BufImgSurfaceData {45static final float UPPER_BND = Float.MAX_VALUE / 2.0f;46static final float LOWER_BND = -UPPER_BND;4748protected static CRenderer sQuartzPipe = null;49protected static CTextPipe sCocoaTextPipe = null;50protected static CompositeCRenderer sQuartzCompositePipe = null;5152private GraphicsConfiguration fConfig;53private Rectangle fBounds; // bounds in user coordinates5455static {56sQuartzPipe = new CRenderer(); // Creates the singleton quartz pipe.57}5859// NOTE: Any subclasses must eventually call QuartzSurfaceData_InitOps in OSXSurfaceData.h60// This sets up the native side for the SurfaceData, and is required.61public OSXSurfaceData(SurfaceType sType, ColorModel cm) {62this(sType, cm, null, new Rectangle());63}6465public OSXSurfaceData(SurfaceType sType, ColorModel cm, GraphicsConfiguration config, Rectangle bounds) {66super(sType, cm);6768this.fConfig = config;6970this.fBounds = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.y + bounds.height);7172this.fGraphicsStates = getBufferOfSize(kSizeOfParameters);73this.fGraphicsStatesInt = this.fGraphicsStates.asIntBuffer();74this.fGraphicsStatesFloat = this.fGraphicsStates.asFloatBuffer();75this.fGraphicsStatesLong = this.fGraphicsStates.asLongBuffer();76this.fGraphicsStatesObject = new Object[8]; // clip coordinates +77// clip types +78// texture paint image +79// stroke dash array +80// font + font paint +81// linear/radial gradient color +82// linear/radial gradient fractions8384// NOTE: All access to the DrawingQueue comes through this OSXSurfaceData instance. Therefore85// every instance method of OSXSurfaceData that accesses the fDrawingQueue is synchronized.8687// Thread.dumpStack();88}8990public void validatePipe(SunGraphics2D sg2d) {9192if (sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) {93if (sCocoaTextPipe == null) {94sCocoaTextPipe = new CTextPipe();95}9697sg2d.imagepipe = sQuartzPipe;98sg2d.drawpipe = sQuartzPipe;99sg2d.fillpipe = sQuartzPipe;100sg2d.shapepipe = sQuartzPipe;101sg2d.textpipe = sCocoaTextPipe;102} else {103setPipesToQuartzComposite(sg2d);104}105}106107protected void setPipesToQuartzComposite(SunGraphics2D sg2d) {108if (sQuartzCompositePipe == null) {109sQuartzCompositePipe = new CompositeCRenderer();110}111112if (sCocoaTextPipe == null) {113sCocoaTextPipe = new CTextPipe();114}115116sg2d.imagepipe = sQuartzCompositePipe;117sg2d.drawpipe = sQuartzCompositePipe;118sg2d.fillpipe = sQuartzCompositePipe;119sg2d.shapepipe = sQuartzCompositePipe;120sg2d.textpipe = sCocoaTextPipe;121}122123public Rectangle getBounds() {124// gznote: always return a copy, not the rect itself and translate into device space125return new Rectangle(fBounds.x, fBounds.y, fBounds.width, fBounds.height - fBounds.y);126}127128public GraphicsConfiguration getDeviceConfiguration() {129return fConfig;130}131132protected void setBounds(int x, int y, int w, int h) {133fBounds.setBounds(x, y, w, y + h);134}135136// START compositing support API137public abstract BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage image);138139public abstract boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR);140141GraphicsConfiguration sDefaultGraphicsConfiguration = null;142143protected BufferedImage getCompositingImage(int w, int h) {144if (sDefaultGraphicsConfiguration == null) {145sDefaultGraphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();146}147148BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);149// clear the image.150clearRect(img, w, h);151return img;152}153154protected BufferedImage getCompositingImageSame(BufferedImage img, int w, int h) {155if ((img == null) || (img.getWidth() != w) || (img.getHeight() != h)) {156img = getCompositingImage(w, h);157}158return img;159}160161BufferedImage sSrcComposite = null;162163public BufferedImage getCompositingSrcImage(int w, int h) {164// <rdar://problem/3720263>. Changed from getCompositingImageBiggerOrSame() to165// getCompositingImageSame(). (vm)166BufferedImage bim = getCompositingImageSame(sSrcComposite, w, h);167sSrcComposite = bim;168return bim;169}170171BufferedImage sDstInComposite = null;172173public BufferedImage getCompositingDstInImage(int w, int h) {174BufferedImage bim = getCompositingImageSame(sDstInComposite, w, h);175sDstInComposite = bim;176return bim;177}178179BufferedImage sDstOutComposite = null;180181public BufferedImage getCompositingDstOutImage(int w, int h) {182BufferedImage bim = getCompositingImageSame(sDstOutComposite, w, h);183sDstOutComposite = bim;184return bim;185}186187public void clearRect(BufferedImage bim, int w, int h) {188Graphics2D g = bim.createGraphics();189g.setComposite(AlphaComposite.Clear);190g.fillRect(0, 0, w, h);191g.dispose();192}193194// END compositing support API195196public void invalidate() {197// always valid198}199200// graphics primitives drawing implementation:201202// certain primitives don't care about all the states (ex. drawing an image needs not involve setting current paint)203@Native static final int kPrimitive = 0;204@Native static final int kImage = 1;205@Native static final int kText = 2;206@Native static final int kCopyArea = 3;207@Native static final int kExternal = 4;208209@Native static final int kLine = 5; // belongs to kPrimitive210@Native static final int kRect = 6; // belongs to kPrimitive211@Native static final int kRoundRect = 7; // belongs to kPrimitive212@Native static final int kOval = 8; // belongs to kPrimitive213@Native static final int kArc = 9; // belongs to kPrimitive214@Native static final int kPolygon = 10; // belongs to kPrimitive215@Native static final int kShape = 11; // belongs to kPrimitive216// static final int kImage = 12; // belongs to kImage217@Native static final int kString = 13; // belongs to kText218@Native static final int kGlyphs = 14; // belongs to kText219@Native static final int kUnicodes = 15; // belongs to kText220// static final int kCopyArea = 16; // belongs to kCopyArea221// static final int kExternal = 17; // belongs to kExternal222223@Native static final int kCommonParameterCount = 1 + 1 + 4 + 4; // type + change flags + color info (type(1) align(1) and224// value(2)) + parameters ((x1, y1, x2, y2) OR (x, y, w, h))225@Native static final int kLineParametersCount = kCommonParameterCount; // kCommonParameterCount226@Native static final int kRectParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill227@Native static final int kRoundRectParametersCount = kCommonParameterCount + 2 + 1; // kCommonParameterCount + arcW + arcH +228// isfill229@Native static final int kOvalParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill230@Native static final int kArcParametersCount = kCommonParameterCount + 2 + 1 + 1;// kCommonParameterCount + startAngle +231// arcAngle + isfill + type232@Native static final int kPolygonParametersCount = 0; // not supported233@Native static final int kShapeParametersCount = 0; // not supported234@Native static final int kImageParametersCount = kCommonParameterCount + 2 + 2 + 4 + 4; // flip horz vert + w&h + src + dst235@Native static final int kStringParametersCount = 0; // not supported236@Native static final int kGlyphsParametersCount = 0; // not supported237@Native static final int kUnicodesParametersCount = 0; // not supported238@Native static final int kPixelParametersCount = 0; // not supported239@Native static final int kExternalParametersCount = 0; // not supported240241// for intParameters242// states info243@Native static final int kChangeFlagIndex = 0; // kBoundsChangedBit | .. | kFontChangedBit244// bounds info245@Native static final int kBoundsXIndex = 1;246@Native static final int kBoundsYIndex = 2;247@Native static final int kBoundsWidthIndex = 3;248@Native static final int kBoundsHeightIndex = 4;249// clip info250@Native static final int kClipStateIndex = 5;251@Native static final int kClipNumTypesIndex = 6;252@Native static final int kClipNumCoordsIndex = 7;253@Native static final int kClipWindingRuleIndex = 8;254@Native static final int kClipXIndex = 9;255@Native static final int kClipYIndex = 10;256@Native static final int kClipWidthIndex = 11;257@Native static final int kClipHeightIndex = 12;258// ctm info259@Native static final int kCTMaIndex = 13;260@Native static final int kCTMbIndex = 14;261@Native static final int kCTMcIndex = 15;262@Native static final int kCTMdIndex = 16;263@Native static final int kCTMtxIndex = 17;264@Native static final int kCTMtyIndex = 18;265// color info266@Native static final int kColorStateIndex = 19; // kColorSimple or kColorGradient or kColorTexture267@Native static final int kColorRGBValueIndex = 20; // if kColorSimple268@Native static final int kColorIndexValueIndex = 21; // if kColorSystem269@Native static final int kColorPointerIndex = 22; //270@Native static final int kColorPointerIndex2 = 23; //271@Native static final int kColorRGBValue1Index = 24; // if kColorGradient272@Native static final int kColorWidthIndex = 25; // if kColorTexture273@Native static final int kColorRGBValue2Index = 26; // if kColorGradient274@Native static final int kColorHeightIndex = 27; // if kColorTexture275@Native static final int kColorIsCyclicIndex = 28; // if kColorGradient (kColorNonCyclic or kColorCyclic)276@Native static final int kColorx1Index = 29;277@Native static final int kColortxIndex = 30;278@Native static final int kColory1Index = 31;279@Native static final int kColortyIndex = 32;280@Native static final int kColorx2Index = 33;281@Native static final int kColorsxIndex = 34;282@Native static final int kColory2Index = 35;283@Native static final int kColorsyIndex = 36;284// composite info285@Native static final int kCompositeRuleIndex = 37; // kCGCompositeClear or ... or kCGCompositeXor286@Native static final int kCompositeValueIndex = 38;287// stroke info288@Native static final int kStrokeJoinIndex = 39; // see BasicStroke.java289@Native static final int kStrokeCapIndex = 40; // see BasicStroke.java290@Native static final int kStrokeWidthIndex = 41;291@Native static final int kStrokeDashPhaseIndex = 42;292@Native static final int kStrokeLimitIndex = 43;293// hints info294@Native static final int kHintsAntialiasIndex = 44;295@Native static final int kHintsTextAntialiasIndex = 45;296@Native static final int kHintsFractionalMetricsIndex = 46;297@Native static final int kHintsRenderingIndex = 47;298@Native static final int kHintsInterpolationIndex = 48;299//gradient info300@Native static final int kRadiusIndex = 49;301302@Native static final int kSizeOfParameters = kRadiusIndex + 1;303304// for objectParameters305@Native static final int kClipCoordinatesIndex = 0;306@Native static final int kClipTypesIndex = 1;307@Native static final int kTextureImageIndex = 2;308@Native static final int kStrokeDashArrayIndex = 3;309@Native static final int kFontIndex = 4;310@Native static final int kFontPaintIndex = 5;311@Native static final int kColorArrayIndex = 6;312@Native static final int kFractionsArrayIndex = 7;313314// possible state changes315@Native static final int kBoundsChangedBit = 1 << 0;316@Native static final int kBoundsNotChangedBit = ~kBoundsChangedBit;317@Native static final int kClipChangedBit = 1 << 1;318@Native static final int kClipNotChangedBit = ~kClipChangedBit;319@Native static final int kCTMChangedBit = 1 << 2;320@Native static final int kCTMNotChangedBit = ~kCTMChangedBit;321@Native static final int kColorChangedBit = 1 << 3;322@Native static final int kColorNotChangedBit = ~kColorChangedBit;323@Native static final int kCompositeChangedBit = 1 << 4;324@Native static final int kCompositeNotChangedBit = ~kCompositeChangedBit;325@Native static final int kStrokeChangedBit = 1 << 5;326@Native static final int kStrokeNotChangedBit = ~kStrokeChangedBit;327@Native static final int kHintsChangedBit = 1 << 6;328@Native static final int kHintsNotChangedBit = ~kHintsChangedBit;329@Native static final int kFontChangedBit = 1 << 7;330@Native static final int kFontNotChangedBit = ~kFontChangedBit;331@Native static final int kEverythingChangedFlag = 0xffffffff;332333// possible color states334@Native static final int kColorSimple = 0;335@Native static final int kColorSystem = 1;336@Native static final int kColorGradient = 2;337@Native static final int kColorTexture = 3;338@Native static final int kColorLinearGradient = 4;339@Native static final int kColorRadialGradient = 5;340341// possible gradient color states342@Native static final int kColorNonCyclic = 0;343@Native static final int kColorCyclic = 1;344345// possible clip states346@Native static final int kClipRect = 0;347@Native static final int kClipShape = 1;348349static int getRendererTypeForPrimitive(int primitiveType) {350switch (primitiveType) {351case kImage:352return kImage;353case kCopyArea:354return kCopyArea;355case kExternal:356return kExternal;357case kString:358case kGlyphs:359case kUnicodes:360return kText;361default:362return kPrimitive;363}364}365366int fChangeFlag;367protected ByteBuffer fGraphicsStates = null;368IntBuffer fGraphicsStatesInt = null;369FloatBuffer fGraphicsStatesFloat = null;370LongBuffer fGraphicsStatesLong = null;371protected Object[] fGraphicsStatesObject = null;372373Rectangle userBounds = new Rectangle();374float lastUserX = 0;375float lastUserY = 0;376float lastUserW = 0;377float lastUserH = 0;378379void setUserBounds(SunGraphics2D sg2d, int x, int y, int width, int height) {380if ((lastUserX != x) || (lastUserY != y) || (lastUserW != width) || (lastUserH != height)) {381lastUserX = x;382lastUserY = y;383lastUserW = width;384lastUserH = height;385386this.fGraphicsStatesInt.put(kBoundsXIndex, x);387this.fGraphicsStatesInt.put(kBoundsYIndex, y);388this.fGraphicsStatesInt.put(kBoundsWidthIndex, width);389this.fGraphicsStatesInt.put(kBoundsHeightIndex, height);390391userBounds.setBounds(x, y, width, height);392393this.fChangeFlag = (this.fChangeFlag | kBoundsChangedBit);394} else {395this.fChangeFlag = (this.fChangeFlag & kBoundsNotChangedBit);396}397}398399static ByteBuffer getBufferOfSize(int size) {400ByteBuffer buffer = ByteBuffer.allocateDirect(size * 4);401buffer.order(ByteOrder.nativeOrder());402return buffer;403}404405FloatBuffer clipCoordinatesArray = null;406IntBuffer clipTypesArray = null;407Shape lastClipShape = null;408float lastClipX = 0;409float lastClipY = 0;410float lastClipW = 0;411float lastClipH = 0;412413void setupClip(SunGraphics2D sg2d) {414switch (sg2d.clipState) {415case SunGraphics2D.CLIP_DEVICE:416case SunGraphics2D.CLIP_RECTANGULAR: {417Region clip = sg2d.getCompClip();418float x = clip.getLoX();419float y = clip.getLoY();420float w = clip.getWidth();421float h = clip.getHeight();422if ((this.fGraphicsStatesInt.get(kClipStateIndex) != kClipRect) ||423(x != lastClipX) ||424(y != lastClipY) ||425(w != lastClipW) ||426(h != lastClipH)) {427this.fGraphicsStatesFloat.put(kClipXIndex, x);428this.fGraphicsStatesFloat.put(kClipYIndex, y);429this.fGraphicsStatesFloat.put(kClipWidthIndex, w);430this.fGraphicsStatesFloat.put(kClipHeightIndex, h);431432lastClipX = x;433lastClipY = y;434lastClipW = w;435lastClipH = h;436437this.fChangeFlag = (this.fChangeFlag | kClipChangedBit);438} else {439this.fChangeFlag = (this.fChangeFlag & kClipNotChangedBit);440}441this.fGraphicsStatesInt.put(kClipStateIndex, kClipRect);442break;443}444case SunGraphics2D.CLIP_SHAPE: {445// if (lastClipShape != sg2d.usrClip) shapes are mutable!, and doing "equals" traverses all446// the coordinates, so we might as well do all of it anyhow447lastClipShape = sg2d.usrClip;448449GeneralPath gp = null;450451if (sg2d.usrClip instanceof GeneralPath) {452gp = (GeneralPath) sg2d.usrClip;453} else {454gp = new GeneralPath(sg2d.usrClip);455}456457int shapeLength = getPathLength(gp);458459if ((clipCoordinatesArray == null) || (clipCoordinatesArray.capacity() < (shapeLength * 6))) {460clipCoordinatesArray = getBufferOfSize(shapeLength * 6).asFloatBuffer(); // segment can have a461// max of 6 coordinates462}463if ((clipTypesArray == null) || (clipTypesArray.capacity() < shapeLength)) {464clipTypesArray = getBufferOfSize(shapeLength).asIntBuffer();465}466467int windingRule = getPathCoordinates(gp, clipCoordinatesArray, clipTypesArray);468469this.fGraphicsStatesInt.put(kClipNumTypesIndex, clipTypesArray.position());470this.fGraphicsStatesInt.put(kClipNumCoordsIndex, clipCoordinatesArray.position());471this.fGraphicsStatesInt.put(kClipWindingRuleIndex, windingRule);472this.fGraphicsStatesObject[kClipTypesIndex] = clipTypesArray;473this.fGraphicsStatesObject[kClipCoordinatesIndex] = clipCoordinatesArray;474475this.fChangeFlag = (this.fChangeFlag | kClipChangedBit);476this.fGraphicsStatesInt.put(kClipStateIndex, kClipShape);477break;478}479}480481}482483final double[] lastCTM = new double[6];484float lastCTMa = 0;485float lastCTMb = 0;486float lastCTMc = 0;487float lastCTMd = 0;488float lastCTMtx = 0;489float lastCTMty = 0;490491void setupTransform(SunGraphics2D sg2d) {492sg2d.transform.getMatrix(lastCTM);493494float a = (float) lastCTM[0];495float b = (float) lastCTM[1];496float c = (float) lastCTM[2];497float d = (float) lastCTM[3];498float tx = (float) lastCTM[4];499float ty = (float) lastCTM[5];500if (tx != lastCTMtx ||501ty != lastCTMty ||502a != lastCTMa ||503b != lastCTMb ||504c != lastCTMc ||505d != lastCTMd) {506this.fGraphicsStatesFloat.put(kCTMaIndex, a);507this.fGraphicsStatesFloat.put(kCTMbIndex, b);508this.fGraphicsStatesFloat.put(kCTMcIndex, c);509this.fGraphicsStatesFloat.put(kCTMdIndex, d);510this.fGraphicsStatesFloat.put(kCTMtxIndex, tx);511this.fGraphicsStatesFloat.put(kCTMtyIndex, ty);512513lastCTMa = a;514lastCTMb = b;515lastCTMc = c;516lastCTMd = d;517lastCTMtx = tx;518lastCTMty = ty;519520this.fChangeFlag = (this.fChangeFlag | kCTMChangedBit);521} else {522this.fChangeFlag = (this.fChangeFlag & kCTMNotChangedBit);523}524}525526static AffineTransform sIdentityMatrix = new AffineTransform();527Paint lastPaint = null;528long lastPaintPtr = 0;529int lastPaintRGB = 0;530int lastPaintIndex = 0;531BufferedImage texturePaintImage = null;532533void setGradientViaRasterPath(SunGraphics2D sg2d) {534if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorTexture) || (lastPaint != sg2d.paint) || ((this.fChangeFlag & kBoundsChangedBit) != 0)) {535PaintContext context = sg2d.paint.createContext(sg2d.getDeviceColorModel(), userBounds, userBounds, sIdentityMatrix, sg2d.getRenderingHints());536WritableRaster raster = (WritableRaster) (context.getRaster(userBounds.x, userBounds.y, userBounds.width, userBounds.height));537ColorModel cm = context.getColorModel();538texturePaintImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);539540this.fGraphicsStatesInt.put(kColorStateIndex, kColorTexture);541this.fGraphicsStatesInt.put(kColorWidthIndex, texturePaintImage.getWidth());542this.fGraphicsStatesInt.put(kColorHeightIndex, texturePaintImage.getHeight());543this.fGraphicsStatesFloat.put(kColortxIndex, (float) userBounds.getX());544this.fGraphicsStatesFloat.put(kColortyIndex, (float) userBounds.getY());545this.fGraphicsStatesFloat.put(kColorsxIndex, 1.0f);546this.fGraphicsStatesFloat.put(kColorsyIndex, 1.0f);547this.fGraphicsStatesObject[kTextureImageIndex] = OSXOffScreenSurfaceData.createNewSurface(texturePaintImage);548549this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);550} else {551this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);552}553}554555void setupPaint(SunGraphics2D sg2d, int x, int y, int w, int h) {556if (sg2d.paint instanceof SystemColor) {557SystemColor color = (SystemColor) sg2d.paint;558int index = color.hashCode(); // depends on Color.java hashCode implementation! (returns "value" of color)559if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorSystem) || (index != this.lastPaintIndex)) {560this.lastPaintIndex = index;561562this.fGraphicsStatesInt.put(kColorStateIndex, kColorSystem);563this.fGraphicsStatesInt.put(kColorIndexValueIndex, index);564565this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);566} else {567this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);568}569} else if (sg2d.paint instanceof Color) {570Color color = (Color) sg2d.paint;571int rgb = color.getRGB();572if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorSimple) || (rgb != this.lastPaintRGB)) {573this.lastPaintRGB = rgb;574575this.fGraphicsStatesInt.put(kColorStateIndex, kColorSimple);576this.fGraphicsStatesInt.put(kColorRGBValueIndex, rgb);577578this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);579} else {580this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);581}582} else if (sg2d.paint instanceof GradientPaint) {583if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorGradient) || (lastPaint != sg2d.paint)) {584GradientPaint color = (GradientPaint) sg2d.paint;585this.fGraphicsStatesInt.put(kColorStateIndex, kColorGradient);586this.fGraphicsStatesInt.put(kColorRGBValue1Index, color.getColor1().getRGB());587this.fGraphicsStatesInt.put(kColorRGBValue2Index, color.getColor2().getRGB());588this.fGraphicsStatesInt.put(kColorIsCyclicIndex, (color.isCyclic()) ? kColorCyclic : kColorNonCyclic);589Point2D p = color.getPoint1();590this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());591this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());592p = color.getPoint2();593this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());594this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());595596this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);597} else {598this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);599}600} else if (sg2d.paint instanceof LinearGradientPaint) {601LinearGradientPaint color = (LinearGradientPaint) sg2d.paint;602if (color.getCycleMethod() == LinearGradientPaint.CycleMethod.NO_CYCLE) {603if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorLinearGradient) || (lastPaint != sg2d.paint)) {604605this.fGraphicsStatesInt.put(kColorStateIndex, kColorLinearGradient);606int numColor = color.getColors().length;607int[] colorArray = new int[numColor];608for (int i = 0; i < numColor; i++) {609colorArray[i] = color.getColors()[i].getRGB();610}611this.fGraphicsStatesObject[kColorArrayIndex] = colorArray;612613int numFractions = color.getFractions().length;614float[] fractionArray = new float[numFractions];615for (int i = 0; i < numFractions; i++) {616fractionArray[i] = color.getFractions()[i];617}618this.fGraphicsStatesObject[kFractionsArrayIndex] = color.getFractions();619620Point2D p = color.getStartPoint();621this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());622this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());623p = color.getEndPoint();624this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());625this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());626627this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);628} else {629this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);630}631} else {632setGradientViaRasterPath(sg2d);633}634} else if (sg2d.paint instanceof RadialGradientPaint) {635RadialGradientPaint color = (RadialGradientPaint) sg2d.paint;636if (color.getCycleMethod() == RadialGradientPaint.CycleMethod.NO_CYCLE) {637if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorRadialGradient) || (lastPaint != sg2d.paint)) {638639this.fGraphicsStatesInt.put(kColorStateIndex, kColorRadialGradient);640int numColor = color.getColors().length;641int[] colorArray = new int[numColor];642for (int i = 0; i < numColor; i++) {643colorArray[i] = color.getColors()[i].getRGB();644}645this.fGraphicsStatesObject[kColorArrayIndex] = colorArray;646647int numStops = color.getFractions().length;648float[] stopsArray = new float[numStops];649for (int i = 0; i < numStops; i++) {650stopsArray[i] = color.getFractions()[i];651}652this.fGraphicsStatesObject[kFractionsArrayIndex] = color.getFractions();653654Point2D p = color.getFocusPoint();655this.fGraphicsStatesFloat.put(kColorx1Index, (float) p.getX());656this.fGraphicsStatesFloat.put(kColory1Index, (float) p.getY());657p = color.getCenterPoint();658this.fGraphicsStatesFloat.put(kColorx2Index, (float) p.getX());659this.fGraphicsStatesFloat.put(kColory2Index, (float) p.getY());660this.fGraphicsStatesFloat.put(kRadiusIndex, color.getRadius());661662this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);663} else {664this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);665}666} else {667setGradientViaRasterPath(sg2d);668}669} else if (sg2d.paint instanceof TexturePaint) {670if ((this.fGraphicsStatesInt.get(kColorStateIndex) != kColorTexture) || (lastPaint != sg2d.paint)) {671TexturePaint color = (TexturePaint) sg2d.paint;672this.fGraphicsStatesInt.put(kColorStateIndex, kColorTexture);673texturePaintImage = color.getImage();674SurfaceData textureSurfaceData = OSXOffScreenSurfaceData.createNewSurface(texturePaintImage);675this.fGraphicsStatesInt.put(kColorWidthIndex, texturePaintImage.getWidth());676this.fGraphicsStatesInt.put(kColorHeightIndex, texturePaintImage.getHeight());677Rectangle2D anchor = color.getAnchorRect();678this.fGraphicsStatesFloat.put(kColortxIndex, (float) anchor.getX());679this.fGraphicsStatesFloat.put(kColortyIndex, (float) anchor.getY());680this.fGraphicsStatesFloat.put(kColorsxIndex, (float) (anchor.getWidth() / texturePaintImage.getWidth()));681this.fGraphicsStatesFloat.put(kColorsyIndex, (float) (anchor.getHeight() / texturePaintImage.getHeight()));682this.fGraphicsStatesObject[kTextureImageIndex] = textureSurfaceData;683684this.fChangeFlag = (this.fChangeFlag | kColorChangedBit);685} else {686this.fChangeFlag = (this.fChangeFlag & kColorNotChangedBit);687}688} else {689setGradientViaRasterPath(sg2d);690}691lastPaint = sg2d.paint;692}693694Composite lastComposite;695int lastCompositeAlphaRule = 0;696float lastCompositeAlphaValue = 0;697698void setupComposite(SunGraphics2D sg2d) {699Composite composite = sg2d.composite;700701if (lastComposite != composite) {702lastComposite = composite;703704// For composite state COMP_ISCOPY, COMP_XOR or COMP_CUSTOM set alpha compositor to COPY:705int alphaRule = AlphaComposite.SRC_OVER;706float alphaValue = 1.0f;707708// For composite state COMP_ISCOPY composite could be null. If it's not (or composite state == COMP_ALPHA)709// get alpha compositor's values:710if ((sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) && (composite != null)) {711AlphaComposite alphaComposite = (AlphaComposite) composite;712alphaRule = alphaComposite.getRule();713alphaValue = alphaComposite.getAlpha();714}715716// 2-17-03 VL: [Radar 3174922]717// For COMP_XOR and COMP_CUSTOM compositing modes we should be setting alphaRule = AlphaComposite.SRC718// which should map to kCGCompositeCopy.719720if ((lastCompositeAlphaRule != alphaRule) || (lastCompositeAlphaValue != alphaValue)) {721this.fGraphicsStatesInt.put(kCompositeRuleIndex, alphaRule);722this.fGraphicsStatesFloat.put(kCompositeValueIndex, alphaValue);723724lastCompositeAlphaRule = alphaRule;725lastCompositeAlphaValue = alphaValue;726727this.fChangeFlag = (this.fChangeFlag | kCompositeChangedBit);728} else {729this.fChangeFlag = (this.fChangeFlag & kCompositeNotChangedBit);730}731} else {732this.fChangeFlag = (this.fChangeFlag & kCompositeNotChangedBit);733}734}735736BasicStroke lastStroke = null;737static BasicStroke defaultBasicStroke = new BasicStroke();738739void setupStroke(SunGraphics2D sg2d) {740BasicStroke stroke = defaultBasicStroke;741742if (sg2d.stroke instanceof BasicStroke) {743stroke = (BasicStroke) sg2d.stroke;744}745746if (lastStroke != stroke) {747this.fGraphicsStatesObject[kStrokeDashArrayIndex] = stroke.getDashArray();748this.fGraphicsStatesFloat.put(kStrokeDashPhaseIndex, stroke.getDashPhase());749this.fGraphicsStatesInt.put(kStrokeCapIndex, stroke.getEndCap());750this.fGraphicsStatesInt.put(kStrokeJoinIndex, stroke.getLineJoin());751this.fGraphicsStatesFloat.put(kStrokeWidthIndex, stroke.getLineWidth());752this.fGraphicsStatesFloat.put(kStrokeLimitIndex, stroke.getMiterLimit());753754this.fChangeFlag = (this.fChangeFlag | kStrokeChangedBit);755756lastStroke = stroke;757} else {758this.fChangeFlag = (this.fChangeFlag & kStrokeNotChangedBit);759}760}761762Font lastFont;763764void setupFont(Font font, Paint paint) {765if (font == null) { return; }766767// We have to setup the kFontPaintIndex if we have changed the color so we added the last768// test to see if the color has changed - needed for complex strings769// see Radar 3368674770if ((font != lastFont) || ((this.fChangeFlag & kColorChangedBit) != 0)) {771this.fGraphicsStatesObject[kFontIndex] = font;772this.fGraphicsStatesObject[kFontPaintIndex] = paint;773774this.fChangeFlag = (this.fChangeFlag | kFontChangedBit);775776lastFont = font;777} else {778this.fChangeFlag = (this.fChangeFlag & kFontNotChangedBit);779}780}781782void setupRenderingHints(SunGraphics2D sg2d) {783boolean hintsChanged = false;784785// Significant for draw, fill, text, and image ops:786int antialiasHint = sg2d.antialiasHint;787if (this.fGraphicsStatesInt.get(kHintsAntialiasIndex) != antialiasHint) {788this.fGraphicsStatesInt.put(kHintsAntialiasIndex, antialiasHint);789hintsChanged = true;790}791792// Significant only for text ops:793int textAntialiasHint = sg2d.textAntialiasHint;794if (this.fGraphicsStatesInt.get(kHintsTextAntialiasIndex) != textAntialiasHint) {795this.fGraphicsStatesInt.put(kHintsTextAntialiasIndex, textAntialiasHint);796hintsChanged = true;797}798799// Significant only for text ops:800int fractionalMetricsHint = sg2d.fractionalMetricsHint;801if (this.fGraphicsStatesInt.get(kHintsFractionalMetricsIndex) != fractionalMetricsHint) {802this.fGraphicsStatesInt.put(kHintsFractionalMetricsIndex, fractionalMetricsHint);803hintsChanged = true;804}805806// Significant only for image ops:807int renderHint = sg2d.renderHint;808if (this.fGraphicsStatesInt.get(kHintsRenderingIndex) != renderHint) {809this.fGraphicsStatesInt.put(kHintsRenderingIndex, renderHint);810hintsChanged = true;811}812813// Significant only for image ops:814Object hintValue = sg2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);815int interpolationHint = (hintValue != null ? ((SunHints.Value) hintValue).getIndex() : -1);816if (this.fGraphicsStatesInt.get(kHintsInterpolationIndex) != interpolationHint) {817this.fGraphicsStatesInt.put(kHintsInterpolationIndex, interpolationHint);818hintsChanged = true;819}820821if (hintsChanged) {822this.fChangeFlag = (this.fChangeFlag | kHintsChangedBit);823} else {824this.fChangeFlag = (this.fChangeFlag & kHintsNotChangedBit);825}826}827828SunGraphics2D sg2dCurrent = null;829Thread threadCurrent = null;830831void setupGraphicsState(SunGraphics2D sg2d, int primitiveType) {832setupGraphicsState(sg2d, primitiveType, sg2d.font, 0, 0, fBounds.width, fBounds.height); // deviceBounds into userBounds833}834835void setupGraphicsState(SunGraphics2D sg2d, int primitiveType, int x, int y, int w, int h) {836setupGraphicsState(sg2d, primitiveType, sg2d.font, x, y, w, h);837}838839// the method below is overriden by CPeerSurface to check the last peer used to draw840// if the peer changed we finish lazy drawing841void setupGraphicsState(SunGraphics2D sg2d, int primitiveType, Font font, int x, int y, int w, int h) {842this.fChangeFlag = 0;843844setUserBounds(sg2d, x, y, w, h);845846Thread thread = Thread.currentThread();847if ((this.sg2dCurrent != sg2d) || (this.threadCurrent != thread)) {848this.sg2dCurrent = sg2d;849this.threadCurrent = thread;850851setupClip(sg2d);852setupTransform(sg2d);853setupPaint(sg2d, x, y, w, h);854setupComposite(sg2d);855setupStroke(sg2d);856setupFont(font, sg2d.paint);857setupRenderingHints(sg2d);858859this.fChangeFlag = kEverythingChangedFlag;860} else {861int rendererType = getRendererTypeForPrimitive(primitiveType);862863setupClip(sg2d);864setupTransform(sg2d);865866if (rendererType != kCopyArea) {867setupComposite(sg2d);868setupRenderingHints(sg2d);869870if ((rendererType != kImage)) {871setupPaint(sg2d, x, y, w, h);872setupStroke(sg2d);873}874if (rendererType != kPrimitive) {875setupFont(font, sg2d.paint);876}877878}879}880881this.fGraphicsStatesInt.put(kChangeFlagIndex, this.fChangeFlag);882}883884boolean isCustomPaint(SunGraphics2D sg2d) {885if ((sg2d.paint instanceof Color) || (sg2d.paint instanceof SystemColor) || (sg2d.paint instanceof GradientPaint) || (sg2d.paint instanceof TexturePaint)) { return false; }886887return true;888}889890final float[] segmentCoordinatesArray = new float[6];891892int getPathLength(GeneralPath gp) {893int length = 0;894895PathIterator pi = gp.getPathIterator(null);896while (pi.isDone() == false) {897pi.next();898length++;899}900901return length;902}903904int getPathCoordinates(GeneralPath gp, FloatBuffer coordinates, IntBuffer types) {905// System.err.println("getPathCoordinates");906boolean skip = false;907908coordinates.clear();909types.clear();910911int type;912913PathIterator pi = gp.getPathIterator(null);914while (pi.isDone() == false) {915skip = false;916type = pi.currentSegment(segmentCoordinatesArray);917918switch (type) {919case PathIterator.SEG_MOVETO:920// System.err.println(" SEG_MOVETO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+")");921if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&922segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND) {923coordinates.put(segmentCoordinatesArray[0]);924coordinates.put(segmentCoordinatesArray[1]);925} else {926skip = true;927}928break;929case PathIterator.SEG_LINETO:930// System.err.println(" SEG_LINETO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+")");931if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&932segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND) {933coordinates.put(segmentCoordinatesArray[0]);934coordinates.put(segmentCoordinatesArray[1]);935} else {936skip = true;937}938break;939case PathIterator.SEG_QUADTO:940// System.err.println(" SEG_QUADTO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+"), ("+segmentCoordinatesArray[2]+", "+segmentCoordinatesArray[3]+")");941if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&942segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND &&943segmentCoordinatesArray[2] < UPPER_BND && segmentCoordinatesArray[2] > LOWER_BND &&944segmentCoordinatesArray[3] < UPPER_BND && segmentCoordinatesArray[3] > LOWER_BND) {945coordinates.put(segmentCoordinatesArray[0]);946coordinates.put(segmentCoordinatesArray[1]);947coordinates.put(segmentCoordinatesArray[2]);948coordinates.put(segmentCoordinatesArray[3]);949} else {950skip = true;951}952break;953case PathIterator.SEG_CUBICTO:954// System.err.println(" SEG_QUADTO ("+segmentCoordinatesArray[0]+", "+segmentCoordinatesArray[1]+"), ("+segmentCoordinatesArray[2]+", "+segmentCoordinatesArray[3]+"), ("+segmentCoordinatesArray[4]+", "+segmentCoordinatesArray[5]+")");955if (segmentCoordinatesArray[0] < UPPER_BND && segmentCoordinatesArray[0] > LOWER_BND &&956segmentCoordinatesArray[1] < UPPER_BND && segmentCoordinatesArray[1] > LOWER_BND &&957segmentCoordinatesArray[2] < UPPER_BND && segmentCoordinatesArray[2] > LOWER_BND &&958segmentCoordinatesArray[3] < UPPER_BND && segmentCoordinatesArray[3] > LOWER_BND &&959segmentCoordinatesArray[4] < UPPER_BND && segmentCoordinatesArray[4] > LOWER_BND &&960segmentCoordinatesArray[5] < UPPER_BND && segmentCoordinatesArray[5] > LOWER_BND) {961coordinates.put(segmentCoordinatesArray[0]);962coordinates.put(segmentCoordinatesArray[1]);963coordinates.put(segmentCoordinatesArray[2]);964coordinates.put(segmentCoordinatesArray[3]);965coordinates.put(segmentCoordinatesArray[4]);966coordinates.put(segmentCoordinatesArray[5]);967} else {968skip = true;969}970break;971case PathIterator.SEG_CLOSE:972// System.err.println(" SEG_CLOSE");973break;974}975976if (!skip) {977types.put(type);978}979980pi.next();981}982983return pi.getWindingRule();984}985986public void doLine(CRenderer renderer, SunGraphics2D sg2d, float x1, float y1, float x2, float y2) {987// System.err.println("-- doLine x1="+x1+" y1="+y1+" x2="+x2+" y2="+y2+" paint="+sg2d.paint);988setupGraphicsState(sg2d, kLine, sg2d.font, 0, 0, fBounds.width, fBounds.height);989renderer.doLine(this, x1, y1, x2, y2);990}991992public void doRect(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, boolean isfill) {993// System.err.println("-- doRect x="+x+" y="+y+" w="+width+" h="+height+" isfill="+isfill+" paint="+sg2d.paint);994if ((isfill) && (isCustomPaint(sg2d))) {995setupGraphicsState(sg2d, kRect, (int) x, (int) y, (int) width, (int) height);996} else {997setupGraphicsState(sg2d, kRect, sg2d.font, 0, 0, fBounds.width, fBounds.height);998}999renderer.doRect(this, x, y, width, height, isfill);1000}10011002public void doRoundRect(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, float arcW, float arcH, boolean isfill) {1003// System.err.println("--- doRoundRect");1004if ((isfill) && (isCustomPaint(sg2d))) {1005setupGraphicsState(sg2d, kRoundRect, (int) x, (int) y, (int) width, (int) height);1006} else {1007setupGraphicsState(sg2d, kRoundRect, sg2d.font, 0, 0, fBounds.width, fBounds.height);1008}1009renderer.doRoundRect(this, x, y, width, height, arcW, arcH, isfill);1010}10111012public void doOval(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, boolean isfill) {1013// System.err.println("--- doOval");1014if ((isfill) && (isCustomPaint(sg2d))) {1015setupGraphicsState(sg2d, kOval, (int) x, (int) y, (int) width, (int) height);1016} else {1017setupGraphicsState(sg2d, kOval, sg2d.font, 0, 0, fBounds.width, fBounds.height);1018}1019renderer.doOval(this, x, y, width, height, isfill);1020}10211022public void doArc(CRenderer renderer, SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type, boolean isfill) {1023// System.err.println("--- doArc");1024if ((isfill) && (isCustomPaint(sg2d))) {1025setupGraphicsState(sg2d, kArc, (int) x, (int) y, (int) width, (int) height);1026} else {1027setupGraphicsState(sg2d, kArc, sg2d.font, 0, 0, fBounds.width, fBounds.height);1028}10291030renderer.doArc(this, x, y, width, height, startAngle, arcAngle, type, isfill);1031}10321033public void doPolygon(CRenderer renderer, SunGraphics2D sg2d, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill) {1034// System.err.println("--- doPolygon");10351036if ((isfill) && (isCustomPaint(sg2d))) {1037int minx = xpoints[0];1038int miny = ypoints[0];1039int maxx = minx;1040int maxy = miny;1041for (int i = 1; i < npoints; i++) {1042int x = xpoints[i];1043if (x < minx) {1044minx = x;1045} else if (x > maxx) {1046maxx = x;1047}10481049int y = ypoints[i];1050if (y < miny) {1051miny = y;1052} else if (y > maxy) {1053maxy = y;1054}1055}1056setupGraphicsState(sg2d, kPolygon, minx, miny, maxx - minx, maxy - miny);1057} else {1058setupGraphicsState(sg2d, kPolygon, sg2d.font, 0, 0, fBounds.width, fBounds.height);1059}1060renderer.doPoly(this, xpoints, ypoints, npoints, ispolygon, isfill);1061}10621063FloatBuffer shapeCoordinatesArray = null;1064IntBuffer shapeTypesArray = null;10651066public void drawfillShape(CRenderer renderer, SunGraphics2D sg2d, GeneralPath gp, boolean isfill, boolean shouldApplyOffset) {1067// System.err.println("--- drawfillShape");10681069if ((isfill) && (isCustomPaint(sg2d))) {1070Rectangle bounds = gp.getBounds();1071setupGraphicsState(sg2d, kShape, bounds.x, bounds.y, bounds.width, bounds.height);1072} else {1073setupGraphicsState(sg2d, kShape, sg2d.font, 0, 0, fBounds.width, fBounds.height);1074}10751076int shapeLength = getPathLength(gp);10771078if ((shapeCoordinatesArray == null) || (shapeCoordinatesArray.capacity() < (shapeLength * 6))) {1079shapeCoordinatesArray = getBufferOfSize(shapeLength * 6).asFloatBuffer(); // segment can have a max of 61080// coordinates1081}1082if ((shapeTypesArray == null) || (shapeTypesArray.capacity() < shapeLength)) {1083shapeTypesArray = getBufferOfSize(shapeLength).asIntBuffer();1084}10851086int windingRule = getPathCoordinates(gp, shapeCoordinatesArray, shapeTypesArray);10871088renderer.doShape(this, shapeLength, shapeCoordinatesArray, shapeTypesArray, windingRule, isfill, shouldApplyOffset);1089}10901091public void blitImage(CRenderer renderer, SunGraphics2D sg2d, SurfaceData img, boolean fliph, boolean flipv, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, Color bgColor) {1092// System.err.println("--- blitImage sx="+sx+", sy="+sy+", sw="+sw+", sh="+sh+", img="+img);1093OSXOffScreenSurfaceData osxsd = (OSXOffScreenSurfaceData) img;1094synchronized (osxsd.getLockObject()) {1095int w = osxsd.bim.getWidth();1096int h = osxsd.bim.getHeight();10971098// the image itself can have outstanding graphics primitives that might need to be flushed1099setupGraphicsState(sg2d, kImage, sg2d.font, 0, 0, fBounds.width, fBounds.height);11001101// 04/06/04 cmc: radr://3612381 Graphics.drawImage ignores bgcolor parameter1102if (bgColor != null) {1103img = osxsd.getCopyWithBgColor(bgColor);1104}11051106renderer.doImage(this, img, fliph, flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh);1107}1108}11091110public interface CGContextDrawable {1111public void drawIntoCGContext(final long cgContext);1112}11131114public void drawString(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, String str, double x, double y) {1115// System.err.println("--- drawString str=\""+str+"\"");1116// see <rdar://problem/3825795>. We don't want to call anything if the string is empty!1117if (str.length() == 0) { return; }11181119setupGraphicsState(sg2d, kString, sg2d.font, 0, 0, fBounds.width, fBounds.height);1120renderer.doDrawString(this, nativeStrikePtr, str, x, y);1121}11221123public void drawGlyphs(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, GlyphVector gv, float x, float y) {1124// System.err.println("--- drawGlyphs");1125setupGraphicsState(sg2d, kGlyphs, gv.getFont(), 0, 0, fBounds.width, fBounds.height);1126renderer.doDrawGlyphs(this, nativeStrikePtr, gv, x, y);1127}11281129public void drawUnicodes(CTextPipe renderer, SunGraphics2D sg2d, long nativeStrikePtr, char[] unicodes, int offset, int length, float x, float y) {1130// System.err.println("--- drawUnicodes "+(new String(unicodes, offset, length)));1131setupGraphicsState(sg2d, kUnicodes, sg2d.font, 0, 0, fBounds.width, fBounds.height);1132if (length == 1) {1133renderer.doOneUnicode(this, nativeStrikePtr, unicodes[offset], x, y);1134} else {1135renderer.doUnicodes(this, nativeStrikePtr, unicodes, offset, length, x, y);1136}1137}11381139// used by copyArea:11401141Rectangle srcCopyAreaRect = new Rectangle();1142Rectangle dstCopyAreaRect = new Rectangle();1143Rectangle finalCopyAreaRect = new Rectangle();1144Rectangle copyAreaBounds = new Rectangle();11451146void intersection(Rectangle r1, Rectangle r2, Rectangle r3) {1147// this code is taken from Rectangle.java (modified to put results in r3)1148int tx1 = r1.x;1149int ty1 = r1.y;1150long tx2 = tx1 + r1.width;1151long ty2 = ty1 + r1.height;11521153int rx1 = r2.x;1154int ry1 = r2.y;1155long rx2 = rx1 + r2.width;1156long ry2 = ry1 + r2.height;11571158if (tx1 < rx1) tx1 = rx1;1159if (ty1 < ry1) ty1 = ry1;1160if (tx2 > rx2) tx2 = rx2;1161if (ty2 > ry2) ty2 = ry2;11621163tx2 -= tx1;1164ty2 -= ty1;11651166// tx2,ty2 will never overflow (they will never be1167// larger than the smallest of the two source w,h)1168// they might underflow, though...1169if (tx2 < Integer.MIN_VALUE) tx2 = Integer.MIN_VALUE;1170if (ty2 < Integer.MIN_VALUE) ty2 = Integer.MIN_VALUE;11711172r3.setBounds(tx1, ty1, (int) tx2, (int) ty2);1173}11741175/**1176* Clips the copy area to the heavyweight bounds and returns the clipped rectangle.1177* The returned clipped rectangle is in the coordinate space of the surface.1178*/1179protected Rectangle clipCopyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy) {1180// we need to clip against the heavyweight bounds1181copyAreaBounds.setBounds(sg2d.devClip.getLoX(), sg2d.devClip.getLoY(), sg2d.devClip.getWidth(), sg2d.devClip.getHeight());11821183// clip src rect1184srcCopyAreaRect.setBounds(x, y, w, h);1185intersection(srcCopyAreaRect, copyAreaBounds, srcCopyAreaRect);1186if ((srcCopyAreaRect.width <= 0) || (srcCopyAreaRect.height <= 0)) {1187// src rect outside bounds1188return null;1189}11901191// clip dst rect1192dstCopyAreaRect.setBounds(srcCopyAreaRect.x + dx, srcCopyAreaRect.y + dy, srcCopyAreaRect.width, srcCopyAreaRect.height);1193intersection(dstCopyAreaRect, copyAreaBounds, dstCopyAreaRect);1194if ((dstCopyAreaRect.width <= 0) || (dstCopyAreaRect.height <= 0)) {1195// dst rect outside clip1196return null;1197}11981199x = dstCopyAreaRect.x - dx;1200y = dstCopyAreaRect.y - dy;1201w = dstCopyAreaRect.width;1202h = dstCopyAreaRect.height;12031204finalCopyAreaRect.setBounds(x, y, w, h);12051206return finalCopyAreaRect;1207}12081209// <rdar://3785539> We only need to mark dirty on screen surfaces. This method is1210// marked as protected and it is intended for subclasses to override if they need to1211// be notified when the surface is dirtied. See CPeerSurfaceData.markDirty() for implementation.1212// We don't do anything for buffered images.1213protected void markDirty(boolean markAsDirty) {1214// do nothing by default1215}12161217// LazyDrawing optimization implementation:12181219@Override1220public boolean canRenderLCDText(SunGraphics2D sg2d) {1221if (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&1222sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&1223sg2d.clipState <= SunGraphics2D.CLIP_RECTANGULAR &&1224// sg2d.surfaceData.getTransparency() == Transparency.OPAQUE &&1225// This last test is a workaround until we fix loop selection1226// in the pipe validation1227sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) { return true; }1228return false; /* for now - in the future we may want to search */1229}12301231public static boolean IsSimpleColor(Object c) {1232return ((c instanceof Color) || (c instanceof SystemColor) || (c instanceof javax.swing.plaf.ColorUIResource));1233}12341235static {1236if ((kColorPointerIndex % 2) != 0) {1237System.err.println("kColorPointerIndex=" + kColorPointerIndex + " is NOT aligned for 64 bit");1238System.exit(0);1239}1240}1241}124212431244