src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m
author sveerabhadra
Fri, 22 Dec 2017 11:00:06 +0530
changeset 48640 42ad9a781f51
parent 47216 71c04702a3d5
permissions -rw-r--r--
8190192: Double click on the title bar no longer repositions the window Reviewed-by: serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
23615
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
    25
#import "jni_util.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#import "GeomUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
#import "sun_lwawt_macosx_CImage.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
static void CImage_CopyArrayIntoNSImageRep
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
(jint *srcPixels, jint *dstPixels, int width, int height)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
    int x, y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
    // TODO: test this on big endian systems (not sure if its correct)...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
    for (y = 0; y < height; y++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
        for (x = 0; x < width; x++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
            jint pix = srcPixels[x];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
            jint a = (pix >> 24) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
            jint r = (pix >> 16) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
            jint g = (pix >>  8) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
            jint b = (pix      ) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
            dstPixels[x] = (b << 24) | (g << 16) | (r << 8) | a;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
        srcPixels += width; // TODO: use explicit scanStride
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
        dstPixels += width;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    CGColorSpaceRelease(colorspace);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
    NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgRef flipped:NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
    CGContextRelease(cgRef);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    NSGraphicsContext *oldContext = [[NSGraphicsContext currentContext] retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
               operation:NSCompositeSourceOver
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
                fraction:1.0];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    [NSGraphicsContext setCurrentContext:oldContext];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    [oldContext release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
{
24554
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    79
    NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    80
                                                                          pixelsWide:width
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    81
                                                                          pixelsHigh:height
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    82
                                                                       bitsPerSample:8
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    83
                                                                     samplesPerPixel:4
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    84
                                                                            hasAlpha:YES
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    85
                                                                            isPlanar:NO
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    86
                                                                      colorSpaceName:NSDeviceRGBColorSpace
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    87
                                                                        bitmapFormat:NSAlphaFirstBitmapFormat
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    88
                                                                         bytesPerRow:width*4 // TODO: use explicit scanStride
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
    89
                                                                        bitsPerPixel:32] autorelease];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    jint *imgData = (jint *)[imageRep bitmapData];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    if (imgData == NULL) return 0L;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    jint *src = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    if (src == NULL) return 0L;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    CImage_CopyArrayIntoNSImageRep(src, imgData, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    (*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   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) {
24554
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
   118
        NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
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
        result = ptr_to_jlong(nsImage);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   123
JNF_COCOA_EXIT(env);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   124
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   125
    return result;
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   126
}
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
 * Class:     sun_lwawt_macosx_CImage
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   130
 * Method:    nativeCreateNSImageFromArrays
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   131
 * Signature: ([[I[I[I)J
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   132
 */
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   133
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
   134
(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
   135
{
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   136
    jlong result = 0L;
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   137
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   138
JNF_COCOA_ENTER(env);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   139
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   140
    jsize num = (*env)->GetArrayLength(env, buffers);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   141
    NSMutableArray * reps = [NSMutableArray arrayWithCapacity: num];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   142
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   143
    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
   144
    if (ws != NULL) {
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   145
        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
   146
        if (hs != NULL) {
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   147
            jsize i;
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   148
            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
   149
                jintArray buffer = (*env)->GetObjectArrayElement(env, buffers, i);
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   150
23319
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   151
                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
   152
                if (imageRep) {
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   153
                    [reps addObject: imageRep];
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   154
                }
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
            (*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT);
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   158
        }
23319
b6523289a3b7 8034105: [parfait] JNI exception pending in jdk/src/macosx/native/sun/awt/CImage.m
serb
parents: 23257
diff changeset
   159
        (*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT);
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   160
    }
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   161
    if ([reps count]) {
24554
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
   162
        NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   163
        [nsImage addRepresentations: reps];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   164
        result = ptr_to_jlong(nsImage);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   165
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    return result;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
 * Method:    nativeCreateNSImageFromIconSelector
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
 * Signature: (I)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromIconSelector
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
(JNIEnv *env, jclass klass, jint selector)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
    NSImage *image = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
    IconRef iconRef;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
    if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) {
24554
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
   186
        image = [[NSImage alloc] initWithIconRef:iconRef];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        ReleaseIconRef(iconRef);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
    return ptr_to_jlong(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
 * Method:    nativeCreateNSImageFromFileContents
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
 * Signature: (Ljava/lang/String;)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromFileContents
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
(JNIEnv *env, jclass klass, jstring file)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    NSImage *image = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
    NSString *path = JNFNormalizedNSStringForPath(env, file);
24554
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
   208
    image = [[NSImage alloc] initByReferencingFile:path];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
    return ptr_to_jlong(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
 * Method:    nativeCreateNSImageOfFileFromLaunchServices
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
 * Signature: (Ljava/lang/String;)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageOfFileFromLaunchServices
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
(JNIEnv *env, jclass klass, jstring file)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    __block NSImage *image = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    NSString *path = JNFNormalizedNSStringForPath(env, file);
15322
3638f33225ec 7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents: 12654
diff changeset
   228
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23615
diff changeset
   229
        image = [[[NSWorkspace sharedWorkspace] iconForFile:path] retain];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
        [image setScalesWhenResized:TRUE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
    return ptr_to_jlong(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
 * Method:    nativeCreateNSImageFromImageName
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
 * Signature: (Ljava/lang/String;)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromImageName
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
(JNIEnv *env, jclass klass, jstring name)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    NSImage *image = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23615
diff changeset
   250
    image = [[NSImage imageNamed:JNFJavaToNSString(env, name)] retain];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    return ptr_to_jlong(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
 * Method:    nativeCopyNSImageIntoArray
23615
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   260
 * Signature: (J[IIIII)V
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeCopyNSImageIntoArray
23615
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   263
(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
   264
                 jint dw, jint dh)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
    NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    if (dst) {
23615
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   271
        NSRect fromRect = NSMakeRect(0, 0, sw, sh);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   272
        NSRect toRect = NSMakeRect(0, 0, dw, dh);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   273
        CImage_CopyNSImageIntoArray(img, dst, fromRect, toRect);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        (*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
 * Method:    nativeGetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
 * Signature: (J)Ljava/awt/geom/Dimension2D;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CImage_nativeGetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
(JNIEnv *env, jclass klass, jlong nsImgPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
    jobject size = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
    size = NSToJavaSize(env, [(NSImage *)jlong_to_ptr(nsImgPtr) size]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
    return size;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
 * Method:    nativeSetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
 * Signature: (JDD)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeSetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
    if (!image) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
    NSImage *i = (NSImage *)jlong_to_ptr(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
    [i setScalesWhenResized:TRUE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    [i setSize:NSMakeSize(w, h)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
}
23257
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   317
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   318
/*
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   319
 * Class:     sun_lwawt_macosx_CImage
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   320
 * Method:    nativeResizeNSImageRepresentations
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   321
 * Signature: (JDD)V
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   322
 */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   323
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeResizeNSImageRepresentations
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   324
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h)
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   325
{
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   326
    if (!image) return;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   327
    NSImage *i = (NSImage *)jlong_to_ptr(image);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   328
    
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   329
JNF_COCOA_ENTER(env);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   330
    
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   331
    NSImageRep *imageRep = nil;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   332
    NSArray *imageRepresentations = [i representations];
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   333
    NSEnumerator *imageEnumerator = [imageRepresentations objectEnumerator];
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   334
    while ((imageRep = [imageEnumerator nextObject]) != nil) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   335
        [imageRep setSize:NSMakeSize(w, h)];
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   336
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   337
    
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   338
JNF_COCOA_EXIT(env);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents: 15322
diff changeset
   339
}
23615
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   340
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   341
NSComparisonResult getOrder(BOOL order){
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   342
    return (NSComparisonResult) (order ? NSOrderedAscending : NSOrderedDescending);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   343
}
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
 * Class:     sun_lwawt_macosx_CImage
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   347
 * Method:    nativeGetNSImageRepresentationsCount
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   348
 * Signature: (JDD)[Ljava/awt/geom/Dimension2D;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   349
 */
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   350
JNIEXPORT jobjectArray JNICALL
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   351
                  Java_sun_lwawt_macosx_CImage_nativeGetNSImageRepresentationSizes
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   352
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h)
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   353
{
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   354
    if (!image) return NULL;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   355
    jobjectArray jreturnArray = NULL;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   356
    NSImage *img = (NSImage *)jlong_to_ptr(image);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   357
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   358
JNF_COCOA_ENTER(env);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   359
        
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   360
    NSArray *imageRepresentations = [img representations];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   361
    if([imageRepresentations count] == 0){
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   362
        return NULL;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   363
    }
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
    NSArray *sortedImageRepresentations = [imageRepresentations
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   366
                    sortedArrayUsingComparator: ^(id obj1, id obj2) {
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   367
        
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   368
        NSImageRep *imageRep1 = (NSImageRep *) obj1;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   369
        NSImageRep *imageRep2 = (NSImageRep *) obj2;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   370
        NSSize size1 = [imageRep1 size];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   371
        NSSize size2 = [imageRep2 size];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   372
        
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   373
        if (NSEqualSizes(size1, size2)) {
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   374
            return getOrder([imageRep1 pixelsWide] <= [imageRep2 pixelsWide] &&
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   375
                            [imageRep1 pixelsHigh] <= [imageRep2 pixelsHigh]);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   376
        }
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
        return getOrder(size1.width <= size2.width && size1.height <= size2.height);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   379
    }];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   380
24137
b4066d0e2bca 8036882: [macosx] Native memory leak in Java_sun_lwawt_macosx_CImage_nativeGetNSImageRepresentationSizes
alexsch
parents: 23652
diff changeset
   381
    NSMutableArray *sortedPixelSizes = [[[NSMutableArray alloc] init] autorelease];
23615
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   382
    NSSize lastSize = [[sortedImageRepresentations lastObject] size];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   383
    
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   384
    NSUInteger i = [sortedImageRepresentations indexOfObjectPassingTest:
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   385
               ^BOOL(id obj, NSUInteger idx, BOOL *stop) {
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   386
        NSSize imageRepSize = [obj size];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   387
        return (w <= imageRepSize.width && h <= imageRepSize.height)
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   388
                   || NSEqualSizes(imageRepSize, lastSize);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   389
    }];
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
    NSUInteger count = [sortedImageRepresentations count];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   392
    i = (i == NSNotFound) ? count - 1 : i;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   393
    NSSize bestFitSize = [[sortedImageRepresentations objectAtIndex: i] size];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   394
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   395
    for(; i < count; i++){
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   396
        NSImageRep *imageRep = [sortedImageRepresentations objectAtIndex: i];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   397
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   398
        if (!NSEqualSizes([imageRep size], bestFitSize)) {
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   399
            break;
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   400
        }
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
        NSSize pixelSize = NSMakeSize(
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   403
                                [imageRep pixelsWide], [imageRep pixelsHigh]);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   404
        [sortedPixelSizes addObject: [NSValue valueWithSize: pixelSize]];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   405
    }
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
    count = [sortedPixelSizes count];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   408
    static JNF_CLASS_CACHE(jc_Dimension, "java/awt/Dimension");
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   409
    jreturnArray = JNFNewObjectArray(env, &jc_Dimension, count);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   410
    CHECK_NULL_RETURN(jreturnArray, NULL);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   411
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   412
    for(i = 0; i < count; i++){
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   413
        NSSize pixelSize = [[sortedPixelSizes objectAtIndex: i] sizeValue];
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   414
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   415
        (*env)->SetObjectArrayElement(env, jreturnArray, i,
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   416
                                      NSToJavaSize(env, pixelSize));
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   417
        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   418
    }
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
JNF_COCOA_EXIT(env);
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   421
a0825e77bfad 8033534: [macosx] Get MultiResolution image from native system
alexsch
parents: 23328
diff changeset
   422
    return jreturnArray;
23651
e41298d0da2f 8037099: [macosx] Remove all references to GC from native OBJ-C code
pchelko
parents: 23615
diff changeset
   423
}
23652
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   424
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
 * Class:     sun_lwawt_macosx_CImage
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   427
 * Method:    nativeGetPlatformImageBytes
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   428
 * Signature: ([III)[B
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   429
 */
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   430
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
   431
(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
   432
{
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   433
    jbyteArray result = 0L;
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   434
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   435
    JNF_COCOA_ENTER(env);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   436
24554
55edf9459457 8036917: [macosx] Native memory leaks.
pchelko
parents: 24137
diff changeset
   437
    NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
23652
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   438
    if (imageRep) {
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   439
        NSData *tiffImage = [imageRep TIFFRepresentation];
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   440
        jsize tiffSize = (jsize)[tiffImage length];
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   441
        result = (*env)->NewByteArray(env, tiffSize);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   442
        CHECK_NULL_RETURN(result, nil);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   443
        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
   444
        CHECK_NULL_RETURN(tiffData, nil);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   445
        [tiffImage getBytes:tiffData];
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   446
        (*env)->ReleasePrimitiveArrayCritical(env, result, tiffData, 0);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   447
    }
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
    JNF_COCOA_EXIT(env);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   450
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   451
    return result;
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   452
}
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
 * Class:     sun_lwawt_macosx_CImage
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   456
 * Method:    nativeCreateNSImageFromBytes
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   457
 * Signature: ([B)J
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   458
 */
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   459
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
   460
(JNIEnv *env, jclass klass, jbyteArray sourceData)
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   461
{
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   462
    jlong result = 0L;
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   463
    CHECK_NULL_RETURN(sourceData, 0L);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   464
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   465
    JNF_COCOA_ENTER(env);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   466
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   467
    jsize sourceSize = (*env)->GetArrayLength(env, sourceData);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   468
    if (sourceSize == 0) return 0L;
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   469
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   470
    jbyte *sourceBytes = (*env)->GetPrimitiveArrayCritical(env, sourceData, NULL);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   471
    CHECK_NULL_RETURN(sourceBytes, 0L);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   472
    NSData *rawData = [NSData dataWithBytes:sourceBytes length:sourceSize];
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   473
    NSImage *newImage = [[NSImage alloc] initWithData:rawData];
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   474
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   475
    (*env)->ReleasePrimitiveArrayCritical(env, sourceData, sourceBytes, JNI_ABORT);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   476
    CHECK_NULL_RETURN(newImage, 0L);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   477
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   478
    result = ptr_to_jlong(newImage);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   479
    JNF_COCOA_EXIT(env);
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   480
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   481
    return result;
11515e3c3f85 8037371: [macosx] Test closed/java/awt/dnd/ImageTransferTest/ImageTransferTest.html fails
pchelko
parents: 23651
diff changeset
   482
}