author | pchelko |
Fri, 14 Mar 2014 17:48:28 +0400 | |
changeset 23652 | 11515e3c3f85 |
parent 23651 | e41298d0da2f |
child 24137 | b4066d0e2bca |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23319
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
12047 | 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 |
*/ |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
25 |
#import "jni_util.h" |
12047 | 26 |
|
27 |
#import <Cocoa/Cocoa.h> |
|
28 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
29 |
||
30 |
#import "GeomUtilities.h" |
|
31 |
#import "ThreadUtilities.h" |
|
32 |
||
33 |
#import "sun_lwawt_macosx_CImage.h" |
|
34 |
||
35 |
||
36 |
static void CImage_CopyArrayIntoNSImageRep |
|
37 |
(jint *srcPixels, jint *dstPixels, int width, int height) |
|
38 |
{ |
|
39 |
int x, y; |
|
40 |
// TODO: test this on big endian systems (not sure if its correct)... |
|
41 |
for (y = 0; y < height; y++) { |
|
42 |
for (x = 0; x < width; x++) { |
|
43 |
jint pix = srcPixels[x]; |
|
44 |
jint a = (pix >> 24) & 0xff; |
|
45 |
jint r = (pix >> 16) & 0xff; |
|
46 |
jint g = (pix >> 8) & 0xff; |
|
47 |
jint b = (pix ) & 0xff; |
|
48 |
dstPixels[x] = (b << 24) | (g << 16) | (r << 8) | a; |
|
49 |
} |
|
50 |
srcPixels += width; // TODO: use explicit scanStride |
|
51 |
dstPixels += width; |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
static void CImage_CopyNSImageIntoArray |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
56 |
(NSImage *srcImage, jint *dstPixels, NSRect fromRect, NSRect toRect) |
12047 | 57 |
{ |
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
58 |
int width = toRect.size.width; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
59 |
int height = toRect.size.height; |
12047 | 60 |
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); |
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
61 |
CGContextRef cgRef = CGBitmapContextCreate(dstPixels, width, height, |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
62 |
8, width * 4, colorspace, |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
63 |
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host); |
12047 | 64 |
CGColorSpaceRelease(colorspace); |
65 |
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgRef flipped:NO]; |
|
66 |
CGContextRelease(cgRef); |
|
67 |
NSGraphicsContext *oldContext = [[NSGraphicsContext currentContext] retain]; |
|
68 |
[NSGraphicsContext setCurrentContext:context]; |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
69 |
[srcImage drawInRect:toRect |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
70 |
fromRect:fromRect |
12047 | 71 |
operation:NSCompositeSourceOver |
72 |
fraction:1.0]; |
|
73 |
[NSGraphicsContext setCurrentContext:oldContext]; |
|
74 |
[oldContext release]; |
|
75 |
} |
|
76 |
||
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
77 |
static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height) |
12047 | 78 |
{ |
79 |
NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL |
|
80 |
pixelsWide:width |
|
81 |
pixelsHigh:height |
|
82 |
bitsPerSample:8 |
|
83 |
samplesPerPixel:4 |
|
84 |
hasAlpha:YES |
|
85 |
isPlanar:NO |
|
86 |
colorSpaceName:NSDeviceRGBColorSpace |
|
87 |
bitmapFormat:NSAlphaFirstBitmapFormat |
|
88 |
bytesPerRow:width*4 // TODO: use explicit scanStride |
|
89 |
bitsPerPixel:32]; |
|
90 |
||
91 |
jint *imgData = (jint *)[imageRep bitmapData]; |
|
92 |
if (imgData == NULL) return 0L; |
|
93 |
||
94 |
jint *src = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL); |
|
95 |
if (src == NULL) return 0L; |
|
96 |
||
97 |
CImage_CopyArrayIntoNSImageRep(src, imgData, width, height); |
|
98 |
||
99 |
(*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT); |
|
100 |
||
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
101 |
return imageRep; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
102 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
103 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
104 |
/* |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
105 |
* Class: sun_lwawt_macosx_CImage |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
106 |
* Method: nativeCreateNSImageFromArray |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
107 |
* Signature: ([III)J |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
108 |
*/ |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
109 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArray |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
110 |
(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height) |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
111 |
{ |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
112 |
jlong result = 0L; |
12047 | 113 |
|
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
114 |
JNF_COCOA_ENTER(env); |
23652
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
115 |
|
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
116 |
NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
117 |
if (imageRep) { |
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
118 |
NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain]; |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
119 |
[nsImage addRepresentation:imageRep]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
120 |
[imageRep release]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
121 |
result = ptr_to_jlong(nsImage); |
12047 | 122 |
} |
123 |
||
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
124 |
JNF_COCOA_EXIT(env); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
125 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
126 |
return result; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
127 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
128 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
129 |
/* |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
130 |
* Class: sun_lwawt_macosx_CImage |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
131 |
* Method: nativeCreateNSImageFromArrays |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
132 |
* Signature: ([[I[I[I)J |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
133 |
*/ |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
134 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArrays |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
135 |
(JNIEnv *env, jclass klass, jobjectArray buffers, jintArray widths, jintArray heights) |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
136 |
{ |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
137 |
jlong result = 0L; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
138 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
139 |
JNF_COCOA_ENTER(env); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
140 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
141 |
jsize num = (*env)->GetArrayLength(env, buffers); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
142 |
NSMutableArray * reps = [NSMutableArray arrayWithCapacity: num]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
143 |
|
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
144 |
jint * ws = (*env)->GetIntArrayElements(env, widths, NULL); |
23319
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
145 |
if (ws != NULL) { |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
146 |
jint * hs = (*env)->GetIntArrayElements(env, heights, NULL); |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
147 |
if (hs != NULL) { |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
148 |
jsize i; |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
149 |
for (i = 0; i < num; i++) { |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
150 |
jintArray buffer = (*env)->GetObjectArrayElement(env, buffers, i); |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
151 |
|
23319
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
152 |
NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, ws[i], hs[i]); |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
153 |
if (imageRep) { |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
154 |
[reps addObject: imageRep]; |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
155 |
} |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
156 |
} |
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
157 |
|
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
158 |
(*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT); |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
159 |
} |
23319
b6523289a3b7
8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents:
23257
diff
changeset
|
160 |
(*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT); |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
161 |
} |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
162 |
if ([reps count]) { |
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
163 |
NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(0, 0)] retain]; |
12403
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
164 |
[nsImage addRepresentations: reps]; |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
165 |
result = ptr_to_jlong(nsImage); |
50b3f2982b59
7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents:
12047
diff
changeset
|
166 |
} |
12047 | 167 |
|
168 |
JNF_COCOA_EXIT(env); |
|
169 |
||
170 |
return result; |
|
171 |
} |
|
172 |
||
173 |
/* |
|
174 |
* Class: sun_lwawt_macosx_CImage |
|
175 |
* Method: nativeCreateNSImageFromIconSelector |
|
176 |
* Signature: (I)J |
|
177 |
*/ |
|
178 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromIconSelector |
|
179 |
(JNIEnv *env, jclass klass, jint selector) |
|
180 |
{ |
|
181 |
NSImage *image = nil; |
|
182 |
||
183 |
JNF_COCOA_ENTER(env); |
|
184 |
||
185 |
IconRef iconRef; |
|
186 |
if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) { |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
187 |
image = [[[NSImage alloc] initWithIconRef:iconRef] retain]; |
12047 | 188 |
ReleaseIconRef(iconRef); |
189 |
} |
|
190 |
||
191 |
JNF_COCOA_EXIT(env); |
|
192 |
||
193 |
return ptr_to_jlong(image); |
|
194 |
} |
|
195 |
||
196 |
/* |
|
197 |
* Class: sun_lwawt_macosx_CImage |
|
198 |
* Method: nativeCreateNSImageFromFileContents |
|
199 |
* Signature: (Ljava/lang/String;)J |
|
200 |
*/ |
|
201 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromFileContents |
|
202 |
(JNIEnv *env, jclass klass, jstring file) |
|
203 |
{ |
|
204 |
NSImage *image = nil; |
|
205 |
||
206 |
JNF_COCOA_ENTER(env); |
|
207 |
||
208 |
NSString *path = JNFNormalizedNSStringForPath(env, file); |
|
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
209 |
image = [[[NSImage alloc] initByReferencingFile:path] retain]; |
12047 | 210 |
|
211 |
JNF_COCOA_EXIT(env); |
|
212 |
||
213 |
return ptr_to_jlong(image); |
|
214 |
} |
|
215 |
||
216 |
/* |
|
217 |
* Class: sun_lwawt_macosx_CImage |
|
218 |
* Method: nativeCreateNSImageOfFileFromLaunchServices |
|
219 |
* Signature: (Ljava/lang/String;)J |
|
220 |
*/ |
|
221 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageOfFileFromLaunchServices |
|
222 |
(JNIEnv *env, jclass klass, jstring file) |
|
223 |
{ |
|
224 |
__block NSImage *image = nil; |
|
225 |
||
226 |
JNF_COCOA_ENTER(env); |
|
227 |
||
228 |
NSString *path = JNFNormalizedNSStringForPath(env, file); |
|
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
12654
diff
changeset
|
229 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
230 |
image = [[[NSWorkspace sharedWorkspace] iconForFile:path] retain]; |
12047 | 231 |
[image setScalesWhenResized:TRUE]; |
232 |
}]; |
|
233 |
||
234 |
JNF_COCOA_EXIT(env); |
|
235 |
||
236 |
return ptr_to_jlong(image); |
|
237 |
} |
|
238 |
||
239 |
/* |
|
240 |
* Class: sun_lwawt_macosx_CImage |
|
241 |
* Method: nativeCreateNSImageFromImageName |
|
242 |
* Signature: (Ljava/lang/String;)J |
|
243 |
*/ |
|
244 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromImageName |
|
245 |
(JNIEnv *env, jclass klass, jstring name) |
|
246 |
{ |
|
247 |
NSImage *image = nil; |
|
248 |
||
249 |
JNF_COCOA_ENTER(env); |
|
250 |
||
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
251 |
image = [[NSImage imageNamed:JNFJavaToNSString(env, name)] retain]; |
12047 | 252 |
|
253 |
JNF_COCOA_EXIT(env); |
|
254 |
||
255 |
return ptr_to_jlong(image); |
|
256 |
} |
|
257 |
||
258 |
/* |
|
259 |
* Class: sun_lwawt_macosx_CImage |
|
260 |
* Method: nativeCopyNSImageIntoArray |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
261 |
* Signature: (J[IIIII)V |
12047 | 262 |
*/ |
263 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeCopyNSImageIntoArray |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
264 |
(JNIEnv *env, jclass klass, jlong nsImgPtr, jintArray buffer, jint sw, jint sh, |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
265 |
jint dw, jint dh) |
12047 | 266 |
{ |
267 |
JNF_COCOA_ENTER(env); |
|
268 |
||
269 |
NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr); |
|
270 |
jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL); |
|
271 |
if (dst) { |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
272 |
NSRect fromRect = NSMakeRect(0, 0, sw, sh); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
273 |
NSRect toRect = NSMakeRect(0, 0, dw, dh); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
274 |
CImage_CopyNSImageIntoArray(img, dst, fromRect, toRect); |
12047 | 275 |
(*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT); |
276 |
} |
|
277 |
||
278 |
JNF_COCOA_EXIT(env); |
|
279 |
} |
|
280 |
||
281 |
/* |
|
282 |
* Class: sun_lwawt_macosx_CImage |
|
283 |
* Method: nativeGetNSImageSize |
|
284 |
* Signature: (J)Ljava/awt/geom/Dimension2D; |
|
285 |
*/ |
|
286 |
JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CImage_nativeGetNSImageSize |
|
287 |
(JNIEnv *env, jclass klass, jlong nsImgPtr) |
|
288 |
{ |
|
289 |
jobject size = NULL; |
|
290 |
||
291 |
JNF_COCOA_ENTER(env); |
|
292 |
||
293 |
size = NSToJavaSize(env, [(NSImage *)jlong_to_ptr(nsImgPtr) size]); |
|
294 |
||
295 |
JNF_COCOA_EXIT(env); |
|
296 |
||
297 |
return size; |
|
298 |
} |
|
299 |
||
300 |
/* |
|
301 |
* Class: sun_lwawt_macosx_CImage |
|
302 |
* Method: nativeSetNSImageSize |
|
303 |
* Signature: (JDD)V |
|
304 |
*/ |
|
305 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeSetNSImageSize |
|
306 |
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h) |
|
307 |
{ |
|
308 |
if (!image) return; |
|
309 |
NSImage *i = (NSImage *)jlong_to_ptr(image); |
|
310 |
||
311 |
JNF_COCOA_ENTER(env); |
|
312 |
||
313 |
[i setScalesWhenResized:TRUE]; |
|
314 |
[i setSize:NSMakeSize(w, h)]; |
|
315 |
||
316 |
JNF_COCOA_EXIT(env); |
|
317 |
} |
|
23257 | 318 |
|
319 |
/* |
|
320 |
* Class: sun_lwawt_macosx_CImage |
|
321 |
* Method: nativeResizeNSImageRepresentations |
|
322 |
* Signature: (JDD)V |
|
323 |
*/ |
|
324 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeResizeNSImageRepresentations |
|
325 |
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h) |
|
326 |
{ |
|
327 |
if (!image) return; |
|
328 |
NSImage *i = (NSImage *)jlong_to_ptr(image); |
|
329 |
||
330 |
JNF_COCOA_ENTER(env); |
|
331 |
||
332 |
NSImageRep *imageRep = nil; |
|
333 |
NSArray *imageRepresentations = [i representations]; |
|
334 |
NSEnumerator *imageEnumerator = [imageRepresentations objectEnumerator]; |
|
335 |
while ((imageRep = [imageEnumerator nextObject]) != nil) { |
|
336 |
[imageRep setSize:NSMakeSize(w, h)]; |
|
337 |
} |
|
338 |
||
339 |
JNF_COCOA_EXIT(env); |
|
340 |
} |
|
23615
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
341 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
342 |
NSComparisonResult getOrder(BOOL order){ |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
343 |
return (NSComparisonResult) (order ? NSOrderedAscending : NSOrderedDescending); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
344 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
345 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
346 |
/* |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
347 |
* Class: sun_lwawt_macosx_CImage |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
348 |
* Method: nativeGetNSImageRepresentationsCount |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
349 |
* Signature: (JDD)[Ljava/awt/geom/Dimension2D; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
350 |
*/ |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
351 |
JNIEXPORT jobjectArray JNICALL |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
352 |
Java_sun_lwawt_macosx_CImage_nativeGetNSImageRepresentationSizes |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
353 |
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h) |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
354 |
{ |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
355 |
if (!image) return NULL; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
356 |
jobjectArray jreturnArray = NULL; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
357 |
NSImage *img = (NSImage *)jlong_to_ptr(image); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
358 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
359 |
JNF_COCOA_ENTER(env); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
360 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
361 |
NSArray *imageRepresentations = [img representations]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
362 |
if([imageRepresentations count] == 0){ |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
363 |
return NULL; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
364 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
365 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
366 |
NSArray *sortedImageRepresentations = [imageRepresentations |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
367 |
sortedArrayUsingComparator: ^(id obj1, id obj2) { |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
368 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
369 |
NSImageRep *imageRep1 = (NSImageRep *) obj1; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
370 |
NSImageRep *imageRep2 = (NSImageRep *) obj2; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
371 |
NSSize size1 = [imageRep1 size]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
372 |
NSSize size2 = [imageRep2 size]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
373 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
374 |
if (NSEqualSizes(size1, size2)) { |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
375 |
return getOrder([imageRep1 pixelsWide] <= [imageRep2 pixelsWide] && |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
376 |
[imageRep1 pixelsHigh] <= [imageRep2 pixelsHigh]); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
377 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
378 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
379 |
return getOrder(size1.width <= size2.width && size1.height <= size2.height); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
380 |
}]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
381 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
382 |
NSMutableArray *sortedPixelSizes = [[NSMutableArray alloc] init]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
383 |
NSSize lastSize = [[sortedImageRepresentations lastObject] size]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
384 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
385 |
NSUInteger i = [sortedImageRepresentations indexOfObjectPassingTest: |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
386 |
^BOOL(id obj, NSUInteger idx, BOOL *stop) { |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
387 |
NSSize imageRepSize = [obj size]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
388 |
return (w <= imageRepSize.width && h <= imageRepSize.height) |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
389 |
|| NSEqualSizes(imageRepSize, lastSize); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
390 |
}]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
391 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
392 |
NSUInteger count = [sortedImageRepresentations count]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
393 |
i = (i == NSNotFound) ? count - 1 : i; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
394 |
NSSize bestFitSize = [[sortedImageRepresentations objectAtIndex: i] size]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
395 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
396 |
for(; i < count; i++){ |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
397 |
NSImageRep *imageRep = [sortedImageRepresentations objectAtIndex: i]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
398 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
399 |
if (!NSEqualSizes([imageRep size], bestFitSize)) { |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
400 |
break; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
401 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
402 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
403 |
NSSize pixelSize = NSMakeSize( |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
404 |
[imageRep pixelsWide], [imageRep pixelsHigh]); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
405 |
[sortedPixelSizes addObject: [NSValue valueWithSize: pixelSize]]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
406 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
407 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
408 |
count = [sortedPixelSizes count]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
409 |
static JNF_CLASS_CACHE(jc_Dimension, "java/awt/Dimension"); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
410 |
jreturnArray = JNFNewObjectArray(env, &jc_Dimension, count); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
411 |
CHECK_NULL_RETURN(jreturnArray, NULL); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
412 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
413 |
for(i = 0; i < count; i++){ |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
414 |
NSSize pixelSize = [[sortedPixelSizes objectAtIndex: i] sizeValue]; |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
415 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
416 |
(*env)->SetObjectArrayElement(env, jreturnArray, i, |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
417 |
NSToJavaSize(env, pixelSize)); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
418 |
JNU_CHECK_EXCEPTION_RETURN(env, NULL); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
419 |
} |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
420 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
421 |
JNF_COCOA_EXIT(env); |
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
422 |
|
a0825e77bfad
8033534: [macosx] Get MultiResolution image from native system
alexsch
parents:
23328
diff
changeset
|
423 |
return jreturnArray; |
23651
e41298d0da2f
8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents:
23615
diff
changeset
|
424 |
} |
23652
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
425 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
426 |
/* |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
427 |
* Class: sun_lwawt_macosx_CImage |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
428 |
* Method: nativeGetPlatformImageBytes |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
429 |
* Signature: ([III)[B |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
430 |
*/ |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
431 |
JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CImage_nativeGetPlatformImageBytes |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
432 |
(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height) |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
433 |
{ |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
434 |
jbyteArray result = 0L; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
435 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
436 |
JNF_COCOA_ENTER(env); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
437 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
438 |
NSBitmapImageRep* imageRep = [CImage_CreateImageRep(env, buffer, width, height) autorelease]; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
439 |
if (imageRep) { |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
440 |
NSData *tiffImage = [imageRep TIFFRepresentation]; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
441 |
jsize tiffSize = (jsize)[tiffImage length]; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
442 |
result = (*env)->NewByteArray(env, tiffSize); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
443 |
CHECK_NULL_RETURN(result, nil); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
444 |
jbyte *tiffData = (jbyte *)(*env)->GetPrimitiveArrayCritical(env, result, 0); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
445 |
CHECK_NULL_RETURN(tiffData, nil); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
446 |
[tiffImage getBytes:tiffData]; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
447 |
(*env)->ReleasePrimitiveArrayCritical(env, result, tiffData, 0); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
448 |
} |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
449 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
450 |
JNF_COCOA_EXIT(env); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
451 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
452 |
return result; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
453 |
} |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
454 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
455 |
/* |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
456 |
* Class: sun_lwawt_macosx_CImage |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
457 |
* Method: nativeCreateNSImageFromBytes |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
458 |
* Signature: ([B)J |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
459 |
*/ |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
460 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromBytes |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
461 |
(JNIEnv *env, jclass klass, jbyteArray sourceData) |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
462 |
{ |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
463 |
jlong result = 0L; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
464 |
CHECK_NULL_RETURN(sourceData, 0L); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
465 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
466 |
JNF_COCOA_ENTER(env); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
467 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
468 |
jsize sourceSize = (*env)->GetArrayLength(env, sourceData); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
469 |
if (sourceSize == 0) return 0L; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
470 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
471 |
jbyte *sourceBytes = (*env)->GetPrimitiveArrayCritical(env, sourceData, NULL); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
472 |
CHECK_NULL_RETURN(sourceBytes, 0L); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
473 |
NSData *rawData = [NSData dataWithBytes:sourceBytes length:sourceSize]; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
474 |
NSImage *newImage = [[NSImage alloc] initWithData:rawData]; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
475 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
476 |
(*env)->ReleasePrimitiveArrayCritical(env, sourceData, sourceBytes, JNI_ABORT); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
477 |
CHECK_NULL_RETURN(newImage, 0L); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
478 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
479 |
result = ptr_to_jlong(newImage); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
480 |
JNF_COCOA_EXIT(env); |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
481 |
|
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
482 |
return result; |
11515e3c3f85
8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents:
23651
diff
changeset
|
483 |
} |