changeset 12406:893feff4c809

8176287: [macosx] The print test crashed with Nimbus L&F Reviewed-by: serb, prr
author psadhukhan
date Thu, 30 Mar 2017 06:05:16 -0700
parents 685eacce7d97
children b281494e3031
files src/macosx/native/sun/awt/QuartzSurfaceData.m
diffstat 1 files changed, 15 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/native/sun/awt/QuartzSurfaceData.m	Tue Mar 28 12:30:30 2017 -0700
+++ b/src/macosx/native/sun/awt/QuartzSurfaceData.m	Thu Mar 30 06:05:16 2017 -0700
@@ -72,7 +72,7 @@
 
 // given a UInt32 color, it tries to find that find the corresponding CGColorRef in the hash cache. If the CGColorRef
 // doesn't exist or there is a collision, it creates a new one CGColorRef and put's in the cache. Then,
-// it sets with current fill/stroke color for the the CGContext passed in (qsdo->cgRef).
+// it sets with current fill/stroke color for the CGContext passed in (qsdo->cgRef).
 void setCachedColor(QuartzSDOps *qsdo, UInt32 color)
 {
     static const CGFloat kColorConversionMultiplier = 1.0f/255.0f;
@@ -286,26 +286,19 @@
 
     for (i = 0; i < num_locations; i++) {
         locations[i] = gradientInfo->fractionsdata[i];
-//fprintf(stderr, "locations[%d] %f\n", i, locations[i]);
     }
     for (i = 0; i < component_size; i++) {
         components[i] = gradientInfo->colordata[i];
-//fprintf(stderr, "components[%d] %f, gradientInfo->colordata[%d] %f\n",
-//                  i, components[i], i, gradientInfo->colordata[i]);
     } 
     CGContextSaveGState(cgRef);
     gradient = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations);
-//fprintf(stderr, "gradientInfo->start.x %f, gradientInfo->start.y %f\n", 
-//                 gradientInfo->start.x, gradientInfo->start.y);
-//fprintf(stderr, "gradientInfo->end.x %f, gradientInfo->end.y %f\n", 
-//                 gradientInfo->end.x, gradientInfo->end.y);
     if (qsdo->isEvenOddFill) {
         CGContextEOClip(cgRef);
     } else {
         CGContextClip(cgRef);
     }
     CGContextDrawLinearGradient(cgRef, gradient, gradientInfo->start, gradientInfo->end, kCGGradientDrawsAfterEndLocation);    
-    
+
     CGContextRestoreGState(cgRef);
     CGColorSpaceRelease(colorspace);
     CGGradientRelease(gradient);
@@ -334,25 +327,17 @@
 
     for (i = 0; i < num_locations; i++) {
         locations[i] = gradientInfo->fractionsdata[i];
-//fprintf(stderr, "locations[%d] %f\n", i, locations[i]);
     }
     for (i = 0; i < component_size; i++) {
         components[i] = gradientInfo->colordata[i];
-//fprintf(stderr, "components[%d] %f, gradientInfo->colordata[%d] %f\n",
-//                  i, components[i], i, gradientInfo->colordata[i]);
     } 
     CGContextSaveGState(cgRef);
     gradient = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations);
-//fprintf(stderr, "gradientInfo->start.x %f, gradientInfo->start.y %f\n", 
-//                 gradientInfo->start.x, gradientInfo->start.y);
-//fprintf(stderr, "gradientInfo->end.x %f, gradientInfo->end.y %f\n", 
-//                 gradientInfo->end.x, gradientInfo->end.y);
     if (qsdo->isEvenOddFill) {
         CGContextEOClip(cgRef);
     } else {
         CGContextClip(cgRef);
     }
-//fprintf(stderr, "gradientInfo->startRadius %f, gradientInfo->endRadius %f\n",startRadius,endRadius);
     CGContextDrawRadialGradient(cgRef, gradient, gradientInfo->start, 0, gradientInfo->end, endRadius, kCGGradientDrawsAfterEndLocation);    
     
     CGContextRestoreGState(cgRef);
