1 /* 2 * Copyright (c) 2011, 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 package sun.java2d; 27 28 import java.awt.*; 29 import java.awt.font.*; 30 import java.awt.geom.*; 31 import java.awt.image.*; 32 import java.nio.*; 33 34 import sun.awt.*; 35 import sun.awt.image.*; 36 import sun.java2d.loops.*; 37 import sun.java2d.pipe.*; 38 import sun.lwawt.macosx.*; 39 40 import javax.tools.annotation.GenerateNativeHeader; 41 42 /* 43 * This is the SurfaceData for a CGContextRef. 44 */ 45 /* No native methods here, but the constants are needed in the supporting JNI code */ 46 @GenerateNativeHeader 47 public abstract class OSXSurfaceData extends BufImgSurfaceData { 48 final static float UPPER_BND = Float.MAX_VALUE / 2.0f; 49 final static float LOWER_BND = -UPPER_BND; 50 51 protected static CRenderer sQuartzPipe = null; 52 protected static CTextPipe sCocoaTextPipe = null; 53 protected static CompositeCRenderer sQuartzCompositePipe = null; 54 55 private GraphicsConfiguration fConfig; 56 private Rectangle fBounds; // bounds in user coordinates 57 58 static { 59 sQuartzPipe = new CRenderer(); // Creates the singleton quartz pipe. 60 } 61 62 // NOTE: Any subclasses must eventually call QuartzSurfaceData_InitOps in OSXSurfaceData.h 63 // This sets up the native side for the SurfaceData, and is required. 64 public OSXSurfaceData(SurfaceType sType, ColorModel cm) { 65 this(sType, cm, null, new Rectangle()); 66 } 181 sDstOutComposite = bim; 182 return bim; 183 } 184 185 public void clearRect(BufferedImage bim, int w, int h) { 186 Graphics2D g = bim.createGraphics(); 187 g.setComposite(AlphaComposite.Clear); 188 g.fillRect(0, 0, w, h); 189 g.dispose(); 190 } 191 192 // END compositing support API 193 194 public void invalidate() { 195 // always valid 196 } 197 198 // graphics primitives drawing implementation: 199 200 // certain primitives don't care about all the states (ex. drawing an image needs not involve setting current paint) 201 static final int kPrimitive = 0; 202 static final int kImage = 1; 203 static final int kText = 2; 204 static final int kCopyArea = 3; 205 static final int kExternal = 4; 206 207 static final int kLine = 5; // belongs to kPrimitive 208 static final int kRect = 6; // belongs to kPrimitive 209 static final int kRoundRect = 7; // belongs to kPrimitive 210 static final int kOval = 8; // belongs to kPrimitive 211 static final int kArc = 9; // belongs to kPrimitive 212 static final int kPolygon = 10; // belongs to kPrimitive 213 static final int kShape = 11; // belongs to kPrimitive 214 // static final int kImage = 12; // belongs to kImage 215 static final int kString = 13; // belongs to kText 216 static final int kGlyphs = 14; // belongs to kText 217 static final int kUnicodes = 15; // belongs to kText 218 // static final int kCopyArea = 16; // belongs to kCopyArea 219 // static final int kExternal = 17; // belongs to kExternal 220 221 static final int kCommonParameterCount = 1 + 1 + 4 + 4; // type + change flags + color info (type(1) align(1) and 222 // value(2)) + parameters ((x1, y1, x2, y2) OR (x, y, w, h)) 223 static final int kLineParametersCount = kCommonParameterCount; // kCommonParameterCount 224 static final int kRectParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill 225 static final int kRoundRectParametersCount = kCommonParameterCount + 2 + 1; // kCommonParameterCount + arcW + arcH + 226 // isfill 227 static final int kOvalParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill 228 static final int kArcParametersCount = kCommonParameterCount + 2 + 1 + 1;// kCommonParameterCount + startAngle + 229 // arcAngle + isfill + type 230 static final int kPolygonParametersCount = 0; // not supported 231 static final int kShapeParametersCount = 0; // not supported 232 static final int kImageParametersCount = kCommonParameterCount + 2 + 2 + 4 + 4; // flip horz vert + w&h + src + dst 233 static final int kStringParametersCount = 0; // not supported 234 static final int kGlyphsParametersCount = 0; // not supported 235 static final int kUnicodesParametersCount = 0; // not supported 236 static final int kPixelParametersCount = 0; // not supported 237 static final int kExternalParametersCount = 0; // not supported 238 239 // for intParameters 240 // states info 241 static final int kChangeFlagIndex = 0; // kBoundsChangedBit | .. | kFontChangedBit 242 // bounds info 243 static final int kBoundsXIndex = 1; 244 static final int kBoundsYIndex = 2; 245 static final int kBoundsWidthIndex = 3; 246 static final int kBoundsHeightIndex = 4; 247 // clip info 248 static final int kClipStateIndex = 5; 249 static final int kClipNumTypesIndex = 6; 250 static final int kClipNumCoordsIndex = 7; 251 static final int kClipWindingRuleIndex = 8; 252 static final int kClipXIndex = 9; 253 static final int kClipYIndex = 10; 254 static final int kClipWidthIndex = 11; 255 static final int kClipHeightIndex = 12; 256 // ctm info 257 static final int kCTMaIndex = 13; 258 static final int kCTMbIndex = 14; 259 static final int kCTMcIndex = 15; 260 static final int kCTMdIndex = 16; 261 static final int kCTMtxIndex = 17; 262 static final int kCTMtyIndex = 18; 263 // color info 264 static final int kColorStateIndex = 19; // kColorSimple or kColorGradient or kColorTexture 265 static final int kColorRGBValueIndex = 20; // if kColorSimple 266 static final int kColorIndexValueIndex = 21; // if kColorSystem 267 static final int kColorPointerIndex = 22; // 268 static final int kColorPointerIndex2 = 23; // 269 static final int kColorRGBValue1Index = 24; // if kColorGradient 270 static final int kColorWidthIndex = 25; // if kColorTexture 271 static final int kColorRGBValue2Index = 26; // if kColorGradient 272 static final int kColorHeightIndex = 27; // if kColorTexture 273 static final int kColorIsCyclicIndex = 28; // if kColorGradient (kColorNonCyclic or kColorCyclic) 274 static final int kColorx1Index = 29; 275 static final int kColortxIndex = 30; 276 static final int kColory1Index = 31; 277 static final int kColortyIndex = 32; 278 static final int kColorx2Index = 33; 279 static final int kColorsxIndex = 34; 280 static final int kColory2Index = 35; 281 static final int kColorsyIndex = 36; 282 // composite info 283 static final int kCompositeRuleIndex = 37; // kCGCompositeClear or ... or kCGCompositeXor 284 static final int kCompositeValueIndex = 38; 285 // stroke info 286 static final int kStrokeJoinIndex = 39; // see BasicStroke.java 287 static final int kStrokeCapIndex = 40; // see BasicStroke.java 288 static final int kStrokeWidthIndex = 41; 289 static final int kStrokeDashPhaseIndex = 42; 290 static final int kStrokeLimitIndex = 43; 291 // hints info 292 static final int kHintsAntialiasIndex = 44; 293 static final int kHintsTextAntialiasIndex = 45; 294 static final int kHintsFractionalMetricsIndex = 46; 295 static final int kHintsRenderingIndex = 47; 296 static final int kHintsInterpolationIndex = 48; 297 // live resizing info 298 static final int kCanDrawDuringLiveResizeIndex = 49; 299 300 static final int kSizeOfParameters = kCanDrawDuringLiveResizeIndex + 1; 301 302 // for objectParameters 303 static final int kClipCoordinatesIndex = 0; 304 static final int kClipTypesIndex = 1; 305 static final int kTextureImageIndex = 2; 306 static final int kStrokeDashArrayIndex = 3; 307 static final int kFontIndex = 4; 308 static final int kFontPaintIndex = 5; 309 310 // possible state changes 311 static final int kBoundsChangedBit = 1 << 0; 312 static final int kBoundsNotChangedBit = ~kBoundsChangedBit; 313 static final int kClipChangedBit = 1 << 1; 314 static final int kClipNotChangedBit = ~kClipChangedBit; 315 static final int kCTMChangedBit = 1 << 2; 316 static final int kCTMNotChangedBit = ~kCTMChangedBit; 317 static final int kColorChangedBit = 1 << 3; 318 static final int kColorNotChangedBit = ~kColorChangedBit; 319 static final int kCompositeChangedBit = 1 << 4; 320 static final int kCompositeNotChangedBit = ~kCompositeChangedBit; 321 static final int kStrokeChangedBit = 1 << 5; 322 static final int kStrokeNotChangedBit = ~kStrokeChangedBit; 323 static final int kHintsChangedBit = 1 << 6; 324 static final int kHintsNotChangedBit = ~kHintsChangedBit; 325 static final int kFontChangedBit = 1 << 7; 326 static final int kFontNotChangedBit = ~kFontChangedBit; 327 static final int kEverythingChangedFlag = 0xffffffff; 328 329 // possible color states 330 static final int kColorSimple = 0; 331 static final int kColorSystem = 1; 332 static final int kColorGradient = 2; 333 static final int kColorTexture = 3; 334 335 // possible gradient color states 336 static final int kColorNonCyclic = 0; 337 static final int kColorCyclic = 1; 338 339 // possible clip states 340 static final int kClipRect = 0; 341 static final int kClipShape = 1; 342 343 static int getRendererTypeForPrimitive(int primitiveType) { 344 switch (primitiveType) { 345 case kImage: 346 return kImage; 347 case kCopyArea: 348 return kCopyArea; 349 case kExternal: 350 return kExternal; 351 case kString: 352 case kGlyphs: 353 case kUnicodes: 354 return kText; 355 default: 356 return kPrimitive; 357 } 358 } 359 360 int fChangeFlag; 361 protected ByteBuffer fGraphicsStates = null; | 1 /* 2 * Copyright (c) 2011, 2013, 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 package sun.java2d; 27 28 import java.awt.*; 29 import java.awt.font.*; 30 import java.awt.geom.*; 31 import java.awt.image.*; 32 import java.nio.*; 33 34 import sun.awt.*; 35 import sun.awt.image.*; 36 import sun.java2d.loops.*; 37 import sun.java2d.pipe.*; 38 import sun.lwawt.macosx.*; 39 40 import java.lang.annotation.Native; 41 42 /* 43 * This is the SurfaceData for a CGContextRef. 44 */ 45 public abstract class OSXSurfaceData extends BufImgSurfaceData { 46 final static float UPPER_BND = Float.MAX_VALUE / 2.0f; 47 final static float LOWER_BND = -UPPER_BND; 48 49 protected static CRenderer sQuartzPipe = null; 50 protected static CTextPipe sCocoaTextPipe = null; 51 protected static CompositeCRenderer sQuartzCompositePipe = null; 52 53 private GraphicsConfiguration fConfig; 54 private Rectangle fBounds; // bounds in user coordinates 55 56 static { 57 sQuartzPipe = new CRenderer(); // Creates the singleton quartz pipe. 58 } 59 60 // NOTE: Any subclasses must eventually call QuartzSurfaceData_InitOps in OSXSurfaceData.h 61 // This sets up the native side for the SurfaceData, and is required. 62 public OSXSurfaceData(SurfaceType sType, ColorModel cm) { 63 this(sType, cm, null, new Rectangle()); 64 } 179 sDstOutComposite = bim; 180 return bim; 181 } 182 183 public void clearRect(BufferedImage bim, int w, int h) { 184 Graphics2D g = bim.createGraphics(); 185 g.setComposite(AlphaComposite.Clear); 186 g.fillRect(0, 0, w, h); 187 g.dispose(); 188 } 189 190 // END compositing support API 191 192 public void invalidate() { 193 // always valid 194 } 195 196 // graphics primitives drawing implementation: 197 198 // certain primitives don't care about all the states (ex. drawing an image needs not involve setting current paint) 199 @Native static final int kPrimitive = 0; 200 @Native static final int kImage = 1; 201 @Native static final int kText = 2; 202 @Native static final int kCopyArea = 3; 203 @Native static final int kExternal = 4; 204 205 @Native static final int kLine = 5; // belongs to kPrimitive 206 @Native static final int kRect = 6; // belongs to kPrimitive 207 @Native static final int kRoundRect = 7; // belongs to kPrimitive 208 @Native static final int kOval = 8; // belongs to kPrimitive 209 @Native static final int kArc = 9; // belongs to kPrimitive 210 @Native static final int kPolygon = 10; // belongs to kPrimitive 211 @Native static final int kShape = 11; // belongs to kPrimitive 212 // static final int kImage = 12; // belongs to kImage 213 @Native static final int kString = 13; // belongs to kText 214 @Native static final int kGlyphs = 14; // belongs to kText 215 @Native static final int kUnicodes = 15; // belongs to kText 216 // static final int kCopyArea = 16; // belongs to kCopyArea 217 // static final int kExternal = 17; // belongs to kExternal 218 219 @Native static final int kCommonParameterCount = 1 + 1 + 4 + 4; // type + change flags + color info (type(1) align(1) and 220 // value(2)) + parameters ((x1, y1, x2, y2) OR (x, y, w, h)) 221 @Native static final int kLineParametersCount = kCommonParameterCount; // kCommonParameterCount 222 @Native static final int kRectParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill 223 @Native static final int kRoundRectParametersCount = kCommonParameterCount + 2 + 1; // kCommonParameterCount + arcW + arcH + 224 // isfill 225 @Native static final int kOvalParametersCount = kCommonParameterCount + 1; // kCommonParameterCount + isfill 226 @Native static final int kArcParametersCount = kCommonParameterCount + 2 + 1 + 1;// kCommonParameterCount + startAngle + 227 // arcAngle + isfill + type 228 @Native static final int kPolygonParametersCount = 0; // not supported 229 @Native static final int kShapeParametersCount = 0; // not supported 230 @Native static final int kImageParametersCount = kCommonParameterCount + 2 + 2 + 4 + 4; // flip horz vert + w&h + src + dst 231 @Native static final int kStringParametersCount = 0; // not supported 232 @Native static final int kGlyphsParametersCount = 0; // not supported 233 @Native static final int kUnicodesParametersCount = 0; // not supported 234 @Native static final int kPixelParametersCount = 0; // not supported 235 @Native static final int kExternalParametersCount = 0; // not supported 236 237 // for intParameters 238 // states info 239 @Native static final int kChangeFlagIndex = 0; // kBoundsChangedBit | .. | kFontChangedBit 240 // bounds info 241 @Native static final int kBoundsXIndex = 1; 242 @Native static final int kBoundsYIndex = 2; 243 @Native static final int kBoundsWidthIndex = 3; 244 @Native static final int kBoundsHeightIndex = 4; 245 // clip info 246 @Native static final int kClipStateIndex = 5; 247 @Native static final int kClipNumTypesIndex = 6; 248 @Native static final int kClipNumCoordsIndex = 7; 249 @Native static final int kClipWindingRuleIndex = 8; 250 @Native static final int kClipXIndex = 9; 251 @Native static final int kClipYIndex = 10; 252 @Native static final int kClipWidthIndex = 11; 253 @Native static final int kClipHeightIndex = 12; 254 // ctm info 255 @Native static final int kCTMaIndex = 13; 256 @Native static final int kCTMbIndex = 14; 257 @Native static final int kCTMcIndex = 15; 258 @Native static final int kCTMdIndex = 16; 259 @Native static final int kCTMtxIndex = 17; 260 @Native static final int kCTMtyIndex = 18; 261 // color info 262 @Native static final int kColorStateIndex = 19; // kColorSimple or kColorGradient or kColorTexture 263 @Native static final int kColorRGBValueIndex = 20; // if kColorSimple 264 @Native static final int kColorIndexValueIndex = 21; // if kColorSystem 265 @Native static final int kColorPointerIndex = 22; // 266 @Native static final int kColorPointerIndex2 = 23; // 267 @Native static final int kColorRGBValue1Index = 24; // if kColorGradient 268 @Native static final int kColorWidthIndex = 25; // if kColorTexture 269 @Native static final int kColorRGBValue2Index = 26; // if kColorGradient 270 @Native static final int kColorHeightIndex = 27; // if kColorTexture 271 @Native static final int kColorIsCyclicIndex = 28; // if kColorGradient (kColorNonCyclic or kColorCyclic) 272 @Native static final int kColorx1Index = 29; 273 @Native static final int kColortxIndex = 30; 274 @Native static final int kColory1Index = 31; 275 @Native static final int kColortyIndex = 32; 276 @Native static final int kColorx2Index = 33; 277 @Native static final int kColorsxIndex = 34; 278 @Native static final int kColory2Index = 35; 279 @Native static final int kColorsyIndex = 36; 280 // composite info 281 @Native static final int kCompositeRuleIndex = 37; // kCGCompositeClear or ... or kCGCompositeXor 282 @Native static final int kCompositeValueIndex = 38; 283 // stroke info 284 @Native static final int kStrokeJoinIndex = 39; // see BasicStroke.java 285 @Native static final int kStrokeCapIndex = 40; // see BasicStroke.java 286 @Native static final int kStrokeWidthIndex = 41; 287 @Native static final int kStrokeDashPhaseIndex = 42; 288 @Native static final int kStrokeLimitIndex = 43; 289 // hints info 290 @Native static final int kHintsAntialiasIndex = 44; 291 @Native static final int kHintsTextAntialiasIndex = 45; 292 @Native static final int kHintsFractionalMetricsIndex = 46; 293 @Native static final int kHintsRenderingIndex = 47; 294 @Native static final int kHintsInterpolationIndex = 48; 295 // live resizing info 296 @Native static final int kCanDrawDuringLiveResizeIndex = 49; 297 298 @Native static final int kSizeOfParameters = kCanDrawDuringLiveResizeIndex + 1; 299 300 // for objectParameters 301 @Native static final int kClipCoordinatesIndex = 0; 302 @Native static final int kClipTypesIndex = 1; 303 @Native static final int kTextureImageIndex = 2; 304 @Native static final int kStrokeDashArrayIndex = 3; 305 @Native static final int kFontIndex = 4; 306 @Native static final int kFontPaintIndex = 5; 307 308 // possible state changes 309 @Native static final int kBoundsChangedBit = 1 << 0; 310 @Native static final int kBoundsNotChangedBit = ~kBoundsChangedBit; 311 @Native static final int kClipChangedBit = 1 << 1; 312 @Native static final int kClipNotChangedBit = ~kClipChangedBit; 313 @Native static final int kCTMChangedBit = 1 << 2; 314 @Native static final int kCTMNotChangedBit = ~kCTMChangedBit; 315 @Native static final int kColorChangedBit = 1 << 3; 316 @Native static final int kColorNotChangedBit = ~kColorChangedBit; 317 @Native static final int kCompositeChangedBit = 1 << 4; 318 @Native static final int kCompositeNotChangedBit = ~kCompositeChangedBit; 319 @Native static final int kStrokeChangedBit = 1 << 5; 320 @Native static final int kStrokeNotChangedBit = ~kStrokeChangedBit; 321 @Native static final int kHintsChangedBit = 1 << 6; 322 @Native static final int kHintsNotChangedBit = ~kHintsChangedBit; 323 @Native static final int kFontChangedBit = 1 << 7; 324 @Native static final int kFontNotChangedBit = ~kFontChangedBit; 325 @Native static final int kEverythingChangedFlag = 0xffffffff; 326 327 // possible color states 328 @Native static final int kColorSimple = 0; 329 @Native static final int kColorSystem = 1; 330 @Native static final int kColorGradient = 2; 331 @Native static final int kColorTexture = 3; 332 333 // possible gradient color states 334 @Native static final int kColorNonCyclic = 0; 335 @Native static final int kColorCyclic = 1; 336 337 // possible clip states 338 @Native static final int kClipRect = 0; 339 @Native static final int kClipShape = 1; 340 341 static int getRendererTypeForPrimitive(int primitiveType) { 342 switch (primitiveType) { 343 case kImage: 344 return kImage; 345 case kCopyArea: 346 return kCopyArea; 347 case kExternal: 348 return kExternal; 349 case kString: 350 case kGlyphs: 351 case kUnicodes: 352 return kText; 353 default: 354 return kPrimitive; 355 } 356 } 357 358 int fChangeFlag; 359 protected ByteBuffer fGraphicsStates = null; |