src/macosx/native/sun/awt/QuartzSurfaceData.m

Print this page




  23  * questions.
  24  */
  25 
  26 #import "QuartzSurfaceData.h"
  27 
  28 #import "java_awt_BasicStroke.h"
  29 #import "java_awt_AlphaComposite.h"
  30 #import "java_awt_geom_PathIterator.h"
  31 #import "java_awt_image_BufferedImage.h"
  32 #import "sun_awt_SunHints.h"
  33 #import "sun_java2d_CRenderer.h"
  34 #import "sun_java2d_OSXSurfaceData.h"
  35 #import "sun_lwawt_macosx_CPrinterSurfaceData.h"
  36 #import "ImageSurfaceData.h"
  37 
  38 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  39 
  40 #import <AppKit/AppKit.h>
  41 #import "ThreadUtilities.h"
  42 
  43 // private Quartz routines needed here
  44 CG_EXTERN void CGContextSetCTM(CGContextRef ref, CGAffineTransform tx);
  45 
  46 //#define DEBUG
  47 #if defined DEBUG
  48     #define PRINT(msg) {fprintf(stderr, "%s\n", msg);}
  49 #else
  50     #define PRINT(msg) {}
  51 #endif
  52 
  53 // from CGAffineTransformPrivate.h
  54 extern CGPoint CGPointApplyInverseAffineTransform(CGPoint point, CGAffineTransform t);
  55 
  56 #define kOffset (0.5f)
  57 
  58 BOOL gAdjustForJavaDrawing;
  59 
  60 #pragma mark
  61 #pragma mark --- Color Cache ---
  62 
  63 // Creating and deleting CGColorRefs can be expensive, therefore we have a color cache.
  64 // The color cache was first introduced with <rdar://problem/3923927>
  65 // With <rdar://problem/4280514>, the hashing function was improved
  66 // With <rdar://problem/4012223>, the color cache became global (per process) instead of per surface.
  67 
  68 // Must be power of 2. 1024 is the least power of 2 number that makes SwingSet2 run without any non-empty cache misses
  69 #define gColorCacheSize 1024
  70 struct _ColorCacheInfo
  71 {
  72     UInt32        keys[gColorCacheSize];
  73     CGColorRef    values[gColorCacheSize];
  74 };
  75 static struct _ColorCacheInfo colorCacheInfo;


 591         CGFloat d = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMdIndex];
 592         CGFloat tx = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMtxIndex];
 593         CGFloat ty = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMtyIndex];
 594 
 595         CGContextConcatCTM(cgRef, CGAffineTransformMake(a, b, c, d, tx, ty));
 596 
 597         if (gAdjustForJavaDrawing == YES)
 598         {
 599             // find the offsets in the device corrdinate system
 600             CGAffineTransform ctm = CGContextGetCTM(cgRef);
 601             if ((qsdo->graphicsStateInfo.ctm.a != ctm.a) ||
 602                     (qsdo->graphicsStateInfo.ctm.b != ctm.b) ||
 603                         (qsdo->graphicsStateInfo.ctm.c != ctm.c) ||
 604                             (qsdo->graphicsStateInfo.ctm.d != ctm.d))
 605             {
 606                 qsdo->graphicsStateInfo.ctm = ctm;
 607                 // In CG affine xforms y' = bx+dy+ty
 608                 // We need to flip both y coefficeints to flip the offset point into the java coordinate system.
 609                 ctm.b = -ctm.b; ctm.d = -ctm.d; ctm.tx = 0.0f; ctm.ty = 0.0f;
 610                 CGPoint offsets = {kOffset, kOffset};
 611                 offsets = CGPointApplyInverseAffineTransform(offsets, ctm);

 612                 qsdo->graphicsStateInfo.offsetX = offsets.x;
 613                 qsdo->graphicsStateInfo.offsetY = offsets.y;
 614             }
 615         }
 616         else
 617         {
 618             qsdo->graphicsStateInfo.offsetX = 0.0f;
 619             qsdo->graphicsStateInfo.offsetY = 0.0f;
 620         }
 621     }
 622 
 623 // for debugging
 624 //CGContextResetCTM(cgRef);
 625 
 626     if ((everyThingChanged == YES) || (compositeChanged == YES))
 627     {
 628         jint alphaCompositeRule = javaGraphicsStates[sun_java2d_OSXSurfaceData_kCompositeRuleIndex];
 629         CGFloat alphaCompositeValue = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCompositeValueIndex];
 630 
 631         NSCompositingOperation op;




  23  * questions.
  24  */
  25 
  26 #import "QuartzSurfaceData.h"
  27 
  28 #import "java_awt_BasicStroke.h"
  29 #import "java_awt_AlphaComposite.h"
  30 #import "java_awt_geom_PathIterator.h"
  31 #import "java_awt_image_BufferedImage.h"
  32 #import "sun_awt_SunHints.h"
  33 #import "sun_java2d_CRenderer.h"
  34 #import "sun_java2d_OSXSurfaceData.h"
  35 #import "sun_lwawt_macosx_CPrinterSurfaceData.h"
  36 #import "ImageSurfaceData.h"
  37 
  38 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  39 
  40 #import <AppKit/AppKit.h>
  41 #import "ThreadUtilities.h"
  42 



  43 //#define DEBUG
  44 #if defined DEBUG
  45     #define PRINT(msg) {fprintf(stderr, "%s\n", msg);}
  46 #else
  47     #define PRINT(msg) {}
  48 #endif
  49 



  50 #define kOffset (0.5f)
  51 
  52 BOOL gAdjustForJavaDrawing;
  53 
  54 #pragma mark
  55 #pragma mark --- Color Cache ---
  56 
  57 // Creating and deleting CGColorRefs can be expensive, therefore we have a color cache.
  58 // The color cache was first introduced with <rdar://problem/3923927>
  59 // With <rdar://problem/4280514>, the hashing function was improved
  60 // With <rdar://problem/4012223>, the color cache became global (per process) instead of per surface.
  61 
  62 // Must be power of 2. 1024 is the least power of 2 number that makes SwingSet2 run without any non-empty cache misses
  63 #define gColorCacheSize 1024
  64 struct _ColorCacheInfo
  65 {
  66     UInt32        keys[gColorCacheSize];
  67     CGColorRef    values[gColorCacheSize];
  68 };
  69 static struct _ColorCacheInfo colorCacheInfo;


 585         CGFloat d = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMdIndex];
 586         CGFloat tx = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMtxIndex];
 587         CGFloat ty = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCTMtyIndex];
 588 
 589         CGContextConcatCTM(cgRef, CGAffineTransformMake(a, b, c, d, tx, ty));
 590 
 591         if (gAdjustForJavaDrawing == YES)
 592         {
 593             // find the offsets in the device corrdinate system
 594             CGAffineTransform ctm = CGContextGetCTM(cgRef);
 595             if ((qsdo->graphicsStateInfo.ctm.a != ctm.a) ||
 596                     (qsdo->graphicsStateInfo.ctm.b != ctm.b) ||
 597                         (qsdo->graphicsStateInfo.ctm.c != ctm.c) ||
 598                             (qsdo->graphicsStateInfo.ctm.d != ctm.d))
 599             {
 600                 qsdo->graphicsStateInfo.ctm = ctm;
 601                 // In CG affine xforms y' = bx+dy+ty
 602                 // We need to flip both y coefficeints to flip the offset point into the java coordinate system.
 603                 ctm.b = -ctm.b; ctm.d = -ctm.d; ctm.tx = 0.0f; ctm.ty = 0.0f;
 604                 CGPoint offsets = {kOffset, kOffset};
 605                 CGAffineTransform inverse = CGAffineTransformInvert(ctm);
 606                 offsets = CGPointApplyAffineTransform(offsets, inverse);
 607                 qsdo->graphicsStateInfo.offsetX = offsets.x;
 608                 qsdo->graphicsStateInfo.offsetY = offsets.y;
 609             }
 610         }
 611         else
 612         {
 613             qsdo->graphicsStateInfo.offsetX = 0.0f;
 614             qsdo->graphicsStateInfo.offsetY = 0.0f;
 615         }
 616     }
 617 
 618 // for debugging
 619 //CGContextResetCTM(cgRef);
 620 
 621     if ((everyThingChanged == YES) || (compositeChanged == YES))
 622     {
 623         jint alphaCompositeRule = javaGraphicsStates[sun_java2d_OSXSurfaceData_kCompositeRuleIndex];
 624         CGFloat alphaCompositeValue = javaFloatGraphicsStates[sun_java2d_OSXSurfaceData_kCompositeValueIndex];
 625 
 626         NSCompositingOperation op;