Mercurial > hg > icedtea7-forest > jdk
changeset 9157:b86ab588efc5
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
Summary: Pass all images provided by user code to the system and let it do the right thing
Reviewed-by: art, swingler
author | anthony |
---|---|
date | Thu, 20 Apr 2017 21:23:52 +0100 |
parents | 794fa1fde9e9 |
children | d08745a5cfab |
files | src/macosx/classes/sun/lwawt/macosx/CImage.java src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/native/sun/awt/CImage.m |
diffstat | 3 files changed, 105 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CImage.java Thu Apr 20 20:28:44 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CImage.java Thu Apr 20 21:23:52 2017 +0100 @@ -29,10 +29,14 @@ import java.awt.geom.Dimension2D; import java.awt.image.*; +import java.util.Arrays; +import java.util.List; + import sun.awt.image.SunWritableRaster; public class CImage extends CFRetainedResource { private static native long nativeCreateNSImageFromArray(int[] buffer, int w, int h); + private static native long nativeCreateNSImageFromArrays(int[][] buffers, int w[], int h[]); private static native long nativeCreateNSImageFromFileContents(String file); private static native long nativeCreateNSImageOfFileFromLaunchServices(String file); private static native long nativeCreateNSImageFromImageName(String name); @@ -148,6 +152,40 @@ return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null))); } + public CImage createFromImages(List<Image> images) { + if (images == null || images.isEmpty()) { + return null; + } + + int num = images.size(); + + int[][] buffers = new int[num][]; + int[] w = new int[num]; + int[] h = new int[num]; + + num = 0; + + for (Image img : images) { + buffers[num] = imageToArray(img, true); + if (buffers[num] == null) { + // Unable to process the image + continue; + } + w[num] = img.getWidth(null); + h[num] = img.getHeight(null); + num++; + } + + if (num == 0) { + return null; + } + + return new CImage(nativeCreateNSImageFromArrays( + Arrays.copyOf(buffers, num), + Arrays.copyOf(w, num), + Arrays.copyOf(h, num))); + } + static int getSelectorAsInt(final String fromString) { final byte[] b = fromString.getBytes(); final int len = Math.min(b.length, 4);
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu Apr 20 20:28:44 2017 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu Apr 20 21:23:52 2017 +0100 @@ -885,19 +885,7 @@ if (icons == null || icons.size() == 0) { return null; } - - // Choose the best (largest) image - Image image = icons.get(0); - // Assume images are square, so check their widths only - int width = image.getWidth(null); - for (Image img : icons) { - final int w = img.getWidth(null); - if (w > width) { - image = img; - width = w; - } - } - return CImage.getCreator().createFromImage(image); + return CImage.getCreator().createFromImages(icons); } /*
--- a/src/macosx/native/sun/awt/CImage.m Thu Apr 20 20:28:44 2017 +0100 +++ b/src/macosx/native/sun/awt/CImage.m Thu Apr 20 21:23:52 2017 +0100 @@ -70,18 +70,8 @@ [oldContext release]; } -/* - * Class: sun_lwawt_macosx_CImage - * Method: nativeCreateNSImageFromArray - * Signature: ([III)J - */ -JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArray -(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height) +static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height) { - jlong result = 0L; - -JNF_COCOA_ENTER(env); - NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:width pixelsHigh:height @@ -104,10 +94,71 @@ (*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT); - NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain]; - [nsImage addRepresentation:imageRep]; - [imageRep release]; - result = ptr_to_jlong(nsImage); + return imageRep; +} + +/* + * Class: sun_lwawt_macosx_CImage + * Method: nativeCreateNSImageFromArray + * Signature: ([III)J + */ +JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArray +(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height) +{ + jlong result = 0L; + +JNF_COCOA_ENTER(env); + + NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height); + if (imageRep) { + NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain]; + [nsImage addRepresentation:imageRep]; + [imageRep release]; + result = ptr_to_jlong(nsImage); + } + +JNF_COCOA_EXIT(env); + + return result; +} + +/* + * Class: sun_lwawt_macosx_CImage + * Method: nativeCreateNSImageFromArrays + * Signature: ([[I[I[I)J + */ +JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArrays +(JNIEnv *env, jclass klass, jobjectArray buffers, jintArray widths, jintArray heights) +{ + jlong result = 0L; + +JNF_COCOA_ENTER(env); + + jsize num = (*env)->GetArrayLength(env, buffers); + NSMutableArray * reps = [NSMutableArray arrayWithCapacity: num]; + + jint * ws = (*env)->GetIntArrayElements(env, widths, NULL); + jint * hs = (*env)->GetIntArrayElements(env, heights, NULL); + + jsize i; + for (i = 0; i < num; i++) { + jintArray buffer = (*env)->GetObjectArrayElement(env, buffers, i); + + NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, ws[i], hs[i]); + if (imageRep) { + [reps addObject: imageRep]; + } + } + + (*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT); + (*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT); + + if ([reps count]) { + NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(0, 0)] retain]; + [nsImage addRepresentations: reps]; + [reps release]; + result = ptr_to_jlong(nsImage); + } JNF_COCOA_EXIT(env);