src/macosx/native/com/apple/laf/JRSUIController.m

Print this page


   1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 182  */
 183 JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintChangesToCGContext
 184 (JNIEnv *env, jclass clazz, jlong cgContextPtr, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jlong changes)
 185 {
 186     int syncStatus = doSyncChanges(env, controlPtr, changes);
 187     if (syncStatus != apple_laf_JRSUIControl_SUCCESS) return syncStatus;
 188 
 189     return doPaintCGContext((CGContextRef)jlong_to_ptr(cgContextPtr), controlPtr, oldProperties, newProperties, x, y, w, h);
 190 }
 191 
 192 static inline jint doPaintImage
 193 (JNIEnv *env, jlong controlPtr, jlong oldProperties, jlong newProperties, jintArray data, jint imgW, jint imgH, jdouble x, jdouble y, jdouble w, jdouble h)
 194 {
 195     jboolean isCopy = JNI_FALSE;
 196     void *rawPixelData = (*env)->GetPrimitiveArrayCritical(env, data, &isCopy);
 197     if (!rawPixelData) return apple_laf_JRSUIControl_NULL_PTR;
 198 
 199     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
 200     CGContextRef cgRef = CGBitmapContextCreate(rawPixelData, imgW, imgH, 8, imgW * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
 201     CGColorSpaceRelease(colorspace);

 202 
 203     jint status = doPaintCGContext(cgRef, controlPtr, oldProperties, newProperties, x, y, w, h);
 204     CGContextRelease(cgRef);
 205 
 206     (*env)->ReleasePrimitiveArrayCritical(env, data, rawPixelData, 0);
 207 
 208     return status == noErr ? apple_laf_JRSUIControl_SUCCESS : status;
 209 }
 210 
 211 /*
 212  * Class:     apple_laf_JRSUIControl
 213  * Method:    paintImage
 214  * Signature: ([IIIJJJDDDD)I
 215  */
 216 JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintImage
 217 (JNIEnv *env, jclass clazz, jintArray data, jint imgW, jint imgH, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h)
 218 {
 219     return doPaintImage(env, controlPtr, oldProperties, newProperties, data, imgW, imgH, x, y, w, h);
 220 }
 221 


   1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 182  */
 183 JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintChangesToCGContext
 184 (JNIEnv *env, jclass clazz, jlong cgContextPtr, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h, jlong changes)
 185 {
 186     int syncStatus = doSyncChanges(env, controlPtr, changes);
 187     if (syncStatus != apple_laf_JRSUIControl_SUCCESS) return syncStatus;
 188 
 189     return doPaintCGContext((CGContextRef)jlong_to_ptr(cgContextPtr), controlPtr, oldProperties, newProperties, x, y, w, h);
 190 }
 191 
 192 static inline jint doPaintImage
 193 (JNIEnv *env, jlong controlPtr, jlong oldProperties, jlong newProperties, jintArray data, jint imgW, jint imgH, jdouble x, jdouble y, jdouble w, jdouble h)
 194 {
 195     jboolean isCopy = JNI_FALSE;
 196     void *rawPixelData = (*env)->GetPrimitiveArrayCritical(env, data, &isCopy);
 197     if (!rawPixelData) return apple_laf_JRSUIControl_NULL_PTR;
 198 
 199     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
 200     CGContextRef cgRef = CGBitmapContextCreate(rawPixelData, imgW, imgH, 8, imgW * 4, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
 201     CGColorSpaceRelease(colorspace);
 202     CGContextScaleCTM(cgRef, imgW/w , imgH/h);
 203 
 204     jint status = doPaintCGContext(cgRef, controlPtr, oldProperties, newProperties, x, y, w, h);
 205     CGContextRelease(cgRef);
 206 
 207     (*env)->ReleasePrimitiveArrayCritical(env, data, rawPixelData, 0);
 208 
 209     return status == noErr ? apple_laf_JRSUIControl_SUCCESS : status;
 210 }
 211 
 212 /*
 213  * Class:     apple_laf_JRSUIControl
 214  * Method:    paintImage
 215  * Signature: ([IIIJJJDDDD)I
 216  */
 217 JNIEXPORT jint JNICALL Java_apple_laf_JRSUIControl_paintImage
 218 (JNIEnv *env, jclass clazz, jintArray data, jint imgW, jint imgH, jlong controlPtr, jlong oldProperties, jlong newProperties, jdouble x, jdouble y, jdouble w, jdouble h)
 219 {
 220     return doPaintImage(env, controlPtr, oldProperties, newProperties, data, imgW, imgH, x, y, w, h);
 221 }
 222