@@ -944,55 +929,41 @@
     if (colorArray != NULL)
     {
         jint length = (*env)->GetArrayLength(env, colorArray);
-//fprintf(stderr, "length %d\n", length);
 
         jint* jcolorData = (jint*)(*env)->GetPrimitiveArrayCritical(env, colorArray, NULL);
-        CGFloat* colors= (CGFloat*)calloc(0, sizeof(CGFloat)*length);
-        int i = 0;
+        qsdo->gradientInfo->colordata = (CGFloat*)malloc(sizeof(CGFloat)*4*length);
+        memset(qsdo->gradientInfo->colordata, 0, sizeof(CGFloat)*4*length);
         if (jcolorData != NULL)
         {
-            jint ival;
-            for (ival=0; ival<length; ival++)
+            int i;
+            for (i=0; i<length; i++)
             {
-                colors[ival] = (CGFloat)jcolorData[ival];
+                qsdo->gradientInfo->colordata[i*4] = ((jcolorData[i]>>16)&0xff)*kColorConversionMultiplier;
+
+                qsdo->gradientInfo->colordata[i*4+1] = ((jcolorData[i]>>8)&0xff)*kColorConversionMultiplier;
+
+                qsdo->gradientInfo->colordata[i*4+2] = ((jcolorData[i]>>0)&0xff)*kColorConversionMultiplier;
+
+                qsdo->gradientInfo->colordata[i*4+3] = ((jcolorData[i]>>24)&0xff)*kColorConversionMultiplier;
             }
         }
         (*env)->ReleasePrimitiveArrayCritical(env, colorArray, jcolorData, 0);
-        qsdo->gradientInfo->colordata = (CGFloat*)calloc(0, sizeof(CGFloat)*4*length);
-        for (i = 0; i < length; i++) 
-        {
-            jint c1 = colors[i];
-//fprintf(stderr, "c1 %x\n", c1);
-            qsdo->gradientInfo->colordata[i*4] = ((c1>>16)&0xff)*kColorConversionMultiplier;
-//fprintf(stderr, "qsdo->gradientInfo->colordata[%d] %f\n", i*4, qsdo->gradientInfo->colordata[i*4]);
-
-            qsdo->gradientInfo->colordata[i*4+1] = ((c1>>8)&0xff)*kColorConversionMultiplier;
-//fprintf(stderr, "qsdo->gradientInfo->colordata[%d] %f\n", i*4+1, qsdo->gradientInfo->colordata[i*4+1]);
-
-            qsdo->gradientInfo->colordata[i*4+2] = ((c1>>0)&0xff)*kColorConversionMultiplier;
-//fprintf(stderr, "qsdo->gradientInfo->colordata[%d] %f\n", i*4+2, qsdo->gradientInfo->colordata[i*4+2]);
-
-            qsdo->gradientInfo->colordata[i*4+3] = ((c1>>24)&0xff)*kColorConversionMultiplier;
-//fprintf(stderr, "qsdo->gradientInfo->colordata[%d] %f\n", i*4+3, qsdo->gradientInfo->colordata[i*4+3]);
-        }
-        free(colors);
     }
     jobject fractionsArray  = ((*env)->GetObjectArrayElement(env, qsdo->javaGraphicsStatesObjects, sun_java2d_OSXSurfaceData_kFractionsArrayIndex)); 
     if (fractionsArray != NULL)
     {
         jint length = (*env)->GetArrayLength(env, fractionsArray);
-//fprintf(stderr, "fractions length %d\n", length);
         qsdo->gradientInfo->fractionsLength = length;
 
         jfloat* jfractionsData = (jfloat*)(*env)->GetPrimitiveArrayCritical(env, fractionsArray, NULL);
         if (jfractionsData != NULL)
         {
+            int i;
             qsdo->gradientInfo->fractionsdata = (CGFloat *)malloc(sizeof(CGFloat) *length);
-            jint i;
+            memset(qsdo->gradientInfo->fractionsdata, 0, sizeof(CGFloat)*length);
             for (i=0; i<length; i++)
             {
                 qsdo->gradientInfo->fractionsdata[i] = jfractionsData[i];
-//fprintf(stderr, "jfrationsData[%d] %f, qsdo->gradientInfo->fractionsdata[%d] = %f\n", i, jfractionsData[i], i, qsdo->gradientInfo->fractionsdata[i]);
             }
             (*env)->ReleasePrimitiveArrayCritical(env, fractionsArray, jfractionsData, 0);
         }