1 /*
   2  * Copyright (c) 2012, 2017, 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
  23  * questions.
  24  */
  25 
  26 #include "LensCommon.h"
  27 #include "com_sun_glass_ui_lens_LensCursor.h"
  28 #include "LensCursorImages.h"
  29 
  30 /*
  31  * Class:     com_sun_glass_ui_lens_LensCursor
  32  * Method:    _setNativeCursor
  33  * Signature: (J)V
  34  */
  35 JNIEXPORT void JNICALL Java_com_sun_glass_ui_lens_LensCursor__1setNativeCursor
  36 (JNIEnv *env, jobject jCursor, jlong nativeCursorPointer) {
  37     glass_cursor_setNativeCursor(nativeCursorPointer);
  38 }
  39 
  40 /*
  41  * Class:     com_sun_glass_ui_lens_LensCursor
  42  * Method:    _releaseNativeCursor
  43  * Signature: (J)V
  44  */
  45 JNIEXPORT void JNICALL Java_com_sun_glass_ui_lens_LensCursor__1releaseNativeCursor
  46 (JNIEnv *env, jobject jCursor, jlong nativeCursorPointer) {
  47     glass_cursor_releaseNativeCursor(nativeCursorPointer);
  48 }
  49 
  50 /*
  51  * Class:     com_sun_glass_ui_lens_LensCursor
  52  * Method:    _createNativeCursorByType
  53  * Signature: (I)J
  54  */
  55 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_lens_LensCursor__1createNativeCursorByType
  56 (JNIEnv *env, jobject jCursor, jint type) {
  57 
  58     int width, height;
  59     jbyte *img = lensCursorsGetCursor(type, &width, &height,
  60                                       glass_cursor_supportsTranslucency());
  61 
  62     return glass_cursor_createNativeCursor(env, 0, 0, img, width, height);
  63 }
  64 
  65 
  66 /*
  67  * Class:     com_sun_glass_ui_lens_LensCursor
  68  * Method:    _createNativeCursorInts
  69  * Signature: (II[III)J
  70  */
  71 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_lens_LensCursor__1createNativeCursorInts
  72 (JNIEnv *env, jobject jCursor, jint x, jint y,  jintArray srcArray, jint width, jint height) {
  73 
  74     jbyte *src = (*env)->GetPrimitiveArrayCritical(env, srcArray, 0);
  75     if (src == NULL) {
  76         fprintf(stderr, "1createNativeCursorInts: GetPrimitiveArrayCritical returns NULL: out of memory\n");
  77         return 0;
  78     }
  79 
  80     jlong res =  glass_cursor_createNativeCursor(env, x, y, src, width, height);
  81 
  82 
  83     (*env)->ReleasePrimitiveArrayCritical(env, srcArray, src, JNI_ABORT);
  84 
  85     return res;
  86 }
  87 
  88 
  89 /*
  90  * Class:     com_sun_glass_ui_lens_LensCursor
  91  * Method:    _createNativeCursorBytes
  92  * Signature: (II[BII)J
  93  */
  94 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_lens_LensCursor__1createNativeCursorBytes
  95 (JNIEnv *env, jobject jCursor, jint x, jint y,  jbyteArray srcArray, jint width, jint height) {
  96     glass_throw_exception_by_name(env, glass_RuntimeException, "Unimplemented");
  97     return 0;
  98 }
  99 
 100 
 101 /*
 102  * Class:     com_sun_glass_ui_lens_LensCursor
 103  * Method:    _createNativeCursorDirect
 104  * Signature: (IILjava/nio/Buffer;III)J
 105  */
 106 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_lens_LensCursor__1createNativeCursorDirect
 107 (JNIEnv *env, jobject jCursor, jint x, jint y,  jobject srcArray, jint capacity, jint width, jint height) {
 108     glass_throw_exception_by_name(env, glass_RuntimeException, "Unimplemented");
 109     return 0;
 110 }
 111 
 112 
 113 /*
 114  * Class:     com_sun_glass_ui_lens_LensCursor
 115  * Method:    _setVisible
 116  * Signature: (Z)V
 117  */
 118 JNIEXPORT void JNICALL Java_com_sun_glass_ui_lens_LensCursor__1setVisible
 119 (JNIEnv *env, jclass cursurClass, jboolean isVisible) {
 120     glass_cursor_setVisible(isVisible);
 121 }
 122 
 123 
 124 
 125 
 126 /*
 127 * Destructor function to clean the cursor resources.
 128 * The execution time of this function must be short since it is called
 129 * when the application is exiting.
 130 */
 131 int lensCursorDestructor(void) __attribute__((destructor));
 132 
 133 int lensCursorDestructor(void) {
 134     glass_cursor_terminate();
 135 
 136     return 0;
 137 }