jdk/src/macosx/native/sun/awt/CImage.m
author anthony
Wed, 16 May 2012 14:28:12 +0400
changeset 12654 9c691a35d1da
parent 12403 50b3f2982b59
child 15322 3638f33225ec
permissions -rw-r--r--
7168851: [macosx] Netbeans crashes in CImage.nativeCreateNSImageFromArray Summary: Eliminate unnecessary -release call Reviewed-by: dcherepanov
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
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#import <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#import "GeomUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#import "ThreadUtilities.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#import "sun_lwawt_macosx_CImage.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
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
static void CImage_CopyArrayIntoNSImageRep
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
(jint *srcPixels, jint *dstPixels, int width, int height)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
    int x, y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
    // 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
    40
    for (y = 0; y < height; y++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
        for (x = 0; x < width; x++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
            jint pix = srcPixels[x];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
            jint a = (pix >> 24) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
            jint r = (pix >> 16) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
            jint g = (pix >>  8) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
            jint b = (pix      ) & 0xff;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
            dstPixels[x] = (b << 24) | (g << 16) | (r << 8) | a;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
        srcPixels += width; // TODO: use explicit scanStride
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
        dstPixels += width;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    }
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
static void CImage_CopyNSImageIntoArray
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
(NSImage *srcImage, jint *dstPixels, int width, int height)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
    CGContextRef cgRef = CGBitmapContextCreate(dstPixels, width, height, 8, width * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
    CGColorSpaceRelease(colorspace);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgRef flipped:NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    CGContextRelease(cgRef);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
    NSGraphicsContext *oldContext = [[NSGraphicsContext currentContext] retain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    [NSGraphicsContext setCurrentContext:context];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    NSRect rect = NSMakeRect(0, 0, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
    [srcImage drawInRect:rect
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
                fromRect:rect
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
               operation:NSCompositeSourceOver
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
                fraction:1.0];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    [NSGraphicsContext setCurrentContext:oldContext];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
    [oldContext release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
    73
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
    74
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
    NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
                                                                         pixelsWide:width
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
                                                                         pixelsHigh:height
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
                                                                      bitsPerSample:8
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
                                                                    samplesPerPixel:4
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
                                                                           hasAlpha:YES
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
                                                                           isPlanar:NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
                                                                     colorSpaceName:NSDeviceRGBColorSpace
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
                                                                       bitmapFormat:NSAlphaFirstBitmapFormat
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
                                                                        bytesPerRow:width*4 // TODO: use explicit scanStride
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
                                                                       bitsPerPixel:32];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    jint *imgData = (jint *)[imageRep bitmapData];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    if (imgData == NULL) return 0L;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    jint *src = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    if (src == NULL) return 0L;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    CImage_CopyArrayIntoNSImageRep(src, imgData, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    (*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
    97
    return imageRep;
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
    98
}
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
    99
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   100
/*
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   101
 * Class:     sun_lwawt_macosx_CImage
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   102
 * Method:    nativeCreateNSImageFromArray
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   103
 * Signature: ([III)J
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
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
   106
(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
   107
{
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   108
    jlong result = 0L;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   110
JNF_COCOA_ENTER(env);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   111
AWT_ASSERT_ANY_THREAD;
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   112
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   113
    NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   114
    if (imageRep) {
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   115
        NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   116
        [nsImage addRepresentation:imageRep];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   117
        [imageRep release];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   118
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   119
        if (nsImage != nil) {
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   120
            CFRetain(nsImage); // GC
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   121
        }
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   122
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   123
        result = ptr_to_jlong(nsImage);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
12403
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   126
JNF_COCOA_EXIT(env);
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
    return result;
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
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   131
/*
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   132
 * Class:     sun_lwawt_macosx_CImage
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   133
 * Method:    nativeCreateNSImageFromArrays
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   134
 * Signature: ([[I[I[I)J
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
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
   137
(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
   138
{
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   139
    jlong result = 0L;
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
JNF_COCOA_ENTER(env);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   142
AWT_ASSERT_ANY_THREAD;
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
    jsize num = (*env)->GetArrayLength(env, buffers);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   145
    NSMutableArray * reps = [NSMutableArray arrayWithCapacity: num];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   146
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   147
    jint * ws = (*env)->GetIntArrayElements(env, widths, NULL);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   148
    jint * hs = (*env)->GetIntArrayElements(env, heights, NULL);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   149
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   150
    jsize i;
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   151
    for (i = 0; i < num; i++) {
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   152
        jintArray buffer = (*env)->GetObjectArrayElement(env, buffers, i);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   153
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   154
        NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, ws[i], hs[i]);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   155
        if (imageRep) {
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   156
            [reps addObject: imageRep];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   157
        }
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   158
    }
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   159
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   160
    (*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   161
    (*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   162
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   163
    if ([reps count]) {
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   164
        NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   165
        [nsImage addRepresentations: reps];
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   166
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   167
        if (nsImage != nil) {
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   168
            CFRetain(nsImage); // GC
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   169
        }
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   170
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   171
        result = ptr_to_jlong(nsImage);
50b3f2982b59 7148275: [macosx] setIconImages() not working correctly (distorted icon when minimized)
anthony
parents: 12047
diff changeset
   172
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
    return result;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
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
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
 * Method:    nativeCreateNSImageFromIconSelector
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
 * Signature: (I)J
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
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromIconSelector
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
(JNIEnv *env, jclass klass, jint selector)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
    NSImage *image = nil;
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
AWT_ASSERT_ANY_THREAD;
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
    IconRef iconRef;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
        image = [[NSImage alloc] initWithIconRef:iconRef];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
        if (image) CFRetain(image); // GC
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
        ReleaseIconRef(iconRef);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    return ptr_to_jlong(image);
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
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
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
 * Method:    nativeCreateNSImageFromFileContents
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
 * Signature: (Ljava/lang/String;)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromFileContents
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
(JNIEnv *env, jclass klass, jstring file)
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
    NSImage *image = nil;
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
AWT_ASSERT_ANY_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
    NSString *path = JNFNormalizedNSStringForPath(env, file);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
    image = [[NSImage alloc] initByReferencingFile:path];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
    if (image) CFRetain(image); // GC
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
JNF_COCOA_EXIT(env);
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
    return ptr_to_jlong(image);
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
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
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
 * Method:    nativeCreateNSImageOfFileFromLaunchServices
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
 * Signature: (Ljava/lang/String;)J
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageOfFileFromLaunchServices
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
(JNIEnv *env, jclass klass, jstring file)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
    __block NSImage *image = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
AWT_ASSERT_ANY_THREAD;
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
    NSString *path = JNFNormalizedNSStringForPath(env, file);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
        image = [[NSWorkspace sharedWorkspace] iconForFile:path];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
        [image setScalesWhenResized:TRUE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
        if (image) CFRetain(image); // GC
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
    }];
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
JNF_COCOA_EXIT(env);
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
    return ptr_to_jlong(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
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
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
 * Method:    nativeCreateNSImageFromImageName
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
 * Signature: (Ljava/lang/String;)J
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
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromImageName
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
(JNIEnv *env, jclass klass, jstring name)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
    NSImage *image = nil;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
AWT_ASSERT_ANY_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
    image = [NSImage imageNamed:JNFJavaToNSString(env, name)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
    if (image) CFRetain(image); // GC
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    return ptr_to_jlong(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
 * Method:    nativeCopyNSImageIntoArray
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
 * Signature: (J[III)V
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
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeCopyNSImageIntoArray
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
(JNIEnv *env, jclass klass, jlong nsImgPtr, jintArray buffer, jint w, jint h)
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
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
AWT_ASSERT_ANY_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
    jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
    if (dst) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
        CImage_CopyNSImageIntoArray(img, dst, w, h);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
        (*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
    }
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_EXIT(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
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
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
 * Method:    nativeGetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
 * Signature: (J)Ljava/awt/geom/Dimension2D;
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
JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CImage_nativeGetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
(JNIEnv *env, jclass klass, jlong nsImgPtr)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
    jobject size = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
AWT_ASSERT_ANY_THREAD;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
    size = NSToJavaSize(env, [(NSImage *)jlong_to_ptr(nsImgPtr) size]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
JNF_COCOA_EXIT(env);
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
    return size;
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
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
 * Class:     sun_lwawt_macosx_CImage
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
 * Method:    nativeSetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
 * Signature: (JDD)V
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CImage_nativeSetNSImageSize
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
(JNIEnv *env, jclass clazz, jlong image, jdouble w, jdouble h)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
    if (!image) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    NSImage *i = (NSImage *)jlong_to_ptr(image);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
JNF_COCOA_ENTER(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
    [i setScalesWhenResized:TRUE];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
    [i setSize:NSMakeSize(w, h)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
JNF_COCOA_EXIT(env);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
}